diff --git a/server/server_application.cpp b/server/server_application.cpp index c7003c9..92957ef 100644 --- a/server/server_application.cpp +++ b/server/server_application.cpp @@ -168,13 +168,37 @@ void ServerApplication::Broadcast(BroadcastRequest& bcast) { } void ServerApplication::HandleConnection(JoinRequest& request) { + if (clients.size() >= SDLNET_MAX_UDPCHANNELS) { + //ignore the new connection if there's too many clients connected + return; + } //create the containers - ClientData client = { clientTicker++ }; - PlayerData player = { playerTicker++ }; + ClientData client = { uniqueIndex }; + PlayerData player = { uniqueIndex }; + + uniqueIndex++; //link the containers client.playerIndex = player.index; player.clientIndex = client.index; - //??? oh fuck + //fill the containers + player.handle = request.playerHandle; + player.avatar = request.playerAvatar; + + //bind the address + client.channel = netUtil->Bind(&request.meta.address); + + //push this information + clients[client.index] = client; + players[player.index] = player; + + //send the player their information + Packet p; + p.meta.type = PacketType::JOIN_RESPONSE; + p.joinResponse.playerIndex = player.index; + netUtil->Send(client.channel, &p, sizeof(Packet)); + + //send it out to new players + //TODO } \ No newline at end of file diff --git a/server/server_application.hpp b/server/server_application.hpp index 9876ca5..3b1056f 100644 --- a/server/server_application.hpp +++ b/server/server_application.hpp @@ -14,6 +14,7 @@ #include #include +#include struct ClientData { int index; @@ -24,6 +25,8 @@ struct ClientData { struct PlayerData { int index; int clientIndex; + std::string handle; + std::string avatar; Vector2 position; Vector2 motion; @@ -62,8 +65,7 @@ private: bool running = false; - int clientTicker = 0; - int playerTicker = 0; + int uniqueIndex = 0; }; #endif