@@ -8,6 +8,18 @@ namespace OpenRA.Mods.Common.Widgets.Logic
88{
99 public static class LobbyCommands
1010 {
11+ static int ResolveClientIndex ( JObject json , OrderManager orderManager )
12+ {
13+ var index = json [ "clientIndex" ] ? . ToObject < int > ( ) ;
14+ if ( index != null )
15+ return index . Value ;
16+
17+ if ( orderManager . LocalClient == null )
18+ throw new InvalidOperationException ( "Local client not found" ) ;
19+
20+ return orderManager . LocalClient . Index ;
21+ }
22+
1123 public static void Register ( LobbyCommandServer server )
1224 {
1325 server . CommandHandlers [ "set_faction" ] = SetFaction ;
@@ -31,8 +43,8 @@ public static string SetFaction(JObject json, OrderManager orderManager)
3143 if ( string . IsNullOrEmpty ( faction ) )
3244 throw new ArgumentException ( "Missing faction parameter" ) ;
3345
34- // Validate faction? orderManager will likely ignore invalid ones or handle it.
35- orderManager . IssueOrder ( Order . Command ( $ "faction { faction } ") ) ;
46+ var clientIndex = ResolveClientIndex ( json , orderManager ) ;
47+ orderManager . IssueOrder ( Order . Command ( $ "faction { clientIndex } { faction } ") ) ;
3648 return "Faction set order issued" ;
3749 }
3850
@@ -42,7 +54,8 @@ public static string SetTeam(JObject json, OrderManager orderManager)
4254 if ( team == null )
4355 throw new ArgumentException ( "Missing team parameter" ) ;
4456
45- orderManager . IssueOrder ( Order . Command ( $ "team { team } ") ) ;
57+ var clientIndex = ResolveClientIndex ( json , orderManager ) ;
58+ orderManager . IssueOrder ( Order . Command ( $ "team { clientIndex } { team . Value } ") ) ;
4659 return "Team set order issued" ;
4760 }
4861
@@ -52,7 +65,8 @@ public static string SetSpawn(JObject json, OrderManager orderManager)
5265 if ( spawn == null )
5366 throw new ArgumentException ( "Missing spawn parameter" ) ;
5467
55- orderManager . IssueOrder ( Order . Command ( $ "spawn { spawn } ") ) ;
68+ var clientIndex = ResolveClientIndex ( json , orderManager ) ;
69+ orderManager . IssueOrder ( Order . Command ( $ "spawn { clientIndex } { spawn . Value } ") ) ;
5670 return "Spawn set order issued" ;
5771 }
5872
@@ -64,41 +78,10 @@ public static string SetSpectator(JObject json, OrderManager orderManager)
6478
6579 public static string SetReady ( JObject json , OrderManager orderManager )
6680 {
67- var ready = json [ "ready" ] ? . ToObject < bool > ( ) ;
68- if ( ready == null )
69- {
70- // Toggle if not specified, but let's be explicit
71- // Actually the command is just "ready" which toggles.
72- // If we want to enforce state, we need to check current state.
73- var client = orderManager . LocalClient ;
74- if ( client != null )
75- {
76- if ( client . IsReady != true ) // If not ready, toggle to ready
77- {
78- orderManager . IssueOrder ( Order . Command ( "ready" ) ) ;
79- return "Ready toggled" ;
80- }
81- else
82- {
83- return "Already ready" ;
84- }
85- }
86- orderManager . IssueOrder ( Order . Command ( "ready" ) ) ;
87- return "Ready toggled" ;
88- }
89-
90- var clientState = orderManager . LocalClient ;
91- if ( clientState != null )
92- {
93- if ( clientState . IsReady != ready . Value )
94- {
95- orderManager . IssueOrder ( Order . Command ( "ready" ) ) ;
96- return $ "Ready set to { ready . Value } ";
97- }
98- return $ "Ready already { ready . Value } ";
99- }
100-
101- return "Local client not found" ;
81+ var ready = json [ "ready" ] ? . ToObject < bool > ( ) ?? true ;
82+ var state = ready ? Session . ClientState . Ready : Session . ClientState . NotReady ;
83+ orderManager . IssueOrder ( Order . Command ( $ "state { state } ") ) ;
84+ return $ "Ready state set to { ready } ";
10285 }
10386
10487 public static string StartGame ( JObject json , OrderManager orderManager )
0 commit comments