Exemplo n.º 1
0
    public IEnumerator RequestHeartbeat(float time)
    {
        yield return(new WaitForSeconds(time));

        if (cManager)
        {
            RequestHeartbeat request = new RequestHeartbeat();
            request.send();
            cManager.send(request);
        }

        StartCoroutine(RequestHeartbeat(time));
    }
Exemplo n.º 2
0
    public IEnumerator RequestHeartbeat(float time)
    {
        Debug.Log("In Coroutine");
        cManager = gameObject.GetComponent <ConnectionManager>();


        RequestHeartbeat request = new RequestHeartbeat();

        request.send();

        cManager.send(request);

        yield return(new WaitForSeconds(time));
        //StartCoroutine(RequestHeartbeat(1f));
    }
Exemplo n.º 3
0
    // Update is called once per frame
    public IEnumerator RequestHeartbeat(float time)
    {
        yield return(new WaitForSeconds(time));

        ConnectionManager cManager = gameObject.GetComponent <ConnectionManager>();

        if (cManager)
        {
            RequestHeartbeat request = new RequestHeartbeat();
            request.send();

            cManager.send(request);
        }

        StartCoroutine(RequestHeartbeat(1f));
    }
Exemplo n.º 4
0
    public IEnumerator RequestHeartbeat(float time)
    {
        yield return(new WaitForSeconds(time));

        ConnectionManager cManager = gameObject.GetComponent <ConnectionManager>();

        if (cManager)
        {
            RequestHeartbeat request = new RequestHeartbeat(); //create new request, which contians Constants.CMSG_HEARTBEAT as request_id
            request.send();                                    //put it to a Gamepacket

            cManager.send(request);                            // put it in byte[] and send to server.
        }

        StartCoroutine(RequestHeartbeat(1f));
    }
    public IEnumerator UpdateLoop(float updateDelay)
    {
        yield return(new WaitForSeconds(updateDelay));

        if (cManager)
        {
            switch (gameState)
            {
            case GameState.LOBBY:
                RequestKeepAlive keepAlive = new RequestKeepAlive();
                keepAlive.send();
                cManager.send(keepAlive);
                break;

            case GameState.LOADING_GAME:
                while (SceneManager.GetActiveScene().name != "Sandbox")
                {
                    yield return(null);
                }

                gameState = GameState.INGAME;
                RequestPushUpdate.init();
                ResponseHeartbeat.init();

                break;

            case GameState.INGAME:
                //Create the two request objects that will be sent to the server
                RequestHeartbeat  heartbeat  = (RequestHeartbeat)NetworkRequestTable.get(Constants.CMSG_HEARTBEAT);
                RequestPushUpdate pushUpdate = (RequestPushUpdate)NetworkRequestTable.get(Constants.CMSG_PUSHUPDATE);

                //Create the messages to be sent
                heartbeat.send();
                pushUpdate.send();

                //Send the messages
                cManager.send(heartbeat);
                cManager.send(pushUpdate);
                break;

            default:
                break;
            }
        }
        StartCoroutine(UpdateLoop(updateDelay));
    }
Exemplo n.º 6
0
    public IEnumerator UpdateLoop(float updateDelay)
    {
        yield return(new WaitForSeconds(updateDelay));

        if (cManager)
        {
            switch (gameState)
            {
            case GameState.LOBBY:
            // will have specific request to keep it live at this point
            // but doesn't yet...
            // todo: add getLobbies code when lobbies are implemented
            // break;
            case GameState.LOGIN:
            case GameState.MAIN_MENU:
                if (lastState == GameState.GAME)
                {
                    sceneController.FadeAndLoadScene("Main_Menu");                                  // reload menu after a game;
                }
                RequestKeepAlive keepAlive = new RequestKeepAlive();
                keepAlive.send();
                cManager.send(keepAlive);
                break;

            case GameState.GAME:
                if (lastState == GameState.MAIN_MENU)
                {
                    sceneController.FadeAndLoadScene("Game_Scene");

                    while (SceneManager.GetActiveScene().name != "Game_Scene")
                    {
                        yield return(null);
                    }

                    Constants.loadSceneAConstants();

                    setCharacterValues();

                    Debug.Log("Joined Game");
                }

                //Create the two request objects that will be sent to the server
                RequestHeartbeat  heartbeat  = (RequestHeartbeat)NetworkRequestTable.get(Constants.CMSG_HEARTBEAT);
                RequestPushUpdate pushUpdate = (RequestPushUpdate)NetworkRequestTable.get(Constants.CMSG_PUSHUPDATE);

                //Create the messages to be sent
                heartbeat.send();
                pushUpdate.send();

                //Send the messages
                cManager.send(heartbeat);
                cManager.send(pushUpdate);

                break;

            default:
                break;
            }

            lastState = gameState;
        }
        StartCoroutine(UpdateLoop(updateDelay));
    }