Ingame syncing kinda works

Reminder to self: Submarines must spawn attached shuttles in Dedicated Server, must've been something I missed when moving over client-specific code
This commit is contained in:
juanjp600
2017-06-20 22:28:18 -03:00
parent 7003214847
commit 0740579f62
25 changed files with 109 additions and 43 deletions
@@ -47,6 +47,8 @@ namespace Barotrauma
private void InitProjSpecific(XDocument doc) private void InitProjSpecific(XDocument doc)
{ {
keys = new Key[Enum.GetNames(typeof(InputType)).Length];
for (int i = 0; i < Enum.GetNames(typeof(InputType)).Length; i++) for (int i = 0; i < Enum.GetNames(typeof(InputType)).Length; i++)
{ {
keys[i] = new Key(GameMain.Config.KeyBind((InputType)i)); keys[i] = new Key(GameMain.Config.KeyBind((InputType)i));
@@ -186,6 +186,8 @@ namespace Barotrauma
} }
public static Character ReadSpawnData(NetBuffer inc, bool spawn = true) public static Character ReadSpawnData(NetBuffer inc, bool spawn = true)
{ {
DebugConsole.NewMessage("READING CHARACTER SPAWN DATA", Color.Cyan);
if (GameMain.Server != null) return null; if (GameMain.Server != null) return null;
bool noInfo = inc.ReadBoolean(); bool noInfo = inc.ReadBoolean();
+1
View File
@@ -146,6 +146,7 @@ namespace Barotrauma
case "help": case "help":
case "dumpids": case "dumpids":
case "admin": case "admin":
case "entitylist":
return true; return true;
default: default:
return false; return false;
@@ -190,7 +190,7 @@ namespace Barotrauma.Networking
{ {
if (GameSettings.VerboseLogging) if (GameSettings.VerboseLogging)
{ {
DebugConsole.ThrowError("Failed to read event for entity \"" + entity.ToString() + "!", e); DebugConsole.ThrowError("Failed to read event for entity \"" + entity.ToString() + "\"!", e);
} }
msg.Position = msgPosition + msgLength * 8; msg.Position = msgPosition + msgLength * 8;
} }
@@ -11,6 +11,22 @@ namespace Barotrauma.Networking
{ {
abstract partial class NetworkMember abstract partial class NetworkMember
{ {
protected CharacterInfo characterInfo;
protected Character myCharacter;
public CharacterInfo CharacterInfo
{
get { return characterInfo; }
set { characterInfo = value; }
}
public Character Character
{
get { return myCharacter; }
set { myCharacter = value; }
}
protected GUIFrame inGameHUD; protected GUIFrame inGameHUD;
protected GUIListBox chatBox; protected GUIListBox chatBox;
protected GUITextBox chatMsgBox; protected GUITextBox chatMsgBox;
+1 -1
View File
@@ -164,7 +164,7 @@ namespace Barotrauma
sw.WriteLine(sb.ToString()); sw.WriteLine(sb.ToString());
sw.Close(); sw.Close();
CrashMessageBox( "A crash report (\"crashreport.txt\") was saved in the root folder of the game."+ CrashMessageBox( "A crash report (\"crashreport.txt\") was saved in the root folder of the game."+
" If you'd like to help fix this bug, please post the report on the Undertow Games forums."); " If you'd like to help fix this bug, please post the report on the Undertow Games forums.");
@@ -26,7 +26,7 @@ namespace Barotrauma
private void InitProjSpecific(XDocument doc) private void InitProjSpecific(XDocument doc)
{ {
//do nothing keys = null;
} }
private void UpdateControlled(float deltaTime) private void UpdateControlled(float deltaTime)
+14
View File
@@ -43,6 +43,20 @@ namespace Barotrauma
if (Screen.Selected == GameMain.NetLobbyScreen) break; if (Screen.Selected == GameMain.NetLobbyScreen) break;
GameMain.Server.EndGame(); GameMain.Server.EndGame();
break; break;
case "entitydata":
Entity ent = Entity.FindEntityByID(Convert.ToUInt16(commands[1]));
if (ent != null)
{
NewMessage(ent.ToString(), Color.Lime);
}
break;
case "eventdata":
ServerEntityEvent ev = GameMain.Server.EntityEventManager.Events[Convert.ToUInt16(commands[1])];
if (ev != null)
{
NewMessage(ev.StackTrace, Color.Lime);
}
break;
default: default:
return false; return false;
break; break;
+1 -1
View File
@@ -103,7 +103,7 @@ namespace Barotrauma
while (true) while (true)
{ {
DebugConsole.Update(); DebugConsole.Update();
NetLobbyScreen.Update((float)Timing.Step); if (Screen.Selected != null) Screen.Selected.Update((float)Timing.Step);
Server.Update((float)Timing.Step); Server.Update((float)Timing.Step);
CoroutineManager.Update((float)Timing.Step, (float)Timing.Step); CoroutineManager.Update((float)Timing.Step, (float)Timing.Step);
@@ -11,6 +11,20 @@ namespace Barotrauma.Networking
{ {
abstract partial class NetworkMember abstract partial class NetworkMember
{ {
protected const CharacterInfo characterInfo = null;
protected const Character myCharacter = null;
public CharacterInfo CharacterInfo
{
get { return null; }
}
public Character Character
{
get { return null; }
}
private void InitProjSpecific() private void InitProjSpecific()
{ {
//do nothing //do nothing
+5 -1
View File
@@ -29,17 +29,19 @@ namespace Barotrauma
static void Main() static void Main()
{ {
GameMain game = null; GameMain game = null;
Thread inputThread = null;
try try
{ {
game = new GameMain(); game = new GameMain();
Thread inputThread = new Thread(new ThreadStart(game.ProcessInput)); inputThread = new Thread(new ThreadStart(game.ProcessInput));
inputThread.Start(); inputThread.Start();
game.Run(); game.Run();
} }
catch (Exception e) catch (Exception e)
{ {
CrashDump(game, "servercrashreport.txt", e); CrashDump(game, "servercrashreport.txt", e);
//inputThread.Abort(); inputThread.Join();
} }
} }
@@ -84,6 +86,8 @@ namespace Barotrauma
sb.AppendLine(" "+DebugConsole.Messages[i].Time+" - "+DebugConsole.Messages[i].Text); sb.AppendLine(" "+DebugConsole.Messages[i].Time+" - "+DebugConsole.Messages[i].Text);
} }
Console.ForegroundColor = ConsoleColor.Red;
Console.Write(sb.ToString());
sw.WriteLine(sb.ToString()); sw.WriteLine(sb.ToString());
sw.Close(); sw.Close();
@@ -53,7 +53,7 @@ namespace Barotrauma
} }
private List<Submarine> subs = new List<Submarine>(); private List<Submarine> subs;
public List<Submarine> GetSubList() public List<Submarine> GetSubList()
{ {
return subs; return subs;
@@ -27,6 +27,7 @@ namespace Barotrauma
dictionary.Add(Color.Cyan, ConsoleColor.Cyan); dictionary.Add(Color.Cyan, ConsoleColor.Cyan);
dictionary.Add(Color.DarkBlue, ConsoleColor.DarkBlue); dictionary.Add(Color.DarkBlue, ConsoleColor.DarkBlue);
dictionary.Add(Color.Pink, ConsoleColor.Magenta); dictionary.Add(Color.Pink, ConsoleColor.Magenta);
dictionary.Add(Color.Magenta, ConsoleColor.Magenta);
} }
ConsoleColor val = ConsoleColor.White; ConsoleColor val = ConsoleColor.White;
@@ -505,8 +505,6 @@ namespace Barotrauma
protected Character(string file, Vector2 position, CharacterInfo characterInfo = null, bool isRemotePlayer = false) protected Character(string file, Vector2 position, CharacterInfo characterInfo = null, bool isRemotePlayer = false)
: base(null) : base(null)
{ {
keys = new Key[Enum.GetNames(typeof(InputType)).Length];
ConfigPath = file; ConfigPath = file;
selectedItems = new Item[2]; selectedItems = new Item[2];
@@ -899,8 +897,8 @@ namespace Barotrauma
} }
} }
if (IsRemotePlayer) if (IsRemotePlayer && keys!=null)
{ {
foreach (Key key in keys) foreach (Key key in keys)
{ {
@@ -1726,9 +1724,9 @@ namespace Barotrauma
{ {
GameMain.GameSession.CrewManager.characters.Remove(this); GameMain.GameSession.CrewManager.characters.Remove(this);
} }
#endif
if (GameMain.Client != null && GameMain.Client.Character == this) GameMain.Client.Character = null; if (GameMain.Client != null && GameMain.Client.Character == this) GameMain.Client.Character = null;
#endif
if (aiTarget != null) aiTarget.Remove(); if (aiTarget != null) aiTarget.Remove();
@@ -401,7 +401,7 @@ namespace Barotrauma
attack = dequeuedInput.HasFlag(InputNetFlags.Attack); attack = dequeuedInput.HasFlag(InputNetFlags.Attack);
} }
else else if (keys != null)
{ {
aiming = keys[(int)InputType.Aim].GetHeldQueue; aiming = keys[(int)InputType.Aim].GetHeldQueue;
use = keys[(int)InputType.Use].GetHeldQueue; use = keys[(int)InputType.Use].GetHeldQueue;
+13 -1
View File
@@ -29,7 +29,7 @@ namespace Barotrauma
static partial class DebugConsole static partial class DebugConsole
{ {
const int MaxMessages = 200; const int MaxMessages = 20000;
public static List<ColoredText> Messages = new List<ColoredText>(); public static List<ColoredText> Messages = new List<ColoredText>();
@@ -55,6 +55,17 @@ namespace Barotrauma
switch (commands[0].ToLowerInvariant()) switch (commands[0].ToLowerInvariant())
{ {
case "entitylist":
System.IO.StreamWriter sw = new System.IO.StreamWriter("ENTLIST "+Rand.Int(20000).ToString()+".TXT");
List<Entity> entList = Entity.GetEntityList();
foreach (Entity ent in entList)
{
sw.WriteLine(ent.ID.ToString()+" "+ent.ToString());
}
sw.Close();
break;
case "help": case "help":
NewMessage("menu: go to main menu", Color.Cyan); NewMessage("menu: go to main menu", Color.Cyan);
NewMessage("game: enter the \"game screen\"", Color.Cyan); NewMessage("game: enter the \"game screen\"", Color.Cyan);
@@ -501,6 +512,7 @@ namespace Barotrauma
//TODO: REMOVE //TODO: REMOVE
Console.ForegroundColor = XnaToConsoleColor.Convert(color); Console.ForegroundColor = XnaToConsoleColor.Convert(color);
Console.WriteLine(msg); Console.WriteLine(msg);
Console.ForegroundColor = ConsoleColor.White;
#endif #endif
if (Messages.Count > MaxMessages) if (Messages.Count > MaxMessages)
+4 -3
View File
@@ -293,11 +293,11 @@ namespace Barotrauma
public override string ToString() public override string ToString()
{ {
#if CLIENT /*#if CLIENT
return (GameMain.DebugDraw) ? Name + "(ID: " + ID + ")" : Name; return (GameMain.DebugDraw) ? Name + "(ID: " + ID + ")" : Name;
#elif SERVER #elif SERVER*/
return Name + "(ID: " + ID + ")"; return Name + "(ID: " + ID + ")";
#endif //#endif
} }
public List<IPropertyObject> AllPropertyObjects public List<IPropertyObject> AllPropertyObjects
@@ -1304,6 +1304,7 @@ namespace Barotrauma
public void ServerWrite(NetBuffer msg, Client c, object[] extraData = null) public void ServerWrite(NetBuffer msg, Client c, object[] extraData = null)
{ {
DebugConsole.NewMessage(ToString(), Color.Magenta);
if (extraData == null || extraData.Length == 0 || !(extraData[0] is NetEntityEvent.Type)) if (extraData == null || extraData.Length == 0 || !(extraData[0] is NetEntityEvent.Type))
{ {
return; return;
+4
View File
@@ -10,6 +10,10 @@ namespace Barotrauma
class Entity class Entity
{ {
private static Dictionary<ushort, Entity> dictionary = new Dictionary<ushort, Entity>(); private static Dictionary<ushort, Entity> dictionary = new Dictionary<ushort, Entity>();
public static List<Entity> GetEntityList()
{
return dictionary.Values.ToList();
}
public static EntitySpawner Spawner; public static EntitySpawner Spawner;
@@ -183,9 +183,10 @@ namespace Barotrauma
else if (entities.Entity is Character) else if (entities.Entity is Character)
{ {
message.Write((byte)SpawnableType.Character); message.Write((byte)SpawnableType.Character);
DebugConsole.NewMessage("WRITING CHARACTER DATA: " + (entities.Entity).ToString(),Color.Cyan);
((Character)entities.Entity).WriteSpawnData(message); ((Character)entities.Entity).WriteSpawnData(message);
} }
} }
} }
} }
} }
@@ -1185,6 +1185,7 @@ namespace Barotrauma.Networking
#endif #endif
} }
#if CLIENT
if (characterInfo != null && hostTeam == teamID) if (characterInfo != null && hostTeam == teamID)
{ {
myCharacter = Character.Create(characterInfo, assignedWayPoints[assignedWayPoints.Length - 1].WorldPosition, false, false); myCharacter = Character.Create(characterInfo, assignedWayPoints[assignedWayPoints.Length - 1].WorldPosition, false, false);
@@ -1192,10 +1193,10 @@ namespace Barotrauma.Networking
myCharacter.TeamID = (byte)teamID; myCharacter.TeamID = (byte)teamID;
Character.Controlled = myCharacter; Character.Controlled = myCharacter;
#if CLIENT
GameMain.GameSession.CrewManager.characters.Add(myCharacter); GameMain.GameSession.CrewManager.characters.Add(myCharacter);
#endif
} }
#endif
} }
@@ -1247,7 +1248,7 @@ namespace Barotrauma.Networking
GameMain.GameScreen.Cam.TargetPos = Vector2.Zero; GameMain.GameScreen.Cam.TargetPos = Vector2.Zero;
GameMain.GameScreen.Select(); GameMain.GameScreen.Select();
AddChatMessage("Press TAB to chat. Use ''r;'' to talk through the radio.", ChatMessageType.Server); AddChatMessage("Press TAB to chat. Use \"r;\" to talk through the radio.", ChatMessageType.Server);
GameMain.NetLobbyScreen.StartButtonEnabled = true; GameMain.NetLobbyScreen.StartButtonEnabled = true;
@@ -1336,12 +1337,13 @@ namespace Barotrauma.Networking
if (SaveServerLogs) log.Save(); if (SaveServerLogs) log.Save();
Character.Controlled = null; Character.Controlled = null;
myCharacter = null;
GameMain.GameScreen.Cam.TargetPos = Vector2.Zero; GameMain.GameScreen.Cam.TargetPos = Vector2.Zero;
#if CLIENT #if CLIENT
myCharacter = null;
GameMain.LightManager.LosEnabled = false; GameMain.LightManager.LosEnabled = false;
#endif #endif
entityEventManager.Clear(); entityEventManager.Clear();
foreach (Client c in connectedClients) foreach (Client c in connectedClients)
{ {
@@ -64,6 +64,8 @@ namespace Barotrauma.Networking
public bool Sent; public bool Sent;
public string StackTrace;
private double createTime; private double createTime;
public double CreateTime public double CreateTime
{ {
@@ -76,6 +78,8 @@ namespace Barotrauma.Networking
serializable = entity; serializable = entity;
createTime = Timing.TotalTime; createTime = Timing.TotalTime;
StackTrace = Environment.StackTrace.ToString();
} }
public void Write(NetBuffer msg, Client recipient) public void Write(NetBuffer msg, Client recipient)
@@ -137,7 +137,7 @@ namespace Barotrauma.Networking
{ {
if (GameSettings.VerboseLogging) if (GameSettings.VerboseLogging)
{ {
DebugConsole.ThrowError("Failed to read event for entity \"" + bufferedEvent.TargetEntity.ToString() + "!", e); DebugConsole.ThrowError("Failed to read event for entity \"" + bufferedEvent.TargetEntity.ToString() + "\"!", e);
} }
} }
@@ -232,6 +232,7 @@ namespace Barotrauma.Networking
msg.Write(client.UnreceivedEntityEventCount); msg.Write(client.UnreceivedEntityEventCount);
msg.Write(client.FirstNewEventID); msg.Write(client.FirstNewEventID);
//DebugConsole.NewMessage(eventsToSync[0].ID.ToString(), Microsoft.Xna.Framework.Color.Yellow);
Write(msg, eventsToSync, client); Write(msg, eventsToSync, client);
} }
else else
@@ -90,27 +90,12 @@ namespace Barotrauma.Networking
protected bool gameStarted; protected bool gameStarted;
protected Character myCharacter;
protected CharacterInfo characterInfo;
public Dictionary<string, bool> monsterEnabled; public Dictionary<string, bool> monsterEnabled;
protected RespawnManager respawnManager; protected RespawnManager respawnManager;
public Voting Voting; public Voting Voting;
public Character Character
{
get { return myCharacter; }
set { myCharacter = value; }
}
public CharacterInfo CharacterInfo
{
get { return characterInfo; }
set { characterInfo = value; }
}
public string Name public string Name
{ {
get { return name; } get { return name; }
@@ -437,20 +437,24 @@ namespace Barotrauma.Networking
var character = Character.Create(characterInfos[i], shuttleSpawnPoints[i].WorldPosition, !myCharacter, false); var character = Character.Create(characterInfos[i], shuttleSpawnPoints[i].WorldPosition, !myCharacter, false);
character.TeamID = 1; character.TeamID = 1;
#if CLIENT
if (myCharacter) if (myCharacter)
{ {
server.Character = character; server.Character = character;
Character.Controlled = character; Character.Controlled = character;
#if CLIENT
GameMain.LightManager.LosEnabled = true; GameMain.LightManager.LosEnabled = true;
#endif
} }
else else
{ {
#endif
clients[i].Character = character; clients[i].Character = character;
#if CLIENT
} }
#endif
Vector2 pos = cargoSp == null ? character.Position : cargoSp.Position; Vector2 pos = cargoSp == null ? character.Position : cargoSp.Position;
if (divingSuitPrefab != null && oxyPrefab != null) if (divingSuitPrefab != null && oxyPrefab != null)
+1 -1
View File
@@ -26,7 +26,7 @@ namespace Barotrauma
private static void Assert(RandSync sync) private static void Assert(RandSync sync)
{ {
//TODO: REMOVE AFTER FINDING ALL WRONG RNG USAGE //TODO: REMOVE AFTER FINDING ALL WRONG RNG USAGE
#if CLIENT #if false
string trace = Environment.StackTrace.ToString(); string trace = Environment.StackTrace.ToString();
if (sync != RandSync.Server) return; if (sync != RandSync.Server) return;
if (trace.ToLower().Contains("barotraumaclient\\source")) DebugConsole.NewMessage("WARNING: Client code using RandSync.Server\n"+trace,Color.Yellow); if (trace.ToLower().Contains("barotraumaclient\\source")) DebugConsole.NewMessage("WARNING: Client code using RandSync.Server\n"+trace,Color.Yellow);