com.xmobitea.changx.gn-unity 2.0.2 → 2.3.0
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/Editor/GNServerSettingsEditor.cs +42 -322
- package/Runtime/Common/GNArray.cs +120 -35
- package/Runtime/Common/GNData.cs +19 -6
- package/Runtime/Common/GNHashtable.cs +174 -11
- package/Runtime/Common/IGNData.cs +11 -2
- package/Runtime/Config/GNServerSettings.cs +136 -92
- package/Runtime/Constant/Commands.cs +82 -19
- package/Runtime/Constant/EnumType/GoogleLoginType.cs +5 -5
- package/Runtime/Constant/EnumType/GroupStatus.cs +7 -7
- package/Runtime/Constant/EnumType/ItemType.cs +5 -5
- package/Runtime/Constant/EnumType/MatchmakingMemberStatus.cs +6 -6
- package/Runtime/Constant/EnumType/MatchmakingTicketStatus.cs +2 -2
- package/Runtime/Constant/EnumType/OwnerType.cs +3 -2
- package/Runtime/Constant/EnumType/PushPlatformType.cs +10 -0
- package/Runtime/Constant/EnumType/PushPlatformType.cs.meta +11 -0
- package/Runtime/Constant/EnumType/RequestType.cs +1 -0
- package/Runtime/Constant/EnumType/StoreReceiveType.cs +13 -0
- package/Runtime/Constant/EnumType/StoreReceiveType.cs.meta +11 -0
- package/Runtime/Constant/ErrorCode/GNErrorCode.cs +53 -48
- package/Runtime/Constant/EventCode.cs +29 -2
- package/Runtime/Constant/OperationCode.cs +249 -211
- package/Runtime/Constant/ParameterCode/GNParameterCode.cs +610 -466
- package/Runtime/Constant/ReturnCode.cs +50 -2
- package/Runtime/Entity/DataMember.cs +221 -3
- package/Runtime/Entity/GNMetadata.cs +46 -1
- package/Runtime/Entity/InvalidMember.cs +24 -5
- package/Runtime/Entity/Models/AuthenticateModels.cs +251 -207
- package/Runtime/Entity/Models/AuthenticateRequestModels.cs +153 -131
- package/Runtime/Entity/Models/AuthenticateResponseModels.cs +61 -51
- package/Runtime/Entity/Models/CharacterPlayerModels.cs +985 -849
- package/Runtime/Entity/Models/CharacterPlayerRequestModels.cs +957 -885
- package/Runtime/Entity/Models/CharacterPlayerResponseModels.cs +165 -150
- package/Runtime/Entity/Models/CloudScriptModels.cs +185 -0
- package/Runtime/Entity/Models/CloudScriptModels.cs.meta +11 -0
- package/Runtime/Entity/Models/CloudScriptRequestModels.cs +134 -0
- package/Runtime/Entity/Models/CloudScriptRequestModels.cs.meta +11 -0
- package/Runtime/Entity/Models/CloudScriptResponseModels.cs +34 -0
- package/Runtime/Entity/Models/CloudScriptResponseModels.cs.meta +11 -0
- package/Runtime/Entity/Models/ContentModels.cs +150 -153
- package/Runtime/Entity/Models/ContentRequestModels.cs +129 -129
- package/Runtime/Entity/Models/ContentResponseModels.cs +24 -24
- package/Runtime/Entity/Models/DashboardModels.cs +1684 -1156
- package/Runtime/Entity/Models/DashboardRequestModels.cs +220 -147
- package/Runtime/Entity/Models/DashboardResponseModels.cs +92 -57
- package/Runtime/Entity/Models/GamePlayerModels.cs +1073 -933
- package/Runtime/Entity/Models/GamePlayerRequestModels.cs +939 -867
- package/Runtime/Entity/Models/GamePlayerResponseModels.cs +162 -147
- package/Runtime/Entity/Models/GenericModels.cs +102 -102
- package/Runtime/Entity/Models/GroupModels.cs +812 -676
- package/Runtime/Entity/Models/GroupRequestModels.cs +741 -669
- package/Runtime/Entity/Models/GroupResponseModels.cs +129 -114
- package/Runtime/Entity/Models/InventoryModels.cs +667 -558
- package/Runtime/Entity/Models/InventoryRequestModels.cs +626 -579
- package/Runtime/Entity/Models/InventoryResponseModels.cs +109 -99
- package/Runtime/Entity/Models/MasterPlayerModels.cs +1882 -1340
- package/Runtime/Entity/Models/MasterPlayerRequestModels.cs +1643 -1253
- package/Runtime/Entity/Models/MasterPlayerResponseModels.cs +293 -213
- package/Runtime/Entity/Models/MultiplayerModels.cs +293 -223
- package/Runtime/Entity/Models/MultiplayerRequestModels.cs +199 -149
- package/Runtime/Entity/Models/MultiplayerResponseModels.cs +10 -0
- package/Runtime/Entity/Models/StoreInventoryModels.cs +514 -323
- package/Runtime/Entity/Models/StoreInventoryRequestModels.cs +236 -165
- package/Runtime/Entity/Models/StoreInventoryResponseModels.cs +45 -30
- package/Runtime/Entity/OperationEvent.cs +43 -7
- package/Runtime/Entity/OperationHelper.cs +18 -2
- package/Runtime/Entity/OperationRequest.cs +80 -37
- package/Runtime/Entity/OperationResponse.cs +111 -63
- package/Runtime/Entity/Request/CustomOperationRequest.cs +53 -2
- package/Runtime/Entity/Response/CustomOperationResponse.cs +25 -4
- package/Runtime/GNNetwork.cs +333 -21
- package/Runtime/GNNetworkApi.cs +25 -13
- package/Runtime/GNNetworkAuthenticateApi.cs +531 -98
- package/Runtime/GNNetworkCharacterPlayerApi.cs +1587 -762
- package/Runtime/GNNetworkCloudScriptApi.cs +181 -0
- package/Runtime/GNNetworkCloudScriptApi.cs.meta +11 -0
- package/Runtime/GNNetworkContentApi.cs +238 -132
- package/Runtime/GNNetworkDashboardApi.cs +278 -117
- package/Runtime/GNNetworkGamePlayerApi.cs +1558 -747
- package/Runtime/GNNetworkGroupApi.cs +1228 -582
- package/Runtime/GNNetworkInventoryApi.cs +1048 -507
- package/Runtime/GNNetworkMasterPlayerApi.cs +2586 -1067
- package/Runtime/GNNetworkMultiplayerApi.cs +328 -147
- package/Runtime/GNNetworkStoreInventoryApi.cs +388 -162
- package/Runtime/Helper/CodeHelper.cs +45 -3
- package/Runtime/Helper/ConverterService.cs +240 -85
- package/Runtime/Logger/GNDebug.cs +46 -3
- package/Runtime/Networking/AuthenticateStatus.cs +30 -8
- package/Runtime/Networking/Handler/IServerEventHandler.cs +8 -8
- package/Runtime/Networking/Handler/OnCharacterPlayerFriendUpdateEventHandler.cs +31 -2
- package/Runtime/Networking/Handler/OnCharacterPlayerGroupUpdateEventHandler.cs +24 -3
- package/Runtime/Networking/Handler/OnGamePlayerFriendUpdateEventHandler.cs +24 -2
- package/Runtime/Networking/Handler/OnGamePlayerGroupUpdateEventHandler.cs +24 -2
- package/Runtime/Networking/Handler/OnGroupMemberUpdateEventHandler.cs +21 -2
- package/Runtime/Networking/Handler/OnGroupMessageUpdateEventHandler.cs +20 -2
- package/Runtime/Networking/Http/HttpPeer.cs +68 -25
- package/Runtime/Networking/Http/NetworkingHttpPeerBase.cs +44 -4
- package/Runtime/Networking/Http/NetworkingPeerHttpClientRequest.cs +63 -40
- package/Runtime/Networking/Http/NetworkingPeerHttpRequest.cs +43 -13
- package/Runtime/Networking/Http/NetworkingPeerUnityWebRequest.cs +72 -39
- package/Runtime/Networking/IPeer.cs +24 -2
- package/Runtime/Networking/NetworkingPeer.cs +64 -10
- package/Runtime/Networking/NetworkingPeerAPI.cs +20 -21
- package/Runtime/Networking/OperationPending.cs +79 -15
- package/Runtime/Networking/PeerBase.cs +86 -23
- package/Runtime/Networking/Socket/NetworkingPeerSocketV2.cs +57 -18
- package/Runtime/Networking/Socket/NetworkingPeerSocketV3.cs +70 -10
- package/Runtime/Networking/Socket/NetworkingSocketPeerBase.cs +165 -23
- package/Runtime/Networking/Socket/SocketPeer.cs +63 -12
- package/Runtime/Unity/ServiceCoroutine.cs +10 -0
- package/Runtime/Unity/ServiceCoroutine.cs.meta +11 -0
- package/Runtime/Unity/ServiceUpdate.cs +14 -1
- package/package.json +1 -1
package/Runtime/GNNetwork.cs
CHANGED
|
@@ -1,54 +1,110 @@
|
|
|
1
1
|
namespace XmobiTea.GN
|
|
2
2
|
{
|
|
3
|
-
using XmobiTea.GN.Networking;
|
|
4
|
-
using XmobiTea.GN.Config;
|
|
5
|
-
|
|
6
3
|
using System;
|
|
7
|
-
|
|
8
|
-
using
|
|
4
|
+
using System.Threading.Tasks;
|
|
5
|
+
using XmobiTea.GN.Common;
|
|
6
|
+
using XmobiTea.GN.Config;
|
|
7
|
+
using XmobiTea.GN.Constant;
|
|
9
8
|
using XmobiTea.GN.Entity;
|
|
10
|
-
using XmobiTea.GN.Logger;
|
|
11
9
|
using XmobiTea.GN.Entity.Request;
|
|
12
10
|
using XmobiTea.GN.Entity.Response;
|
|
13
|
-
using XmobiTea.GN.
|
|
14
|
-
using XmobiTea.GN.
|
|
11
|
+
using XmobiTea.GN.Logger;
|
|
12
|
+
using XmobiTea.GN.Networking;
|
|
15
13
|
|
|
14
|
+
/// <summary>
|
|
15
|
+
/// Static class GNNetwork handles all the networking logic, including socket and HTTP communication.
|
|
16
|
+
/// </summary>
|
|
16
17
|
public static partial class GNNetwork
|
|
17
18
|
{
|
|
18
|
-
|
|
19
|
-
|
|
19
|
+
/// <summary>
|
|
20
|
+
/// Current SDK version.
|
|
21
|
+
/// </summary>
|
|
22
|
+
private const string GN_VERSION = "2.3";
|
|
23
|
+
|
|
24
|
+
/// <summary>
|
|
25
|
+
/// Key for storing authentication token in PlayerPrefs.
|
|
26
|
+
/// </summary>
|
|
20
27
|
internal const string AUTH_TOKEN_KEY = "[GN]_AUTH_TOKEN_KEY";
|
|
28
|
+
|
|
29
|
+
/// <summary>
|
|
30
|
+
/// Key for storing user ID in PlayerPrefs.
|
|
31
|
+
/// </summary>
|
|
21
32
|
internal const string USER_ID_KEY = "[GN]_USER_ID_KEY";
|
|
22
33
|
|
|
34
|
+
/// <summary>
|
|
35
|
+
/// Key for storing game ID in PlayerPrefs.
|
|
36
|
+
/// </summary>
|
|
37
|
+
internal const string GAME_ID_KEY = "[GN]_GAME_ID_KEY";
|
|
38
|
+
|
|
39
|
+
/// <summary>
|
|
40
|
+
/// Holds GN server settings loaded from resources.
|
|
41
|
+
/// </summary>
|
|
23
42
|
public static GNServerSettings gnServerSettings { get; private set; }
|
|
24
43
|
|
|
44
|
+
/// <summary>
|
|
45
|
+
/// Instance of the NetworkingPeer for handling socket connections.
|
|
46
|
+
/// </summary>
|
|
25
47
|
internal static NetworkingPeer peer { get; private set; }
|
|
26
48
|
|
|
49
|
+
/// <summary>
|
|
50
|
+
/// Gets the current ping in milliseconds.
|
|
51
|
+
/// </summary>
|
|
52
|
+
/// <returns>The current ping value, or -1 if no peer exists.</returns>
|
|
27
53
|
public static int getPing() => GNNetwork.peer != null ? GNNetwork.peer.getPing() : -1;
|
|
28
54
|
|
|
55
|
+
/// <summary>
|
|
56
|
+
/// Gets the current socket session ID.
|
|
57
|
+
/// </summary>
|
|
58
|
+
/// <returns>The socket session ID, or null if not connected.</returns>
|
|
29
59
|
public static string getSocketSId() => GNNetwork.peer != null ? GNNetwork.peer.getClientId() : null;
|
|
30
60
|
|
|
61
|
+
/// <summary>
|
|
62
|
+
/// Checks if the socket connection is active.
|
|
63
|
+
/// </summary>
|
|
64
|
+
/// <returns>True if the socket is connected; otherwise, false.</returns>
|
|
31
65
|
public static bool isSocketConnected() => !string.IsNullOrEmpty(GNNetwork.getSocketSId());
|
|
32
66
|
|
|
67
|
+
/// <summary>
|
|
68
|
+
/// Gets the server's current timestamp in milliseconds.
|
|
69
|
+
/// </summary>
|
|
70
|
+
/// <returns>The server's current timestamp, or the local UTC timestamp if no peer exists.</returns>
|
|
33
71
|
public static long getServerTimestamp() => GNNetwork.peer != null ? GNNetwork.peer.getServerTimestamp() : DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
|
|
34
72
|
|
|
73
|
+
/// <summary>
|
|
74
|
+
/// Gets the current authentication status of the connection.
|
|
75
|
+
/// </summary>
|
|
76
|
+
/// <returns>The current <see cref="AuthenticateStatus"/> of the peer.</returns>
|
|
35
77
|
public static AuthenticateStatus getAuthenticateStatus() => GNNetwork.peer.authenticateStatus;
|
|
36
78
|
|
|
37
|
-
|
|
38
|
-
|
|
79
|
+
/// <summary>
|
|
80
|
+
/// Gets the current override gameId
|
|
81
|
+
/// </summary>
|
|
82
|
+
/// <returns></returns>
|
|
83
|
+
public static string getGameId() => GNNetwork.peer.gameId;
|
|
84
|
+
|
|
85
|
+
/// <summary>
|
|
86
|
+
/// Gets the current platform of the application.
|
|
87
|
+
/// </summary>
|
|
88
|
+
/// <returns>The current runtime platform.</returns>
|
|
89
|
+
public static UnityEngine.RuntimePlatform getPlatform() => UnityEngine.Application.platform;
|
|
90
|
+
|
|
91
|
+
/// <summary>
|
|
92
|
+
/// Static constructor initializes the GNNetwork class.
|
|
93
|
+
/// </summary>
|
|
39
94
|
static GNNetwork()
|
|
40
95
|
{
|
|
41
96
|
GNNetwork.initServerSettings();
|
|
42
97
|
GNNetwork.initGNDebug();
|
|
43
98
|
|
|
44
|
-
if (!Application.isPlaying) return;
|
|
99
|
+
if (!UnityEngine.Application.isPlaying) return;
|
|
45
100
|
|
|
46
|
-
GNDebug.log("GNNetwork init on
|
|
101
|
+
GNDebug.log("GNNetwork init on Unity. Version: " + GNNetwork.getClientSdkVersion());
|
|
47
102
|
|
|
48
103
|
GNNetwork.initGNSocketObject();
|
|
49
104
|
|
|
50
|
-
GNNetwork.peer.authenticateStatus.setAuthToken(PlayerPrefs.GetString(GNNetwork.AUTH_TOKEN_KEY, string.Empty));
|
|
51
|
-
GNNetwork.peer.authenticateStatus.setUserId(PlayerPrefs.GetString(GNNetwork.USER_ID_KEY, string.Empty));
|
|
105
|
+
GNNetwork.peer.authenticateStatus.setAuthToken(UnityEngine.PlayerPrefs.GetString(GNNetwork.AUTH_TOKEN_KEY, string.Empty));
|
|
106
|
+
GNNetwork.peer.authenticateStatus.setUserId(UnityEngine.PlayerPrefs.GetString(GNNetwork.USER_ID_KEY, string.Empty));
|
|
107
|
+
GNNetwork.peer.gameId = UnityEngine.PlayerPrefs.GetString(GNNetwork.GAME_ID_KEY, string.Empty);
|
|
52
108
|
|
|
53
109
|
GNNetwork.authenticate = new AuthenticateApi();
|
|
54
110
|
GNNetwork.characterPlayer = new CharacterPlayerApi();
|
|
@@ -60,30 +116,44 @@
|
|
|
60
116
|
GNNetwork.masterPlayer = new MasterPlayerApi();
|
|
61
117
|
GNNetwork.storeInventory = new StoreInventoryApi();
|
|
62
118
|
GNNetwork.multiplayer = new MultiplayerApi();
|
|
119
|
+
GNNetwork.cloudScript = new CloudScriptApi();
|
|
63
120
|
}
|
|
64
121
|
|
|
122
|
+
/// <summary>
|
|
123
|
+
/// Gets the current SDK version.
|
|
124
|
+
/// </summary>
|
|
125
|
+
/// <returns>The current SDK version as a string.</returns>
|
|
65
126
|
public static string getClientSdkVersion() => GNNetwork.GN_VERSION;
|
|
66
127
|
|
|
128
|
+
/// <summary>
|
|
129
|
+
/// Initializes server settings from resources.
|
|
130
|
+
/// </summary>
|
|
67
131
|
private static void initServerSettings()
|
|
68
132
|
{
|
|
69
|
-
GNNetwork.gnServerSettings = Resources.Load(GNServerSettings.ResourcesPath) as GNServerSettings;
|
|
133
|
+
GNNetwork.gnServerSettings = UnityEngine.Resources.Load(GNServerSettings.ResourcesPath) as GNServerSettings;
|
|
70
134
|
if (GNNetwork.gnServerSettings == null)
|
|
71
135
|
{
|
|
72
136
|
#if UNITY_EDITOR
|
|
73
137
|
UnityEditor.EditorApplication.ExecuteMenuItem("XmobiTea GN/Open Settings");
|
|
74
|
-
GNNetwork.gnServerSettings = Resources.Load(GNServerSettings.ResourcesPath) as GNServerSettings;
|
|
138
|
+
GNNetwork.gnServerSettings = UnityEngine.Resources.Load(GNServerSettings.ResourcesPath) as GNServerSettings;
|
|
75
139
|
if (GNNetwork.gnServerSettings == null) throw new NullReferenceException("Null GN Server Settings, please find it now");
|
|
76
140
|
#endif
|
|
77
141
|
}
|
|
78
142
|
}
|
|
79
143
|
|
|
144
|
+
/// <summary>
|
|
145
|
+
/// Initializes GN Debug settings based on the loaded server settings.
|
|
146
|
+
/// </summary>
|
|
80
147
|
private static void initGNDebug()
|
|
81
148
|
{
|
|
82
|
-
if (GNNetwork.gnServerSettings == null) throw new NullReferenceException("Null
|
|
149
|
+
if (GNNetwork.gnServerSettings == null) throw new NullReferenceException("Null GN Server Settings, please find it now");
|
|
83
150
|
|
|
84
151
|
GNDebug.logType = GNNetwork.gnServerSettings.getLogType();
|
|
85
152
|
}
|
|
86
153
|
|
|
154
|
+
/// <summary>
|
|
155
|
+
/// Initializes the socket connection object and its corresponding service update GameObject.
|
|
156
|
+
/// </summary>
|
|
87
157
|
private static void initGNSocketObject()
|
|
88
158
|
{
|
|
89
159
|
var peer = new NetworkingPeer();
|
|
@@ -92,32 +162,189 @@
|
|
|
92
162
|
|
|
93
163
|
GNNetwork.peer = peer;
|
|
94
164
|
|
|
95
|
-
var serviceUpdate = new GameObject("[GN] ServiceUpdate").AddComponent<Unity.ServiceUpdate>();
|
|
96
|
-
GameObject.DontDestroyOnLoad(serviceUpdate.gameObject);
|
|
165
|
+
var serviceUpdate = new UnityEngine.GameObject("[GN] ServiceUpdate").AddComponent<Unity.ServiceUpdate>();
|
|
166
|
+
UnityEngine.GameObject.DontDestroyOnLoad(serviceUpdate.gameObject);
|
|
97
167
|
|
|
98
168
|
serviceUpdate.peer = peer;
|
|
99
169
|
}
|
|
100
170
|
|
|
171
|
+
public static void setNewAuthenticateStatus(AuthenticateStatus authenticateStatus)
|
|
172
|
+
{
|
|
173
|
+
UnityEngine.PlayerPrefs.SetString(GNNetwork.AUTH_TOKEN_KEY, authenticateStatus.getAuthToken());
|
|
174
|
+
UnityEngine.PlayerPrefs.SetString(GNNetwork.USER_ID_KEY, authenticateStatus.getUserId());
|
|
175
|
+
|
|
176
|
+
GNNetwork.peer.authenticateStatus.setAuthToken(authenticateStatus.getAuthToken());
|
|
177
|
+
GNNetwork.peer.authenticateStatus.setUserId(authenticateStatus.getUserId());
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
public static void setGameId(string gameId)
|
|
181
|
+
{
|
|
182
|
+
UnityEngine.PlayerPrefs.SetString(GNNetwork.GAME_ID_KEY, gameId);
|
|
183
|
+
|
|
184
|
+
GNNetwork.peer.gameId = gameId;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/// <summary>
|
|
188
|
+
/// Sends a request via socket.
|
|
189
|
+
/// </summary>
|
|
190
|
+
/// <param name="requestType">The type of the request.</param>
|
|
191
|
+
/// <param name="requestRole">The role of the request.</param>
|
|
192
|
+
/// <param name="request">The request data to send.</param>
|
|
193
|
+
/// <param name="onResponse">Optional callback for handling the response.</param>
|
|
194
|
+
/// <param name="overrideAuthToken">Optional token override for the request.</param>
|
|
195
|
+
/// <param name="overrideSecretKey">Optional secret key override for the request.</param>
|
|
196
|
+
/// <param name="customTags">Optional custom tags for the request.</param>
|
|
101
197
|
public static void sendViaSocket(RequestType requestType, RequestRole requestRole, OperationRequest request, Action<OperationResponse> onResponse = null, string overrideAuthToken = null, string overrideSecretKey = null, GNHashtable customTags = null)
|
|
102
198
|
{
|
|
103
199
|
GNNetwork.peer.sendViaSocket(requestType, requestRole, request, onResponse, overrideAuthToken, overrideSecretKey, customTags);
|
|
104
200
|
}
|
|
105
201
|
|
|
202
|
+
/// <summary>
|
|
203
|
+
/// Sends a request via socket asynchronously and returns the response.
|
|
204
|
+
/// </summary>
|
|
205
|
+
/// <param name="requestType">The type of the request.</param>
|
|
206
|
+
/// <param name="requestRole">The role of the request.</param>
|
|
207
|
+
/// <param name="request">The request data.</param>
|
|
208
|
+
/// <param name="overrideAuthToken">Optional token to override the default authentication token.</param>
|
|
209
|
+
/// <param name="overrideSecretKey">Optional secret key to override the default key.</param>
|
|
210
|
+
/// <param name="customTags">Optional custom tags for the request.</param>
|
|
211
|
+
/// <returns>A Task that resolves with the operation response.</returns>
|
|
212
|
+
public static Task<OperationResponse> sendViaSocketAsync(RequestType requestType, RequestRole requestRole, OperationRequest request, string overrideAuthToken = null, string overrideSecretKey = null, GNHashtable customTags = null)
|
|
213
|
+
{
|
|
214
|
+
var taskCompletionSource = new TaskCompletionSource<OperationResponse>();
|
|
215
|
+
|
|
216
|
+
GNNetwork.sendViaSocket(requestType, requestRole, request, response =>
|
|
217
|
+
{
|
|
218
|
+
taskCompletionSource.SetResult(response);
|
|
219
|
+
}, overrideAuthToken, overrideSecretKey, customTags);
|
|
220
|
+
|
|
221
|
+
return taskCompletionSource.Task;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/// <summary>
|
|
225
|
+
/// Sends a request via HTTP.
|
|
226
|
+
/// </summary>
|
|
227
|
+
/// <param name="requestType">The type of the request.</param>
|
|
228
|
+
/// <param name="requestRole">The role of the request.</param>
|
|
229
|
+
/// <param name="request">The request data.</param>
|
|
230
|
+
/// <param name="onResponse">Optional callback to handle the response.</param>
|
|
231
|
+
/// <param name="overrideAuthToken">Optional token to override the default authentication token.</param>
|
|
232
|
+
/// <param name="overrideSecretKey">Optional secret key to override the default key.</param>
|
|
233
|
+
/// <param name="customTags">Optional custom tags for the request.</param>
|
|
106
234
|
public static void sendViaHttp(RequestType requestType, RequestRole requestRole, OperationRequest request, Action<OperationResponse> onResponse = null, string overrideAuthToken = null, string overrideSecretKey = null, GNHashtable customTags = null)
|
|
107
235
|
{
|
|
108
236
|
GNNetwork.peer.sendViaHttp(requestType, requestRole, request, onResponse, overrideAuthToken, overrideSecretKey, customTags);
|
|
109
237
|
}
|
|
110
238
|
|
|
239
|
+
/// <summary>
|
|
240
|
+
/// Sends a request via HTTP asynchronously and returns the response.
|
|
241
|
+
/// </summary>
|
|
242
|
+
/// <param name="requestType">The type of the request.</param>
|
|
243
|
+
/// <param name="requestRole">The role of the request.</param>
|
|
244
|
+
/// <param name="request">The request data.</param>
|
|
245
|
+
/// <param name="overrideAuthToken">Optional token to override the default authentication token.</param>
|
|
246
|
+
/// <param name="overrideSecretKey">Optional secret key to override the default key.</param>
|
|
247
|
+
/// <param name="customTags">Optional custom tags for the request.</param>
|
|
248
|
+
/// <returns>A Task that resolves with the operation response.</returns>
|
|
249
|
+
public static Task<OperationResponse> sendViaHttpAsync(RequestType requestType, RequestRole requestRole, OperationRequest request, string overrideAuthToken = null, string overrideSecretKey = null, GNHashtable customTags = null)
|
|
250
|
+
{
|
|
251
|
+
var taskCompletionSource = new TaskCompletionSource<OperationResponse>();
|
|
252
|
+
|
|
253
|
+
GNNetwork.sendViaHttp(requestType, requestRole, request, response =>
|
|
254
|
+
{
|
|
255
|
+
taskCompletionSource.SetResult(response);
|
|
256
|
+
}, overrideAuthToken, overrideSecretKey, customTags);
|
|
257
|
+
|
|
258
|
+
return taskCompletionSource.Task;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
/// <summary>
|
|
262
|
+
/// Sends a request via socket with strongly-typed request and response.
|
|
263
|
+
/// </summary>
|
|
264
|
+
/// <typeparam name="TRequest">The type of the request.</typeparam>
|
|
265
|
+
/// <typeparam name="TResponse">The type of the response.</typeparam>
|
|
266
|
+
/// <param name="request">The request object to send.</param>
|
|
267
|
+
/// <param name="onResponse">Optional callback to handle the response.</param>
|
|
268
|
+
/// <param name="overrideAuthToken">Optional token to override the default authentication token.</param>
|
|
269
|
+
/// <param name="overrideSecretKey">Optional secret key to override the default key.</param>
|
|
270
|
+
/// <param name="customTags">Optional custom tags for the request.</param>
|
|
111
271
|
public static void sendViaSocket<TRequest, TResponse>(TRequest request, Action<TResponse> onResponse = null, string overrideAuthToken = null, string overrideSecretKey = null, GNHashtable customTags = null) where TRequest : CustomOperationRequest where TResponse : CustomOperationResponse, new()
|
|
112
272
|
{
|
|
113
273
|
GNNetwork.sendViaSocket(request.getRequestType(), request.getRequestRole(), request.build(), onResponse, overrideAuthToken, overrideSecretKey, customTags);
|
|
114
274
|
}
|
|
115
275
|
|
|
276
|
+
/// <summary>
|
|
277
|
+
/// Sends a request via socket asynchronously with strongly-typed request and response.
|
|
278
|
+
/// </summary>
|
|
279
|
+
/// <typeparam name="TRequest">The type of the request.</typeparam>
|
|
280
|
+
/// <typeparam name="TResponse">The type of the response.</typeparam>
|
|
281
|
+
/// <param name="request">The request object to send.</param>
|
|
282
|
+
/// <param name="overrideAuthToken">Optional token to override the default authentication token.</param>
|
|
283
|
+
/// <param name="overrideSecretKey">Optional secret key to override the default key.</param>
|
|
284
|
+
/// <param name="customTags">Optional custom tags for the request.</param>
|
|
285
|
+
/// <returns>A Task that resolves with the typed response.</returns>
|
|
286
|
+
public static Task<TResponse> sendViaSocketAsync<TRequest, TResponse>(TRequest request, string overrideAuthToken = null, string overrideSecretKey = null, GNHashtable customTags = null) where TRequest : CustomOperationRequest where TResponse : CustomOperationResponse, new()
|
|
287
|
+
{
|
|
288
|
+
var taskCompletionSource = new TaskCompletionSource<TResponse>();
|
|
289
|
+
|
|
290
|
+
GNNetwork.sendViaSocket<TRequest, TResponse>(request, response =>
|
|
291
|
+
{
|
|
292
|
+
taskCompletionSource.SetResult(response);
|
|
293
|
+
}, overrideAuthToken, overrideSecretKey, customTags);
|
|
294
|
+
|
|
295
|
+
return taskCompletionSource.Task;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
// Similar comments for other methods (HTTP variants and generics)
|
|
299
|
+
|
|
300
|
+
/// <summary>
|
|
301
|
+
/// Sends a request via HTTP with strongly-typed request and response.
|
|
302
|
+
/// </summary>
|
|
303
|
+
/// <typeparam name="TRequest">The type of the request.</typeparam>
|
|
304
|
+
/// <typeparam name="TResponse">The type of the response.</typeparam>
|
|
305
|
+
/// <param name="request">The request object to send.</param>
|
|
306
|
+
/// <param name="onResponse">Optional callback to handle the response.</param>
|
|
307
|
+
/// <param name="overrideAuthToken">Optional token to override the default authentication token.</param>
|
|
308
|
+
/// <param name="overrideSecretKey">Optional secret key to override the default key.</param>
|
|
309
|
+
/// <param name="customTags">Optional custom tags for the request.</param>
|
|
116
310
|
public static void sendViaHttp<TRequest, TResponse>(TRequest request, Action<TResponse> onResponse = null, string overrideAuthToken = null, string overrideSecretKey = null, GNHashtable customTags = null) where TRequest : CustomOperationRequest where TResponse : CustomOperationResponse, new()
|
|
117
311
|
{
|
|
118
312
|
GNNetwork.sendViaHttp(request.getRequestType(), request.getRequestRole(), request.build(), onResponse, overrideAuthToken, overrideSecretKey, customTags);
|
|
119
313
|
}
|
|
120
314
|
|
|
315
|
+
/// <summary>
|
|
316
|
+
/// Sends a request via HTTP asynchronously with strongly-typed request and response.
|
|
317
|
+
/// </summary>
|
|
318
|
+
/// <typeparam name="TRequest">The type of the request.</typeparam>
|
|
319
|
+
/// <typeparam name="TResponse">The type of the response.</typeparam>
|
|
320
|
+
/// <param name="request">The request object to send.</param>
|
|
321
|
+
/// <param name="overrideAuthToken">Optional token to override the default authentication token.</param>
|
|
322
|
+
/// <param name="overrideSecretKey">Optional secret key to override the default key.</param>
|
|
323
|
+
/// <param name="customTags">Optional custom tags for the request.</param>
|
|
324
|
+
/// <returns>A Task that resolves with the typed response.</returns>
|
|
325
|
+
public static Task<TResponse> sendViaHttpAsync<TRequest, TResponse>(TRequest request, string overrideAuthToken = null, string overrideSecretKey = null, GNHashtable customTags = null) where TRequest : CustomOperationRequest where TResponse : CustomOperationResponse, new()
|
|
326
|
+
{
|
|
327
|
+
var taskCompletionSource = new TaskCompletionSource<TResponse>();
|
|
328
|
+
|
|
329
|
+
GNNetwork.sendViaHttp<TRequest, TResponse>(request, response =>
|
|
330
|
+
{
|
|
331
|
+
taskCompletionSource.SetResult(response);
|
|
332
|
+
}, overrideAuthToken, overrideSecretKey, customTags);
|
|
333
|
+
|
|
334
|
+
return taskCompletionSource.Task;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
/// <summary>
|
|
338
|
+
/// Sends a request via socket with a strongly-typed response.
|
|
339
|
+
/// </summary>
|
|
340
|
+
/// <typeparam name="TResponse">The type of the response object.</typeparam>
|
|
341
|
+
/// <param name="requestType">The type of the request being sent.</param>
|
|
342
|
+
/// <param name="requestRole">The role of the request being sent.</param>
|
|
343
|
+
/// <param name="request">The request data to send.</param>
|
|
344
|
+
/// <param name="onResponse">Optional callback to handle the strongly-typed response.</param>
|
|
345
|
+
/// <param name="overrideAuthToken">Optional authentication token to override the default value.</param>
|
|
346
|
+
/// <param name="overrideSecretKey">Optional secret key to override the default value.</param>
|
|
347
|
+
/// <param name="customTags">Optional custom tags to send with the request.</param>
|
|
121
348
|
public static void sendViaSocket<TResponse>(RequestType requestType, RequestRole requestRole, OperationRequest request, Action<TResponse> onResponse = null, string overrideAuthToken = null, string overrideSecretKey = null, GNHashtable customTags = null) where TResponse : CustomOperationResponse, new()
|
|
122
349
|
{
|
|
123
350
|
GNNetwork.sendViaSocket(requestType, requestRole, request, response =>
|
|
@@ -131,6 +358,40 @@
|
|
|
131
358
|
}, overrideAuthToken, overrideSecretKey, customTags);
|
|
132
359
|
}
|
|
133
360
|
|
|
361
|
+
/// <summary>
|
|
362
|
+
/// Sends a request via socket asynchronously with a strongly-typed response.
|
|
363
|
+
/// </summary>
|
|
364
|
+
/// <typeparam name="TResponse">The type of the response object.</typeparam>
|
|
365
|
+
/// <param name="requestType">The type of the request being sent.</param>
|
|
366
|
+
/// <param name="requestRole">The role of the request being sent.</param>
|
|
367
|
+
/// <param name="request">The request data to send.</param>
|
|
368
|
+
/// <param name="overrideAuthToken">Optional authentication token to override the default value.</param>
|
|
369
|
+
/// <param name="overrideSecretKey">Optional secret key to override the default value.</param>
|
|
370
|
+
/// <param name="customTags">Optional custom tags to send with the request.</param>
|
|
371
|
+
/// <returns>A Task that resolves to the strongly-typed response.</returns>
|
|
372
|
+
public static Task<TResponse> sendViaSocketAsync<TResponse>(RequestType requestType, RequestRole requestRole, OperationRequest request, string overrideAuthToken = null, string overrideSecretKey = null, GNHashtable customTags = null) where TResponse : CustomOperationResponse, new()
|
|
373
|
+
{
|
|
374
|
+
var taskCompletionSource = new TaskCompletionSource<TResponse>();
|
|
375
|
+
|
|
376
|
+
GNNetwork.sendViaSocket<TResponse>(requestType, requestRole, request, response =>
|
|
377
|
+
{
|
|
378
|
+
taskCompletionSource.SetResult(response);
|
|
379
|
+
}, overrideAuthToken, overrideSecretKey, customTags);
|
|
380
|
+
|
|
381
|
+
return taskCompletionSource.Task;
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
/// <summary>
|
|
385
|
+
/// Sends a request via HTTP with a strongly-typed response.
|
|
386
|
+
/// </summary>
|
|
387
|
+
/// <typeparam name="TResponse">The type of the response object.</typeparam>
|
|
388
|
+
/// <param name="requestType">The type of the request being sent.</param>
|
|
389
|
+
/// <param name="requestRole">The role of the request being sent.</param>
|
|
390
|
+
/// <param name="request">The request data to send.</param>
|
|
391
|
+
/// <param name="onResponse">Optional callback to handle the strongly-typed response.</param>
|
|
392
|
+
/// <param name="overrideAuthToken">Optional authentication token to override the default value.</param>
|
|
393
|
+
/// <param name="overrideSecretKey">Optional secret key to override the default value.</param>
|
|
394
|
+
/// <param name="customTags">Optional custom tags to send with the request.</param>
|
|
134
395
|
public static void sendViaHttp<TResponse>(RequestType requestType, RequestRole requestRole, OperationRequest request, Action<TResponse> onResponse = null, string overrideAuthToken = null, string overrideSecretKey = null, GNHashtable customTags = null) where TResponse : CustomOperationResponse, new()
|
|
135
396
|
{
|
|
136
397
|
GNNetwork.sendViaHttp(requestType, requestRole, request, response =>
|
|
@@ -144,36 +405,87 @@
|
|
|
144
405
|
}, overrideAuthToken, overrideSecretKey, customTags);
|
|
145
406
|
}
|
|
146
407
|
|
|
408
|
+
/// <summary>
|
|
409
|
+
/// Sends a request via HTTP asynchronously with a strongly-typed response.
|
|
410
|
+
/// </summary>
|
|
411
|
+
/// <typeparam name="TResponse">The type of the response object.</typeparam>
|
|
412
|
+
/// <param name="requestType">The type of the request being sent.</param>
|
|
413
|
+
/// <param name="requestRole">The role of the request being sent.</param>
|
|
414
|
+
/// <param name="request">The request data to send.</param>
|
|
415
|
+
/// <param name="overrideAuthToken">Optional authentication token to override the default value.</param>
|
|
416
|
+
/// <param name="overrideSecretKey">Optional secret key to override the default value.</param>
|
|
417
|
+
/// <param name="customTags">Optional custom tags to send with the request.</param>
|
|
418
|
+
/// <returns>A Task that resolves to the strongly-typed response.</returns>
|
|
419
|
+
public static Task<TResponse> sendViaHttpAsync<TResponse>(RequestType requestType, RequestRole requestRole, OperationRequest request, string overrideAuthToken = null, string overrideSecretKey = null, GNHashtable customTags = null) where TResponse : CustomOperationResponse, new()
|
|
420
|
+
{
|
|
421
|
+
var taskCompletionSource = new TaskCompletionSource<TResponse>();
|
|
422
|
+
|
|
423
|
+
GNNetwork.sendViaHttp<TResponse>(requestType, requestRole, request, response =>
|
|
424
|
+
{
|
|
425
|
+
taskCompletionSource.SetResult(response);
|
|
426
|
+
}, overrideAuthToken, overrideSecretKey, customTags);
|
|
427
|
+
|
|
428
|
+
return taskCompletionSource.Task;
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
/// <summary>
|
|
432
|
+
/// Connects to the socket server.
|
|
433
|
+
/// </summary>
|
|
434
|
+
/// <param name="_onSocketConnect">Optional callback invoked when the socket is connected.</param>
|
|
147
435
|
public static void connectSocket(Action _onSocketConnect = null)
|
|
148
436
|
{
|
|
149
437
|
GNNetwork.peer.connectSocket(_onSocketConnect);
|
|
150
438
|
}
|
|
151
439
|
|
|
440
|
+
/// <summary>
|
|
441
|
+
/// Disconnects from the socket server.
|
|
442
|
+
/// </summary>
|
|
443
|
+
/// <param name="_onSocketDisconnect">Optional callback invoked when the socket is disconnected.</param>
|
|
152
444
|
public static void disconnectSocket(Action _onSocketDisconnect = null)
|
|
153
445
|
{
|
|
154
446
|
GNNetwork.peer.disconnectSocket(_onSocketDisconnect);
|
|
155
447
|
}
|
|
156
448
|
|
|
449
|
+
/// <summary>
|
|
450
|
+
/// Subscribes to event handlers for socket events.
|
|
451
|
+
/// </summary>
|
|
452
|
+
/// <param name="_onEventHandler">The handler to invoke when an event occurs.</param>
|
|
157
453
|
public static void setOnEventHandler(Action<OperationEvent> _onEventHandler)
|
|
158
454
|
{
|
|
159
455
|
GNNetwork.peer.setOnEventHandler(_onEventHandler);
|
|
160
456
|
}
|
|
161
457
|
|
|
458
|
+
/// <summary>
|
|
459
|
+
/// Subscribes a handler to be invoked when the socket connects successfully.
|
|
460
|
+
/// </summary>
|
|
461
|
+
/// <param name="onConnectHandler">The action to execute when the socket connects.</param>
|
|
162
462
|
public static void subscriberOnConnectHandler(Action onConnectHandler)
|
|
163
463
|
{
|
|
164
464
|
GNNetwork.peer.setOnConnectHandler(onConnectHandler);
|
|
165
465
|
}
|
|
166
466
|
|
|
467
|
+
/// <summary>
|
|
468
|
+
/// Subscribes a handler to be invoked when the socket disconnects.
|
|
469
|
+
/// </summary>
|
|
470
|
+
/// <param name="onDisconnectHandler">The action to execute when the socket disconnects.</param>
|
|
167
471
|
public static void subscriberOnDisconnectHandler(Action onDisconnectHandler)
|
|
168
472
|
{
|
|
169
473
|
GNNetwork.peer.setOnDisconnectHandler(onDisconnectHandler);
|
|
170
474
|
}
|
|
171
475
|
|
|
476
|
+
/// <summary>
|
|
477
|
+
/// Unsubscribes a previously subscribed handler for socket connection events.
|
|
478
|
+
/// </summary>
|
|
479
|
+
/// <param name="onConnectHandler">The action to remove from connection event handlers.</param>
|
|
172
480
|
public static void unscriberOnConnectHandler(Action onConnectHandler)
|
|
173
481
|
{
|
|
174
482
|
GNNetwork.peer.removeOnConnectHandler(onConnectHandler);
|
|
175
483
|
}
|
|
176
484
|
|
|
485
|
+
/// <summary>
|
|
486
|
+
/// Unsubscribes a previously subscribed handler for socket disconnection events.
|
|
487
|
+
/// </summary>
|
|
488
|
+
/// <param name="onDisconnectHandler">The action to remove from disconnection event handlers.</param>
|
|
177
489
|
public static void unsubscriberOnDisconnectHandler(Action onDisconnectHandler)
|
|
178
490
|
{
|
|
179
491
|
GNNetwork.peer.removeOnDisconnectHandler(onDisconnectHandler);
|
package/Runtime/GNNetworkApi.cs
CHANGED
|
@@ -1,26 +1,38 @@
|
|
|
1
1
|
namespace XmobiTea.GN
|
|
2
2
|
{
|
|
3
|
-
using XmobiTea.GN.Common;
|
|
4
|
-
using XmobiTea.GN.Entity.Response;
|
|
5
|
-
|
|
6
3
|
using System;
|
|
7
|
-
using
|
|
8
|
-
using XmobiTea.GN.Constant;
|
|
9
|
-
using System.Collections.Generic;
|
|
10
|
-
using XmobiTea.GN.Entity;
|
|
4
|
+
using System.Threading.Tasks;
|
|
11
5
|
|
|
12
6
|
public static partial class GNNetwork
|
|
13
7
|
{
|
|
14
|
-
|
|
8
|
+
/// <summary>
|
|
9
|
+
/// Synchronizes the timestamp by calling a peer method and invokes the callback with the result.
|
|
10
|
+
/// </summary>
|
|
11
|
+
/// <param name="onResponse">An optional callback that receives the synchronized timestamp.</param>
|
|
12
|
+
public static void syncTs(Action<long> onResponse = null)
|
|
15
13
|
{
|
|
14
|
+
// Delegate the synchronization to the peer's syncTs method.
|
|
16
15
|
GNNetwork.peer.syncTs(onResponse);
|
|
17
16
|
}
|
|
18
17
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
18
|
+
/// <summary>
|
|
19
|
+
/// Asynchronously synchronizes the timestamp and returns the result as a Task.
|
|
20
|
+
/// </summary>
|
|
21
|
+
/// <returns>A Task that resolves to the synchronized timestamp.</returns>
|
|
22
|
+
public static Task<long> syncTsAsync()
|
|
23
|
+
{
|
|
24
|
+
// Create a TaskCompletionSource to manage the asynchronous operation.
|
|
25
|
+
var taskCompletionSource = new TaskCompletionSource<long>();
|
|
23
26
|
|
|
24
|
-
|
|
27
|
+
// Call the syncTs method and use the callback to set the Task result.
|
|
28
|
+
GNNetwork.syncTs(response =>
|
|
29
|
+
{
|
|
30
|
+
// Set the result of the Task once the callback is invoked.
|
|
31
|
+
taskCompletionSource.SetResult(response);
|
|
32
|
+
});
|
|
25
33
|
|
|
34
|
+
// Return the Task to the caller, allowing them to await the result.
|
|
35
|
+
return taskCompletionSource.Task;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
26
38
|
}
|