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): save <name> over the control socket

Olcay Seygan4d1e711f9c87
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/System/ControlServer.cpp b/GeneralsMD/Code/GameEngine/Source/Common/System/ControlServer.cpp
index c299681ee..e99553ca3 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/System/ControlServer.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/System/ControlServer.cpp
@@ -29,6 +29,7 @@
#include "Common/ControlServer.h"
#include "Common/Energy.h"
#include "Common/GameEngine.h"
+#include "Common/GameState.h"
#include "Common/GlobalData.h"
#include "Common/MessageStream.h"
#include "Common/Money.h"
@@ -650,6 +651,35 @@ static void handleCommand( const AsciiString &command )
return;
}
+ /* save <name>: the save menu's Save, into <name>.sav in the save directory, so a script can make
+ the file -loadsave opens. Letters, digits, - and _ only, since it becomes a path. */
+ if (strncmp( command.str(), "save ", 5 ) == 0)
+ {
+ AsciiString name( command.str() + 5 );
+ name.trim();
+ if (name.isEmpty() || strspn( name.str(), "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_" ) != (size_t)name.getLength())
+ {
+ replyError( "save wants a name of letters, digits, - and _" );
+ return;
+ }
+ if (TheGameLogic == NULL || !TheGameLogic->isInGame() || TheGameLogic->isInShellGame())
+ {
+ replyError( "save needs a match in progress" );
+ return;
+ }
+ AsciiString filename;
+ filename.format( "%s.sav", name.str() );
+ UnicodeString description;
+ description.translate( name );
+ if (TheGameState->saveGame( filename, description, SAVE_FILE_TYPE_NORMAL ) != SC_OK)
+ {
+ replyError( "the game could not write the save" );
+ return;
+ }
+ replyOk( "\"saved\":true" );
+ return;
+ }
+
/* The quit menu's Exit, which in a network game is the other half of "quit": the process goes
on, the player surrenders and the match is left through the network, so everybody else sees
a player leave on an agreed frame rather than a connection drop. exitQuitMenu in QuitMenu.cpp