Beispiel #1
0
 /// <summary>
 /// Called when the user press to logout
 /// todo: Move from here because login does not have this option only in the next scenes
 /// </summary>
 protected void Logout()
 {
     if (SocketController.IsConnected())
     {
         Debug.Log("Requesting to logout..");
         SocketController.Send(NetworkInstructions.LOGOUT_REQUEST, null);
     }
 }
Beispiel #2
0
 public bool Beat()
 {
     SocketController.Send(new Heartbeat());
     //Payload response = SocketController.Receive();
     //Console.WriteLine(response);
     return(true);
     //return response.Opcode == (int)Opcodes.HeartbeatACK;
 }
Beispiel #3
0
    /// <summary>
    /// Called when the server returns Login Success opcode
    /// </summary>
    /// <param name="netMsg"></param>
    protected void OnLoginSuccess(NetworkMessage netMsg)
    {
        UnityMainThreadDispatcher.Instance().Enqueue(() =>
        {
            LoginPanel.SetActive(false);
            if (GameObject.Find("LoadingBox") != null)
            {
                Destroy(GameObject.Find("LoadingBox"));
            }

            //Create a spinner
            var spin  = Instantiate(Resources.Load <GameObject>("Prefabs/Modals/LoadingBox"), UI.transform) as GameObject;
            spin.name = "LoadingBox";
            spin.transform.Find("Text").GetComponent <Text>().text = "Loading Profile..";

            //Read profileData
            var profileData = netMsg.ReadMessage <ProfileData>();


            //We make observer for WhenData arrives in order to define dynamiclly when loading or loaded is done
            spin.transform.Find("Text").GetComponent <Text>().text = "Loading Cards..";
            SocketController.Send(NetworkInstructions.PLAYER_CARDS_REQUEST, null);

            //Save the username and pwd if the remmeber is set true
            if (PlayerPrefs.GetInt("login_remmeber") == 1)
            {
                PlayerPrefs.SetString("login_username", usrField.text);
                PlayerPrefs.SetString("login_password", pwdField.text);
                Debug.Log("Remmeber saved");
            }

            //Unbind the login handlers since we're going to load the next scene
            SocketController.UnbindEvent(NetworkInstructions.LOGIN_FAIL);
            SocketController.UnbindEvent(NetworkInstructions.LOGIN_REQUEST);
            SocketController.UnbindEvent(NetworkInstructions.LOGIN_SUCCESS);

            //Wipe notifier list if it gives problems trying to notify here
            SocketController.UnbindEvent(NetworkInstructions.ServerOffline);

            //Load next scene
            SceneManager.LoadSceneAsync("MainMenu");
        });
    }
Beispiel #4
0
    /// <summary>
    /// Event for return key or submit button click
    /// </summary>
    public void SubmitValidation()
    {
        if (SocketController.IsConnected())
        {
            var p = new AuthData
            {
                username = usrField.text,
                password = pwdField.text
            };

            SocketController.Send(NetworkInstructions.LOGIN_REQUEST, p);

            LoginPanel.SetActive(false);

            var spin = Instantiate(Resources.Load <GameObject>("Prefabs/Modals/LoadingBox"), UI.transform) as GameObject;
            spin.name = "LoadingBox";
            spin.transform.Find("Text").GetComponent <Text>().text = "Authenticating..";
        }
        else
        {
            Debug.Log("Socket Controller has no instance or is not connected");
        }
    }
        /// <summary>
        /// 执行RMTP监测相关指令(监测指令和非监测指令)
        /// </summary>
        /// <param name="pCommand">命令类型</param>
        /// <param name="pParameter">命令携带参数</param>
        /// <param name="pPricode">是正在进行的控制的优先级代码,默认值:1</param>
        /// <param name="pChannelid">执行任务的设备通道号,默认值:0</param>
        /// <param name="pIsNewMeasureNumber">true - 生成新测量序号,false - 保持原测量序号</param>
        public void ExecuteCommand(RmtpCommand pCommand,
                                   object pParameter        = null,
                                   int pPricode             = 1,
                                   int pChannelid           = 0,
                                   bool pIsNewMeasureNumber = false)
        {
            if (_rmtpControler == null || !_rmtpControler.IsConnected)
            {
                AssistTool.WriteOutput(string.Format("Rmtp服务连接已断开,指令“{0}”无效", pCommand));
                return;
            }

            if (!_executeRmtpFun.ContainsKey(pCommand))
            {
                return;
            }

            var cmdMessageFrame = new CommandMessageFrame(pCommand);

            _executeRmtpFun[pCommand].CommandHandler(cmdMessageFrame, new[] { pParameter, pPricode, pChannelid });
            cmdMessageFrame.Header.ChannelId = pChannelid;

            _rmtpControler.Send(cmdMessageFrame);
        }
        public async Task <bool> Beat()
        {
            Payload response = await SocketController.Send(new Heartbeat());

            return(response.Opcode == (int)Opcodes.HeartbeatACK);
        }
Beispiel #7
0
 public void Send(string json)
 {
     SocketController.Send(json);
 }
Beispiel #8
0
 public async Task <Payload> Send(Payload payload)
 {
     return(await SocketController.Send(payload));
 }