OregonCore  revision fb2a440-git
Your Favourite TBC server
Main.cpp File Reference
#include "SystemConfig.h"
#include "Common.h"
#include "Database/DatabaseEnv.h"
#include "Config/Config.h"
#include "Log.h"
#include "Master.h"
#include <ace/Version.h>
#include <ace/Get_Opt.h>

Go to the source code of this file.

Macros

#define _OREGON_CORE_CONFIG   "oregoncore.conf"
 
#define _OREGON_CORE_CONFVER   2014091557
 

Functions

void usage (const char *prog)
 
int main (int argc, char **argv)
 

Variables

DatabaseType WorldDatabase
 Accessor to the world database. More...
 
DatabaseType CharacterDatabase
 Accessor to the character database. More...
 
DatabaseType LoginDatabase
 Accessor to the realm/login database. More...
 
uint32 realmID
 Id of the realm. More...
 

Macro Definition Documentation

#define _OREGON_CORE_CONFIG   "oregoncore.conf"

Definition at line 29 of file Main.cpp.

Referenced by main().

#define _OREGON_CORE_CONFVER   2014091557

Definition at line 35 of file Main.cpp.

Referenced by main().

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 76 of file Main.cpp.

References _FULLVERSION, _OREGON_CORE_CONFIG, _OREGON_CORE_CONFVER, sConfig, sLog, sMaster, and usage().

Referenced by WDT_file::free(), WDT_file::prepareLoadedData(), and WDT_file::WDT_file().

77 {
78  // Command line parsing
79  char const* cfg_file = _OREGON_CORE_CONFIG;
80 
81  #ifdef _WIN32
82  char const* options = ":c:s:";
83  #else
84  char const* options = ":c:";
85  #endif
86 
87  bool runRegressionTtests = false;
88 
89  ACE_Get_Opt cmd_opts(argc, argv, options);
90  cmd_opts.long_option("version", 'v');
91  cmd_opts.long_option("run-tests", 't');
92 
93  int option;
94  while ((option = cmd_opts()) != EOF)
95  {
96  switch (option)
97  {
98  case 'c':
99  cfg_file = cmd_opts.opt_arg();
100  break;
101  case 'v':
102  printf("%s\n", _FULLVERSION);
103  return 0;
104  #ifdef _WIN32
105  case 's':
106  {
107  const char* mode = cmd_opts.opt_arg();
108 
109  if (!strcmp(mode, "install"))
110  {
111  if (WinServiceInstall())
112  sLog.outString("Installing service");
113  return 1;
114  }
115  else if (!strcmp(mode, "uninstall"))
116  {
117  if (WinServiceUninstall())
118  sLog.outString("Uninstalling service");
119  return 1;
120  }
121  else if (!strcmp(mode, "run"))
122  WinServiceRun();
123  else
124  {
125  sLog.outError("Runtime-Error: -%c unsupported argument %s", cmd_opts.opt_opt(), mode);
126  usage(argv[0]);
127  return 1;
128  }
129  break;
130  }
131  #endif
132  case 't':
133  runRegressionTtests = true;
134  break;
135  case ':':
136  sLog.outError("Runtime-Error: -%c option requires an input argument", cmd_opts.opt_opt());
137  usage(argv[0]);
138  return 1;
139  default:
140  sLog.outError("Runtime-Error: bad format of commandline arguments");
141  usage(argv[0]);
142  return 1;
143  }
144  }
145 
146  if (!sConfig.SetSource(cfg_file))
147  {
148  sLog.outError("Invalid or missing configuration file : %s", cfg_file);
149  sLog.outError("Verify that the file exists and has \'[worldserver]' written in the top of the file!");
150  return 1;
151  }
152  sLog.outString("Using configuration file %s.", cfg_file);
153 
154  uint32 confVersion = sConfig.GetIntDefault("ConfVersion", 0);
155  if (confVersion < _OREGON_CORE_CONFVER)
156  {
157  sLog.outError("*****************************************************************************");
158  sLog.outError(" WARNING: Your oregoncore.conf version indicates your conf file is out of date!");
159  sLog.outError(" Please check for updates, as your current default values may cause");
160  sLog.outError(" strange behavior.");
161  sLog.outError("*****************************************************************************");
162  clock_t pause = 3000 + clock();
163 
164  while (pause > clock()) {}
165  }
166 
167  sLog.outDetail("Using ACE: %s", ACE_VERSION);
168 
169  // and run the 'Master'
170  // todo - Why do we need this 'Master'? Can't all of this be in the Main as for Realmd?
171  int exitcode = sMaster.Run(runRegressionTtests);
172  if (exitcode == 2)
173  {
174  /* We need to close all fds except the standard ones,
175  to avoid resoruce leaking. In the current status
176  this is the best way to do it. */
177 
178  int fd;
179  #ifdef _WIN32
180  _CrtSetReportMode(_CRT_ASSERT, 0); // Disable complaining about passing invalid values to close()
181  fd = _getmaxstdio();
182  #elif defined(OPEN_MAX)
183  fd = OPEN_MAX;
184  #elif defined(NOFILE)
185  fd = NOFILE;
186  #else
187  fd = getdtablesize();
188  #endif
189  while (fd > 2)
190  close(fd--);
191 
192  #ifndef _WIN32
193  execv(argv[0], argv);
194  #else
195  /* On windows we have to quote first argument
196  because spawned process won't be able to restart */
197  std::string arg0;
198  arg0.append(1, '"');
199  arg0.append(argv[0]);
200  arg0.append(1, '"');
201 
202  char* path = argv[0];
203  argv[0] = const_cast<char*>(arg0.c_str());
204  _execv(path, argv);
205  #endif
206 
207  fprintf(stderr, "Couldn't restart server: %s", strerror(errno));
208  _exit(exitcode); // avoid crashes as we closed fds
209  }
210  return exitcode;
211  // at sMaster return function exist with codes
212  // 0 - normal shutdown
213  // 1 - shutdown at error
214  // 2 - restart command used, this code can be used by restarter for restart OregonCore
215 }
#define sConfig
Definition: Config.h:52
#define sMaster
Definition: Master.h:46
#define sLog
Log class singleton.
Definition: Log.h:187
void usage(const char *prog)
Definition: Main.cpp:60
#define _FULLVERSION
Definition: SystemConfig.h:40
#define _OREGON_CORE_CONFVER
Definition: Main.cpp:35
ACE_UINT32 uint32
Definition: Define.h:71
#define _OREGON_CORE_CONFIG
Definition: Main.cpp:29
void usage ( const char *  prog)

Definition at line 60 of file Main.cpp.

References sLog.

Referenced by main().

61 {
62  sLog.outString("Usage: \n %s [<options>]\n"
63  " -v, --version print version and exit\n\r"
64  " -c config_file use config_file as configuration file\n\r"
65  #ifdef _WIN32
66  " Running as service functions:\n\r"
67  " -s run run as service\n\r"
68  " -s install install service\n\r"
69  " -s uninstall uninstall service\n\r"
70  #endif
71  " -t --run-tests run regression tests and exit\n\r"
72  , prog);
73 }
#define sLog
Log class singleton.
Definition: Log.h:187

Variable Documentation

DatabaseType CharacterDatabase

Accessor to the character database.

Definition at line 54 of file Main.cpp.

Referenced by Group::_addMember(), Pet::_LoadAuras(), Player::_LoadBoundInstances(), Player::_LoadHomeBind(), Player::_LoadInventory(), Player::_LoadMail(), Player::_LoadMailedItems(), Player::_LoadSkills(), Pet::_LoadSpellCooldowns(), Pet::_LoadSpells(), Group::_removeMember(), InstanceSaveManager::_ResetOrWarnAll(), Player::_SaveActions(), Pet::_SaveAuras(), Player::_SaveAuras(), Player::_SaveBGData(), Player::_SaveDailyQuestStatus(), Player::_SaveInventory(), Player::_SaveMail(), Player::_SaveQuestStatus(), Player::_SaveSkills(), Pet::_SaveSpellCooldowns(), Player::_SaveSpellCooldowns(), Pet::_SaveSpells(), Player::_SaveSpells(), Player::_SaveTutorials(), Group::_setAssistantFlag(), Group::_setLeader(), Group::_setMainAssistant(), Group::_setMainTank(), Group::_setMembersGroup(), Master::_StartDB(), Guild::AddGBankItemToDB(), ArenaTeam::AddMember(), Guild::AddMember(), AuctionHouseBot::addNewAuctionBuyerBotBid(), Pet::addSpell(), Player::AddSpell(), PlayerSocial::AddToSocialList(), Player::AutoUnequipOffhandIfNeed(), World::BanAccount(), Group::BindToInstance(), Player::BindToInstance(), Guild::ChangeRank(), InstanceSaveManager::CleanupInstances(), Master::clearOnlineAccounts(), AuctionHouseBot::Commands(), Player::ConvertInstancesToGroup(), Group::ConvertToRaid(), ArenaTeam::Create(), Group::Create(), Guild::Create(), Guild::CreateBankRightForTab(), Guild::CreateDefaultGuildRanks(), CreateDumpString(), InstanceMap::CreateInstanceData(), ObjectMgr::CreateItemText(), Guild::CreateNewBankTab(), Guild::CreateRank(), AccountMgr::DeleteAccount(), Corpse::DeleteFromDB(), AuctionEntry::DeleteFromDB(), Pet::DeleteFromDB(), Item::DeleteFromDB(), Player::DeleteFromDB(), Item::DeleteFromInventoryDB(), TicketMgr::DeleteGMTicketPermanently(), MailDraft::deleteIncludedItems(), InstanceSaveManager::DeleteInstanceFromDB(), Player::DeleteOldCharacters(), ArenaTeam::DelMember(), Guild::DelMember(), Guild::DelRank(), Player::DestroyItem(), ArenaTeam::Disband(), Group::Disband(), Guild::Disband(), BattlegroundMgr::DistributeArenaPoints(), PlayerDumpWriter::DumpTable(), Guild::FillPlayerData(), Player::GetArenaTeamIdFromDB(), AccountMgr::GetCharactersCount(), ChatHandler::GetDeletedCharacterInfoList(), Player::GetGuildIdFromDB(), Player::GetLevelFromDB(), Guild::GetMemberMoneyWithdrawRem(), Guild::GetMemberSlotWithdrawRem(), ObjectMgr::GetPlayerAccountIdByGUID(), ObjectMgr::GetPlayerAccountIdByPlayerName(), ObjectMgr::GetPlayerGUIDByName(), ObjectMgr::GetPlayerNameByGUID(), ObjectMgr::GetPlayerTeamByGUID(), Player::GetRankFromDB(), Player::GetZoneIdFromDB(), WorldSession::HandleAcceptTradeOpcode(), ChatHandler::HandleAccountOnlineListCommand(), WorldSession::HandleAddFriendOpcode(), WorldSession::HandleAddIgnoreOpcode(), WorldSession::HandleAuctionPlaceBid(), WorldSession::HandleAuctionRemoveItem(), WorldSession::HandleAuctionSellItem(), ChatHandler::HandleBanListCharacterCommand(), WorldSession::HandleBugOpcode(), WorldSession::HandleChangePlayerNameOpcode(), WorldSession::HandleChangePlayerNameOpcodeCallBack(), ChatHandler::HandleCharacterDeletedRestoreHelper(), ChatHandler::HandleCharacterRenameCommand(), WorldSession::HandleCharCreateOpcode(), WorldSession::HandleCharDeleteOpcode(), WorldSession::HandleCharEnumOpcode(), WorldSession::HandleDeclinedPlayerNameOpcode(), WorldSession::HandleGMSurveySubmit(), WorldSession::HandleGuildBankDeposit(), WorldSession::HandleGuildBankDepositItem(), WorldSession::HandleGuildBankWithdraw(), ChatHandler::HandleLevelUpCommand(), ChatHandler::HandleListFreezeCommand(), ChatHandler::HandleListItemCommand(), WorldSession::HandleOfferPetitionOpcode(), WorldSession::HandleOpenItemOpcode(), WorldSession::HandlePetitionBuyOpcode(), WorldSession::HandlePetitionDeclineOpcode(), WorldSession::HandlePetitionRenameOpcode(), WorldSession::HandlePetitionShowSignOpcode(), WorldSession::HandlePetitionSignOpcode(), WorldSession::HandlePetRename(), ChatHandler::HandlePInfoCommand(), WorldSession::HandlePlayerLogin(), WorldSession::HandlePlayerLoginOpcode(), GameEventMgr::HandleQuestComplete(), ChatHandler::HandleResetAllCommand(), ChatHandler::HandleResetSpellsCommand(), ChatHandler::HandleResetTalentsCommand(), WorldSession::HandleReturnToSender(), WorldSession::HandleSendMail(), WorldSession::HandleStablePet(), WorldSession::HandleStableSwapPet(), WorldSession::HandleTakeItem(), WorldSession::HandleTakeMoney(), WorldSession::HandleTurnInPetitionOpcode(), ChatHandler::HandleUnFreezeCommand(), WorldSession::HandleUnstablePet(), WorldSession::HandleWrapItemOpcode(), BattlegroundMgr::InitAutomaticArenaPointDistribution(), World::InitDailyQuestResetTime(), AuctionHouseBot::Initialize(), MapManager::InitMaxInstanceId(), World::InitResultQueue(), TicketMgr::InitTicketID(), ObjectMgr::LoadArenaTeams(), AuctionHouseMgr::LoadAuctionItems(), AuctionHouseMgr::LoadAuctions(), Guild::LoadBankRightsFromDB(), ObjectMgr::LoadCorpses(), PlayerDumpReader::LoadDump(), GameEventMgr::LoadFromDB(), Item::LoadFromDB(), Player::LoadFromDB(), TicketMgr::LoadGMSurveys(), TicketMgr::LoadGMTickets(), Group::LoadGroupFromDB(), ObjectMgr::LoadGroups(), Guild::LoadGuildBankEventLogFromDB(), Guild::LoadGuildBankFromDB(), Guild::LoadGuildEventLogFromDB(), ObjectMgr::LoadGuilds(), ObjectMgr::LoadItemTexts(), ArenaTeam::LoadMembersFromDB(), Guild::LoadMembersFromDB(), Player::LoadPet(), Pet::LoadPetFromDB(), ObjectMgr::LoadPetNumber(), Player::LoadPositionFromDB(), Guild::LoadRanksFromDB(), InstanceSaveManager::LoadResetTimes(), World::LoadSQLUpdates(), AuctionHouseBot::LoadValues(), Player::LoadValuesArrayFromDB(), Guild::LogBankEvent(), Guild::LogGuildEvent(), WorldSession::LogoutPlayer(), ChatHandler::LookupPlayerSearchCommand(), Guild::MemberItemWithdraw(), Guild::MemberMoneyWithdraw(), Player::ModifyArenaPoints(), InstanceSaveManager::PackInstances(), PlayerSocial::RemoveFromSocialList(), InstanceSaveManager::RemoveInstanceSave(), Guild::RemoveItem(), Player::RemovePetitionsAndSigns(), Guild::RenumBankLogs(), Guild::RenumGuildEventlog(), World::ResetDailyQuests(), Group::ResetInstances(), Player::ResetSpells(), Player::ResetTalents(), ObjectMgr::ReturnOrDeleteOldMails(), Master::Run(), Player::SaveDataFieldToDB(), TicketMgr::SaveGMTicket(), Player::SaveGoldToDB(), Pet::SavePetToDB(), Player::SavePositionInDB(), PoolMgr::SaveQuestsToDB(), Corpse::SaveToDB(), ReputationMgr::SaveToDB(), AuctionEntry::SaveToDB(), InstanceSave::SaveToDB(), InstanceData::SaveToDB(), Item::SaveToDB(), ArenaTeam::SaveToDB(), Player::SaveToDB(), Player::SaveValuesArrayInDB(), GameEventMgr::SaveWorldEventStateToDB(), AuctionHouseMgr::SendAuctionWonMail(), WorldSession::SendExternalMails(), MailDraft::SendMailTo(), WorldSession::SendNameQueryOpcodeFromDB(), WorldSession::SendPetitionQueryOpcode(), MailDraft::SendReturnToSender(), WorldSession::SendStablePet(), Guild::SetBankMoney(), Guild::SetBankMoneyPerDay(), Guild::SetBankRightsAndSlots(), ArenaTeam::SetCaptain(), Group::SetDifficulty(), ArenaTeam::SetEmblem(), Guild::SetEmblem(), PlayerSocial::SetFriendNote(), Guild::SetGINFO(), Guild::SetGuildBankTabInfo(), Guild::SetGuildBankTabText(), ObjectMgr::SetHighestGuids(), Player::SetHomebindToLocation(), World::SetInitialWorldSettings(), Guild::SetLeader(), Guild::SetMOTD(), Guild::SetOFFNOTE(), Guild::SetPNOTE(), Guild::SetRankName(), Guild::SetRankRights(), ArenaTeam::SetStats(), PoolGroup< Quest >::SpawnObject(), GameEventMgr::StopEvent(), Group::UnbindInstance(), Player::UnbindInstance(), AuctionHouseObject::Update(), BattlegroundMgr::Update(), World::UpdateRealmCharCount(), Battleground::~Battleground(), and WorldSession::~WorldSession().

DatabaseType LoginDatabase

Accessor to the realm/login database.

Definition at line 55 of file Main.cpp.

uint32 realmID

Id of the realm.

Definition at line 57 of file Main.cpp.

DatabaseType WorldDatabase

Accessor to the world database.

Definition at line 53 of file Main.cpp.

Referenced by Master::_StartDB(), ObjectMgr::AddGameTele(), ObjectMgr::AddGraveYardLink(), ObjectMgr::AddVendorItem(), WDBThreadStartReq1::call(), WDBThreadEndReq1::call(), InstanceSaveManager::CleanupInstances(), BattlegroundMgr::CreateInitialBattlegrounds(), OPvPCapturePoint::DelCreature(), Creature::DeleteFromDB(), GameObject::DeleteFromDB(), ObjectMgr::DeleteGameTele(), ObjectMgr::DeleteRespawnTimeForInstance(), ChatHandler::getCommandTable(), ChatHandler::HandleAddItemCommand(), ChatHandler::HandleGoCreatureCommand(), ChatHandler::HandleLearnAllMySpellsCommand(), ChatHandler::HandleListCreatureCommand(), ChatHandler::HandleListObjectCommand(), ChatHandler::HandleNearObjectCommand(), ChatHandler::HandleNpcFactionIdCommand(), ChatHandler::HandleNpcFlagCommand(), ChatHandler::HandleNpcMoveCommand(), ChatHandler::HandleNpcSpawnDistCommand(), ChatHandler::HandleNpcSpawnTimeCommand(), ChatHandler::HandlePInfoCommand(), ChatHandler::HandleTargetObjectCommand(), ChatHandler::HandleWpAddCommand(), ChatHandler::HandleWpEventCommand(), ChatHandler::HandleWpLoadPathCommand(), ChatHandler::HandleWpModifyCommand(), ChatHandler::HandleWpShowCommand(), ChatHandler::HandleWpUnLoadPathCommand(), PoolMgr::Initialize(), AuctionHouseBot::Initialize(), WaypointMgr::Load(), SQLStorageLoaderBase< T >::Load(), ObjectMgr::LoadAccessRequirements(), ObjectMgr::LoadAreaTriggerScripts(), ObjectMgr::LoadAreaTriggerTeleports(), World::LoadAutobroadcasts(), ObjectMgr::LoadBattleMastersEntry(), ConditionMgr::LoadConditions(), ObjectMgr::LoadCreatureClassLevelStats(), CreatureEventAIMgr::LoadCreatureEventAI_Scripts(), CreatureEventAIMgr::LoadCreatureEventAI_Summons(), CreatureEventAIMgr::LoadCreatureEventAI_Texts(), FormationMgr::LoadCreatureFormations(), ObjectMgr::LoadCreatureLinkedRespawn(), ObjectMgr::LoadCreatureLocales(), ObjectMgr::LoadCreatureRespawnTimes(), ObjectMgr::LoadCreatures(), CreatureTextMgr::LoadCreatureTextLocales(), CreatureTextMgr::LoadCreatureTexts(), ObjectMgr::LoadDbScriptStrings(), World::LoadDBVersion(), DisableMgr::LoadDisables(), ObjectMgr::LoadExplorationBaseXP(), ObjectMgr::LoadFishingBaseSkillLevel(), GameEventMgr::LoadFromDB(), PoolMgr::LoadFromDB(), SmartWaypointMgr::LoadFromDB(), ObjectMgr::LoadGameObjectLocales(), ObjectMgr::LoadGameobjectRespawnTimes(), ObjectMgr::LoadGameobjects(), ObjectMgr::LoadGameTele(), ObjectMgr::LoadGossipMenu(), ObjectMgr::LoadGossipMenuItems(), ObjectMgr::LoadGossipMenuItemsLocales(), ObjectMgr::LoadGossipText(), ObjectMgr::LoadGraveyardZones(), World::LoadIp2nation(), ObjectMgr::LoadItemLocales(), LootStore::LoadLootTable(), ObjectMgr::LoadNpcTextId(), ObjectMgr::LoadNpcTextLocales(), World::LoadOpcodeProtection(), ObjectMgr::LoadOregonStrings(), ObjectMgr::LoadPageTextLocales(), ObjectMgr::LoadPetCreateSpells(), ObjectMgr::LoadPetLevelInfo(), ObjectMgr::LoadPetNames(), ObjectMgr::LoadPlayerInfo(), ObjectMgr::LoadQuestAreaTriggers(), ObjectMgr::LoadQuestLocales(), PoolMgr::LoadQuestPools(), ObjectMgr::LoadQuestRelationsHelper(), ObjectMgr::LoadQuests(), LoadRandomEnchantmentsTable(), ObjectMgr::LoadReputationOnKill(), ObjectMgr::LoadReputationSpilloverTemplate(), ObjectMgr::LoadReservedPlayersNames(), InstanceSaveManager::LoadResetTimes(), ObjectMgr::LoadScriptNames(), ObjectMgr::LoadScripts(), SystemMgr::LoadScriptTexts(), SystemMgr::LoadScriptTextsCustom(), SystemMgr::LoadScriptWaypoints(), LoadSkillDiscoveryTable(), LoadSkillExtraItemTable(), SmartAIMgr::LoadSmartAIFromDB(), SpellMgr::LoadSpellAffects(), SpellMgr::LoadSpellCustomCooldowns(), SpellMgr::LoadSpellDummyCondition(), SpellMgr::LoadSpellEnchantProcData(), SpellMgr::LoadSpellGroups(), SpellMgr::LoadSpellGroupStackRules(), SpellMgr::LoadSpellLearnSpells(), SpellMgr::LoadSpellLinked(), SpellMgr::LoadSpellPetAuras(), SpellMgr::LoadSpellProcEvents(), SpellMgr::LoadSpellRequired(), SpellMgr::LoadSpellTargetPositions(), SpellMgr::LoadSpellThreats(), World::LoadSQLUpdates(), ObjectMgr::LoadTavernAreaTriggers(), ObjectMgr::LoadTempSummons(), ObjectMgr::LoadTrainerSpell(), ObjectMgr::LoadTransportEvents(), MapManager::LoadTransports(), ObjectMgr::LoadVendors(), SystemMgr::LoadVersion(), CWardenDataStorage::LoadWardenDataResult(), ObjectMgr::LoadWaypointScripts(), ObjectMgr::LoadWeatherZoneChances(), InstanceSaveManager::PackInstances(), WaypointMgr::ReloadPath(), ObjectMgr::RemoveGraveYardLink(), ObjectMgr::RemoveVendorItem(), Master::Run(), ObjectMgr::SaveCreatureRespawnTime(), ObjectMgr::SaveGORespawnTime(), Creature::SaveToDB(), GameObject::SaveToDB(), ObjectMgr::SetCreatureLinkedRespawn(), ObjectMgr::SetHighestGuids(), ReactorRunnable::svc(), and Battleground::~Battleground().