Skip to content

Commit

Permalink
Fix incorrect player verification in CnCNet lobby (CnCNet#587)
Browse files Browse the repository at this point in the history
* Add XML documentation for PlayerInfo.Verified

* Set PlayerInfo.Verified regardless of hash consistency

* Rename to PlayerInfo.HashReceived

* Code style changes
  • Loading branch information
SadPencil authored Dec 2, 2024
1 parent 42854e1 commit a8522b0
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 14 deletions.
13 changes: 5 additions & 8 deletions DXMainClient/DXGUI/Multiplayer/CnCNet/CnCNetGameLoadingLobby.cs
Original file line number Diff line number Diff line change
Expand Up @@ -416,17 +416,14 @@ private void HandleFileHashCommand(string sender, string fileHash)
if (!IsHost)
return;

if (fileHash != gameFilesHash)
{
PlayerInfo pInfo = Players.Find(p => p.Name == sender);

if (pInfo == null)
return;
PlayerInfo pInfo = Players.Find(p => p.Name == sender);
if (pInfo == null)
return;

pInfo.Verified = true;
pInfo.HashReceived = true;

if (fileHash != gameFilesHash)
HandleCheaterNotification(hostName, sender); // This is kinda hacky
}
}

private void HandleCheaterNotification(string sender, string cheaterName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1456,7 +1456,7 @@ private void FileHashNotification(string sender, string filesHash)
PlayerInfo pInfo = Players.Find(p => p.Name == sender);

if (pInfo != null)
pInfo.Verified = true;
pInfo.HashReceived = true;
CopyPlayerDataToUI();

if (filesHash != gameFilesHash)
Expand Down
2 changes: 1 addition & 1 deletion DXMainClient/DXGUI/Multiplayer/GameLobby/LANGameLobby.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ private void HandleFileHashCommand(string sender, string fileHash)
if (pInfo == null)
return;

pInfo.Verified = true;
pInfo.HashReceived = true;
CopyPlayerDataToUI();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -843,7 +843,7 @@ protected override void BtnLaunchGame_LeftClick(object sender, EventArgs e)
if (player.Name == ProgramConstants.PLAYERNAME)
continue;

if (!player.Verified)
if (!player.HashReceived)
{
NotVerifiedNotification(iId - 1);
return;
Expand Down Expand Up @@ -998,7 +998,7 @@ protected override void CopyPlayerDataToUI()
// Player statuses
for (int pId = 0; pId < Players.Count; pId++)
{
/* if (pId != 0 && !Players[pId].Verified) // If player is not verified (not counting the host)
/* if (pId != 0 && !Players[pId].HashReceived) // If player is not verified (not counting the host)
{
StatusIndicators[pId].SwitchTexture("error");
}
Expand Down
2 changes: 1 addition & 1 deletion DXMainClient/DXGUI/Multiplayer/LANGameLoadingLobby.cs
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ private void Server_HandleFileHashMessage(LANPlayerInfo sender, string hash)
{
if (hash != localFileHash)
AddNotice(string.Format("{0} - modified files detected! They could be cheating!".L10N("Client:Main:PlayerCheating"), sender.Name), Color.Red);
sender.Verified = true;
sender.HashReceived = true;
}

private void Server_HandleReadyRequest(LANPlayerInfo sender)
Expand Down
6 changes: 5 additions & 1 deletion DXMainClient/Domain/Multiplayer/PlayerInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ public PlayerInfo(string name, int sideId, int startingLocation, int colorId, in
public bool IsInGame { get; set; }
public virtual string IPAddress { get; set; } = "0.0.0.0";
public int Port { get; set; }
public bool Verified { get; set; }

/// <summary>
/// Whether the file hash information is received from the player, regardless of whether it is consistent with the one calculated by this client.
/// </summary>
public bool HashReceived { get; set; }

public int Index { get; set; }

Expand Down

0 comments on commit a8522b0

Please sign in to comment.