Rework server orders.
- Server messages now show as from "Server". - Fixes #3224.
This commit is contained in:
@@ -51,14 +51,14 @@ namespace OpenRA.Network
|
|||||||
Game.AddChatLine(Color.White, "(player {0})".F(clientId), order.TargetString);
|
Game.AddChatLine(Color.White, "(player {0})".F(clientId), order.TargetString);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case "Message": // Server message
|
||||||
|
Game.AddChatLine(Color.White, "Server", order.TargetString);
|
||||||
|
break;
|
||||||
case "Disconnected": /* reports that the target player disconnected */
|
case "Disconnected": /* reports that the target player disconnected */
|
||||||
{
|
{
|
||||||
var client = orderManager.LobbyInfo.ClientWithIndex(clientId);
|
var client = orderManager.LobbyInfo.ClientWithIndex(clientId);
|
||||||
if (client != null)
|
if (client != null)
|
||||||
{
|
|
||||||
client.State = Session.ClientState.Disconnected;
|
client.State = Session.ClientState.Disconnected;
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -306,7 +306,7 @@ namespace OpenRA.Server
|
|||||||
t.ClientJoined(this, newConn);
|
t.ClientJoined(this, newConn);
|
||||||
|
|
||||||
SyncLobbyInfo();
|
SyncLobbyInfo();
|
||||||
SendChat(newConn, "has joined the game.");
|
SendMessage("{0} has joined the server.".F(client.Name));
|
||||||
|
|
||||||
// Send initial ping
|
// Send initial ping
|
||||||
SendOrderTo(newConn, "Ping", Environment.TickCount.ToString());
|
SendOrderTo(newConn, "Ping", Environment.TickCount.ToString());
|
||||||
@@ -314,20 +314,18 @@ namespace OpenRA.Server
|
|||||||
if (File.Exists("{0}motd_{1}.txt".F(Platform.SupportDir, lobbyInfo.GlobalSettings.Mods[0])))
|
if (File.Exists("{0}motd_{1}.txt".F(Platform.SupportDir, lobbyInfo.GlobalSettings.Mods[0])))
|
||||||
{
|
{
|
||||||
var motd = System.IO.File.ReadAllText("{0}motd_{1}.txt".F(Platform.SupportDir, lobbyInfo.GlobalSettings.Mods[0]));
|
var motd = System.IO.File.ReadAllText("{0}motd_{1}.txt".F(Platform.SupportDir, lobbyInfo.GlobalSettings.Mods[0]));
|
||||||
SendChatTo(newConn, motd);
|
SendOrderTo(newConn, "Message", motd);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lobbyInfo.GlobalSettings.Dedicated)
|
if (lobbyInfo.GlobalSettings.Dedicated)
|
||||||
{
|
{
|
||||||
if (client.IsAdmin)
|
var message = client.IsAdmin ? "You are the server admin." : "{0} is the server admin.".F(clientAdmin.Name);
|
||||||
SendChatTo(newConn, " You are admin now!");
|
SendOrderTo(newConn, "Message", message);
|
||||||
else
|
|
||||||
SendChatTo(newConn, " Current admin is {0}".F(clientAdmin.Name));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mods.Any(m => m.Contains("{DEV_VERSION}")))
|
if (mods.Any(m => m.Contains("{DEV_VERSION}")))
|
||||||
SendChat(newConn, "is running a non-versioned development build, "+
|
SendMessage("{0} is running an unversioned development build, ".F(client.Name) +
|
||||||
"and may cause desync if it contains any incompatible changes.");
|
"and may desynchronize the game state if they have incompatible rules.");
|
||||||
}
|
}
|
||||||
catch (Exception) { DropClient(newConn); }
|
catch (Exception) { DropClient(newConn); }
|
||||||
}
|
}
|
||||||
@@ -376,16 +374,19 @@ namespace OpenRA.Server
|
|||||||
catch (Exception) { DropClient(c); }
|
catch (Exception) { DropClient(c); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DispatchOrders(Connection conn, int frame, byte[] data)
|
public void DispatchOrdersToClients(Connection conn, int frame, byte[] data)
|
||||||
{
|
|
||||||
if (frame == 0 && conn != null)
|
|
||||||
InterpretServerOrders(conn, data);
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
var from = conn != null ? conn.PlayerIndex : 0;
|
var from = conn != null ? conn.PlayerIndex : 0;
|
||||||
foreach (var c in conns.Except(conn).ToArray())
|
foreach (var c in conns.Except(conn).ToArray())
|
||||||
DispatchOrdersToClient(c, from, frame, data);
|
DispatchOrdersToClient(c, from, frame, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void DispatchOrders(Connection conn, int frame, byte[] data)
|
||||||
|
{
|
||||||
|
if (frame == 0 && conn != null)
|
||||||
|
InterpretServerOrders(conn, data);
|
||||||
|
else
|
||||||
|
DispatchOrdersToClients(conn, frame, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
void InterpretServerOrders(Connection conn, byte[] data)
|
void InterpretServerOrders(Connection conn, byte[] data)
|
||||||
@@ -406,32 +407,18 @@ namespace OpenRA.Server
|
|||||||
catch (NotImplementedException) { }
|
catch (NotImplementedException) { }
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SendChatTo(Connection conn, string text)
|
|
||||||
{
|
|
||||||
SendOrderTo(conn, "Chat", text);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void SendOrderTo(Connection conn, string order, string data)
|
public void SendOrderTo(Connection conn, string order, string data)
|
||||||
{
|
{
|
||||||
DispatchOrdersToClient(conn, 0, 0,
|
DispatchOrdersToClient(conn, 0, 0, new ServerOrder(order, data).Serialize());
|
||||||
new ServerOrder(order, data).Serialize());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SendChat(Connection asConn, string text)
|
public void SendMessage(string text)
|
||||||
{
|
{
|
||||||
DispatchOrders(asConn, 0, new ServerOrder("Chat", text).Serialize());
|
DispatchOrdersToClients(null, 0, new ServerOrder("Message", text).Serialize());
|
||||||
}
|
|
||||||
|
|
||||||
public void SendDisconnected(Connection asConn)
|
|
||||||
{
|
|
||||||
DispatchOrders(asConn, 0, new ServerOrder("Disconnected", "").Serialize());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void InterpretServerOrder(Connection conn, ServerOrder so)
|
void InterpretServerOrder(Connection conn, ServerOrder so)
|
||||||
{
|
{
|
||||||
var fromClient = GetClient(conn);
|
|
||||||
var fromIndex = fromClient != null ? fromClient.Index : 0;
|
|
||||||
|
|
||||||
switch (so.Name)
|
switch (so.Name)
|
||||||
{
|
{
|
||||||
case "Command":
|
case "Command":
|
||||||
@@ -443,7 +430,7 @@ namespace OpenRA.Server
|
|||||||
if (!handled)
|
if (!handled)
|
||||||
{
|
{
|
||||||
Log.Write("server", "Unknown server command: {0}", so.Data);
|
Log.Write("server", "Unknown server command: {0}", so.Data);
|
||||||
SendChatTo(conn, "Unknown server command: {0}".F(so.Data));
|
SendOrderTo(conn, "Message", "Unknown server command: {0}".F(so.Data));
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
@@ -451,16 +438,10 @@ namespace OpenRA.Server
|
|||||||
case "HandshakeResponse":
|
case "HandshakeResponse":
|
||||||
ValidateClient(conn, so.Data);
|
ValidateClient(conn, so.Data);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "Chat":
|
case "Chat":
|
||||||
case "TeamChat":
|
case "TeamChat":
|
||||||
foreach (var c in conns.Except(conn).ToArray())
|
|
||||||
DispatchOrdersToClient(c, fromIndex, 0, so.Serialize());
|
|
||||||
break;
|
|
||||||
|
|
||||||
case "PauseGame":
|
case "PauseGame":
|
||||||
foreach (var c in conns.Except(conn).ToArray())
|
DispatchOrdersToClients(conn, 0, so.Serialize());
|
||||||
DispatchOrdersToClient(c, fromIndex, 0, so.Serialize());
|
|
||||||
break;
|
break;
|
||||||
case "Pong":
|
case "Pong":
|
||||||
{
|
{
|
||||||
@@ -471,6 +452,7 @@ namespace OpenRA.Server
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var fromClient = GetClient(conn);
|
||||||
var history = fromClient.LatencyHistory.ToList();
|
var history = fromClient.LatencyHistory.ToList();
|
||||||
history.Add(Environment.TickCount - pingSent);
|
history.Add(Environment.TickCount - pingSent);
|
||||||
|
|
||||||
@@ -502,12 +484,12 @@ namespace OpenRA.Server
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
conns.Remove(toDrop);
|
conns.Remove(toDrop);
|
||||||
SendChat(toDrop, "Connection Dropped");
|
|
||||||
|
|
||||||
OpenRA.Network.Session.Client dropClient = lobbyInfo.Clients.Where(c1 => c1.Index == toDrop.PlayerIndex).Single();
|
OpenRA.Network.Session.Client dropClient = lobbyInfo.Clients.Where(c1 => c1.Index == toDrop.PlayerIndex).Single();
|
||||||
|
|
||||||
if (State == ServerState.GameStarted)
|
// Send disconnected order, even if still in the lobby
|
||||||
SendDisconnected(toDrop); /* Report disconnection */
|
SendMessage("{0} has disconnected.".F(dropClient.Name));
|
||||||
|
DispatchOrdersToClients(toDrop, 0, new ServerOrder("Disconnected", "").Serialize());
|
||||||
|
|
||||||
lobbyInfo.Clients.RemoveAll(c => c.Index == toDrop.PlayerIndex);
|
lobbyInfo.Clients.RemoveAll(c => c.Index == toDrop.PlayerIndex);
|
||||||
|
|
||||||
@@ -522,7 +504,7 @@ namespace OpenRA.Server
|
|||||||
// client was not alone on the server but he was admin: set admin to the last connected client
|
// client was not alone on the server but he was admin: set admin to the last connected client
|
||||||
OpenRA.Network.Session.Client lastClient = lobbyInfo.Clients.Where(c1 => c1.Bot == null).Last();
|
OpenRA.Network.Session.Client lastClient = lobbyInfo.Clients.Where(c1 => c1.Bot == null).Last();
|
||||||
lastClient.IsAdmin = true;
|
lastClient.IsAdmin = true;
|
||||||
SendChat(toDrop, "Admin left! {0} is a new admin now!".F(lastClient.Name));
|
SendMessage("{0} is now the admin.".F(lastClient.Name));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ namespace OpenRA.Mods.RA.Server
|
|||||||
|
|
||||||
if (requiresHost && !client.IsAdmin)
|
if (requiresHost && !client.IsAdmin)
|
||||||
{
|
{
|
||||||
server.SendChatTo(conn, "Only the host can do that");
|
server.SendOrderTo(conn, "Message", "Only the host can do that");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -41,12 +41,12 @@ namespace OpenRA.Mods.RA.Server
|
|||||||
{
|
{
|
||||||
if (server.State == ServerState.GameStarted)
|
if (server.State == ServerState.GameStarted)
|
||||||
{
|
{
|
||||||
server.SendChatTo(conn, "Cannot change state when game started. ({0})".F(cmd));
|
server.SendOrderTo(conn, "Message", "Cannot change state when game started. ({0})".F(cmd));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else if (client.State == Session.ClientState.Ready && !(cmd == "ready" || cmd == "startgame"))
|
else if (client.State == Session.ClientState.Ready && !(cmd == "ready" || cmd == "startgame"))
|
||||||
{
|
{
|
||||||
server.SendChatTo(conn, "Cannot change state when marked as ready.");
|
server.SendOrderTo(conn, "Message", "Cannot change state when marked as ready.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -94,7 +94,7 @@ namespace OpenRA.Mods.RA.Server
|
|||||||
if (server.lobbyInfo.Slots.Any(sl => sl.Value.Required &&
|
if (server.lobbyInfo.Slots.Any(sl => sl.Value.Required &&
|
||||||
server.lobbyInfo.ClientInSlot(sl.Key) == null))
|
server.lobbyInfo.ClientInSlot(sl.Key) == null))
|
||||||
{
|
{
|
||||||
server.SendChatTo(conn, "Unable to start the game until required slots are full.");
|
server.SendOrderTo(conn, "Message", "Unable to start the game until required slots are full.");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
server.StartGame();
|
server.StartGame();
|
||||||
@@ -180,7 +180,7 @@ namespace OpenRA.Mods.RA.Server
|
|||||||
|
|
||||||
if (parts.Length < 3)
|
if (parts.Length < 3)
|
||||||
{
|
{
|
||||||
server.SendChatTo(conn, "Malformed slot_bot command");
|
server.SendOrderTo(conn, "Message", "Malformed slot_bot command");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -200,7 +200,7 @@ namespace OpenRA.Mods.RA.Server
|
|||||||
// Invalid slot
|
// Invalid slot
|
||||||
if (bot != null && bot.Bot == null)
|
if (bot != null && bot.Bot == null)
|
||||||
{
|
{
|
||||||
server.SendChatTo(conn, "Can't add bots to a slot with another client");
|
server.SendOrderTo(conn, "Message", "Can't add bots to a slot with another client");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -245,12 +245,13 @@ namespace OpenRA.Mods.RA.Server
|
|||||||
{
|
{
|
||||||
if (!client.IsAdmin)
|
if (!client.IsAdmin)
|
||||||
{
|
{
|
||||||
server.SendChatTo( conn, "Only the host can change the map" );
|
server.SendOrderTo(conn, "Message", "Only the host can change the map");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!server.ModData.AvailableMaps.ContainsKey(s))
|
if (!server.ModData.AvailableMaps.ContainsKey(s))
|
||||||
{
|
{
|
||||||
server.SendChatTo( conn, "Map not found");
|
server.SendOrderTo(conn, "Message", "Map not found");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
server.lobbyInfo.GlobalSettings.Map = s;
|
server.lobbyInfo.GlobalSettings.Map = s;
|
||||||
@@ -292,7 +293,7 @@ namespace OpenRA.Mods.RA.Server
|
|||||||
{
|
{
|
||||||
if (!client.IsAdmin)
|
if (!client.IsAdmin)
|
||||||
{
|
{
|
||||||
server.SendChatTo( conn, "Only the host can set that option" );
|
server.SendOrderTo(conn, "Message", "Only the host can set that option");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -305,7 +306,7 @@ namespace OpenRA.Mods.RA.Server
|
|||||||
{
|
{
|
||||||
if (!client.IsAdmin)
|
if (!client.IsAdmin)
|
||||||
{
|
{
|
||||||
server.SendChatTo( conn, "Only the host can set that option" );
|
server.SendOrderTo(conn, "Message", "Only the host can set that option");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -318,14 +319,14 @@ namespace OpenRA.Mods.RA.Server
|
|||||||
{
|
{
|
||||||
if (!client.IsAdmin)
|
if (!client.IsAdmin)
|
||||||
{
|
{
|
||||||
server.SendChatTo(conn, "Only the host can set that option");
|
server.SendOrderTo(conn, "Message", "Only the host can set that option");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int teams;
|
int teams;
|
||||||
if (!int.TryParse(s, out teams))
|
if (!int.TryParse(s, out teams))
|
||||||
{
|
{
|
||||||
server.SendChatTo(conn, "Number of teams could not be parsed: {0}".F(s));
|
server.SendOrderTo(conn, "Message", "Number of teams could not be parsed: {0}".F(s));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
teams = teams.Clamp(2, 8);
|
teams = teams.Clamp(2, 8);
|
||||||
@@ -335,12 +336,12 @@ namespace OpenRA.Mods.RA.Server
|
|||||||
.Where(c => c != null && !server.lobbyInfo.Slots[c.Slot].LockTeam).ToArray();
|
.Where(c => c != null && !server.lobbyInfo.Slots[c.Slot].LockTeam).ToArray();
|
||||||
if (players.Length < 2)
|
if (players.Length < 2)
|
||||||
{
|
{
|
||||||
server.SendChatTo(conn, "Not enough players to assign teams");
|
server.SendOrderTo(conn, "Message", "Not enough players to assign teams");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (teams > players.Length)
|
if (teams > players.Length)
|
||||||
{
|
{
|
||||||
server.SendChatTo(conn, "Too many teams for the number of players");
|
server.SendOrderTo(conn, "Message", "Too many teams for the number of players");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -367,7 +368,7 @@ namespace OpenRA.Mods.RA.Server
|
|||||||
{
|
{
|
||||||
if (!client.IsAdmin)
|
if (!client.IsAdmin)
|
||||||
{
|
{
|
||||||
server.SendChatTo(conn, "Only the host can set that option");
|
server.SendOrderTo(conn, "Message", "Only the host can set that option");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -380,13 +381,13 @@ namespace OpenRA.Mods.RA.Server
|
|||||||
{
|
{
|
||||||
if (!client.IsAdmin)
|
if (!client.IsAdmin)
|
||||||
{
|
{
|
||||||
server.SendChatTo(conn, "Only the host can set that option");
|
server.SendOrderTo(conn, "Message", "Only the host can set that option");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if ((server.Map.Difficulties == null && s != null) || (server.Map.Difficulties != null && !server.Map.Difficulties.Contains(s)))
|
if ((server.Map.Difficulties == null && s != null) || (server.Map.Difficulties != null && !server.Map.Difficulties.Contains(s)))
|
||||||
{
|
{
|
||||||
server.SendChatTo(conn, "Unsupported difficulty selected: {0}".F(s));
|
server.SendOrderTo(conn, "Message", "Unsupported difficulty selected: {0}".F(s));
|
||||||
server.SendChatTo(conn, "Supported difficulties: {0}".F(server.Map.Difficulties.JoinWith(",")));
|
server.SendOrderTo(conn, "Message", "Supported difficulties: {0}".F(server.Map.Difficulties.JoinWith(",")));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -400,7 +401,7 @@ namespace OpenRA.Mods.RA.Server
|
|||||||
|
|
||||||
if (!client.IsAdmin)
|
if (!client.IsAdmin)
|
||||||
{
|
{
|
||||||
server.SendChatTo( conn, "Only the host can kick players" );
|
server.SendOrderTo(conn, "Message", "Only the host can kick players");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -410,7 +411,7 @@ namespace OpenRA.Mods.RA.Server
|
|||||||
var connToKick = server.conns.SingleOrDefault( c => server.GetClient(c) != null && server.GetClient(c).Index == clientID);
|
var connToKick = server.conns.SingleOrDefault( c => server.GetClient(c) != null && server.GetClient(c).Index == clientID);
|
||||||
if (connToKick == null)
|
if (connToKick == null)
|
||||||
{
|
{
|
||||||
server.SendChatTo( conn, "Noone in that slot." );
|
server.SendOrderTo(conn, "Message", "Noone in that slot.");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -497,7 +498,7 @@ namespace OpenRA.Mods.RA.Server
|
|||||||
|
|
||||||
if (server.lobbyInfo.Clients.Where( cc => cc != client ).Any( cc => (cc.SpawnPoint == spawnPoint) && (cc.SpawnPoint != 0) ))
|
if (server.lobbyInfo.Clients.Where( cc => cc != client ).Any( cc => (cc.SpawnPoint == spawnPoint) && (cc.SpawnPoint != 0) ))
|
||||||
{
|
{
|
||||||
server.SendChatTo( conn, "You can't be at the same spawn point as another player" );
|
server.SendOrderTo(conn, "Message", "You can't be at the same spawn point as another player");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ namespace OpenRA.Mods.RA.Server
|
|||||||
else
|
else
|
||||||
lock (masterServerMessages)
|
lock (masterServerMessages)
|
||||||
while (masterServerMessages.Count > 0)
|
while (masterServerMessages.Count > 0)
|
||||||
server.SendChat(null, masterServerMessages.Dequeue());
|
server.SendMessage(masterServerMessages.Dequeue());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user