Changed a bunch of method names, including Singleton<>

This commit is contained in:
Kayne Ruse
2014-10-01 01:57:03 +10:00
parent 9b43b4641f
commit be9ce33637
5 changed files with 44 additions and 41 deletions
+6 -6
View File
@@ -33,22 +33,22 @@ using namespace std;
int main(int argc, char* argv[]) { int main(int argc, char* argv[]) {
try { try {
//create the singletons //create the singletons
ConfigUtility::Create(); ConfigUtility::CreateSingleton();
UDPNetworkUtility::Create(); UDPNetworkUtility::CreateSingleton();
//call the server's routines //call the server's routines
ClientApplication::Create(); ClientApplication::CreateSingleton();
ClientApplication& app = ClientApplication::GetSingleton(); ClientApplication& app = ClientApplication::GetSingleton();
app.Init(argc, argv); app.Init(argc, argv);
app.Proc(); app.Proc();
app.Quit(); app.Quit();
ClientApplication::Delete(); ClientApplication::DeleteSingleton();
//delete the singletons //delete the singletons
ConfigUtility::Delete(); ConfigUtility::DeleteSingleton();
UDPNetworkUtility::Delete(); UDPNetworkUtility::DeleteSingleton();
} }
catch(exception& e) { catch(exception& e) {
cerr << "Fatal exception thrown: " << e.what() << endl; cerr << "Fatal exception thrown: " << e.what() << endl;
+2 -2
View File
@@ -33,13 +33,13 @@ public:
} }
return *ptr; return *ptr;
} }
static void Create() { static void CreateSingleton() {
if (ptr) { if (ptr) {
throw(std::logic_error("This singleton has already been created")); throw(std::logic_error("This singleton has already been created"));
} }
ptr = new T(); ptr = new T();
} }
static void Delete() { static void DeleteSingleton() {
if (!ptr) { if (!ptr) {
throw(std::logic_error("A non-existant singleton cannot be deleted")); throw(std::logic_error("A non-existant singleton cannot be deleted"));
} }
+15 -12
View File
@@ -22,7 +22,10 @@
#include "server_application.hpp" #include "server_application.hpp"
//singletons //singletons
#include "account_manager.hpp"
#include "character_manager.hpp"
#include "config_utility.hpp" #include "config_utility.hpp"
#include "room_manager.hpp"
#include "udp_network_utility.hpp" #include "udp_network_utility.hpp"
#include <stdexcept> #include <stdexcept>
@@ -33,28 +36,28 @@ using namespace std;
int main(int argc, char* argv[]) { int main(int argc, char* argv[]) {
try { try {
//create the singletons //create the singletons
AccountManager::Create(); AccountManager::CreateSingleton();
CharacterManager::Create(); CharacterManager::CreateSingleton();
ConfigUtility::Create(); ConfigUtility::CreateSingleton();
RoomManager::Create(); RoomManager::CreateSingleton();
UDPNetworkUtility::Create(); UDPNetworkUtility::CreateSingleton();
//call the server's routines //call the server's routines
ServerApplication::Create(); ServerApplication::CreateSingleton();
ServerApplication& app = ServerApplication::GetSingleton(); ServerApplication& app = ServerApplication::GetSingleton();
app.Init(argc, argv); app.Init(argc, argv);
app.Proc(); app.Proc();
app.Quit(); app.Quit();
ServerApplication::Delete(); ServerApplication::DeleteSingleton();
//delete the singletons //delete the singletons
AccountManager::Delete(); AccountManager::DeleteSingleton();
CharacterManager::Delete(); CharacterManager::DeleteSingleton();
ConfigUtility::Delete(); ConfigUtility::DeleteSingleton();
RoomManager::Delete(); RoomManager::DeleteSingleton();
UDPNetworkUtility::Delete(); UDPNetworkUtility::DeleteSingleton();
} }
catch(exception& e) { catch(exception& e) {
cerr << "Fatal exception thrown: " << e.what() << endl; cerr << "Fatal exception thrown: " << e.what() << endl;
+1 -1
View File
@@ -22,7 +22,7 @@
#include "server_application.hpp" #include "server_application.hpp"
//utility functions //utility functions
#include "sql_utility.hpp" #include "sql_tools.hpp"
#include "utility.hpp" #include "utility.hpp"
#include <stdexcept> #include <stdexcept>
+20 -20
View File
@@ -52,7 +52,7 @@ void ServerApplication::HandleBroadcastRequest(ServerPacket* const argPacket) {
newPacket.type = SerialPacketType::BROADCAST_RESPONSE; newPacket.type = SerialPacketType::BROADCAST_RESPONSE;
strncpy(newPacket.name, config["server.name"].c_str(), PACKET_STRING_SIZE); strncpy(newPacket.name, config["server.name"].c_str(), PACKET_STRING_SIZE);
newPacket.playerCount = characterMgr.GetContainer()->size(); newPacket.playerCount = characterMgr.GetLoadedCount();
newPacket.version = NETWORK_VERSION; newPacket.version = NETWORK_VERSION;
network.SendTo(argPacket->srcAddress, static_cast<SerialPacket*>(&newPacket)); network.SendTo(argPacket->srcAddress, static_cast<SerialPacket*>(&newPacket));
@@ -61,7 +61,7 @@ void ServerApplication::HandleBroadcastRequest(ServerPacket* const argPacket) {
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
int accountIndex = accountMgr.LoadAccount(argPacket->username, clientIndex); int accountIndex = accountMgr.Load(argPacket->username, clientIndex);
//Cannot load //Cannot load
if (accountIndex < 0) { if (accountIndex < 0) {
@@ -88,7 +88,7 @@ void ServerApplication::HandleJoinRequest(ClientPacket* const argPacket) {
clientMap[clientIndex++] = newClient; clientMap[clientIndex++] = newClient;
//finished this routine //finished this routine
std::cout << "New connection, " << clientMap.size() << " clients and " << accountMgr.GetContainer()->size() << " accounts total" << std::endl; std::cout << "New connection, " << clientMap.size() << " clients and " << accountMgr.GetLoadedCount() << " accounts total" << std::endl;
} }
void ServerApplication::HandleDisconnect(ClientPacket* const argPacket) { void ServerApplication::HandleDisconnect(ClientPacket* const argPacket) {
@@ -105,26 +105,26 @@ void ServerApplication::HandleDisconnect(ClientPacket* const argPacket) {
//forward to the specified client //forward to the specified client
network.SendTo( network.SendTo(
clientMap[ accountMgr.GetAccount(argPacket->accountIndex)->GetClientIndex() ].GetAddress(), clientMap[ accountMgr.Get(argPacket->accountIndex)->GetClientIndex() ].GetAddress(),
static_cast<SerialPacket*>(argPacket) static_cast<SerialPacket*>(argPacket)
); );
//save and unload this account's characters //save and unload this account's characters
characterMgr.UnloadCharacterIf([&](std::map<int, CharacterData>::iterator it) -> bool { characterMgr.UnloadIf([&](std::pair<int, CharacterData> it) -> bool {
if (argPacket->accountIndex == it->second.GetOwner()) { if (argPacket->accountIndex == it.second.GetOwner()) {
//pump the unload message to all remaining clients //pump the unload message to all remaining clients
PumpCharacterUnload(it->first); PumpCharacterUnload(it.first);
return true; return true;
} }
return false; return false;
}); });
//erase the in-memory stuff //erase the in-memory stuff
clientMap.erase(accountMgr.GetAccount(argPacket->accountIndex)->GetClientIndex()); clientMap.erase(accountMgr.Get(argPacket->accountIndex)->GetClientIndex());
accountMgr.UnloadAccount(argPacket->accountIndex); accountMgr.Unload(argPacket->accountIndex);
//finished this routine //finished this routine
std::cout << "Disconnection, " << clientMap.size() << " clients and " << accountMgr.GetContainer()->size() << " accounts total" << std::endl; std::cout << "Disconnection, " << clientMap.size() << " clients and " << accountMgr.GetLoadedCount() << " accounts total" << std::endl;
} }
void ServerApplication::HandleShutdown(ClientPacket* const argPacket) { void ServerApplication::HandleShutdown(ClientPacket* const argPacket) {
@@ -173,7 +173,7 @@ void ServerApplication::HandleRegionRequest(RegionPacket* const argPacket) {
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.LoadCharacter(argPacket->accountIndex, argPacket->handle, argPacket->avatar); int characterIndex = characterMgr.Load(argPacket->accountIndex, argPacket->handle, argPacket->avatar);
//cannot load or create //cannot load or create
if (characterIndex < 0) { if (characterIndex < 0) {
@@ -207,10 +207,10 @@ 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
//Authenticate the owner is doing this //Authenticate the owner is doing this
int characterIndex = characterMgr.LoadCharacter(argPacket->accountIndex, argPacket->handle, argPacket->avatar); int characterIndex = characterMgr.Load(argPacket->accountIndex, argPacket->handle, argPacket->avatar);
//if this is not your character //if this is not your character
if (characterIndex < 0 && characterMgr.GetCharacter(characterIndex)->GetOwner() != argPacket->accountIndex) { if (characterIndex < 0 && characterMgr.Get(characterIndex)->GetOwner() != argPacket->accountIndex) {
//send the rejection packet //send the rejection packet
TextPacket newPacket; TextPacket newPacket;
newPacket.type = SerialPacketType::CHARACTER_REJECTION; newPacket.type = SerialPacketType::CHARACTER_REJECTION;
@@ -220,13 +220,13 @@ void ServerApplication::HandleCharacterDelete(CharacterPacket* const argPacket)
//unload an unneeded character //unload an unneeded character
if (characterIndex != -1) { if (characterIndex != -1) {
characterMgr.UnloadCharacter(characterIndex); characterMgr.Unload(characterIndex);
} }
return; return;
} }
//delete it //delete it
characterMgr.DeleteCharacter(characterIndex); characterMgr.Delete(characterIndex);
//TODO: success packet //TODO: success packet
@@ -235,7 +235,7 @@ void ServerApplication::HandleCharacterDelete(CharacterPacket* const argPacket)
} }
void ServerApplication::HandleCharacterUpdate(CharacterPacket* const argPacket) { void ServerApplication::HandleCharacterUpdate(CharacterPacket* const argPacket) {
CharacterData* character = characterMgr.GetCharacter(argPacket->characterIndex); CharacterData* character = characterMgr.Get(argPacket->characterIndex);
//make a new character if this one doesn't exist //make a new character if this one doesn't exist
if (!character) { if (!character) {
@@ -327,8 +327,8 @@ void ServerApplication::CleanupLostConnection(int clientIndex) {
network.SendTo(clientMap[clientIndex].GetAddress(), &newPacket); network.SendTo(clientMap[clientIndex].GetAddress(), &newPacket);
//clean up this mess //clean up this mess
characterMgr.UnloadCharacter(characterIndex); characterMgr.Unload(characterIndex);
accountMgr.UnloadAccount(accountIndex); accountMgr.Unload(accountIndex);
clientMap.erase(clientIndex); clientMap.erase(clientIndex);
PumpCharacterUnload(characterIndex); PumpCharacterUnload(characterIndex);
@@ -338,7 +338,7 @@ void ServerApplication::CleanupLostConnection(int clientIndex) {
std::cerr << "\tClient: " << clientIndex << std::endl; std::cerr << "\tClient: " << clientIndex << std::endl;
std::cerr << "\tAccount: " << accountIndex << std::endl; std::cerr << "\tAccount: " << accountIndex << std::endl;
std::cerr << "\tCharacter: " << characterIndex << std::endl; std::cerr << "\tCharacter: " << characterIndex << std::endl;
std::cout << clientMap.size() << " clients and " << accountMgr.GetContainer()->size() << " accounts total" << std::endl; std::cout << clientMap.size() << " clients and " << accountMgr.GetLoadedCount() << " accounts total" << std::endl;
} }
//TODO: a function that only sends to characters in a certain proximity //TODO: a function that only sends to characters in a certain proximity
@@ -359,7 +359,7 @@ void ServerApplication::PumpCharacterUnload(int uid) {
} }
void ServerApplication::CopyCharacterToPacket(CharacterPacket* const packet, int characterIndex) { void ServerApplication::CopyCharacterToPacket(CharacterPacket* const packet, int characterIndex) {
CharacterData* character = characterMgr.GetCharacter(characterIndex); CharacterData* character = characterMgr.Get(characterIndex);
if (!character) { if (!character) {
throw(std::runtime_error("Failed to copy a character to a packet")); throw(std::runtime_error("Failed to copy a character to a packet"));
} }