本文整理汇总了C#中OpenRA.Server.Server.DropClient方法的典型用法代码示例。如果您正苦于以下问题:C# Server.DropClient方法的具体用法?C# Server.DropClient怎么用?C# Server.DropClient使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OpenRA.Server.Server
的用法示例。
在下文中一共展示了Server.DropClient方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReadData
public void ReadData(Server server)
{
if (ReadDataInner(server))
while (data.Count >= ExpectLength)
{
var bytes = PopBytes(ExpectLength);
switch (State)
{
case ReceiveState.Header:
{
ExpectLength = BitConverter.ToInt32(bytes, 0) - 4;
Frame = BitConverter.ToInt32(bytes, 4);
State = ReceiveState.Data;
if (ExpectLength < 0 || ExpectLength > MaxOrderLength)
{
server.DropClient(this);
Log.Write("server", "Dropping client {0} for excessive order length = {1}", PlayerIndex, ExpectLength);
return;
}
} break;
case ReceiveState.Data:
{
server.DispatchOrders(this, Frame, bytes);
MostRecentFrame = Frame;
ExpectLength = 8;
State = ReceiveState.Header;
} break;
}
}
}
示例2: ReadDataInner
bool ReadDataInner(Server server)
{
var rx = new byte[1024];
var len = 0;
for (;;)
{
try
{
// NOTE(jsd): Poll the socket first to see if there's anything there.
// This avoids the exception with SocketErrorCode == `SocketError.WouldBlock` thrown
// from `socket.Receive(rx)`.
if (!Socket.Poll(0, SelectMode.SelectRead)) break;
if (0 < (len = Socket.Receive(rx)))
Data.AddRange(rx.Take(len));
else
{
if (len == 0)
server.DropClient(this);
break;
}
}
catch (SocketException e)
{
// NOTE(jsd): This should no longer be needed with the socket.Poll call above.
if (e.SocketErrorCode == SocketError.WouldBlock) break;
server.DropClient(this);
Log.Write("server", "Dropping client {0} because reading the data failed: {1}", PlayerIndex, e);
return false;
}
}
lastReceivedTime = Game.RunTime;
TimeoutMessageShown = false;
return true;
}
示例3: Tick
public void Tick(S server)
{
if ((Game.RunTime - lastPing > PingInterval) || isInitialPing)
{
isInitialPing = false;
lastPing = Game.RunTime;
foreach (var c in server.Conns.ToList())
{
if (c.TimeSinceLastResponse < ConnTimeout)
{
server.SendOrderTo(c, "Ping", Game.RunTime.ToString());
if (!c.TimeoutMessageShown && c.TimeSinceLastResponse > PingInterval * 2)
{
server.SendMessage(server.GetClient(c).Name + " is experiencing connection problems.");
c.TimeoutMessageShown = true;
}
}
else
{
server.SendMessage(server.GetClient(c).Name + " has been dropped after timing out.");
server.DropClient(c, -1);
}
}
}
if (Game.RunTime - lastConnReport > ConnReportInterval)
{
lastConnReport = Game.RunTime;
var timeouts = server.Conns
.Where(c => c.TimeSinceLastResponse > ConnReportInterval && c.TimeSinceLastResponse < ConnTimeout)
.OrderBy(c => c.TimeSinceLastResponse);
foreach (var c in timeouts)
server.SendMessage("{0} will be dropped in {1} seconds.".F(
server.GetClient(c).Name, (ConnTimeout - c.TimeSinceLastResponse) / 1000));
}
}
示例4: InterpretCommand
//.........这里部分代码省略.........
return false;
client.Slot = slot;
SyncClientToPlayerReference(client, slotData.MapPlayer != null ? server.Map.Players[slotData.MapPlayer] : null);
server.SyncLobbyInfo();
return true;
}},
{ "slot_close",
s =>
{
int slot;
if (!int.TryParse(s, out slot)) { Log.Write("server", "Invalid slot: {0}", s ); return false; }
var slotData = server.lobbyInfo.Slots.FirstOrDefault( x => x.Index == slot );
if (slotData == null)
return false;
if (conn.PlayerIndex != 0)
{
server.SendChatTo( conn, "Only the host can alter slots" );
return true;
}
slotData.Closed = true;
slotData.Bot = null;
/* kick any player that's in the slot */
var occupant = server.lobbyInfo.Clients.FirstOrDefault( c => c.Slot == slotData.Index );
if (occupant != null)
{
var occupantConn = server.conns.FirstOrDefault( c => c.PlayerIndex == occupant.Index );
if (occupantConn != null)
server.DropClient( occupantConn, new Exception() );
}
server.SyncLobbyInfo();
return true;
}},
{ "slot_open",
s =>
{
int slot;
if (!int.TryParse(s, out slot)) { Log.Write("server", "Invalid slot: {0}", s ); return false; }
var slotData = server.lobbyInfo.Slots.FirstOrDefault( x => x.Index == slot );
if (slotData == null)
return false;
if (conn.PlayerIndex != 0)
{
server.SendChatTo( conn, "Only the host can alter slots" );
return true;
}
slotData.Closed = false;
slotData.Bot = null;
server.SyncLobbyInfo();
return true;
}},
{ "slot_bot",
s =>
{
var parts = s.Split(' ');
示例5: InterpretCommand
//.........这里部分代码省略.........
return true;
}
else
return false;
}
},
{ "slot_close",
s =>
{
if (!ValidateSlotCommand(server, conn, client, s, true))
return false;
// kick any player that's in the slot
var occupant = server.LobbyInfo.ClientInSlot(s);
if (occupant != null)
{
if (occupant.Bot != null)
{
server.LobbyInfo.Clients.Remove(occupant);
server.SyncLobbyClients();
var ping = server.LobbyInfo.PingFromClient(occupant);
if (ping != null)
{
server.LobbyInfo.ClientPings.Remove(ping);
server.SyncClientPing();
}
}
else
{
var occupantConn = server.Conns.FirstOrDefault(c => c.PlayerIndex == occupant.Index);
if (occupantConn != null)
{
server.SendOrderTo(occupantConn, "ServerError", "Your slot was closed by the host.");
server.DropClient(occupantConn);
}
}
}
server.LobbyInfo.Slots[s].Closed = true;
server.SyncLobbySlots();
return true;
}
},
{ "slot_open",
s =>
{
if (!ValidateSlotCommand(server, conn, client, s, true))
return false;
var slot = server.LobbyInfo.Slots[s];
slot.Closed = false;
server.SyncLobbySlots();
// Slot may have a bot in it
var occupant = server.LobbyInfo.ClientInSlot(s);
if (occupant != null && occupant.Bot != null)
{
server.LobbyInfo.Clients.Remove(occupant);
var ping = server.LobbyInfo.PingFromClient(occupant);
if (ping != null)
{
server.LobbyInfo.ClientPings.Remove(ping);
server.SyncClientPing();
}
}
示例6: InterpretCommand
public bool InterpretCommand(S server, Connection conn, Session.Client client, string cmd)
{
if (!ValidateCommand(server, conn, client, cmd))
return false;
var dict = new Dictionary<string, Func<string, bool>>
{
{ "ready",
s =>
{
// if we're downloading, we can't ready up.
if (client.State == Session.ClientState.NotReady)
client.State = Session.ClientState.Ready;
else if (client.State == Session.ClientState.Ready)
client.State = Session.ClientState.NotReady;
Log.Write("server", "Player @{0} is {1}",
conn.socket.RemoteEndPoint, client.State);
server.SyncLobbyInfo();
CheckAutoStart(server, conn, client);
return true;
}},
{ "startgame",
s =>
{
if (!client.IsAdmin)
{
server.SendOrderTo(conn, "Message", "Only the host can start the game");
return true;
}
if (server.lobbyInfo.Slots.Any(sl => sl.Value.Required &&
server.lobbyInfo.ClientInSlot(sl.Key) == null))
{
server.SendOrderTo(conn, "Message", "Unable to start the game until required slots are full.");
return true;
}
server.StartGame();
return true;
}},
{ "slot",
s =>
{
if (!server.lobbyInfo.Slots.ContainsKey(s))
{
Log.Write("server", "Invalid slot: {0}", s );
return false;
}
var slot = server.lobbyInfo.Slots[s];
if (slot.Closed || server.lobbyInfo.ClientInSlot(s) != null)
return false;
client.Slot = s;
S.SyncClientToPlayerReference(client, server.Map.Players[s]);
server.SyncLobbyInfo();
CheckAutoStart(server, conn, client);
return true;
}},
{ "spectate",
s =>
{
client.Slot = null;
client.SpawnPoint = 0;
client.Color = HSLColor.FromRGB(255, 255, 255);
server.SyncLobbyInfo();
return true;
}},
{ "slot_close",
s =>
{
if (!ValidateSlotCommand( server, conn, client, s, true ))
return false;
// kick any player that's in the slot
var occupant = server.lobbyInfo.ClientInSlot(s);
if (occupant != null)
{
if (occupant.Bot != null)
server.lobbyInfo.Clients.Remove(occupant);
else
{
var occupantConn = server.conns.FirstOrDefault( c => c.PlayerIndex == occupant.Index );
if (occupantConn != null)
{
server.SendOrderTo(occupantConn, "ServerError", "Your slot was closed by the host");
server.DropClient(occupantConn);
}
}
}
server.lobbyInfo.Slots[s].Closed = true;
server.SyncLobbyInfo();
return true;
}},
//.........这里部分代码省略.........
示例7: InterpretCommand
public bool InterpretCommand(S server, Connection conn, Session.Client client, string cmd)
{
if (!ValidateCommand(server, conn, client, cmd))
return false;
var dict = new Dictionary<string, Func<string, bool>>
{
{ "ready",
s =>
{
// if we're downloading, we can't ready up.
if (client.State == Session.ClientState.NotReady)
client.State = Session.ClientState.Ready;
else if (client.State == Session.ClientState.Ready)
client.State = Session.ClientState.NotReady;
Log.Write("server", "Player @{0} is {1}",
conn.socket.RemoteEndPoint, client.State);
server.SyncLobbyInfo();
if (server.conns.Count > 0 && server.conns.All(c => server.GetClient(c).State == Session.ClientState.Ready))
InterpretCommand(server, conn, client, "startgame");
return true;
}},
{ "startgame",
s =>
{
server.StartGame();
return true;
}},
{ "lag",
s =>
{
int lag;
if (!int.TryParse(s, out lag)) { Log.Write("server", "Invalid order lag: {0}", s); return false; }
Log.Write("server", "Order lag is now {0} frames.", lag);
server.lobbyInfo.GlobalSettings.OrderLatency = lag;
server.SyncLobbyInfo();
return true;
}},
{ "slot",
s =>
{
if (!server.lobbyInfo.Slots.ContainsKey(s))
{
Log.Write("server", "Invalid slot: {0}", s );
return false;
}
var slot = server.lobbyInfo.Slots[s];
if (slot.Closed || server.lobbyInfo.ClientInSlot(s) != null)
return false;
client.Slot = s;
S.SyncClientToPlayerReference(client, server.Map.Players[s]);
server.SyncLobbyInfo();
return true;
}},
{ "spectate",
s =>
{
client.Slot = null;
client.SpawnPoint = 0;
server.SyncLobbyInfo();
return true;
}},
{ "slot_close",
s =>
{
if (!ValidateSlotCommand( server, conn, client, s, true ))
return false;
// kick any player that's in the slot
var occupant = server.lobbyInfo.ClientInSlot(s);
if (occupant != null)
{
if (occupant.Bot != null)
server.lobbyInfo.Clients.Remove(occupant);
else
{
var occupantConn = server.conns.FirstOrDefault( c => c.PlayerIndex == occupant.Index );
if (occupantConn != null)
{
server.SendOrderTo(occupantConn, "ServerError", "Your slot was closed by the host");
server.DropClient(occupantConn);
}
}
}
server.lobbyInfo.Slots[s].Closed = true;
server.SyncLobbyInfo();
return true;
}},
{ "slot_open",
s =>
//.........这里部分代码省略.........
示例8: InterpretCommand
//.........这里部分代码省略.........
return true;
}
else
return false;
}
},
{ "slot_close",
s =>
{
if (!ValidateSlotCommand(server, conn, client, s, true))
return false;
// kick any player that's in the slot
var occupant = server.LobbyInfo.ClientInSlot(s);
if (occupant != null)
{
if (occupant.Bot != null)
{
server.LobbyInfo.Clients.Remove(occupant);
server.SyncLobbyClients();
var ping = server.LobbyInfo.PingFromClient(occupant);
if (ping != null)
{
server.LobbyInfo.ClientPings.Remove(ping);
server.SyncClientPing();
}
}
else
{
var occupantConn = server.Conns.FirstOrDefault(c => c.PlayerIndex == occupant.Index);
if (occupantConn != null)
{
server.SendOrderTo(occupantConn, "ServerError", "Your slot was closed by the host.");
server.DropClient(occupantConn);
}
}
}
server.LobbyInfo.Slots[s].Closed = true;
server.SyncLobbySlots();
return true;
}
},
{ "slot_open",
s =>
{
if (!ValidateSlotCommand(server, conn, client, s, true))
return false;
var slot = server.LobbyInfo.Slots[s];
slot.Closed = false;
server.SyncLobbySlots();
// Slot may have a bot in it
var occupant = server.LobbyInfo.ClientInSlot(s);
if (occupant != null && occupant.Bot != null)
{
server.LobbyInfo.Clients.Remove(occupant);
var ping = server.LobbyInfo.PingFromClient(occupant);
if (ping != null)
{
server.LobbyInfo.ClientPings.Remove(ping);
server.SyncClientPing();
}
}
示例9: Tick
public void Tick(S server)
{
if ((Game.RunTime - lastPing > PingInterval) || isInitialPing)
{
isInitialPing = false;
lastPing = Game.RunTime;
// Ignore client timeout in singleplayer games to make debugging easier
if (server.LobbyInfo.IsSinglePlayer && !server.Settings.Dedicated)
foreach (var c in server.Conns.ToList())
server.SendOrderTo(c, "Ping", Game.RunTime.ToString());
else
{
foreach (var c in server.Conns.ToList())
{
if (c == null || c.Socket == null)
continue;
var client = server.GetClient(c);
if (client == null)
{
server.DropClient(c, -1);
server.SendMessage("A player has been dropped after timing out.");
continue;
}
if (c.TimeSinceLastResponse < ConnTimeout)
{
server.SendOrderTo(c, "Ping", Game.RunTime.ToString());
if (!c.TimeoutMessageShown && c.TimeSinceLastResponse > PingInterval * 2)
{
server.SendMessage(client.Name + " is experiencing connection problems.");
c.TimeoutMessageShown = true;
}
}
else
{
server.SendMessage(client.Name + " has been dropped after timing out.");
server.DropClient(c, -1);
}
}
if (Game.RunTime - lastConnReport > ConnReportInterval)
{
lastConnReport = Game.RunTime;
var timeouts = server.Conns
.Where(c => c.TimeSinceLastResponse > ConnReportInterval && c.TimeSinceLastResponse < ConnTimeout)
.OrderBy(c => c.TimeSinceLastResponse);
foreach (var c in timeouts)
{
if (c == null || c.Socket == null)
continue;
var client = server.GetClient(c);
if (client != null)
server.SendMessage("{0} will be dropped in {1} seconds.".F(client.Name, (ConnTimeout - c.TimeSinceLastResponse) / 1000));
}
}
}
}
}
示例10: ReadDataInner
bool ReadDataInner( Server server )
{
var rx = new byte[1024];
var len = 0;
for (; ; )
{
try
{
if (0 < (len = socket.Receive(rx)))
data.AddRange(rx.Take(len));
else
{
if (len == 0)
server.DropClient(this);
break;
}
}
catch (SocketException e)
{
if (e.SocketErrorCode == SocketError.WouldBlock) break;
server.DropClient(this);
return false;
}
}
return true;
}
示例11: ReadDataInner
bool ReadDataInner( Server server )
{
var rx = new byte[1024];
var len = 0;
for (; ; )
{
try
{
// NOTE(jsd): Poll the socket first to see if there's anything there.
// This avoids the exception with SocketErrorCode == `SocketError.WouldBlock` thrown
// from `socket.Receive(rx)`.
if (!socket.Poll(0, SelectMode.SelectRead)) break;
if (0 < (len = socket.Receive(rx)))
data.AddRange(rx.Take(len));
else
{
if (len == 0)
server.DropClient(this);
break;
}
}
catch (SocketException e)
{
// NOTE(jsd): This should no longer be needed with the socket.Poll call above.
if (e.SocketErrorCode == SocketError.WouldBlock) break;
server.DropClient(this);
return false;
}
}
return true;
}