Server log, ai characters steer away from the abyss
This commit is contained in:
@@ -20,7 +20,7 @@ namespace Barotrauma.Networking
|
||||
private NetStats netStats;
|
||||
|
||||
private int roundStartSeed;
|
||||
|
||||
|
||||
//is the server running
|
||||
private bool started;
|
||||
|
||||
@@ -32,6 +32,8 @@ namespace Barotrauma.Networking
|
||||
|
||||
private bool masterServerResponded;
|
||||
|
||||
private ServerLog log;
|
||||
|
||||
public TraitorManager TraitorManager;
|
||||
|
||||
public GameServer(string name, int port, bool isPublic = false, string password = "", bool attemptUPnP = false, int maxPlayers = 10)
|
||||
@@ -41,6 +43,8 @@ namespace Barotrauma.Networking
|
||||
|
||||
banList = new BanList();
|
||||
|
||||
log = new ServerLog(name);
|
||||
|
||||
this.name = name;
|
||||
this.password = password;
|
||||
|
||||
@@ -78,12 +82,14 @@ namespace Barotrauma.Networking
|
||||
{
|
||||
try
|
||||
{
|
||||
Log("Starting the server...");
|
||||
server = new NetServer(config);
|
||||
netPeer = server;
|
||||
server.Start();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log("Error while starting the server ("+e.Message+")");
|
||||
DebugConsole.ThrowError("Couldn't start the server", e);
|
||||
}
|
||||
|
||||
@@ -166,8 +172,8 @@ namespace Barotrauma.Networking
|
||||
request.AddParameter("action", "refreshserver");
|
||||
request.AddParameter("gamestarted", gameStarted ? 1 : 0);
|
||||
request.AddParameter("playercount", PlayerCountToByte(ConnectedClients.Count, config.MaximumConnections));
|
||||
|
||||
System.Diagnostics.Debug.WriteLine("refreshing master");
|
||||
|
||||
Log("Refreshing connection with master server...");
|
||||
|
||||
var sw = new Stopwatch();
|
||||
sw.Start();
|
||||
@@ -182,6 +188,9 @@ 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)");
|
||||
|
||||
break;
|
||||
//registeredToMaster = false;
|
||||
}
|
||||
@@ -201,14 +210,18 @@ namespace Barotrauma.Networking
|
||||
if (response.ErrorException != null)
|
||||
{
|
||||
DebugConsole.NewMessage("Error while registering to master server (" + response.ErrorException + ")", Color.Red);
|
||||
Log("Error while registering to master server (" + response.ErrorException + ")");
|
||||
return;
|
||||
}
|
||||
|
||||
if (response.StatusCode != System.Net.HttpStatusCode.OK)
|
||||
{
|
||||
DebugConsole.NewMessage("Error while reporting to master server (" + response.StatusCode + ": " + response.StatusDescription + ")", Color.Red);
|
||||
Log("Error while reporting to master server (" + response.StatusCode + ": " + response.StatusDescription + ")");
|
||||
return;
|
||||
}
|
||||
|
||||
Log("Master server responded");
|
||||
}
|
||||
|
||||
public override void Update(float deltaTime)
|
||||
@@ -233,6 +246,15 @@ namespace Barotrauma.Networking
|
||||
||
|
||||
(endRoundAtLevelEnd && Submarine.Loaded!=null && Submarine.Loaded.AtEndPosition))
|
||||
{
|
||||
if (AutoRestart && isCrewDead)
|
||||
{
|
||||
Log("Ending round (entire crew dead)");
|
||||
}
|
||||
else
|
||||
{
|
||||
Log("Ending round (submarine reached the end of the level)");
|
||||
}
|
||||
|
||||
EndButtonHit(null, null);
|
||||
UpdateNetLobby(null,null);
|
||||
return;
|
||||
@@ -474,10 +496,10 @@ namespace Barotrauma.Networking
|
||||
case (byte)PacketTypes.Vote:
|
||||
Voting.RegisterVote(inc, ConnectedClients);
|
||||
|
||||
if (Voting.AllowEndVoting && EndVoteMax > 0 &&
|
||||
|
||||
if (Voting.AllowEndVoting && EndVoteMax > 0 &&
|
||||
((float)EndVoteCount / (float)EndVoteMax) >= EndVoteRequiredRatio)
|
||||
{
|
||||
Log("Ending round by votes ("+EndVoteCount+"/"+(EndVoteMax-EndVoteCount)+")");
|
||||
EndButtonHit(null,null);
|
||||
}
|
||||
break;
|
||||
@@ -673,8 +695,10 @@ namespace Barotrauma.Networking
|
||||
{
|
||||
yield return new WaitForSeconds(3.0f);
|
||||
|
||||
//save all the current events to a list and clear them
|
||||
var existingEvents = NetworkEvent.Events;
|
||||
NetworkEvent.Events.Clear();
|
||||
|
||||
foreach (Hull hull in Hull.hullList)
|
||||
{
|
||||
if (!hull.FireSources.Any() && hull.Volume < 0.01f) continue;
|
||||
@@ -703,13 +727,18 @@ namespace Barotrauma.Networking
|
||||
List<NetworkEvent> syncMessages = new List<NetworkEvent>(NetworkEvent.Events);
|
||||
while (syncMessages.Any())
|
||||
{
|
||||
//put 5 events in the message and send them to the spectator
|
||||
NetworkEvent.Events = syncMessages.GetRange(0, Math.Min(syncMessages.Count, 5));
|
||||
SendNetworkEvents(new List<Client>() { sender });
|
||||
syncMessages.RemoveRange(0, Math.Min(syncMessages.Count, 5));
|
||||
|
||||
//restore "normal" events
|
||||
NetworkEvent.Events = existingEvents;
|
||||
|
||||
yield return new WaitForSeconds(0.1f);
|
||||
|
||||
//save "normal" events again
|
||||
existingEvents = NetworkEvent.Events;
|
||||
}
|
||||
|
||||
yield return CoroutineStatus.Success;
|
||||
@@ -762,6 +791,11 @@ namespace Barotrauma.Networking
|
||||
GameMain.GameSession = new GameSession(selectedSub, "", selectedMode);
|
||||
GameMain.GameSession.StartShift(GameMain.NetLobbyScreen.LevelSeed);
|
||||
|
||||
GameServer.Log("Starting a new round...");
|
||||
GameServer.Log("Submarine: " + selectedSub.Name);
|
||||
GameServer.Log("Game mode: " + selectedMode.Name);
|
||||
GameServer.Log("Level seed: " + GameMain.NetLobbyScreen.LevelSeed);
|
||||
|
||||
yield return CoroutineStatus.Running;
|
||||
|
||||
List<CharacterInfo> characterInfos = new List<CharacterInfo>();
|
||||
@@ -972,6 +1006,8 @@ 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);
|
||||
|
||||
NetOutgoingMessage outmsg = server.CreateMessage();
|
||||
outmsg.Write((byte)PacketTypes.KickedOut);
|
||||
@@ -1079,6 +1115,8 @@ namespace Barotrauma.Networking
|
||||
return;
|
||||
}
|
||||
|
||||
Log(traitor.Info.Name + " is the traitor and the target is " + target.Info.Name);
|
||||
|
||||
Client traitorClient = null;
|
||||
foreach (Client c in ConnectedClients)
|
||||
{
|
||||
@@ -1196,8 +1234,6 @@ namespace Barotrauma.Networking
|
||||
banButton.OnClicked += GameMain.NetLobbyScreen.BanPlayer;
|
||||
}
|
||||
|
||||
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
@@ -1392,6 +1428,13 @@ namespace Barotrauma.Networking
|
||||
return preferredClient;
|
||||
}
|
||||
|
||||
public static void Log(string line)
|
||||
{
|
||||
if (GameMain.Server == null || GameMain.Server.saveServerLogs) return;
|
||||
|
||||
GameMain.Server.log.WriteLine(line);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// sends some random data to the clients
|
||||
/// use for debugging purposes
|
||||
@@ -1432,6 +1475,13 @@ namespace Barotrauma.Networking
|
||||
public override void Disconnect()
|
||||
{
|
||||
banList.Save();
|
||||
|
||||
if (saveServerLogs)
|
||||
{
|
||||
Log("Shutting down server...");
|
||||
log.Save();
|
||||
}
|
||||
|
||||
server.Shutdown("The server has shut down");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,6 +43,8 @@ namespace Barotrauma.Networking
|
||||
|
||||
private bool endRoundAtLevelEnd = true;
|
||||
|
||||
private bool saveServerLogs = true;
|
||||
|
||||
public bool AutoRestart
|
||||
{
|
||||
get { return (ConnectedClients.Count == 0) ? false : autoRestart; }
|
||||
@@ -97,7 +99,11 @@ namespace Barotrauma.Networking
|
||||
|
||||
var randomizeLevelBox = new GUITickBox(new Rectangle(0, 30, 20, 20), "Randomize level seed between rounds", Alignment.Left, innerFrame);
|
||||
randomizeLevelBox.Selected = randomizeSeed;
|
||||
randomizeLevelBox.OnSelected = ToggleRandomizeSeed;
|
||||
randomizeLevelBox.OnSelected = (GUITickBox) =>
|
||||
{
|
||||
randomizeSeed = GUITickBox.Selected;
|
||||
return true;
|
||||
};
|
||||
|
||||
var endBox = new GUITickBox(new Rectangle(0, 60, 20, 20), "End round when destination reached", Alignment.Left, innerFrame);
|
||||
endBox.Selected = endRoundAtLevelEnd;
|
||||
@@ -116,6 +122,7 @@ namespace Barotrauma.Networking
|
||||
|
||||
var votesRequiredSlider = new GUIScrollBar(new Rectangle(150,115, 100, 10), GUI.Style, 0.1f, innerFrame);
|
||||
votesRequiredSlider.UserData = votesRequiredText;
|
||||
votesRequiredSlider.BarScroll = (EndVoteRequiredRatio - 0.5f) * 2.0f;
|
||||
votesRequiredSlider.OnMoved = (GUIScrollBar scrollBar, float barScroll) =>
|
||||
{
|
||||
GUITextBlock voteText = scrollBar.UserData as GUITextBlock;
|
||||
@@ -125,7 +132,8 @@ namespace Barotrauma.Networking
|
||||
voteText.Text = "Votes required: " + (int)MathUtils.Round(EndVoteRequiredRatio * 100.0f, 10.0f) + " %";
|
||||
return true;
|
||||
};
|
||||
|
||||
votesRequiredSlider.OnMoved(votesRequiredSlider, votesRequiredSlider.BarScroll);
|
||||
|
||||
new GUITextBlock(new Rectangle(0, 95+50, 100, 20), "Submarine selection:", GUI.Style, innerFrame);
|
||||
var selectionFrame = new GUIFrame(new Rectangle(0, 120 + 50, 300, 20), null, innerFrame);
|
||||
for (int i = 0; i<3; i++)
|
||||
@@ -147,8 +155,20 @@ namespace Barotrauma.Networking
|
||||
}
|
||||
|
||||
var allowSpecBox = new GUITickBox(new Rectangle(0, 210 + 50, 20, 20), "Allow spectating", Alignment.Left, innerFrame);
|
||||
allowSpecBox.Selected = true;
|
||||
allowSpecBox.OnSelected = ToggleAllowSpectating;
|
||||
allowSpecBox.Selected = allowSpectating;
|
||||
allowSpecBox.OnSelected = (GUITickBox) =>
|
||||
{
|
||||
allowSpectating = GUITickBox.Selected;
|
||||
return true;
|
||||
};
|
||||
|
||||
var saveLogsBox = new GUITickBox(new Rectangle(0, 240 + 50, 20, 20), "Save server logs", Alignment.Left, innerFrame);
|
||||
saveLogsBox.Selected = saveServerLogs;
|
||||
saveLogsBox.OnSelected = (GUITickBox) =>
|
||||
{
|
||||
saveServerLogs = GUITickBox.Selected;
|
||||
return true;
|
||||
}; ;
|
||||
|
||||
var closeButton = new GUIButton(new Rectangle(0, 0, 100, 20), "Close", Alignment.BottomRight, GUI.Style, innerFrame);
|
||||
closeButton.OnClicked = ToggleSettingsFrame;
|
||||
@@ -194,17 +214,6 @@ namespace Barotrauma.Networking
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool ToggleRandomizeSeed(GUITickBox tickBox)
|
||||
{
|
||||
randomizeSeed = tickBox.Selected;
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool ToggleAllowSpectating(GUITickBox tickBox)
|
||||
{
|
||||
allowSpectating = tickBox.Selected;
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool ToggleSettingsFrame(GUIButton button, object obj)
|
||||
{
|
||||
|
||||
@@ -186,6 +186,8 @@ namespace Barotrauma.Networking
|
||||
{
|
||||
GameMain.NetLobbyScreen.NewChatMessage(message, messageColor[(int)messageType]);
|
||||
|
||||
GameServer.Log(message);
|
||||
|
||||
while (chatBox.CountChildren > 20)
|
||||
{
|
||||
chatBox.RemoveChild(chatBox.children[1]);
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Barotrauma.Networking
|
||||
{
|
||||
class ServerLog
|
||||
{
|
||||
const int LinesPerFile = 500;
|
||||
|
||||
const string SavePath = "ServerLogs";
|
||||
|
||||
private string serverName;
|
||||
|
||||
private Queue<string> lines;
|
||||
|
||||
public ServerLog(string serverName)
|
||||
{
|
||||
this.serverName = serverName;
|
||||
|
||||
lines = new Queue<string>();
|
||||
}
|
||||
|
||||
public void WriteLine(string line)
|
||||
{
|
||||
string logLine = "[" + DateTime.Now.ToLongTimeString() + "] " + line;
|
||||
|
||||
lines.Enqueue(logLine);
|
||||
|
||||
if (lines.Count>=LinesPerFile)
|
||||
{
|
||||
Save();
|
||||
}
|
||||
}
|
||||
|
||||
public void Save()
|
||||
{
|
||||
if (!Directory.Exists(SavePath))
|
||||
{
|
||||
try
|
||||
{
|
||||
Directory.CreateDirectory(SavePath);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
DebugConsole.ThrowError("Failed to create a folder for server logs", e);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
string fileName = serverName+"_"+DateTime.Now.ToShortDateString()+"_"+DateTime.Now.ToShortTimeString()+".txt";
|
||||
|
||||
fileName = fileName.Replace(":", "");
|
||||
|
||||
string filePath = Path.Combine(SavePath, fileName);
|
||||
|
||||
try
|
||||
{
|
||||
File.WriteAllLines(filePath, lines);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
DebugConsole.ThrowError("Saving the server log to " + filePath + " failed", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user