// *************************************************************** // Function: Initialization.cpp // *************************************************************** #include "Main.h" bool CheckForCrash(); bool InitLogFiles(); bool InitScriptingSystem(); bool LoadReplayPackets(); bool LoadConfiguration(); bool PopulateOpcodeTable(); bool UpdateLoop(); int InitNetworkServers(); bool ConnectToDatabase(); int Shutdown(); unsigned long gServerStartTime=0; //************************************ // Name: RealMain // // Initializes the server. // // Parameters: // argc - Number of command line arguments // argv[] - Command line arguments // // Return: // 0 - no errors // -1 - errors //************************************ int RealMain(int argc, char* argv[]) { //initialize the timer TimerInit(); //Initialize the unique ID generator for instances gInstanceIds.Init(); //Check for any unprocessed crash files CheckForCrash(); //this information should be filled out after loading from a config file this is just for testing purposes gServerConfig.restrictedNames.push_back(RESTRICTED_NAME("fuck")); //open the game server log file and output the application title InitLogFiles(); //Load scripts, compile, etc. if (!InitScriptingSystem()) { Shutdown(); return -1; } //loads things such as packets, config, etc. if (!LoadReplayPackets()) { Shutdown(); return -1; } //Load the server configuration if (!LoadConfiguration()) { Shutdown(); return -1; } //Load the packet headers from the packet header file if (!PopulateOpcodeTable()) { Shutdown(); return -1; } gCoreLog.WriteCategory("[Connecting]"); gCoreLog.Section("GWLP Database..."); //connect to GWLP database if (!ConnectToDatabase()) { Shutdown(); return -1; } //Load the item stuff from the database gCoreLog.Section("Loading stuff from database..."); if (gItemDefMan.Load()!=0) { gCoreLog.SectionFail(); gCoreLog.error("Failed to load item stuff from the database."); Shutdown(); return -1; } gCoreLog.SectionOk(); //Load zone information from the database gCoreLog.Section("Loading zone information..."); if (Instance::LoadZoneInfos()!=0) { gCoreLog.SectionFail(); Shutdown(); return -1; } gCoreLog.SectionOk(); //Load the group permissions from the database gCoreLog.Section("Loading group permissions..."); gpPermissionGroups = new GroupPermissions; if (gpPermissionGroups==NULL) { gCoreLog.SectionFail(); gCoreLog.error("Out of memory!"); Shutdown(); return -1; } if (!gpPermissionGroups->LoadGroups()) { gCoreLog.SectionFail(); gCoreLog.error("Could not load group permissions from database!"); Shutdown(); return -1; } gCoreLog.SectionOk(); //-------------------------------------------------------- //initialize the login server //-------------------------------------------------------- gCoreLog.Section("Attempting to start network communications..."); if (InitNetworkServers()!=0) { gCoreLog.SectionFail(); Shutdown(); return -1; } //Start up stuff =D /* Item item; if (!ItemDefMan.CreateItem("BirthdayCupcake", &item)) { CoreLog.LOCATION; CoreLog.error("Failed to create Cupcake!"); } for (int i=0; i<20; i++) { item.GenerateID(56, 163, NULL); item.SetItemStorageLocation(LOC_IN_BACKPACK); item.SetItemStoragePosition(i); item.GetRAWItemData()->Quantity=250; item.Save(); }*/ //The server has been started, start the main loop gServerStartTime=(unsigned long)TimerGetTime(); gCoreLog.WriteCategory("[Game Server Started]"); gServerStats.startTime=time(NULL); UpdateLoop(); return 0; }