From a02931054abe11e8f63543662a79386c7b489afd Mon Sep 17 00:00:00 2001 From: juanjp600 Date: Mon, 5 Sep 2016 17:15:41 -0300 Subject: [PATCH] Sync sub selection --- Subsurface/Source/Networking/GameClient.cs | 60 ++++++++++++---------- Subsurface/Source/Networking/GameServer.cs | 10 ++-- 2 files changed, 40 insertions(+), 30 deletions(-) diff --git a/Subsurface/Source/Networking/GameClient.cs b/Subsurface/Source/Networking/GameClient.cs index c8159fb15..17bdcadfd 100644 --- a/Subsurface/Source/Networking/GameClient.cs +++ b/Subsurface/Source/Networking/GameClient.cs @@ -529,34 +529,40 @@ namespace Barotrauma.Networking case ServerNetObject.SYNC_IDS: bool lobbyUpdated = inc.ReadBoolean(); inc.ReadPadBits(); - if (lobbyUpdated) - { - GameMain.NetLobbyScreen.LastUpdateID = inc.ReadUInt32(); - GameMain.NetLobbyScreen.ServerName = inc.ReadString(); - GameMain.NetLobbyScreen.ServerMessage = inc.ReadString(); - - UInt16 subListCount = inc.ReadUInt16(); - if (subListCount > 0) - { - List submarines = new List(); - for (int i = 0; i < subListCount; i++) - { - string subName = inc.ReadString(); - string subHash = inc.ReadString(); - - var matchingSub = Submarine.SavedSubmarines.Find(s => s.Name == subName); - if (matchingSub != null) - { - submarines.Add(matchingSub); - } - else - { - submarines.Add(new Submarine(Path.Combine(Submarine.SavePath, subName), subHash, false)); - } - } + if (lobbyUpdated) + { + GameMain.NetLobbyScreen.LastUpdateID = inc.ReadUInt32(); + GameMain.NetLobbyScreen.ServerName = inc.ReadString(); + GameMain.NetLobbyScreen.ServerMessage = inc.ReadString(); + + UInt16 subListCount = inc.ReadUInt16(); + if (subListCount > 0) + { + List submarines = new List(); + for (int i = 0; i < subListCount; i++) + { + string subName = inc.ReadString(); + string subHash = inc.ReadString(); + + var matchingSub = Submarine.SavedSubmarines.Find(s => s.Name == subName); + if (matchingSub != null) + { + submarines.Add(matchingSub); + } + else + { + submarines.Add(new Submarine(Path.Combine(Submarine.SavePath, subName), subHash, false)); + } + } GameMain.NetLobbyScreen.UpdateSubList(GameMain.NetLobbyScreen.SubList, submarines); - GameMain.NetLobbyScreen.UpdateSubList(GameMain.NetLobbyScreen.ShuttleList.ListBox, submarines); - } + GameMain.NetLobbyScreen.UpdateSubList(GameMain.NetLobbyScreen.ShuttleList.ListBox, submarines); + } + string selectSubName = inc.ReadString(); + string selectSubHash = inc.ReadString(); + GameMain.NetLobbyScreen.TrySelectSub(selectSubName, selectSubHash, GameMain.NetLobbyScreen.SubList); + string selectShuttleName = inc.ReadString(); + string selectShuttleHash = inc.ReadString(); + GameMain.NetLobbyScreen.TrySelectSub(selectShuttleName, selectShuttleHash, GameMain.NetLobbyScreen.ShuttleList.ListBox); } lastRecvChatMsgID = inc.ReadUInt32(); break; diff --git a/Subsurface/Source/Networking/GameServer.cs b/Subsurface/Source/Networking/GameServer.cs index d8c0369ae..c820b087c 100644 --- a/Subsurface/Source/Networking/GameServer.cs +++ b/Subsurface/Source/Networking/GameServer.cs @@ -622,9 +622,9 @@ namespace Barotrauma.Networking outmsg.Write(GameMain.NetLobbyScreen.LastUpdateID); outmsg.Write(GameMain.NetLobbyScreen.GetServerName()); outmsg.Write(GameMain.NetLobbyScreen.ServerMessage); + var subList = GameMain.NetLobbyScreen.GetSubList(); if (c.lastRecvLobbyUpdate < 1) { - var subList = GameMain.NetLobbyScreen.GetSubList(); outmsg.Write((UInt16)subList.Count); for (int i = 0; i < subList.Count; i++) { @@ -636,6 +636,10 @@ namespace Barotrauma.Networking { outmsg.Write((UInt16)0); } + outmsg.Write((GameMain.NetLobbyScreen.SubList.SelectedData as Submarine).Name); + outmsg.Write((GameMain.NetLobbyScreen.SubList.SelectedData as Submarine).MD5Hash.ToString()); + outmsg.Write((GameMain.NetLobbyScreen.ShuttleList.SelectedData as Submarine).Name); + outmsg.Write((GameMain.NetLobbyScreen.ShuttleList.SelectedData as Submarine).MD5Hash.ToString()); } else { @@ -812,8 +816,8 @@ namespace Barotrauma.Networking if (ban) { DisconnectClient(client, client.name + " has been banned from the server", "You have been banned from the server"); - string ip = client.Connection.RemoteEndPoint.Address.ToString(); - if (range) { ip = banList.ToRange(ip); } + string ip = client.Connection.RemoteEndPoint.Address.ToString(); + if (range) { ip = banList.ToRange(ip); } banList.BanPlayer(client.name, ip); } else