diff --git a/Makefile b/Makefile index fb0328f..58578a8 100644 --- a/Makefile +++ b/Makefile @@ -37,6 +37,12 @@ CHDR=\ vendor/bcrypt/winbcrypt.h\ CXXSRC=\ + src/core/CNProtocol.cpp\ + src/core/CNShared.cpp\ + src/core/Packets.cpp\ + src/servers/CNLoginServer.cpp\ + src/servers/CNShardServer.cpp\ + src/servers/Monitor.cpp\ src/db/init.cpp\ src/db/login.cpp\ src/db/shard.cpp\ @@ -44,11 +50,6 @@ CXXSRC=\ src/db/email.cpp\ src/Chat.cpp\ src/CustomCommands.cpp\ - src/CNLoginServer.cpp\ - src/CNProtocol.cpp\ - src/CNShardServer.cpp\ - src/CNShared.cpp\ - src/Defines.cpp\ src/Email.cpp\ src/main.cpp\ src/Missions.cpp\ @@ -67,28 +68,29 @@ CXXSRC=\ src/Chunking.cpp\ src/Buddies.cpp\ src/Groups.cpp\ - src/Monitor.cpp\ src/Racing.cpp\ src/Vendor.cpp\ src/Trading.cpp\ # headers (for timestamp purposes) CXXHDR=\ + src/core/CNProtocol.hpp\ + src/core/CNShared.hpp\ + src/core/CNStructs.hpp\ + src/core/Defines.hpp\ + src/core/Core.hpp\ + src/servers/CNLoginServer.hpp\ + src/servers/CNShardServer.hpp\ + src/servers/Monitor.hpp\ + src/db/Database.hpp\ + src/db/internal.hpp\ vendor/bcrypt/BCrypt.hpp\ vendor/INIReader.hpp\ vendor/JSON.hpp\ vendor/INIReader.hpp\ vendor/JSON.hpp\ - src/db/Database.hpp\ - src/db/internal.hpp\ src/Chat.hpp\ src/CustomCommands.hpp\ - src/CNLoginServer.hpp\ - src/CNProtocol.hpp\ - src/CNShardServer.hpp\ - src/CNShared.hpp\ - src/CNStructs.hpp\ - src/Defines.hpp\ src/Email.hpp\ src/Missions.hpp\ src/MobAI.hpp\ @@ -107,7 +109,6 @@ CXXHDR=\ src/Chunking.hpp\ src/Buddies.hpp\ src/Groups.hpp\ - src/Monitor.hpp\ src/Racing.hpp\ src/Vendor.hpp\ src/Trading.hpp\ diff --git a/src/Abilities.hpp b/src/Abilities.hpp index ebb91d3..fc3ea76 100644 --- a/src/Abilities.hpp +++ b/src/Abilities.hpp @@ -1,6 +1,6 @@ #pragma once -#include "CNProtocol.hpp" +#include "core/Core.hpp" #include "Combat.hpp" typedef void (*PowerHandler)(CNSocket*, std::vector, int16_t, int16_t, int16_t, int16_t, int16_t, int32_t, int16_t); diff --git a/src/Buddies.cpp b/src/Buddies.cpp index 29f6583..e51ed98 100644 --- a/src/Buddies.cpp +++ b/src/Buddies.cpp @@ -1,5 +1,4 @@ -#include "CNShardServer.hpp" -#include "CNStructs.hpp" +#include "servers/CNShardServer.hpp" #include "Buddies.hpp" #include "PlayerManager.hpp" #include "Buddies.hpp" diff --git a/src/Buddies.hpp b/src/Buddies.hpp index e7b5b18..6144e6d 100644 --- a/src/Buddies.hpp +++ b/src/Buddies.hpp @@ -1,9 +1,8 @@ #pragma once #include "Player.hpp" -#include "CNProtocol.hpp" -#include "CNStructs.hpp" -#include "CNProtocol.hpp" +#include "core/Core.hpp" +#include "core/Core.hpp" namespace Buddies { void init(); diff --git a/src/BuiltinCommands.hpp b/src/BuiltinCommands.hpp index 558178f..a0ff9c7 100644 --- a/src/BuiltinCommands.hpp +++ b/src/BuiltinCommands.hpp @@ -1,6 +1,6 @@ #pragma once -#include "CNProtocol.hpp" +#include "core/Core.hpp" namespace BuiltinCommands { void init(); diff --git a/src/Chat.hpp b/src/Chat.hpp index a2e4111..acaca06 100644 --- a/src/Chat.hpp +++ b/src/Chat.hpp @@ -2,7 +2,7 @@ #define CMD_PREFIX '/' -#include "CNShardServer.hpp" +#include "servers/CNShardServer.hpp" namespace Chat { extern std::vector dump; diff --git a/src/Chunking.hpp b/src/Chunking.hpp index 3dd464c..248181a 100644 --- a/src/Chunking.hpp +++ b/src/Chunking.hpp @@ -1,7 +1,6 @@ #pragma once -#include "CNProtocol.hpp" -#include "CNStructs.hpp" +#include "core/Core.hpp" #include #include diff --git a/src/Combat.hpp b/src/Combat.hpp index ef4d0ec..f7ee0f9 100644 --- a/src/Combat.hpp +++ b/src/Combat.hpp @@ -1,8 +1,7 @@ #pragma once -#include "CNProtocol.hpp" -#include "CNShared.hpp" -#include "CNShardServer.hpp" +#include "core/Core.hpp" +#include "servers/CNShardServer.hpp" #include "NPC.hpp" #include "MobAI.hpp" diff --git a/src/CustomCommands.hpp b/src/CustomCommands.hpp index 29d8405..62103da 100644 --- a/src/CustomCommands.hpp +++ b/src/CustomCommands.hpp @@ -1,6 +1,6 @@ #pragma once -#include "CNProtocol.hpp" +#include "core/Core.hpp" namespace CustomCommands { void init(); diff --git a/src/Email.cpp b/src/Email.cpp index db183e8..23242df 100644 --- a/src/Email.cpp +++ b/src/Email.cpp @@ -1,8 +1,7 @@ #include "Email.hpp" -#include "CNProtocol.hpp" -#include "CNStructs.hpp" -#include "CNShardServer.hpp" +#include "core/Core.hpp" +#include "servers/CNShardServer.hpp" #include "db/Database.hpp" #include "PlayerManager.hpp" diff --git a/src/Groups.cpp b/src/Groups.cpp index ebbf2db..f38c0f8 100644 --- a/src/Groups.cpp +++ b/src/Groups.cpp @@ -1,5 +1,4 @@ -#include "CNShardServer.hpp" -#include "CNStructs.hpp" +#include "servers/CNShardServer.hpp" #include "PlayerManager.hpp" #include "Groups.hpp" #include "Nanos.hpp" diff --git a/src/Groups.hpp b/src/Groups.hpp index 8bebf44..248b74c 100644 --- a/src/Groups.hpp +++ b/src/Groups.hpp @@ -1,9 +1,8 @@ #pragma once #include "Player.hpp" -#include "CNProtocol.hpp" -#include "CNStructs.hpp" -#include "CNShardServer.hpp" +#include "core/Core.hpp" +#include "servers/CNShardServer.hpp" #include #include diff --git a/src/Items.cpp b/src/Items.cpp index 9c4f497..751f332 100644 --- a/src/Items.cpp +++ b/src/Items.cpp @@ -1,5 +1,4 @@ -#include "CNShardServer.hpp" -#include "CNStructs.hpp" +#include "servers/CNShardServer.hpp" #include "Items.hpp" #include "PlayerManager.hpp" #include "Nanos.hpp" diff --git a/src/Items.hpp b/src/Items.hpp index 5cc7f51..d2a6a4b 100644 --- a/src/Items.hpp +++ b/src/Items.hpp @@ -1,6 +1,6 @@ #pragma once -#include "CNShardServer.hpp" +#include "servers/CNShardServer.hpp" #include "Player.hpp" #include "MobAI.hpp" diff --git a/src/Missions.cpp b/src/Missions.cpp index 84a998d..41c7f1e 100644 --- a/src/Missions.cpp +++ b/src/Missions.cpp @@ -1,5 +1,4 @@ -#include "CNShardServer.hpp" -#include "CNStructs.hpp" +#include "servers/CNShardServer.hpp" #include "Missions.hpp" #include "PlayerManager.hpp" #include "Nanos.hpp" diff --git a/src/Missions.hpp b/src/Missions.hpp index 1adcfd4..6dd95bd 100644 --- a/src/Missions.hpp +++ b/src/Missions.hpp @@ -1,6 +1,6 @@ #pragma once -#include "CNShardServer.hpp" +#include "servers/CNShardServer.hpp" #include "Player.hpp" #include "JSON.hpp" diff --git a/src/MobAI.hpp b/src/MobAI.hpp index ff52f69..4c3cec1 100644 --- a/src/MobAI.hpp +++ b/src/MobAI.hpp @@ -1,6 +1,6 @@ #pragma once -#include "CNProtocol.hpp" +#include "core/Core.hpp" #include "NPCManager.hpp" enum class MobState { diff --git a/src/NPC.hpp b/src/NPC.hpp index 24575af..255a55f 100644 --- a/src/NPC.hpp +++ b/src/NPC.hpp @@ -1,6 +1,5 @@ #pragma once -#include "CNStructs.hpp" #include "Chunking.hpp" class BaseNPC { diff --git a/src/NPCManager.hpp b/src/NPCManager.hpp index 4ff2e1f..a561765 100644 --- a/src/NPCManager.hpp +++ b/src/NPCManager.hpp @@ -1,6 +1,6 @@ #pragma once -#include "CNProtocol.hpp" +#include "core/Core.hpp" #include "PlayerManager.hpp" #include "NPC.hpp" diff --git a/src/Nanos.cpp b/src/Nanos.cpp index 4106c7d..227df37 100644 --- a/src/Nanos.cpp +++ b/src/Nanos.cpp @@ -1,5 +1,4 @@ -#include "CNShardServer.hpp" -#include "CNStructs.hpp" +#include "servers/CNShardServer.hpp" #include "Nanos.hpp" #include "PlayerManager.hpp" #include "NPCManager.hpp" diff --git a/src/Nanos.hpp b/src/Nanos.hpp index debd030..c41318e 100644 --- a/src/Nanos.hpp +++ b/src/Nanos.hpp @@ -4,7 +4,7 @@ #include #include "Player.hpp" -#include "CNShardServer.hpp" +#include "servers/CNShardServer.hpp" struct NanoData { int style; diff --git a/src/Player.hpp b/src/Player.hpp index 0d6fbb7..ee11559 100644 --- a/src/Player.hpp +++ b/src/Player.hpp @@ -3,8 +3,7 @@ #include #include -#include "CNProtocol.hpp" -#include "CNStructs.hpp" +#include "core/Core.hpp" #include "Chunking.hpp" #define ACTIVE_MISSION_COUNT 6 diff --git a/src/PlayerManager.cpp b/src/PlayerManager.cpp index 70e430c..9f4b345 100644 --- a/src/PlayerManager.cpp +++ b/src/PlayerManager.cpp @@ -1,12 +1,14 @@ +#include "core/Core.hpp" +#include "core/CNShared.hpp" +#include "servers/CNShardServer.hpp" +#include "db/Database.hpp" #include "PlayerManager.hpp" #include "NPCManager.hpp" -#include "CNShardServer.hpp" #include "Missions.hpp" #include "Items.hpp" #include "Nanos.hpp" #include "Groups.hpp" #include "Chat.hpp" -#include "db/Database.hpp" #include "Buddies.hpp" #include "Combat.hpp" #include "Racing.hpp" diff --git a/src/PlayerManager.hpp b/src/PlayerManager.hpp index 2cdce12..616db50 100644 --- a/src/PlayerManager.hpp +++ b/src/PlayerManager.hpp @@ -1,9 +1,8 @@ #pragma once #include "Player.hpp" -#include "CNProtocol.hpp" -#include "CNStructs.hpp" -#include "CNShardServer.hpp" +#include "core/Core.hpp" +#include "servers/CNShardServer.hpp" #include "Chunking.hpp" #include diff --git a/src/PlayerMovement.cpp b/src/PlayerMovement.cpp index ecc31d5..03620f7 100644 --- a/src/PlayerMovement.cpp +++ b/src/PlayerMovement.cpp @@ -1,6 +1,6 @@ #include "PlayerMovement.hpp" #include "PlayerManager.hpp" -#include "CNProtocol.hpp" +#include "core/Core.hpp" static void movePlayer(CNSocket* sock, CNPacketData* data) { if (data->size != sizeof(sP_CL2FE_REQ_PC_MOVE)) diff --git a/src/Racing.cpp b/src/Racing.cpp index a0b7406..a5cf0cd 100644 --- a/src/Racing.cpp +++ b/src/Racing.cpp @@ -1,5 +1,4 @@ -#include "CNShardServer.hpp" -#include "CNStructs.hpp" +#include "servers/CNShardServer.hpp" #include "Racing.hpp" #include "PlayerManager.hpp" #include "Missions.hpp" diff --git a/src/Racing.hpp b/src/Racing.hpp index a211537..ece2dc5 100644 --- a/src/Racing.hpp +++ b/src/Racing.hpp @@ -1,6 +1,6 @@ #pragma once -#include "CNShardServer.hpp" +#include "servers/CNShardServer.hpp" struct EPInfo { int zoneX, zoneY, EPID, maxScore, maxTime; diff --git a/src/Transport.cpp b/src/Transport.cpp index 18fbbe0..7cc6200 100644 --- a/src/Transport.cpp +++ b/src/Transport.cpp @@ -1,5 +1,4 @@ -#include "CNShardServer.hpp" -#include "CNStructs.hpp" +#include "servers/CNShardServer.hpp" #include "PlayerManager.hpp" #include "Nanos.hpp" #include "Transport.hpp" diff --git a/src/Transport.hpp b/src/Transport.hpp index 58831b7..dca36b6 100644 --- a/src/Transport.hpp +++ b/src/Transport.hpp @@ -1,6 +1,6 @@ #pragma once -#include "CNShardServer.hpp" +#include "servers/CNShardServer.hpp" #include "NPCManager.hpp" #include diff --git a/src/Vendor.hpp b/src/Vendor.hpp index 6ef0de7..2a2c72f 100644 --- a/src/Vendor.hpp +++ b/src/Vendor.hpp @@ -1,8 +1,7 @@ #pragma once -#include "CNProtocol.hpp" -#include "CNStructs.hpp" -#include "CNShardServer.hpp" +#include "core/Core.hpp" +#include "servers/CNShardServer.hpp" #include "Items.hpp" #include "PlayerManager.hpp" diff --git a/src/CNProtocol.cpp b/src/core/CNProtocol.cpp similarity index 99% rename from src/CNProtocol.cpp rename to src/core/CNProtocol.cpp index c91bb71..e64558c 100644 --- a/src/CNProtocol.cpp +++ b/src/core/CNProtocol.cpp @@ -1,4 +1,4 @@ -#include "CNProtocol.hpp" +#include "core/CNProtocol.hpp" #include "CNStructs.hpp" #include @@ -469,7 +469,7 @@ void CNServer::printPacket(CNPacketData *data, int type) { return; } - std::cout << "OpenFusion: received " << Defines::p2str(type, data->type) << " (" << data->type << ")" << std::endl; + std::cout << "OpenFusion: received " << Packets::p2str(type, data->type) << " (" << data->type << ")" << std::endl; } bool CNServer::checkExtraSockets(int i) { return false; } // stubbed diff --git a/src/CNProtocol.hpp b/src/core/CNProtocol.hpp similarity index 100% rename from src/CNProtocol.hpp rename to src/core/CNProtocol.hpp diff --git a/src/CNShared.cpp b/src/core/CNShared.cpp similarity index 96% rename from src/CNShared.cpp rename to src/core/CNShared.cpp index 7054fd3..d6859a3 100644 --- a/src/CNShared.cpp +++ b/src/core/CNShared.cpp @@ -1,4 +1,4 @@ -#include "CNShared.hpp" +#include "core/CNShared.hpp" #if defined(__MINGW32__) && !defined(_GLIBCXX_HAS_GTHREADS) #include "mingw/mingw.mutex.h" diff --git a/src/CNShared.hpp b/src/core/CNShared.hpp similarity index 95% rename from src/CNShared.hpp rename to src/core/CNShared.hpp index 572661a..3382b4e 100644 --- a/src/CNShared.hpp +++ b/src/core/CNShared.hpp @@ -1,5 +1,5 @@ /* - * CNShared.hpp + * core/CNShared.hpp * There's some data shared between the Login Server and the Shard Server. Of course all of this needs to be thread-safe. No mucking about on this one! */ diff --git a/src/CNStructs.hpp b/src/core/CNStructs.hpp similarity index 100% rename from src/CNStructs.hpp rename to src/core/CNStructs.hpp diff --git a/src/core/Core.hpp b/src/core/Core.hpp new file mode 100644 index 0000000..2c615df --- /dev/null +++ b/src/core/Core.hpp @@ -0,0 +1,11 @@ +#pragma once + +/* + * Convenience header. + * + * We omit CNShared, as it's only relevant to the Login and Shard servers + * and the PlayerManager. We omit Defines, as CNProtocol already includes it. + */ + +#include "core/CNProtocol.hpp" +#include "core/CNStructs.hpp" diff --git a/src/Defines.hpp b/src/core/Defines.hpp similarity index 99% rename from src/Defines.hpp rename to src/core/Defines.hpp index 040372e..872c01e 100644 --- a/src/Defines.hpp +++ b/src/core/Defines.hpp @@ -941,6 +941,6 @@ enum { N_PACKETS = N_CL2LS + N_CL2FE + N_FE2CL + N_LS2CL }; -namespace Defines { +namespace Packets { std::string p2str(int type, int val); } diff --git a/src/Defines.cpp b/src/core/Packets.cpp similarity index 99% rename from src/Defines.cpp rename to src/core/Packets.cpp index 8552a43..1be214e 100644 --- a/src/Defines.cpp +++ b/src/core/Packets.cpp @@ -200,7 +200,7 @@ PacketMap cl2fe_map[] = { STRINGIFY(P_CL2FE_REQ_PC_ITEM_ENCHANT), }; -std::string Defines::p2str(int type, int val) { +std::string Packets::p2str(int type, int val) { switch (type) { case CL2LS: val = val - CL2LS - 1; diff --git a/src/db/Database.hpp b/src/db/Database.hpp index d1797cd..89bc315 100644 --- a/src/db/Database.hpp +++ b/src/db/Database.hpp @@ -1,6 +1,7 @@ #pragma once -#include "CNStructs.hpp" + #include "Player.hpp" + #include #include diff --git a/src/main.cpp b/src/main.cpp index 643e82a..fdbd73f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,5 +1,5 @@ -#include "CNLoginServer.hpp" -#include "CNShardServer.hpp" +#include "servers/CNLoginServer.hpp" +#include "servers/CNShardServer.hpp" #include "PlayerManager.hpp" #include "PlayerMovement.hpp" #include "BuiltinCommands.hpp" @@ -16,7 +16,7 @@ #include "db/Database.hpp" #include "TableData.hpp" #include "Groups.hpp" -#include "Monitor.hpp" +#include "servers/Monitor.hpp" #include "Racing.hpp" #include "Trading.hpp" #include "Email.hpp" diff --git a/src/CNLoginServer.cpp b/src/servers/CNLoginServer.cpp similarity index 99% rename from src/CNLoginServer.cpp rename to src/servers/CNLoginServer.cpp index 838fdb2..9ffbedd 100644 --- a/src/CNLoginServer.cpp +++ b/src/servers/CNLoginServer.cpp @@ -1,6 +1,5 @@ -#include "CNLoginServer.hpp" -#include "CNShared.hpp" -#include "CNStructs.hpp" +#include "servers/CNLoginServer.hpp" +#include "core/CNShared.hpp" #include "db/Database.hpp" #include "PlayerManager.hpp" #include "Items.hpp" @@ -63,7 +62,7 @@ void CNLoginServer::handlePacket(CNSocket* sock, CNPacketData* data) { } default: if (settings::VERBOSITY) - std::cerr << "OpenFusion: LOGIN UNIMPLM ERR. PacketType: " << Defines::p2str(CL2LS, data->type) << " (" << data->type << ")" << std::endl; + std::cerr << "OpenFusion: LOGIN UNIMPLM ERR. PacketType: " << Packets::p2str(CL2LS, data->type) << " (" << data->type << ")" << std::endl; break; /* * Unimplemented CL2LS packets: diff --git a/src/CNLoginServer.hpp b/src/servers/CNLoginServer.hpp similarity index 97% rename from src/CNLoginServer.hpp rename to src/servers/CNLoginServer.hpp index aba07ab..6547b44 100644 --- a/src/CNLoginServer.hpp +++ b/src/servers/CNLoginServer.hpp @@ -1,7 +1,6 @@ #pragma once -#include "CNProtocol.hpp" -#include "Defines.hpp" +#include "core/Core.hpp" #include "Player.hpp" #include diff --git a/src/CNShardServer.cpp b/src/servers/CNShardServer.cpp similarity index 95% rename from src/CNShardServer.cpp rename to src/servers/CNShardServer.cpp index 069166a..1b13e72 100644 --- a/src/CNShardServer.cpp +++ b/src/servers/CNShardServer.cpp @@ -1,12 +1,11 @@ -#include "CNProtocol.hpp" -#include "CNStructs.hpp" -#include "CNShardServer.hpp" +#include "core/Core.hpp" +#include "db/Database.hpp" +#include "servers/Monitor.hpp" +#include "servers/CNShardServer.hpp" #include "PlayerManager.hpp" #include "MobAI.hpp" -#include "CNShared.hpp" +#include "core/CNShared.hpp" #include "settings.hpp" -#include "db/Database.hpp" -#include "Monitor.hpp" #include "TableData.hpp" // for flush() #include @@ -33,7 +32,7 @@ void CNShardServer::handlePacket(CNSocket* sock, CNPacketData* data) { if (ShardPackets.find(data->type) != ShardPackets.end()) ShardPackets[data->type](sock, data); else if (settings::VERBOSITY > 0) - std::cerr << "OpenFusion: SHARD UNIMPLM ERR. PacketType: " << Defines::p2str(CL2FE, data->type) << " (" << data->type << ")" << std::endl; + std::cerr << "OpenFusion: SHARD UNIMPLM ERR. PacketType: " << Packets::p2str(CL2FE, data->type) << " (" << data->type << ")" << std::endl; if (PlayerManager::players.find(sock) != PlayerManager::players.end()) PlayerManager::players[sock]->lastHeartbeat = getTime(); diff --git a/src/CNShardServer.hpp b/src/servers/CNShardServer.hpp similarity index 94% rename from src/CNShardServer.hpp rename to src/servers/CNShardServer.hpp index 6e1d3f1..a16f38a 100644 --- a/src/CNShardServer.hpp +++ b/src/servers/CNShardServer.hpp @@ -1,7 +1,6 @@ #pragma once -#include "CNProtocol.hpp" -#include "Defines.hpp" +#include "core/Core.hpp" #include diff --git a/src/Monitor.cpp b/src/servers/Monitor.cpp similarity index 98% rename from src/Monitor.cpp rename to src/servers/Monitor.cpp index e526159..60d701b 100644 --- a/src/Monitor.cpp +++ b/src/servers/Monitor.cpp @@ -1,8 +1,7 @@ -#include "CNShardServer.hpp" +#include "servers/CNShardServer.hpp" #include "PlayerManager.hpp" #include "Chat.hpp" -#include "CNStructs.hpp" -#include "Monitor.hpp" +#include "servers/Monitor.hpp" #include "settings.hpp" #include diff --git a/src/Monitor.hpp b/src/servers/Monitor.hpp similarity index 83% rename from src/Monitor.hpp rename to src/servers/Monitor.hpp index 41e3eb9..dd40877 100644 --- a/src/Monitor.hpp +++ b/src/servers/Monitor.hpp @@ -1,6 +1,6 @@ #pragma once -#include "CNProtocol.hpp" +#include "core/Core.hpp" #include #include diff --git a/src/settings.cpp b/src/settings.cpp index 1c77c2f..e7f0db8 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -1,7 +1,6 @@ #include #include "settings.hpp" #include "INIReader.hpp" -#include "CNStructs.hpp" // for ACADEMY // defaults :) int settings::VERBOSITY = 1;