예제 #1
0
    public void onConnectButtonPressed()
    {
        if (NwkSystemBase.isServer())
        {
            NwkServer.nwkServer.disconnect();
        }

        if (!NwkClient.isClient())
        {
            Debug.LogWarning("not on client ? can't react to that button");
            return;
        }

        bool clientConnection = NwkClient.nwkClient.isConnected();

        NwkClient.nwkClient.log("clicked : " + btnConnect.GetComponentInChildren <Text>().text + " / is connected ? " + clientConnection);

        if (clientConnection)
        {
            NwkClient.nwkClient.disconnect();
        }
        else
        {
            NwkClient.nwkClient.connectToIpPort(); // ui view button connect
        }
    }
예제 #2
0
    public void setConnected(bool connected)
    {
        stConnection.color = connected ? Color.green : Color.red;

        if (!btnConnect.gameObject.activeSelf)
        {
            btnConnect.gameObject.SetActive(true);
        }

        Text label = btnConnect.GetComponentInChildren <Text>();

        if (label != null)
        {
            if (NwkSystemBase.isServer())
            {
                label.text = connected ? "Shutdown" : "Boot";
            }
            else
            {
                label.text = connected ? "Disconnect" : "Connect";
            }
        }

        //show();
    }
예제 #3
0
    void Update()
    {
        //can update if nwksys is present
        bool allowUpdate = canUpdate();

        //kill visual if can't update
        float targetAlpha = allowUpdate ? 1f : 0f;

        if (groupData.alpha != targetAlpha)
        {
            groupData.alpha = targetAlpha;
        }

        if (!allowUpdate)
        {
            return;
        }

        bool _server = NwkSystemBase.isServer();

        List <NwkClientData> datas = NwkSystemBase.nwkSys.clientDatas;

        string ct = "clients x" + datas.Count;

        for (int i = 0; i < datas.Count; i++)
        {
            //datas[i].update(); // update size timer

            //STATE
            ct += "\n #" + datas[i].nwkUid + "\t(" + datas[i].state + ")";

            if (datas[i].isDisconnected())
            {
                continue;
            }

            //PING

            // ping display (client = ping ; server = timeout)
            ct += "\n ping " + datas[i].getPingDelta();

            //SIZE

            if (_server)
            {
                ct += "\n size " + datas[i].sizeSeconds;
            }
        }

        txtClients.text = ct;
    }
예제 #4
0
    public void resetTickCount()
    {
        data.tick          = 0;
        data.tickRateTimer = -1f;

        if (NwkSystemBase.isClient())
        {
            Debug.Log("client is connected, asking to server for tick data");

            NwkMessageBasic mb = new NwkMessageBasic();
            mb.getIdCard().setupId(NwkClient.nwkUid, (int)eNwkMessageType.TICK);
            NwkClient.nwkClient.sendWrapperClient.sendClientToServer(mb);
        }

        if (NwkSystemBase.isServer())
        {
            data.tickRateTimer = 0f; // starts counting
        }
    }
예제 #5
0
    public int getPingDelta()
    {
        if (state == ClientState.DISCONNECTED)
        {
            return(-1);
        }

        float output = ping; // default is client ping

        if (NwkSystemBase.isServer())
        {
            if (output <= 0f)
            {
                output = Time.realtimeSinceStartup;
            }
            output = Time.realtimeSinceStartup - output; // server is last seen time
        }

        //return NwkModPing.getMilliSec(output);
        return(Mathf.FloorToInt(output)); // ms
    }