コード例 #1
0
    void CreateWebSoket()
    {
        ws            = new WebSocket("ws://localhost:9010/game");
        ws.OnMessage += (s, e) =>
        {
            Debug.Log(string.Format("Response: {0}", e.Data));

            try
            {
                var br = JObject.Parse(e.Data);

                Debug.LogWarning("C: " + br["command"] + " S: " + br["sucess"] + ".");

                string command = br["command"].ToString();

                switch (command)
                {
                case "player/registration":
                    if (JsonConvert.DeserializeObject <RegistrationResponseDTO>(e.Data).Success)
                    {
                        LoginPanelsUI.SetState(LoginPanelsUI.State.Login);
                    }
                    break;

                case "player/authorization":

                    var authResponse = JsonConvert.DeserializeObject <AuthorizationResponseDTO>(e.Data);

                    Debug.LogWarning(authResponse.Success);

                    if (authResponse.Success)
                    {
                        token = authResponse.Payload.Token;
                        LoginPanelsUI.SetState(LoginPanelsUI.State.Dummy);

                        //TODO task manager. Below cannot be called from socket.
                        //PlayerData.Save();
                    }

                    break;

                default:
                    Debug.LogError("UNCNOWN C: " + br["command"]);
                    break;
                }
            }

            catch (Exception ex)

            {
                Debug.LogError(ex.ToString());
            }
        };
        ws.OnOpen += (s, e) =>
        {
            Debug.Log("Open WS");
        };
        ws.OnClose += (s, e) =>
        {
            Debug.Log("Close WS");
        };
        ws.Connect();
    }
コード例 #2
0
ファイル: LoginPanelsUI.cs プロジェクト: bzz86/Aurora
 void Awake()
 {
     instance = this;
 }