[refactor] Move files to core/ and servers/ subdirectories

CNProtocol, CNShared, CNStructs and Defines are now in core/.
CNLoginServer, CNShardServer and Monitor are now in servers/.

core/Core.hpp wraps all the core headers except for CNShared.hpp.

Defines.cpp has been renamed to Packets.cpp, and so has its
corresponding namespace, but not the header file. This is in preparation
for upcoming changes.
This commit is contained in:
dongresource 2021-03-17 20:07:40 +01:00
parent e9bc2fe561
commit a55a34e09a
47 changed files with 89 additions and 96 deletions

View File

@ -37,6 +37,12 @@ CHDR=\
vendor/bcrypt/winbcrypt.h\ vendor/bcrypt/winbcrypt.h\
CXXSRC=\ 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/init.cpp\
src/db/login.cpp\ src/db/login.cpp\
src/db/shard.cpp\ src/db/shard.cpp\
@ -44,11 +50,6 @@ CXXSRC=\
src/db/email.cpp\ src/db/email.cpp\
src/Chat.cpp\ src/Chat.cpp\
src/CustomCommands.cpp\ src/CustomCommands.cpp\
src/CNLoginServer.cpp\
src/CNProtocol.cpp\
src/CNShardServer.cpp\
src/CNShared.cpp\
src/Defines.cpp\
src/Email.cpp\ src/Email.cpp\
src/main.cpp\ src/main.cpp\
src/Missions.cpp\ src/Missions.cpp\
@ -67,28 +68,29 @@ CXXSRC=\
src/Chunking.cpp\ src/Chunking.cpp\
src/Buddies.cpp\ src/Buddies.cpp\
src/Groups.cpp\ src/Groups.cpp\
src/Monitor.cpp\
src/Racing.cpp\ src/Racing.cpp\
src/Vendor.cpp\ src/Vendor.cpp\
src/Trading.cpp\ src/Trading.cpp\
# headers (for timestamp purposes) # headers (for timestamp purposes)
CXXHDR=\ 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/bcrypt/BCrypt.hpp\
vendor/INIReader.hpp\ vendor/INIReader.hpp\
vendor/JSON.hpp\ vendor/JSON.hpp\
vendor/INIReader.hpp\ vendor/INIReader.hpp\
vendor/JSON.hpp\ vendor/JSON.hpp\
src/db/Database.hpp\
src/db/internal.hpp\
src/Chat.hpp\ src/Chat.hpp\
src/CustomCommands.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/Email.hpp\
src/Missions.hpp\ src/Missions.hpp\
src/MobAI.hpp\ src/MobAI.hpp\
@ -107,7 +109,6 @@ CXXHDR=\
src/Chunking.hpp\ src/Chunking.hpp\
src/Buddies.hpp\ src/Buddies.hpp\
src/Groups.hpp\ src/Groups.hpp\
src/Monitor.hpp\
src/Racing.hpp\ src/Racing.hpp\
src/Vendor.hpp\ src/Vendor.hpp\
src/Trading.hpp\ src/Trading.hpp\

View File

@ -1,6 +1,6 @@
#pragma once #pragma once
#include "CNProtocol.hpp" #include "core/Core.hpp"
#include "Combat.hpp" #include "Combat.hpp"
typedef void (*PowerHandler)(CNSocket*, std::vector<int>, int16_t, int16_t, int16_t, int16_t, int16_t, int32_t, int16_t); typedef void (*PowerHandler)(CNSocket*, std::vector<int>, int16_t, int16_t, int16_t, int16_t, int16_t, int32_t, int16_t);

View File

@ -1,5 +1,4 @@
#include "CNShardServer.hpp" #include "servers/CNShardServer.hpp"
#include "CNStructs.hpp"
#include "Buddies.hpp" #include "Buddies.hpp"
#include "PlayerManager.hpp" #include "PlayerManager.hpp"
#include "Buddies.hpp" #include "Buddies.hpp"

View File

@ -1,9 +1,8 @@
#pragma once #pragma once
#include "Player.hpp" #include "Player.hpp"
#include "CNProtocol.hpp" #include "core/Core.hpp"
#include "CNStructs.hpp" #include "core/Core.hpp"
#include "CNProtocol.hpp"
namespace Buddies { namespace Buddies {
void init(); void init();

View File

@ -1,6 +1,6 @@
#pragma once #pragma once
#include "CNProtocol.hpp" #include "core/Core.hpp"
namespace BuiltinCommands { namespace BuiltinCommands {
void init(); void init();

View File

@ -2,7 +2,7 @@
#define CMD_PREFIX '/' #define CMD_PREFIX '/'
#include "CNShardServer.hpp" #include "servers/CNShardServer.hpp"
namespace Chat { namespace Chat {
extern std::vector<std::string> dump; extern std::vector<std::string> dump;

View File

@ -1,7 +1,6 @@
#pragma once #pragma once
#include "CNProtocol.hpp" #include "core/Core.hpp"
#include "CNStructs.hpp"
#include <utility> #include <utility>
#include <set> #include <set>

View File

@ -1,8 +1,7 @@
#pragma once #pragma once
#include "CNProtocol.hpp" #include "core/Core.hpp"
#include "CNShared.hpp" #include "servers/CNShardServer.hpp"
#include "CNShardServer.hpp"
#include "NPC.hpp" #include "NPC.hpp"
#include "MobAI.hpp" #include "MobAI.hpp"

View File

@ -1,6 +1,6 @@
#pragma once #pragma once
#include "CNProtocol.hpp" #include "core/Core.hpp"
namespace CustomCommands { namespace CustomCommands {
void init(); void init();

View File

@ -1,8 +1,7 @@
#include "Email.hpp" #include "Email.hpp"
#include "CNProtocol.hpp" #include "core/Core.hpp"
#include "CNStructs.hpp" #include "servers/CNShardServer.hpp"
#include "CNShardServer.hpp"
#include "db/Database.hpp" #include "db/Database.hpp"
#include "PlayerManager.hpp" #include "PlayerManager.hpp"

View File

@ -1,5 +1,4 @@
#include "CNShardServer.hpp" #include "servers/CNShardServer.hpp"
#include "CNStructs.hpp"
#include "PlayerManager.hpp" #include "PlayerManager.hpp"
#include "Groups.hpp" #include "Groups.hpp"
#include "Nanos.hpp" #include "Nanos.hpp"

View File

@ -1,9 +1,8 @@
#pragma once #pragma once
#include "Player.hpp" #include "Player.hpp"
#include "CNProtocol.hpp" #include "core/Core.hpp"
#include "CNStructs.hpp" #include "servers/CNShardServer.hpp"
#include "CNShardServer.hpp"
#include <map> #include <map>
#include <list> #include <list>

View File

@ -1,5 +1,4 @@
#include "CNShardServer.hpp" #include "servers/CNShardServer.hpp"
#include "CNStructs.hpp"
#include "Items.hpp" #include "Items.hpp"
#include "PlayerManager.hpp" #include "PlayerManager.hpp"
#include "Nanos.hpp" #include "Nanos.hpp"

View File

@ -1,6 +1,6 @@
#pragma once #pragma once
#include "CNShardServer.hpp" #include "servers/CNShardServer.hpp"
#include "Player.hpp" #include "Player.hpp"
#include "MobAI.hpp" #include "MobAI.hpp"

View File

@ -1,5 +1,4 @@
#include "CNShardServer.hpp" #include "servers/CNShardServer.hpp"
#include "CNStructs.hpp"
#include "Missions.hpp" #include "Missions.hpp"
#include "PlayerManager.hpp" #include "PlayerManager.hpp"
#include "Nanos.hpp" #include "Nanos.hpp"

View File

@ -1,6 +1,6 @@
#pragma once #pragma once
#include "CNShardServer.hpp" #include "servers/CNShardServer.hpp"
#include "Player.hpp" #include "Player.hpp"
#include "JSON.hpp" #include "JSON.hpp"

View File

@ -1,6 +1,6 @@
#pragma once #pragma once
#include "CNProtocol.hpp" #include "core/Core.hpp"
#include "NPCManager.hpp" #include "NPCManager.hpp"
enum class MobState { enum class MobState {

View File

@ -1,6 +1,5 @@
#pragma once #pragma once
#include "CNStructs.hpp"
#include "Chunking.hpp" #include "Chunking.hpp"
class BaseNPC { class BaseNPC {

View File

@ -1,6 +1,6 @@
#pragma once #pragma once
#include "CNProtocol.hpp" #include "core/Core.hpp"
#include "PlayerManager.hpp" #include "PlayerManager.hpp"
#include "NPC.hpp" #include "NPC.hpp"

View File

@ -1,5 +1,4 @@
#include "CNShardServer.hpp" #include "servers/CNShardServer.hpp"
#include "CNStructs.hpp"
#include "Nanos.hpp" #include "Nanos.hpp"
#include "PlayerManager.hpp" #include "PlayerManager.hpp"
#include "NPCManager.hpp" #include "NPCManager.hpp"

View File

@ -4,7 +4,7 @@
#include <vector> #include <vector>
#include "Player.hpp" #include "Player.hpp"
#include "CNShardServer.hpp" #include "servers/CNShardServer.hpp"
struct NanoData { struct NanoData {
int style; int style;

View File

@ -3,8 +3,7 @@
#include <string> #include <string>
#include <cstring> #include <cstring>
#include "CNProtocol.hpp" #include "core/Core.hpp"
#include "CNStructs.hpp"
#include "Chunking.hpp" #include "Chunking.hpp"
#define ACTIVE_MISSION_COUNT 6 #define ACTIVE_MISSION_COUNT 6

View File

@ -1,12 +1,14 @@
#include "core/Core.hpp"
#include "core/CNShared.hpp"
#include "servers/CNShardServer.hpp"
#include "db/Database.hpp"
#include "PlayerManager.hpp" #include "PlayerManager.hpp"
#include "NPCManager.hpp" #include "NPCManager.hpp"
#include "CNShardServer.hpp"
#include "Missions.hpp" #include "Missions.hpp"
#include "Items.hpp" #include "Items.hpp"
#include "Nanos.hpp" #include "Nanos.hpp"
#include "Groups.hpp" #include "Groups.hpp"
#include "Chat.hpp" #include "Chat.hpp"
#include "db/Database.hpp"
#include "Buddies.hpp" #include "Buddies.hpp"
#include "Combat.hpp" #include "Combat.hpp"
#include "Racing.hpp" #include "Racing.hpp"

View File

@ -1,9 +1,8 @@
#pragma once #pragma once
#include "Player.hpp" #include "Player.hpp"
#include "CNProtocol.hpp" #include "core/Core.hpp"
#include "CNStructs.hpp" #include "servers/CNShardServer.hpp"
#include "CNShardServer.hpp"
#include "Chunking.hpp" #include "Chunking.hpp"
#include <utility> #include <utility>

View File

@ -1,6 +1,6 @@
#include "PlayerMovement.hpp" #include "PlayerMovement.hpp"
#include "PlayerManager.hpp" #include "PlayerManager.hpp"
#include "CNProtocol.hpp" #include "core/Core.hpp"
static void movePlayer(CNSocket* sock, CNPacketData* data) { static void movePlayer(CNSocket* sock, CNPacketData* data) {
if (data->size != sizeof(sP_CL2FE_REQ_PC_MOVE)) if (data->size != sizeof(sP_CL2FE_REQ_PC_MOVE))

View File

@ -1,5 +1,4 @@
#include "CNShardServer.hpp" #include "servers/CNShardServer.hpp"
#include "CNStructs.hpp"
#include "Racing.hpp" #include "Racing.hpp"
#include "PlayerManager.hpp" #include "PlayerManager.hpp"
#include "Missions.hpp" #include "Missions.hpp"

View File

@ -1,6 +1,6 @@
#pragma once #pragma once
#include "CNShardServer.hpp" #include "servers/CNShardServer.hpp"
struct EPInfo { struct EPInfo {
int zoneX, zoneY, EPID, maxScore, maxTime; int zoneX, zoneY, EPID, maxScore, maxTime;

View File

@ -1,5 +1,4 @@
#include "CNShardServer.hpp" #include "servers/CNShardServer.hpp"
#include "CNStructs.hpp"
#include "PlayerManager.hpp" #include "PlayerManager.hpp"
#include "Nanos.hpp" #include "Nanos.hpp"
#include "Transport.hpp" #include "Transport.hpp"

View File

@ -1,6 +1,6 @@
#pragma once #pragma once
#include "CNShardServer.hpp" #include "servers/CNShardServer.hpp"
#include "NPCManager.hpp" #include "NPCManager.hpp"
#include <unordered_map> #include <unordered_map>

View File

@ -1,8 +1,7 @@
#pragma once #pragma once
#include "CNProtocol.hpp" #include "core/Core.hpp"
#include "CNStructs.hpp" #include "servers/CNShardServer.hpp"
#include "CNShardServer.hpp"
#include "Items.hpp" #include "Items.hpp"
#include "PlayerManager.hpp" #include "PlayerManager.hpp"

View File

@ -1,4 +1,4 @@
#include "CNProtocol.hpp" #include "core/CNProtocol.hpp"
#include "CNStructs.hpp" #include "CNStructs.hpp"
#include <assert.h> #include <assert.h>
@ -469,7 +469,7 @@ void CNServer::printPacket(CNPacketData *data, int type) {
return; 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 bool CNServer::checkExtraSockets(int i) { return false; } // stubbed

View File

@ -1,4 +1,4 @@
#include "CNShared.hpp" #include "core/CNShared.hpp"
#if defined(__MINGW32__) && !defined(_GLIBCXX_HAS_GTHREADS) #if defined(__MINGW32__) && !defined(_GLIBCXX_HAS_GTHREADS)
#include "mingw/mingw.mutex.h" #include "mingw/mingw.mutex.h"

View File

@ -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! * 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!
*/ */

11
src/core/Core.hpp Normal file
View File

@ -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"

View File

@ -941,6 +941,6 @@ enum {
N_PACKETS = N_CL2LS + N_CL2FE + N_FE2CL + N_LS2CL N_PACKETS = N_CL2LS + N_CL2FE + N_FE2CL + N_LS2CL
}; };
namespace Defines { namespace Packets {
std::string p2str(int type, int val); std::string p2str(int type, int val);
} }

View File

@ -200,7 +200,7 @@ PacketMap cl2fe_map[] = {
STRINGIFY(P_CL2FE_REQ_PC_ITEM_ENCHANT), 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) { switch (type) {
case CL2LS: case CL2LS:
val = val - CL2LS - 1; val = val - CL2LS - 1;

View File

@ -1,6 +1,7 @@
#pragma once #pragma once
#include "CNStructs.hpp"
#include "Player.hpp" #include "Player.hpp"
#include <string> #include <string>
#include <vector> #include <vector>

View File

@ -1,5 +1,5 @@
#include "CNLoginServer.hpp" #include "servers/CNLoginServer.hpp"
#include "CNShardServer.hpp" #include "servers/CNShardServer.hpp"
#include "PlayerManager.hpp" #include "PlayerManager.hpp"
#include "PlayerMovement.hpp" #include "PlayerMovement.hpp"
#include "BuiltinCommands.hpp" #include "BuiltinCommands.hpp"
@ -16,7 +16,7 @@
#include "db/Database.hpp" #include "db/Database.hpp"
#include "TableData.hpp" #include "TableData.hpp"
#include "Groups.hpp" #include "Groups.hpp"
#include "Monitor.hpp" #include "servers/Monitor.hpp"
#include "Racing.hpp" #include "Racing.hpp"
#include "Trading.hpp" #include "Trading.hpp"
#include "Email.hpp" #include "Email.hpp"

View File

@ -1,6 +1,5 @@
#include "CNLoginServer.hpp" #include "servers/CNLoginServer.hpp"
#include "CNShared.hpp" #include "core/CNShared.hpp"
#include "CNStructs.hpp"
#include "db/Database.hpp" #include "db/Database.hpp"
#include "PlayerManager.hpp" #include "PlayerManager.hpp"
#include "Items.hpp" #include "Items.hpp"
@ -63,7 +62,7 @@ void CNLoginServer::handlePacket(CNSocket* sock, CNPacketData* data) {
} }
default: default:
if (settings::VERBOSITY) 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; break;
/* /*
* Unimplemented CL2LS packets: * Unimplemented CL2LS packets:

View File

@ -1,7 +1,6 @@
#pragma once #pragma once
#include "CNProtocol.hpp" #include "core/Core.hpp"
#include "Defines.hpp"
#include "Player.hpp" #include "Player.hpp"
#include <map> #include <map>

View File

@ -1,12 +1,11 @@
#include "CNProtocol.hpp" #include "core/Core.hpp"
#include "CNStructs.hpp" #include "db/Database.hpp"
#include "CNShardServer.hpp" #include "servers/Monitor.hpp"
#include "servers/CNShardServer.hpp"
#include "PlayerManager.hpp" #include "PlayerManager.hpp"
#include "MobAI.hpp" #include "MobAI.hpp"
#include "CNShared.hpp" #include "core/CNShared.hpp"
#include "settings.hpp" #include "settings.hpp"
#include "db/Database.hpp"
#include "Monitor.hpp"
#include "TableData.hpp" // for flush() #include "TableData.hpp" // for flush()
#include <iostream> #include <iostream>
@ -33,7 +32,7 @@ void CNShardServer::handlePacket(CNSocket* sock, CNPacketData* data) {
if (ShardPackets.find(data->type) != ShardPackets.end()) if (ShardPackets.find(data->type) != ShardPackets.end())
ShardPackets[data->type](sock, data); ShardPackets[data->type](sock, data);
else if (settings::VERBOSITY > 0) 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()) if (PlayerManager::players.find(sock) != PlayerManager::players.end())
PlayerManager::players[sock]->lastHeartbeat = getTime(); PlayerManager::players[sock]->lastHeartbeat = getTime();

View File

@ -1,7 +1,6 @@
#pragma once #pragma once
#include "CNProtocol.hpp" #include "core/Core.hpp"
#include "Defines.hpp"
#include <map> #include <map>

View File

@ -1,8 +1,7 @@
#include "CNShardServer.hpp" #include "servers/CNShardServer.hpp"
#include "PlayerManager.hpp" #include "PlayerManager.hpp"
#include "Chat.hpp" #include "Chat.hpp"
#include "CNStructs.hpp" #include "servers/Monitor.hpp"
#include "Monitor.hpp"
#include "settings.hpp" #include "settings.hpp"
#include <cstdio> #include <cstdio>

View File

@ -1,6 +1,6 @@
#pragma once #pragma once
#include "CNProtocol.hpp" #include "core/Core.hpp"
#include <list> #include <list>
#include <mutex> #include <mutex>

View File

@ -1,7 +1,6 @@
#include <iostream> #include <iostream>
#include "settings.hpp" #include "settings.hpp"
#include "INIReader.hpp" #include "INIReader.hpp"
#include "CNStructs.hpp" // for ACADEMY
// defaults :) // defaults :)
int settings::VERBOSITY = 1; int settings::VERBOSITY = 1;