From f584dd140bd666b460999bc2e359e508585450eb Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Thu, 23 Oct 2014 23:50:49 +1100 Subject: [PATCH 01/73] Began work on expanding the network protocols --- .../network/packet_types/character_packet.hpp | 1 + common/network/serial_packet.hpp | 2 +- common/network/serial_packet_type.hpp | 39 ++++++++++++------- rsc/scripts/setup_server.sql | 2 + server/accounts/account_data.hpp | 1 + 5 files changed, 30 insertions(+), 15 deletions(-) diff --git a/common/network/packet_types/character_packet.hpp b/common/network/packet_types/character_packet.hpp index 5d94c16..e743589 100644 --- a/common/network/packet_types/character_packet.hpp +++ b/common/network/packet_types/character_packet.hpp @@ -35,6 +35,7 @@ struct CharacterPacket : SerialPacketBase { //the owner int accountIndex; + //TODO: Authentication token? //location int roomIndex; diff --git a/common/network/serial_packet.hpp b/common/network/serial_packet.hpp index 7dd6c81..5d9d008 100644 --- a/common/network/serial_packet.hpp +++ b/common/network/serial_packet.hpp @@ -33,7 +33,7 @@ typedef SerialPacketBase SerialPacket; //DOCS: NETWORK_VERSION is used to discern compatible servers and clients -constexpr int NETWORK_VERSION = 20140909; +constexpr int NETWORK_VERSION = -1; union MaxPacket { CharacterPacket a; diff --git a/common/network/serial_packet_type.hpp b/common/network/serial_packet_type.hpp index 1c517a8..b93b51f 100644 --- a/common/network/serial_packet_type.hpp +++ b/common/network/serial_packet_type.hpp @@ -46,21 +46,19 @@ enum class SerialPacketType { //------------------------- //ClientPacket - // client index, account index, character index + // client index, account index, username //------------------------- //Connecting to a server as a client JOIN_REQUEST, JOIN_RESPONSE, - //client requests all information from the server - SYNCHRONIZE, - //disconnect from the server - DISCONNECT, + DISCONNECT_REQUEST, + DISCONNECT_FORCED, //shut down the server - SHUTDOWN, + SHUTDOWN_REQUEST, //------------------------- //RegionPacket @@ -73,20 +71,33 @@ enum class SerialPacketType { //------------------------- //CharacterPacket - // handle, avatar, character index, account index, - // room index, origin, motion + // character index, + // handle, avatar, + // account index (owner), + // room index, origin, motion, // statistics //------------------------- - //controlling characters - CHARACTER_NEW, - CHARACTER_DELETE, - CHARACTER_UPDATE, - - //authentication, character index => character stats + //all stats CHARACTER_STATS_REQUEST, CHARACTER_STATS_RESPONSE, + //character management + //NOTE: The server sends create & delete messages to the clients, but the clients... don't? + CHARACTER_CREATE + CHARACTER_DELETE + CHARACTER_LOAD + CHARACTER_UNLOAD + + //find out info from the server + CHARACTER_QUERY_EXISTS + CHARACTER_QUERY_LOCATION + + //set the info in the server + CHARACTER_SET_ROOM + CHARACTER_SET_ORIGIN + CHARACTER_SET_MOTION + //------------------------- //TextPacket // name, text diff --git a/rsc/scripts/setup_server.sql b/rsc/scripts/setup_server.sql index 80da6fe..e7e9c63 100644 --- a/rsc/scripts/setup_server.sql +++ b/rsc/scripts/setup_server.sql @@ -1,3 +1,5 @@ +--TODO: An archive table of all dead characters + CREATE TABLE IF NOT EXISTS Accounts ( uid INTEGER PRIMARY KEY AUTOINCREMENT, username varchar(100) UNIQUE, diff --git a/server/accounts/account_data.hpp b/server/accounts/account_data.hpp index d7fb022..6242add 100644 --- a/server/accounts/account_data.hpp +++ b/server/accounts/account_data.hpp @@ -49,6 +49,7 @@ private: std::string username; //TODO: password + //bit fields? bool blackListed = false; bool whiteListed = true; bool mod = false; From 8c78a5d26c6563d4207c245a640b1b5c62f1f4da Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Wed, 29 Oct 2014 23:34:36 +1100 Subject: [PATCH 02/73] Updated TODO.txt --- todo.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/todo.txt b/todo.txt index f2f38ec..3c637ec 100644 --- a/todo.txt +++ b/todo.txt @@ -3,6 +3,7 @@ TODO: SerialPacketType::CHARACTER_LOCATION, CHARACTER_MOVE, CHARACTER_TELEPORT, TODO: Fix shoddy movement TODO: Handle statistics server-side TODO: Periodic mass server saves +TODO: join vs login TODO: Remove the big "Shut Down" button TODO: Make a way for the server owner to control the server directly From 0735037f10d87c4eb2dbd9eefe28b26d7ddb281c Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Thu, 30 Oct 2014 00:21:55 +1100 Subject: [PATCH 03/73] Created ClientManager --- server/{ => clients}/client_data.cpp | 20 ++++++++ server/{ => clients}/client_data.hpp | 11 ++--- server/clients/client_manager.cpp | 68 ++++++++++++++++++++++++++++ server/clients/client_manager.hpp | 63 ++++++++++++++++++++++++++ server/clients/makefile | 37 +++++++++++++++ 5 files changed, 193 insertions(+), 6 deletions(-) rename server/{ => clients}/client_data.cpp (77%) rename server/{ => clients}/client_data.hpp (82%) create mode 100644 server/clients/client_manager.cpp create mode 100644 server/clients/client_manager.hpp create mode 100644 server/clients/makefile diff --git a/server/client_data.cpp b/server/clients/client_data.cpp similarity index 77% rename from server/client_data.cpp rename to server/clients/client_data.cpp index 56eddc6..b2dd4fc 100644 --- a/server/client_data.cpp +++ b/server/clients/client_data.cpp @@ -21,6 +21,26 @@ */ #include "client_data.hpp" +ClientData::ClientData(IPaddress add) { + address = add; +} + +IPaddress ClientData::SetAddress(IPaddress add) { + return address = add; +} + +IPaddress ClientData::GetAddress() { + return address; +} + +ClientData::Clock::time_point ClientData::GetLastBeat() { + return lastBeat; +} + +int ClientData::GetAttempts() { + return attemptedBeats; +} + int ClientData::IncrementAttempts() { lastBeat = Clock::now(); return attemptedBeats++; diff --git a/server/client_data.hpp b/server/clients/client_data.hpp similarity index 82% rename from server/client_data.hpp rename to server/clients/client_data.hpp index 0af85ed..29b3f78 100644 --- a/server/client_data.hpp +++ b/server/clients/client_data.hpp @@ -26,21 +26,20 @@ #include -//TODO: ClientManager? class ClientData { public: typedef std::chrono::steady_clock Clock; ClientData() = default; - ClientData(IPaddress add): address(add) {} + ClientData(IPaddress add); ~ClientData() = default; - IPaddress SetAddress(IPaddress add) { return address = add; } - IPaddress GetAddress() { return address; } + IPaddress SetAddress(IPaddress add); + IPaddress GetAddress(); - Clock::time_point GetLastBeat() { return lastBeat; } + Clock::time_point GetLastBeat(); - int GetAttempts() { return attemptedBeats; } + int GetAttempts(); int IncrementAttempts(); int ResetAttempts(); diff --git a/server/clients/client_manager.cpp b/server/clients/client_manager.cpp new file mode 100644 index 0000000..e61090d --- /dev/null +++ b/server/clients/client_manager.cpp @@ -0,0 +1,68 @@ +/* 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_manager.hpp" + +//TODO: client_manager.cpp + +int ClientManager::Create(IPaddress add) { + // +} + +int ClientManager::Load(IPaddress add) { + // +} + +int ClientManager::Save(int uid) { + // +} + +void ClientManager::Unload(int uid) { + // +} + +void ClientManager::Delete(int uid) { + // +} + +void ClientManager::UnloadAll() { + // +} + +void ClientManager::UnloadIf(std::function)> fn) { + // +} + +ClientData* ClientManager::Get(int uid) { + // +} + +int ClientManager::GetLoadedCount() { + // +} + +int ClientManager::GetTotalCount() { + // +} + +std::map* ClientManager::GetContainer() { + // +} \ No newline at end of file diff --git a/server/clients/client_manager.hpp b/server/clients/client_manager.hpp new file mode 100644 index 0000000..d5e7cec --- /dev/null +++ b/server/clients/client_manager.hpp @@ -0,0 +1,63 @@ +/* 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 CLIENTMANAGER_HPP_ +#define CLIENTMANAGER_HPP_ + +#include "client_data.hpp" +#include "manager_interface.hpp" +#include "singleton.hpp" + +#include "SDL/SDL_net.h" + +#include + +class ClientManager: + Singleton, + ManagerInterface +{ +public: + //common public methods + int Create(IPaddress); + int Load(IPaddress); + int Save(int uid); + void Unload(int uid); + void Delete(int uid); + + void UnloadAll(); + void UnloadIf(std::function)> fn); + + //accessors & mutators + ClientData* Get(int uid); + int GetLoadedCount(); + int GetTotalCount(); + std::map* GetContainer(); + +private: + friend Singleton; + + ClientManager() = default; + ~ClientManager() = default; + + int counter = 0; +}; + +#endif \ No newline at end of file diff --git a/server/clients/makefile b/server/clients/makefile new file mode 100644 index 0000000..2a5c671 --- /dev/null +++ b/server/clients/makefile @@ -0,0 +1,37 @@ +#config +INCLUDES+=. ../server_utilities ../../common/utilities +LIBS+= +CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES)) + +#source +CXXSRC=$(wildcard *.cpp) + +#objects +OBJDIR=obj +OBJ+=$(addprefix $(OBJDIR)/,$(CXXSRC:.cpp=.o)) + +#output +OUTDIR=.. +OUT=$(addprefix $(OUTDIR)/,server.a) + +#targets +all: $(OBJ) $(OUT) + ar -crs $(OUT) $(OBJ) + +$(OBJ): | $(OBJDIR) + +$(OUT): | $(OUTDIR) + +$(OBJDIR): + mkdir $(OBJDIR) + +$(OUTDIR): + mkdir $(OUTDIR) + +$(OBJDIR)/%.o: %.cpp + $(CXX) $(CXXFLAGS) -c -o $@ $< + +clean: + $(RM) *.o *.a *.exe + +rebuild: clean all From 7da5de619b3ef1ad8dec0326abd1a0a37a78cafe Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Thu, 30 Oct 2014 00:41:47 +1100 Subject: [PATCH 04/73] Created entity.hpp and door system --- server/doors/door_data.cpp | 38 ++++++++++++++++++++ server/doors/door_data.hpp | 49 +++++++++++++++++++++++++ server/doors/door_manager.cpp | 68 +++++++++++++++++++++++++++++++++++ server/doors/door_manager.hpp | 60 +++++++++++++++++++++++++++++++ server/doors/makefile | 37 +++++++++++++++++++ server/entities/entity.hpp | 51 ++++++++++++++++++++++++++ server/entities/makefile | 37 +++++++++++++++++++ 7 files changed, 340 insertions(+) create mode 100644 server/doors/door_data.cpp create mode 100644 server/doors/door_data.hpp create mode 100644 server/doors/door_manager.cpp create mode 100644 server/doors/door_manager.hpp create mode 100644 server/doors/makefile create mode 100644 server/entities/entity.hpp create mode 100644 server/entities/makefile diff --git a/server/doors/door_data.cpp b/server/doors/door_data.cpp new file mode 100644 index 0000000..954365b --- /dev/null +++ b/server/doors/door_data.cpp @@ -0,0 +1,38 @@ +/* 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 "door_data.hpp" + +std::string DoorData::SetRoomName(std::string s) { + return roomName = s; +} + +Vector2 DoorData::SetDestPosition(Vector2 v) { + return destPosition = v; +} + +std::string DoorData::GetRoomName() { + return roomName; +} + +Vector2 DoorData::GetDestPosition() { + return destPosition; +} diff --git a/server/doors/door_data.hpp b/server/doors/door_data.hpp new file mode 100644 index 0000000..e6d3b53 --- /dev/null +++ b/server/doors/door_data.hpp @@ -0,0 +1,49 @@ +/* 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 DOORDATA_HPP_ +#define DOORDATA_HPP_ + +#include "entity.hpp" +#include "vector2.hpp" + +#include + +class DoorData: Entity { +public: + DoorData() = default; + ~DoorData() = default; + + //accessors & mutators + std::string SetRoomName(std::string); + Vector2 SetDestPosition(Vector2); + + std::string GetRoomName(); + Vector2 GetDestPosition(); + +private: + friend class DoorManager; + + std::string roomName; + Vector2 destPosition; +}; + +#endif \ No newline at end of file diff --git a/server/doors/door_manager.cpp b/server/doors/door_manager.cpp new file mode 100644 index 0000000..8a16211 --- /dev/null +++ b/server/doors/door_manager.cpp @@ -0,0 +1,68 @@ +/* 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 "door_manager.hpp" + +//TODO: door_manager.cpp + +int DoorManager::Create(std::string, Vector2) { + // +} + +int DoorManager::Load(std::string, Vector2) { + // +} + +int DoorManager::Save(int uid) { + // +} + +void DoorManager::Unload(int uid) { + // +} + +void DoorManager::Delete(int uid) { + // +} + +void DoorManager::UnloadAll() { + // +} + +void DoorManager::UnloadIf(std::function)> fn) { + // +} + +DoorData* DoorManager::Get(int uid) { + // +} + +int DoorManager::GetLoadedCount() { + // +} + +int DoorManager::GetTotalCount() { + // +} + +std::map* DoorManager::GetContainer() { + // +} diff --git a/server/doors/door_manager.hpp b/server/doors/door_manager.hpp new file mode 100644 index 0000000..0b06bc9 --- /dev/null +++ b/server/doors/door_manager.hpp @@ -0,0 +1,60 @@ +/* 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 DOORMANAGER_HPP_ +#define DOORMANAGER_HPP_ + +#include "door_data.hpp" +#include "manager_interface.hpp" +#include "singleton.hpp" +#include "vector2.hpp" + +#include +#include + +class DoorManager: + Singleton, + ManagerInterface +{ +public: + //common public methods + int Create(std::string, Vector2); + int Load(std::string, Vector2); + int Save(int uid); + void Unload(int uid); + void Delete(int uid); + + void UnloadAll(); + void UnloadIf(std::function)> fn); + + //accessors & mutators + DoorData* Get(int uid); + int GetLoadedCount(); + int GetTotalCount(); + std::map* GetContainer(); +private: + friend Singleton; + + DoorManager() = default; + ~DoorManager() = default; +}; + +#endif \ No newline at end of file diff --git a/server/doors/makefile b/server/doors/makefile new file mode 100644 index 0000000..3585271 --- /dev/null +++ b/server/doors/makefile @@ -0,0 +1,37 @@ +#config +INCLUDES+=. ../entities ../server_utilities ../../common/utilities +LIBS+= +CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES)) + +#source +CXXSRC=$(wildcard *.cpp) + +#objects +OBJDIR=obj +OBJ+=$(addprefix $(OBJDIR)/,$(CXXSRC:.cpp=.o)) + +#output +OUTDIR=.. +OUT=$(addprefix $(OUTDIR)/,server.a) + +#targets +all: $(OBJ) $(OUT) + ar -crs $(OUT) $(OBJ) + +$(OBJ): | $(OBJDIR) + +$(OUT): | $(OUTDIR) + +$(OBJDIR): + mkdir $(OBJDIR) + +$(OUTDIR): + mkdir $(OUTDIR) + +$(OBJDIR)/%.o: %.cpp + $(CXX) $(CXXFLAGS) -c -o $@ $< + +clean: + $(RM) *.o *.a *.exe + +rebuild: clean all diff --git a/server/entities/entity.hpp b/server/entities/entity.hpp new file mode 100644 index 0000000..f71b04a --- /dev/null +++ b/server/entities/entity.hpp @@ -0,0 +1,51 @@ +/* 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 ENTITY_HPP_ +#define ENTITY_HPP_ + +#include "vector2.hpp" + +//The base class for all objects in the world +class Entity { +public: + //accessors & mutators + int SetEntityIndex(int i) { return entityIndex = i; } + int SetRoomIndex(int i) { return roomIndex = i; } + Vector2 SetOrigin(Vector2 v) { return origin = v; } + Vector2 SetMotion(Vector2 v) { return motion = v; } + + int GetEntityIndex() { return entityIndex; } + int GetRoomIndex() { return roomIndex; } + Vector2 GetOrigin() { return origin; } + Vector2 GetMotion() { return motion; } + +protected: + Entity() = default; + ~Entity() = default; + + int entityIndex = -1; + int roomIndex = -1; + Vector2 origin; + Vector2 motion; +}; + +#endif \ No newline at end of file diff --git a/server/entities/makefile b/server/entities/makefile new file mode 100644 index 0000000..f24e1ba --- /dev/null +++ b/server/entities/makefile @@ -0,0 +1,37 @@ +#config +INCLUDES+=. ../../common/utilities +LIBS+= +CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES)) + +#source +CXXSRC=$(wildcard *.cpp) + +#objects +OBJDIR=obj +OBJ+=$(addprefix $(OBJDIR)/,$(CXXSRC:.cpp=.o)) + +#output +OUTDIR=.. +OUT=$(addprefix $(OUTDIR)/,server.a) + +#targets +all: $(OBJ) $(OUT) + ar -crs $(OUT) $(OBJ) + +$(OBJ): | $(OBJDIR) + +$(OUT): | $(OUTDIR) + +$(OBJDIR): + mkdir $(OBJDIR) + +$(OUTDIR): + mkdir $(OUTDIR) + +$(OBJDIR)/%.o: %.cpp + $(CXX) $(CXXFLAGS) -c -o $@ $< + +clean: + $(RM) *.o *.a *.exe + +rebuild: clean all From 6399efc227169a89a34c03fdfc3998d93b0b0a20 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Thu, 30 Oct 2014 01:05:41 +1100 Subject: [PATCH 05/73] Created the monster system --- server/monsters/makefile | 37 +++++++++++++ server/monsters/monster_data.cpp | 42 +++++++++++++++ server/monsters/monster_data.hpp | 51 ++++++++++++++++++ server/monsters/monster_manager.cpp | 84 +++++++++++++++++++++++++++++ server/monsters/monster_manager.hpp | 77 ++++++++++++++++++++++++++ todo.txt | 1 + 6 files changed, 292 insertions(+) create mode 100644 server/monsters/makefile create mode 100644 server/monsters/monster_data.cpp create mode 100644 server/monsters/monster_data.hpp create mode 100644 server/monsters/monster_manager.cpp create mode 100644 server/monsters/monster_manager.hpp diff --git a/server/monsters/makefile b/server/monsters/makefile new file mode 100644 index 0000000..7e666d5 --- /dev/null +++ b/server/monsters/makefile @@ -0,0 +1,37 @@ +#config +INCLUDES+=. ../entities ../server_utilities ../../common/gameplay ../../common/utilities +LIBS+= +CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES)) + +#source +CXXSRC=$(wildcard *.cpp) + +#objects +OBJDIR=obj +OBJ+=$(addprefix $(OBJDIR)/,$(CXXSRC:.cpp=.o)) + +#output +OUTDIR=.. +OUT=$(addprefix $(OUTDIR)/,server.a) + +#targets +all: $(OBJ) $(OUT) + ar -crs $(OUT) $(OBJ) + +$(OBJ): | $(OBJDIR) + +$(OUT): | $(OUTDIR) + +$(OBJDIR): + mkdir $(OBJDIR) + +$(OUTDIR): + mkdir $(OUTDIR) + +$(OBJDIR)/%.o: %.cpp + $(CXX) $(CXXFLAGS) -c -o $@ $< + +clean: + $(RM) *.o *.a *.exe + +rebuild: clean all diff --git a/server/monsters/monster_data.cpp b/server/monsters/monster_data.cpp new file mode 100644 index 0000000..2298c06 --- /dev/null +++ b/server/monsters/monster_data.cpp @@ -0,0 +1,42 @@ +/* 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 "monster_data.hpp" + +Statistics* MonsterData::GetBaseStats() { + return &baseStats; +} + +std::string MonsterData::SetAvatar(std::string s) { + return avatar = s; +} + +int MonsterData::SetScriptReference(int i) { + return scriptRef = i; +} + +std::string MonsterData::GetAvatar() { + return avatar; +} + +int MonsterData::GetScriptReference() { + return scriptRef; +} \ No newline at end of file diff --git a/server/monsters/monster_data.hpp b/server/monsters/monster_data.hpp new file mode 100644 index 0000000..1e1fcb2 --- /dev/null +++ b/server/monsters/monster_data.hpp @@ -0,0 +1,51 @@ +/* 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 MONSTERDATA_HPP_ +#define MONSTERDATA_HPP_ + +#include "entity.hpp" +#include "statistics.hpp" + +#include + +class MonsterData: Entity { +public: + MonsterData() = default; + ~MonsterData() = default; + + Statistics* GetBaseStats(); + + std::string SetAvatar(std::string); + int SetScriptReference(int); + + std::string GetAvatar(); + int GetScriptReference(); + +private: + friend class MonsterManager; + + Statistics baseStats; + std::string avatar; + int scriptRef; +}; + +#endif \ No newline at end of file diff --git a/server/monsters/monster_manager.cpp b/server/monsters/monster_manager.cpp new file mode 100644 index 0000000..2df1f5e --- /dev/null +++ b/server/monsters/monster_manager.cpp @@ -0,0 +1,84 @@ +/* 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 "monster_manager.hpp" + +//TODO: monster_manager.cpp + +int MonsterManager::Create(std::string) { + // +} + +int MonsterManager::Load(std::string) { + // +} + +int MonsterManager::Save(int uid) { + // +} + +void MonsterManager::Unload(int uid) { + // +} + +void MonsterManager::Delete(int uid) { + // +} + +void MonsterManager::UnloadAll() { + // +} + +void MonsterManager::UnloadIf(std::function)> fn) { + // +} + +MonsterData* MonsterManager::Get(int uid) { + // +} + +int MonsterManager::GetLoadedCount() { + // +} + +int MonsterManager::GetTotalCount() { + // +} + +std::map* MonsterManager::GetContainer() { + // +} + +sqlite3* MonsterManager::SetDatabase(sqlite3* db) { + // +} + +sqlite3* MonsterManager::GetDatabase() { + // +} + +lua_State* MonsterManager::SetLuaState(lua_State* L) { + // +} + +lua_State* MonsterManager::GetLuaState() { + // +} diff --git a/server/monsters/monster_manager.hpp b/server/monsters/monster_manager.hpp new file mode 100644 index 0000000..9b05db8 --- /dev/null +++ b/server/monsters/monster_manager.hpp @@ -0,0 +1,77 @@ +/* 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 MONSTERMANAGER_HPP_ +#define MONSTERMANAGER_HPP_ + +#include "manager_interface.hpp" +#include "monster_data.hpp" +#include "singleton.hpp" + +#ifdef __unix__ + #include "lua.hpp" + #include "sqlite3.h" +#else + #include "lua/lua.hpp" + #include "sqlite3/sqlite3.h" +#endif + +#include +#include + +class MonsterManager: + Singleton, + ManagerInterface +{ +public: + //common public methods + int Create(std::string); + int Load(std::string); + int Save(int uid); + void Unload(int uid); + void Delete(int uid); + + void UnloadAll(); + void UnloadIf(std::function)> fn); + + //accessors & mutators + MonsterData* Get(int uid); + int GetLoadedCount(); + int GetTotalCount(); + std::map* GetContainer(); + + //hooks + sqlite3* SetDatabase(sqlite3* db); + sqlite3* GetDatabase(); + lua_State* SetLuaState(lua_State* L); + lua_State* GetLuaState(); + +private: + friend Singleton; + + MonsterManager() = default; + ~MonsterManager() = default; + + sqlite3* database = nullptr; + lua_State* lua = nullptr; +}; + +#endif \ No newline at end of file diff --git a/todo.txt b/todo.txt index f2f38ec..ab0e4a9 100644 --- a/todo.txt +++ b/todo.txt @@ -1,4 +1,5 @@ TODO: Get the rooms working, even if only via hotkeys +TODO: I need a better way to handle the statistics TODO: SerialPacketType::CHARACTER_LOCATION, CHARACTER_MOVE, CHARACTER_TELEPORT, ROOM_CHANGE, etc. TODO: Fix shoddy movement TODO: Handle statistics server-side From 5327d91917a0b8d2cfff350ac860207445c35935 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Sun, 2 Nov 2014 20:42:26 +1100 Subject: [PATCH 06/73] Moved API files to their own directory --- server/{ => api}/linit.cpp | 0 server/{rooms => api}/room_api.cpp | 0 server/{rooms => api}/room_api.hpp | 0 server/{rooms => api}/room_manager_api.cpp | 0 server/{rooms => api}/room_manager_api.hpp | 0 5 files changed, 0 insertions(+), 0 deletions(-) rename server/{ => api}/linit.cpp (100%) rename server/{rooms => api}/room_api.cpp (100%) rename server/{rooms => api}/room_api.hpp (100%) rename server/{rooms => api}/room_manager_api.cpp (100%) rename server/{rooms => api}/room_manager_api.hpp (100%) diff --git a/server/linit.cpp b/server/api/linit.cpp similarity index 100% rename from server/linit.cpp rename to server/api/linit.cpp diff --git a/server/rooms/room_api.cpp b/server/api/room_api.cpp similarity index 100% rename from server/rooms/room_api.cpp rename to server/api/room_api.cpp diff --git a/server/rooms/room_api.hpp b/server/api/room_api.hpp similarity index 100% rename from server/rooms/room_api.hpp rename to server/api/room_api.hpp diff --git a/server/rooms/room_manager_api.cpp b/server/api/room_manager_api.cpp similarity index 100% rename from server/rooms/room_manager_api.cpp rename to server/api/room_manager_api.cpp diff --git a/server/rooms/room_manager_api.hpp b/server/api/room_manager_api.hpp similarity index 100% rename from server/rooms/room_manager_api.hpp rename to server/api/room_manager_api.hpp From 966443be3d64fa9f9b18b1c9efa6c9af52ed785f Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Wed, 5 Nov 2014 23:02:14 +1100 Subject: [PATCH 07/73] CharacterData inherits from Entity --- server/characters/character_data.hpp | 18 ++---------------- server/characters/makefile | 2 +- server/doors/door_data.hpp | 2 +- server/monsters/monster_data.hpp | 2 +- 4 files changed, 5 insertions(+), 19 deletions(-) diff --git a/server/characters/character_data.hpp b/server/characters/character_data.hpp index edc3d01..aad302c 100644 --- a/server/characters/character_data.hpp +++ b/server/characters/character_data.hpp @@ -24,27 +24,18 @@ //components #include "character_defines.hpp" -#include "vector2.hpp" +#include "entity.hpp" #include "statistics.hpp" //std namespace #include #include -class CharacterData { +class CharacterData: public Entity { public: CharacterData() = default; ~CharacterData() = default; - //location and movement - int SetRoomIndex(int i) { return roomIndex = i; } - Vector2 SetOrigin(Vector2 v) { return origin = v; } - Vector2 SetMotion(Vector2 v) { return motion = v; } - - int GetRoomIndex() { return roomIndex; } - Vector2 GetOrigin() { return origin; } - Vector2 GetMotion() { return motion; } - //accessors and mutators Statistics* GetBaseStats() { return &baseStats; } @@ -56,11 +47,6 @@ public: private: friend class CharacterManager; - //world position - int roomIndex = 0; - Vector2 origin = {0.0,0.0}; - Vector2 motion = {0.0,0.0}; - Statistics baseStats; int owner; diff --git a/server/characters/makefile b/server/characters/makefile index 7133d20..7e666d5 100644 --- a/server/characters/makefile +++ b/server/characters/makefile @@ -1,5 +1,5 @@ #config -INCLUDES+=. ../server_utilities ../../common/gameplay ../../common/utilities +INCLUDES+=. ../entities ../server_utilities ../../common/gameplay ../../common/utilities LIBS+= CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES)) diff --git a/server/doors/door_data.hpp b/server/doors/door_data.hpp index e6d3b53..62f5615 100644 --- a/server/doors/door_data.hpp +++ b/server/doors/door_data.hpp @@ -27,7 +27,7 @@ #include -class DoorData: Entity { +class DoorData: public Entity { public: DoorData() = default; ~DoorData() = default; diff --git a/server/monsters/monster_data.hpp b/server/monsters/monster_data.hpp index 1e1fcb2..a98daa7 100644 --- a/server/monsters/monster_data.hpp +++ b/server/monsters/monster_data.hpp @@ -27,7 +27,7 @@ #include -class MonsterData: Entity { +class MonsterData: public Entity { public: MonsterData() = default; ~MonsterData() = default; From 8eefdd71b5fe43b81d9a32c7e4552852002dc759 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Wed, 5 Nov 2014 23:07:34 +1100 Subject: [PATCH 08/73] Moved the API files back again --- server/{api => }/linit.cpp | 0 server/{api => rooms}/room_api.cpp | 0 server/{api => rooms}/room_api.hpp | 0 server/{api => rooms}/room_manager_api.cpp | 0 server/{api => rooms}/room_manager_api.hpp | 0 5 files changed, 0 insertions(+), 0 deletions(-) rename server/{api => }/linit.cpp (100%) rename server/{api => rooms}/room_api.cpp (100%) rename server/{api => rooms}/room_api.hpp (100%) rename server/{api => rooms}/room_manager_api.cpp (100%) rename server/{api => rooms}/room_manager_api.hpp (100%) diff --git a/server/api/linit.cpp b/server/linit.cpp similarity index 100% rename from server/api/linit.cpp rename to server/linit.cpp diff --git a/server/api/room_api.cpp b/server/rooms/room_api.cpp similarity index 100% rename from server/api/room_api.cpp rename to server/rooms/room_api.cpp diff --git a/server/api/room_api.hpp b/server/rooms/room_api.hpp similarity index 100% rename from server/api/room_api.hpp rename to server/rooms/room_api.hpp diff --git a/server/api/room_manager_api.cpp b/server/rooms/room_manager_api.cpp similarity index 100% rename from server/api/room_manager_api.cpp rename to server/rooms/room_manager_api.cpp diff --git a/server/api/room_manager_api.hpp b/server/rooms/room_manager_api.hpp similarity index 100% rename from server/api/room_manager_api.hpp rename to server/rooms/room_manager_api.hpp From fc2bc069923fde9979dfb1990cbbede8150b85e6 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Wed, 5 Nov 2014 23:43:36 +1100 Subject: [PATCH 09/73] Made a few tweaks to various managers --- server/clients/client_manager.hpp | 22 ++++++++++----------- server/doors/door_manager.hpp | 23 +++++++++++----------- server/makefile | 4 ++-- server/monsters/monster_manager.hpp | 30 ++++++++++++++--------------- server/rooms/makefile | 2 +- server/rooms/room_data.cpp | 23 ++++++++++++++++++++++ server/rooms/room_data.hpp | 13 ++++++++++--- server/rooms/room_manager.cpp | 4 ++-- server/rooms/room_manager.hpp | 6 +++--- 9 files changed, 79 insertions(+), 48 deletions(-) create mode 100644 server/rooms/room_data.cpp diff --git a/server/clients/client_manager.hpp b/server/clients/client_manager.hpp index d5e7cec..756fe0d 100644 --- a/server/clients/client_manager.hpp +++ b/server/clients/client_manager.hpp @@ -36,20 +36,20 @@ class ClientManager: { public: //common public methods - int Create(IPaddress); - int Load(IPaddress); - int Save(int uid); - void Unload(int uid); - void Delete(int uid); + int Create(IPaddress) override; + int Load(IPaddress) override; + int Save(int uid) override; + void Unload(int uid) override; + void Delete(int uid) override; - void UnloadAll(); - void UnloadIf(std::function)> fn); + void UnloadAll() override; + void UnloadIf(std::function)> fn) override; //accessors & mutators - ClientData* Get(int uid); - int GetLoadedCount(); - int GetTotalCount(); - std::map* GetContainer(); + ClientData* Get(int uid) override; + int GetLoadedCount() override; + int GetTotalCount() override; + std::map* GetContainer() override; private: friend Singleton; diff --git a/server/doors/door_manager.hpp b/server/doors/door_manager.hpp index 0b06bc9..2933b52 100644 --- a/server/doors/door_manager.hpp +++ b/server/doors/door_manager.hpp @@ -36,20 +36,21 @@ class DoorManager: { public: //common public methods - int Create(std::string, Vector2); - int Load(std::string, Vector2); - int Save(int uid); - void Unload(int uid); - void Delete(int uid); + int Create(std::string, Vector2) override; + int Load(std::string, Vector2) override; + int Save(int uid) override; + void Unload(int uid) override; + void Delete(int uid) override; - void UnloadAll(); - void UnloadIf(std::function)> fn); + void UnloadAll() override; + void UnloadIf(std::function)> fn) override; //accessors & mutators - DoorData* Get(int uid); - int GetLoadedCount(); - int GetTotalCount(); - std::map* GetContainer(); + DoorData* Get(int uid) override; + int GetLoadedCount() override; + int GetTotalCount() override; + std::map* GetContainer() override; + private: friend Singleton; diff --git a/server/makefile b/server/makefile index b4a33a1..0d87c3e 100644 --- a/server/makefile +++ b/server/makefile @@ -24,12 +24,12 @@ OUTDIR=../out OUT=$(addprefix $(OUTDIR)/,server) #targets -all: $(OBJ) $(OUT) +all: $(OUT) $(MAKE) -C accounts $(MAKE) -C characters $(MAKE) -C rooms $(MAKE) -C server_utilities - $(CXX) $(CXXFLAGS) -o $(OUT) $(OBJ) $(LIBS) +# $(CXX) $(CXXFLAGS) -o $(OUT) $(OBJ) $(LIBS) $(OBJ): | $(OBJDIR) diff --git a/server/monsters/monster_manager.hpp b/server/monsters/monster_manager.hpp index 9b05db8..20b7826 100644 --- a/server/monsters/monster_manager.hpp +++ b/server/monsters/monster_manager.hpp @@ -43,26 +43,26 @@ class MonsterManager: { public: //common public methods - int Create(std::string); - int Load(std::string); - int Save(int uid); - void Unload(int uid); - void Delete(int uid); + int Create(std::string) override; + int Load(std::string) override; + int Save(int uid) override; + void Unload(int uid) override; + void Delete(int uid) override; - void UnloadAll(); - void UnloadIf(std::function)> fn); + void UnloadAll() override; + void UnloadIf(std::function)> fn) override; //accessors & mutators - MonsterData* Get(int uid); - int GetLoadedCount(); - int GetTotalCount(); - std::map* GetContainer(); + MonsterData* Get(int uid) override; + int GetLoadedCount() override; + int GetTotalCount() override; + std::map* GetContainer() override; //hooks - sqlite3* SetDatabase(sqlite3* db); - sqlite3* GetDatabase(); - lua_State* SetLuaState(lua_State* L); - lua_State* GetLuaState(); + sqlite3* SetDatabase(sqlite3* db) override; + sqlite3* GetDatabase() override; + lua_State* SetLuaState(lua_State* L) override; + lua_State* GetLuaState() override; private: friend Singleton; diff --git a/server/rooms/makefile b/server/rooms/makefile index 4b00d80..514e483 100644 --- a/server/rooms/makefile +++ b/server/rooms/makefile @@ -1,5 +1,5 @@ #config -INCLUDES+=. ../server_utilities ../../common/map ../../common/utilities +INCLUDES+=. ../entities ../server_utilities ../../common/map ../../common/utilities LIBS+= CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES)) diff --git a/server/rooms/room_data.cpp b/server/rooms/room_data.cpp new file mode 100644 index 0000000..cd231b5 --- /dev/null +++ b/server/rooms/room_data.cpp @@ -0,0 +1,23 @@ +/* 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 "room_data.hpp" + diff --git a/server/rooms/room_data.hpp b/server/rooms/room_data.hpp index 046b119..5c9de55 100644 --- a/server/rooms/room_data.hpp +++ b/server/rooms/room_data.hpp @@ -22,9 +22,12 @@ #ifndef ROOMDATA_HPP_ #define ROOMDATA_HPP_ -//map system +#include "entity.hpp" #include "region_pager_lua.hpp" +#include "lua.hpp" + +#include #include class RoomData { @@ -48,8 +51,12 @@ private: RegionPagerLua pager; std::string roomName; std::string tilesetName; - //TODO: pass the room name & tileset name to the clients - //TODO: lua references i.e. create, unload, etc. + std::list entityList; + + //lua references + int createRef = LUA_NOREF; + int loadRef = LUA_NOREF; + int unloadRef = LUA_NOREF; }; #endif diff --git a/server/rooms/room_manager.cpp b/server/rooms/room_manager.cpp index a697201..26d5042 100644 --- a/server/rooms/room_manager.cpp +++ b/server/rooms/room_manager.cpp @@ -29,7 +29,7 @@ //public access methods //------------------------- -int RoomManager::Create() { +int RoomManager::Create(std::string roomName, std::string tilesetName) { //create the room RoomData* newRoom = &elementMap[counter]; //implicitly constructs the element newRoom->pager.SetLuaState(lua); @@ -38,7 +38,7 @@ int RoomManager::Create() { return counter++; } -int RoomManager::Load() { +int RoomManager::Load(std::string roomName, std::string tilesetName) { //TODO: RoomManager::Load() return -1; } diff --git a/server/rooms/room_manager.hpp b/server/rooms/room_manager.hpp index 093f902..de73b5c 100644 --- a/server/rooms/room_manager.hpp +++ b/server/rooms/room_manager.hpp @@ -34,12 +34,12 @@ class RoomManager: public Singleton, - public ManagerInterface + public ManagerInterface { public: //common public methods - int Create() override; - int Load() override; + int Create(std::string, std::string) override; + int Load(std::string, std::string) override; int Save(int uid) override; void Unload(int uid) override; void Delete(int uid) override; From cfdc61c3571e70651faba8d41e260343176cbc29 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Thu, 6 Nov 2014 00:04:42 +1100 Subject: [PATCH 10/73] Tweaked TODO comments --- server/clients/client_manager.cpp | 24 ++++++++++---------- server/doors/door_manager.cpp | 24 ++++++++++---------- server/monsters/monster_manager.cpp | 32 +++++++++++++-------------- server/rooms/room_data.hpp | 6 ++++- todo.txt | 34 +++++------------------------ 5 files changed, 47 insertions(+), 73 deletions(-) diff --git a/server/clients/client_manager.cpp b/server/clients/client_manager.cpp index e61090d..8fa0cb1 100644 --- a/server/clients/client_manager.cpp +++ b/server/clients/client_manager.cpp @@ -21,48 +21,46 @@ */ #include "client_manager.hpp" -//TODO: client_manager.cpp - int ClientManager::Create(IPaddress add) { - // + //TODO } int ClientManager::Load(IPaddress add) { - // + //TODO } int ClientManager::Save(int uid) { - // + //TODO } void ClientManager::Unload(int uid) { - // + //TODO } void ClientManager::Delete(int uid) { - // + //TODO } void ClientManager::UnloadAll() { - // + //TODO } void ClientManager::UnloadIf(std::function)> fn) { - // + //TODO } ClientData* ClientManager::Get(int uid) { - // + //TODO } int ClientManager::GetLoadedCount() { - // + //TODO } int ClientManager::GetTotalCount() { - // + //TODO } std::map* ClientManager::GetContainer() { - // + //TODO } \ No newline at end of file diff --git a/server/doors/door_manager.cpp b/server/doors/door_manager.cpp index 8a16211..bf264aa 100644 --- a/server/doors/door_manager.cpp +++ b/server/doors/door_manager.cpp @@ -21,48 +21,46 @@ */ #include "door_manager.hpp" -//TODO: door_manager.cpp - int DoorManager::Create(std::string, Vector2) { - // + //TODO } int DoorManager::Load(std::string, Vector2) { - // + //TODO } int DoorManager::Save(int uid) { - // + //TODO } void DoorManager::Unload(int uid) { - // + //TODO } void DoorManager::Delete(int uid) { - // + //TODO } void DoorManager::UnloadAll() { - // + //TODO } void DoorManager::UnloadIf(std::function)> fn) { - // + //TODO } DoorData* DoorManager::Get(int uid) { - // + //TODO } int DoorManager::GetLoadedCount() { - // + //TODO } int DoorManager::GetTotalCount() { - // + //TODO } std::map* DoorManager::GetContainer() { - // + //TODO } diff --git a/server/monsters/monster_manager.cpp b/server/monsters/monster_manager.cpp index 2df1f5e..1b2f885 100644 --- a/server/monsters/monster_manager.cpp +++ b/server/monsters/monster_manager.cpp @@ -21,64 +21,62 @@ */ #include "monster_manager.hpp" -//TODO: monster_manager.cpp - int MonsterManager::Create(std::string) { - // + //TODO } int MonsterManager::Load(std::string) { - // + //TODO } int MonsterManager::Save(int uid) { - // + //TODO } void MonsterManager::Unload(int uid) { - // + //TODO } void MonsterManager::Delete(int uid) { - // + //TODO } void MonsterManager::UnloadAll() { - // + //TODO } void MonsterManager::UnloadIf(std::function)> fn) { - // + //TODO } MonsterData* MonsterManager::Get(int uid) { - // + //TODO } int MonsterManager::GetLoadedCount() { - // + //TODO } int MonsterManager::GetTotalCount() { - // + //TODO } std::map* MonsterManager::GetContainer() { - // + //TODO } sqlite3* MonsterManager::SetDatabase(sqlite3* db) { - // + //TODO } sqlite3* MonsterManager::GetDatabase() { - // + //TODO } lua_State* MonsterManager::SetLuaState(lua_State* L) { - // + //TODO } lua_State* MonsterManager::GetLuaState() { - // + //TODO } diff --git a/server/rooms/room_data.hpp b/server/rooms/room_data.hpp index 5c9de55..9f38cbb 100644 --- a/server/rooms/room_data.hpp +++ b/server/rooms/room_data.hpp @@ -25,7 +25,11 @@ #include "entity.hpp" #include "region_pager_lua.hpp" -#include "lua.hpp" +#if defined(__MINGW32__) + #include "lua/lua.hpp" +#else + #include "lua.hpp" +#endif #include #include diff --git a/todo.txt b/todo.txt index ab0e4a9..d764117 100644 --- a/todo.txt +++ b/todo.txt @@ -1,40 +1,16 @@ -TODO: Get the rooms working, even if only via hotkeys +TODO: client_manager.cpp +TODO: door_manager.cpp +TODO: monster_manager.cpp + TODO: I need a better way to handle the statistics -TODO: SerialPacketType::CHARACTER_LOCATION, CHARACTER_MOVE, CHARACTER_TELEPORT, ROOM_CHANGE, etc. TODO: Fix shoddy movement TODO: Handle statistics server-side TODO: Periodic mass server saves TODO: Remove the big "Shut Down" button TODO: Make a way for the server owner to control the server directly -TODO: Move the map system into it's own namespace? TODO: The TileSheet class should implement the surface itself -TODO: make the whole thing more fault tolerant -TODO: Authentication - +TODO: Passwords/Authentication TODO: Time delay for requesting region packets TODO: A proper logging system TODO: Update Codebase with the improvements from Tortuga - -------------------------- -Serial Packet Types -------------------------- - -//character management -* CHARACTER_CREATE //make this character -* CHARACTER_DELETE //unmake this character -* CHARACTER_LOAD //load this character into the world -* CHARACTER_UNLOAD //unload this character from the world - -//find out info from the server -* CHARACTER_QUERY_EXISTS //also sends the owner's info -* CHARACTER_QUERY_LOCATION -* CHARACTER_get all the entities within a distance of this - -//set the info in the server -* CHARACTER_SET_ORIGIN -* CHARACTER_SET_MOTION - -//authentication, character index => character stats -CHARACTER_STATS_REQUEST -CHARACTER_STATS_RESPONSE From a4ed23f6c7a47528472b86f23bfd73c2cefbeaf8 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Thu, 6 Nov 2014 01:16:02 +1100 Subject: [PATCH 11/73] Created a way to coalesce map modules into one table --- common/map/map_system_api.cpp | 46 +++++++++++++++++++++++++++++++++ common/map/map_system_api.hpp | 34 ++++++++++++++++++++++++ common/map/region_api.hpp | 2 +- common/map/region_pager_api.hpp | 2 +- common/map/tile_sheet_api.hpp | 3 +-- 5 files changed, 83 insertions(+), 4 deletions(-) create mode 100644 common/map/map_system_api.cpp create mode 100644 common/map/map_system_api.hpp diff --git a/common/map/map_system_api.cpp b/common/map/map_system_api.cpp new file mode 100644 index 0000000..65c0a10 --- /dev/null +++ b/common/map/map_system_api.cpp @@ -0,0 +1,46 @@ +/* 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 "map_system_api.hpp" + +//all map API headers +#include "region_api.hpp" +#include "region_pager_api.hpp" +#include "tile_sheet.hpp" + +/* This mimics linit.c to create a nested collection of all map modules. +*/ + +static const luaL_Reg maplibs[] = { + {"Region", openRegionAPI}, + {"RegionPager", openRegionPagerAPI}, +// {"TileSheet", openTileSheetAPI}, + {nullptr, nullptr} +}; + +int openMapSystemAPI(lua_State* L) { + luaL_newlibtable(L, maplibs); + for (const luaL_Reg* lib = maplibs; lib->func; lib++) { + lua_pushcfunction(L, lib->func); + lua_setfield(L, -2, lib->name); + } + return 1; +} \ No newline at end of file diff --git a/common/map/map_system_api.hpp b/common/map/map_system_api.hpp new file mode 100644 index 0000000..10f2f94 --- /dev/null +++ b/common/map/map_system_api.hpp @@ -0,0 +1,34 @@ +/* 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 MAPSYSTEMAPI_HPP_ +#define MAPSYSTEMAPI_APP_ + +#if defined(__MINGW32__) + #include "lua/lua.hpp" +#else + #include "lua.hpp" +#endif + +#define TORTUGA_MAP_SYSTEM_API "map_system" +LUAMOD_API int openMapSystemAPI(lua_State* L); + +#endif \ No newline at end of file diff --git a/common/map/region_api.hpp b/common/map/region_api.hpp index babbb4f..b276645 100644 --- a/common/map/region_api.hpp +++ b/common/map/region_api.hpp @@ -28,7 +28,7 @@ #include "lua.hpp" #endif -#define TORTUGA_REGION_NAME "Region" +#define TORTUGA_REGION_NAME "region" LUAMOD_API int openRegionAPI(lua_State* L); #endif diff --git a/common/map/region_pager_api.hpp b/common/map/region_pager_api.hpp index b4f8c7b..a8f9297 100644 --- a/common/map/region_pager_api.hpp +++ b/common/map/region_pager_api.hpp @@ -28,7 +28,7 @@ #include "lua.hpp" #endif -#define TORTUGA_REGION_PAGER_NAME "RegionPager" +#define TORTUGA_REGION_PAGER_NAME "region_pager" LUAMOD_API int openRegionPagerAPI(lua_State* L); #endif diff --git a/common/map/tile_sheet_api.hpp b/common/map/tile_sheet_api.hpp index 385a4b2..dc3d277 100644 --- a/common/map/tile_sheet_api.hpp +++ b/common/map/tile_sheet_api.hpp @@ -28,8 +28,7 @@ #include "lua.hpp" #endif - -#define TORTUGA_TILE_SHEET_NAME "TileSheet" +#define TORTUGA_TILE_SHEET_NAME "tile_sheet" LUAMOD_API int openTileSheetAPI(lua_State* L); #endif From daa38413f34453222040f114df564e24f0412d3a Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Thu, 6 Nov 2014 01:21:37 +1100 Subject: [PATCH 12/73] temp script changes --- rsc/scripts/map_saver.lua | 1 + rsc/scripts/setup_room.lua | 0 rsc/scripts/setup_server.lua | 9 ++++----- server/linit.cpp | 8 ++------ server/rooms/room_data.hpp | 1 - server/server_logic.cpp | 2 ++ 6 files changed, 9 insertions(+), 12 deletions(-) delete mode 100644 rsc/scripts/setup_room.lua diff --git a/rsc/scripts/map_saver.lua b/rsc/scripts/map_saver.lua index e69de29..f521381 100644 --- a/rsc/scripts/map_saver.lua +++ b/rsc/scripts/map_saver.lua @@ -0,0 +1 @@ +--TODO: create a flexible saving & loading system \ No newline at end of file diff --git a/rsc/scripts/setup_room.lua b/rsc/scripts/setup_room.lua deleted file mode 100644 index e69de29..0000000 diff --git a/rsc/scripts/setup_server.lua b/rsc/scripts/setup_server.lua index 78a9b32..f9dbc07 100644 --- a/rsc/scripts/setup_server.lua +++ b/rsc/scripts/setup_server.lua @@ -2,11 +2,10 @@ print("Lua script check") mapMaker = require "map_maker" mapSaver = require "map_saver" +roomSystem = require "room_system" ---BUG: #35 The server fails without at least one room ---TODO: Create rooms with names? -newRoom = RoomManager.CreateRoom("overworld", "overworld.bmp") -pager = Room.GetPager(newRoom) -RegionPager.SetOnCreate(pager, mapMaker.debugIsland) +--create the overworld, set it's generator, loader & saver +local overworld = roomSystem.CreateRoom("overworld", "overworld.bmp") +roomSystem.SetOnLoad(overworld, mapMaker.debugIsland, mapSaver.load, mapSaver.save) print("Finished the lua script") diff --git a/server/linit.cpp b/server/linit.cpp index cec8779..7702d51 100644 --- a/server/linit.cpp +++ b/server/linit.cpp @@ -40,9 +40,7 @@ #include "lua.hpp" #endif -#include "region_api.hpp" -#include "region_pager_api.hpp" -#include "tile_sheet_api.hpp" +#include "map_system_api.hpp" #include "room_api.hpp" #include "room_manager_api.hpp" @@ -61,9 +59,6 @@ static const luaL_Reg loadedlibs[] = { {LUA_DBLIBNAME, luaopen_debug}, //Tortuga's API - {TORTUGA_REGION_NAME, openRegionAPI}, - {TORTUGA_REGION_PAGER_NAME, openRegionPagerAPI}, - {TORTUGA_TILE_SHEET_NAME, openTileSheetAPI}, {TORTUGA_ROOM_NAME, openRoomAPI}, {TORTUGA_ROOM_MANAGER_NAME, openRoomManagerAPI}, @@ -73,6 +68,7 @@ static const luaL_Reg loadedlibs[] = { //these libs are preloaded and must be required before used static const luaL_Reg preloadedlibs[] = { + {TORTUGA_MAP_SYSTEM_API, openMapSystemAPI}, {NULL, NULL} }; diff --git a/server/rooms/room_data.hpp b/server/rooms/room_data.hpp index 9f38cbb..6586405 100644 --- a/server/rooms/room_data.hpp +++ b/server/rooms/room_data.hpp @@ -58,7 +58,6 @@ private: std::list entityList; //lua references - int createRef = LUA_NOREF; int loadRef = LUA_NOREF; int unloadRef = LUA_NOREF; }; diff --git a/server/server_logic.cpp b/server/server_logic.cpp index c83447b..5afdf99 100644 --- a/server/server_logic.cpp +++ b/server/server_logic.cpp @@ -35,6 +35,8 @@ //public methods //------------------------- +//BUG: #35 The server fails without at least one room + 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 " << argv[0] << std::endl; From f2d79225a30867cea3c83f5210f440efd7d0d6bb Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Thu, 6 Nov 2014 01:54:20 +1100 Subject: [PATCH 13/73] Created '*_data.cpp' files, modified API files a bit --- common/map/map_system_api.cpp | 32 +++++++++++++++-- server/accounts/account_data.cpp | 54 ++++++++++++++++++++++++++++ server/accounts/account_data.hpp | 16 ++++----- server/characters/character_data.cpp | 38 ++++++++++++++++++++ server/characters/character_data.hpp | 8 ++--- server/entities/entity.cpp | 53 +++++++++++++++++++++++++++ server/entities/entity.hpp | 16 ++++----- server/makefile | 4 +++ server/monsters/monster_manager.hpp | 8 ++--- server/rooms/room_api.cpp | 14 ++++---- server/rooms/room_api.hpp | 2 +- server/rooms/room_data.cpp | 39 ++++++++++++++++++++ server/rooms/room_data.hpp | 20 +++++++---- server/rooms/room_manager_api.hpp | 2 +- todo.txt | 2 ++ 15 files changed, 268 insertions(+), 40 deletions(-) create mode 100644 server/accounts/account_data.cpp create mode 100644 server/characters/character_data.cpp create mode 100644 server/entities/entity.cpp diff --git a/common/map/map_system_api.cpp b/common/map/map_system_api.cpp index 65c0a10..c3a9cca 100644 --- a/common/map/map_system_api.cpp +++ b/common/map/map_system_api.cpp @@ -26,8 +26,30 @@ #include "region_pager_api.hpp" #include "tile_sheet.hpp" -/* This mimics linit.c to create a nested collection of all map modules. -*/ +//useful "globals" +static int getRegionWidth(lua_State* L) { + lua_pushinteger(L, REGION_WIDTH); + return 1; +} + +static int getRegionHeight(lua_State* L) { + lua_pushinteger(L, REGION_HEIGHT); + return 1; +} + +static int getRegionDepth(lua_State* L) { + lua_pushinteger(L, REGION_DEPTH); + return 1; +} + +//This mimics linit.c to create a nested collection of all map modules. +static const luaL_Reg mapfuncs[] = { + //synonyms + {"GetRegionWidth", getRegionWidth}, + {"GetRegionHeight", getRegionHeight}, + {"GetRegionDepth", getRegionDepth}, + {nullptr, nullptr} +}; static const luaL_Reg maplibs[] = { {"Region", openRegionAPI}, @@ -37,7 +59,13 @@ static const luaL_Reg maplibs[] = { }; int openMapSystemAPI(lua_State* L) { + //create the table luaL_newlibtable(L, maplibs); + + //push the "global" functions + luaL_setfuncs(L, mapfuncs, 0); + + //push the substable for (const luaL_Reg* lib = maplibs; lib->func; lib++) { lua_pushcfunction(L, lib->func); lua_setfield(L, -2, lib->name); diff --git a/server/accounts/account_data.cpp b/server/accounts/account_data.cpp new file mode 100644 index 0000000..4b8b872 --- /dev/null +++ b/server/accounts/account_data.cpp @@ -0,0 +1,54 @@ +/* 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 "account_data.hpp" + +int AccountData::SetClientIndex(int i) { + return clientIndex = i; +} + +int AccountData::GetClientIndex() { + return clientIndex; +} + +std::string AccountData::SetUsername(std::string s) { + return username = s; +} + +std::string AccountData::GetUsername() { + return username; +} + +bool AccountData::GetBlackListed() { + return blackListed; +} + +bool AccountData::GetWhiteListed() { + return whiteListed; +} + +bool AccountData::GetModerator() { + return mod; +} + +bool AccountData::GetAdministrator() { + return admin; +} \ No newline at end of file diff --git a/server/accounts/account_data.hpp b/server/accounts/account_data.hpp index d7fb022..4d615a4 100644 --- a/server/accounts/account_data.hpp +++ b/server/accounts/account_data.hpp @@ -30,17 +30,17 @@ public: ~AccountData() = default; //accessors and mutators - int SetClientIndex(int i) { return clientIndex = i; } - int GetClientIndex() { return clientIndex; } + int SetClientIndex(int i); + int GetClientIndex(); - std::string SetUsername(std::string s) { return username = s; } - std::string GetUsername() { return username; } + std::string SetUsername(std::string s); + std::string GetUsername(); //database stuff - bool GetBlackListed() { return blackListed; } - bool GetWhiteListed() { return whiteListed; } - bool GetModerator() { return mod; } - bool GetAdministrator() { return admin; } + bool GetBlackListed(); + bool GetWhiteListed(); + bool GetModerator(); + bool GetAdministrator(); private: friend class AccountManager; diff --git a/server/characters/character_data.cpp b/server/characters/character_data.cpp new file mode 100644 index 0000000..359812c --- /dev/null +++ b/server/characters/character_data.cpp @@ -0,0 +1,38 @@ +/* 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 "character_data.hpp" + +Statistics* CharacterData::GetBaseStats() { + return &baseStats; +} + +int CharacterData::GetOwner() { + return owner; +} + +std::string CharacterData::GetHandle() { + return handle; +} + +std::string CharacterData::GetAvatar() { + return avatar; +} \ No newline at end of file diff --git a/server/characters/character_data.hpp b/server/characters/character_data.hpp index aad302c..400f4cb 100644 --- a/server/characters/character_data.hpp +++ b/server/characters/character_data.hpp @@ -37,12 +37,12 @@ public: ~CharacterData() = default; //accessors and mutators - Statistics* GetBaseStats() { return &baseStats; } + Statistics* GetBaseStats(); //database stuff - int GetOwner() { return owner; } - std::string GetHandle() { return handle; } - std::string GetAvatar() { return avatar; } + int GetOwner(); + std::string GetHandle(); + std::string GetAvatar(); private: friend class CharacterManager; diff --git a/server/entities/entity.cpp b/server/entities/entity.cpp new file mode 100644 index 0000000..d22a5d3 --- /dev/null +++ b/server/entities/entity.cpp @@ -0,0 +1,53 @@ +/* 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 "entity.hpp" + +int Entity::SetEntityIndex(int i) { + return entityIndex = i; +} + +int Entity::SetRoomIndex(int i) { + return roomIndex = i; +} + +Vector2 Entity::SetOrigin(Vector2 v) { + return origin = v; +} + +Vector2 Entity::SetMotion(Vector2 v) { + return motion = v; +} +int Entity::GetEntityIndex() { + return entityIndex; +} + +int Entity::GetRoomIndex() { + return roomIndex; +} + +Vector2 Entity::GetOrigin() { + return origin; +} + +Vector2 Entity::GetMotion() { + return motion; +} \ No newline at end of file diff --git a/server/entities/entity.hpp b/server/entities/entity.hpp index f71b04a..8933c38 100644 --- a/server/entities/entity.hpp +++ b/server/entities/entity.hpp @@ -28,15 +28,15 @@ class Entity { public: //accessors & mutators - int SetEntityIndex(int i) { return entityIndex = i; } - int SetRoomIndex(int i) { return roomIndex = i; } - Vector2 SetOrigin(Vector2 v) { return origin = v; } - Vector2 SetMotion(Vector2 v) { return motion = v; } + int SetEntityIndex(int i); + int SetRoomIndex(int i); + Vector2 SetOrigin(Vector2 v); + Vector2 SetMotion(Vector2 v); - int GetEntityIndex() { return entityIndex; } - int GetRoomIndex() { return roomIndex; } - Vector2 GetOrigin() { return origin; } - Vector2 GetMotion() { return motion; } + int GetEntityIndex(); + int GetRoomIndex(); + Vector2 GetOrigin(); + Vector2 GetMotion(); protected: Entity() = default; diff --git a/server/makefile b/server/makefile index 0d87c3e..2cba03c 100644 --- a/server/makefile +++ b/server/makefile @@ -27,6 +27,10 @@ OUT=$(addprefix $(OUTDIR)/,server) all: $(OUT) $(MAKE) -C accounts $(MAKE) -C characters + $(MAKE) -C clients + $(MAKE) -C doors + $(MAKE) -C entities + $(MAKE) -C monsters $(MAKE) -C rooms $(MAKE) -C server_utilities # $(CXX) $(CXXFLAGS) -o $(OUT) $(OBJ) $(LIBS) diff --git a/server/monsters/monster_manager.hpp b/server/monsters/monster_manager.hpp index 20b7826..8a12fbd 100644 --- a/server/monsters/monster_manager.hpp +++ b/server/monsters/monster_manager.hpp @@ -59,10 +59,10 @@ public: std::map* GetContainer() override; //hooks - sqlite3* SetDatabase(sqlite3* db) override; - sqlite3* GetDatabase() override; - lua_State* SetLuaState(lua_State* L) override; - lua_State* GetLuaState() override; + sqlite3* SetDatabase(sqlite3* db); + sqlite3* GetDatabase(); + lua_State* SetLuaState(lua_State* L); + lua_State* GetLuaState(); private: friend Singleton; diff --git a/server/rooms/room_api.cpp b/server/rooms/room_api.cpp index bc8b1a1..03f5956 100644 --- a/server/rooms/room_api.cpp +++ b/server/rooms/room_api.cpp @@ -23,12 +23,6 @@ #include "room_data.hpp" -static int getPager(lua_State* L) { - RoomData* room = reinterpret_cast(lua_touserdata(L, 1)); - lua_pushlightuserdata(L, reinterpret_cast(room->GetPager()) ); - return 1; -} - static int setRoomName(lua_State* L) { RoomData* room = reinterpret_cast(lua_touserdata(L, 1)); room->SetRoomName(lua_tostring(L, 2)); @@ -53,6 +47,14 @@ static int getTilesetName(lua_State* L) { return 1; } +static int getPager(lua_State* L) { + RoomData* room = reinterpret_cast(lua_touserdata(L, 1)); + lua_pushlightuserdata(L, reinterpret_cast(room->GetPager()) ); + return 1; +} + + + static const luaL_Reg roomLib[] = { {"GetPager",getPager}, {"SetRoomName", setRoomName}, diff --git a/server/rooms/room_api.hpp b/server/rooms/room_api.hpp index 5a1a0c2..060a68d 100644 --- a/server/rooms/room_api.hpp +++ b/server/rooms/room_api.hpp @@ -28,7 +28,7 @@ #include "lua.hpp" #endif -#define TORTUGA_ROOM_NAME "Room" +#define TORTUGA_ROOM_NAME "room" LUAMOD_API int openRoomAPI(lua_State* L); #endif diff --git a/server/rooms/room_data.cpp b/server/rooms/room_data.cpp index cd231b5..7fb9061 100644 --- a/server/rooms/room_data.cpp +++ b/server/rooms/room_data.cpp @@ -21,3 +21,42 @@ */ #include "room_data.hpp" +std::string RoomData::SetRoomName(std::string s) { + return roomName = s; +} + +std::string RoomData::GetRoomName() { + return roomName; +} + +std::string RoomData::SetTilesetName(std::string s) { + return tilesetName = s; +} + +std::string RoomData::GetTilesetName() { + return tilesetName; +} + +RegionPagerLua* RoomData::GetPager() { + return &pager; +} + +std::list* RoomData::GetEntityList() { + return &entityList; +} + +int RoomData::SetLoadReference(int i) { + return loadRef = i; +} + +int RoomData::GetLoadReference() { + return loadRef; +} + +int RoomData::SetUnloadReference(int i) { + return unloadRef = i; +} + +int RoomData::GetUnloadReference() { + return unloadRef; +} \ No newline at end of file diff --git a/server/rooms/room_data.hpp b/server/rooms/room_data.hpp index 6586405..65a488d 100644 --- a/server/rooms/room_data.hpp +++ b/server/rooms/room_data.hpp @@ -40,21 +40,29 @@ public: ~RoomData() = default; //accessors and mutators - RegionPagerLua* GetPager() { return &pager; } + std::string SetRoomName(std::string s); + std::string GetRoomName(); - std::string SetRoomName(std::string s) { return roomName = s; } - std::string GetRoomName() { return roomName; } + std::string SetTilesetName(std::string s); + std::string GetTilesetName(); - std::string SetTilesetName(std::string s) { return tilesetName = s; } - std::string GetTilesetName() { return tilesetName; } + RegionPagerLua* GetPager(); + std::list* GetEntityList(); + + //hooks + int SetLoadReference(int); + int GetLoadReference(); + int SetUnloadReference(int); + int GetUnloadReference(); private: friend class RoomManager; //members - RegionPagerLua pager; std::string roomName; std::string tilesetName; + + RegionPagerLua pager; std::list entityList; //lua references diff --git a/server/rooms/room_manager_api.hpp b/server/rooms/room_manager_api.hpp index d8d7b75..8ca0418 100644 --- a/server/rooms/room_manager_api.hpp +++ b/server/rooms/room_manager_api.hpp @@ -28,7 +28,7 @@ #include "lua.hpp" #endif -#define TORTUGA_ROOM_MANAGER_NAME "RoomManager" +#define TORTUGA_ROOM_MANAGER_NAME "room_manager" LUAMOD_API int openRoomManagerAPI(lua_State* L); #endif diff --git a/todo.txt b/todo.txt index d764117..cbef2ec 100644 --- a/todo.txt +++ b/todo.txt @@ -1,6 +1,8 @@ TODO: client_manager.cpp TODO: door_manager.cpp TODO: monster_manager.cpp +TODO: *_data.cpp +TODO: reduce friendships TODO: I need a better way to handle the statistics TODO: Fix shoddy movement From 73d90956047361904d91955cb1c63c36849e72e5 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Thu, 6 Nov 2014 02:00:13 +1100 Subject: [PATCH 14/73] Minor comment tweaks --- server/rooms/room_api.cpp | 2 +- server/rooms/room_manager_api.cpp | 2 +- todo.txt | 8 +++----- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/server/rooms/room_api.cpp b/server/rooms/room_api.cpp index 03f5956..57a90ec 100644 --- a/server/rooms/room_api.cpp +++ b/server/rooms/room_api.cpp @@ -53,7 +53,7 @@ static int getPager(lua_State* L) { return 1; } - +//TODO: GetEntityList? static const luaL_Reg roomLib[] = { {"GetPager",getPager}, diff --git a/server/rooms/room_manager_api.cpp b/server/rooms/room_manager_api.cpp index ab4d6d9..217577d 100644 --- a/server/rooms/room_manager_api.cpp +++ b/server/rooms/room_manager_api.cpp @@ -26,7 +26,7 @@ int createRoom(lua_State* L) { //create & get the room RoomManager& roomMgr = RoomManager::GetSingleton(); - int uid = roomMgr.Create(); + int uid = roomMgr.Create("",""); //TODO: All new managers need their internals fleshed out RoomData* room = roomMgr.Get(uid); //setup the room diff --git a/todo.txt b/todo.txt index cbef2ec..afb6f10 100644 --- a/todo.txt +++ b/todo.txt @@ -1,8 +1,6 @@ -TODO: client_manager.cpp -TODO: door_manager.cpp -TODO: monster_manager.cpp -TODO: *_data.cpp -TODO: reduce friendships +TODO: All new managers need their internals fleshed out +TODO: room_system api +TODO: rewrite the main body of the server TODO: I need a better way to handle the statistics TODO: Fix shoddy movement From 06e027710f526dcf91e926eb1ada6ed02d86b685 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Thu, 6 Nov 2014 22:42:03 +1100 Subject: [PATCH 15/73] Created the room system's API, and tweaked some other APIs --- common/map/map_system_api.cpp | 15 +++++---- server/linit.cpp | 9 ++--- server/rooms/room_api.hpp | 2 +- server/rooms/room_manager_api.hpp | 4 +-- server/rooms/room_system_api.cpp | 56 +++++++++++++++++++++++++++++++ server/rooms/room_system_api.hpp | 34 +++++++++++++++++++ 6 files changed, 104 insertions(+), 16 deletions(-) create mode 100644 server/rooms/room_system_api.cpp create mode 100644 server/rooms/room_system_api.hpp diff --git a/common/map/map_system_api.cpp b/common/map/map_system_api.cpp index c3a9cca..46b6355 100644 --- a/common/map/map_system_api.cpp +++ b/common/map/map_system_api.cpp @@ -24,7 +24,10 @@ //all map API headers #include "region_api.hpp" #include "region_pager_api.hpp" -#include "tile_sheet.hpp" +#include "tile_sheet_api.hpp" + +//macros +#include "region.hpp" //useful "globals" static int getRegionWidth(lua_State* L) { @@ -43,7 +46,7 @@ static int getRegionDepth(lua_State* L) { } //This mimics linit.c to create a nested collection of all map modules. -static const luaL_Reg mapfuncs[] = { +static const luaL_Reg funcs[] = { //synonyms {"GetRegionWidth", getRegionWidth}, {"GetRegionHeight", getRegionHeight}, @@ -51,7 +54,7 @@ static const luaL_Reg mapfuncs[] = { {nullptr, nullptr} }; -static const luaL_Reg maplibs[] = { +static const luaL_Reg libs[] = { {"Region", openRegionAPI}, {"RegionPager", openRegionPagerAPI}, // {"TileSheet", openTileSheetAPI}, @@ -60,13 +63,13 @@ static const luaL_Reg maplibs[] = { int openMapSystemAPI(lua_State* L) { //create the table - luaL_newlibtable(L, maplibs); + luaL_newlibtable(L, libs); //push the "global" functions - luaL_setfuncs(L, mapfuncs, 0); + luaL_setfuncs(L, funcs, 0); //push the substable - for (const luaL_Reg* lib = maplibs; lib->func; lib++) { + for (const luaL_Reg* lib = libs; lib->func; lib++) { lua_pushcfunction(L, lib->func); lua_setfield(L, -2, lib->name); } diff --git a/server/linit.cpp b/server/linit.cpp index 7702d51..c442680 100644 --- a/server/linit.cpp +++ b/server/linit.cpp @@ -41,8 +41,7 @@ #endif #include "map_system_api.hpp" -#include "room_api.hpp" -#include "room_manager_api.hpp" +#include "room_system_api.hpp" //these libs are loaded by lua.c and are readily available to any Lua program static const luaL_Reg loadedlibs[] = { @@ -57,11 +56,6 @@ static const luaL_Reg loadedlibs[] = { {LUA_BITLIBNAME, luaopen_bit32}, {LUA_MATHLIBNAME, luaopen_math}, {LUA_DBLIBNAME, luaopen_debug}, - - //Tortuga's API - {TORTUGA_ROOM_NAME, openRoomAPI}, - {TORTUGA_ROOM_MANAGER_NAME, openRoomManagerAPI}, - {NULL, NULL} }; @@ -69,6 +63,7 @@ static const luaL_Reg loadedlibs[] = { //these libs are preloaded and must be required before used static const luaL_Reg preloadedlibs[] = { {TORTUGA_MAP_SYSTEM_API, openMapSystemAPI}, + {TORTUGA_ROOM_SYSTEM_API, openRoomSystemAPI}, {NULL, NULL} }; diff --git a/server/rooms/room_api.hpp b/server/rooms/room_api.hpp index 060a68d..087c6c2 100644 --- a/server/rooms/room_api.hpp +++ b/server/rooms/room_api.hpp @@ -28,7 +28,7 @@ #include "lua.hpp" #endif -#define TORTUGA_ROOM_NAME "room" +#define TORTUGA_ROOM_API "room" LUAMOD_API int openRoomAPI(lua_State* L); #endif diff --git a/server/rooms/room_manager_api.hpp b/server/rooms/room_manager_api.hpp index 8ca0418..1cd042d 100644 --- a/server/rooms/room_manager_api.hpp +++ b/server/rooms/room_manager_api.hpp @@ -28,7 +28,7 @@ #include "lua.hpp" #endif -#define TORTUGA_ROOM_MANAGER_NAME "room_manager" +#define TORTUGA_ROOM_MANAGER_API "room_manager" LUAMOD_API int openRoomManagerAPI(lua_State* L); -#endif +#endif \ No newline at end of file diff --git a/server/rooms/room_system_api.cpp b/server/rooms/room_system_api.cpp new file mode 100644 index 0000000..fcbb205 --- /dev/null +++ b/server/rooms/room_system_api.cpp @@ -0,0 +1,56 @@ +/* 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 "room_system_api.hpp" + +//all map API headers +#include "room_api.hpp" +#include "room_manager_api.hpp" + +//useful "globals" +//... + +//This mimics linit.c to create a nested collection of all map modules. +static const luaL_Reg funcs[] = { + {nullptr, nullptr} +}; + +static const luaL_Reg libs[] = { + {"Room", openRoomAPI}, + {"RoomManager", openRoomManagerAPI}, +// {"TileSheet", openTileSheetAPI}, + {nullptr, nullptr} +}; + +int openMapSystemAPI(lua_State* L) { + //create the table + luaL_newlibtable(L, libs); + + //push the "global" functions + luaL_setfuncs(L, funcs, 0); + + //push the substable + for (const luaL_Reg* lib = libs; lib->func; lib++) { + lua_pushcfunction(L, lib->func); + lua_setfield(L, -2, lib->name); + } + return 1; +} \ No newline at end of file diff --git a/server/rooms/room_system_api.hpp b/server/rooms/room_system_api.hpp new file mode 100644 index 0000000..9006ce5 --- /dev/null +++ b/server/rooms/room_system_api.hpp @@ -0,0 +1,34 @@ +/* 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 ROOMSYSTEMAPI_HPP_ +#define ROOMSYSTEMAPI_HPP_ + +#if defined(__MINGW32__) + #include "lua/lua.hpp" +#else + #include "lua.hpp" +#endif + +#define TORTUGA_ROOM_SYSTEM_API "room_system" +LUAMOD_API int openRoomSystemAPI(lua_State* L); + +#endif \ No newline at end of file From 74234684af818a3f478f17c2817800b8c3ceb423 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Fri, 7 Nov 2014 00:07:19 +1100 Subject: [PATCH 16/73] Started planning ServerApp refactoring --- server/main.cpp | 9 +++++++++ server/makefile | 6 +++--- server/server_application.hpp | 11 ----------- server/server_methods.cpp | 17 +++++++++++++++++ 4 files changed, 29 insertions(+), 14 deletions(-) diff --git a/server/main.cpp b/server/main.cpp index fdd4894..3cd5b9b 100644 --- a/server/main.cpp +++ b/server/main.cpp @@ -24,7 +24,10 @@ //singletons #include "account_manager.hpp" #include "character_manager.hpp" +#include "client_manager.hpp" #include "config_utility.hpp" +#include "door_manager.hpp" +#include "monster_manager.hpp" #include "room_manager.hpp" #include "udp_network_utility.hpp" @@ -38,7 +41,10 @@ int main(int argc, char* argv[]) { //create the singletons AccountManager::CreateSingleton(); CharacterManager::CreateSingleton(); + ClientManager::CreateSingleton(); ConfigUtility::CreateSingleton(); + DoorManager::CreateSingleton(); + MonsterManager::CreateSingleton(); RoomManager::CreateSingleton(); UDPNetworkUtility::CreateSingleton(); @@ -55,7 +61,10 @@ int main(int argc, char* argv[]) { //delete the singletons AccountManager::DeleteSingleton(); CharacterManager::DeleteSingleton(); + ClientManager::DeleteSingleton(); ConfigUtility::DeleteSingleton(); + DoorManager::DeleteSingleton(); + MonsterManager::DeleteSingleton(); RoomManager::DeleteSingleton(); UDPNetworkUtility::DeleteSingleton(); } diff --git a/server/makefile b/server/makefile index 2cba03c..b798e8b 100644 --- a/server/makefile +++ b/server/makefile @@ -1,5 +1,5 @@ #include directories -INCLUDES+=. accounts characters rooms server_utilities ../common/debugging ../common/gameplay ../common/map ../common/network ../common/network/packet_types ../common/utilities +INCLUDES+=. accounts characters clients doors entities monsters rooms server_utilities ../common/debugging ../common/gameplay ../common/map ../common/network ../common/network/packet_types ../common/utilities #libraries #the order of the $(LIBS) is important, at least for MinGW @@ -24,7 +24,7 @@ OUTDIR=../out OUT=$(addprefix $(OUTDIR)/,server) #targets -all: $(OUT) +all: $(OBJ) $(OUT) $(MAKE) -C accounts $(MAKE) -C characters $(MAKE) -C clients @@ -33,7 +33,7 @@ all: $(OUT) $(MAKE) -C monsters $(MAKE) -C rooms $(MAKE) -C server_utilities -# $(CXX) $(CXXFLAGS) -o $(OUT) $(OBJ) $(LIBS) + $(CXX) $(CXXFLAGS) -o $(OUT) $(OBJ) $(LIBS) $(OBJ): | $(OBJDIR) diff --git a/server/server_application.hpp b/server/server_application.hpp index ee27742..64fe13c 100644 --- a/server/server_application.hpp +++ b/server/server_application.hpp @@ -96,20 +96,9 @@ private: //APIs and utilities sqlite3* database = nullptr; lua_State* luaState = nullptr; - UDPNetworkUtility& network = UDPNetworkUtility::GetSingleton(); - ConfigUtility& config = ConfigUtility::GetSingleton(); - - //simple tables - std::map clientMap; - - //managers - AccountManager& accountMgr = AccountManager::GetSingleton(); - CharacterManager& characterMgr = CharacterManager::GetSingleton(); - RoomManager& roomMgr = RoomManager::GetSingleton(); //misc bool running = true; - int clientIndex = 0; }; #endif diff --git a/server/server_methods.cpp b/server/server_methods.cpp index 79f8d46..0d07d01 100644 --- a/server/server_methods.cpp +++ b/server/server_methods.cpp @@ -28,12 +28,14 @@ //basic connections //------------------------- +//SET: utility void ServerApplication::HandlePing(ServerPacket* const argPacket) { ServerPacket newPacket; newPacket.type = SerialPacketType::PONG; network.SendTo(argPacket->srcAddress, &newPacket); } +//SET: utility/manager void ServerApplication::HandlePong(ServerPacket* const argPacket) { //find and update the specified client for (auto& it : clientMap) { @@ -46,6 +48,7 @@ void ServerApplication::HandlePong(ServerPacket* const argPacket) { } } +//SET: utility void ServerApplication::HandleBroadcastRequest(ServerPacket* const argPacket) { //send the server's data ServerPacket newPacket; @@ -58,6 +61,7 @@ void ServerApplication::HandleBroadcastRequest(ServerPacket* const argPacket) { network.SendTo(argPacket->srcAddress, static_cast(&newPacket)); } +//SET: connections void ServerApplication::HandleJoinRequest(ClientPacket* const argPacket) { //load the user account //TODO: handle passwords @@ -91,6 +95,7 @@ void ServerApplication::HandleJoinRequest(ClientPacket* const argPacket) { std::cout << "New connection, " << clientMap.size() << " clients and " << accountMgr.GetLoadedCount() << " accounts total" << std::endl; } +//SET: connections void ServerApplication::HandleDisconnect(ClientPacket* const argPacket) { //TODO: authenticate who is disconnecting/kicking /*Pseudocode: @@ -127,6 +132,7 @@ void ServerApplication::HandleDisconnect(ClientPacket* const argPacket) { std::cout << "Disconnection, " << clientMap.size() << " clients and " << accountMgr.GetLoadedCount() << " accounts total" << std::endl; } +//SET: connections void ServerApplication::HandleShutdown(ClientPacket* const argPacket) { //TODO: authenticate who is shutting the server down /*Pseudocode: @@ -152,6 +158,7 @@ void ServerApplication::HandleShutdown(ClientPacket* const argPacket) { //map management //------------------------- +//SET: resources void ServerApplication::HandleRegionRequest(RegionPacket* const argPacket) { RegionPacket newPacket; @@ -171,6 +178,7 @@ void ServerApplication::HandleRegionRequest(RegionPacket* const argPacket) { //Character Management //------------------------- +//SET: entities void ServerApplication::HandleCharacterNew(CharacterPacket* const argPacket) { //NOTE: misnomer, try to load the character first int characterIndex = characterMgr.Load(argPacket->accountIndex, argPacket->handle, argPacket->avatar); @@ -203,6 +211,7 @@ void ServerApplication::HandleCharacterNew(CharacterPacket* const argPacket) { PumpPacket(&newPacket); } +//SET: entities void ServerApplication::HandleCharacterDelete(CharacterPacket* const argPacket) { //NOTE: Disconnecting only unloads a character, this explicitly deletes it @@ -234,6 +243,7 @@ void ServerApplication::HandleCharacterDelete(CharacterPacket* const argPacket) PumpCharacterUnload(characterIndex); } +//SET: entities void ServerApplication::HandleCharacterUpdate(CharacterPacket* const argPacket) { CharacterData* character = characterMgr.Get(argPacket->characterIndex); @@ -259,6 +269,7 @@ void ServerApplication::HandleCharacterUpdate(CharacterPacket* const argPacket) //mismanagement //------------------------- +//SET: delete void ServerApplication::HandleSynchronize(ClientPacket* const argPacket) { //TODO: compensate for large distances //NOTE: I quite dislike this function @@ -282,6 +293,7 @@ void ServerApplication::HandleSynchronize(ClientPacket* const argPacket) { //utility methods //------------------------- +//SET: utility/manager void ServerApplication::CheckClientConnections() { for (auto& it : clientMap) { if (std::chrono::steady_clock::now() - it.second.GetLastBeat() > std::chrono::seconds(3)) { @@ -299,6 +311,7 @@ void ServerApplication::CheckClientConnections() { } } +//SET: utility/manager void ServerApplication::CleanupLostConnection(int clientIndex) { //NOTE: This assumes each player has only one account and character at a time //TODO: handle multiple characters (bots, etc.) @@ -341,14 +354,17 @@ void ServerApplication::CleanupLostConnection(int clientIndex) { std::cout << clientMap.size() << " clients and " << accountMgr.GetLoadedCount() << " accounts total" << std::endl; } +//SET: utility //TODO: a function that only sends to characters in a certain proximity +//SET: utility void ServerApplication::PumpPacket(SerialPacket* const argPacket) { for (auto& it : clientMap) { network.SendTo(it.second.GetAddress(), argPacket); } } +//?? void ServerApplication::PumpCharacterUnload(int uid) { //delete the client-side character(s) //NOTE: This is a strange function @@ -358,6 +374,7 @@ void ServerApplication::PumpCharacterUnload(int uid) { PumpPacket(static_cast(&newPacket)); } +//SET: utility void ServerApplication::CopyCharacterToPacket(CharacterPacket* const packet, int characterIndex) { CharacterData* character = characterMgr.Get(characterIndex); if (!character) { From f7ba34dcecf450d212e9300098de566d48ffb4e2 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Sat, 8 Nov 2014 16:33:27 +1100 Subject: [PATCH 17/73] Fleshed out ClientManager * Fleshed out the ClientManager internals * Folded some ServerApplication methods into ClientManager * Removed Manager references from ServerApplication * Corrected server_methods.cpp (compiles) --- server/clients/client_manager.cpp | 83 ++++++++++++++++++++++------- server/clients/client_manager.hpp | 17 ++++-- server/clients/makefile | 2 +- server/doors/door_manager.hpp | 4 +- server/monsters/monster_manager.hpp | 4 +- server/server_application.hpp | 11 ---- server/server_logic.cpp | 56 ++++++++++++------- server/server_methods.cpp | 38 ------------- 8 files changed, 117 insertions(+), 98 deletions(-) diff --git a/server/clients/client_manager.cpp b/server/clients/client_manager.cpp index 8fa0cb1..d2ae9bf 100644 --- a/server/clients/client_manager.cpp +++ b/server/clients/client_manager.cpp @@ -21,46 +21,89 @@ */ #include "client_manager.hpp" +#include "udp_network_utility.hpp" + +#include + +int ClientManager::CheckConnections() { + for (auto& it : elementMap) { + //3 seconds between beats + if (ClientData::Clock::now() - it.second.GetLastBeat() > std::chrono::seconds(3)) { + ServerPacket newPacket; + newPacket.type = SerialPacketType::PING; + UDPNetworkUtility::GetSingleton().SendTo(it.second.GetAddress(), &newPacket); + it.second.IncrementAttempts(); + } + } + + for (auto& it : elementMap) { + if (it.second.GetAttempts() > 2) { + int ret = it.first; + elementMap.erase(it.first); + return ret; + } + } + + return -1; +} + +void ClientManager::HandlePong(ServerPacket* const argPacket) { + //find and update the specified client + for (auto& it : elementMap) { + if (it.second.GetAddress().host == argPacket->srcAddress.host && + it.second.GetAddress().port == argPacket->srcAddress.port + ) { + it.second.ResetAttempts(); + return; + } + } +} + int ClientManager::Create(IPaddress add) { - //TODO -} - -int ClientManager::Load(IPaddress add) { - //TODO -} - -int ClientManager::Save(int uid) { - //TODO + ClientData& client = elementMap[counter]; + client.SetAddress(add); + return counter++; } void ClientManager::Unload(int uid) { - //TODO -} - -void ClientManager::Delete(int uid) { - //TODO + elementMap.erase(uid); } void ClientManager::UnloadAll() { - //TODO + elementMap.clear(); } void ClientManager::UnloadIf(std::function)> fn) { - //TODO + std::map::iterator it = elementMap.begin(); + while (it != elementMap.end()) { + if (fn(*it)) { + it = elementMap.erase(it); + //TODO: ? disconnect, unload characters, notify other clients + } + else { + ++it; + } + } } ClientData* ClientManager::Get(int uid) { - //TODO + std::map::iterator it = elementMap.find(uid); + + if (it == elementMap.end()) { + return nullptr; + } + + return &it->second; } int ClientManager::GetLoadedCount() { - //TODO + return elementMap.size(); } int ClientManager::GetTotalCount() { - //TODO + return elementMap.size(); } std::map* ClientManager::GetContainer() { - //TODO + return &elementMap; } \ No newline at end of file diff --git a/server/clients/client_manager.hpp b/server/clients/client_manager.hpp index 756fe0d..d90fb57 100644 --- a/server/clients/client_manager.hpp +++ b/server/clients/client_manager.hpp @@ -24,6 +24,7 @@ #include "client_data.hpp" #include "manager_interface.hpp" +#include "server_packet.hpp" #include "singleton.hpp" #include "SDL/SDL_net.h" @@ -31,16 +32,17 @@ #include class ClientManager: - Singleton, - ManagerInterface + public Singleton, + public ManagerInterface { public: + //methods + int CheckConnections(); + void HandlePong(ServerPacket* const argPacket); + //common public methods int Create(IPaddress) override; - int Load(IPaddress) override; - int Save(int uid) override; void Unload(int uid) override; - void Delete(int uid) override; void UnloadAll() override; void UnloadIf(std::function)> fn) override; @@ -57,6 +59,11 @@ private: ClientManager() = default; ~ClientManager() = default; + //EMPTY + int Load(IPaddress) override { return -1; } + int Save(int uid) override { return -1; } + void Delete(int uid) override { return; } + int counter = 0; }; diff --git a/server/clients/makefile b/server/clients/makefile index 2a5c671..4eb98bd 100644 --- a/server/clients/makefile +++ b/server/clients/makefile @@ -1,5 +1,5 @@ #config -INCLUDES+=. ../server_utilities ../../common/utilities +INCLUDES+=. ../server_utilities ../../common/network ../../common/network/packet_types ../../common/utilities LIBS+= CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES)) diff --git a/server/doors/door_manager.hpp b/server/doors/door_manager.hpp index 2933b52..bfed8ed 100644 --- a/server/doors/door_manager.hpp +++ b/server/doors/door_manager.hpp @@ -31,8 +31,8 @@ #include class DoorManager: - Singleton, - ManagerInterface + public Singleton, + public ManagerInterface { public: //common public methods diff --git a/server/monsters/monster_manager.hpp b/server/monsters/monster_manager.hpp index 8a12fbd..5fcc56b 100644 --- a/server/monsters/monster_manager.hpp +++ b/server/monsters/monster_manager.hpp @@ -38,8 +38,8 @@ #include class MonsterManager: - Singleton, - ManagerInterface + public Singleton, + public ManagerInterface { public: //common public methods diff --git a/server/server_application.hpp b/server/server_application.hpp index 64fe13c..e5e578a 100644 --- a/server/server_application.hpp +++ b/server/server_application.hpp @@ -22,16 +22,8 @@ #ifndef SERVERAPPLICATION_HPP_ #define SERVERAPPLICATION_HPP_ -//server specific stuff, mostly managers -#include "client_data.hpp" -#include "account_manager.hpp" -#include "character_manager.hpp" -#include "room_manager.hpp" - //common utilities -#include "udp_network_utility.hpp" #include "serial_packet.hpp" -#include "config_utility.hpp" #include "singleton.hpp" //APIs @@ -67,8 +59,6 @@ private: void HandlePacket(SerialPacket* const); //basic connections - void HandlePing(ServerPacket* const); - void HandlePong(ServerPacket* const); void HandleBroadcastRequest(ServerPacket* const); void HandleJoinRequest(ClientPacket* const); void HandleDisconnect(ClientPacket* const); @@ -86,7 +76,6 @@ private: void HandleSynchronize(ClientPacket* const); //utility methods - void CheckClientConnections(); //TODO: a function that only sends to characters in a certain proximity void CleanupLostConnection(int index); void PumpPacket(SerialPacket* const); diff --git a/server/server_logic.cpp b/server/server_logic.cpp index 5afdf99..ef25106 100644 --- a/server/server_logic.cpp +++ b/server/server_logic.cpp @@ -21,10 +21,21 @@ */ #include "server_application.hpp" +//managers +#include "account_manager.hpp" +#include "character_manager.hpp" +#include "client_manager.hpp" +#include "room_manager.hpp" + +//utilities +#include "config_utility.hpp" +#include "udp_network_utility.hpp" + //utility functions #include "sql_tools.hpp" #include "utility.hpp" +//std & STL #include #include #include @@ -41,7 +52,8 @@ 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 " << argv[0] << std::endl; - //load the prerequisites + //load the config settings + ConfigUtility& config = ConfigUtility::GetSingleton(); config.Load("rsc/config.cfg", argc, argv); //------------------------- @@ -58,7 +70,7 @@ void ServerApplication::Init(int argc, char* argv[]) { if (SDLNet_Init()) { throw(std::runtime_error("Failed to initialize SDL_net")); } - network.Open(config.Int("server.port")); + UDPNetworkUtility::GetSingleton().Open(config.Int("server.port")); std::cout << "Initialized SDL_net" << std::endl; //Init SQL @@ -77,7 +89,7 @@ void ServerApplication::Init(int argc, char* argv[]) { std::cout << "Initialized lua" << std::endl; - //append config["dir.scripts"] to the module path + //prepend config["dir.scripts"] to the module path if (config["dir.scripts"].size() > 0) { //get the original path lua_getglobal(luaState, "package"); @@ -100,10 +112,10 @@ void ServerApplication::Init(int argc, char* argv[]) { //------------------------- //set the hooks - accountMgr.SetDatabase(database); - characterMgr.SetDatabase(database); + AccountManager::GetSingleton().SetDatabase(database); + CharacterManager::GetSingleton().SetDatabase(database); - roomMgr.SetLuaState(luaState); + RoomManager::GetSingleton().SetLuaState(luaState); std::cout << "Internal managers initialized" << std::endl; @@ -164,14 +176,17 @@ void ServerApplication::Proc() { SerialPacket* packetBuffer = reinterpret_cast(new char[MAX_PACKET_SIZE]); while(running) { //suck in the waiting packets & process them - while(network.Receive(packetBuffer)) { + while(UDPNetworkUtility::GetSingleton().Receive(packetBuffer)) { HandlePacket(packetBuffer); } //update the internals //... //Check connections - CheckClientConnections(); + int disconnected = ClientManager::GetSingleton().CheckConnections(); + if (disconnected != -1) { + //TODO: clean up after this disconnection + } //give the computer a break SDL_Delay(10); @@ -183,17 +198,15 @@ void ServerApplication::Quit() { std::cout << "Shutting down" << std::endl; //close the managers - clientMap.clear(); - accountMgr.UnloadAll(); - characterMgr.UnloadAll(); - //TODO: unload combats - //TODO: unload enemies - roomMgr.UnloadAll(); + ClientManager::GetSingleton().UnloadAll(); + AccountManager::GetSingleton().UnloadAll(); + CharacterManager::GetSingleton().UnloadAll(); + RoomManager::GetSingleton().UnloadAll(); //APIs lua_close(luaState); sqlite3_close_v2(database); - network.Close(); + UDPNetworkUtility::GetSingleton().Close(); SDLNet_Quit(); SDL_Quit(); @@ -206,13 +219,18 @@ void ServerApplication::Quit() { void ServerApplication::HandlePacket(SerialPacket* const argPacket) { switch(argPacket->type) { - //basic connections - case SerialPacketType::PING: - HandlePing(static_cast(argPacket)); + //heartbeat system + case SerialPacketType::PING: { + ServerPacket newPacket; + newPacket.type = SerialPacketType::PONG; + UDPNetworkUtility::GetSingleton().SendTo(argPacket->srcAddress, &newPacket); + } break; case SerialPacketType::PONG: - HandlePong(static_cast(argPacket)); + ClientManager::GetSingleton().HandlePong(static_cast(argPacket)); break; + + //connections case SerialPacketType::BROADCAST_REQUEST: HandleBroadcastRequest(static_cast(argPacket)); break; diff --git a/server/server_methods.cpp b/server/server_methods.cpp index 0d07d01..e13bc47 100644 --- a/server/server_methods.cpp +++ b/server/server_methods.cpp @@ -28,26 +28,6 @@ //basic connections //------------------------- -//SET: utility -void ServerApplication::HandlePing(ServerPacket* const argPacket) { - ServerPacket newPacket; - newPacket.type = SerialPacketType::PONG; - network.SendTo(argPacket->srcAddress, &newPacket); -} - -//SET: utility/manager -void ServerApplication::HandlePong(ServerPacket* const argPacket) { - //find and update the specified client - for (auto& it : clientMap) { - if (it.second.GetAddress().host == argPacket->srcAddress.host && - it.second.GetAddress().port == argPacket->srcAddress.port - ) { - it.second.ResetAttempts(); - break; - } - } -} - //SET: utility void ServerApplication::HandleBroadcastRequest(ServerPacket* const argPacket) { //send the server's data @@ -293,24 +273,6 @@ void ServerApplication::HandleSynchronize(ClientPacket* const argPacket) { //utility methods //------------------------- -//SET: utility/manager -void ServerApplication::CheckClientConnections() { - for (auto& it : clientMap) { - if (std::chrono::steady_clock::now() - it.second.GetLastBeat() > std::chrono::seconds(3)) { - ServerPacket newPacket; - newPacket.type = SerialPacketType::PING; - network.SendTo(it.second.GetAddress(), &newPacket); - it.second.IncrementAttempts(); - } - - if (it.second.GetAttempts() > 2) { - CleanupLostConnection(it.first); - //all iterators are invalid, so we can't continue - break; - } - } -} - //SET: utility/manager void ServerApplication::CleanupLostConnection(int clientIndex) { //NOTE: This assumes each player has only one account and character at a time From a1c20959fefea45d33a64559c5df6a1c2490f5d9 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Sun, 9 Nov 2014 23:15:09 +1100 Subject: [PATCH 18/73] The server builds using the new packet types; incomplete Most of this was achieved by dummying out calls in HandlePacket(), so the server's actual logic is incomplete. --- common/network/serial_packet_type.hpp | 39 ++++---- common/network/serial_utility.cpp | 52 +++++++---- server/rooms/room_system_api.cpp | 2 +- server/server_application.hpp | 11 +++ server/server_logic.cpp | 130 ++++++++++++++++++-------- server/server_methods.cpp | 64 +++++++------ 6 files changed, 193 insertions(+), 105 deletions(-) diff --git a/common/network/serial_packet_type.hpp b/common/network/serial_packet_type.hpp index b93b51f..e6637af 100644 --- a/common/network/serial_packet_type.hpp +++ b/common/network/serial_packet_type.hpp @@ -27,6 +27,7 @@ * valid data, but it will still be carried in that packet's format. */ +//TODO: This needs to be smoothed out enum class SerialPacketType { //default: there is something wrong NONE = 0, @@ -57,6 +58,14 @@ enum class SerialPacketType { DISCONNECT_REQUEST, DISCONNECT_FORCED, + //load the account + LOGIN_REQUEST, + LOGIN_RESPONSE, + + //unload the account + LOGOUT_REQUEST, + LOGOUT_RESPONSE, + //shut down the server SHUTDOWN_REQUEST, @@ -66,7 +75,7 @@ enum class SerialPacketType { //------------------------- //map data - REGION_REQUEST, + REGION_REQUEST, //NOTE: technically a query REGION_CONTENT, //------------------------- @@ -78,25 +87,23 @@ enum class SerialPacketType { // statistics //------------------------- - //all stats - CHARACTER_STATS_REQUEST, - CHARACTER_STATS_RESPONSE, - //character management - //NOTE: The server sends create & delete messages to the clients, but the clients... don't? - CHARACTER_CREATE - CHARACTER_DELETE - CHARACTER_LOAD - CHARACTER_UNLOAD + CHARACTER_CREATE, + CHARACTER_DELETE, + CHARACTER_LOAD, + CHARACTER_UNLOAD, //find out info from the server - CHARACTER_QUERY_EXISTS - CHARACTER_QUERY_LOCATION + QUERY_CHARACTER_EXISTS, + QUERY_CHARACTER_STATS, + QUERY_CHARACTER_LOCATION, //set the info in the server - CHARACTER_SET_ROOM - CHARACTER_SET_ORIGIN - CHARACTER_SET_MOTION + CHARACTER_SET_ROOM, + CHARACTER_SET_ORIGIN, + CHARACTER_SET_MOTION, + + //TODO: enemy management //------------------------- //TextPacket @@ -107,9 +114,9 @@ enum class SerialPacketType { TEXT_BROADCAST, //rejection/error messages - SHUTDOWN_REJECTION, JOIN_REJECTION, CHARACTER_REJECTION, + SHUTDOWN_REJECTION, //------------------------- //not used diff --git a/common/network/serial_utility.cpp b/common/network/serial_utility.cpp index 6572887..fe2e87e 100644 --- a/common/network/serial_utility.cpp +++ b/common/network/serial_utility.cpp @@ -54,26 +54,35 @@ void serializePacket(void* buffer, SerialPacketBase* packet) { break; case SerialPacketType::JOIN_REQUEST: case SerialPacketType::JOIN_RESPONSE: - case SerialPacketType::SYNCHRONIZE: - case SerialPacketType::DISCONNECT: - case SerialPacketType::SHUTDOWN: + case SerialPacketType::DISCONNECT_REQUEST: + case SerialPacketType::DISCONNECT_FORCED: + case SerialPacketType::LOGIN_REQUEST: + case SerialPacketType::LOGIN_RESPONSE: + case SerialPacketType::LOGOUT_REQUEST: + case SerialPacketType::LOGOUT_RESPONSE: + case SerialPacketType::SHUTDOWN_REQUEST: serializeClient(buffer, static_cast(packet)); break; case SerialPacketType::REGION_REQUEST: case SerialPacketType::REGION_CONTENT: serializeRegion(buffer, static_cast(packet)); break; - case SerialPacketType::CHARACTER_NEW: + case SerialPacketType::CHARACTER_CREATE: case SerialPacketType::CHARACTER_DELETE: - case SerialPacketType::CHARACTER_UPDATE: - case SerialPacketType::CHARACTER_STATS_REQUEST: - case SerialPacketType::CHARACTER_STATS_RESPONSE: + case SerialPacketType::CHARACTER_LOAD: + case SerialPacketType::CHARACTER_UNLOAD: + case SerialPacketType::QUERY_CHARACTER_EXISTS: + case SerialPacketType::QUERY_CHARACTER_STATS: + case SerialPacketType::QUERY_CHARACTER_LOCATION: + case SerialPacketType::CHARACTER_SET_ROOM: + case SerialPacketType::CHARACTER_SET_ORIGIN: + case SerialPacketType::CHARACTER_SET_MOTION: serializeCharacter(buffer, static_cast(packet)); break; case SerialPacketType::TEXT_BROADCAST: case SerialPacketType::JOIN_REJECTION: - case SerialPacketType::SHUTDOWN_REJECTION: case SerialPacketType::CHARACTER_REJECTION: + case SerialPacketType::SHUTDOWN_REJECTION: serializeText(buffer, static_cast(packet)); break; } @@ -84,7 +93,7 @@ void deserializePacket(void* buffer, SerialPacketBase* packet) { SerialPacketType type; memcpy(&type, buffer, sizeof(SerialPacketType)); - switch(type) { + switch(packet->type) { case SerialPacketType::PING: case SerialPacketType::PONG: case SerialPacketType::BROADCAST_REQUEST: @@ -93,26 +102,35 @@ void deserializePacket(void* buffer, SerialPacketBase* packet) { break; case SerialPacketType::JOIN_REQUEST: case SerialPacketType::JOIN_RESPONSE: - case SerialPacketType::SYNCHRONIZE: - case SerialPacketType::DISCONNECT: - case SerialPacketType::SHUTDOWN: + case SerialPacketType::DISCONNECT_REQUEST: + case SerialPacketType::DISCONNECT_FORCED: + case SerialPacketType::LOGIN_REQUEST: + case SerialPacketType::LOGIN_RESPONSE: + case SerialPacketType::LOGOUT_REQUEST: + case SerialPacketType::LOGOUT_RESPONSE: + case SerialPacketType::SHUTDOWN_REQUEST: deserializeClient(buffer, static_cast(packet)); break; case SerialPacketType::REGION_REQUEST: case SerialPacketType::REGION_CONTENT: deserializeRegion(buffer, static_cast(packet)); break; - case SerialPacketType::CHARACTER_NEW: + case SerialPacketType::CHARACTER_CREATE: case SerialPacketType::CHARACTER_DELETE: - case SerialPacketType::CHARACTER_UPDATE: - case SerialPacketType::CHARACTER_STATS_REQUEST: - case SerialPacketType::CHARACTER_STATS_RESPONSE: + case SerialPacketType::CHARACTER_LOAD: + case SerialPacketType::CHARACTER_UNLOAD: + case SerialPacketType::QUERY_CHARACTER_EXISTS: + case SerialPacketType::QUERY_CHARACTER_STATS: + case SerialPacketType::QUERY_CHARACTER_LOCATION: + case SerialPacketType::CHARACTER_SET_ROOM: + case SerialPacketType::CHARACTER_SET_ORIGIN: + case SerialPacketType::CHARACTER_SET_MOTION: deserializeCharacter(buffer, static_cast(packet)); break; case SerialPacketType::TEXT_BROADCAST: case SerialPacketType::JOIN_REJECTION: - case SerialPacketType::SHUTDOWN_REJECTION: case SerialPacketType::CHARACTER_REJECTION: + case SerialPacketType::SHUTDOWN_REJECTION: deserializeText(buffer, static_cast(packet)); break; } diff --git a/server/rooms/room_system_api.cpp b/server/rooms/room_system_api.cpp index fcbb205..35c041a 100644 --- a/server/rooms/room_system_api.cpp +++ b/server/rooms/room_system_api.cpp @@ -40,7 +40,7 @@ static const luaL_Reg libs[] = { {nullptr, nullptr} }; -int openMapSystemAPI(lua_State* L) { +int openRoomSystemAPI(lua_State* L) { //create the table luaL_newlibtable(L, libs); diff --git a/server/server_application.hpp b/server/server_application.hpp index 012c41d..a91bbbc 100644 --- a/server/server_application.hpp +++ b/server/server_application.hpp @@ -98,6 +98,17 @@ private: sqlite3* database = nullptr; lua_State* luaState = nullptr; + //ugly references; I hate this + AccountManager& accountMgr = AccountManager::GetSingleton(); + CharacterManager& characterMgr = CharacterManager::GetSingleton(); + ClientManager& clientMgr = ClientManager::GetSingleton(); + DoorManager& doorMgr = DoorManager::GetSingleton(); + MonsterManager& monsterMgr = MonsterManager::GetSingleton(); + RoomManager& roomMgr = RoomManager::GetSingleton(); + + ConfigUtility& config = ConfigUtility::GetSingleton(); + UDPNetworkUtility& network = UDPNetworkUtility::GetSingleton(); + //misc bool running = true; }; diff --git a/server/server_logic.cpp b/server/server_logic.cpp index 0c4484c..0c80ff8 100644 --- a/server/server_logic.cpp +++ b/server/server_logic.cpp @@ -43,7 +43,6 @@ void ServerApplication::Init(int argc, char* argv[]) { std::cout << "Beginning " << argv[0] << std::endl; //load the config settings - ConfigUtility& config = ConfigUtility::GetSingleton(); config.Load("rsc/config.cfg", argc, argv); //------------------------- @@ -60,7 +59,7 @@ void ServerApplication::Init(int argc, char* argv[]) { if (SDLNet_Init()) { throw(std::runtime_error("Failed to initialize SDL_net")); } - UDPNetworkUtility::GetSingleton().Open(config.Int("server.port")); + network.Open(config.Int("server.port")); std::cout << "Initialized SDL_net" << std::endl; //Init SQL @@ -102,10 +101,10 @@ void ServerApplication::Init(int argc, char* argv[]) { //------------------------- //set the hooks - AccountManager::GetSingleton().SetDatabase(database); - CharacterManager::GetSingleton().SetDatabase(database); + accountMgr.SetDatabase(database); + characterMgr.SetDatabase(database); - RoomManager::GetSingleton().SetLuaState(luaState); + roomMgr.SetLuaState(luaState); std::cout << "Internal managers initialized" << std::endl; @@ -173,9 +172,23 @@ void ServerApplication::Proc() { //... //Check connections - int disconnected = ClientManager::GetSingleton().CheckConnections(); + int disconnected = clientMgr.CheckConnections(); if (disconnected != -1) { - //TODO: clean up after this disconnection + //find and unload the accounts associated with this client + accountMgr.UnloadIf([&](std::pair account) -> bool { + if (account.second.GetClientIndex() == disconnected) { + //find and unload the characters associated with this account + characterMgr.UnloadIf([&](std::pair character) -> bool { + if (character.second.GetOwner() == account.first) { + PumpCharacterUnload(character.first); + return true; + } + return false; + }); + return true; + } + return false; + }); } //give the computer a break @@ -187,16 +200,20 @@ void ServerApplication::Proc() { void ServerApplication::Quit() { std::cout << "Shutting down" << std::endl; + //TODO: save the server state + //close the managers - ClientManager::GetSingleton().UnloadAll(); - AccountManager::GetSingleton().UnloadAll(); - CharacterManager::GetSingleton().UnloadAll(); - RoomManager::GetSingleton().UnloadAll(); + accountMgr.UnloadAll(); + characterMgr.UnloadAll(); + clientMgr.UnloadAll(); + doorMgr.UnloadAll(); + monsterMgr.UnloadAll(); + roomMgr.UnloadAll(); //APIs lua_close(luaState); sqlite3_close_v2(database); - UDPNetworkUtility::GetSingleton().Close(); + network.Close(); SDLNet_Quit(); SDL_Quit(); @@ -213,60 +230,93 @@ void ServerApplication::HandlePacket(SerialPacket* const argPacket) { case SerialPacketType::PING: { ServerPacket newPacket; newPacket.type = SerialPacketType::PONG; - UDPNetworkUtility::GetSingleton().SendTo(argPacket->srcAddress, &newPacket); + network.SendTo(argPacket->srcAddress, &newPacket); } break; case SerialPacketType::PONG: - ClientManager::GetSingleton().HandlePong(static_cast(argPacket)); + clientMgr.HandlePong(static_cast(argPacket)); break; - //connections + //client connections case SerialPacketType::BROADCAST_REQUEST: - HandleBroadcastRequest(static_cast(argPacket)); +// HandleBroadcastRequest(static_cast(argPacket)); break; case SerialPacketType::JOIN_REQUEST: - HandleJoinRequest(static_cast(argPacket)); +// HandleJoinRequest(static_cast(argPacket)); break; - case SerialPacketType::DISCONNECT: - HandleDisconnect(static_cast(argPacket)); - break; - case SerialPacketType::SHUTDOWN: - HandleShutdown(static_cast(argPacket)); + case SerialPacketType::LOGIN_REQUEST: +// HandleLoginRequest(static_cast(argPacket)); break; - //map management + //client disconnections + case SerialPacketType::DISCONNECT_REQUEST: +// HandleDisconnectRequest(static_cast(argPacket)); + break; + case SerialPacketType::DISCONNECT_FORCED: +// HandleDisconnectForced(static_cast(argPacket)); + break; + case SerialPacketType::LOGOUT_REQUEST: +// HandleLogoutRequest(static_cast(argPacket)); + break; + + //server commands + case SerialPacketType::SHUTDOWN_REQUEST: +// HandleShutdownRequest(static_cast(argPacket)); + break; + + //data management & queries case SerialPacketType::REGION_REQUEST: - HandleRegionRequest(static_cast(argPacket)); +// HandleRegionRequest(static_cast(argPacket)); + break; + case SerialPacketType::QUERY_CHARACTER_EXISTS: +// HandleCharacterStatsRequest(static_cast(argPacket)); + break; + case SerialPacketType::QUERY_CHARACTER_STATS: +// HandleCharacterStatsRequest(static_cast(argPacket)); + break; + case SerialPacketType::QUERY_CHARACTER_LOCATION: +// HandleCharacterStatsRequest(static_cast(argPacket)); + break; + case SerialPacketType::TEXT_BROADCAST: +// HandleCharacterStatsRequest(static_cast(argPacket)); break; - - //combat management - //TODO: combat management //character management - case SerialPacketType::CHARACTER_NEW: - HandleCharacterNew(static_cast(argPacket)); + case SerialPacketType::CHARACTER_CREATE: +// HandleCharacterNew(static_cast(argPacket)); break; case SerialPacketType::CHARACTER_DELETE: - HandleCharacterDelete(static_cast(argPacket)); +// HandleCharacterDelete(static_cast(argPacket)); break; - case SerialPacketType::CHARACTER_UPDATE: - case SerialPacketType::CHARACTER_STATS_REQUEST: - HandleCharacterUpdate(static_cast(argPacket)); + case SerialPacketType::CHARACTER_LOAD: +// HandleCharacterNew(static_cast(argPacket)); + break; + case SerialPacketType::CHARACTER_UNLOAD: +// HandleCharacterDelete(static_cast(argPacket)); + break; + + //character movement + case SerialPacketType::CHARACTER_SET_ROOM: +// HandleCharacterUpdate(static_cast(argPacket)); + break; + case SerialPacketType::CHARACTER_SET_ORIGIN: +// HandleCharacterUpdate(static_cast(argPacket)); + break; + case SerialPacketType::CHARACTER_SET_MOTION: +// HandleCharacterUpdate(static_cast(argPacket)); break; //enemy management //TODO: enemy management - //mismanagement - case SerialPacketType::SYNCHRONIZE: - HandleSynchronize(static_cast(argPacket)); - break; + //TODO: text //handle errors default: { - std::string msg = "Unknown SerialPacketType encountered in the server: "; - msg += to_string_custom(static_cast(argPacket->type)); - throw(std::runtime_error(msg)); + std::ostringstream msg; + msg << "Unknown SerialPacketType encountered in the server: "; + msg << to_string_custom(static_cast(argPacket->type)); + throw(std::runtime_error(msg.str())); } break; } diff --git a/server/server_methods.cpp b/server/server_methods.cpp index 5531221..d73d899 100644 --- a/server/server_methods.cpp +++ b/server/server_methods.cpp @@ -23,6 +23,7 @@ #include #include +#include //------------------------- //basic connections @@ -43,18 +44,24 @@ void ServerApplication::HandleBroadcastRequest(ServerPacket* const argPacket) { //SET: connections void ServerApplication::HandleJoinRequest(ClientPacket* const argPacket) { + //register the client + int clientIndex = clientMgr.Create(argPacket->srcAddress); + //load the user account //TODO: handle passwords int accountIndex = accountMgr.Load(argPacket->username, clientIndex); //Cannot load if (accountIndex < 0) { + std::ostringstream msg; + msg << "Account already loaded: " << argPacket->username; + TextPacket newPacket; newPacket.type = SerialPacketType::JOIN_REJECTION; - std::string msg = std::string() + "Account already loaded: " + argPacket->username; memset(newPacket.name, 0, PACKET_STRING_SIZE); - strncpy(newPacket.text, msg.c_str(), PACKET_STRING_SIZE); //BUG: If the name is too long this would truncate it + strncpy(newPacket.text, msg.str().c_str(), PACKET_STRING_SIZE); network.SendTo(argPacket->srcAddress, static_cast(&newPacket)); + clientMgr.Unload(clientIndex); return; } @@ -66,13 +73,8 @@ void ServerApplication::HandleJoinRequest(ClientPacket* const argPacket) { network.SendTo(argPacket->srcAddress, static_cast(&newPacket)); - //register the client - ClientData newClient; - newClient.SetAddress(argPacket->srcAddress); - clientMap[clientIndex++] = newClient; - //finished this routine - std::cout << "New connection, " << clientMap.size() << " clients and " << accountMgr.GetLoadedCount() << " accounts total" << std::endl; + std::cout << "New connection, " << clientMgr.GetLoadedCount() << " clients and " << accountMgr.GetLoadedCount() << " accounts total" << std::endl; } //SET: connections @@ -90,7 +92,7 @@ void ServerApplication::HandleDisconnect(ClientPacket* const argPacket) { //forward to the specified client network.SendTo( - clientMap[ accountMgr.Get(argPacket->accountIndex)->GetClientIndex() ].GetAddress(), + clientMgr.Get(accountMgr.Get(argPacket->accountIndex)->GetClientIndex())->GetAddress(), static_cast(argPacket) ); @@ -105,11 +107,11 @@ void ServerApplication::HandleDisconnect(ClientPacket* const argPacket) { }); //erase the in-memory stuff - clientMap.erase(accountMgr.Get(argPacket->accountIndex)->GetClientIndex()); + clientMgr.Unload(accountMgr.Get(argPacket->accountIndex)->GetClientIndex()); accountMgr.Unload(argPacket->accountIndex); //finished this routine - std::cout << "Disconnection, " << clientMap.size() << " clients and " << accountMgr.GetLoadedCount() << " accounts total" << std::endl; + std::cout << "Disconnection, " << clientMgr.GetLoadedCount() << " clients and " << accountMgr.GetLoadedCount() << " accounts total" << std::endl; } //SET: connections @@ -127,7 +129,7 @@ void ServerApplication::HandleShutdown(ClientPacket* const argPacket) { //disconnect all clients ClientPacket newPacket; - newPacket.type = SerialPacketType::DISCONNECT; + newPacket.type = SerialPacketType::DISCONNECT_FORCED; PumpPacket(&newPacket); //finished this routine @@ -166,27 +168,27 @@ void ServerApplication::HandleCharacterNew(CharacterPacket* const argPacket) { //cannot load or create if (characterIndex < 0) { //build the error message - std::string msg; + std::ostringstream msg; if (characterIndex == -1) { - msg += "Character already loaded: "; + msg << "Character already loaded: "; } else if (characterIndex == -2) { - msg += "Character already exists: "; + msg << "Character already exists: "; } - msg += argPacket->handle; + msg << argPacket->handle; //create, fill and send the packet TextPacket newPacket; newPacket.type = SerialPacketType::CHARACTER_REJECTION; memset(newPacket.name, 0, PACKET_STRING_SIZE); - strncpy(newPacket.text, msg.c_str(), PACKET_STRING_SIZE); + strncpy(newPacket.text, msg.str().c_str(), PACKET_STRING_SIZE); network.SendTo(argPacket->srcAddress, static_cast(&newPacket)); return; } //send this new character to all clients CharacterPacket newPacket; - newPacket.type = SerialPacketType::CHARACTER_NEW; + newPacket.type = SerialPacketType::CHARACTER_CREATE; CopyCharacterToPacket(&newPacket, characterIndex); PumpPacket(&newPacket); } @@ -255,15 +257,15 @@ void ServerApplication::HandleSynchronize(ClientPacket* const argPacket) { //NOTE: I quite dislike this function //send all of the server's data to this client - ClientData& client = clientMap[argPacket->clientIndex]; + ClientData* client = clientMgr.Get(argPacket->clientIndex); //send all characters CharacterPacket newPacket; - newPacket.type = SerialPacketType::CHARACTER_UPDATE; + newPacket.type = SerialPacketType::CHARACTER_SET_ORIGIN; for (auto& it : *characterMgr.GetContainer()) { CopyCharacterToPacket(&newPacket, it.first); - network.SendTo(client.GetAddress(), static_cast(&newPacket)); + network.SendTo(client->GetAddress(), static_cast(&newPacket)); } //TODO: more in HandleSynchronize() @@ -278,6 +280,11 @@ void ServerApplication::CleanupLostConnection(int clientIndex) { //NOTE: This assumes each player has only one account and character at a time //TODO: handle multiple characters (bots, etc.) + //send a disconnection message just in case + ClientPacket newPacket; + newPacket.type = SerialPacketType::DISCONNECT_FORCED; + network.SendTo(clientMgr.Get(clientIndex)->GetAddress(), &newPacket); + //find the account int accountIndex = -1; for (auto& it : *accountMgr.GetContainer()) { @@ -296,15 +303,10 @@ void ServerApplication::CleanupLostConnection(int clientIndex) { } } - //send a disconnection message just in case - ClientPacket newPacket; - newPacket.type = SerialPacketType::DISCONNECT; - network.SendTo(clientMap[clientIndex].GetAddress(), &newPacket); - //clean up this mess characterMgr.Unload(characterIndex); accountMgr.Unload(accountIndex); - clientMap.erase(clientIndex); + clientMgr.Unload(clientIndex); PumpCharacterUnload(characterIndex); @@ -313,7 +315,7 @@ void ServerApplication::CleanupLostConnection(int clientIndex) { std::cerr << "\tClient: " << clientIndex << std::endl; std::cerr << "\tAccount: " << accountIndex << std::endl; std::cerr << "\tCharacter: " << characterIndex << std::endl; - std::cout << clientMap.size() << " clients and " << accountMgr.GetLoadedCount() << " accounts total" << std::endl; + std::cout << clientMgr.GetLoadedCount() << " clients and " << accountMgr.GetLoadedCount() << " accounts total" << std::endl; } //SET: utility @@ -321,12 +323,12 @@ void ServerApplication::CleanupLostConnection(int clientIndex) { //SET: utility void ServerApplication::PumpPacket(SerialPacket* const argPacket) { - for (auto& it : clientMap) { + for (auto& it : *clientMgr.GetContainer()) { network.SendTo(it.second.GetAddress(), argPacket); } } -//SET: utility +//SET: utility/delete void ServerApplication::PumpCharacterUnload(int uid) { //delete the client-side character(s) //NOTE: This is a strange function @@ -336,7 +338,7 @@ void ServerApplication::PumpCharacterUnload(int uid) { PumpPacket(static_cast(&newPacket)); } -//SET: utility +//SET: utility/delete void ServerApplication::CopyCharacterToPacket(CharacterPacket* const packet, int characterIndex) { CharacterData* character = characterMgr.Get(characterIndex); if (!character) { From 100c4f652288a537dcb9cc2659e311a52d549007 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Fri, 14 Nov 2014 10:01:24 +1100 Subject: [PATCH 19/73] Added TODO --- server/rooms/room_manager_api.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/server/rooms/room_manager_api.cpp b/server/rooms/room_manager_api.cpp index 217577d..880022f 100644 --- a/server/rooms/room_manager_api.cpp +++ b/server/rooms/room_manager_api.cpp @@ -48,6 +48,8 @@ int unloadRoom(lua_State* L) { return 0; } +//TODO: lua API RoomManager.GetRoom(uid) + static const luaL_Reg roomManagerLib[] = { {"CreateRoom", createRoom}, {"UnloadRoom", unloadRoom}, @@ -57,4 +59,4 @@ static const luaL_Reg roomManagerLib[] = { LUAMOD_API int openRoomManagerAPI(lua_State* L) { luaL_newlib(L, roomManagerLib); return 1; -} \ No newline at end of file +} From d35ab24e15df54b71537e598095ba4eaf9bfe6a3 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Fri, 14 Nov 2014 10:02:15 +1100 Subject: [PATCH 20/73] Added TODO --- server/rooms/room_data.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/server/rooms/room_data.hpp b/server/rooms/room_data.hpp index 65a488d..78612fe 100644 --- a/server/rooms/room_data.hpp +++ b/server/rooms/room_data.hpp @@ -66,6 +66,7 @@ private: std::list entityList; //lua references + //TODO: use RoomData's lua references for load and unload functions int loadRef = LUA_NOREF; int unloadRef = LUA_NOREF; }; From ecd0b43abe5f138b3d0f8bc8e85cf1e6829f7e4d Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Fri, 14 Nov 2014 10:05:00 +1100 Subject: [PATCH 21/73] Corrected comments Because this file was originally copied from the map API, there were references to the map. I've corrected this. --- server/rooms/room_system_api.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/server/rooms/room_system_api.cpp b/server/rooms/room_system_api.cpp index 35c041a..d0d47e0 100644 --- a/server/rooms/room_system_api.cpp +++ b/server/rooms/room_system_api.cpp @@ -21,14 +21,14 @@ */ #include "room_system_api.hpp" -//all map API headers +//all room API headers #include "room_api.hpp" #include "room_manager_api.hpp" //useful "globals" //... -//This mimics linit.c to create a nested collection of all map modules. +//This mimics linit.c to create a nested collection of all room modules. static const luaL_Reg funcs[] = { {nullptr, nullptr} }; @@ -36,7 +36,6 @@ static const luaL_Reg funcs[] = { static const luaL_Reg libs[] = { {"Room", openRoomAPI}, {"RoomManager", openRoomManagerAPI}, -// {"TileSheet", openTileSheetAPI}, {nullptr, nullptr} }; @@ -53,4 +52,4 @@ int openRoomSystemAPI(lua_State* L) { lua_setfield(L, -2, lib->name); } return 1; -} \ No newline at end of file +} From a01d75549fd880e81a086e980d6ac9f491ae665c Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Fri, 14 Nov 2014 10:16:27 +1100 Subject: [PATCH 22/73] Updated todo.txt I'm so bored I'm working on my game remotely. This is a public access computer without a compiler :/ --- todo.txt | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/todo.txt b/todo.txt index 5424e31..eb2bb64 100644 --- a/todo.txt +++ b/todo.txt @@ -1,7 +1,9 @@ -TODO: All new managers need their internals fleshed out -TODO: room_system api -TODO: rewrite the main body of the server +TODO: Account system needs salts & hashes for security +TODO: Character system might need an API +TODO: Door system needs an API +TODO: monster system needs an API +TODO: rewrite the main body of the server TODO: I need a better way to handle the statistics TODO: Fix shoddy movement TODO: Handle statistics server-side @@ -14,4 +16,3 @@ TODO: The TileSheet class should implement the surface itself TODO: Passwords/Authentication TODO: Time delay for requesting region packets TODO: A proper logging system -TODO: Update Codebase with the improvements from Tortuga From 97b79451914e84e12a89e825df631f575e65ab45 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Fri, 14 Nov 2014 10:20:04 +1100 Subject: [PATCH 23/73] need to go TMP COMMIT --- todo.txt | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/todo.txt b/todo.txt index eb2bb64..b31ad34 100644 --- a/todo.txt +++ b/todo.txt @@ -16,3 +16,11 @@ TODO: The TileSheet class should implement the surface itself TODO: Passwords/Authentication TODO: Time delay for requesting region packets TODO: A proper logging system + +------------------------- + +The entities might need an API, which interfaces with all entity types (characters, monsters, doors, etc.) +The Entity base class handles position (including room) and motion, so something generic like this could be used (or aliased by other APIs) + +entity: + From cacd3dcd6dd6768694a7e40266d473f8c5e0ebdb Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Sun, 16 Nov 2014 22:34:12 +1100 Subject: [PATCH 24/73] Removed the statistics structure from common/* and server/* --- common/gameplay/statistics.hpp | 42 ------------ .../network/packet_types/character_packet.cpp | 8 --- .../network/packet_types/character_packet.hpp | 4 -- .../packet_types/serial_statistics.cpp | 64 ------------------- .../packet_types/serial_statistics.hpp | 30 --------- server/characters/character_data.cpp | 4 -- server/characters/character_data.hpp | 5 +- server/monsters/monster_data.cpp | 4 -- server/monsters/monster_data.hpp | 4 -- server/server_methods.cpp | 3 - 10 files changed, 1 insertion(+), 167 deletions(-) delete mode 100644 common/gameplay/statistics.hpp delete mode 100644 common/network/packet_types/serial_statistics.cpp delete mode 100644 common/network/packet_types/serial_statistics.hpp diff --git a/common/gameplay/statistics.hpp b/common/gameplay/statistics.hpp deleted file mode 100644 index 71020ae..0000000 --- a/common/gameplay/statistics.hpp +++ /dev/null @@ -1,42 +0,0 @@ -/* 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 STATISTICS_HPP_ -#define STATISTICS_HPP_ - -struct Statistics { - int level = 0; - int exp = 0; - int maxHP = 0; - int health = 0; - int maxMP = 0; - int mana = 0; - int attack = 0; - int defence = 0; - int intelligence = 0; - int resistance = 0; - int speed = 0; - float accuracy = 0.0; - float evasion = 0.0; - float luck = 0.0; -}; - -#endif \ No newline at end of file diff --git a/common/network/packet_types/character_packet.cpp b/common/network/packet_types/character_packet.cpp index 7f6620c..c18d1bf 100644 --- a/common/network/packet_types/character_packet.cpp +++ b/common/network/packet_types/character_packet.cpp @@ -23,8 +23,6 @@ #include "serial_utility.hpp" -#include "serial_statistics.hpp" - void serializeCharacter(void* buffer, CharacterPacket* packet) { serialCopy(&buffer, &packet->type, sizeof(SerialPacketType)); @@ -43,9 +41,6 @@ void serializeCharacter(void* buffer, CharacterPacket* packet) { serialCopy(&buffer, &packet->motion.x, sizeof(double)); serialCopy(&buffer, &packet->motion.y, sizeof(double)); - //stats structure - serializeStatistics(&buffer, &packet->stats); - //gameplay components: equipment, items, buffs, debuffs... } @@ -67,8 +62,5 @@ void deserializeCharacter(void* buffer, CharacterPacket* packet) { deserialCopy(&buffer, &packet->motion.x, sizeof(double)); deserialCopy(&buffer, &packet->motion.y, sizeof(double)); - //stats structure - deserializeStatistics(&buffer, &packet->stats); - //gameplay components: equipment, items, buffs, debuffs... } diff --git a/common/network/packet_types/character_packet.hpp b/common/network/packet_types/character_packet.hpp index e743589..98d2c31 100644 --- a/common/network/packet_types/character_packet.hpp +++ b/common/network/packet_types/character_packet.hpp @@ -25,7 +25,6 @@ #include "serial_packet_base.hpp" #include "vector2.hpp" -#include "statistics.hpp" struct CharacterPacket : SerialPacketBase { //identify the character @@ -42,9 +41,6 @@ struct CharacterPacket : SerialPacketBase { Vector2 origin; Vector2 motion; - //gameplay - Statistics stats; - //gameplay components: equipment, items, buffs, debuffs... }; diff --git a/common/network/packet_types/serial_statistics.cpp b/common/network/packet_types/serial_statistics.cpp deleted file mode 100644 index fae799e..0000000 --- a/common/network/packet_types/serial_statistics.cpp +++ /dev/null @@ -1,64 +0,0 @@ -/* 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 "serial_statistics.hpp" - -#include "serial_utility.hpp" - -void serializeStatistics(void** buffer, Statistics* stats) { - //integers - serialCopy(buffer, &stats->level, sizeof(int)); - serialCopy(buffer, &stats->exp, sizeof(int)); - serialCopy(buffer, &stats->maxHP, sizeof(int)); - serialCopy(buffer, &stats->health, sizeof(int)); - serialCopy(buffer, &stats->maxMP, sizeof(int)); - serialCopy(buffer, &stats->mana, sizeof(int)); - serialCopy(buffer, &stats->attack, sizeof(int)); - serialCopy(buffer, &stats->defence, sizeof(int)); - serialCopy(buffer, &stats->intelligence, sizeof(int)); - serialCopy(buffer, &stats->resistance, sizeof(int)); - serialCopy(buffer, &stats->speed, sizeof(int)); - - //floats - serialCopy(buffer, &stats->accuracy, sizeof(float)); - serialCopy(buffer, &stats->evasion, sizeof(float)); - serialCopy(buffer, &stats->luck, sizeof(float)); -} - -void deserializeStatistics(void** buffer, Statistics* stats) { - //integers - deserialCopy(buffer, &stats->level, sizeof(int)); - deserialCopy(buffer, &stats->exp, sizeof(int)); - deserialCopy(buffer, &stats->maxHP, sizeof(int)); - deserialCopy(buffer, &stats->health, sizeof(int)); - deserialCopy(buffer, &stats->maxMP, sizeof(int)); - deserialCopy(buffer, &stats->mana, sizeof(int)); - deserialCopy(buffer, &stats->attack, sizeof(int)); - deserialCopy(buffer, &stats->defence, sizeof(int)); - deserialCopy(buffer, &stats->intelligence, sizeof(int)); - deserialCopy(buffer, &stats->resistance, sizeof(int)); - deserialCopy(buffer, &stats->speed, sizeof(int)); - - //floats - deserialCopy(buffer, &stats->accuracy, sizeof(float)); - deserialCopy(buffer, &stats->evasion, sizeof(float)); - deserialCopy(buffer, &stats->luck, sizeof(float)); -} diff --git a/common/network/packet_types/serial_statistics.hpp b/common/network/packet_types/serial_statistics.hpp deleted file mode 100644 index 2f4243f..0000000 --- a/common/network/packet_types/serial_statistics.hpp +++ /dev/null @@ -1,30 +0,0 @@ -/* 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 SERIALSTATISTICS_HPP_ -#define SERIALSTATISTICS_HPP_ - -#include "statistics.hpp" - -void serializeStatistics(void** buffer, Statistics* stats); -void deserializeStatistics(void** buffer, Statistics* stats); - -#endif \ No newline at end of file diff --git a/server/characters/character_data.cpp b/server/characters/character_data.cpp index 359812c..2e4fa25 100644 --- a/server/characters/character_data.cpp +++ b/server/characters/character_data.cpp @@ -21,10 +21,6 @@ */ #include "character_data.hpp" -Statistics* CharacterData::GetBaseStats() { - return &baseStats; -} - int CharacterData::GetOwner() { return owner; } diff --git a/server/characters/character_data.hpp b/server/characters/character_data.hpp index 400f4cb..2e94a7c 100644 --- a/server/characters/character_data.hpp +++ b/server/characters/character_data.hpp @@ -25,7 +25,6 @@ //components #include "character_defines.hpp" #include "entity.hpp" -#include "statistics.hpp" //std namespace #include @@ -37,7 +36,7 @@ public: ~CharacterData() = default; //accessors and mutators - Statistics* GetBaseStats(); + //... //database stuff int GetOwner(); @@ -47,8 +46,6 @@ public: private: friend class CharacterManager; - Statistics baseStats; - int owner; std::string handle; std::string avatar; diff --git a/server/monsters/monster_data.cpp b/server/monsters/monster_data.cpp index 2298c06..2e7560d 100644 --- a/server/monsters/monster_data.cpp +++ b/server/monsters/monster_data.cpp @@ -21,10 +21,6 @@ */ #include "monster_data.hpp" -Statistics* MonsterData::GetBaseStats() { - return &baseStats; -} - std::string MonsterData::SetAvatar(std::string s) { return avatar = s; } diff --git a/server/monsters/monster_data.hpp b/server/monsters/monster_data.hpp index a98daa7..bd45699 100644 --- a/server/monsters/monster_data.hpp +++ b/server/monsters/monster_data.hpp @@ -23,7 +23,6 @@ #define MONSTERDATA_HPP_ #include "entity.hpp" -#include "statistics.hpp" #include @@ -32,8 +31,6 @@ public: MonsterData() = default; ~MonsterData() = default; - Statistics* GetBaseStats(); - std::string SetAvatar(std::string); int SetScriptReference(int); @@ -43,7 +40,6 @@ public: private: friend class MonsterManager; - Statistics baseStats; std::string avatar; int scriptRef; }; diff --git a/server/server_methods.cpp b/server/server_methods.cpp index d73d899..7e84f8e 100644 --- a/server/server_methods.cpp +++ b/server/server_methods.cpp @@ -240,8 +240,6 @@ void ServerApplication::HandleCharacterUpdate(CharacterPacket* const argPacket) character->SetOrigin(argPacket->origin); character->SetMotion(argPacket->motion); - *character->GetBaseStats() = argPacket->stats; - //TODO: gameplay components: equipment, items, buffs, debuffs PumpPacket(argPacket); @@ -353,5 +351,4 @@ void ServerApplication::CopyCharacterToPacket(CharacterPacket* const packet, int packet->roomIndex = character->GetRoomIndex(); packet->origin = character->GetOrigin(); packet->motion = character->GetMotion(); - packet->stats = *character->GetBaseStats(); } \ No newline at end of file From 1f3c1f32f4d5c37820b20f8477d442384a74fec0 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Sun, 16 Nov 2014 22:40:13 +1100 Subject: [PATCH 25/73] Moved 'renderable' stuff to 'entities' --- .../base_character.cpp | 0 .../base_character.hpp | 4 +- .../{renderable => entities}/base_monster.cpp | 0 .../{renderable => entities}/base_monster.hpp | 4 +- .../renderable.cpp => entities/entity.cpp} | 37 ++++++++++++++-- .../renderable.hpp => entities/entity.hpp} | 38 +++++++++------- client/{renderable => entities}/makefile | 0 client/renderable/local_character.cpp | 23 ---------- client/renderable/local_character.hpp | 44 ------------------- 9 files changed, 60 insertions(+), 90 deletions(-) rename client/{renderable => entities}/base_character.cpp (100%) rename client/{renderable => entities}/base_character.hpp (95%) rename client/{renderable => entities}/base_monster.cpp (100%) rename client/{renderable => entities}/base_monster.hpp (94%) rename client/{renderable/renderable.cpp => entities/entity.cpp} (64%) rename client/{renderable/renderable.hpp => entities/entity.hpp} (73%) rename client/{renderable => entities}/makefile (100%) delete mode 100644 client/renderable/local_character.cpp delete mode 100644 client/renderable/local_character.hpp diff --git a/client/renderable/base_character.cpp b/client/entities/base_character.cpp similarity index 100% rename from client/renderable/base_character.cpp rename to client/entities/base_character.cpp diff --git a/client/renderable/base_character.hpp b/client/entities/base_character.hpp similarity index 95% rename from client/renderable/base_character.hpp rename to client/entities/base_character.hpp index 1531ba3..8c44ce3 100644 --- a/client/renderable/base_character.hpp +++ b/client/entities/base_character.hpp @@ -24,12 +24,12 @@ //components #include "character_defines.hpp" -#include "renderable.hpp" +#include "entity.hpp" //std namespace #include -class BaseCharacter : public Renderable { +class BaseCharacter : public Entity { public: BaseCharacter() = default; virtual ~BaseCharacter() = default; diff --git a/client/renderable/base_monster.cpp b/client/entities/base_monster.cpp similarity index 100% rename from client/renderable/base_monster.cpp rename to client/entities/base_monster.cpp diff --git a/client/renderable/base_monster.hpp b/client/entities/base_monster.hpp similarity index 94% rename from client/renderable/base_monster.hpp rename to client/entities/base_monster.hpp index 15cea7d..ddcc876 100644 --- a/client/renderable/base_monster.hpp +++ b/client/entities/base_monster.hpp @@ -22,9 +22,9 @@ #ifndef BASEMONSTER_HPP_ #define BASEMONSTER_HPP_ -#include "renderable.hpp" +#include "entity.hpp" -class BaseMonster { +class BaseMonster : public Entity { public: BaseMonster() = default; virtual ~BaseMonster() = default; diff --git a/client/renderable/renderable.cpp b/client/entities/entity.cpp similarity index 64% rename from client/renderable/renderable.cpp rename to client/entities/entity.cpp index 46d319d..5509604 100644 --- a/client/renderable/renderable.cpp +++ b/client/entities/entity.cpp @@ -19,13 +19,44 @@ * 3. This notice may not be removed or altered from any source * distribution. */ -#include "renderable.hpp" +#include "entity.hpp" -void Renderable::Update() { +void Entity::Update() { origin += motion; sprite.Update(0.016); } -void Renderable::DrawTo(SDL_Surface* const dest, int camX, int camY) { +void Entity::DrawTo(SDL_Surface* const dest, int camX, int camY) { sprite.DrawTo(dest, origin.x - camX, origin.y - camY); +} + +int Entity::SetEntityIndex(int i) { + return entityIndex = i; +} + +int Entity::SetRoomIndex(int i) { + return roomIndex = i; +} + +Vector2 Entity::SetOrigin(Vector2 v) { + return origin = v; +} + +Vector2 Entity::SetMotion(Vector2 v) { + return motion = v; +} +int Entity::GetEntityIndex() { + return entityIndex; +} + +int Entity::GetRoomIndex() { + return roomIndex; +} + +Vector2 Entity::GetOrigin() { + return origin; +} + +Vector2 Entity::GetMotion() { + return motion; } \ No newline at end of file diff --git a/client/renderable/renderable.hpp b/client/entities/entity.hpp similarity index 73% rename from client/renderable/renderable.hpp rename to client/entities/entity.hpp index d78cde2..a73d3eb 100644 --- a/client/renderable/renderable.hpp +++ b/client/entities/entity.hpp @@ -19,37 +19,43 @@ * 3. This notice may not be removed or altered from any source * distribution. */ -#ifndef RENDERABLE_HPP_ -#define RENDERABLE_HPP_ +#ifndef ENTITY_HPP_ +#define ENTITY_HPP_ #include "bounding_box.hpp" #include "sprite_sheet.hpp" #include "vector2.hpp" -class Renderable { +//The base class for all objects in the world +class Entity { public: - Renderable() = default; - virtual ~Renderable() = default; - virtual void Update(); virtual void DrawTo(SDL_Surface* const, int camX, int camY); SpriteSheet* GetSprite() { return &sprite; } - //position - Vector2 SetOrigin(Vector2 v) { return origin = v; } - Vector2 GetOrigin() const { return origin; } - Vector2 SetMotion(Vector2 v) { return motion = v; } - Vector2 GetMotion() const { return motion; } - - //collision + //accessors & mutators + int SetEntityIndex(int i); + int SetRoomIndex(int i); + Vector2 SetOrigin(Vector2 v); + Vector2 SetMotion(Vector2 v); BoundingBox SetBounds(BoundingBox b) { return bounds = b; } + + int GetEntityIndex(); + int GetRoomIndex(); + Vector2 GetOrigin(); + Vector2 GetMotion(); BoundingBox GetBounds() { return bounds; } -protected: //TODO: should be private +protected: + Entity() = default; + ~Entity() = default; + SpriteSheet sprite; - Vector2 origin = {0, 0}; - Vector2 motion = {0, 0}; + int entityIndex = -1; + int roomIndex = -1; + Vector2 origin; + Vector2 motion; BoundingBox bounds; }; diff --git a/client/renderable/makefile b/client/entities/makefile similarity index 100% rename from client/renderable/makefile rename to client/entities/makefile diff --git a/client/renderable/local_character.cpp b/client/renderable/local_character.cpp deleted file mode 100644 index 211a6bc..0000000 --- a/client/renderable/local_character.cpp +++ /dev/null @@ -1,23 +0,0 @@ -/* 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 "local_character.hpp" - diff --git a/client/renderable/local_character.hpp b/client/renderable/local_character.hpp deleted file mode 100644 index 37e90de..0000000 --- a/client/renderable/local_character.hpp +++ /dev/null @@ -1,44 +0,0 @@ -/* 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 LOCALCHARACTER_HPP_ -#define LOCALCHARACTER_HPP_ - -#include "base_character.hpp" -#include "statistics.hpp" - -class LocalCharacter : public BaseCharacter { -public: - LocalCharacter() = default; - ~LocalCharacter() = default; - - int SetRoomIndex(int i) { return roomIndex = i; } - int GetRoomIndex() { return roomIndex; } - - Statistics* GetBaseStats() { return &baseStats; } - -private: - int roomIndex = -1; - Statistics baseStats; - //TODO: weapons, armour, buffs, debuffs, etc. -}; - -#endif From ace87b438b63166cc71251e5b6dc2b203ec30013 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Sun, 16 Nov 2014 22:53:11 +1100 Subject: [PATCH 26/73] Began working changes into lobby --- client/client_utilities/makefile | 37 --------------------------- client/makefile | 5 ++-- client/scenes/in_world.hpp | 1 - client/scenes/lobby_menu.cpp | 37 +++++++++++++++++++++++++-- client/scenes/lobby_menu.hpp | 3 +++ client/scenes/makefile | 2 +- common/network/serial_packet_type.hpp | 1 + common/network/serial_utility.cpp | 2 ++ todo.txt | 5 ++++ 9 files changed, 49 insertions(+), 44 deletions(-) delete mode 100644 client/client_utilities/makefile diff --git a/client/client_utilities/makefile b/client/client_utilities/makefile deleted file mode 100644 index 4a01dcd..0000000 --- a/client/client_utilities/makefile +++ /dev/null @@ -1,37 +0,0 @@ -#config -INCLUDES+=. -LIBS+= -CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES)) - -#source -CXXSRC=$(wildcard *.cpp) - -#objects -OBJDIR=obj -OBJ+=$(addprefix $(OBJDIR)/,$(CXXSRC:.cpp=.o)) - -#output -OUTDIR=.. -OUT=$(addprefix $(OUTDIR)/,client.a) - -#targets -all: $(OBJ) $(OUT) - ar -crs $(OUT) $(OBJ) - -$(OBJ): | $(OBJDIR) - -$(OUT): | $(OUTDIR) - -$(OBJDIR): - mkdir $(OBJDIR) - -$(OUTDIR): - mkdir $(OUTDIR) - -$(OBJDIR)/%.o: %.cpp - $(CXX) $(CXXFLAGS) -c -o $@ $< - -clean: - $(RM) *.o *.a *.exe - -rebuild: clean all diff --git a/client/makefile b/client/makefile index 39c104f..d7adf5a 100644 --- a/client/makefile +++ b/client/makefile @@ -1,5 +1,5 @@ #include directories -INCLUDES+=. client_utilities renderable scenes ../common/debugging ../common/gameplay ../common/graphics ../common/map ../common/network ../common/network/packet_types ../common/ui ../common/utilities +INCLUDES+=. entities scenes ../common/debugging ../common/gameplay ../common/graphics ../common/map ../common/network ../common/network/packet_types ../common/ui ../common/utilities #libraries #the order of the $(LIBS) is important, at least for MinGW @@ -25,9 +25,8 @@ OUT=$(addprefix $(OUTDIR)/,client) #targets all: $(OBJ) $(OUT) - $(MAKE) -C client_utilities + $(MAKE) -C entities $(MAKE) -C scenes - $(MAKE) -C renderable $(CXX) $(CXXFLAGS) -o $(OUT) $(OBJ) $(LIBS) $(OBJ): | $(OBJDIR) diff --git a/client/scenes/in_world.hpp b/client/scenes/in_world.hpp index 7f2e078..e995868 100644 --- a/client/scenes/in_world.hpp +++ b/client/scenes/in_world.hpp @@ -40,7 +40,6 @@ #include "base_character.hpp" #include "base_monster.hpp" -#include "local_character.hpp" //client #include "base_scene.hpp" diff --git a/client/scenes/lobby_menu.cpp b/client/scenes/lobby_menu.cpp index c679f96..3fbc1c1 100644 --- a/client/scenes/lobby_menu.cpp +++ b/client/scenes/lobby_menu.cpp @@ -190,15 +190,25 @@ void LobbyMenu::KeyUp(SDL_KeyboardEvent const& key) { void LobbyMenu::HandlePacket(SerialPacket* const argPacket) { switch(argPacket->type) { + //responses case SerialPacketType::BROADCAST_RESPONSE: HandleBroadcastResponse(static_cast(argPacket)); break; case SerialPacketType::JOIN_RESPONSE: HandleJoinResponse(static_cast(argPacket)); break; + case SerialPacketType::LOGIN_RESPONSE: + HandleLoginResponse(static_cast(argPacket)); + break; + + //rejections case SerialPacketType::JOIN_REJECTION: HandleJoinRejection(static_cast(argPacket)); break; + case SerialPacketType::LOGIN_REJECTION: + HandleLoginRejection(static_cast(argPacket)); + break; + //handle errors default: throw(std::runtime_error(std::string() + "Unknown SerialPacketType encountered in LobbyMenu: " + to_string_custom(static_cast(argPacket->type)) )); @@ -222,9 +232,19 @@ void LobbyMenu::HandleBroadcastResponse(ServerPacket* const argPacket) { } void LobbyMenu::HandleJoinResponse(ClientPacket* const argPacket) { + //save the server's data clientIndex = argPacket->clientIndex; - accountIndex = argPacket->accountIndex; network.Bind(argPacket->srcAddress, Channels::SERVER); + + //request login data + SendLoginRequest(); +} + +void LobbyMenu::HandleLoginResponse(ClientPacket* const argPacket) { + if (argPacket->clientIndex != clientIndex) { + throw(std::runtime_error("Client index invalid during login")); + } + accountIndex = argPacket->accountIndex; SetNextScene(SceneList::INWORLD); } @@ -232,6 +252,10 @@ void LobbyMenu::HandleJoinRejection(TextPacket* const argPacket) { //TODO: Better output for join rejection } +void LobbyMenu::HandleLoginRejection(TextPacket* const argPacket) { + //TODO: Better output for login rejection +} + //------------------------- //server control //------------------------- @@ -251,9 +275,18 @@ void LobbyMenu::SendJoinRequest() { //pack the packet ClientPacket packet; packet.type = SerialPacketType::JOIN_REQUEST; - strncpy(packet.username, config["client.username"].c_str(), PACKET_STRING_SIZE); //join the selected server network.SendTo(selection->address, &packet); selection = nullptr; } + +void LobbyMenu::SendLoginRequest() { + //NOTE: high cohesion + ClientPacket packet; + packet.type = SerialPacketType::LOGIN_REQUEST; + packet.clientIndex = clientIndex; + strncpy(packet.username, config["client.username"].c_str(), PACKET_STRING_SIZE); + + network.SendTo(Channels::SERVER, &packet); +} diff --git a/client/scenes/lobby_menu.hpp b/client/scenes/lobby_menu.hpp index 1959c56..b8e5347 100644 --- a/client/scenes/lobby_menu.hpp +++ b/client/scenes/lobby_menu.hpp @@ -63,11 +63,14 @@ protected: void HandlePacket(SerialPacket* const); void HandleBroadcastResponse(ServerPacket* const); void HandleJoinResponse(ClientPacket* const); + void HandleLoginResponse(ClientPacket* const); void HandleJoinRejection(TextPacket* const); + void HandleLoginRejection(TextPacket* const); //server control void SendBroadcastRequest(); void SendJoinRequest(); + void SendLoginRequest(); //shared parameters ConfigUtility& config = ConfigUtility::GetSingleton(); diff --git a/client/scenes/makefile b/client/scenes/makefile index 7a59128..73a4950 100644 --- a/client/scenes/makefile +++ b/client/scenes/makefile @@ -1,5 +1,5 @@ #config -INCLUDES+=. .. ../renderable ../../common/gameplay ../../common/graphics ../../common/map ../../common/network ../../common/network/packet_types ../../common/ui ../../common/utilities +INCLUDES+=. .. ../entities ../../common/gameplay ../../common/graphics ../../common/map ../../common/network ../../common/network/packet_types ../../common/ui ../../common/utilities LIBS+= CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES)) diff --git a/common/network/serial_packet_type.hpp b/common/network/serial_packet_type.hpp index e6637af..d40a264 100644 --- a/common/network/serial_packet_type.hpp +++ b/common/network/serial_packet_type.hpp @@ -115,6 +115,7 @@ enum class SerialPacketType { //rejection/error messages JOIN_REJECTION, + LOGIN_REJECTION, CHARACTER_REJECTION, SHUTDOWN_REJECTION, diff --git a/common/network/serial_utility.cpp b/common/network/serial_utility.cpp index fe2e87e..ddad0e7 100644 --- a/common/network/serial_utility.cpp +++ b/common/network/serial_utility.cpp @@ -81,6 +81,7 @@ void serializePacket(void* buffer, SerialPacketBase* packet) { break; case SerialPacketType::TEXT_BROADCAST: case SerialPacketType::JOIN_REJECTION: + case SerialPacketType::LOGIN_REJECTION: case SerialPacketType::CHARACTER_REJECTION: case SerialPacketType::SHUTDOWN_REJECTION: serializeText(buffer, static_cast(packet)); @@ -129,6 +130,7 @@ void deserializePacket(void* buffer, SerialPacketBase* packet) { break; case SerialPacketType::TEXT_BROADCAST: case SerialPacketType::JOIN_REJECTION: + case SerialPacketType::LOGIN_REJECTION: case SerialPacketType::CHARACTER_REJECTION: case SerialPacketType::SHUTDOWN_REJECTION: deserializeText(buffer, static_cast(packet)); diff --git a/todo.txt b/todo.txt index b31ad34..7fd4030 100644 --- a/todo.txt +++ b/todo.txt @@ -24,3 +24,8 @@ The Entity base class handles position (including room) and motion, so something entity: +------------------------- + +Lobby: + JOIN_REQUEST -> JOIN_RESPONSE, JOIN_REJECTION + LOGIN_REQUEST -> LOGIN_RESPONSE, LOGIN_REJECTION \ No newline at end of file From 9329274866c6ddf3064757484d926db5487b253c Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Sun, 16 Nov 2014 23:16:21 +1100 Subject: [PATCH 27/73] Project builds, but with a lot of logic dummied out --- client/scenes/in_world.cpp | 93 +++++++++++++++++++++++--------------- client/scenes/in_world.hpp | 1 - 2 files changed, 56 insertions(+), 38 deletions(-) diff --git a/client/scenes/in_world.cpp b/client/scenes/in_world.cpp index bea05c3..d774c09 100644 --- a/client/scenes/in_world.cpp +++ b/client/scenes/in_world.cpp @@ -67,15 +67,15 @@ InWorld::InWorld(int* const argClientIndex, int* const argAccountIndex): tileSheet.Load(config["dir.tilesets"] + "overworld.bmp", 32, 32); //send this player's character info - CharacterPacket newPacket; - newPacket.type = SerialPacketType::CHARACTER_NEW; - strncpy(newPacket.handle, config["client.handle"].c_str(), PACKET_STRING_SIZE); - strncpy(newPacket.avatar, config["client.avatar"].c_str(), PACKET_STRING_SIZE); - newPacket.accountIndex = accountIndex; - network.SendTo(Channels::SERVER, &newPacket); +// CharacterPacket newPacket; +// newPacket.type = SerialPacketType::CHARACTER_NEW; +// strncpy(newPacket.handle, config["client.handle"].c_str(), PACKET_STRING_SIZE); +// strncpy(newPacket.avatar, config["client.avatar"].c_str(), PACKET_STRING_SIZE); +// newPacket.accountIndex = accountIndex; +// network.SendTo(Channels::SERVER, &newPacket); //request a sync - RequestSynchronize(); +// RequestSynchronize(); //debug // @@ -288,30 +288,55 @@ void InWorld::KeyUp(SDL_KeyboardEvent const& key) { void InWorld::HandlePacket(SerialPacket* const argPacket) { switch(argPacket->type) { - case SerialPacketType::PING: - HandlePing(static_cast(argPacket)); + //heartbeat system + case SerialPacketType::PING: { + ServerPacket newPacket; + newPacket.type = SerialPacketType::PONG; + network.SendTo(argPacket->srcAddress, &newPacket); + } break; case SerialPacketType::PONG: - HandlePong(static_cast(argPacket)); +// HandlePong(static_cast(argPacket)); break; - case SerialPacketType::DISCONNECT: - HandleDisconnect(static_cast(argPacket)); + + //game server connections + case SerialPacketType::LOGOUT_RESPONSE: +// HandleLogoutResponse(static_cast(argPacket)); break; - case SerialPacketType::CHARACTER_NEW: - HandleCharacterNew(static_cast(argPacket)); + case SerialPacketType::DISCONNECT_REQUEST: +// HandleDisconnectRequest(static_cast(argPacket)); break; - case SerialPacketType::CHARACTER_DELETE: - HandleCharacterDelete(static_cast(argPacket)); - break; - case SerialPacketType::CHARACTER_UPDATE: - HandleCharacterUpdate(static_cast(argPacket)); - break; - case SerialPacketType::CHARACTER_REJECTION: - HandleCharacterRejection(static_cast(argPacket)); + case SerialPacketType::DISCONNECT_FORCED: +// HandleDisconnectForced(static_cast(argPacket)); break; + + //data management case SerialPacketType::REGION_CONTENT: - HandleRegionContent(static_cast(argPacket)); +// HandleRegionContent(static_cast(argPacket)); break; +// case SerialPacketType::QUERY_CHARACTER_EXISTS: +// case SerialPacketType::QUERY_CHARACTER_STATS: +// case SerialPacketType::QUERY_CHARACTER_LOCATION: + + //character management +// case SerialPacketType::CHARACTER_NEW: +// HandleCharacterNew(static_cast(argPacket)); +// break; +// case SerialPacketType::CHARACTER_DELETE: +// HandleCharacterDelete(static_cast(argPacket)); +// break; +// case SerialPacketType::CHARACTER_UPDATE: +// HandleCharacterUpdate(static_cast(argPacket)); +// break; +// case SerialPacketType::CHARACTER_REJECTION: +// HandleCharacterRejection(static_cast(argPacket)); +// break; + + //enemy management + //TODO: enemy management + + //TODO: text + //handle errors default: throw(std::runtime_error(std::string() + "Unknown SerialPacketType encountered in InWorld: " + to_string_custom(static_cast(argPacket->type)) )); @@ -319,12 +344,6 @@ void InWorld::HandlePacket(SerialPacket* const argPacket) { } } -void InWorld::HandlePing(ServerPacket* const argPacket) { - ServerPacket newPacket; - newPacket.type = SerialPacketType::PONG; - network.SendTo(argPacket->srcAddress, &newPacket); -} - void InWorld::HandlePong(ServerPacket* const argPacket) { if (network.GetIPAddress(Channels::SERVER)->host != argPacket->srcAddress.host) { throw(std::runtime_error("Heartbeat message received from an unknown source")); @@ -434,23 +453,23 @@ void InWorld::HandleRegionContent(RegionPacket* const argPacket) { //------------------------- void InWorld::RequestSynchronize() { - ClientPacket newPacket; +// ClientPacket newPacket; //request a sync - newPacket.type = SerialPacketType::SYNCHRONIZE; - newPacket.clientIndex = clientIndex; - newPacket.accountIndex = accountIndex; +// newPacket.type = SerialPacketType::SYNCHRONIZE; +// newPacket.clientIndex = clientIndex; +// newPacket.accountIndex = accountIndex; //TODO: location, range for sync request - network.SendTo(Channels::SERVER, &newPacket); +// network.SendTo(Channels::SERVER, &newPacket); } void InWorld::SendPlayerUpdate() { CharacterPacket newPacket; //pack the packet - newPacket.type = SerialPacketType::CHARACTER_UPDATE; +// newPacket.type = SerialPacketType::CHARACTER_UPDATE; newPacket.characterIndex = characterIndex; //NOTE: omitting the handle and avatar here @@ -469,7 +488,7 @@ void InWorld::RequestDisconnect() { ClientPacket newPacket; //send a disconnect request - newPacket.type = SerialPacketType::DISCONNECT; + newPacket.type = SerialPacketType::DISCONNECT_REQUEST; newPacket.clientIndex = clientIndex; newPacket.accountIndex = accountIndex; @@ -480,7 +499,7 @@ void InWorld::RequestShutDown() { ClientPacket newPacket; //send a shutdown request - newPacket.type = SerialPacketType::SHUTDOWN; + newPacket.type = SerialPacketType::SHUTDOWN_REQUEST; newPacket.clientIndex = clientIndex; newPacket.accountIndex = accountIndex; diff --git a/client/scenes/in_world.hpp b/client/scenes/in_world.hpp index e995868..ce5c29b 100644 --- a/client/scenes/in_world.hpp +++ b/client/scenes/in_world.hpp @@ -73,7 +73,6 @@ protected: //Network handlers void HandlePacket(SerialPacket* const); - void HandlePing(ServerPacket* const); void HandlePong(ServerPacket* const); void HandleDisconnect(ClientPacket* const); void HandleCharacterNew(CharacterPacket* const); From 20d40d5b8119cbf1a47b80ce446525e1818f724a Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Sun, 23 Nov 2014 05:47:21 +1100 Subject: [PATCH 28/73] Implemented two-step logins, basic connections build --- common/network/serial_packet_type.hpp | 1 + common/network/serial_utility.cpp | 2 + server/server_application.hpp | 36 +++-- server/server_logic.cpp | 39 +++--- server/server_methods.cpp | 188 +++++++++++++++++++------- 5 files changed, 187 insertions(+), 79 deletions(-) diff --git a/common/network/serial_packet_type.hpp b/common/network/serial_packet_type.hpp index d40a264..7b50b93 100644 --- a/common/network/serial_packet_type.hpp +++ b/common/network/serial_packet_type.hpp @@ -56,6 +56,7 @@ enum class SerialPacketType { //disconnect from the server DISCONNECT_REQUEST, + DISCONNECT_RESPONSE, DISCONNECT_FORCED, //load the account diff --git a/common/network/serial_utility.cpp b/common/network/serial_utility.cpp index ddad0e7..086e6a7 100644 --- a/common/network/serial_utility.cpp +++ b/common/network/serial_utility.cpp @@ -55,6 +55,7 @@ void serializePacket(void* buffer, SerialPacketBase* packet) { case SerialPacketType::JOIN_REQUEST: case SerialPacketType::JOIN_RESPONSE: case SerialPacketType::DISCONNECT_REQUEST: + case SerialPacketType::DISCONNECT_RESPONSE: case SerialPacketType::DISCONNECT_FORCED: case SerialPacketType::LOGIN_REQUEST: case SerialPacketType::LOGIN_RESPONSE: @@ -104,6 +105,7 @@ void deserializePacket(void* buffer, SerialPacketBase* packet) { case SerialPacketType::JOIN_REQUEST: case SerialPacketType::JOIN_RESPONSE: case SerialPacketType::DISCONNECT_REQUEST: + case SerialPacketType::DISCONNECT_RESPONSE: case SerialPacketType::DISCONNECT_FORCED: case SerialPacketType::LOGIN_REQUEST: case SerialPacketType::LOGIN_RESPONSE: diff --git a/server/server_application.hpp b/server/server_application.hpp index a91bbbc..77cb847 100644 --- a/server/server_application.hpp +++ b/server/server_application.hpp @@ -70,29 +70,43 @@ private: //handle incoming traffic void HandlePacket(SerialPacket* const); + //heartbeat sustem + void HandlePing(ServerPacket* const); + void HandlePong(ServerPacket* const); + //basic connections void HandleBroadcastRequest(ServerPacket* const); void HandleJoinRequest(ClientPacket* const); - void HandleDisconnect(ClientPacket* const); - void HandleShutdown(ClientPacket* const); + void HandleLoginRequest(ClientPacket* const); + + //client disconnections + void HandleLogoutRequest(ClientPacket* const); + void HandleDisconnectRequest(ClientPacket* const); + + //server commands +// void HandleDisconnectForced(ClientPacket* const); + void HandleShutdownRequest(ClientPacket* const); //map management - void HandleRegionRequest(RegionPacket* const); +// void HandleRegionRequest(RegionPacket* const); //character management - void HandleCharacterNew(CharacterPacket* const); - void HandleCharacterDelete(CharacterPacket* const); - void HandleCharacterUpdate(CharacterPacket* const); +// void HandleCharacterNew(CharacterPacket* const); +// void HandleCharacterDelete(CharacterPacket* const); +// void HandleCharacterUpdate(CharacterPacket* const); //mismanagement - void HandleSynchronize(ClientPacket* const); +// void HandleSynchronize(ClientPacket* const); //utility methods //TODO: a function that only sends to characters in a certain proximity - void CleanupLostConnection(int index); - void PumpPacket(SerialPacket* const); - void PumpCharacterUnload(int uid); - void CopyCharacterToPacket(CharacterPacket* const packet, int characterIndex); +// void CleanupLostConnection(int index); +// void PumpPacket(SerialPacket* const); +// void PumpCharacterUnload(int uid); +// void CopyCharacterToPacket(CharacterPacket* const packet, int characterIndex); + + //data management + void SaveServerState(); //APIs and utilities sqlite3* database = nullptr; diff --git a/server/server_logic.cpp b/server/server_logic.cpp index 0c80ff8..df12171 100644 --- a/server/server_logic.cpp +++ b/server/server_logic.cpp @@ -180,7 +180,7 @@ void ServerApplication::Proc() { //find and unload the characters associated with this account characterMgr.UnloadIf([&](std::pair character) -> bool { if (character.second.GetOwner() == account.first) { - PumpCharacterUnload(character.first); +// PumpCharacterUnload(character.first); return true; } return false; @@ -227,43 +227,40 @@ void ServerApplication::Quit() { void ServerApplication::HandlePacket(SerialPacket* const argPacket) { switch(argPacket->type) { //heartbeat system - case SerialPacketType::PING: { - ServerPacket newPacket; - newPacket.type = SerialPacketType::PONG; - network.SendTo(argPacket->srcAddress, &newPacket); - } + case SerialPacketType::PING: + HandlePing(static_cast(argPacket)); break; case SerialPacketType::PONG: - clientMgr.HandlePong(static_cast(argPacket)); + HandlePong(static_cast(argPacket)); break; //client connections case SerialPacketType::BROADCAST_REQUEST: -// HandleBroadcastRequest(static_cast(argPacket)); + HandleBroadcastRequest(static_cast(argPacket)); break; case SerialPacketType::JOIN_REQUEST: -// HandleJoinRequest(static_cast(argPacket)); + HandleJoinRequest(static_cast(argPacket)); break; case SerialPacketType::LOGIN_REQUEST: -// HandleLoginRequest(static_cast(argPacket)); + HandleLoginRequest(static_cast(argPacket)); break; //client disconnections - case SerialPacketType::DISCONNECT_REQUEST: -// HandleDisconnectRequest(static_cast(argPacket)); - break; - case SerialPacketType::DISCONNECT_FORCED: -// HandleDisconnectForced(static_cast(argPacket)); - break; case SerialPacketType::LOGOUT_REQUEST: -// HandleLogoutRequest(static_cast(argPacket)); + HandleLogoutRequest(static_cast(argPacket)); + break; + case SerialPacketType::DISCONNECT_REQUEST: + HandleDisconnectRequest(static_cast(argPacket)); break; //server commands - case SerialPacketType::SHUTDOWN_REQUEST: -// HandleShutdownRequest(static_cast(argPacket)); + case SerialPacketType::DISCONNECT_FORCED: +// HandleDisconnectForced(static_cast(argPacket)); break; - + case SerialPacketType::SHUTDOWN_REQUEST: + HandleShutdownRequest(static_cast(argPacket)); + break; +/* //data management & queries case SerialPacketType::REGION_REQUEST: // HandleRegionRequest(static_cast(argPacket)); @@ -310,7 +307,7 @@ void ServerApplication::HandlePacket(SerialPacket* const argPacket) { //TODO: enemy management //TODO: text - +*/ //handle errors default: { std::ostringstream msg; diff --git a/server/server_methods.cpp b/server/server_methods.cpp index 7e84f8e..202e075 100644 --- a/server/server_methods.cpp +++ b/server/server_methods.cpp @@ -25,11 +25,36 @@ #include #include +//------------------------- +//these should've come standard +//------------------------- + +bool operator==(IPaddress lhs, IPaddress rhs) { + return lhs.host == rhs.host && lhs.port == rhs.port; +} + +bool operator!=(IPaddress lhs, IPaddress rhs) { + return !(lhs == rhs); +} + +//------------------------- +//heartbeat system +//------------------------- + +void ServerApplication::HandlePing(ServerPacket* const argPacket) { + ServerPacket newPacket; + newPacket.type = SerialPacketType::PONG; + network.SendTo(argPacket->srcAddress, &newPacket); +} + +void ServerApplication::HandlePong(ServerPacket* const argPacket) { + clientMgr.HandlePong(argPacket); +} + //------------------------- //basic connections //------------------------- -//SET: utility void ServerApplication::HandleBroadcastRequest(ServerPacket* const argPacket) { //send the server's data ServerPacket newPacket; @@ -42,14 +67,33 @@ void ServerApplication::HandleBroadcastRequest(ServerPacket* const argPacket) { network.SendTo(argPacket->srcAddress, static_cast(&newPacket)); } -//SET: connections void ServerApplication::HandleJoinRequest(ClientPacket* const argPacket) { //register the client int clientIndex = clientMgr.Create(argPacket->srcAddress); + //send the client their info + ClientPacket newPacket; + newPacket.type = SerialPacketType::JOIN_RESPONSE; + newPacket.clientIndex = clientIndex; + + network.SendTo(argPacket->srcAddress, static_cast(&newPacket)); + + //finished this routine + std::cout << "New join, " << clientMgr.GetLoadedCount() << " clients and " << accountMgr.GetLoadedCount() << " accounts total" << std::endl; +} + +void ServerApplication::HandleLoginRequest(ClientPacket* const argPacket) { + //get the client data + ClientData* clientData = clientMgr.Get(argPacket->clientIndex); + + if (clientData == nullptr || clientData->GetAddress() != argPacket->srcAddress) { + std::cerr << "Falsified client index detected: " << argPacket->clientIndex << std::endl; + //TODO: rejection message? + return; + } + //load the user account - //TODO: handle passwords - int accountIndex = accountMgr.Load(argPacket->username, clientIndex); + int accountIndex = accountMgr.Load(argPacket->username, argPacket->clientIndex); //Cannot load if (accountIndex < 0) { @@ -57,85 +101,132 @@ void ServerApplication::HandleJoinRequest(ClientPacket* const argPacket) { msg << "Account already loaded: " << argPacket->username; TextPacket newPacket; - newPacket.type = SerialPacketType::JOIN_REJECTION; - memset(newPacket.name, 0, PACKET_STRING_SIZE); + newPacket.type = SerialPacketType::LOGIN_REJECTION; +// memset(newPacket.name, 0, PACKET_STRING_SIZE); strncpy(newPacket.text, msg.str().c_str(), PACKET_STRING_SIZE); - network.SendTo(argPacket->srcAddress, static_cast(&newPacket)); - clientMgr.Unload(clientIndex); + network.SendTo(clientData->GetAddress(), static_cast(&newPacket)); return; } //send the client their info ClientPacket newPacket; - newPacket.type = SerialPacketType::JOIN_RESPONSE; - newPacket.clientIndex = clientIndex; + newPacket.type = SerialPacketType::LOGIN_RESPONSE; + newPacket.clientIndex = argPacket->clientIndex; newPacket.accountIndex = accountIndex; - network.SendTo(argPacket->srcAddress, static_cast(&newPacket)); + network.SendTo(clientData->GetAddress(), static_cast(&newPacket)); //finished this routine - std::cout << "New connection, " << clientMgr.GetLoadedCount() << " clients and " << accountMgr.GetLoadedCount() << " accounts total" << std::endl; + std::cout << "New login, " << clientMgr.GetLoadedCount() << " clients and " << accountMgr.GetLoadedCount() << " accounts total" << std::endl; } -//SET: connections -void ServerApplication::HandleDisconnect(ClientPacket* const argPacket) { - //TODO: authenticate who is disconnecting/kicking - /*Pseudocode: - if sender's account index -> client index -> address == sender's address then - continue - end - if sender's account index -> admin == true OR sender's account index -> mod == true then - continue - end - if neither of the above is true, then output a warning to the console, and return - */ +void ServerApplication::HandleLogoutRequest(ClientPacket* const argPacket) { + //get the account and client data + AccountData* accountData = accountMgr.Get(argPacket->accountIndex); + ClientData* clientData = clientMgr.Get(accountData->GetClientIndex()); - //forward to the specified client - network.SendTo( - clientMgr.Get(accountMgr.Get(argPacket->accountIndex)->GetClientIndex())->GetAddress(), - static_cast(argPacket) - ); + if (clientData->GetAddress() != argPacket->srcAddress) { + std::cerr << "Falsified logout detected targeting: " << accountData->GetUsername() << std::endl; + return; + } - //save and unload this account's characters + //send the logout response + ClientPacket newPacket; + newPacket.type = SerialPacketType::LOGOUT_RESPONSE; + newPacket.clientIndex = accountData->GetClientIndex(); + newPacket.accountIndex = argPacket->accountIndex; + + network.SendTo(clientData->GetAddress(), static_cast(&newPacket)); + + //save and unload this accounts characters characterMgr.UnloadIf([&](std::pair it) -> bool { if (argPacket->accountIndex == it.second.GetOwner()) { //pump the unload message to all remaining clients - PumpCharacterUnload(it.first); +// PumpCharacterUnload(it.first); return true; } return false; }); - //erase the in-memory stuff - clientMgr.Unload(accountMgr.Get(argPacket->accountIndex)->GetClientIndex()); + //unload this account accountMgr.Unload(argPacket->accountIndex); //finished this routine - std::cout << "Disconnection, " << clientMgr.GetLoadedCount() << " clients and " << accountMgr.GetLoadedCount() << " accounts total" << std::endl; + std::cout << "New logout, " << clientMgr.GetLoadedCount() << " clients and " << accountMgr.GetLoadedCount() << " accounts total" << std::endl; } -//SET: connections -void ServerApplication::HandleShutdown(ClientPacket* const argPacket) { - //TODO: authenticate who is shutting the server down - /*Pseudocode: - if sender's account -> admin is not true then - print a warning - return - end - */ +void ServerApplication::HandleDisconnectRequest(ClientPacket* const argPacket) { + //get the client data + ClientData* clientData = clientMgr.Get(argPacket->clientIndex); + + if (clientData->GetAddress() != argPacket->srcAddress) { + std::cerr << "Falsified disconnection detected targeting: " << argPacket->clientIndex << std::endl; + return; + } + + //send the disconnect response + ClientPacket newPacket; + newPacket.type = SerialPacketType::DISCONNECT_RESPONSE; + newPacket.clientIndex = argPacket->clientIndex; + + network.SendTo(clientData->GetAddress(), static_cast(&newPacket)); + + //TODO: need a method for this redundunt chunk of redundant code + //find and unload the accounts associated with this client + accountMgr.UnloadIf([&](std::pair account) -> bool { + if (account.second.GetClientIndex() == argPacket->clientIndex) { + //find and unload the characters associated with this account + characterMgr.UnloadIf([&](std::pair character) -> bool { + if (character.second.GetOwner() == account.first) { +// PumpCharacterUnload(character.first); + return true; + } + return false; + }); + return true; + } + return false; + }); + + //unload this client + clientMgr.Unload(argPacket->clientIndex); + + //finished this routine + std::cout << "New disconnection, " << clientMgr.GetLoadedCount() << " clients and " << accountMgr.GetLoadedCount() << " accounts total" << std::endl; +} + +//------------------------- +//server commands +//------------------------- + +//void ServerApplication::HandleDisconnectForced(ClientPacket* const argPacket) { +// //TODO +//} + +void ServerApplication::HandleShutdownRequest(ClientPacket* const argPacket) { + //get the account and client data + AccountData* accountData = accountMgr.Get(argPacket->accountIndex); + ClientData* clientData = clientMgr.Get(accountData->GetClientIndex()); + + if (clientData->GetAddress() != argPacket->srcAddress || accountData->GetAdministrator() != true) { + std::cerr << "Falsified server shutdown detected from: " << accountData->GetUsername() << std::endl; + return; + } //end the server running = false; //disconnect all clients - ClientPacket newPacket; - newPacket.type = SerialPacketType::DISCONNECT_FORCED; - PumpPacket(&newPacket); +// ClientPacket newPacket; +// newPacket.type = SerialPacketType::DISCONNECT_FORCED; +// PumpPacket(&newPacket); //finished this routine std::cout << "Shutdown signal accepted" << std::endl; } +/* + //------------------------- //map management //------------------------- @@ -351,4 +442,7 @@ void ServerApplication::CopyCharacterToPacket(CharacterPacket* const packet, int packet->roomIndex = character->GetRoomIndex(); packet->origin = character->GetOrigin(); packet->motion = character->GetMotion(); -} \ No newline at end of file +} + +//TODO: remove this terminate comment +//*/ \ No newline at end of file From 5eeda8235dc337812af39fd71fed0f9f21d4073c Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Sun, 23 Nov 2014 06:38:40 +1100 Subject: [PATCH 29/73] Fixed the scripts struggling with nested API tables I actually don't remember what the RoomData's lua references where for, but I'm pretty srue it wasn't this. I'll figure something out when I've had a sleep. --- rsc/scripts/map_maker.lua | 16 +++++++++------- rsc/scripts/map_saver.lua | 4 +++- rsc/scripts/setup_server.lua | 26 ++++++++++++++++++++++++-- server/rooms/room_api.cpp | 32 ++++++++++++++++++++++++++++++++ server/rooms/room_system_api.cpp | 2 +- 5 files changed, 69 insertions(+), 11 deletions(-) diff --git a/rsc/scripts/map_maker.lua b/rsc/scripts/map_maker.lua index 3c1ca18..ca9ebc8 100644 --- a/rsc/scripts/map_maker.lua +++ b/rsc/scripts/map_maker.lua @@ -1,3 +1,5 @@ +local mapSystem = require "map_system" + local mapMaker = {} --utility functions @@ -19,16 +21,16 @@ mapMaker.dirt = 18 + 3 * 4 --custom generation systems here function mapMaker.debugIsland(region) - for i = 1, Region.GetWidth(region) do - for j = 1, Region.GetHeight(region) do - local dist = mapMaker.dist(0, 0, i + Region.GetX(region) -1, j + Region.GetY(region) -1) + for i = 1, mapSystem.Region.GetWidth(region) do + for j = 1, mapSystem.Region.GetHeight(region) do + local dist = mapMaker.dist(0, 0, i + mapSystem.Region.GetX(region) -1, j + mapSystem.Region.GetY(region) -1) if dist < 10 then - Region.SetTile(region, i, j, 1, mapMaker.plains) + mapSystem.Region.SetTile(region, i, j, 1, mapMaker.plains) elseif dist < 12 then - Region.SetTile(region, i, j, 1, mapMaker.sand) + mapSystem.Region.SetTile(region, i, j, 1, mapMaker.sand) else - Region.SetTile(region, i, j, 1, mapMaker.water) - Region.SetSolid(region, i, j, true) + mapSystem.Region.SetTile(region, i, j, 1, mapMaker.water) + mapSystem.Region.SetSolid(region, i, j, true) end end end diff --git a/rsc/scripts/map_saver.lua b/rsc/scripts/map_saver.lua index f521381..6ec65fd 100644 --- a/rsc/scripts/map_saver.lua +++ b/rsc/scripts/map_saver.lua @@ -1 +1,3 @@ ---TODO: create a flexible saving & loading system \ No newline at end of file +local mapSaver = {} +--TODO: create a flexible saving & loading system +return mapSaver \ No newline at end of file diff --git a/rsc/scripts/setup_server.lua b/rsc/scripts/setup_server.lua index f9dbc07..15526d4 100644 --- a/rsc/scripts/setup_server.lua +++ b/rsc/scripts/setup_server.lua @@ -4,8 +4,30 @@ mapMaker = require "map_maker" mapSaver = require "map_saver" roomSystem = require "room_system" +local function dumpTable(t) + print(t) + for k, v in pairs(t) do + print("",k, v) + end +end + +dumpTable(mapMaker) +dumpTable(mapSaver) +dumpTable(roomSystem) +dumpTable(roomSystem.Room) +dumpTable(roomSystem.RoomManager) + --create the overworld, set it's generator, loader & saver -local overworld = roomSystem.CreateRoom("overworld", "overworld.bmp") -roomSystem.SetOnLoad(overworld, mapMaker.debugIsland, mapSaver.load, mapSaver.save) +local overworld = roomSystem.RoomManager.CreateRoom("overworld", "overworld.bmp") +roomSystem.Room.SetOnLoad(overworld, 1123) +roomSystem.Room.SetOnUnload(overworld, 458) + +if roomSystem.Room.GetOnLoad(overworld) == 1123 then + print("onload retreival works") +end + +if roomSystem.Room.GetOnUnload(overworld) == 458 then + print("onunload retreival works") +end print("Finished the lua script") diff --git a/server/rooms/room_api.cpp b/server/rooms/room_api.cpp index 57a90ec..e443bf8 100644 --- a/server/rooms/room_api.cpp +++ b/server/rooms/room_api.cpp @@ -55,12 +55,44 @@ static int getPager(lua_State* L) { //TODO: GetEntityList? +static int setLoadReference(lua_State* L) { + RoomData* room = reinterpret_cast(lua_touserdata(L, 1)); + luaL_unref(L, LUA_REGISTRYINDEX, room->GetLoadReference()); + room->SetLoadReference(luaL_ref(L, LUA_REGISTRYINDEX)); + return 0; +} + +static int getLoadReference(lua_State* L) { + RoomData* room = reinterpret_cast(lua_touserdata(L, 1)); + lua_pushinteger(L, room->GetLoadReference()); + lua_gettable(L, LUA_REGISTRYINDEX); + return 1; +} + +static int setUnloadReference(lua_State* L) { + RoomData* room = reinterpret_cast(lua_touserdata(L, 1)); + luaL_unref(L, LUA_REGISTRYINDEX, room->GetUnloadReference()); + room->SetUnloadReference(luaL_ref(L, LUA_REGISTRYINDEX)); + return 0; +} + +static int getUnloadReference(lua_State* L) { + RoomData* room = reinterpret_cast(lua_touserdata(L, 1)); + lua_pushinteger(L, room->GetUnloadReference()); + lua_gettable(L, LUA_REGISTRYINDEX); + return 1; +} + static const luaL_Reg roomLib[] = { {"GetPager",getPager}, {"SetRoomName", setRoomName}, {"GetRoomName", getRoomName}, {"SetTileset", setTilesetName}, {"GetTileset", getTilesetName}, + {"SetOnLoad", setLoadReference}, + {"GetOnLoad", getLoadReference}, + {"SetOnUnload", setUnloadReference}, + {"GetOnUnload", getUnloadReference}, {nullptr, nullptr} }; diff --git a/server/rooms/room_system_api.cpp b/server/rooms/room_system_api.cpp index d0d47e0..17b6243 100644 --- a/server/rooms/room_system_api.cpp +++ b/server/rooms/room_system_api.cpp @@ -48,7 +48,7 @@ int openRoomSystemAPI(lua_State* L) { //push the substable for (const luaL_Reg* lib = libs; lib->func; lib++) { - lua_pushcfunction(L, lib->func); + lib->func(L); lua_setfield(L, -2, lib->name); } return 1; From 9ba76c8987fda91854cd8906f7baa11e311bcc8b Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Wed, 26 Nov 2014 06:11:27 +1100 Subject: [PATCH 30/73] Added RegionPagerLua destructor --- common/map/region_pager_lua.cpp | 14 ++++++++++++++ common/map/region_pager_lua.hpp | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/common/map/region_pager_lua.cpp b/common/map/region_pager_lua.cpp index d8fb538..4eeea2b 100644 --- a/common/map/region_pager_lua.cpp +++ b/common/map/region_pager_lua.cpp @@ -23,6 +23,17 @@ #include +RegionPagerLua::~RegionPagerLua() { + //unload all regions + UnloadAll(); + //clear any stored functions + luaL_unref(lua, LUA_REGISTRYINDEX, loadRef); + luaL_unref(lua, LUA_REGISTRYINDEX, saveRef); + luaL_unref(lua, LUA_REGISTRYINDEX, createRef); + luaL_unref(lua, LUA_REGISTRYINDEX, unloadRef); +} + +//return the loaded region, or nullptr on failure Region* RegionPagerLua::LoadRegion(int x, int y) { //get the pager's function from the registry lua_rawgeti(lua, LUA_REGISTRYINDEX, loadRef); @@ -54,6 +65,7 @@ Region* RegionPagerLua::LoadRegion(int x, int y) { } } +//return the saved region, or nullptr on failure Region* RegionPagerLua::SaveRegion(int x, int y) { //get the pager's function from the registry lua_rawgeti(lua, LUA_REGISTRYINDEX, saveRef); @@ -88,6 +100,7 @@ Region* RegionPagerLua::SaveRegion(int x, int y) { } } +//return the created region, or nullptr on failure Region* RegionPagerLua::CreateRegion(int x, int y) { if (FindRegion(x, y)) { throw(std::logic_error("Cannot overwrite an existing region")); @@ -116,6 +129,7 @@ Region* RegionPagerLua::CreateRegion(int x, int y) { return ®ionList.front(); } +//no return void RegionPagerLua::UnloadRegion(int x, int y) { //get the pager's function from the registry lua_rawgeti(lua, LUA_REGISTRYINDEX, unloadRef); diff --git a/common/map/region_pager_lua.hpp b/common/map/region_pager_lua.hpp index d23260f..656074c 100644 --- a/common/map/region_pager_lua.hpp +++ b/common/map/region_pager_lua.hpp @@ -35,7 +35,7 @@ class RegionPagerLua : public RegionPagerBase { public: RegionPagerLua() = default; - ~RegionPagerLua() = default; + ~RegionPagerLua(); //region manipulation Region* LoadRegion(int x, int y) override; From 81a3a92603eb554076415bdf2130dfd73857f94a Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Wed, 26 Nov 2014 06:12:01 +1100 Subject: [PATCH 31/73] Simplified setup_server.lua --- rsc/scripts/setup_server.lua | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/rsc/scripts/setup_server.lua b/rsc/scripts/setup_server.lua index 15526d4..71ebf50 100644 --- a/rsc/scripts/setup_server.lua +++ b/rsc/scripts/setup_server.lua @@ -11,23 +11,20 @@ local function dumpTable(t) end end -dumpTable(mapMaker) -dumpTable(mapSaver) -dumpTable(roomSystem) -dumpTable(roomSystem.Room) -dumpTable(roomSystem.RoomManager) - --create the overworld, set it's generator, loader & saver -local overworld = roomSystem.RoomManager.CreateRoom("overworld", "overworld.bmp") -roomSystem.Room.SetOnLoad(overworld, 1123) -roomSystem.Room.SetOnUnload(overworld, 458) +--[[ +local t = { + "overworld.bmp", --tileset name + mapSaver.load, --load function + mapSaver.save, --save function + mapMaker.debugIsland, --create function + mapSaver.save --unload function +}]] -if roomSystem.Room.GetOnLoad(overworld) == 1123 then - print("onload retreival works") -end +dumpTable(roomSystem) +dumpTable(roomSystem.RoomManager) +dumpTable(roomSystem.Room) -if roomSystem.Room.GetOnUnload(overworld) == 458 then - print("onunload retreival works") -end +local overworld = roomSystem.RoomManager.CreateRoom("overworld") print("Finished the lua script") From 6485839dcf9c5a87cff625efc2aaca7b8f07d915 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Wed, 26 Nov 2014 06:33:02 +1100 Subject: [PATCH 32/73] Replaced RoomData's hooks with Initialize API function --- rsc/scripts/map_saver.lua | 6 +++++ rsc/scripts/setup_server.lua | 1 + server/rooms/room_api.cpp | 42 +++++++++---------------------- server/rooms/room_data.cpp | 16 ------------ server/rooms/room_data.hpp | 11 -------- server/rooms/room_manager_api.cpp | 3 ++- 6 files changed, 21 insertions(+), 58 deletions(-) diff --git a/rsc/scripts/map_saver.lua b/rsc/scripts/map_saver.lua index 6ec65fd..0d7431f 100644 --- a/rsc/scripts/map_saver.lua +++ b/rsc/scripts/map_saver.lua @@ -1,3 +1,9 @@ local mapSaver = {} +function mapSaver.Load(region) + --empty +end +function mapSaver.Save(region) + --empty +end --TODO: create a flexible saving & loading system return mapSaver \ No newline at end of file diff --git a/rsc/scripts/setup_server.lua b/rsc/scripts/setup_server.lua index 71ebf50..3b4c46b 100644 --- a/rsc/scripts/setup_server.lua +++ b/rsc/scripts/setup_server.lua @@ -26,5 +26,6 @@ dumpTable(roomSystem.RoomManager) dumpTable(roomSystem.Room) local overworld = roomSystem.RoomManager.CreateRoom("overworld") +roomSystem.Room.Initialize(overworld, "overworld.bmp", mapSaver.Load, mapSaver.Save, mapMaker.debugIsland, mapSaver.Save) print("Finished the lua script") diff --git a/server/rooms/room_api.cpp b/server/rooms/room_api.cpp index e443bf8..6edcc38 100644 --- a/server/rooms/room_api.cpp +++ b/server/rooms/room_api.cpp @@ -53,46 +53,28 @@ static int getPager(lua_State* L) { return 1; } -//TODO: GetEntityList? +static int initialize(lua_State* L) { + //set the members of the given room + RoomData* room = static_cast(lua_touserdata(L, 1)); + room->SetRoomName(lua_tostring(L, 2)); -static int setLoadReference(lua_State* L) { - RoomData* room = reinterpret_cast(lua_touserdata(L, 1)); - luaL_unref(L, LUA_REGISTRYINDEX, room->GetLoadReference()); - room->SetLoadReference(luaL_ref(L, LUA_REGISTRYINDEX)); + //set the refs of these parameters (backwards, since it pops from the top of the stack) + room->GetPager()->SetUnloadReference(luaL_ref(L, LUA_REGISTRYINDEX)); + room->GetPager()->SetCreateReference(luaL_ref(L, LUA_REGISTRYINDEX)); + room->GetPager()->SetSaveReference(luaL_ref(L, LUA_REGISTRYINDEX)); + room->GetPager()->SetLoadReference(luaL_ref(L, LUA_REGISTRYINDEX)); + + //more parameters can be added here later return 0; } -static int getLoadReference(lua_State* L) { - RoomData* room = reinterpret_cast(lua_touserdata(L, 1)); - lua_pushinteger(L, room->GetLoadReference()); - lua_gettable(L, LUA_REGISTRYINDEX); - return 1; -} - -static int setUnloadReference(lua_State* L) { - RoomData* room = reinterpret_cast(lua_touserdata(L, 1)); - luaL_unref(L, LUA_REGISTRYINDEX, room->GetUnloadReference()); - room->SetUnloadReference(luaL_ref(L, LUA_REGISTRYINDEX)); - return 0; -} - -static int getUnloadReference(lua_State* L) { - RoomData* room = reinterpret_cast(lua_touserdata(L, 1)); - lua_pushinteger(L, room->GetUnloadReference()); - lua_gettable(L, LUA_REGISTRYINDEX); - return 1; -} - static const luaL_Reg roomLib[] = { {"GetPager",getPager}, {"SetRoomName", setRoomName}, {"GetRoomName", getRoomName}, {"SetTileset", setTilesetName}, {"GetTileset", getTilesetName}, - {"SetOnLoad", setLoadReference}, - {"GetOnLoad", getLoadReference}, - {"SetOnUnload", setUnloadReference}, - {"GetOnUnload", getUnloadReference}, + {"Initialize", initialize}, {nullptr, nullptr} }; diff --git a/server/rooms/room_data.cpp b/server/rooms/room_data.cpp index 7fb9061..e21b439 100644 --- a/server/rooms/room_data.cpp +++ b/server/rooms/room_data.cpp @@ -44,19 +44,3 @@ RegionPagerLua* RoomData::GetPager() { std::list* RoomData::GetEntityList() { return &entityList; } - -int RoomData::SetLoadReference(int i) { - return loadRef = i; -} - -int RoomData::GetLoadReference() { - return loadRef; -} - -int RoomData::SetUnloadReference(int i) { - return unloadRef = i; -} - -int RoomData::GetUnloadReference() { - return unloadRef; -} \ No newline at end of file diff --git a/server/rooms/room_data.hpp b/server/rooms/room_data.hpp index 78612fe..069e84c 100644 --- a/server/rooms/room_data.hpp +++ b/server/rooms/room_data.hpp @@ -49,12 +49,6 @@ public: RegionPagerLua* GetPager(); std::list* GetEntityList(); - //hooks - int SetLoadReference(int); - int GetLoadReference(); - int SetUnloadReference(int); - int GetUnloadReference(); - private: friend class RoomManager; @@ -64,11 +58,6 @@ private: RegionPagerLua pager; std::list entityList; - - //lua references - //TODO: use RoomData's lua references for load and unload functions - int loadRef = LUA_NOREF; - int unloadRef = LUA_NOREF; }; #endif diff --git a/server/rooms/room_manager_api.cpp b/server/rooms/room_manager_api.cpp index 880022f..7225a75 100644 --- a/server/rooms/room_manager_api.cpp +++ b/server/rooms/room_manager_api.cpp @@ -24,6 +24,7 @@ #include "room_manager.hpp" int createRoom(lua_State* L) { + //create & get the room RoomManager& roomMgr = RoomManager::GetSingleton(); int uid = roomMgr.Create("",""); //TODO: All new managers need their internals fleshed out @@ -32,7 +33,7 @@ int createRoom(lua_State* L) { //setup the room //TODO: room parameters only set via lua, fix this room->SetRoomName(lua_tostring(L, 1)); - room->SetTilesetName(lua_tostring(L, 2)); +// room->SetTilesetName(lua_tostring(L, 2)); //return room, uid lua_pushlightuserdata(L, static_cast(room)); From fa0d232727ffbdb95663c2c9ed15591a04421525 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Wed, 26 Nov 2014 06:41:29 +1100 Subject: [PATCH 33/73] Removed one parameter from RoomManager::Create() --- server/rooms/room_manager.cpp | 19 ++----------------- server/rooms/room_manager.hpp | 11 ++++++----- server/rooms/room_manager_api.cpp | 7 +------ 3 files changed, 9 insertions(+), 28 deletions(-) diff --git a/server/rooms/room_manager.cpp b/server/rooms/room_manager.cpp index 26d5042..cefd11a 100644 --- a/server/rooms/room_manager.cpp +++ b/server/rooms/room_manager.cpp @@ -29,25 +29,16 @@ //public access methods //------------------------- -int RoomManager::Create(std::string roomName, std::string tilesetName) { +int RoomManager::Create(std::string roomName) { //create the room RoomData* newRoom = &elementMap[counter]; //implicitly constructs the element + newRoom->SetRoomName(roomName); newRoom->pager.SetLuaState(lua); //finish the routine return counter++; } -int RoomManager::Load(std::string roomName, std::string tilesetName) { - //TODO: RoomManager::Load() - return -1; -} - -int RoomManager::Save(int uid) { - //TODO: RoomManager::Save(uid) - return -1; -} - void RoomManager::Unload(int uid) { //find the room std::map::iterator it = elementMap.find(uid); @@ -59,12 +50,6 @@ void RoomManager::Unload(int uid) { elementMap.erase(uid); } -void RoomManager::Delete(int uid) { - //TODO: RoomManager::Delete(int uid) - //NOTE: aliased to RoomManager::Unload(int uid) - Unload(uid); -} - void RoomManager::UnloadAll() { elementMap.clear(); } diff --git a/server/rooms/room_manager.hpp b/server/rooms/room_manager.hpp index 228b692..1b659d0 100644 --- a/server/rooms/room_manager.hpp +++ b/server/rooms/room_manager.hpp @@ -34,15 +34,12 @@ class RoomManager: public Singleton, - public ManagerInterface + public ManagerInterface { public: //common public methods - int Create(std::string, std::string) override; - int Load(std::string, std::string) override; - int Save(int uid) override; + int Create(std::string) override; void Unload(int uid) override; - void Delete(int uid) override; void UnloadAll() override; void UnloadIf(std::function)> fn) override; @@ -63,6 +60,10 @@ private: RoomManager() = default; ~RoomManager() = default; + int Load(std::string) override { return -1; } + int Save(int uid) override { return -1; } + void Delete(int uid) override { } + lua_State* lua = nullptr; int counter = 0; }; diff --git a/server/rooms/room_manager_api.cpp b/server/rooms/room_manager_api.cpp index 7225a75..091f794 100644 --- a/server/rooms/room_manager_api.cpp +++ b/server/rooms/room_manager_api.cpp @@ -27,14 +27,9 @@ int createRoom(lua_State* L) { //create & get the room RoomManager& roomMgr = RoomManager::GetSingleton(); - int uid = roomMgr.Create("",""); //TODO: All new managers need their internals fleshed out + int uid = roomMgr.Create(lua_tostring(L, 1)); RoomData* room = roomMgr.Get(uid); - //setup the room - //TODO: room parameters only set via lua, fix this - room->SetRoomName(lua_tostring(L, 1)); -// room->SetTilesetName(lua_tostring(L, 2)); - //return room, uid lua_pushlightuserdata(L, static_cast(room)); lua_pushinteger(L, uid); From 01461deaa557ee4f7772873f5dba780906e9e316 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Wed, 26 Nov 2014 07:11:27 +1100 Subject: [PATCH 34/73] Set the values for packets, and added getRoom() --- common/network/serial_packet_type.hpp | 64 +++++++++++++-------------- server/rooms/room_manager_api.cpp | 17 ++++++- 2 files changed, 48 insertions(+), 33 deletions(-) diff --git a/common/network/serial_packet_type.hpp b/common/network/serial_packet_type.hpp index 7b50b93..be1b1d3 100644 --- a/common/network/serial_packet_type.hpp +++ b/common/network/serial_packet_type.hpp @@ -38,12 +38,12 @@ enum class SerialPacketType { //------------------------- //heartbeat - PING, - PONG, + PING = 1, + PONG = 2, //Used for finding available servers - BROADCAST_REQUEST, - BROADCAST_RESPONSE, + BROADCAST_REQUEST = 3, + BROADCAST_RESPONSE = 4, //------------------------- //ClientPacket @@ -51,24 +51,24 @@ enum class SerialPacketType { //------------------------- //Connecting to a server as a client - JOIN_REQUEST, - JOIN_RESPONSE, + JOIN_REQUEST = 5, + JOIN_RESPONSE = 6, //disconnect from the server - DISCONNECT_REQUEST, - DISCONNECT_RESPONSE, - DISCONNECT_FORCED, + DISCONNECT_REQUEST = 7, + DISCONNECT_RESPONSE = 8, + DISCONNECT_FORCED = 9, //load the account - LOGIN_REQUEST, - LOGIN_RESPONSE, + LOGIN_REQUEST = 10, + LOGIN_RESPONSE = 11, //unload the account - LOGOUT_REQUEST, - LOGOUT_RESPONSE, + LOGOUT_REQUEST = 12, + LOGOUT_RESPONSE = 13, //shut down the server - SHUTDOWN_REQUEST, + SHUTDOWN_REQUEST = 14, //------------------------- //RegionPacket @@ -76,8 +76,8 @@ enum class SerialPacketType { //------------------------- //map data - REGION_REQUEST, //NOTE: technically a query - REGION_CONTENT, + REGION_REQUEST = 15, //NOTE: technically a query + REGION_CONTENT = 16, //------------------------- //CharacterPacket @@ -89,20 +89,20 @@ enum class SerialPacketType { //------------------------- //character management - CHARACTER_CREATE, - CHARACTER_DELETE, - CHARACTER_LOAD, - CHARACTER_UNLOAD, + CHARACTER_CREATE = 17, + CHARACTER_DELETE = 18, + CHARACTER_LOAD = 19, + CHARACTER_UNLOAD = 20, //find out info from the server - QUERY_CHARACTER_EXISTS, - QUERY_CHARACTER_STATS, - QUERY_CHARACTER_LOCATION, + QUERY_CHARACTER_EXISTS = 21, + QUERY_CHARACTER_STATS = 22, + QUERY_CHARACTER_LOCATION = 23, //set the info in the server - CHARACTER_SET_ROOM, - CHARACTER_SET_ORIGIN, - CHARACTER_SET_MOTION, + CHARACTER_SET_ROOM = 24, + CHARACTER_SET_ORIGIN = 25, + CHARACTER_SET_MOTION = 26, //TODO: enemy management @@ -112,19 +112,19 @@ enum class SerialPacketType { //------------------------- //general speech - TEXT_BROADCAST, + TEXT_BROADCAST = 27, //rejection/error messages - JOIN_REJECTION, - LOGIN_REJECTION, - CHARACTER_REJECTION, - SHUTDOWN_REJECTION, + JOIN_REJECTION = 28, + LOGIN_REJECTION = 29, + CHARACTER_REJECTION = 30, + SHUTDOWN_REJECTION = 31, //------------------------- //not used //------------------------- - LAST + LAST = 32 }; #endif \ No newline at end of file diff --git a/server/rooms/room_manager_api.cpp b/server/rooms/room_manager_api.cpp index 091f794..2494605 100644 --- a/server/rooms/room_manager_api.cpp +++ b/server/rooms/room_manager_api.cpp @@ -44,11 +44,26 @@ int unloadRoom(lua_State* L) { return 0; } -//TODO: lua API RoomManager.GetRoom(uid) +int getRoom(lua_State* L) { + //TODO: integer vs name for getRoom() + RoomManager& roomMgr = RoomManager::GetSingleton(); + + RoomData* room = roomMgr.Get(lua_tointeger(L, 1)); + + if (room) { + lua_pushlightuserdata(L, static_cast(room)); + } + else { + lua_pushnil(L); + } + + return 1; +} static const luaL_Reg roomManagerLib[] = { {"CreateRoom", createRoom}, {"UnloadRoom", unloadRoom}, + {"GetRoom", getRoom}, {nullptr, nullptr} }; From 584b6ea3036076d5960be51d980c10eef9120fe1 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Wed, 26 Nov 2014 07:51:24 +1100 Subject: [PATCH 35/73] Fixed a bug in deserializePacket() --- common/network/serial_utility.cpp | 2 +- server/server_logic.cpp | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/common/network/serial_utility.cpp b/common/network/serial_utility.cpp index 086e6a7..d440eb8 100644 --- a/common/network/serial_utility.cpp +++ b/common/network/serial_utility.cpp @@ -95,7 +95,7 @@ void deserializePacket(void* buffer, SerialPacketBase* packet) { SerialPacketType type; memcpy(&type, buffer, sizeof(SerialPacketType)); - switch(packet->type) { + switch(type) { case SerialPacketType::PING: case SerialPacketType::PONG: case SerialPacketType::BROADCAST_REQUEST: diff --git a/server/server_logic.cpp b/server/server_logic.cpp index df12171..5bc30e2 100644 --- a/server/server_logic.cpp +++ b/server/server_logic.cpp @@ -163,10 +163,18 @@ void ServerApplication::Init(int argc, char* argv[]) { void ServerApplication::Proc() { SerialPacket* packetBuffer = reinterpret_cast(new char[MAX_PACKET_SIZE]); + memset(packetBuffer, 0, MAX_PACKET_SIZE); //zero the buffer + while(running) { //suck in the waiting packets & process them while(UDPNetworkUtility::GetSingleton().Receive(packetBuffer)) { - HandlePacket(packetBuffer); + try { + HandlePacket(packetBuffer); + } + catch(std::exception& e) { + std::cerr << "HandlePacket Error: " << e.what() << std::endl; + } + memset(packetBuffer, 0, MAX_PACKET_SIZE); //reset the buffer } //update the internals //... From e5abd51f76e4673f8e6544811648e34799e6a5fa Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Wed, 26 Nov 2014 10:14:26 +1100 Subject: [PATCH 36/73] Two-step login system works perfectly; can't shut the server down I've also removed a large amount of commented and uncommented code from in_world.cpp, simply because so much code was dummied out. I can readd this code as I reimeplement various features. --- client/scenes/in_world.cpp | 425 +++++++------------------------------ client/scenes/in_world.hpp | 41 ++-- server/server_logic.cpp | 2 +- server/server_methods.cpp | 26 ++- 4 files changed, 119 insertions(+), 375 deletions(-) diff --git a/client/scenes/in_world.cpp b/client/scenes/in_world.cpp index d774c09..e1cce1c 100644 --- a/client/scenes/in_world.cpp +++ b/client/scenes/in_world.cpp @@ -23,12 +23,24 @@ #include "channels.hpp" #include "utility.hpp" -#include "config_utility.hpp" #include #include #include #include +#include + +//------------------------- +//these should've come standard +//------------------------- + +bool operator==(IPaddress lhs, IPaddress rhs) { + return lhs.host == rhs.host && lhs.port == rhs.port; +} + +bool operator!=(IPaddress lhs, IPaddress rhs) { + return !(lhs == rhs); +} //------------------------- //Public access members @@ -38,8 +50,6 @@ InWorld::InWorld(int* const argClientIndex, int* const argAccountIndex): clientIndex(*argClientIndex), accountIndex(*argAccountIndex) { - ConfigUtility& config = ConfigUtility::GetSingleton(); - //setup the utility objects buttonImage.LoadSurface(config["dir.interface"] + "button_menu.bmp"); buttonImage.SetClipH(buttonImage.GetClipH()/3); @@ -61,22 +71,6 @@ InWorld::InWorld(int* const argClientIndex, int* const argAccountIndex): disconnectButton.SetText("Disconnect"); shutDownButton.SetText("Shut Down"); - //load the tilesheet - //TODO: add the tilesheet to the map system? - //TODO: Tile size and tile sheet should be loaded elsewhere - tileSheet.Load(config["dir.tilesets"] + "overworld.bmp", 32, 32); - - //send this player's character info -// CharacterPacket newPacket; -// newPacket.type = SerialPacketType::CHARACTER_NEW; -// strncpy(newPacket.handle, config["client.handle"].c_str(), PACKET_STRING_SIZE); -// strncpy(newPacket.avatar, config["client.avatar"].c_str(), PACKET_STRING_SIZE); -// newPacket.accountIndex = accountIndex; -// network.SendTo(Channels::SERVER, &newPacket); - - //request a sync -// RequestSynchronize(); - //debug // } @@ -94,58 +88,30 @@ void InWorld::FrameStart() { } void InWorld::Update() { - //suck in and process all waiting packets + //create and zero the buffer SerialPacket* packetBuffer = reinterpret_cast(new char[MAX_PACKET_SIZE]); - while(network.Receive(packetBuffer)) { - HandlePacket(packetBuffer); - } - delete reinterpret_cast(packetBuffer); + memset(packetBuffer, 0, MAX_PACKET_SIZE); - //update the characters - for (auto& it : characterMap) { - it.second.Update(); - } - - //check the map - UpdateMap(); - - //skip the rest - if (!localCharacter) { - return; - } - - //check for collisions with the map - BoundingBox wallBounds = {0, 0, tileSheet.GetTileW(), tileSheet.GetTileH()}; - const int xCount = localCharacter->GetBounds().w / wallBounds.w + 1; - const int yCount = localCharacter->GetBounds().h / wallBounds.h + 1; - - for (int i = -1; i <= xCount; ++i) { - for (int j = -1; j <= yCount; ++j) { - //set the wall's position - wallBounds.x = wallBounds.w * i + snapToBase((double)wallBounds.w, localCharacter->GetOrigin().x); - wallBounds.y = wallBounds.h * j + snapToBase((double)wallBounds.h, localCharacter->GetOrigin().y); - - if (!regionPager.GetSolid(wallBounds.x / wallBounds.w, wallBounds.y / wallBounds.h)) { - continue; - } - - if ((localCharacter->GetOrigin() + localCharacter->GetBounds()).CheckOverlap(wallBounds)) { - localCharacter->SetOrigin(localCharacter->GetOrigin() - (localCharacter->GetMotion())); - localCharacter->SetMotion({0,0}); - localCharacter->CorrectSprite(); - SendPlayerUpdate(); - } + try { + //suck in and process all waiting packets + while(network.Receive(packetBuffer)) { + HandlePacket(packetBuffer); } } + catch(std::exception& e) { + std::cerr << "HandlePacket Error: " << e.what() << std::endl; + } - //update the camera (following the player) - camera.x = localCharacter->GetOrigin().x - camera.marginX; - camera.y = localCharacter->GetOrigin().y - camera.marginY; + //free the buffer + delete reinterpret_cast(packetBuffer); - //check the connection + //check the connection (heartbeat) if (Clock::now() - lastBeat > std::chrono::seconds(3)) { if (attemptedBeats > 2) { - RequestDisconnect(); + //two-step logout + SendLogoutRequest(); + SendDisconnectRequest(); + SetNextScene(SceneList::DISCONNECTEDSCREEN); ConfigUtility::GetSingleton()["client.disconnectMessage"] = "Error: Lost connection to the server"; } @@ -164,25 +130,13 @@ void InWorld::FrameEnd() { } void InWorld::RenderFrame() { -// SDL_FillRect(GetScreen(), 0, 0); + SDL_FillRect(GetScreen(), 0, 0); Render(GetScreen()); SDL_Flip(GetScreen()); fps.Calculate(); } void InWorld::Render(SDL_Surface* const screen) { - //draw the map - for (std::list::iterator it = regionPager.GetContainer()->begin(); it != regionPager.GetContainer()->end(); it++) { - tileSheet.DrawRegionTo(screen, &(*it), camera.x, camera.y); - } - - //draw characters - for (auto& it : characterMap) { - //BUG: #29 drawing order according to Y origin - //TODO: use a list of renderable objects - it.second.DrawTo(screen, camera.x, camera.y); - } - //draw UI disconnectButton.DrawTo(screen); shutDownButton.DrawTo(screen); @@ -194,8 +148,9 @@ void InWorld::Render(SDL_Surface* const screen) { //------------------------- void InWorld::QuitEvent() { - //exit the game AND the server - RequestDisconnect(); + //two-step logout + SendLogoutRequest(); + SendDisconnectRequest(); SetNextScene(SceneList::QUIT); } @@ -211,348 +166,124 @@ void InWorld::MouseButtonDown(SDL_MouseButtonEvent const& button) { void InWorld::MouseButtonUp(SDL_MouseButtonEvent const& button) { if (disconnectButton.MouseButtonUp(button) == Button::State::HOVER && button.button == SDL_BUTTON_LEFT) { - RequestDisconnect(); + SendLogoutRequest(); } if (shutDownButton.MouseButtonUp(button) == Button::State::HOVER && button.button == SDL_BUTTON_LEFT) { - RequestShutDown(); + SendShutdownRequest(); } } void InWorld::KeyDown(SDL_KeyboardEvent const& key) { - if (!localCharacter) { - return; - } - //hotkeys switch(key.keysym.sym) { case SDLK_ESCAPE: - RequestDisconnect(); + //the escape key should actually control menus and stuff + SendLogoutRequest(); break; } - - //player movement - Vector2 motion = localCharacter->GetMotion(); - switch(key.keysym.sym) { - case SDLK_LEFT: - motion.x -= CHARACTER_WALKING_SPEED; - break; - case SDLK_RIGHT: - motion.x += CHARACTER_WALKING_SPEED; - break; - case SDLK_UP: - motion.y -= CHARACTER_WALKING_SPEED; - break; - case SDLK_DOWN: - motion.y += CHARACTER_WALKING_SPEED; - break; - default: - return; - } - localCharacter->SetMotion(motion); - localCharacter->CorrectSprite(); - SendPlayerUpdate(); } void InWorld::KeyUp(SDL_KeyboardEvent const& key) { - if (!localCharacter) { - return; - } - - //player movement - Vector2 motion = localCharacter->GetMotion(); - switch(key.keysym.sym) { - //NOTE: The use of min/max here are to prevent awkward movements - case SDLK_LEFT: - motion.x = std::min(motion.x + CHARACTER_WALKING_SPEED, 0.0); - break; - case SDLK_RIGHT: - motion.x = std::max(motion.x - CHARACTER_WALKING_SPEED, 0.0); - break; - case SDLK_UP: - motion.y = std::min(motion.y + CHARACTER_WALKING_SPEED, 0.0); - break; - case SDLK_DOWN: - motion.y = std::max(motion.y - CHARACTER_WALKING_SPEED, 0.0); - break; - default: - return; - } - localCharacter->SetMotion(motion); - localCharacter->CorrectSprite(); - SendPlayerUpdate(); + // } //------------------------- -//Network handlers +//Basic connections //------------------------- void InWorld::HandlePacket(SerialPacket* const argPacket) { switch(argPacket->type) { //heartbeat system - case SerialPacketType::PING: { - ServerPacket newPacket; - newPacket.type = SerialPacketType::PONG; - network.SendTo(argPacket->srcAddress, &newPacket); - } + case SerialPacketType::PING: + HandlePing(static_cast(argPacket)); break; case SerialPacketType::PONG: -// HandlePong(static_cast(argPacket)); + HandlePong(static_cast(argPacket)); break; //game server connections case SerialPacketType::LOGOUT_RESPONSE: -// HandleLogoutResponse(static_cast(argPacket)); + HandleLogoutResponse(static_cast(argPacket)); break; - case SerialPacketType::DISCONNECT_REQUEST: -// HandleDisconnectRequest(static_cast(argPacket)); + case SerialPacketType::DISCONNECT_RESPONSE: + HandleDisconnectResponse(static_cast(argPacket)); break; case SerialPacketType::DISCONNECT_FORCED: -// HandleDisconnectForced(static_cast(argPacket)); + HandleDisconnectForced(static_cast(argPacket)); break; - //data management - case SerialPacketType::REGION_CONTENT: -// HandleRegionContent(static_cast(argPacket)); - break; -// case SerialPacketType::QUERY_CHARACTER_EXISTS: -// case SerialPacketType::QUERY_CHARACTER_STATS: -// case SerialPacketType::QUERY_CHARACTER_LOCATION: - - //character management -// case SerialPacketType::CHARACTER_NEW: -// HandleCharacterNew(static_cast(argPacket)); -// break; -// case SerialPacketType::CHARACTER_DELETE: -// HandleCharacterDelete(static_cast(argPacket)); -// break; -// case SerialPacketType::CHARACTER_UPDATE: -// HandleCharacterUpdate(static_cast(argPacket)); -// break; -// case SerialPacketType::CHARACTER_REJECTION: -// HandleCharacterRejection(static_cast(argPacket)); -// break; - - //enemy management - //TODO: enemy management - - //TODO: text - - //handle errors - default: - throw(std::runtime_error(std::string() + "Unknown SerialPacketType encountered in InWorld: " + to_string_custom(static_cast(argPacket->type)) )); + default: { + std::ostringstream msg; + msg << "Unknown SerialPacketType encountered in InWorld: " << static_cast(argPacket->type); + throw(std::runtime_error(msg.str())); + } break; } } +void InWorld::HandlePing(ServerPacket* const argPacket) { + ServerPacket newPacket; + newPacket.type = SerialPacketType::PONG; + network.SendTo(argPacket->srcAddress, &newPacket); +} + void InWorld::HandlePong(ServerPacket* const argPacket) { - if (network.GetIPAddress(Channels::SERVER)->host != argPacket->srcAddress.host) { + if (*network.GetIPAddress(Channels::SERVER) != argPacket->srcAddress) { throw(std::runtime_error("Heartbeat message received from an unknown source")); } - attemptedBeats = 0; lastBeat = Clock::now(); } -void InWorld::HandleDisconnect(ClientPacket* const argPacket) { - //TODO: More needed in the disconnection - SetNextScene(SceneList::DISCONNECTEDSCREEN); - ConfigUtility::GetSingleton()["client.disconnectMessage"] = "You have been disconnected"; -} - -void InWorld::HandleCharacterNew(CharacterPacket* const argPacket) { - if (characterMap.find(argPacket->characterIndex) != characterMap.end()) { - throw(std::runtime_error("Cannot create duplicate characters")); - } - - //create the character object - BaseCharacter& newCharacter = characterMap[argPacket->characterIndex]; - - //fill out the character's members - newCharacter.SetHandle(argPacket->handle); - newCharacter.SetAvatar(argPacket->avatar); - - newCharacter.GetSprite()->LoadSurface(ConfigUtility::GetSingleton()["dir.sprites"] + newCharacter.GetAvatar(), 4, 4); - - newCharacter.SetOrigin(argPacket->origin); - newCharacter.SetMotion(argPacket->motion); - newCharacter.SetBounds({ - CHARACTER_BOUNDS_X, - CHARACTER_BOUNDS_Y, - CHARACTER_BOUNDS_WIDTH, - CHARACTER_BOUNDS_HEIGHT - }); - -// (*newCharacter.GetBaseStats()) = argPacket->stats; - - //bookkeeping code - newCharacter.CorrectSprite(); - - //catch this client's player object - if (argPacket->accountIndex == accountIndex && !localCharacter) { - characterIndex = argPacket->characterIndex; - localCharacter = &newCharacter; - - //setup the camera - camera.width = GetScreen()->w; - camera.height = GetScreen()->h; - - //center on the player's character - camera.marginX = (GetScreen()->w / 2 - localCharacter->GetSprite()->GetImage()->GetClipW() / 2); - camera.marginY = (GetScreen()->h / 2 - localCharacter->GetSprite()->GetImage()->GetClipH() / 2); - } -} - -void InWorld::HandleCharacterDelete(CharacterPacket* const argPacket) { - //TODO: authenticate when own character is being deleted (linked to a TODO in the server) - - //catch this client's player object - if (argPacket->characterIndex == characterIndex) { - characterIndex = -1; - localCharacter = nullptr; - } - - characterMap.erase(argPacket->characterIndex); -} - -void InWorld::HandleCharacterUpdate(CharacterPacket* const argPacket) { - if (characterMap.find(argPacket->characterIndex) == characterMap.end()) { - HandleCharacterNew(argPacket); - return; - } - - BaseCharacter& character = characterMap[argPacket->characterIndex]; - - //other characters moving - if (argPacket->characterIndex != characterIndex) { - character.SetOrigin(argPacket->origin); - character.SetMotion(argPacket->motion); - character.CorrectSprite(); - } -} - -void InWorld::HandleCharacterRejection(TextPacket* const argPacket) { - RequestDisconnect(); - SetNextScene(SceneList::DISCONNECTEDSCREEN); - ConfigUtility& config = ConfigUtility::GetSingleton(); - config["client.disconnectMessage"] = "Error: "; - config["client.disconnectMessage"] += argPacket->text; -} - -void InWorld::HandleRegionContent(RegionPacket* const argPacket) { - //replace existing regions - regionPager.UnloadRegion(argPacket->x, argPacket->y); - regionPager.PushRegion(argPacket->region); - - //clean up after the serial code - delete argPacket->region; - argPacket->region = nullptr; -} - //------------------------- -//Server control +//Connection control //------------------------- -void InWorld::RequestSynchronize() { -// ClientPacket newPacket; +void InWorld::SendLogoutRequest() { + ClientPacket newPacket; - //request a sync -// newPacket.type = SerialPacketType::SYNCHRONIZE; -// newPacket.clientIndex = clientIndex; -// newPacket.accountIndex = accountIndex; - - //TODO: location, range for sync request - -// network.SendTo(Channels::SERVER, &newPacket); -} - -void InWorld::SendPlayerUpdate() { - CharacterPacket newPacket; - - //pack the packet -// newPacket.type = SerialPacketType::CHARACTER_UPDATE; - - newPacket.characterIndex = characterIndex; - //NOTE: omitting the handle and avatar here + //send a logout request + newPacket.type = SerialPacketType::LOGOUT_REQUEST; newPacket.accountIndex = accountIndex; - newPacket.roomIndex = 0; //TODO: room index - newPacket.origin = localCharacter->GetOrigin(); - newPacket.motion = localCharacter->GetMotion(); -// newPacket.stats = *localCharacter->GetBaseStats(); - - //TODO: gameplay components: equipment, items, buffs, debuffs network.SendTo(Channels::SERVER, &newPacket); } -void InWorld::RequestDisconnect() { +void InWorld::SendDisconnectRequest() { ClientPacket newPacket; //send a disconnect request newPacket.type = SerialPacketType::DISCONNECT_REQUEST; newPacket.clientIndex = clientIndex; - newPacket.accountIndex = accountIndex; network.SendTo(Channels::SERVER, &newPacket); } -void InWorld::RequestShutDown() { +void InWorld::SendShutdownRequest() { ClientPacket newPacket; //send a shutdown request newPacket.type = SerialPacketType::SHUTDOWN_REQUEST; - newPacket.clientIndex = clientIndex; newPacket.accountIndex = accountIndex; network.SendTo(Channels::SERVER, &newPacket); } -void InWorld::RequestRegion(int roomIndex, int x, int y) { - RegionPacket packet; +void InWorld::HandleLogoutResponse(ClientPacket* const argPacket) { + accountIndex = -1; - //pack the region's data - packet.type = SerialPacketType::REGION_REQUEST; - packet.roomIndex = roomIndex; - packet.x = x; - packet.y = y; + //TODO: unload the character - network.SendTo(Channels::SERVER, &packet); + SendDisconnectRequest(); } -//------------------------- -//Utilities -//------------------------- - -//TODO: convert this into a more generic function?; using parameters for the bounds -void InWorld::UpdateMap() { - //these represent the zone of regions that the client needs loaded, including the mandatory buffers (+1/-1) - int xStart = snapToBase(REGION_WIDTH, camera.x/tileSheet.GetTileW()) - REGION_WIDTH; - int xEnd = snapToBase(REGION_WIDTH, (camera.x+camera.width)/tileSheet.GetTileW()) + REGION_WIDTH; - - int yStart = snapToBase(REGION_HEIGHT, camera.y/tileSheet.GetTileH()) - REGION_HEIGHT; - int yEnd = snapToBase(REGION_HEIGHT, (camera.y+camera.height)/tileSheet.GetTileH()) + REGION_HEIGHT; - - //prune distant regions - for (std::list::iterator it = regionPager.GetContainer()->begin(); it != regionPager.GetContainer()->end(); /* EMPTY */) { - //check if the region is outside of this area - if (it->GetX() < xStart || it->GetX() > xEnd || it->GetY() < yStart || it->GetY() > yEnd) { - - //clunky, but the alternative was time consuming - int tmpX = it->GetX(); - int tmpY = it->GetY(); - ++it; - - regionPager.UnloadRegion(tmpX, tmpY); - continue; - } - ++it; - } - - //request empty regions within this zone - for (int i = xStart; i <= xEnd; i += REGION_WIDTH) { - for (int j = yStart; j <= yEnd; j += REGION_HEIGHT) { - if (!regionPager.FindRegion(i, j)) { - RequestRegion(0, i, j); - } - } - } +void InWorld::HandleDisconnectResponse(ClientPacket* const argPacket) { + SetNextScene(SceneList::DISCONNECTEDSCREEN); + ConfigUtility::GetSingleton()["client.disconnectMessage"] = "You have successfully logged out"; +} + +void InWorld::HandleDisconnectForced(ClientPacket* const argPacket) { + //TODO: More needed in the disconnection + SetNextScene(SceneList::DISCONNECTEDSCREEN); + ConfigUtility::GetSingleton()["client.disconnectMessage"] = "You have been forcibly disconnected by the server"; } diff --git a/client/scenes/in_world.hpp b/client/scenes/in_world.hpp index ce5c29b..dfced78 100644 --- a/client/scenes/in_world.hpp +++ b/client/scenes/in_world.hpp @@ -25,9 +25,10 @@ //maps #include "region_pager_base.hpp" -//networking +//utilities #include "udp_network_utility.hpp" #include "serial_packet.hpp" +#include "config_utility.hpp" //graphics #include "image.hpp" @@ -71,33 +72,23 @@ protected: void KeyDown(SDL_KeyboardEvent const&); void KeyUp(SDL_KeyboardEvent const&); - //Network handlers + //Basic connections void HandlePacket(SerialPacket* const); + void HandlePing(ServerPacket* const); void HandlePong(ServerPacket* const); - void HandleDisconnect(ClientPacket* const); - void HandleCharacterNew(CharacterPacket* const); - void HandleCharacterDelete(CharacterPacket* const); - void HandleCharacterUpdate(CharacterPacket* const); - void HandleCharacterRejection(TextPacket* const); - void HandleRegionContent(RegionPacket* const); - //Server control - void RequestSynchronize(); - void SendPlayerUpdate(); - void RequestDisconnect(); - void RequestShutDown(); - void RequestRegion(int roomIndex, int x, int y); + //Connection control + void SendLogoutRequest(); + void SendDisconnectRequest(); + void SendShutdownRequest(); - //utilities - void UpdateMap(); - - //singleton shortcut - UDPNetworkUtility& network = UDPNetworkUtility::GetSingleton(); + void HandleLogoutResponse(ClientPacket* const); + void HandleDisconnectResponse(ClientPacket* const); + void HandleDisconnectForced(ClientPacket* const); //indexes int& clientIndex; int& accountIndex; - int characterIndex = -1; //graphics Image buttonImage; @@ -119,16 +110,16 @@ protected: int marginX = 0, marginY = 0; } camera; - //game components - BaseCharacter* localCharacter = nullptr; - std::map characterMap; - std::map monsterMap; //heartbeat - //TODO: This needs it's own utility, for both InWorld and InCombat + //TODO: Heartbeat needs it's own utility typedef std::chrono::steady_clock Clock; Clock::time_point lastBeat = Clock::now(); int attemptedBeats = 0; + + //ugly references; I hate this + ConfigUtility& config = ConfigUtility::GetSingleton(); + UDPNetworkUtility& network = UDPNetworkUtility::GetSingleton(); }; #endif diff --git a/server/server_logic.cpp b/server/server_logic.cpp index 5bc30e2..da43e81 100644 --- a/server/server_logic.cpp +++ b/server/server_logic.cpp @@ -167,7 +167,7 @@ void ServerApplication::Proc() { while(running) { //suck in the waiting packets & process them - while(UDPNetworkUtility::GetSingleton().Receive(packetBuffer)) { + while(network.Receive(packetBuffer)) { try { HandlePacket(packetBuffer); } diff --git a/server/server_methods.cpp b/server/server_methods.cpp index 202e075..fad0985 100644 --- a/server/server_methods.cpp +++ b/server/server_methods.cpp @@ -123,8 +123,18 @@ void ServerApplication::HandleLoginRequest(ClientPacket* const argPacket) { void ServerApplication::HandleLogoutRequest(ClientPacket* const argPacket) { //get the account and client data AccountData* accountData = accountMgr.Get(argPacket->accountIndex); - ClientData* clientData = clientMgr.Get(accountData->GetClientIndex()); + if (!accountData) { + return; + } + ClientData* clientData = clientMgr.Get(accountData->GetClientIndex()); + if (!clientData) { + std::ostringstream msg; + msg << "No client found for an account: " << accountData->GetUserName(); + throw(std::logic_error(msg.str())); + } + + //check for fraud if (clientData->GetAddress() != argPacket->srcAddress) { std::cerr << "Falsified logout detected targeting: " << accountData->GetUsername() << std::endl; return; @@ -133,7 +143,6 @@ void ServerApplication::HandleLogoutRequest(ClientPacket* const argPacket) { //send the logout response ClientPacket newPacket; newPacket.type = SerialPacketType::LOGOUT_RESPONSE; - newPacket.clientIndex = accountData->GetClientIndex(); newPacket.accountIndex = argPacket->accountIndex; network.SendTo(clientData->GetAddress(), static_cast(&newPacket)); @@ -158,7 +167,11 @@ void ServerApplication::HandleLogoutRequest(ClientPacket* const argPacket) { void ServerApplication::HandleDisconnectRequest(ClientPacket* const argPacket) { //get the client data ClientData* clientData = clientMgr.Get(argPacket->clientIndex); + if (!clientData) { + return; + } + //check for fraud if (clientData->GetAddress() != argPacket->srcAddress) { std::cerr << "Falsified disconnection detected targeting: " << argPacket->clientIndex << std::endl; return; @@ -206,8 +219,17 @@ void ServerApplication::HandleDisconnectRequest(ClientPacket* const argPacket) { void ServerApplication::HandleShutdownRequest(ClientPacket* const argPacket) { //get the account and client data AccountData* accountData = accountMgr.Get(argPacket->accountIndex); + if (!accountData) { + return; + } ClientData* clientData = clientMgr.Get(accountData->GetClientIndex()); + if (!clientData) { + std::ostringstream msg; + msg << "No client found for an account: " << accountData->GetUserName(); + throw(std::logic_error(msg.str())); + } + //check for fraud if (clientData->GetAddress() != argPacket->srcAddress || accountData->GetAdministrator() != true) { std::cerr << "Falsified server shutdown detected from: " << accountData->GetUsername() << std::endl; return; From bac8bc2b41ddbce245dff49332c299e16c59f057 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Wed, 26 Nov 2014 10:28:57 +1100 Subject: [PATCH 37/73] Fixed a misspelled method call --- server/server_methods.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/server_methods.cpp b/server/server_methods.cpp index fad0985..b69068a 100644 --- a/server/server_methods.cpp +++ b/server/server_methods.cpp @@ -130,7 +130,7 @@ void ServerApplication::HandleLogoutRequest(ClientPacket* const argPacket) { ClientData* clientData = clientMgr.Get(accountData->GetClientIndex()); if (!clientData) { std::ostringstream msg; - msg << "No client found for an account: " << accountData->GetUserName(); + msg << "No client found for an account: " << accountData->GetUsername(); throw(std::logic_error(msg.str())); } @@ -225,7 +225,7 @@ void ServerApplication::HandleShutdownRequest(ClientPacket* const argPacket) { ClientData* clientData = clientMgr.Get(accountData->GetClientIndex()); if (!clientData) { std::ostringstream msg; - msg << "No client found for an account: " << accountData->GetUserName(); + msg << "No client found for an account: " << accountData->GetUsername(); throw(std::logic_error(msg.str())); } From b59cd0fe870a79a0dbe3574820adba343a51c809 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Sun, 30 Nov 2014 22:23:46 +1100 Subject: [PATCH 38/73] Server-side HandleRegionRequest() reimplemented Note that this locally handles bug #35, and adds a new packet type: REGION_REJECTION --- common/network/serial_packet_type.hpp | 7 +++-- common/network/serial_utility.cpp | 2 ++ server/server_application.hpp | 8 ++--- server/server_logic.cpp | 6 ++-- server/server_methods.cpp | 44 ++++++++++++++++++--------- 5 files changed, 43 insertions(+), 24 deletions(-) diff --git a/common/network/serial_packet_type.hpp b/common/network/serial_packet_type.hpp index be1b1d3..489f78d 100644 --- a/common/network/serial_packet_type.hpp +++ b/common/network/serial_packet_type.hpp @@ -117,14 +117,15 @@ enum class SerialPacketType { //rejection/error messages JOIN_REJECTION = 28, LOGIN_REJECTION = 29, - CHARACTER_REJECTION = 30, - SHUTDOWN_REJECTION = 31, + REGION_REJECTION = 30, + CHARACTER_REJECTION = 31, + SHUTDOWN_REJECTION = 32, //------------------------- //not used //------------------------- - LAST = 32 + LAST = 33 }; #endif \ No newline at end of file diff --git a/common/network/serial_utility.cpp b/common/network/serial_utility.cpp index d440eb8..f3874b6 100644 --- a/common/network/serial_utility.cpp +++ b/common/network/serial_utility.cpp @@ -83,6 +83,7 @@ void serializePacket(void* buffer, SerialPacketBase* packet) { case SerialPacketType::TEXT_BROADCAST: case SerialPacketType::JOIN_REJECTION: case SerialPacketType::LOGIN_REJECTION: + case SerialPacketType::REGION_REJECTION: case SerialPacketType::CHARACTER_REJECTION: case SerialPacketType::SHUTDOWN_REJECTION: serializeText(buffer, static_cast(packet)); @@ -133,6 +134,7 @@ void deserializePacket(void* buffer, SerialPacketBase* packet) { case SerialPacketType::TEXT_BROADCAST: case SerialPacketType::JOIN_REJECTION: case SerialPacketType::LOGIN_REJECTION: + case SerialPacketType::REGION_REJECTION: case SerialPacketType::CHARACTER_REJECTION: case SerialPacketType::SHUTDOWN_REJECTION: deserializeText(buffer, static_cast(packet)); diff --git a/server/server_application.hpp b/server/server_application.hpp index 77cb847..1f98437 100644 --- a/server/server_application.hpp +++ b/server/server_application.hpp @@ -87,8 +87,9 @@ private: // void HandleDisconnectForced(ClientPacket* const); void HandleShutdownRequest(ClientPacket* const); - //map management -// void HandleRegionRequest(RegionPacket* const); + //data management + void HandleRegionRequest(RegionPacket* const); + void SaveServerState(); //character management // void HandleCharacterNew(CharacterPacket* const); @@ -105,9 +106,6 @@ private: // void PumpCharacterUnload(int uid); // void CopyCharacterToPacket(CharacterPacket* const packet, int characterIndex); - //data management - void SaveServerState(); - //APIs and utilities sqlite3* database = nullptr; lua_State* luaState = nullptr; diff --git a/server/server_logic.cpp b/server/server_logic.cpp index da43e81..794cc57 100644 --- a/server/server_logic.cpp +++ b/server/server_logic.cpp @@ -268,11 +268,13 @@ void ServerApplication::HandlePacket(SerialPacket* const argPacket) { case SerialPacketType::SHUTDOWN_REQUEST: HandleShutdownRequest(static_cast(argPacket)); break; -/* + //data management & queries case SerialPacketType::REGION_REQUEST: -// HandleRegionRequest(static_cast(argPacket)); + HandleRegionRequest(static_cast(argPacket)); break; + +/* case SerialPacketType::QUERY_CHARACTER_EXISTS: // HandleCharacterStatsRequest(static_cast(argPacket)); break; diff --git a/server/server_methods.cpp b/server/server_methods.cpp index b69068a..310bfba 100644 --- a/server/server_methods.cpp +++ b/server/server_methods.cpp @@ -88,7 +88,6 @@ void ServerApplication::HandleLoginRequest(ClientPacket* const argPacket) { if (clientData == nullptr || clientData->GetAddress() != argPacket->srcAddress) { std::cerr << "Falsified client index detected: " << argPacket->clientIndex << std::endl; - //TODO: rejection message? return; } @@ -97,14 +96,18 @@ void ServerApplication::HandleLoginRequest(ClientPacket* const argPacket) { //Cannot load if (accountIndex < 0) { + //build the message std::ostringstream msg; msg << "Account already loaded: " << argPacket->username; + //build the packet TextPacket newPacket; newPacket.type = SerialPacketType::LOGIN_REJECTION; -// memset(newPacket.name, 0, PACKET_STRING_SIZE); strncpy(newPacket.text, msg.str().c_str(), PACKET_STRING_SIZE); network.SendTo(clientData->GetAddress(), static_cast(&newPacket)); + + //log the error + std::cerr << "Error message sent: " << msg << std::endl; return; } @@ -247,28 +250,45 @@ void ServerApplication::HandleShutdownRequest(ClientPacket* const argPacket) { std::cout << "Shutdown signal accepted" << std::endl; } -/* - //------------------------- -//map management +//data management //------------------------- -//SET: resources void ServerApplication::HandleRegionRequest(RegionPacket* const argPacket) { + //get the region object, send a rejection on error + RoomData* room = roomMgr.Get(argPacket->roomIndex); + if (!room) { + //build the error message + std::ostringstream msg; + msg << "Failed to find Region (" << argPacket->roomIndex << "," << argPacket->x << "," << argPacket->y << ");"; + msg << "Room " << argPacket->roomIndex << "does not exist"; + + //build the packet + TextPacket newPacket; + newPacket.type = SerialPacketType::REGION_REJECTION; + strncpy(newPacket.text, msg.str().c_str(), PACKET_STRING_SIZE); + network.SendTo(argPacket->srcAddress, static_cast(&newPacket)); + + //log the error + std::cerr << "Error message sent: " << msg << std::endl; + return; + } + Region* region = room->GetPager()->GetRegion(argPacket->x, argPacket->y); + + //send the content RegionPacket newPacket; newPacket.type = SerialPacketType::REGION_CONTENT; newPacket.roomIndex = argPacket->roomIndex; newPacket.x = argPacket->x; newPacket.y = argPacket->y; + newPacket.region = region; - //BUG: possibly related to #35 - newPacket.region = roomMgr.Get(argPacket->roomIndex)->GetPager()->GetRegion(argPacket->x, argPacket->y); - - //send the content network.SendTo(argPacket->srcAddress, static_cast(&newPacket)); } +/* + //------------------------- //Character Management //------------------------- @@ -382,10 +402,6 @@ void ServerApplication::HandleSynchronize(ClientPacket* const argPacket) { //TODO: more in HandleSynchronize() } -//------------------------- -//utility methods -//------------------------- - //SET: utility/manager void ServerApplication::CleanupLostConnection(int clientIndex) { //NOTE: This assumes each player has only one account and character at a time From 06eb1f2e9e7968326b93f403b322db07164370b4 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Sun, 30 Nov 2014 23:04:35 +1100 Subject: [PATCH 39/73] Minor tweak to the Timer class; kind of pointless --- common/debugging/timer.cpp | 4 ++-- common/debugging/timer.hpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/common/debugging/timer.cpp b/common/debugging/timer.cpp index 29d107a..efcaf3b 100644 --- a/common/debugging/timer.cpp +++ b/common/debugging/timer.cpp @@ -39,7 +39,7 @@ void Timer::Stop() { std::ostream& operator<<(std::ostream& os, Timer& t) { os << t.GetName() << ": "; - os << std::chrono::duration_cast(t.GetTime()).count(); - os << "ms"; + os << std::chrono::duration_cast(t.GetTime()).count(); + os << "us"; return os; } diff --git a/common/debugging/timer.hpp b/common/debugging/timer.hpp index dfafec9..ac66419 100644 --- a/common/debugging/timer.hpp +++ b/common/debugging/timer.hpp @@ -34,8 +34,8 @@ public: Timer(std::string s); ~Timer() = default; - inline void Start(); - inline void Stop(); + void Start(); + void Stop(); //accessors and mutators Clock::duration GetTime() { return timeSpan; } From 8579d7e0d68260beb7b03b32fa9fccfe20d9c91a Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Sun, 30 Nov 2014 23:29:46 +1100 Subject: [PATCH 40/73] Implemented client-side HandleRegionContent() --- client/scenes/in_world.cpp | 20 ++++++++++++++++++++ client/scenes/in_world.hpp | 3 +++ 2 files changed, 23 insertions(+) diff --git a/client/scenes/in_world.cpp b/client/scenes/in_world.cpp index e1cce1c..1a32178 100644 --- a/client/scenes/in_world.cpp +++ b/client/scenes/in_world.cpp @@ -212,6 +212,12 @@ void InWorld::HandlePacket(SerialPacket* const argPacket) { HandleDisconnectForced(static_cast(argPacket)); break; + //map management + case SerialPacketType::REGION_CONTENT: + HandleRegionContent(static_cast(argPacket)); + break; + + //errors default: { std::ostringstream msg; msg << "Unknown SerialPacketType encountered in InWorld: " << static_cast(argPacket->type); @@ -287,3 +293,17 @@ void InWorld::HandleDisconnectForced(ClientPacket* const argPacket) { SetNextScene(SceneList::DISCONNECTEDSCREEN); ConfigUtility::GetSingleton()["client.disconnectMessage"] = "You have been forcibly disconnected by the server"; } + +//------------------------- +//map management +//------------------------- + +void InWorld::HandleRegionContent(RegionPacket* const argPacket) { + //replace existing regions + regionPager.UnloadRegion(argPacket->x, argPacket->y); + regionPager.PushRegion(argPacket->region); + + //clean up after the serial code + delete argPacket->region; + argPacket->region = nullptr; +} \ No newline at end of file diff --git a/client/scenes/in_world.hpp b/client/scenes/in_world.hpp index dfced78..539d2dc 100644 --- a/client/scenes/in_world.hpp +++ b/client/scenes/in_world.hpp @@ -86,6 +86,9 @@ protected: void HandleDisconnectResponse(ClientPacket* const); void HandleDisconnectForced(ClientPacket* const); + //map management + void HandleRegionContent(RegionPacket* const); + //indexes int& clientIndex; int& accountIndex; From 822ff5827eac5e39929fa96b85370fede9ae6604 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Mon, 1 Dec 2014 00:13:46 +1100 Subject: [PATCH 41/73] Map protocol works in theory --- client/scenes/in_world.cpp | 50 +++++++++++++++++++++++++++++++++++++- client/scenes/in_world.hpp | 2 ++ 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/client/scenes/in_world.cpp b/client/scenes/in_world.cpp index 1a32178..6167051 100644 --- a/client/scenes/in_world.cpp +++ b/client/scenes/in_world.cpp @@ -71,6 +71,11 @@ InWorld::InWorld(int* const argClientIndex, int* const argAccountIndex): disconnectButton.SetText("Disconnect"); shutDownButton.SetText("Shut Down"); + //load the tilesheet + //TODO: add the tilesheet to the map system? + //TODO: Tile size and tile sheet should be loaded elsewhere + tileSheet.Load(config["dir.tilesets"] + "overworld.bmp", 32, 32); + //debug // } @@ -105,6 +110,9 @@ void InWorld::Update() { //free the buffer delete reinterpret_cast(packetBuffer); + //update the map + UpdateMap(); + //check the connection (heartbeat) if (Clock::now() - lastBeat > std::chrono::seconds(3)) { if (attemptedBeats > 2) { @@ -137,6 +145,11 @@ void InWorld::RenderFrame() { } void InWorld::Render(SDL_Surface* const screen) { + //draw the map + for (std::list::iterator it = regionPager.GetContainer()->begin(); it != regionPager.GetContainer()->end(); it++) { + tileSheet.DrawRegionTo(screen, &(*it), camera.x, camera.y); + } + //draw UI disconnectButton.DrawTo(screen); shutDownButton.DrawTo(screen); @@ -298,6 +311,18 @@ void InWorld::HandleDisconnectForced(ClientPacket* const argPacket) { //map management //------------------------- +void InWorld::SendRegionRequest(int roomIndex, int x, int y) { + RegionPacket packet; + + //pack the region's data + packet.type = SerialPacketType::REGION_REQUEST; + packet.roomIndex = roomIndex; + packet.x = x; + packet.y = y; + + network.SendTo(Channels::SERVER, &packet); +} + void InWorld::HandleRegionContent(RegionPacket* const argPacket) { //replace existing regions regionPager.UnloadRegion(argPacket->x, argPacket->y); @@ -306,4 +331,27 @@ void InWorld::HandleRegionContent(RegionPacket* const argPacket) { //clean up after the serial code delete argPacket->region; argPacket->region = nullptr; -} \ No newline at end of file +} + +void InWorld::UpdateMap() { + //these represent the zone of regions that the client needs loaded, including the mandatory buffers (+1/-1) + int xStart = snapToBase(REGION_WIDTH, camera.x/tileSheet.GetTileW()) - REGION_WIDTH; + int xEnd = snapToBase(REGION_WIDTH, (camera.x+camera.width)/tileSheet.GetTileW()) + REGION_WIDTH; + + int yStart = snapToBase(REGION_HEIGHT, camera.y/tileSheet.GetTileH()) - REGION_HEIGHT; + int yEnd = snapToBase(REGION_HEIGHT, (camera.y+camera.height)/tileSheet.GetTileH()) + REGION_HEIGHT; + + //prune distant regions + regionPager.GetContainer()->remove_if([&](Region const& region) -> bool { + return region.GetX() < xStart || region.GetX() > xEnd || region.GetY() < yStart || region.GetY() > yEnd; + }); + + //request empty regions within this zone + for (int i = xStart; i <= xEnd; i += REGION_WIDTH) { + for (int j = yStart; j <= yEnd; j += REGION_HEIGHT) { + if (!regionPager.FindRegion(i, j)) { + SendRegionRequest(0, i, j); + } + } + } +} diff --git a/client/scenes/in_world.hpp b/client/scenes/in_world.hpp index 539d2dc..1c7c58c 100644 --- a/client/scenes/in_world.hpp +++ b/client/scenes/in_world.hpp @@ -87,7 +87,9 @@ protected: void HandleDisconnectForced(ClientPacket* const); //map management + void SendRegionRequest(int roomIndex, int x, int y); void HandleRegionContent(RegionPacket* const); + void UpdateMap(); //indexes int& clientIndex; From c89f94b6812cc2387f530db8011a054bc8032be1 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Mon, 1 Dec 2014 00:26:47 +1100 Subject: [PATCH 42/73] Missed the map system's nested API table --- common/map/map_system_api.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/map/map_system_api.cpp b/common/map/map_system_api.cpp index 46b6355..0e12796 100644 --- a/common/map/map_system_api.cpp +++ b/common/map/map_system_api.cpp @@ -70,7 +70,7 @@ int openMapSystemAPI(lua_State* L) { //push the substable for (const luaL_Reg* lib = libs; lib->func; lib++) { - lua_pushcfunction(L, lib->func); + lib->func(L); lua_setfield(L, -2, lib->name); } return 1; From cc167180f692beeed8684938a05ed69b38ad9880 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Mon, 1 Dec 2014 22:33:15 +1100 Subject: [PATCH 43/73] Added support for cleaning up after rejection messages --- client/client_utilities/makefile | 37 ++++++++++++++++++++++ client/client_utilities/terminal_error.cpp | 23 ++++++++++++++ client/client_utilities/terminal_error.hpp | 34 ++++++++++++++++++++ client/makefile | 3 +- client/scenes/in_world.cpp | 13 ++++++++ client/scenes/makefile | 2 +- rsc/scripts/setup_server.lua | 3 +- server/server_methods.cpp | 29 ++++++++++++++--- 8 files changed, 136 insertions(+), 8 deletions(-) create mode 100644 client/client_utilities/makefile create mode 100644 client/client_utilities/terminal_error.cpp create mode 100644 client/client_utilities/terminal_error.hpp diff --git a/client/client_utilities/makefile b/client/client_utilities/makefile new file mode 100644 index 0000000..4a01dcd --- /dev/null +++ b/client/client_utilities/makefile @@ -0,0 +1,37 @@ +#config +INCLUDES+=. +LIBS+= +CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES)) + +#source +CXXSRC=$(wildcard *.cpp) + +#objects +OBJDIR=obj +OBJ+=$(addprefix $(OBJDIR)/,$(CXXSRC:.cpp=.o)) + +#output +OUTDIR=.. +OUT=$(addprefix $(OUTDIR)/,client.a) + +#targets +all: $(OBJ) $(OUT) + ar -crs $(OUT) $(OBJ) + +$(OBJ): | $(OBJDIR) + +$(OUT): | $(OUTDIR) + +$(OBJDIR): + mkdir $(OBJDIR) + +$(OUTDIR): + mkdir $(OUTDIR) + +$(OBJDIR)/%.o: %.cpp + $(CXX) $(CXXFLAGS) -c -o $@ $< + +clean: + $(RM) *.o *.a *.exe + +rebuild: clean all diff --git a/client/client_utilities/terminal_error.cpp b/client/client_utilities/terminal_error.cpp new file mode 100644 index 0000000..d391add --- /dev/null +++ b/client/client_utilities/terminal_error.cpp @@ -0,0 +1,23 @@ +/* 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 "terminal_error.hpp" + diff --git a/client/client_utilities/terminal_error.hpp b/client/client_utilities/terminal_error.hpp new file mode 100644 index 0000000..980b4e3 --- /dev/null +++ b/client/client_utilities/terminal_error.hpp @@ -0,0 +1,34 @@ +/* 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 TERMINALERROR_HPP_ +#define TERMINALERROR_HPP_ + +#include +#include + +class terminal_error: public std::runtime_error { +public: + explicit terminal_error(const std::string& str): runtime_error(str) {} + explicit terminal_error(const char* cstr): runtime_error(cstr) {} +}; + +#endif diff --git a/client/makefile b/client/makefile index d7adf5a..68ce8d9 100644 --- a/client/makefile +++ b/client/makefile @@ -1,5 +1,5 @@ #include directories -INCLUDES+=. entities scenes ../common/debugging ../common/gameplay ../common/graphics ../common/map ../common/network ../common/network/packet_types ../common/ui ../common/utilities +INCLUDES+=. client_utilities entities scenes ../common/debugging ../common/gameplay ../common/graphics ../common/map ../common/network ../common/network/packet_types ../common/ui ../common/utilities #libraries #the order of the $(LIBS) is important, at least for MinGW @@ -25,6 +25,7 @@ OUT=$(addprefix $(OUTDIR)/,client) #targets all: $(OBJ) $(OUT) + $(MAKE) -C client_utilities $(MAKE) -C entities $(MAKE) -C scenes $(CXX) $(CXXFLAGS) -o $(OUT) $(OBJ) $(LIBS) diff --git a/client/scenes/in_world.cpp b/client/scenes/in_world.cpp index 6167051..5873de7 100644 --- a/client/scenes/in_world.cpp +++ b/client/scenes/in_world.cpp @@ -24,6 +24,7 @@ #include "channels.hpp" #include "utility.hpp" +#include "terminal_error.hpp" #include #include #include @@ -103,6 +104,9 @@ void InWorld::Update() { HandlePacket(packetBuffer); } } + catch(terminal_error& e) { + throw(e); + } catch(std::exception& e) { std::cerr << "HandlePacket Error: " << e.what() << std::endl; } @@ -230,6 +234,15 @@ void InWorld::HandlePacket(SerialPacket* const argPacket) { HandleRegionContent(static_cast(argPacket)); break; + //rejection messages + case SerialPacketType::REGION_REJECTION: + case SerialPacketType::CHARACTER_REJECTION: + throw(terminal_error(static_cast(argPacket)->text)); + break; + case SerialPacketType::SHUTDOWN_REJECTION: + throw(std::runtime_error(static_cast(argPacket)->text)); + break; + //errors default: { std::ostringstream msg; diff --git a/client/scenes/makefile b/client/scenes/makefile index 73a4950..c11a607 100644 --- a/client/scenes/makefile +++ b/client/scenes/makefile @@ -1,5 +1,5 @@ #config -INCLUDES+=. .. ../entities ../../common/gameplay ../../common/graphics ../../common/map ../../common/network ../../common/network/packet_types ../../common/ui ../../common/utilities +INCLUDES+=. .. ../client_utilities ../entities ../../common/gameplay ../../common/graphics ../../common/map ../../common/network ../../common/network/packet_types ../../common/ui ../../common/utilities LIBS+= CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES)) diff --git a/rsc/scripts/setup_server.lua b/rsc/scripts/setup_server.lua index 3b4c46b..7ac5afc 100644 --- a/rsc/scripts/setup_server.lua +++ b/rsc/scripts/setup_server.lua @@ -25,7 +25,8 @@ dumpTable(roomSystem) dumpTable(roomSystem.RoomManager) dumpTable(roomSystem.Room) -local overworld = roomSystem.RoomManager.CreateRoom("overworld") +--NOTE: room 0 is the first that the client asks for, therefore it must exist +local overworld, uid = roomSystem.RoomManager.CreateRoom("overworld") roomSystem.Room.Initialize(overworld, "overworld.bmp", mapSaver.Load, mapSaver.Save, mapMaker.debugIsland, mapSaver.Save) print("Finished the lua script") diff --git a/server/server_methods.cpp b/server/server_methods.cpp index 310bfba..863b0cf 100644 --- a/server/server_methods.cpp +++ b/server/server_methods.cpp @@ -107,7 +107,7 @@ void ServerApplication::HandleLoginRequest(ClientPacket* const argPacket) { network.SendTo(clientData->GetAddress(), static_cast(&newPacket)); //log the error - std::cerr << "Error message sent: " << msg << std::endl; + std::cerr << "Error message sent: " << newPacket.text << std::endl; return; } @@ -233,11 +233,30 @@ void ServerApplication::HandleShutdownRequest(ClientPacket* const argPacket) { } //check for fraud - if (clientData->GetAddress() != argPacket->srcAddress || accountData->GetAdministrator() != true) { + if (clientData->GetAddress() != argPacket->srcAddress) { std::cerr << "Falsified server shutdown detected from: " << accountData->GetUsername() << std::endl; return; } + //reject non-admin requests + if (accountData->GetAdministrator() != true) { + std::cerr << "Rejected server shutdown command from: " << accountData->GetUsername() << std::endl; + + //build the message + std::ostringstream msg; + msg << "Invalid admin status"; + + //build the packet + TextPacket newPacket; + newPacket.type = SerialPacketType::SHUTDOWN_REJECTION; + strncpy(newPacket.text, msg.str().c_str(), PACKET_STRING_SIZE); + + //send the rejection message + network.SendTo(argPacket->srcAddress, static_cast(&newPacket)); + + return; + } + //end the server running = false; @@ -260,8 +279,8 @@ void ServerApplication::HandleRegionRequest(RegionPacket* const argPacket) { if (!room) { //build the error message std::ostringstream msg; - msg << "Failed to find Region (" << argPacket->roomIndex << "," << argPacket->x << "," << argPacket->y << ");"; - msg << "Room " << argPacket->roomIndex << "does not exist"; + msg << "Failed to find Region (" << argPacket->roomIndex << "," << argPacket->x << "," << argPacket->y << "); "; + msg << "Room " << argPacket->roomIndex << " does not exist"; //build the packet TextPacket newPacket; @@ -270,7 +289,7 @@ void ServerApplication::HandleRegionRequest(RegionPacket* const argPacket) { network.SendTo(argPacket->srcAddress, static_cast(&newPacket)); //log the error - std::cerr << "Error message sent: " << msg << std::endl; + std::cerr << "Error message sent: " << newPacket.text << std::endl; return; } Region* region = room->GetPager()->GetRegion(argPacket->x, argPacket->y); From f50406d69f9b64da72a05a88409bf4cef93a71d5 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Mon, 1 Dec 2014 22:59:26 +1100 Subject: [PATCH 44/73] Code tweak --- client/entities/base_character.cpp | 32 ++++++++++++++++++++++++++++++ client/entities/base_character.hpp | 14 ++++++------- client/entities/base_monster.hpp | 2 +- client/entities/entity.cpp | 17 ++++++++++++++++ client/entities/entity.hpp | 8 ++++---- 5 files changed, 61 insertions(+), 12 deletions(-) diff --git a/client/entities/base_character.cpp b/client/entities/base_character.cpp index ad31e92..8acdc72 100644 --- a/client/entities/base_character.cpp +++ b/client/entities/base_character.cpp @@ -21,6 +21,10 @@ */ #include "base_character.hpp" +//------------------------- +//graphics +//------------------------- + void BaseCharacter::CorrectSprite() { //NOTE: These must correspond to the sprite sheet in use if (motion.y > 0) { @@ -45,3 +49,31 @@ void BaseCharacter::CorrectSprite() { sprite.SetXIndex(0); } } + +//------------------------- +//metadata +//------------------------- + +int BaseCharacter::SetOwner(int i) { + return owner = i; +} + +int BaseCharacter::GetOwner() { + return owner; +} + +std::string BaseCharacter::SetHandle(std::string s) { + return handle = s; +} + +std::string BaseCharacter::GetHandle() const { + return handle; +} + +std::string BaseCharacter::SetAvatar(std::string s) { + return avatar = s; +} + +std::string BaseCharacter::GetAvatar() const { + return avatar; +} \ No newline at end of file diff --git a/client/entities/base_character.hpp b/client/entities/base_character.hpp index 8c44ce3..c3d1b1e 100644 --- a/client/entities/base_character.hpp +++ b/client/entities/base_character.hpp @@ -29,7 +29,7 @@ //std namespace #include -class BaseCharacter : public Entity { +class BaseCharacter: public Entity { public: BaseCharacter() = default; virtual ~BaseCharacter() = default; @@ -38,12 +38,12 @@ public: void CorrectSprite(); //metadata - int SetOwner(int i) { return owner = i; } - int GetOwner() { return owner; } - std::string SetHandle(std::string s) { return handle = s; } - std::string GetHandle() const { return handle; } - std::string SetAvatar(std::string s) { return avatar = s; } - std::string GetAvatar() const { return avatar; } + int SetOwner(int i); + int GetOwner(); + std::string SetHandle(std::string s); + std::string GetHandle() const; + std::string SetAvatar(std::string s); + std::string GetAvatar() const; private: //metadata diff --git a/client/entities/base_monster.hpp b/client/entities/base_monster.hpp index ddcc876..d7d1b6b 100644 --- a/client/entities/base_monster.hpp +++ b/client/entities/base_monster.hpp @@ -24,7 +24,7 @@ #include "entity.hpp" -class BaseMonster : public Entity { +class BaseMonster: public Entity { public: BaseMonster() = default; virtual ~BaseMonster() = default; diff --git a/client/entities/entity.cpp b/client/entities/entity.cpp index 5509604..04ba38a 100644 --- a/client/entities/entity.cpp +++ b/client/entities/entity.cpp @@ -30,6 +30,14 @@ void Entity::DrawTo(SDL_Surface* const dest, int camX, int camY) { sprite.DrawTo(dest, origin.x - camX, origin.y - camY); } +SpriteSheet* Entity::GetSprite() { + return &sprite; +} + +//------------------------- +//accessors & mutators +//------------------------- + int Entity::SetEntityIndex(int i) { return entityIndex = i; } @@ -45,6 +53,11 @@ Vector2 Entity::SetOrigin(Vector2 v) { Vector2 Entity::SetMotion(Vector2 v) { return motion = v; } + +BoundingBox Entity::SetBounds(BoundingBox b) { + return bounds = b; +} + int Entity::GetEntityIndex() { return entityIndex; } @@ -59,4 +72,8 @@ Vector2 Entity::GetOrigin() { Vector2 Entity::GetMotion() { return motion; +} + +BoundingBox Entity::GetBounds() { + return bounds; } \ No newline at end of file diff --git a/client/entities/entity.hpp b/client/entities/entity.hpp index a73d3eb..694490d 100644 --- a/client/entities/entity.hpp +++ b/client/entities/entity.hpp @@ -32,24 +32,24 @@ public: virtual void Update(); virtual void DrawTo(SDL_Surface* const, int camX, int camY); - SpriteSheet* GetSprite() { return &sprite; } + SpriteSheet* GetSprite(); //accessors & mutators int SetEntityIndex(int i); int SetRoomIndex(int i); Vector2 SetOrigin(Vector2 v); Vector2 SetMotion(Vector2 v); - BoundingBox SetBounds(BoundingBox b) { return bounds = b; } + BoundingBox SetBounds(BoundingBox b); int GetEntityIndex(); int GetRoomIndex(); Vector2 GetOrigin(); Vector2 GetMotion(); - BoundingBox GetBounds() { return bounds; } + BoundingBox GetBounds(); protected: Entity() = default; - ~Entity() = default; + virtual ~Entity() = default; SpriteSheet sprite; int entityIndex = -1; From 0e666d32031ad07c1952050a95ad42aec3d2c426 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Tue, 2 Dec 2014 23:11:08 +1100 Subject: [PATCH 45/73] Server accepts and creates the character's data --- client/scenes/in_world.cpp | 11 +++++- server/server_application.hpp | 7 ++-- server/server_logic.cpp | 28 ++++++++-------- server/server_methods.cpp | 63 ++++++++++++++++++++++++----------- 4 files changed, 72 insertions(+), 37 deletions(-) diff --git a/client/scenes/in_world.cpp b/client/scenes/in_world.cpp index 5873de7..1e45649 100644 --- a/client/scenes/in_world.cpp +++ b/client/scenes/in_world.cpp @@ -73,10 +73,19 @@ InWorld::InWorld(int* const argClientIndex, int* const argAccountIndex): shutDownButton.SetText("Shut Down"); //load the tilesheet - //TODO: add the tilesheet to the map system? + //TODO: add the tilesheet to the map system //TODO: Tile size and tile sheet should be loaded elsewhere tileSheet.Load(config["dir.tilesets"] + "overworld.bmp", 32, 32); + //Send the character data + //TODO: login scene, prompt, etc. + CharacterPacket newPacket; + newPacket.type = SerialPacketType::CHARACTER_LOAD; + strncpy(newPacket.handle, config["client.handle"].c_str(), PACKET_STRING_SIZE); + strncpy(newPacket.avatar, config["client.avatar"].c_str(), PACKET_STRING_SIZE); + newPacket.accountIndex = accountIndex; + network.SendTo(Channels::SERVER, &newPacket); + //debug // } diff --git a/server/server_application.hpp b/server/server_application.hpp index 1f98437..4300c9b 100644 --- a/server/server_application.hpp +++ b/server/server_application.hpp @@ -92,9 +92,10 @@ private: void SaveServerState(); //character management -// void HandleCharacterNew(CharacterPacket* const); -// void HandleCharacterDelete(CharacterPacket* const); -// void HandleCharacterUpdate(CharacterPacket* const); + void HandleCharacterCreate(CharacterPacket* const); + void HandleCharacterDelete(CharacterPacket* const); + void HandleCharacterLoad(CharacterPacket* const); + void HandleCharacterUnload(CharacterPacket* const); //mismanagement // void HandleSynchronize(ClientPacket* const); diff --git a/server/server_logic.cpp b/server/server_logic.cpp index 794cc57..341a46c 100644 --- a/server/server_logic.cpp +++ b/server/server_logic.cpp @@ -274,6 +274,20 @@ void ServerApplication::HandlePacket(SerialPacket* const argPacket) { HandleRegionRequest(static_cast(argPacket)); break; + //character management + case SerialPacketType::CHARACTER_CREATE: + HandleCharacterCreate(static_cast(argPacket)); + break; + case SerialPacketType::CHARACTER_DELETE: + HandleCharacterDelete(static_cast(argPacket)); + break; + case SerialPacketType::CHARACTER_LOAD: + HandleCharacterLoad(static_cast(argPacket)); + break; + case SerialPacketType::CHARACTER_UNLOAD: + HandleCharacterUnload(static_cast(argPacket)); + break; + /* case SerialPacketType::QUERY_CHARACTER_EXISTS: // HandleCharacterStatsRequest(static_cast(argPacket)); @@ -288,20 +302,6 @@ void ServerApplication::HandlePacket(SerialPacket* const argPacket) { // HandleCharacterStatsRequest(static_cast(argPacket)); break; - //character management - case SerialPacketType::CHARACTER_CREATE: -// HandleCharacterNew(static_cast(argPacket)); - break; - case SerialPacketType::CHARACTER_DELETE: -// HandleCharacterDelete(static_cast(argPacket)); - break; - case SerialPacketType::CHARACTER_LOAD: -// HandleCharacterNew(static_cast(argPacket)); - break; - case SerialPacketType::CHARACTER_UNLOAD: -// HandleCharacterDelete(static_cast(argPacket)); - break; - //character movement case SerialPacketType::CHARACTER_SET_ROOM: // HandleCharacterUpdate(static_cast(argPacket)); diff --git a/server/server_methods.cpp b/server/server_methods.cpp index 863b0cf..cae9910 100644 --- a/server/server_methods.cpp +++ b/server/server_methods.cpp @@ -306,45 +306,70 @@ void ServerApplication::HandleRegionRequest(RegionPacket* const argPacket) { network.SendTo(argPacket->srcAddress, static_cast(&newPacket)); } -/* - //------------------------- //Character Management //------------------------- -//SET: entities -void ServerApplication::HandleCharacterNew(CharacterPacket* const argPacket) { - //NOTE: misnomer, try to load the character first - int characterIndex = characterMgr.Load(argPacket->accountIndex, argPacket->handle, argPacket->avatar); +void ServerApplication::HandleCharacterCreate(CharacterPacket* const argPacket) { + int characterIndex = characterMgr.Create(argPacket->accountIndex, argPacket->handle, argPacket->avatar); - //cannot load or create if (characterIndex < 0) { //build the error message std::ostringstream msg; - if (characterIndex == -1) { - msg << "Character already loaded: "; - } - else if (characterIndex == -2) { - msg << "Character already exists: "; - } - msg << argPacket->handle; + msg << "Character already exists: " << argPacket->handle; - //create, fill and send the packet + //build & send the packet TextPacket newPacket; newPacket.type = SerialPacketType::CHARACTER_REJECTION; - memset(newPacket.name, 0, PACKET_STRING_SIZE); strncpy(newPacket.text, msg.str().c_str(), PACKET_STRING_SIZE); network.SendTo(argPacket->srcAddress, static_cast(&newPacket)); + return; } - //send this new character to all clients + //send this character to the player CharacterPacket newPacket; newPacket.type = SerialPacketType::CHARACTER_CREATE; - CopyCharacterToPacket(&newPacket, characterIndex); - PumpPacket(&newPacket); + //TODO? } +void ServerApplication::HandleCharacterDelete(CharacterPacket* const argPacket) { + //TODO +} + +void ServerApplication::HandleCharacterLoad(CharacterPacket* const argPacket) { + int characterIndex = characterMgr.Load(argPacket->accountIndex, argPacket->handle, argPacket->avatar); + + if (characterIndex < 0) { + //build the error message + std::ostringstream msg; + if (characterIndex == -1) + msg << "Character already loaded: "; + if (characterIndex == -1) + msg << "Character name is taken: "; + msg << argPacket->handle; + + //build & send the packet + TextPacket newPacket; + newPacket.type = SerialPacketType::CHARACTER_REJECTION; + strncpy(newPacket.text, msg.str().c_str(), PACKET_STRING_SIZE); + network.SendTo(argPacket->srcAddress, static_cast(&newPacket)); + + return; + } + + //send this character to the player + CharacterPacket newPacket; + newPacket.type = SerialPacketType::CHARACTER_CREATE; + //TODO? +} + +void ServerApplication::HandleCharacterUnload(CharacterPacket* const argPacket) { + //TODO +} + +/* + //SET: entities void ServerApplication::HandleCharacterDelete(CharacterPacket* const argPacket) { //NOTE: Disconnecting only unloads a character, this explicitly deletes it From 5607f76ce7303a99f56995e1e2e7e4339e0cb4b8 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Tue, 2 Dec 2014 23:41:08 +1100 Subject: [PATCH 46/73] Server-side HandleCharacterDelete() --- server/characters/character_manager.cpp | 2 + server/server_methods.cpp | 76 +++++++++++++------------ 2 files changed, 43 insertions(+), 35 deletions(-) diff --git a/server/characters/character_manager.cpp b/server/characters/character_manager.cpp index 13d7efa..c83cfcf 100644 --- a/server/characters/character_manager.cpp +++ b/server/characters/character_manager.cpp @@ -110,6 +110,8 @@ int CharacterManager::Load(int owner, std::string handle, std::string avatar) { //check the owner if (owner != sqlite3_column_int(statement, 1)) { sqlite3_finalize(statement); + //unload the already loaded character + Unload(uid); return -2; } diff --git a/server/server_methods.cpp b/server/server_methods.cpp index cae9910..bf80735 100644 --- a/server/server_methods.cpp +++ b/server/server_methods.cpp @@ -334,7 +334,43 @@ void ServerApplication::HandleCharacterCreate(CharacterPacket* const argPacket) } void ServerApplication::HandleCharacterDelete(CharacterPacket* const argPacket) { - //TODO + //get the user's data + AccountData* accountData = accountMgr.Get(argPacket->accountIndex); + if (!accountData) { + return; + } + ClientData* clientData = clientMgr.Get(accountData->GetClientIndex()); + if (!clientData) { + return; + } + + //check for fraud + if (clientData->GetAddress() != argPacket->srcAddress) { + std::cerr << "Falsified character deletion detected targeting: " << argPacket->handle << std::endl; + return; + } + + //load the character into memory + int characterIndex = characterMgr.Load(argPacket->accountIndex, argPacket->handle, argPacket->avatar); + + if (characterIndex < 0) { + //build the error message + std::ostringstream msg; + msg << "Cannot delete this character"; + + //build & send the packet + TextPacket newPacket; + newPacket.type = SerialPacketType::CHARACTER_REJECTION; + strncpy(newPacket.text, msg.str().c_str(), PACKET_STRING_SIZE); + network.SendTo(argPacket->srcAddress, static_cast(&newPacket)); + + return; + } + + //delete the character + characterMgr.Delete(characterIndex); + + //TODO: pump character unload } void ServerApplication::HandleCharacterLoad(CharacterPacket* const argPacket) { @@ -343,10 +379,12 @@ void ServerApplication::HandleCharacterLoad(CharacterPacket* const argPacket) { if (characterIndex < 0) { //build the error message std::ostringstream msg; - if (characterIndex == -1) + if (characterIndex == -1) { msg << "Character already loaded: "; - if (characterIndex == -1) + } + if (characterIndex == -1) { msg << "Character name is taken: "; + } msg << argPacket->handle; //build & send the packet @@ -370,38 +408,6 @@ void ServerApplication::HandleCharacterUnload(CharacterPacket* const argPacket) /* -//SET: entities -void ServerApplication::HandleCharacterDelete(CharacterPacket* const argPacket) { - //NOTE: Disconnecting only unloads a character, this explicitly deletes it - - //Authenticate the owner is doing this - int characterIndex = characterMgr.Load(argPacket->accountIndex, argPacket->handle, argPacket->avatar); - - //if this is not your character - if (characterIndex < 0 && characterMgr.Get(characterIndex)->GetOwner() != argPacket->accountIndex) { - //send the rejection packet - TextPacket newPacket; - newPacket.type = SerialPacketType::CHARACTER_REJECTION; - memset(newPacket.name, 0, PACKET_STRING_SIZE); - strncpy(newPacket.text, "Character cannot be deleted", PACKET_STRING_SIZE); - network.SendTo(argPacket->srcAddress, static_cast(&newPacket)); - - //unload an unneeded character - if (characterIndex != -1) { - characterMgr.Unload(characterIndex); - } - return; - } - - //delete it - characterMgr.Delete(characterIndex); - - //TODO: success packet - - //Unload this character from all clients - PumpCharacterUnload(characterIndex); -} - //SET: entities void ServerApplication::HandleCharacterUpdate(CharacterPacket* const argPacket) { CharacterData* character = characterMgr.Get(argPacket->characterIndex); From 61f462a882c97bb1ef56e5396a82597bda879cf2 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Tue, 2 Dec 2014 23:55:12 +1100 Subject: [PATCH 47/73] Server-side HandleCharacterUnload() --- server/server_methods.cpp | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/server/server_methods.cpp b/server/server_methods.cpp index bf80735..f3a21b9 100644 --- a/server/server_methods.cpp +++ b/server/server_methods.cpp @@ -330,7 +330,7 @@ void ServerApplication::HandleCharacterCreate(CharacterPacket* const argPacket) //send this character to the player CharacterPacket newPacket; newPacket.type = SerialPacketType::CHARACTER_CREATE; - //TODO? + //TODO: pump character load } void ServerApplication::HandleCharacterDelete(CharacterPacket* const argPacket) { @@ -399,11 +399,36 @@ void ServerApplication::HandleCharacterLoad(CharacterPacket* const argPacket) { //send this character to the player CharacterPacket newPacket; newPacket.type = SerialPacketType::CHARACTER_CREATE; - //TODO? + //TODO: pump character load } void ServerApplication::HandleCharacterUnload(CharacterPacket* const argPacket) { - //TODO + //get the entries + CharacterData* characterData = characterMgr.Get(argPacket->characterIndex); + if (!characterData) { + return; + } + + AccountData* accountData = accountMgr.Get(characterData->GetOwner()); + if (!accountData) { + return; //TODO: logic_error + } + + ClientData* clientData = clientMgr.Get(accountData->GetClientIndex()); + if (!clientData) { + return; //TODO: logic_error + } + + //check for fraud + if (clientData->GetAddress() != argPacket->srcAddress) { + std::cerr << "Falsified character unload detected targeting: uid(" << argPacket->characterIndex << ")" << std::endl; + return; + } + + //unload the character + characterMgr.Unload(argPacket->characterIndex); + + //TODO: pump character unload } /* From de4e53944975c24b4fcfbac13d7b960b061d5cf3 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Wed, 3 Dec 2014 00:46:38 +1100 Subject: [PATCH 48/73] Moved the connection code to server_connections.cpp --- server/server_application.hpp | 4 + server/server_connections.cpp | 199 ++++++++++++++++++++++++++++++++++ server/server_methods.cpp | 192 +------------------------------- server/server_util.cpp | 34 ++++++ 4 files changed, 240 insertions(+), 189 deletions(-) create mode 100644 server/server_connections.cpp create mode 100644 server/server_util.cpp diff --git a/server/server_application.hpp b/server/server_application.hpp index 4300c9b..fa39475 100644 --- a/server/server_application.hpp +++ b/server/server_application.hpp @@ -53,6 +53,10 @@ #include #include +//global utility functions +bool operator==(IPaddress lhs, IPaddress rhs); +bool operator!=(IPaddress lhs, IPaddress rhs); + //The main application class class ServerApplication: public Singleton { public: diff --git a/server/server_connections.cpp b/server/server_connections.cpp new file mode 100644 index 0000000..0f8f2b3 --- /dev/null +++ b/server/server_connections.cpp @@ -0,0 +1,199 @@ +/* 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 +#include + +//------------------------- +//heartbeat system +//------------------------- + +void ServerApplication::HandlePing(ServerPacket* const argPacket) { + ServerPacket newPacket; + newPacket.type = SerialPacketType::PONG; + network.SendTo(argPacket->srcAddress, &newPacket); +} + +void ServerApplication::HandlePong(ServerPacket* const argPacket) { + clientMgr.HandlePong(argPacket); +} + +//------------------------- +//basic connections +//------------------------- + +void ServerApplication::HandleBroadcastRequest(ServerPacket* const argPacket) { + //send the server's data + ServerPacket newPacket; + + newPacket.type = SerialPacketType::BROADCAST_RESPONSE; + strncpy(newPacket.name, config["server.name"].c_str(), PACKET_STRING_SIZE); + newPacket.playerCount = characterMgr.GetLoadedCount(); + newPacket.version = NETWORK_VERSION; + + network.SendTo(argPacket->srcAddress, static_cast(&newPacket)); +} + +void ServerApplication::HandleJoinRequest(ClientPacket* const argPacket) { + //register the client + int clientIndex = clientMgr.Create(argPacket->srcAddress); + + //send the client their info + ClientPacket newPacket; + newPacket.type = SerialPacketType::JOIN_RESPONSE; + newPacket.clientIndex = clientIndex; + + network.SendTo(argPacket->srcAddress, static_cast(&newPacket)); + + //finished this routine + std::cout << "New join, " << clientMgr.GetLoadedCount() << " clients and " << accountMgr.GetLoadedCount() << " accounts total" << std::endl; +} + +void ServerApplication::HandleLoginRequest(ClientPacket* const argPacket) { + //get the client data + ClientData* clientData = clientMgr.Get(argPacket->clientIndex); + + if (clientData == nullptr || clientData->GetAddress() != argPacket->srcAddress) { + std::cerr << "Falsified client index detected: " << argPacket->clientIndex << std::endl; + return; + } + + //load the user account + int accountIndex = accountMgr.Load(argPacket->username, argPacket->clientIndex); + + //Cannot load + if (accountIndex < 0) { + //build the message + std::ostringstream msg; + msg << "Account already loaded: " << argPacket->username; + + //build the packet + TextPacket newPacket; + newPacket.type = SerialPacketType::LOGIN_REJECTION; + strncpy(newPacket.text, msg.str().c_str(), PACKET_STRING_SIZE); + network.SendTo(clientData->GetAddress(), static_cast(&newPacket)); + + //log the error + std::cerr << "Error message sent: " << newPacket.text << std::endl; + return; + } + + //send the client their info + ClientPacket newPacket; + newPacket.type = SerialPacketType::LOGIN_RESPONSE; + newPacket.clientIndex = argPacket->clientIndex; + newPacket.accountIndex = accountIndex; + + network.SendTo(clientData->GetAddress(), static_cast(&newPacket)); + + //finished this routine + std::cout << "New login, " << clientMgr.GetLoadedCount() << " clients and " << accountMgr.GetLoadedCount() << " accounts total" << std::endl; +} + +void ServerApplication::HandleLogoutRequest(ClientPacket* const argPacket) { + //get the account and client data + AccountData* accountData = accountMgr.Get(argPacket->accountIndex); + if (!accountData) { + return; + } + + ClientData* clientData = clientMgr.Get(accountData->GetClientIndex()); + if (!clientData) { + std::ostringstream msg; + msg << "No client found for an account: " << accountData->GetUsername(); + throw(std::logic_error(msg.str())); + } + + //check for fraud + if (clientData->GetAddress() != argPacket->srcAddress) { + std::cerr << "Falsified logout detected targeting: " << accountData->GetUsername() << std::endl; + return; + } + + //send the logout response + ClientPacket newPacket; + newPacket.type = SerialPacketType::LOGOUT_RESPONSE; + newPacket.accountIndex = argPacket->accountIndex; + + network.SendTo(clientData->GetAddress(), static_cast(&newPacket)); + + //save and unload this accounts characters + characterMgr.UnloadIf([&](std::pair it) -> bool { + if (argPacket->accountIndex == it.second.GetOwner()) { + //pump the unload message to all remaining clients + //TODO: pump character unload + return true; + } + return false; + }); + + //unload this account + accountMgr.Unload(argPacket->accountIndex); + + //finished this routine + std::cout << "New logout, " << clientMgr.GetLoadedCount() << " clients and " << accountMgr.GetLoadedCount() << " accounts total" << std::endl; +} + +void ServerApplication::HandleDisconnectRequest(ClientPacket* const argPacket) { + //get the client data + ClientData* clientData = clientMgr.Get(argPacket->clientIndex); + if (!clientData) { + return; + } + + //check for fraud + if (clientData->GetAddress() != argPacket->srcAddress) { + std::cerr << "Falsified disconnection detected targeting: " << argPacket->clientIndex << std::endl; + return; + } + + //send the disconnect response + ClientPacket newPacket; + newPacket.type = SerialPacketType::DISCONNECT_RESPONSE; + newPacket.clientIndex = argPacket->clientIndex; + + network.SendTo(clientData->GetAddress(), static_cast(&newPacket)); + + //TODO: need a method for this redundunt chunk of redundant code + //find and unload the accounts associated with this client + accountMgr.UnloadIf([&](std::pair account) -> bool { + if (account.second.GetClientIndex() == argPacket->clientIndex) { + //find and unload the characters associated with this account + characterMgr.UnloadIf([&](std::pair character) -> bool { + if (character.second.GetOwner() == account.first) { + //TODO: pump character unload + return true; + } + return false; + }); + return true; + } + return false; + }); + + //unload this client + clientMgr.Unload(argPacket->clientIndex); + + //finished this routine + std::cout << "New disconnection, " << clientMgr.GetLoadedCount() << " clients and " << accountMgr.GetLoadedCount() << " accounts total" << std::endl; +} diff --git a/server/server_methods.cpp b/server/server_methods.cpp index f3a21b9..b335e37 100644 --- a/server/server_methods.cpp +++ b/server/server_methods.cpp @@ -25,192 +25,6 @@ #include #include -//------------------------- -//these should've come standard -//------------------------- - -bool operator==(IPaddress lhs, IPaddress rhs) { - return lhs.host == rhs.host && lhs.port == rhs.port; -} - -bool operator!=(IPaddress lhs, IPaddress rhs) { - return !(lhs == rhs); -} - -//------------------------- -//heartbeat system -//------------------------- - -void ServerApplication::HandlePing(ServerPacket* const argPacket) { - ServerPacket newPacket; - newPacket.type = SerialPacketType::PONG; - network.SendTo(argPacket->srcAddress, &newPacket); -} - -void ServerApplication::HandlePong(ServerPacket* const argPacket) { - clientMgr.HandlePong(argPacket); -} - -//------------------------- -//basic connections -//------------------------- - -void ServerApplication::HandleBroadcastRequest(ServerPacket* const argPacket) { - //send the server's data - ServerPacket newPacket; - - newPacket.type = SerialPacketType::BROADCAST_RESPONSE; - strncpy(newPacket.name, config["server.name"].c_str(), PACKET_STRING_SIZE); - newPacket.playerCount = characterMgr.GetLoadedCount(); - newPacket.version = NETWORK_VERSION; - - network.SendTo(argPacket->srcAddress, static_cast(&newPacket)); -} - -void ServerApplication::HandleJoinRequest(ClientPacket* const argPacket) { - //register the client - int clientIndex = clientMgr.Create(argPacket->srcAddress); - - //send the client their info - ClientPacket newPacket; - newPacket.type = SerialPacketType::JOIN_RESPONSE; - newPacket.clientIndex = clientIndex; - - network.SendTo(argPacket->srcAddress, static_cast(&newPacket)); - - //finished this routine - std::cout << "New join, " << clientMgr.GetLoadedCount() << " clients and " << accountMgr.GetLoadedCount() << " accounts total" << std::endl; -} - -void ServerApplication::HandleLoginRequest(ClientPacket* const argPacket) { - //get the client data - ClientData* clientData = clientMgr.Get(argPacket->clientIndex); - - if (clientData == nullptr || clientData->GetAddress() != argPacket->srcAddress) { - std::cerr << "Falsified client index detected: " << argPacket->clientIndex << std::endl; - return; - } - - //load the user account - int accountIndex = accountMgr.Load(argPacket->username, argPacket->clientIndex); - - //Cannot load - if (accountIndex < 0) { - //build the message - std::ostringstream msg; - msg << "Account already loaded: " << argPacket->username; - - //build the packet - TextPacket newPacket; - newPacket.type = SerialPacketType::LOGIN_REJECTION; - strncpy(newPacket.text, msg.str().c_str(), PACKET_STRING_SIZE); - network.SendTo(clientData->GetAddress(), static_cast(&newPacket)); - - //log the error - std::cerr << "Error message sent: " << newPacket.text << std::endl; - return; - } - - //send the client their info - ClientPacket newPacket; - newPacket.type = SerialPacketType::LOGIN_RESPONSE; - newPacket.clientIndex = argPacket->clientIndex; - newPacket.accountIndex = accountIndex; - - network.SendTo(clientData->GetAddress(), static_cast(&newPacket)); - - //finished this routine - std::cout << "New login, " << clientMgr.GetLoadedCount() << " clients and " << accountMgr.GetLoadedCount() << " accounts total" << std::endl; -} - -void ServerApplication::HandleLogoutRequest(ClientPacket* const argPacket) { - //get the account and client data - AccountData* accountData = accountMgr.Get(argPacket->accountIndex); - if (!accountData) { - return; - } - - ClientData* clientData = clientMgr.Get(accountData->GetClientIndex()); - if (!clientData) { - std::ostringstream msg; - msg << "No client found for an account: " << accountData->GetUsername(); - throw(std::logic_error(msg.str())); - } - - //check for fraud - if (clientData->GetAddress() != argPacket->srcAddress) { - std::cerr << "Falsified logout detected targeting: " << accountData->GetUsername() << std::endl; - return; - } - - //send the logout response - ClientPacket newPacket; - newPacket.type = SerialPacketType::LOGOUT_RESPONSE; - newPacket.accountIndex = argPacket->accountIndex; - - network.SendTo(clientData->GetAddress(), static_cast(&newPacket)); - - //save and unload this accounts characters - characterMgr.UnloadIf([&](std::pair it) -> bool { - if (argPacket->accountIndex == it.second.GetOwner()) { - //pump the unload message to all remaining clients -// PumpCharacterUnload(it.first); - return true; - } - return false; - }); - - //unload this account - accountMgr.Unload(argPacket->accountIndex); - - //finished this routine - std::cout << "New logout, " << clientMgr.GetLoadedCount() << " clients and " << accountMgr.GetLoadedCount() << " accounts total" << std::endl; -} - -void ServerApplication::HandleDisconnectRequest(ClientPacket* const argPacket) { - //get the client data - ClientData* clientData = clientMgr.Get(argPacket->clientIndex); - if (!clientData) { - return; - } - - //check for fraud - if (clientData->GetAddress() != argPacket->srcAddress) { - std::cerr << "Falsified disconnection detected targeting: " << argPacket->clientIndex << std::endl; - return; - } - - //send the disconnect response - ClientPacket newPacket; - newPacket.type = SerialPacketType::DISCONNECT_RESPONSE; - newPacket.clientIndex = argPacket->clientIndex; - - network.SendTo(clientData->GetAddress(), static_cast(&newPacket)); - - //TODO: need a method for this redundunt chunk of redundant code - //find and unload the accounts associated with this client - accountMgr.UnloadIf([&](std::pair account) -> bool { - if (account.second.GetClientIndex() == argPacket->clientIndex) { - //find and unload the characters associated with this account - characterMgr.UnloadIf([&](std::pair character) -> bool { - if (character.second.GetOwner() == account.first) { -// PumpCharacterUnload(character.first); - return true; - } - return false; - }); - return true; - } - return false; - }); - - //unload this client - clientMgr.Unload(argPacket->clientIndex); - - //finished this routine - std::cout << "New disconnection, " << clientMgr.GetLoadedCount() << " clients and " << accountMgr.GetLoadedCount() << " accounts total" << std::endl; -} - //------------------------- //server commands //------------------------- @@ -261,9 +75,9 @@ void ServerApplication::HandleShutdownRequest(ClientPacket* const argPacket) { running = false; //disconnect all clients -// ClientPacket newPacket; -// newPacket.type = SerialPacketType::DISCONNECT_FORCED; -// PumpPacket(&newPacket); + //ClientPacket newPacket; + //newPacket.type = SerialPacketType::DISCONNECT_FORCED; + //PumpPacket(&newPacket); //finished this routine std::cout << "Shutdown signal accepted" << std::endl; diff --git a/server/server_util.cpp b/server/server_util.cpp new file mode 100644 index 0000000..b0defb8 --- /dev/null +++ b/server/server_util.cpp @@ -0,0 +1,34 @@ +/* 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" + +//------------------------- +//these should've come standard +//------------------------- + +bool operator==(IPaddress lhs, IPaddress rhs) { + return lhs.host == rhs.host && lhs.port == rhs.port; +} + +bool operator!=(IPaddress lhs, IPaddress rhs) { + return !(lhs == rhs); +} \ No newline at end of file From dbd1289cedf7d83c7dc31577347e0e09b69b3e1b Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Tue, 9 Dec 2014 00:41:09 +1100 Subject: [PATCH 49/73] Moved map and character management to server_data.cpp --- server/server_application.hpp | 9 +- server/server_connections.cpp | 4 + server/server_data.cpp | 197 ++++++++++++++++++++++++++++++++++ server/server_methods.cpp | 183 +------------------------------ server/server_util.cpp | 21 +++- 5 files changed, 229 insertions(+), 185 deletions(-) create mode 100644 server/server_data.cpp diff --git a/server/server_application.hpp b/server/server_application.hpp index fa39475..723899b 100644 --- a/server/server_application.hpp +++ b/server/server_application.hpp @@ -88,7 +88,7 @@ private: void HandleDisconnectRequest(ClientPacket* const); //server commands -// void HandleDisconnectForced(ClientPacket* const); + void HandleDisconnectForced(ClientPacket* const); void HandleShutdownRequest(ClientPacket* const); //data management @@ -101,13 +101,12 @@ private: void HandleCharacterLoad(CharacterPacket* const); void HandleCharacterUnload(CharacterPacket* const); - //mismanagement -// void HandleSynchronize(ClientPacket* const); + //utility methods + void PumpPacket(SerialPacket* const); + void PumpPacketProximity(SerialPacket* const, int roomIndex, int x, int y, int radius); //utility methods - //TODO: a function that only sends to characters in a certain proximity // void CleanupLostConnection(int index); -// void PumpPacket(SerialPacket* const); // void PumpCharacterUnload(int uid); // void CopyCharacterToPacket(CharacterPacket* const packet, int characterIndex); diff --git a/server/server_connections.cpp b/server/server_connections.cpp index 0f8f2b3..b9ca988 100644 --- a/server/server_connections.cpp +++ b/server/server_connections.cpp @@ -197,3 +197,7 @@ void ServerApplication::HandleDisconnectRequest(ClientPacket* const argPacket) { //finished this routine std::cout << "New disconnection, " << clientMgr.GetLoadedCount() << " clients and " << accountMgr.GetLoadedCount() << " accounts total" << std::endl; } + +void ServerApplication::HandleDisconnectForced(ClientPacket* const argPacket) { + //TODO: HandleDisconnectForced +} \ No newline at end of file diff --git a/server/server_data.cpp b/server/server_data.cpp new file mode 100644 index 0000000..85ba3ae --- /dev/null +++ b/server/server_data.cpp @@ -0,0 +1,197 @@ +/* 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 +#include + +//------------------------- +//General data management +//------------------------- + +//TODO: Queries + +void ServerApplication::SaveServerState() { + //TODO: SaveServerState +} + +//------------------------- +//Map management +//------------------------- + +void ServerApplication::HandleRegionRequest(RegionPacket* const argPacket) { + //get the region object, send a rejection on error + RoomData* room = roomMgr.Get(argPacket->roomIndex); + if (!room) { + //build the error message + std::ostringstream msg; + msg << "Failed to find Region (" << argPacket->roomIndex << "," << argPacket->x << "," << argPacket->y << "); "; + msg << "Room " << argPacket->roomIndex << " does not exist"; + + //build the packet + TextPacket newPacket; + newPacket.type = SerialPacketType::REGION_REJECTION; + strncpy(newPacket.text, msg.str().c_str(), PACKET_STRING_SIZE); + network.SendTo(argPacket->srcAddress, static_cast(&newPacket)); + + //log the error + std::cerr << "Error message sent: " << newPacket.text << std::endl; + return; + } + Region* region = room->GetPager()->GetRegion(argPacket->x, argPacket->y); + + //send the content + RegionPacket newPacket; + + newPacket.type = SerialPacketType::REGION_CONTENT; + newPacket.roomIndex = argPacket->roomIndex; + newPacket.x = argPacket->x; + newPacket.y = argPacket->y; + newPacket.region = region; + + network.SendTo(argPacket->srcAddress, static_cast(&newPacket)); +} + +//------------------------- +//Character Management +//------------------------- + +void ServerApplication::HandleCharacterCreate(CharacterPacket* const argPacket) { + int characterIndex = characterMgr.Create(argPacket->accountIndex, argPacket->handle, argPacket->avatar); + + if (characterIndex < 0) { + //build the error message + std::ostringstream msg; + msg << "Character already exists: " << argPacket->handle; + + //build & send the packet + TextPacket newPacket; + newPacket.type = SerialPacketType::CHARACTER_REJECTION; + strncpy(newPacket.text, msg.str().c_str(), PACKET_STRING_SIZE); + network.SendTo(argPacket->srcAddress, static_cast(&newPacket)); + + return; + } + + //send this character to the player + CharacterPacket newPacket; + newPacket.type = SerialPacketType::CHARACTER_CREATE; + //TODO: pump character load +} + +void ServerApplication::HandleCharacterDelete(CharacterPacket* const argPacket) { + //get the user's data + AccountData* accountData = accountMgr.Get(argPacket->accountIndex); + if (!accountData) { + return; + } + ClientData* clientData = clientMgr.Get(accountData->GetClientIndex()); + if (!clientData) { + return; + } + + //check for fraud + if (clientData->GetAddress() != argPacket->srcAddress) { + std::cerr << "Falsified character deletion detected targeting: " << argPacket->handle << std::endl; + return; + } + + //load the character into memory + int characterIndex = characterMgr.Load(argPacket->accountIndex, argPacket->handle, argPacket->avatar); + + if (characterIndex < 0) { + //build the error message + std::ostringstream msg; + msg << "Cannot delete this character"; + + //build & send the packet + TextPacket newPacket; + newPacket.type = SerialPacketType::CHARACTER_REJECTION; + strncpy(newPacket.text, msg.str().c_str(), PACKET_STRING_SIZE); + network.SendTo(argPacket->srcAddress, static_cast(&newPacket)); + + return; + } + + //delete the character + characterMgr.Delete(characterIndex); + + //TODO: pump character unload +} + +void ServerApplication::HandleCharacterLoad(CharacterPacket* const argPacket) { + int characterIndex = characterMgr.Load(argPacket->accountIndex, argPacket->handle, argPacket->avatar); + + if (characterIndex < 0) { + //build the error message + std::ostringstream msg; + if (characterIndex == -1) { + msg << "Character already loaded: "; + } + if (characterIndex == -1) { + msg << "Character name is taken: "; + } + msg << argPacket->handle; + + //build & send the packet + TextPacket newPacket; + newPacket.type = SerialPacketType::CHARACTER_REJECTION; + strncpy(newPacket.text, msg.str().c_str(), PACKET_STRING_SIZE); + network.SendTo(argPacket->srcAddress, static_cast(&newPacket)); + + return; + } + + //send this character to the player + CharacterPacket newPacket; + newPacket.type = SerialPacketType::CHARACTER_CREATE; + //TODO: pump character load +} + +void ServerApplication::HandleCharacterUnload(CharacterPacket* const argPacket) { + //get the entries + CharacterData* characterData = characterMgr.Get(argPacket->characterIndex); + if (!characterData) { + return; + } + + AccountData* accountData = accountMgr.Get(characterData->GetOwner()); + if (!accountData) { + return; //TODO: logic_error + } + + ClientData* clientData = clientMgr.Get(accountData->GetClientIndex()); + if (!clientData) { + return; //TODO: logic_error + } + + //check for fraud + if (clientData->GetAddress() != argPacket->srcAddress) { + std::cerr << "Falsified character unload detected targeting: uid(" << argPacket->characterIndex << ")" << std::endl; + return; + } + + //unload the character + characterMgr.Unload(argPacket->characterIndex); + + //TODO: pump character unload +} \ No newline at end of file diff --git a/server/server_methods.cpp b/server/server_methods.cpp index b335e37..87de59a 100644 --- a/server/server_methods.cpp +++ b/server/server_methods.cpp @@ -29,10 +29,6 @@ //server commands //------------------------- -//void ServerApplication::HandleDisconnectForced(ClientPacket* const argPacket) { -// //TODO -//} - void ServerApplication::HandleShutdownRequest(ClientPacket* const argPacket) { //get the account and client data AccountData* accountData = accountMgr.Get(argPacket->accountIndex); @@ -75,176 +71,15 @@ void ServerApplication::HandleShutdownRequest(ClientPacket* const argPacket) { running = false; //disconnect all clients - //ClientPacket newPacket; - //newPacket.type = SerialPacketType::DISCONNECT_FORCED; - //PumpPacket(&newPacket); + TextPacket newPacket; + newPacket.type = SerialPacketType::DISCONNECT_FORCED; + strncpy(newPacket.text, "Server shutdown", PACKET_STRING_SIZE); + PumpPacket(&newPacket); //finished this routine std::cout << "Shutdown signal accepted" << std::endl; } -//------------------------- -//data management -//------------------------- - -void ServerApplication::HandleRegionRequest(RegionPacket* const argPacket) { - //get the region object, send a rejection on error - RoomData* room = roomMgr.Get(argPacket->roomIndex); - if (!room) { - //build the error message - std::ostringstream msg; - msg << "Failed to find Region (" << argPacket->roomIndex << "," << argPacket->x << "," << argPacket->y << "); "; - msg << "Room " << argPacket->roomIndex << " does not exist"; - - //build the packet - TextPacket newPacket; - newPacket.type = SerialPacketType::REGION_REJECTION; - strncpy(newPacket.text, msg.str().c_str(), PACKET_STRING_SIZE); - network.SendTo(argPacket->srcAddress, static_cast(&newPacket)); - - //log the error - std::cerr << "Error message sent: " << newPacket.text << std::endl; - return; - } - Region* region = room->GetPager()->GetRegion(argPacket->x, argPacket->y); - - //send the content - RegionPacket newPacket; - - newPacket.type = SerialPacketType::REGION_CONTENT; - newPacket.roomIndex = argPacket->roomIndex; - newPacket.x = argPacket->x; - newPacket.y = argPacket->y; - newPacket.region = region; - - network.SendTo(argPacket->srcAddress, static_cast(&newPacket)); -} - -//------------------------- -//Character Management -//------------------------- - -void ServerApplication::HandleCharacterCreate(CharacterPacket* const argPacket) { - int characterIndex = characterMgr.Create(argPacket->accountIndex, argPacket->handle, argPacket->avatar); - - if (characterIndex < 0) { - //build the error message - std::ostringstream msg; - msg << "Character already exists: " << argPacket->handle; - - //build & send the packet - TextPacket newPacket; - newPacket.type = SerialPacketType::CHARACTER_REJECTION; - strncpy(newPacket.text, msg.str().c_str(), PACKET_STRING_SIZE); - network.SendTo(argPacket->srcAddress, static_cast(&newPacket)); - - return; - } - - //send this character to the player - CharacterPacket newPacket; - newPacket.type = SerialPacketType::CHARACTER_CREATE; - //TODO: pump character load -} - -void ServerApplication::HandleCharacterDelete(CharacterPacket* const argPacket) { - //get the user's data - AccountData* accountData = accountMgr.Get(argPacket->accountIndex); - if (!accountData) { - return; - } - ClientData* clientData = clientMgr.Get(accountData->GetClientIndex()); - if (!clientData) { - return; - } - - //check for fraud - if (clientData->GetAddress() != argPacket->srcAddress) { - std::cerr << "Falsified character deletion detected targeting: " << argPacket->handle << std::endl; - return; - } - - //load the character into memory - int characterIndex = characterMgr.Load(argPacket->accountIndex, argPacket->handle, argPacket->avatar); - - if (characterIndex < 0) { - //build the error message - std::ostringstream msg; - msg << "Cannot delete this character"; - - //build & send the packet - TextPacket newPacket; - newPacket.type = SerialPacketType::CHARACTER_REJECTION; - strncpy(newPacket.text, msg.str().c_str(), PACKET_STRING_SIZE); - network.SendTo(argPacket->srcAddress, static_cast(&newPacket)); - - return; - } - - //delete the character - characterMgr.Delete(characterIndex); - - //TODO: pump character unload -} - -void ServerApplication::HandleCharacterLoad(CharacterPacket* const argPacket) { - int characterIndex = characterMgr.Load(argPacket->accountIndex, argPacket->handle, argPacket->avatar); - - if (characterIndex < 0) { - //build the error message - std::ostringstream msg; - if (characterIndex == -1) { - msg << "Character already loaded: "; - } - if (characterIndex == -1) { - msg << "Character name is taken: "; - } - msg << argPacket->handle; - - //build & send the packet - TextPacket newPacket; - newPacket.type = SerialPacketType::CHARACTER_REJECTION; - strncpy(newPacket.text, msg.str().c_str(), PACKET_STRING_SIZE); - network.SendTo(argPacket->srcAddress, static_cast(&newPacket)); - - return; - } - - //send this character to the player - CharacterPacket newPacket; - newPacket.type = SerialPacketType::CHARACTER_CREATE; - //TODO: pump character load -} - -void ServerApplication::HandleCharacterUnload(CharacterPacket* const argPacket) { - //get the entries - CharacterData* characterData = characterMgr.Get(argPacket->characterIndex); - if (!characterData) { - return; - } - - AccountData* accountData = accountMgr.Get(characterData->GetOwner()); - if (!accountData) { - return; //TODO: logic_error - } - - ClientData* clientData = clientMgr.Get(accountData->GetClientIndex()); - if (!clientData) { - return; //TODO: logic_error - } - - //check for fraud - if (clientData->GetAddress() != argPacket->srcAddress) { - std::cerr << "Falsified character unload detected targeting: uid(" << argPacket->characterIndex << ")" << std::endl; - return; - } - - //unload the character - characterMgr.Unload(argPacket->characterIndex); - - //TODO: pump character unload -} - /* //SET: entities @@ -334,16 +169,6 @@ void ServerApplication::CleanupLostConnection(int clientIndex) { std::cout << clientMgr.GetLoadedCount() << " clients and " << accountMgr.GetLoadedCount() << " accounts total" << std::endl; } -//SET: utility -//TODO: a function that only sends to characters in a certain proximity - -//SET: utility -void ServerApplication::PumpPacket(SerialPacket* const argPacket) { - for (auto& it : *clientMgr.GetContainer()) { - network.SendTo(it.second.GetAddress(), argPacket); - } -} - //SET: utility/delete void ServerApplication::PumpCharacterUnload(int uid) { //delete the client-side character(s) diff --git a/server/server_util.cpp b/server/server_util.cpp index b0defb8..4c8a01b 100644 --- a/server/server_util.cpp +++ b/server/server_util.cpp @@ -31,4 +31,23 @@ bool operator==(IPaddress lhs, IPaddress rhs) { bool operator!=(IPaddress lhs, IPaddress rhs) { return !(lhs == rhs); -} \ No newline at end of file +} + +//------------------------- +//Packet pumps +//------------------------- + +void ServerApplication::PumpPacket(SerialPacket* const argPacket) { + for (auto& it : *clientMgr.GetContainer()) { + network.SendTo(it.second.GetAddress(), argPacket); + } +} + +void ServerApplication::PumpPacketProximity(SerialPacket* const argPacket, int roomIndex, int x, int y, int radius) { + //TODO: PumpPacketProximity + //for position (roomIndex, x, y), find all characters within that distance + //find that character's owner + //find that account's client + //send the packet to that client + //NOTE: this is perhaps too complex; I write it if I need it +} From 72f641bf6345c3cc94c8f3be6fa6ead2a3c8d4c4 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Thu, 11 Dec 2014 07:12:16 +1100 Subject: [PATCH 50/73] Server sends character create & delete messages --- client/scenes/in_world.cpp | 18 ++++++++++++++++++ client/scenes/in_world.hpp | 4 ++++ server/server_application.hpp | 6 +----- server/server_data.cpp | 22 ++++++++++++++++------ server/server_logic.cpp | 8 +++++++- server/server_methods.cpp | 27 --------------------------- server/server_util.cpp | 20 ++++++++++++++++++++ 7 files changed, 66 insertions(+), 39 deletions(-) diff --git a/client/scenes/in_world.cpp b/client/scenes/in_world.cpp index 1e45649..43db4eb 100644 --- a/client/scenes/in_world.cpp +++ b/client/scenes/in_world.cpp @@ -243,6 +243,14 @@ void InWorld::HandlePacket(SerialPacket* const argPacket) { HandleRegionContent(static_cast(argPacket)); break; + //character management + case SerialPacketType::CHARACTER_CREATE: + HandleCharacterCreate(static_cast(argPacket)); + break; + case SerialPacketType::CHARACTER_DELETE: + HandleCharacterDelete(static_cast(argPacket)); + break; + //rejection messages case SerialPacketType::REGION_REJECTION: case SerialPacketType::CHARACTER_REJECTION: @@ -377,3 +385,13 @@ void InWorld::UpdateMap() { } } } + +void InWorld::HandleCharacterCreate(CharacterPacket* const argPacket) { + //TODO: HandleCharacterCreate() + std::cout << "HandleCharacterCreate" << std::endl; +} + +void InWorld::HandleCharacterDelete(CharacterPacket* const argPacket) { + //TODO: HandleCharacterDelete() + std::cout << "HandleCharacterDelete" << std::endl; +} \ No newline at end of file diff --git a/client/scenes/in_world.hpp b/client/scenes/in_world.hpp index 1c7c58c..5e2ae31 100644 --- a/client/scenes/in_world.hpp +++ b/client/scenes/in_world.hpp @@ -91,6 +91,10 @@ protected: void HandleRegionContent(RegionPacket* const); void UpdateMap(); + //character management + void HandleCharacterCreate(CharacterPacket* const); + void HandleCharacterDelete(CharacterPacket* const); + //indexes int& clientIndex; int& accountIndex; diff --git a/server/server_application.hpp b/server/server_application.hpp index 723899b..ee93dfb 100644 --- a/server/server_application.hpp +++ b/server/server_application.hpp @@ -104,11 +104,7 @@ private: //utility methods void PumpPacket(SerialPacket* const); void PumpPacketProximity(SerialPacket* const, int roomIndex, int x, int y, int radius); - - //utility methods -// void CleanupLostConnection(int index); -// void PumpCharacterUnload(int uid); -// void CopyCharacterToPacket(CharacterPacket* const packet, int characterIndex); + void CopyCharacterToPacket(CharacterPacket* const packet, int characterIndex); //APIs and utilities sqlite3* database = nullptr; diff --git a/server/server_data.cpp b/server/server_data.cpp index 85ba3ae..135dfa2 100644 --- a/server/server_data.cpp +++ b/server/server_data.cpp @@ -92,10 +92,11 @@ void ServerApplication::HandleCharacterCreate(CharacterPacket* const argPacket) return; } - //send this character to the player + //pump this character to all clients CharacterPacket newPacket; + CopyCharacterToPacket(&newPacket, characterIndex); newPacket.type = SerialPacketType::CHARACTER_CREATE; - //TODO: pump character load + PumpPacket(&newPacket); } void ServerApplication::HandleCharacterDelete(CharacterPacket* const argPacket) { @@ -135,7 +136,11 @@ void ServerApplication::HandleCharacterDelete(CharacterPacket* const argPacket) //delete the character characterMgr.Delete(characterIndex); - //TODO: pump character unload + //pump character delete + CharacterPacket newPacket; + newPacket.type = SerialPacketType::CHARACTER_DELETE; + newPacket.characterIndex = characterIndex; + PumpPacket(static_cast(&newPacket)); } void ServerApplication::HandleCharacterLoad(CharacterPacket* const argPacket) { @@ -161,10 +166,11 @@ void ServerApplication::HandleCharacterLoad(CharacterPacket* const argPacket) { return; } - //send this character to the player + //pump this character to all clients CharacterPacket newPacket; + CopyCharacterToPacket(&newPacket, characterIndex); newPacket.type = SerialPacketType::CHARACTER_CREATE; - //TODO: pump character load + PumpPacket(&newPacket); } void ServerApplication::HandleCharacterUnload(CharacterPacket* const argPacket) { @@ -193,5 +199,9 @@ void ServerApplication::HandleCharacterUnload(CharacterPacket* const argPacket) //unload the character characterMgr.Unload(argPacket->characterIndex); - //TODO: pump character unload + //pump character delete + CharacterPacket newPacket; + newPacket.type = SerialPacketType::CHARACTER_DELETE; + newPacket.characterIndex = argPacket->characterIndex; + PumpPacket(static_cast(&newPacket)); } \ No newline at end of file diff --git a/server/server_logic.cpp b/server/server_logic.cpp index 341a46c..9db5034 100644 --- a/server/server_logic.cpp +++ b/server/server_logic.cpp @@ -188,7 +188,13 @@ void ServerApplication::Proc() { //find and unload the characters associated with this account characterMgr.UnloadIf([&](std::pair character) -> bool { if (character.second.GetOwner() == account.first) { -// PumpCharacterUnload(character.first); + //pump character delete + CharacterPacket newPacket; + newPacket.type = SerialPacketType::CHARACTER_DELETE; + newPacket.characterIndex = character.first; + PumpPacket(static_cast(&newPacket)); + + //unload this character return true; } return false; diff --git a/server/server_methods.cpp b/server/server_methods.cpp index 87de59a..610e525 100644 --- a/server/server_methods.cpp +++ b/server/server_methods.cpp @@ -169,32 +169,5 @@ void ServerApplication::CleanupLostConnection(int clientIndex) { std::cout << clientMgr.GetLoadedCount() << " clients and " << accountMgr.GetLoadedCount() << " accounts total" << std::endl; } -//SET: utility/delete -void ServerApplication::PumpCharacterUnload(int uid) { - //delete the client-side character(s) - //NOTE: This is a strange function - CharacterPacket newPacket; - newPacket.type = SerialPacketType::CHARACTER_DELETE; - newPacket.characterIndex = uid; - PumpPacket(static_cast(&newPacket)); -} - -//SET: utility/delete -void ServerApplication::CopyCharacterToPacket(CharacterPacket* const packet, int characterIndex) { - CharacterData* character = characterMgr.Get(characterIndex); - if (!character) { - throw(std::runtime_error("Failed to copy a character to a packet")); - } - - //TODO: keep this up to date when the character changes - packet->characterIndex = characterIndex; - strncpy(packet->handle, character->GetHandle().c_str(), PACKET_STRING_SIZE); - strncpy(packet->avatar, character->GetAvatar().c_str(), PACKET_STRING_SIZE); - packet->accountIndex = character->GetOwner(); - packet->roomIndex = character->GetRoomIndex(); - packet->origin = character->GetOrigin(); - packet->motion = character->GetMotion(); -} - //TODO: remove this terminate comment //*/ \ No newline at end of file diff --git a/server/server_util.cpp b/server/server_util.cpp index 4c8a01b..b0ef563 100644 --- a/server/server_util.cpp +++ b/server/server_util.cpp @@ -51,3 +51,23 @@ void ServerApplication::PumpPacketProximity(SerialPacket* const argPacket, int r //send the packet to that client //NOTE: this is perhaps too complex; I write it if I need it } + +//------------------------- +//common copy methods +//------------------------- + +void ServerApplication::CopyCharacterToPacket(CharacterPacket* const packet, int characterIndex) { + CharacterData* character = characterMgr.Get(characterIndex); + if (!character) { + throw(std::runtime_error("Failed to copy a character to a packet")); + } + + //NOTE: keep this up to date when the character changes + packet->characterIndex = characterIndex; + strncpy(packet->handle, character->GetHandle().c_str(), PACKET_STRING_SIZE); + strncpy(packet->avatar, character->GetAvatar().c_str(), PACKET_STRING_SIZE); + packet->accountIndex = character->GetOwner(); + packet->roomIndex = character->GetRoomIndex(); + packet->origin = character->GetOrigin(); + packet->motion = character->GetMotion(); +} \ No newline at end of file From ae046977f0b71907c95738b522fa9b0fe7f96335 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Thu, 11 Dec 2014 08:02:38 +1100 Subject: [PATCH 51/73] Server state query works, client doesn't use the result yet Both sides of this message uses QUERY_CHARACTER_EXISTS because I'm just trying to push forward, without worrying about mistakes I might be making. I just want to merge this back into the main branch so I can say that I've actually done something over the last few months. --- client/scenes/in_world.cpp | 16 ++++++++ client/scenes/in_world.hpp | 1 + server/server_application.hpp | 2 + server/server_data.cpp | 10 +++++ server/server_logic.cpp | 3 ++ server/server_methods.cpp | 71 +---------------------------------- 6 files changed, 33 insertions(+), 70 deletions(-) diff --git a/client/scenes/in_world.cpp b/client/scenes/in_world.cpp index 43db4eb..1293ade 100644 --- a/client/scenes/in_world.cpp +++ b/client/scenes/in_world.cpp @@ -86,6 +86,11 @@ InWorld::InWorld(int* const argClientIndex, int* const argAccountIndex): newPacket.accountIndex = accountIndex; network.SendTo(Channels::SERVER, &newPacket); + //query the world state + memset(&newPacket, 0, MAX_PACKET_SIZE); + newPacket.type = SerialPacketType::QUERY_CHARACTER_EXISTS; + network.SendTo(Channels::SERVER, &newPacket); + //debug // } @@ -250,6 +255,9 @@ void InWorld::HandlePacket(SerialPacket* const argPacket) { case SerialPacketType::CHARACTER_DELETE: HandleCharacterDelete(static_cast(argPacket)); break; + case SerialPacketType::QUERY_CHARACTER_EXISTS: + HandleCharacterQueryExists(static_cast(argPacket)); + break; //rejection messages case SerialPacketType::REGION_REJECTION: @@ -394,4 +402,12 @@ void InWorld::HandleCharacterCreate(CharacterPacket* const argPacket) { void InWorld::HandleCharacterDelete(CharacterPacket* const argPacket) { //TODO: HandleCharacterDelete() std::cout << "HandleCharacterDelete" << std::endl; +} + +void InWorld::HandleCharacterQueryExists(CharacterPacket* const argPacket) { + //TODO: HandleCharacterQueryExists() + std::cout << "HandleCharacterQueryExists" << std::endl; + //NOTE: preexisting characters will result in query responses + //NOTE: new characters will result in create messages + //NOTE: this client's character will exist in both } \ No newline at end of file diff --git a/client/scenes/in_world.hpp b/client/scenes/in_world.hpp index 5e2ae31..ccf1c42 100644 --- a/client/scenes/in_world.hpp +++ b/client/scenes/in_world.hpp @@ -94,6 +94,7 @@ protected: //character management void HandleCharacterCreate(CharacterPacket* const); void HandleCharacterDelete(CharacterPacket* const); + void HandleCharacterQueryExists(CharacterPacket* const); //indexes int& clientIndex; diff --git a/server/server_application.hpp b/server/server_application.hpp index ee93dfb..b794b3f 100644 --- a/server/server_application.hpp +++ b/server/server_application.hpp @@ -93,6 +93,8 @@ private: //data management void HandleRegionRequest(RegionPacket* const); + void HandleCharacterExists(CharacterPacket* const); + void SaveServerState(); //character management diff --git a/server/server_data.cpp b/server/server_data.cpp index 135dfa2..76b1573 100644 --- a/server/server_data.cpp +++ b/server/server_data.cpp @@ -71,6 +71,16 @@ void ServerApplication::HandleRegionRequest(RegionPacket* const argPacket) { network.SendTo(argPacket->srcAddress, static_cast(&newPacket)); } +void ServerApplication::HandleCharacterExists(CharacterPacket* const argPacket) { + //respond with all character data + CharacterPacket newPacket; + for (auto& it : *characterMgr.GetContainer()) { + CopyCharacterToPacket(&newPacket, it.first); + newPacket.type = SerialPacketType::QUERY_CHARACTER_EXISTS; + network.SendTo(argPacket->srcAddress, static_cast(&newPacket)); + } +} + //------------------------- //Character Management //------------------------- diff --git a/server/server_logic.cpp b/server/server_logic.cpp index 9db5034..1e1dbf1 100644 --- a/server/server_logic.cpp +++ b/server/server_logic.cpp @@ -279,6 +279,9 @@ void ServerApplication::HandlePacket(SerialPacket* const argPacket) { case SerialPacketType::REGION_REQUEST: HandleRegionRequest(static_cast(argPacket)); break; + case SerialPacketType::QUERY_CHARACTER_EXISTS: + HandleCharacterExists(static_cast(argPacket)); + break; //character management case SerialPacketType::CHARACTER_CREATE: diff --git a/server/server_methods.cpp b/server/server_methods.cpp index 610e525..d163f18 100644 --- a/server/server_methods.cpp +++ b/server/server_methods.cpp @@ -101,73 +101,4 @@ void ServerApplication::HandleCharacterUpdate(CharacterPacket* const argPacket) PumpPacket(argPacket); } - -//------------------------- -//mismanagement -//------------------------- - -//SET: delete -void ServerApplication::HandleSynchronize(ClientPacket* const argPacket) { - //TODO: compensate for large distances - //NOTE: I quite dislike this function - - //send all of the server's data to this client - ClientData* client = clientMgr.Get(argPacket->clientIndex); - - //send all characters - CharacterPacket newPacket; - newPacket.type = SerialPacketType::CHARACTER_SET_ORIGIN; - - for (auto& it : *characterMgr.GetContainer()) { - CopyCharacterToPacket(&newPacket, it.first); - network.SendTo(client->GetAddress(), static_cast(&newPacket)); - } - - //TODO: more in HandleSynchronize() -} - -//SET: utility/manager -void ServerApplication::CleanupLostConnection(int clientIndex) { - //NOTE: This assumes each player has only one account and character at a time - //TODO: handle multiple characters (bots, etc.) - - //send a disconnection message just in case - ClientPacket newPacket; - newPacket.type = SerialPacketType::DISCONNECT_FORCED; - network.SendTo(clientMgr.Get(clientIndex)->GetAddress(), &newPacket); - - //find the account - int accountIndex = -1; - for (auto& it : *accountMgr.GetContainer()) { - if (it.second.GetClientIndex() == clientIndex) { - accountIndex = it.first; - break; - } - } - - //find the character - int characterIndex = -1; - for (auto& it : *characterMgr.GetContainer()) { - if (it.second.GetOwner() == accountIndex) { - characterIndex = it.first; - break; - } - } - - //clean up this mess - characterMgr.Unload(characterIndex); - accountMgr.Unload(accountIndex); - clientMgr.Unload(clientIndex); - - PumpCharacterUnload(characterIndex); - - //output a message - std::cerr << "Connection lost: " << std::endl; - std::cerr << "\tClient: " << clientIndex << std::endl; - std::cerr << "\tAccount: " << accountIndex << std::endl; - std::cerr << "\tCharacter: " << characterIndex << std::endl; - std::cout << clientMgr.GetLoadedCount() << " clients and " << accountMgr.GetLoadedCount() << " accounts total" << std::endl; -} - -//TODO: remove this terminate comment -//*/ \ No newline at end of file +*/ \ No newline at end of file From 3399053e64e67d313247eecef0a949b121e047fc Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Tue, 16 Dec 2014 21:49:50 +1100 Subject: [PATCH 52/73] Added an option to skip missing config files --- client/client_application.cpp | 2 +- client/main.cpp | 2 +- common/utilities/config_utility.cpp | 17 +++++++++++------ common/utilities/config_utility.hpp | 9 +++------ server/server_logic.cpp | 2 +- 5 files changed, 17 insertions(+), 15 deletions(-) diff --git a/client/client_application.cpp b/client/client_application.cpp index 2725314..cb3ad64 100644 --- a/client/client_application.cpp +++ b/client/client_application.cpp @@ -49,7 +49,7 @@ void ClientApplication::Init(int argc, char* argv[]) { //load the prerequisites ConfigUtility& config = ConfigUtility::GetSingleton(); - config.Load("rsc/config.cfg", argc, argv); + config.Load("rsc/config.cfg", false, argc, argv); //------------------------- //Initialize the APIs diff --git a/client/main.cpp b/client/main.cpp index 2115115..337f836 100644 --- a/client/main.cpp +++ b/client/main.cpp @@ -36,7 +36,7 @@ int main(int argc, char* argv[]) { ConfigUtility::CreateSingleton(); UDPNetworkUtility::CreateSingleton(); - //call the server's routines + //call the client's routines ClientApplication::CreateSingleton(); ClientApplication& app = ClientApplication::GetSingleton(); diff --git a/common/utilities/config_utility.cpp b/common/utilities/config_utility.cpp index fedf7e0..38cc7da 100644 --- a/common/utilities/config_utility.cpp +++ b/common/utilities/config_utility.cpp @@ -27,13 +27,13 @@ #include #include -void ConfigUtility::Load(std::string fname, int argc, char* argv[]) { +void ConfigUtility::Load(std::string fname, bool skipMissingFile, int argc, char* argv[]) { //clear the stored configuration configMap.clear(); //use the default file if (argc < 2) { - configMap = Read(fname); + configMap = Read(fname, skipMissingFile); return; } @@ -47,7 +47,9 @@ void ConfigUtility::Load(std::string fname, int argc, char* argv[]) { for (int i = 1; i < argc; ++i) { //read from a specified config file if (!strncmp(argv[i], "-config=", 8)) { - redirectedFile = Read(argv[i] + 8); + //older specified files take precedence + table_t tmp = Read(argv[i] + 8, skipMissingFile); + redirectedFile.insert(tmp.begin(), tmp.end()); redirectUsed = true; continue; } @@ -73,18 +75,21 @@ void ConfigUtility::Load(std::string fname, int argc, char* argv[]) { //finally, construct the final config table if (!redirectUsed) { - redirectedFile = Read(fname); + redirectedFile = Read(fname, skipMissingFile); } configMap.insert(cmdLineParams.begin(), cmdLineParams.end()); configMap.insert(redirectedFile.begin(), redirectedFile.end()); } -ConfigUtility::table_t ConfigUtility::Read(std::string fname) { +ConfigUtility::table_t ConfigUtility::Read(std::string fname, bool skipMissingFile) { //read in and return this file's data table_t retTable; std::ifstream is(fname); if (!is.is_open()) { + if (skipMissingFile) { + return {}; //empty table + } std::ostringstream os; os << "Failed to open a config file: " << fname; throw(std::runtime_error( os.str() )); @@ -143,7 +148,7 @@ ConfigUtility::table_t ConfigUtility::Read(std::string fname) { //load in any subordinate config files if (retTable.find("config.next") != retTable.end()) { - table_t subTable = Read(retTable["config.next"]); + table_t subTable = Read(retTable["config.next"], skipMissingFile); retTable.insert(subTable.begin(), subTable.end()); } diff --git a/common/utilities/config_utility.hpp b/common/utilities/config_utility.hpp index fd6fb99..b09fa65 100644 --- a/common/utilities/config_utility.hpp +++ b/common/utilities/config_utility.hpp @@ -27,9 +27,9 @@ #include #include -class ConfigUtility : public Singleton { +class ConfigUtility: public Singleton { public: - void Load(std::string fname, int argc = 0, char* argv[] = nullptr); + void Load(std::string fname, bool skipMissingFile = false, int argc = 0, char* argv[] = nullptr); //convert to a type std::string& String(std::string); @@ -47,10 +47,7 @@ private: friend Singleton; - ConfigUtility() = default; - ~ConfigUtility() = default; - - table_t Read(std::string fname); + table_t Read(std::string fname, bool skipMissingFile); table_t configMap; }; diff --git a/server/server_logic.cpp b/server/server_logic.cpp index c83447b..72ddccb 100644 --- a/server/server_logic.cpp +++ b/server/server_logic.cpp @@ -40,7 +40,7 @@ void ServerApplication::Init(int argc, char* argv[]) { std::cout << "Beginning " << argv[0] << std::endl; //load the prerequisites - config.Load("rsc/config.cfg", argc, argv); + config.Load("rsc/config.cfg", false, argc, argv); //------------------------- //Initialize the APIs From 015631a73d1a6d5b2bee093b705eb00db78564fa Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Thu, 18 Dec 2014 09:14:11 +1100 Subject: [PATCH 53/73] Implemented client-side HandleCharacterCreate --- client/entities/base_character.cpp | 6 ++- client/entities/entity.cpp | 8 ---- client/entities/entity.hpp | 3 -- client/scenes/in_world.cpp | 56 ++++++++++++++++++++++----- client/scenes/in_world.hpp | 6 +++ common/gameplay/character_defines.hpp | 4 ++ 6 files changed, 62 insertions(+), 21 deletions(-) diff --git a/client/entities/base_character.cpp b/client/entities/base_character.cpp index 8acdc72..cfa20b4 100644 --- a/client/entities/base_character.cpp +++ b/client/entities/base_character.cpp @@ -21,6 +21,8 @@ */ #include "base_character.hpp" +#include "config_utility.hpp" + //------------------------- //graphics //------------------------- @@ -71,7 +73,9 @@ std::string BaseCharacter::GetHandle() const { } std::string BaseCharacter::SetAvatar(std::string s) { - return avatar = s; + avatar = s; + sprite.LoadSurface(ConfigUtility::GetSingleton()["dir.sprites"] + avatar, CHARACTER_CELLS_X, CHARACTER_CELLS_Y); + return avatar; } std::string BaseCharacter::GetAvatar() const { diff --git a/client/entities/entity.cpp b/client/entities/entity.cpp index 04ba38a..98b9483 100644 --- a/client/entities/entity.cpp +++ b/client/entities/entity.cpp @@ -42,10 +42,6 @@ int Entity::SetEntityIndex(int i) { return entityIndex = i; } -int Entity::SetRoomIndex(int i) { - return roomIndex = i; -} - Vector2 Entity::SetOrigin(Vector2 v) { return origin = v; } @@ -62,10 +58,6 @@ int Entity::GetEntityIndex() { return entityIndex; } -int Entity::GetRoomIndex() { - return roomIndex; -} - Vector2 Entity::GetOrigin() { return origin; } diff --git a/client/entities/entity.hpp b/client/entities/entity.hpp index 694490d..c12fb71 100644 --- a/client/entities/entity.hpp +++ b/client/entities/entity.hpp @@ -36,13 +36,11 @@ public: //accessors & mutators int SetEntityIndex(int i); - int SetRoomIndex(int i); Vector2 SetOrigin(Vector2 v); Vector2 SetMotion(Vector2 v); BoundingBox SetBounds(BoundingBox b); int GetEntityIndex(); - int GetRoomIndex(); Vector2 GetOrigin(); Vector2 GetMotion(); BoundingBox GetBounds(); @@ -53,7 +51,6 @@ protected: SpriteSheet sprite; int entityIndex = -1; - int roomIndex = -1; Vector2 origin; Vector2 motion; BoundingBox bounds; diff --git a/client/scenes/in_world.cpp b/client/scenes/in_world.cpp index 1293ade..3cf019f 100644 --- a/client/scenes/in_world.cpp +++ b/client/scenes/in_world.cpp @@ -96,7 +96,9 @@ InWorld::InWorld(int* const argClientIndex, int* const argAccountIndex): } InWorld::~InWorld() { - // + //unload the local data + characterMap.clear(); + monsterMap.clear(); } //------------------------- @@ -168,6 +170,16 @@ void InWorld::Render(SDL_Surface* const screen) { tileSheet.DrawRegionTo(screen, &(*it), camera.x, camera.y); } + //draw the entities + for (auto& it : characterMap) { + //TODO: depth ordering + it.second.DrawTo(screen, camera.x, camera.y); + } + for (auto& it : monsterMap) { + //TODO: depth ordering + it.second.DrawTo(screen, camera.x, camera.y); + } + //draw UI disconnectButton.DrawTo(screen); shutDownButton.DrawTo(screen); @@ -328,8 +340,7 @@ void InWorld::SendShutdownRequest() { void InWorld::HandleLogoutResponse(ClientPacket* const argPacket) { accountIndex = -1; - - //TODO: unload the character + characterIndex = -1; SendDisconnectRequest(); } @@ -340,7 +351,10 @@ void InWorld::HandleDisconnectResponse(ClientPacket* const argPacket) { } void InWorld::HandleDisconnectForced(ClientPacket* const argPacket) { - //TODO: More needed in the disconnection + //clear the local data + accountIndex = -1; + characterIndex = -1; + SetNextScene(SceneList::DISCONNECTEDSCREEN); ConfigUtility::GetSingleton()["client.disconnectMessage"] = "You have been forcibly disconnected by the server"; } @@ -394,9 +408,36 @@ void InWorld::UpdateMap() { } } +//------------------------- +//entity management +//------------------------- + +//NOTE: preexisting characters will result in query responses +//NOTE: new characters will result in create messages +//NOTE: this client's character will exist in both + void InWorld::HandleCharacterCreate(CharacterPacket* const argPacket) { - //TODO: HandleCharacterCreate() - std::cout << "HandleCharacterCreate" << std::endl; + //prevent double message + if (characterMap.find(argPacket->characterIndex) != characterMap.end()) { + std::ostringstream msg; + msg << "Double character creation event; "; + msg << "Index: " << argPacket->characterIndex << "; "; + msg << "Handle: " << argPacket->handle; + throw(std::runtime_error(msg.str())); + } + + //implicity create and retrieve the entity + BaseCharacter& character = characterMap[argPacket->characterIndex]; + + //fill the character's info + character.SetOrigin({0, 0}); + character.SetMotion({0, 0}); + character.SetBounds({CHARACTER_BOUNDS_X, CHARACTER_BOUNDS_Y, CHARACTER_BOUNDS_WIDTH, CHARACTER_BOUNDS_HEIGHT}); + character.SetHandle(argPacket->handle); + character.SetAvatar(argPacket->avatar); + + //debug + std::cout << "Create, total: " << characterMap.size() << std::endl; } void InWorld::HandleCharacterDelete(CharacterPacket* const argPacket) { @@ -407,7 +448,4 @@ void InWorld::HandleCharacterDelete(CharacterPacket* const argPacket) { void InWorld::HandleCharacterQueryExists(CharacterPacket* const argPacket) { //TODO: HandleCharacterQueryExists() std::cout << "HandleCharacterQueryExists" << std::endl; - //NOTE: preexisting characters will result in query responses - //NOTE: new characters will result in create messages - //NOTE: this client's character will exist in both } \ No newline at end of file diff --git a/client/scenes/in_world.hpp b/client/scenes/in_world.hpp index ccf1c42..65e3ae6 100644 --- a/client/scenes/in_world.hpp +++ b/client/scenes/in_world.hpp @@ -44,6 +44,8 @@ //client #include "base_scene.hpp" +#include "base_character.hpp" +#include "base_monster.hpp" //STL #include @@ -99,6 +101,7 @@ protected: //indexes int& clientIndex; int& accountIndex; + int characterIndex = -1; //graphics Image buttonImage; @@ -120,6 +123,9 @@ protected: int marginX = 0, marginY = 0; } camera; + //entities + std::map characterMap; + std::map monsterMap; //heartbeat //TODO: Heartbeat needs it's own utility diff --git a/common/gameplay/character_defines.hpp b/common/gameplay/character_defines.hpp index d5ca3b6..7b759d1 100644 --- a/common/gameplay/character_defines.hpp +++ b/common/gameplay/character_defines.hpp @@ -35,4 +35,8 @@ constexpr int CHARACTER_BOUNDS_Y = 16; constexpr int CHARACTER_BOUNDS_WIDTH = 32; constexpr int CHARACTER_BOUNDS_HEIGHT = 32; +//the character's sprite format +constexpr int CHARACTER_CELLS_X = 4; +constexpr int CHARACTER_CELLS_Y = 4; + #endif From 4d1bb17382a9ba0535e69ba1009106abccabcdae Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Thu, 18 Dec 2014 09:28:24 +1100 Subject: [PATCH 54/73] Comment tweaks --- server/server_application.hpp | 2 +- server/server_logic.cpp | 3 --- server/server_methods.cpp | 23 ----------------------- server/server_util.cpp | 6 +++--- 4 files changed, 4 insertions(+), 30 deletions(-) diff --git a/server/server_application.hpp b/server/server_application.hpp index b794b3f..bd01b5f 100644 --- a/server/server_application.hpp +++ b/server/server_application.hpp @@ -105,7 +105,7 @@ private: //utility methods void PumpPacket(SerialPacket* const); - void PumpPacketProximity(SerialPacket* const, int roomIndex, int x, int y, int radius); +// void PumpPacketProximity(SerialPacket* const, int roomIndex, int x, int y, int radius); void CopyCharacterToPacket(CharacterPacket* const packet, int characterIndex); //APIs and utilities diff --git a/server/server_logic.cpp b/server/server_logic.cpp index 1e1dbf1..0a76d59 100644 --- a/server/server_logic.cpp +++ b/server/server_logic.cpp @@ -298,9 +298,6 @@ void ServerApplication::HandlePacket(SerialPacket* const argPacket) { break; /* - case SerialPacketType::QUERY_CHARACTER_EXISTS: -// HandleCharacterStatsRequest(static_cast(argPacket)); - break; case SerialPacketType::QUERY_CHARACTER_STATS: // HandleCharacterStatsRequest(static_cast(argPacket)); break; diff --git a/server/server_methods.cpp b/server/server_methods.cpp index d163f18..d9e433f 100644 --- a/server/server_methods.cpp +++ b/server/server_methods.cpp @@ -79,26 +79,3 @@ void ServerApplication::HandleShutdownRequest(ClientPacket* const argPacket) { //finished this routine std::cout << "Shutdown signal accepted" << std::endl; } - -/* - -//SET: entities -void ServerApplication::HandleCharacterUpdate(CharacterPacket* const argPacket) { - CharacterData* character = characterMgr.Get(argPacket->characterIndex); - - //make a new character if this one doesn't exist - if (!character) { - HandleCharacterNew(argPacket); - return; - } - - //accept client-side logic - character->SetRoomIndex(argPacket->roomIndex); - character->SetOrigin(argPacket->origin); - character->SetMotion(argPacket->motion); - - //TODO: gameplay components: equipment, items, buffs, debuffs - - PumpPacket(argPacket); -} -*/ \ No newline at end of file diff --git a/server/server_util.cpp b/server/server_util.cpp index b0ef563..c5f1729 100644 --- a/server/server_util.cpp +++ b/server/server_util.cpp @@ -43,14 +43,14 @@ void ServerApplication::PumpPacket(SerialPacket* const argPacket) { } } -void ServerApplication::PumpPacketProximity(SerialPacket* const argPacket, int roomIndex, int x, int y, int radius) { +/*void ServerApplication::PumpPacketProximity(SerialPacket* const argPacket, int roomIndex, int x, int y, int radius) { //TODO: PumpPacketProximity //for position (roomIndex, x, y), find all characters within that distance //find that character's owner //find that account's client //send the packet to that client //NOTE: this is perhaps too complex; I write it if I need it -} +*/} //------------------------- //common copy methods @@ -70,4 +70,4 @@ void ServerApplication::CopyCharacterToPacket(CharacterPacket* const packet, int packet->roomIndex = character->GetRoomIndex(); packet->origin = character->GetOrigin(); packet->motion = character->GetMotion(); -} \ No newline at end of file +} From 7962692641f686b93a1b2ecaef50e48512a11919 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Fri, 19 Dec 2014 14:21:05 +1100 Subject: [PATCH 55/73] Implemented client-side character delete; untested --- client/scenes/in_world.cpp | 33 +++++++++++++++++++++++++-------- server/server_util.cpp | 2 +- 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/client/scenes/in_world.cpp b/client/scenes/in_world.cpp index 3cf019f..e7942e1 100644 --- a/client/scenes/in_world.cpp +++ b/client/scenes/in_world.cpp @@ -427,22 +427,39 @@ void InWorld::HandleCharacterCreate(CharacterPacket* const argPacket) { } //implicity create and retrieve the entity - BaseCharacter& character = characterMap[argPacket->characterIndex]; + BaseCharacter* character = &characterMap[argPacket->characterIndex]; //fill the character's info - character.SetOrigin({0, 0}); - character.SetMotion({0, 0}); - character.SetBounds({CHARACTER_BOUNDS_X, CHARACTER_BOUNDS_Y, CHARACTER_BOUNDS_WIDTH, CHARACTER_BOUNDS_HEIGHT}); - character.SetHandle(argPacket->handle); - character.SetAvatar(argPacket->avatar); + character->SetOrigin({0, 0}); + character->SetMotion({0, 0}); + character->SetBounds({CHARACTER_BOUNDS_X, CHARACTER_BOUNDS_Y, CHARACTER_BOUNDS_WIDTH, CHARACTER_BOUNDS_HEIGHT}); + character->SetHandle(argPacket->handle); + character->SetAvatar(argPacket->avatar); + + //TODO: check for this player's character + + //TODO: setup the camera //debug std::cout << "Create, total: " << characterMap.size() << std::endl; } void InWorld::HandleCharacterDelete(CharacterPacket* const argPacket) { - //TODO: HandleCharacterDelete() - std::cout << "HandleCharacterDelete" << std::endl; + //ignore if this character doesn't exist + std::map::iterator characterIt = characterMap.find(argPacket->characterIndex); + if (characterIt == characterMap.end()) { + //debug + std::cout << "Ignoring character deletion" << std::endl; + return; + } + + //TODO: check for this player's character + + //remove this character + characterMap.erase(characterIt); + + //debug + std::cout << "Delete, total: " << characterMap.size() << std::endl; } void InWorld::HandleCharacterQueryExists(CharacterPacket* const argPacket) { diff --git a/server/server_util.cpp b/server/server_util.cpp index c5f1729..24ed80f 100644 --- a/server/server_util.cpp +++ b/server/server_util.cpp @@ -50,7 +50,7 @@ void ServerApplication::PumpPacket(SerialPacket* const argPacket) { //find that account's client //send the packet to that client //NOTE: this is perhaps too complex; I write it if I need it -*/} +}*/ //------------------------- //common copy methods From 0d9dfad4a50f24d32f2cf81e7bdb2ef4ec315c3f Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Fri, 19 Dec 2014 15:52:05 +1100 Subject: [PATCH 56/73] Implemented 'full unload' methods, not used yet --- server/server_application.hpp | 3 ++ server/server_methods.cpp | 62 +++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) diff --git a/server/server_application.hpp b/server/server_application.hpp index bd01b5f..a47bef6 100644 --- a/server/server_application.hpp +++ b/server/server_application.hpp @@ -96,6 +96,9 @@ private: void HandleCharacterExists(CharacterPacket* const); void SaveServerState(); + void FullClientUnload(int index); + void FullAccountUnload(int index); + void FullCharacterUnload(int index); //character management void HandleCharacterCreate(CharacterPacket* const); diff --git a/server/server_methods.cpp b/server/server_methods.cpp index d9e433f..b3e77c6 100644 --- a/server/server_methods.cpp +++ b/server/server_methods.cpp @@ -79,3 +79,65 @@ void ServerApplication::HandleShutdownRequest(ClientPacket* const argPacket) { //finished this routine std::cout << "Shutdown signal accepted" << std::endl; } + +//------------------------- +//full unload methods +//------------------------- + +void ServerApplication::FullClientUnload(int index) { + clientMgr.UnloadIf([&](std::pair client) -> bool { + //skip the wrong clients + if (client.first != index) { + return false; + } + + //unload associated accounts + for (auto& it : *accountMgr.GetContainer()) { + if (it.second.GetClientIndex() == index) { + FullAccountUnload(it.first); + } + } + + //unload this client + return true; + }); +} + +void ServerApplication::FullAccountUnload(int index) { + accountMgr.UnloadIf([&](std::pair account) -> bool { + //skip the wrong accounts + if (account.first != index) { + return false; + } + + //unload associated characters + for (auto& it : *characterMgr.GetContainer()) { + if (it.second.GetOwner() == index) { + FullCharacterUnload(it.first); + } + } + + //unload this account + return true; + }); +} + +void ServerApplication::FullCharacterUnload(int index) { + characterMgr.UnloadIf([&](std::pair character) -> bool { + //skip the wrong characters + if (character.first != index) { + return false; + } + + //pump character unload + CharacterPacket newPacket; + newPacket.type = SerialPacketType::CHARACTER_DELETE; + newPacket.characterIndex = character.first; + //NOTE: more character info as needed + + PumpPacket(&newPacket); + + //unload this character + return true; + }); +} From 15ea360b8a131135288f8fc72655f3b6da1272b2 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Fri, 19 Dec 2014 17:58:50 +1100 Subject: [PATCH 57/73] Replaced lambda implementations with calls to the 'full unload' methods IT should be noted that ClientManager::CheckConnections() no longer removes a client; instead, it returns a client index that needs to be removed via another means. This allows ServerApplication to use the 'full unload' method. --- server/clients/client_manager.cpp | 2 +- server/server_connections.cpp | 35 ++++--------------------------- server/server_logic.cpp | 22 +------------------ 3 files changed, 6 insertions(+), 53 deletions(-) diff --git a/server/clients/client_manager.cpp b/server/clients/client_manager.cpp index d2ae9bf..86ccdb3 100644 --- a/server/clients/client_manager.cpp +++ b/server/clients/client_manager.cpp @@ -39,7 +39,7 @@ int ClientManager::CheckConnections() { for (auto& it : elementMap) { if (it.second.GetAttempts() > 2) { int ret = it.first; - elementMap.erase(it.first); +// elementMap.erase(it.first); return ret; } } diff --git a/server/server_connections.cpp b/server/server_connections.cpp index b9ca988..79d8c23 100644 --- a/server/server_connections.cpp +++ b/server/server_connections.cpp @@ -137,18 +137,8 @@ void ServerApplication::HandleLogoutRequest(ClientPacket* const argPacket) { network.SendTo(clientData->GetAddress(), static_cast(&newPacket)); - //save and unload this accounts characters - characterMgr.UnloadIf([&](std::pair it) -> bool { - if (argPacket->accountIndex == it.second.GetOwner()) { - //pump the unload message to all remaining clients - //TODO: pump character unload - return true; - } - return false; - }); - - //unload this account - accountMgr.Unload(argPacket->accountIndex); + //save and unload this account and it's characters + FullAccountUnload(argPacket->accountIndex); //finished this routine std::cout << "New logout, " << clientMgr.GetLoadedCount() << " clients and " << accountMgr.GetLoadedCount() << " accounts total" << std::endl; @@ -174,25 +164,8 @@ void ServerApplication::HandleDisconnectRequest(ClientPacket* const argPacket) { network.SendTo(clientData->GetAddress(), static_cast(&newPacket)); - //TODO: need a method for this redundunt chunk of redundant code - //find and unload the accounts associated with this client - accountMgr.UnloadIf([&](std::pair account) -> bool { - if (account.second.GetClientIndex() == argPacket->clientIndex) { - //find and unload the characters associated with this account - characterMgr.UnloadIf([&](std::pair character) -> bool { - if (character.second.GetOwner() == account.first) { - //TODO: pump character unload - return true; - } - return false; - }); - return true; - } - return false; - }); - - //unload this client - clientMgr.Unload(argPacket->clientIndex); + //unload the client, it's accounts, and their characters + FullClientUnload(argPacket->clientIndex); //finished this routine std::cout << "New disconnection, " << clientMgr.GetLoadedCount() << " clients and " << accountMgr.GetLoadedCount() << " accounts total" << std::endl; diff --git a/server/server_logic.cpp b/server/server_logic.cpp index 0a76d59..0b20037 100644 --- a/server/server_logic.cpp +++ b/server/server_logic.cpp @@ -182,27 +182,7 @@ void ServerApplication::Proc() { //Check connections int disconnected = clientMgr.CheckConnections(); if (disconnected != -1) { - //find and unload the accounts associated with this client - accountMgr.UnloadIf([&](std::pair account) -> bool { - if (account.second.GetClientIndex() == disconnected) { - //find and unload the characters associated with this account - characterMgr.UnloadIf([&](std::pair character) -> bool { - if (character.second.GetOwner() == account.first) { - //pump character delete - CharacterPacket newPacket; - newPacket.type = SerialPacketType::CHARACTER_DELETE; - newPacket.characterIndex = character.first; - PumpPacket(static_cast(&newPacket)); - - //unload this character - return true; - } - return false; - }); - return true; - } - return false; - }); + FullClientUnload(disconnected); } //give the computer a break From 07af05712b463c58bf3c3f41c259294369471104 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Fri, 19 Dec 2014 18:33:41 +1100 Subject: [PATCH 58/73] Implemented client-side query --- client/scenes/in_world.cpp | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/client/scenes/in_world.cpp b/client/scenes/in_world.cpp index e7942e1..bb2c440 100644 --- a/client/scenes/in_world.cpp +++ b/client/scenes/in_world.cpp @@ -430,8 +430,8 @@ void InWorld::HandleCharacterCreate(CharacterPacket* const argPacket) { BaseCharacter* character = &characterMap[argPacket->characterIndex]; //fill the character's info - character->SetOrigin({0, 0}); - character->SetMotion({0, 0}); + character->SetOrigin(argPacket->origin); + character->SetMotion(argPacket->motion); character->SetBounds({CHARACTER_BOUNDS_X, CHARACTER_BOUNDS_Y, CHARACTER_BOUNDS_WIDTH, CHARACTER_BOUNDS_HEIGHT}); character->SetHandle(argPacket->handle); character->SetAvatar(argPacket->avatar); @@ -463,6 +463,16 @@ void InWorld::HandleCharacterDelete(CharacterPacket* const argPacket) { } void InWorld::HandleCharacterQueryExists(CharacterPacket* const argPacket) { - //TODO: HandleCharacterQueryExists() - std::cout << "HandleCharacterQueryExists" << std::endl; + //implicitly construct the character if it doesn't exist + BaseCharacter* character = &characterMap[argPacket->characterIndex]; + + //set/update the character's info + character->SetOrigin(argPacket->origin); + character->SetMotion(argPacket->motion); + character->SetBounds({CHARACTER_BOUNDS_X, CHARACTER_BOUNDS_Y, CHARACTER_BOUNDS_WIDTH, CHARACTER_BOUNDS_HEIGHT}); + character->SetHandle(argPacket->handle); + character->SetAvatar(argPacket->avatar); + + //debug + std::cout << "Query, total: " << characterMap.size() << std::endl; } \ No newline at end of file From 2ae2c488198fc2cc04725db8ab38d61745c5f8c6 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Fri, 19 Dec 2014 19:44:34 +1100 Subject: [PATCH 59/73] Added LocalCharacter, removed entityIndex --- client/entities/base_character.hpp | 2 +- client/entities/base_monster.hpp | 2 +- client/entities/entity.cpp | 8 ----- client/entities/entity.hpp | 3 -- client/entities/local_character.cpp | 23 ++++++++++++++ client/entities/local_character.hpp | 34 +++++++++++++++++++++ client/scenes/in_world.cpp | 47 ++++++++++++++++++++++++++--- client/scenes/in_world.hpp | 6 ++-- server/entities/entity.cpp | 7 ----- server/entities/entity.hpp | 3 -- 10 files changed, 104 insertions(+), 31 deletions(-) create mode 100644 client/entities/local_character.cpp create mode 100644 client/entities/local_character.hpp diff --git a/client/entities/base_character.hpp b/client/entities/base_character.hpp index c3d1b1e..ba699d9 100644 --- a/client/entities/base_character.hpp +++ b/client/entities/base_character.hpp @@ -45,7 +45,7 @@ public: std::string SetAvatar(std::string s); std::string GetAvatar() const; -private: +protected: //metadata int owner; std::string handle; diff --git a/client/entities/base_monster.hpp b/client/entities/base_monster.hpp index d7d1b6b..6fd91e9 100644 --- a/client/entities/base_monster.hpp +++ b/client/entities/base_monster.hpp @@ -29,7 +29,7 @@ public: BaseMonster() = default; virtual ~BaseMonster() = default; -private: +protected: // }; diff --git a/client/entities/entity.cpp b/client/entities/entity.cpp index 98b9483..34cc6cf 100644 --- a/client/entities/entity.cpp +++ b/client/entities/entity.cpp @@ -38,10 +38,6 @@ SpriteSheet* Entity::GetSprite() { //accessors & mutators //------------------------- -int Entity::SetEntityIndex(int i) { - return entityIndex = i; -} - Vector2 Entity::SetOrigin(Vector2 v) { return origin = v; } @@ -54,10 +50,6 @@ BoundingBox Entity::SetBounds(BoundingBox b) { return bounds = b; } -int Entity::GetEntityIndex() { - return entityIndex; -} - Vector2 Entity::GetOrigin() { return origin; } diff --git a/client/entities/entity.hpp b/client/entities/entity.hpp index c12fb71..a40f94f 100644 --- a/client/entities/entity.hpp +++ b/client/entities/entity.hpp @@ -35,12 +35,10 @@ public: SpriteSheet* GetSprite(); //accessors & mutators - int SetEntityIndex(int i); Vector2 SetOrigin(Vector2 v); Vector2 SetMotion(Vector2 v); BoundingBox SetBounds(BoundingBox b); - int GetEntityIndex(); Vector2 GetOrigin(); Vector2 GetMotion(); BoundingBox GetBounds(); @@ -50,7 +48,6 @@ protected: virtual ~Entity() = default; SpriteSheet sprite; - int entityIndex = -1; Vector2 origin; Vector2 motion; BoundingBox bounds; diff --git a/client/entities/local_character.cpp b/client/entities/local_character.cpp new file mode 100644 index 0000000..211a6bc --- /dev/null +++ b/client/entities/local_character.cpp @@ -0,0 +1,23 @@ +/* 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 "local_character.hpp" + diff --git a/client/entities/local_character.hpp b/client/entities/local_character.hpp new file mode 100644 index 0000000..bef4edc --- /dev/null +++ b/client/entities/local_character.hpp @@ -0,0 +1,34 @@ +/* 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 LOCALCHARACTER_HPP_ +#define LOCALCHARACTER_HPP_ + +#include "base_character.hpp" + +class LocalCharacter: public BaseCharacter { +public: + // +private: + //NOTE: NO MEMBERS +}; + +#endif \ No newline at end of file diff --git a/client/scenes/in_world.cpp b/client/scenes/in_world.cpp index bb2c440..6e2aa76 100644 --- a/client/scenes/in_world.cpp +++ b/client/scenes/in_world.cpp @@ -91,6 +91,10 @@ InWorld::InWorld(int* const argClientIndex, int* const argAccountIndex): newPacket.type = SerialPacketType::QUERY_CHARACTER_EXISTS; network.SendTo(Channels::SERVER, &newPacket); + //set the camera's values + camera.width = GetScreen()->w; + camera.height = GetScreen()->h; + //debug // } @@ -133,6 +137,14 @@ void InWorld::Update() { //update the map UpdateMap(); + //update all entities + for (auto& it : characterMap) { + it.second.Update(); + } + for (auto& it : monsterMap) { + it.second.Update(); + } + //check the connection (heartbeat) if (Clock::now() - lastBeat > std::chrono::seconds(3)) { if (attemptedBeats > 2) { @@ -342,6 +354,10 @@ void InWorld::HandleLogoutResponse(ClientPacket* const argPacket) { accountIndex = -1; characterIndex = -1; + //reset the camera + camera.x = camera .y = 0; + camera.marginX = camera.marginY = 0; + SendDisconnectRequest(); } @@ -355,6 +371,10 @@ void InWorld::HandleDisconnectForced(ClientPacket* const argPacket) { accountIndex = -1; characterIndex = -1; + //reset the camera + camera.x = camera .y = 0; + camera.marginX = camera.marginY = 0; + SetNextScene(SceneList::DISCONNECTEDSCREEN); ConfigUtility::GetSingleton()["client.disconnectMessage"] = "You have been forcibly disconnected by the server"; } @@ -414,7 +434,7 @@ void InWorld::UpdateMap() { //NOTE: preexisting characters will result in query responses //NOTE: new characters will result in create messages -//NOTE: this client's character will exist in both +//NOTE: this client's character will exist in both (skipped) void InWorld::HandleCharacterCreate(CharacterPacket* const argPacket) { //prevent double message @@ -435,10 +455,16 @@ void InWorld::HandleCharacterCreate(CharacterPacket* const argPacket) { character->SetBounds({CHARACTER_BOUNDS_X, CHARACTER_BOUNDS_Y, CHARACTER_BOUNDS_WIDTH, CHARACTER_BOUNDS_HEIGHT}); character->SetHandle(argPacket->handle); character->SetAvatar(argPacket->avatar); + character->SetOwner(argPacket->accountIndex); - //TODO: check for this player's character + //check for this player's character + if (character->GetOwner() == accountIndex) { + localCharacter = static_cast(character); - //TODO: setup the camera + //focus the camera on this character + camera.marginX = (camera.width / 2 - localCharacter->GetSprite()->GetImage()->GetClipW() / 2); + camera.marginY = (camera.height/ 2 - localCharacter->GetSprite()->GetImage()->GetClipH() / 2); + } //debug std::cout << "Create, total: " << characterMap.size() << std::endl; @@ -453,7 +479,14 @@ void InWorld::HandleCharacterDelete(CharacterPacket* const argPacket) { return; } - //TODO: check for this player's character + //check for this player's character + if ((*characterIt).second.GetOwner() == accountIndex) { + localCharacter = nullptr; + + //clear the camera + camera.marginX = 0; + camera.marginY = 0; + } //remove this character characterMap.erase(characterIt); @@ -463,6 +496,11 @@ void InWorld::HandleCharacterDelete(CharacterPacket* const argPacket) { } void InWorld::HandleCharacterQueryExists(CharacterPacket* const argPacket) { + //prevent a double message about this player's character + if (argPacket->accountIndex == accountIndex) { + return; + } + //implicitly construct the character if it doesn't exist BaseCharacter* character = &characterMap[argPacket->characterIndex]; @@ -472,6 +510,7 @@ void InWorld::HandleCharacterQueryExists(CharacterPacket* const argPacket) { character->SetBounds({CHARACTER_BOUNDS_X, CHARACTER_BOUNDS_Y, CHARACTER_BOUNDS_WIDTH, CHARACTER_BOUNDS_HEIGHT}); character->SetHandle(argPacket->handle); character->SetAvatar(argPacket->avatar); + character->SetOwner(argPacket->accountIndex); //debug std::cout << "Query, total: " << characterMap.size() << std::endl; diff --git a/client/scenes/in_world.hpp b/client/scenes/in_world.hpp index 65e3ae6..2348cf9 100644 --- a/client/scenes/in_world.hpp +++ b/client/scenes/in_world.hpp @@ -39,13 +39,10 @@ //common #include "frame_rate.hpp" -#include "base_character.hpp" -#include "base_monster.hpp" - //client #include "base_scene.hpp" -#include "base_character.hpp" #include "base_monster.hpp" +#include "local_character.hpp" //STL #include @@ -126,6 +123,7 @@ protected: //entities std::map characterMap; std::map monsterMap; + LocalCharacter* localCharacter = nullptr; //heartbeat //TODO: Heartbeat needs it's own utility diff --git a/server/entities/entity.cpp b/server/entities/entity.cpp index d22a5d3..ebada62 100644 --- a/server/entities/entity.cpp +++ b/server/entities/entity.cpp @@ -21,10 +21,6 @@ */ #include "entity.hpp" -int Entity::SetEntityIndex(int i) { - return entityIndex = i; -} - int Entity::SetRoomIndex(int i) { return roomIndex = i; } @@ -36,9 +32,6 @@ Vector2 Entity::SetOrigin(Vector2 v) { Vector2 Entity::SetMotion(Vector2 v) { return motion = v; } -int Entity::GetEntityIndex() { - return entityIndex; -} int Entity::GetRoomIndex() { return roomIndex; diff --git a/server/entities/entity.hpp b/server/entities/entity.hpp index 8933c38..bad1627 100644 --- a/server/entities/entity.hpp +++ b/server/entities/entity.hpp @@ -28,12 +28,10 @@ class Entity { public: //accessors & mutators - int SetEntityIndex(int i); int SetRoomIndex(int i); Vector2 SetOrigin(Vector2 v); Vector2 SetMotion(Vector2 v); - int GetEntityIndex(); int GetRoomIndex(); Vector2 GetOrigin(); Vector2 GetMotion(); @@ -42,7 +40,6 @@ protected: Entity() = default; ~Entity() = default; - int entityIndex = -1; int roomIndex = -1; Vector2 origin; Vector2 motion; From 44a1edac30cd30fb6b127190adf6a45800d7ab00 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Fri, 19 Dec 2014 20:11:22 +1100 Subject: [PATCH 60/73] HOTFIX: Patched the stupid auto& for loop with the jenky pattern --- server/server_methods.cpp | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/server/server_methods.cpp b/server/server_methods.cpp index b3e77c6..b6287c2 100644 --- a/server/server_methods.cpp +++ b/server/server_methods.cpp @@ -92,9 +92,13 @@ void ServerApplication::FullClientUnload(int index) { } //unload associated accounts - for (auto& it : *accountMgr.GetContainer()) { - if (it.second.GetClientIndex() == index) { - FullAccountUnload(it.first); + for (std::map::iterator it = accountMgr.GetContainer()->begin(); it != accountMgr.GetContainer()->end(); /* EMPTY */) { + if (it->second.GetClientIndex() == index) { + FullAccountUnload(it->first); + it = accountMgr.GetContainer()->begin(); + } + else { + ++it; } } @@ -111,9 +115,13 @@ void ServerApplication::FullAccountUnload(int index) { } //unload associated characters - for (auto& it : *characterMgr.GetContainer()) { - if (it.second.GetOwner() == index) { - FullCharacterUnload(it.first); + for (std::map::iterator it = characterMgr.GetContainer()->begin(); it != characterMgr.GetContainer()->end(); /* EMPTY */) { + if (it->second.GetOwner() == index) { + FullCharacterUnload(it->first); + it = characterMgr.GetContainer()->begin(); + } + else { + ++it; } } From 900f623f3be0ef9896f8bb9723c2b20c3b40540d Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Fri, 19 Dec 2014 20:33:09 +1100 Subject: [PATCH 61/73] Camera centering and client drop message --- client/entities/local_character.hpp | 4 +++- client/scenes/in_world.cpp | 8 +++++++- server/server_logic.cpp | 1 + 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/client/entities/local_character.hpp b/client/entities/local_character.hpp index bef4edc..3cbff5f 100644 --- a/client/entities/local_character.hpp +++ b/client/entities/local_character.hpp @@ -26,7 +26,9 @@ class LocalCharacter: public BaseCharacter { public: - // + LocalCharacter() = default; + virtual ~LocalCharacter() = default; + private: //NOTE: NO MEMBERS }; diff --git a/client/scenes/in_world.cpp b/client/scenes/in_world.cpp index 6e2aa76..30a2e2b 100644 --- a/client/scenes/in_world.cpp +++ b/client/scenes/in_world.cpp @@ -145,6 +145,12 @@ void InWorld::Update() { it.second.Update(); } + //update the camera + if (localCharacter) { + camera.x = localCharacter->GetOrigin().x - camera.marginX; + camera.y = localCharacter->GetOrigin().y - camera.marginY; + } + //check the connection (heartbeat) if (Clock::now() - lastBeat > std::chrono::seconds(3)) { if (attemptedBeats > 2) { @@ -355,7 +361,7 @@ void InWorld::HandleLogoutResponse(ClientPacket* const argPacket) { characterIndex = -1; //reset the camera - camera.x = camera .y = 0; + camera.x = camera.y = 0; camera.marginX = camera.marginY = 0; SendDisconnectRequest(); diff --git a/server/server_logic.cpp b/server/server_logic.cpp index 0b20037..5408e94 100644 --- a/server/server_logic.cpp +++ b/server/server_logic.cpp @@ -183,6 +183,7 @@ void ServerApplication::Proc() { int disconnected = clientMgr.CheckConnections(); if (disconnected != -1) { FullClientUnload(disconnected); + std::cerr << "Client dropped: " << disconnected << std::endl; } //give the computer a break From dff04b5b690137a94bd23d773eaba9eced7241a1 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Sun, 21 Dec 2014 08:07:55 +1100 Subject: [PATCH 62/73] Moved server_util.cpp methods; created server_character_methods.cpp --- server/server_application.hpp | 6 +- server/server_character_methods.cpp | 176 ++++++++++++++++++++++++++++ server/server_data.cpp | 135 --------------------- server/server_logic.cpp | 25 ++-- server/server_methods.cpp | 38 ++++++ server/server_util.cpp | 73 ------------ 6 files changed, 231 insertions(+), 222 deletions(-) create mode 100644 server/server_character_methods.cpp delete mode 100644 server/server_util.cpp diff --git a/server/server_application.hpp b/server/server_application.hpp index a47bef6..eff3bef 100644 --- a/server/server_application.hpp +++ b/server/server_application.hpp @@ -106,9 +106,13 @@ private: void HandleCharacterLoad(CharacterPacket* const); void HandleCharacterUnload(CharacterPacket* const); + //character movement + void HandleCharacterSetRoom(CharacterPacket* const); + void HandleCharacterSetOrigin(CharacterPacket* const); + void HandleCharacterSetMotion(CharacterPacket* const); + //utility methods void PumpPacket(SerialPacket* const); -// void PumpPacketProximity(SerialPacket* const, int roomIndex, int x, int y, int radius); void CopyCharacterToPacket(CharacterPacket* const packet, int characterIndex); //APIs and utilities diff --git a/server/server_character_methods.cpp b/server/server_character_methods.cpp new file mode 100644 index 0000000..a379289 --- /dev/null +++ b/server/server_character_methods.cpp @@ -0,0 +1,176 @@ +/* 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 +#include + +//------------------------- +//Character Management +//------------------------- + +void ServerApplication::HandleCharacterCreate(CharacterPacket* const argPacket) { + int characterIndex = characterMgr.Create(argPacket->accountIndex, argPacket->handle, argPacket->avatar); + + if (characterIndex < 0) { + //build the error message + std::ostringstream msg; + msg << "Character already exists: " << argPacket->handle; + + //build & send the packet + TextPacket newPacket; + newPacket.type = SerialPacketType::CHARACTER_REJECTION; + strncpy(newPacket.text, msg.str().c_str(), PACKET_STRING_SIZE); + network.SendTo(argPacket->srcAddress, static_cast(&newPacket)); + + return; + } + + //pump this character to all clients + CharacterPacket newPacket; + CopyCharacterToPacket(&newPacket, characterIndex); + newPacket.type = SerialPacketType::CHARACTER_CREATE; + PumpPacket(&newPacket); +} + +void ServerApplication::HandleCharacterDelete(CharacterPacket* const argPacket) { + //get the user's data + AccountData* accountData = accountMgr.Get(argPacket->accountIndex); + if (!accountData) { + return; + } + ClientData* clientData = clientMgr.Get(accountData->GetClientIndex()); + if (!clientData) { + return; + } + + //check for fraud + if (clientData->GetAddress() != argPacket->srcAddress) { + std::cerr << "Falsified character deletion detected targeting: " << argPacket->handle << std::endl; + return; + } + + //load the character into memory + int characterIndex = characterMgr.Load(argPacket->accountIndex, argPacket->handle, argPacket->avatar); + + if (characterIndex < 0) { + //build the error message + std::ostringstream msg; + msg << "Cannot delete this character"; + + //build & send the packet + TextPacket newPacket; + newPacket.type = SerialPacketType::CHARACTER_REJECTION; + strncpy(newPacket.text, msg.str().c_str(), PACKET_STRING_SIZE); + network.SendTo(argPacket->srcAddress, static_cast(&newPacket)); + + return; + } + + //delete the character + characterMgr.Delete(characterIndex); + + //pump character delete + CharacterPacket newPacket; + newPacket.type = SerialPacketType::CHARACTER_DELETE; + newPacket.characterIndex = characterIndex; + PumpPacket(static_cast(&newPacket)); +} + +void ServerApplication::HandleCharacterLoad(CharacterPacket* const argPacket) { + int characterIndex = characterMgr.Load(argPacket->accountIndex, argPacket->handle, argPacket->avatar); + + if (characterIndex < 0) { + //build the error message + std::ostringstream msg; + if (characterIndex == -1) { + msg << "Character already loaded: "; + } + if (characterIndex == -1) { + msg << "Character name is taken: "; + } + msg << argPacket->handle; + + //build & send the packet + TextPacket newPacket; + newPacket.type = SerialPacketType::CHARACTER_REJECTION; + strncpy(newPacket.text, msg.str().c_str(), PACKET_STRING_SIZE); + network.SendTo(argPacket->srcAddress, static_cast(&newPacket)); + + return; + } + + //pump this character to all clients + CharacterPacket newPacket; + CopyCharacterToPacket(&newPacket, characterIndex); + newPacket.type = SerialPacketType::CHARACTER_CREATE; + PumpPacket(&newPacket); +} + +void ServerApplication::HandleCharacterUnload(CharacterPacket* const argPacket) { + //get the entries + CharacterData* characterData = characterMgr.Get(argPacket->characterIndex); + if (!characterData) { + return; + } + + AccountData* accountData = accountMgr.Get(characterData->GetOwner()); + if (!accountData) { + return; //TODO: logic_error + } + + ClientData* clientData = clientMgr.Get(accountData->GetClientIndex()); + if (!clientData) { + return; //TODO: logic_error + } + + //check for fraud + if (clientData->GetAddress() != argPacket->srcAddress) { + std::cerr << "Falsified character unload detected targeting: uid(" << argPacket->characterIndex << ")" << std::endl; + return; + } + + //unload the character + characterMgr.Unload(argPacket->characterIndex); + + //pump character delete + CharacterPacket newPacket; + newPacket.type = SerialPacketType::CHARACTER_DELETE; + newPacket.characterIndex = argPacket->characterIndex; + PumpPacket(static_cast(&newPacket)); +} + +//------------------------- +//character movement +//------------------------- + +void ServerApplication::HandleCharacterSetRoom(CharacterPacket* const argPacket) { + //TODO +} + +void ServerApplication::HandleCharacterSetOrigin(CharacterPacket* const argPacket) { + //TODO +} + +void ServerApplication::HandleCharacterSetMotion(CharacterPacket* const argPacket) { + //TODO +} diff --git a/server/server_data.cpp b/server/server_data.cpp index 76b1573..4eadeba 100644 --- a/server/server_data.cpp +++ b/server/server_data.cpp @@ -80,138 +80,3 @@ void ServerApplication::HandleCharacterExists(CharacterPacket* const argPacket) network.SendTo(argPacket->srcAddress, static_cast(&newPacket)); } } - -//------------------------- -//Character Management -//------------------------- - -void ServerApplication::HandleCharacterCreate(CharacterPacket* const argPacket) { - int characterIndex = characterMgr.Create(argPacket->accountIndex, argPacket->handle, argPacket->avatar); - - if (characterIndex < 0) { - //build the error message - std::ostringstream msg; - msg << "Character already exists: " << argPacket->handle; - - //build & send the packet - TextPacket newPacket; - newPacket.type = SerialPacketType::CHARACTER_REJECTION; - strncpy(newPacket.text, msg.str().c_str(), PACKET_STRING_SIZE); - network.SendTo(argPacket->srcAddress, static_cast(&newPacket)); - - return; - } - - //pump this character to all clients - CharacterPacket newPacket; - CopyCharacterToPacket(&newPacket, characterIndex); - newPacket.type = SerialPacketType::CHARACTER_CREATE; - PumpPacket(&newPacket); -} - -void ServerApplication::HandleCharacterDelete(CharacterPacket* const argPacket) { - //get the user's data - AccountData* accountData = accountMgr.Get(argPacket->accountIndex); - if (!accountData) { - return; - } - ClientData* clientData = clientMgr.Get(accountData->GetClientIndex()); - if (!clientData) { - return; - } - - //check for fraud - if (clientData->GetAddress() != argPacket->srcAddress) { - std::cerr << "Falsified character deletion detected targeting: " << argPacket->handle << std::endl; - return; - } - - //load the character into memory - int characterIndex = characterMgr.Load(argPacket->accountIndex, argPacket->handle, argPacket->avatar); - - if (characterIndex < 0) { - //build the error message - std::ostringstream msg; - msg << "Cannot delete this character"; - - //build & send the packet - TextPacket newPacket; - newPacket.type = SerialPacketType::CHARACTER_REJECTION; - strncpy(newPacket.text, msg.str().c_str(), PACKET_STRING_SIZE); - network.SendTo(argPacket->srcAddress, static_cast(&newPacket)); - - return; - } - - //delete the character - characterMgr.Delete(characterIndex); - - //pump character delete - CharacterPacket newPacket; - newPacket.type = SerialPacketType::CHARACTER_DELETE; - newPacket.characterIndex = characterIndex; - PumpPacket(static_cast(&newPacket)); -} - -void ServerApplication::HandleCharacterLoad(CharacterPacket* const argPacket) { - int characterIndex = characterMgr.Load(argPacket->accountIndex, argPacket->handle, argPacket->avatar); - - if (characterIndex < 0) { - //build the error message - std::ostringstream msg; - if (characterIndex == -1) { - msg << "Character already loaded: "; - } - if (characterIndex == -1) { - msg << "Character name is taken: "; - } - msg << argPacket->handle; - - //build & send the packet - TextPacket newPacket; - newPacket.type = SerialPacketType::CHARACTER_REJECTION; - strncpy(newPacket.text, msg.str().c_str(), PACKET_STRING_SIZE); - network.SendTo(argPacket->srcAddress, static_cast(&newPacket)); - - return; - } - - //pump this character to all clients - CharacterPacket newPacket; - CopyCharacterToPacket(&newPacket, characterIndex); - newPacket.type = SerialPacketType::CHARACTER_CREATE; - PumpPacket(&newPacket); -} - -void ServerApplication::HandleCharacterUnload(CharacterPacket* const argPacket) { - //get the entries - CharacterData* characterData = characterMgr.Get(argPacket->characterIndex); - if (!characterData) { - return; - } - - AccountData* accountData = accountMgr.Get(characterData->GetOwner()); - if (!accountData) { - return; //TODO: logic_error - } - - ClientData* clientData = clientMgr.Get(accountData->GetClientIndex()); - if (!clientData) { - return; //TODO: logic_error - } - - //check for fraud - if (clientData->GetAddress() != argPacket->srcAddress) { - std::cerr << "Falsified character unload detected targeting: uid(" << argPacket->characterIndex << ")" << std::endl; - return; - } - - //unload the character - characterMgr.Unload(argPacket->characterIndex); - - //pump character delete - CharacterPacket newPacket; - newPacket.type = SerialPacketType::CHARACTER_DELETE; - newPacket.characterIndex = argPacket->characterIndex; - PumpPacket(static_cast(&newPacket)); -} \ No newline at end of file diff --git a/server/server_logic.cpp b/server/server_logic.cpp index 5408e94..fdf4eb9 100644 --- a/server/server_logic.cpp +++ b/server/server_logic.cpp @@ -249,9 +249,9 @@ void ServerApplication::HandlePacket(SerialPacket* const argPacket) { break; //server commands - case SerialPacketType::DISCONNECT_FORCED: +// case SerialPacketType::DISCONNECT_FORCED: // HandleDisconnectForced(static_cast(argPacket)); - break; +// break; case SerialPacketType::SHUTDOWN_REQUEST: HandleShutdownRequest(static_cast(argPacket)); break; @@ -278,6 +278,16 @@ void ServerApplication::HandlePacket(SerialPacket* const argPacket) { HandleCharacterUnload(static_cast(argPacket)); break; + //character movement + case SerialPacketType::CHARACTER_SET_ROOM: + HandleCharacterSetRoom(static_cast(argPacket)); + break; + case SerialPacketType::CHARACTER_SET_ORIGIN: + HandleCharacterSetOrigin(static_cast(argPacket)); + break; + case SerialPacketType::CHARACTER_SET_MOTION: + HandleCharacterSetMotion(static_cast(argPacket)); + break; /* case SerialPacketType::QUERY_CHARACTER_STATS: // HandleCharacterStatsRequest(static_cast(argPacket)); @@ -289,17 +299,6 @@ void ServerApplication::HandlePacket(SerialPacket* const argPacket) { // HandleCharacterStatsRequest(static_cast(argPacket)); break; - //character movement - case SerialPacketType::CHARACTER_SET_ROOM: -// HandleCharacterUpdate(static_cast(argPacket)); - break; - case SerialPacketType::CHARACTER_SET_ORIGIN: -// HandleCharacterUpdate(static_cast(argPacket)); - break; - case SerialPacketType::CHARACTER_SET_MOTION: -// HandleCharacterUpdate(static_cast(argPacket)); - break; - //enemy management //TODO: enemy management diff --git a/server/server_methods.cpp b/server/server_methods.cpp index b6287c2..d38b53c 100644 --- a/server/server_methods.cpp +++ b/server/server_methods.cpp @@ -25,6 +25,18 @@ #include #include +//------------------------- +//these should've come standard +//------------------------- + +bool operator==(IPaddress lhs, IPaddress rhs) { + return lhs.host == rhs.host && lhs.port == rhs.port; +} + +bool operator!=(IPaddress lhs, IPaddress rhs) { + return !(lhs == rhs); +} + //------------------------- //server commands //------------------------- @@ -149,3 +161,29 @@ void ServerApplication::FullCharacterUnload(int index) { return true; }); } + +//------------------------- +//utility methods +//------------------------- + +void ServerApplication::PumpPacket(SerialPacket* const argPacket) { + for (auto& it : *clientMgr.GetContainer()) { + network.SendTo(it.second.GetAddress(), argPacket); + } +} + +void ServerApplication::CopyCharacterToPacket(CharacterPacket* const packet, int characterIndex) { + CharacterData* character = characterMgr.Get(characterIndex); + if (!character) { + throw(std::runtime_error("Failed to copy a character to a packet")); + } + + //NOTE: keep this up to date when the character changes + packet->characterIndex = characterIndex; + strncpy(packet->handle, character->GetHandle().c_str(), PACKET_STRING_SIZE); + strncpy(packet->avatar, character->GetAvatar().c_str(), PACKET_STRING_SIZE); + packet->accountIndex = character->GetOwner(); + packet->roomIndex = character->GetRoomIndex(); + packet->origin = character->GetOrigin(); + packet->motion = character->GetMotion(); +} diff --git a/server/server_util.cpp b/server/server_util.cpp deleted file mode 100644 index 24ed80f..0000000 --- a/server/server_util.cpp +++ /dev/null @@ -1,73 +0,0 @@ -/* 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" - -//------------------------- -//these should've come standard -//------------------------- - -bool operator==(IPaddress lhs, IPaddress rhs) { - return lhs.host == rhs.host && lhs.port == rhs.port; -} - -bool operator!=(IPaddress lhs, IPaddress rhs) { - return !(lhs == rhs); -} - -//------------------------- -//Packet pumps -//------------------------- - -void ServerApplication::PumpPacket(SerialPacket* const argPacket) { - for (auto& it : *clientMgr.GetContainer()) { - network.SendTo(it.second.GetAddress(), argPacket); - } -} - -/*void ServerApplication::PumpPacketProximity(SerialPacket* const argPacket, int roomIndex, int x, int y, int radius) { - //TODO: PumpPacketProximity - //for position (roomIndex, x, y), find all characters within that distance - //find that character's owner - //find that account's client - //send the packet to that client - //NOTE: this is perhaps too complex; I write it if I need it -}*/ - -//------------------------- -//common copy methods -//------------------------- - -void ServerApplication::CopyCharacterToPacket(CharacterPacket* const packet, int characterIndex) { - CharacterData* character = characterMgr.Get(characterIndex); - if (!character) { - throw(std::runtime_error("Failed to copy a character to a packet")); - } - - //NOTE: keep this up to date when the character changes - packet->characterIndex = characterIndex; - strncpy(packet->handle, character->GetHandle().c_str(), PACKET_STRING_SIZE); - strncpy(packet->avatar, character->GetAvatar().c_str(), PACKET_STRING_SIZE); - packet->accountIndex = character->GetOwner(); - packet->roomIndex = character->GetRoomIndex(); - packet->origin = character->GetOrigin(); - packet->motion = character->GetMotion(); -} From f52eafdf5564b71e13cf59e16af0a52efa79abd7 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Mon, 22 Dec 2014 22:08:22 +1100 Subject: [PATCH 63/73] Implemented server-side HandleSetCharacter*(); untested --- server/server_character_methods.cpp | 106 +++++++++++++++++++++++++++- 1 file changed, 103 insertions(+), 3 deletions(-) diff --git a/server/server_character_methods.cpp b/server/server_character_methods.cpp index a379289..8f4a22b 100644 --- a/server/server_character_methods.cpp +++ b/server/server_character_methods.cpp @@ -163,14 +163,114 @@ void ServerApplication::HandleCharacterUnload(CharacterPacket* const argPacket) //character movement //------------------------- +//TODO: ? Could replace this verbosity with a "verify" method, taking a client, account and character ptr as arguments + void ServerApplication::HandleCharacterSetRoom(CharacterPacket* const argPacket) { - //TODO + //get the specified objects + AccountData* accountData = accountMgr.Get(argPacket->accountIndex); + CharacterData* characterData = characterMgr.Get(argPacket->characterIndex); + + if (!accountData || !characterData) { + throw(std::runtime_error("Failed to set character room, missing data")); + } + + //get this account's client + ClientData* clientData = clientMgr.Get(accountData->GetClientIndex()); + + //check for fraud + if (clientData->GetAddress() != argPacket->srcAddress) { + std::cerr << "Falsified set character origin targeting uid(" << argPacket->characterIndex << ")" << std::endl; + return; + } + + //check if allowed + if (characterData->GetOwner() != argPacket->accountIndex && !accountData->GetModerator() && !accountData->GetAdministrator()) { + //TODO: send to the client? + std::cerr << "Failed to set character room due to lack of permissions targeting uid(" << argPacket->characterIndex << ")" << std::endl; + return; + } + + //set the character's room, zero it's origin, zero it's motion + //TODO: Set the origin here + characterData->SetRoom(argPacket->roomIndex); + characterData->SetOrigin({0, 0}); + characterData->SetMotion({0, 0}); + + //update the clients + CharacterPacket newPacket; + CopyCharacterToPacket(&newPacket, argPacket->characterIndex); + newPacket.type = SerialPacketType::CHARACTER_SET_ROOM; + PumpPacket(&newPacket); } void ServerApplication::HandleCharacterSetOrigin(CharacterPacket* const argPacket) { - //TODO + //get the specified objects + AccountData* accountData = accountMgr.Get(argPacket->accountIndex); + CharacterData* characterData = characterMgr.Get(argPacket->characterIndex); + + if (!accountData || !characterData) { + throw(std::runtime_error("Failed to set character origin, missing data")); + } + + //get this account's client + ClientData* clientData = clientMgr.Get(accountData->GetClientIndex()); + + //check for fraud + if (clientData->GetAddress() != argPacket->srcAddress) { + std::cerr << "Falsified set character origin targeting uid(" << argPacket->characterIndex << ")" << std::endl; + return; + } + + //check if allowed + if (characterData->GetOwner() != argPacket->accountIndex && !accountData->GetModerator() && !accountData->GetAdministrator()) { + //TODO: send to the client? + std::cerr << "Failed to set character origin due to lack of permissions targeting uid(" << argPacket->characterIndex << ")" << std::endl; + return; + } + + //set the character's origin, zero it's motion + characterData->SetOrigin(argPacket->origin); + characterData->SetMotion({0, 0}); + + //update the clients + CharacterPacket newPacket; + CopyCharacterToPacket(&newPacket, argPacket->characterIndex); + newPacket.type = SerialPacketType::CHARACTER_SET_ORIGIN; + PumpPacket(&newPacket); } void ServerApplication::HandleCharacterSetMotion(CharacterPacket* const argPacket) { - //TODO + //get the specified objects + AccountData* accountData = accountMgr.Get(argPacket->accountIndex); + CharacterData* characterData = characterMgr.Get(argPacket->characterIndex); + + if (!accountData || !characterData) { + throw(std::runtime_error("Failed to set character motion, missing data")); + } + + //get this account's client + ClientData* clientData = clientMgr.Get(accountData->GetClientIndex()); + + //check for fraud + if (clientData->GetAddress() != argPacket->srcAddress) { + std::cerr << "Falsified set character motion targeting uid(" << argPacket->characterIndex << ")" << std::endl; + return; + } + + //check if allowed + if (characterData->GetOwner() != argPacket->accountIndex && !accountData->GetModerator() && !accountData->GetAdministrator()) { + //TODO: send to the client? + std::cerr << "Failed to set character motion due to lack of permissions targeting uid(" << argPacket->characterIndex << ")" << std::endl; + return; + } + + //set the character's origin and motion + characterData->SetOrigin(argPacket->origin); + characterData->SetMotion(argPacket->motion); + + //update the clients + CharacterPacket newPacket; + CopyCharacterToPacket(&newPacket, argPacket->characterIndex); + newPacket.type = SerialPacketType::CHARACTER_SET_MOTION; + PumpPacket(&newPacket); } From 3e2d1a5a56e2c04148622268aa5cc999e9eb4471 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Mon, 22 Dec 2014 23:01:53 +1100 Subject: [PATCH 64/73] Implemented client-side HandleCharacterSet*(); untested --- client/scenes/in_world.cpp | 84 ++++++++++++++++++++++++++++- client/scenes/in_world.hpp | 4 ++ server/server_character_methods.cpp | 2 +- server/server_data.cpp | 1 + 4 files changed, 88 insertions(+), 3 deletions(-) diff --git a/client/scenes/in_world.cpp b/client/scenes/in_world.cpp index 30a2e2b..1b6e060 100644 --- a/client/scenes/in_world.cpp +++ b/client/scenes/in_world.cpp @@ -289,6 +289,17 @@ void InWorld::HandlePacket(SerialPacket* const argPacket) { HandleCharacterQueryExists(static_cast(argPacket)); break; + //character movement + case SerialPacketType::CHARACTER_SET_ROOM: + HandleCharacterSetRoom(static_cast(argPacket)); + break; + case SerialPacketType::CHARACTER_SET_ORIGIN: + HandleCharacterSetOrigin(static_cast(argPacket)); + break; + case SerialPacketType::CHARACTER_SET_MOTION: + HandleCharacterSetMotion(static_cast(argPacket)); + break; + //rejection messages case SerialPacketType::REGION_REJECTION: case SerialPacketType::CHARACTER_REJECTION: @@ -412,6 +423,10 @@ void InWorld::HandleRegionContent(RegionPacket* const argPacket) { } void InWorld::UpdateMap() { + if (roomIndex == -1) { + return; + } + //these represent the zone of regions that the client needs loaded, including the mandatory buffers (+1/-1) int xStart = snapToBase(REGION_WIDTH, camera.x/tileSheet.GetTileW()) - REGION_WIDTH; int xEnd = snapToBase(REGION_WIDTH, (camera.x+camera.width)/tileSheet.GetTileW()) + REGION_WIDTH; @@ -428,7 +443,7 @@ void InWorld::UpdateMap() { for (int i = xStart; i <= xEnd; i += REGION_WIDTH) { for (int j = yStart; j <= yEnd; j += REGION_HEIGHT) { if (!regionPager.FindRegion(i, j)) { - SendRegionRequest(0, i, j); + SendRegionRequest(roomIndex, i, j); } } } @@ -470,6 +485,9 @@ void InWorld::HandleCharacterCreate(CharacterPacket* const argPacket) { //focus the camera on this character camera.marginX = (camera.width / 2 - localCharacter->GetSprite()->GetImage()->GetClipW() / 2); camera.marginY = (camera.height/ 2 - localCharacter->GetSprite()->GetImage()->GetClipH() / 2); + + //focus on this character's room + roomIndex = argPacket->roomIndex; } //debug @@ -492,6 +510,9 @@ void InWorld::HandleCharacterDelete(CharacterPacket* const argPacket) { //clear the camera camera.marginX = 0; camera.marginY = 0; + + //clear the room + roomIndex = -1; } //remove this character @@ -507,6 +528,11 @@ void InWorld::HandleCharacterQueryExists(CharacterPacket* const argPacket) { return; } + //ignore characters in a different room (sub-optimal) + if (argPacket->roomIndex != roomIndex) { + return; + } + //implicitly construct the character if it doesn't exist BaseCharacter* character = &characterMap[argPacket->characterIndex]; @@ -520,4 +546,58 @@ void InWorld::HandleCharacterQueryExists(CharacterPacket* const argPacket) { //debug std::cout << "Query, total: " << characterMap.size() << std::endl; -} \ No newline at end of file +} + +void InWorld::HandleCharacterSetRoom(CharacterPacket* const argPacket) { + //someone else's character + if (argPacket->characterIndex != characterIndex) { + characterMap.erase(argPacket->characterIndex); + return; + } + + //this character is moving between rooms + roomIndex = argPacket->roomIndex; + + //set the character's info + localCharacter->SetOrigin(argPacket->origin); + localCharacter->SetMotion(argPacket->motion); + + //clear the old room's data + regionPager.UnloadAll(); + monsterMap.clear(); + + //use the jenky pattern for std::map to skip this player's character + for (std::map::iterator it = characterMap.begin(); it != characterMap.end(); /* EMPTY */ ) { + if (it->first != characterIndex) { + it = characterMap.erase(it); + } + else { + ++it; + } + } + + //request the info on characters in this room + CharacterPacket newPacket; + newPacket.type = SerialPacketType::QUERY_CHARACTER_EXISTS; + network.SendTo(Channels::SERVER, &newPacket); +} + +void InWorld::HandleCharacterSetOrigin(CharacterPacket* const argPacket) { + //check that this character exists + std::map::iterator characterIt = characterMap.find(argPacket->characterIndex); + if (characterIt != characterMap.end()) { + //set the origin and motion + characterIt->second.SetOrigin(argPacket->origin); + characterIt->second.SetMotion(argPacket->motion); + } +} + +void InWorld::HandleCharacterSetMotion(CharacterPacket* const argPacket) { + //check that this character exists + std::map::iterator characterIt = characterMap.find(argPacket->characterIndex); + if (characterIt != characterMap.end()) { + //set the origin and motion + characterIt->second.SetOrigin(argPacket->origin); + characterIt->second.SetMotion(argPacket->motion); + } +} diff --git a/client/scenes/in_world.hpp b/client/scenes/in_world.hpp index 2348cf9..e2fb9d9 100644 --- a/client/scenes/in_world.hpp +++ b/client/scenes/in_world.hpp @@ -94,11 +94,15 @@ protected: void HandleCharacterCreate(CharacterPacket* const); void HandleCharacterDelete(CharacterPacket* const); void HandleCharacterQueryExists(CharacterPacket* const); + void HandleCharacterSetRoom(CharacterPacket* const); + void HandleCharacterSetOrigin(CharacterPacket* const); + void HandleCharacterSetMotion(CharacterPacket* const); //indexes int& clientIndex; int& accountIndex; int characterIndex = -1; + int roomIndex = -1; //graphics Image buttonImage; diff --git a/server/server_character_methods.cpp b/server/server_character_methods.cpp index 8f4a22b..780bf24 100644 --- a/server/server_character_methods.cpp +++ b/server/server_character_methods.cpp @@ -192,7 +192,7 @@ void ServerApplication::HandleCharacterSetRoom(CharacterPacket* const argPacket) //set the character's room, zero it's origin, zero it's motion //TODO: Set the origin here - characterData->SetRoom(argPacket->roomIndex); + characterData->SetRoomIndex(argPacket->roomIndex); characterData->SetOrigin({0, 0}); characterData->SetMotion({0, 0}); diff --git a/server/server_data.cpp b/server/server_data.cpp index 4eadeba..b9098fa 100644 --- a/server/server_data.cpp +++ b/server/server_data.cpp @@ -73,6 +73,7 @@ void ServerApplication::HandleRegionRequest(RegionPacket* const argPacket) { void ServerApplication::HandleCharacterExists(CharacterPacket* const argPacket) { //respond with all character data + //TODO: handle room and location specifications CharacterPacket newPacket; for (auto& it : *characterMgr.GetContainer()) { CopyCharacterToPacket(&newPacket, it.first); From 398f1c8bfd5d018231c9e6998285d496499925f0 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Sat, 27 Dec 2014 01:33:10 +1100 Subject: [PATCH 65/73] Added a room check to the character query --- client/scenes/in_world.cpp | 1 + server/server_data.cpp | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/client/scenes/in_world.cpp b/client/scenes/in_world.cpp index 1b6e060..63b5afc 100644 --- a/client/scenes/in_world.cpp +++ b/client/scenes/in_world.cpp @@ -579,6 +579,7 @@ void InWorld::HandleCharacterSetRoom(CharacterPacket* const argPacket) { //request the info on characters in this room CharacterPacket newPacket; newPacket.type = SerialPacketType::QUERY_CHARACTER_EXISTS; + newPacket.roomIndex = roomIndex; network.SendTo(Channels::SERVER, &newPacket); } diff --git a/server/server_data.cpp b/server/server_data.cpp index b9098fa..bd00a8f 100644 --- a/server/server_data.cpp +++ b/server/server_data.cpp @@ -73,9 +73,12 @@ void ServerApplication::HandleRegionRequest(RegionPacket* const argPacket) { void ServerApplication::HandleCharacterExists(CharacterPacket* const argPacket) { //respond with all character data - //TODO: handle room and location specifications CharacterPacket newPacket; + for (auto& it : *characterMgr.GetContainer()) { + if (argPacket->roomIndex != -1 && it.second.GetRoomIndex() != argPacket->roomIndex) { + continue; + } CopyCharacterToPacket(&newPacket, it.first); newPacket.type = SerialPacketType::QUERY_CHARACTER_EXISTS; network.SendTo(argPacket->srcAddress, static_cast(&newPacket)); From 6c11aa09275509de41e0351d6f9317b200b2d1a8 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Sat, 27 Dec 2014 02:26:44 +1100 Subject: [PATCH 66/73] Characters are moving around in the world --- client/scenes/in_world.cpp | 77 ++++++++++++++++++++++++++++- client/scenes/in_world.hpp | 3 ++ server/server_character_methods.cpp | 15 +++++- 3 files changed, 91 insertions(+), 4 deletions(-) diff --git a/client/scenes/in_world.cpp b/client/scenes/in_world.cpp index 63b5afc..abd68d4 100644 --- a/client/scenes/in_world.cpp +++ b/client/scenes/in_world.cpp @@ -242,10 +242,59 @@ void InWorld::KeyDown(SDL_KeyboardEvent const& key) { SendLogoutRequest(); break; } + + //character movement + if (!localCharacter) { + return; + } + Vector2 motion = localCharacter->GetMotion(); + switch(key.keysym.sym) { + case SDLK_w: + motion.y -= CHARACTER_WALKING_SPEED; + break; + case SDLK_a: + motion.x -= CHARACTER_WALKING_SPEED; + break; + case SDLK_s: + motion.y += CHARACTER_WALKING_SPEED; + break; + case SDLK_d: + motion.x += CHARACTER_WALKING_SPEED; + break; + } + //handle diagonals + if (motion.x != 0 && motion.y != 0) { + motion *= CHARACTER_WALKING_MOD; + } + localCharacter->SetMotion(motion); + localCharacter->CorrectSprite(); + SendLocalCharacterMotion(); } void InWorld::KeyUp(SDL_KeyboardEvent const& key) { - // + //character movement + if (!localCharacter) { + return; + } + Vector2 motion = localCharacter->GetMotion(); + switch(key.keysym.sym) { + case SDLK_w: + motion.y = std::min(0.0, motion.y += CHARACTER_WALKING_SPEED); + break; + case SDLK_a: + motion.x = std::min(0.0, motion.x += CHARACTER_WALKING_SPEED); + break; + case SDLK_s: + motion.y = std::max(0.0, motion.y -= CHARACTER_WALKING_SPEED); + break; + case SDLK_d: + motion.x = std::max(0.0, motion.x -= CHARACTER_WALKING_SPEED); + break; + } + //handle diagonals + localCharacter->SetMotion(motion); + localCharacter->CorrectSprite(); + SendLocalCharacterMotion(); } //------------------------- @@ -477,6 +526,7 @@ void InWorld::HandleCharacterCreate(CharacterPacket* const argPacket) { character->SetHandle(argPacket->handle); character->SetAvatar(argPacket->avatar); character->SetOwner(argPacket->accountIndex); + character->CorrectSprite(); //check for this player's character if (character->GetOwner() == accountIndex) { @@ -486,7 +536,8 @@ void InWorld::HandleCharacterCreate(CharacterPacket* const argPacket) { camera.marginX = (camera.width / 2 - localCharacter->GetSprite()->GetImage()->GetClipW() / 2); camera.marginY = (camera.height/ 2 - localCharacter->GetSprite()->GetImage()->GetClipH() / 2); - //focus on this character's room + //focus on this character's info + characterIndex = argPacket->characterIndex; roomIndex = argPacket->roomIndex; } @@ -543,6 +594,7 @@ void InWorld::HandleCharacterQueryExists(CharacterPacket* const argPacket) { character->SetHandle(argPacket->handle); character->SetAvatar(argPacket->avatar); character->SetOwner(argPacket->accountIndex); + character->CorrectSprite(); //debug std::cout << "Query, total: " << characterMap.size() << std::endl; @@ -561,6 +613,7 @@ void InWorld::HandleCharacterSetRoom(CharacterPacket* const argPacket) { //set the character's info localCharacter->SetOrigin(argPacket->origin); localCharacter->SetMotion(argPacket->motion); + localCharacter->CorrectSprite(); //clear the old room's data regionPager.UnloadAll(); @@ -590,6 +643,7 @@ void InWorld::HandleCharacterSetOrigin(CharacterPacket* const argPacket) { //set the origin and motion characterIt->second.SetOrigin(argPacket->origin); characterIt->second.SetMotion(argPacket->motion); + characterIt->second.CorrectSprite(); } } @@ -600,5 +654,24 @@ void InWorld::HandleCharacterSetMotion(CharacterPacket* const argPacket) { //set the origin and motion characterIt->second.SetOrigin(argPacket->origin); characterIt->second.SetMotion(argPacket->motion); + characterIt->second.CorrectSprite(); } } + +//------------------------- +//player movement +//------------------------- + +//TODO: add a "movement" packet type +void InWorld::SendLocalCharacterMotion() { + CharacterPacket newPacket; + newPacket.type = SerialPacketType::CHARACTER_SET_MOTION; + + newPacket.accountIndex = accountIndex; + newPacket.characterIndex = characterIndex; + newPacket.roomIndex = roomIndex; + newPacket.origin = localCharacter->GetOrigin(); + newPacket.motion = localCharacter->GetMotion(); + + network.SendTo(Channels::SERVER, &newPacket); +} \ No newline at end of file diff --git a/client/scenes/in_world.hpp b/client/scenes/in_world.hpp index e2fb9d9..c4d2b75 100644 --- a/client/scenes/in_world.hpp +++ b/client/scenes/in_world.hpp @@ -98,6 +98,9 @@ protected: void HandleCharacterSetOrigin(CharacterPacket* const); void HandleCharacterSetMotion(CharacterPacket* const); + //player movement + void SendLocalCharacterMotion(); + //indexes int& clientIndex; int& accountIndex; diff --git a/server/server_character_methods.cpp b/server/server_character_methods.cpp index 780bf24..b4ada65 100644 --- a/server/server_character_methods.cpp +++ b/server/server_character_methods.cpp @@ -242,10 +242,21 @@ void ServerApplication::HandleCharacterSetOrigin(CharacterPacket* const argPacke void ServerApplication::HandleCharacterSetMotion(CharacterPacket* const argPacket) { //get the specified objects AccountData* accountData = accountMgr.Get(argPacket->accountIndex); + + if (!accountData) { + std::ostringstream msg; + msg << "Failed to set character motion, missing account: Index " << argPacket->accountIndex << "; "; + msg << "Number of accounts loaded: " << accountMgr.GetContainer()->size(); + throw(std::runtime_error(msg.str())); + } + CharacterData* characterData = characterMgr.Get(argPacket->characterIndex); - if (!accountData || !characterData) { - throw(std::runtime_error("Failed to set character motion, missing data")); + if (!characterData) { + std::ostringstream msg; + msg << "Failed to set character motion, missing character: Index " << argPacket->characterIndex << "; "; + msg << "Number of characters loaded: " << characterMgr.GetContainer()->size(); + throw(std::runtime_error(msg.str())); } //get this account's client From f2d517df9df8528029fe54f1d940c750bccb0233 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Sat, 27 Dec 2014 12:33:51 +1100 Subject: [PATCH 67/73] BUGFIX: Infinitely small motion on an axis after repeated key release; read more I've patched this issue by setting motion's elements to CHARACTER_WALKING_SPEED or negative CHARACTER_WALKING_SPEED if they're above or below zero, respectively. --- client/scenes/in_world.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/client/scenes/in_world.cpp b/client/scenes/in_world.cpp index abd68d4..1819fb2 100644 --- a/client/scenes/in_world.cpp +++ b/client/scenes/in_world.cpp @@ -266,6 +266,7 @@ void InWorld::KeyDown(SDL_KeyboardEvent const& key) { if (motion.x != 0 && motion.y != 0) { motion *= CHARACTER_WALKING_MOD; } + //set the info localCharacter->SetMotion(motion); localCharacter->CorrectSprite(); SendLocalCharacterMotion(); @@ -291,7 +292,24 @@ void InWorld::KeyUp(SDL_KeyboardEvent const& key) { motion.x = std::max(0.0, motion.x -= CHARACTER_WALKING_SPEED); break; } + //BUGFIX: reset cardinal direction speed on key release + if (motion.x > 0) { + motion.x = CHARACTER_WALKING_SPEED; + } + else if (motion.x < 0) { + motion.x = -CHARACTER_WALKING_SPEED; + } + if (motion.y > 0) { + motion.y = CHARACTER_WALKING_SPEED; + } + else if (motion.y < 0) { + motion.y = -CHARACTER_WALKING_SPEED; + } //handle diagonals + if (motion.x != 0 && motion.y != 0) { + motion *= CHARACTER_WALKING_MOD; + } + //set the info localCharacter->SetMotion(motion); localCharacter->CorrectSprite(); SendLocalCharacterMotion(); From 7e5a7f8183c4ed7bfdd81141bfcc7f67ece945d7 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Sat, 27 Dec 2014 13:29:16 +1100 Subject: [PATCH 68/73] Updated the copyright headers about a week ahead --- client/channels.hpp | 2 +- client/client_application.cpp | 6 +++--- client/client_application.hpp | 2 +- client/client_utilities/terminal_error.cpp | 2 +- client/client_utilities/terminal_error.hpp | 2 +- client/entities/base_character.cpp | 2 +- client/entities/base_character.hpp | 2 +- client/entities/base_monster.cpp | 2 +- client/entities/base_monster.hpp | 2 +- client/entities/entity.cpp | 2 +- client/entities/entity.hpp | 2 +- client/entities/local_character.cpp | 2 +- client/entities/local_character.hpp | 2 +- client/main.cpp | 2 +- client/scene_list.hpp | 2 +- client/scenes/base_scene.cpp | 2 +- client/scenes/base_scene.hpp | 2 +- client/scenes/disconnected_screen.cpp | 2 +- client/scenes/disconnected_screen.hpp | 2 +- client/scenes/in_world.cpp | 5 ++++- client/scenes/in_world.hpp | 2 +- client/scenes/lobby_menu.cpp | 2 +- client/scenes/lobby_menu.hpp | 2 +- client/scenes/main_menu.cpp | 2 +- client/scenes/main_menu.hpp | 2 +- client/scenes/options_menu.cpp | 2 +- client/scenes/options_menu.hpp | 2 +- client/scenes/splash_screen.cpp | 2 +- client/scenes/splash_screen.hpp | 2 +- common/debugging/timer.cpp | 2 +- common/debugging/timer.hpp | 2 +- common/gameplay/character_defines.hpp | 2 +- common/graphics/image.cpp | 2 +- common/graphics/image.hpp | 2 +- common/graphics/sprite_sheet.cpp | 2 +- common/graphics/sprite_sheet.hpp | 2 +- common/map/map_system_api.cpp | 2 +- common/map/map_system_api.hpp | 2 +- common/map/region.cpp | 2 +- common/map/region.hpp | 2 +- common/map/region_api.cpp | 2 +- common/map/region_api.hpp | 2 +- common/map/region_pager_api.cpp | 2 +- common/map/region_pager_api.hpp | 2 +- common/map/region_pager_base.cpp | 2 +- common/map/region_pager_base.hpp | 2 +- common/map/region_pager_lua.cpp | 2 +- common/map/region_pager_lua.hpp | 2 +- common/map/tile_sheet.cpp | 2 +- common/map/tile_sheet.hpp | 2 +- common/map/tile_sheet_api.cpp | 2 +- common/map/tile_sheet_api.hpp | 2 +- common/network/packet_types/character_packet.cpp | 2 +- common/network/packet_types/character_packet.hpp | 2 +- common/network/packet_types/client_packet.cpp | 2 +- common/network/packet_types/client_packet.hpp | 2 +- common/network/packet_types/region_packet.cpp | 2 +- common/network/packet_types/region_packet.hpp | 2 +- common/network/packet_types/serial_packet_base.cpp | 2 +- common/network/packet_types/serial_packet_base.hpp | 2 +- common/network/packet_types/server_packet.cpp | 2 +- common/network/packet_types/server_packet.hpp | 2 +- common/network/packet_types/text_packet.cpp | 2 +- common/network/packet_types/text_packet.hpp | 2 +- common/network/serial_packet.hpp | 4 ++-- common/network/serial_packet_type.hpp | 2 +- common/network/serial_utility.cpp | 2 +- common/network/serial_utility.hpp | 2 +- common/network/udp_network_utility.cpp | 2 +- common/network/udp_network_utility.hpp | 2 +- common/ui/button.cpp | 2 +- common/ui/button.hpp | 2 +- common/ui/menu_bar.cpp | 2 +- common/ui/menu_bar.hpp | 2 +- common/ui/raster_font.cpp | 2 +- common/ui/raster_font.hpp | 2 +- common/utilities/bounding_box.hpp | 2 +- common/utilities/config_utility.cpp | 2 +- common/utilities/config_utility.hpp | 2 +- common/utilities/frame_rate.hpp | 2 +- common/utilities/singleton.hpp | 2 +- common/utilities/utility.cpp | 2 +- common/utilities/utility.hpp | 2 +- common/utilities/vector2.hpp | 2 +- server/accounts/account_data.cpp | 2 +- server/accounts/account_data.hpp | 2 +- server/accounts/account_manager.cpp | 2 +- server/accounts/account_manager.hpp | 2 +- server/characters/character_data.cpp | 2 +- server/characters/character_data.hpp | 2 +- server/characters/character_manager.cpp | 2 +- server/characters/character_manager.hpp | 2 +- server/clients/client_data.cpp | 2 +- server/clients/client_data.hpp | 2 +- server/clients/client_manager.cpp | 2 +- server/clients/client_manager.hpp | 2 +- server/doors/door_data.cpp | 2 +- server/doors/door_data.hpp | 2 +- server/doors/door_manager.cpp | 2 +- server/doors/door_manager.hpp | 2 +- server/entities/entity.cpp | 2 +- server/entities/entity.hpp | 2 +- server/linit.cpp | 2 +- server/main.cpp | 2 +- server/monsters/monster_data.cpp | 2 +- server/monsters/monster_data.hpp | 2 +- server/monsters/monster_manager.cpp | 2 +- server/monsters/monster_manager.hpp | 2 +- server/rooms/room_api.cpp | 2 +- server/rooms/room_api.hpp | 2 +- server/rooms/room_data.cpp | 2 +- server/rooms/room_data.hpp | 2 +- server/rooms/room_manager.cpp | 2 +- server/rooms/room_manager.hpp | 2 +- server/rooms/room_manager_api.cpp | 2 +- server/rooms/room_manager_api.hpp | 2 +- server/rooms/room_system_api.cpp | 2 +- server/rooms/room_system_api.hpp | 2 +- server/server_application.hpp | 2 +- server/server_character_methods.cpp | 2 +- server/server_connections.cpp | 2 +- server/server_data.cpp | 2 +- server/server_logic.cpp | 2 +- server/server_methods.cpp | 2 +- server/server_utilities/manager_interface.hpp | 2 +- server/server_utilities/sql_tools.cpp | 2 +- server/server_utilities/sql_tools.hpp | 2 +- 127 files changed, 133 insertions(+), 130 deletions(-) diff --git a/client/channels.hpp b/client/channels.hpp index 2fe04a7..431b877 100644 --- a/client/channels.hpp +++ b/client/channels.hpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2013, 2014 +/* Copyright: (c) Kayne Ruse 2013-2015 * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages diff --git a/client/client_application.cpp b/client/client_application.cpp index 2725314..c3835da 100644 --- a/client/client_application.cpp +++ b/client/client_application.cpp @@ -1,11 +1,11 @@ -/* Copyright: (c) Kayne Ruse 2013, 2014 +/* Copyright: (c) Kayne Ruse 2013-2015 * * 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 ClientApplications, and to alter it and redistribute it + * 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 @@ -178,7 +178,7 @@ void ClientApplication::LoadScene(SceneList sceneIndex) { activeScene = new OptionsMenu(); break; case SceneList::LOBBYMENU: - activeScene = new LobbyMenu(&clientIndex, &accountIndex); //TODO: can I use the ConfigUtility for these parameters? + activeScene = new LobbyMenu(&clientIndex, &accountIndex); break; case SceneList::INWORLD: activeScene = new InWorld(&clientIndex, &accountIndex); diff --git a/client/client_application.hpp b/client/client_application.hpp index 7e99458..6f6fc0b 100644 --- a/client/client_application.hpp +++ b/client/client_application.hpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2013, 2014 +/* Copyright: (c) Kayne Ruse 2013-2015 * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages diff --git a/client/client_utilities/terminal_error.cpp b/client/client_utilities/terminal_error.cpp index d391add..b113807 100644 --- a/client/client_utilities/terminal_error.cpp +++ b/client/client_utilities/terminal_error.cpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2014 +/* Copyright: (c) Kayne Ruse 2013-2015 * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages diff --git a/client/client_utilities/terminal_error.hpp b/client/client_utilities/terminal_error.hpp index 980b4e3..8a7216b 100644 --- a/client/client_utilities/terminal_error.hpp +++ b/client/client_utilities/terminal_error.hpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2014 +/* Copyright: (c) Kayne Ruse 2013-2015 * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages diff --git a/client/entities/base_character.cpp b/client/entities/base_character.cpp index cfa20b4..c0e3f99 100644 --- a/client/entities/base_character.cpp +++ b/client/entities/base_character.cpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2014 +/* Copyright: (c) Kayne Ruse 2013-2015 * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages diff --git a/client/entities/base_character.hpp b/client/entities/base_character.hpp index ba699d9..cd38a6a 100644 --- a/client/entities/base_character.hpp +++ b/client/entities/base_character.hpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2014 +/* Copyright: (c) Kayne Ruse 2013-2015 * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages diff --git a/client/entities/base_monster.cpp b/client/entities/base_monster.cpp index e6350c4..2eaa513 100644 --- a/client/entities/base_monster.cpp +++ b/client/entities/base_monster.cpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2014 +/* Copyright: (c) Kayne Ruse 2013-2015 * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages diff --git a/client/entities/base_monster.hpp b/client/entities/base_monster.hpp index 6fd91e9..c9b7bb3 100644 --- a/client/entities/base_monster.hpp +++ b/client/entities/base_monster.hpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2014 +/* Copyright: (c) Kayne Ruse 2013-2015 * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages diff --git a/client/entities/entity.cpp b/client/entities/entity.cpp index 34cc6cf..da67f27 100644 --- a/client/entities/entity.cpp +++ b/client/entities/entity.cpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2014 +/* Copyright: (c) Kayne Ruse 2013-2015 * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages diff --git a/client/entities/entity.hpp b/client/entities/entity.hpp index a40f94f..77b5c1c 100644 --- a/client/entities/entity.hpp +++ b/client/entities/entity.hpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2014 +/* Copyright: (c) Kayne Ruse 2013-2015 * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages diff --git a/client/entities/local_character.cpp b/client/entities/local_character.cpp index 211a6bc..201ef48 100644 --- a/client/entities/local_character.cpp +++ b/client/entities/local_character.cpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2014 +/* Copyright: (c) Kayne Ruse 2013-2015 * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages diff --git a/client/entities/local_character.hpp b/client/entities/local_character.hpp index 3cbff5f..4493fb4 100644 --- a/client/entities/local_character.hpp +++ b/client/entities/local_character.hpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2014 +/* Copyright: (c) Kayne Ruse 2013-2015 * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages diff --git a/client/main.cpp b/client/main.cpp index 2115115..087a537 100644 --- a/client/main.cpp +++ b/client/main.cpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2013, 2014 +/* Copyright: (c) Kayne Ruse 2013-2015 * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages diff --git a/client/scene_list.hpp b/client/scene_list.hpp index 82895cd..475e5bb 100644 --- a/client/scene_list.hpp +++ b/client/scene_list.hpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2013, 2014 +/* Copyright: (c) Kayne Ruse 2013-2015 * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages diff --git a/client/scenes/base_scene.cpp b/client/scenes/base_scene.cpp index d4b7824..ba62b4c 100644 --- a/client/scenes/base_scene.cpp +++ b/client/scenes/base_scene.cpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2013, 2014 +/* Copyright: (c) Kayne Ruse 2013-2015 * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages diff --git a/client/scenes/base_scene.hpp b/client/scenes/base_scene.hpp index d954ca0..453ab75 100644 --- a/client/scenes/base_scene.hpp +++ b/client/scenes/base_scene.hpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2013, 2014 +/* Copyright: (c) Kayne Ruse 2013-2015 * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages diff --git a/client/scenes/disconnected_screen.cpp b/client/scenes/disconnected_screen.cpp index 7d95293..d3c0fb3 100644 --- a/client/scenes/disconnected_screen.cpp +++ b/client/scenes/disconnected_screen.cpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2014 +/* Copyright: (c) Kayne Ruse 2013-2015 * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages diff --git a/client/scenes/disconnected_screen.hpp b/client/scenes/disconnected_screen.hpp index 453dad8..a735289 100644 --- a/client/scenes/disconnected_screen.hpp +++ b/client/scenes/disconnected_screen.hpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2014 +/* Copyright: (c) Kayne Ruse 2013-2015 * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages diff --git a/client/scenes/in_world.cpp b/client/scenes/in_world.cpp index 1819fb2..be7ed3c 100644 --- a/client/scenes/in_world.cpp +++ b/client/scenes/in_world.cpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2013, 2014 +/* Copyright: (c) Kayne Ruse 2013-2015 * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages @@ -145,6 +145,9 @@ void InWorld::Update() { it.second.Update(); } + //process collisions + // + //update the camera if (localCharacter) { camera.x = localCharacter->GetOrigin().x - camera.marginX; diff --git a/client/scenes/in_world.hpp b/client/scenes/in_world.hpp index c4d2b75..cacf2dd 100644 --- a/client/scenes/in_world.hpp +++ b/client/scenes/in_world.hpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2013, 2014 +/* Copyright: (c) Kayne Ruse 2013-2015 * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages diff --git a/client/scenes/lobby_menu.cpp b/client/scenes/lobby_menu.cpp index 3fbc1c1..0776242 100644 --- a/client/scenes/lobby_menu.cpp +++ b/client/scenes/lobby_menu.cpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2013, 2014 +/* Copyright: (c) Kayne Ruse 2013-2015 * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages diff --git a/client/scenes/lobby_menu.hpp b/client/scenes/lobby_menu.hpp index b8e5347..067af8c 100644 --- a/client/scenes/lobby_menu.hpp +++ b/client/scenes/lobby_menu.hpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2013, 2014 +/* Copyright: (c) Kayne Ruse 2013-2015 * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages diff --git a/client/scenes/main_menu.cpp b/client/scenes/main_menu.cpp index 5aa431b..2be7c93 100644 --- a/client/scenes/main_menu.cpp +++ b/client/scenes/main_menu.cpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2013, 2014 +/* Copyright: (c) Kayne Ruse 2013-2015 * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages diff --git a/client/scenes/main_menu.hpp b/client/scenes/main_menu.hpp index 9572499..d3e7f74 100644 --- a/client/scenes/main_menu.hpp +++ b/client/scenes/main_menu.hpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2013, 2014 +/* Copyright: (c) Kayne Ruse 2013-2015 * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages diff --git a/client/scenes/options_menu.cpp b/client/scenes/options_menu.cpp index 7aa2493..f06b798 100644 --- a/client/scenes/options_menu.cpp +++ b/client/scenes/options_menu.cpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2013, 2014 +/* Copyright: (c) Kayne Ruse 2013-2015 * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages diff --git a/client/scenes/options_menu.hpp b/client/scenes/options_menu.hpp index 5bb3eed..bb15569 100644 --- a/client/scenes/options_menu.hpp +++ b/client/scenes/options_menu.hpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2013, 2014 +/* Copyright: (c) Kayne Ruse 2013-2015 * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages diff --git a/client/scenes/splash_screen.cpp b/client/scenes/splash_screen.cpp index 5473d79..5399efd 100644 --- a/client/scenes/splash_screen.cpp +++ b/client/scenes/splash_screen.cpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2013, 2014 +/* Copyright: (c) Kayne Ruse 2013-2015 * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages diff --git a/client/scenes/splash_screen.hpp b/client/scenes/splash_screen.hpp index c6440c1..a8bec1b 100644 --- a/client/scenes/splash_screen.hpp +++ b/client/scenes/splash_screen.hpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2013, 2014 +/* Copyright: (c) Kayne Ruse 2013-2015 * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages diff --git a/common/debugging/timer.cpp b/common/debugging/timer.cpp index 29d107a..302ddb5 100644 --- a/common/debugging/timer.cpp +++ b/common/debugging/timer.cpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2014 +/* Copyright: (c) Kayne Ruse 2013-2015 * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages diff --git a/common/debugging/timer.hpp b/common/debugging/timer.hpp index dfafec9..e5139d3 100644 --- a/common/debugging/timer.hpp +++ b/common/debugging/timer.hpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2014 +/* Copyright: (c) Kayne Ruse 2013-2015 * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages diff --git a/common/gameplay/character_defines.hpp b/common/gameplay/character_defines.hpp index 7b759d1..7b0d7d6 100644 --- a/common/gameplay/character_defines.hpp +++ b/common/gameplay/character_defines.hpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2014 +/* Copyright: (c) Kayne Ruse 2013-2015 * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages diff --git a/common/graphics/image.cpp b/common/graphics/image.cpp index 3b4f99b..4089814 100644 --- a/common/graphics/image.cpp +++ b/common/graphics/image.cpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2013, 2014 +/* Copyright: (c) Kayne Ruse 2013-2015 * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages diff --git a/common/graphics/image.hpp b/common/graphics/image.hpp index 462e565..709490d 100644 --- a/common/graphics/image.hpp +++ b/common/graphics/image.hpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2013, 2014 +/* Copyright: (c) Kayne Ruse 2013-2015 * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages diff --git a/common/graphics/sprite_sheet.cpp b/common/graphics/sprite_sheet.cpp index 7726484..93c1984 100644 --- a/common/graphics/sprite_sheet.cpp +++ b/common/graphics/sprite_sheet.cpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2013, 2014 +/* Copyright: (c) Kayne Ruse 2013-2015 * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages diff --git a/common/graphics/sprite_sheet.hpp b/common/graphics/sprite_sheet.hpp index 8ecaa5b..ea28a86 100644 --- a/common/graphics/sprite_sheet.hpp +++ b/common/graphics/sprite_sheet.hpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2013, 2014 +/* Copyright: (c) Kayne Ruse 2013-2015 * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages diff --git a/common/map/map_system_api.cpp b/common/map/map_system_api.cpp index 0e12796..9e908ad 100644 --- a/common/map/map_system_api.cpp +++ b/common/map/map_system_api.cpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2014 +/* Copyright: (c) Kayne Ruse 2013-2015 * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages diff --git a/common/map/map_system_api.hpp b/common/map/map_system_api.hpp index 10f2f94..d01c276 100644 --- a/common/map/map_system_api.hpp +++ b/common/map/map_system_api.hpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2014 +/* Copyright: (c) Kayne Ruse 2013-2015 * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages diff --git a/common/map/region.cpp b/common/map/region.cpp index ea1f402..229c350 100644 --- a/common/map/region.cpp +++ b/common/map/region.cpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2014 +/* Copyright: (c) Kayne Ruse 2013-2015 * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages diff --git a/common/map/region.hpp b/common/map/region.hpp index 55e7e9f..5e2f882 100644 --- a/common/map/region.hpp +++ b/common/map/region.hpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2014 +/* Copyright: (c) Kayne Ruse 2013-2015 * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages diff --git a/common/map/region_api.cpp b/common/map/region_api.cpp index 0ccb880..1749f49 100644 --- a/common/map/region_api.cpp +++ b/common/map/region_api.cpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2014 +/* Copyright: (c) Kayne Ruse 2013-2015 * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages diff --git a/common/map/region_api.hpp b/common/map/region_api.hpp index b276645..aae8b29 100644 --- a/common/map/region_api.hpp +++ b/common/map/region_api.hpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2014 +/* Copyright: (c) Kayne Ruse 2013-2015 * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages diff --git a/common/map/region_pager_api.cpp b/common/map/region_pager_api.cpp index 73019d1..d7a38e9 100644 --- a/common/map/region_pager_api.cpp +++ b/common/map/region_pager_api.cpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2014 +/* Copyright: (c) Kayne Ruse 2013-2015 * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages diff --git a/common/map/region_pager_api.hpp b/common/map/region_pager_api.hpp index a8f9297..2476a95 100644 --- a/common/map/region_pager_api.hpp +++ b/common/map/region_pager_api.hpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2014 +/* Copyright: (c) Kayne Ruse 2013-2015 * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages diff --git a/common/map/region_pager_base.cpp b/common/map/region_pager_base.cpp index c046bdc..d20b346 100644 --- a/common/map/region_pager_base.cpp +++ b/common/map/region_pager_base.cpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2014 +/* Copyright: (c) Kayne Ruse 2013-2015 * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages diff --git a/common/map/region_pager_base.hpp b/common/map/region_pager_base.hpp index 53bb097..c6d6b3d 100644 --- a/common/map/region_pager_base.hpp +++ b/common/map/region_pager_base.hpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2014 +/* Copyright: (c) Kayne Ruse 2013-2015 * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages diff --git a/common/map/region_pager_lua.cpp b/common/map/region_pager_lua.cpp index 4eeea2b..8fb0dfc 100644 --- a/common/map/region_pager_lua.cpp +++ b/common/map/region_pager_lua.cpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2014 +/* Copyright: (c) Kayne Ruse 2013-2015 * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages diff --git a/common/map/region_pager_lua.hpp b/common/map/region_pager_lua.hpp index 656074c..203715b 100644 --- a/common/map/region_pager_lua.hpp +++ b/common/map/region_pager_lua.hpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2014 +/* Copyright: (c) Kayne Ruse 2013-2015 * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages diff --git a/common/map/tile_sheet.cpp b/common/map/tile_sheet.cpp index 819d709..6f47337 100644 --- a/common/map/tile_sheet.cpp +++ b/common/map/tile_sheet.cpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2014 +/* Copyright: (c) Kayne Ruse 2013-2015 * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages diff --git a/common/map/tile_sheet.hpp b/common/map/tile_sheet.hpp index f9bf8ea..6ad94ea 100644 --- a/common/map/tile_sheet.hpp +++ b/common/map/tile_sheet.hpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2014 +/* Copyright: (c) Kayne Ruse 2013-2015 * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages diff --git a/common/map/tile_sheet_api.cpp b/common/map/tile_sheet_api.cpp index 5ee280f..141f200 100644 --- a/common/map/tile_sheet_api.cpp +++ b/common/map/tile_sheet_api.cpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2014 +/* Copyright: (c) Kayne Ruse 2013-2015 * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages diff --git a/common/map/tile_sheet_api.hpp b/common/map/tile_sheet_api.hpp index dc3d277..3cdd0e5 100644 --- a/common/map/tile_sheet_api.hpp +++ b/common/map/tile_sheet_api.hpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2014 +/* Copyright: (c) Kayne Ruse 2013-2015 * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages diff --git a/common/network/packet_types/character_packet.cpp b/common/network/packet_types/character_packet.cpp index c18d1bf..98083f3 100644 --- a/common/network/packet_types/character_packet.cpp +++ b/common/network/packet_types/character_packet.cpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2014 +/* Copyright: (c) Kayne Ruse 2013-2015 * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages diff --git a/common/network/packet_types/character_packet.hpp b/common/network/packet_types/character_packet.hpp index 98d2c31..9b7dfde 100644 --- a/common/network/packet_types/character_packet.hpp +++ b/common/network/packet_types/character_packet.hpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2013, 2014 +/* Copyright: (c) Kayne Ruse 2013-2015 * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages diff --git a/common/network/packet_types/client_packet.cpp b/common/network/packet_types/client_packet.cpp index 77da2e0..a0c6617 100644 --- a/common/network/packet_types/client_packet.cpp +++ b/common/network/packet_types/client_packet.cpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2014 +/* Copyright: (c) Kayne Ruse 2013-2015 * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages diff --git a/common/network/packet_types/client_packet.hpp b/common/network/packet_types/client_packet.hpp index bd19c02..32efb06 100644 --- a/common/network/packet_types/client_packet.hpp +++ b/common/network/packet_types/client_packet.hpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2013, 2014 +/* Copyright: (c) Kayne Ruse 2013-2015 * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages diff --git a/common/network/packet_types/region_packet.cpp b/common/network/packet_types/region_packet.cpp index b6b983a..4ac1471 100644 --- a/common/network/packet_types/region_packet.cpp +++ b/common/network/packet_types/region_packet.cpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2014 +/* Copyright: (c) Kayne Ruse 2013-2015 * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages diff --git a/common/network/packet_types/region_packet.hpp b/common/network/packet_types/region_packet.hpp index 0c4d717..3020262 100644 --- a/common/network/packet_types/region_packet.hpp +++ b/common/network/packet_types/region_packet.hpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2013, 2014 +/* Copyright: (c) Kayne Ruse 2013-2015 * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages diff --git a/common/network/packet_types/serial_packet_base.cpp b/common/network/packet_types/serial_packet_base.cpp index c8803b0..d90b868 100644 --- a/common/network/packet_types/serial_packet_base.cpp +++ b/common/network/packet_types/serial_packet_base.cpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2014 +/* Copyright: (c) Kayne Ruse 2013-2015 * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages diff --git a/common/network/packet_types/serial_packet_base.hpp b/common/network/packet_types/serial_packet_base.hpp index 364e645..711fce2 100644 --- a/common/network/packet_types/serial_packet_base.hpp +++ b/common/network/packet_types/serial_packet_base.hpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2013, 2014 +/* Copyright: (c) Kayne Ruse 2013-2015 * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages diff --git a/common/network/packet_types/server_packet.cpp b/common/network/packet_types/server_packet.cpp index 85ec493..562d353 100644 --- a/common/network/packet_types/server_packet.cpp +++ b/common/network/packet_types/server_packet.cpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2014 +/* Copyright: (c) Kayne Ruse 2013-2015 * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages diff --git a/common/network/packet_types/server_packet.hpp b/common/network/packet_types/server_packet.hpp index 3de5a2d..169946e 100644 --- a/common/network/packet_types/server_packet.hpp +++ b/common/network/packet_types/server_packet.hpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2013, 2014 +/* Copyright: (c) Kayne Ruse 2013-2015 * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages diff --git a/common/network/packet_types/text_packet.cpp b/common/network/packet_types/text_packet.cpp index fbe0d9f..56a9836 100644 --- a/common/network/packet_types/text_packet.cpp +++ b/common/network/packet_types/text_packet.cpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2013, 2014 +/* Copyright: (c) Kayne Ruse 2013-2015 * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages diff --git a/common/network/packet_types/text_packet.hpp b/common/network/packet_types/text_packet.hpp index 8dfbe22..0e793b6 100644 --- a/common/network/packet_types/text_packet.hpp +++ b/common/network/packet_types/text_packet.hpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2013, 2014 +/* Copyright: (c) Kayne Ruse 2013-2015 * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages diff --git a/common/network/serial_packet.hpp b/common/network/serial_packet.hpp index 5d9d008..5d609f3 100644 --- a/common/network/serial_packet.hpp +++ b/common/network/serial_packet.hpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2013, 2014 +/* Copyright: (c) Kayne Ruse 2013-2015 * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages @@ -33,7 +33,7 @@ typedef SerialPacketBase SerialPacket; //DOCS: NETWORK_VERSION is used to discern compatible servers and clients -constexpr int NETWORK_VERSION = -1; +constexpr int NETWORK_VERSION = 20141227; union MaxPacket { CharacterPacket a; diff --git a/common/network/serial_packet_type.hpp b/common/network/serial_packet_type.hpp index 489f78d..c4e9842 100644 --- a/common/network/serial_packet_type.hpp +++ b/common/network/serial_packet_type.hpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2013, 2014 +/* Copyright: (c) Kayne Ruse 2013-2015 * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages diff --git a/common/network/serial_utility.cpp b/common/network/serial_utility.cpp index f3874b6..a0d2c61 100644 --- a/common/network/serial_utility.cpp +++ b/common/network/serial_utility.cpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2014 +/* Copyright: (c) Kayne Ruse 2013-2015 * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages diff --git a/common/network/serial_utility.hpp b/common/network/serial_utility.hpp index 829c904..0d3e9c0 100644 --- a/common/network/serial_utility.hpp +++ b/common/network/serial_utility.hpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2014 +/* Copyright: (c) Kayne Ruse 2013-2015 * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages diff --git a/common/network/udp_network_utility.cpp b/common/network/udp_network_utility.cpp index e677854..c069b27 100644 --- a/common/network/udp_network_utility.cpp +++ b/common/network/udp_network_utility.cpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2013, 2014 +/* Copyright: (c) Kayne Ruse 2013-2015 * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages diff --git a/common/network/udp_network_utility.hpp b/common/network/udp_network_utility.hpp index eef3de3..a162d89 100644 --- a/common/network/udp_network_utility.hpp +++ b/common/network/udp_network_utility.hpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2013, 2014 +/* Copyright: (c) Kayne Ruse 2013-2015 * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages diff --git a/common/ui/button.cpp b/common/ui/button.cpp index 59b0ae2..c794c09 100644 --- a/common/ui/button.cpp +++ b/common/ui/button.cpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2013, 2014 +/* Copyright: (c) Kayne Ruse 2013-2015 * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages diff --git a/common/ui/button.hpp b/common/ui/button.hpp index 2fe2faa..b1d6ff1 100644 --- a/common/ui/button.hpp +++ b/common/ui/button.hpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2013, 2014 +/* Copyright: (c) Kayne Ruse 2013-2015 * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages diff --git a/common/ui/menu_bar.cpp b/common/ui/menu_bar.cpp index 2670e32..45358cc 100644 --- a/common/ui/menu_bar.cpp +++ b/common/ui/menu_bar.cpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2013, 2014 +/* Copyright: (c) Kayne Ruse 2013-2015 * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages diff --git a/common/ui/menu_bar.hpp b/common/ui/menu_bar.hpp index e4dd392..ddbb250 100644 --- a/common/ui/menu_bar.hpp +++ b/common/ui/menu_bar.hpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2013, 2014 +/* Copyright: (c) Kayne Ruse 2013-2015 * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages diff --git a/common/ui/raster_font.cpp b/common/ui/raster_font.cpp index 5005f7f..8b48fd2 100644 --- a/common/ui/raster_font.cpp +++ b/common/ui/raster_font.cpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2013, 2014 +/* Copyright: (c) Kayne Ruse 2013-2015 * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages diff --git a/common/ui/raster_font.hpp b/common/ui/raster_font.hpp index c3c1ddd..25fa39a 100644 --- a/common/ui/raster_font.hpp +++ b/common/ui/raster_font.hpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2013, 2014 +/* Copyright: (c) Kayne Ruse 2013-2015 * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages diff --git a/common/utilities/bounding_box.hpp b/common/utilities/bounding_box.hpp index ac7daf2..baf9917 100644 --- a/common/utilities/bounding_box.hpp +++ b/common/utilities/bounding_box.hpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2013, 2014 +/* Copyright: (c) Kayne Ruse 2013-2015 * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages diff --git a/common/utilities/config_utility.cpp b/common/utilities/config_utility.cpp index fedf7e0..2c47929 100644 --- a/common/utilities/config_utility.cpp +++ b/common/utilities/config_utility.cpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2013, 2014 +/* Copyright: (c) Kayne Ruse 2013-2015 * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages diff --git a/common/utilities/config_utility.hpp b/common/utilities/config_utility.hpp index fd6fb99..0f97dbd 100644 --- a/common/utilities/config_utility.hpp +++ b/common/utilities/config_utility.hpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2013, 2014 +/* Copyright: (c) Kayne Ruse 2013-2015 * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages diff --git a/common/utilities/frame_rate.hpp b/common/utilities/frame_rate.hpp index f9b0a6d..e9899ac 100644 --- a/common/utilities/frame_rate.hpp +++ b/common/utilities/frame_rate.hpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2014 +/* Copyright: (c) Kayne Ruse 2013-2015 * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages diff --git a/common/utilities/singleton.hpp b/common/utilities/singleton.hpp index 1754b84..ee9fbb0 100644 --- a/common/utilities/singleton.hpp +++ b/common/utilities/singleton.hpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2014 +/* Copyright: (c) Kayne Ruse 2013-2015 * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages diff --git a/common/utilities/utility.cpp b/common/utilities/utility.cpp index 6f9e171..64b135b 100644 --- a/common/utilities/utility.cpp +++ b/common/utilities/utility.cpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2013, 2014 +/* Copyright: (c) Kayne Ruse 2013-2015 * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages diff --git a/common/utilities/utility.hpp b/common/utilities/utility.hpp index 2cec21f..53cb426 100644 --- a/common/utilities/utility.hpp +++ b/common/utilities/utility.hpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2013, 2014 +/* Copyright: (c) Kayne Ruse 2013-2015 * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages diff --git a/common/utilities/vector2.hpp b/common/utilities/vector2.hpp index 57c716c..e1688d4 100644 --- a/common/utilities/vector2.hpp +++ b/common/utilities/vector2.hpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2013, 2014 +/* Copyright: (c) Kayne Ruse 2013-2015 * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages diff --git a/server/accounts/account_data.cpp b/server/accounts/account_data.cpp index 4b8b872..0ee36b0 100644 --- a/server/accounts/account_data.cpp +++ b/server/accounts/account_data.cpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2014 +/* Copyright: (c) Kayne Ruse 2013-2015 * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages diff --git a/server/accounts/account_data.hpp b/server/accounts/account_data.hpp index 4a27c95..c40f281 100644 --- a/server/accounts/account_data.hpp +++ b/server/accounts/account_data.hpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2014 +/* Copyright: (c) Kayne Ruse 2013-2015 * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages diff --git a/server/accounts/account_manager.cpp b/server/accounts/account_manager.cpp index fccf530..84e7d06 100644 --- a/server/accounts/account_manager.cpp +++ b/server/accounts/account_manager.cpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2014 +/* Copyright: (c) Kayne Ruse 2013-2015 * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages diff --git a/server/accounts/account_manager.hpp b/server/accounts/account_manager.hpp index 9520839..9e6e550 100644 --- a/server/accounts/account_manager.hpp +++ b/server/accounts/account_manager.hpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2014 +/* Copyright: (c) Kayne Ruse 2013-2015 * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages diff --git a/server/characters/character_data.cpp b/server/characters/character_data.cpp index 2e4fa25..c0549d6 100644 --- a/server/characters/character_data.cpp +++ b/server/characters/character_data.cpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2014 +/* Copyright: (c) Kayne Ruse 2013-2015 * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages diff --git a/server/characters/character_data.hpp b/server/characters/character_data.hpp index 2e94a7c..873bfa4 100644 --- a/server/characters/character_data.hpp +++ b/server/characters/character_data.hpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2014 +/* Copyright: (c) Kayne Ruse 2013-2015 * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages diff --git a/server/characters/character_manager.cpp b/server/characters/character_manager.cpp index c83cfcf..53edc9c 100644 --- a/server/characters/character_manager.cpp +++ b/server/characters/character_manager.cpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2014 +/* Copyright: (c) Kayne Ruse 2013-2015 * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages diff --git a/server/characters/character_manager.hpp b/server/characters/character_manager.hpp index d8b2b80..fadf54c 100644 --- a/server/characters/character_manager.hpp +++ b/server/characters/character_manager.hpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2014 +/* Copyright: (c) Kayne Ruse 2013-2015 * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages diff --git a/server/clients/client_data.cpp b/server/clients/client_data.cpp index b2dd4fc..1a549a4 100644 --- a/server/clients/client_data.cpp +++ b/server/clients/client_data.cpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2014 +/* Copyright: (c) Kayne Ruse 2013-2015 * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages diff --git a/server/clients/client_data.hpp b/server/clients/client_data.hpp index 29b3f78..18b93ef 100644 --- a/server/clients/client_data.hpp +++ b/server/clients/client_data.hpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2014 +/* Copyright: (c) Kayne Ruse 2013-2015 * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages diff --git a/server/clients/client_manager.cpp b/server/clients/client_manager.cpp index 86ccdb3..87604f6 100644 --- a/server/clients/client_manager.cpp +++ b/server/clients/client_manager.cpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2014 +/* Copyright: (c) Kayne Ruse 2013-2015 * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages diff --git a/server/clients/client_manager.hpp b/server/clients/client_manager.hpp index d90fb57..4e0b0d1 100644 --- a/server/clients/client_manager.hpp +++ b/server/clients/client_manager.hpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2014 +/* Copyright: (c) Kayne Ruse 2013-2015 * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages diff --git a/server/doors/door_data.cpp b/server/doors/door_data.cpp index 954365b..c03f5a2 100644 --- a/server/doors/door_data.cpp +++ b/server/doors/door_data.cpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2014 +/* Copyright: (c) Kayne Ruse 2013-2015 * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages diff --git a/server/doors/door_data.hpp b/server/doors/door_data.hpp index 62f5615..fbd009d 100644 --- a/server/doors/door_data.hpp +++ b/server/doors/door_data.hpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2014 +/* Copyright: (c) Kayne Ruse 2013-2015 * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages diff --git a/server/doors/door_manager.cpp b/server/doors/door_manager.cpp index bf264aa..f2c3ebe 100644 --- a/server/doors/door_manager.cpp +++ b/server/doors/door_manager.cpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2014 +/* Copyright: (c) Kayne Ruse 2013-2015 * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages diff --git a/server/doors/door_manager.hpp b/server/doors/door_manager.hpp index bfed8ed..908da7d 100644 --- a/server/doors/door_manager.hpp +++ b/server/doors/door_manager.hpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2014 +/* Copyright: (c) Kayne Ruse 2013-2015 * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages diff --git a/server/entities/entity.cpp b/server/entities/entity.cpp index ebada62..fcfa8aa 100644 --- a/server/entities/entity.cpp +++ b/server/entities/entity.cpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2014 +/* Copyright: (c) Kayne Ruse 2013-2015 * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages diff --git a/server/entities/entity.hpp b/server/entities/entity.hpp index bad1627..e110e80 100644 --- a/server/entities/entity.hpp +++ b/server/entities/entity.hpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2014 +/* Copyright: (c) Kayne Ruse 2013-2015 * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages diff --git a/server/linit.cpp b/server/linit.cpp index c442680..1030490 100644 --- a/server/linit.cpp +++ b/server/linit.cpp @@ -10,7 +10,7 @@ * Modified for use in Tortuga, renamed to linit.cpp * Modifications are released under the zlib license: * - * Copyright: (c) Kayne Ruse 2014 + * Copyright: (c) Kayne Ruse 2013-2015 * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages diff --git a/server/main.cpp b/server/main.cpp index 3cd5b9b..a132c96 100644 --- a/server/main.cpp +++ b/server/main.cpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2013, 2014 +/* Copyright: (c) Kayne Ruse 2013-2015 * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages diff --git a/server/monsters/monster_data.cpp b/server/monsters/monster_data.cpp index 2e7560d..7fda714 100644 --- a/server/monsters/monster_data.cpp +++ b/server/monsters/monster_data.cpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2014 +/* Copyright: (c) Kayne Ruse 2013-2015 * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages diff --git a/server/monsters/monster_data.hpp b/server/monsters/monster_data.hpp index bd45699..034cebb 100644 --- a/server/monsters/monster_data.hpp +++ b/server/monsters/monster_data.hpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2014 +/* Copyright: (c) Kayne Ruse 2013-2015 * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages diff --git a/server/monsters/monster_manager.cpp b/server/monsters/monster_manager.cpp index 1b2f885..dd88668 100644 --- a/server/monsters/monster_manager.cpp +++ b/server/monsters/monster_manager.cpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2014 +/* Copyright: (c) Kayne Ruse 2013-2015 * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages diff --git a/server/monsters/monster_manager.hpp b/server/monsters/monster_manager.hpp index 5fcc56b..de19e2c 100644 --- a/server/monsters/monster_manager.hpp +++ b/server/monsters/monster_manager.hpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2014 +/* Copyright: (c) Kayne Ruse 2013-2015 * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages diff --git a/server/rooms/room_api.cpp b/server/rooms/room_api.cpp index 6edcc38..b40d123 100644 --- a/server/rooms/room_api.cpp +++ b/server/rooms/room_api.cpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2014 +/* Copyright: (c) Kayne Ruse 2013-2015 * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages diff --git a/server/rooms/room_api.hpp b/server/rooms/room_api.hpp index 087c6c2..a091fd3 100644 --- a/server/rooms/room_api.hpp +++ b/server/rooms/room_api.hpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2014 +/* Copyright: (c) Kayne Ruse 2013-2015 * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages diff --git a/server/rooms/room_data.cpp b/server/rooms/room_data.cpp index e21b439..5b7ec8f 100644 --- a/server/rooms/room_data.cpp +++ b/server/rooms/room_data.cpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2014 +/* Copyright: (c) Kayne Ruse 2013-2015 * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages diff --git a/server/rooms/room_data.hpp b/server/rooms/room_data.hpp index 069e84c..c3668fc 100644 --- a/server/rooms/room_data.hpp +++ b/server/rooms/room_data.hpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2014 +/* Copyright: (c) Kayne Ruse 2013-2015 * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages diff --git a/server/rooms/room_manager.cpp b/server/rooms/room_manager.cpp index cefd11a..2d190c9 100644 --- a/server/rooms/room_manager.cpp +++ b/server/rooms/room_manager.cpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2014 +/* Copyright: (c) Kayne Ruse 2013-2015 * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages diff --git a/server/rooms/room_manager.hpp b/server/rooms/room_manager.hpp index 1b659d0..e5ae344 100644 --- a/server/rooms/room_manager.hpp +++ b/server/rooms/room_manager.hpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2014 +/* Copyright: (c) Kayne Ruse 2013-2015 * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages diff --git a/server/rooms/room_manager_api.cpp b/server/rooms/room_manager_api.cpp index 2494605..0a22f46 100644 --- a/server/rooms/room_manager_api.cpp +++ b/server/rooms/room_manager_api.cpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2014 +/* Copyright: (c) Kayne Ruse 2013-2015 * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages diff --git a/server/rooms/room_manager_api.hpp b/server/rooms/room_manager_api.hpp index 1cd042d..bbee066 100644 --- a/server/rooms/room_manager_api.hpp +++ b/server/rooms/room_manager_api.hpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2014 +/* Copyright: (c) Kayne Ruse 2013-2015 * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages diff --git a/server/rooms/room_system_api.cpp b/server/rooms/room_system_api.cpp index 17b6243..0d6fa1a 100644 --- a/server/rooms/room_system_api.cpp +++ b/server/rooms/room_system_api.cpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2014 +/* Copyright: (c) Kayne Ruse 2013-2015 * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages diff --git a/server/rooms/room_system_api.hpp b/server/rooms/room_system_api.hpp index 9006ce5..7a8284a 100644 --- a/server/rooms/room_system_api.hpp +++ b/server/rooms/room_system_api.hpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2014 +/* Copyright: (c) Kayne Ruse 2013-2015 * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages diff --git a/server/server_application.hpp b/server/server_application.hpp index eff3bef..37b33bc 100644 --- a/server/server_application.hpp +++ b/server/server_application.hpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2013, 2014 +/* Copyright: (c) Kayne Ruse 2013-2015 * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages diff --git a/server/server_character_methods.cpp b/server/server_character_methods.cpp index b4ada65..018db97 100644 --- a/server/server_character_methods.cpp +++ b/server/server_character_methods.cpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2014 +/* Copyright: (c) Kayne Ruse 2013-2015 * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages diff --git a/server/server_connections.cpp b/server/server_connections.cpp index 79d8c23..12ceda0 100644 --- a/server/server_connections.cpp +++ b/server/server_connections.cpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2014 +/* Copyright: (c) Kayne Ruse 2013-2015 * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages diff --git a/server/server_data.cpp b/server/server_data.cpp index bd00a8f..c8f3c92 100644 --- a/server/server_data.cpp +++ b/server/server_data.cpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2014 +/* Copyright: (c) Kayne Ruse 2013-2015 * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages diff --git a/server/server_logic.cpp b/server/server_logic.cpp index fdf4eb9..0fc2fe5 100644 --- a/server/server_logic.cpp +++ b/server/server_logic.cpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2014 +/* Copyright: (c) Kayne Ruse 2013-2015 * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages diff --git a/server/server_methods.cpp b/server/server_methods.cpp index d38b53c..1a97a68 100644 --- a/server/server_methods.cpp +++ b/server/server_methods.cpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2014 +/* Copyright: (c) Kayne Ruse 2013-2015 * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages diff --git a/server/server_utilities/manager_interface.hpp b/server/server_utilities/manager_interface.hpp index 8a5161f..c10e6d2 100644 --- a/server/server_utilities/manager_interface.hpp +++ b/server/server_utilities/manager_interface.hpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2014 +/* Copyright: (c) Kayne Ruse 2013-2015 * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages diff --git a/server/server_utilities/sql_tools.cpp b/server/server_utilities/sql_tools.cpp index 19e0ddb..d83acba 100644 --- a/server/server_utilities/sql_tools.cpp +++ b/server/server_utilities/sql_tools.cpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2014 +/* Copyright: (c) Kayne Ruse 2013-2015 * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages diff --git a/server/server_utilities/sql_tools.hpp b/server/server_utilities/sql_tools.hpp index 99d0902..6e019f8 100644 --- a/server/server_utilities/sql_tools.hpp +++ b/server/server_utilities/sql_tools.hpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2014 +/* Copyright: (c) Kayne Ruse 2013-2015 * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages From ee0b7884a8e529213d5ae89d2b38d83f46477339 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Sat, 27 Dec 2014 15:05:34 +1100 Subject: [PATCH 69/73] Partial collision (box prep) complete; untested --- client/scenes/in_world.cpp | 83 ++++++++++++++++++++++++++------------ 1 file changed, 57 insertions(+), 26 deletions(-) diff --git a/client/scenes/in_world.cpp b/client/scenes/in_world.cpp index be7ed3c..03ec1e3 100644 --- a/client/scenes/in_world.cpp +++ b/client/scenes/in_world.cpp @@ -134,26 +134,6 @@ void InWorld::Update() { //free the buffer delete reinterpret_cast(packetBuffer); - //update the map - UpdateMap(); - - //update all entities - for (auto& it : characterMap) { - it.second.Update(); - } - for (auto& it : monsterMap) { - it.second.Update(); - } - - //process collisions - // - - //update the camera - if (localCharacter) { - camera.x = localCharacter->GetOrigin().x - camera.marginX; - camera.y = localCharacter->GetOrigin().y - camera.marginY; - } - //check the connection (heartbeat) if (Clock::now() - lastBeat > std::chrono::seconds(3)) { if (attemptedBeats > 2) { @@ -164,14 +144,65 @@ void InWorld::Update() { SetNextScene(SceneList::DISCONNECTEDSCREEN); ConfigUtility::GetSingleton()["client.disconnectMessage"] = "Error: Lost connection to the server"; } + else { + ServerPacket newPacket; + newPacket.type = SerialPacketType::PING; + network.SendTo(Channels::SERVER, &newPacket); - ServerPacket newPacket; - newPacket.type = SerialPacketType::PING; - network.SendTo(Channels::SERVER, &newPacket); - - attemptedBeats++; - lastBeat = Clock::now(); + attemptedBeats++; + lastBeat = Clock::now(); + } } + + //update all entities + for (auto& it : characterMap) { + it.second.Update(); + } + for (auto& it : monsterMap) { + it.second.Update(); + } + + //update the map + UpdateMap(); + + //skip the rest without a local character + if (!localCharacter) { + return; + } + + //prepare for collisions + BoundingBox wallBounds = {0, 0, tileSheet.GetTileW(), tileSheet.GetTileH()}; + std::list boxList; + + //NOTE: for loops were too dense to work with, so I've just used while loops + //NOTE: this code is complex, and can be replaced with hard-coded relative positions, at the cost of variable-sized sprites/bounding boxes + + //outer loop + wallBounds.x = snapToBase((double)wallBounds.w, localCharacter->GetOrigin().x) - wallBounds.w; + while(wallBounds.x < (localCharacter->GetOrigin() + localCharacter->GetBounds()).x + localCharacter->GetBounds().w) { + //inner loop + wallBounds.y = snapToBase((double)wallBounds.h, localCharacter->GetOrigin().y) - wallBounds.h; + while(wallBounds.y < (localCharacter->GetOrigin() + localCharacter->GetBounds()).y + localCharacter->GetBounds().h) { + //check to see if this tile is solid + if (regionPager.GetSolid(wallBounds.x / wallBounds.w, wallBounds.y / wallBounds.h)) { + //push onto the box set + boxList.push_front(wallBounds); + } + + //increment + wallBounds.y += wallBounds.h; + } + + //increment + wallBounds.x += wallBounds.w; + } + + //process the collisions + std::cout << "boxList.size(): " << boxList.size() << std::endl; + + //update the camera + camera.x = localCharacter->GetOrigin().x - camera.marginX; + camera.y = localCharacter->GetOrigin().y - camera.marginY; } void InWorld::FrameEnd() { From f6e90d7e39fedecb97ece9f955d2088a5231523f Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Sat, 27 Dec 2014 19:25:49 +1100 Subject: [PATCH 70/73] Fixed controls & hotkeys interferring; smoother logouts --- client/scenes/in_world.cpp | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/client/scenes/in_world.cpp b/client/scenes/in_world.cpp index 03ec1e3..9bc3283 100644 --- a/client/scenes/in_world.cpp +++ b/client/scenes/in_world.cpp @@ -137,10 +137,8 @@ void InWorld::Update() { //check the connection (heartbeat) if (Clock::now() - lastBeat > std::chrono::seconds(3)) { if (attemptedBeats > 2) { - //two-step logout - SendLogoutRequest(); + //escape to the disconnect screen SendDisconnectRequest(); - SetNextScene(SceneList::DISCONNECTEDSCREEN); ConfigUtility::GetSingleton()["client.disconnectMessage"] = "Error: Lost connection to the server"; } @@ -244,7 +242,6 @@ void InWorld::Render(SDL_Surface* const screen) { void InWorld::QuitEvent() { //two-step logout - SendLogoutRequest(); SendDisconnectRequest(); SetNextScene(SceneList::QUIT); } @@ -272,9 +269,9 @@ void InWorld::KeyDown(SDL_KeyboardEvent const& key) { //hotkeys switch(key.keysym.sym) { case SDLK_ESCAPE: - //the escape key should actually control menus and stuff + //TODO: the escape key should actually control menus and stuff SendLogoutRequest(); - break; + return; } //character movement @@ -295,6 +292,9 @@ void InWorld::KeyDown(SDL_KeyboardEvent const& key) { case SDLK_d: motion.x += CHARACTER_WALKING_SPEED; break; + default: + //DOCS: prevents wrong keys screwing with character movement + return; } //handle diagonals if (motion.x != 0 && motion.y != 0) { @@ -325,6 +325,9 @@ void InWorld::KeyUp(SDL_KeyboardEvent const& key) { case SDLK_d: motion.x = std::max(0.0, motion.x -= CHARACTER_WALKING_SPEED); break; + default: + //DOCS: prevents wrong keys screwing with character movement + return; } //BUGFIX: reset cardinal direction speed on key release if (motion.x > 0) { @@ -469,30 +472,29 @@ void InWorld::SendShutdownRequest() { } void InWorld::HandleLogoutResponse(ClientPacket* const argPacket) { + if (localCharacter) { + characterMap.erase(characterIndex); + localCharacter = nullptr; + } + accountIndex = -1; characterIndex = -1; //reset the camera - camera.x = camera.y = 0; camera.marginX = camera.marginY = 0; + //because, why not? I guess... SendDisconnectRequest(); } void InWorld::HandleDisconnectResponse(ClientPacket* const argPacket) { + HandleLogoutResponse(argPacket);//shortcut SetNextScene(SceneList::DISCONNECTEDSCREEN); ConfigUtility::GetSingleton()["client.disconnectMessage"] = "You have successfully logged out"; } void InWorld::HandleDisconnectForced(ClientPacket* const argPacket) { - //clear the local data - accountIndex = -1; - characterIndex = -1; - - //reset the camera - camera.x = camera .y = 0; - camera.marginX = camera.marginY = 0; - + HandleDisconnectResponse(argPacket);//shortcut SetNextScene(SceneList::DISCONNECTEDSCREEN); ConfigUtility::GetSingleton()["client.disconnectMessage"] = "You have been forcibly disconnected by the server"; } From 33c3143de95d515a4de15682564dd97412480e2c Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Sat, 27 Dec 2014 20:31:09 +1100 Subject: [PATCH 71/73] Added unary negative to Vector2 This is the only fragment I'm bothering to salvage from the collisions branch. --- common/utilities/vector2.hpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/common/utilities/vector2.hpp b/common/utilities/vector2.hpp index e1688d4..00f4a06 100644 --- a/common/utilities/vector2.hpp +++ b/common/utilities/vector2.hpp @@ -92,6 +92,10 @@ public: return ret; } + //unary operators + Vector2 operator-() { return {-x, -y}; } + + //comparison operators bool operator==(Vector2 v) { return (x == v.x && y == v.y); } bool operator!=(Vector2 v) { return (x != v.x || y != v.y); } From b67e85e87ba10f6e0b4bcc0bf655b98540d48b47 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Sat, 27 Dec 2014 21:00:00 +1100 Subject: [PATCH 72/73] Moved some messy code from InWorld::Update() to utility methods --- client/scenes/in_world.cpp | 97 +++++++++++++++++++++----------------- client/scenes/in_world.hpp | 3 ++ 2 files changed, 57 insertions(+), 43 deletions(-) diff --git a/client/scenes/in_world.cpp b/client/scenes/in_world.cpp index 9bc3283..a57ab29 100644 --- a/client/scenes/in_world.cpp +++ b/client/scenes/in_world.cpp @@ -134,23 +134,8 @@ void InWorld::Update() { //free the buffer delete reinterpret_cast(packetBuffer); - //check the connection (heartbeat) - if (Clock::now() - lastBeat > std::chrono::seconds(3)) { - if (attemptedBeats > 2) { - //escape to the disconnect screen - SendDisconnectRequest(); - SetNextScene(SceneList::DISCONNECTEDSCREEN); - ConfigUtility::GetSingleton()["client.disconnectMessage"] = "Error: Lost connection to the server"; - } - else { - ServerPacket newPacket; - newPacket.type = SerialPacketType::PING; - network.SendTo(Channels::SERVER, &newPacket); - - attemptedBeats++; - lastBeat = Clock::now(); - } - } + //heartbeat system + CheckHeartBeat(); //update all entities for (auto& it : characterMap) { @@ -168,32 +153,8 @@ void InWorld::Update() { return; } - //prepare for collisions - BoundingBox wallBounds = {0, 0, tileSheet.GetTileW(), tileSheet.GetTileH()}; - std::list boxList; - - //NOTE: for loops were too dense to work with, so I've just used while loops - //NOTE: this code is complex, and can be replaced with hard-coded relative positions, at the cost of variable-sized sprites/bounding boxes - - //outer loop - wallBounds.x = snapToBase((double)wallBounds.w, localCharacter->GetOrigin().x) - wallBounds.w; - while(wallBounds.x < (localCharacter->GetOrigin() + localCharacter->GetBounds()).x + localCharacter->GetBounds().w) { - //inner loop - wallBounds.y = snapToBase((double)wallBounds.h, localCharacter->GetOrigin().y) - wallBounds.h; - while(wallBounds.y < (localCharacter->GetOrigin() + localCharacter->GetBounds()).y + localCharacter->GetBounds().h) { - //check to see if this tile is solid - if (regionPager.GetSolid(wallBounds.x / wallBounds.w, wallBounds.y / wallBounds.h)) { - //push onto the box set - boxList.push_front(wallBounds); - } - - //increment - wallBounds.y += wallBounds.h; - } - - //increment - wallBounds.x += wallBounds.w; - } + //get the collidable boxes + std::list boxList = GenerateCollisionGrid(localCharacter, tileSheet.GetTileW(), tileSheet.GetTileH()); //process the collisions std::cout << "boxList.size(): " << boxList.size() << std::endl; @@ -499,6 +460,26 @@ void InWorld::HandleDisconnectForced(ClientPacket* const argPacket) { ConfigUtility::GetSingleton()["client.disconnectMessage"] = "You have been forcibly disconnected by the server"; } +void InWorld::CheckHeartBeat() { + //check the connection (heartbeat) + if (Clock::now() - lastBeat > std::chrono::seconds(3)) { + if (attemptedBeats > 2) { + //escape to the disconnect screen + SendDisconnectRequest(); + SetNextScene(SceneList::DISCONNECTEDSCREEN); + ConfigUtility::GetSingleton()["client.disconnectMessage"] = "Error: Lost connection to the server"; + } + else { + ServerPacket newPacket; + newPacket.type = SerialPacketType::PING; + network.SendTo(Channels::SERVER, &newPacket); + + attemptedBeats++; + lastBeat = Clock::now(); + } + } +} + //------------------------- //map management //------------------------- @@ -728,4 +709,34 @@ void InWorld::SendLocalCharacterMotion() { newPacket.motion = localCharacter->GetMotion(); network.SendTo(Channels::SERVER, &newPacket); +} + +std::list InWorld::GenerateCollisionGrid(Entity* ptr, int tileWidth, int tileHeight) { + //prepare for collisions + BoundingBox wallBounds = {0, 0, tileWidth, tileHeight}; + std::list boxList; + + //NOTE: for loops were too dense to work with, so I've just used while loops + + //outer loop + wallBounds.x = snapToBase((double)wallBounds.w, ptr->GetOrigin().x) - wallBounds.w; + while(wallBounds.x < (ptr->GetOrigin() + ptr->GetBounds()).x + ptr->GetBounds().w) { + //inner loop + wallBounds.y = snapToBase((double)wallBounds.h, ptr->GetOrigin().y) - wallBounds.h; + while(wallBounds.y < (ptr->GetOrigin() + ptr->GetBounds()).y + ptr->GetBounds().h) { + //check to see if this tile is solid + if (regionPager.GetSolid(wallBounds.x / wallBounds.w, wallBounds.y / wallBounds.h)) { + //push onto the box set + boxList.push_front(wallBounds); + } + + //increment + wallBounds.y += wallBounds.h; + } + + //increment + wallBounds.x += wallBounds.w; + } + + return std::move(boxList); } \ No newline at end of file diff --git a/client/scenes/in_world.hpp b/client/scenes/in_world.hpp index cacf2dd..7ce1288 100644 --- a/client/scenes/in_world.hpp +++ b/client/scenes/in_world.hpp @@ -85,6 +85,8 @@ protected: void HandleDisconnectResponse(ClientPacket* const); void HandleDisconnectForced(ClientPacket* const); + void CheckHeartBeat(); + //map management void SendRegionRequest(int roomIndex, int x, int y); void HandleRegionContent(RegionPacket* const); @@ -100,6 +102,7 @@ protected: //player movement void SendLocalCharacterMotion(); + std::list GenerateCollisionGrid(Entity*, int tileWidth, int tileHeight); //indexes int& clientIndex; From 8708cfbee0d645d74a37f6fc7b35687e2f1f7650 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Sat, 27 Dec 2014 23:16:48 +1100 Subject: [PATCH 73/73] I give up, I'm just using the stop-dead system for now. --- client/entities/local_character.cpp | 12 ++++++++++++ client/entities/local_character.hpp | 6 ++++++ client/scenes/in_world.cpp | 19 ++++++++++++++++--- 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/client/entities/local_character.cpp b/client/entities/local_character.cpp index 201ef48..16c1eff 100644 --- a/client/entities/local_character.cpp +++ b/client/entities/local_character.cpp @@ -21,3 +21,15 @@ */ #include "local_character.hpp" +#include + +bool LocalCharacter::ProcessCollisionGrid(std::list boxList) { + for(auto& box : boxList) { + if (box.CheckOverlap(origin + bounds)) { + origin -= motion; + motion = {0, 0}; + return true; + } + } + return false; +} \ No newline at end of file diff --git a/client/entities/local_character.hpp b/client/entities/local_character.hpp index 4493fb4..a462ddc 100644 --- a/client/entities/local_character.hpp +++ b/client/entities/local_character.hpp @@ -23,12 +23,18 @@ #define LOCALCHARACTER_HPP_ #include "base_character.hpp" +#include "bounding_box.hpp" +#include "vector2.hpp" + +#include class LocalCharacter: public BaseCharacter { public: LocalCharacter() = default; virtual ~LocalCharacter() = default; + bool ProcessCollisionGrid(std::list); + private: //NOTE: NO MEMBERS }; diff --git a/client/scenes/in_world.cpp b/client/scenes/in_world.cpp index a57ab29..7dff310 100644 --- a/client/scenes/in_world.cpp +++ b/client/scenes/in_world.cpp @@ -157,7 +157,10 @@ void InWorld::Update() { std::list boxList = GenerateCollisionGrid(localCharacter, tileSheet.GetTileW(), tileSheet.GetTileH()); //process the collisions - std::cout << "boxList.size(): " << boxList.size() << std::endl; + if (localCharacter->ProcessCollisionGrid(boxList)) { + localCharacter->CorrectSprite(); + SendLocalCharacterMotion(); + } //update the camera camera.x = localCharacter->GetOrigin().x - camera.marginX; @@ -672,6 +675,11 @@ void InWorld::HandleCharacterSetRoom(CharacterPacket* const argPacket) { } void InWorld::HandleCharacterSetOrigin(CharacterPacket* const argPacket) { + //TODO: Authentication + if (argPacket->characterIndex == characterIndex) { + return; + } + //check that this character exists std::map::iterator characterIt = characterMap.find(argPacket->characterIndex); if (characterIt != characterMap.end()) { @@ -683,6 +691,11 @@ void InWorld::HandleCharacterSetOrigin(CharacterPacket* const argPacket) { } void InWorld::HandleCharacterSetMotion(CharacterPacket* const argPacket) { + //TODO: Authentication + if (argPacket->characterIndex == characterIndex) { + return; + } + //check that this character exists std::map::iterator characterIt = characterMap.find(argPacket->characterIndex); if (characterIt != characterMap.end()) { @@ -719,10 +732,10 @@ std::list InWorld::GenerateCollisionGrid(Entity* ptr, int tileWidth //NOTE: for loops were too dense to work with, so I've just used while loops //outer loop - wallBounds.x = snapToBase((double)wallBounds.w, ptr->GetOrigin().x) - wallBounds.w; + wallBounds.x = snapToBase((double)wallBounds.w, ptr->GetOrigin().x); while(wallBounds.x < (ptr->GetOrigin() + ptr->GetBounds()).x + ptr->GetBounds().w) { //inner loop - wallBounds.y = snapToBase((double)wallBounds.h, ptr->GetOrigin().y) - wallBounds.h; + wallBounds.y = snapToBase((double)wallBounds.h, ptr->GetOrigin().y); while(wallBounds.y < (ptr->GetOrigin() + ptr->GetBounds()).y + ptr->GetBounds().h) { //check to see if this tile is solid if (regionPager.GetSolid(wallBounds.x / wallBounds.w, wallBounds.y / wallBounds.h)) {