From b29346ee878c21f431cc038a3250a61477f27efa Mon Sep 17 00:00:00 2001 From: fnord <olelange@protonmail.com> Date: Sat, 27 May 2017 20:57:07 +0200 Subject: [PATCH] blargh --- GPN_BadgeLasertag.ino | 18 +++++++++++++++++- GameClient.cpp | 2 +- GameClient.hpp | 2 +- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/GPN_BadgeLasertag.ino b/GPN_BadgeLasertag.ino index 76c7dde..574fb51 100644 --- a/GPN_BadgeLasertag.ino +++ b/GPN_BadgeLasertag.ino @@ -81,6 +81,22 @@ void hostGame() { #endif } +bool isValidIp(String ip){ + + unsigned short pos0 = ip.indexOf('.'); + unsigned short pos1 = ip.indexOf('.', pos0); + unsigned short pos2 = ip.indexOf('.', pos1); + unsigned short pos3 = ip.indexOf('.', pos2); + + String part0 = ip.substring(0, pos0); + String part1 = ip.substring(pos0, pos1); + String part2 = ip.substring(pos1, pos2); + String part3 = ip.substring(pos2, ip.length()); + + Serial.printf("Zerhackstuekelte IP: %s:%s:%s:%s", part0.c_str(), part1.c_str(), part2.c_str(), part3.c_str()); + +} + String recv_ir() { badge.setGPIO(IR_EN, HIGH); Serial.println("Entering receive mode"); @@ -126,7 +142,7 @@ String recv_ir() { Serial.printf("->:\n\t0: %c\n\t1: %c\n\t2: %c\n\t3: %c\n", buf[0], buf[1], buf[2], buf[3]); if (buf[0] == '\n' || buf[1] == '\n' || buf[2] == '\n' || buf[3] == '\n') { stringCompleted = true; - done = true; + done = isValidIp(received.substring(1, received.length() - 2)); } } irrecv.resume(); // Prepare for the next value diff --git a/GameClient.cpp b/GameClient.cpp index 37e41ff..7dc1da0 100644 --- a/GameClient.cpp +++ b/GameClient.cpp @@ -43,7 +43,7 @@ void GameClient::joinGame(String ip) { badge->setVibrator(false); playerList->addMenuItem(new MenuItem(player->getNickname(), []() {})); ui->open(playerList); - client->connect(ip, SERVER_PORT); + client->connect(ip.c_str(), SERVER_PORT); client->print(player->getNickname()); client->flush(); diff --git a/GameClient.hpp b/GameClient.hpp index f5770aa..ac33e8a 100644 --- a/GameClient.hpp +++ b/GameClient.hpp @@ -22,7 +22,7 @@ public: void startGame(); - void joinGame(); + void joinGame(String ip); bool wasHit(String* lastHitBy, int* lastDamage, bool enable = true); -- GitLab