I'm just going to ditch this prototype soon

This commit is contained in:
Kayne Ruse
2013-06-07 03:13:38 +10:00
parent d347545c20
commit 6b677e5de8
3 changed files with 32 additions and 4 deletions
+20
View File
@@ -116,6 +116,26 @@ int UDPNetworkUtility::Send(int channel, void* data, int len) {
return ret; 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() { int UDPNetworkUtility::Receive() {
memset(packIn->data, 0, packIn->maxlen); memset(packIn->data, 0, packIn->maxlen);
int ret = SDLNet_UDP_Recv(socket, packIn); int ret = SDLNet_UDP_Recv(socket, packIn);
+1
View File
@@ -52,6 +52,7 @@ public:
int Send(const char* ip, int port, void* data, int len); int Send(const char* ip, int port, void* data, int len);
int Send(IPaddress* add, void* data, int len); int Send(IPaddress* add, void* data, int len);
int Send(int channel, void* data, int len); int Send(int channel, void* data, int len);
int SendAll(void* data, int len);
int Receive(); int Receive();
void* GetOutData() const { void* GetOutData() const {
+11 -4
View File
@@ -127,11 +127,18 @@ void ServerApplication::Disconnect(int playerID) {
return; return;
} }
cout << "disconnecting: " << playerID << endl; 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); netUtil.Unbind(clientMap[playerID].channel);
clientMap.erase(playerID); clientMap.erase(playerID);
//TODO: Delete player
#ifdef DEBUG #ifdef DEBUG
cout << "current players: " << clientMap.size() << endl; cout << "current players: " << clientMap.size() << endl;
#endif #endif
@@ -170,9 +177,9 @@ void ServerApplication::NewClientData(int playerID) {
} }
void ServerApplication::SendClientData(int playerID) { void ServerApplication::SendClientData(int playerID) {
//TODO //relay a client's data
} }
void ServerApplication::SynchronizeClient(int playerID) { void ServerApplication::SynchronizeClient(int playerID) {
//TODO //send all server data to a specific client
} }