GameServer.cpp 4.83 KiB
//
// Created by hoelshare on 22.05.17.
//
#define AUSGABE
#include "GameServer.hpp"
#include "ConfigPacket.hpp"
#include "Player.hpp"
#define RESISTANCE 100
#define HEALTH 100
void GameServer::setTeamPlay(char isTeam) {
#ifdef AUSGABE
Serial.printf("Is team play: %s", isTeam ? "true" : "false");
#endif
//TODO set Teamplay
}
void GameServer::secureQuestion() {
#ifdef AUSGABE
Serial.printf("Sicherheitsabfrage!");
#endif
//secureMenu = new PlayerListMenu(4);
//secureMenu->addMenuItem(new MenuItem("Start?", [=]() { this->startGame(); Serial.println("Lambda Start - Ende"); }));
//secureMenu->addMenuItem(new MenuItem("Cancel?", [=]() {
// ui->dispatchInput(badge->getJoystickState());
// ui->closeCurrent();
// ui->draw();
//}));
//secureMenu->setRightAction([=]() {
// ui->dispatchInput(badge->getJoystickState());
// ui->closeCurrent();
// ui->draw();
//});
//secureMenu->setLeftAction([=]() { this->startGame(); });
//ui->open(secureMenu);
}
void GameServer::kick() {
if (playerList) {
// unsigned short index = playerList->getIndex();
// do something with the index
}
}
void GameServer::update() {
if (!this->gameStarted) {
if (server->hasClient()) {
Serial.println("Has Client");
serverClients[numConnections] = server->available();
Serial.printf("New connection %d\n", numConnections);
handleWelcome(&(serverClients[numConnections]), numConnections);
}
} else {
// Serial.println("Waiting for packets");
for (short i = 0; i < numConnections; i++) { //iterate throu the slots
if (serverClients[i].connected() && serverClients[i].available()) { //skip unconnected slots
String message = serverClients[i].readStringUntil('\n');
UrlDecode decode(message.c_str());
String strTyp = String(decode.getKey("typ"));
Serial.println(message);
if (strTyp == "hit") {
HitPacket *packet = HitPacket::read(message);
sendHit(packet);
delete packet;
}
}
}