diff --git a/include/core.h b/include/core.h index dd51ab2..bd6bc72 100644 --- a/include/core.h +++ b/include/core.h @@ -1481,6 +1481,7 @@ extern bool FindNearestPlayer (void **holder, edict_t *to, float searchDistance extern void FreeLibraryMemory (void); extern void RoundInit (void); +extern void CheckWelcomeMessage (void); extern void AddLogEntry (bool outputToConsole, int logLevel, const char *format, ...); extern void DisplayMenuToClient (edict_t *ent, MenuText *menu); extern void DecalTrace (entvars_t *pev, TraceResult *trace, int logotypeIndex); diff --git a/include/corelib.h b/include/corelib.h index 1c7a30a..d623331 100644 --- a/include/corelib.h +++ b/include/corelib.h @@ -4018,9 +4018,3 @@ public: // Squared Length // #define GET_SQUARE(in) (in * in) - - -// -// Wrapper for singleton access -// -#define SA(obj) obj::GetReference () \ No newline at end of file diff --git a/include/globals.h b/include/globals.h index c2f3826..38cdef3 100644 --- a/include/globals.h +++ b/include/globals.h @@ -17,6 +17,7 @@ extern bool g_waypointOn; extern bool g_autoWaypoint; extern bool g_botsCanPause; extern bool g_editNoclip; +extern bool g_isCommencing; extern float g_autoPathDistance; extern float g_timeBombPlanted; @@ -73,35 +74,3 @@ static inline bool IsNullString (const char *input) return *input == '\0'; } - -// -// simple class to handle welcome messages -// -class WelcomeMessage : public Singleton -{ -private: - bool m_gameCommenced; - bool m_msgReceived; - - float m_receiveTimer; - -public: - WelcomeMessage (void) : m_gameCommenced (false), m_msgReceived (false), m_receiveTimer (0.0f) { } - -public: - void SetGameCommenceFlag (bool isCommenced); - void VerifyMessageSent (void); -}; -]=. - - -inline void WelcomeMessage::SetGameCommenceFlag (bool isCommenced) -{ - m_gameCommenced = isCommenced; - - if (!isCommenced) - { - m_receiveTimer = 0.0f; - m_msgReceived = false; - } -} \ No newline at end of file diff --git a/source/engine.cpp b/source/engine.cpp index 6b5293d..38ec4cc 100644 --- a/source/engine.cpp +++ b/source/engine.cpp @@ -947,8 +947,8 @@ void Engine::ProcessMessageCapture (void *ptr) { g_roundEnded = true; - if (strcmp (strVal, "#Game_Commencing") == 0) - SA (WelcomeMessage).SetGameCommenceFlag (true); + if (FStrEq (strVal, "#Game_Commencing")) + g_isCommencing = true; if (FStrEq (strVal, "#CTs_Win")) { diff --git a/source/globals.cpp b/source/globals.cpp index ba4dc0b..1e0441e 100644 --- a/source/globals.cpp +++ b/source/globals.cpp @@ -439,68 +439,3 @@ MenuText g_menus[21] = "0. Exit" } }; - - -void WelcomeMessage::VerifyMessageSent (void) -{ - if (m_msgReceived) - return; - - static Array sentences; - - if (!(g_gameFlags & (GAME_MOBILITY | GAME_XASH)) && sentences.IsEmpty ()) - { - // add default messages - sentences.Push ("hello user,communication is acquired"); - sentences.Push ("your presence is acknowledged"); - sentences.Push ("high man, your in command now"); - sentences.Push ("blast your hostile for good"); - sentences.Push ("high man, kill some idiot here"); - sentences.Push ("is there a doctor in the area"); - sentences.Push ("warning, experimental materials detected"); - sentences.Push ("high amigo, shoot some but"); - sentences.Push ("attention, hours of work software, detected"); - sentences.Push ("time for some bad ass explosion"); - sentences.Push ("bad ass son of a breach device activated"); - sentences.Push ("high, do not question this great service"); - sentences.Push ("engine is operative, hello and goodbye"); - sentences.Push ("high amigo, your administration has been great last day"); - sentences.Push ("attention, expect experimental armed hostile presence"); - sentences.Push ("warning, medical attention required"); - } - - if (IsAlive (g_hostEntity) && !m_msgReceived && m_receiveTimer < 1.0f && (g_numWaypoints > 0 ? m_gameCommenced : true)) - m_receiveTimer = engine.Time () + 4.0f; // receive welcome message in four seconds after game has commencing - - if (m_receiveTimer > 0.0f && m_receiveTimer < engine.Time () && !m_msgReceived && (g_numWaypoints > 0 ? m_gameCommenced : true)) - { - if (!(g_gameFlags & (GAME_MOBILITY | GAME_XASH))) - engine.IssueCmd ("speak \"%s\"", const_cast (sentences.GetRandomElement ().GetBuffer ())); - - engine.ChatPrintf ("----- %s v%s (Build: %u), {%s}, (c) 2016, by %s (%s)-----", PRODUCT_NAME, PRODUCT_VERSION, GenerateBuildNumber (), PRODUCT_DATE, PRODUCT_AUTHOR, PRODUCT_URL); - - MESSAGE_BEGIN (MSG_ONE, SVC_TEMPENTITY, NULL, g_hostEntity); - WRITE_BYTE (TE_TEXTMESSAGE); - WRITE_BYTE (1); - WRITE_SHORT (FixedSigned16 (-1, 1 << 13)); - WRITE_SHORT (FixedSigned16 (-1, 1 << 13)); - WRITE_BYTE (2); - WRITE_BYTE (Random.Long (33, 255)); - WRITE_BYTE (Random.Long (33, 255)); - WRITE_BYTE (Random.Long (33, 255)); - WRITE_BYTE (0); - WRITE_BYTE (Random.Long (230, 255)); - WRITE_BYTE (Random.Long (230, 255)); - WRITE_BYTE (Random.Long (230, 255)); - WRITE_BYTE (200); - WRITE_SHORT (FixedUnsigned16 (0.0078125f, 1 << 8)); - WRITE_SHORT (FixedUnsigned16 (2.0f, 1 << 8)); - WRITE_SHORT (FixedUnsigned16 (6.0f, 1 << 8)); - WRITE_SHORT (FixedUnsigned16 (0.1f, 1 << 8)); - WRITE_STRING (FormatBuffer ("\nServer is running YaPB v%s (Build: %u)\nDeveloped by %s\n\n%s", PRODUCT_VERSION, GenerateBuildNumber (), PRODUCT_AUTHOR, waypoints.GetInfo ())); - MESSAGE_END (); - - m_receiveTimer = 0.0; - m_msgReceived = true; - } -} diff --git a/source/interface.cpp b/source/interface.cpp index 8f28dc5..8cdb76b 100644 --- a/source/interface.cpp +++ b/source/interface.cpp @@ -2183,7 +2183,7 @@ void StartFrame (void) if (g_waypointOn) waypoints.Think (); - SA (WelcomeMessage).VerifyMessageSent (); + CheckWelcomeMessage (); } bots.SetDeathMsgState (false); @@ -2317,9 +2317,6 @@ void pfnChangeLevel (char *s1, char *s2) waypoints.SaveExperienceTab (); waypoints.SaveVisibilityTab (); - // reset welcome message strate - SA (WelcomeMessage).SetGameCommenceFlag (false); - if (g_gameFlags & GAME_METAMOD) RETURN_META (MRES_IGNORED); diff --git a/source/support.cpp b/source/support.cpp index 42d228f..fe1e691 100644 --- a/source/support.cpp +++ b/source/support.cpp @@ -501,6 +501,75 @@ bool OpenConfig (const char *fileName, const char *errorIfNotExists, MemoryFile return true; } +void CheckWelcomeMessage (void) +{ + // the purpose of this function, is to send quick welcome message, to the listenserver entity. + + static bool alreadyReceived = false; + static float receiveTime = 0.0f; + + if (alreadyReceived) + return; + + Array sentences; + + if (!(g_gameFlags & (GAME_MOBILITY | GAME_XASH))) + { + // add default messages + sentences.Push ("hello user,communication is acquired"); + sentences.Push ("your presence is acknowledged"); + sentences.Push ("high man, your in command now"); + sentences.Push ("blast your hostile for good"); + sentences.Push ("high man, kill some idiot here"); + sentences.Push ("is there a doctor in the area"); + sentences.Push ("warning, experimental materials detected"); + sentences.Push ("high amigo, shoot some but"); + sentences.Push ("attention, hours of work software, detected"); + sentences.Push ("time for some bad ass explosion"); + sentences.Push ("bad ass son of a breach device activated"); + sentences.Push ("high, do not question this great service"); + sentences.Push ("engine is operative, hello and goodbye"); + sentences.Push ("high amigo, your administration has been great last day"); + sentences.Push ("attention, expect experimental armed hostile presence"); + sentences.Push ("warning, medical attention required"); + } + + if (IsAlive (g_hostEntity) && !alreadyReceived && receiveTime < 1.0 && (g_numWaypoints > 0 ? g_isCommencing : true)) + receiveTime = engine.Time () + 4.0f; // receive welcome message in four seconds after game has commencing + + if (receiveTime > 0.0f && receiveTime < engine.Time () && !alreadyReceived && (g_numWaypoints > 0 ? g_isCommencing : true)) + { + if (!(g_gameFlags & (GAME_MOBILITY | GAME_XASH))) + engine.IssueCmd ("speak \"%s\"", const_cast (sentences.GetRandomElement ().GetBuffer ())); + + engine.ChatPrintf ("----- %s v%s (Build: %u), {%s}, (c) 2016, by %s (%s)-----", PRODUCT_NAME, PRODUCT_VERSION, GenerateBuildNumber (), PRODUCT_DATE, PRODUCT_AUTHOR, PRODUCT_URL); + + MESSAGE_BEGIN (MSG_ONE, SVC_TEMPENTITY, NULL, g_hostEntity); + WRITE_BYTE (TE_TEXTMESSAGE); + WRITE_BYTE (1); + WRITE_SHORT (FixedSigned16 (-1, 1 << 13)); + WRITE_SHORT (FixedSigned16 (-1, 1 << 13)); + WRITE_BYTE (2); + WRITE_BYTE (Random.Long (33, 255)); + WRITE_BYTE (Random.Long (33, 255)); + WRITE_BYTE (Random.Long (33, 255)); + WRITE_BYTE (0); + WRITE_BYTE (Random.Long (230, 255)); + WRITE_BYTE (Random.Long (230, 255)); + WRITE_BYTE (Random.Long (230, 255)); + WRITE_BYTE (200); + WRITE_SHORT (FixedUnsigned16 (0.0078125f, 1 << 8)); + WRITE_SHORT (FixedUnsigned16 (2.0f, 1 << 8)); + WRITE_SHORT (FixedUnsigned16 (6.0f, 1 << 8)); + WRITE_SHORT (FixedUnsigned16 (0.1f, 1 << 8)); + WRITE_STRING (FormatBuffer ("\nServer is running YaPB v%s (Build: %u)\nDeveloped by %s\n\n%s", PRODUCT_VERSION, GenerateBuildNumber (), PRODUCT_AUTHOR, waypoints.GetInfo ())); + MESSAGE_END (); + + receiveTime = 0.0; + alreadyReceived = true; + } +} + void AddLogEntry (bool outputToConsole, int logLevel, const char *format, ...) {