Merge pull request #7851 from Mailaender/dedicated-console-log

Added status messages to console output for dedicated servers
This commit is contained in:
Pavel Penev
2015-06-25 01:45:49 +03:00
3 changed files with 41 additions and 37 deletions

View File

@@ -450,6 +450,9 @@ namespace OpenRA.Server
public void SendMessage(string text) public void SendMessage(string text)
{ {
DispatchOrdersToClients(null, 0, new ServerOrder("Message", text).Serialize()); DispatchOrdersToClients(null, 0, new ServerOrder("Message", text).Serialize());
if (Settings.Dedicated)
Console.WriteLine("[{0}] {1}".F(DateTime.Now.ToString(Settings.TimestampFormat), text));
} }
void InterpretServerOrder(Connection conn, ServerOrder so) void InterpretServerOrder(Connection conn, ServerOrder so)

View File

@@ -39,6 +39,7 @@ namespace OpenRA
public bool DedicatedLoop = true; public bool DedicatedLoop = true;
public bool LockBots = false; public bool LockBots = false;
public bool AllowVersionMismatch = false; public bool AllowVersionMismatch = false;
public string TimestampFormat = "HH:mm";
public ServerSettings() { } public ServerSettings() { }

View File

@@ -63,54 +63,54 @@ namespace OpenRA.Mods.Common.Server
var clients = server.LobbyInfo.Clients.Where(c1 => c1.Bot == null).Select(c => Convert.ToBase64String(Encoding.UTF8.GetBytes(c.Name))).ToArray(); var clients = server.LobbyInfo.Clients.Where(c1 => c1.Bot == null).Select(c => Convert.ToBase64String(Encoding.UTF8.GetBytes(c.Name))).ToArray();
Action a = () => Action a = () =>
{
try
{ {
try var url = "ping?port={0}&name={1}&state={2}&players={3}&bots={4}&mods={5}&map={6}&maxplayers={7}&spectators={8}&protected={9}&clients={10}";
if (isInitialPing) url += "&new=1";
using (var wc = new WebClient())
{ {
var url = "ping?port={0}&name={1}&state={2}&players={3}&bots={4}&mods={5}&map={6}&maxplayers={7}&spectators={8}&protected={9}&clients={10}"; wc.Proxy = null;
if (isInitialPing) url += "&new=1"; var masterResponse = wc.DownloadData(
server.Settings.MasterServer + url.F(
server.Settings.ExternalPort, Uri.EscapeUriString(server.Settings.Name),
(int)server.State,
numPlayers,
numBots,
"{0}@{1}".F(mod.Id, mod.Version),
server.LobbyInfo.GlobalSettings.Map,
numSlots,
numSpectators,
passwordProtected,
string.Join(",", clients)));
using (var wc = new WebClient()) if (isInitialPing)
{ {
wc.Proxy = null; var masterResponseText = Encoding.UTF8.GetString(masterResponse);
var masterResponse = wc.DownloadData( isInitialPing = false;
server.Settings.MasterServer + url.F( lock (masterServerMessages)
server.Settings.ExternalPort, Uri.EscapeUriString(server.Settings.Name),
(int)server.State,
numPlayers,
numBots,
"{0}@{1}".F(mod.Id, mod.Version),
server.LobbyInfo.GlobalSettings.Map,
numSlots,
numSpectators,
passwordProtected,
string.Join(",", clients)));
if (isInitialPing)
{ {
var masterResponseText = Encoding.UTF8.GetString(masterResponse); masterServerMessages.Enqueue("Master server communication established.");
isInitialPing = false; if (masterResponseText.Contains("[001]")) // Server does not respond code
lock (masterServerMessages)
{ {
masterServerMessages.Enqueue("Master server communication established."); Log.Write("server", masterResponseText);
if (masterResponseText.Contains("[001]")) // Server does not respond code masterServerMessages.Enqueue("Warning: Server ports are not forwarded.");
{ masterServerMessages.Enqueue("Game has not been advertised online.");
Log.Write("server", masterResponseText);
masterServerMessages.Enqueue("Warning: Server ports are not forwarded.");
masterServerMessages.Enqueue("Game has not been advertised online.");
}
} }
} }
} }
} }
catch (Exception ex) }
{ catch (Exception ex)
Log.Write("server", ex.ToString()); {
lock (masterServerMessages) Log.Write("server", ex.ToString());
masterServerMessages.Enqueue("Master server communication failed."); lock (masterServerMessages)
} masterServerMessages.Enqueue("Master server communication failed.");
}
isBusy = false; isBusy = false;
}; };
a.BeginInvoke(null, null); a.BeginInvoke(null, null);
} }