Esempio n. 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
        }
    }
Esempio n. 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();
    }
Esempio n. 3
0
    virtual protected void setup()
    {
        NwkSystemBase nwkCtx = NwkSystemBase.nwkSys;

        nwkClient = nwkCtx as NwkClient;
        nwkServer = nwkCtx as NwkServer;

        enabled = true;
    }
Esempio n. 4
0
    //NwkServer _server;

    protected override void setup()
    {
        base.setup();

        //if(GameObject.FindObjectOfType<NwkSyncer>() == null) log("<color=red>no syncer</color> ; can't sync stuff");

        owner = GameObject.FindObjectOfType <NwkSystemBase>();
        Debug.Assert(owner != null, "no nwk system ?");

        setupModule();
    }
Esempio n. 5
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;
    }
Esempio n. 6
0
    //protected NwkUiViewLogs nvLogs;

    virtual protected void Awake()
    {
        nwkSys = this;

        tick = getModule <NwkTick>();

        //sendWrapper = generateSendWrapper();

        listener = NwkMessageListener.getListener();
        if (listener == null)
        {
            listener = gameObject.AddComponent <NwkMessageListener>();
        }
    }
Esempio n. 7
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
        }
    }
Esempio n. 8
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
    }