Skip to content

Commit

Permalink
Prevent scoreboard script crash if max players is lower than actual p…
Browse files Browse the repository at this point in the history
…layers on server

- Limit club tag text width
- Do not put nickname in custom nicknames array if it equals ubiname
  • Loading branch information
araszka committed Oct 6, 2024
1 parent 8530c4b commit a4d1589
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using EvoSC.Common.Events.Attributes;
using EvoSC.Common.Interfaces.Controllers;
using EvoSC.Common.Remote;
using EvoSC.Common.Remote.EventArgsModels;
using EvoSC.Modules.Official.ScoreboardModule.Interfaces;
using GbxRemoteNet.Events;

Expand All @@ -20,10 +19,6 @@ IScoreboardNicknamesService nicknamesService
public Task OnPlayerConnectAsync(object sender, PlayerGbxEventArgs args) =>
nicknamesService.AddNicknameByLoginAsync(args.Login);

[Subscribe(ModeScriptEvent.EndMapEnd)]
public Task OnEndMapAsync(object sender, MapEventArgs args) =>
nicknamesService.ClearNicknamesAsync();

[Subscribe(GbxRemoteEvent.BeginMap)]
public async Task OnBeginMapAsync(object sender, MapGbxEventArgs args)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public Task ClearNicknamesAsync()
public async Task LoadNicknamesAsync()
{
var onlinePlayers = await playerManagerService.GetOnlinePlayersAsync();
foreach (var player in onlinePlayers)
foreach (var player in onlinePlayers.Where(player => player.NickName != player.UbisoftName))
{
_nicknames[player.GetLogin()] = player.NickName;
}
Expand Down
14 changes: 12 additions & 2 deletions src/Modules/ScoreboardModule/Services/ScoreboardService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,19 @@ public async Task SendScoreboardAsync()

private async Task<dynamic> GetDataAsync()
{
var maxPlayers = await server.Remote.GetMaxPlayersAsync();
var currentNextMaxPlayers = await server.Remote.GetMaxPlayersAsync();
var maxPlayers = 128;

return new { settings, MaxPlayers = maxPlayers.CurrentValue };
if (currentNextMaxPlayers.CurrentValue > 0)
{
maxPlayers = currentNextMaxPlayers.CurrentValue;
}
else if (currentNextMaxPlayers.NextValue > 0)
{
maxPlayers = currentNextMaxPlayers.NextValue;
}

return new { settings, MaxPlayers = maxPlayers };
}

public Task HideNadeoScoreboardAsync() =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
class="text-primary"
text="CLUB"
pos="{{ rowInnerHeight * 0.75 }} 0"
size="{{ rowInnerHeight * 2.0 }} {{ rowInnerHeight }}"
valign="center2"
halign="center"
textsize="{{ Theme.UI_FontSize*2 }}"
Expand Down
8 changes: 8 additions & 0 deletions src/Modules/ScoreboardModule/Templates/Scoreboard.mt
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,10 @@
declare cursor = 0;

foreach(Score => Weight in GetSortedScores()){
if(!RowsFrame.Controls.existskey(cursor)){
continue;
}

declare persistent Boolean SB_Setting_ShowSpectators for LocalUser = True;
declare persistent Boolean SB_Setting_ShowDisconnected for LocalUser = True;

Expand Down Expand Up @@ -459,6 +463,10 @@

//Hide remaining rows
for(i, cursor, {{ MaxPlayers - 1 }}){
if(!RowsFrame.Controls.existskey(i)){
continue;
}

declare playerRow = (RowsFrame.Controls[i] as CMlFrame);
playerRow.Hide();
}
Expand Down

0 comments on commit a4d1589

Please sign in to comment.