internal IPromise <Nothing> KickPlayer(PlayerHandle handle, string reason = "") { Log.Information("Kicking player {player}/{hash}/{endpoint} due to {reason}, terminating shortly after", handle.Name, handle.Stream.ConnectionHash, handle.Stream.ConnectionEndpoint, reason); this.PlayerLoggedOff(handle); return(handle.Terminate(new ErrorException("terminated", reason))); }
internal override bool Validate(PlayerHandle sender, ChatManager server) { ErrorException exception = null; try { this.user = this.loginService.AuthorizeUser(this.token); this.character = this.characterService.LoginCharacter(user, this.id, this.name, this.sex); PlayerHandle sameUserPlayer; lock (server) { sameUserPlayer = server.World.FindPlayerByUser(user); } if (sameUserPlayer != null) { server.KickPlayer(sameUserPlayer, Strings.LOGGED_IN_AS_ANOTHER_CHAR); } PlayerHandle sameNamePlayer; lock (server) { sameNamePlayer = server.World.FindPlayer(this.name); } if (sameNamePlayer != null) { server.KickPlayer(sameNamePlayer, Strings.LOGGED_IN_IN_ANOTHER_INSTANCE); } } catch (LoginService.InvalidTokenException) { exception = new ErrorException("invalid token", Strings.LOGIN_TOKEN_INVALID); } catch (CharacterService.NotAuthorizedException) { exception = new ErrorException("not authorized", Strings.NOT_AUTHORIZED_TO_PLAY_AS_THIS_CHARACTER); } catch (CharacterService.NotFoundException) { exception = new ErrorException("not found", Strings.CHARACTER_NOT_FOUND); } catch (ErrorException e) { exception = e; } catch (Exception e) { Log.Warning("Failed to login character {name}/{token}: {exception}", this.name, this.token, e); exception = new ErrorException("internal", Strings.INTERNAL_SERVER_ERROR); } if (exception != null) { Log.Information("Kicking connection of {name}/{id} from {hash}/{address} - {message}, terminating shortly after", this.name, this.id, sender.Stream.ConnectionHash, sender.Stream.ConnectionEndpoint, exception.Message); sender.Terminate(exception); return(false); } else { return(true); } }