private void StartConnectionWithClient() { this.ClientIP = ((IPEndPoint)ClientSocket.RemoteEndPoint).Address.ToString(); this.ClientPort = ((IPEndPoint)ClientSocket.RemoteEndPoint).Port; if (MainManager.ChatSecurePasswordConnection) { int AttemptionsCount = MainManager.AttemptionsCount(ClientIP); if (AttemptionsCount != -1) { if ((DateTime.Now - (MainManager.GetAttemptions(ClientIP).LastAttemption)).TotalHours < 24) { if ((MainManager.GetAttemptions(ClientIP).Attemptions >= MainManager.MaxAttemptionsPerDay)) { ClientSocket.Close(); return; } } else { MainManager.DischargeAttemptions(ClientIP); } } AuntificationState state; PasswordChecker(out state); switch (state) { case AuntificationState.WrongPassword: MainManager.AddAttemption(ClientIP); ClientSocket.Send(Encoding.UTF8.GetBytes("Wrong Password! Enter correct password")); ClientSocket.Close(); return; case AuntificationState.Error: ClientSocket.Send(Encoding.UTF8.GetBytes("Something went wrong, try again")); ClientSocket.Close(); return; case AuntificationState.Successfully: ConnectedAt = DateTime.Now; this.ClientID = MainManager.ChatClients.Count + 1; Logger.NetworkChatLog($"User with IP: {ClientIP}:{ClientPort}, Successfully connected to the Network chat. ChatClientID: {this.ClientID}"); ClientSocket.Send(Encoding.UTF8.GetBytes("The password is correct, you have successfully connected to the chat.")); MainManager.DischargeAttemptions(ClientIP); break; } } MainManager.ChatClients.Add(this); msgdelegate = new MainManager.onNewMessageDelegate(TX); onPlayerConnectedDelegate = new NetworkPlayerDelegate(onPlayerConnectedTX); onPlayerDisconnectedDelegate = new NetworkPlayerDelegate(onPlayerDisconnectedTX); new Thread(RX).Start(); MainManager.onMessage += msgdelegate; NetworkEvents.onPlayerConnected += onPlayerConnectedDelegate; NetworkEvents.onPlayerDisconnected += onPlayerDisconnectedDelegate; }
private void StartConnectionWithClient() { this.ClientIP = EndPoint.Address.ToString(); this.ClientPort = EndPoint.Port; int AttemptionsCount = MainManager.AttemptionsCount(ClientIP); if (AttemptionsCount != -1) { if ((DateTime.Now - (MainManager.GetAttemptions(ClientIP).LastAttemption)).TotalHours < 24) { if ((MainManager.GetAttemptions(ClientIP).Attemptions >= MainManager.MaxAttemptionsPerDay)) { ClientSocket.Close(); return; } } else { MainManager.DischargeAttemptions(ClientIP); } } AuntificationState state; NetworkAccount acc = Login(out state); this.Account = acc; switch (state) { case AuntificationState.WrongPassword: MainManager.AddAttemption(ClientIP); SendMessage("Wrong Password! Enter correct password"); return; case AuntificationState.Error: SendMessage("Something went wrong, try again"); return; case AuntificationState.Successfully: this.ClientID = MainManager.CommandsClients.Count + 1; ConnectedAt = DateTime.Now; SendMessage("The password is correct, you have successfully entered to the RCON"); Logger.NetworkCommandsLog($"User with IP: {ClientIP}:{ClientPort}, Login: {this.Account.Login}, Connected to the RCON. ClientID {this.ClientID}"); MainManager.DischargeAttemptions(ClientIP); break; } MainManager.CommandsClients.Add(this); new Thread(CommandsChecker).Start(); }