From aaa33d5385a4ef881e41d25c878d7b1526defc85 Mon Sep 17 00:00:00 2001 From: VladimirMangos Date: Sun, 16 May 2010 02:01:01 +0400 Subject: [PATCH] [9904] Add new config option for wait mode at startup error. Note: it not applied to crashes and shutdowns after mangosd/relamd startup completed. You can continue without delay (as now) and fast exist, or wait , or some secs for continue. Last can be helpful for see for example not applied sql update revision data and etc. --- src/game/Player.cpp | 2 +- src/game/World.cpp | 8 ++------ src/mangosd/Main.cpp | 3 +++ src/mangosd/Master.cpp | 5 +++++ src/mangosd/mangosd.conf.dist.in | 7 +++++++ src/realmd/Main.cpp | 14 +++++++++++--- src/realmd/realmd.conf.dist.in | 7 +++++++ src/shared/Log.cpp | 28 ++++++++++++++++++++++++++++ src/shared/Log.h | 2 ++ src/shared/revision_nr.h | 2 +- 10 files changed, 67 insertions(+), 11 deletions(-) diff --git a/src/game/Player.cpp b/src/game/Player.cpp index d4c8a5d3a..5fce4ab06 100644 --- a/src/game/Player.cpp +++ b/src/game/Player.cpp @@ -4269,7 +4269,7 @@ void Player::DeleteOldCharacters(uint32 keepDays) QueryResult *resultChars = CharacterDatabase.PQuery("SELECT guid, deleteInfos_Account FROM characters WHERE deleteDate IS NOT NULL AND deleteDate < '" UI64FMTD "'", uint64(time(NULL) - time_t(keepDays * DAY))); if (resultChars) { - sLog.outString("Player::DeleteOldChars: Found %u character(s) to delete",resultChars->GetRowCount()); + sLog.outString("Player::DeleteOldChars: Found %u character(s) to delete",uint32(resultChars->GetRowCount())); do { Field *charFields = resultChars->Fetch(); diff --git a/src/game/World.cpp b/src/game/World.cpp index f8a076492..40e73595c 100644 --- a/src/game/World.cpp +++ b/src/game/World.cpp @@ -419,9 +419,7 @@ void World::LoadConfigSettings(bool reload) sLog.outError(" WARNING: mangosd.conf does not include a ConfVersion variable."); sLog.outError(" Your configuration file may be out of date!"); sLog.outError("*****************************************************************************"); - clock_t pause = 3000 + clock(); - while (pause > clock()) - ; // empty body + Log::WaitBeforeContinueIfNeed(); } else { @@ -432,9 +430,7 @@ void World::LoadConfigSettings(bool reload) sLog.outError(" Please check for updates, as your current default values may cause"); sLog.outError(" unexpected behavior."); sLog.outError("*****************************************************************************"); - clock_t pause = 3000 + clock(); - while (pause > clock()) - ; // empty body + Log::WaitBeforeContinueIfNeed(); } } diff --git a/src/mangosd/Main.cpp b/src/mangosd/Main.cpp index b3ac953e6..af5daf420 100644 --- a/src/mangosd/Main.cpp +++ b/src/mangosd/Main.cpp @@ -108,6 +108,7 @@ extern int main(int argc, char **argv) { sLog.outError("Runtime-Error: -s option requires an input argument"); usage(argv[0]); + Log::WaitBeforeContinueIfNeed(); return 1; } if( strcmp(argv[c],"install") == 0) @@ -126,6 +127,7 @@ extern int main(int argc, char **argv) { sLog.outError("Runtime-Error: unsupported option %s",argv[c]); usage(argv[0]); + Log::WaitBeforeContinueIfNeed(); return 1; } } @@ -141,6 +143,7 @@ extern int main(int argc, char **argv) if (!sConfig.SetSource(cfg_file)) { sLog.outError("Could not find configuration file %s.", cfg_file); + Log::WaitBeforeContinueIfNeed(); return 1; } diff --git a/src/mangosd/Master.cpp b/src/mangosd/Master.cpp index 99f5836e7..9478a8d9d 100644 --- a/src/mangosd/Master.cpp +++ b/src/mangosd/Master.cpp @@ -194,6 +194,7 @@ int Master::Run() if( !pid ) { sLog.outError( "Cannot create PID file %s.\n", pidfile.c_str() ); + Log::WaitBeforeContinueIfNeed(); return 1; } @@ -202,7 +203,10 @@ int Master::Run() ///- Start the databases if (!_StartDB()) + { + Log::WaitBeforeContinueIfNeed(); return 1; + } ///- Initialize the World sWorld.SetInitialWorldSettings(); @@ -315,6 +319,7 @@ int Master::Run() if (sWorldSocketMgr->StartNetwork (wsport, bind_ip) == -1) { sLog.outError ("Failed to start network"); + Log::WaitBeforeContinueIfNeed(); World::StopNow(ERROR_EXIT_CODE); // go down and shutdown the server } diff --git a/src/mangosd/mangosd.conf.dist.in b/src/mangosd/mangosd.conf.dist.in index fbf9a2176..b0e66de69 100644 --- a/src/mangosd/mangosd.conf.dist.in +++ b/src/mangosd/mangosd.conf.dist.in @@ -669,6 +669,12 @@ LogColors = "" # Default: 1 (true) # 0 (false) # +# WaitAtStartupError +# After startup error report wait or some time before continue (and possible close console window) +# -1 (wait until press) +# Default: 0 (not wait) +# N (>0, wait N secs) +# # Motd # Message of the Day. Displayed at worldlogin for every user ('@' for a newline). # @@ -733,6 +739,7 @@ OffhandCheckAtTalentsReset = 0 ClientCacheVersion = 0 Event.Announce = 0 BeepAtStart = 1 +WaitAtStartupError = 0 Motd = "Welcome to the Massive Network Game Object Server." ################################################################################################################### diff --git a/src/realmd/Main.cpp b/src/realmd/Main.cpp index 8462d1162..80000bc76 100644 --- a/src/realmd/Main.cpp +++ b/src/realmd/Main.cpp @@ -87,6 +87,7 @@ extern int main(int argc, char **argv) { sLog.outError("Runtime-Error: -c option requires an input argument"); usage(argv[0]); + Log::WaitBeforeContinueIfNeed(); return 1; } else @@ -109,6 +110,7 @@ extern int main(int argc, char **argv) { sLog.outError("Runtime-Error: -s option requires an input argument"); usage(argv[0]); + Log::WaitBeforeContinueIfNeed(); return 1; } if( strcmp(argv[c],"install") == 0) @@ -127,6 +129,7 @@ extern int main(int argc, char **argv) { sLog.outError("Runtime-Error: unsupported option %s",argv[c]); usage(argv[0]); + Log::WaitBeforeContinueIfNeed(); return 1; } } @@ -142,6 +145,7 @@ extern int main(int argc, char **argv) if (!sConfig.SetSource(cfg_file)) { sLog.outError("Could not find configuration file %s.", cfg_file); + Log::WaitBeforeContinueIfNeed(); return 1; } sLog.Initialize(); @@ -159,9 +163,7 @@ extern int main(int argc, char **argv) sLog.outError(" Please check for updates, as your current default values may cause"); sLog.outError(" strange behavior."); sLog.outError("*****************************************************************************"); - clock_t pause = 3000 + clock(); - - while (pause > clock()) {} + Log::WaitBeforeContinueIfNeed(); } DETAIL_LOG("%s (Library: %s)", OPENSSL_VERSION_TEXT, SSLeay_version(SSLEAY_VERSION)); @@ -179,6 +181,7 @@ extern int main(int argc, char **argv) if( !pid ) { sLog.outError( "Cannot create PID file %s.\n", pidfile.c_str() ); + Log::WaitBeforeContinueIfNeed(); return 1; } @@ -187,13 +190,17 @@ extern int main(int argc, char **argv) ///- Initialize the database connection if(!StartDB()) + { + Log::WaitBeforeContinueIfNeed(); return 1; + } ///- Get the list of realms for the server sRealmList.Initialize(sConfig.GetIntDefault("RealmsStateUpdateDelay", 20)); if (sRealmList.size() == 0) { sLog.outError("No valid realms specified."); + Log::WaitBeforeContinueIfNeed(); return 1; } @@ -206,6 +213,7 @@ extern int main(int argc, char **argv) if ( authListenSocket.Bind(bind_ip.c_str(),rmport)) { sLog.outError( "MaNGOS realmd can not bind to %s:%d",bind_ip.c_str(), rmport ); + Log::WaitBeforeContinueIfNeed(); return 1; } diff --git a/src/realmd/realmd.conf.dist.in b/src/realmd/realmd.conf.dist.in index 66335b718..20e179217 100644 --- a/src/realmd/realmd.conf.dist.in +++ b/src/realmd/realmd.conf.dist.in @@ -76,6 +76,12 @@ ConfVersion=2007062001 # Default: 1 (HIGH) # 0 (Normal) # +# WaitAtStartupError +# After startup error report wait or some time before continue (and possible close console window) +# -1 (wait until press) +# Default: 0 (not wait) +# N (>0, wait N secs) +# # RealmsStateUpdateDelay # Realm list Update up delay (updated at realm list request if delay expired). # Default: 20 @@ -110,6 +116,7 @@ LogFileLevel = 0 LogColors = "" UseProcessors = 0 ProcessPriority = 1 +WaitAtStartupError = 0 RealmsStateUpdateDelay = 20 WrongPass.MaxCount = 0 WrongPass.BanTime = 600 diff --git a/src/shared/Log.cpp b/src/shared/Log.cpp index 83d75a563..894574d90 100644 --- a/src/shared/Log.cpp +++ b/src/shared/Log.cpp @@ -22,8 +22,13 @@ #include "Config/ConfigEnv.h" #include "Util.h" #include "ByteBuffer.h" +#include "ProgressBar.h" #include +#include +#include + +#include "ace/OS_NS_unistd.h" INSTANTIATE_SINGLETON_1( Log ); @@ -815,6 +820,29 @@ void Log::outRALog( const char * str, ... ) fflush(stdout); } +void Log::WaitBeforeContinueIfNeed() +{ + int mode = sConfig.GetIntDefault("WaitAtStartupError",0); + + if (mode < 0) + { + printf("\nPress for continue\n"); + + std::string line; + std::getline (std::cin, line); + } + else if (mode > 0) + { + printf("\nWait %u secs for continue.\n",mode); + barGoLink bar(mode); + for(int i = 0; i < mode; ++i) + { + bar.step(); + ACE_OS::sleep(1); + } + } +} + void outstring_log(const char * str, ...) { if (!str) diff --git a/src/shared/Log.h b/src/shared/Log.h index 8cfb9f802..93815753b 100644 --- a/src/shared/Log.h +++ b/src/shared/Log.h @@ -140,6 +140,8 @@ class Log : public MaNGOS::Singleton= loglvl || (m_logFileLevel >= loglvl && logfile); } bool IsOutCharDump() const { return m_charLog_Dump; } bool IsIncludeTime() const { return m_includeTime; } + + static void WaitBeforeContinueIfNeed(); private: FILE* openLogFile(char const* configFileName,char const* configTimeStampFlag, char const* mode); FILE* openGmlogPerAccount(uint32 account); diff --git a/src/shared/revision_nr.h b/src/shared/revision_nr.h index 965ce8269..a5af4178b 100644 --- a/src/shared/revision_nr.h +++ b/src/shared/revision_nr.h @@ -1,4 +1,4 @@ #ifndef __REVISION_NR_H__ #define __REVISION_NR_H__ - #define REVISION_NR "9903" + #define REVISION_NR "9904" #endif // __REVISION_NR_H__