From 9c673928e60416cdb5ce8f19195775417fbe341f Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Sat, 26 Apr 2014 02:05:22 +1000 Subject: [PATCH 1/2] Began segmenting the server's code I've created a separate branch for this because it's gonna be a bitch to get compiled, and then I'll still have to ensure that the client & server are work together correctly. This build does not compile. --- server/client_entry.cpp | 2 +- server/client_entry.hpp | 2 +- ...{server_application.cpp => networking.cpp} | 165 ++--------------- server/player_entry.cpp | 2 +- server/player_entry.hpp | 3 +- server/player_management.cpp | 46 +++++ server/server_application.hpp | 18 +- server/server_internals.cpp | 166 ++++++++++++++++++ 8 files changed, 238 insertions(+), 166 deletions(-) rename server/{server_application.cpp => networking.cpp} (61%) create mode 100644 server/player_management.cpp create mode 100644 server/server_internals.cpp diff --git a/server/client_entry.cpp b/server/client_entry.cpp index 7708423..88e2ab9 100644 --- a/server/client_entry.cpp +++ b/server/client_entry.cpp @@ -21,4 +21,4 @@ */ #include "client_entry.hpp" -unsigned int ClientEntry::uidCounter; +int ClientEntry::uidCounter = 0; diff --git a/server/client_entry.hpp b/server/client_entry.hpp index 42225b8..7e5dc90 100644 --- a/server/client_entry.hpp +++ b/server/client_entry.hpp @@ -26,7 +26,7 @@ struct ClientEntry { IPaddress address; - static unsigned int uidCounter; + static int uidCounter; }; #endif diff --git a/server/server_application.cpp b/server/networking.cpp similarity index 61% rename from server/server_application.cpp rename to server/networking.cpp index 1a96d5b..a981abf 100644 --- a/server/server_application.cpp +++ b/server/networking.cpp @@ -21,167 +21,19 @@ */ #include "server_application.hpp" -#include "utility.hpp" - #include #include -#include - -//------------------------- -//Define the public members -//------------------------- - -void ServerApplication::Init(int argc, char** argv) { - //NOTE: I might need to rearrange the init process so that lua & SQL can interact with the map system as needed. - std::cout << "Beginning startup" << std::endl; - - //initial setup - ClientEntry::uidCounter = 0; - PlayerEntry::uidCounter = 0; - config.Load("rsc\\config.cfg"); - - //Init SDL - if (SDL_Init(0)) { - throw(std::runtime_error("Failed to initialize SDL")); - } - std::cout << "Initialized SDL" << std::endl; - - //Init SDL_net - if (SDLNet_Init()) { - throw(std::runtime_error("Failed to initialize SDL_net")); - } - network.Open(config.Int("server.port"), PACKET_BUFFER_SIZE); - std::cout << "Initialized SDL_net" << std::endl; - - //Init SQL - int ret = sqlite3_open_v2(config["server.dbname"].c_str(), &database, SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE, nullptr); - if (ret != SQLITE_OK || !database) { - throw(std::runtime_error(std::string() + "Failed to initialize SQL: " + sqlite3_errmsg(database) )); - } - std::cout << "Initialized SQL" << std::endl; - - //setup the database - if (runSQLScript(database, config["dir.scripts"] + "setup_server.sql")) { - throw(std::runtime_error("Failed to initialize SQL's setup script")); - } - std::cout << "Initialized SQL's setup script" << std::endl; - - //lua - luaState = luaL_newstate(); - if (!luaState) { - throw(std::runtime_error("Failed to initialize lua")); - } - luaL_openlibs(luaState); - std::cout << "Initialized lua" << std::endl; - - //run the startup script - if (luaL_dofile(luaState, (config["dir.scripts"] + "setup_server.lua").c_str())) { - throw(std::runtime_error(std::string() + "Failed to initialize lua's setup script: " + lua_tostring(luaState, -1) )); - } - std::cout << "Initialized lua's setup script" << std::endl; - - //setup the map object - regionPager.GetAllocator()->SetLuaState(luaState); - regionPager.GetFormat()->SetLuaState(luaState); - //TODO: config parameter - regionPager.GetFormat()->SetSaveDir("save/mapname/"); - - std::cout << "Initialized the map system" << std::endl; - std::cout << "\tsizeof(SerialPacket): " << sizeof(SerialPacket) << std::endl; - std::cout << "\tPACKET_BUFFER_SIZE: " << PACKET_BUFFER_SIZE << std::endl; - - //finalize the startup - std::cout << "Startup completed successfully" << std::endl; - - //debugging - // -} - -void ServerApplication::Proc() { - SerialPacket packet; - while(running) { - //suck in the waiting packets & process them - while(network.Receive()) { - //get the packet - deserialize(&packet, network.GetInData()); - //cache the source address - packet.meta.srcAddress = network.GetInPacket()->address; - //we need to go deeper - HandlePacket(packet); - } - //give the computer a break - SDL_Delay(10); - } -} - -void ServerApplication::Quit() { - std::cout << "Shutting down" << std::endl; - //empty the members - regionPager.UnloadAll(); - - //APIs - lua_close(luaState); - sqlite3_close_v2(database); - network.Close(); - SDLNet_Quit(); - SDL_Quit(); - std::cout << "Shutdown finished" << std::endl; -} - -//------------------------- -//Define the uber switch -//------------------------- - -void ServerApplication::HandlePacket(SerialPacket packet) { - switch(packet.meta.type) { - case SerialPacket::Type::BROADCAST_REQUEST: - HandleBroadcastRequest(packet); - break; - case SerialPacket::Type::JOIN_REQUEST: - HandleJoinRequest(packet); - break; - case SerialPacket::Type::DISCONNECT: - HandleDisconnect(packet); - break; - case SerialPacket::Type::SYNCHRONIZE: - HandleSynchronize(packet); - break; - case SerialPacket::Type::SHUTDOWN: - HandleShutdown(packet); - break; - case SerialPacket::Type::PLAYER_NEW: - HandlePlayerNew(packet); - break; - case SerialPacket::Type::PLAYER_DELETE: - HandlePlayerDelete(packet); - break; - case SerialPacket::Type::PLAYER_UPDATE: - HandlePlayerUpdate(packet); - break; - case SerialPacket::Type::REGION_REQUEST: - HandleRegionRequest(packet); - break; - //handle errors - default: - throw(std::runtime_error("Unknown SerialPacket::Type encountered")); - break; - } -} //------------------------- //Handle various network input //------------------------- void ServerApplication::HandleBroadcastRequest(SerialPacket packet) { - //send back the server's metadata - packet.meta.type = SerialPacket::Type::BROADCAST_RESPONSE; - //pack the data + packet.meta.type = SerialPacket::Type::BROADCAST_RESPONSE; + packet.serverInfo.networkVersion = NETWORK_VERSION; snprintf(packet.serverInfo.name, PACKET_STRING_SIZE, "%s", config["server.name"].c_str()); packet.serverInfo.playerCount = playerMap.size(); - packet.serverInfo.regionWidth = REGION_WIDTH; - packet.serverInfo.regionHeight = REGION_HEIGHT; - packet.serverInfo.regionDepth = REGION_DEPTH; //send the data char buffer[PACKET_BUFFER_SIZE]; @@ -195,13 +47,16 @@ void ServerApplication::HandleJoinRequest(SerialPacket packet) { newClient.address = packet.meta.srcAddress; clientMap[ClientEntry::uidCounter] = newClient; - //send the client their index - char buffer[PACKET_BUFFER_SIZE]; + //create the new player + //TODO: make the player + + //send the client their info packet.meta.type = SerialPacket::Type::JOIN_RESPONSE; packet.clientInfo.index = ClientEntry::uidCounter; - serialize(&packet, buffer); //bounce this packet + char buffer[PACKET_BUFFER_SIZE]; + serialize(&packet, buffer); network.Send(&newClient.address, buffer, PACKET_BUFFER_SIZE); //finished this routine @@ -224,7 +79,7 @@ void ServerApplication::HandleDisconnect(SerialPacket packet) { //TODO: can this use DeletePlayer() instead? //delete server and client side players - erase_if(playerMap, [&](std::pair it) -> bool { + erase_if(playerMap, [&](std::pair it) -> bool { //find the internal players to delete if (it.second.clientIndex == packet.clientInfo.index) { //send the delete player command to all clients @@ -323,7 +178,7 @@ void ServerApplication::HandlePlayerDelete(SerialPacket packet) { delPacket.meta.type = SerialPacket::Type::PLAYER_DELETE; //delete the specified playerEntry - erase_if(playerMap, [&](std::pair it) -> bool { + erase_if(playerMap, [&](std::pair it) -> bool { //find the specified PlayerEntry if (it.first == packet.playerInfo.playerIndex) { //send to all diff --git a/server/player_entry.cpp b/server/player_entry.cpp index 11cfdfc..3eb8777 100644 --- a/server/player_entry.cpp +++ b/server/player_entry.cpp @@ -21,4 +21,4 @@ */ #include "player_entry.hpp" -unsigned int PlayerEntry::uidCounter; +int PlayerEntry::uidCounter = 0; diff --git a/server/player_entry.hpp b/server/player_entry.hpp index 17dca99..70939e6 100644 --- a/server/player_entry.hpp +++ b/server/player_entry.hpp @@ -31,6 +31,7 @@ struct PlayerEntry { //metadata int clientIndex; + std::string player; std::string handle; std::string avatar; @@ -56,7 +57,7 @@ struct PlayerEntry { float luck; //uid - static unsigned int uidCounter; + static int uidCounter; }; #endif diff --git a/server/player_management.cpp b/server/player_management.cpp new file mode 100644 index 0000000..78ab785 --- /dev/null +++ b/server/player_management.cpp @@ -0,0 +1,46 @@ +/* Copyright: (c) Kayne Ruse 2013, 2014 + * + * This software is provided 'as-is', without any express or implied + * warranty. In no event will the authors be held liable for any damages + * arising from the use of this software. + * + * Permission is granted to anyone to use this software for any purpose, + * including commercial applications, and to alter it and redistribute it + * freely, subject to the following restrictions: + * + * 1. The origin of this software must not be misrepresented; you must not + * claim that you wrote the original software. If you use this software + * in a product, an acknowledgment in the product documentation would be + * appreciated but is not required. + * + * 2. Altered source versions must be plainly marked as such, and must not be + * misrepresented as being the original software. + * + * 3. This notice may not be removed or altered from any source + * distribution. +*/ +#include "server_application.hpp" + +//------------------------- +//player management +//------------------------- + +void ServerApplication::LoadPlayer() { + // +} + +void ServerApplication::UnloadPlayer() { + // +} + +void ServerApplication::CreatePlayer() { + // +} + +void ServerApplication::DeletePlayer() { + // +} + +void ServerApplication::SavePlayer() { + // +} diff --git a/server/server_application.hpp b/server/server_application.hpp index 2da5de1..c010dd2 100644 --- a/server/server_application.hpp +++ b/server/server_application.hpp @@ -23,7 +23,6 @@ #define SERVERAPPLICATION_HPP_ //server specific stuff -#include "server_utility.hpp" #include "client_entry.hpp" #include "player_entry.hpp" @@ -63,28 +62,33 @@ public: private: void HandlePacket(SerialPacket); - //high cohesion utility functions + //handle incoming traffic void HandleBroadcastRequest(SerialPacket); void HandleJoinRequest(SerialPacket); - void HandleDisconnect(SerialPacket); void HandleSynchronize(SerialPacket); + void HandleDisconnect(SerialPacket); void HandleShutdown(SerialPacket); - void HandlePlayerNew(SerialPacket); - void HandlePlayerDelete(SerialPacket); void HandlePlayerUpdate(SerialPacket); void HandleRegionRequest(SerialPacket); //TODO: a function that only sends to players in a certain proximity void PumpPacket(SerialPacket); + //player management + void LoadPlayer(); + void UnloadPlayer(); + void CreatePlayer(); + void DeletePlayer(); + void SavePlayer(); + //APIs UDPNetworkUtility network; sqlite3* database = nullptr; lua_State* luaState = nullptr; //server tables - std::map clientMap; - std::map playerMap; + std::map clientMap; + std::map playerMap; //maps //TODO: I need to handle multiple map objects diff --git a/server/server_internals.cpp b/server/server_internals.cpp new file mode 100644 index 0000000..21f8372 --- /dev/null +++ b/server/server_internals.cpp @@ -0,0 +1,166 @@ +/* Copyright: (c) Kayne Ruse 2014 + * + * This software is provided 'as-is', without any express or implied + * warranty. In no event will the authors be held liable for any damages + * arising from the use of this software. + * + * Permission is granted to anyone to use this software for any purpose, + * including commercial applications, and to alter it and redistribute it + * freely, subject to the following restrictions: + * + * 1. The origin of this software must not be misrepresented; you must not + * claim that you wrote the original software. If you use this software + * in a product, an acknowledgment in the product documentation would be + * appreciated but is not required. + * + * 2. Altered source versions must be plainly marked as such, and must not be + * misrepresented as being the original software. + * + * 3. This notice may not be removed or altered from any source + * distribution. +*/ +#include "server_application.hpp" + +#include "server_utility.hpp" + +#include +#include +#include + +//------------------------- +//Define the public members +//------------------------- + +void ServerApplication::Init(int argc, char** argv) { + //NOTE: I might need to rearrange the init process so that lua & SQL can interact with the map system as needed. + std::cout << "Beginning startup" << std::endl; + + //initial setup + config.Load("rsc\\config.cfg"); + + //Init SDL + if (SDL_Init(0)) { + throw(std::runtime_error("Failed to initialize SDL")); + } + std::cout << "Initialized SDL" << std::endl; + + //Init SDL_net + if (SDLNet_Init()) { + throw(std::runtime_error("Failed to initialize SDL_net")); + } + network.Open(config.Int("server.port"), PACKET_BUFFER_SIZE); + std::cout << "Initialized SDL_net" << std::endl; + + //Init SQL + int ret = sqlite3_open_v2(config["server.dbname"].c_str(), &database, SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE, nullptr); + if (ret != SQLITE_OK || !database) { + throw(std::runtime_error(std::string() + "Failed to initialize SQL: " + sqlite3_errmsg(database) )); + } + std::cout << "Initialized SQL" << std::endl; + + //setup the database + if (runSQLScript(database, config["dir.scripts"] + "setup_server.sql")) { + throw(std::runtime_error("Failed to initialize SQL's setup script")); + } + std::cout << "Initialized SQL's setup script" << std::endl; + + //lua + luaState = luaL_newstate(); + if (!luaState) { + throw(std::runtime_error("Failed to initialize lua")); + } + luaL_openlibs(luaState); + std::cout << "Initialized lua" << std::endl; + + //run the startup script + if (luaL_dofile(luaState, (config["dir.scripts"] + "setup_server.lua").c_str())) { + throw(std::runtime_error(std::string() + "Failed to initialize lua's setup script: " + lua_tostring(luaState, -1) )); + } + std::cout << "Initialized lua's setup script" << std::endl; + + //setup the map object + regionPager.GetAllocator()->SetLuaState(luaState); + regionPager.GetFormat()->SetLuaState(luaState); + //TODO: config parameter + regionPager.GetFormat()->SetSaveDir("save/mapname/"); + + std::cout << "Initialized the map system" << std::endl; + std::cout << "\tsizeof(SerialPacket): " << sizeof(SerialPacket) << std::endl; + std::cout << "\tPACKET_BUFFER_SIZE: " << PACKET_BUFFER_SIZE << std::endl; + + //finalize the startup + std::cout << "Startup completed successfully" << std::endl; + + //debugging + // +} + +void ServerApplication::Proc() { + SerialPacket packet; + while(running) { + //suck in the waiting packets & process them + while(network.Receive()) { + //get the packet + deserialize(&packet, network.GetInData()); + //cache the source address + packet.meta.srcAddress = network.GetInPacket()->address; + //we need to go deeper + HandlePacket(packet); + } + //give the computer a break + SDL_Delay(10); + } +} + +void ServerApplication::Quit() { + std::cout << "Shutting down" << std::endl; + + //save the server state + //TODO: save the existing players + + //empty the members + regionPager.UnloadAll(); + + //APIs + lua_close(luaState); + sqlite3_close_v2(database); + network.Close(); + SDLNet_Quit(); + SDL_Quit(); + + std::cout << "Shutdown finished" << std::endl; +} + +//------------------------- +//Define the uber switch +//------------------------- + +void ServerApplication::HandlePacket(SerialPacket packet) { + switch(packet.meta.type) { + case SerialPacket::Type::BROADCAST_REQUEST: + HandleBroadcastRequest(packet); + break; + case SerialPacket::Type::JOIN_REQUEST: + HandleJoinRequest(packet); + break; + case SerialPacket::Type::SYNCHRONIZE: + HandleSynchronize(packet); + break; + case SerialPacket::Type::DISCONNECT: + HandleDisconnect(packet); + break; + case SerialPacket::Type::SHUTDOWN: + HandleShutdown(packet); + break; + case SerialPacket::Type::PLAYER_UPDATE: + HandlePlayerUpdate(packet); + break; + case SerialPacket::Type::REGION_REQUEST: + HandleRegionRequest(packet); + break; + //handle errors + default: + throw(std::runtime_error("Unknown SerialPacket::Type encountered")); + break; + } +} From 01b50d5590ac60de07146d60c76740b537b01490 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Sat, 26 Apr 2014 02:31:48 +1000 Subject: [PATCH 2/2] I guess it was easier to compile the fragmented server than I thought --- server/networking.cpp | 150 ++++++++++++------------------------ server/server_internals.cpp | 2 + 2 files changed, 53 insertions(+), 99 deletions(-) diff --git a/server/networking.cpp b/server/networking.cpp index a981abf..c7afbc9 100644 --- a/server/networking.cpp +++ b/server/networking.cpp @@ -29,13 +29,13 @@ //------------------------- void ServerApplication::HandleBroadcastRequest(SerialPacket packet) { - //pack the data + //pack the server's data packet.meta.type = SerialPacket::Type::BROADCAST_RESPONSE; packet.serverInfo.networkVersion = NETWORK_VERSION; snprintf(packet.serverInfo.name, PACKET_STRING_SIZE, "%s", config["server.name"].c_str()); packet.serverInfo.playerCount = playerMap.size(); - //send the data + //bounce this packet char buffer[PACKET_BUFFER_SIZE]; serialize(&packet, buffer); network.Send(&packet.meta.srcAddress, buffer, PACKET_BUFFER_SIZE); @@ -47,57 +47,32 @@ void ServerApplication::HandleJoinRequest(SerialPacket packet) { newClient.address = packet.meta.srcAddress; clientMap[ClientEntry::uidCounter] = newClient; - //create the new player - //TODO: make the player + //register the new player + PlayerEntry newPlayer; + newPlayer.clientIndex = ClientEntry::uidCounter; + newPlayer.player = packet.clientInfo.player; + newPlayer.handle = packet.clientInfo.handle; + newPlayer.avatar = packet.clientInfo.avatar; + playerMap[PlayerEntry::uidCounter] = newPlayer; //send the client their info packet.meta.type = SerialPacket::Type::JOIN_RESPONSE; - packet.clientInfo.index = ClientEntry::uidCounter; + packet.clientInfo.clientIndex = ClientEntry::uidCounter; + packet.clientInfo.playerIndex = PlayerEntry::uidCounter; //bounce this packet char buffer[PACKET_BUFFER_SIZE]; serialize(&packet, buffer); network.Send(&newClient.address, buffer, PACKET_BUFFER_SIZE); + //TODO: finish the player's initialization + //finished this routine ClientEntry::uidCounter++; + PlayerEntry::uidCounter++; std::cout << "Connect, total: " << clientMap.size() << std::endl; } -void ServerApplication::HandleDisconnect(SerialPacket packet) { - //TODO: authenticate who is disconnecting/kicking - - //disconnect the specified client - char buffer[PACKET_BUFFER_SIZE]; - serialize(&packet, buffer); - network.Send(&clientMap[packet.clientInfo.index].address, buffer, PACKET_BUFFER_SIZE); - clientMap.erase(packet.clientInfo.index); - - //prep the delete packet - SerialPacket delPacket; - delPacket.meta.type = SerialPacket::Type::PLAYER_DELETE; - - //TODO: can this use DeletePlayer() instead? - //delete server and client side players - erase_if(playerMap, [&](std::pair it) -> bool { - //find the internal players to delete - if (it.second.clientIndex == packet.clientInfo.index) { - //send the delete player command to all clients - delPacket.playerInfo.playerIndex = it.first; - PumpPacket(delPacket); - - //delete this player object - return true; - } - - //don't delete this player object - return false; - }); - - //finished this routine - std::cout << "Disconnect, total: " << clientMap.size() << std::endl; -} - void ServerApplication::HandleSynchronize(SerialPacket packet) { //TODO: compensate for large distances @@ -115,82 +90,57 @@ void ServerApplication::HandleSynchronize(SerialPacket packet) { newPacket.playerInfo.position = it.second.position; newPacket.playerInfo.motion = it.second.motion; serialize(&newPacket, buffer); - network.Send(&clientMap[packet.clientInfo.index].address, buffer, PACKET_BUFFER_SIZE); + network.Send(&clientMap[packet.clientInfo.clientIndex].address, buffer, PACKET_BUFFER_SIZE); } } -void ServerApplication::HandleShutdown(SerialPacket packet) { - //end the server - running = false; +void ServerApplication::HandleDisconnect(SerialPacket packet) { + //TODO: authenticate who is disconnecting/kicking + //TODO: define the difference between unloading and deletng a player - //disconnect all clients - packet.meta.type = SerialPacket::Type::DISCONNECT; - PumpPacket(packet); - - //finished this routine - std::cout << "Shutdown signal accepted" << std::endl; -} - -void ServerApplication::HandlePlayerNew(SerialPacket packet) { - //register the new PlayerEntry - //NOTE: assigning each field one-by-one so adding or moving a field doesn't break this code - PlayerEntry newPlayer; - - //metadata - newPlayer.clientIndex = packet.playerInfo.clientIndex; - newPlayer.handle = packet.playerInfo.handle; - newPlayer.avatar = packet.playerInfo.avatar; - - //position - newPlayer.mapIndex = 0; - newPlayer.position = {0,0}; - newPlayer.motion = {0,0}; - newPlayer.bbox = {0, 0, 0, 0}; - - //TODO: Add the statistic creation code here - - //push this player - playerMap[PlayerEntry::uidCounter] = newPlayer; - - //send the client their info - packet.playerInfo.playerIndex = PlayerEntry::uidCounter; - packet.playerInfo.position = newPlayer.position; - packet.playerInfo.motion = newPlayer.motion; - - //actually send to everyone - PumpPacket(packet); - - //finish this routine - PlayerEntry::uidCounter++; -} - -//TODO: differentiate between delete and unload -void ServerApplication::HandlePlayerDelete(SerialPacket packet) { - //TODO: authenticate who is deleting this player - if (playerMap.find(packet.playerInfo.playerIndex) == playerMap.end()) { - throw(std::runtime_error("Cannot delete a non-existant player")); - } - - //TODO: remove the deleted player from the database? + //disconnect the specified client + char buffer[PACKET_BUFFER_SIZE]; + serialize(&packet, buffer); + network.Send(&clientMap[packet.clientInfo.clientIndex].address, buffer, PACKET_BUFFER_SIZE); + clientMap.erase(packet.clientInfo.clientIndex); //prep the delete packet SerialPacket delPacket; delPacket.meta.type = SerialPacket::Type::PLAYER_DELETE; - //delete the specified playerEntry + //delete server and client side players erase_if(playerMap, [&](std::pair it) -> bool { - //find the specified PlayerEntry - if (it.first == packet.playerInfo.playerIndex) { - //send to all + //find the internal players to delete + if (it.second.clientIndex == packet.clientInfo.clientIndex) { + //send the delete player command to all clients delPacket.playerInfo.playerIndex = it.first; PumpPacket(delPacket); - //delete this player + //delete this player object return true; } - //skip this player + + //don't delete this player object return false; }); + + //finished this routine + std::cout << "Disconnect, total: " << clientMap.size() << std::endl; +} + +void ServerApplication::HandleShutdown(SerialPacket packet) { + //TODO: authenticate who is shitting the server down + + //end the server + running = false; + + //disconnect all clients + packet.meta.type = SerialPacket::Type::DISCONNECT; + packet.clientInfo.clientIndex = -1; + PumpPacket(packet); + + //finished this routine + std::cout << "Shutdown signal accepted" << std::endl; } void ServerApplication::HandlePlayerUpdate(SerialPacket packet) { @@ -206,9 +156,11 @@ void ServerApplication::HandlePlayerUpdate(SerialPacket packet) { } void ServerApplication::HandleRegionRequest(SerialPacket packet) { - char buffer[PACKET_BUFFER_SIZE]; packet.meta.type = SerialPacket::Type::REGION_CONTENT; packet.regionInfo.region = regionPager.GetRegion(packet.regionInfo.x, packet.regionInfo.y); + + //send the content + char buffer[PACKET_BUFFER_SIZE]; serialize(&packet, buffer); network.Send(&packet.meta.srcAddress, buffer, PACKET_BUFFER_SIZE); } diff --git a/server/server_internals.cpp b/server/server_internals.cpp index 21f8372..e1a9cb9 100644 --- a/server/server_internals.cpp +++ b/server/server_internals.cpp @@ -107,6 +107,8 @@ void ServerApplication::Proc() { //we need to go deeper HandlePacket(packet); } + //update the internals + //TODO: update the internals i.e. player positions //give the computer a break SDL_Delay(10); }