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

View File

@@ -47,6 +47,8 @@ namespace Barotrauma
private void InitProjSpecific(XDocument doc)
{
keys = new Key[Enum.GetNames(typeof(InputType)).Length];
for (int i = 0; i < Enum.GetNames(typeof(InputType)).Length; i++)
{
keys[i] = new Key(GameMain.Config.KeyBind((InputType)i));

View File

@@ -186,6 +186,8 @@ namespace Barotrauma
}
public static Character ReadSpawnData(NetBuffer inc, bool spawn = true)
{
DebugConsole.NewMessage("READING CHARACTER SPAWN DATA", Color.Cyan);
if (GameMain.Server != null) return null;
bool noInfo = inc.ReadBoolean();

View File

@@ -146,6 +146,7 @@ namespace Barotrauma
case "help":
case "dumpids":
case "admin":
case "entitylist":
return true;
default:
return false;

View File

@@ -190,7 +190,7 @@ namespace Barotrauma.Networking
{
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;
}

View File

@@ -11,6 +11,22 @@ namespace Barotrauma.Networking
{
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 GUIListBox chatBox;
protected GUITextBox chatMsgBox;

View File

@@ -164,7 +164,7 @@ namespace Barotrauma
sw.WriteLine(sb.ToString());
sw.Close();
sw.Close();
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.");

View File

@@ -26,7 +26,7 @@ namespace Barotrauma
private void InitProjSpecific(XDocument doc)
{
//do nothing
keys = null;
}
private void UpdateControlled(float deltaTime)

View File

@@ -43,6 +43,20 @@ namespace Barotrauma
if (Screen.Selected == GameMain.NetLobbyScreen) break;
GameMain.Server.EndGame();
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:
return false;
break;

View File

@@ -103,7 +103,7 @@ namespace Barotrauma
while (true)
{
DebugConsole.Update();
NetLobbyScreen.Update((float)Timing.Step);
if (Screen.Selected != null) Screen.Selected.Update((float)Timing.Step);
Server.Update((float)Timing.Step);
CoroutineManager.Update((float)Timing.Step, (float)Timing.Step);

View File

@@ -11,6 +11,20 @@ namespace Barotrauma.Networking
{
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()
{
//do nothing

View File

@@ -29,17 +29,19 @@ namespace Barotrauma
static void Main()
{
GameMain game = null;
Thread inputThread = null;
try
{
game = new GameMain();
Thread inputThread = new Thread(new ThreadStart(game.ProcessInput));
inputThread = new Thread(new ThreadStart(game.ProcessInput));
inputThread.Start();
game.Run();
}
catch (Exception 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);
}
Console.ForegroundColor = ConsoleColor.Red;
Console.Write(sb.ToString());
sw.WriteLine(sb.ToString());
sw.Close();

View File

@@ -53,7 +53,7 @@ namespace Barotrauma
}
private List<Submarine> subs = new List<Submarine>();
private List<Submarine> subs;
public List<Submarine> GetSubList()
{
return subs;

View File

@@ -27,6 +27,7 @@ namespace Barotrauma
dictionary.Add(Color.Cyan, ConsoleColor.Cyan);
dictionary.Add(Color.DarkBlue, ConsoleColor.DarkBlue);
dictionary.Add(Color.Pink, ConsoleColor.Magenta);
dictionary.Add(Color.Magenta, ConsoleColor.Magenta);
}
ConsoleColor val = ConsoleColor.White;

View File

@@ -505,8 +505,6 @@ namespace Barotrauma
protected Character(string file, Vector2 position, CharacterInfo characterInfo = null, bool isRemotePlayer = false)
: base(null)
{
keys = new Key[Enum.GetNames(typeof(InputType)).Length];
ConfigPath = file;
selectedItems = new Item[2];
@@ -899,8 +897,8 @@ namespace Barotrauma
}
}
if (IsRemotePlayer)
if (IsRemotePlayer && keys!=null)
{
foreach (Key key in keys)
{
@@ -1726,9 +1724,9 @@ namespace Barotrauma
{
GameMain.GameSession.CrewManager.characters.Remove(this);
}
#endif
if (GameMain.Client != null && GameMain.Client.Character == this) GameMain.Client.Character = null;
#endif
if (aiTarget != null) aiTarget.Remove();

View File

@@ -401,7 +401,7 @@ namespace Barotrauma
attack = dequeuedInput.HasFlag(InputNetFlags.Attack);
}
else
else if (keys != null)
{
aiming = keys[(int)InputType.Aim].GetHeldQueue;
use = keys[(int)InputType.Use].GetHeldQueue;

View File

@@ -29,7 +29,7 @@ namespace Barotrauma
static partial class DebugConsole
{
const int MaxMessages = 200;
const int MaxMessages = 20000;
public static List<ColoredText> Messages = new List<ColoredText>();
@@ -55,6 +55,17 @@ namespace Barotrauma
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":
NewMessage("menu: go to main menu", Color.Cyan);
NewMessage("game: enter the \"game screen\"", Color.Cyan);
@@ -501,6 +512,7 @@ namespace Barotrauma
//TODO: REMOVE
Console.ForegroundColor = XnaToConsoleColor.Convert(color);
Console.WriteLine(msg);
Console.ForegroundColor = ConsoleColor.White;
#endif
if (Messages.Count > MaxMessages)

View File

@@ -293,11 +293,11 @@ namespace Barotrauma
public override string ToString()
{
#if CLIENT
/*#if CLIENT
return (GameMain.DebugDraw) ? Name + "(ID: " + ID + ")" : Name;
#elif SERVER
#elif SERVER*/
return Name + "(ID: " + ID + ")";
#endif
//#endif
}
public List<IPropertyObject> AllPropertyObjects
@@ -1304,6 +1304,7 @@ namespace Barotrauma
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))
{
return;

View File

@@ -10,6 +10,10 @@ namespace Barotrauma
class Entity
{
private static Dictionary<ushort, Entity> dictionary = new Dictionary<ushort, Entity>();
public static List<Entity> GetEntityList()
{
return dictionary.Values.ToList();
}
public static EntitySpawner Spawner;

View File

@@ -183,9 +183,10 @@ namespace Barotrauma
else if (entities.Entity is Character)
{
message.Write((byte)SpawnableType.Character);
DebugConsole.NewMessage("WRITING CHARACTER DATA: " + (entities.Entity).ToString(),Color.Cyan);
((Character)entities.Entity).WriteSpawnData(message);
}
}
}
}
}
}

View File

@@ -1185,6 +1185,7 @@ namespace Barotrauma.Networking
#endif
}
#if CLIENT
if (characterInfo != null && hostTeam == teamID)
{
myCharacter = Character.Create(characterInfo, assignedWayPoints[assignedWayPoints.Length - 1].WorldPosition, false, false);
@@ -1192,10 +1193,10 @@ namespace Barotrauma.Networking
myCharacter.TeamID = (byte)teamID;
Character.Controlled = myCharacter;
#if CLIENT
GameMain.GameSession.CrewManager.characters.Add(myCharacter);
#endif
}
#endif
}
@@ -1247,7 +1248,7 @@ namespace Barotrauma.Networking
GameMain.GameScreen.Cam.TargetPos = Vector2.Zero;
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;
@@ -1336,12 +1337,13 @@ namespace Barotrauma.Networking
if (SaveServerLogs) log.Save();
Character.Controlled = null;
myCharacter = null;
GameMain.GameScreen.Cam.TargetPos = Vector2.Zero;
#if CLIENT
myCharacter = null;
GameMain.LightManager.LosEnabled = false;
#endif
entityEventManager.Clear();
foreach (Client c in connectedClients)
{

View File

@@ -64,6 +64,8 @@ namespace Barotrauma.Networking
public bool Sent;
public string StackTrace;
private double createTime;
public double CreateTime
{
@@ -76,6 +78,8 @@ namespace Barotrauma.Networking
serializable = entity;
createTime = Timing.TotalTime;
StackTrace = Environment.StackTrace.ToString();
}
public void Write(NetBuffer msg, Client recipient)

View File

@@ -137,7 +137,7 @@ namespace Barotrauma.Networking
{
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.FirstNewEventID);
//DebugConsole.NewMessage(eventsToSync[0].ID.ToString(), Microsoft.Xna.Framework.Color.Yellow);
Write(msg, eventsToSync, client);
}
else

View File

@@ -90,27 +90,12 @@ namespace Barotrauma.Networking
protected bool gameStarted;
protected Character myCharacter;
protected CharacterInfo characterInfo;
public Dictionary<string, bool> monsterEnabled;
protected RespawnManager respawnManager;
public Voting Voting;
public Character Character
{
get { return myCharacter; }
set { myCharacter = value; }
}
public CharacterInfo CharacterInfo
{
get { return characterInfo; }
set { characterInfo = value; }
}
public string Name
{
get { return name; }

View File

@@ -437,20 +437,24 @@ namespace Barotrauma.Networking
var character = Character.Create(characterInfos[i], shuttleSpawnPoints[i].WorldPosition, !myCharacter, false);
character.TeamID = 1;
#if CLIENT
if (myCharacter)
{
server.Character = character;
Character.Controlled = character;
#if CLIENT
GameMain.LightManager.LosEnabled = true;
#endif
}
else
{
#endif
clients[i].Character = character;
#if CLIENT
}
#endif
Vector2 pos = cargoSp == null ? character.Position : cargoSp.Position;
if (divingSuitPrefab != null && oxyPrefab != null)

View File

@@ -26,7 +26,7 @@ namespace Barotrauma
private static void Assert(RandSync sync)
{
//TODO: REMOVE AFTER FINDING ALL WRONG RNG USAGE
#if CLIENT
#if false
string trace = Environment.StackTrace.ToString();
if (sync != RandSync.Server) return;
if (trace.ToLower().Contains("barotraumaclient\\source")) DebugConsole.NewMessage("WARNING: Client code using RandSync.Server\n"+trace,Color.Yellow);