From 6b677e5de8c7b43cf116ada3d3276a2db985bfbf Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Fri, 7 Jun 2013 03:13:38 +1000 Subject: [PATCH] I'm just going to ditch this prototype soon --- common/udp_network_utility.cpp | 20 ++++++++++++++++++++ common/udp_network_utility.hpp | 1 + server/server_application.cpp | 15 +++++++++++---- 3 files changed, 32 insertions(+), 4 deletions(-) diff --git a/common/udp_network_utility.cpp b/common/udp_network_utility.cpp index 388124c..5f828c7 100644 --- a/common/udp_network_utility.cpp +++ b/common/udp_network_utility.cpp @@ -116,6 +116,26 @@ int UDPNetworkUtility::Send(int channel, void* data, int len) { return ret; } +int UDPNetworkUtility::SendAll(void* data, int len) { + if (len > packOut->maxlen) { + throw(std::runtime_error("Failed to copy the data into the packet")); + } + memset(packOut->data, 0, packOut->maxlen); + memcpy(packOut->data, data, len); + packOut->len = len; + + int sent = 0; + + //send to all bound channels + for (int i = 0; i < SDLNET_MAX_UDPCHANNELS; i++) { + if (SDLNet_UDP_GetPeerAddress(socket, i)) { + sent += SDLNet_UDP_Send(socket, i, packOut); + } + } + + return sent; +} + int UDPNetworkUtility::Receive() { memset(packIn->data, 0, packIn->maxlen); int ret = SDLNet_UDP_Recv(socket, packIn); diff --git a/common/udp_network_utility.hpp b/common/udp_network_utility.hpp index 5422165..dbd752e 100644 --- a/common/udp_network_utility.hpp +++ b/common/udp_network_utility.hpp @@ -52,6 +52,7 @@ public: int Send(const char* ip, int port, void* data, int len); int Send(IPaddress* add, void* data, int len); int Send(int channel, void* data, int len); + int SendAll(void* data, int len); int Receive(); void* GetOutData() const { diff --git a/server/server_application.cpp b/server/server_application.cpp index b42e135..326fbb4 100644 --- a/server/server_application.cpp +++ b/server/server_application.cpp @@ -127,11 +127,18 @@ void ServerApplication::Disconnect(int playerID) { return; } cout << "disconnecting: " << playerID << endl; + + //delete the player from all clients + PacketData p; + p.type = PacketList::DELETEPLAYER; + p.deletePlayer.playerID = playerID; + + netUtil.SendAll(&p, sizeof(PacketData)); + + //remove the player from the server netUtil.Unbind(clientMap[playerID].channel); clientMap.erase(playerID); - //TODO: Delete player - #ifdef DEBUG cout << "current players: " << clientMap.size() << endl; #endif @@ -170,9 +177,9 @@ void ServerApplication::NewClientData(int playerID) { } void ServerApplication::SendClientData(int playerID) { - //TODO + //relay a client's data } void ServerApplication::SynchronizeClient(int playerID) { - //TODO + //send all server data to a specific client }