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> ResponseInvitation( [FromBody] ResponseInvitation.Request req, [FromServices] GeneralManager gm) { var res = new ResponseInvitation.Response(); await gm.EnqueueJob(async() => { var inv = gm.PgInvitationManager.GetInvitationTo(req.playerIdDst.Value); if (inv == null) { res.resultCode = ProtocolModels.PremadeGroup.ResponseInvitation.Response.ResultCode.Timeup; return; } if (inv.PlayerSrc.PlayerId != req.playerIdSrc) { res.resultCode = ProtocolModels.PremadeGroup.ResponseInvitation.Response.ResultCode.Timeup; return; } Logger.Logging( new LogObj().AddChild(new LogModels.ResponseInvitationParty { PlayerIdSrc = req.playerIdSrc.Value, PlayerIdDst = req.playerIdDst.Value, Date = DateTime.UtcNow, Type = (req.approved.Value) ? evolib.PremadeGroup.ResponseType.Join : evolib.PremadeGroup.ResponseType.Deny, }) ); // OK! gm.PgInvitationManager.RemoveInvitation(inv); if (req.approved.Value) { if (gm.BattleEntryManager.Leave(inv.PlayerDst.PlayerId, evolib.BattleEntry.Type.Leave)) { await new ConnectionQueue(inv.PlayerDst.SessionId).EnqueueAsync(new BattleEntryState() { state = BattleEntryState.State.Cancel, }); } var match = gm.MatchManager.ReleasePlayer(inv.PlayerDst.PlayerId); if (match != null) { await new ConnectionQueue(match.Server.SessionId).EnqueueAsync(new DisconnectPlayer() { players = new List <long>() { inv.PlayerDst.PlayerId } }); } gm.PremadeGroupManager.Form(inv); gm.WatchDogSession.TemporaryAdd(inv.PlayerSrc.SessionId); gm.WatchDogSession.TemporaryAdd(inv.PlayerDst.SessionId); } var queData = gm.CreatePremadeGroupQueueData(inv.PlayerSrc.PlayerId); await new ConnectionQueue(inv.PlayerSrc.SessionId).EnqueueAsync(queData); var group = gm.PremadeGroupManager.GetBelongs(inv.PlayerSrc.PlayerId); if (group != null) { List <long> playerIds = new List <long>(); for (int i = 0; i < group.Players.Count; i++) { var member = group.Players[i]; if (member.PlayerId != inv.PlayerDst.PlayerId) { playerIds.Add(member.PlayerId); } if (member.PlayerId == inv.PlayerSrc.PlayerId) { continue; //already sended! } await new ConnectionQueue(member.SessionId).EnqueueAsync(queData); } Logger.Logging( new LogObj().AddChild(new LogModels.UpdateParty { GroupId = group.GroupId, PlayerId = inv.PlayerDst.PlayerId, Date = DateTime.UtcNow, Type = evolib.PremadeGroup.Type.Entry, PlayerIds = playerIds, }) ); } res.resultCode = ProtocolModels.PremadeGroup.ResponseInvitation.Response.ResultCode.Ok; }); return(Ok(res)); }