I'm just going to ditch this prototype soon
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user