@@ -630,19 +630,35 @@ public async Task OnUserDisconnected(string name)
630630
631631 // ===================== LOBBY COMMANDS =====================
632632
633- public PwMatchCommand GenerateLobbyCommand ( string playerFaction = null )
633+ public PwMatchCommand GenerateLobbyCommand ( string playerName = null , string playerFaction = null )
634634 {
635635 PwMatchCommand command = null ;
636636 try
637637 {
638638 if ( MiscVar . PlanetWarsMode != PlanetWarsModes . Running )
639639 return new PwMatchCommand ( PwMatchCommand . ModeType . Clear ) ;
640640
641+ int ? playerFactionId = null ;
642+ if ( playerFaction != null )
643+ {
644+ var fac = factions . FirstOrDefault ( f => f . Shortcut == playerFaction ) ;
645+ playerFactionId = fac ? . FactionID ;
646+ }
647+
641648 if ( Phase == PwPhase . AttackCollect )
642649 {
650+ var canAttack = playerFactionId != null && playerFactionId == AttackingFaction . FactionID ;
651+ var options = AttackOptions . Select ( x =>
652+ {
653+ var v = x . ToVoteOption ( PwMatchCommand . ModeType . Attack ) ;
654+ v . CanSelectForBattle = canAttack ;
655+ v . PlayerIsAttacker = playerName != null && x . Attackers . Contains ( playerName ) ;
656+ return v ;
657+ } ) . ToList ( ) ;
658+
643659 command = new PwMatchCommand ( PwMatchCommand . ModeType . Attack )
644660 {
645- Options = AttackOptions . Select ( x => x . ToVoteOption ( PwMatchCommand . ModeType . Attack ) ) . ToList ( ) ,
661+ Options = options ,
646662 Deadline = GetAttackDeadline ( ) ,
647663 DeadlineSeconds = ( int ) GetAttackDeadline ( ) . Subtract ( DateTime . UtcNow ) . TotalSeconds ,
648664 AttackerFaction = AttackingFaction . Shortcut
@@ -658,27 +674,18 @@ public PwMatchCommand GenerateLobbyCommand(string playerFaction = null)
658674 defFactionCache [ planetId ] = GetDefendingFactions ( FormedSquads . First ( s => s . PlanetID == planetId ) ) ;
659675 }
660676
661- // resolve player's faction ID for filtering
662- int ? playerFactionId = null ;
663- if ( playerFaction != null )
664- {
665- var fac = factions . FirstOrDefault ( f => f . Shortcut == playerFaction ) ;
666- playerFactionId = fac ? . FactionID ;
667- }
668-
669- // aggregate per planet, filtered to planets this player can defend
677+ // aggregate per planet — send all planets, flag which ones the viewer can act on
670678 var options = new List < PwMatchCommand . VoteOption > ( ) ;
671679 foreach ( var planetId in FormedSquads . Select ( s => s . PlanetID ) . Distinct ( ) )
672680 {
673- // skip planets this player's faction cannot defend
674- if ( playerFactionId != null && ! defFactionCache [ planetId ] . Any ( f => f . FactionID == playerFactionId ) )
675- continue ;
676-
677681 var squads = FormedSquads . Where ( s => s . PlanetID == planetId ) . ToList ( ) ;
678682 var first = squads . First ( ) ;
679683 var totalNeeded = squads . Sum ( s => s . TeamSize ) ;
680684 var volunteered = DefenderVotes . ContainsKey ( planetId ) ? DefenderVotes [ planetId ] . Count : 0 ;
681685
686+ var playerIsAttacker = playerName != null && squads . Any ( s => s . Attackers . Contains ( playerName ) ) ;
687+ var canDefend = playerFactionId != null && defFactionCache [ planetId ] . Any ( f => f . FactionID == playerFactionId ) ;
688+
682689 options . Add ( new PwMatchCommand . VoteOption
683690 {
684691 PlanetID = first . PlanetID ,
@@ -688,7 +695,9 @@ public PwMatchCommand GenerateLobbyCommand(string playerFaction = null)
688695 StructureImages = first . StructureImages ,
689696 PlanetImage = first . PlanetImage ,
690697 Count = volunteered ,
691- Needed = totalNeeded
698+ Needed = totalNeeded ,
699+ CanSelectForBattle = canDefend && ! playerIsAttacker ,
700+ PlayerIsAttacker = playerIsAttacker
692701 } ) ;
693702 }
694703
@@ -916,24 +925,17 @@ public void RemoveFromRunningBattles(int battleID)
916925
917926 private async Task UpdateLobby ( )
918927 {
919- if ( Phase == PwPhase . DefendCollect )
920- {
921- // send per-player filtered options (only planets they can defend)
922- foreach ( var conus in server . ConnectedUsers . Values . Where ( x => x . User . CanUserPlanetWars ( ) ) )
923- await conus . SendCommand ( GenerateLobbyCommand ( conus . User . Faction ) ) ;
924- }
925- else
926- {
927- await server . Broadcast ( server . ConnectedUsers . Values . Where ( x => x . User . CanUserPlanetWars ( ) ) , GenerateLobbyCommand ( ) ) ;
928- }
928+ // per-player: flags (CanSelectForBattle / PlayerIsAttacker) depend on the viewer
929+ foreach ( var conus in server . ConnectedUsers . Values . Where ( x => x . User . CanUserPlanetWars ( ) ) )
930+ await conus . SendCommand ( GenerateLobbyCommand ( conus . Name , conus . User . Faction ) ) ;
929931 SaveStateToDb ( ) ;
930932 }
931933
932934 private Task UpdateLobby ( string player )
933935 {
934936 var conus = server . ConnectedUsers . Get ( player ) ;
935937 if ( conus == null ) return Task . CompletedTask ;
936- return conus . SendCommand ( GenerateLobbyCommand ( conus . User . Faction ) ) ;
938+ return conus . SendCommand ( GenerateLobbyCommand ( conus . Name , conus . User . Faction ) ) ;
937939 }
938940
939941 private void SaveStateToDb ( )
0 commit comments