internal bool _EmitPlayerPreJoin(object user) { if (user == null || !(user is User castedUser)) { return(false); } EcoPlayer ecoPlayer = playerManager?.InternalPlayersList.FirstOrDefault(x => x.Id.Equals(castedUser.SlgId) || x.Id.Equals(castedUser.SteamId)); if (ecoPlayer == null) { ecoPlayer = new EcoPlayer(castedUser, playerManager, runtime.Container); playerManager?.InternalPlayersList.Add(ecoPlayer); } else if (ecoPlayer.InternalEcoUser == null) { ecoPlayer.BuildReference(castedUser); } logger.LogDebug($"Emitting PlayerPreConnectEvent [{ecoPlayer.Id}]"); PlayerPreConnectEvent e = new PlayerPreConnectEvent(ecoPlayer); eventManager.Emit(this, e); if (!e.IsCancelled) { return(true); } logger.LogInformation($"[{ecoPlayer.Id}] {ecoPlayer.Name} was prevent from joining for the reason: " + (e.RejectionReason ?? "No reason was supplied.")); ecoPlayer.InternalEcoPlayer.Client.Disconnect("You have been prevented from joining.", e.RejectionReason ?? "No reason was supplied."); return(false); }
public void HandleEvent(IEventEmitter emitter, PlayerPreConnectEvent @event) { if (Database.IsBanned(@event.Player)) { @event.RejectionReason = "You have been banned."; @event.IsCancelled = true; } }