diff --git a/GPN_BadgeLasertag.ino b/GPN_BadgeLasertag.ino index 76c7ddea92e49a62d03228cddda43c3b1378185e..574fb515925895f83903c81940c05e5f66fe513f 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 37e41ff51a3a0d47f0fd43fc5d67f791589b59c7..7dc1da0fd6d42e48050e0e5e499f75e64b5d0658 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 f5770aa0ea1ca900a278cb4b948074d0e613e4aa..ac33e8a9ce87a72dea0f327cab3e43513fb3fe60 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);