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.
Files changed (112) hide show
  1. package/Editor/GNServerSettingsEditor.cs +42 -322
  2. package/Runtime/Common/GNArray.cs +120 -35
  3. package/Runtime/Common/GNData.cs +19 -6
  4. package/Runtime/Common/GNHashtable.cs +174 -11
  5. package/Runtime/Common/IGNData.cs +11 -2
  6. package/Runtime/Config/GNServerSettings.cs +136 -92
  7. package/Runtime/Constant/Commands.cs +82 -19
  8. package/Runtime/Constant/EnumType/GoogleLoginType.cs +5 -5
  9. package/Runtime/Constant/EnumType/GroupStatus.cs +7 -7
  10. package/Runtime/Constant/EnumType/ItemType.cs +5 -5
  11. package/Runtime/Constant/EnumType/MatchmakingMemberStatus.cs +6 -6
  12. package/Runtime/Constant/EnumType/MatchmakingTicketStatus.cs +2 -2
  13. package/Runtime/Constant/EnumType/OwnerType.cs +3 -2
  14. package/Runtime/Constant/EnumType/PushPlatformType.cs +10 -0
  15. package/Runtime/Constant/EnumType/PushPlatformType.cs.meta +11 -0
  16. package/Runtime/Constant/EnumType/RequestType.cs +1 -0
  17. package/Runtime/Constant/EnumType/StoreReceiveType.cs +13 -0
  18. package/Runtime/Constant/EnumType/StoreReceiveType.cs.meta +11 -0
  19. package/Runtime/Constant/ErrorCode/GNErrorCode.cs +53 -48
  20. package/Runtime/Constant/EventCode.cs +29 -2
  21. package/Runtime/Constant/OperationCode.cs +249 -211
  22. package/Runtime/Constant/ParameterCode/GNParameterCode.cs +610 -466
  23. package/Runtime/Constant/ReturnCode.cs +50 -2
  24. package/Runtime/Entity/DataMember.cs +221 -3
  25. package/Runtime/Entity/GNMetadata.cs +46 -1
  26. package/Runtime/Entity/InvalidMember.cs +24 -5
  27. package/Runtime/Entity/Models/AuthenticateModels.cs +251 -207
  28. package/Runtime/Entity/Models/AuthenticateRequestModels.cs +153 -131
  29. package/Runtime/Entity/Models/AuthenticateResponseModels.cs +61 -51
  30. package/Runtime/Entity/Models/CharacterPlayerModels.cs +985 -849
  31. package/Runtime/Entity/Models/CharacterPlayerRequestModels.cs +957 -885
  32. package/Runtime/Entity/Models/CharacterPlayerResponseModels.cs +165 -150
  33. package/Runtime/Entity/Models/CloudScriptModels.cs +185 -0
  34. package/Runtime/Entity/Models/CloudScriptModels.cs.meta +11 -0
  35. package/Runtime/Entity/Models/CloudScriptRequestModels.cs +134 -0
  36. package/Runtime/Entity/Models/CloudScriptRequestModels.cs.meta +11 -0
  37. package/Runtime/Entity/Models/CloudScriptResponseModels.cs +34 -0
  38. package/Runtime/Entity/Models/CloudScriptResponseModels.cs.meta +11 -0
  39. package/Runtime/Entity/Models/ContentModels.cs +150 -153
  40. package/Runtime/Entity/Models/ContentRequestModels.cs +129 -129
  41. package/Runtime/Entity/Models/ContentResponseModels.cs +24 -24
  42. package/Runtime/Entity/Models/DashboardModels.cs +1684 -1156
  43. package/Runtime/Entity/Models/DashboardRequestModels.cs +220 -147
  44. package/Runtime/Entity/Models/DashboardResponseModels.cs +92 -57
  45. package/Runtime/Entity/Models/GamePlayerModels.cs +1073 -933
  46. package/Runtime/Entity/Models/GamePlayerRequestModels.cs +939 -867
  47. package/Runtime/Entity/Models/GamePlayerResponseModels.cs +162 -147
  48. package/Runtime/Entity/Models/GenericModels.cs +102 -102
  49. package/Runtime/Entity/Models/GroupModels.cs +812 -676
  50. package/Runtime/Entity/Models/GroupRequestModels.cs +741 -669
  51. package/Runtime/Entity/Models/GroupResponseModels.cs +129 -114
  52. package/Runtime/Entity/Models/InventoryModels.cs +667 -558
  53. package/Runtime/Entity/Models/InventoryRequestModels.cs +626 -579
  54. package/Runtime/Entity/Models/InventoryResponseModels.cs +109 -99
  55. package/Runtime/Entity/Models/MasterPlayerModels.cs +1882 -1340
  56. package/Runtime/Entity/Models/MasterPlayerRequestModels.cs +1643 -1253
  57. package/Runtime/Entity/Models/MasterPlayerResponseModels.cs +293 -213
  58. package/Runtime/Entity/Models/MultiplayerModels.cs +293 -223
  59. package/Runtime/Entity/Models/MultiplayerRequestModels.cs +199 -149
  60. package/Runtime/Entity/Models/MultiplayerResponseModels.cs +10 -0
  61. package/Runtime/Entity/Models/StoreInventoryModels.cs +514 -323
  62. package/Runtime/Entity/Models/StoreInventoryRequestModels.cs +236 -165
  63. package/Runtime/Entity/Models/StoreInventoryResponseModels.cs +45 -30
  64. package/Runtime/Entity/OperationEvent.cs +43 -7
  65. package/Runtime/Entity/OperationHelper.cs +18 -2
  66. package/Runtime/Entity/OperationRequest.cs +80 -37
  67. package/Runtime/Entity/OperationResponse.cs +111 -63
  68. package/Runtime/Entity/Request/CustomOperationRequest.cs +53 -2
  69. package/Runtime/Entity/Response/CustomOperationResponse.cs +25 -4
  70. package/Runtime/GNNetwork.cs +333 -21
  71. package/Runtime/GNNetworkApi.cs +25 -13
  72. package/Runtime/GNNetworkAuthenticateApi.cs +531 -98
  73. package/Runtime/GNNetworkCharacterPlayerApi.cs +1587 -762
  74. package/Runtime/GNNetworkCloudScriptApi.cs +181 -0
  75. package/Runtime/GNNetworkCloudScriptApi.cs.meta +11 -0
  76. package/Runtime/GNNetworkContentApi.cs +238 -132
  77. package/Runtime/GNNetworkDashboardApi.cs +278 -117
  78. package/Runtime/GNNetworkGamePlayerApi.cs +1558 -747
  79. package/Runtime/GNNetworkGroupApi.cs +1228 -582
  80. package/Runtime/GNNetworkInventoryApi.cs +1048 -507
  81. package/Runtime/GNNetworkMasterPlayerApi.cs +2586 -1067
  82. package/Runtime/GNNetworkMultiplayerApi.cs +328 -147
  83. package/Runtime/GNNetworkStoreInventoryApi.cs +388 -162
  84. package/Runtime/Helper/CodeHelper.cs +45 -3
  85. package/Runtime/Helper/ConverterService.cs +240 -85
  86. package/Runtime/Logger/GNDebug.cs +46 -3
  87. package/Runtime/Networking/AuthenticateStatus.cs +30 -8
  88. package/Runtime/Networking/Handler/IServerEventHandler.cs +8 -8
  89. package/Runtime/Networking/Handler/OnCharacterPlayerFriendUpdateEventHandler.cs +31 -2
  90. package/Runtime/Networking/Handler/OnCharacterPlayerGroupUpdateEventHandler.cs +24 -3
  91. package/Runtime/Networking/Handler/OnGamePlayerFriendUpdateEventHandler.cs +24 -2
  92. package/Runtime/Networking/Handler/OnGamePlayerGroupUpdateEventHandler.cs +24 -2
  93. package/Runtime/Networking/Handler/OnGroupMemberUpdateEventHandler.cs +21 -2
  94. package/Runtime/Networking/Handler/OnGroupMessageUpdateEventHandler.cs +20 -2
  95. package/Runtime/Networking/Http/HttpPeer.cs +68 -25
  96. package/Runtime/Networking/Http/NetworkingHttpPeerBase.cs +44 -4
  97. package/Runtime/Networking/Http/NetworkingPeerHttpClientRequest.cs +63 -40
  98. package/Runtime/Networking/Http/NetworkingPeerHttpRequest.cs +43 -13
  99. package/Runtime/Networking/Http/NetworkingPeerUnityWebRequest.cs +72 -39
  100. package/Runtime/Networking/IPeer.cs +24 -2
  101. package/Runtime/Networking/NetworkingPeer.cs +64 -10
  102. package/Runtime/Networking/NetworkingPeerAPI.cs +20 -21
  103. package/Runtime/Networking/OperationPending.cs +79 -15
  104. package/Runtime/Networking/PeerBase.cs +86 -23
  105. package/Runtime/Networking/Socket/NetworkingPeerSocketV2.cs +57 -18
  106. package/Runtime/Networking/Socket/NetworkingPeerSocketV3.cs +70 -10
  107. package/Runtime/Networking/Socket/NetworkingSocketPeerBase.cs +165 -23
  108. package/Runtime/Networking/Socket/SocketPeer.cs +63 -12
  109. package/Runtime/Unity/ServiceCoroutine.cs +10 -0
  110. package/Runtime/Unity/ServiceCoroutine.cs.meta +11 -0
  111. package/Runtime/Unity/ServiceUpdate.cs +14 -1
  112. package/package.json +1 -1
@@ -5,21 +5,35 @@ namespace XmobiTea.GN.Networking
5
5
  using XmobiTea.GN.Constant;
6
6
  using XmobiTea.GN.Entity;
7
7
 
8
+ /// <summary>
9
+ /// Represents a pending operation request, including metadata and timing information.
10
+ /// </summary>
8
11
  public struct OperationPending
9
12
  {
10
- private OperationRequest operationRequest;
11
- private RequestType requestType;
12
- private RequestRole requestRole;
13
- private string authToken;
14
- private string secretKey;
15
- private GNHashtable customTags;
16
- private Action<OperationResponse> onOperationResponse;
17
- private float timeout;
18
-
19
- private float firstSend;
20
- private float secondsSend;
21
-
22
- public OperationPending(RequestType requestType, RequestRole requestRole, OperationRequest operationRequest, Action<OperationResponse> onOperationResponse, string authToken, string secretKey, GNHashtable customTags)
13
+ private OperationRequest operationRequest; // The operation request to be processed.
14
+ private RequestType requestType; // The type of the request.
15
+ private RequestRole requestRole; // The role associated with the request.
16
+ private string authToken; // The authentication token for the request.
17
+ private string secretKey; // The secret key for the request, if applicable.
18
+ private string gameId; // The game id for the request
19
+ private GNHashtable customTags; // Custom tags to be sent with the request.
20
+ private Action<OperationResponse> onOperationResponse; // The callback for handling the operation response.
21
+ private float timeout; // The timeout for the operation.
22
+
23
+ private float firstSend; // The timestamp of the first send attempt.
24
+ private float secondsSend; // The timestamp of the response receipt.
25
+
26
+ /// <summary>
27
+ /// Initializes a new instance of the <see cref="OperationPending"/> struct.
28
+ /// </summary>
29
+ /// <param name="requestType">The type of the request.</param>
30
+ /// <param name="requestRole">The role associated with the request.</param>
31
+ /// <param name="operationRequest">The operation request data.</param>
32
+ /// <param name="onOperationResponse">The callback for the response.</param>
33
+ /// <param name="authToken">The authentication token.</param>
34
+ /// <param name="secretKey">The secret key, if applicable.</param>
35
+ /// <param name="customTags">Custom tags for the request.</param>
36
+ public OperationPending(RequestType requestType, RequestRole requestRole, OperationRequest operationRequest, Action<OperationResponse> onOperationResponse, string authToken, string secretKey, GNHashtable customTags, string gameId)
23
37
  {
24
38
  this.operationRequest = operationRequest;
25
39
  this.onOperationResponse = onOperationResponse;
@@ -31,65 +45,115 @@ namespace XmobiTea.GN.Networking
31
45
  this.requestRole = requestRole;
32
46
  this.authToken = authToken;
33
47
  this.secretKey = secretKey;
48
+ this.gameId = gameId;
34
49
  this.customTags = customTags;
35
50
  }
36
51
 
52
+ /// <summary>
53
+ /// Gets the request type.
54
+ /// </summary>
55
+ /// <returns>The request type.</returns>
37
56
  public RequestType getRequestType()
38
57
  {
39
58
  return this.requestType;
40
59
  }
41
60
 
61
+ /// <summary>
62
+ /// Gets the request role.
63
+ /// </summary>
64
+ /// <returns>The request role.</returns>
42
65
  public RequestRole getRequestRole()
43
66
  {
44
67
  return this.requestRole;
45
68
  }
46
69
 
70
+ /// <summary>
71
+ /// Gets the authentication token for the request.
72
+ /// </summary>
73
+ /// <returns>The authentication token.</returns>
47
74
  public string getAuthToken()
48
75
  {
49
76
  return this.authToken;
50
77
  }
51
78
 
79
+ /// <summary>
80
+ /// Gets the secret key for the request.
81
+ /// </summary>
82
+ /// <returns>The secret key.</returns>
52
83
  public string getSecretKey()
53
84
  {
54
85
  return this.secretKey;
55
86
  }
56
87
 
88
+ /// <summary>
89
+ /// Gets the game id with the request.
90
+ /// </summary>
91
+ /// <returns>the game id.</returns>
92
+ public string getGameId()
93
+ {
94
+ return this.gameId;
95
+ }
96
+
97
+ /// <summary>
98
+ /// Gets the custom tags associated with the request.
99
+ /// </summary>
100
+ /// <returns>A GNHashtable containing the custom tags.</returns>
57
101
  public GNHashtable getCustomTags()
58
102
  {
59
103
  return this.customTags;
60
104
  }
61
105
 
106
+ /// <summary>
107
+ /// Marks the request as sent and updates the timeout.
108
+ /// </summary>
62
109
  public void onSend()
63
110
  {
64
111
  this.firstSend = UnityEngine.Time.realtimeSinceStartup;
65
112
  this.timeout = this.firstSend + this.operationRequest.getTimeout();
66
113
  }
67
114
 
115
+ /// <summary>
116
+ /// Marks the request as having received a response.
117
+ /// </summary>
68
118
  public void onRecv()
69
119
  {
70
120
  this.secondsSend = UnityEngine.Time.realtimeSinceStartup;
71
121
  }
72
122
 
123
+ /// <summary>
124
+ /// Gets the execution time of the request in milliseconds.
125
+ /// </summary>
126
+ /// <returns>The execution time in milliseconds.</returns>
73
127
  public float getExecuteTimerInMs()
74
128
  {
75
129
  return (this.secondsSend - this.firstSend) * 1000;
76
130
  }
77
131
 
132
+ /// <summary>
133
+ /// Determines whether the operation has timed out.
134
+ /// </summary>
135
+ /// <returns>True if the operation has timed out; otherwise, false.</returns>
78
136
  public bool isTimeout()
79
137
  {
80
138
  return this.timeout < UnityEngine.Time.realtimeSinceStartup;
81
139
  }
82
140
 
141
+ /// <summary>
142
+ /// Gets the operation request associated with this pending operation.
143
+ /// </summary>
144
+ /// <returns>The operation request.</returns>
83
145
  public OperationRequest getOperationRequest()
84
146
  {
85
147
  return this.operationRequest;
86
148
  }
87
149
 
150
+ /// <summary>
151
+ /// Gets the callback for handling the operation response.
152
+ /// </summary>
153
+ /// <returns>The response callback action.</returns>
88
154
  public Action<OperationResponse> getCallback()
89
155
  {
90
156
  return this.onOperationResponse;
91
157
  }
92
-
93
158
  }
94
-
95
159
  }
@@ -3,82 +3,132 @@
3
3
  using System;
4
4
  using System.Collections.Generic;
5
5
  using System.Linq;
6
- using UnityEngine;
7
6
  using XmobiTea.GN.Common;
8
7
  using XmobiTea.GN.Constant;
9
8
  using XmobiTea.GN.Entity;
10
9
  using XmobiTea.GN.Logger;
11
10
 
11
+ /// <summary>
12
+ /// Abstract base class for managing common functionalities of network peers.
13
+ /// Implements the <see cref="IPeer"/> interface.
14
+ /// </summary>
12
15
  internal abstract class PeerBase : IPeer
13
16
  {
14
- private Queue<OperationPending> operationPendingQueue;
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.
15
19
 
16
- private Dictionary<int, OperationPending> operationWaitingResponseDict;
20
+ private static int requestId; // Static counter for generating unique request IDs.
17
21
 
18
- private static int requestId;
19
-
20
- private float perMsgTimer;
21
- private float nextSendMsgTimer;
22
- private float checkTimeoutOperationPending = 0;
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.
23
25
 
26
+ /// <summary>
27
+ /// Gets the message send rate (messages per second).
28
+ /// </summary>
29
+ /// <returns>The send rate in messages per second.</returns>
24
30
  protected int getSendRate()
25
31
  {
26
32
  return (int)(1000 / this.perMsgTimer);
27
33
  }
28
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>
29
39
  protected void setSendRate(int sendRate)
30
40
  {
31
41
  this.perMsgTimer = (float)1000 / sendRate / 1000;
32
42
  }
33
43
 
44
+ /// <summary>
45
+ /// Gets or sets the ping value for the connection.
46
+ /// </summary>
34
47
  internal int ping { get; set; } = -1;
35
- private Queue<float> pingLst;
36
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>
37
54
  protected bool isUse { get; set; }
38
55
 
56
+ /// <summary>
57
+ /// Initializes the peer by setting up queues, dictionaries, and network objects.
58
+ /// </summary>
39
59
  void IPeer.initPeer()
40
60
  {
41
- if (this.operationWaitingResponseDict == null) this.operationWaitingResponseDict = new Dictionary<int, OperationPending>();
61
+ if (this.operationWaitingResponseDict == null)
62
+ this.operationWaitingResponseDict = new Dictionary<int, OperationPending>();
42
63
 
43
- if (this.operationPendingQueue == null) this.operationPendingQueue = new Queue<OperationPending>();
64
+ if (this.operationPendingQueue == null)
65
+ this.operationPendingQueue = new Queue<OperationPending>();
44
66
 
45
- if (this.pingLst == null) this.pingLst = new Queue<float>();
67
+ if (this.pingLst == null)
68
+ this.pingLst = new Queue<float>();
46
69
 
47
70
  this.initSendRate();
48
71
  this.initGNSocketObject();
49
72
  }
50
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>
51
78
  private void initSendRate()
52
79
  {
53
80
  var gnServerSettings = GNNetwork.gnServerSettings;
54
- if (gnServerSettings == null) throw new NullReferenceException("Null GN Server Settings, please find it now");
81
+ if (gnServerSettings == null)
82
+ throw new NullReferenceException("Null GN Server Settings, please find it now");
55
83
 
56
84
  this.setSendRate(gnServerSettings.getSendRate());
57
85
  }
58
86
 
87
+ /// <summary>
88
+ /// Initializes the GN socket object for derived classes.
89
+ /// This method must be implemented in subclasses.
90
+ /// </summary>
59
91
  internal abstract void initGNSocketObject();
60
92
 
61
- void IPeer.enqueue(RequestType requestType, RequestRole requestRole, OperationRequest operationRequest, Action<OperationResponse> onOperationResponse, string authToken, string secretKey, GNHashtable customTags)
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)
62
104
  {
63
105
  if (!this.isUse)
64
106
  {
65
- GNDebug.logError("[GN] Server Settings dont setup to use this to send operation request.");
107
+ GNDebug.logError("[GN] Server Settings don't setup to use this to send operation request.");
66
108
  return;
67
109
  }
68
110
 
69
- var operationPending = new OperationPending(requestType, requestRole, operationRequest, onOperationResponse, authToken, secretKey, customTags);
111
+ var operationPending = new OperationPending(requestType, requestRole, operationRequest, onOperationResponse, authToken, secretKey, customTags, gameId);
70
112
  this.operationPendingQueue.Enqueue(operationPending);
71
113
  }
72
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>
73
119
  bool IPeer.isUsing()
74
120
  {
75
121
  return this.isUse;
76
122
  }
77
123
 
124
+ /// <summary>
125
+ /// Processes pending operations and handles responses and timeouts.
126
+ /// </summary>
78
127
  public virtual void service()
79
128
  {
80
129
  if (!this.isUse) return;
81
130
 
131
+ // Check for timed-out operations.
82
132
  if (this.checkTimeoutOperationPending < UnityEngine.Time.time)
83
133
  {
84
134
  this.checkTimeoutOperationPending = UnityEngine.Time.time + 0.1f;
@@ -114,6 +164,7 @@
114
164
  }
115
165
  }
116
166
 
167
+ // Send the next pending message.
117
168
  if (this.nextSendMsgTimer < UnityEngine.Time.time)
118
169
  {
119
170
  if (this.operationPendingQueue.Count != 0)
@@ -127,6 +178,11 @@
127
178
  }
128
179
  }
129
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>
130
186
  internal void onResponseHandler(GNArray obj, bool isEncrypted)
131
187
  {
132
188
  var responseId = obj.getInt(2);
@@ -182,19 +238,15 @@
182
238
  if (parameters.containsKey(ParameterCode.AuthToken))
183
239
  {
184
240
  var authToken = parameters.getString(ParameterCode.AuthToken);
185
-
186
241
  GNNetwork.getAuthenticateStatus().setAuthToken(authToken);
187
-
188
- PlayerPrefs.SetString(GNNetwork.AUTH_TOKEN_KEY, authToken);
242
+ UnityEngine.PlayerPrefs.SetString(GNNetwork.AUTH_TOKEN_KEY, authToken);
189
243
  }
190
244
 
191
245
  if (parameters.containsKey(ParameterCode.UserId))
192
246
  {
193
247
  var userId = parameters.getString(ParameterCode.UserId);
194
-
195
248
  GNNetwork.getAuthenticateStatus().setUserId(userId);
196
-
197
- PlayerPrefs.SetString(GNNetwork.USER_ID_KEY, userId);
249
+ UnityEngine.PlayerPrefs.SetString(GNNetwork.USER_ID_KEY, userId);
198
250
  }
199
251
 
200
252
  if (parameters.containsKey(ParameterCode.Ts))
@@ -214,6 +266,10 @@
214
266
  }
215
267
  }
216
268
 
269
+ /// <summary>
270
+ /// Sends the given operation request.
271
+ /// </summary>
272
+ /// <param name="operationPending">The operation request to be sent.</param>
217
273
  internal virtual void send(OperationPending operationPending)
218
274
  {
219
275
  operationPending.onSend();
@@ -231,12 +287,19 @@
231
287
  }
232
288
  }
233
289
 
290
+ /// <summary>
291
+ /// Adds a ping measurement for the current operation.
292
+ /// </summary>
293
+ /// <param name="value">The ping value in milliseconds.</param>
234
294
  private void addPing(float value)
235
295
  {
236
- if (this.pingLst.Count > 10) this.pingLst.Dequeue();
296
+ if (this.pingLst.Count > 10)
297
+ this.pingLst.Dequeue();
298
+
237
299
  this.pingLst.Enqueue(value / 2);
238
300
  this.ping = (int)(this.pingLst.Average() * 1000);
239
301
  }
302
+
240
303
  }
241
304
 
242
305
  }
@@ -1,28 +1,42 @@
1
1
  namespace XmobiTea.GN.Networking.Socket
2
2
  {
3
- using System;
3
+ #if UNITY_USING_BEST_HTTP
4
4
 
5
5
  using BestHTTP.SocketIO;
6
- using XmobiTea.GN.Entity;
6
+ using System;
7
+ using XmobiTea.GN.Common;
7
8
  using XmobiTea.GN.Constant;
8
- using XmobiTea.MsgPack;
9
+ using XmobiTea.GN.Entity;
9
10
  using XmobiTea.GN.Logger;
10
- using XmobiTea.GN.Common;
11
+ using XmobiTea.MsgPack;
11
12
 
13
+ /// <summary>
14
+ /// Handles socket networking using BestHTTP Socket.IO v2.
15
+ /// </summary>
12
16
  internal class NetworkingPeerSocketV2 : NetworkingSocketPeerBase
13
17
  {
14
18
  private SocketManager socketManager;
15
19
  private bool isConnected;
16
20
 
21
+ /// <summary>
22
+ /// Gets whether the WebSocket connection is open.
23
+ /// </summary>
17
24
  internal override bool isWsConnected => this.socketManager != null ? this.socketManager.State == SocketManager.States.Open : false;
18
25
 
19
26
  private SupportedSocketIOVersions serverVersion = SupportedSocketIOVersions.v3;
20
27
 
28
+ /// <summary>
29
+ /// Sets the Socket.IO server version.
30
+ /// </summary>
31
+ /// <param name="serverVersion">The server version to use.</param>
21
32
  public void setServerVersion(SupportedSocketIOVersions serverVersion)
22
33
  {
23
34
  this.serverVersion = serverVersion;
24
35
  }
25
36
 
37
+ /// <summary>
38
+ /// Sends an authentication request via the socket.
39
+ /// </summary>
26
40
  internal override void sendRequestAuthSocket()
27
41
  {
28
42
  base.sendRequestAuthSocket();
@@ -31,6 +45,9 @@
31
45
  this.socketManager.Socket.Emit(Commands.RequestAuthTokenCmd, GNNetwork.getAuthenticateStatus().getAuthToken());
32
46
  }
33
47
 
48
+ /// <summary>
49
+ /// Reinitializes the socket with a new configuration.
50
+ /// </summary>
34
51
  internal override void reInitNewSocket()
35
52
  {
36
53
  base.reInitNewSocket();
@@ -40,7 +57,7 @@
40
57
  var uri = new Uri(this.url + "/socket.io/");
41
58
  this.socketManager = new SocketManager(uri, new SocketOptions()
42
59
  {
43
- ServerVersion = serverVersion,
60
+ ServerVersion = this.serverVersion,
44
61
  Reconnection = true,
45
62
  ReconnectionDelay = TimeSpan.FromMilliseconds(this.reconnectDelay),
46
63
  Timeout = TimeSpan.FromMilliseconds(this.pingTimeout),
@@ -48,15 +65,15 @@
48
65
  ConnectWith = BestHTTP.SocketIO.Transports.TransportTypes.WebSocket
49
66
  });
50
67
 
51
- this.socketManager.Socket.On(SocketIOEventTypes.Connect, onConnect);
52
- this.socketManager.Socket.On(SocketIOEventTypes.Disconnect, onDisconnect);
53
- this.socketManager.Socket.On(SocketIOEventTypes.Error, onError);
68
+ this.socketManager.Socket.On(SocketIOEventTypes.Connect, this.onConnect);
69
+ this.socketManager.Socket.On(SocketIOEventTypes.Disconnect, this.onDisconnect);
70
+ this.socketManager.Socket.On(SocketIOEventTypes.Error, this.onError);
54
71
 
55
- this.socketManager.Socket.On(Commands.ResponseCmd_MsgPack, onResponseMsgPack);
56
- this.socketManager.Socket.On(Commands.EventCmd_MsgPack, onEventMsgPack);
72
+ this.socketManager.Socket.On(Commands.ResponseCmd_MsgPack, this.onResponseMsgPack);
73
+ this.socketManager.Socket.On(Commands.EventCmd_MsgPack, this.onEventMsgPack);
57
74
 
58
- this.socketManager.Socket.On(Commands.ResponseCmd_Json, onResponseJson);
59
- this.socketManager.Socket.On(Commands.EventCmd_Json, onEventJson);
75
+ this.socketManager.Socket.On(Commands.ResponseCmd_Json, this.onResponseJson);
76
+ this.socketManager.Socket.On(Commands.EventCmd_Json, this.onEventJson);
60
77
  }
61
78
  }
62
79
 
@@ -115,18 +132,33 @@
115
132
  GNDebug.logError(string.Format("Error: {0}", args[0].ToString()));
116
133
  }
117
134
 
135
+ /// <summary>
136
+ /// Initializes the socket with the given configuration.
137
+ /// </summary>
138
+ /// <param name="url">The server URL.</param>
139
+ /// <param name="reconnectDelay">Delay in milliseconds before attempting to reconnect.</param>
140
+ /// <param name="pingInterval">Ping interval in seconds.</param>
141
+ /// <param name="pingTimeout">Ping timeout in seconds.</param>
118
142
  internal override void init(string url, int reconnectDelay, float pingInterval, float pingTimeout)
119
143
  {
120
144
  base.init(url, reconnectDelay, pingInterval, pingTimeout);
121
145
  }
122
146
 
123
- protected override void emit(RequestType requestType, RequestRole requestRole, OperationRequest operationRequest, string authToken, string secretKey, GNHashtable customTags)
147
+ /// <summary>
148
+ /// Emits a request via the socket.
149
+ /// </summary>
150
+ /// <param name="requestType">The type of request to emit.</param>
151
+ /// <param name="requestRole">The role associated with the request.</param>
152
+ /// <param name="operationRequest">The operation request data.</param>
153
+ /// <param name="authToken">Authentication token, if available.</param>
154
+ /// <param name="secretKey">Secret key, if available.</param>
155
+ /// <param name="customTags">Custom tags for the request.</param>
156
+ protected override void emit(RequestType requestType, RequestRole requestRole, OperationRequest operationRequest, string authToken, string secretKey, GNHashtable customTags, string gameId)
124
157
  {
125
- base.emit(requestType, requestRole, operationRequest, authToken, secretKey, customTags);
158
+ base.emit(requestType, requestRole, operationRequest, authToken, secretKey, customTags, gameId);
126
159
 
127
160
  if (this.socketManager == null || this.socketManager.Socket == null)
128
161
  {
129
- // callback here
130
162
  return;
131
163
  }
132
164
 
@@ -140,6 +172,10 @@
140
172
  this.socketManager.Socket.Emit(Commands.RequestCmd_Json, dataSend);
141
173
  }
142
174
 
175
+ /// <summary>
176
+ /// Closes the socket connection.
177
+ /// </summary>
178
+ /// <param name="_onSocketDisconnect">Callback for when the socket is disconnected.</param>
143
179
  internal override void close(Action _onSocketDisconnect)
144
180
  {
145
181
  base.close(_onSocketDisconnect);
@@ -157,9 +193,13 @@
157
193
 
158
194
  GNDebug.log("[GN Socket] Disconnecting via SocketIOv2 BestHTTP 2");
159
195
 
160
- onDisconnectHandler();
196
+ this.onDisconnectHandler();
161
197
  }
162
198
 
199
+ /// <summary>
200
+ /// Opens a socket connection.
201
+ /// </summary>
202
+ /// <param name="_onSocketConnect">Callback for when the socket is connected.</param>
163
203
  internal override void connect(Action _onSocketConnect)
164
204
  {
165
205
  base.connect(_onSocketConnect);
@@ -167,7 +207,6 @@
167
207
  if (this.isConnected)
168
208
  {
169
209
  GNDebug.log("[GN Socket] Reconnecting");
170
-
171
210
  return;
172
211
  }
173
212
 
@@ -177,7 +216,7 @@
177
216
 
178
217
  if (this.socketManager != null) this.socketManager.Open();
179
218
  }
180
-
181
219
  }
182
220
 
221
+ #endif
183
222
  }