修改问题
This commit is contained in:
parent
213a26b9b1
commit
fa8983d242
|
|
@ -135,7 +135,7 @@ public class PlayGameController : CloudGamingControllerBase
|
|||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Authorize]
|
||||
public async Task<BaseResponse<object>> GetMyScListAsync([FromBody] RequestBaseModel requestBaseModel)
|
||||
public async Task<GameListDto> GetMyScListAsync([FromBody] RequestBaseModel requestBaseModel)
|
||||
{
|
||||
PlayGameBLL playGameBLL = new PlayGameBLL(ServiceProvider, JYApi);
|
||||
return await playGameBLL.GetMyScList(requestBaseModel.Sn);
|
||||
|
|
@ -145,13 +145,13 @@ public class PlayGameController : CloudGamingControllerBase
|
|||
/// <summary>
|
||||
/// 重连会话
|
||||
/// </summary>
|
||||
/// <param name="reconPlayGameSettings"></param>
|
||||
/// <param name="gameRequest"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Authorize]
|
||||
public async Task<BaseResponse<object>> ReconPlayGameAsync([FromBody] ReconPlayGameRequest reconPlayGameSettings)
|
||||
public async Task<BaseResponse<string>> ReconPlayGameAsync([FromBody] GameRequest gameRequest)
|
||||
{
|
||||
PlayGameBLL playGameBLL = new PlayGameBLL(ServiceProvider, JYApi);
|
||||
return await playGameBLL.ReconPlayGame(reconPlayGameSettings);
|
||||
return await playGameBLL.ReconPlayGame(gameRequest);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -84,7 +84,7 @@ namespace CloudGaming.Code.Contract
|
|||
/// <param name="requestBase"></param>
|
||||
/// <returns></returns>
|
||||
[Post("/jyapi/myScList")]
|
||||
Task<JYApiResponse<Dictionary<string, object>>> MyScList([Body(BodySerializationMethod.UrlEncoded)] JYRequestParameter parameter);
|
||||
Task<JYApiResponse<MyScListModel>> MyScList([Body(BodySerializationMethod.UrlEncoded)] JYRequestParameter parameter);
|
||||
/// <summary>
|
||||
/// 获取会话列表
|
||||
/// </summary>
|
||||
|
|
|
|||
|
|
@ -143,6 +143,7 @@ public class PlayGameBLL : CloudGamingBase
|
|||
await Dao.DaoPhone.Context.SaveChangesAsync();
|
||||
gameInfoCache?.PlayGameStart(gameResponse?.Data?.ScId ?? 0, userGameList.Id, playGameSettings.DisplayGrade, jyResponseData);
|
||||
gameInfoCache.Ip = HttpContextAccessor.HttpContext.GetClientIpAddress();
|
||||
gameInfoCache.Channel = AppRequestInfo.Channel;
|
||||
var gameResponse1 = JsonConvert.DeserializeObject<Dictionary<string, object>>(jyResponseData.ResponseContent);
|
||||
if (gameResponse1 != null && gameResponse1.TryGetValue("data", out var xxx))
|
||||
{
|
||||
|
|
@ -202,7 +203,8 @@ public class PlayGameBLL : CloudGamingBase
|
|||
Sn = gameInfoCache.Sn,
|
||||
};
|
||||
var jyResponse = await JYApi.StopGame(playGameCommonSetting);
|
||||
gameInfoCache.PlayGameClose();
|
||||
gameInfoCache.PlayGameUserNotDiamond(jyResponse);
|
||||
await gameInfoCache.SaveChangesAsync(this);
|
||||
throw MessageBox.Show(ResponseCode.NotMoney, "钻石不足");
|
||||
}
|
||||
PlayGameHeartbeatResponse playGameHeartbeatResponse = new PlayGameHeartbeatResponse()
|
||||
|
|
@ -492,16 +494,33 @@ public class PlayGameBLL : CloudGamingBase
|
|||
/// </summary>
|
||||
/// <param name="sn"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<BaseResponse<dynamic>> GetMyScList(string sn)
|
||||
public async Task<GameListDto> GetMyScList(string sn)
|
||||
{
|
||||
var requestParmat = new JYRequestParameter(sn, _UserId);
|
||||
var response = await JYApi.MyScList(requestParmat);
|
||||
if (response.IsSuccess)
|
||||
{
|
||||
return new BaseResponse<dynamic>(ResponseCode.Success, "", response.Data) { };
|
||||
if (response.Data?.List?.Count > 0)
|
||||
{
|
||||
var sess = response.Data?.List[0];
|
||||
if (sess != null)
|
||||
{
|
||||
var gameInfo = await PlayGameExtend.PlayGameRecon(this, _UserId, sess.ScId);
|
||||
if (gameInfo != null)
|
||||
{
|
||||
var game = Cache.GameEntityCache[gameInfo.GameId];
|
||||
if (game != null)
|
||||
{
|
||||
await gameInfo.SaveChangesAsync(this);
|
||||
return new GameListDto(game, DtoModel.Epg.EpgEnum.ImageResStyle.小LOGO);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
throw response.ToMessageBox();
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -509,27 +528,43 @@ public class PlayGameBLL : CloudGamingBase
|
|||
/// </summary>
|
||||
/// <param name="reconPlayGameRequest"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<BaseResponse<dynamic>> ReconPlayGame(ReconPlayGameRequest reconPlayGameRequest)
|
||||
public async Task<BaseResponse<string>> ReconPlayGame(GameRequest gameRequest)
|
||||
{
|
||||
var setting = new ReconPlayGameSettings(reconPlayGameRequest.Sn, _UserId)
|
||||
var gameId = gameRequest.GameId;
|
||||
// 检查游戏是否存在
|
||||
var gameCache = Cache.GameEntityCache;
|
||||
var gameInfo = gameCache[gameId];
|
||||
if (gameInfo == null)
|
||||
{
|
||||
ScId = reconPlayGameRequest.ScId,
|
||||
DisplayGrade = reconPlayGameRequest.DisplayGrade,
|
||||
Cpu = reconPlayGameRequest.Cpu,
|
||||
ModelName = reconPlayGameRequest.ModelName,
|
||||
throw MessageBox.ErrorShow("游戏不存在");
|
||||
}
|
||||
|
||||
// 获取用户和游戏信息
|
||||
var userInfo = UserInfo;
|
||||
PlayGameUserInfo gameInfoCache = await PlayGameExtend.GetPlayGameUserInfoOrNull(this, userInfo, gameInfo);
|
||||
if (gameInfoCache == null)
|
||||
{
|
||||
throw MessageBox.ErrorShow("未找到游戏信息");
|
||||
}
|
||||
var setting = new ReconPlayGameSettings(gameInfoCache.Sn, _UserId)
|
||||
{
|
||||
ScId = gameInfoCache.ScId,
|
||||
DisplayGrade = gameInfoCache.DisplayGrade,
|
||||
Cpu = gameInfoCache.Cpu,
|
||||
ModelName = gameInfoCache.ModelName,
|
||||
};
|
||||
var jyResponseData = await JYApi.ReconPlayGame(setting);
|
||||
if (jyResponseData.IsSuccess)
|
||||
{
|
||||
var gameInfo = await PlayGameExtend.PlayGameRecon(this, _UserId, reconPlayGameRequest.ScId);
|
||||
var gameResponse1 = JsonConvert.DeserializeObject<Dictionary<string, object>>(jyResponseData.ResponseContent);
|
||||
if (gameResponse1 != null && gameResponse1.TryGetValue("data", out var xxx))
|
||||
{
|
||||
if (gameInfo != null)
|
||||
{
|
||||
await gameInfo.SaveChangesAsync(this);
|
||||
gameInfoCache.PlayGameRecon(jyResponseData);
|
||||
await gameInfoCache.SaveChangesAsync(this);
|
||||
}
|
||||
return new BaseResponse<dynamic>(ResponseCode.Success, "", new { GameId = gameInfo?.GameId, GameData = JsonConvert.SerializeObject(xxx) });
|
||||
return new BaseResponse<string>(ResponseCode.Success, "", JsonConvert.SerializeObject(xxx));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -342,6 +342,38 @@ namespace CloudGaming.Code.Game
|
|||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 游戏掉线
|
||||
/// </summary>
|
||||
/// <param name="playGameUserInfo"></param>
|
||||
/// <returns></returns>
|
||||
public static bool PlayGameDiaoXian(this PlayGameUserInfo playGameUserInfo, IJYApiRespnse jYApiRespnse)
|
||||
{
|
||||
playGameUserInfo.GameStatus = PlayGameStatus.游戏掉线结束;
|
||||
playGameUserInfo.GameUserOperation.Add(new PlayGameUserOperation(jYApiRespnse)
|
||||
{
|
||||
Content = $"用户游戏掉线,结束游戏",
|
||||
OperationDateTime = DateTime.Now,
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 游戏掉线
|
||||
/// </summary>
|
||||
/// <param name="playGameUserInfo"></param>
|
||||
/// <returns></returns>
|
||||
public static bool PlayGameUserNotDiamond(this PlayGameUserInfo playGameUserInfo, IJYApiRespnse jYApiRespnse)
|
||||
{
|
||||
playGameUserInfo.GameStatus = PlayGameStatus.用户钻石不足;
|
||||
playGameUserInfo.GameUserOperation.Add(new PlayGameUserOperation(jYApiRespnse)
|
||||
{
|
||||
OperationDateTime = DateTime.Now,
|
||||
Content = $"用户余额不足,准备退出游戏"
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
|
|
@ -367,7 +399,9 @@ namespace CloudGaming.Code.Game
|
|||
/// <summary>
|
||||
/// 游戏游戏重连
|
||||
/// </summary>
|
||||
/// <param name="playGameUserInfo"></param>
|
||||
/// <param name="cloudGamingBase"></param>
|
||||
/// <param name="userId"></param>
|
||||
/// <param name="scId"></param>
|
||||
/// <returns></returns>
|
||||
public static async Task<PlayGameUserInfo> PlayGameRecon(CloudGamingBase cloudGamingBase, int userId, int scId)
|
||||
{
|
||||
|
|
@ -381,22 +415,43 @@ namespace CloudGaming.Code.Game
|
|||
}
|
||||
if (playGameUserInfo != null)
|
||||
{
|
||||
if (playGameUserInfo.GameStatus != PlayGameStatus.游戏掉线)
|
||||
playGameUserInfo.GameUserOperation.Add(new PlayGameUserOperation()
|
||||
{
|
||||
playGameUserInfo.GameStatus = PlayGameStatus.游戏掉线;
|
||||
playGameUserInfo.GameUserOperation.Add(new PlayGameUserOperation()
|
||||
{
|
||||
Content = $"用户游戏掉线,上一次心跳时间{playGameUserInfo.PlayGameHeartbeatAt?.ToString("yyyy-MM-dd HH:mm:ss")};",
|
||||
OperationDateTime = DateTime.Now,
|
||||
});
|
||||
}
|
||||
Content = $"用户获取可连接的游戏列表scId:${scId};",
|
||||
OperationDateTime = DateTime.Now,
|
||||
});
|
||||
}
|
||||
return playGameUserInfo;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
/// <summary>
|
||||
/// 游戏游戏重连
|
||||
/// </summary>
|
||||
/// <param name="cloudGamingBase"></param>
|
||||
/// <param name="userId"></param>
|
||||
/// <param name="scId"></param>
|
||||
/// <returns></returns>
|
||||
public static PlayGameUserInfo PlayGameRecon(this PlayGameUserInfo playGameUserInfo, IJYApiRespnse jYApiRespnse)
|
||||
{
|
||||
|
||||
|
||||
if (playGameUserInfo != null)
|
||||
{
|
||||
if (playGameUserInfo.GameStatus != PlayGameStatus.游戏掉线)
|
||||
{
|
||||
playGameUserInfo.GameStatus = PlayGameStatus.游戏中;
|
||||
|
||||
}
|
||||
playGameUserInfo.GameUserOperation.Add(new PlayGameUserOperation(jYApiRespnse)
|
||||
{
|
||||
Content = $"用户重连游戏成功,上一次心跳时间{playGameUserInfo.PlayGameHeartbeatAt?.ToString("yyyy-MM-dd HH:mm:ss")};",
|
||||
OperationDateTime = DateTime.Now,
|
||||
});
|
||||
}
|
||||
return playGameUserInfo;
|
||||
}
|
||||
/// <summary>
|
||||
/// 保存缓存到redis中
|
||||
/// </summary>
|
||||
|
|
@ -420,47 +475,62 @@ namespace CloudGaming.Code.Game
|
|||
{
|
||||
playGameUserInfo.LastDateTime = DateTime.Now;
|
||||
var redisGameKey = GetPlayGameKey(playGameUserInfo.GameId, playGameUserInfo.UserId);
|
||||
if (playGameUserInfo.GameStatus == PlayGameStatus.取消排队 || playGameUserInfo.GameStatus == PlayGameStatus.游戏启动失败 || playGameUserInfo.GameStatus == PlayGameStatus.游戏结束)
|
||||
if (playGameUserInfo.GameStatus == PlayGameStatus.取消排队 || playGameUserInfo.GameStatus == PlayGameStatus.游戏启动失败 || playGameUserInfo.GameStatus == PlayGameStatus.游戏结束 || playGameUserInfo.GameStatus == PlayGameStatus.用户钻石不足 || playGameUserInfo.GameStatus == PlayGameStatus.游戏掉线结束)
|
||||
{
|
||||
T_User_GameList userGameListLog = null;
|
||||
if (playGameUserInfo.DiamondListId > 0)
|
||||
{
|
||||
//设置游玩记录
|
||||
var userGameListLog = await dao.DaoPhone.Context.T_User_GameList.FirstOrDefaultAsync(it => it.Id == playGameUserInfo.DiamondListId);
|
||||
if (userGameListLog != null)
|
||||
userGameListLog = await dao.DaoPhone.Context.T_User_GameList.FirstOrDefaultAsync(it => it.Id == playGameUserInfo.DiamondListId);
|
||||
}
|
||||
if (userGameListLog == null)
|
||||
{
|
||||
userGameListLog = new T_User_GameList
|
||||
{
|
||||
userGameListLog.Status = (int)PlayGameStatus.游戏结束;
|
||||
Channel = playGameUserInfo.Channel,
|
||||
CreateTime = playGameUserInfo.PlayGameStartAt ?? playGameUserInfo.CreateDateTime,
|
||||
GameId = playGameUserInfo.GameId,
|
||||
Status = (int)PlayGameStatus.开始游戏,
|
||||
UpdateTime = DateTime.Now,
|
||||
UserId = playGameUserInfo.UserId,
|
||||
SessionId = playGameUserInfo?.SessionId
|
||||
};
|
||||
await dao.DaoPhone.Context.T_User_GameList.AddAsync(userGameListLog);
|
||||
}
|
||||
userGameListLog.Status = (int)PlayGameStatus.游戏结束;
|
||||
|
||||
var t = DateTime.Now.Subtract(playGameUserInfo.PlayGameStartAt ?? playGameUserInfo.CreateDateTime);
|
||||
var playTime = (int)t.TotalSeconds / 60;
|
||||
userGameListLog.PlaySeconds = (int)t.TotalSeconds;
|
||||
userGameListLog.PlayTime = playTime;
|
||||
userGameListLog.UpdateTime = DateTime.Now;
|
||||
await dao.DaoPhone.Context.SaveChangesAsync();
|
||||
//设置游玩历史
|
||||
var userId = playGameUserInfo.UserId;
|
||||
var gameId = playGameUserInfo.GameId;
|
||||
//设置用户游玩历史
|
||||
var playGameTime = await dao.DaoPhone.Context.T_User_PlayGameTime.Where(it => it.UserId == userId && it.GameId == gameId).FirstOrDefaultAsync();
|
||||
if (playGameTime == null)
|
||||
var t = DateTime.Now.Subtract(playGameUserInfo.PlayGameStartAt ?? playGameUserInfo.CreateDateTime);
|
||||
var playTime = (int)t.TotalSeconds / 60;
|
||||
userGameListLog.PlaySeconds = (int)t.TotalSeconds;
|
||||
userGameListLog.PlayTime = playTime;
|
||||
userGameListLog.UpdateTime = DateTime.Now;
|
||||
await dao.DaoPhone.Context.SaveChangesAsync();
|
||||
//设置游玩历史
|
||||
var userId = playGameUserInfo.UserId;
|
||||
var gameId = playGameUserInfo.GameId;
|
||||
if (playGameUserInfo.GameStatus != PlayGameStatus.取消排队 && playGameUserInfo.GameStatus != PlayGameStatus.游戏启动失败)
|
||||
{
|
||||
//设置用户游玩历史
|
||||
var playGameTime = await dao.DaoPhone.Context.T_User_PlayGameTime.Where(it => it.UserId == userId && it.GameId == gameId).FirstOrDefaultAsync();
|
||||
if (playGameTime == null)
|
||||
{
|
||||
playGameTime = new T_User_PlayGameTime()
|
||||
{
|
||||
playGameTime = new T_User_PlayGameTime()
|
||||
{
|
||||
Createtime = DateTime.Now,
|
||||
NightCardPlayTime = 0,
|
||||
DiamondPlayTime = 0,
|
||||
FreePlayTime = 0,
|
||||
GameId = gameId,
|
||||
PlayTime = 0,
|
||||
UpdateTime = DateTime.Now,
|
||||
UserId = userId,
|
||||
};
|
||||
await dao.DaoPhone.Context.T_User_PlayGameTime.AddAsync(playGameTime);
|
||||
}
|
||||
playGameTime.PlayTime += playTime;
|
||||
playGameTime.UpdateTime = DateTime.Now;
|
||||
playGameTime.DiamondPlayTime += playTime;
|
||||
await dao.DaoPhone.Context.SaveChangesAsync();
|
||||
Createtime = DateTime.Now,
|
||||
NightCardPlayTime = 0,
|
||||
DiamondPlayTime = 0,
|
||||
FreePlayTime = 0,
|
||||
GameId = gameId,
|
||||
PlayTime = 0,
|
||||
UpdateTime = DateTime.Now,
|
||||
UserId = userId,
|
||||
};
|
||||
await dao.DaoPhone.Context.T_User_PlayGameTime.AddAsync(playGameTime);
|
||||
}
|
||||
playGameTime.PlayTime += playTime;
|
||||
playGameTime.UpdateTime = DateTime.Now;
|
||||
playGameTime.DiamondPlayTime += playTime;
|
||||
await dao.DaoPhone.Context.SaveChangesAsync();
|
||||
}
|
||||
var playGameLog = playGameUserInfo.ToGamePlayGameLog();
|
||||
if (playGameLog != null)
|
||||
|
|
|
|||
|
|
@ -120,7 +120,7 @@ public class PlayGameProcessor(IServiceProvider serviceProvider) : ThreadProcess
|
|||
|
||||
var jyResponse = await jyApi.StopGame(playGameCommonSetting).ConfigureAwait(false);
|
||||
|
||||
user.ExitPlayGame(jyResponse);
|
||||
user.PlayGameDiaoXian(jyResponse);
|
||||
await user.SaveChangesAsync(dao, redis).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,21 @@
|
|||
using CloudGaming.DtoModel.PlayGame;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CloudGaming.DtoModel.JY
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取我的会话列表
|
||||
/// </summary>
|
||||
public class MyScListModel
|
||||
{
|
||||
/// <summary>
|
||||
/// 会话列表
|
||||
/// </summary>
|
||||
public List<PlayGameSession> List { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,60 @@
|
|||
using Newtonsoft.Json;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.Json.Serialization;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CloudGaming.DtoModel.PlayGame
|
||||
{
|
||||
/// <summary>
|
||||
/// 游戏会话
|
||||
/// </summary>
|
||||
public class PlayGameSession
|
||||
{
|
||||
/// <summary>
|
||||
///会话 ID
|
||||
/// </summary>
|
||||
[JsonProperty("sc_id")]
|
||||
[JsonPropertyName("sc_id")]
|
||||
public int ScId { get; set; }
|
||||
/// <summary>
|
||||
/// 类型 (able_take 或 able_recon)
|
||||
/// </summary>
|
||||
[JsonProperty("type")]
|
||||
[JsonPropertyName("type")]
|
||||
public string Type { get; set; }
|
||||
/// <summary>
|
||||
/// 挂机剩余时长
|
||||
/// </summary>
|
||||
[JsonProperty("rest_time")]
|
||||
[JsonPropertyName("rest_time")]
|
||||
public int RestTime { get; set; }
|
||||
/// <summary>
|
||||
/// 游戏 key
|
||||
/// </summary>
|
||||
[JsonProperty("game_key")]
|
||||
[JsonPropertyName("game_key")]
|
||||
public string GameKey { get; set; }
|
||||
/// <summary>
|
||||
/// 游戏名称
|
||||
/// </summary>
|
||||
[JsonProperty("game_name")]
|
||||
[JsonPropertyName("game_name")]
|
||||
public string GameName { get; set; }
|
||||
/// <summary>
|
||||
/// 房间 ID
|
||||
/// </summary>
|
||||
[JsonProperty("room_id")]
|
||||
[JsonPropertyName("room_id")]
|
||||
public int RoomId { get; set; }
|
||||
/// <summary>
|
||||
/// 房间名称
|
||||
/// </summary>
|
||||
[JsonProperty("room_name")]
|
||||
[JsonPropertyName("room_name")]
|
||||
public string RoomName { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
@ -48,11 +48,22 @@ namespace CloudGaming.DtoModel.PlayGame
|
|||
/// 游戏掉线
|
||||
/// </summary>
|
||||
游戏掉线 = 8,
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
游戏掉线结束 = 10,
|
||||
|
||||
/// <summary>
|
||||
/// 游戏启动失败
|
||||
/// </summary>
|
||||
游戏启动失败 = 9,
|
||||
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
用户钻石不足 = 11,
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -146,6 +146,11 @@ public class PlayGameUserInfo
|
|||
/// </summary>
|
||||
public string Ip { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 渠道号
|
||||
/// </summary>
|
||||
public string Channel { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 转化成数据库实体类
|
||||
/// </summary>
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
using System;
|
||||
using System;
|
||||
|
||||
namespace CloudGaming.Model.DbSqlServer.Db_Phone;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user