From 7fe71c60d052286d90f1392ed4710eb55211ccb6 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Sun, 13 Apr 2014 03:37:21 +1000 Subject: [PATCH] This will not build; working on refactoring --- server/client.cpp | 29 +++++++++++++++++++++++++++++ server/client.hpp | 33 +++++++++++++++++++++++++++++++++ server/player_entity.hpp | 19 ++++++++++++++++++- server/server_application.cpp | 14 ++++++++------ server/server_application.hpp | 23 ++++------------------- 5 files changed, 92 insertions(+), 26 deletions(-) create mode 100644 server/client.cpp create mode 100644 server/client.hpp diff --git a/server/client.cpp b/server/client.cpp new file mode 100644 index 0000000..9ca11b4 --- /dev/null +++ b/server/client.cpp @@ -0,0 +1,29 @@ +/* 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 "client.hpp" + +#include + +//This is explicitly a POD +static_assert(std::is_pod::value, "Client is not a POD"); + +unsigned int Client::uidCounter; \ No newline at end of file diff --git a/server/client.hpp b/server/client.hpp new file mode 100644 index 0000000..658030c --- /dev/null +++ b/server/client.hpp @@ -0,0 +1,33 @@ +/* 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. +*/ +#ifndef CLIENT_HPP_ +#define CLIENT_HPP_ + +#include "SDL/SDL_net.h" + +struct Client { + IPaddress address; + unsigned int uid; + static unsigned int uidCounter; +}; + +#endif diff --git a/server/player_entity.hpp b/server/player_entity.hpp index b60227e..675f66f 100644 --- a/server/player_entity.hpp +++ b/server/player_entity.hpp @@ -22,8 +22,25 @@ #ifndef PLAYERENTITY_HPP_ #define PLAYERENTITY_HPP_ +#include + struct PlayerEntity { - //TODO: stuff + int clientIndex; + std::string handle; + std::string avatar; + int level; + int exp; + int maxHP; + int health; + int maxMP; + int mana; + int attack; + int defence; + int intelligence; + int resistance; + float accuracy; + float evasion; + float luck; }; #endif diff --git a/server/server_application.cpp b/server/server_application.cpp index 25a53bc..a794c3e 100644 --- a/server/server_application.cpp +++ b/server/server_application.cpp @@ -54,6 +54,7 @@ void ServerApplication::Init(int argc, char** argv) { int ret = 0; //initial setup + Client::uidCounter = 0; Entity::uidCounter = 0; config.Load("rsc\\config.cfg"); @@ -103,6 +104,7 @@ void ServerApplication::Init(int argc, char** argv) { mapPager.SetRegionDepth(REGION_DEPTH); mapPager.GetGenerator()->SetLuaState(luaState); mapPager.GetFormat()->SetLuaState(luaState); + //TODO: config parameter mapPager.GetFormat()->SetSaveDir("save/mapname/"); //TODO: pass args to the generator & format as needed //NOTE: I might need to rearrange the init process so that lua & SQL can interact @@ -208,21 +210,21 @@ void ServerApplication::HandleBroadcastRequest(NetworkPacket packet) { void ServerApplication::HandleJoinRequest(NetworkPacket packet) { //register the new client - ClientEntry c; + Client c; c.address = packet.meta.srcAddress; - clientMap[clientCounter] = c; + clientMap[Client::uidCounter] = c; //send the client their info char buffer[PACKET_BUFFER_SIZE]; packet.meta.type = NetworkPacket::Type::JOIN_RESPONSE; - packet.clientInfo.index = clientCounter; + packet.clientInfo.index = Client::uidCounter; serialize(&packet, buffer); - network.Send(&clientMap[clientCounter].address, buffer, PACKET_BUFFER_SIZE); + network.Send(&clientMap[Client::uidCounter].address, buffer, PACKET_BUFFER_SIZE); - //finished this routine - clientCounter++; + //finished this routine+ + Client::uidCounter++; cout << "Connect, total: " << clientMap.size() << endl; } diff --git a/server/server_application.hpp b/server/server_application.hpp index 7c30067..8b81c61 100644 --- a/server/server_application.hpp +++ b/server/server_application.hpp @@ -23,6 +23,7 @@ #define SERVERAPPLICATION_HPP_ //server specific stuff +#include "client.hpp" #include "entity.hpp" #include "player_entity.hpp" @@ -49,19 +50,6 @@ #include #include -struct ClientEntry { - IPaddress address; -}; - -struct PlayerEntry { - int clientIndex; - int mapIndex; - std::string handle; - std::string avatar; - Vector2 position; - Vector2 motion; -}; - //The main application class class ServerApplication { public: @@ -89,6 +77,9 @@ private: void PumpPacket(NetworkPacket); + //APIs + std::map clientMap; + //maps RegionPager mapPager; @@ -104,12 +95,6 @@ private: //misc bool running = true; ConfigUtility config; - - std::map clientMap; - std::map playerMap; - - int clientCounter = 0; - int playerCounter = 0; }; #endif