From 348d81a66fdefe1588a0a9a7b34b60933b2bf7e2 Mon Sep 17 00:00:00 2001 From: Joonas Rikkonen Date: Wed, 13 Sep 2017 18:37:17 +0300 Subject: [PATCH] MP campaign fixes --- .../Source/Networking/GameClient.cs | 31 +- .../Source/Screens/CampaignUI.cs | 11 +- .../Source/Events/ArtifactEvent.cs | 5 + .../Source/Events/EventManager.cs | 11 +- .../Source/Events/MonsterEvent.cs | 4 + .../GameModes/MultiplayerCampaign.cs | 37 +- .../Source/Map/Levels/Level.cs | 5 + .../BarotraumaShared/Source/Map/Map/Map.cs | 4 + .../Source/Networking/GameServer.cs | 18 +- .../Source/Screens/sygwkgy0.iv5 | 337 ------------------ 10 files changed, 88 insertions(+), 375 deletions(-) delete mode 100644 Barotrauma/BarotraumaShared/Source/Screens/sygwkgy0.iv5 diff --git a/Barotrauma/BarotraumaClient/Source/Networking/GameClient.cs b/Barotrauma/BarotraumaClient/Source/Networking/GameClient.cs index d35f2f464..113464deb 100644 --- a/Barotrauma/BarotraumaClient/Source/Networking/GameClient.cs +++ b/Barotrauma/BarotraumaClient/Source/Networking/GameClient.cs @@ -684,6 +684,8 @@ namespace Barotrauma.Networking inc.ReadPadBits(); GameModePreset gameMode = GameModePreset.list.Find(gm => gm.Name == modeName); + MultiplayerCampaign campaign = GameMain.NetLobbyScreen.SelectedMode == GameMain.GameSession?.GameMode.Preset ? + GameMain.GameSession?.GameMode as MultiplayerCampaign : null; if (gameMode == null) { @@ -691,24 +693,31 @@ namespace Barotrauma.Networking yield return CoroutineStatus.Success; } - if (!GameMain.NetLobbyScreen.TrySelectSub(subName, subHash, GameMain.NetLobbyScreen.SubList)) + if (campaign == null) { - yield return CoroutineStatus.Success; - } + if (!GameMain.NetLobbyScreen.TrySelectSub(subName, subHash, GameMain.NetLobbyScreen.SubList)) + { + yield return CoroutineStatus.Success; + } - if (!GameMain.NetLobbyScreen.TrySelectSub(shuttleName, shuttleHash, GameMain.NetLobbyScreen.ShuttleList.ListBox)) - { - yield return CoroutineStatus.Success; + if (!GameMain.NetLobbyScreen.TrySelectSub(shuttleName, shuttleHash, GameMain.NetLobbyScreen.ShuttleList.ListBox)) + { + yield return CoroutineStatus.Success; + } } Rand.SetSyncedSeed(seed); - if (gameMode.Name != "Campaign") + if (campaign == null) { GameMain.GameSession = new GameSession(GameMain.NetLobbyScreen.SelectedSub, "", gameMode, Mission.MissionTypes[missionTypeIndex]); + GameMain.GameSession.StartRound(levelSeed, loadSecondSub); } - GameMain.GameSession.StartRound(levelSeed, loadSecondSub); - + else + { + GameMain.GameSession.StartRound(campaign.Map.SelectedConnection.Level, true, false); + } + if (respawnAllowed) respawnManager = new RespawnManager(this, GameMain.NetLobbyScreen.SelectedShuttle); if (isTraitor) @@ -1113,6 +1122,10 @@ namespace Barotrauma.Networking GameMain.GameSession.Submarine = new Submarine(subPath, ""); } + else + { + SaveUtil.DecompressToDirectory(GameMain.GameSession.SavePath, SaveUtil.TempPath, null); + } break; } diff --git a/Barotrauma/BarotraumaClient/Source/Screens/CampaignUI.cs b/Barotrauma/BarotraumaClient/Source/Screens/CampaignUI.cs index f6fbeda1b..32a534483 100644 --- a/Barotrauma/BarotraumaClient/Source/Screens/CampaignUI.cs +++ b/Barotrauma/BarotraumaClient/Source/Screens/CampaignUI.cs @@ -85,10 +85,13 @@ namespace Barotrauma tabs[(int)Tab.Map] = new GUIFrame(Rectangle.Empty, null, container); tabs[(int)Tab.Map].Padding = Vector4.One * 10.0f; - startButton = new GUIButton(new Rectangle(0, 0, 100, 30), "Start", - Alignment.BottomRight, "", tabs[(int)Tab.Map]); - startButton.OnClicked = (GUIButton btn, object obj) => { StartRound?.Invoke(); return true; }; - startButton.Enabled = false; + if (GameMain.Client == null) + { + startButton = new GUIButton(new Rectangle(0, 0, 100, 30), "Start", + Alignment.BottomRight, "", tabs[(int)Tab.Map]); + startButton.OnClicked = (GUIButton btn, object obj) => { StartRound?.Invoke(); return true; }; + startButton.Enabled = false; + } //--------------------------------------- diff --git a/Barotrauma/BarotraumaShared/Source/Events/ArtifactEvent.cs b/Barotrauma/BarotraumaShared/Source/Events/ArtifactEvent.cs index 279610058..067844b95 100644 --- a/Barotrauma/BarotraumaShared/Source/Events/ArtifactEvent.cs +++ b/Barotrauma/BarotraumaShared/Source/Events/ArtifactEvent.cs @@ -55,6 +55,11 @@ namespace Barotrauma itemContainer.Combine(item); break; } + + if (GameSettings.VerboseLogging) + { + DebugConsole.NewMessage("Initialized ArtifactEvent (" + item.Name + ")", Color.White); + } } public override void Update(float deltaTime) diff --git a/Barotrauma/BarotraumaShared/Source/Events/EventManager.cs b/Barotrauma/BarotraumaShared/Source/Events/EventManager.cs index 978a71605..3b2f7398a 100644 --- a/Barotrauma/BarotraumaShared/Source/Events/EventManager.cs +++ b/Barotrauma/BarotraumaShared/Source/Events/EventManager.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using Microsoft.Xna.Framework; +using System.Collections.Generic; namespace Barotrauma { @@ -34,7 +35,15 @@ namespace Barotrauma private void CreateScriptedEvents(Level level) { + System.Diagnostics.Debug.Assert(events.Count == 0); + MTRandom rand = new MTRandom(ToolBox.StringToInt(level.Seed)); + + if (GameSettings.VerboseLogging) + { + DebugConsole.NewMessage("Generating events (seed: " + level.Seed + ")", Color.White); + } + events.AddRange(ScriptedEvent.GenerateLevelEvents(rand, level)); } diff --git a/Barotrauma/BarotraumaShared/Source/Events/MonsterEvent.cs b/Barotrauma/BarotraumaShared/Source/Events/MonsterEvent.cs index 183efee70..cbfa785f7 100644 --- a/Barotrauma/BarotraumaShared/Source/Events/MonsterEvent.cs +++ b/Barotrauma/BarotraumaShared/Source/Events/MonsterEvent.cs @@ -74,6 +74,10 @@ namespace Barotrauma base.Init(); monsters = SpawnMonsters(Rand.Range(minAmount, maxAmount, Rand.RandSync.Server)); + if (GameSettings.VerboseLogging) + { + DebugConsole.NewMessage("Initialized MonsterEvent (" + monsters[0]?.SpeciesName + " x" + monsters.Length + ")", Color.White); + } } private Character[] SpawnMonsters(int amount) diff --git a/Barotrauma/BarotraumaShared/Source/GameSession/GameModes/MultiplayerCampaign.cs b/Barotrauma/BarotraumaShared/Source/GameSession/GameModes/MultiplayerCampaign.cs index 524ddbfde..b504cf771 100644 --- a/Barotrauma/BarotraumaShared/Source/GameSession/GameModes/MultiplayerCampaign.cs +++ b/Barotrauma/BarotraumaShared/Source/GameSession/GameModes/MultiplayerCampaign.cs @@ -66,7 +66,7 @@ namespace Barotrauma campaignSetupUI.StartNewGame = (Submarine sub, string saveName, string mapSeed) => { - GameMain.GameSession = new GameSession(sub, saveName, GameModePreset.list.Find(g => g.Name == "Campaign")); + GameMain.GameSession = new GameSession(new Submarine(sub.FilePath, ""), saveName, GameModePreset.list.Find(g => g.Name == "Campaign")); var campaign = ((MultiplayerCampaign)GameMain.GameSession.GameMode); campaign.GenerateMap(mapSeed); campaign.map.OnLocationSelected += (loc, connection) => { campaign.LastUpdateID++; }; @@ -142,6 +142,18 @@ namespace Barotrauma GameMain.GameSession.EndRound(""); + //TODO: save player inventories between mp campaign rounds + + //remove all items that are in someone's inventory + foreach (Character c in Character.CharacterList) + { + if (c.Inventory == null) continue; + foreach (Item item in c.Inventory.Items) + { + if (item != null) item.Remove(); + } + } + if (success) { bool atEndPosition = Submarine.MainSub.AtEndPosition; @@ -167,11 +179,9 @@ namespace Barotrauma SaveUtil.SaveGame(GameMain.GameSession.SavePath); } - if (!success) { - /* var summaryScreen = GUIMessageBox.VisibleBox; - + var summaryScreen = GUIMessageBox.VisibleBox; if (summaryScreen != null) { summaryScreen = summaryScreen.children[0]; @@ -184,16 +194,13 @@ namespace Barotrauma var quitButton = new GUIButton(new Rectangle(0, 0, 100, 30), "Quit", Alignment.BottomRight, "", summaryScreen); quitButton.OnClicked += GameMain.LobbyScreen.QuitToMainMenu; quitButton.OnClicked += (GUIButton button, object obj) => { GUIMessageBox.MessageBoxes.Remove(GUIMessageBox.VisibleBox); return true; }; - }*/ + } } } - - for (int i = Character.CharacterList.Count - 1; i >= 0; i--) + else { - Character.CharacterList[i].Remove(); + GameMain.GameSession.EndRound(""); } - - Submarine.Unload(); } public static MultiplayerCampaign Load(XElement element) @@ -260,19 +267,17 @@ namespace Barotrauma UInt16 selectedLocIndex = msg.ReadUInt16(); MultiplayerCampaign campaign = GameMain.GameSession?.GameMode as MultiplayerCampaign; - if (campaign == null) + if (campaign == null || mapSeed != campaign.Map.Seed) { string savePath = SaveUtil.CreateSavePath(SaveUtil.SaveType.Multiplayer); - GameMain.GameSession = new GameSession( - null, //TODO: set the sub (after receiving the save file?) - savePath, GameModePreset.list.Find(g => g.Name == "Campaign")); + GameMain.GameSession = new GameSession(null, savePath, GameModePreset.list.Find(g => g.Name == "Campaign")); campaign = ((MultiplayerCampaign)GameMain.GameSession.GameMode); campaign.GenerateMap(mapSeed); - - GameMain.NetLobbyScreen.ToggleCampaignMode(true); } + + GameMain.NetLobbyScreen.ToggleCampaignMode(true); if (NetIdUtils.IdMoreRecent(campaign.lastUpdateID, updateID)) return; //server has a newer save file diff --git a/Barotrauma/BarotraumaShared/Source/Map/Levels/Level.cs b/Barotrauma/BarotraumaShared/Source/Map/Levels/Level.cs index 9ec3fd5e9..236cffcfe 100644 --- a/Barotrauma/BarotraumaShared/Source/Map/Levels/Level.cs +++ b/Barotrauma/BarotraumaShared/Source/Map/Levels/Level.cs @@ -499,6 +499,11 @@ namespace Barotrauma Debug.WriteLine("Generated a map with " + sites.Count + " sites in " + sw.ElapsedMilliseconds + " ms"); Debug.WriteLine("Seed: " + seed); Debug.WriteLine("**********************************************************************************"); + + if (GameSettings.VerboseLogging) + { + DebugConsole.NewMessage("Generated level with the seed " + seed + " (type: " + generationParams.Name + ")", Color.White); + } } diff --git a/Barotrauma/BarotraumaShared/Source/Map/Map/Map.cs b/Barotrauma/BarotraumaShared/Source/Map/Map/Map.cs index bd6f9cf37..bb9e15242 100644 --- a/Barotrauma/BarotraumaShared/Source/Map/Map/Map.cs +++ b/Barotrauma/BarotraumaShared/Source/Map/Map/Map.cs @@ -451,6 +451,10 @@ namespace Barotrauma if (rand.NextDouble() < 0.3f) return null; mission = Mission.LoadRandom(locations, rand, "", true); + if (GameSettings.VerboseLogging && mission != null) + { + DebugConsole.NewMessage("Generated a new mission for a location connection (seed: " + seed + ", type: " + mission.Name + ")", Color.White); + } } return mission; diff --git a/Barotrauma/BarotraumaShared/Source/Networking/GameServer.cs b/Barotrauma/BarotraumaShared/Source/Networking/GameServer.cs index bb41a1f42..a9f1e9103 100644 --- a/Barotrauma/BarotraumaShared/Source/Networking/GameServer.cs +++ b/Barotrauma/BarotraumaShared/Source/Networking/GameServer.cs @@ -1152,7 +1152,8 @@ namespace Barotrauma.Networking int teamCount = 1; byte hostTeam = 1; - MultiplayerCampaign campaign = GameMain.GameSession?.GameMode as MultiplayerCampaign; + MultiplayerCampaign campaign = GameMain.NetLobbyScreen.SelectedMode == GameMain.GameSession?.GameMode.Preset ? + GameMain.GameSession?.GameMode as MultiplayerCampaign : null; //don't instantiate a new gamesession if we're playing a campaign if (campaign == null || GameMain.GameSession == null) @@ -1184,9 +1185,9 @@ namespace Barotrauma.Networking 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) || - ((MissionMode)GameMain.GameSession.GameMode).Mission.AllowRespawn; + bool missionAllowRespawn = campaign == null && + (!(GameMain.GameSession.GameMode is MissionMode) || + ((MissionMode)GameMain.GameSession.GameMode).Mission.AllowRespawn); if (AllowRespawn && missionAllowRespawn) respawnManager = new RespawnManager(this, selectedShuttle); @@ -1255,7 +1256,6 @@ namespace Barotrauma.Networking #endif } - foreach (Submarine sub in Submarine.MainSubs) { if (sub == null) continue; @@ -1343,9 +1343,11 @@ namespace Barotrauma.Networking msg.Write(selectedMode.Name); - bool missionAllowRespawn = - !(GameMain.GameSession.GameMode is MissionMode) || - ((MissionMode)GameMain.GameSession.GameMode).Mission.AllowRespawn; + MultiplayerCampaign campaign = GameMain.GameSession?.GameMode as MultiplayerCampaign; + + bool missionAllowRespawn = campaign == null && + (!(GameMain.GameSession.GameMode is MissionMode) || + ((MissionMode)GameMain.GameSession.GameMode).Mission.AllowRespawn); msg.Write(AllowRespawn && missionAllowRespawn); msg.Write(Submarine.MainSubs[1] != null); //loadSecondSub diff --git a/Barotrauma/BarotraumaShared/Source/Screens/sygwkgy0.iv5 b/Barotrauma/BarotraumaShared/Source/Screens/sygwkgy0.iv5 deleted file mode 100644 index 20c7aa855..000000000 --- a/Barotrauma/BarotraumaShared/Source/Screens/sygwkgy0.iv5 +++ /dev/null @@ -1,337 +0,0 @@ -using System; -using Lidgren.Network; -using Microsoft.Xna.Framework; -using Microsoft.Xna.Framework.Graphics; -using Barotrauma.Networking; -using FarseerPhysics; -using FarseerPhysics.Factories; -using FarseerPhysics.Dynamics; -using System.IO; -using System.Collections.Generic; -using RestSharp; - -namespace Barotrauma -{ - class ServerListScreen : Screen - { - //how often the client is allowed to refresh servers - private TimeSpan AllowedRefreshInterval = new TimeSpan(0,0,3); - - private GUIFrame menu; - - private GUIListBox serverList; - - private GUIButton joinButton; - - private GUITextBox clientNameBox, ipBox; - - //private RestRequestAsyncHandle restRequestHandle; - private bool masterServerResponded; - - private int[] columnX; - - //a timer for - private DateTime refreshDisableTimer; - private bool waitingForRefresh; - - public ServerListScreen() - { - int width = Math.Min(GameMain.GraphicsWidth - 160, 1000); - int height = Math.Min(GameMain.GraphicsHeight - 160, 700); - - Rectangle panelRect = new Rectangle(0, 0, width, height); - - menu = new GUIFrame(panelRect, null, Alignment.Center, GUI.Style); - menu.Padding = new Vector4(40.0f, 40.0f, 40.0f, 20.0f); - - new GUITextBlock(new Rectangle(0, -25, 0, 30), "Join Server", GUI.Style, Alignment.CenterX, Alignment.CenterX, menu, false, GUI.LargeFont); - - new GUITextBlock(new Rectangle(0, 30, 0, 30), "Your Name:", GUI.Style, menu); - clientNameBox = new GUITextBox(new Rectangle(0, 60, 200, 30), GUI.Style, menu); - - new GUITextBlock(new Rectangle(0, 100, 0, 30), "Server IP:", GUI.Style, menu); - ipBox = new GUITextBox(new Rectangle(0, 130, 200, 30), GUI.Style, menu); - - int middleX = (int)(width * 0.4f); - - serverList = new GUIListBox(new Rectangle(middleX,60,0,height-160), GUI.Style, menu); - serverList.OnSelected = SelectServer; - - float[] columnRelativeX = new float[] { 0.15f, 0.55f, 0.15f, 0.15f }; - columnX = new int[columnRelativeX.Length]; - for (int n = 0; n < columnX.Length; n++) - { - columnX[n] = (int)(columnRelativeX[n] * serverList.Rect.Width); - if (n > 0) columnX[n] += columnX[n - 1]; - } - - SpriteFont font = serverList.Rect.Width < 400 ? GUI.SmallFont : GUI.Font; - - new GUITextBlock(new Rectangle(middleX, 30, 0, 30), "Password", GUI.Style, menu).Font = font; - - new GUITextBlock(new Rectangle(middleX + columnX[0], 30, 0, 30), "Name", GUI.Style, menu).Font = font; - new GUITextBlock(new Rectangle(middleX + columnX[1], 30, 0, 30), "Players", GUI.Style, menu).Font = font; - new GUITextBlock(new Rectangle(middleX + columnX[2], 30, 0, 30), "Round started", GUI.Style, menu).Font = font; - - joinButton = new GUIButton(new Rectangle(-170, 0, 150, 30), "Refresh", Alignment.BottomRight, GUI.Style, menu); - joinButton.OnClicked = RefreshServers; - - joinButton = new GUIButton(new Rectangle(0,0,150,30), "Join", Alignment.BottomRight, GUI.Style, menu); - joinButton.OnClicked = JoinServer; - - GUIButton button = new GUIButton(new Rectangle(-20, -20, 100, 30), "Back", Alignment.TopLeft, GUI.Style, menu); - button.OnClicked = GameMain.MainMenuScreen.SelectTab; - button.CanBeSelected = false; - button.SelectedColor = button.Color; - - refreshDisableTimer = DateTime.Now; - } - - public override void Select() - { - base.Select(); - - - RefreshServers(null, null); - } - - private bool SelectServer(GUIComponent component, object obj) - { - string ip = obj as string; - if (string.IsNullOrWhiteSpace(ip)) return false; - - ipBox.Text = ip; - - return true; - } - - private bool RefreshServers(GUIButton button, object obj) - { - if (waitingForRefresh) return false; - serverList.ClearChildren(); - - new GUITextBlock(new Rectangle(0, 0, 0, 20), "Refreshing server list...", GUI.Style, serverList); - - CoroutineManager.StartCoroutine(WaitForRefresh()); - - return true; - } - - private IEnumerable WaitForRefresh() - { - waitingForRefresh = true; - if (refreshDisableTimer > DateTime.Now) - { - yield return new WaitForSeconds((float)(refreshDisableTimer - DateTime.Now).TotalSeconds); - } - - //CoroutineManager.StartCoroutine(UpdateServerList()); - CoroutineManager.StartCoroutine(SendMasterServerRequest()); - - waitingForRefresh = false; - - refreshDisableTimer = DateTime.Now + AllowedRefreshInterval; - - yield return CoroutineStatus.Success; - } - - private void UpdateServerList(string masterServerData) - { - serverList.ClearChildren(); - - //string masterServerData = GetMasterServerData(); - - if (string.IsNullOrWhiteSpace(masterServerData)) - { - var nameText = new GUITextBlock(new Rectangle(0, 0, 0, 20), "Couldn't find any servers", GUI.Style, serverList); - - return; - } - - if (masterServerData.Substring(0,5).ToLower()=="error") - { - DebugConsole.ThrowError("Error while connecting to master server ("+masterServerData+")!"); - - return; - } - - string[] lines = masterServerData.Split('\n'); - - for (int i = 0; i 3) ? arguments[3] : ""; - string playerCountStr = (arguments.Length > 4) ? arguments[4] : ""; - - string hasPassWordStr = (arguments.Length > 5) ? arguments[5] : ""; - - var serverFrame = new GUIFrame(new Rectangle(0,0,0,20), (i%2 == 0) ? Color.Transparent : Color.White*0.2f, null, serverList); - serverFrame.UserData = IP+":"+port; - serverFrame.HoverColor = Color.Gold * 0.2f; - serverFrame.SelectedColor = Color.Gold * 0.5f; - - var passwordBox = new GUITickBox(new Rectangle(columnX[0]/2, 0, 20, 20), "", Alignment.TopLeft, serverFrame); - passwordBox.Selected = hasPassWordStr == "1"; - passwordBox.Enabled = false; - passwordBox.UserData = "password"; - - var nameText = new GUITextBlock(new Rectangle(columnX[0], 0, 0, 0), serverName, GUI.Style, serverFrame); - - int playerCount, maxPlayers; - playerCount = GameClient.ByteToPlayerCount((byte)int.Parse(playerCountStr), out maxPlayers); - - var playerCountText = new GUITextBlock(new Rectangle(columnX[1], 0, 0, 0), playerCount + "/" + maxPlayers, GUI.Style, serverFrame); - - var gameStartedBox = new GUITickBox(new Rectangle(columnX[2] + (columnX[3] - columnX[2])/ 2, 0, 20, 20), "", Alignment.TopLeft, serverFrame); - gameStartedBox.Selected = gameStarted == "1"; - gameStartedBox.Enabled = false; - - } - } - - private IEnumerable SendMasterServerRequest() - { - RestClient client = null; - try - { - client = new RestClient(NetConfig.MasterServerUrl); - } - catch (Exception e) - { - DebugConsole.ThrowError("Error while connecting to master server", e); - } - - if (client == null) yield return CoroutineStatus.Success; - - - var request = new RestRequest("masterserver.php", Method.GET); - request.AddParameter("gamename", "barotrauma"); // adds to POST or URL querystring based on Method - request.AddParameter("action", "listservers"); // adds to POST or URL querystring based on Method - - - // easily add HTTP Headers - //request.AddHeader("header", "value"); - - //// add files to upload (works with compatible verbs) - //request.AddFile(path); - - // execute the request - masterServerResponded = false; - var restRequestHandle = client.ExecuteAsync(request, response => MasterServerCallBack(response)); - - DateTime timeOut = DateTime.Now + new TimeSpan(0, 0, 8); - while (!masterServerResponded) - { - if (DateTime.Now > timeOut) - { - serverList.ClearChildren(); - restRequestHandle.Abort(); - DebugConsole.ThrowError("Couldn't connect to master server (request timed out)"); - } - yield return CoroutineStatus.Running; - } - - yield return CoroutineStatus.Success; - - } - - private void MasterServerCallBack(IRestResponse response) - { - masterServerResponded = true; - - if (response.ErrorException!=null) - { - serverList.ClearChildren(); - DebugConsole.ThrowError("Error while connecting to master server", response.ErrorException); - return; - } - - if (response.StatusCode!= System.Net.HttpStatusCode.OK) - { - serverList.ClearChildren(); - DebugConsole.ThrowError("Error while connecting to master server (" +response.StatusCode+": "+response.StatusDescription+")"); - return; - } - - UpdateServerList(response.Content); - } - - private bool JoinServer(GUIButton button, object obj) - { - if (string.IsNullOrWhiteSpace(clientNameBox.Text)) - { - clientNameBox.Flash(); - return false; - } - - string ip = ipBox.Text; - - if (string.IsNullOrWhiteSpace(ip)) - { - ipBox.Flash(); - return false; - } - - CoroutineManager.StartCoroutine(JoinServer(ip)); - - - return true; - } - - private IEnumerable JoinServer(string ip) - { - string selectedPassword = ""; - - if (serverList.Selected!=null && (serverList.Selected.GetChild("password") as GUITickBox).Selected) - { - var msgBox = new GUIMessageBox("Password required:", ""); - var passwordBox = new GUITextBox(new Rectangle(0,40,150,25), Alignment.TopLeft, GUI.Style, msgBox); - passwordBox.UserData = "password"; - - var okButton = msgBox.GetChild(); - - while (GUIMessageBox.MessageBoxes.Contains(msgBox)) - { - okButton.Enabled = !string.IsNullOrWhiteSpace(passwordBox.Text); - yield return CoroutineStatus.Running; - } - - selectedPassword = passwordBox.Text; - } - - GameMain.NetworkMember = new GameClient(clientNameBox.Text); - GameMain.Client.ConnectToServer(ip, selectedPassword); - - yield return CoroutineStatus.Success; - } - - public override void Draw(double deltaTime, GraphicsDevice graphics, SpriteBatch spriteBatch) - { - graphics.Clear(Color.CornflowerBlue); - - GameMain.GameScreen.DrawMap(graphics, spriteBatch); - - spriteBatch.Begin(); - - menu.Draw(spriteBatch); - - //if (previewPlayer!=null) previewPlayer.Draw(spriteBatch); - - GUI.Draw((float)deltaTime, spriteBatch, null); - - spriteBatch.End(); - } - - public override void Update(double deltaTime) - { - menu.Update((float)deltaTime); - - GUI.Update((float)deltaTime); - } - } -}