本文整理汇总了C#中OpenRA.Server.Server.SendOrderTo方法的典型用法代码示例。如果您正苦于以下问题:C# Server.SendOrderTo方法的具体用法?C# Server.SendOrderTo怎么用?C# Server.SendOrderTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OpenRA.Server.Server
的用法示例。
在下文中一共展示了Server.SendOrderTo方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ValidateCommand
public static bool ValidateCommand(S server, Connection conn, Session.Client client, string cmd)
{
if (server.State == ServerState.GameStarted)
{
server.SendOrderTo(conn, "Message", "Cannot change state when game started. ({0})".F(cmd));
return false;
}
else if (client.State == Session.ClientState.Ready && !(cmd.StartsWith("state") || cmd == "startgame"))
{
server.SendOrderTo(conn, "Message", "Cannot change state when marked as ready.");
return false;
}
return true;
}
示例2: Tick
public void Tick(S server)
{
if ((Environment.TickCount - lastPing > PingInterval) || isInitialPing)
{
isInitialPing = false;
lastPing = Environment.TickCount;
foreach (var p in server.Conns)
server.SendOrderTo(p, "Ping", Environment.TickCount.ToString());
}
}
示例3: ValidateSlotCommand
static bool ValidateSlotCommand(S server, Connection conn, Session.Client client, string arg, bool requiresHost)
{
if (!server.LobbyInfo.Slots.ContainsKey(arg))
{
Log.Write("server", "Invalid slot: {0}", arg);
return false;
}
if (requiresHost && !client.IsAdmin)
{
server.SendOrderTo(conn, "Message", "Only the host can do that.");
return false;
}
return true;
}
示例4: 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));
}
}
示例5: InterpretCommand
public bool InterpretCommand(S server, Connection conn, Session.Client client, string cmd)
{
if (server == null || conn == null || client == null || !ValidateCommand(server, conn, client, cmd))
return false;
var dict = new Dictionary<string, Func<string, bool>>
{
{ "state",
s =>
{
var state = Session.ClientState.Invalid;
if (!Enum<Session.ClientState>.TryParse(s, false, out state))
{
server.SendOrderTo(conn, "Message", "Malformed state command");
return true;
}
client.State = state;
Log.Write("server", "Player @{0} is {1}",
conn.Socket.RemoteEndPoint, client.State);
server.SyncLobbyClients();
CheckAutoStart(server);
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;
}
if (server.Settings.DisableSinglePlayer &&
server.LobbyInfo.Clients.Where(c => c.Bot == null && c.Slot != null).Count() == 1)
{
server.SendOrderTo(conn, "Message", "Unable to start the game until another player joins.");
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;
// If the previous slot had a locked spawn then we must not carry that to the new slot
var oldSlot = client.Slot != null ? server.LobbyInfo.Slots[client.Slot] : null;
if (oldSlot != null && oldSlot.LockSpawn)
client.SpawnPoint = 0;
client.Slot = s;
S.SyncClientToPlayerReference(client, server.Map.Players.Players[s]);
if (!slot.LockColor)
client.PreferredColor = client.Color = SanitizePlayerColor(server, client.Color, client.Index, conn);
server.SyncLobbyClients();
CheckAutoStart(server);
return true;
}
},
{ "allow_spectators",
s =>
{
if (bool.TryParse(s, out server.LobbyInfo.GlobalSettings.AllowSpectators))
{
server.SyncLobbyGlobalSettings();
return true;
}
else
{
server.SendOrderTo(conn, "Message", "Malformed allow_spectate command");
return true;
}
//.........这里部分代码省略.........
示例6: SanitizePlayerColor
static HSLColor SanitizePlayerColor(S server, HSLColor askedColor, int playerIndex, Connection connectionToEcho = null)
{
var validator = server.ModData.Manifest.Get<ColorValidator>();
var askColor = askedColor;
Action<string> onError = message =>
{
if (connectionToEcho != null)
server.SendOrderTo(connectionToEcho, "Message", message);
};
var tileset = server.Map.Rules.TileSet;
var terrainColors = tileset.TerrainInfo.Where(ti => ti.RestrictPlayerColor).Select(ti => ti.Color).ToList();
var playerColors = server.LobbyInfo.Clients.Where(c => c.Index != playerIndex).Select(c => c.Color.RGB)
.Concat(server.Map.Players.Players.Values.Select(p => p.Color.RGB)).ToList();
return validator.MakeValid(askColor.RGB, server.Random, terrainColors, playerColors, onError);
}
示例7: ValidatePlayerNewColor
public static bool ValidatePlayerNewColor(S server, Color askedColor, int playerIndex, out Color forbiddenColor, Connection connectionToEcho = null)
{
// Validate color against the current map tileset
var tileset = server.Map.Rules.TileSets[server.Map.Tileset];
var forbiddenColors = tileset.TerrainInfo.Select(terrainInfo => terrainInfo.Color);
if (!ValidateColorAgainstForbidden(askedColor, forbiddenColors, out forbiddenColor))
{
if (connectionToEcho != null)
server.SendOrderTo(connectionToEcho, "Message", "Color was too similar to the terrain, and has been adjusted.");
return false;
}
// Validate color against other clients
var playerColors = server.LobbyInfo.Clients.Where(c => c.Index != playerIndex).Select(c => c.Color.RGB);
if (!ValidateColorAgainstForbidden(askedColor, playerColors, out forbiddenColor))
{
if (connectionToEcho != null)
server.SendOrderTo(connectionToEcho, "Message", "Color was too similar to another player's color, and has been adjusted.");
return false;
}
var mapPlayerColors = server.MapPlayers.Players.Values.Select(p => p.ColorRamp.RGB);
if (!ValidateColorAgainstForbidden(askedColor, mapPlayerColors, out forbiddenColor))
{
if (connectionToEcho != null)
server.SendOrderTo(connectionToEcho, "Message", "Color was too similar to a non-combatant player, and has been adjusted.");
return false;
}
// Color is valid
forbiddenColor = default(Color);
return true;
}
示例8: 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;
}},
//.........这里部分代码省略.........
示例9: 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 =>
//.........这里部分代码省略.........
示例10: ClientJoined
public void ClientJoined(S server, Connection conn)
{
var client = server.GetClient(conn);
// Validate whether color is allowed and get an alternative if it isn't
if (client.Slot == null || !server.LobbyInfo.Slots[client.Slot].LockColor)
client.Color = SanitizePlayerColor(server, client.Color, client.Index);
// Report any custom map details
// HACK: this isn't the best place for this to live, but if we move it somewhere else
// then we need a larger hack to hook the map change event.
var briefing = MissionBriefingOrDefault(server);
if (briefing != null)
server.SendOrderTo(conn, "Message", briefing);
}
示例11: InterpretCommand
public bool InterpretCommand(S server, Connection conn, Session.Client client, string cmd)
{
if (server == null || conn == null || client == null || !ValidateCommand(server, conn, client, cmd))
return false;
var dict = new Dictionary<string, Func<string, bool>>
{
{ "state",
s =>
{
var state = Session.ClientState.Invalid;
if (!Enum<Session.ClientState>.TryParse(s, false, out state))
{
server.SendOrderTo(conn, "Message", "Malformed state command");
return true;
}
client.State = state;
Log.Write("server", "Player @{0} is {1}",
conn.Socket.RemoteEndPoint, client.State);
server.SyncLobbyClients();
CheckAutoStart(server);
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.MapPlayers.Players[s]);
var validatedColor = ColorValidator.ValidatePlayerColorAndGetAlternative(server, client.Color, client.Index, conn);
client.PreferredColor = client.Color = validatedColor;
server.SyncLobbyClients();
CheckAutoStart(server);
return true;
}
},
{ "allow_spectators",
s =>
{
if (bool.TryParse(s, out server.LobbyInfo.GlobalSettings.AllowSpectators))
{
server.SyncLobbyGlobalSettings();
return true;
}
else
{
server.SendOrderTo(conn, "Message", "Malformed allow_spectate command");
return true;
}
}
},
{ "spectate",
s =>
{
if (server.LobbyInfo.GlobalSettings.AllowSpectators || client.IsAdmin)
{
client.Slot = null;
client.SpawnPoint = 0;
client.Color = HSLColor.FromRGB(255, 255, 255);
server.SyncLobbyClients();
return true;
//.........这里部分代码省略.........
示例12: 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));
}
}
}
}
}