public async Task <IActionResult> ResponseInvitation([FromBody] ResponseInvitation.Request req)
        {
            var requester = new evomatching.ProtocolModels.PremadeGroup.ResponseInvitation();

            requester.request.playerIdSrc = req.playerId;
            requester.request.playerIdDst = SelfHost.playerInfo.playerId;
            requester.request.approved    = req.approved;
            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.PremadeGroup.ResponseInvitation.Response.ResultCode.Ok:
                return(Ok(new ResponseInvitation.Response()));

            case evomatching.ProtocolModels.PremadeGroup.ResponseInvitation.Response.ResultCode.Timeup:
                return(BuildErrorResponse(Error.LowCode.PremadeGroupResponseTimeup));

            default:
                return(BuildErrorResponse(Error.LowCode.BadRequest));
            }
        }
        public async Task <IActionResult> EntryBattleServer([FromBody] EntryBattleServer.Request req)
        {
            var requester = new evomatching.ProtocolModels.Matching.EntryBattleServer();

            requester.request.sessionId           = SelfHost.sessionId;
            requester.request.ipAddr              = req.ipAddr;
            requester.request.port                = req.port.Value;
            requester.request.rule                = req.rule;
            requester.request.mapId               = req.mapId;
            requester.request.autoMatchmakeTarget = req.autoMatchmakeTarget.Value;
            requester.request.label               = req.label;
            requester.request.description         = req.description;
            requester.request.serverName          = req.serverName;
            requester.request.region              = req.region;
            requester.request.owner               = req.owner;
            var response = await requester.PostAsyncXXX(MatchingServerInfo.AreaUri(SelfHost.matchingArea));

            if (response.StatusCode == System.Net.HttpStatusCode.OK)
            {
                var session = new Session(SelfHost.sessionId);
                session.Model.matchId = response.Payload.matchId;
                await session.SaveAsync();
            }

            return(Ok(new EntryBattleServer.Response
            {
            }));
        }
        public async Task <IActionResult> ReportAcceptPlayer([FromBody] ReportAcceptPlayer.Request req)
        {
            var requester = new evomatching.ProtocolModels.Matching.ReportAcceptPlayer();

            requester.request.battleServerSessionId = SelfHost.sessionId;
            requester.request.joinPassword          = req.joinPassword;
            var response = await requester.PostAsyncXXX(MatchingServerInfo.AreaUri(SelfHost.matchingArea));

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

            var res = new ReportAcceptPlayer.Response
            {
                playerId = response.Payload.playerId,
                allowed  = response.Payload.allowed,
                side     = response.Payload.side,
                rating   = response.Payload.rating,
            };

            if (response.Payload.allowed)
            {
                var player = new Player(response.Payload.playerId);
                await player.FetchAsync();

                res.privilegeLevel = player.Model.privilegeLevel;
                res.sessionId      = player.Model.sessionId;
            }

            return(Ok(res));
        }
        public async Task <IActionResult> EntryPlayer([FromBody] EntryPlayer.Request req)
        {
            if (req.pingResults != null)
            {
                var results = new List <LogModels.PingResults.Result>();
                foreach (var pingResult in req.pingResults)
                {
                    results.Add(new LogModels.PingResults.Result
                    {
                        regionCode = pingResult.regionCode,
                        time       = pingResult.time,
                    });
                }

                Logger.Logging(
                    new LogObj().AddChild(new LogModels.PingResults
                {
                    PlayerId = SelfHost.playerInfo.playerId,
                    Results  = results,
                })
                    );
            }


            if (!VersionChecker.Get(VersionChecker.CheckTarget.EnabledMatchmake).Check())
            {
                return(BuildErrorResponse(Error.LowCode.DisabledMatchmake));
            }

            var requester = new evomatching.ProtocolModels.Matching.EntryPlayer();

            requester.request.playerId  = SelfHost.playerInfo.playerId;
            requester.request.matchType = req.matchType.Value;
            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.EntryPlayer.Response.ResultCode.Ok:
                return(Ok(new EntryPlayer.Response()));

            case evomatching.ProtocolModels.Matching.EntryPlayer.Response.ResultCode.OldPackageVersion:
                return(BuildErrorResponse(Error.LowCode.NgPackageVersion));

            case evomatching.ProtocolModels.Matching.EntryPlayer.Response.ResultCode.SendedPgInvitation:
                return(BuildErrorResponse(Error.LowCode.SentPgInvitation));

            case evomatching.ProtocolModels.Matching.EntryPlayer.Response.ResultCode.RecievedPgInvitation:
                return(BuildErrorResponse(Error.LowCode.RecievedPgInvitation));

            default:
                return(BuildErrorResponse(Error.LowCode.CouldNotMatchingEnty));
            }
        }
Exemple #5
0
        public async Task <IActionResult> SemiAutoMatchmake([FromBody] SemiAutoMatchmake.Request req)
        {
            await MatchingServerInfo.MultiMatchingServersAsync();

            var requester = new evomatching.ProtocolModels.Matching.SemiAutoMatchmake();

            requester.request = req;
            var res = await requester.PostAsyncXXX(MatchingServerInfo.AreaUri(req.matchingArea.Value));

            return(Ok(res.Payload));
        }
Exemple #6
0
        public async Task <IActionResult> Say([FromBody] Say.Request req)
        {
            var requester = new evomatching.ProtocolModels.Chat.Chat();

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

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

            Logger.Logging(
                new LogObj().AddChild(new LogModels.SayChat
            {
                PlayerId = SelfHost.playerInfo.playerId,
                Date     = DateTime.UtcNow,
                ChatType = req.type.Value,
                GroupId  = response.Payload.groupId,
                MatchId  = response.Payload.matchId,
                Side     = response.Payload.side,
                Text     = req.text,
            })
                );

            var data = new Chat()
            {
                type       = req.type.Value,
                playerId   = SelfHost.playerInfo.playerId,
                playerName = SelfHost.playerInfo.playerName,
                text       = req.text,
            };

            if (response.Payload.sessionIds.Count == 0)
            {
                await new ConnectionQueue(SelfHost.sessionId).EnqueueAsync(data);
            }
            else
            {
                for (int i = 0; i < response.Payload.sessionIds.Count; i++)
                {
                    var sessionId = response.Payload.sessionIds[i];

                    await new ConnectionQueue(sessionId).EnqueueAsync(data);
                }
            }

            var res = new Say.Response();

            return(Ok(res));
        }
Exemple #7
0
        public async Task <IActionResult> ForceMatchmake([FromBody] ForceMatchmake.Request req)
        {
            await MatchingServerInfo.MultiMatchingServersAsync();

            var requester = new evomatching.ProtocolModels.Matching.ForceMatchmake();

            requester.request = req;
            var res = await requester.PostAsyncXXX(MatchingServerInfo.AreaUri(req.matchingArea.Value));

            return(Ok(new ForceMatchmake.Response
            {
                matchingArea = req.matchingArea.Value,
            }));
        }
Exemple #8
0
        public async Task <IActionResult> GetEntries([FromBody] GetEntries.Request req)
        {
            await MatchingServerInfo.MultiMatchingServersAsync();

            var requester = new evomatching.ProtocolModels.Matching.GetEntries();
            var res       = await requester.PostAsyncXXX(MatchingServerInfo.AreaUri(req.matchingArea.Value));

            return(Ok(new GetEntries.Response
            {
                entries = res.Payload.entries,
                battleServers = res.Payload.battleServers,
                matchingArea = req.matchingArea.Value,
            }));
        }
        public async Task <IActionResult> Leave([FromBody] Leave.Request req)
        {
            var requester = new evomatching.ProtocolModels.PremadeGroup.Leave();

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

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

            var res = new Leave.Response();

            return(Ok(res));
        }
        public async Task <IActionResult> RequestLeaveBattle([FromBody] RequestLeaveBattle.Request req)
        {
            var requester = new evomatching.ProtocolModels.Matching.RequestLeaveBattleServer();

            requester.request.playerId   = SelfHost.playerInfo.playerId;
            requester.request.individual = req.individual.Value;
            var response = await requester.PostAsync(MatchingServerInfo.AreaUri(SelfHost.matchingArea));

            if (response == null)
            {
                return(BuildErrorResponse(Error.LowCode.ServerInternalError));
            }


            var res = new RequestLeaveBattle.Response();

            return(Ok(res));
        }
        public async Task <IActionResult> ReportBattlePhase([FromBody] ReportBattlePhase.Request req)
        {
            foreach (Battle.Phase phase in Enum.GetValues(typeof(Battle.Phase)))
            {
                var str = Enum.GetName(typeof(Battle.Phase), phase);
                if (str == req.phase)
                {
                    var requester = new evomatching.ProtocolModels.Matching.ReportBattlePhase();
                    requester.request.battleServerSessionId = SelfHost.sessionId;
                    requester.request.phase = phase;
                    var response = await requester.PostAsync(MatchingServerInfo.AreaUri(SelfHost.matchingArea));

                    var res = new ReportBattlePhase.Response();
                    return(Ok(res));
                }
            }

            return(BuildErrorResponse(Error.LowCode.BadParameter));
        }
        public async Task <IActionResult> ReportDisconnectPlayer([FromBody] ReportDisconnectPlayer.Request req)
        {
            var requester = new evomatching.ProtocolModels.Matching.ReportDisconnectPlayer();

            requester.request.battleServerSessionId = SelfHost.sessionId;
            requester.request.playerId = req.playerId;
            var response = await requester.PostAsync(MatchingServerInfo.AreaUri(SelfHost.matchingArea));

            var lastBattle = new LastBattle(req.playerId);

            lastBattle.Model.matchId         = (req.forbiddenReturnMatch) ? "" : SelfHost.battleServerInfo.matchId;
            lastBattle.Model.lastExistedDate = DateTime.UtcNow;
            await lastBattle.SaveAsync();


            var res = new ReportDisconnectPlayer.Response();

            res.playerId = req.playerId;
            return(Ok(res));
        }
        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));
            }
        }
        public async Task <IActionResult> SendInvitation([FromBody] SendInvitation.Request req)
        {
            var requester = new evomatching.ProtocolModels.PremadeGroup.SendInvitation();

            //dst
            var playerDst = new Player(req.playerId.Value);

            if (!await playerDst.Validate(PDBSM))
            {
                return(BuildErrorResponse(Error.LowCode.BadParameter));
            }
            requester.request.playerIdDst  = playerDst.playerId;
            requester.request.sessionIdDst = playerDst.Model.sessionId;

            if (playerDst.Model.matchingArea != SelfHost.matchingArea)
            {
                return(BuildErrorResponse(Error.LowCode.PremadeGroupDifferentArea));
            }

            //src
            requester.request.playerIdSrc  = SelfHost.playerInfo.playerId;
            requester.request.sessionIdSrc = SelfHost.sessionId;


            if (requester.request.playerIdSrc == requester.request.playerIdDst)
            {
                return(BuildErrorResponse(Error.LowCode.BadParameter));
            }

            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.PremadeGroup.SendInvitation.Response.ResultCode.Ok:
                return(Ok(new SendInvitation.Response()
                {
                }));

            case evomatching.ProtocolModels.PremadeGroup.SendInvitation.Response.ResultCode.AlreadyEntrySelf:
            case evomatching.ProtocolModels.PremadeGroup.SendInvitation.Response.ResultCode.AlreadyBattleSelf:
                return(BuildErrorResponse(Error.LowCode.BadRequest));

            case evomatching.ProtocolModels.PremadeGroup.SendInvitation.Response.ResultCode.ReceivedInvitationSelf:
                return(BuildErrorResponse(Error.LowCode.PremadeGroupRecievedInvitationSelf));

            case evomatching.ProtocolModels.PremadeGroup.SendInvitation.Response.ResultCode.BusyTarget:
                return(BuildErrorResponse(Error.LowCode.PremadeGroupTargetBusy));

            case evomatching.ProtocolModels.PremadeGroup.SendInvitation.Response.ResultCode.AlreadyGroupTarget:
                return(BuildErrorResponse(Error.LowCode.PremadeGroupAlreadyGroupTarget));

            case evomatching.ProtocolModels.PremadeGroup.SendInvitation.Response.ResultCode.AlreadyEntryTarget:
                return(BuildErrorResponse(Error.LowCode.PremadeGroupAlreadyEntryTarget));

            case evomatching.ProtocolModels.PremadeGroup.SendInvitation.Response.ResultCode.AlreadyBattleTarget:
                return(BuildErrorResponse(Error.LowCode.PremadeGroupAlreadyBattleTarget));

            case evomatching.ProtocolModels.PremadeGroup.SendInvitation.Response.ResultCode.OverLimit:
                return(BuildErrorResponse(Error.LowCode.PremadeGroupOverLimit));

            default:
                return(BuildErrorResponse(Error.LowCode.Others));
            }
        }