diff --git a/docs/client.txt b/docs/client.txt new file mode 100644 index 0000000..e69de29 diff --git a/docs/server.txt b/docs/server.txt new file mode 100644 index 0000000..0cd66f0 --- /dev/null +++ b/docs/server.txt @@ -0,0 +1,24 @@ +init and quit are self explanatory. + +the main server loop will have three main phases: + +* receive messages from the clients +* update the server-side game world +* send all updates out to the clients + +As far as possible multithreading goes, each of these main phases can run several operations at once; I need to actually *learn* multithreading, what better excuse? + +------------------------- + +Messages from the clients refers to anything from player movement to text communications to new player connections. Anything that has changed is marked as such, so that it can be sent out again later. + +Updating the game world involes updating players or monsters already in motion, loot drop count downs, entity AI and anything else that needs to happen each frame. + +Finally, updating the clients is important: anything that has been marked as "changed" needs to be resent to the players. Any new players that have joined need to receive everything as far as client-side data goes. + +If a player is in motion, the server will update their internal position, but this *won't* be marked as changed; only the beginning and end (and changes of direction) of a player's movement will be considered changes. Each client will preform their own updates based on the last known information. The server-side updates are required for new connections. + +------------------------- + +This outline is only the most basic example of the server's operation possible, but it's a good start. I'll need to consider things such as server-specific map data, scripts and other resources being sent to new connections. + diff --git a/server/server.cpp b/server/server.cpp index 2e1ca0e..0142057 100644 --- a/server/server.cpp +++ b/server/server.cpp @@ -4,11 +4,12 @@ #include "SDL_net/SDL_net.h" #include +#include using namespace std; Server::Server() { - // + running = true; } Server::~Server() { @@ -19,15 +20,32 @@ void Server::Init() { if (SDLNet_Init()) { throw(runtime_error("Failed to init SDL_net")); } + netMgr.Init(100); } void Server::Proc() { - bool running = true; while(running) { - // + HandleInput(); + UpdateWorld(); + HandleOutput(); } } void Server::Quit() { + netMgr.Quit(); SDLNet_Quit(); } + +void Server::HandleInput() { + //accept new connections + //accept updates from the clients +} + +void Server::UpdateWorld() { + //update internals +} + +void Server::HandleOutput() { + //send all information to new connections + //selective updates to existing connectons +} diff --git a/server/server.hpp b/server/server.hpp index e9a7bc2..9682950 100644 --- a/server/server.hpp +++ b/server/server.hpp @@ -1,6 +1,8 @@ #ifndef SERVER_HPP_ #define SERVER_HPP_ +#include "tcp_network_manager.hpp" + class Server { public: Server(); @@ -9,7 +11,13 @@ public: void Init(); void Proc(); void Quit(); + + void HandleInput(); + void UpdateWorld(); + void HandleOutput(); private: + bool running; + TCPNetworkManager netMgr; }; #endif diff --git a/server/tcp_network_manager.cpp b/server/tcp_network_manager.cpp index 8b94885..326bb7b 100644 --- a/server/tcp_network_manager.cpp +++ b/server/tcp_network_manager.cpp @@ -1,2 +1,53 @@ #include "tcp_network_manager.hpp" +TCPNetworkManager::TCPNetworkManager() { + maxConnections = currentConnections = 0; +} + +TCPNetworkManager::~TCPNetworkManager() { + // +} + +void TCPNetworkManager::Init(int maxConnections) { + // +} + +void TCPNetworkManager::Quit() { + // +} + +int TCPNetworkManager::AcceptConnection() { + // +} + +int TCPNetworkManager::CheckSockets() { + // +} + +int TCPNetworkManager::Send(int index, const void* data, int len) { + // +} + +int TCPNetworkManager::SendAll(const void* data, int len) { + // +} + +int TCPNetworkManager::OpenSocket(const char* host, int port) { + // +} + +TCPsocket TCPNetworkManager::GetSocket(int index) { + // +} + +int TCPNetworkManager::CloseSocket(int index) { + // +} + +int TCPNetworkManager::GetMaxConnections() { + // +} + +int TCPNetworkManager::GetCurrentConnections() { + // +} diff --git a/server/tcp_network_manager.hpp b/server/tcp_network_manager.hpp index 9202554..0010df7 100644 --- a/server/tcp_network_manager.hpp +++ b/server/tcp_network_manager.hpp @@ -11,7 +11,7 @@ public: void Init(int maxConnections); void Quit(); - int AcceptConnections(); + int AcceptConnection(); int CheckSockets(); int Send(int index, const void* data, int len);