From 4b0892691729e5efba27c796e29002b1e1d54166 Mon Sep 17 00:00:00 2001 From: Yohann Ferreira Date: Wed, 22 Sep 2010 00:02:05 +0200 Subject: Centralized the servers' exit values. Also made random code format clean-ups. Resolves: Mana-Mantis #217 Reviewed-by: Jaxad0127. --- src/account-server/accounthandler.cpp | 22 +++++++-------- src/account-server/main-account.cpp | 15 +++++----- src/defines.h | 52 ++++++++++++++++++++++++++++------- src/game-server/accountconnection.cpp | 14 ++++++---- src/game-server/attributemanager.cpp | 4 +-- src/game-server/main-game.cpp | 14 ++++++---- 6 files changed, 79 insertions(+), 42 deletions(-) (limited to 'src') diff --git a/src/account-server/accounthandler.cpp b/src/account-server/accounthandler.cpp index 28b92024..ab049dd5 100644 --- a/src/account-server/accounthandler.cpp +++ b/src/account-server/accounthandler.cpp @@ -138,7 +138,7 @@ AccountHandler::AccountHandler(const std::string &attrFile): if (absPathFile.empty()) { LOG_FATAL("Account handler: Could not find " << attrFile << "!"); - exit(3); + exit(EXIT_XML_NOT_FOUND); } XML::Document doc(absPathFile, int()); @@ -147,7 +147,7 @@ AccountHandler::AccountHandler(const std::string &attrFile): { LOG_FATAL("Account handler: " << attrFile << ": " << " is not a valid database file!"); - exit(3); + exit(EXIT_XML_BAD_PARAMETER); } for_each_xml_child_node(attributenode, node) @@ -187,7 +187,7 @@ AccountHandler::AccountHandler(const std::string &attrFile): LOG_FATAL("Account handler: " << attrFile << ": " << " The characters starting points " << "are incomplete or not set!"); - exit(3); + exit(EXIT_XML_BAD_PARAMETER); } } } // End for each XML nodes @@ -197,7 +197,7 @@ AccountHandler::AccountHandler(const std::string &attrFile): { LOG_FATAL("Account handler: " << attrFile << ": " << "No modifiable attributes found!"); - exit(3); + exit(EXIT_XML_BAD_PARAMETER); } // Sanity checks on starting points. @@ -208,7 +208,7 @@ AccountHandler::AccountHandler(const std::string &attrFile): LOG_FATAL("Account handler: " << attrFile << ": " << "Character's point values make " << "the character's creation impossible!"); - exit(3); + exit(EXIT_XML_BAD_PARAMETER); } LOG_DEBUG("Character start points: " << startPoints << " (Min: " @@ -358,15 +358,15 @@ void AccountHandler::handleLoginMessage(AccountClient &client, MessageIn &msg) return; } - // The client successfully logged in + // The client successfully logged in... - // set lastLogin date of the account + // Set lastLogin date of the account. time_t login; time(&login); acc->setLastLogin(login); storage->updateLastLogin(acc); - // Associate account with connection + // Associate account with connection. client.setAccount(acc); client.status = CLIENT_CONNECTED; @@ -502,11 +502,11 @@ void AccountHandler::handleRegisterMessage(AccountClient &client, acc->setPassword(sha256(password)); // We hash email server-side for additional privacy // we ask for it again when we need it and verify it - // through comparing it with the hash + // through comparing it with the hash. acc->setEmail(sha256(email)); acc->setLevel(AL_PLAYER); - // set the date and time of the account registration, and the last login + // Set the date and time of the account registration, and the last login time_t regdate; time(®date); acc->setRegistrationDate(regdate); @@ -723,7 +723,7 @@ void AccountHandler::handleCharacterCreateMessage(AccountClient &client, return; } - // LATER_ON: Add race, face and maybe special attributes. + // TODO: Add race, face and maybe special attributes. // Customization of character's attributes... std::vector attributes = std::vector(initAttr.size(), 0); diff --git a/src/account-server/main-account.cpp b/src/account-server/main-account.cpp index 733369d7..0be05abe 100644 --- a/src/account-server/main-account.cpp +++ b/src/account-server/main-account.cpp @@ -39,6 +39,7 @@ #include "utils/processorutils.hpp" #include "utils/stringfilter.h" #include "utils/timer.h" +#include "defines.h" #include #include @@ -106,7 +107,7 @@ static void initializeConfiguration(std::string configPath = std::string()) { LOG_FATAL("Refusing to run without configuration!" << std::endl << "Invalid config path: " << configPath << "."); - exit(1); + exit(EXIT_CONFIG_NOT_FOUND); } } @@ -116,7 +117,7 @@ static void initializeConfiguration(std::string configPath = std::string()) if (Configuration::getValue("net_password", "") == "") { LOG_FATAL("SECURITY WARNING: 'net_password' not set!"); - exit(3); + exit(EXIT_BAD_CONFIG_PARAMETER); } } @@ -169,7 +170,7 @@ static void initialize() catch (std::string &error) { LOG_FATAL("Error opening the database: " << error); - exit(1); + exit(EXIT_DB_EXCEPTION); } // --- Initialize the managers @@ -188,7 +189,7 @@ static void initialize() if (enet_initialize() != 0) { LOG_FATAL("An error occurred while initializing ENet"); - exit(2); + exit(EXIT_NET_EXCEPTION); } // Initialize the processor utility functions @@ -257,7 +258,7 @@ static void printHelp() << " - 3. Plus standard information." << std::endl << " - 4. Plus debugging information." << std::endl << " --port : Set the default port to listen on" << std::endl; - exit(0); + exit(EXIT_NORMAL); } struct CommandLineOptions @@ -365,7 +366,7 @@ int main(int argc, char *argv[]) !chatHandler->startListen(options.port + 2, host)) { LOG_FATAL("Unable to create an ENet server host."); - return 3; + return EXIT_NET_EXCEPTION; } // Dump statistics every 10 seconds. @@ -402,5 +403,5 @@ int main(int argc, char *argv[]) chatHandler->stopListen(); deinitializeServer(); - return 0; + return EXIT_NORMAL; } diff --git a/src/defines.h b/src/defines.h index 4f80afaa..5cce0f7b 100644 --- a/src/defines.h +++ b/src/defines.h @@ -21,8 +21,25 @@ #ifndef DEFINES_H #define DEFINES_H +// Precomputed square-root of 2. #define SQRT2 1.4142135623730950488 +/** + * Exit value codes are thrown back at servers exit to reflect their exit state. + */ +enum exitValue +{ + EXIT_NORMAL = 0, + EXIT_CONFIG_NOT_FOUND, // The main configuration file wasn't found. + EXIT_BAD_CONFIG_PARAMETER, // The configuration file has a wrong parameter. + EXIT_XML_NOT_FOUND, // A required base xml configuration file wasn't found. + EXIT_XML_BAD_PARAMETER, // The configuration of an xml file is faulty. + EXIT_MAP_FILE_NOT_FOUND, // No map files found. + EXIT_DB_EXCEPTION, // The database is invalid or unreachable. + EXIT_NET_EXCEPTION, // The server was unable to start network connections. + EXIT_OTHER_EXCEPTION +}; + /** * Enumeration type for account levels. * A normal player would have permissions of 1 @@ -31,7 +48,7 @@ * A gm would have permissions of 11 (AL_PLAYER | AL_TESTER | AL_GM) * A admin would have permissions of 255 (*) */ -enum +enum accessLevel { AL_BANNED = 0, /**< This user is currently banned. */ AL_PLAYER = 1, /**< User has regular rights. */ @@ -49,7 +66,7 @@ enum * Memeber with KICK can remove other users * Members with OWNER can invite users and set permissions */ -enum +enum guildAccessLevel { GAL_NONE = 0, GAL_TOPIC_CHANGE = 1, @@ -62,6 +79,7 @@ enum * Determine the default area in which a character is aware of other beings */ const int DEFAULT_INTERACTION_TILES_AREA = 20; + /** * Default tile length in pixel */ @@ -106,10 +124,11 @@ enum Element /** * A series of hardcoded attributes that must be defined. - * Much of these serve only to indicate derivatives, and so would not be + * FIXME: Much of these serve only to indicate derivatives, and so would not be * needed once this is no longer a hardcoded system. */ +// Base Statistics #define ATTR_STR 1 #define ATTR_AGI 2 #define ATTR_VIT 3 @@ -117,6 +136,7 @@ enum Element #define ATTR_DEX 5 #define ATTR_WIL 6 +// Derived attributes #define ATTR_ACCURACY 7 #define ATTR_DEFENSE 8 #define ATTR_DODGE 9 @@ -134,6 +154,8 @@ enum Element // Separate primary movespeed (tiles * second ^-1) and derived movespeed (raw) #define ATTR_MOVE_SPEED_TPS 16 #define ATTR_MOVE_SPEED_RAW 17 + +// Money and inventory size attributes. #define ATTR_GP 18 #define ATTR_INV_CAPACITY 19 @@ -146,26 +168,36 @@ enum Element #define MOB_ATTR_MAG_ATK 22 /** - * Attribute types. Can be one of stackable, non stackable, or non stackable bonus. + * Attribute types. Can be one of stackable, non stackable, + * or non stackable bonus. * @todo non-stackable malus layers */ - -enum AT_TY { +enum AT_TY +{ TY_ST, TY_NST, TY_NSTB, - TY_NONE // Should only be used on types that have not yet been properly defined + TY_NONE // Should only be used on types + // that have not yet been properly defined. }; -enum AME_TY { +/** + * Attribute augmentation methods. + * Can be additive or multiplicative. + */ +enum AME_TY +{ AME_MULT, AME_ADD }; -struct AttributeInfoType { + +struct AttributeInfoType +{ AT_TY sType; AME_TY eType; - AttributeInfoType(AT_TY s, AME_TY e) : sType(s), eType(e) {} + AttributeInfoType(AT_TY s, AME_TY e) : sType(s), eType(e) + {} }; #endif // DEFINES_H diff --git a/src/game-server/accountconnection.cpp b/src/game-server/accountconnection.cpp index 128e3df0..e68d9c3b 100644 --- a/src/game-server/accountconnection.cpp +++ b/src/game-server/accountconnection.cpp @@ -104,19 +104,21 @@ void AccountConnection::processMessage(MessageIn &msg) if (msg.readShort() != DATA_VERSION_OK) { LOG_ERROR("Item database is outdated! Please update to " - "prevent inconsistencies"); - stop(); // disconnect gracefully from account server - exit(1); // stop gameserver to prevent inconsistencies + "prevent inconsistencies"); + stop(); // Disconnect gracefully from account server. + // Stop gameserver to prevent inconsistencies. + exit(EXIT_DB_EXCEPTION); } else { - LOG_DEBUG("Local item database is in sync with account server."); + LOG_DEBUG("Local item database is " + "in sync with account server."); } if (msg.readShort() != PASSWORD_OK) { - LOG_ERROR("This game server sent a invaild password"); + LOG_ERROR("This game server sent a invalid password"); stop(); - exit(1); + exit(EXIT_BAD_CONFIG_PARAMETER); } } break; diff --git a/src/game-server/attributemanager.cpp b/src/game-server/attributemanager.cpp index d24c2645..7e32d4dc 100644 --- a/src/game-server/attributemanager.cpp +++ b/src/game-server/attributemanager.cpp @@ -43,7 +43,7 @@ void AttributeManager::reload() { LOG_FATAL("Attribute Manager: Could not find " << mAttributeReferenceFile << "!"); - exit(3); + exit(EXIT_XML_NOT_FOUND); } XML::Document doc(absPathFile, int()); @@ -52,7 +52,7 @@ void AttributeManager::reload() { LOG_FATAL("Attribute Manager: " << mAttributeReferenceFile << " is not a valid database file!"); - exit(3); + exit(EXIT_XML_BAD_PARAMETER); } LOG_INFO("Loading attribute reference..."); diff --git a/src/game-server/main-game.cpp b/src/game-server/main-game.cpp index 364745d4..db118325 100644 --- a/src/game-server/main-game.cpp +++ b/src/game-server/main-game.cpp @@ -132,7 +132,7 @@ static void initializeConfiguration(std::string configPath = std::string()) { LOG_FATAL("Refusing to run without configuration!" << std::endl << "Invalid config path: " << configPath << "."); - exit(1); + exit(EXIT_CONFIG_NOT_FOUND); } } @@ -142,7 +142,7 @@ static void initializeConfiguration(std::string configPath = std::string()) if (Configuration::getValue("net_password", "") == "") { LOG_FATAL("SECURITY WARNING: 'net_password' not set!"); - exit(3); + exit(EXIT_BAD_CONFIG_PARAMETER); } } @@ -179,7 +179,7 @@ static void initializeServer() if (MapManager::initialize(DEFAULT_MAPSDB_FILE) < 1) { LOG_FATAL("The Game Server can't find any valid/available maps."); - exit(2); + exit(EXIT_MAP_FILE_NOT_FOUND); } attributeManager->initialize(); SkillManager::initialize(DEFAULT_SKILLSDB_FILE); @@ -203,7 +203,7 @@ static void initializeServer() if (enet_initialize() != 0) { LOG_FATAL("An error occurred while initializing ENet"); - exit(2); + exit(EXIT_NET_EXCEPTION); } // Set enet to quit on exit. @@ -263,7 +263,7 @@ static void printHelp() << " - 4. Plus debugging information." << std::endl << " --port : Set the default port to listen on." << std::endl; - exit(0); + exit(EXIT_NORMAL); } struct CommandLineOptions @@ -383,7 +383,7 @@ int main(int argc, char *argv[]) if (!gameHandler->startListen(options.port)) { LOG_FATAL("Unable to create an ENet server host."); - return 3; + return EXIT_NET_EXCEPTION; } // Initialize world timer @@ -463,4 +463,6 @@ int main(int argc, char *argv[]) gameHandler->stopListen(); accountHandler->stop(); deinitializeServer(); + + return EXIT_NORMAL; } -- cgit v1.2.3-60-g2f50