From 9bd0a71ca8aba3fbe7e37424bf08ab74ede08cb2 Mon Sep 17 00:00:00 2001 From: abcdefg30 Date: Sat, 13 Apr 2019 15:01:04 +0200 Subject: [PATCH] Return early instead of nesting --- OpenRA.Game/Network/UnitOrders.cs | 32 +++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/OpenRA.Game/Network/UnitOrders.cs b/OpenRA.Game/Network/UnitOrders.cs index 91e20fb382..9b0b450bf2 100644 --- a/OpenRA.Game/Network/UnitOrders.cs +++ b/OpenRA.Game/Network/UnitOrders.cs @@ -80,31 +80,31 @@ namespace OpenRA.Network case "TeamChat": { var client = orderManager.LobbyInfo.ClientWithIndex(clientId); + if (client == null) + break; // Cut chat messages to the hard limit to avoid exploits var message = order.TargetString; if (message.Length > 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) - Game.AddChatLine(client.Color, "[Team] " + client.Name, message); - } - else - { - var player = world.FindPlayerByClient(client); - if (player != null && player.WinState == WinState.Lost) - Game.AddChatLine(client.Color, client.Name + " (Dead)", message); - else if ((player != null && world.LocalPlayer != null && player.Stances[world.LocalPlayer] == Stance.Ally) || (world.IsReplay && player != null)) - 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)) - Game.AddChatLine(client.Color, "[Spectators] " + client.Name, message); - } + if (orderManager.LocalClient != null && client.Team == orderManager.LocalClient.Team) + Game.AddChatLine(client.Color, "[Team] " + client.Name, message); + + break; } + var player = world.FindPlayerByClient(client); + if (player != null && player.WinState == WinState.Lost) + Game.AddChatLine(client.Color, client.Name + " (Dead)", message); + else if ((player != null && world.LocalPlayer != null && player.Stances[world.LocalPlayer] == Stance.Ally) || (world.IsReplay && player != null)) + 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)) + Game.AddChatLine(client.Color, "[Spectators] " + client.Name, message); + break; }