Implemented a macro for the serial buffer size

This commit is contained in:
Kayne Ruse
2014-03-15 23:36:31 +11:00
parent d5b551cec3
commit 9db86c19f6
6 changed files with 56 additions and 25 deletions
+12 -11
View File
@@ -66,7 +66,7 @@ void ServerApplication::Init(int argc, char** argv) {
if (SDLNet_Init()) {
throw(runtime_error("Failed to initialize SDL_net"));
}
network.Open(config.Int("server.port"), sizeof(NetworkPacket));
network.Open(config.Int("server.port"), PACKET_BUFFER_SIZE);
cout << "Initialized SDL_net" << endl;
//Init SQL
@@ -105,6 +105,7 @@ void ServerApplication::Init(int argc, char** argv) {
// with the map system as needed.
cout << "Initialized the map system" << endl;
cout << "\tsizeof(NetworkPacket): " << sizeof(NetworkPacket) << endl;
cout << "\tPACKET_BUFFER_SIZE: " << PACKET_BUFFER_SIZE << endl;
//finalize the startup
cout << "Startup completed successfully" << endl;
@@ -189,9 +190,9 @@ void ServerApplication::HandleBroadcastRequest(NetworkPacket packet) {
//TODO: version info
snprintf(packet.serverInfo.name, PACKET_STRING_SIZE, "%s", config["server.name"].c_str());
//TODO: player count
char buffer[sizeof(NetworkPacket)];
char buffer[PACKET_BUFFER_SIZE];
serialize(&packet, buffer);
network.Send(&packet.meta.srcAddress, buffer, sizeof(NetworkPacket));
network.Send(&packet.meta.srcAddress, buffer, PACKET_BUFFER_SIZE);
}
void ServerApplication::HandleJoinRequest(NetworkPacket packet) {
@@ -201,13 +202,13 @@ void ServerApplication::HandleJoinRequest(NetworkPacket packet) {
clientMap[clientCounter] = c;
//send the client their info
char buffer[sizeof(NetworkPacket)];
char buffer[PACKET_BUFFER_SIZE];
packet.meta.type = NetworkPacket::Type::JOIN_RESPONSE;
packet.clientInfo.index = clientCounter;
serialize(&packet, buffer);
network.Send(&clientMap[clientCounter].address, buffer, sizeof(NetworkPacket));
network.Send(&clientMap[clientCounter].address, buffer, PACKET_BUFFER_SIZE);
//finished this routine
clientCounter++;
@@ -217,9 +218,9 @@ void ServerApplication::HandleJoinRequest(NetworkPacket packet) {
void ServerApplication::HandleDisconnect(NetworkPacket packet) {
//disconnect the specified client
//TODO: authenticate who is disconnecting/kicking
char buffer[sizeof(NetworkPacket)];
char buffer[PACKET_BUFFER_SIZE];
serialize(&packet, buffer);
network.Send(&clientMap[packet.clientInfo.index].address, buffer, sizeof(NetworkPacket));
network.Send(&clientMap[packet.clientInfo.index].address, buffer, PACKET_BUFFER_SIZE);
clientMap.erase(packet.clientInfo.index);
//delete players from all clients
@@ -245,7 +246,7 @@ void ServerApplication::HandleSynchronize(NetworkPacket packet) {
//send all the server's data to this client
//TODO: compensate for large distances
NetworkPacket newPacket;
char buffer[sizeof(NetworkPacket)];
char buffer[PACKET_BUFFER_SIZE];
//players
newPacket.meta.type = NetworkPacket::Type::PLAYER_UPDATE;
@@ -256,7 +257,7 @@ void ServerApplication::HandleSynchronize(NetworkPacket packet) {
newPacket.playerInfo.position = it.second.position;
newPacket.playerInfo.motion = it.second.motion;
serialize(&newPacket, buffer);
network.Send(&clientMap[packet.clientInfo.index].address, buffer, sizeof(NetworkPacket));
network.Send(&clientMap[packet.clientInfo.index].address, buffer, PACKET_BUFFER_SIZE);
}
}
@@ -334,9 +335,9 @@ void ServerApplication::HandlePlayerUpdate(NetworkPacket packet) {
void ServerApplication::PumpPacket(NetworkPacket packet) {
//I don't really like this, but it'll do for now
char buffer[sizeof(NetworkPacket)];
char buffer[PACKET_BUFFER_SIZE];
serialize(&packet, buffer);
for (auto& it : clientMap) {
network.Send(&it.second.address, buffer, sizeof(NetworkPacket));
network.Send(&it.second.address, buffer, PACKET_BUFFER_SIZE);
}
}