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,242 +1,305 @@
1
- namespace XmobiTea.GN.Networking
2
- {
3
- using System;
4
- using System.Collections.Generic;
5
- using System.Linq;
6
- using UnityEngine;
7
- using XmobiTea.GN.Common;
8
- using XmobiTea.GN.Constant;
9
- using XmobiTea.GN.Entity;
10
- using XmobiTea.GN.Logger;
11
-
12
- internal abstract class PeerBase : IPeer
13
- {
14
- private Queue<OperationPending> operationPendingQueue;
15
-
16
- private Dictionary<int, OperationPending> operationWaitingResponseDict;
17
-
18
- private static int requestId;
19
-
20
- private float perMsgTimer;
21
- private float nextSendMsgTimer;
22
- private float checkTimeoutOperationPending = 0;
23
-
24
- protected int getSendRate()
25
- {
26
- return (int)(1000 / this.perMsgTimer);
27
- }
28
-
29
- protected void setSendRate(int sendRate)
30
- {
31
- this.perMsgTimer = (float)1000 / sendRate / 1000;
32
- }
33
-
34
- internal int ping { get; set; } = -1;
35
- private Queue<float> pingLst;
36
-
37
- protected bool isUse { get; set; }
38
-
39
- void IPeer.initPeer()
40
- {
41
- if (this.operationWaitingResponseDict == null) this.operationWaitingResponseDict = new Dictionary<int, OperationPending>();
42
-
43
- if (this.operationPendingQueue == null) this.operationPendingQueue = new Queue<OperationPending>();
44
-
45
- if (this.pingLst == null) this.pingLst = new Queue<float>();
46
-
47
- this.initSendRate();
48
- this.initGNSocketObject();
49
- }
50
-
51
- private void initSendRate()
52
- {
53
- var gnServerSettings = GNNetwork.gnServerSettings;
54
- if (gnServerSettings == null) throw new NullReferenceException("Null GN Server Settings, please find it now");
55
-
56
- this.setSendRate(gnServerSettings.getSendRate());
57
- }
58
-
59
- internal abstract void initGNSocketObject();
60
-
61
- void IPeer.enqueue(RequestType requestType, RequestRole requestRole, OperationRequest operationRequest, Action<OperationResponse> onOperationResponse, string authToken, string secretKey, GNHashtable customTags)
62
- {
63
- if (!this.isUse)
64
- {
65
- GNDebug.logError("[GN] Server Settings dont setup to use this to send operation request.");
66
- return;
67
- }
68
-
69
- var operationPending = new OperationPending(requestType, requestRole, operationRequest, onOperationResponse, authToken, secretKey, customTags);
70
- this.operationPendingQueue.Enqueue(operationPending);
71
- }
72
-
73
- bool IPeer.isUsing()
74
- {
75
- return this.isUse;
76
- }
77
-
78
- public virtual void service()
79
- {
80
- if (!this.isUse) return;
81
-
82
- if (this.checkTimeoutOperationPending < UnityEngine.Time.time)
83
- {
84
- this.checkTimeoutOperationPending = UnityEngine.Time.time + 0.1f;
85
-
86
- if (this.operationWaitingResponseDict.Count != 0)
87
- {
88
- var gnArrayLst = new List<GNArray>();
89
-
90
- foreach (var operationPendingPair in this.operationWaitingResponseDict)
91
- {
92
- var operationPending = operationPendingPair.Value;
93
-
94
- if (operationPending.isTimeout())
95
- {
96
- var gnArray = new GNArray();
97
-
98
- gnArray.add((int)ReturnCode.OperationTimeout);
99
- gnArray.add(null);
100
- gnArray.add(operationPending.getOperationRequest().getRequestId());
101
- gnArray.add(operationPending.getOperationRequest().isEncrypted());
102
-
103
- gnArrayLst.Add(gnArray);
104
- }
105
- }
106
-
107
- if (gnArrayLst.Count != 0)
108
- {
109
- foreach (var gnArray in gnArrayLst)
110
- {
111
- this.onResponseHandler(gnArray, gnArray.getBool(3));
112
- }
113
- }
114
- }
115
- }
116
-
117
- if (this.nextSendMsgTimer < UnityEngine.Time.time)
118
- {
119
- if (this.operationPendingQueue.Count != 0)
120
- {
121
- this.nextSendMsgTimer = UnityEngine.Time.time + this.perMsgTimer;
122
-
123
- var operationPending = this.operationPendingQueue.Dequeue();
124
-
125
- this.send(operationPending);
126
- }
127
- }
128
- }
129
-
130
- internal void onResponseHandler(GNArray obj, bool isEncrypted)
131
- {
132
- var responseId = obj.getInt(2);
133
-
134
- if (this.operationWaitingResponseDict.ContainsKey(responseId))
135
- {
136
- var operationPending = this.operationWaitingResponseDict[responseId];
137
- operationPending.onRecv();
138
-
139
- this.operationWaitingResponseDict.Remove(responseId);
140
-
141
- var returnCode = obj.getInt(0);
142
-
143
- GNHashtable parameters = null;
144
- string debugMessage = null;
145
- GNArray array = null;
146
-
147
- if (returnCode == ReturnCode.Ok) parameters = obj.getGNHashtable(1);
148
- else if (returnCode == ReturnCode.InvalidRequestParameters) array = obj.getGNArray(1);
149
- else if (returnCode == ReturnCode.OperationNotAuthorized)
150
- {
151
-
152
- }
153
- else debugMessage = obj.getString(1);
154
-
155
- var operationRequest = operationPending.getOperationRequest();
156
- var operationResponse = new OperationResponse(operationRequest.getOperationCode(), operationRequest.getRequestId(), isEncrypted);
157
-
158
- operationResponse.setReturnCode(returnCode);
159
- operationResponse.setDebugMessage(debugMessage);
160
- operationResponse.setParameters(parameters);
161
-
162
- //if (!parameters.containsKey(GNParameterCode.CustomTags)) parameters.add(GNParameterCode.CustomTags, customTags);
163
-
164
- if (array != null)
165
- {
166
- var invalidMembers = new InvalidMember[array.count()];
167
- for (var i = 0; i < array.count(); i++)
168
- {
169
- var arrChild = array.getGNArray(i);
170
-
171
- invalidMembers[i] = new InvalidMember(arrChild.getString(0), (InvalidMemberType)arrChild.getInt(1));
172
- }
173
- operationResponse.setInvalidMembers(invalidMembers);
174
- }
175
-
176
- if (!operationResponse.hasError())
177
- {
178
- this.addPing(operationPending.getExecuteTimerInMs());
179
-
180
- if (parameters != null)
181
- {
182
- if (parameters.containsKey(ParameterCode.AuthToken))
183
- {
184
- var authToken = parameters.getString(ParameterCode.AuthToken);
185
-
186
- GNNetwork.getAuthenticateStatus().setAuthToken(authToken);
187
-
188
- PlayerPrefs.SetString(GNNetwork.AUTH_TOKEN_KEY, authToken);
189
- }
190
-
191
- if (parameters.containsKey(ParameterCode.UserId))
192
- {
193
- var userId = parameters.getString(ParameterCode.UserId);
194
-
195
- GNNetwork.getAuthenticateStatus().setUserId(userId);
196
-
197
- PlayerPrefs.SetString(GNNetwork.USER_ID_KEY, userId);
198
- }
199
-
200
- if (parameters.containsKey(ParameterCode.Ts))
201
- {
202
- GNNetwork.peer.setServerTimeMilliseconds(parameters.getLong(ParameterCode.Ts, DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()));
203
- }
204
- }
205
- }
206
-
207
- GNDebug.log("[GN RECV] " + operationResponse.ToString());
208
-
209
- operationPending.getCallback()?.Invoke(operationResponse);
210
- }
211
- else
212
- {
213
- GNDebug.logError("[GN] OnResponseHandler, unavailable request id " + obj);
214
- }
215
- }
216
-
217
- internal virtual void send(OperationPending operationPending)
218
- {
219
- operationPending.onSend();
220
-
221
- var operationRequest = operationPending.getOperationRequest();
222
-
223
- if (operationRequest.getRequestId() != -1)
224
- {
225
- operationRequest.setRequestId(PeerBase.requestId++);
226
-
227
- if (operationPending.getCallback() != null)
228
- {
229
- this.operationWaitingResponseDict[operationRequest.getRequestId()] = operationPending;
230
- }
231
- }
232
- }
233
-
234
- private void addPing(float value)
235
- {
236
- if (this.pingLst.Count > 10) this.pingLst.Dequeue();
237
- this.pingLst.Enqueue(value / 2);
238
- this.ping = (int)(this.pingLst.Average() * 1000);
239
- }
240
- }
241
-
242
- }
1
+ namespace XmobiTea.GN.Networking
2
+ {
3
+ using System;
4
+ using System.Collections.Generic;
5
+ using System.Linq;
6
+ using XmobiTea.GN.Common;
7
+ using XmobiTea.GN.Constant;
8
+ using XmobiTea.GN.Entity;
9
+ using XmobiTea.GN.Logger;
10
+
11
+ /// <summary>
12
+ /// Abstract base class for managing common functionalities of network peers.
13
+ /// Implements the <see cref="IPeer"/> interface.
14
+ /// </summary>
15
+ internal abstract class PeerBase : IPeer
16
+ {
17
+ private Queue<OperationPending> operationPendingQueue; // Queue to store pending operations to be sent.
18
+ private Dictionary<int, OperationPending> operationWaitingResponseDict; // Dictionary to track operations awaiting responses.
19
+
20
+ private static int requestId; // Static counter for generating unique request IDs.
21
+
22
+ private float perMsgTimer; // Interval between sending messages.
23
+ private float nextSendMsgTimer; // Time for the next message to be sent.
24
+ private float checkTimeoutOperationPending = 0; // Timer to check for timed-out operations.
25
+
26
+ /// <summary>
27
+ /// Gets the message send rate (messages per second).
28
+ /// </summary>
29
+ /// <returns>The send rate in messages per second.</returns>
30
+ protected int getSendRate()
31
+ {
32
+ return (int)(1000 / this.perMsgTimer);
33
+ }
34
+
35
+ /// <summary>
36
+ /// Sets the message send rate (messages per second).
37
+ /// </summary>
38
+ /// <param name="sendRate">The desired send rate in messages per second.</param>
39
+ protected void setSendRate(int sendRate)
40
+ {
41
+ this.perMsgTimer = (float)1000 / sendRate / 1000;
42
+ }
43
+
44
+ /// <summary>
45
+ /// Gets or sets the ping value for the connection.
46
+ /// </summary>
47
+ internal int ping { get; set; } = -1;
48
+
49
+ private Queue<float> pingLst; // Queue to store recent ping values for averaging.
50
+
51
+ /// <summary>
52
+ /// Gets or sets whether this peer is in use.
53
+ /// </summary>
54
+ protected bool isUse { get; set; }
55
+
56
+ /// <summary>
57
+ /// Initializes the peer by setting up queues, dictionaries, and network objects.
58
+ /// </summary>
59
+ void IPeer.initPeer()
60
+ {
61
+ if (this.operationWaitingResponseDict == null)
62
+ this.operationWaitingResponseDict = new Dictionary<int, OperationPending>();
63
+
64
+ if (this.operationPendingQueue == null)
65
+ this.operationPendingQueue = new Queue<OperationPending>();
66
+
67
+ if (this.pingLst == null)
68
+ this.pingLst = new Queue<float>();
69
+
70
+ this.initSendRate();
71
+ this.initGNSocketObject();
72
+ }
73
+
74
+ /// <summary>
75
+ /// Initializes the message send rate based on the server settings.
76
+ /// </summary>
77
+ /// <exception cref="NullReferenceException">Thrown if server settings are not available.</exception>
78
+ private void initSendRate()
79
+ {
80
+ var gnServerSettings = GNNetwork.gnServerSettings;
81
+ if (gnServerSettings == null)
82
+ throw new NullReferenceException("Null GN Server Settings, please find it now");
83
+
84
+ this.setSendRate(gnServerSettings.getSendRate());
85
+ }
86
+
87
+ /// <summary>
88
+ /// Initializes the GN socket object for derived classes.
89
+ /// This method must be implemented in subclasses.
90
+ /// </summary>
91
+ internal abstract void initGNSocketObject();
92
+
93
+ /// <summary>
94
+ /// Enqueues an operation request for processing.
95
+ /// </summary>
96
+ /// <param name="requestType">The type of the request.</param>
97
+ /// <param name="requestRole">The role associated with the request.</param>
98
+ /// <param name="operationRequest">The operation request to be enqueued.</param>
99
+ /// <param name="onOperationResponse">The callback for the response.</param>
100
+ /// <param name="authToken">The authentication token.</param>
101
+ /// <param name="secretKey">The secret key, if applicable.</param>
102
+ /// <param name="customTags">Custom tags for the operation.</param>
103
+ void IPeer.enqueue(RequestType requestType, RequestRole requestRole, OperationRequest operationRequest, Action<OperationResponse> onOperationResponse, string authToken, string secretKey, GNHashtable customTags, string gameId)
104
+ {
105
+ if (!this.isUse)
106
+ {
107
+ GNDebug.logError("[GN] Server Settings don't setup to use this to send operation request.");
108
+ return;
109
+ }
110
+
111
+ var operationPending = new OperationPending(requestType, requestRole, operationRequest, onOperationResponse, authToken, secretKey, customTags, gameId);
112
+ this.operationPendingQueue.Enqueue(operationPending);
113
+ }
114
+
115
+ /// <summary>
116
+ /// Checks if this peer is in use.
117
+ /// </summary>
118
+ /// <returns>True if the peer is in use, otherwise false.</returns>
119
+ bool IPeer.isUsing()
120
+ {
121
+ return this.isUse;
122
+ }
123
+
124
+ /// <summary>
125
+ /// Processes pending operations and handles responses and timeouts.
126
+ /// </summary>
127
+ public virtual void service()
128
+ {
129
+ if (!this.isUse) return;
130
+
131
+ // Check for timed-out operations.
132
+ if (this.checkTimeoutOperationPending < UnityEngine.Time.time)
133
+ {
134
+ this.checkTimeoutOperationPending = UnityEngine.Time.time + 0.1f;
135
+
136
+ if (this.operationWaitingResponseDict.Count != 0)
137
+ {
138
+ var gnArrayLst = new List<GNArray>();
139
+
140
+ foreach (var operationPendingPair in this.operationWaitingResponseDict)
141
+ {
142
+ var operationPending = operationPendingPair.Value;
143
+
144
+ if (operationPending.isTimeout())
145
+ {
146
+ var gnArray = new GNArray();
147
+
148
+ gnArray.add((int)ReturnCode.OperationTimeout);
149
+ gnArray.add(null);
150
+ gnArray.add(operationPending.getOperationRequest().getRequestId());
151
+ gnArray.add(operationPending.getOperationRequest().isEncrypted());
152
+
153
+ gnArrayLst.Add(gnArray);
154
+ }
155
+ }
156
+
157
+ if (gnArrayLst.Count != 0)
158
+ {
159
+ foreach (var gnArray in gnArrayLst)
160
+ {
161
+ this.onResponseHandler(gnArray, gnArray.getBool(3));
162
+ }
163
+ }
164
+ }
165
+ }
166
+
167
+ // Send the next pending message.
168
+ if (this.nextSendMsgTimer < UnityEngine.Time.time)
169
+ {
170
+ if (this.operationPendingQueue.Count != 0)
171
+ {
172
+ this.nextSendMsgTimer = UnityEngine.Time.time + this.perMsgTimer;
173
+
174
+ var operationPending = this.operationPendingQueue.Dequeue();
175
+
176
+ this.send(operationPending);
177
+ }
178
+ }
179
+ }
180
+
181
+ /// <summary>
182
+ /// Handles responses from the server.
183
+ /// </summary>
184
+ /// <param name="obj">The response object.</param>
185
+ /// <param name="isEncrypted">Indicates if the response is encrypted.</param>
186
+ internal void onResponseHandler(GNArray obj, bool isEncrypted)
187
+ {
188
+ var responseId = obj.getInt(2);
189
+
190
+ if (this.operationWaitingResponseDict.ContainsKey(responseId))
191
+ {
192
+ var operationPending = this.operationWaitingResponseDict[responseId];
193
+ operationPending.onRecv();
194
+
195
+ this.operationWaitingResponseDict.Remove(responseId);
196
+
197
+ var returnCode = obj.getInt(0);
198
+
199
+ GNHashtable parameters = null;
200
+ string debugMessage = null;
201
+ GNArray array = null;
202
+
203
+ if (returnCode == ReturnCode.Ok) parameters = obj.getGNHashtable(1);
204
+ else if (returnCode == ReturnCode.InvalidRequestParameters) array = obj.getGNArray(1);
205
+ else if (returnCode == ReturnCode.OperationNotAuthorized)
206
+ {
207
+
208
+ }
209
+ else debugMessage = obj.getString(1);
210
+
211
+ var operationRequest = operationPending.getOperationRequest();
212
+ var operationResponse = new OperationResponse(operationRequest.getOperationCode(), operationRequest.getRequestId(), isEncrypted);
213
+
214
+ operationResponse.setReturnCode(returnCode);
215
+ operationResponse.setDebugMessage(debugMessage);
216
+ operationResponse.setParameters(parameters);
217
+
218
+ //if (!parameters.containsKey(GNParameterCode.CustomTags)) parameters.add(GNParameterCode.CustomTags, customTags);
219
+
220
+ if (array != null)
221
+ {
222
+ var invalidMembers = new InvalidMember[array.count()];
223
+ for (var i = 0; i < array.count(); i++)
224
+ {
225
+ var arrChild = array.getGNArray(i);
226
+
227
+ invalidMembers[i] = new InvalidMember(arrChild.getString(0), (InvalidMemberType)arrChild.getInt(1));
228
+ }
229
+ operationResponse.setInvalidMembers(invalidMembers);
230
+ }
231
+
232
+ if (!operationResponse.hasError())
233
+ {
234
+ this.addPing(operationPending.getExecuteTimerInMs());
235
+
236
+ if (parameters != null)
237
+ {
238
+ if (parameters.containsKey(ParameterCode.AuthToken))
239
+ {
240
+ var authToken = parameters.getString(ParameterCode.AuthToken);
241
+ GNNetwork.getAuthenticateStatus().setAuthToken(authToken);
242
+ UnityEngine.PlayerPrefs.SetString(GNNetwork.AUTH_TOKEN_KEY, authToken);
243
+ }
244
+
245
+ if (parameters.containsKey(ParameterCode.UserId))
246
+ {
247
+ var userId = parameters.getString(ParameterCode.UserId);
248
+ GNNetwork.getAuthenticateStatus().setUserId(userId);
249
+ UnityEngine.PlayerPrefs.SetString(GNNetwork.USER_ID_KEY, userId);
250
+ }
251
+
252
+ if (parameters.containsKey(ParameterCode.Ts))
253
+ {
254
+ GNNetwork.peer.setServerTimeMilliseconds(parameters.getLong(ParameterCode.Ts, DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()));
255
+ }
256
+ }
257
+ }
258
+
259
+ GNDebug.log("[GN RECV] " + operationResponse.ToString());
260
+
261
+ operationPending.getCallback()?.Invoke(operationResponse);
262
+ }
263
+ else
264
+ {
265
+ GNDebug.logError("[GN] OnResponseHandler, unavailable request id " + obj);
266
+ }
267
+ }
268
+
269
+ /// <summary>
270
+ /// Sends the given operation request.
271
+ /// </summary>
272
+ /// <param name="operationPending">The operation request to be sent.</param>
273
+ internal virtual void send(OperationPending operationPending)
274
+ {
275
+ operationPending.onSend();
276
+
277
+ var operationRequest = operationPending.getOperationRequest();
278
+
279
+ if (operationRequest.getRequestId() != -1)
280
+ {
281
+ operationRequest.setRequestId(PeerBase.requestId++);
282
+
283
+ if (operationPending.getCallback() != null)
284
+ {
285
+ this.operationWaitingResponseDict[operationRequest.getRequestId()] = operationPending;
286
+ }
287
+ }
288
+ }
289
+
290
+ /// <summary>
291
+ /// Adds a ping measurement for the current operation.
292
+ /// </summary>
293
+ /// <param name="value">The ping value in milliseconds.</param>
294
+ private void addPing(float value)
295
+ {
296
+ if (this.pingLst.Count > 10)
297
+ this.pingLst.Dequeue();
298
+
299
+ this.pingLst.Enqueue(value / 2);
300
+ this.ping = (int)(this.pingLst.Average() * 1000);
301
+ }
302
+
303
+ }
304
+
305
+ }
@@ -1,11 +1,11 @@
1
- fileFormatVersion: 2
2
- guid: 42b0b6a0bb4033e48b899110d30e4e35
3
- MonoImporter:
4
- externalObjects: {}
5
- serializedVersion: 2
6
- defaultReferences: []
7
- executionOrder: 0
8
- icon: {instanceID: 0}
9
- userData:
10
- assetBundleName:
11
- assetBundleVariant:
1
+ fileFormatVersion: 2
2
+ guid: 42b0b6a0bb4033e48b899110d30e4e35
3
+ MonoImporter:
4
+ externalObjects: {}
5
+ serializedVersion: 2
6
+ defaultReferences: []
7
+ executionOrder: 0
8
+ icon: {instanceID: 0}
9
+ userData:
10
+ assetBundleName:
11
+ assetBundleVariant: