Skip to content

Commit

Permalink
Fix HFTSite for Unity 2017
Browse files Browse the repository at this point in the history
Unity broke the WWW class so I had to switch to UnityWebRequest
  • Loading branch information
greggman committed Sep 20, 2017
1 parent 2318fdb commit 65d52c3
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions Assets/HappyFunTimes/HappyFunTimesCore/Server/HFTSite.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Collections.Generic;
using System.Net;
using UnityEngine;
using UnityEngine.Networking;

namespace HappyFunTimes
{
Expand Down Expand Up @@ -39,7 +40,7 @@ class Informer {
int tryCount_ = 0;
bool done_ = false;
bool haveNewAddresses_ = false;
WWW www_;
UnityWebRequest www_;
HFTLog log_;

public Informer(HFTLog log, SharedState sharedState, string url, string domain)
Expand Down Expand Up @@ -85,20 +86,19 @@ public void Stop(MonoBehaviour monoBehaviour)

IEnumerator InformCoroutine()
{
var headers = new Dictionary<string, string>();
headers["Content-Type"] = "application/json";
headers["Host"] = domain_;
www_ = new UnityWebRequest(url_, UnityWebRequest.kHttpVerbPOST);
www_.uploadHandler = new UploadHandlerRaw(addressesBytes_);
www_.uploadHandler.contentType = "application/json";
www_.downloadHandler = new DownloadHandlerBuffer();

www_ = new WWW(url_, addressesBytes_, headers);
yield return www_.Send();

yield return www_;

string err = www_.error;
string result = www_.text;
bool isError = (www_.isNetworkError || www_.isHttpError);
string result = www_.downloadHandler.text;
www_ = null;

// Was it successful?
if (String.IsNullOrEmpty(err))
if (!isError)
{
// Yes
log_.Info("registered: " + addressesStr_ + " with " + domain_ + " for: " + result);
Expand Down Expand Up @@ -230,7 +230,6 @@ IEnumerator CheckAddresses()
oldAddressesStr_ = newAddressesStr;
var data = new InformData(addresses, options_.port);
var json = Serializer.Serialize(data);
log_.Info("sending: " + json);
addressBytes_ = System.Text.Encoding.UTF8.GetBytes(json);
haveNewAddresses = true;
}
Expand Down

0 comments on commit 65d52c3

Please sign in to comment.