Removed a lot of rubbish from the server

This commit is contained in:
Kayne Ruse
2013-11-02 19:00:08 +11:00
parent 2bd8adaf69
commit 54cd26b76f
17 changed files with 25 additions and 632 deletions
-25
View File
@@ -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;
-44
View File
@@ -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 <list>
class AccountManager {
private:
AccountManager() = default;
~AccountManager() = default;
static AccountManager instance;
public:
static AccountManager* GetInstance() { return &instance; }
private:
struct AccountEntry {
int index;
};
std::list<AccountEntry> list;
};
#endif
-52
View File
@@ -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 <map>
#include <string>
//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
-42
View File
@@ -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() {
//
}
-42
View File
@@ -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
-114
View File
@@ -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 <sstream>
#include <stdexcept>
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;
}
-49
View File
@@ -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 <deque>
#include <string>
//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<std::string> input;
std::deque<std::string> output;
SDL_mutex* inLock = nullptr;
SDL_mutex* outLock = nullptr;
};
#endif
+4 -3
View File
@@ -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;
-25
View File
@@ -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;
-44
View File
@@ -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 <list>
class PlayerManager {
private:
PlayerManager() = default;
~PlayerManager() = default;
static PlayerManager instance;
public:
static PlayerManager* GetInstance() { return &instance; }
private:
struct PlayerEntry {
int index;
};
std::list<PlayerEntry> list;
};
#endif
-42
View File
@@ -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 <iostream>
RoomManager RoomManager::instance;
int roomThread(void* ptr) {
std::cout << "Opening room" << std::endl;
try {
reinterpret_cast<BaseRoom*>(ptr)->Init();
reinterpret_cast<BaseRoom*>(ptr)->Loop();
reinterpret_cast<BaseRoom*>(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;
}
-54
View File
@@ -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 <list>
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<RoomHandle> rooms;
};
#endif
+3 -4
View File
@@ -29,14 +29,13 @@
#include <fstream>
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];
+1 -5
View File
@@ -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();
-42
View File
@@ -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() {
//
}
-43
View File
@@ -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