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); } } }
public static void HandlePlaySinglePlayerQuickMatch(object packet, Session session) { if (BattleManager.Battles.ContainsKey(session.Player.Id)) { LogManager.Write("Player", "Player {0} wants to play several skirmish at once ! Not possible !", session.Player.Id); return; } // 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); }*/ // TODO : handle AI robot name and deck var newBattle = new Battle(BattleType.SP_QUICKMATCH); newBattle.WhiteSide = new BattleSide(session.Player.Id, session.Player.Username, PlayerColor.white); newBattle.BlackSide = new BattleSide(UInt16.MaxValue, "Easy AI", PlayerColor.black); newBattle.WhiteSide.OpponentSide = newBattle.BlackSide; newBattle.BlackSide.OpponentSide = newBattle.WhiteSide; BattleManager.Battles[session.Player.Id] = newBattle; var battleRedirect = new PacketBattleRedirect() { IP = ConfigManager.Config.Network.Host, Port = (uint)ConfigManager.Config.Network.BattlePort }; session.Send(battleRedirect); }