private void KickLoser(Player player) { var players = _players.ToList(); players.Remove(player); var updatedPlayers = new Queue <Player>(); foreach (var p in players) { updatedPlayers.Enqueue(p); } if (updatedPlayers.Count == 1) { GameEnded?.Invoke(this, new GameEndedEvent { Winner = updatedPlayers.First() }); } _players = updatedPlayers; PlayerKicked?.Invoke(this, new PlayerKickedEvent { Player = player }); }
/// <summary> /// Hooks into EAC checks and exposes events for it; /// MUST be called after in GameStartDone or later /// </summary> public static void Init() { //if (_isInitialized) // throw new InvalidOperationException(nameof(EacTools) + "." + nameof(Init) + " may only be called once."); Log.Debug("Hooking into the EAC response callbacks ..."); if (EACServer.Instance == null) { throw new ApplicationException("Cannot activate EAC monitoring because EAC server is not (yet) started."); } var successDelegate = EACServer.Instance.GetSuccessDelegate(); var kickDelegate = EACServer.Instance.GetKickDelegate(); if (successDelegate == null || kickDelegate == null) { throw new ApplicationException("Cannot activate EAC monitoring because success and kick delegates are not (yet) set."); } var kickDelegateNew = new KickPlayerDelegate(delegate(ClientInfo info, GameUtils.KickPlayerData data) { if (PersistentData.Instance.EacWhitelist.Contains(info.playerId)) { Log.Out($"EAC check failed but player \"{info.playerName}\" ({info.playerId}) is exempt from EAC kicks."); // Call success delegate instead successDelegate(info); } else { // Let original kick delegate handle it kickDelegate(info, data); PlayerKicked?.Invoke(info, data); } }); // Replace original kick delegate with our new modified one EACServer.Instance.SetKickDelegate(kickDelegateNew); var successDelegateNew = new AuthenticationSuccessfulCallbackDelegate(delegate(ClientInfo info) { // Let original kick delegate handle it successDelegate(info); AuthenticationSuccessful?.Invoke(info); }); // Replace original success delegate with our new modified one EACServer.Instance.SetSuccessDelegate(successDelegateNew); //_isInitialized = true; Log.Debug("EAC monitoring activated."); }
internal void RaiseClientKicked(ulong user) { PlayerKicked?.Invoke(user); }