コード例 #1
0
    protected override void solveBasic(NwkMessageBasic message, int connID)
    {
        log("basic : " + message.getIdCard().toString(), message.isSilent());

        NwkMessageBasic bMessage;

        eNwkMessageType mtype = (eNwkMessageType)message.getIdCard().getMessageType();

        switch (mtype)
        {
        case eNwkMessageType.PING: // client sent ping

            //ref timestamp to solve timeout
            pingMessage(message.getIdCard().getMessageSender());

            //setup pong message
            bMessage = new NwkMessageBasic();
            bMessage.getIdCard().setMessageType(eNwkMessageType.PONG);

            //log("sending pong to " + connID + " , " + message.getIdCard().getMessageSender());

            //Send pong message
            sendWrapper.sendToSpecificClient(bMessage, connID);

            break;

        case eNwkMessageType.DISCONNECTION:

            getClientData(message.getIdCard().getMessageSender()).setAsDisconnected();

            //msg.clean();

            break;

        case eNwkMessageType.TICK:

            //send tick data

            log("sending tick data to " + connID);

            NwkMessageFull mf = new NwkMessageFull();
            mf.getIdCard().setupId(0, (int)eNwkMessageType.TICK);
            mf.bytes.setByteData(getModule <NwkTick>().data);

            sendWrapper.sendToSpecificClient(mf, connID);

            break;

        case eNwkMessageType.NONE: break;

        default: throw new NotImplementedException("base ; not implem " + mtype);
        }
    }
コード例 #2
0
    public void ping()
    {
        _pingTime = Time.realtimeSinceStartup;

        pingMessage.getIdCard().setMessageSender(NwkClient.nwkUid);
        _client.sendWrapperClient.sendClientToServer(pingMessage, false);

        //Debug.Log("ping ! " + _pingTime);
    }
コード例 #3
0
    protected override void setupModule()
    {
        base.setupModule();

        pingMessage = new NwkMessageBasic();
        pingMessage.getIdCard().setMessageType(eNwkMessageType.PING);

        pingTimer = pingItv;

        if (pingTimer <= 0f)
        {
            Debug.LogWarning("ping NOT active");
        }
    }
コード例 #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
    override protected void solveBasic(NwkMessageBasic message, int connID)
    {
        eNwkMessageType mtype = (eNwkMessageType)message.getIdCard().getMessageType();

        //log("basic ? " + message.getIdCard().toString());

        switch (mtype)
        {
        case eNwkMessageType.PONG: // received a pong, do something with it

            //inject pong delta
            getClientData(NwkClient.nwkUid).eventPing(getModule <NwkModPing>().pong());

            break;

        case eNwkMessageType.NONE: break;

        default: throw new NotImplementedException("basic not implem " + mtype);
        }
    }
コード例 #6
0
    void broadcastDisconnectionPing()
    {
        log("server -> broadcasting disconnection ping (clients " + clientDatas.Count + ")");

        //error
        if (clientDatas.Count == 0)
        {
            log("disconnection event but no clients recorded ?");
            return;
        }

        //send a disconnection transaction to everyone
        //server will start timeout-ing all clients
        //and will stop timeout-ing everyclients that answers
        NwkMessageBasic msg = new NwkMessageBasic();

        msg.getIdCard().setupId(0, (int)eNwkMessageType.SRV_DISCONNECTION_PING);

        sendWrapper.broadcastServerToAll(msg, 0);

        //after deconnection we wait for a signal JIC
        //for (int i = 0; i < clientDatas.Count; i++) clientDatas[i].startTimeout();
    }