public void Leave(PlayerData leavingPlayer, RoomLeaveReason reason = RoomLeaveReason.Normal) { var player = Players.Find(x => x.Data.ID == leavingPlayer.ID); player.SendRoomLeaveReason(reason); OnPlayerConnectionClosed(this, new PlayerConnectionClosed(player, PlayerCloseReason.Left)); }
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 Leave(Player plr, RoomLeaveReason roomLeaveReason = RoomLeaveReason.Left) { if (plr.Room != this) { return; } Group.Leave(plr.RelaySession.HostId); Broadcast(new SLeavePlayerAckMessage(plr.Account.Id, plr.Account.Nickname, roomLeaveReason)); if (roomLeaveReason == RoomLeaveReason.Kicked || roomLeaveReason == RoomLeaveReason.ModeratorKick || roomLeaveReason == RoomLeaveReason.VoteKick) { _kickedPlayers.TryAdd(plr.Account.Id, null); } plr.RoomInfo.PeerId = 0; plr.RoomInfo.Team.Leave(plr); _players.Remove(plr.Account.Id); plr.Room = null; plr.Session.SendAsync(new Network.Message.Game.SLeavePlayerAckMessage(plr.Account.Id)); OnPlayerLeft(new RoomPlayerEventArgs(plr)); if (_players.Count > 0) { if (Master == plr) { // Prioritize players that are ready // This makes it possible for players to give master to a specific player var newMaster = GetPlayerWithLowestPing(Players.Values.Where(x => x.RoomInfo.IsReady)) ?? GetPlayerWithLowestPing(); ChangeMaster(newMaster); } if (Host == plr) { ChangeHost(GetPlayerWithLowestPing()); } } else { RoomManager.Remove(this); } }
public void Leave(Player plr, RoomLeaveReason roomLeaveReason = RoomLeaveReason.Left) { if (plr.Room != this) { return; } Group.Leave(plr.RelaySession.HostId); Broadcast(new SLeavePlayerAckMessage(plr.Account.Id, plr.Account.Nickname, roomLeaveReason)); if (roomLeaveReason == RoomLeaveReason.Kicked || roomLeaveReason == RoomLeaveReason.ModeratorKick || roomLeaveReason == RoomLeaveReason.VoteKick) { _kickedPlayers.TryAdd(plr.Account.Id, null); } plr.RoomInfo.PeerId = 0; plr.RoomInfo.Team.Leave(plr); _players.Remove(plr.Account.Id); plr.Room = null; plr.Session.SendAsync(new Network.Message.Game.SLeavePlayerAckMessage(plr.Account.Id)); OnPlayerLeft(new RoomPlayerEventArgs(plr)); if (_players.Count > 0) { if (Master == plr) { ChangeMaster(GetPlayerWithLowestPing()); } if (Host == plr) { ChangeHost(GetPlayerWithLowestPing()); } } else { RoomManager.Remove(this); } }
public SLeavePlayerAckMessage(ulong accountId, string nickname, RoomLeaveReason reason) { AccountId = accountId; Nickname = nickname; Reason = reason; }
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 SendRoomLeaveReason(RoomLeaveReason reason) { var message = new ServerMessage.NotifyRoomLeave(reason); Socket.Send(message.AsJson()); }
public NotifyRoomLeave(RoomLeaveReason reason) { Reason = reason; }
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()); } } }