public void Leave(Player plr, RoomLeaveReason roomLeaveReason = RoomLeaveReason.Left) { if (plr == null) { return; } if (plr.Room != this) { return; } if (_players.ContainsKey(plr.Account?.Id ?? 0)) { if (roomLeaveReason == RoomLeaveReason.Kicked || roomLeaveReason == RoomLeaveReason.ModeratorKick || roomLeaveReason == RoomLeaveReason.VoteKick) { _kickedPlayers.TryAdd(plr.Account.Id, null); } plr.RelaySession?.P2PGroup?.Leave(plr.RelaySession.HostId); Broadcast(new RoomLeavePlayerAckMessage(plr.Account.Id, plr.Account.Nickname, roomLeaveReason)); _players.Remove(plr.Account.Id, out _); TeamManager.Leave(plr); plr.RoomInfo.PeerId = 0; plr.Room = null; plr.SendAsync(new RoomLeavePlayerInfoAckMessage(plr.Account.Id)); plr.SendAsync(new ItemClearInvalidEquipItemAckMessage()); plr.SendAsync(new ItemClearEsperChipAckMessage()); plr.Channel?.BroadcastExcept(plr, new ChannelEnterPlayerAckMessage(plr.Map <Player, PlayerInfoShortDto>())); plr.Channel?.SendPlayerlist(plr); if (TeamManager.Players.Any()) { ChangeMasterIfNeeded(GetPlayerWithLowestPing()); ChangeHostIfNeeded(GetPlayerWithLowestPing()); OnPlayerLeft(new RoomPlayerEventArgs(plr)); } else { RoomManager?.Remove(this); } } }
public void Update(TimeSpan delta) { try { if (!(RoomManager?.Contains(this) ?? false)) { return; } if (Players.Count == 0 || !TeamManager.Players.Any()) { if (Master.Room == this && !Master.IsLoggedIn()) { RoomManager?.Remove(this); } return; } if (!(Master?.IsLoggedIn() ?? true) || Master?.Room != this) { ChangeMasterIfNeeded(GetPlayerWithLowestPing(), true); ChangeHostIfNeeded(GetPlayerWithLowestPing(), true); } if (IsChangingRules) { _changingRulesTimer += delta; if (_changingRulesTimer >= _changingRulesTime && IsChangingRulesCooldown != true) { RoomManager.Channel.BroadcastCencored(new RoomChangeRoomInfoAck2Message(GetRoomInfo())); Broadcast(new RoomChangeRuleAckMessage(Options.Map <RoomCreationOptions, ChangeRuleDto>())); Broadcast(new GameChangeStateAckMessage(GameState)); IsChangingRulesCooldown = true; } if (_changingRulesTimer >= _changingRulesTime.Add(TimeSpan.FromSeconds(3))) { IsChangingRules = false; IsChangingRulesCooldown = false; } } } catch (Exception e) { Logger.Error(e.ToString()); } GameRuleManager.Update(delta); }
public void Leave(Player plr, RoomLeaveReason roomLeaveReason = RoomLeaveReason.Left) { if (plr.Room != this) { return; } try { if (plr.RelaySession?.HostId != null) { Group?.Leave(plr.RelaySession.HostId); } Broadcast(new RoomLeavePlayerAckMessage(plr.Account.Id, plr.Account.Nickname, roomLeaveReason)); Broadcast(new RoomLeavePlayerInfoAckMessage(plr.Account.Id)); if (roomLeaveReason == RoomLeaveReason.Kicked || roomLeaveReason == RoomLeaveReason.ModeratorKick || roomLeaveReason == RoomLeaveReason.VoteKick) { _kickedPlayers.TryAdd(plr.Account.Id, null); } plr.LocationInfo.Invisible = false; var curchannelid = (uint)plr.Channel.Id; plr.Channel.Leave(plr, true); GameServer.Instance.ChannelManager[curchannelid].Join(plr); plr.RoomInfo.PeerId = 0; plr.RoomInfo?.Team?.Leave(plr); _players?.Remove(plr.Account.Id); plr.Room = null; if (_players != null && _players.Count > 0) { if (Master == plr) { ChangeMasterIfNeeded(GetPlayerWithLowestPing(), true); } if (Host == plr) { ChangeHostIfNeeded(GetPlayerWithLowestPing(), true); } OnPlayerLeft(new RoomPlayerEventArgs(plr)); } else { RoomManager.Remove(this); } } catch (Exception ex) { Broadcast(new RoomLeavePlayerAckMessage(plr.Account.Id, plr.Account.Nickname, roomLeaveReason)); Broadcast(new RoomLeavePlayerInfoAckMessage(plr.Account.Id)); if (_players.Count == 1) { plr?.Channel?.RoomManager?.Remove(this); } _players?.Remove(plr.Account.Id); Logger.Error(ex.ToString()); } }
public void Update(TimeSpan delta) { try { if (!(RoomManager?.Contains(this) ?? false)) { return; } if (Players.Count == 0 || !TeamManager.Players.Any()) { if (Master.Room == this && !Master.IsLoggedIn()) { RoomManager?.Remove(this); } return; } //if (Host != null) //{ // _hostUpdateTimer += delta; // if (_hostUpdateTimer >= _hostUpdateTime) // { // var lowest = GetPlayerWithLowestPing(); // if (Host != lowest) // { // var diff = Math.Abs(Host.Session.UnreliablePing - lowest.Session.UnreliablePing); // if (diff >= PingDifferenceForChange) // ChangeHostIfNeeded(lowest, true); // } // // _hostUpdateTimer = TimeSpan.Zero; // } //} if (IsChangingRules) { _changingRulesTimer += delta; if (_changingRulesTimer >= _changingRulesTime && IsChangingRulesCooldown != true) { GameRuleManager.MapInfo = GameServer.Instance.ResourceCache.GetMaps()[Options.MapID]; GameRuleManager.GameRule = RoomManager.GameRuleFactory.Get(Options.GameRule, this); Broadcast(new RoomChangeRuleAckMessage(Options.Map <RoomCreationOptions, ChangeRuleDto>())); Broadcast(new RoomChangeRuleFailAckMessage { Result = 0 }); BroadcastBriefing(); IsChangingRulesCooldown = true; } if (_changingRulesTimer >= _changingRulesTime.Add(TimeSpan.FromSeconds(3))) { IsChangingRules = false; IsChangingRulesCooldown = false; } } } catch (Exception e) { Logger.Error(e.ToString()); } GameRuleManager.Update(delta); }
public void Leave(Player plr, RoomLeaveReason roomLeaveReason = RoomLeaveReason.Left) { using (_playerSync.Lock()) { if (plr.Room != this) { return; } try { if (plr.RelaySession?.HostId != null) { Group?.Leave(plr.RelaySession.HostId); } Broadcast(new RoomLeavePlayerAckMessage(plr.Account.Id, plr.Account.Nickname, roomLeaveReason)); if (roomLeaveReason == RoomLeaveReason.Kicked || roomLeaveReason == RoomLeaveReason.ModeratorKick || roomLeaveReason == RoomLeaveReason.VoteKick) { _kickedPlayers.TryAdd(plr.Account.Id, null); } plr.LocationInfo.Invisible = false; var curchannelid = (uint)(plr.Channel?.Id ?? 0); plr.Channel?.Leave(plr, true); GameServer.Instance.ChannelManager[curchannelid].Join(plr); plr.RoomInfo.PeerId = 0; plr.RoomInfo.Team?.Leave(plr); _players?.Remove(plr.Account.Id); plr.Room = null; plr.Session?.SendAsync(new RoomLeavePlayerInfoAckMessage(plr.Account.Id)); plr.Session?.SendAsync( new ItemClearInvalidEquipItemAckMessage { Items = new InvalidateItemInfoDto[] { } }); plr.Session?.SendAsync(new ItemClearEsperChipAckMessage { Unk = new ClearEsperChipDto[] { } }); if (GameState == GameState.Playing) { plr.stats.Loss++; } if (TeamManager.Players.Any()) { ChangeMasterIfNeeded(GetPlayerWithLowestPing()); ChangeHostIfNeeded(GetPlayerWithLowestPing()); OnPlayerLeft(new RoomPlayerEventArgs(plr)); } else { RoomManager.Remove(this); } } catch (Exception ex) { Broadcast(new RoomLeavePlayerAckMessage(plr.Account.Id, plr.Account.Nickname, roomLeaveReason)); Broadcast(new RoomLeavePlayerInfoAckMessage(plr.Account.Id)); _players?.Remove(plr.Account.Id); Logger.Error(ex.ToString()); } } }
public void Update(AccurateDelta delta) { if (Disposed) { return; } try { if (!Players.Any()) { RoomManager.Remove(this); return; } if (!(Master?.IsLoggedIn() ?? true) || Master?.Room != this) { ChangeMasterIfNeeded(GetPlayerWithLowestPing(), true); ChangeHostIfNeeded(GetPlayerWithLowestPing(), true); } if (!TeamManager.NoSpectatorPlayers.Any() && TeamManager.Players.Any()) { foreach (var spectator in TeamManager.Spectators) { TeamManager.ChangeMode(spectator, PlayerGameMode.Normal); } } if (IsChangingRules) { _changingRulesTimer += delta.delta; if (_changingRulesTimer >= _changingRulesTime && !IsChangingRulesCooldown) { RoomManager.Channel.BroadcastCencored(new RoomChangeRoomInfoAck2Message(GetRoomInfo())); Broadcast(new RoomChangeRuleAckMessage(Options.Map <RoomCreationOptions, ChangeRuleDto2>())); Broadcast(new GameChangeStateAckMessage(GameState)); IsChangingRulesCooldown = true; } foreach (var player in _players.Values) { player.RoomInfo.LastMapID = (byte)Options.MapId; } if (_changingRulesTimer >= _changingRulesTime.Add(TimeSpan.FromSeconds(3))) { IsChangingRules = false; IsChangingRulesCooldown = false; } } else { foreach (var player in Players.Values.Where(x => !TeamManager.Players.Contains(x))) { TeamManager.Join(player); } } if (VoteKickMgr.State == VoteKickManager.KickState.Execution) { _voteKicktimer += delta.delta; if (_voteKicktimer < _voteKickTime) { VoteKickMgr.Update(); } else { _voteKicktimer = TimeSpan.Zero; VoteKickMgr.Evaluate(); } } } catch (Exception e) { Logger.Error(e.ToString()); } GameRuleManager?.Update(delta); }