Started planning ServerApp refactoring
This commit is contained in:
@@ -24,7 +24,10 @@
|
|||||||
//singletons
|
//singletons
|
||||||
#include "account_manager.hpp"
|
#include "account_manager.hpp"
|
||||||
#include "character_manager.hpp"
|
#include "character_manager.hpp"
|
||||||
|
#include "client_manager.hpp"
|
||||||
#include "config_utility.hpp"
|
#include "config_utility.hpp"
|
||||||
|
#include "door_manager.hpp"
|
||||||
|
#include "monster_manager.hpp"
|
||||||
#include "room_manager.hpp"
|
#include "room_manager.hpp"
|
||||||
#include "udp_network_utility.hpp"
|
#include "udp_network_utility.hpp"
|
||||||
|
|
||||||
@@ -38,7 +41,10 @@ int main(int argc, char* argv[]) {
|
|||||||
//create the singletons
|
//create the singletons
|
||||||
AccountManager::CreateSingleton();
|
AccountManager::CreateSingleton();
|
||||||
CharacterManager::CreateSingleton();
|
CharacterManager::CreateSingleton();
|
||||||
|
ClientManager::CreateSingleton();
|
||||||
ConfigUtility::CreateSingleton();
|
ConfigUtility::CreateSingleton();
|
||||||
|
DoorManager::CreateSingleton();
|
||||||
|
MonsterManager::CreateSingleton();
|
||||||
RoomManager::CreateSingleton();
|
RoomManager::CreateSingleton();
|
||||||
UDPNetworkUtility::CreateSingleton();
|
UDPNetworkUtility::CreateSingleton();
|
||||||
|
|
||||||
@@ -55,7 +61,10 @@ int main(int argc, char* argv[]) {
|
|||||||
//delete the singletons
|
//delete the singletons
|
||||||
AccountManager::DeleteSingleton();
|
AccountManager::DeleteSingleton();
|
||||||
CharacterManager::DeleteSingleton();
|
CharacterManager::DeleteSingleton();
|
||||||
|
ClientManager::DeleteSingleton();
|
||||||
ConfigUtility::DeleteSingleton();
|
ConfigUtility::DeleteSingleton();
|
||||||
|
DoorManager::DeleteSingleton();
|
||||||
|
MonsterManager::DeleteSingleton();
|
||||||
RoomManager::DeleteSingleton();
|
RoomManager::DeleteSingleton();
|
||||||
UDPNetworkUtility::DeleteSingleton();
|
UDPNetworkUtility::DeleteSingleton();
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-3
@@ -1,5 +1,5 @@
|
|||||||
#include directories
|
#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
|
#libraries
|
||||||
#the order of the $(LIBS) is important, at least for MinGW
|
#the order of the $(LIBS) is important, at least for MinGW
|
||||||
@@ -24,7 +24,7 @@ OUTDIR=../out
|
|||||||
OUT=$(addprefix $(OUTDIR)/,server)
|
OUT=$(addprefix $(OUTDIR)/,server)
|
||||||
|
|
||||||
#targets
|
#targets
|
||||||
all: $(OUT)
|
all: $(OBJ) $(OUT)
|
||||||
$(MAKE) -C accounts
|
$(MAKE) -C accounts
|
||||||
$(MAKE) -C characters
|
$(MAKE) -C characters
|
||||||
$(MAKE) -C clients
|
$(MAKE) -C clients
|
||||||
@@ -33,7 +33,7 @@ all: $(OUT)
|
|||||||
$(MAKE) -C monsters
|
$(MAKE) -C monsters
|
||||||
$(MAKE) -C rooms
|
$(MAKE) -C rooms
|
||||||
$(MAKE) -C server_utilities
|
$(MAKE) -C server_utilities
|
||||||
# $(CXX) $(CXXFLAGS) -o $(OUT) $(OBJ) $(LIBS)
|
$(CXX) $(CXXFLAGS) -o $(OUT) $(OBJ) $(LIBS)
|
||||||
|
|
||||||
$(OBJ): | $(OBJDIR)
|
$(OBJ): | $(OBJDIR)
|
||||||
|
|
||||||
|
|||||||
@@ -96,20 +96,9 @@ private:
|
|||||||
//APIs and utilities
|
//APIs and utilities
|
||||||
sqlite3* database = nullptr;
|
sqlite3* database = nullptr;
|
||||||
lua_State* luaState = nullptr;
|
lua_State* luaState = nullptr;
|
||||||
UDPNetworkUtility& network = UDPNetworkUtility::GetSingleton();
|
|
||||||
ConfigUtility& config = ConfigUtility::GetSingleton();
|
|
||||||
|
|
||||||
//simple tables
|
|
||||||
std::map<int, ClientData> clientMap;
|
|
||||||
|
|
||||||
//managers
|
|
||||||
AccountManager& accountMgr = AccountManager::GetSingleton();
|
|
||||||
CharacterManager& characterMgr = CharacterManager::GetSingleton();
|
|
||||||
RoomManager& roomMgr = RoomManager::GetSingleton();
|
|
||||||
|
|
||||||
//misc
|
//misc
|
||||||
bool running = true;
|
bool running = true;
|
||||||
int clientIndex = 0;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -28,12 +28,14 @@
|
|||||||
//basic connections
|
//basic connections
|
||||||
//-------------------------
|
//-------------------------
|
||||||
|
|
||||||
|
//SET: utility
|
||||||
void ServerApplication::HandlePing(ServerPacket* const argPacket) {
|
void ServerApplication::HandlePing(ServerPacket* const argPacket) {
|
||||||
ServerPacket newPacket;
|
ServerPacket newPacket;
|
||||||
newPacket.type = SerialPacketType::PONG;
|
newPacket.type = SerialPacketType::PONG;
|
||||||
network.SendTo(argPacket->srcAddress, &newPacket);
|
network.SendTo(argPacket->srcAddress, &newPacket);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//SET: utility/manager
|
||||||
void ServerApplication::HandlePong(ServerPacket* const argPacket) {
|
void ServerApplication::HandlePong(ServerPacket* const argPacket) {
|
||||||
//find and update the specified client
|
//find and update the specified client
|
||||||
for (auto& it : clientMap) {
|
for (auto& it : clientMap) {
|
||||||
@@ -46,6 +48,7 @@ void ServerApplication::HandlePong(ServerPacket* const argPacket) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//SET: utility
|
||||||
void ServerApplication::HandleBroadcastRequest(ServerPacket* const argPacket) {
|
void ServerApplication::HandleBroadcastRequest(ServerPacket* const argPacket) {
|
||||||
//send the server's data
|
//send the server's data
|
||||||
ServerPacket newPacket;
|
ServerPacket newPacket;
|
||||||
@@ -58,6 +61,7 @@ void ServerApplication::HandleBroadcastRequest(ServerPacket* const argPacket) {
|
|||||||
network.SendTo(argPacket->srcAddress, static_cast<SerialPacket*>(&newPacket));
|
network.SendTo(argPacket->srcAddress, static_cast<SerialPacket*>(&newPacket));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//SET: connections
|
||||||
void ServerApplication::HandleJoinRequest(ClientPacket* const argPacket) {
|
void ServerApplication::HandleJoinRequest(ClientPacket* const argPacket) {
|
||||||
//load the user account
|
//load the user account
|
||||||
//TODO: handle passwords
|
//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;
|
std::cout << "New connection, " << clientMap.size() << " clients and " << accountMgr.GetLoadedCount() << " accounts total" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//SET: connections
|
||||||
void ServerApplication::HandleDisconnect(ClientPacket* const argPacket) {
|
void ServerApplication::HandleDisconnect(ClientPacket* const argPacket) {
|
||||||
//TODO: authenticate who is disconnecting/kicking
|
//TODO: authenticate who is disconnecting/kicking
|
||||||
/*Pseudocode:
|
/*Pseudocode:
|
||||||
@@ -127,6 +132,7 @@ void ServerApplication::HandleDisconnect(ClientPacket* const argPacket) {
|
|||||||
std::cout << "Disconnection, " << clientMap.size() << " clients and " << accountMgr.GetLoadedCount() << " accounts total" << std::endl;
|
std::cout << "Disconnection, " << clientMap.size() << " clients and " << accountMgr.GetLoadedCount() << " accounts total" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//SET: connections
|
||||||
void ServerApplication::HandleShutdown(ClientPacket* const argPacket) {
|
void ServerApplication::HandleShutdown(ClientPacket* const argPacket) {
|
||||||
//TODO: authenticate who is shutting the server down
|
//TODO: authenticate who is shutting the server down
|
||||||
/*Pseudocode:
|
/*Pseudocode:
|
||||||
@@ -152,6 +158,7 @@ void ServerApplication::HandleShutdown(ClientPacket* const argPacket) {
|
|||||||
//map management
|
//map management
|
||||||
//-------------------------
|
//-------------------------
|
||||||
|
|
||||||
|
//SET: resources
|
||||||
void ServerApplication::HandleRegionRequest(RegionPacket* const argPacket) {
|
void ServerApplication::HandleRegionRequest(RegionPacket* const argPacket) {
|
||||||
RegionPacket newPacket;
|
RegionPacket newPacket;
|
||||||
|
|
||||||
@@ -171,6 +178,7 @@ void ServerApplication::HandleRegionRequest(RegionPacket* const argPacket) {
|
|||||||
//Character Management
|
//Character Management
|
||||||
//-------------------------
|
//-------------------------
|
||||||
|
|
||||||
|
//SET: entities
|
||||||
void ServerApplication::HandleCharacterNew(CharacterPacket* const argPacket) {
|
void ServerApplication::HandleCharacterNew(CharacterPacket* const argPacket) {
|
||||||
//NOTE: misnomer, try to load the character first
|
//NOTE: misnomer, try to load the character first
|
||||||
int characterIndex = characterMgr.Load(argPacket->accountIndex, argPacket->handle, argPacket->avatar);
|
int characterIndex = characterMgr.Load(argPacket->accountIndex, argPacket->handle, argPacket->avatar);
|
||||||
@@ -203,6 +211,7 @@ void ServerApplication::HandleCharacterNew(CharacterPacket* const argPacket) {
|
|||||||
PumpPacket(&newPacket);
|
PumpPacket(&newPacket);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//SET: entities
|
||||||
void ServerApplication::HandleCharacterDelete(CharacterPacket* const argPacket) {
|
void ServerApplication::HandleCharacterDelete(CharacterPacket* const argPacket) {
|
||||||
//NOTE: Disconnecting only unloads a character, this explicitly deletes it
|
//NOTE: Disconnecting only unloads a character, this explicitly deletes it
|
||||||
|
|
||||||
@@ -234,6 +243,7 @@ void ServerApplication::HandleCharacterDelete(CharacterPacket* const argPacket)
|
|||||||
PumpCharacterUnload(characterIndex);
|
PumpCharacterUnload(characterIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//SET: entities
|
||||||
void ServerApplication::HandleCharacterUpdate(CharacterPacket* const argPacket) {
|
void ServerApplication::HandleCharacterUpdate(CharacterPacket* const argPacket) {
|
||||||
CharacterData* character = characterMgr.Get(argPacket->characterIndex);
|
CharacterData* character = characterMgr.Get(argPacket->characterIndex);
|
||||||
|
|
||||||
@@ -259,6 +269,7 @@ void ServerApplication::HandleCharacterUpdate(CharacterPacket* const argPacket)
|
|||||||
//mismanagement
|
//mismanagement
|
||||||
//-------------------------
|
//-------------------------
|
||||||
|
|
||||||
|
//SET: delete
|
||||||
void ServerApplication::HandleSynchronize(ClientPacket* const argPacket) {
|
void ServerApplication::HandleSynchronize(ClientPacket* const argPacket) {
|
||||||
//TODO: compensate for large distances
|
//TODO: compensate for large distances
|
||||||
//NOTE: I quite dislike this function
|
//NOTE: I quite dislike this function
|
||||||
@@ -282,6 +293,7 @@ void ServerApplication::HandleSynchronize(ClientPacket* const argPacket) {
|
|||||||
//utility methods
|
//utility methods
|
||||||
//-------------------------
|
//-------------------------
|
||||||
|
|
||||||
|
//SET: utility/manager
|
||||||
void ServerApplication::CheckClientConnections() {
|
void ServerApplication::CheckClientConnections() {
|
||||||
for (auto& it : clientMap) {
|
for (auto& it : clientMap) {
|
||||||
if (std::chrono::steady_clock::now() - it.second.GetLastBeat() > std::chrono::seconds(3)) {
|
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) {
|
void ServerApplication::CleanupLostConnection(int clientIndex) {
|
||||||
//NOTE: This assumes each player has only one account and character at a time
|
//NOTE: This assumes each player has only one account and character at a time
|
||||||
//TODO: handle multiple characters (bots, etc.)
|
//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;
|
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
|
//TODO: a function that only sends to characters in a certain proximity
|
||||||
|
|
||||||
|
//SET: utility
|
||||||
void ServerApplication::PumpPacket(SerialPacket* const argPacket) {
|
void ServerApplication::PumpPacket(SerialPacket* const argPacket) {
|
||||||
for (auto& it : clientMap) {
|
for (auto& it : clientMap) {
|
||||||
network.SendTo(it.second.GetAddress(), argPacket);
|
network.SendTo(it.second.GetAddress(), argPacket);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//??
|
||||||
void ServerApplication::PumpCharacterUnload(int uid) {
|
void ServerApplication::PumpCharacterUnload(int uid) {
|
||||||
//delete the client-side character(s)
|
//delete the client-side character(s)
|
||||||
//NOTE: This is a strange function
|
//NOTE: This is a strange function
|
||||||
@@ -358,6 +374,7 @@ void ServerApplication::PumpCharacterUnload(int uid) {
|
|||||||
PumpPacket(static_cast<SerialPacket*>(&newPacket));
|
PumpPacket(static_cast<SerialPacket*>(&newPacket));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//SET: utility
|
||||||
void ServerApplication::CopyCharacterToPacket(CharacterPacket* const packet, int characterIndex) {
|
void ServerApplication::CopyCharacterToPacket(CharacterPacket* const packet, int characterIndex) {
|
||||||
CharacterData* character = characterMgr.Get(characterIndex);
|
CharacterData* character = characterMgr.Get(characterIndex);
|
||||||
if (!character) {
|
if (!character) {
|
||||||
|
|||||||
Reference in New Issue
Block a user