Exemple #1
0
        public void ChannelInfoReq(GameSession session, ChannelInfoReqMessage message)
        {
            if (session.Player.Room != null)
            {
                return;
            }

            if (session.Player.Channel == null)
            {
                try
                {
                    GameServer.Instance.ChannelManager[0].Join(session.Player);
                }
                catch (Exception)
                {
                    //ignored
                }
            }

            try
            {
                switch (message.Request)
                {
                case ChannelInfoRequest.ChannelList:
                    var channels = GameServer.Instance.ChannelManager.Select(c => c.Map <Channel, ChannelInfoDto>())
                                   .ToArray();
                    channels = channels.Skip(1).ToArray();
                    foreach (var channel in channels)
                    {
                        if (channel.Name.Contains("Clan"))
                        {
                            channel.IsClanChannel = true;
                        }
                    }

                    session.SendAsync(new ChannelListInfoAckMessage(channels));
                    break;

                case ChannelInfoRequest.RoomList:
                case ChannelInfoRequest.RoomList2:
                    if (session.Player?.Channel == null)
                    {
                        return;
                    }

                    var roomlist2 = new List <RoomDto>();
                    foreach (var room in session.Player.Channel.RoomManager)
                    {
                        if (room == null || room.Disposed)
                        {
                            continue;
                        }

                        if (!room.TeamManager.Players.Any())
                        {
                            continue;
                        }

                        var temproom2 = room.GetRoomInfo();
                        temproom2.Password =
                            !string.IsNullOrWhiteSpace(room.Options.Password) ||
                            !string.IsNullOrEmpty(room.Options.Password)
                      ? "nice try :)"
                      : string.Empty;
                        roomlist2.Add(temproom2);
                    }

                    session.SendAsync(new RoomListInfoAck2Message(roomlist2.ToArray()),
                                      SendOptions.ReliableSecureCompress);
                    break;

                default:
                    Logger.ForAccount(session)
                    .Error("Invalid request {request}", message.Request);
                    break;
                }
            }
            catch (Exception e)
            {
                Logger.Error(e.ToString());
            }

            if (session.ConnectDate.Add(TimeSpan.FromMinutes(5)) >
                DateTimeOffset.Now)
            {
                session.ConnectDate = DateTimeOffset.Now;
                session.Player.BE.EnableBE();
            }
        }
        public void ChannelInfoReq(GameSession session, ChannelInfoReqMessage message)
        {
            if (session.Player.Room != null)
            {
                return;
            }
            if (session.Player.Channel == null)
            {
                try
                {
                    GameServer.Instance.ChannelManager[0].Join(session.Player, true);
                }
                catch (Exception ex)
                {
                }
            }
            switch (message.Request)
            {
            case ChannelInfoRequest.ChannelList:

                var channels = GameServer.Instance.ChannelManager.Select(c => c.Map <Channel, ChannelInfoDto>())
                               .ToArray();
                channels = channels.Skip(1).ToArray();

                foreach (var channel in channels)
                {
                    if (channel.Name.Contains("Clan"))
                    {
                        channel.IsClanChannel = true;
                    }
                }
                session.SendAsync(new ChannelListInfoAckMessage(channels));
                break;

            case ChannelInfoRequest.RoomList:
            case ChannelInfoRequest.RoomList2:
                if (session.Player.Channel == null)
                {
                    return;
                }
                var roomlist2 = new List <RoomDto>();
                foreach (var room in session.Player.Channel.RoomManager.Where(x => !x.TeamManager.Players.Any()))
                {
                    var temproom2 = room.GetRoomInfo();
                    temproom2.Password =
                        !string.IsNullOrWhiteSpace(room.Options.Password) ||
                        !string.IsNullOrEmpty(room.Options.Password)
                                ? "nice try :)"
                                : "";
                    roomlist2.Add(temproom2);
                }
                session.SendAsync(new RoomListInfoAck2Message(roomlist2.ToArray()));
                foreach (var room in session.Player.Channel.RoomManager.Where(x => !x.TeamManager.Players.Any()))
                {
                    session.Player.Channel.RoomManager.Remove(room);
                }
                break;

            default:
                Logger.ForAccount(session)
                .Error("Invalid request {request}", message.Request);
                break;
            }
        }
        public void ChannelInfoReq(GameSession session, ChannelInfoReqMessage message)
        {
            if (session.Player.Channel == null)
            {
                try
                {
                    GameServer.Instance.ChannelManager[0].Join(session.Player, true);
                }
                catch (Exception ex)
                {
                }
            }
            switch (message.Request)
            {
            case ChannelInfoRequest.ChannelList:

                ChannelInfoDto[] channels = GameServer.Instance.ChannelManager.Select(c => c.Map <Channel, ChannelInfoDto>()).ToArray();
                channels = channels.Skip(1).ToArray();

                foreach (ChannelInfoDto channel in channels)
                {
                    if (channel.Name.Contains("Clan"))
                    {
                        channel.IsClanChannel = true;
                    }
                }
                session.SendAsync(new ChannelListInfoAckMessage(channels));
                break;

            case ChannelInfoRequest.RoomList:
            case ChannelInfoRequest.RoomList2:
                if (session.Player.Channel == null)
                {
                    return;
                }
                List <RoomDto> roomlist = new List <RoomDto>();

                foreach (Room room in session.Player.Channel.RoomManager)
                {
                    RoomDto temproom = new RoomDto();
                    temproom.RoomId      = (byte)room.Id;
                    temproom.PlayerCount = (byte)room.Players.Count;
                    temproom.PlayerLimit = room.Options.PlayerLimit;
                    temproom.State       = (byte)room.GameRuleManager.GameRule.StateMachine.State;
                    temproom.State2      = (byte)room.GameRuleManager.GameRule.StateMachine.State;
                    temproom.GameRule    = (int)room.Options.GameRule;
                    temproom.Map         = (byte)room.Options.MapID;
                    temproom.WeaponLimit = room.Options.ItemLimit;
                    temproom.Name        = room.Options.Name;
                    temproom.Password    = room.Options.Password;
                    temproom.FMBURNMode  = room.GetFMBurnModeInfo();
                    roomlist.Add(temproom);
                }

                RoomDto[] rooms = roomlist.ToArray();
                session.SendAsync(new RoomListInfoAck2Message(rooms));

                // RoomDto[] rooms = new RoomDto[51];

                //for (int i = 0; i < 51; i++)
                //{
                //    rooms[i] = new RoomDto();
                //    rooms[i].RoomId = (byte)i;
                //    rooms[i].PlayerCount = 1;
                //    rooms[i].PlayerLimit = 12;
                //    rooms[i].State = (byte)0;
                //    rooms[i].State2 = 0;
                //    rooms[i].GameRule = (int)GameRule.Touchdown;
                //    rooms[i].Map = 66;
                //    rooms[i].WeaponLimit = 0;
                //    rooms[i].Name = $"Testroom{i}";
                //    rooms[i].Password = "";
                //    //rooms[i].Unk1 = 0;
                //    //rooms[i].Unk2 = 0;
                //}

                //int count = 0;
                //foreach (Room room in session.Player.Channel.RoomManager)
                //{
                //    count++;
                //}
                //RoomDto[] rooms = new RoomDto[count];
                //
                //for (uint i = 0; i <= session.Player.Channel.RoomManager.Count; i++)
                //{
                //    rooms[i] = new RoomDto();
                //    rooms[i].RoomId = (byte)session.Player.Channel.RoomManager[i].Id;
                //    rooms[i].PlayerCount = (byte)session.Player.Channel.RoomManager[i].Players.Count;
                //    rooms[i].PlayerLimit = session.Player.Channel.RoomManager[i].Options.PlayerLimit;
                //    rooms[i].State = (byte)0;
                //    rooms[i].GameRule = (int)session.Player.Channel.RoomManager[i].Options.GameRule;
                //    rooms[i].Map = session.Player.Channel.RoomManager[i].Options.MapID;
                //    rooms[i].WeaponLimit = session.Player.Channel.RoomManager[i].Options.ItemLimit;
                //    rooms[i].Name = session.Player.Channel.RoomManager[i].Options.Name;
                //    rooms[i].Password = session.Player.Channel.RoomManager[i].Options.Password;
                //}
                //session.SendAsync(new RoomListInfoAckMessage(session.Player.Channel.RoomManager.Select(r => r.Map<Room, RoomDto>()).ToArray()));

                break;

            default:
                Logger.ForAccount(session)
                .Error("Invalid request {request}", message.Request);
                break;
            }
        }