/// <summary> /// Notifies the user that a Send Message From Player request has failed. /// </summary> /// /// <param name="serverResponse">A container for information on the response from the server. Only /// failed responses can be passed into this method.</param> /// <param name="request"> The request that was sent to the server.</param> /// <param name="callback">The error callback.</param> private void NotifySendMessageFromPlayerError(ServerResponse serverResponse, SendMessageFromPlayerRequest request, Action <SendMessageFromPlayerRequest, SendMessageFromPlayerError> errorCallback) { ReleaseAssert.IsTrue(serverResponse.Result != HttpResult.Success || serverResponse.HttpResponseCode != SuccessHttpResponseCode, "Input server request must describe an error."); switch (serverResponse.Result) { case HttpResult.Success: m_logging.LogVerboseMessage("Send Message From Player request failed with http response code: " + serverResponse.HttpResponseCode); break; case HttpResult.CouldNotConnect: m_logging.LogVerboseMessage("Send Message From Player request failed becuase a connection could be established."); break; default: m_logging.LogVerboseMessage("Send Message From Player request failed for an unknown reason."); throw new ArgumentException("Invalid value for server response result."); } SendMessageFromPlayerError error = new SendMessageFromPlayerError(serverResponse); m_taskScheduler.ScheduleMainThreadTask(() => { errorCallback(request, error); }); }
/// <summary> /// Sends a message to a player from the currently logged-in Player. A message can /// transfer Currency and Inventory items between players. Direct access to this /// method from the SDKs is disabled by default and must be enabled from the /// ChilliConnect dashboard. Note: At least one of; Title, Text, Data, or Rewards is /// required. /// </summary> /// /// <param name="desc">The request description.</param> /// <param name="successCallback">The delegate which is called if the request was successful.</param> /// <param name="errorCallback">The delegate which is called if the request was unsuccessful. Provides /// a container with information on what went wrong.</param> public void SendMessageFromPlayer(SendMessageFromPlayerRequestDesc desc, Action <SendMessageFromPlayerRequest, SendMessageFromPlayerResponse> successCallback, Action <SendMessageFromPlayerRequest, SendMessageFromPlayerError> errorCallback) { m_logging.LogVerboseMessage("Sending Send Message From Player request."); var connectAccessToken = m_dataStore.GetString("UserAccessToken"); var request = new SendMessageFromPlayerRequest(desc, connectAccessToken); m_serverRequestSystem.SendImmediateRequest(request, (IImmediateServerRequest sentRequest, ServerResponse serverResponse) => { ReleaseAssert.IsTrue(request == sentRequest, "Received request is not the same as the one sent!"); if (serverResponse.Result == HttpResult.Success && serverResponse.HttpResponseCode == SuccessHttpResponseCode) { NotifySendMessageFromPlayerSuccess(serverResponse, request, successCallback); } else { NotifySendMessageFromPlayerError(serverResponse, request, errorCallback); } }); }
/// <summary> /// Notifies the user that a Send Message From Player request was successful. /// </summary> /// /// <param name="serverResponse">A container for information on the response from the server. Only /// successful responses can be passed into this method.</param> /// <param name="request"> The request that was sent to the server.</param> /// <param name="callback">The success callback.</param> private void NotifySendMessageFromPlayerSuccess(ServerResponse serverResponse, SendMessageFromPlayerRequest request, Action <SendMessageFromPlayerRequest, SendMessageFromPlayerResponse> successCallback) { ReleaseAssert.IsTrue(serverResponse.Result == HttpResult.Success && serverResponse.HttpResponseCode == SuccessHttpResponseCode, "Input server request must describe a success."); m_logging.LogVerboseMessage("SendMessageFromPlayer request succeeded."); SendMessageFromPlayerResponse outputResponse = new SendMessageFromPlayerResponse(serverResponse.Body); m_taskScheduler.ScheduleMainThreadTask(() => { successCallback(request, outputResponse); }); }