private bool CheckIfUserDeletedOrModified(User user) { List <User> remoteUsers = ServerSystemController.GetRegisteredUsers(); List <User> filteredListed = remoteUsers.Where(p => p.Id == user.Id).ToList(); if (filteredListed.Count > 0) { User userInList = filteredListed[0]; if (userInList.NickName != user.NickName) { User userInServer = RegisteredUsers.FirstOrDefault(x => x.Value.NickName.Equals(user.NickName)).Value; TcpClient clientInServer = RegisteredUsers.FirstOrDefault(x => x.Value.NickName.Equals(user.NickName)).Key; RegisteredUsers.Remove(clientInServer); userInServer.NickName = userInList.NickName; RegisteredUsers.Add(clientInServer, userInServer); showRegisteredPlayers(); showConnectedPlayers(); } return(true); } else { return(false); } }
private void sendAuthorizatonData(string data, NetworkStream nws, TcpClient client, ref User user) { List <User> remoteUsers = ServerSystemController.GetRegisteredUsers(); byte[] responseStream; lock (registrationLock) { if (!remoteUsers.Contains(user)) { RegisteredUsers.Add(client, user); ServerSystemController.AddUserToSystem(user); showRegisteredPlayers(); showConnectedPlayers(); responseStream = Protocol.GenerateStream(ProtocolConstants.SendType.RESPONSE, ProtocolConstants.LOGIN, ProtocolConstants.OK_RESPONSE_CODE); } else { if (RegisteredUsers.ContainsValue(user)) { User userInServer = RegisteredUsers.FirstOrDefault(x => x.Value.NickName.Equals(data)).Value; TcpClient clientInServer = RegisteredUsers.FirstOrDefault(x => x.Value.NickName.Equals(data)).Key; if (userInServer.Connected) { responseStream = Protocol.GenerateStream(ProtocolConstants.SendType.RESPONSE, ProtocolConstants.LOGIN, "400"); } else { User userFromServer = ServerSystemController.GetUserInServer(user); RegisteredUsers.Remove(clientInServer); RegisteredUsers.Add(client, userFromServer); showRegisteredPlayers(); showConnectedPlayers(); responseStream = Protocol.GenerateStream(ProtocolConstants.SendType.RESPONSE, ProtocolConstants.LOGIN, ProtocolConstants.OK_RESPONSE_CODE); } } else { User userFromServer = ServerSystemController.GetUserInServer(user); RegisteredUsers.Add(client, userFromServer); showRegisteredPlayers(); showConnectedPlayers(); responseStream = Protocol.GenerateStream(ProtocolConstants.SendType.RESPONSE, ProtocolConstants.LOGIN, ProtocolConstants.OK_RESPONSE_CODE); } } nws.Write(responseStream, 0, responseStream.Length); } }
public bool UnRegisterUser(LoginUserInfo info) { if (RegisteredUsers.ContainsKey(info.AccountID)) { if (info.Status >= LoginStatus.在线) { KickUser(info.AccountID, 0, LogoutReason.系统踢出, null); } if (info.ParentGroup != null) { info.ParentGroup.RemoveUser(info.AccountID); } return(RegisteredUsers.Remove(info.AccountID)); } return(false); }