From 54cf2e799376bc5e39fa2b2f38042dc8889e2c71 Mon Sep 17 00:00:00 2001 From: Chris Forbes Date: Fri, 24 Dec 2010 12:10:38 +1300 Subject: [PATCH] add kick command to LobbyCommands --- OpenRA.Game/Server/Connection.cs | 4 +-- OpenRA.Game/Server/Server.cs | 6 ++--- OpenRA.Mods.RA/ServerTraits/LobbyCommands.cs | 27 +++++++++++++++++++- 3 files changed, 31 insertions(+), 6 deletions(-) diff --git a/OpenRA.Game/Server/Connection.cs b/OpenRA.Game/Server/Connection.cs index e3cc64004d..8ae3afa372 100644 --- a/OpenRA.Game/Server/Connection.cs +++ b/OpenRA.Game/Server/Connection.cs @@ -49,7 +49,7 @@ namespace OpenRA.Server else { if (len == 0) - server.DropClient(this, null); + server.DropClient(this); break; } @@ -57,7 +57,7 @@ namespace OpenRA.Server catch (SocketException e) { if (e.SocketErrorCode == SocketError.WouldBlock) break; - server.DropClient(this, e); + server.DropClient(this); return false; } } diff --git a/OpenRA.Game/Server/Server.cs b/OpenRA.Game/Server/Server.cs index d1a7001bfe..628ca6a5fe 100644 --- a/OpenRA.Game/Server/Server.cs +++ b/OpenRA.Game/Server/Server.cs @@ -165,7 +165,7 @@ namespace OpenRA.Server foreach (var t in ServerTraits.WithInterface()) t.ClientJoined(this, newConn); } - catch (Exception e) { DropClient(newConn, e); } + catch (Exception e) { DropClient(newConn); } } public void UpdateInFlightFrames(Connection conn) @@ -193,7 +193,7 @@ namespace OpenRA.Server ms.Write( data ); c.socket.Send( ms.ToArray() ); } - catch( Exception e ) { DropClient( c, e ); } + catch (Exception e) { DropClient(c); } } public void DispatchOrders(Connection conn, int frame, byte[] data) @@ -277,7 +277,7 @@ namespace OpenRA.Server return lobbyInfo.ClientWithIndex(conn.PlayerIndex); } - public void DropClient(Connection toDrop, Exception e) + public void DropClient(Connection toDrop) { conns.Remove(toDrop); SendChat(toDrop, "Connection Dropped"); diff --git a/OpenRA.Mods.RA/ServerTraits/LobbyCommands.cs b/OpenRA.Mods.RA/ServerTraits/LobbyCommands.cs index c716f6bd7c..593b66e107 100644 --- a/OpenRA.Mods.RA/ServerTraits/LobbyCommands.cs +++ b/OpenRA.Mods.RA/ServerTraits/LobbyCommands.cs @@ -129,7 +129,7 @@ namespace OpenRA.Mods.RA.Server { var occupantConn = server.conns.FirstOrDefault( c => c.PlayerIndex == occupant.Index ); if (occupantConn != null) - server.DropClient( occupantConn, new Exception() ); + server.DropClient(occupantConn); } server.SyncLobbyInfo(); @@ -221,6 +221,31 @@ namespace OpenRA.Mods.RA.Server bool.TryParse(s, out server.lobbyInfo.GlobalSettings.LockTeams); server.SyncLobbyInfo(); + return true; + }}, + { "kick", + s => + { + if (conn.PlayerIndex != 0) + { + server.SendChatTo( conn, "Only the host can kick players" ); + return true; + } + + int slot; + int.TryParse( s, out slot ); + + var connToKick = server.conns.SingleOrDefault( c => server.GetClient(c) != null && server.GetClient(c).Slot == slot); + if (connToKick == null) + { + server.SendChatTo( conn, "Noone in that slot." ); + return true; + } + + server.DropClient(connToKick); + + server.SyncLobbyInfo(); + return true; }}, };