Ejemplo n.º 1
0
        public static void HandleGameChallengeAccept(object packet, Session session)
        {
            var gameChallangeAccept = (PacketGameChallengeAccept)packet;

            Session opponentSession = WorldManager.GetPlayerSession(gameChallangeAccept.ProfileId);
            if (opponentSession != null)
            {
                if (BattleManager.Battles.ContainsKey(session.Player.Id))
                    LogManager.Write("Lobby handler", "player {0} wants to play several quickmatches at once ! Not possible !", session.Player.Id);
                else if (BattleManager.Battles.ContainsKey(opponentSession.Player.Id))
                    LogManager.Write("Lobby handler", "player {0} wants to play several quickmatches at once ! Not possible !", opponentSession.Player.Id);
                else
                {
                    // TODO: handle this better
                    /*BattleType[] typesToAbort = new BattleType[3] { BattleType.MP_QUICKMATCH, BattleType.MP_RANKED, BattleType.MP_LIMITED };
                    foreach (BattleType battleType in typesToAbort)
                    {
                        var cancelQueue = new PacketGameMatchQueueStatus()
                        {
                            InQueue = false,
                            GameType = battleType
                        };
                        session.Send(cancelQueue);
                        opponentSession.Send(cancelQueue);
                    }*/

                    PacketGameChallengeResponse gameChallenge = new PacketGameChallengeResponse()
                    {
                        From   = opponentSession.Player.GeneratePacketProfile(),
                        To     = session.Player.GeneratePacketProfile(),
                        Status = "ACCEPT"
                    };

                    opponentSession.Send(gameChallenge);
                    session.SendOkPacket("GameChallengeAccept");

                    Random random = new Random();
                    PlayerColor challengerColor, challengedColor;
                    if (random.Next(2) > 0)
                    {
                        challengerColor = PlayerColor.white;
                        challengedColor = PlayerColor.black;
                    }
                    else
                    {
                        challengedColor = PlayerColor.white;
                        challengerColor = PlayerColor.black;
                    }

                    Battle newBattle = new Battle(BattleType.MP_UNRANKED);
                    BattleSide challengedSide = new BattleSide(session.Player.Id, session.Player.Username, challengedColor);
                    BattleSide challengerSide = new BattleSide(opponentSession.Player.Id, opponentSession.Player.Username, challengerColor);
                    challengedSide.OpponentSide = challengerSide;
                    challengerSide.OpponentSide = challengedSide;
                    newBattle.WhiteSide = challengerColor == PlayerColor.white ? challengerSide : challengedSide;
                    newBattle.BlackSide = challengerColor == PlayerColor.black ? challengerSide : challengedSide;

                    BattleManager.Battles[session.Player.Id] = newBattle;
                    BattleManager.Battles[opponentSession.Player.Id] = newBattle;

                    var battleRedirect = new PacketBattleRedirect()
                    {
                        IP = ((IPEndPoint)session.Socket.LocalEndPoint).Address.ToString(),
                        Port = (uint)ConfigManager.Config.Network.BattlePort
                    };
                    session.Send(battleRedirect);
                    opponentSession.Send(battleRedirect);

                }
            }
        }
Ejemplo n.º 2
0
        public static void HandleGameChallengeDecline(object packet, Session session)
        {
            var gameChallengeDecline = (PacketGameChallengeDecline)packet;

            var opponentSession = WorldManager.GetPlayerSession(gameChallengeDecline.ProfileId);
            if (opponentSession == null)
            {
                LogManager.Write("Player", "Player {0} tried to decline challange non existant player {1} to a battle!",
                    session.Player.Id, gameChallengeDecline.ProfileId);
            }

            var packetGameChallengeResponse = new PacketGameChallengeResponse()
            {
                From   = opponentSession.Player.GeneratePacketProfile(),
                To     = session.Player.GeneratePacketProfile(),
                Status = "DECLINE"
            };

            opponentSession.Send(packetGameChallengeResponse);
            session.Send(packetGameChallengeResponse);
        }