Started planning ServerApp refactoring
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
+3
-3
@@ -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)
|
||||
|
||||
|
||||
@@ -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<int, ClientData> clientMap;
|
||||
|
||||
//managers
|
||||
AccountManager& accountMgr = AccountManager::GetSingleton();
|
||||
CharacterManager& characterMgr = CharacterManager::GetSingleton();
|
||||
RoomManager& roomMgr = RoomManager::GetSingleton();
|
||||
|
||||
//misc
|
||||
bool running = true;
|
||||
int clientIndex = 0;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -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<SerialPacket*>(&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<SerialPacket*>(&newPacket));
|
||||
}
|
||||
|
||||
//SET: utility
|
||||
void ServerApplication::CopyCharacterToPacket(CharacterPacket* const packet, int characterIndex) {
|
||||
CharacterData* character = characterMgr.Get(characterIndex);
|
||||
if (!character) {
|
||||
|
||||
Reference in New Issue
Block a user