Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,650 changes: 1,650 additions & 0 deletions TheGameOR/Assets/Canvas.prefab

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions TheGameOR/Assets/Canvas.prefab.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

221 changes: 221 additions & 0 deletions TheGameOR/Assets/ConnectToNoble.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,221 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

using NobleConnect.Mirror;
using Mirror;
using UnityEngine.Networking;

public class ConnectToNoble : MonoBehaviour
{

NobleNetworkManager networkManager;

public Text status;

public InputField nfcID;

public InputField nfcIDToJoin;

public GameObject disconnectButton;

public static ConnectToNoble instance;

public string ip, port;

// Used to determine which GUI to display
bool isHost, isClient;

bool connected;

public void Start()
{

nfcID.text = DDL.playerID;
instance = this;
// Cast from Unity's NetworkManager to a NobleNetworkManager.
networkManager = (NobleNetworkManager)NetworkManager.singleton;
}


public void startHost()
{
connected = false;
isHost = true;
isClient = false;

networkManager.StartHost();


}

public void startClient()
{
//if no adress given, then get it
StartCoroutine(IE_startClientFromDB(nfcIDToJoin.text));

}

public void startClient(string id)
{

StartCoroutine(IE_startClientFromDB(id));

}


IEnumerator IE_startClientFromDB(string idToJoin)
{
//Get ip and port from database (do this with webrequest)
WWWForm form = new WWWForm();

form.AddField("playerID", idToJoin);

UnityWebRequest uwr = UnityWebRequest.Post("https://thegameor.000webhostapp.com/get.php", form);

yield return uwr.SendWebRequest();
string dataText = uwr.downloadHandler.text;

if (dataText[0].Equals('0'))
{

//if it worked, then startclient with data:

Debug.Log(dataText);

string[] splitData = dataText.Remove(0, 1).Split(':'); //array with ip on 0 and port on 1

print(splitData[0] + " " + splitData[1]);

startClient(splitData[0], ushort.Parse(splitData[1]));
}
else
{
print("ERROR: " + dataText);
}
}


IEnumerator sendAdressToDB(string givenIp, string givenPort)
{

WWWForm form = new WWWForm();

form.AddField("playerID", nfcID.text);
form.AddField("ip", givenIp);
form.AddField("port", givenPort);

UnityWebRequest uwr = UnityWebRequest.Post("https://thegameor.000webhostapp.com/set.php", form);

yield return uwr.SendWebRequest();
string dataText = uwr.downloadHandler.text;

if (dataText[0].Equals('0'))
{

//if it worked, then startclient with data:

Debug.Log("worked");


}
else
{
print("ERROR: " + dataText);
Disconnect();
}
}

public void startClient(string givenIp, int givenPort)
{
//Initialize client
networkManager.InitClient();
isHost = false;
isClient = true;



//set the ip and port in the network manager
networkManager.networkAddress = givenIp;
networkManager.networkPort = givenPort;


//start client
networkManager.StartClient();
}

private void Update()
{
disconnectButton.SetActive(true);
if (isHost)
{
//Host stuff
if (networkManager.HostEndPoint != null)
{
ip = networkManager.HostEndPoint.Address.ToString();
port = networkManager.HostEndPoint.Port.ToString();
status.text = "Connected :D - ip: " + ip + ":" + port;

if (!connected)
{
connected = true;
if (nfcID.text.Equals("")) nfcID.text = DDL.playerID;
StartCoroutine(sendAdressToDB(ip, port));

}
}



if (!NobleServer.active) isHost = false;

}
else if (isClient && networkManager.client != null)
{
//Client stuff




}
else
{
disconnectButton.SetActive(false);
}


}

public void Disconnect()
{
if (isHost)
{
networkManager.StopHost();
isHost = false;
}else if (isClient)
{
if (networkManager.client.isConnected)
{
// If we are already connected it is best to quit gracefully by sending
// a disconnect message to the host.
networkManager.client.Disconnect();
}
else
{
// If the connection is still in progress StopClient will cancel it
networkManager.StopClient();
}
isClient = false;
}
}









}
11 changes: 11 additions & 0 deletions TheGameOR/Assets/ConnectToNoble.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 34 additions & 0 deletions TheGameOR/Assets/DDL.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class DDL : MonoBehaviour
{



public static string playerID;


private void Awake()
{
PlayerPrefs.GetString("playerID", "");

DontDestroyOnLoad(this.gameObject);
}

public void resetPlayerID()
{

PlayerPrefs.DeleteKey("playerID");
playerID = "";
}

public static void setPlayerID(string pID)
{
DDL.playerID= pID;
PlayerPrefs.SetString("playerID", pID);
}


}
11 changes: 11 additions & 0 deletions TheGameOR/Assets/DDL.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions TheGameOR/Assets/GM.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
public class GM : NetworkBehaviour
{



public GameObject redWin, blueWin;

[SyncVar]
Expand All @@ -31,6 +33,8 @@ void Start()
instance = this;
}



// Update is called once per frame
void Update()
{
Expand Down
Loading