fix console initializing too early

the console was initialized too early, leading to the server waiting for
it to shut down if the authkey is invalid, among other issues.
This commit is contained in:
Lion Kortlepel
2023-12-21 12:46:50 +01:00
parent a6cbffc774
commit 81299db946
4 changed files with 51 additions and 38 deletions

View File

@@ -75,7 +75,7 @@ public:
static void RegisterShutdownHandler(const TShutdownHandler& Handler);
// Causes all threads to finish up and exit gracefull gracefully
static void GracefullyShutdown();
static TConsole& Console() { return *mConsole; }
static TConsole& Console() { return mConsole; }
static std::string ServerVersionString();
static const Version& ServerVersion() { return mVersion; }
static uint8_t ClientMajorVersion() { return 2; }
@@ -101,9 +101,7 @@ public:
static void SleepSafeSeconds(size_t Seconds);
static void InitializeConsole() {
if (!mConsole) {
mConsole = std::make_unique<TConsole>();
}
mConsole.InitializeCommandline();
}
enum class Status {
@@ -129,7 +127,7 @@ private:
static inline SystemStatusMap mSystemStatusMap {};
static inline std::mutex mSystemStatusMapMutex {};
static inline std::string mPPS;
static inline std::unique_ptr<TConsole> mConsole;
static inline TConsole mConsole;
static inline std::shared_mutex mShutdownMtx {};
static inline bool mShutdown { false };
static inline std::mutex mShutdownHandlersMutex {};

View File

@@ -17,12 +17,15 @@ class TConsole {
public:
TConsole();
// Initializes the commandline app to take over I/O
void InitializeCommandline();
void Write(const std::string& str);
void WriteRaw(const std::string& str);
void InitializeLuaConsole(TLuaEngine& Engine);
void BackupOldLog();
void StartLoggingToFile();
Commandline& Internal() { return mCommandline; }
Commandline& Internal() { return *mCommandline; }
private:
void RunAsCommand(const std::string& cmd, bool IgnoreNotACommand = false);
@@ -56,7 +59,7 @@ private:
{ "say", [this](const auto&, const auto&) { Command_Say(""); } }, // shouldn't actually be called
};
Commandline mCommandline;
std::unique_ptr<Commandline> mCommandline { nullptr };
std::vector<std::string> mCachedLuaHistory;
std::vector<std::string> mCachedRegularHistory;
TLuaEngine* mLuaEngine { nullptr };