com.xmobitea.changx.gn-unity 2.0.2 → 2.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Editor/GNServerSettingsEditor.cs +42 -322
- package/Runtime/Common/GNArray.cs +120 -35
- package/Runtime/Common/GNData.cs +19 -6
- package/Runtime/Common/GNHashtable.cs +174 -11
- package/Runtime/Common/IGNData.cs +11 -2
- package/Runtime/Config/GNServerSettings.cs +136 -92
- package/Runtime/Constant/Commands.cs +82 -19
- package/Runtime/Constant/EnumType/GoogleLoginType.cs +5 -5
- package/Runtime/Constant/EnumType/GroupStatus.cs +7 -7
- package/Runtime/Constant/EnumType/ItemType.cs +5 -5
- package/Runtime/Constant/EnumType/MatchmakingMemberStatus.cs +6 -6
- package/Runtime/Constant/EnumType/MatchmakingTicketStatus.cs +2 -2
- package/Runtime/Constant/EnumType/OwnerType.cs +3 -2
- package/Runtime/Constant/EnumType/PushPlatformType.cs +10 -0
- package/Runtime/Constant/EnumType/PushPlatformType.cs.meta +11 -0
- package/Runtime/Constant/EnumType/RequestType.cs +1 -0
- package/Runtime/Constant/EnumType/StoreReceiveType.cs +13 -0
- package/Runtime/Constant/EnumType/StoreReceiveType.cs.meta +11 -0
- package/Runtime/Constant/ErrorCode/GNErrorCode.cs +53 -48
- package/Runtime/Constant/EventCode.cs +29 -2
- package/Runtime/Constant/OperationCode.cs +249 -211
- package/Runtime/Constant/ParameterCode/GNParameterCode.cs +610 -466
- package/Runtime/Constant/ReturnCode.cs +50 -2
- package/Runtime/Entity/DataMember.cs +221 -3
- package/Runtime/Entity/GNMetadata.cs +46 -1
- package/Runtime/Entity/InvalidMember.cs +24 -5
- package/Runtime/Entity/Models/AuthenticateModels.cs +251 -207
- package/Runtime/Entity/Models/AuthenticateRequestModels.cs +153 -131
- package/Runtime/Entity/Models/AuthenticateResponseModels.cs +61 -51
- package/Runtime/Entity/Models/CharacterPlayerModels.cs +985 -849
- package/Runtime/Entity/Models/CharacterPlayerRequestModels.cs +957 -885
- package/Runtime/Entity/Models/CharacterPlayerResponseModels.cs +165 -150
- package/Runtime/Entity/Models/CloudScriptModels.cs +185 -0
- package/Runtime/Entity/Models/CloudScriptModels.cs.meta +11 -0
- package/Runtime/Entity/Models/CloudScriptRequestModels.cs +134 -0
- package/Runtime/Entity/Models/CloudScriptRequestModels.cs.meta +11 -0
- package/Runtime/Entity/Models/CloudScriptResponseModels.cs +34 -0
- package/Runtime/Entity/Models/CloudScriptResponseModels.cs.meta +11 -0
- package/Runtime/Entity/Models/ContentModels.cs +150 -153
- package/Runtime/Entity/Models/ContentRequestModels.cs +129 -129
- package/Runtime/Entity/Models/ContentResponseModels.cs +24 -24
- package/Runtime/Entity/Models/DashboardModels.cs +1684 -1156
- package/Runtime/Entity/Models/DashboardRequestModels.cs +220 -147
- package/Runtime/Entity/Models/DashboardResponseModels.cs +92 -57
- package/Runtime/Entity/Models/GamePlayerModels.cs +1073 -933
- package/Runtime/Entity/Models/GamePlayerRequestModels.cs +939 -867
- package/Runtime/Entity/Models/GamePlayerResponseModels.cs +162 -147
- package/Runtime/Entity/Models/GenericModels.cs +102 -102
- package/Runtime/Entity/Models/GroupModels.cs +812 -676
- package/Runtime/Entity/Models/GroupRequestModels.cs +741 -669
- package/Runtime/Entity/Models/GroupResponseModels.cs +129 -114
- package/Runtime/Entity/Models/InventoryModels.cs +667 -558
- package/Runtime/Entity/Models/InventoryRequestModels.cs +626 -579
- package/Runtime/Entity/Models/InventoryResponseModels.cs +109 -99
- package/Runtime/Entity/Models/MasterPlayerModels.cs +1882 -1340
- package/Runtime/Entity/Models/MasterPlayerRequestModels.cs +1643 -1253
- package/Runtime/Entity/Models/MasterPlayerResponseModels.cs +293 -213
- package/Runtime/Entity/Models/MultiplayerModels.cs +293 -223
- package/Runtime/Entity/Models/MultiplayerRequestModels.cs +199 -149
- package/Runtime/Entity/Models/MultiplayerResponseModels.cs +10 -0
- package/Runtime/Entity/Models/StoreInventoryModels.cs +514 -323
- package/Runtime/Entity/Models/StoreInventoryRequestModels.cs +236 -165
- package/Runtime/Entity/Models/StoreInventoryResponseModels.cs +45 -30
- package/Runtime/Entity/OperationEvent.cs +43 -7
- package/Runtime/Entity/OperationHelper.cs +18 -2
- package/Runtime/Entity/OperationRequest.cs +80 -37
- package/Runtime/Entity/OperationResponse.cs +111 -63
- package/Runtime/Entity/Request/CustomOperationRequest.cs +53 -2
- package/Runtime/Entity/Response/CustomOperationResponse.cs +25 -4
- package/Runtime/GNNetwork.cs +333 -21
- package/Runtime/GNNetworkApi.cs +25 -13
- package/Runtime/GNNetworkAuthenticateApi.cs +531 -98
- package/Runtime/GNNetworkCharacterPlayerApi.cs +1587 -762
- package/Runtime/GNNetworkCloudScriptApi.cs +181 -0
- package/Runtime/GNNetworkCloudScriptApi.cs.meta +11 -0
- package/Runtime/GNNetworkContentApi.cs +238 -132
- package/Runtime/GNNetworkDashboardApi.cs +278 -117
- package/Runtime/GNNetworkGamePlayerApi.cs +1558 -747
- package/Runtime/GNNetworkGroupApi.cs +1228 -582
- package/Runtime/GNNetworkInventoryApi.cs +1048 -507
- package/Runtime/GNNetworkMasterPlayerApi.cs +2586 -1067
- package/Runtime/GNNetworkMultiplayerApi.cs +328 -147
- package/Runtime/GNNetworkStoreInventoryApi.cs +388 -162
- package/Runtime/Helper/CodeHelper.cs +45 -3
- package/Runtime/Helper/ConverterService.cs +240 -85
- package/Runtime/Logger/GNDebug.cs +46 -3
- package/Runtime/Networking/AuthenticateStatus.cs +30 -8
- package/Runtime/Networking/Handler/IServerEventHandler.cs +8 -8
- package/Runtime/Networking/Handler/OnCharacterPlayerFriendUpdateEventHandler.cs +31 -2
- package/Runtime/Networking/Handler/OnCharacterPlayerGroupUpdateEventHandler.cs +24 -3
- package/Runtime/Networking/Handler/OnGamePlayerFriendUpdateEventHandler.cs +24 -2
- package/Runtime/Networking/Handler/OnGamePlayerGroupUpdateEventHandler.cs +24 -2
- package/Runtime/Networking/Handler/OnGroupMemberUpdateEventHandler.cs +21 -2
- package/Runtime/Networking/Handler/OnGroupMessageUpdateEventHandler.cs +20 -2
- package/Runtime/Networking/Http/HttpPeer.cs +68 -25
- package/Runtime/Networking/Http/NetworkingHttpPeerBase.cs +44 -4
- package/Runtime/Networking/Http/NetworkingPeerHttpClientRequest.cs +63 -40
- package/Runtime/Networking/Http/NetworkingPeerHttpRequest.cs +43 -13
- package/Runtime/Networking/Http/NetworkingPeerUnityWebRequest.cs +72 -39
- package/Runtime/Networking/IPeer.cs +24 -2
- package/Runtime/Networking/NetworkingPeer.cs +64 -10
- package/Runtime/Networking/NetworkingPeerAPI.cs +20 -21
- package/Runtime/Networking/OperationPending.cs +79 -15
- package/Runtime/Networking/PeerBase.cs +86 -23
- package/Runtime/Networking/Socket/NetworkingPeerSocketV2.cs +57 -18
- package/Runtime/Networking/Socket/NetworkingPeerSocketV3.cs +70 -10
- package/Runtime/Networking/Socket/NetworkingSocketPeerBase.cs +165 -23
- package/Runtime/Networking/Socket/SocketPeer.cs +63 -12
- package/Runtime/Unity/ServiceCoroutine.cs +10 -0
- package/Runtime/Unity/ServiceCoroutine.cs.meta +11 -0
- package/Runtime/Unity/ServiceUpdate.cs +14 -1
- package/package.json +1 -1
|
@@ -1,67 +1,95 @@
|
|
|
1
1
|
namespace XmobiTea.GN.Networking.Http
|
|
2
2
|
{
|
|
3
3
|
using System;
|
|
4
|
-
|
|
5
|
-
using XmobiTea.GN.Constant;
|
|
6
|
-
using XmobiTea.GN.Helper;
|
|
4
|
+
using System.Text;
|
|
7
5
|
using XmobiTea.GN.Common;
|
|
8
6
|
using XmobiTea.GN.Config;
|
|
9
|
-
using
|
|
10
|
-
using XmobiTea.
|
|
7
|
+
using XmobiTea.GN.Constant;
|
|
8
|
+
using XmobiTea.GN.Helper;
|
|
11
9
|
using XmobiTea.GN.Logger;
|
|
10
|
+
using XmobiTea.MsgPack;
|
|
12
11
|
|
|
12
|
+
/// <summary>
|
|
13
|
+
/// Represents the HTTP application response.
|
|
14
|
+
/// </summary>
|
|
13
15
|
public class HttpAppResponse
|
|
14
16
|
{
|
|
17
|
+
/// <summary>Gets or sets the HTTP status code.</summary>
|
|
15
18
|
public long statusCode { get; internal set; }
|
|
19
|
+
|
|
20
|
+
/// <summary>Gets or sets the error message, if any.</summary>
|
|
16
21
|
public string error { get; internal set; }
|
|
22
|
+
|
|
23
|
+
/// <summary>Gets or sets the response data in byte array format.</summary>
|
|
17
24
|
public byte[] data { get; internal set; }
|
|
25
|
+
|
|
26
|
+
/// <summary>Gets or sets the response text as a string.</summary>
|
|
18
27
|
public string text { get; internal set; }
|
|
19
28
|
|
|
29
|
+
/// <summary>
|
|
30
|
+
/// Checks if the response contains an error.
|
|
31
|
+
/// </summary>
|
|
32
|
+
/// <returns>True if there is an error; otherwise, false.</returns>
|
|
20
33
|
public bool hasError()
|
|
21
34
|
{
|
|
22
35
|
return this.error != null;
|
|
23
36
|
}
|
|
24
37
|
|
|
38
|
+
/// <summary>
|
|
39
|
+
/// Converts the HTTP response to a string for logging purposes.
|
|
40
|
+
/// </summary>
|
|
41
|
+
/// <returns>A string representation of the response.</returns>
|
|
25
42
|
public string toString()
|
|
26
43
|
{
|
|
27
44
|
var stringBuilder = new StringBuilder();
|
|
28
|
-
|
|
29
45
|
stringBuilder.Append(" StatusCode: " + this.statusCode);
|
|
30
46
|
if (!string.IsNullOrEmpty(this.error)) stringBuilder.Append(", <color=red>Error: " + this.error + "</color>");
|
|
31
47
|
stringBuilder.Append(", Text: " + this.text);
|
|
32
|
-
|
|
33
48
|
return stringBuilder.ToString();
|
|
34
49
|
}
|
|
35
50
|
|
|
51
|
+
/// <summary>
|
|
52
|
+
/// Returns a string representation of the HTTP response.
|
|
53
|
+
/// </summary>
|
|
54
|
+
/// <returns>A string representation of the HTTP response.</returns>
|
|
36
55
|
public override string ToString()
|
|
37
56
|
{
|
|
38
57
|
return this.toString();
|
|
39
58
|
}
|
|
40
59
|
}
|
|
41
60
|
|
|
61
|
+
/// <summary>
|
|
62
|
+
/// Enum representing the type of HTTP POST requests.
|
|
63
|
+
/// </summary>
|
|
42
64
|
public enum PostType
|
|
43
65
|
{
|
|
44
66
|
Json = 0,
|
|
45
67
|
MsgPack = 1,
|
|
46
68
|
}
|
|
47
69
|
|
|
70
|
+
/// <summary>
|
|
71
|
+
/// Class for managing HTTP peer connections and requests.
|
|
72
|
+
/// </summary>
|
|
48
73
|
internal class HttpPeer : PeerBase
|
|
49
74
|
{
|
|
50
75
|
private NetworkingHttpPeerBase networkingHttpPeerBase;
|
|
51
76
|
|
|
52
77
|
private const char JSON_CHAR_KNOWN = '[';
|
|
53
78
|
|
|
79
|
+
/// <summary>
|
|
80
|
+
/// Initializes the GN HTTP socket object.
|
|
81
|
+
/// </summary>
|
|
54
82
|
internal override void initGNSocketObject()
|
|
55
83
|
{
|
|
56
84
|
var gnServerSettings = GNNetwork.gnServerSettings;
|
|
57
85
|
if (gnServerSettings == null) throw new NullReferenceException("Where is GN Server Settings");
|
|
58
86
|
|
|
59
87
|
this.isUse = gnServerSettings.isUseHttp();
|
|
60
|
-
|
|
61
88
|
var httpRequestType = gnServerSettings.getHttpRequestType();
|
|
62
89
|
|
|
63
90
|
#if UNITY_USING_BEST_HTTP
|
|
64
|
-
if (httpRequestType == HttpRequestType.HTTPRequest) this.networkingHttpPeerBase = new NetworkingPeerHttpRequest();
|
|
91
|
+
if (httpRequestType == HttpRequestType.HTTPRequest) this.networkingHttpPeerBase = new NetworkingPeerHttpRequest();
|
|
92
|
+
else
|
|
65
93
|
#endif
|
|
66
94
|
if (httpRequestType == HttpRequestType.UnityWebRequest) this.networkingHttpPeerBase = new NetworkingPeerUnityWebRequest();
|
|
67
95
|
else if (httpRequestType == HttpRequestType.HttpWebRequest) this.networkingHttpPeerBase = new NetworkingPeerHttpWebRequest();
|
|
@@ -71,18 +99,20 @@
|
|
|
71
99
|
this.networkingHttpPeerBase.init(httpUrl, userAgent);
|
|
72
100
|
}
|
|
73
101
|
|
|
102
|
+
/// <summary>
|
|
103
|
+
/// Sends an operation request via HTTP.
|
|
104
|
+
/// </summary>
|
|
105
|
+
/// <param name="operationPending">The operation pending to be sent.</param>
|
|
74
106
|
internal override void send(OperationPending operationPending)
|
|
75
107
|
{
|
|
76
108
|
base.send(operationPending);
|
|
77
|
-
|
|
78
109
|
GNDebug.log("[GN Http SEND] " + operationPending.getOperationRequest().ToString());
|
|
79
110
|
|
|
80
111
|
var operationRequest = operationPending.getOperationRequest();
|
|
81
|
-
|
|
82
112
|
var authToken = operationPending.getAuthToken();
|
|
83
113
|
var secretKey = operationPending.getSecretKey();
|
|
114
|
+
var gameId = operationPending.getGameId();
|
|
84
115
|
var customTags = operationPending.getCustomTags();
|
|
85
|
-
|
|
86
116
|
var postType = !operationRequest.isEncrypted() ? PostType.Json : PostType.MsgPack;
|
|
87
117
|
|
|
88
118
|
var subUri = (postType == PostType.Json ? NetworkingPeer.API_JSON : NetworkingPeer.API_MSG_PACK) + "/" + operationRequest.getOperationCode() + "/" + (int)operationPending.getRequestType() + "/" + (int)operationPending.getRequestRole();
|
|
@@ -90,20 +120,24 @@
|
|
|
90
120
|
this.networkingHttpPeerBase.postRequest(subUri, operationRequest.getParameters(), postType, httpAppResponse =>
|
|
91
121
|
{
|
|
92
122
|
this.onSendOperationRequestResponse(operationPending, httpAppResponse);
|
|
93
|
-
}, operationRequest.getTimeout(), authToken, secretKey, customTags);
|
|
123
|
+
}, operationRequest.getTimeout(), authToken, secretKey, customTags, gameId);
|
|
94
124
|
}
|
|
95
125
|
|
|
126
|
+
/// <summary>
|
|
127
|
+
/// Handles the response of an operation request.
|
|
128
|
+
/// </summary>
|
|
129
|
+
/// <param name="operationPending">The pending operation.</param>
|
|
130
|
+
/// <param name="httpAppResponse">The HTTP application response received.</param>
|
|
96
131
|
void onSendOperationRequestResponse(OperationPending operationPending, HttpAppResponse httpAppResponse)
|
|
97
132
|
{
|
|
98
133
|
var operationRequest = operationPending.getOperationRequest();
|
|
99
134
|
var obj = new GNArray();
|
|
100
|
-
|
|
135
|
+
|
|
101
136
|
if (!httpAppResponse.hasError())
|
|
102
137
|
{
|
|
103
138
|
if (httpAppResponse.statusCode == 200)
|
|
104
139
|
{
|
|
105
140
|
var isEncrypted = false;
|
|
106
|
-
|
|
107
141
|
GNArray gnArray = null;
|
|
108
142
|
|
|
109
143
|
if (!string.IsNullOrEmpty(httpAppResponse.text))
|
|
@@ -150,31 +184,40 @@
|
|
|
150
184
|
this.onResponseHandler(obj, operationRequest.isEncrypted());
|
|
151
185
|
}
|
|
152
186
|
|
|
153
|
-
|
|
187
|
+
/// <summary>
|
|
188
|
+
/// Sends a GET request to the specified URI.
|
|
189
|
+
/// </summary>
|
|
190
|
+
/// <param name="subUri">The sub-URI for the request.</param>
|
|
191
|
+
/// <param name="onHttpAppResponse">Callback to handle the HTTP response.</param>
|
|
192
|
+
/// <param name="timeout">The timeout for the request, in seconds.</param>
|
|
193
|
+
/// <param name="authToken">Optional authentication token.</param>
|
|
194
|
+
/// <param name="secretKey">Optional secret key.</param>
|
|
195
|
+
internal void getRequest(string subUri, Action<HttpAppResponse> onHttpAppResponse, float timeout = 15, string authToken = null, string secretKey = null, string gameId = null)
|
|
154
196
|
{
|
|
155
|
-
this.networkingHttpPeerBase.getRequest(subUri, onHttpAppResponse, timeout, authToken, secretKey);
|
|
197
|
+
this.networkingHttpPeerBase.getRequest(subUri, onHttpAppResponse, timeout, authToken, secretKey, gameId);
|
|
156
198
|
}
|
|
157
199
|
|
|
200
|
+
/// <summary>
|
|
201
|
+
/// Uploads a file to the server.
|
|
202
|
+
/// </summary>
|
|
203
|
+
/// <param name="fileId">The ID of the file to upload.</param>
|
|
204
|
+
/// <param name="content">The content of the file as a byte array.</param>
|
|
205
|
+
/// <param name="mimetype">The MIME type of the file.</param>
|
|
206
|
+
/// <param name="onHttpAppResponse">Callback to handle the HTTP response.</param>
|
|
207
|
+
/// <param name="timeout">The timeout for the request, in seconds.</param>
|
|
158
208
|
internal void uploadFile(string fileId, byte[] content, string mimetype, Action<HttpAppResponse> onHttpAppResponse, float timeout = 60)
|
|
159
209
|
{
|
|
160
210
|
var authToken = GNNetwork.getAuthenticateStatus().getAuthToken();
|
|
161
211
|
|
|
162
212
|
if (string.IsNullOrEmpty(authToken))
|
|
163
213
|
{
|
|
164
|
-
var httpAppResponse = new HttpAppResponse
|
|
165
|
-
httpAppResponse.statusCode = 401;
|
|
166
|
-
httpAppResponse.error = "Auth token null";
|
|
167
|
-
|
|
214
|
+
var httpAppResponse = new HttpAppResponse { statusCode = 401, error = "Auth token null" };
|
|
168
215
|
onHttpAppResponse?.Invoke(httpAppResponse);
|
|
169
|
-
|
|
170
216
|
return;
|
|
171
217
|
}
|
|
172
218
|
|
|
173
219
|
var subUri = NetworkingPeer.UPLOAD_FILE + "/" + fileId;
|
|
174
|
-
|
|
175
220
|
this.networkingHttpPeerBase.postRequestUpload(subUri, content, mimetype, onHttpAppResponse, timeout);
|
|
176
221
|
}
|
|
177
|
-
|
|
178
222
|
}
|
|
179
|
-
|
|
180
223
|
}
|
|
@@ -3,23 +3,63 @@ namespace XmobiTea.GN.Networking.Http
|
|
|
3
3
|
using System;
|
|
4
4
|
using XmobiTea.GN.Common;
|
|
5
5
|
|
|
6
|
+
/// <summary>
|
|
7
|
+
/// Abstract base class for HTTP networking operations.
|
|
8
|
+
/// </summary>
|
|
6
9
|
internal abstract class NetworkingHttpPeerBase
|
|
7
10
|
{
|
|
11
|
+
/// <summary>
|
|
12
|
+
/// Gets the HTTP URL used for requests.
|
|
13
|
+
/// </summary>
|
|
8
14
|
protected string httpUrl { get; private set; }
|
|
15
|
+
|
|
16
|
+
/// <summary>
|
|
17
|
+
/// Gets the user agent string used for requests.
|
|
18
|
+
/// </summary>
|
|
9
19
|
protected string userAgent { get; private set; }
|
|
10
20
|
|
|
11
|
-
|
|
21
|
+
/// <summary>
|
|
22
|
+
/// Sends a GET request to the specified URI.
|
|
23
|
+
/// </summary>
|
|
24
|
+
/// <param name="subUri">The sub-URI for the request.</param>
|
|
25
|
+
/// <param name="onHttpAppResponse">Callback to handle the HTTP response.</param>
|
|
26
|
+
/// <param name="timeout">The timeout for the request, in seconds.</param>
|
|
27
|
+
/// <param name="authToken">Optional authentication token.</param>
|
|
28
|
+
/// <param name="secretKey">Optional secret key.</param>
|
|
29
|
+
public abstract void getRequest(string subUri, Action<HttpAppResponse> onHttpAppResponse, float timeout, string authToken, string secretKe, string gameIdy);
|
|
12
30
|
|
|
13
|
-
|
|
31
|
+
/// <summary>
|
|
32
|
+
/// Sends a POST request to the specified URI.
|
|
33
|
+
/// </summary>
|
|
34
|
+
/// <param name="subUri">The sub-URI for the request.</param>
|
|
35
|
+
/// <param name="param">The parameters to include in the request.</param>
|
|
36
|
+
/// <param name="postType">The type of POST request (e.g., JSON, MsgPack).</param>
|
|
37
|
+
/// <param name="onHttpAppResponse">Callback to handle the HTTP response.</param>
|
|
38
|
+
/// <param name="timeout">The timeout for the request, in seconds.</param>
|
|
39
|
+
/// <param name="authToken">Optional authentication token.</param>
|
|
40
|
+
/// <param name="secretKey">Optional secret key.</param>
|
|
41
|
+
/// <param name="customTags">Optional custom tags to include in the request.</param>
|
|
42
|
+
public abstract void postRequest(string subUri, GNHashtable param, PostType postType, Action<HttpAppResponse> onHttpAppResponse, float timeout, string authToken, string secretKey, GNHashtable customTags, string gameId);
|
|
14
43
|
|
|
44
|
+
/// <summary>
|
|
45
|
+
/// Sends a file upload request to the specified URI.
|
|
46
|
+
/// </summary>
|
|
47
|
+
/// <param name="subUri">The sub-URI for the request.</param>
|
|
48
|
+
/// <param name="content">The file content to upload.</param>
|
|
49
|
+
/// <param name="mimetype">The MIME type of the file.</param>
|
|
50
|
+
/// <param name="onHttpAppResponse">Callback to handle the HTTP response.</param>
|
|
51
|
+
/// <param name="timeout">The timeout for the request, in seconds.</param>
|
|
15
52
|
public abstract void postRequestUpload(string subUri, byte[] content, string mimetype, Action<HttpAppResponse> onHttpAppResponse, float timeout);
|
|
16
53
|
|
|
54
|
+
/// <summary>
|
|
55
|
+
/// Initializes the HTTP peer with the specified URL and user agent.
|
|
56
|
+
/// </summary>
|
|
57
|
+
/// <param name="httpUrl">The base URL for the HTTP requests.</param>
|
|
58
|
+
/// <param name="userAgent">The user agent string to include in the requests.</param>
|
|
17
59
|
public virtual void init(string httpUrl, string userAgent)
|
|
18
60
|
{
|
|
19
61
|
this.httpUrl = httpUrl;
|
|
20
62
|
this.userAgent = userAgent;
|
|
21
63
|
}
|
|
22
|
-
|
|
23
64
|
}
|
|
24
|
-
|
|
25
65
|
}
|
|
@@ -9,31 +9,42 @@
|
|
|
9
9
|
using XmobiTea.GN.Helper;
|
|
10
10
|
using XmobiTea.MsgPack;
|
|
11
11
|
|
|
12
|
+
/// <summary>
|
|
13
|
+
/// Handles HTTP networking using HttpWebRequest or HttpClient.
|
|
14
|
+
/// </summary>
|
|
12
15
|
internal class NetworkingPeerHttpWebRequest : NetworkingHttpPeerBase
|
|
13
16
|
{
|
|
14
17
|
private readonly HttpClient client;
|
|
15
18
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
19
|
+
/// <summary>
|
|
20
|
+
/// Sends a GET request using HttpWebRequest or HttpClient.
|
|
21
|
+
/// </summary>
|
|
22
|
+
/// <param name="subUri">The sub-URI for the request.</param>
|
|
23
|
+
/// <param name="onHttpAppResponse">Callback to handle the HTTP response.</param>
|
|
24
|
+
/// <param name="timeout">Timeout for the request, in seconds.</param>
|
|
25
|
+
/// <param name="authToken">Optional authentication token.</param>
|
|
26
|
+
/// <param name="secretKey">Optional secret key.</param>
|
|
27
|
+
public override void getRequest(string subUri, Action<HttpAppResponse> onHttpAppResponse, float timeout, string authToken, string secretKey, string gameId)
|
|
20
28
|
{
|
|
21
|
-
this.getRequestViaHttpWeb(subUri, onHttpAppResponse, timeout, authToken, secretKey);
|
|
29
|
+
this.getRequestViaHttpWeb(subUri, onHttpAppResponse, timeout, authToken, secretKey, gameId);
|
|
22
30
|
}
|
|
23
31
|
|
|
24
|
-
private async void getRequestViaHttpWeb(string subUri, Action<HttpAppResponse> onHttpAppResponse, float timeout, string authToken, string secretKey)
|
|
32
|
+
private async void getRequestViaHttpWeb(string subUri, Action<HttpAppResponse> onHttpAppResponse, float timeout, string authToken, string secretKey, string gameId)
|
|
25
33
|
{
|
|
26
34
|
using (var requestMessage = new HttpRequestMessage(HttpMethod.Get, this.httpUrl + "/" + subUri))
|
|
27
35
|
{
|
|
28
36
|
if (!string.IsNullOrEmpty(authToken)) requestMessage.Headers.Add(Commands.RequestAuthTokenCmd, authToken);
|
|
29
37
|
if (!string.IsNullOrEmpty(secretKey)) requestMessage.Headers.Add(Commands.RequestSecretCmd, secretKey);
|
|
38
|
+
if (!string.IsNullOrEmpty(gameId)) requestMessage.Headers.Add(Commands.RequestGameIdCmd, gameId);
|
|
30
39
|
|
|
31
40
|
try
|
|
32
41
|
{
|
|
33
42
|
var webResponse = await this.client.SendAsync(requestMessage);
|
|
34
43
|
|
|
35
|
-
var httpAppResponse = new HttpAppResponse
|
|
36
|
-
|
|
44
|
+
var httpAppResponse = new HttpAppResponse
|
|
45
|
+
{
|
|
46
|
+
statusCode = (int)webResponse.StatusCode
|
|
47
|
+
};
|
|
37
48
|
|
|
38
49
|
if (webResponse.StatusCode == HttpStatusCode.OK)
|
|
39
50
|
{
|
|
@@ -49,10 +60,11 @@
|
|
|
49
60
|
}
|
|
50
61
|
catch (Exception e)
|
|
51
62
|
{
|
|
52
|
-
var httpAppResponse = new HttpAppResponse
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
63
|
+
var httpAppResponse = new HttpAppResponse
|
|
64
|
+
{
|
|
65
|
+
statusCode = -1,
|
|
66
|
+
error = e.Message
|
|
67
|
+
};
|
|
56
68
|
|
|
57
69
|
onHttpAppResponse?.Invoke(httpAppResponse);
|
|
58
70
|
}
|
|
@@ -134,45 +146,54 @@
|
|
|
134
146
|
// }
|
|
135
147
|
//}
|
|
136
148
|
|
|
137
|
-
|
|
149
|
+
/// <summary>
|
|
150
|
+
/// Sends a POST request using HttpWebRequest or HttpClient.
|
|
151
|
+
/// </summary>
|
|
152
|
+
/// <param name="subUri">The sub-URI for the request.</param>
|
|
153
|
+
/// <param name="param">The parameters to include in the request.</param>
|
|
154
|
+
/// <param name="postType">The type of POST request (e.g., JSON, MsgPack).</param>
|
|
155
|
+
/// <param name="onHttpAppResponse">Callback to handle the HTTP response.</param>
|
|
156
|
+
/// <param name="timeout">Timeout for the request, in seconds.</param>
|
|
157
|
+
/// <param name="authToken">Optional authentication token.</param>
|
|
158
|
+
/// <param name="secretKey">Optional secret key.</param>
|
|
159
|
+
/// <param name="customTags">Optional custom tags.</param>
|
|
160
|
+
public override void postRequest(string subUri, GNHashtable param, PostType postType, Action<HttpAppResponse> onHttpAppResponse, float timeout, string authToken, string secretKey, GNHashtable customTags, string gameId)
|
|
138
161
|
{
|
|
139
|
-
this.postRequestViaHttpWeb(subUri, param, postType, onHttpAppResponse, timeout, authToken, secretKey, customTags);
|
|
162
|
+
this.postRequestViaHttpWeb(subUri, param, postType, onHttpAppResponse, timeout, authToken, secretKey, customTags, gameId);
|
|
140
163
|
}
|
|
141
164
|
|
|
142
|
-
private async void postRequestViaHttpWeb(string subUri, GNHashtable param, PostType postType, Action<HttpAppResponse> onHttpAppResponse, float timeout, string authToken, string secretKey, GNHashtable customTags)
|
|
165
|
+
private async void postRequestViaHttpWeb(string subUri, GNHashtable param, PostType postType, Action<HttpAppResponse> onHttpAppResponse, float timeout, string authToken, string secretKey, GNHashtable customTags, string gameId)
|
|
143
166
|
{
|
|
144
167
|
using (var requestMessage = new HttpRequestMessage(HttpMethod.Post, this.httpUrl + "/" + subUri))
|
|
145
168
|
{
|
|
146
169
|
if (param == null) param = new GNHashtable();
|
|
147
|
-
|
|
148
170
|
if (customTags != null) param.add(GNParameterCode.CustomTags, customTags);
|
|
149
171
|
|
|
150
172
|
if (postType == PostType.Json)
|
|
151
173
|
{
|
|
152
174
|
var content = Encoding.UTF8.GetBytes(Serializer.Serialize(param.toData()));
|
|
153
|
-
|
|
154
175
|
requestMessage.Content = new ByteArrayContent(content);
|
|
155
|
-
|
|
156
|
-
requestMessage.Headers.TryAddWithoutValidation(Commands.CONTENT_TYPE, Commands.APPLICATION_JSON);
|
|
176
|
+
requestMessage.Headers.Add(Commands.CONTENT_TYPE, Commands.APPLICATION_JSON);
|
|
157
177
|
}
|
|
158
178
|
else if (postType == PostType.MsgPack)
|
|
159
179
|
{
|
|
160
180
|
var content = MsgPackSerializer.Serialize(param.toData());
|
|
161
|
-
|
|
162
181
|
requestMessage.Content = new ByteArrayContent(content);
|
|
163
|
-
|
|
164
|
-
requestMessage.Headers.TryAddWithoutValidation(Commands.CONTENT_TYPE, Commands.APPLICATION_MSGPACK);
|
|
182
|
+
requestMessage.Headers.Add(Commands.CONTENT_TYPE, Commands.APPLICATION_MSGPACK);
|
|
165
183
|
}
|
|
166
184
|
|
|
167
|
-
if (!string.IsNullOrEmpty(authToken)) requestMessage.Headers.
|
|
168
|
-
if (!string.IsNullOrEmpty(secretKey)) requestMessage.Headers.
|
|
185
|
+
if (!string.IsNullOrEmpty(authToken)) requestMessage.Headers.Add(Commands.RequestAuthTokenCmd, authToken);
|
|
186
|
+
if (!string.IsNullOrEmpty(secretKey)) requestMessage.Headers.Add(Commands.RequestSecretCmd, secretKey);
|
|
187
|
+
if (!string.IsNullOrEmpty(gameId)) requestMessage.Headers.Add(Commands.RequestGameIdCmd, gameId);
|
|
169
188
|
|
|
170
189
|
try
|
|
171
190
|
{
|
|
172
191
|
var webResponse = await this.client.SendAsync(requestMessage);
|
|
173
192
|
|
|
174
|
-
var httpAppResponse = new HttpAppResponse
|
|
175
|
-
|
|
193
|
+
var httpAppResponse = new HttpAppResponse
|
|
194
|
+
{
|
|
195
|
+
statusCode = (int)webResponse.StatusCode
|
|
196
|
+
};
|
|
176
197
|
|
|
177
198
|
if (webResponse.StatusCode == HttpStatusCode.OK)
|
|
178
199
|
{
|
|
@@ -188,10 +209,11 @@
|
|
|
188
209
|
}
|
|
189
210
|
catch (Exception e)
|
|
190
211
|
{
|
|
191
|
-
var httpAppResponse = new HttpAppResponse
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
212
|
+
var httpAppResponse = new HttpAppResponse
|
|
213
|
+
{
|
|
214
|
+
statusCode = -1,
|
|
215
|
+
error = e.Message
|
|
216
|
+
};
|
|
195
217
|
|
|
196
218
|
onHttpAppResponse?.Invoke(httpAppResponse);
|
|
197
219
|
}
|
|
@@ -299,7 +321,14 @@
|
|
|
299
321
|
// onHttpAppResponse?.Invoke(httpAppResponse);
|
|
300
322
|
// }
|
|
301
323
|
//}
|
|
302
|
-
|
|
324
|
+
/// <summary>
|
|
325
|
+
/// Sends a file upload request using HttpWebRequest or HttpClient.
|
|
326
|
+
/// </summary>
|
|
327
|
+
/// <param name="subUri">The sub-URI for the request.</param>
|
|
328
|
+
/// <param name="content">The file content to upload.</param>
|
|
329
|
+
/// <param name="mimetype">The MIME type of the file.</param>
|
|
330
|
+
/// <param name="onHttpAppResponse">Callback to handle the HTTP response.</param>
|
|
331
|
+
/// <param name="timeout">Timeout for the request, in seconds.</param>
|
|
303
332
|
public override void postRequestUpload(string subUri, byte[] content, string mimetype, Action<HttpAppResponse> onHttpAppResponse, float timeout)
|
|
304
333
|
{
|
|
305
334
|
this.postRequestUploadViaHttpWeb(subUri, content, mimetype, onHttpAppResponse, timeout);
|
|
@@ -471,20 +500,14 @@
|
|
|
471
500
|
// }
|
|
472
501
|
//}
|
|
473
502
|
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
this.client.DefaultRequestHeaders.TryAddWithoutValidation(Commands.USER_AGENT, userAgent);
|
|
479
|
-
}
|
|
480
|
-
|
|
503
|
+
/// <summary>
|
|
504
|
+
/// Initializes a new instance of the <see cref="NetworkingPeerHttpWebRequest"/> class.
|
|
505
|
+
/// </summary>
|
|
481
506
|
public NetworkingPeerHttpWebRequest()
|
|
482
507
|
{
|
|
483
508
|
//HTTPManager.KeepAliveDefaultValue = true;
|
|
484
509
|
|
|
485
510
|
this.client = new HttpClient();
|
|
486
511
|
}
|
|
487
|
-
|
|
488
512
|
}
|
|
489
|
-
|
|
490
513
|
}
|
|
@@ -11,9 +11,20 @@ namespace XmobiTea.GN.Networking.Http
|
|
|
11
11
|
using XmobiTea.GN.Helper;
|
|
12
12
|
using XmobiTea.MsgPack;
|
|
13
13
|
|
|
14
|
+
/// <summary>
|
|
15
|
+
/// Handles HTTP requests using BestHTTP library.
|
|
16
|
+
/// </summary>
|
|
14
17
|
internal class NetworkingPeerHttpRequest : NetworkingHttpPeerBase
|
|
15
18
|
{
|
|
16
|
-
|
|
19
|
+
/// <summary>
|
|
20
|
+
/// Sends a GET request to the specified URI.
|
|
21
|
+
/// </summary>
|
|
22
|
+
/// <param name="subUri">The sub-URI for the request.</param>
|
|
23
|
+
/// <param name="onHttpAppResponse">Callback to handle the HTTP response.</param>
|
|
24
|
+
/// <param name="timeout">Timeout for the request, in seconds.</param>
|
|
25
|
+
/// <param name="authToken">Optional authentication token.</param>
|
|
26
|
+
/// <param name="secretKey">Optional secret key.</param>
|
|
27
|
+
public override void getRequest(string subUri, Action<HttpAppResponse> onHttpAppResponse, float timeout, string authToken, string secretKey, string gameId)
|
|
17
28
|
{
|
|
18
29
|
var request = new HTTPRequest(new Uri(this.httpUrl + "/" + subUri), HTTPMethods.Get, (httpRequest, httpResponse) =>
|
|
19
30
|
{
|
|
@@ -38,11 +49,23 @@ namespace XmobiTea.GN.Networking.Http
|
|
|
38
49
|
|
|
39
50
|
if (!string.IsNullOrEmpty(authToken)) request.SetHeader(Commands.RequestAuthTokenCmd, authToken);
|
|
40
51
|
if (!string.IsNullOrEmpty(secretKey)) request.SetHeader(Commands.RequestSecretCmd, secretKey);
|
|
52
|
+
if (!string.IsNullOrEmpty(gameId)) request.SetHeader(Commands.RequestGameIdCmd, gameId);
|
|
41
53
|
|
|
42
54
|
request.Send();
|
|
43
55
|
}
|
|
44
56
|
|
|
45
|
-
|
|
57
|
+
/// <summary>
|
|
58
|
+
/// Sends a POST request with specified parameters and content type.
|
|
59
|
+
/// </summary>
|
|
60
|
+
/// <param name="subUri">The sub-URI for the request.</param>
|
|
61
|
+
/// <param name="param">The parameters to include in the request.</param>
|
|
62
|
+
/// <param name="postType">The type of POST request (e.g., JSON, MsgPack).</param>
|
|
63
|
+
/// <param name="onHttpAppResponse">Callback to handle the HTTP response.</param>
|
|
64
|
+
/// <param name="timeout">Timeout for the request, in seconds.</param>
|
|
65
|
+
/// <param name="authToken">Optional authentication token.</param>
|
|
66
|
+
/// <param name="secretKey">Optional secret key.</param>
|
|
67
|
+
/// <param name="customTags">Optional custom tags.</param>
|
|
68
|
+
public override void postRequest(string subUri, GNHashtable param, PostType postType, Action<HttpAppResponse> onHttpAppResponse, float timeout, string authToken, string secretKey, GNHashtable customTags, string gameId)
|
|
46
69
|
{
|
|
47
70
|
var request = new HTTPRequest(new Uri(this.httpUrl + "/" + subUri), HTTPMethods.Post, (httpRequest, httpResponse) =>
|
|
48
71
|
{
|
|
@@ -64,25 +87,18 @@ namespace XmobiTea.GN.Networking.Http
|
|
|
64
87
|
});
|
|
65
88
|
|
|
66
89
|
if (param == null) param = new GNHashtable();
|
|
67
|
-
|
|
68
90
|
if (customTags != null) param.add(GNParameterCode.CustomTags, customTags);
|
|
69
91
|
|
|
70
92
|
if (postType == PostType.Json)
|
|
71
93
|
{
|
|
72
94
|
request.SetHeader(Commands.CONTENT_TYPE, Commands.APPLICATION_JSON);
|
|
73
|
-
|
|
74
95
|
var content = Encoding.UTF8.GetBytes(Serializer.Serialize(param.toData()));
|
|
75
|
-
|
|
76
96
|
request.UploadStream = new MemoryStream(content);
|
|
77
97
|
}
|
|
78
98
|
else if (postType == PostType.MsgPack)
|
|
79
99
|
{
|
|
80
100
|
request.SetHeader(Commands.CONTENT_TYPE, Commands.APPLICATION_MSGPACK);
|
|
81
|
-
|
|
82
|
-
var dataSend = param.toData();
|
|
83
|
-
|
|
84
|
-
var content = MsgPackSerializer.Serialize(dataSend);
|
|
85
|
-
|
|
101
|
+
var content = MsgPackSerializer.Serialize(param.toData());
|
|
86
102
|
request.UploadStream = new MemoryStream(content);
|
|
87
103
|
}
|
|
88
104
|
|
|
@@ -90,10 +106,19 @@ namespace XmobiTea.GN.Networking.Http
|
|
|
90
106
|
|
|
91
107
|
if (!string.IsNullOrEmpty(authToken)) request.SetHeader(Commands.RequestAuthTokenCmd, authToken);
|
|
92
108
|
if (!string.IsNullOrEmpty(secretKey)) request.SetHeader(Commands.RequestSecretCmd, secretKey);
|
|
109
|
+
if (!string.IsNullOrEmpty(gameId)) request.SetHeader(Commands.RequestGameIdCmd, gameId);
|
|
93
110
|
|
|
94
111
|
request.Send();
|
|
95
112
|
}
|
|
96
113
|
|
|
114
|
+
/// <summary>
|
|
115
|
+
/// Sends a file upload request to the specified URI.
|
|
116
|
+
/// </summary>
|
|
117
|
+
/// <param name="subUri">The sub-URI for the request.</param>
|
|
118
|
+
/// <param name="content">The file content to upload.</param>
|
|
119
|
+
/// <param name="mimetype">The MIME type of the file.</param>
|
|
120
|
+
/// <param name="onHttpAppResponse">Callback to handle the HTTP response.</param>
|
|
121
|
+
/// <param name="timeout">Timeout for the request, in seconds.</param>
|
|
97
122
|
public override void postRequestUpload(string subUri, byte[] content, string mimetype, Action<HttpAppResponse> onHttpAppResponse, float timeout)
|
|
98
123
|
{
|
|
99
124
|
var request = new HTTPRequest(new Uri(this.httpUrl + "/" + subUri), HTTPMethods.Post, (httpRequest, httpResponse) =>
|
|
@@ -116,23 +141,28 @@ namespace XmobiTea.GN.Networking.Http
|
|
|
116
141
|
});
|
|
117
142
|
|
|
118
143
|
request.Timeout = TimeSpan.FromSeconds(timeout);
|
|
119
|
-
|
|
120
144
|
request.AddBinaryData(Commands.File, content, null, mimetype);
|
|
121
145
|
|
|
122
146
|
var authToken = GNNetwork.getAuthenticateStatus().getAuthToken();
|
|
123
|
-
|
|
124
147
|
if (!string.IsNullOrEmpty(authToken)) request.SetHeader(Commands.RequestAuthTokenCmd, authToken);
|
|
125
148
|
|
|
126
149
|
request.Send();
|
|
127
150
|
}
|
|
128
151
|
|
|
152
|
+
/// <summary>
|
|
153
|
+
/// Initializes the HTTP peer with the specified URL and user agent.
|
|
154
|
+
/// </summary>
|
|
155
|
+
/// <param name="httpUrl">The base URL for the HTTP requests.</param>
|
|
156
|
+
/// <param name="userAgent">The user agent string to include in the requests.</param>
|
|
129
157
|
public override void init(string httpUrl, string userAgent)
|
|
130
158
|
{
|
|
131
159
|
base.init(httpUrl, userAgent);
|
|
132
|
-
|
|
133
160
|
HTTPManager.UserAgent = userAgent;
|
|
134
161
|
}
|
|
135
162
|
|
|
163
|
+
/// <summary>
|
|
164
|
+
/// Initializes a new instance of the <see cref="NetworkingPeerHttpRequest"/> class.
|
|
165
|
+
/// </summary>
|
|
136
166
|
public NetworkingPeerHttpRequest()
|
|
137
167
|
{
|
|
138
168
|
HTTPManager.KeepAliveDefaultValue = true;
|