Skip to content

Commit

Permalink
fixes for 2019
Browse files Browse the repository at this point in the history
  • Loading branch information
greggman committed May 26, 2019
1 parent 576d37f commit 97b7647
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 45 deletions.
39 changes: 20 additions & 19 deletions Assets/HappyFunTimes/HappyFunTimesCore/HFTCheck.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
using UnityEngine;
using UnityEngine.Networking;
using HappyFunTimes;
using System;
using System.Collections;
Expand All @@ -46,7 +47,6 @@ public class HFTCheck : MonoBehaviour {
string m_url;
int m_tries;
bool m_found;
WWW m_www;
const int s_maxTries = 500;

public void Init(string url, Action onConnect, Action onFail)
Expand Down Expand Up @@ -88,27 +88,28 @@ IEnumerator PingHFT()
{
string json = JsonUtility.ToJson(new PostCmd("happyFunTimesPingForGame"));
byte[] bytes = System.Text.Encoding.UTF8.GetBytes(json);
var headers = new Dictionary<string, string>();
headers["Content-Type"] = "application/json";
m_www = new WWW(m_url, bytes, headers);
using (var www = new UnityWebRequest(m_url, UnityWebRequest.kHttpVerbPOST)) {
www.uploadHandler = new UploadHandlerRaw(bytes);
www.uploadHandler.contentType = "application/json";
www.downloadHandler = new DownloadHandlerBuffer();
www.SetRequestHeader("Content-Type", "application/json");
yield return www.SendWebRequest();

yield return m_www;

string err = m_www.error;
string result = m_www.text;
m_www = null;

if (String.IsNullOrEmpty(err))
{
HFTPing ping = JsonUtility.FromJson<HFTPing>(result);
if (ping != null && ping.id.Equals("HappyFunTimes")) {
m_found = true;
string err = www.error;
string result = www.downloadHandler.text;

if (!www.isHttpError && !www.isNetworkError && String.IsNullOrEmpty(err))
{
HFTPing ping = JsonUtility.FromJson<HFTPing>(result);
if (ping != null && ping.id.Equals("HappyFunTimes")) {
m_found = true;
}
}
}

if (!m_found)
{
m_log.Tell("error: " + err + ", result:" + result);
if (!m_found)
{
m_log.Tell("error: " + err + ", result:" + result);
}
}
}
}
Expand Down
46 changes: 23 additions & 23 deletions Assets/HappyFunTimes/HappyFunTimesCore/HFTSyncedClock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
using System.Collections.Generic;
using DeJson;
using UnityEngine;
using UnityEngine.Networking;

namespace HappyFunTimes
{
Expand Down Expand Up @@ -96,40 +97,39 @@ IEnumerator SyncClock()

IEnumerator PingClock()
{
m_www = new WWW(m_url, m_timeCmdBytes, m_headers);
using (var www = new UnityWebRequest(m_url, UnityWebRequest.kHttpVerbPOST)) {
www.uploadHandler = new UploadHandlerRaw(m_timeCmdBytes);
www.uploadHandler.contentType = "application/json";
www.downloadHandler = new DownloadHandlerBuffer();
www.SetRequestHeader("Content-Type", "application/json");
double sendTime = HFTUtil.GetJSTimeInSeconds();
yield return www.SendWebRequest();
double receiveTime = HFTUtil.GetJSTimeInSeconds();

double sendTime = HFTUtil.GetJSTimeInSeconds();
yield return m_www;
double receiveTime = HFTUtil.GetJSTimeInSeconds();
string err = www.error;
string result = www.downloadHandler.text;

string err = m_www.error;
string result = m_www.text;
m_www = null;

if (!String.IsNullOrEmpty(err))
{
m_log.Tell("error: " + err + ", result:" + result);
}
else
{
HFTTimePing ping = JsonUtility.FromJson<HFTTimePing>(result);
if (ping != null && ping.time > 0.0)
if (www.isHttpError || www.isNetworkError && !String.IsNullOrEmpty(err)) {
m_log.Tell("error: " + err + ", result:" + result);
}
else
{
double duration = receiveTime - sendTime;
double serverTime = ping.time + duration / 2;
s_timeOffsetSeconds = serverTime - receiveTime;
HFTTimePing ping = JsonUtility.FromJson<HFTTimePing>(result);
if (ping != null && ping.time > 0.0)
{
double duration = receiveTime - sendTime;
double serverTime = ping.time + duration / 2;
s_timeOffsetSeconds = serverTime - receiveTime;
}

}
}
}

bool m_running = false;
HFTLog m_log = new HFTLog("HFTSyncedClock");
string m_url;
WWW m_www;
byte[] m_timeCmdBytes = System.Text.Encoding.UTF8.GetBytes(JsonUtility.ToJson(new PostCmd("time")));
Dictionary<string, string> m_headers = new Dictionary<string, string>() {
{ "Content-Type", "application/json" },
};

static bool s_haveSyncedClock = false;
static double s_timeOffsetSeconds = 0.0;
Expand Down
6 changes: 5 additions & 1 deletion Assets/HappyFunTimes/HappyFunTimesCore/Server/HFTSite.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,11 @@ public InformData(string[] _addresses, string _port)

string MakeDirectUrl(string address)
{
return rendezvousUri_.Scheme + "://" + address + ":" + rendezvousUri_.Port + rendezvousUri_.PathAndQuery;
if (address.Contains(":")) {
return rendezvousUri_.Scheme + "://[" + address + "]:" + rendezvousUri_.Port + rendezvousUri_.PathAndQuery;
} else {
return rendezvousUri_.Scheme + "://" + address + ":" + rendezvousUri_.Port + rendezvousUri_.PathAndQuery;
}
}

string[] GetIPAddresses(DNS.Protocol.RecordType type)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ private class MessageMove {
};

private class MessagePic {
public string dataUrl;
public string dataUrl = "";
}

void InitializeNetPlayer(SpawnInfo spawnInfo) {
Expand Down
Binary file modified ProjectSettings/ProjectSettings.asset
Binary file not shown.
3 changes: 2 additions & 1 deletion ProjectSettings/ProjectVersion.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
m_EditorVersion: 2018.2.15f1
m_EditorVersion: 2019.1.4f1
m_EditorVersionWithRevision: 2019.1.4f1 (ffa3a7a2dd7d)

0 comments on commit 97b7647

Please sign in to comment.