示例#1
0
    // 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>());
            }
        }
    }
示例#3
0
        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);
    }
示例#5
0
    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>());
                }
            }
        }
    }
示例#6
0
    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>());
            }
        }
    }
示例#7
0
    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);
 }
示例#9
0
 // Remove reference to TcpClient
 public void RemoveClient(TcpClient client)
 {
     clients.Remove(client);
 }