/// <summary> /// Limpa os dados de usuário para voltar a tela de login /// </summary> /// <param name="index"></param> public static void BackToLoginScreen(string hexID) { var pData = Authentication.FindByHexID(hexID); Accounts_DB.UpdateLastIP(pData.Account, pData.IP); Accounts_DB.UpdateLoggedIn(pData.Account, 0); //0 = false pData.Clear(); }
/// <summary> /// Recebe os dados dos clientes. /// </summary> public static void ReceivedData() { while ((msg = socket.ReadMessage()) != null) { pData = Authentication.FindByConnection(msg.SenderConnection); switch (msg.MessageType) { case NetIncomingMessageType.DiscoveryRequest: #region Find Banned Country var ip = msg.SenderEndPoint.Address.ToString(); if (GeoIp.Enabled) { //Verifica se o ip já está bloqueado temporariamente (evitar processamento desnecessario) if (!GeoIp.IsIpBlocked(ip)) { //verifica se o ip do país está na lista de bloqueados. if (GeoIp.IsCountryIpBlocked(ip)) { var country = GeoIp.FindCountryByIp(ip); //adiciona na lista de bloqueado temporareamente GeoIp.AddIpAddress(ip); FileLog.WriteLog($"Banned country trying to connect: {ip} {country.Country}-{country.Code}", Color.Coral); return; } } else { return; } } #endregion #region Find Banned IP if (Accounts_DB.IsBannedIp(msg.SenderEndPoint.Address.ToString()) == true) { FileLog.WriteLog("Warning: Attempted IP Banned " + msg.SenderEndPoint.Address, Color.Coral); return; } #endregion LoginNetwork.socket.SendDiscoveryResponse(null, msg.SenderEndPoint); FileLog.WriteLog($"Discovery Response IPEndPoint: {msg.SenderEndPoint.Address}", Color.Coral); break; case NetIncomingMessageType.ErrorMessage: FileLog.WriteLog($"Error: {msg.ReadString()}", Color.Coral); break; case NetIncomingMessageType.StatusChanged: #region Status Changed Connected NetConnectionStatus status = (NetConnectionStatus)msg.ReadByte(); if (status == NetConnectionStatus.Connected) { FileLog.WriteLog($"Status changed to connected: {msg.SenderEndPoint.Address}", Color.Coral); Authentication.Player.Add(new PlayerData(msg.SenderConnection, NetUtility.ToHexString(msg.SenderConnection.RemoteUniqueIdentifier), msg.SenderEndPoint.Address.ToString())); } #endregion #region Status Changed Disconnected if (status == NetConnectionStatus.Disconnected) { if (pData == null) { return; } FileLog.WriteLog($"Status changed to disconnected: {pData?.ID} {pData?.Account} {msg?.SenderEndPoint.Address} {pData?.HexID}", Color.Coral); Accounts_DB.UpdateLastIP(pData.Account, pData.IP); Accounts_DB.UpdateLoggedIn(pData.Account, 0); //0 disconnect Accounts_DB.UpdateCurrentIP(pData.Account, string.Empty); //limpa o ip atual Authentication.Player.Remove(pData); } #endregion break; case NetIncomingMessageType.Data: LoginData.HandleData(pData.HexID, msg); break; default: //Registra qualquer mensagem invalida FileLog.WriteLog($"Unhandled type: {msg.MessageType}", Color.DarkRed); break; } LoginNetwork.socket.Recycle(msg); } }
/// <summary> /// Recebe os dados dos clientes. /// </summary> public static void ReceivedData() { NetIncomingMessage msg; while ((msg = Socket.ReadMessage()) != null) { var pData = Authentication.FindByConnection(msg.SenderConnection); switch (msg.MessageType) { case NetIncomingMessageType.DiscoveryRequest: #region Find Banned IP if (Accounts_DB.BannedIP(msg.SenderEndPoint.Address.ToString()) == true) { LogConfig.WriteLog("Warning: Attempted IP Banned " + msg.SenderEndPoint.Address); LogConfig.WriteLog("Warning: Attempted IP Banned " + msg.SenderEndPoint.Address, Color.Coral); return; } #endregion LoginServerNetwork.Socket.SendDiscoveryResponse(null, msg.SenderEndPoint); LogConfig.WriteLog($"Discovery Response IPEndPoint: {msg.SenderEndPoint.Address}", Color.Coral); break; case NetIncomingMessageType.ErrorMessage: LogConfig.WriteLog($"Error: {msg.ReadString()}", Color.Coral); break; case NetIncomingMessageType.StatusChanged: #region Status Changed Connected NetConnectionStatus status = (NetConnectionStatus)msg.ReadByte(); if (status == NetConnectionStatus.Connected) { LogConfig.WriteLog($"Status changed to connected: {msg.SenderEndPoint.Address}", Color.Coral); Authentication.Player.Add(new PlayerData(msg.SenderConnection, NetUtility.ToHexString(msg.SenderConnection.RemoteUniqueIdentifier), msg.SenderEndPoint.Address.ToString())); } #endregion #region Status Changed Disconnected if (status == NetConnectionStatus.Disconnected) { pData = Authentication.FindByHexID(NetUtility.ToHexString(msg.SenderConnection.RemoteUniqueIdentifier)); //1 - enabled, 0 - disabled if (Settings.LogSystem == 1) { LogConfig.WriteLog($"Status changed to disconnected: {pData?.ID} {pData?.Account} {msg.SenderEndPoint.Address} {pData.HexID}"); } if (!Settings.LogSystemScreen) { LogConfig.WriteLog($"Status changed to disconnected: {pData?.ID} {pData?.Account} {msg.SenderEndPoint.Address} {pData.HexID}", Color.Coral); } Accounts_DB.UpdateLastIP(pData.Account, pData.IP); Accounts_DB.UpdateLoggedIn(pData.Account, 0); //0 disconnect Accounts_DB.UpdateCurrentIP(pData.Account, ""); Authentication.Player.Remove(pData); } #endregion break; case NetIncomingMessageType.Data: LoginServerData.HandleData(pData.HexID, msg); break; default: //Registra qualquer mensagem invalida LogConfig.WriteLog($"Unhandled type: {msg.MessageType}", Color.DarkRed); break; } LoginServerNetwork.Socket.Recycle(msg); } }