Ejemplo n.º 1
0
        public async Task <IActionResult> RequestReturnBattleServer(
            [FromBody] RequestReturnBattleServer.Request req, [FromServices] GeneralManager gm)
        {
            var res = new RequestReturnBattleServer.Response();

            await gm.EnqueueJob(async() =>
            {
                var match = gm.MatchManager.GetMatch(req.matchId);
                if (match == null || match.State > MatchState.Result)
                {
                    return;
                }

                if (gm.BattleEntryManager.Entried(req.playerId))
                {
                    return;
                }


                var side = gm.MatchManager.LastSide(req.matchId, req.playerId);
                if (side == Battle.Side.Unknown)
                {
                    return;
                }


                var player = new Player(req.playerId);
                await player.Validate(PDBSM);

                var entryPlayers = new List <IBattleEntryPlayer>()
                {
                    BattleEntryManager.IBattleEntryPlayer(
                        player.playerId,
                        player.Model.playerName,
                        player.Model.battleRating,
                        player.Model.sessionId
                        ),
                };
                res.isAssigned = gm.MatchManager.AssignPlayers(req.matchId, entryPlayers, side);
                if (res.isAssigned)
                {
                    await new ConnectionQueue(player.Model.sessionId).EnqueueAsync(match.JoinBattleServer(player.playerId));

                    gm.WatchDogSession.TemporaryAdd(player.Model.sessionId);

                    await new ConnectionQueue(match.Server.SessionId).EnqueueAsync(match.MatchInfo());
                }
            });

            return(Ok(res));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> EntryPlayer(
            [FromBody] EntryPlayer.Request req, [FromServices] GeneralManager gm)
        {
            var res = new EntryPlayer.Response();

            await gm.EnqueueJob(async() =>
            {
                if (gm.BattleEntryManager.Entried(req.playerId))
                {
                    res.resultCode = ProtocolModels.Matching.EntryPlayer.Response.ResultCode.AlreadyEntry;
                    return;
                }

                if (null != gm.MatchManager.GetAssignedMatch(req.playerId))
                {
                    res.resultCode = ProtocolModels.Matching.EntryPlayer.Response.ResultCode.AlreadyBattle;
                    return;
                }

                if (null != gm.PgInvitationManager.GetInvitationTo(req.playerId))
                {
                    res.resultCode = ProtocolModels.Matching.EntryPlayer.Response.ResultCode.RecievedPgInvitation;
                    return;
                }

                var queData = gm.CreatePremadeGroupQueueData(req.playerId);
                if (0 <= queData.players.FindIndex(p => p.isInvitation))
                {
                    res.resultCode = ProtocolModels.Matching.EntryPlayer.Response.ResultCode.SendedPgInvitation;
                    return;
                }


                var playerIds = new List <long>();

                var group = gm.PremadeGroupManager.GetBelongs(req.playerId);
                if (group != null)
                {
                    if (group.LeaderPlayerId != req.playerId)
                    {
                        res.resultCode = ProtocolModels.Matching.EntryPlayer.Response.ResultCode.NotLeader;
                        return;
                    }

                    for (int i = 0; i < group.Players.Count; i++)
                    {
                        playerIds.Add(group.Players[i].PlayerId);
                    }
                }
                else
                {
                    playerIds.Add(req.playerId);
                }

                var limitPackagerVer = VersionChecker.Valued(VersionChecker.ReferenceSrc.PackageVersion,
                                                             VersionChecker.LimitPackageVersion(VersionChecker.CheckTarget.Matchmake));
                UInt64 minPackageVersion = UInt64.MaxValue;

                var entries = new List <IBattleEntryPlayer>();

                for (int i = 0; i < playerIds.Count; i++)
                {
                    var player = new Player(playerIds[i]);
                    await player.Validate(PDBSM);

                    if (player.Model.packageVersion < limitPackagerVer)
                    {
                        res.resultCode = ProtocolModels.Matching.EntryPlayer.Response.ResultCode.OldPackageVersion;
                        return;
                    }

                    minPackageVersion = Math.Min(player.Model.packageVersion, minPackageVersion);

                    entries.Add(
                        BattleEntryManager.IBattleEntryPlayer(
                            player.playerId,
                            player.Model.playerName,
                            player.Model.battleRating,
                            player.Model.sessionId
                            )
                        );
                }

                Logger.Logging(
                    new LogObj().AddChild(new LogModels.EntryPlayer
                {
                    Date      = DateTime.UtcNow,
                    MatchType = req.matchType,
                    GroupId   = (group != null) ? group.GroupId : "",
                    PlayerIds = playerIds,
                })
                    );

                var result = gm.BattleEntryManager.Entry(req.matchType, minPackageVersion, entries);
                for (int i = 0; i < result.Count; i++)
                {
                    await new ConnectionQueue(result[i].SessionId).EnqueueAsync(new BattleEntryState
                    {
                        state = (req.matchType == Battle.MatchType.Casual)
                                                                                                        ? BattleEntryState.State.CasualMatchEntry
                                                                                                        : BattleEntryState.State.RankMatchEntry,
                    });

                    gm.WatchDogSession.TemporaryAdd(result[i].SessionId);
                }

                res.resultCode = ProtocolModels.Matching.EntryPlayer.Response.ResultCode.Ok;
            });

            return(Ok(res));
        }