Return early instead of nesting

This commit is contained in:
abcdefg30
2019-04-13 15:01:04 +02:00
committed by Paul Chote
parent e7f60a1e25
commit 9bd0a71ca8

View File

@@ -80,21 +80,23 @@ namespace OpenRA.Network
case "TeamChat": case "TeamChat":
{ {
var client = orderManager.LobbyInfo.ClientWithIndex(clientId); var client = orderManager.LobbyInfo.ClientWithIndex(clientId);
if (client == null)
break;
// Cut chat messages to the hard limit to avoid exploits // Cut chat messages to the hard limit to avoid exploits
var message = order.TargetString; var message = order.TargetString;
if (message.Length > ChatMessageMaxLength) if (message.Length > ChatMessageMaxLength)
message = order.TargetString.Substring(0, ChatMessageMaxLength); message = order.TargetString.Substring(0, ChatMessageMaxLength);
if (client != null) // We are still in the lobby
{
if (world == null) if (world == null)
{ {
if (orderManager.LocalClient != null && client.Team == orderManager.LocalClient.Team) if (orderManager.LocalClient != null && client.Team == orderManager.LocalClient.Team)
Game.AddChatLine(client.Color, "[Team] " + client.Name, message); Game.AddChatLine(client.Color, "[Team] " + client.Name, message);
break;
} }
else
{
var player = world.FindPlayerByClient(client); var player = world.FindPlayerByClient(client);
if (player != null && player.WinState == WinState.Lost) if (player != null && player.WinState == WinState.Lost)
Game.AddChatLine(client.Color, client.Name + " (Dead)", message); Game.AddChatLine(client.Color, client.Name + " (Dead)", message);
@@ -102,8 +104,6 @@ namespace OpenRA.Network
Game.AddChatLine(client.Color, "[Team" + (world.IsReplay ? " " + client.Team : "") + "] " + client.Name, message); Game.AddChatLine(client.Color, "[Team" + (world.IsReplay ? " " + client.Team : "") + "] " + client.Name, message);
else if ((orderManager.LocalClient != null && orderManager.LocalClient.IsObserver && client.IsObserver) || (world.IsReplay && client.IsObserver)) else if ((orderManager.LocalClient != null && orderManager.LocalClient.IsObserver && client.IsObserver) || (world.IsReplay && client.IsObserver))
Game.AddChatLine(client.Color, "[Spectators] " + client.Name, message); Game.AddChatLine(client.Color, "[Spectators] " + client.Name, message);
}
}
break; break;
} }