Exemple #1
0
        public void Connect(string _username)
        {
            Connection = new HubConnection(BASE_URL, new Dictionary <string, string>
            {
                { "username", _username }
            });

            Proxy = Connection.CreateHubProxy("ChatHub");

            Proxy.On <string, string>("GetMessage", (username, message) =>
            {
                OnGetMessage?.Invoke(username, message);
            });

            Proxy.On <string>("GetMe", (message) =>
            {
                OnGetMyMessage?.Invoke(message);
            });


            Proxy.On <string>("GetInfo", (info) =>
            {
                OnGetInfo?.Invoke(info);
            });

            Start().ContinueWith(task =>
            {
                if (task.IsFaulted)
                {
                    ConnectionErrorOcurned?.Invoke();
                }
            });
        }
    //Message Handlers
    protected virtual string HandleGetInfo(string Data)
    {
        string result =
            "<CONTROL>" +
            "  <NAME>" + Name + "</NAME>" +
            "  <VERSION>" + Version + "</VERSION>" +
            "  <DEVELOPERID>" + DeveloperID + "</DEVELOPERID>" +
            "  <CUSTOMIZATIONID>" + CustomizationID + "</CUSTOMIZATIONID>" +
            "</CONTROL>";
        var XDoc = new XmlDocument();

        XDoc.LoadXml(Data);

        XmlNode root = XDoc.FirstChild;

        foreach (XmlNode nextNode in root.ChildNodes)
        {
            if (nextNode.Name == "PROXYSID")
            {
                proxySID = nextNode.InnerText;
                break;
            }
        }

        OnGetInfo?.Invoke();
        return(result);
    }
Exemple #3
0
    public bool HandleMessage(IMessage message)
    {
        var response = message as Response;

        switch (response.ReturnCode)
        {
        case (int)ReturnCode.OK:
        {
            Loading.Load(LoadingScene.Login);
            OnGetInfo?.Invoke("Register success.");
            return(true);
        }

        case (int)ReturnCode.OperationInvalid:
        case (int)ReturnCode.AlreadyExist:
        {
            OnGetInfo?.Invoke(response.DebugMessage);
            return(true);
        }

        default:
        {
            OnGetInfo?.Invoke("OperationDenied.");
            Debug.LogFormat("OperationDenied. DebugMessage = {0}", response.DebugMessage);
            return(true);
        }
        }
    }
Exemple #4
0
        public void SendUserInfoRequest(string id, OnGetInfo onGetInfo)
        {
            if (m_mock)
            {
#if DEBUG_LOG
                Debug.Log("Mocking user. Auto logging in with random ID (or forced ID provided if any)");
#endif // DEBUG_LOG
                string _id   = m_forceUserID.Length > 0 ? m_forceUserID : System.Guid.NewGuid().ToString();
                string _user = m_forceUserName.Length > 0 ? m_forceUserName : "******";
                onGetInfo(new UserInfo(_id, _user, "*****@*****.**", "00-00-0001"));
                return;
            }
#if DEBUG_LOG
            Debug.Log("Requesting user info from " + id);
#endif // DEBUG_LOG

            m_userRequests.Enqueue(new UserInfoRequest()
            {
                ID = id, Callback = onGetInfo
            });

            if (!m_readyForNextRequest)
            {
                return;
            }

            m_readyForNextRequest = false;
            SendUserInfoRequest(id);
        }
    public bool HandleMessage(IMessage message)
    {
        var response = message as Response;

        switch (response.ReturnCode)
        {
        case (int)ReturnCode.OK:
        {
            // Set all user parameters
            Loading.Load(LoadingScene.Game);
            OnGetInfo?.Invoke("Login success.");
            return(true);
        }

        case (int)ReturnCode.OperationInvalid:
        case (int)ReturnCode.LoginOrPasswordIncorrect:
        {
            OnGetInfo?.Invoke(response.DebugMessage);
            return(true);
        }

        default:
        {
            OnGetInfo?.Invoke("OperationDenied.");
            Debug.LogFormat("OperationDenied. DebugMessage = {0}", response.DebugMessage);
            return(true);
        }
        }
    }