// It's our responsibility to create a GameObject with a TcpClient // and return it to the server. public tk.TcpClient OnClientConnected() { if (clientTemplateObj == null) { Debug.LogError("client template object was null."); return(null); } if (_server.debug) { Debug.Log("creating client obj"); } GameObject go = GameObject.Instantiate(clientTemplateObj) as GameObject; go.transform.parent = this.transform; if (spawn_pt != null) { go.transform.position = spawn_pt.position + UnityEngine.Random.insideUnitSphere * 2; } tk.TcpClient client = go.GetComponent <tk.TcpClient>(); InitClient(client); return(client); }
private void InitClient(tk.TcpClient client) { if (spawnCarswClients) { CarSpawner spawner = GameObject.FindObjectOfType <CarSpawner>(); if (spawner) { if (_server.debug) { Debug.Log("spawning car."); } spawner.Spawn(client.gameObject.GetComponent <tk.JsonTcpClient>()); } } else { //we are in the front end. tk.TcpMenuHandler handler = GameObject.FindObjectOfType <TcpMenuHandler>(); if (handler) { if (_server.debug) { Debug.Log("init menu handler."); } handler.Init(client.gameObject.GetComponent <tk.JsonTcpClient>()); } } }
void Awake() { recv_packets = new List <string>(); dispatcher = new tk.Dispatcher(); dispatcher.Init(); client = GetComponent <tk.TcpClient>(); Initcallbacks(); }
public void OnClientDisconnected(tk.TcpClient client) { CarSpawner spawner = GameObject.FindObjectOfType <CarSpawner>(); if (spawner) { spawner.RemoveCar(client.gameObject.GetComponent <tk.JsonTcpClient>()); } GameObject.Destroy(client.gameObject); }
private void InitClient(tk.TcpClient client) { if (privateAPI) // private API client server { PrivateAPI privateAPIHandler = GameObject.FindObjectOfType <PrivateAPI>(); if (privateAPIHandler != null) { if (_server.debug) { Debug.Log("init private API handler."); } privateAPIHandler.Init(client.gameObject.GetComponent <tk.JsonTcpClient>()); } } else // normal client server { if (spawnCarswClients) // we are on in a track scene { CarSpawner spawner = GameObject.FindObjectOfType <CarSpawner>(); if (spawner != null) { if (_server.debug) { Debug.Log("spawning car."); } spawner.Spawn(client.gameObject.GetComponent <tk.JsonTcpClient>(), false); } } else //we are in the menu { tk.TcpMenuHandler handler = GameObject.FindObjectOfType <TcpMenuHandler>(); if (handler != null) { if (_server.debug) { Debug.Log("init menu handler."); } handler.Init(client.gameObject.GetComponent <tk.JsonTcpClient>()); } } } }
private void InitClient(tk.TcpClient client) { //Is there a race manager active? RaceManager raceMan = GameObject.FindObjectOfType <RaceManager>(); if (raceMan != null) { if (_server.debug) { Debug.Log("client joined race."); } raceMan.OnClientJoined(client.gameObject.GetComponent <tk.JsonTcpClient>()); } else if (spawnCarswClients) { CarSpawner spawner = GameObject.FindObjectOfType <CarSpawner>(); if (spawner) { if (_server.debug) { Debug.Log("spawning car."); } spawner.Spawn(client.gameObject.GetComponent <tk.JsonTcpClient>()); } } else { //we are in the front end. tk.TcpMenuHandler handler = GameObject.FindObjectOfType <TcpMenuHandler>(); if (handler) { if (_server.debug) { Debug.Log("init menu handler."); } handler.Init(client.gameObject.GetComponent <tk.JsonTcpClient>()); } } }
public void OnClientDisconnected(tk.TcpClient client) { RaceManager raceMan = GameObject.FindObjectOfType <RaceManager>(); if (raceMan) { raceMan.OnClientDisconnected(client.gameObject.GetComponent <tk.JsonTcpClient>()); } else { CarSpawner spawner = GameObject.FindObjectOfType <CarSpawner>(); if (spawner) { spawner.RemoveCar(client.gameObject.GetComponent <tk.JsonTcpClient>()); } } GameObject.Destroy(client.gameObject); }
public void Awake() { _client = GetComponent <tk.TcpClient>(); _client.onDataRecvCB += new tk.TcpClient.OnDataRecv(OnRecvData); }
// Remove reference to TcpClient public void RemoveClient(TcpClient client) { clients.Remove(client); }