From 54cd26b76f1f4dc7e0469510493fb7af90f76471 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Sat, 2 Nov 2013 19:00:08 +1100 Subject: [PATCH] Removed a lot of rubbish from the server --- common/network/network_packet.hpp | 19 ++++- server/account_manager.cpp | 25 ------- server/account_manager.hpp | 44 ------------ server/base_room.hpp | 52 -------------- server/combat_room.cpp | 42 ----------- server/combat_room.hpp | 42 ----------- server/mail_box.cpp | 114 ------------------------------ server/mail_box.hpp | 49 ------------- server/main.cpp | 7 +- server/player_manager.cpp | 25 ------- server/player_manager.hpp | 44 ------------ server/room_manager.cpp | 42 ----------- server/room_manager.hpp | 54 -------------- server/server_application.cpp | 7 +- server/server_application.hpp | 6 +- server/world_room.cpp | 42 ----------- server/world_room.hpp | 43 ----------- 17 files changed, 25 insertions(+), 632 deletions(-) delete mode 100644 server/account_manager.cpp delete mode 100644 server/account_manager.hpp delete mode 100644 server/base_room.hpp delete mode 100644 server/combat_room.cpp delete mode 100644 server/combat_room.hpp delete mode 100644 server/mail_box.cpp delete mode 100644 server/mail_box.hpp delete mode 100644 server/player_manager.cpp delete mode 100644 server/player_manager.hpp delete mode 100644 server/room_manager.cpp delete mode 100644 server/room_manager.hpp delete mode 100644 server/world_room.cpp delete mode 100644 server/world_room.hpp diff --git a/common/network/network_packet.hpp b/common/network/network_packet.hpp index a78934f..bf4ad13 100644 --- a/common/network/network_packet.hpp +++ b/common/network/network_packet.hpp @@ -22,11 +22,14 @@ #ifndef NETWORKPACKET_HPP_ #define NETWORKPACKET_HPP_ -//#define PACKET_STRING_SIZE 100 +#include "SDL/SDL_net.h" + +#define PACKET_STRING_SIZE 100 #pragma pack(push, 0) union NetworkPacket { + //types of packets enum class Type { //default: there is something wrong NONE = 0, @@ -35,7 +38,7 @@ union NetworkPacket { PING = 1, PONG = 2, - //bounce information between the client & server + //Searching for a server to join BROADCAST_REQUEST = 3, BROADCAST_RESPONSE = 4, @@ -48,11 +51,23 @@ union NetworkPacket { //mass update SYNCHRONIZE = 8, + + //Player movement, etc. }; + //metadata on the packet itself struct Metadata { Type type; + IPaddress srcAddress; }meta; + + //information about the server + struct ServerInformation { + Metadata meta; + //TODO: version info + char name[PACKET_STRING_SIZE]; + //TODO: player count + }serverInfo; }; #pragma pack(pop) diff --git a/server/account_manager.cpp b/server/account_manager.cpp deleted file mode 100644 index ec20cc0..0000000 --- a/server/account_manager.cpp +++ /dev/null @@ -1,25 +0,0 @@ -/* Copyright: (c) Kayne Ruse 2013 - * - * 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 "account_manager.hpp" - -AccountManager AccountManager::instance; - diff --git a/server/account_manager.hpp b/server/account_manager.hpp deleted file mode 100644 index 298b8fa..0000000 --- a/server/account_manager.hpp +++ /dev/null @@ -1,44 +0,0 @@ -/* Copyright: (c) Kayne Ruse 2013 - * - * 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 ACCOUNTMANAGER_HPP_ -#define ACCOUNTMANAGER_HPP_ - -#include - -class AccountManager { -private: - AccountManager() = default; - ~AccountManager() = default; - static AccountManager instance; - -public: - static AccountManager* GetInstance() { return &instance; } - -private: - struct AccountEntry { - int index; - }; - - std::list list; -}; - -#endif diff --git a/server/base_room.hpp b/server/base_room.hpp deleted file mode 100644 index 58818b3..0000000 --- a/server/base_room.hpp +++ /dev/null @@ -1,52 +0,0 @@ -/* Copyright: (c) Kayne Ruse 2013 - * - * 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 BASEROOM_HPP_ -#define BASEROOM_HPP_ - -#include "mail_box.hpp" - -#include -#include - -//The abstract base class for all rooms -class BaseRoom { -public: - BaseRoom() = default; - ~BaseRoom() = default; - - virtual void Init() = 0; - virtual void Loop() = 0; - virtual void Quit() = 0; - - bool SetRunning(bool b) { return running = b; } - bool GetRunning() const { return running; } - - MailBox* GetMailBox() { return& mailBox; } - -protected: - MailBox mailBox; - -private: - bool running = true; -}; - -#endif diff --git a/server/combat_room.cpp b/server/combat_room.cpp deleted file mode 100644 index c4901e8..0000000 --- a/server/combat_room.cpp +++ /dev/null @@ -1,42 +0,0 @@ -/* Copyright: (c) Kayne Ruse 2013 - * - * 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 "combat_room.hpp" - -CombatRoom::CombatRoom() { - // -} - -CombatRoom::~CombatRoom() { - // -} - -void CombatRoom::Init() { - // -} - -void CombatRoom::Loop() { - // -} - -void CombatRoom::Quit() { - // -} diff --git a/server/combat_room.hpp b/server/combat_room.hpp deleted file mode 100644 index 03858df..0000000 --- a/server/combat_room.hpp +++ /dev/null @@ -1,42 +0,0 @@ -/* Copyright: (c) Kayne Ruse 2013 - * - * 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 COMBATROOM_HPP_ -#define COMBATROOM_HPP_ - -#include "base_room.hpp" - -class CombatRoom : public BaseRoom { -public: - CombatRoom(); - ~CombatRoom(); - - void Init(); - void Loop(); - void Quit(); - -private: - //parent room index - //combatants - //monsters -}; - -#endif \ No newline at end of file diff --git a/server/mail_box.cpp b/server/mail_box.cpp deleted file mode 100644 index 70d1386..0000000 --- a/server/mail_box.cpp +++ /dev/null @@ -1,114 +0,0 @@ -/* Copyright: (c) Kayne Ruse 2013 - * - * 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 "mail_box.hpp" - -#include -#include - -MailBox::MailBox() { - if (!(inLock = SDL_CreateMutex())) { - std::ostringstream os; - os << "Failed to create a MailBox mutex; "; - os << SDL_GetError(); - throw(std::runtime_error(os.str())); - } - if (!(outLock = SDL_CreateMutex())) { - SDL_DestroyMutex(inLock); - std::ostringstream os; - os << "Failed to create a MailBox mutex; "; - os << SDL_GetError(); - throw(std::runtime_error(os.str())); - } -} - -MailBox::~MailBox() { - SDL_DestroyMutex(inLock); - SDL_DestroyMutex(outLock); -} - -std::string MailBox::PushIn(std::string msg) { - SDL_LockMutex(inLock); - input.push_back(msg); - SDL_UnlockMutex(inLock); - return msg; -} - -std::string MailBox::PeekIn() { - std::string ret; - SDL_LockMutex(inLock); - if (input.size()) { - ret = input[0]; - } - else { - ret = ""; - } - SDL_UnlockMutex(inLock); - return ret; -} - -std::string MailBox::PopIn() { - std::string ret; - SDL_LockMutex(inLock); - if (input.size()) { - ret = input[0]; - input.pop_front(); - } - else { - ret = ""; - } - SDL_UnlockMutex(inLock); - return ret; -} - -std::string MailBox::PushOut(std::string msg) { - SDL_LockMutex(outLock); - output.push_back(msg); - SDL_UnlockMutex(outLock); - return msg; -} - -std::string MailBox::PeekOut() { - std::string ret; - SDL_LockMutex(outLock); - if (output.size()) { - ret = output[0]; - } - else { - ret = ""; - } - SDL_UnlockMutex(outLock); - return ret; -} - -std::string MailBox::PopOut() { - std::string ret; - SDL_LockMutex(outLock); - if (output.size()) { - ret = output[0]; - output.pop_front(); - } - else { - ret = ""; - } - SDL_UnlockMutex(outLock); - return ret; -} diff --git a/server/mail_box.hpp b/server/mail_box.hpp deleted file mode 100644 index 491101c..0000000 --- a/server/mail_box.hpp +++ /dev/null @@ -1,49 +0,0 @@ -/* Copyright: (c) Kayne Ruse 2013 - * - * 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 MAILBOX_HPP_ -#define MAILBOX_HPP_ - -#include "SDL/SDL_thread.h" - -#include -#include - -//Thread safe messaging system -class MailBox { -public: - MailBox(); - ~MailBox(); - - std::string PushIn(std::string); - std::string PeekIn(); - std::string PopIn(); - std::string PushOut(std::string); - std::string PeekOut(); - std::string PopOut(); -private: - std::deque input; - std::deque output; - SDL_mutex* inLock = nullptr; - SDL_mutex* outLock = nullptr; -}; - -#endif diff --git a/server/main.cpp b/server/main.cpp index 595f2a0..c9de322 100644 --- a/server/main.cpp +++ b/server/main.cpp @@ -31,9 +31,10 @@ using namespace std; int main(int argc, char** argv) { cout << "Beginning server" << endl; try { - ServerApplication::GetInstance()->Init(argc, argv); - ServerApplication::GetInstance()->Loop(); - ServerApplication::GetInstance()->Quit(); + ServerApplication app; + app.Init(argc, argv); + app.Loop(); + app.Quit(); } catch(exception& e) { cerr << "Fatal error: " << e.what() << endl; diff --git a/server/player_manager.cpp b/server/player_manager.cpp deleted file mode 100644 index 9ac6e2e..0000000 --- a/server/player_manager.cpp +++ /dev/null @@ -1,25 +0,0 @@ -/* Copyright: (c) Kayne Ruse 2013 - * - * 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 "player_manager.hpp" - -PlayerManager PlayerManager::instance; - diff --git a/server/player_manager.hpp b/server/player_manager.hpp deleted file mode 100644 index ff28a18..0000000 --- a/server/player_manager.hpp +++ /dev/null @@ -1,44 +0,0 @@ -/* Copyright: (c) Kayne Ruse 2013 - * - * 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 PLAYERMANAGER_HPP_ -#define PLAYERMANAGER_HPP_ - -#include - -class PlayerManager { -private: - PlayerManager() = default; - ~PlayerManager() = default; - static PlayerManager instance; - -public: - static PlayerManager* GetInstance() { return &instance; } - -private: - struct PlayerEntry { - int index; - }; - - std::list list; -}; - -#endif diff --git a/server/room_manager.cpp b/server/room_manager.cpp deleted file mode 100644 index 613345a..0000000 --- a/server/room_manager.cpp +++ /dev/null @@ -1,42 +0,0 @@ -/* Copyright: (c) Kayne Ruse 2013 - * - * 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 "room_manager.hpp" - -#include - -RoomManager RoomManager::instance; - -int roomThread(void* ptr) { - std::cout << "Opening room" << std::endl; - try { - reinterpret_cast(ptr)->Init(); - reinterpret_cast(ptr)->Loop(); - reinterpret_cast(ptr)->Quit(); - } - catch(std::exception& e) { - std::cerr << "Fatal room error: " << e.what() << std::endl; - return 1; - } - std::cout << "Closing room" << std::endl; - return 0; -} - diff --git a/server/room_manager.hpp b/server/room_manager.hpp deleted file mode 100644 index 9edd9d9..0000000 --- a/server/room_manager.hpp +++ /dev/null @@ -1,54 +0,0 @@ -/* Copyright: (c) Kayne Ruse 2013 - * - * 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 ROOMMANAGER_HPP_ -#define ROOMMANAGER_HPP_ - -#include "base_room.hpp" - -#include "SDL/SDL_thread.h" - -#include - -class RoomManager { -private: - RoomManager() = default; - ~RoomManager() = default; - static RoomManager instance; - -public: - static RoomManager* GetInstance() { return &instance; } - - //open room - //close room - - //get room - //set? - -private: - struct RoomHandle { - SDL_Thread* thread = nullptr; - BaseRoom* room = nullptr; - }; - std::list rooms; -}; - -#endif diff --git a/server/server_application.cpp b/server/server_application.cpp index 92fa92b..f10ed5c 100644 --- a/server/server_application.cpp +++ b/server/server_application.cpp @@ -29,14 +29,13 @@ #include int ClientEntry::indexCounter = 0; -ServerApplication ServerApplication::instance; ServerApplication::ServerApplication() { - //TODO + // } ServerApplication::~ServerApplication() { - //TODO + // } void ServerApplication::Init(int argc, char** argv) { @@ -65,7 +64,7 @@ void ServerApplication::Init(int argc, char** argv) { else { std::cout << "SDL_net initialized" << std::endl; } - networkUtil.Open(8895, 1024); + networkUtil.Open(21795, 1024); //Init SQL std::string dbname = (argc > 1) ? argv[1] : argv[0]; diff --git a/server/server_application.hpp b/server/server_application.hpp index d89811f..1c7b67e 100644 --- a/server/server_application.hpp +++ b/server/server_application.hpp @@ -38,13 +38,9 @@ struct ClientEntry { //The main application class class ServerApplication { -private: +public: ServerApplication(); ~ServerApplication(); - static ServerApplication instance; - -public: - static ServerApplication* GetInstance() { return &instance; } void Init(int argc, char** argv); void Loop(); diff --git a/server/world_room.cpp b/server/world_room.cpp deleted file mode 100644 index 6ad7119..0000000 --- a/server/world_room.cpp +++ /dev/null @@ -1,42 +0,0 @@ -/* Copyright: (c) Kayne Ruse 2013 - * - * 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 "world_room.hpp" - -WorldRoom::WorldRoom() { - // -} - -WorldRoom::~WorldRoom() { - // -} - -void WorldRoom::Init() { - // -} - -void WorldRoom::Loop() { - // -} - -void WorldRoom::Quit() { - // -} diff --git a/server/world_room.hpp b/server/world_room.hpp deleted file mode 100644 index 70197d2..0000000 --- a/server/world_room.hpp +++ /dev/null @@ -1,43 +0,0 @@ -/* Copyright: (c) Kayne Ruse 2013 - * - * 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 WORLDROOM_HPP_ -#define WORLDROOM_HPP_ - -#include "base_room.hpp" - -class WorldRoom : public BaseRoom { -public: - WorldRoom(); - ~WorldRoom(); - - void Init(); - void Loop(); - void Quit(); - -private: - //collision map - //map metadata - //player list - //combat portals -}; - -#endif \ No newline at end of file