本文整理汇总了C#中OpenRA.Server.Server.SyncLobbyInfo方法的典型用法代码示例。如果您正苦于以下问题:C# Server.SyncLobbyInfo方法的具体用法?C# Server.SyncLobbyInfo怎么用?C# Server.SyncLobbyInfo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OpenRA.Server.Server
的用法示例。
在下文中一共展示了Server.SyncLobbyInfo方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InterpretCommand
public bool InterpretCommand(S server, Connection conn, Session.Client client, string cmd)
{
if (server.GameStarted)
{
server.SendChatTo(conn, "Cannot change state when game started. ({0})".F(cmd));
return false;
}
else if (client.State == Session.ClientState.Ready && !(cmd == "ready" || cmd == "startgame"))
{
server.SendChatTo(conn, "Cannot change state when marked as ready.");
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;
}},
{ "spectator",
s =>
{
var slotData = server.lobbyInfo.Slots.Where(ax => ax.Spectator && !server.lobbyInfo.Clients.Any(l => l.Slot == ax.Index)).FirstOrDefault();
if (slotData == null)
return true;
client.Slot = slotData.Index;
SyncClientToPlayerReference(client, slotData.MapPlayer != null ? server.Map.Players[slotData.MapPlayer] : null);
server.SyncLobbyInfo();
return true;
}},
{ "slot",
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 || slotData.Closed || slotData.Bot != null
|| server.lobbyInfo.Clients.Any( c => c.Slot == slot ))
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;
//.........这里部分代码省略.........
示例2: InterpretCommand
public bool InterpretCommand( S server, Connection conn, Session.Client client, string cmd)
{
if (server.GameStarted)
{
server.SendChatTo(conn, "Cannot change state when game started. ({0})".F(cmd));
return false;
}
else if (client.State == Session.ClientState.Ready && !(cmd == "ready" || cmd == "startgame"))
{
server.SendChatTo(conn, "Cannot change state when marked as ready.");
return false;
}
var dict = new Dictionary<string, Func<string, bool>>
{
{ "name",
s =>
{
Log.Write("server", "[email protected]{0} is now known as {1}", conn.socket.RemoteEndPoint, s);
client.Name = s;
server.SyncLobbyInfo();
return true;
}},
{ "race",
s =>
{
client.Country = s;
server.SyncLobbyInfo();
return true;
}},
{ "team",
s =>
{
int team;
if (!int.TryParse(s, out team)) { Log.Write("server", "Invalid team: {0}", s ); return false; }
client.Team = team;
server.SyncLobbyInfo();
return true;
}},
{ "spawn",
s =>
{
int spawnPoint;
if (!int.TryParse(s, out spawnPoint) || spawnPoint < 0 || spawnPoint > server.Map.SpawnPoints.Count())
{
Log.Write("server", "Invalid spawn point: {0}", s);
return false;
}
if (server.lobbyInfo.Slots[client.Slot].Spectator)
{
server.SendChatTo( conn, "Can't select a spawnpoint as a spectator" );
return false;
}
if (server.lobbyInfo.Clients.Where( c => c != client ).Any( c => (c.SpawnPoint == spawnPoint) && (c.SpawnPoint != 0) ))
{
server.SendChatTo( conn, "You can't be at the same spawn point as another player" );
return true;
}
client.SpawnPoint = spawnPoint;
server.SyncLobbyInfo();
return true;
}},
{ "color",
s =>
{
var c = s.Split(',').Select(cc => int.Parse(cc)).ToArray();
client.ColorRamp = new ColorRamp((byte)c[0], (byte)c[1], (byte)c[2], (byte)c[3]);
server.SyncLobbyInfo();
return true;
}}
};
var cmdName = cmd.Split(' ').First();
var cmdValue = string.Join(" ", cmd.Split(' ').Skip(1).ToArray());
Func<string,bool> a;
if (!dict.TryGetValue(cmdName, out a))
return false;
return a(cmdValue);
}
示例3: ClientJoined
public void ClientJoined(S server, Connection newConn)
{
var defaults = new GameRules.PlayerSettings();
var client = new Session.Client()
{
Index = newConn.PlayerIndex,
Color1 = defaults.Color1,
Color2 = defaults.Color2,
Name = defaults.Name,
Country = "random",
State = Session.ClientState.NotReady,
SpawnPoint = 0,
Team = 0,
Slot = ChooseFreeSlot(server),
};
var slotData = server.lobbyInfo.Slots.FirstOrDefault( x => x.Index == client.Slot );
if (slotData != null)
SyncClientToPlayerReference(client, server.Map.Players[slotData.MapPlayer]);
server.lobbyInfo.Clients.Add(client);
Log.Write("server", "Client {0}: Accepted connection from {1}",
newConn.PlayerIndex, newConn.socket.RemoteEndPoint);
server.SendChat(newConn, "has joined the game.");
server.SyncLobbyInfo();
}
示例4: InterpretCommand
//.........这里部分代码省略.........
// Reassign players into new slots based on their old slots:
// - Observers remain as observers
// - Players who now lack a slot are made observers
// - Bots who now lack a slot are dropped
// - Bots who are not defined in the map rules are dropped
var botNames = server.Map.Rules.Actors["player"].TraitInfos<IBotInfo>().Select(t => t.Name);
var slots = server.LobbyInfo.Slots.Keys.ToArray();
var i = 0;
foreach (var os in oldSlots)
{
var c = server.LobbyInfo.ClientInSlot(os);
if (c == null)
continue;
c.SpawnPoint = 0;
c.Slot = i < slots.Length ? slots[i++] : null;
if (c.Slot != null)
{
// Remove Bot from slot if slot forbids bots
if (c.Bot != null && (!server.Map.Players.Players[c.Slot].AllowBots || !botNames.Contains(c.Bot)))
server.LobbyInfo.Clients.Remove(c);
S.SyncClientToPlayerReference(c, server.Map.Players.Players[c.Slot]);
}
else if (c.Bot != null)
server.LobbyInfo.Clients.Remove(c);
}
// Validate if color is allowed and get an alternative if it isn't
foreach (var c in server.LobbyInfo.Clients)
if (c.Slot == null || (c.Slot != null && !server.LobbyInfo.Slots[c.Slot].LockColor))
c.Color = c.PreferredColor = SanitizePlayerColor(server, c.Color, c.Index, conn);
server.SyncLobbyInfo();
server.SendMessage("{0} changed the map to {1}.".F(client.Name, server.Map.Title));
if (server.Map.DefinesUnsafeCustomRules)
server.SendMessage("This map contains custom rules. Game experience may change.");
if (server.Settings.DisableSinglePlayer)
server.SendMessage("Singleplayer games have been disabled on this server.");
else if (server.Map.Players.Players.Where(p => p.Value.Playable).All(p => !p.Value.AllowBots))
server.SendMessage("Bots have been disabled on this map.");
};
Action queryFailed = () =>
server.SendOrderTo(conn, "Message", "Map was not found on server.");
var m = server.ModData.MapCache[s];
if (m.Status == MapStatus.Available || m.Status == MapStatus.DownloadAvailable)
selectMap(m);
else if (server.Settings.QueryMapRepository)
{
server.SendOrderTo(conn, "Message", "Searching for map on the Resource Center...");
server.ModData.MapCache.QueryRemoteMapDetails(new[] { s }, selectMap, queryFailed);
}
else
queryFailed();
return true;
}
},
{ "allowcheats",
s =>
{
示例5: 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;
}},
//.........这里部分代码省略.........
示例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();
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 =>
//.........这里部分代码省略.........
示例7: InterpretCommand
//.........这里部分代码省略.........
c.State = Session.ClientState.Invalid;
// Reassign players into new slots based on their old slots:
// - Observers remain as observers
// - Players who now lack a slot are made observers
// - Bots who now lack a slot are dropped
var slots = server.LobbyInfo.Slots.Keys.ToArray();
var i = 0;
foreach (var os in oldSlots)
{
var c = server.LobbyInfo.ClientInSlot(os);
if (c == null)
continue;
c.SpawnPoint = 0;
c.Slot = i < slots.Length ? slots[i++] : null;
if (c.Slot != null)
{
// Remove Bot from slot if slot forbids bots
if (c.Bot != null && !server.MapPlayers.Players[c.Slot].AllowBots)
server.LobbyInfo.Clients.Remove(c);
S.SyncClientToPlayerReference(c, server.MapPlayers.Players[c.Slot]);
}
else if (c.Bot != null)
server.LobbyInfo.Clients.Remove(c);
}
foreach (var c in server.LobbyInfo.Clients)
{
// Validate if color is allowed and get an alternative it it isn't
c.Color = c.PreferredColor = ColorValidator.ValidatePlayerColorAndGetAlternative(server, c.Color, c.Index, conn);
}
server.SyncLobbyInfo();
server.SendMessage("{0} changed the map to {1}.".F(client.Name, server.Map.Title));
if (server.Map.RuleDefinitions.Any())
server.SendMessage("This map contains custom rules. Game experience may change.");
return true;
}
},
{ "fragilealliance",
s =>
{
if (!client.IsAdmin)
{
server.SendOrderTo(conn, "Message", "Only the host can set that option.");
return true;
}
if (server.Map.Options.FragileAlliances.HasValue)
{
server.SendOrderTo(conn, "Message", "Map has disabled alliance configuration.");
return true;
}
bool.TryParse(s, out server.LobbyInfo.GlobalSettings.FragileAlliances);
server.SyncLobbyGlobalSettings();
server.SendMessage("{0} {1} Diplomacy Changes."
.F(client.Name, server.LobbyInfo.GlobalSettings.FragileAlliances ? "enabled" : "disabled"));
return true;
}
},