Repository URL to install this package:
Version:
2024.6.10 ▾
|
/*
* Copyright 2016 Game Server Services, Inc. or its affiliates. All Rights
* Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using Gs2.Core;
using Gs2.Core.Model;
using Gs2.Core.Net;
using Gs2.Util.LitJson;
#if UNITY_2017_1_OR_NEWER
using System.Collections;
using UnityEngine.Events;
using UnityEngine.Networking;
#if GS2_ENABLE_UNITASK
using Cysharp.Threading.Tasks;
#endif
#else
using System.Threading.Tasks;
using System.Threading;
#endif
namespace Gs2.Gs2Deploy
{
public class Gs2DeployWebSocketClient : AbstractGs2Client
{
public static string Endpoint = "deploy";
protected Gs2WebSocketSession Gs2WebSocketSession => (Gs2WebSocketSession) Gs2Session;
public Gs2DeployWebSocketClient(Gs2WebSocketSession Gs2WebSocketSession) : base(Gs2WebSocketSession)
{
}
public class ValidateTask : Gs2WebSocketSessionTask<Request.ValidateRequest, Result.ValidateResult>
{
public ValidateTask(IGs2Session session, Request.ValidateRequest request) : base(session, request)
{
}
protected override IGs2SessionRequest CreateRequest(Request.ValidateRequest request)
{
var stringBuilder = new StringBuilder();
var jsonWriter = new JsonWriter(stringBuilder);
jsonWriter.WriteObjectStart();
if (request.Template != null)
{
jsonWriter.WritePropertyName("template");
jsonWriter.Write(request.Template.ToString());
}
if (request.ContextStack != null)
{
jsonWriter.WritePropertyName("contextStack");
jsonWriter.Write(request.ContextStack.ToString());
}
if (request.RequestId != null)
{
jsonWriter.WritePropertyName("xGs2RequestId");
jsonWriter.Write(request.RequestId);
}
AddHeader(
Session.Credential,
"deploy",
"stack",
"validate",
jsonWriter
);
jsonWriter.WriteObjectEnd();
return WebSocketSessionRequestFactory.New<WebSocketSessionRequest>(stringBuilder.ToString());
}
}
#if UNITY_2017_1_OR_NEWER
public IEnumerator Validate(
Request.ValidateRequest request,
UnityAction<AsyncResult<Result.ValidateResult>> callback
)
{
var task = new ValidateTask(
Gs2WebSocketSession,
request
);
yield return task;
callback.Invoke(new AsyncResult<Result.ValidateResult>(task.Result, task.Error));
}
public IFuture<Result.ValidateResult> ValidateFuture(
Request.ValidateRequest request
)
{
return new ValidateTask(
Gs2WebSocketSession,
request
);
}
#if GS2_ENABLE_UNITASK
public async UniTask<Result.ValidateResult> ValidateAsync(
Request.ValidateRequest request
)
{
var task = new ValidateTask(
Gs2WebSocketSession,
request
);
return await task.Invoke();
}
#else
public ValidateTask ValidateAsync(
Request.ValidateRequest request
)
{
return new ValidateTask(
Gs2WebSocketSession,
request
);
}
#endif
#else
public async Task<Result.ValidateResult> ValidateAsync(
Request.ValidateRequest request
)
{
var task = new ValidateTask(
Gs2WebSocketSession,
request
);
return await task.Invoke();
}
#endif
}
}