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.
C++ cmakecnccommand-and-conquercppdirectx11game-enginegame-preservationgeneralsrtssage-enginex64zero-hour
feat(gamenetwork): online login only, Create Account opens the site
Olcay Seygan53947e65f211
diff --git a/GeneralsMD/Code/Data/Patch.str b/GeneralsMD/Code/Data/Patch.strindex 3a111f12b..1e8285101 100644--- a/GeneralsMD/Code/Data/Patch.str+++ b/GeneralsMD/Code/Data/Patch.str@@ -3253,3 +3253,8 @@ ENDGUI:???"Random"END++// the online login screen's one account field: the service takes the email or the nick+GUI:OnlineLoginName+"Email or Nickname"+ENDdiff --git a/GeneralsMD/Code/Data/Turkish/Generals.str b/GeneralsMD/Code/Data/Turkish/Generals.strindex c74c43677..dbe6dac12 100644--- a/GeneralsMD/Code/Data/Turkish/Generals.str+++ b/GeneralsMD/Code/Data/Turkish/Generals.str@@ -10529,6 +10529,10 @@ GUI:Lobby"Lobi"END+GUI:OnlineLoginName+"E-posta veya Kullanıcı Adı"+END+GUI:???"Rastgele"ENDdiff --git a/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h b/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.hindex a93bbacea..28aefe161 100644--- a/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h+++ b/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h@@ -551,7 +551,6 @@ public:AsciiString m_onlineCAFile; ///< -onlineca <file>: PEM CA the service's certificate is checked against (empty = the Let's Encrypt roots)AsciiString m_onlineUser; ///< -onlineuser <email>: log in with this account instead of the login screen's fieldsAsciiString m_onlinePass; ///< -onlinepass <password>: its password (a test switch: it shows in the process list)- AsciiString m_onlineRegisterNick; ///< -onlineregister <nick>: create the -onlineuser account under this nick before logging inAsciiString m_onlineHostGame; ///< -onlinehost <name>: host a custom game of this name once in the lobbyAsciiString m_onlineJoinGame; ///< -onlinejoin <name>: join the custom game of this name once it is listedAsciiString m_onlineSay; ///< -onlinesay <text>: say this in the lobby and again in the staging roomdiff --git a/GeneralsMD/Code/GameEngine/Include/GameNetwork/Online/OnlineQueues.h b/GeneralsMD/Code/GameEngine/Include/GameNetwork/Online/OnlineQueues.hindex 8792f4ef9..6d7414093 100644--- a/GeneralsMD/Code/GameEngine/Include/GameNetwork/Online/OnlineQueues.h+++ b/GeneralsMD/Code/GameEngine/Include/GameNetwork/Online/OnlineQueues.h@@ -68,6 +68,16 @@ void OnlineDisconnect( void ); ///< hangs up; the next OnlineUpdate dials a/* The welcome said testMode, which a server sends only when started for a test. Only then does the-control socket run world commands in an online match: anywhere else they are a cheat. */Bool OnlineIsTestServer( void );+/* welcome.registerUrl, the site's page where accounts are made (the game only logs in); empty when the+ server sent none, and the login screen then hides Create Account. */+AsciiString OnlineGetRegisterUrl( void );+/* Opens an http or https address in the player's browser; FALSE when it is not one or nothing could open+ it. Windows asks the shell; elsewhere the platform layer's hook, SDL_OpenURL, set by SdlGameEngine. */+Bool OnlineOpenURL( const char *url );+#if !defined(_WIN32)+typedef bool (*OnlineOpenURLHook)( const char *url );+extern OnlineOpenURLHook TheOnlineOpenURLHook;+#endif/* The relay. Both are FALSE until a login succeeded (auth.ok). The ticket goes into the UDP HELLO_AUTH,which has to be sent right after login: the peer queue answers PEERREQUEST_LOGIN only once the serverdiff --git a/GeneralsMD/Code/GameEngine/Include/GameNetwork/Online/OnlineSession.h b/GeneralsMD/Code/GameEngine/Include/GameNetwork/Online/OnlineSession.hindex 02dcd433b..3782da516 100644--- a/GeneralsMD/Code/GameEngine/Include/GameNetwork/Online/OnlineSession.h+++ b/GeneralsMD/Code/GameEngine/Include/GameNetwork/Online/OnlineSession.h@@ -127,6 +127,7 @@ struct OnlineSessionstd::string config;UnsignedShort relayPort;Bool testMode; ///< welcome.testMode: OnlineIsTestServer+ std::string registerUrl; ///< welcome.registerUrl: OnlineGetRegisterUrl// the accountBool authed; ///< auth.ok arriveddiff --git a/GeneralsMD/Code/GameEngine/Source/Common/CommandLine.cpp b/GeneralsMD/Code/GameEngine/Source/Common/CommandLine.cppindex bf2a6b5f6..00a00aa2f 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/CommandLine.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/CommandLine.cpp@@ -2609,7 +2609,6 @@ Int parseOnlineUser(char *args[], int num)return parseOnlineText( args, num, &GlobalData::m_onlineUser );}Int parseOnlinePass(char *args[], int num) { return parseOnlineText( args, num, &GlobalData::m_onlinePass ); }-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 ); }/* -onlinesay is chat, kept as UTF-8 like every line the service carries. Windows hands the switch over in@@ -3190,7 +3189,6 @@ static CommandLineParam params[] ={ "-onlineca", parseOnlineCA },{ "-onlineuser", parseOnlineUser },{ "-onlinepass", parseOnlinePass },- { "-onlineregister", parseOnlineRegister },{ "-onlinehost", parseOnlineHostGame },{ "-onlinejoin", parseOnlineJoin },{ "-onlinesay", parseOnlineSay },diff --git a/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp b/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cppindex 808c30345..b7353079c 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp@@ -799,7 +799,6 @@ GlobalData::GlobalData()m_onlineCAFile.clear();m_onlineUser.clear();m_onlinePass.clear();- m_onlineRegisterNick.clear();m_onlineHostGame.clear();m_onlineJoinGame.clear();m_onlineSay.clear();diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/WOLLoginMenu.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/WOLLoginMenu.cppindex 816689c35..92eccc04e 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/WOLLoginMenu.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/WOLLoginMenu.cpp@@ -468,6 +468,8 @@ void EnableLoginControls( Bool state )//-------------------------------------------------------------------------------------------------/** Initialize the WOL Login Menu *///-------------------------------------------------------------------------------------------------+static void onlineLoginScreen( void );+void WOLLoginMenuInit( WindowLayout *layout, void *userData ){nextScreen = NULL;@@ -737,6 +739,7 @@ void WOLLoginMenuInit( WindowLayout *layout, void *userData )#endif // ALLOW_NON_PROFILED_LOGINEnableLoginControls(TRUE);+ onlineLoginScreen();// Show Menulayout->hide( FALSE );@@ -828,38 +831,65 @@ static void checkLogin( void )}}-/* -onlineuser/-onlinepass/-onlineregister: fill the fields and press the button a player would, once per- process; a refusal leaves the screen to a person. The birth date is any adult's: the service asks none. */+/* -onlineuser/-onlinepass: fill the fields and press Login as a player would, once per process; a refusal+ leaves the screen to a person. No password logs in with the token a remembered login saved. */static void onlineAutoLogin( void ){static Bool s_done = FALSE;if (s_done || !OnlineIsEnabled() || TheGlobalData->m_onlineUser.isEmpty() || loginAttemptTime- || !comboBoxEmail || !comboBoxLoginName || !textEntryPassword || !parentWOLLogin)+ || !comboBoxEmail || !textEntryPassword || !parentWOLLogin || !buttonLogin)return;s_done = TRUE;- const Bool registering = TheGlobalData->m_onlineRegisterNick.isNotEmpty();UnicodeString text;text.translate( TheGlobalData->m_onlineUser );GadgetComboBoxSetText( comboBoxEmail, text );- text.translate( registering ? TheGlobalData->m_onlineRegisterNick : TheGlobalData->m_onlineUser );- GadgetComboBoxSetText( comboBoxLoginName, text );text.translate( TheGlobalData->m_onlinePass );GadgetTextEntrySetText( textEntryPassword, text );- if (textEntryMonth && textEntryDay && textEntryYear)- {- GadgetTextEntrySetText( textEntryMonth, UnicodeString(u"01") );- GadgetTextEntrySetText( textEntryDay, UnicodeString(u"01") );- GadgetTextEntrySetText( textEntryYear, UnicodeString(u"1990") );- }if (checkBoxRememberPassword)GadgetCheckBoxSetChecked( checkBoxRememberPassword, TRUE );- DEBUG_LOG(("ONLINE AUTOLOGIN %s\n", registering ? "register" : "login"));- GameWindow *button = registering ? buttonCreateAccount : buttonLogin;- const NameKeyType buttonID = registering ? buttonCreateAccountID : buttonLoginID;- if (button)- TheWindowManager->winSendSystemMsg( parentWOLLogin, GBM_SELECTED, (WindowMsgData)button, buttonID );+ DEBUG_LOG(("ONLINE AUTOLOGIN login\n"));+ TheWindowManager->winSendSystemMsg( parentWOLLogin, GBM_SELECTED, (WindowMsgData)buttonLogin, buttonLoginID );+}++/* -online: the game only logs in, the site makes accounts (the owner's call of 2026-11-06). One field takes+ the email or the nick, so the nick box and the birth date go; Create Account opens the site's register+ page the server named in its welcome, and goes too when it named none. */+static void onlineLoginScreen( void )+{+ if (!OnlineIsEnabled())+ return;+ const char *hidden[] = { "GameSpyLoginProfile.wnd:WinAge", "GameSpyLoginProfile.wnd:StaticTextLoginName",+ "GameSpyLoginProfile.wnd:ComboBoxLoginName" };+ AsciiString shown;+ for (Int i = 0; i < (Int)ARRAY_SIZE(hidden); ++i)+ {+ GameWindow *win = TheWindowManager->winGetWindowFromId( NULL, NAMEKEY( hidden[i] ) );+ if (win)+ win->winHide( TRUE );+ }+ GameWindow *emailLabel = TheWindowManager->winGetWindowFromId( NULL, NAMEKEY( "GameSpyLoginProfile.wnd:StaticTextEmail" ) );+ if (emailLabel)+ GadgetStaticTextSetText( emailLabel, TheGameText->fetch( "GUI:OnlineLoginName" ) );+ const AsciiString url = OnlineGetRegisterUrl();+ if (buttonCreateAccount)+ buttonCreateAccount->winHide( url.isEmpty() );+ // what a player can type into, for online_check.py: a window counts when neither it nor a parent is hidden+ const struct { GameWindow *win; const char *name; } fields[] = { { comboBoxEmail, "login" }, { comboBoxLoginName, "nick" },+ { textEntryPassword, "password" }, { textEntryMonth, "birthdate" }, { checkBoxRememberPassword, "remember" } };+ for (Int i = 0; i < (Int)ARRAY_SIZE(fields); ++i)+ {+ Bool visible = fields[i].win != NULL;+ for (GameWindow *w = fields[i].win; w && visible; w = w->winGetParent())+ visible = !w->winIsHidden();+ if (!visible)+ continue;+ if (shown.isNotEmpty())+ shown.concat( "," );+ shown.concat( fields[i].name );+ }+ DEBUG_LOG(("ONLINE LOGINSCREEN fields=%s register=%s\n", shown.str(), url.isEmpty() ? "hidden" : url.str()));}//-------------------------------------------------------------------------------------------------@@ -1333,6 +1363,15 @@ WindowMsgHandledType WOLLoginMenuSystem( GameWindow *window, UnsignedInt msg,#endif // ALLOW_NON_PROFILED_LOGINelse if ( controlID == buttonCreateAccountID ){+ // -online: accounts are made on the site; the button opens its register page. A test server's+ // copies only log the address, so a scripted run puts no browser on the desktop+ if (OnlineIsEnabled())+ {+ const AsciiString url = OnlineGetRegisterUrl();+ const Bool opened = url.isNotEmpty() && !OnlineIsTestServer() && OnlineOpenURL( url.str() );+ DEBUG_LOG(("ONLINE REGISTER url=%s opened=%d\n", url.str(), (Int)opened));+ break;+ }#ifdef ALLOW_NON_PROFILED_LOGINif (GameSpyUseProfiles){@@ -1384,9 +1423,6 @@ WindowMsgHandledType WOLLoginMenuSystem( GameWindow *window, UnsignedInt msg,// -online keeps the session token instead (OnlineSaveToken at login)loginPref->addLogin(email, login, OnlineIsEnabled() ? AsciiString::TheEmptyString : password, date);}- if (OnlineIsEnabled())- onlineLoginSent( email, "register" );-EnableLoginControls( FALSE );// fire off some pings@@ -1435,8 +1471,9 @@ WindowMsgHandledType WOLLoginMenuSystem( GameWindow *window, UnsignedInt msg,month.translate( GadgetTextEntryGetText(textEntryMonth) );day.translate( GadgetTextEntryGetText(textEntryDay) );year.translate( GadgetTextEntryGetText(textEntryYear) );-- if(!isAgeOkay(month, day, year))++ // -online asks no birth date: the site's register page is where an account is made+ if(!OnlineIsEnabled() && !isAgeOkay(month, day, year)){GSMessageBoxOk(TheGameText->fetch("GUI:AgeFailedTitle"), TheGameText->fetch("GUI:AgeFailed"));break;@@ -1445,6 +1482,8 @@ WindowMsgHandledType WOLLoginMenuSystem( GameWindow *window, UnsignedInt msg,email.translate( GadgetComboBoxGetText(comboBoxEmail) );login.translate( GadgetComboBoxGetText(comboBoxLoginName) );password.translate( GadgetTextEntryGetText(textEntryPassword) );+ if (OnlineIsEnabled())+ login = email; // one field, the email or the nick: the server takes either// -online: an empty password with a remembered session token logs in with the tokenAsciiString token;diff --git a/GeneralsMD/Code/GameEngine/Source/GameNetwork/Online/OnlineBuddy.cpp b/GeneralsMD/Code/GameEngine/Source/GameNetwork/Online/OnlineBuddy.cppindex 751233053..13bfa7979 100644--- a/GeneralsMD/Code/GameEngine/Source/GameNetwork/Online/OnlineBuddy.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameNetwork/Online/OnlineBuddy.cpp@@ -84,12 +84,6 @@ void OnlineBuddyQueue::addRequest( const BuddyRequest& req )s.requestAuth( m );return;- case BuddyRequest::BUDDYREQUEST_LOGINNEW:- m.setString( "t", "register" ).setString( "email", req.arg.login.email );- m.setString( "nick", req.arg.login.nick ).setString( "pass", req.arg.login.password );- s.requestAuth( m );- return;-case BuddyRequest::BUDDYREQUEST_LOGOUT:s.disconnect();return;@@ -101,7 +95,8 @@ void OnlineBuddyQueue::addRequest( const BuddyRequest& req )return;default:- return; // buddy lists and status come later; RELOGIN has no saved password to use+ return; // buddy lists and status come later; RELOGIN has no saved password to use; LOGINNEW+ // is the site's /register page now (the login screen's Create Account opens it)}}diff --git a/GeneralsMD/Code/GameEngine/Source/GameNetwork/Online/OnlinePeer.cpp b/GeneralsMD/Code/GameEngine/Source/GameNetwork/Online/OnlinePeer.cppindex 274d77a2d..7554b6f10 100644--- a/GeneralsMD/Code/GameEngine/Source/GameNetwork/Online/OnlinePeer.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameNetwork/Online/OnlinePeer.cpp@@ -38,6 +38,9 @@#include <stdio.h>#include <stdlib.h>#include <string.h>+#if defined(_WIN32)+#include <shellapi.h> // ShellExecuteA, OnlineOpenURL+#endif// FirewallHelperClass::FIREWALL_TYPE_SIMPLE: every route goes through the relay, nothing to negotiatestatic const Int ONLINE_NAT_SIMPLE = 1;@@ -161,6 +164,7 @@ void OnlineSession::beginTest( std::vector<OnlineMessage> *lines )config.clear();relayPort = 8094;testMode = FALSE;+ registerUrl.clear();status = lines ? ONLINE_WELCOMED : ONLINE_OFF;}@@ -438,6 +442,7 @@ void OnlineSession::dispatch( const OnlineMessage &m )config = m.getString( "config" );relayPort = (UnsignedShort)m.getInt( "relayPort" );testMode = m.getBool( "testMode" );+ registerUrl = m.getString( "registerUrl" );status = ONLINE_WELCOMED;if (hasPendingAuth){@@ -1019,6 +1024,28 @@ Bool OnlineIsTestServer( void )return OnlineIsEnabled() && OnlineSession::get().testMode;}+AsciiString OnlineGetRegisterUrl( void )+{+ return OnlineSession::get().registerUrl.c_str();+}++/* Only a web page: the address comes from the server, and ShellExecute would run a program path or open a+ file:// as readily as a page. */+Bool OnlineOpenURL( const char *url )+{+ if (!url || (strncmp( url, "https://", 8 ) != 0 && strncmp( url, "http://", 7 ) != 0))+ return FALSE;+#if defined(_WIN32)+ return (INT_PTR)ShellExecuteA( NULL, "open", url, NULL, NULL, SW_SHOWNORMAL ) > 32;+#else+ return TheOnlineOpenURLHook ? (Bool)TheOnlineOpenURLHook( url ) : FALSE;+#endif+}++#if !defined(_WIN32)+OnlineOpenURLHook TheOnlineOpenURLHook = NULL;+#endif+Bool OnlineGetRelayTicket( UnsignedByte out[16] ){OnlineSession &s = OnlineSession::get();diff --git a/GeneralsMD/Code/GameEngineDevice/Source/SdlDevice/Common/SdlGameEngine.cpp b/GeneralsMD/Code/GameEngineDevice/Source/SdlDevice/Common/SdlGameEngine.cppindex 69cb183e7..fcca0bb17 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/SdlDevice/Common/SdlGameEngine.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/SdlDevice/Common/SdlGameEngine.cpp@@ -24,6 +24,7 @@#include "Common/PlayerList.h"#include "Common/Player.h"#include "GameClient/ApplicationWindowTitle.h"+#include "GameNetwork/Online/OnlineQueues.h"#include "GameLogic/GameLogic.h"#include "SdlDevice/Common/SdlDisplays.h"#include "SdlDevice/Common/SdlGameEngine.h"@@ -243,6 +244,7 @@ void SdlGameEngine::createWindow( void )s_titledWindow = m_window;TheApplicationWindowTitleHook = setTitleOfWindow;setSdlMessageBoxOwner( m_window );+ TheOnlineOpenURLHook = []( const char *url ) { return SDL_OpenURL( url ); }; // the online login's Create Account// WinMain's ApplicationHWnd, for W3DDevice: the device's window, and the calls that dress and size itApplicationHWnd = (RenderWindow)m_window;diff --git a/GeneralsMD/Code/Tests/test_online.cpp b/GeneralsMD/Code/Tests/test_online.cppindex 0c475fbcf..a2a78e1a5 100644--- a/GeneralsMD/Code/Tests/test_online.cpp+++ b/GeneralsMD/Code/Tests/test_online.cpp@@ -749,29 +749,32 @@ TEST(online_adapter_login_waits_for_the_relay)CHECK_STR( rig.sentType( 1 ).c_str(), "stats.get" ); // our own stats, as GameSpy's login read them}-TEST(online_adapter_register_and_refusal)+TEST(online_adapter_login_refusal_and_no_register){AdapterRig rig;BuddyRequest req;memset( &req, 0, sizeof(req) );+ // accounts are made on the site: a new-account request sends nothingreq.buddyRequestType = BuddyRequest::BUDDYREQUEST_LOGINNEW;strcpy( req.arg.login.nick, "Tank" );strcpy( req.arg.login.email, "[email protected]" );strcpy( req.arg.login.password, "secret" );rig.buddy->addRequest( req );+ CHECK_EQ( rig.sent.size(), (size_t)0 );++ req.buddyRequestType = BuddyRequest::BUDDYREQUEST_LOGIN;+ rig.buddy->addRequest( req );CHECK_EQ( rig.sent.size(), (size_t)1 );- CHECK_STR( rig.sentType( 0 ).c_str(), "register" );- CHECK_STR( rig.sent[0].getString( "nick" ).c_str(), "Tank" );+ CHECK_STR( rig.sentType( 0 ).c_str(), "login" );CHECK_STR( rig.sent[0].getString( "email" ).c_str(), "[email protected]" );- CHECK_STR( rig.sent[0].getString( "pass" ).c_str(), "secret" );- rig.feed( "{\"t\":\"auth.fail\",\"code\":\"nicktaken\"}" );+ rig.feed( "{\"t\":\"auth.fail\",\"code\":\"badlogin\"}" );std::vector<PeerResponse> r = rig.peerResponses();CHECK_EQ( r.size(), (size_t)1 );if (r.size() == 1){CHECK_EQ( (int)r[0].peerResponseType, (int)PeerResponse::PEERRESPONSE_DISCONNECT );- CHECK_EQ( (int)r[0].discon.reason, (int)DISCONNECT_NICKTAKEN );+ CHECK_EQ( (int)r[0].discon.reason, (int)DISCONNECT_GP_LOGIN_BAD_PASSWORD );}CHECK( !rig.peer->isConnecting() );UnsignedByte ticket[16];@@ -1335,3 +1338,17 @@ TEST(online_adapter_leaves_the_chat_room_for_a_staging_room)rig.peer->addRequest( leave );CHECK_EQ( rig.sent.size(), (size_t)0 ); // already out}++TEST(online_register_url_from_the_welcome_and_only_a_web_page_opens)+{+ AdapterRig rig;+ rig.feed( "{\"t\":\"welcome\",\"config\":\"\",\"motd\":\"\",\"relayPort\":8094}" );+ CHECK( OnlineGetRegisterUrl().isEmpty() ); // none sent: Create Account hides+ rig.feed( "{\"t\":\"welcome\",\"config\":\"\",\"motd\":\"\",\"relayPort\":8094,\"registerUrl\":\"https://example.test/register\"}" );+ CHECK_STR( OnlineGetRegisterUrl().str(), "https://example.test/register" );+ // a hostile server's address is refused before anything is asked to open it+ CHECK( !OnlineOpenURL( "file:///C:/Windows/System32/calc.exe" ) );+ CHECK( !OnlineOpenURL( "C:\\Windows\\notepad.exe" ) );+ CHECK( !OnlineOpenURL( "" ) );+ CHECK( !OnlineOpenURL( NULL ) );+}