app.hypergames.hypersdk 1.8.14 → 1.8.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
## [1.8.15](https://github.com/mvmhyper/hyper-sdk/compare/v1.8.14...v1.8.15) (2026-06-04)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* derive SDK session timer from backend remaining time ([d1f79a8](https://github.com/mvmhyper/hyper-sdk/commit/d1f79a814c17828faf6590baf46c925dd7d47b80))
|
|
7
|
+
|
|
1
8
|
## [1.8.14](https://github.com/mvmhyper/hyper-sdk/compare/v1.8.13...v1.8.14) (2026-05-14)
|
|
2
9
|
|
|
3
10
|
|
|
@@ -3,13 +3,14 @@ using Newtonsoft.Json.Linq;
|
|
|
3
3
|
using System;
|
|
4
4
|
using System.Collections;
|
|
5
5
|
using System.Collections.Generic;
|
|
6
|
-
using System.
|
|
6
|
+
using System.Globalization;
|
|
7
7
|
using System.Runtime.InteropServices;
|
|
8
8
|
using System.Text;
|
|
9
9
|
using UnityEngine;
|
|
10
10
|
using UnityEngine.Networking;
|
|
11
11
|
using Hyper.Internal;
|
|
12
12
|
using Hyper.Shared;
|
|
13
|
+
using System.Linq;
|
|
13
14
|
|
|
14
15
|
namespace Hyper.Internal.Managers
|
|
15
16
|
{
|
|
@@ -96,6 +97,7 @@ namespace Hyper.Internal.Managers
|
|
|
96
97
|
private string _csrfToken;
|
|
97
98
|
private string _cachedSessionId;
|
|
98
99
|
private bool _hasSessionEnded;
|
|
100
|
+
private bool _hasAppliedBackendSessionRemainingTime;
|
|
99
101
|
|
|
100
102
|
#endregion
|
|
101
103
|
|
|
@@ -163,6 +165,7 @@ namespace Hyper.Internal.Managers
|
|
|
163
165
|
private IEnumerator CreateSessionCoroutine(Action onSuccess)
|
|
164
166
|
{
|
|
165
167
|
_currentRetryCount = 0;
|
|
168
|
+
_hasAppliedBackendSessionRemainingTime = false;
|
|
166
169
|
const int maxRetries = 1;
|
|
167
170
|
|
|
168
171
|
while (_currentRetryCount < maxRetries)
|
|
@@ -222,6 +225,9 @@ namespace Hyper.Internal.Managers
|
|
|
222
225
|
|
|
223
226
|
private bool ProcessSessionResponse(string responseText)
|
|
224
227
|
{
|
|
228
|
+
Debug.Log($"Session creation response: {responseText}");
|
|
229
|
+
TryApplyBackendSessionRemainingTime(responseText, "session creation");
|
|
230
|
+
|
|
225
231
|
try
|
|
226
232
|
{
|
|
227
233
|
var response = JsonConvert.DeserializeObject<Dictionary<string, object>>(responseText);
|
|
@@ -646,6 +652,9 @@ namespace Hyper.Internal.Managers
|
|
|
646
652
|
|
|
647
653
|
public void OnSocketGameStarted(string message)
|
|
648
654
|
{
|
|
655
|
+
HyperDebug.Log($"[WebSocket] gameStarted response: {message}");
|
|
656
|
+
TryApplyBackendSessionRemainingTime(message, "gameStarted");
|
|
657
|
+
|
|
649
658
|
_gameStarted = true;
|
|
650
659
|
_canFlushScoresAfterGameStartAck = true;
|
|
651
660
|
_hasLoggedWaitingForGameStartAck = false;
|
|
@@ -664,6 +673,9 @@ namespace Hyper.Internal.Managers
|
|
|
664
673
|
|
|
665
674
|
public void OnSocketGameResumed(string message)
|
|
666
675
|
{
|
|
676
|
+
HyperDebug.Log($"[WebSocket] gameResumed response: {message}");
|
|
677
|
+
TryApplyBackendSessionRemainingTime(message, "gameResumed");
|
|
678
|
+
|
|
667
679
|
_gameResumed = true;
|
|
668
680
|
HyperDebug.Log("[WebSocket] Received gameResumed event from server.");
|
|
669
681
|
|
|
@@ -681,11 +693,15 @@ namespace Hyper.Internal.Managers
|
|
|
681
693
|
|
|
682
694
|
public void OnSocketMessage(string message)
|
|
683
695
|
{
|
|
684
|
-
|
|
696
|
+
HyperDebug.Log($"[WebSocket] ack response: {message}");
|
|
697
|
+
TryApplyBackendSessionRemainingTime(message, "socket ack");
|
|
685
698
|
}
|
|
686
699
|
|
|
687
700
|
public void OnSocketSdkPong(string message)
|
|
688
701
|
{
|
|
702
|
+
HyperDebug.Log($"[WebSocket] sdkPong response: {message}");
|
|
703
|
+
TryApplyBackendSessionRemainingTime(message, "sdkPong");
|
|
704
|
+
|
|
689
705
|
if (string.IsNullOrEmpty(message) || !_pendingSdkPingId.HasValue)
|
|
690
706
|
return;
|
|
691
707
|
|
|
@@ -718,6 +734,9 @@ namespace Hyper.Internal.Managers
|
|
|
718
734
|
|
|
719
735
|
public void OnSocketScoreUpdated(string message)
|
|
720
736
|
{
|
|
737
|
+
HyperDebug.Log($"[WebSocket] scoreUpdated response: {message}");
|
|
738
|
+
TryApplyBackendSessionRemainingTime(message, "scoreUpdated");
|
|
739
|
+
|
|
721
740
|
if (_lastSentBatch != null && _lastSentBatch.Count > 0)
|
|
722
741
|
{
|
|
723
742
|
_lastScoreData = _lastSentBatch[_lastSentBatch.Count - 1];
|
|
@@ -764,6 +783,37 @@ namespace Hyper.Internal.Managers
|
|
|
764
783
|
}
|
|
765
784
|
}
|
|
766
785
|
|
|
786
|
+
private void TryApplyBackendSessionRemainingTime(string json, string context)
|
|
787
|
+
{
|
|
788
|
+
if (_hasAppliedBackendSessionRemainingTime || string.IsNullOrEmpty(json))
|
|
789
|
+
return;
|
|
790
|
+
|
|
791
|
+
try
|
|
792
|
+
{
|
|
793
|
+
var parsed = JsonConvert.DeserializeObject<Dictionary<string, object>>(json);
|
|
794
|
+
if (!parsed.TryGetValue("remainingTime", out object remainingTimeObj))
|
|
795
|
+
{
|
|
796
|
+
return;
|
|
797
|
+
}
|
|
798
|
+
|
|
799
|
+
if (!float.TryParse(remainingTimeObj.ToString(), NumberStyles.Float, CultureInfo.InvariantCulture, out float remainingTime))
|
|
800
|
+
{
|
|
801
|
+
HyperDebug.LogWarning($"[SessionTimer] Could not parse remainingTime from '{context}': {remainingTimeObj}");
|
|
802
|
+
return;
|
|
803
|
+
}
|
|
804
|
+
|
|
805
|
+
if (HyperRuntime.Timer.TrySetSessionDurationFromBackendRemainingTime(remainingTime))
|
|
806
|
+
{
|
|
807
|
+
_hasAppliedBackendSessionRemainingTime = true;
|
|
808
|
+
HyperDebug.Log($"[SessionTimer] Applied remainingTime from '{context}'.");
|
|
809
|
+
}
|
|
810
|
+
}
|
|
811
|
+
catch (Exception ex)
|
|
812
|
+
{
|
|
813
|
+
HyperDebug.LogWarning($"[SessionTimer] Failed to inspect remainingTime from '{context}': {ex.Message}");
|
|
814
|
+
}
|
|
815
|
+
}
|
|
816
|
+
|
|
767
817
|
private void ResumeScoreSending()
|
|
768
818
|
{
|
|
769
819
|
if (isSocketConnected && !_gameManager.HasGameEnded)
|
|
@@ -1683,4 +1733,4 @@ namespace Hyper.Internal.Managers
|
|
|
1683
1733
|
|
|
1684
1734
|
#endregion
|
|
1685
1735
|
}
|
|
1686
|
-
}
|
|
1736
|
+
}
|
|
@@ -22,6 +22,7 @@ namespace Hyper.Internal.Managers
|
|
|
22
22
|
|
|
23
23
|
#region Configuration
|
|
24
24
|
private const float SESSION_DURATION = HyperConstants.SESSION_DURATION;
|
|
25
|
+
private const float SESSION_DURATION_BUFFER_SECONDS = 60f;
|
|
25
26
|
|
|
26
27
|
#endregion
|
|
27
28
|
|
|
@@ -35,7 +36,9 @@ namespace Hyper.Internal.Managers
|
|
|
35
36
|
private float _fiveSecondTimer = 5f;
|
|
36
37
|
private bool _isFiveSecondTimerRunning;
|
|
37
38
|
private bool _startDeadlineTriggered;
|
|
39
|
+
private float _sessionDuration = SESSION_DURATION;
|
|
38
40
|
private float _sessionTimer = SESSION_DURATION;
|
|
41
|
+
private bool _hasBackendSessionDuration;
|
|
39
42
|
private bool _isPreSessionRunning;
|
|
40
43
|
private bool _isSessionRunning;
|
|
41
44
|
private bool _sessionWarningTriggered;
|
|
@@ -56,6 +59,9 @@ namespace Hyper.Internal.Managers
|
|
|
56
59
|
|
|
57
60
|
_practiceTimer = 0;
|
|
58
61
|
_battleTimer = _gameManager.Config.TimeLimit;
|
|
62
|
+
_sessionDuration = SESSION_DURATION;
|
|
63
|
+
_sessionTimer = SESSION_DURATION;
|
|
64
|
+
_hasBackendSessionDuration = false;
|
|
59
65
|
_lastUnscaledTime = Time.unscaledTime;
|
|
60
66
|
_timeUpTriggered = false;
|
|
61
67
|
}
|
|
@@ -176,6 +182,33 @@ namespace Hyper.Internal.Managers
|
|
|
176
182
|
internal void StartBattle() => _isBattleRunning = true;
|
|
177
183
|
internal void StopBattle() => _isBattleRunning = false;
|
|
178
184
|
|
|
185
|
+
internal bool TrySetSessionDurationFromBackendRemainingTime(float remainingTimeSeconds)
|
|
186
|
+
{
|
|
187
|
+
if (_hasBackendSessionDuration)
|
|
188
|
+
return true;
|
|
189
|
+
|
|
190
|
+
if (remainingTimeSeconds <= SESSION_DURATION_BUFFER_SECONDS)
|
|
191
|
+
{
|
|
192
|
+
HyperDebug.LogWarning($"[SessionTimer] Ignoring backend remainingTime={remainingTimeSeconds}. It must be greater than the {SESSION_DURATION_BUFFER_SECONDS}s buffer.");
|
|
193
|
+
return false;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
_sessionDuration = remainingTimeSeconds - SESSION_DURATION_BUFFER_SECONDS;
|
|
197
|
+
_hasBackendSessionDuration = true;
|
|
198
|
+
|
|
199
|
+
if (_isPreSessionRunning || _isSessionRunning)
|
|
200
|
+
{
|
|
201
|
+
_sessionTimer = Mathf.Min(_sessionTimer, _sessionDuration);
|
|
202
|
+
}
|
|
203
|
+
else
|
|
204
|
+
{
|
|
205
|
+
_sessionTimer = _sessionDuration;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
HyperDebug.Log($"[SessionTimer] Using backend remainingTime={remainingTimeSeconds}. Buffered SDK session duration={_sessionDuration}s.");
|
|
209
|
+
return true;
|
|
210
|
+
}
|
|
211
|
+
|
|
179
212
|
internal void StartSessionTimer(bool isPreSessionTimer = false)
|
|
180
213
|
{
|
|
181
214
|
if(_isPreSessionRunning && _isSessionRunning) return; // Already running both timers
|
|
@@ -183,7 +216,7 @@ namespace Hyper.Internal.Managers
|
|
|
183
216
|
#if UNITY_WEBGL && !UNITY_EDITOR
|
|
184
217
|
StartHTMLSessionTimer();
|
|
185
218
|
#endif
|
|
186
|
-
_sessionTimer =
|
|
219
|
+
_sessionTimer = _sessionDuration;
|
|
187
220
|
_sessionWarningTriggered = false;
|
|
188
221
|
_startDeadlineTriggered = false;
|
|
189
222
|
_lastUnscaledTime = Time.unscaledTime;
|
|
@@ -324,4 +357,4 @@ namespace Hyper.Internal.Managers
|
|
|
324
357
|
|
|
325
358
|
#endregion
|
|
326
359
|
}
|
|
327
|
-
}
|
|
360
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "app.hypergames.hypersdk",
|
|
3
|
-
"version": "1.8.
|
|
3
|
+
"version": "1.8.15",
|
|
4
4
|
"displayName": "HyperSDK",
|
|
5
5
|
"description": "Official Unity SDK for Hyper: multiplayer battles, leaderboards, deterministic RNG, session management, tutorials, and WebGL optimizations for production-ready games.",
|
|
6
6
|
"unity": "6000.0",
|