Skip to content

Commit 9412493

Browse files
committed
Revert "testing mid game join"
This reverts commit 0f0130b.
1 parent 0f0130b commit 9412493

5 files changed

Lines changed: 11 additions & 131 deletions

File tree

Shared/LobbyClient/DedicatedServer.cs

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -102,27 +102,16 @@ public override string ToString()
102102
}
103103

104104
/// <summary>
105-
/// Adds user dynamically to running game as a spectator.
105+
/// Adds user dynamically to running game - for security reasons add his script
106106
/// </summary>
107107
public void AddUser(string name, string scriptPassword, User user)
108-
{
109-
AddUser(name, scriptPassword, user, isSpectator: true, teamNumber: null);
110-
}
111-
112-
/// <summary>
113-
/// Adds user dynamically to running game, optionally as a non-spectator on a specific team.
114-
/// </summary>
115-
public void AddUser(string name, string scriptPassword, User user, bool isSpectator, int? teamNumber)
116108
{
117109
if (IsRunning)
118110
{
119-
if (!isSpectator && teamNumber.HasValue)
120-
talker.SendText($"/adduser {name} {scriptPassword} 0 {teamNumber.Value}");
121-
else
122-
talker.SendText($"/adduser {name} {scriptPassword}");
123-
111+
talker.SendText($"/adduser {name} {scriptPassword}");
124112
if (user != null) talker.SendText($"SPRINGIE:User {new MidGameJoinUser(user)}");
125113
}
114+
126115
}
127116

128117
public event EventHandler<SpringBattleContext> BattleStarted = (sender, args) => { };

Shared/LobbyClient/ScriptGenerator.cs

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -120,31 +120,6 @@ static void GeneratePlayerSection(StringBuilder script, SpringBattleContext setu
120120
teamNum++;
121121
}
122122

123-
// Preallocate empty team slots for mid-game player joins.
124-
// These teams exist in the script from frame 0 but start inactive (no player assigned).
125-
// The engine activates them when a mid-game joiner is assigned via /adduser.
126-
var slotsPerAlly = setup.LobbyStartContext.MidGameSlotsPerAllyTeam;
127-
if (slotsPerAlly > 0)
128-
{
129-
var allyTeamsInUse = setup.LobbyStartContext.Players
130-
.Where(x => !x.IsSpectator)
131-
.Select(x => x.AllyID)
132-
.Union(setup.LobbyStartContext.Bots.Select(x => x.AllyID))
133-
.Distinct()
134-
.OrderBy(x => x)
135-
.ToList();
136-
137-
// Use first real player as TeamLeader for the placeholder teams (engine requires a valid leader)
138-
var leaderUserNum = 0;
139-
foreach (var allyId in allyTeamsInUse)
140-
{
141-
for (var s = 0; s < slotsPerAlly; s++)
142-
{
143-
ScriptAddTeam(script, teamNum, leaderUserNum, allyId);
144-
teamNum++;
145-
}
146-
}
147-
}
148123

149124
// ALLIANCES AND START BOXES
150125
var startboxes = new StringBuilder();

Shared/LobbyClient/Spring.SpringBattleContext.cs

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System;
2-
using System.Collections.Concurrent;
32
using System.Collections.Generic;
43
using System.Linq;
54
using System.Text;
@@ -12,11 +11,6 @@ public class SpringBattleContext
1211
public List<BattlePlayerResult> ActualPlayers = new List<BattlePlayerResult>();
1312
public List<string> PlayersUnreadyOnStart = new List<string>();
1413

15-
/// <summary>
16-
/// Pool of preallocated team numbers available for mid-game player joins, keyed by ally team ID.
17-
/// </summary>
18-
public ConcurrentDictionary<int, ConcurrentQueue<int>> MidGameTeamSlots = new ConcurrentDictionary<int, ConcurrentQueue<int>>();
19-
2014
public int Duration;
2115
public string EngineBattleID;
2216

@@ -99,34 +93,6 @@ public void SetForHosting(LobbyHostingContext startContext,
9993
IsIngameReady = false,
10094
IsIngame = false,
10195
}).ToList();
102-
103-
// Build pool of preallocated team slots for mid-game joins
104-
var slotsPerAlly = startContext.MidGameSlotsPerAllyTeam;
105-
if (slotsPerAlly > 0)
106-
{
107-
// Count how many real teams were generated (non-spectator players + bots)
108-
var realTeamCount = startContext.Players.Count(x => !x.IsSpectator) + startContext.Bots.Count;
109-
110-
var allyTeamsInUse = startContext.Players
111-
.Where(x => !x.IsSpectator)
112-
.Select(x => x.AllyID)
113-
.Union(startContext.Bots.Select(x => x.AllyID))
114-
.Distinct()
115-
.OrderBy(x => x)
116-
.ToList();
117-
118-
var teamNum = realTeamCount;
119-
foreach (var allyId in allyTeamsInUse)
120-
{
121-
var queue = new ConcurrentQueue<int>();
122-
for (var s = 0; s < slotsPerAlly; s++)
123-
{
124-
queue.Enqueue(teamNum);
125-
teamNum++;
126-
}
127-
MidGameTeamSlots[allyId] = queue;
128-
}
129-
}
13096
}
13197

13298

Shared/PlasmaShared/ISpringieService/LobbyHostingContext.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,6 @@ public class LobbyHostingContext
2121
public Dictionary<string,Dictionary<string,string>> UserParameters = new Dictionary<string, Dictionary<string, string>>();
2222
public int BattleID { get; set; }
2323

24-
/// <summary>
25-
/// Number of extra team slots to preallocate per ally team for mid-game player joins.
26-
/// These teams exist in the start script but have no player assigned initially.
27-
/// </summary>
28-
public int MidGameSlotsPerAllyTeam { get; set; }
29-
3024
public void ApplyBalance(BalanceTeamsResult balance)
3125
{
3226
if (balance.DeleteBots) Bots.Clear();

ZkLobbyServer/ServerBattle.cs

Lines changed: 8 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -167,21 +167,6 @@ public string GenerateClientScriptPassword(string name)
167167
return Hash.HashString(battleInstanceGuid + name).ToString();
168168
}
169169

170-
/// <summary>
171-
/// Tries to claim a preallocated team slot for a mid-game joiner on the given ally team.
172-
/// Returns the team number if a slot is available, null otherwise.
173-
/// </summary>
174-
private int? TryClaimMidGameTeamSlot(int allyTeamId)
175-
{
176-
if (spring?.Context?.MidGameTeamSlots != null &&
177-
spring.Context.MidGameTeamSlots.TryGetValue(allyTeamId, out var queue) &&
178-
queue.TryDequeue(out var teamNum))
179-
{
180-
return teamNum;
181-
}
182-
return null;
183-
}
184-
185170
public void Dispose()
186171
{
187172
spring.UnsubscribeEvents(this);
@@ -364,28 +349,11 @@ public virtual async Task ProcessPlayerJoin(ConnectedUser user, string joinPassw
364349

365350
if (spring.IsRunning)
366351
{
367-
// Try to assign a preallocated mid-game team slot if available
368-
int? midGameTeam = null;
369-
if (!ubs.IsSpectator)
370-
{
371-
midGameTeam = TryClaimMidGameTeamSlot(ubs.AllyNumber);
372-
if (midGameTeam == null)
373-
ubs.IsSpectator = true; // no slot available, force spectator
374-
}
375-
376-
spring.AddUser(ubs.Name, ubs.ScriptPassword, ubs.LobbyUser, ubs.IsSpectator, midGameTeam);
377-
378-
if (midGameTeam.HasValue)
379-
{
380-
await SayBattle($"Game is in progress — {ubs.Name} is joining as a player on team {midGameTeam.Value}.");
381-
}
382-
else
383-
{
384-
var started = DateTime.UtcNow.Subtract(spring.IngameStartTime ?? RunningSince ?? DateTime.UtcNow);
385-
started = new TimeSpan((int)started.TotalHours, started.Minutes, started.Seconds);
386-
await SayBattle($"THIS GAME IS CURRENTLY IN PROGRESS, PLEASE WAIT UNTIL IT ENDS! Running for {started}", ubs.Name);
387-
await SayBattle("If you say !notify, I will message you when the current game ends.", ubs.Name);
388-
}
352+
spring.AddUser(ubs.Name, ubs.ScriptPassword, ubs.LobbyUser);
353+
var started = DateTime.UtcNow.Subtract(spring.IngameStartTime ?? RunningSince ?? DateTime.UtcNow);
354+
started = new TimeSpan((int)started.TotalHours, started.Minutes, started.Seconds);
355+
await SayBattle($"THIS GAME IS CURRENTLY IN PROGRESS, PLEASE WAIT UNTIL IT ENDS! Running for {started}", ubs.Name);
356+
await SayBattle("If you say !notify, I will message you when the current game ends.", ubs.Name);
389357
}
390358

391359
try
@@ -438,34 +406,22 @@ public async Task RequestConnectSpring(ConnectedUser conus, string joinPassword)
438406
UserBattleStatus ubs;
439407

440408
startGameStatus = spring.LobbyStartContext.Players.FirstOrDefault(x => x.Name == conus.Name);
441-
409+
442410
if (!Users.TryGetValue(conus.Name, out ubs) && !(IsInGame && startGameStatus != null))
443411
if (IsPassworded && (Password != joinPassword))
444412
{
445413
await conus.Respond("Invalid password");
446414
return;
447415
}
448-
449-
var isSpectator = startGameStatus?.IsSpectator != false;
450-
451-
// For mid-game joins of users not in the original player list, try to assign a team slot
452-
int? midGameTeam = null;
453-
if (isSpectator && startGameStatus == null && Users.TryGetValue(conus.Name, out ubs) && !ubs.IsSpectator)
454-
{
455-
midGameTeam = TryClaimMidGameTeamSlot(ubs.AllyNumber);
456-
if (midGameTeam.HasValue)
457-
isSpectator = false;
458-
}
459-
460416
var pwd = GenerateClientScriptPassword(conus.Name);
461-
spring.AddUser(conus.Name, pwd, conus.User, isSpectator, midGameTeam);
417+
spring.AddUser(conus.Name, pwd, conus.User);
462418

463419
if (spring.Context.LobbyStartContext.Players.Any(x => x.Name == conus.Name) && conus.MyBattle != this)
464420
{
465421
await ProcessPlayerJoin(conus, joinPassword);
466422
}
467423

468-
await conus.SendCommand(GetConnectSpringStructure(pwd, isSpectator));
424+
await conus.SendCommand(GetConnectSpringStructure(pwd, startGameStatus?.IsSpectator != false));
469425
}
470426

471427

0 commit comments

Comments
 (0)