Exemplo n.º 1
0
        protected override void TakeRemote()
        {
            TraceLog.ReleaseWrite("Player:{0} match success", m_RequestPacket.PlayerId.ToString());
            LCPushPvpMatchSuccess package = new LCPushPvpMatchSuccess()
            {
                RoomId         = m_RequestPacket.RoomId,
                InstanceId     = m_RequestPacket.InstanceId,
                Token          = m_RequestPacket.Token,
                RoomServerHost = m_RequestPacket.RoomServerHost,
                RoomServerPort = m_RequestPacket.RoomServerPort,
                EnemyInfo      = m_RequestPacket.EnemyInfo,
            };

            byte[] buffer = CustomActionDispatcher.GeneratePackageStream(package.PacketActionId, ProtoBufUtils.Serialize(package));
            try
            {
                GameSession.Get(m_RequestPacket.PlayerId).SendAsync(buffer, 0, buffer.Length);
            }
            catch
            {
                return;
            }
        }
Exemplo n.º 2
0
        public static void ExecuteMatch(object state)
        {
            var queues = CacheSet.PVPMathcQueueCache.FindAll();
            PlayerSinglePvpLogic psp = new PlayerSinglePvpLogic();

            foreach (var queue in queues)
            {
                if (queue.InQueueGroups.Count <= 1)
                {
                    continue;
                }
                if (queue.MatchedGroupCount > 0)
                {
                    ClearMatchedGroups(queue);
                }
                var groups = new List <PVPGroup>();
                groups.AddRange(queue.InQueueGroups);
                groups.Sort();
                for (int i = 0; i < groups.Count; i++)
                {
                    if (i + 1 >= groups.Count)
                    {
                        break;
                    }
                    bool            success  = true;
                    LRCreateNewRoom userData = new LRCreateNewRoom();
                    foreach (int playerId in groups[i].Players)
                    {
                        if (!GameSession.Get(playerId).Connected)
                        {
                            queue.InQueueGroups.RemoveAt(i);
                            success = false;
                            break;
                        }
                        PBRoomPlayerInfo playerRoomData = GetPlayerRoomData(playerId);
                        userData.RoomPlayerInfo.Add(playerRoomData);
                    }
                    if (!success)
                    {
                        continue;
                    }
                    foreach (int playerId in groups[++i].Players)
                    {
                        if (!GameSession.Get(playerId).Connected)
                        {
                            queue.InQueueGroups.RemoveAt(i);
                            success = false;
                            break;
                        }
                        PBRoomPlayerInfo playerRoomData = GetPlayerRoomData(playerId);
                        userData.RoomPlayerInfo.Add(playerRoomData);
                    }
                    if (!success)
                    {
                        continue;
                    }

                    userData.Token = GetToken();

                    var room = RoomServerManager.GetLowestLoadedRoomServer();
                    TraceLog.Write("room" + room.Id.ToString() + "::" + room.IP);
                    RoomServerSender.Send(room.Id, "LRCreateNewRoomHandler", userData, delegate(RemotePackage callback)
                    {
                        var res = RemoteCommunication.ParseRemotePackage <RLCreateNewRoom>(callback.Message as byte[]);
                        LCPushPvpMatchSuccess package = new LCPushPvpMatchSuccess()
                        {
                            RoomId = res.RoomId, RoomServerHost = room.Host, RoomServerPort = room.Port, Token = userData.Token, InstanceId = res.InstanceId
                        };
                        var rank = RankingFactory.Get <SinglePvpRankUser>("SinglePvpRanking");

                        foreach (int playerId in groups[queue.MatchedGroupCount].Players)
                        {
                            foreach (var rp in userData.RoomPlayerInfo)
                            {
                                if (rp.PlayerInfo.Id != playerId)
                                {
                                    package.EnemyInfo = rp;
                                }
                            }
                            byte[] buffer = CustomActionDispatcher.GeneratePackageStream(package.PacketActionId, ProtoBufUtils.Serialize(package));

                            try
                            {
                                GameSession.Get(playerId).SendAsync(buffer, 0, buffer.Length);
                            }
                            catch
                            {
                                continue;
                            }
                        }
                        foreach (int playerId in groups[queue.MatchedGroupCount + 1].Players)
                        {
                            foreach (var rp in userData.RoomPlayerInfo)
                            {
                                if (rp.PlayerInfo.Id != playerId)
                                {
                                    package.EnemyInfo = rp;
                                }
                            }
                            byte[] buffer = CustomActionDispatcher.GeneratePackageStream(package.PacketActionId, ProtoBufUtils.Serialize(package));
                            try
                            {
                                GameSession.Get(playerId).SendAsync(buffer, 0, buffer.Length);
                            }
                            catch
                            {
                                continue;
                            }
                        }
                        queue.MatchedGroupCount += 2;
                    });
                }
                ClearMatchedGroups(queue);
            }
        }