|
@@ -7,6 +7,7 @@ namespace Kitty_Fall.Website.Controllers
|
|
|
{
|
|
{
|
|
|
public class GameController : Controller
|
|
public class GameController : Controller
|
|
|
{
|
|
{
|
|
|
|
|
+ private const string CompletedGameTransIdSessionKey = "completedGameTransId";
|
|
|
private static readonly log4net.ILog log = log4net.LogManager.GetLogger(typeof(GameController));
|
|
private static readonly log4net.ILog log = log4net.LogManager.GetLogger(typeof(GameController));
|
|
|
private readonly IConfiguration _configuration;
|
|
private readonly IConfiguration _configuration;
|
|
|
|
|
|
|
@@ -20,7 +21,24 @@ namespace Kitty_Fall.Website.Controllers
|
|
|
{
|
|
{
|
|
|
try
|
|
try
|
|
|
{
|
|
{
|
|
|
|
|
+ var completedTransId = HttpContext.Session.GetString(CompletedGameTransIdSessionKey);
|
|
|
|
|
+ if (!string.IsNullOrWhiteSpace(request.transId)
|
|
|
|
|
+ && string.Equals(request.transId, completedTransId, StringComparison.Ordinal))
|
|
|
|
|
+ {
|
|
|
|
|
+ request.transId = Guid.NewGuid().ToString("N");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
var apiResult = await SendGameApiAsync(request, UrlConstant.GameStartSessionUrl);
|
|
var apiResult = await SendGameApiAsync(request, UrlConstant.GameStartSessionUrl);
|
|
|
|
|
+ if (apiResult.errorCode != "0"
|
|
|
|
|
+ && string.Equals(apiResult.data?.reason, "SESSION_CLOSED", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
+ {
|
|
|
|
|
+ // The browser can still hold the completed run's ID (for example
|
|
|
|
|
+ // after iframe navigation/cache). Start a genuinely new run once;
|
|
|
|
|
+ // never reuse or reopen the closed API session.
|
|
|
|
|
+ request.transId = Guid.NewGuid().ToString("N");
|
|
|
|
|
+ apiResult = await SendGameApiAsync(request, UrlConstant.GameStartSessionUrl);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
if (apiResult.errorCode == "0" && apiResult.data != null)
|
|
if (apiResult.errorCode == "0" && apiResult.data != null)
|
|
|
{
|
|
{
|
|
|
var maxLevel = await GetTodayMaxLevelAsync(request);
|
|
var maxLevel = await GetTodayMaxLevelAsync(request);
|
|
@@ -60,6 +78,11 @@ namespace Kitty_Fall.Website.Controllers
|
|
|
var apiResult = await SendGameApiAsync(request, UrlConstant.GameSaveLevelResultUrl);
|
|
var apiResult = await SendGameApiAsync(request, UrlConstant.GameSaveLevelResultUrl);
|
|
|
if (apiResult.data != null)
|
|
if (apiResult.data != null)
|
|
|
{
|
|
{
|
|
|
|
|
+ if (request.gameOver != 0 && apiResult.errorCode == "0")
|
|
|
|
|
+ {
|
|
|
|
|
+ HttpContext.Session.SetString(CompletedGameTransIdSessionKey, request.transId ?? "");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
return Json(new
|
|
return Json(new
|
|
|
{
|
|
{
|
|
|
point = apiResult.data.point,
|
|
point = apiResult.data.point,
|
|
@@ -105,6 +128,7 @@ namespace Kitty_Fall.Website.Controllers
|
|
|
if (apiResult.errorCode == "0" && apiResult.data != null)
|
|
if (apiResult.errorCode == "0" && apiResult.data != null)
|
|
|
{
|
|
{
|
|
|
HttpContext.Session.SetComplexData("totalTurn", (long)apiResult.data.totalTurn);
|
|
HttpContext.Session.SetComplexData("totalTurn", (long)apiResult.data.totalTurn);
|
|
|
|
|
+ HttpContext.Session.SetString(CompletedGameTransIdSessionKey, request.transId ?? "");
|
|
|
}
|
|
}
|
|
|
var payload = JsonSerializer.Serialize(new
|
|
var payload = JsonSerializer.Serialize(new
|
|
|
{
|
|
{
|