diff --git a/Client/Menus/MenusMain.cs b/Client/Menus/MenusMain.cs index 61e4527..43318b8 100644 --- a/Client/Menus/MenusMain.cs +++ b/Client/Menus/MenusMain.cs @@ -30,7 +30,7 @@ namespace CoopClient.Menus #region ITEMS private readonly NativeItem UsernameItem = new NativeItem("Username") { AltTitle = Main.MainSettings.Username }; - private readonly NativeItem ServerIpItem = new NativeItem("Server IP") { AltTitle = Main.MainSettings.LastServerAddress }; + internal readonly NativeItem ServerIpItem = new NativeItem("Server IP") { AltTitle = Main.MainSettings.LastServerAddress }; private readonly NativeItem ServerConnectItem = new NativeItem("Connect"); private readonly NativeItem AboutItem = new NativeItem("About", "~y~SOURCE~s~~n~" + "https://github.com/GTACOOP-R~n~" + @@ -104,7 +104,6 @@ namespace CoopClient.Menus MainMenu.Visible = false; ServerList.MainMenu.Visible = false; - MenuPool.RefreshAll(); } internal void DisconnectedMenuSetting() diff --git a/Client/Menus/Sub/Servers.cs b/Client/Menus/Sub/Servers.cs index 1bc4e26..2d66492 100644 --- a/Client/Menus/Sub/Servers.cs +++ b/Client/Menus/Sub/Servers.cs @@ -93,10 +93,13 @@ namespace CoopClient.Menus.Sub try { MainMenu.Visible = false; - Main.MainMenu.MainMenu.Visible = true; Main.MainNetworking.DisConnectFromServer(server.IP); + Main.MainMenu.ServerIpItem.AltTitle = server.IP; + + Main.MainMenu.MainMenu.Visible = true; + Main.MainSettings.LastServerAddress = server.IP; Util.SaveSettings(); } diff --git a/Client/Networking.cs b/Client/Networking.cs index 5cb82fc..913eec5 100644 --- a/Client/Networking.cs +++ b/Client/Networking.cs @@ -27,10 +27,6 @@ namespace CoopClient { if (IsOnServer()) { - NetOutgoingMessage outgoingMessage = Client.CreateMessage(); - new PlayerDisconnectPacket() { ID = Main.LocalClientID }.PacketToNetOutGoingMessage(outgoingMessage); - Client.SendMessage(outgoingMessage, NetDeliveryMethod.ReliableOrdered); - Client.FlushSendQueue(); Client.Disconnect("Bye!"); } else diff --git a/Server/Server.cs b/Server/Server.cs index ccf2e3d..5cb5c26 100644 --- a/Server/Server.cs +++ b/Server/Server.cs @@ -202,10 +202,10 @@ namespace CoopServer switch (message.MessageType) { case NetIncomingMessageType.ConnectionApproval: - Logging.Info("New incoming connection from: " + message.SenderConnection.RemoteEndPoint.ToString()); + Logging.Info($"New incoming connection from: [{message.SenderConnection.RemoteEndPoint}]"); if (message.ReadByte() != (byte)PacketTypes.HandshakePacket) { - Logging.Info(string.Format("Player with IP {0} blocked, reason: Wrong packet!", message.SenderConnection.RemoteEndPoint.Address.ToString())); + Logging.Info($"IP [{message.SenderConnection.RemoteEndPoint.Address}] was blocked, reason: Wrong packet!"); message.SenderConnection.Deny("Wrong packet!"); } else @@ -219,7 +219,7 @@ namespace CoopServer } catch (Exception e) { - Logging.Info(string.Format("Player with IP {0} blocked, reason: {1}", message.SenderConnection.RemoteEndPoint.Address.ToString(), e.Message)); + Logging.Info($"IP [{message.SenderConnection.RemoteEndPoint.Address}] was blocked, reason: {e.Message}"); message.SenderConnection.Deny(e.Message); } } @@ -227,11 +227,9 @@ namespace CoopServer case NetIncomingMessageType.StatusChanged: NetConnectionStatus status = (NetConnectionStatus)message.ReadByte(); - long clientID = message.SenderConnection.RemoteUniqueIdentifier; - - if (status == NetConnectionStatus.Disconnected && Clients.Any(x => x.ID == clientID)) + if (status == NetConnectionStatus.Disconnected) { - SendPlayerDisconnectPacket(new PlayerDisconnectPacket() { ID = clientID }); + SendPlayerDisconnectPacket(message.SenderConnection.RemoteUniqueIdentifier); } break; case NetIncomingMessageType.Data: @@ -255,18 +253,6 @@ namespace CoopServer message.SenderConnection.Disconnect(e.Message); } break; - case (byte)PacketTypes.PlayerDisconnectPacket: - try - { - packet = new PlayerDisconnectPacket(); - packet.NetIncomingMessageToPacket(message); - SendPlayerDisconnectPacket((PlayerDisconnectPacket)packet); - } - catch (Exception e) - { - message.SenderConnection.Disconnect(e.Message); - } - break; case (byte)PacketTypes.FullSyncPlayerPacket: try { @@ -558,11 +544,6 @@ namespace CoopServer return; } - if (!string.IsNullOrEmpty(MainSettings.WelcomeMessage)) - { - SendChatMessage(new ChatMessagePacket() { Username = "Server", Message = MainSettings.WelcomeMessage }, new List() { local }); - } - List clients; if ((clients = Util.FilterAllLocal(local)).Count > 0) { @@ -600,33 +581,46 @@ namespace CoopServer { MainResource.InvokePlayerConnected(localClient); } + else + { + Logging.Info($"Player {localClient.Player.Username} connected!"); + } + + if (!string.IsNullOrEmpty(MainSettings.WelcomeMessage)) + { + SendChatMessage(new ChatMessagePacket() { Username = "Server", Message = MainSettings.WelcomeMessage }, new List() { local }); + } } // Send all players a message that someone has left the server - private static void SendPlayerDisconnectPacket(PlayerDisconnectPacket packet) + private static void SendPlayerDisconnectPacket(long clientID) { - List clients; - if ((clients = Util.FilterAllLocal(packet.ID)).Count > 0) + List clients = MainNetServer.Connections; + if (clients.Count > 0) { NetOutgoingMessage outgoingMessage = MainNetServer.CreateMessage(); - packet.PacketToNetOutGoingMessage(outgoingMessage); + new PlayerDisconnectPacket() + { + ID = clientID + }.PacketToNetOutGoingMessage(outgoingMessage); MainNetServer.SendMessage(outgoingMessage, clients, NetDeliveryMethod.ReliableOrdered, 0); } - Client localClient = Clients.FirstOrDefault(x => x.ID == packet.ID); + Client localClient = Clients.FirstOrDefault(x => x.ID == clientID); if (localClient.Equals(default(Client))) { return; } + Clients.Remove(localClient); + if (MainResource != null) { MainResource.InvokePlayerDisconnected(localClient); } - - lock (Clients) + else { - Clients.Remove(localClient); + Logging.Info($"Player {localClient.Player.Username} disconnected!"); } }