Exemple #1
0
    // Update is called once per frame
    void Update()
    {
        if (loginSuccessfully)
        {
            return;
        }
        networkHost.ReceiveData();
        while (networkHost.receiveMessages.Count > 0)
        {
            ServerMsg serverMessage = networkHost.receiveMessages.Dequeue();
            Debug.Log("receive server msg type: " + Convert.ToString(serverMessage.msgType, 16));

            if (serverMessage.msgType == NetworkSettings.SERVER_FEEDBACK)
            {
                switch (((ServerFeedbackMsg)serverMessage).code)
                {
                case NetworkSettings.COMMAND_LOGIN_SUCCESSFUL:
                    loginSuccessfully = true;
                    Debug.Log("jump to gamescene");
                    SceneManager.LoadScene("Halloween_Level");
                    break;

                case NetworkSettings.COMMAND_SEND_CLIENTID:
                    Debug.Log(Convert.ToString(((ServerClientIDMsg)serverMessage).clientID));
                    GameSettings.clientID = ((ServerClientIDMsg)serverMessage).clientID;
                    break;

                case NetworkSettings.COMMAND_REGISTER_SUCCESSFUL:
                    tips.text = "[Accept] Register Successfully!";
                    break;

                case NetworkSettings.COMMAND_WRONG_PASSWORD:
                    tips.text = "[Wrong] Wrong Password!";
                    break;

                case NetworkSettings.COMMAND_NAME_ALREADY_EXISTS:
                    tips.text = "[Wrong] This Name Already Exist!";
                    break;

                case NetworkSettings.COMMAND_DATABASE_ERROR:
                    tips.text = "[Wrong] Database Wrong in Server";
                    break;

                case NetworkSettings.COMMAND_LOGIN_ALREADY:
                    tips.text = "[Wrong] User Login Already!";
                    break;
                }
            }
        }
    }
Exemple #2
0
    // Update is called once per frame
    void Update()
    {
        // fisrt register a player entity at server
        if (!playerEneityRegistered && networkHost.connected)
        {
            SendPlayerEntityRegisterMsg();
            playerEneityRegistered = true;
        }

        // sync the player location to server
        if (networkHost.connected && timer >= NetworkSettings.SERVER_SYNC_INTERVAL)
        {
            if (!GameSettings.gameOver)
            {
                SendPlayerEntitySyncMsg();
            }
            timer -= NetworkSettings.SERVER_SYNC_INTERVAL;
        }
        else
        {
            timer += Time.deltaTime;
        }

        // receive data to message queue
        networkHost.ReceiveData();
        while (networkHost.receiveMessages.Count > 0)
        {
            ServerMsg serverMessage = networkHost.receiveMessages.Dequeue();
            HandleServerMsg(serverMessage);
        }

        // change gameobject's position
        ChangeServerGameObjectPosotion(Time.deltaTime);

        if (GameSettings.gameOver && PlayerInput.GetR())
        {
            SendRestartMsg();
            InitPlayerData();
            SceneManager.LoadScene("Login Scene");
        }
    }