public async Task <IActionResult> ChangePretendOffline([FromBody] ChangePretendOffline.Request req) { var db = PDBSM.PersonalDBContext(SelfHost.playerInfo.playerId); var pbi = await db.PlayerBasicInformations.FindAsync(SelfHost.playerInfo.playerId); if (pbi == null) { return(BuildErrorResponse(Error.LowCode.ServerInternalError)); } pbi.pretendOffline = req.enabled.Value; await db.SaveChangesAsync(); Logger.Logging( new LogObj().AddChild(new LogModels.ChangePretendOffline { PlayerId = pbi.playerId, Date = DateTime.UtcNow, PretendOffline = pbi.pretendOffline, }) ); var session = new Session(SelfHost.sessionId); session.Model.pretendedOffline = req.enabled.Value; await session.SaveAsync(); if (session.Model.pretendedOffline) { var onlineState = new OnlineState(SelfHost.playerInfo.playerId); await onlineState.DeleteAsync(); } else { var onlineState = new OnlineState(SelfHost.playerInfo.playerId); onlineState.Model.state = req.onlineState; onlineState.Model.sessionId = SelfHost.sessionId; await onlineState.SaveAsync(); } await new Player(SelfHost.playerInfo.playerId).Invalidate(); return(Ok(new ChangePretendOffline.Response { enabled = req.enabled.Value, })); }
public async Task <IActionResult> ReportOnlineState([FromBody] ReportOnlineState.Request req) { var onlineState = new OnlineState(SelfHost.playerInfo.playerId); if (SelfHost.playerInfo.pretendedOffline) { await onlineState.DeleteAsync(); } else { onlineState.Model.state = req.state; onlineState.Model.sessionId = SelfHost.sessionId; await onlineState.SaveAsync(); } var res = new ReportOnlineState.Response(); return(Ok(res)); }