Skip to content

Commit 61cdd9c

Browse files
SadPencilCopilot
andauthored
Add prompts when there are no games listed (CnCNet#849)
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 9c140a2 commit 61cdd9c

File tree

1 file changed

+57
-5
lines changed

1 file changed

+57
-5
lines changed

DXMainClient/DXGUI/Multiplayer/CnCNet/CnCNetLobby.cs

Lines changed: 57 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ private bool HostedGameMatches(GenericHostedGame hg)
441441

442442
string textUpper = tbGameSearch?.Text?.ToUpperInvariant();
443443

444-
string translatedGameMode = string.IsNullOrEmpty(hg.GameMode)
444+
string translatedGameMode = string.IsNullOrEmpty(hg.GameMode)
445445
? "Unknown".L10N("Client:Main:Unknown")
446446
: hg.GameMode.L10N($"INI:GameModes:{hg.GameMode}:UIName", notify: false);
447447

@@ -784,7 +784,7 @@ private void SetLogOutButtonText()
784784
private void BtnJoinGame_LeftClick(object sender, EventArgs e) => JoinSelectedGame();
785785

786786
private void LbGameList_DoubleLeftClick(object sender, EventArgs e) => JoinSelectedGame();
787-
787+
788788
private void LbGameList_RightClick(object sender, EventArgs e)
789789
{
790790
lbGameList.SelectedIndex = lbGameList.HoveredIndex;
@@ -1364,7 +1364,7 @@ private void DdCurrentChannel_SelectedIndexChanged(object sender, EventArgs e)
13641364
currentChatChannel = (Channel)ddCurrentChannel.SelectedItem?.Tag;
13651365
if (currentChatChannel == null)
13661366
throw new Exception("Current selected chat channel is null. This should not happen.");
1367-
1367+
13681368
currentChatChannel.UserAdded += RefreshPlayerList;
13691369
currentChatChannel.UserLeft += RefreshPlayerList;
13701370
currentChatChannel.UserQuitIRC += RefreshPlayerList;
@@ -1507,6 +1507,20 @@ private void GameBroadcastChannel_CTCPReceived(object sender, ChannelCTCPEventAr
15071507
if (splitMessage.Length != 13)
15081508
{
15091509
Logger.Log("Ignoring CTCP game message because of an invalid amount of parameters.");
1510+
1511+
// Remind users that the network is good but the client is outdated or newer
1512+
if (lbGameList.Items.Count == 0)
1513+
{
1514+
string message = "There are no games listed but you are indeed connected. The client did receive a game message but can't add it to the list because the message is invalid. " +
1515+
"You can ignore this prompt if there are games listed later. " +
1516+
"Otherwise, this usually means that your client is outdated, or, in a rare case, newer than others. Please check for updates.".L10N("Client:Main:InvalidGameMessage");
1517+
1518+
if ((lbChatMessages.Items.LastOrDefault()?.Tag as ChatMessage)?.Message != message)
1519+
{
1520+
lbChatMessages.AddMessage(new ChatMessage(Color.Gray, message));
1521+
}
1522+
}
1523+
15101524
return;
15111525
}
15121526

@@ -1539,13 +1553,51 @@ private void GameBroadcastChannel_CTCPReceived(object sender, ChannelCTCPEventAr
15391553

15401554
CnCNetGame cncnetGame = gameCollection.GameList.Find(g => g.GameBroadcastChannel == channel.ChannelName);
15411555

1556+
if (cncnetGame == null)
1557+
return;
1558+
1559+
// Find the tunnel server specified in the game message
1560+
1561+
if (tunnelHandler.Tunnels.Count == 0)
1562+
{
1563+
Logger.Log("Ignoring CTCP game message because there are no tunnels at all. Available tunnel count: 0. Is the connection to CnCNet HTTP service broken?");
1564+
1565+
// Remind users that the game is ignored because of no tunnel
1566+
if (lbGameList.Items.Count == 0)
1567+
{
1568+
string message = "There are no games listed. The client did receive a valid game message but can't add it to the list because there are no available tunnels. " +
1569+
"You can ignore this prompt if there are games listed later. Otherwise, it might indicate a network problem to CnCNet HTTP service.".L10N("Client:Main:NoTunnels");
1570+
1571+
if ((lbChatMessages.Items.LastOrDefault()?.Tag as ChatMessage)?.Message != message)
1572+
{
1573+
lbChatMessages.AddMessage(new ChatMessage(Color.Gray, message));
1574+
}
1575+
}
1576+
1577+
return;
1578+
}
1579+
15421580
CnCNetTunnel tunnel = tunnelHandler.Tunnels.Find(t => t.Address == tunnelAddress && t.Port == tunnelPort);
15431581

15441582
if (tunnel == null)
1545-
return;
1583+
{
1584+
Logger.Log(string.Format("Ignoring CTCP game message because the specified tunnel {0}:{1} is not available. Available tunnel count: {2}",
1585+
tunnelAddress, tunnelPort, tunnelHandler.Tunnels.Count));
1586+
1587+
// Remind users that the game is ignored because of no specified tunnel
1588+
if (lbGameList.Items.Count == 0)
1589+
{
1590+
string message = string.Format("There are no games listed. The client did receive a valid game message but can't add it to the list because the specified tunnel is not available. " +
1591+
"You can ignore this prompt if there are games listed later. Otherwise, please contact support at {0}.".L10N("Client:Main:NoTunnelForGames"), ClientConfiguration.Instance.LongSupportURL);
1592+
1593+
if ((lbChatMessages.Items.LastOrDefault()?.Tag as ChatMessage)?.Message != message)
1594+
{
1595+
lbChatMessages.AddMessage(new ChatMessage(Color.Gray, message));
1596+
}
1597+
}
15461598

1547-
if (cncnetGame == null)
15481599
return;
1600+
}
15491601

15501602
HostedCnCNetGame game = new HostedCnCNetGame(gameRoomChannelName, revision, gameVersion, maxPlayers,
15511603
gameRoomDisplayName, isCustomPassword, true, players,

0 commit comments

Comments
 (0)