Ejemplo n.º 1
0
        public async Task <IActionResult> CancelPlayer([FromBody] CancelPlayer.Request req)
        {
            var requester = new evomatching.ProtocolModels.Matching.CancelPlayer();

            requester.request.playerId = SelfHost.playerInfo.playerId;
            var response = await requester.PostAsyncXXX(MatchingServerInfo.AreaUri(SelfHost.matchingArea));

            if (response.StatusCode != System.Net.HttpStatusCode.OK)
            {
                return(BuildErrorResponse(Error.LowCode.ServerInternalError));
            }

            switch (response.Payload.resultCode)
            {
            case evomatching.ProtocolModels.Matching.CancelPlayer.Response.ResultCode.Ok:
                return(Ok(new CancelPlayer.Response()));

            default:
                return(BuildErrorResponse(Error.LowCode.CouldNotMatchingCancel));
            }
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> CancelPlayer(
            [FromBody] CancelPlayer.Request req, [FromServices] GeneralManager gm)
        {
            var res = new CancelPlayer.Response();

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

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

                // OK!
                var result = gm.BattleEntryManager.CancelByPlayer(req.playerId);
                for (int i = 0; i < result.Count; i++)
                {
                    await new ConnectionQueue(result[i].SessionId).EnqueueAsync(new BattleEntryState
                    {
                        state = BattleEntryState.State.Cancel,
                    });
                }

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

            return(Ok(res));
        }