Skip to content

Commit

Permalink
Team colors now update from !mp team
Browse files Browse the repository at this point in the history
  • Loading branch information
hburn7 committed Mar 10, 2023
1 parent a7c53c0 commit d449c0d
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 5 deletions.
41 changes: 37 additions & 4 deletions BanchoSharp/Multiplayer/MultiplayerLobby.cs
Original file line number Diff line number Diff line change
Expand Up @@ -373,9 +373,13 @@ private void UpdateLobbyFromBanchoBotSettingsResponse(string banchoResponse)
{
UpdateGameMode(banchoResponse);
}
else if (IsTeamSwapNotification(banchoResponse))
else if (IsSelfInvokedTeamSwapNotification(banchoResponse))
{
UpdatePlayerTeam(banchoResponse);
UpdatePlayerTeamSelfInvoked(banchoResponse);
}
else if (IsManualTeamSwapNotification(banchoResponse))
{
UpdatePlayerTeamManuallyInvoked(banchoResponse);
}
else if (IsTeamModeNotification(banchoResponse))
{
Expand Down Expand Up @@ -471,6 +475,7 @@ private void UpdateLobbyFromBanchoBotSettingsResponse(string banchoResponse)
InvokeOnStateChanged();
}

private bool IsManualTeamSwapNotification(string banchoResponse) => banchoResponse.StartsWith("Moved") && banchoResponse.Contains("to team ");
private bool IsRoomNameNotification(string banchoResponse) => banchoResponse.StartsWith("Room name:");
private bool IsTeamModeNotification(string banchoResponse) => banchoResponse.StartsWith("Team mode:");
private bool IsHostChangingMapNotification(string banchoResponse) => banchoResponse.Equals("Host is changing map...");
Expand All @@ -497,7 +502,35 @@ private void UpdateLobbyFromBanchoBotSettingsResponse(string banchoResponse)
private bool IsMatchAbortedNotification(string banchoResponse) => banchoResponse.StartsWith("Aborted the match");
private bool IsMatchSizeNotification(string banchoResponse) => banchoResponse.StartsWith("Changed match to size");
private bool IsGameModeUpdateNotification(string banchoResponse) => banchoResponse.StartsWith("Changed match mode to ");
private bool IsTeamSwapNotification(string banchoResponse) => banchoResponse.Contains("changed to Red") || banchoResponse.Contains("changed to Blue");

private bool IsSelfInvokedTeamSwapNotification(string banchoResponse) => banchoResponse.Contains("changed to Red") || banchoResponse.Contains("changed to Blue");

private void UpdatePlayerTeamManuallyInvoked(string banchoResponse)
{
var splits = banchoResponse.Split();
var player = splits[1];
var team = splits[^1];

if(team != "Red" && team != "Blue")
return;

var match = FindPlayer(player);
if(match == null)
return;

var prevTeam = match.Team;
switch (team.ToLower())
{
case "red":
match.Team = TeamColor.Red;
break;
case "blue":
match.Team = TeamColor.Blue;
break;
}

OnPlayerChangedTeam?.Invoke(new PlayerChangedTeamEventArgs(match, prevTeam));
}

private void UpdateName(string banchoResponse)
{
Expand All @@ -512,7 +545,7 @@ private void UpdateName(string banchoResponse)
InvokeOnStateChanged();
}

private void UpdatePlayerTeam(string banchoResponse)
private void UpdatePlayerTeamSelfInvoked(string banchoResponse)
{
string player = banchoResponse.Split()[0];
string team = banchoResponse.Split()[^1];
Expand Down
4 changes: 3 additions & 1 deletion BanchoSharpTests/MultiplayerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,9 @@ public void TestMpSetResponseParser()

[TestCase("Timper changed to Red", "Timper", TeamColor.Red)]
[TestCase("Timper changed to Blue", "Timper", TeamColor.Blue)]
public void TestTeamSwapSimple(string response, string player, TeamColor team)
[TestCase("Moved Timper to team Red", "Timper", TeamColor.Red)]
[TestCase("Moved Timper to team Blue", "Timper", TeamColor.Blue)]
public void TestTeamSwap(string response, string player, TeamColor team)
{
_lobby.Players.Add(new MultiplayerPlayer(_lobby, "Timper", 1));

Expand Down

0 comments on commit d449c0d

Please sign in to comment.