Skip to content

Zero Hour rebuilt from EA's source: x64, Direct3D 11, VS2022/CMake, ~60 original bugs fixed, an AI that builds a base. Bring your own game.

feat(gameengine): -onlinelogin, -onlinesay in UTF-8, scripted desync

Olcay Seygan5dfca7d1312d
diff --git a/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h b/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h
index dba02d973..a93bbacea 100644
--- a/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h
+++ b/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h
@@ -558,6 +558,7 @@ public:
AsciiString m_onlineMap; ///< -onlinemap <map>: the map -onlinehost sets
Int m_onlineStart; ///< -onlinestart [N]: the -onlinehost host starts the game at N players (0 = never, bare = 2)
Bool m_quickMatchOnStart; ///< -quickmatch: go into the Quick Match queue once logged in
+ Bool m_onlineLoginOnStart; ///< -onlinelogin: open the online login screen at startup, nothing filled in
Bool m_lanLobbyOnStart; ///< -lanlobby: open the LAN lobby instead of stopping at the main menu
Bool m_skirmishLobbyOnStart; ///< -skirmishlobby: open the skirmish staging room instead of stopping at the main menu
Bool m_optionsMenuOnStart; ///< -optionsmenu: open the options screen over the main menu at startup
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/CommandLine.cpp b/GeneralsMD/Code/GameEngine/Source/Common/CommandLine.cpp
index e6b92dac0..bf2a6b5f6 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/CommandLine.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/CommandLine.cpp
@@ -2612,7 +2612,25 @@ Int parseOnlinePass(char *args[], int num) { return parseOnlineText( args, num
Int parseOnlineRegister(char *args[], int num) { return parseOnlineText( args, num, &GlobalData::m_onlineRegisterNick ); }
Int parseOnlineHostGame(char *args[], int num) { return parseOnlineText( args, num, &GlobalData::m_onlineHostGame ); }
Int parseOnlineJoin(char *args[], int num) { return parseOnlineText( args, num, &GlobalData::m_onlineJoinGame ); }
-Int parseOnlineSay(char *args[], int num) { return parseOnlineText( args, num, &GlobalData::m_onlineSay ); }
+/* -onlinesay is chat, kept as UTF-8 like every line the service carries. Windows hands the switch over in
+ the ANSI code page, which on a Turkish machine made "ı" a lone 0xFD byte. */
+Int parseOnlineSay(char *args[], int num)
+{
+ const Int used = parseOnlineText( args, num, &GlobalData::m_onlineSay );
+#if defined(_WIN32)
+ if (TheWritableGlobalData && num > 1)
+ {
+ const int wideLength = MultiByteToWideChar( CP_ACP, 0, args[1], -1, NULL, 0 );
+ std::wstring wide( wideLength > 0 ? wideLength : 1, L'\0' );
+ MultiByteToWideChar( CP_ACP, 0, args[1], -1, &wide[0], wideLength );
+ const int length = WideCharToMultiByte( CP_UTF8, 0, wide.c_str(), -1, NULL, 0, NULL, NULL );
+ std::string utf8( length > 0 ? length : 1, '\0' );
+ WideCharToMultiByte( CP_UTF8, 0, wide.c_str(), -1, &utf8[0], length, NULL, NULL );
+ TheWritableGlobalData->m_onlineSay = utf8.c_str();
+ }
+#endif
+ return used;
+}
Int parseOnlineMap(char *args[], int num) { return parseOnlineText( args, num, &GlobalData::m_onlineMap ); }
/* -onlinestart N: the -onlinehost host starts the game once N players (itself included) sit in the room;
@@ -2627,6 +2645,18 @@ Int parseOnlineStart(char *args[], int num)
return hasNumber ? 2 : 1;
}
+/* -onlinelogin: the online login screen at startup with empty fields, for a person trying the service by
+ hand; the shell map goes off as it does for -onlineuser */
+Int parseOnlineLogin(char *args[], int num)
+{
+ if (TheWritableGlobalData)
+ {
+ TheWritableGlobalData->m_onlineLoginOnStart = TRUE;
+ TheWritableGlobalData->m_shellMapOn = FALSE;
+ }
+ return 1;
+}
+
Int parseQuickMatch(char *args[], int num)
{
if (TheWritableGlobalData)
@@ -3166,6 +3196,7 @@ static CommandLineParam params[] =
{ "-onlinesay", parseOnlineSay },
{ "-onlinemap", parseOnlineMap },
{ "-onlinestart", parseOnlineStart },
+ { "-onlinelogin", parseOnlineLogin },
{ "-quickmatch", parseQuickMatch },
{ "-lanlobby", parseLanLobby },
{ "-skirmishlobby", parseSkirmishLobby },
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp b/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp
index 595950cf1..808c30345 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp
@@ -806,6 +806,7 @@ GlobalData::GlobalData()
m_onlineMap.clear();
m_onlineStart = 0;
m_quickMatchOnStart = FALSE;
+ m_onlineLoginOnStart = FALSE;
m_lanLobbyOnStart = FALSE;
m_skirmishLobbyOnStart = FALSE;
m_optionsMenuOnStart = FALSE;
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/System/ControlServer.cpp b/GeneralsMD/Code/GameEngine/Source/Common/System/ControlServer.cpp
index cb61e5e4b..9eeb7d77c 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/System/ControlServer.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/System/ControlServer.cpp
@@ -915,8 +915,11 @@ static void handleCommand( const AsciiString &command )
/* A world command changes this machine's simulation and nobody else's. A network match the
lobby started would split on it, and a replay would stop matching its recording; a -netgame
- match is allowed, on the same terms -scenario is (GameLogic::startNewGame). */
- if ((TheGameLogic->isInMultiplayerGame() && !TheGlobalData->m_netGameStarted) || TheGameLogic->isInReplayGame())
+ match is allowed, on the same terms -scenario is (GameLogic::startNewGame). So is an online match a
+ copy logged into with the -onlineuser test switch, where online_check.py forces its desync: a split
+ there ends the match unrated, which is what the check proves. */
+ const Bool scriptedOnline = TheGlobalData->m_onlineUser.isNotEmpty() && TheGlobalData->m_onlinePort != 0;
+ if ((TheGameLogic->isInMultiplayerGame() && !TheGlobalData->m_netGameStarted && !scriptedOnline) || TheGameLogic->isInReplayGame())
{
replyError( "world commands only run in a skirmish or a -netgame match" );
return;
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/WOLGameSetupMenu.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/WOLGameSetupMenu.cpp
index 1496151cc..7b5067dad 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/WOLGameSetupMenu.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/WOLGameSetupMenu.cpp
@@ -63,6 +63,7 @@
#include "GameNetwork/GameSpy/BuddyDefs.h"
#include "GameNetwork/GameSpy/PeerDefs.h"
#include "GameNetwork/GameSpy/PeerThread.h"
+#include "GameNetwork/GameSpy/ThreadUtils.h"
#include "GameNetwork/GameSpy/PersistentStorageDefs.h"
#include "GameNetwork/GameSpy/PersistentStorageThread.h"
#include "GameNetwork/GameSpyOverlay.h"
@@ -1655,12 +1656,16 @@ static void onlineStagingScript( void )
if (!game || !game->isInGame() || game->isGameInProgress())
return;
+ // said once a second player is seated, so somebody reads it
static Bool s_said = FALSE;
- if (!s_said && TheGlobalData->m_onlineSay.isNotEmpty())
+ Int seated = 0;
+ for (Int i = 0; i < MAX_SLOTS; ++i)
+ if (game->getSlot( i ) && game->getSlot( i )->isHuman())
+ ++seated;
+ if (!s_said && seated >= 2 && TheGlobalData->m_onlineSay.isNotEmpty())
{
s_said = TRUE;
- UnicodeString line;
- line.translate( TheGlobalData->m_onlineSay );
+ UnicodeString line( MultiByteToWideCharSingleLine( TheGlobalData->m_onlineSay.str() ).c_str() );
PeerRequest req;
req.peerRequestType = PeerRequest::PEERREQUEST_MESSAGEROOM;
req.text = line.str();
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/WOLLobbyMenu.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/WOLLobbyMenu.cpp
index 5021e73d9..aaa280463 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/WOLLobbyMenu.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/WOLLobbyMenu.cpp
@@ -70,6 +70,7 @@
#include "GameNetwork/GameSpy/LadderDefs.h"
#include "GameNetwork/GameSpy/PeerDefs.h"
#include "GameNetwork/GameSpy/PeerThread.h"
+#include "GameNetwork/GameSpy/ThreadUtils.h"
#include "GameNetwork/GameSpy/PersistentStorageDefs.h"
#include "GameNetwork/GameSpy/PersistentStorageThread.h"
#include "GameNetwork/GameSpy/LobbyUtils.h"
@@ -231,21 +232,24 @@ void SetLobbyAttemptHostJoin(Bool start)
s_tryingToHostOrJoin = start;
}
-/* -online scripting in the lobby, once per process each: -onlinesay says its line, -onlinehost asks for a
- staging room the way the host popup's createGame does (no password, no observers, unrated, no ladder),
- -onlinejoin joins the first listed game of that name the way the Join button does. */
+/* -online scripting in the lobby, once per process each: -onlinesay says its line once somebody else is in
+ the room to read it, -onlinehost asks for a staging room the way the host popup's createGame does (no
+ password, no observers, unrated, no ladder) three seconds after that line so the answer still reaches
+ the lobby, -onlinejoin joins the first listed game of that name the way the Join button does. */
static void onlineLobbyScript( void )
{
static Bool s_said = FALSE, s_hosted = FALSE, s_joined = FALSE;
+ static UnsignedInt s_saidAt = 0;
if (!OnlineIsEnabled() || !TheGameSpyInfo->getCurrentGroupRoom() || s_tryingToHostOrJoin)
return;
- if (!s_said && TheGlobalData->m_onlineSay.isNotEmpty())
+ const Bool saying = TheGlobalData->m_onlineSay.isNotEmpty();
+ if (saying && !s_said && TheGameSpyInfo->getPlayerInfoMap()->size() >= 2)
{
s_said = TRUE;
+ s_saidAt = Clock_Milliseconds();
// straight to the queue: sendChat would drop the staging room's copy as a repeat of this one
- UnicodeString line;
- line.translate( TheGlobalData->m_onlineSay );
+ UnicodeString line( MultiByteToWideCharSingleLine( TheGlobalData->m_onlineSay.str() ).c_str() );
PeerRequest req;
req.peerRequestType = PeerRequest::PEERREQUEST_MESSAGEROOM;
req.text = line.str();
@@ -254,7 +258,8 @@ static void onlineLobbyScript( void )
DEBUG_LOG(("ONLINE SAY where=lobby text=%s\n", TheGlobalData->m_onlineSay.str()));
}
- if (!s_hosted && TheGlobalData->m_onlineHostGame.isNotEmpty())
+ if (!s_hosted && TheGlobalData->m_onlineHostGame.isNotEmpty()
+ && (!saying || (s_said && Clock_Milliseconds() - s_saidAt >= 3000)))
{
s_hosted = TRUE;
SetLobbyAttemptHostJoin( TRUE );
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/Shell/Shell.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/Shell/Shell.cpp
index 6bcd1e89b..bdb1d6fb2 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/Shell/Shell.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/Shell/Shell.cpp
@@ -555,7 +555,7 @@ void Shell::showShell( Bool runInit )
/* -online with -onlineuser: what the main menu's Online button does, spent the same way. The login
screen then logs in from the switches (WOLLoginMenu.cpp). */
- if( OnlineIsEnabled() && TheGlobalData->m_onlineUser.isNotEmpty() && !s_onlineOpened )
+ if( OnlineIsEnabled() && (TheGlobalData->m_onlineUser.isNotEmpty() || TheGlobalData->m_onlineLoginOnStart) && !s_onlineOpened )
{
s_onlineOpened = TRUE;
StartPatchCheck();
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GameText.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GameText.cpp
index 22d75f268..c922ee7c2 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GameText.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GameText.cpp
@@ -1500,7 +1500,8 @@ UnicodeString GameTextManager::fetch( const Char *label, Bool *exists )
noString = noString->next;
}
- //DEBUG_LOG(("*** MISSING:'%s' ***\n", label));
+ // once a label: the list above answers every later fetch. online_check.py greps it
+ DEBUG_LOG(("TEXT MISSING '%s'\n", label));
// Remember file could have been altered at this point.
noString = NEW NoString;
noString->text = missingString;