Serverlog message types (which atm only determine the color of the message)
This commit is contained in:
@@ -125,7 +125,7 @@ namespace Barotrauma.Networking
|
||||
if (banned == null) return false;
|
||||
|
||||
DebugConsole.Log("Removing ban from " + banned.Name);
|
||||
GameServer.Log("Removing ban from " + banned.Name, null);
|
||||
GameServer.Log("Removing ban from " + banned.Name, ServerLog.MessageType.ServerMessage);
|
||||
|
||||
bannedPlayers.Remove(banned);
|
||||
|
||||
@@ -189,7 +189,7 @@ namespace Barotrauma.Networking
|
||||
|
||||
public void Save()
|
||||
{
|
||||
GameServer.Log("Saving banlist", null);
|
||||
GameServer.Log("Saving banlist", ServerLog.MessageType.ServerMessage);
|
||||
|
||||
List<string> lines = new List<string>();
|
||||
|
||||
|
||||
@@ -164,7 +164,7 @@ namespace Barotrauma.Networking
|
||||
bool error = false;
|
||||
try
|
||||
{
|
||||
Log("Starting the server...", Color.Cyan);
|
||||
Log("Starting the server...", ServerLog.MessageType.ServerMessage);
|
||||
server = new NetServer(config);
|
||||
netPeer = server;
|
||||
|
||||
@@ -176,7 +176,7 @@ namespace Barotrauma.Networking
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log("Error while starting the server (" + e.Message + ")", Color.Red);
|
||||
Log("Error while starting the server (" + e.Message + ")", ServerLog.MessageType.Error);
|
||||
|
||||
System.Net.Sockets.SocketException socketException = e as System.Net.Sockets.SocketException;
|
||||
|
||||
@@ -233,7 +233,7 @@ namespace Barotrauma.Networking
|
||||
|
||||
updateInterval = new TimeSpan(0, 0, 0, 0, 150);
|
||||
|
||||
Log("Server started", Color.Cyan);
|
||||
Log("Server started", ServerLog.MessageType.ServerMessage);
|
||||
|
||||
GameMain.NetLobbyScreen.Select();
|
||||
started = true;
|
||||
@@ -266,7 +266,7 @@ namespace Barotrauma.Networking
|
||||
{
|
||||
restRequestHandle.Abort();
|
||||
DebugConsole.NewMessage("Couldn't register to master server (request timed out)", Color.Red);
|
||||
Log("Couldn't register to master server (request timed out)", Color.Red);
|
||||
Log("Couldn't register to master server (request timed out)", ServerLog.MessageType.Error);
|
||||
yield return CoroutineStatus.Success;
|
||||
}
|
||||
|
||||
@@ -304,7 +304,7 @@ namespace Barotrauma.Networking
|
||||
request.AddParameter("currplayers", connectedClients.Count);
|
||||
request.AddParameter("maxplayers", MaxPlayers);
|
||||
|
||||
Log("Refreshing connection with master server...", Color.Cyan);
|
||||
Log("Refreshing connection with master server...", ServerLog.MessageType.ServerMessage);
|
||||
|
||||
var sw = new Stopwatch();
|
||||
sw.Start();
|
||||
@@ -320,7 +320,7 @@ namespace Barotrauma.Networking
|
||||
{
|
||||
restRequestHandle.Abort();
|
||||
DebugConsole.NewMessage("Couldn't connect to master server (request timed out)", Color.Red);
|
||||
Log("Couldn't connect to master server (request timed out)", Color.Red);
|
||||
Log("Couldn't connect to master server (request timed out)", ServerLog.MessageType.Error);
|
||||
yield return CoroutineStatus.Success;
|
||||
}
|
||||
|
||||
@@ -329,22 +329,22 @@ namespace Barotrauma.Networking
|
||||
|
||||
if (masterServerResponse.Content == "Error: server not found")
|
||||
{
|
||||
Log("Not registered to master server, re-registering...", Color.Red);
|
||||
Log("Not registered to master server, re-registering...", ServerLog.MessageType.Error);
|
||||
CoroutineManager.StartCoroutine(RegisterToMasterServer());
|
||||
}
|
||||
else if (masterServerResponse.ErrorException != null)
|
||||
{
|
||||
DebugConsole.NewMessage("Error while registering to master server (" + masterServerResponse.ErrorException + ")", Color.Red);
|
||||
Log("Error while registering to master server (" + masterServerResponse.ErrorException + ")", Color.Red);
|
||||
Log("Error while registering to master server (" + masterServerResponse.ErrorException + ")", ServerLog.MessageType.Error);
|
||||
}
|
||||
else if (masterServerResponse.StatusCode != System.Net.HttpStatusCode.OK)
|
||||
{
|
||||
DebugConsole.NewMessage("Error while reporting to master server (" + masterServerResponse.StatusCode + ": " + masterServerResponse.StatusDescription + ")", Color.Red);
|
||||
Log("Error while reporting to master server (" + masterServerResponse.StatusCode + ": " + masterServerResponse.StatusDescription + ")", Color.Red);
|
||||
Log("Error while reporting to master server (" + masterServerResponse.StatusCode + ": " + masterServerResponse.StatusDescription + ")", ServerLog.MessageType.Error);
|
||||
}
|
||||
else
|
||||
{
|
||||
Log("Master server responded", Color.Cyan);
|
||||
Log("Master server responded", ServerLog.MessageType.ServerMessage);
|
||||
}
|
||||
|
||||
System.Diagnostics.Debug.WriteLine("took "+sw.ElapsedMilliseconds+" ms");
|
||||
@@ -406,11 +406,11 @@ namespace Barotrauma.Networking
|
||||
{
|
||||
if (AutoRestart && isCrewDead)
|
||||
{
|
||||
Log("Ending round (entire crew dead)", Color.Cyan);
|
||||
Log("Ending round (entire crew dead)", ServerLog.MessageType.ServerMessage);
|
||||
}
|
||||
else
|
||||
{
|
||||
Log("Ending round (submarine reached the end of the level)", Color.Cyan);
|
||||
Log("Ending round (submarine reached the end of the level)", ServerLog.MessageType.ServerMessage);
|
||||
}
|
||||
|
||||
EndGame();
|
||||
@@ -777,7 +777,7 @@ namespace Barotrauma.Networking
|
||||
|
||||
if (!c.HasPermission(command))
|
||||
{
|
||||
Log("Client \""+c.name+"\" sent a server command \""+command+"\". Permission denied.", Color.Red);
|
||||
Log("Client \""+c.name+"\" sent a server command \""+command+"\". Permission denied.", ServerLog.MessageType.ServerMessage);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -788,7 +788,7 @@ namespace Barotrauma.Networking
|
||||
var kickedClient = connectedClients.Find(cl => cl != c && cl.name == kickedName);
|
||||
if (kickedClient != null)
|
||||
{
|
||||
Log("Client \"" + c.name + "\" kicked \"" + kickedClient.name + "\".", Color.Red);
|
||||
Log("Client \"" + c.name + "\" kicked \"" + kickedClient.name + "\".", ServerLog.MessageType.ServerMessage);
|
||||
KickClient(kickedClient, false, false);
|
||||
}
|
||||
break;
|
||||
@@ -797,14 +797,14 @@ namespace Barotrauma.Networking
|
||||
var bannedClient = connectedClients.Find(cl => cl != c && cl.name == bannedName);
|
||||
if (bannedClient != null)
|
||||
{
|
||||
Log("Client \"" + c.name + "\" banned \"" + bannedClient.name + "\".", Color.Red);
|
||||
Log("Client \"" + c.name + "\" banned \"" + bannedClient.name + "\".", ServerLog.MessageType.ServerMessage);
|
||||
KickClient(bannedClient, true, false);
|
||||
}
|
||||
break;
|
||||
case ClientPermissions.EndRound:
|
||||
if (gameStarted)
|
||||
{
|
||||
Log("Client \"" + c.name + "\" ended the round.", Color.Cyan);
|
||||
Log("Client \"" + c.name + "\" ended the round.", ServerLog.MessageType.ServerMessage);
|
||||
EndGame();
|
||||
}
|
||||
break;
|
||||
@@ -1088,10 +1088,10 @@ namespace Barotrauma.Networking
|
||||
|
||||
GameMain.GameSession.StartShift(GameMain.NetLobbyScreen.LevelSeed, teamCount > 1);
|
||||
|
||||
GameServer.Log("Starting a new round...", Color.Cyan);
|
||||
GameServer.Log("Submarine: " + selectedSub.Name, Color.Cyan);
|
||||
GameServer.Log("Game mode: " + selectedMode.Name, Color.Cyan);
|
||||
GameServer.Log("Level seed: " + GameMain.NetLobbyScreen.LevelSeed, Color.Cyan);
|
||||
GameServer.Log("Starting a new round...", ServerLog.MessageType.ServerMessage);
|
||||
GameServer.Log("Submarine: " + selectedSub.Name, ServerLog.MessageType.ServerMessage);
|
||||
GameServer.Log("Game mode: " + selectedMode.Name, ServerLog.MessageType.ServerMessage);
|
||||
GameServer.Log("Level seed: " + GameMain.NetLobbyScreen.LevelSeed, ServerLog.MessageType.ServerMessage);
|
||||
|
||||
bool missionAllowRespawn =
|
||||
!(GameMain.GameSession.gameMode is MissionMode) ||
|
||||
@@ -1166,7 +1166,7 @@ namespace Barotrauma.Networking
|
||||
|
||||
if (TraitorManager.TraitorCharacter!=null && TraitorManager.TargetCharacter != null)
|
||||
{
|
||||
Log(TraitorManager.TraitorCharacter.Name + " is the traitor and the target is " + TraitorManager.TargetCharacter.Name, Color.Cyan);
|
||||
Log(TraitorManager.TraitorCharacter.Name + " is the traitor and the target is " + TraitorManager.TargetCharacter.Name, ServerLog.MessageType.ServerMessage);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1409,7 +1409,7 @@ namespace Barotrauma.Networking
|
||||
if (string.IsNullOrWhiteSpace(msg)) msg = client.name + " has left the server";
|
||||
if (string.IsNullOrWhiteSpace(targetmsg)) targetmsg = "You have left the server";
|
||||
|
||||
Log(msg, ChatMessage.MessageColor[(int)ChatMessageType.Server]);
|
||||
Log(msg, ServerLog.MessageType.ServerMessage);
|
||||
|
||||
client.Connection.Disconnect(targetmsg);
|
||||
|
||||
@@ -1818,7 +1818,7 @@ namespace Barotrauma.Networking
|
||||
if (Voting.AllowEndVoting && EndVoteMax > 0 &&
|
||||
((float)EndVoteCount / (float)EndVoteMax) >= EndVoteRequiredRatio)
|
||||
{
|
||||
Log("Ending round by votes (" + EndVoteCount + "/" + (EndVoteMax - EndVoteCount) + ")", Color.Cyan);
|
||||
Log("Ending round by votes (" + EndVoteCount + "/" + (EndVoteMax - EndVoteCount) + ")", ServerLog.MessageType.ServerMessage);
|
||||
EndGame();
|
||||
}
|
||||
}
|
||||
@@ -2005,11 +2005,11 @@ namespace Barotrauma.Networking
|
||||
return preferredClient;
|
||||
}
|
||||
|
||||
public static void Log(string line, Color? color)
|
||||
public static void Log(string line, ServerLog.MessageType messageType)
|
||||
{
|
||||
if (GameMain.Server == null || !GameMain.Server.SaveServerLogs) return;
|
||||
|
||||
GameMain.Server.log.WriteLine(line, color);
|
||||
GameMain.Server.log.WriteLine(line, messageType);
|
||||
}
|
||||
|
||||
public override void Disconnect()
|
||||
@@ -2029,7 +2029,7 @@ namespace Barotrauma.Networking
|
||||
|
||||
if (SaveServerLogs)
|
||||
{
|
||||
Log("Shutting down server...", Color.Cyan);
|
||||
Log("Shutting down the server...", ServerLog.MessageType.ServerMessage);
|
||||
log.Save();
|
||||
}
|
||||
|
||||
|
||||
@@ -127,45 +127,45 @@ namespace Barotrauma.Networking
|
||||
{
|
||||
DisconnectUnauthClient(inc, unauthClient, "You need a name.");
|
||||
|
||||
Log(inc.SenderConnection.RemoteEndPoint.Address.ToString() + " couldn't join the server (no name given)", Color.Red);
|
||||
Log(inc.SenderConnection.RemoteEndPoint.Address.ToString() + " couldn't join the server (no name given)", ServerLog.MessageType.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
if (clVersion != GameMain.Version.ToString())
|
||||
{
|
||||
DisconnectUnauthClient(inc, unauthClient, "Version " + GameMain.Version + " required to connect to the server (Your version: " + clVersion + ")");
|
||||
Log(clName + " couldn't join the server (wrong game version)", Color.Red);
|
||||
Log(clName + " couldn't join the server (wrong game version)", ServerLog.MessageType.Error);
|
||||
return;
|
||||
}
|
||||
if (clPackageName != GameMain.SelectedPackage.Name)
|
||||
{
|
||||
DisconnectUnauthClient(inc, unauthClient, "Your content package (" + clPackageName + ") doesn't match the server's version (" + GameMain.SelectedPackage.Name + ")");
|
||||
Log(clName + " couldn't join the server (wrong content package name)", Color.Red);
|
||||
Log(clName + " couldn't join the server (wrong content package name)", ServerLog.MessageType.Error);
|
||||
return;
|
||||
}
|
||||
if (clPackageHash != GameMain.SelectedPackage.MD5hash.Hash)
|
||||
{
|
||||
DisconnectUnauthClient(inc, unauthClient, "Your content package (MD5: " + clPackageHash + ") doesn't match the server's version (MD5: " + GameMain.SelectedPackage.MD5hash.Hash + ")");
|
||||
Log(clName + " couldn't join the server (wrong content package hash)", Color.Red);
|
||||
Log(clName + " couldn't join the server (wrong content package hash)", ServerLog.MessageType.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!whitelist.IsWhiteListed(clName, inc.SenderConnection.RemoteEndPoint.Address.ToString()))
|
||||
{
|
||||
DisconnectUnauthClient(inc, unauthClient, "You're not in this server's whitelist.");
|
||||
Log(clName + " (" + inc.SenderConnection.RemoteEndPoint.Address.ToString() + ") couldn't join the server (not in whitelist)", Color.Red);
|
||||
Log(clName + " (" + inc.SenderConnection.RemoteEndPoint.Address.ToString() + ") couldn't join the server (not in whitelist)", ServerLog.MessageType.Error);
|
||||
return;
|
||||
}
|
||||
if (!Client.IsValidName(clName))
|
||||
{
|
||||
DisconnectUnauthClient(inc, unauthClient, "Your name contains illegal symbols.");
|
||||
Log(clName + " (" + inc.SenderConnection.RemoteEndPoint.Address.ToString() + ") couldn't join the server (invalid name)", Color.Red);
|
||||
Log(clName + " (" + inc.SenderConnection.RemoteEndPoint.Address.ToString() + ") couldn't join the server (invalid name)", ServerLog.MessageType.Error);
|
||||
return;
|
||||
}
|
||||
if (clName.ToLower() == Name.ToLower())
|
||||
{
|
||||
DisconnectUnauthClient(inc, unauthClient, "That name is taken.");
|
||||
Log(clName + " (" + inc.SenderConnection.RemoteEndPoint.Address.ToString() + ") couldn't join the server (name taken by the server)", Color.Red);
|
||||
Log(clName + " (" + inc.SenderConnection.RemoteEndPoint.Address.ToString() + ") couldn't join the server (name taken by the server)", ServerLog.MessageType.Error);
|
||||
return;
|
||||
}
|
||||
Client nameTaken = ConnectedClients.Find(c => c.name.ToLower() == clName.ToLower());
|
||||
@@ -185,7 +185,7 @@ namespace Barotrauma.Networking
|
||||
{
|
||||
//can't authorize this client
|
||||
DisconnectUnauthClient(inc, unauthClient, "That name is taken.");
|
||||
Log(clName + " (" + inc.SenderConnection.RemoteEndPoint.Address.ToString() + ") couldn't join the server (name already taken)", Color.Red);
|
||||
Log(clName + " (" + inc.SenderConnection.RemoteEndPoint.Address.ToString() + ") couldn't join the server (name already taken)", ServerLog.MessageType.Error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -741,7 +741,7 @@ namespace Barotrauma.Networking
|
||||
|
||||
public void SaveClientPermissions()
|
||||
{
|
||||
GameServer.Log("Saving client permissions", null);
|
||||
GameServer.Log("Saving client permissions", ServerLog.MessageType.ServerMessage);
|
||||
|
||||
List<string> lines = new List<string>();
|
||||
|
||||
|
||||
@@ -227,7 +227,7 @@ namespace Barotrauma.Networking
|
||||
|
||||
public void AddChatMessage(ChatMessage message)
|
||||
{
|
||||
GameServer.Log(message.TextWithSender, message.Color);
|
||||
GameServer.Log(message.TextWithSender, ServerLog.MessageType.Chat);
|
||||
|
||||
string displayedText = message.Text;
|
||||
|
||||
|
||||
@@ -8,6 +8,36 @@ namespace Barotrauma.Networking
|
||||
{
|
||||
class ServerLog
|
||||
{
|
||||
private struct LogMessage
|
||||
{
|
||||
public readonly string Text;
|
||||
public readonly MessageType Type;
|
||||
|
||||
public LogMessage(string text, MessageType type)
|
||||
{
|
||||
Text = "[" + DateTime.Now.ToString() + "] " + text;
|
||||
Type = type;
|
||||
}
|
||||
}
|
||||
|
||||
public enum MessageType
|
||||
{
|
||||
Chat,
|
||||
ItemInteraction,
|
||||
Attack,
|
||||
ServerMessage,
|
||||
Error
|
||||
}
|
||||
|
||||
private Color[] MessageColor = new Color[]
|
||||
{
|
||||
Color.LightBlue,
|
||||
new Color(238, 208, 0),
|
||||
new Color(204, 74, 78),
|
||||
new Color(157, 225, 160),
|
||||
Color.Red
|
||||
};
|
||||
|
||||
private int linesPerFile = 800;
|
||||
|
||||
public const string SavePath = "ServerLogs";
|
||||
@@ -18,7 +48,7 @@ namespace Barotrauma.Networking
|
||||
|
||||
private GUIListBox listBox;
|
||||
|
||||
private readonly Queue<ColoredText> lines;
|
||||
private readonly Queue<LogMessage> lines;
|
||||
|
||||
private int unsavedLineCount;
|
||||
|
||||
@@ -32,14 +62,14 @@ namespace Barotrauma.Networking
|
||||
{
|
||||
this.serverName = serverName;
|
||||
|
||||
lines = new Queue<ColoredText>();
|
||||
lines = new Queue<LogMessage>();
|
||||
}
|
||||
|
||||
public void WriteLine(string line, Color? color)
|
||||
public void WriteLine(string line, MessageType messageType)
|
||||
{
|
||||
string logLine = "[" + DateTime.Now.ToLongTimeString() + "] " + line;
|
||||
//string logLine = "[" + DateTime.Now.ToLongTimeString() + "] " + line;
|
||||
|
||||
var newText = new ColoredText(logLine, color == null ? Color.White : (Color)color);
|
||||
var newText = new LogMessage(line, messageType);
|
||||
|
||||
lines.Enqueue(newText);
|
||||
|
||||
@@ -62,7 +92,7 @@ namespace Barotrauma.Networking
|
||||
{
|
||||
listBox.RemoveChild(listBox.children[0]);
|
||||
lines.Dequeue();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void CreateLogFrame()
|
||||
@@ -83,11 +113,11 @@ namespace Barotrauma.Networking
|
||||
clearButton.OnClicked = ClearFilter;
|
||||
clearButton.UserData = searchBox;
|
||||
|
||||
listBox = new GUIListBox(new Rectangle(0, 30, 0, 320), "", innerFrame);
|
||||
listBox = new GUIListBox(new Rectangle(0, 30, 0, 340), "", innerFrame);
|
||||
|
||||
var currLines = lines.ToList();
|
||||
|
||||
foreach (ColoredText line in currLines)
|
||||
foreach (LogMessage line in currLines)
|
||||
{
|
||||
AddLine(line);
|
||||
}
|
||||
@@ -104,16 +134,14 @@ namespace Barotrauma.Networking
|
||||
};
|
||||
}
|
||||
|
||||
private void AddLine(ColoredText line)
|
||||
private void AddLine(LogMessage line)
|
||||
{
|
||||
float prevSize = listBox.BarSize;
|
||||
|
||||
var textBlock = new GUITextBlock(new Rectangle(0, 0, 0, 0), line.Text, "", Alignment.TopLeft, Alignment.TopLeft, listBox, true, GUI.SmallFont);
|
||||
textBlock.Rect = new Rectangle(textBlock.Rect.X, textBlock.Rect.Y, textBlock.Rect.Width, Math.Max(13, textBlock.Rect.Height));
|
||||
|
||||
//listBox.AddChild(textBlock);
|
||||
|
||||
textBlock.TextColor = line.Color;
|
||||
|
||||
textBlock.TextColor = MessageColor[(int)line.Type];
|
||||
textBlock.CanBeFocused = false;
|
||||
|
||||
if ((prevSize == 1.0f && listBox.BarScroll == 0.0f) || (prevSize < 1.0f && listBox.BarScroll == 1.0f)) listBox.BarScroll = 1.0f;
|
||||
|
||||
@@ -86,7 +86,7 @@ namespace Barotrauma.Networking
|
||||
|
||||
public void Save()
|
||||
{
|
||||
GameServer.Log("Saving whitelist", null);
|
||||
GameServer.Log("Saving whitelist", ServerLog.MessageType.ServerMessage);
|
||||
|
||||
List<string> lines = new List<string>();
|
||||
|
||||
@@ -193,7 +193,7 @@ namespace Barotrauma.Networking
|
||||
if (wlp == null) return false;
|
||||
|
||||
DebugConsole.Log("Removing " + wlp.Name + " from whitelist");
|
||||
GameServer.Log("Removing " + wlp.Name + " from whitelist", null);
|
||||
GameServer.Log("Removing " + wlp.Name + " from whitelist", ServerLog.MessageType.ServerMessage);
|
||||
|
||||
whitelistedPlayers.Remove(wlp);
|
||||
Save();
|
||||
|
||||
Reference in New Issue
Block a user