124 lines
3.3 KiB
C#
124 lines
3.3 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using LightReflectiveMirror;
|
|
using TMPro;
|
|
using UnityEngine.UI;
|
|
using System;
|
|
using Mirror;
|
|
using UnityEngine.SceneManagement;
|
|
using System.Threading.Tasks;
|
|
|
|
public class MatchMaker : MonoBehaviour
|
|
{
|
|
public TMP_Text timerTxt;
|
|
public Button btn_cancel;
|
|
float timer;
|
|
void Start()
|
|
{
|
|
if(!DBmanager.LoggedIn){
|
|
SceneManager.LoadScene(0);
|
|
}
|
|
btn_cancel.onClick.AddListener(Cancel);
|
|
|
|
// StartCoroutine(StartMatchmaking());
|
|
}
|
|
|
|
private void OnClientConnected()
|
|
{
|
|
Debug.Log("Hey look someone connected!");
|
|
}
|
|
|
|
// Update is called once per frame
|
|
float t=0;
|
|
float connectTimeout = 0;
|
|
bool loadedScene;
|
|
void Update()
|
|
{
|
|
timer+=Time.deltaTime;
|
|
timerTxt.text = SceneData.SecondsToText(timer);
|
|
|
|
if(t < 1){
|
|
t += Time.deltaTime;
|
|
}else{
|
|
t=0;
|
|
StartCoroutine(FetchMatchmake());
|
|
}
|
|
}
|
|
|
|
IEnumerator FetchMatchmake(){
|
|
|
|
WWWForm form = new WWWForm();
|
|
form.AddField("name", DBmanager.username);
|
|
form.AddField("region", RegionManager.selectedServer.name);
|
|
|
|
WWW req = new WWW(DBmanager.phpRoot+"matchmake.php", form);
|
|
yield return req;
|
|
Debug.Log(req.text);
|
|
// if(req.text.Contains(DBmanager.username) && !loadedScene){
|
|
// int port
|
|
// //Room created!
|
|
// // isServer= req.text.Substring(0,DBmanager.username.Length) == DBmanager.username;
|
|
// // serverName=req.text;
|
|
// // AutoConnect.serverName = serverName;
|
|
// // AutoConnect.isRankedServer = isServer;
|
|
// // AutoConnect.isRanked = true;
|
|
// Debug.Log($"Room created! [{req.text}] am I the server? : ");
|
|
|
|
// LoadingScreen.instance.LoadLevel("MinigameRanked");
|
|
|
|
// }else{
|
|
// //Waiting
|
|
// }
|
|
|
|
try{
|
|
int port = int.Parse(req.text);
|
|
if(port > 5000){
|
|
Debug.Log("Got the port, Lets go!");
|
|
AutoConnect.serverPort = port;
|
|
LoadingScreen.instance.LoadLevel("MinigameRanked");
|
|
}
|
|
}catch{
|
|
|
|
}
|
|
}
|
|
|
|
// IEnumerator StartMatchmaking(){
|
|
// StartCoroutine(StartLooking());
|
|
|
|
// yield return new WaitForSeconds(1);
|
|
|
|
|
|
// lrm.serverName=DBmanager.username;
|
|
// NetworkManager.singleton.StartHost();
|
|
|
|
// }
|
|
// bool foundServer =false;
|
|
// IEnumerator StartLooking(){
|
|
// int counter =0;
|
|
// while(counter < 3){
|
|
// yield return new WaitForSeconds(1);
|
|
// lrm.RequestServerList();
|
|
// // counter++;
|
|
// }
|
|
// }
|
|
|
|
// void OnServerListUpdated(){
|
|
// Debug.Log("Found " + lrm.relayServerList.Count + " Servers");
|
|
// foreach(Room room in lrm.relayServerList){
|
|
// Debug.Log(room.serverName);
|
|
// if(!foundServer && room.serverName.Length>0 && room.serverName != DBmanager.username){
|
|
// foundServer=true;
|
|
// NetworkManager.singleton.networkAddress = room.serverName;
|
|
// NetworkManager.singleton.StartClient();
|
|
// }
|
|
// }
|
|
// }
|
|
|
|
void Cancel(){
|
|
LoadingScreen.instance.LoadLevel("GameScene");
|
|
}
|
|
|
|
|
|
}
|