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