Exemplo n.º 1
0
    private IEnumerator ProcessExitFromRoom(UserRef user, string roomName)
    {
        try
        {
            var t1 = user.ExitFromRoom(roomName);
            yield return(t1.WaitHandle);

            if (t1.Status != TaskStatus.RanToCompletion)
            {
                UiMessageBox.Show("Exit room error:\n" + t1.Exception.ToString());
                yield break;
            }

            RoomItem item;
            if (_roomItemMap.TryGetValue(roomName, out item) == false)
            {
                yield break;
            }

            _roomItemMap.Remove(roomName);
            Destroy(item.ChatPanel.gameObject);
            G.Communicator.ObserverRegistry.Remove(item.Observer);
            ControlPanel.DeleteRoomItem(roomName);
            if (item.Channel != G.Communicator.Channels[0])
            {
                item.Channel.Close();
            }

            OnRoomItemClick("#general");
        }
        finally
        {
            _isBusy = false;
        }
    }
Exemplo n.º 2
0
 public void OnInputBoxClick()
 {
     UiInputBox.Show("Please input your name:", "Bill", callback: value =>
     {
         UiMessageBox.Show("Your name: " + (value ?? "Canceled"));
     });
 }
Exemplo n.º 3
0
 public void OnMessageQuestionBoxClick()
 {
     UiMessageBox.Show("This is a message question <b>box</b>", UiMessageBox.QuestionType.OkCancel, r =>
     {
         _logger.InfoFormat("MessageQuestionBox done with {0}", r);
     });
 }
Exemplo n.º 4
0
    private void StartLogin()
    {
        LoginPanel.gameObject.SetActive(false);
        LoadingPanel.gameObject.SetActive(false);
        MainPanel.gameObject.SetActive(false);

        if (G.User != null)
        {
            MainPanel.gameObject.SetActive(true);
        }
        else
        {
            if (G.Communicator != null)
            {
                UiMessageBox.Show("Connection Closed!");
                G.Communicator = null;
            }

            LoginPanel.gameObject.SetActive(true);

            var loginServer   = PlayerPrefs.GetString("LoginServer");
            var loginId       = PlayerPrefs.GetString("LoginId");
            var loginPassword = PlayerPrefs.GetString("LoginPassword");

            if (string.IsNullOrEmpty(loginId) == false)
            {
                ServerInput.text   = loginServer;
                IdInput.text       = loginId;
                PasswordInput.text = loginPassword;
            }
        }
    }
Exemplo n.º 5
0
 public void OnMessageBoxClick()
 {
     UiMessageBox.Show("This is a message <b>box</b>", _ =>
     {
         _logger.Info("MessageBox done");
     });
 }
Exemplo n.º 6
0
    private IEnumerator ProcessLoginAndJoinGame()
    {
        var loginServer   = PlayerPrefs.GetString("LoginServer");
        var loginId       = PlayerPrefs.GetString("LoginId");
        var loginPassword = PlayerPrefs.GetString("LoginPassword");

        // TEST
        loginServer   = "";
        loginId       = "editor";
        loginPassword = "******";

        if (string.IsNullOrEmpty(loginId))
        {
            UiMessageBox.Show("Cannot find id");
            yield break;
        }

        yield return(StartCoroutine(ProcessLoginUser(loginServer, loginId, loginPassword)));

        if (G.User == null)
        {
            UiMessageBox.Show("Failed to login");
            yield break;
        }

        yield return(StartCoroutine(ProcessJoinGame()));
    }
Exemplo n.º 7
0
    public void OnPlayButtonClick()
    {
        if (G.User == null)
        {
            UiMessageBox.Show("Login reqruied.");
            return;
        }

        SceneManager.LoadScene("GameScene");
    }
Exemplo n.º 8
0
    public void OnInfoButtonClick()
    {
        if (G.User == null)
        {
            UiMessageBox.Show("Login reqruied.");
            return;
        }

        UiManager.Instance.ShowModalRoot <UserInfoDialogBox>(
            new UserInfoDialogBox.Argument {
            UserContext = G.UserContext
        });
    }
Exemplo n.º 9
0
    public void OnLoginButtonClick()
    {
        var server   = ServerInput.text;
        var id       = IdInput.text;
        var password = PasswordInput.text;

        if (string.IsNullOrEmpty(id))
        {
            UiMessageBox.Show("ID is required.");
            return;
        }

        StartCoroutine(ProcessLoginUser(server, id, password));
    }
Exemplo n.º 10
0
    public void OnTestDialogBoxClick()
    {
        var handle = UiManager.Instance.ShowModalRoot <TestDialogBox>("Input your name?");

        handle.Hidden += (dlg, val) =>
        {
            if (val != null)
            {
                UiMessageBox.Show("Name: " + val);
            }
            else
            {
                UiMessageBox.Show("Canceled");
            }
        };
    }
Exemplo n.º 11
0
    private IEnumerator ShowMessageQuestionBoxCoroutine()
    {
        while (true)
        {
            var handle = UiMessageBox.Show("Do you want to continue?", UiMessageBox.QuestionType.ContinueStop);
            yield return(StartCoroutine(handle.WaitForHide()));

            _logger.Info(handle.ReturnValue);
            if ((UiMessageBox.QuestionResult)handle.ReturnValue == UiMessageBox.QuestionResult.Continue)
            {
                var handle2 = UiMessageBox.Show("Let's do it again");
                yield return(StartCoroutine(handle2.WaitForHide()));
            }
            else
            {
                UiMessageBox.Show("Done");
                yield break;
            }
        }
    }
Exemplo n.º 12
0
    private IEnumerator ProcessSelectRoomAndEnter()
    {
        try
        {
            var t1 = G.User.GetRoomList();
            yield return(t1.WaitHandle);

            if (t1.Exception != null)
            {
                UiMessageBox.Show("GetRoomList error:\n" + t1.Exception.Message);
                yield break;
            }

            var roomDialog = UiManager.Instance.ShowModalRoot <RoomDialog>(
                new RoomDialog.Argument
            {
                CurrentRoomName = _currentRoomName,
                RoomList        = t1.Result
            });
            yield return(StartCoroutine(roomDialog.WaitForHide()));

            if (roomDialog.ReturnValue == null)
            {
                yield break;
            }

            var roomName = (string)roomDialog.ReturnValue;
            if (_roomItemMap.ContainsKey(roomName))
            {
                OnRoomItemClick(roomName);
                yield break;
            }

            yield return(StartCoroutine(ProcessEnterRoom(G.User, roomName)));
        }
        finally
        {
            _isBusy = false;
        }
    }
Exemplo n.º 13
0
    private IEnumerator ProcessLoginUser(string server, string id, string password)
    {
        G.Logger.Info("ProcessLoginUser");

        IPEndPoint endPoint;

        try
        {
            endPoint = LoginProcessor.GetEndPointAddress(server);
        }
        catch (Exception e)
        {
            UiMessageBox.Show("Server EndPoint Error: " + e);
            yield break;
        }

        SwitchPanel(LoginPanel, LoadingPanel);

        var task = LoginProcessor.Login(this, endPoint, id, password, p => LoadingText.text = p + "...");

        yield return(task.WaitHandle);

        if (task.Status == TaskStatus.RanToCompletion)
        {
            SwitchPanel(LoadingPanel, MainPanel);

            PlayerPrefs.SetString("LoginServer", server);
            PlayerPrefs.SetString("LoginId", id);
            PlayerPrefs.SetString("LoginPassword", password);
        }
        else
        {
            UiMessageBox.Show(task.Exception.Message);
            SwitchPanel(LoadingPanel, LoginPanel);

            PlayerPrefs.DeleteKey("LoginServer");
            PlayerPrefs.DeleteKey("LoginId");
            PlayerPrefs.DeleteKey("LoginPassword");
        }
    }
Exemplo n.º 14
0
    private IEnumerator ProcessEnterRoom(UserRef user, string roomName)
    {
        // Spawn new room item

        var go        = UiHelper.AddChild(ContentPanel, ChatPanelTemplate);
        var chatPanel = go.GetComponent <ChatPanel>();

        // Try to enter the room

        var observer = G.Communicator.ObserverRegistry.Create <IRoomObserver>(chatPanel);

        observer.GetEventDispatcher().Pending      = true;
        observer.GetEventDispatcher().KeepingOrder = true;
        var t1 = user.EnterRoom(roomName, observer);

        yield return(t1.WaitHandle);

        if (t1.Status != TaskStatus.RanToCompletion)
        {
            G.Communicator.ObserverRegistry.Remove(observer);
            DestroyObject(go);
            UiMessageBox.Show("Enter room error:\n" + t1.Exception);
            yield break;
        }

        // Spawn new room item

        var occupant = (OccupantRef)t1.Result.Item1;

        if (occupant.IsChannelConnected() == false)
        {
            yield return(occupant.ConnectChannelAsync().WaitHandle);
        }
        chatPanel.SetOccupant(occupant);
        chatPanel.SetRoomInfo(t1.Result.Item2);
        chatPanel.ExitButtonClicked = () => OnRoomExitClick(roomName);

        var item = new RoomItem
        {
            ChatPanel = chatPanel,
            Occupant  = occupant,
            Observer  = (RoomObserver)observer,
            Channel   = (IChannel)occupant.RequestWaiter
        };

        _roomItemMap.Add(roomName, item);
        ControlPanel.AddRoomItem(roomName);
        observer.GetEventDispatcher().Pending = false;

        item.Channel.StateChanged += (_, state) =>
        {
            ChannelEventDispatcher.Post(o =>
            {
                if (state == ChannelStateType.Closed)
                {
                    if (_roomItemMap.ContainsKey(roomName))
                    {
                        OnRoomExitClick(roomName);
                    }
                }
            });
        };

        // Select

        OnRoomItemClick(roomName);
    }
Exemplo n.º 15
0
    private IEnumerator ProcessLogin(string server, ChannelType type, string id, string password)
    {
        try
        {
            IPEndPoint serverEndPoint;
            try
            {
                serverEndPoint = GetEndPointAddress(server);
            }
            catch (Exception e)
            {
                UiMessageBox.Show("Server address error:\n" + e.ToString());
                yield break;
            }

            var communicator = UnityCommunicatorFactory.Create();
            {
                var channelFactory = communicator.ChannelFactory;
                channelFactory.Type                = type;
                channelFactory.ConnectEndPoint     = serverEndPoint;
                channelFactory.CreateChannelLogger = () => LogManager.GetLogger("Channel");
                channelFactory.PacketSerializer    = PacketSerializer.CreatePacketSerializer <DomainProtobufSerializer>();
            }
            var channel = communicator.CreateChannel();

            // connect to gateway

            var t0 = channel.ConnectAsync();
            yield return(t0.WaitHandle);

            if (t0.Exception != null)
            {
                UiMessageBox.Show("Connect error:\n" + t0.Exception.Message);
                yield break;
            }

            // Try Login

            var userLogin = channel.CreateRef <UserLoginRef>();
            var observer  = communicator.ObserverRegistry.Create(_userEventObserver);
            var t1        = userLogin.Login(id, password, observer);
            yield return(t1.WaitHandle);

            if (t1.Exception != null)
            {
                communicator.ObserverRegistry.Remove(observer);
                var re = t1.Exception as ResultException;
                if (re != null)
                {
                    UiMessageBox.Show("Login error:\n" + re.ResultCode.ToString());
                }
                else
                {
                    UiMessageBox.Show("Login error:\n" + t1.Exception.ToString());
                }
                channel.Close();
                yield break;
            }

            var user = (UserRef)t1.Result;
            if (user.IsChannelConnected() == false)
            {
                var t2 = user.ConnectChannelAsync();
                yield return(t2.WaitHandle);

                if (t2.Exception != null)
                {
                    UiMessageBox.Show("ConnectToUser error:\n" + t2.Exception.ToString());
                    channel.Close();
                    yield break;
                }
                channel.Close();
            }

            G.Communicator = communicator;
            G.User         = user;
            G.UserId       = id;
            Hide(id);
        }
        finally
        {
            _isLoginBusy = false;
        }
    }
Exemplo n.º 16
0
    private IEnumerator ProcessJoinGameInternal()
    {
        G.Logger.Info("ProcessJoinGame");

        // Finding Game
        // Register user to pairing queue and waiting for 5 secs.

        LoadingText.text = "Finding Game...";

        _pairedGame = null;

        var pairingObserver = G.Communicator.ObserverRegistry.Create <IUserPairingObserver>(this);

        yield return(G.User.RegisterPairing(pairingObserver).WaitHandle);

        var startTime = DateTime.Now;

        while ((DateTime.Now - startTime).TotalSeconds < 5 && _pairedGame == null && _isLeaveRequested == false)
        {
            yield return(null);
        }

        G.Communicator.ObserverRegistry.Remove(pairingObserver);

        if (_isLeaveRequested)
        {
            yield break;
        }

        if (_pairedGame == null)
        {
            yield return(G.User.UnregisterPairing().WaitHandle);

            if (_isLeaveRequested == false)
            {
                yield return(UiMessageBox.Show("Cannot find game").WaitForHide());
            }
            SceneManager.LoadScene("MainScene");
            yield break;
        }

        // Join Game

        var gameObserver = G.Communicator.ObserverRegistry.Create <IGameObserver>(this, startPending: true);

        gameObserver.GetEventDispatcher().KeepingOrder = true;

        var roomId  = _pairedGame.Item1;
        var joinRet = G.User.JoinGame(roomId, gameObserver);

        yield return(joinRet.WaitHandle);

        if (joinRet.Exception != null)
        {
            G.Communicator.ObserverRegistry.Remove(gameObserver);
            var box = UiMessageBox.Show("Failed to join\n" + joinRet.Exception);
            yield return(StartCoroutine(box.WaitForHide()));

            SceneManager.LoadScene("MainScene");
        }

        _gameObserver = gameObserver;
        _gameInfo     = joinRet.Result.Item3;
        _myPlayerId   = joinRet.Result.Item2;
        _myPlayer     = (GamePlayerRef)joinRet.Result.Item1;

        if (_myPlayer.IsChannelConnected() == false)
        {
            var connectTask = _myPlayer.ConnectChannelAsync();
            yield return(connectTask.WaitHandle);

            if (connectTask.Exception != null)
            {
                var box = UiMessageBox.Show("Failed to connect\n" + joinRet.Exception);
                G.Communicator.ObserverRegistry.Remove(gameObserver);
                yield return(StartCoroutine(box.WaitForHide()));

                _myPlayer = null;
                yield break;
            }
            ((IChannel)_myPlayer.RequestWaiter).StateChanged += (_, state) =>
            {
                if (state == ChannelStateType.Closed)
                {
                    ChannelEventDispatcher.Post(OnChannelClose, _);
                }
            };
        }

        gameObserver.GetEventDispatcher().Pending = false;
        LoadingText.text = "Waiting for " + _pairedGame.Item2 + "...";
    }