diff --git a/server/server_application.cpp b/server/server_application.cpp index d9d6d4b..d61ac82 100644 --- a/server/server_application.cpp +++ b/server/server_application.cpp @@ -34,7 +34,7 @@ using namespace std; //Declarations //------------------------- -int ClientInformation::counter = 0; +int Client::counter = 0; //------------------------- //Define the ServerApplication @@ -129,42 +129,49 @@ void ServerApplication::HandlePacket(NetworkPacket packet) { snprintf(packet.serverInfo.name, PACKET_STRING_SIZE, "%s", config["server.name"].c_str()); network.Send(&packet.meta.srcAddress, &packet, sizeof(NetworkPacket)); break; + case NetworkPacket::Type::JOIN_REQUEST: { //TODO: prevent duplicate logins from the same address? //create the new client, filling it with the correct info - ClientInformation newClient; - newClient.index = ClientInformation::counter++; + Client newClient; newClient.address = packet.meta.srcAddress; //push the new client - clientInfo[newClient.index] = newClient; + clientMap[Client::counter] = newClient; //send the client their info packet.meta.type = NetworkPacket::Type::JOIN_RESPONSE; - packet.clientInfo.index = newClient.index; + packet.clientInfo.index = Client::counter; network.Send(&newClient.address, &packet, sizeof(NetworkPacket)); - cout << "connect, total: " << clientInfo.size() << endl; + //finished this routine + Client::counter++; + cout << "connect, total: " << clientMap.size() << endl; } break; + case NetworkPacket::Type::DISCONNECT: //disconnect the specified client - network.Send(&clientInfo[packet.clientInfo.index].address, &packet, sizeof(NetworkPacket)); - clientInfo.erase(packet.clientInfo.index); + network.Send(&clientMap[packet.clientInfo.index].address, &packet, sizeof(NetworkPacket)); + clientMap.erase(packet.clientInfo.index); - cout << "disconnect, total: " << clientInfo.size() << endl; + //remove players? + + cout << "disconnect, total: " << clientMap.size() << endl; break; + case NetworkPacket::Type::SYNCHRONIZE: //TODO break; + case NetworkPacket::Type::SHUTDOWN: //end the server running = false; //disconnect all clients packet.meta.type = NetworkPacket::Type::DISCONNECT; - for (auto& it : clientInfo) { + for (auto& it : clientMap) { network.Send(&it.second.address, &packet, sizeof(NetworkPacket)); } diff --git a/server/server_application.hpp b/server/server_application.hpp index a2d1432..5dfa9a1 100644 --- a/server/server_application.hpp +++ b/server/server_application.hpp @@ -35,12 +35,10 @@ //STL #include -#include //hold the client info -struct ClientInformation { +struct Client { static int counter; - int index; IPaddress address; }; @@ -60,7 +58,6 @@ private: //networking UDPNetworkUtility network; - std::queue networkQueue; //database sqlite3* database = nullptr; @@ -69,7 +66,7 @@ private: bool running = true; ConfigUtility config; - std::map clientInfo; + std::map clientMap; }; #endif