From fbe7dfc6fbff50b7541167392adbe5c90548a920 Mon Sep 17 00:00:00 2001 From: juanjp600 Date: Mon, 19 Jun 2017 15:12:19 -0300 Subject: [PATCH] Dedicated server actually works to some extent Clients can connect and use chat, the sub list isn't synced properly and there's no way to start a game yet --- BarotraumaClient/Source/GameMain.cs | 2 +- .../Source/Networking/GameServer.cs | 9 ---- BarotraumaServer/Source/GameMain.cs | 42 ++++++++++++++++++- BarotraumaServer/Source/Program.cs | 4 ++ .../Source/Screens/NetLobbyScreen.cs | 12 ++++++ BarotraumaShared/BarotraumaShared.projitems | 3 ++ BarotraumaShared/Source/DebugConsole.cs | 4 ++ .../Source/Networking/GameServer.cs | 12 +++++- .../Source/Networking/ServerLog.cs | 4 ++ BarotraumaShared/serverconfig.xml | 4 ++ 10 files changed, 84 insertions(+), 12 deletions(-) create mode 100644 BarotraumaShared/serverconfig.xml diff --git a/BarotraumaClient/Source/GameMain.cs b/BarotraumaClient/Source/GameMain.cs index 7ad903abe..bc4e78848 100644 --- a/BarotraumaClient/Source/GameMain.cs +++ b/BarotraumaClient/Source/GameMain.cs @@ -360,7 +360,7 @@ namespace Barotrauma } GUI.Update((float)Timing.Step); - } + } CoroutineManager.Update((float)Timing.Step, paused ? 0.0f : (float)Timing.Step); diff --git a/BarotraumaClient/Source/Networking/GameServer.cs b/BarotraumaClient/Source/Networking/GameServer.cs index e804fc660..025401c59 100644 --- a/BarotraumaClient/Source/Networking/GameServer.cs +++ b/BarotraumaClient/Source/Networking/GameServer.cs @@ -25,7 +25,6 @@ namespace Barotrauma.Networking var endRoundButton = new GUIButton(new Rectangle(GameMain.GraphicsWidth - 170, 20, 150, 20), "End round", Alignment.TopLeft, "", inGameHUD); endRoundButton.OnClicked = (btn, userdata) => { EndGame(); return true; }; - log = new ServerLog(name); showLogButton = new GUIButton(new Rectangle(GameMain.GraphicsWidth - 170 - 170, 20, 150, 20), "Server Log", Alignment.TopLeft, "", inGameHUD); showLogButton.OnClicked = (GUIButton button, object userData) => { @@ -45,14 +44,6 @@ namespace Barotrauma.Networking settingsButton.OnClicked = ToggleSettingsFrame; settingsButton.UserData = "settingsButton"; - entityEventManager = new ServerEntityEventManager(this); - - whitelist = new WhiteList(); - banList = new BanList(); - - LoadSettings(); - LoadClientPermissions(); - //---------------------------------------- } diff --git a/BarotraumaServer/Source/GameMain.cs b/BarotraumaServer/Source/GameMain.cs index 3f9c5fc6f..527f5dcf9 100644 --- a/BarotraumaServer/Source/GameMain.cs +++ b/BarotraumaServer/Source/GameMain.cs @@ -6,6 +6,7 @@ using FarseerPhysics.Dynamics; using Barotrauma.Networking; using System.Collections.Generic; using Microsoft.Xna.Framework; +using System.Threading; namespace Barotrauma { @@ -68,7 +69,46 @@ namespace Barotrauma public void Run() { - //TODO: implement + Hyper.ComponentModel.HyperTypeDescriptionProvider.Add(typeof(Character)); + Hyper.ComponentModel.HyperTypeDescriptionProvider.Add(typeof(Item)); + Hyper.ComponentModel.HyperTypeDescriptionProvider.Add(typeof(Items.Components.ItemComponent)); + Hyper.ComponentModel.HyperTypeDescriptionProvider.Add(typeof(Hull)); + + Mission.Init(); + MapEntityPrefab.Init(); + LevelGenerationParams.LoadPresets(); + + JobPrefab.LoadAll(SelectedPackage.GetFilesOfType(ContentType.Jobs)); + StructurePrefab.LoadAll(SelectedPackage.GetFilesOfType(ContentType.Structure)); + + ItemPrefab.LoadAll(SelectedPackage.GetFilesOfType(ContentType.Item)); + + GameModePreset.Init(); + + LocationType.Init(); + + Submarine.RefreshSavedSubs(); + + NetLobbyScreen = new NetLobbyScreen(); + + Server = new GameServer("Dedicated Server Test", 14242, true, "asd", false, 10); + while (true) + { + NetLobbyScreen.Update((float)Timing.Step); + Server.Update((float)Timing.Step); + CoroutineManager.Update((float)Timing.Step, (float)Timing.Step); + + Thread.Sleep((int)(Timing.Step * 1000.0)); + } + } + + public void ProcessInput() + { + while (true) + { + string input = Console.ReadLine(); + DebugConsole.ExecuteCommand(input, this); + } } public CoroutineHandle ShowLoading(IEnumerable loader, bool waitKeyHit = true) diff --git a/BarotraumaServer/Source/Program.cs b/BarotraumaServer/Source/Program.cs index bf0553c9a..47007b4ee 100644 --- a/BarotraumaServer/Source/Program.cs +++ b/BarotraumaServer/Source/Program.cs @@ -4,6 +4,7 @@ using System; using System.IO; using System.Reflection; using System.Text; +using System.Threading; #if WINDOWS using System.Management; @@ -31,6 +32,9 @@ namespace Barotrauma try { game = new GameMain(); + + Thread inputThread = new Thread(new ThreadStart(game.ProcessInput)); + inputThread.Start(); game.Run(); } catch (Exception e) diff --git a/BarotraumaServer/Source/Screens/NetLobbyScreen.cs b/BarotraumaServer/Source/Screens/NetLobbyScreen.cs index fa241bb6a..3c4cc0409 100644 --- a/BarotraumaServer/Source/Screens/NetLobbyScreen.cs +++ b/BarotraumaServer/Source/Screens/NetLobbyScreen.cs @@ -33,6 +33,18 @@ namespace Barotrauma } } + + public override void Select() + { + List subsToShow = Submarine.SavedSubmarines.Where(s => !s.HasTag(SubmarineTag.HideInMenus)).ToList(); + + SelectedSub = subsToShow[0]; + SelectedShuttle = subsToShow[0]; //TODO: don't use the same sub as a shuttle by default + + DebugConsole.NewMessage("Selected sub: " + SelectedSub.Name, Color.White); + DebugConsole.NewMessage("Selected shuttle: " + SelectedShuttle.Name, Color.White); + } + private List subs = new List(); public List GetSubList() { diff --git a/BarotraumaShared/BarotraumaShared.projitems b/BarotraumaShared/BarotraumaShared.projitems index 14e2d5a1b..c9c00d860 100644 --- a/BarotraumaShared/BarotraumaShared.projitems +++ b/BarotraumaShared/BarotraumaShared.projitems @@ -710,6 +710,9 @@ PreserveNewest + + PreserveNewest + diff --git a/BarotraumaShared/Source/DebugConsole.cs b/BarotraumaShared/Source/DebugConsole.cs index b4918a132..1ef8632ae 100644 --- a/BarotraumaShared/Source/DebugConsole.cs +++ b/BarotraumaShared/Source/DebugConsole.cs @@ -497,6 +497,10 @@ namespace Barotrauma if (String.IsNullOrEmpty((msg))) return; Messages.Add(new ColoredText(msg, color)); +#if SERVER + //TODO: REMOVE + Console.WriteLine(msg); +#endif if (Messages.Count > MaxMessages) { diff --git a/BarotraumaShared/Source/Networking/GameServer.cs b/BarotraumaShared/Source/Networking/GameServer.cs index 114d62daa..e2eb901dd 100644 --- a/BarotraumaShared/Source/Networking/GameServer.cs +++ b/BarotraumaShared/Source/Networking/GameServer.cs @@ -119,7 +119,17 @@ namespace Barotrauma.Networking config.EnableMessageType(NetIncomingMessageType.ConnectionApproval); + log = new ServerLog(name); + InitProjSpecific(); + + entityEventManager = new ServerEntityEventManager(this); + + whitelist = new WhiteList(); + banList = new BanList(); + + LoadSettings(); + LoadClientPermissions(); CoroutineManager.StartCoroutine(StartServer(isPublic)); } @@ -341,7 +351,7 @@ namespace Barotrauma.Networking #endif if (!started) return; - + base.Update(deltaTime); foreach (UnauthenticatedClient unauthClient in unauthenticatedClients) diff --git a/BarotraumaShared/Source/Networking/ServerLog.cs b/BarotraumaShared/Source/Networking/ServerLog.cs index d5113ace3..d7047060f 100644 --- a/BarotraumaShared/Source/Networking/ServerLog.cs +++ b/BarotraumaShared/Source/Networking/ServerLog.cs @@ -80,6 +80,10 @@ namespace Barotrauma.Networking { //string logLine = "[" + DateTime.Now.ToLongTimeString() + "] " + line; +#if SERVER + DebugConsole.NewMessage(line, Color.White); //TODO: REMOVE +#endif + var newText = new LogMessage(line, messageType); lines.Enqueue(newText); diff --git a/BarotraumaShared/serverconfig.xml b/BarotraumaShared/serverconfig.xml new file mode 100644 index 000000000..bcfac70f2 --- /dev/null +++ b/BarotraumaShared/serverconfig.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file