Example #1
0
    void Start()
    {
        DataPasser.Get().Set("repeat", "false");
        logout.onClick.Add(new EventDelegate(new EventDelegate.Callback(
                                                 delegate
        {
            buttonSound.Play();
            CloseWidget();
            Application.LoadLevel(0);
        }
                                                 )));



        Deliver();
        if (DataPasser.Get().dic.ContainsKey("tai"))
        {
            tai = (Server.TokenAndId)DataPasser.Get().Get("tai");
        }
        else
        {
            tai = Server.Authorize("einhorn", "795132486");
        }

        SetSetingsPart();

        UnityEngine.Debug.Log("Start lobby");
        Set(tai);
    }
Example #2
0
            public GetPictureSocketThreadedJob(Server.TokenAndId tai, int serverIndex, int pictureId) : base(SocketManager.PICTURE_SERVERS[serverIndex], null)
            {
                this.callback = MessageCallback;
                string str = "get id=" + tai.id + ";token=" + tai.token + ";picture_id=" + pictureId;

                Write(str);
            }
Example #3
0
            public SetPictureSocketThreadedJob(Server.TokenAndId tai, int serverIndex, string content, bool isLarge)
                : base(SocketManager.PICTURE_SERVERS[serverIndex], null)
            {
                this.isLarge     = isLarge;
                this.serverIndex = serverIndex;
                this.callback    = MessageCallback;
                this.tai         = tai;
                StringBuilder chunk = new StringBuilder();
                int           index = 0;

                for (int i = 0; i < content.Length; i++)
                {
                    if (chunk.Length < SocketManager.CHUNK_SIZE)
                    {
                        chunk.Append(content[i]);
                    }

                    if (chunk.Length == SocketManager.CHUNK_SIZE || i == content.Length - 1)
                    {
                        string str = "chunk id=" + tai.id + ";token=" + tai.token + ";index=" + index + ";chunk=" + chunk;
                        Write(str);
                        index++;
                        chunk = new StringBuilder();
                    }
                }
                Write("end id=" + tai.id + ";token=" + tai.token + ";server_index=" + serverIndex);
            }
Example #4
0
 public void InitGameWidgetPart()
 {
     board = b;
     if (!isTest)
     {
         Server.TokenAndId tai = (Server.TokenAndId)DataPasser.Get().Get("tai");
         Game    game          = (Game)DataPasser.Get().Get("game");
         Boolean isObserver    = (Boolean)DataPasser.Get().Get("is_observer");
         SetGameWidgetPart(tai, game);
     }
     else
     {
         Server.TokenAndId tai = Server.Authorize("!!FB!!103018196855905", "uskjlrvkovscfzzwbtsr");
         lw = new LobbyWidget(tai);
         LobbyBackendWidget backgroud = new LobbyBackendWidget(tai);
         backgroud.Controls.timer = new CrazyGoTimerControl(1000, lobbyTimer);
         lw.Controls.backgroud    = backgroud;
         lw.Callbacks.goToGameAsPlayerCallback = delegate(Game g)
         {
             lw.Discard();
             Debug.Log("Go to game as player");
             SetGameWidgetPart(tai, g);
         };
         lw.Go();
         lw.Controls.backgroud.OpenForRandomChallenge("hidden-move-go", "board_size-19|komi-7.5|first_player-0|randomize-1|hm_count-7|time-b3600#60#5");
     }
 }
        public GameSocketThreadedJob(Server.TokenAndId tai, Game game)
            : base(SocketManager.GAME_SERVERS[game.server], null)
        {
            this.game        = game;
            this.tai         = tai;
            this.timers      = new int[game.max];
            this.permissions = new bool[game.max];
            this.callback    = MessageCallback;
            int index = GetIndex();

            if (index != -1)
            {
                string sss = "authorize id=" + tai.id + ";token=" + tai.token + ";game_id=" + game.id + ";index=" + index;
                this.Write(sss);
            }
            else
            {
                string sss = "observe id=" + tai.id + ";token=" + tai.token + ";game_id=" + game.id;
                this.Write(sss);
            }

            if (index == 0)
            {
                string ssss = "initialize id=" + tai.id + ";token=" + tai.token + ";game_id=" + game.id + ";title=" + game.title + ";settings=" + game.settings + ";users=";
                for (int i = 0; i < game.users.Count; i++)
                {
                    ssss += game.users[i];
                    if (i != game.users.Count - 1)
                    {
                        ssss += "?";
                    }
                }
                this.Write(ssss);
            }
        }
Example #6
0
        public static void SetPicture(Server.TokenAndId tai, string content, BrainDuelsLib.delegates.Action resultCallback, bool isLarge)
        {
            Random random      = new System.Random();
            int    serverIndex = random.Next() % SocketManager.PICTURE_SERVERS.Length;
            SetPictureSocketThreadedJob job = new SetPictureSocketThreadedJob(tai, serverIndex, content, isLarge);

            job.resultCallback = resultCallback;
            job.Start();
        }
Example #7
0
        public static void GetPicture(Server.TokenAndId tai, int serverIndex, int pictureId, BrainDuelsLib.delegates.Action <string> resultCallback)
        {
            GetPictureSocketThreadedJob job = new GetPictureSocketThreadedJob(tai, serverIndex, pictureId);

            job.resultCallback = delegate(string s)
            {
                job.IsDone = true;
                job.Update();
                resultCallback(s);
            };
            job.Start();
        }
Example #8
0
 public void Authorize(String login, String password)
 {
     try
     {
         Server.TokenAndId tai = Server.Authorize(login, password);
         store.succesfullLoginCallback(tai);
     }
     catch (WrongLoginPassword e1)
     {
         store.invalidLoginPasswordCallback();
     }
     catch (WebException e2)
     {
         store.errorCallback(e2);
     }
 }
Example #9
0
 public void Register(String login, String password)
 {
     try
     {
         Server.Register(login, password);
         Server.TokenAndId tai = Server.Authorize(login, password);
         Server.SetUser(tai, 0);
         store.succesfullSignUpCallback(tai);
     }
     catch (LoginExists e3)
     {
         store.userExists();
     }
     catch (WebException e2)
     {
         store.errorCallback(e2);
     }
 }
Example #10
0
    void Set(Server.TokenAndId tai)
    {
        moi         = this;
        lobbyWidget = new LobbyWidget(tai);
        LobbyBackendWidget backgroud = new LobbyBackendWidget(tai);

        backgroud.Controls.timer       = new CrazyGoTimerControl(1000, timerScriptLobby);
        lobbyWidget.Controls.backgroud = backgroud;
        lobbyWidget.Callbacks.goToGameAsPlayerCallback = delegate(Game g)
        {
            lobbyWidget.Discard();
            newGameSound.Play();
            UnityEngine.Debug.Log("Go to game");


            DataPasser.Get().Set("lobby", lobbyWidget);
            DataPasser.Get().Set("tai", tai);
            DataPasser.Get().Set("is_observer", false);
            DataPasser.Get().Set("game", g);
            CloseWidget();
            Application.LoadLevel(3);
        };

        lobbyWidget.Callbacks.repeatedCallback = delegate()
        {
            lobbyWidget.Discard();
            UnityEngine.Debug.Log("Already connected");
            CloseWidget();
            DataPasser.Get().Set("repeat", "true");
            Application.LoadLevel(0);
        };


        SetUserInfo();
        SetPlayBarPart(lobbyWidget);
        lobbyWidget.Go();
    }
Example #11
0
    public override void SetItem(GameObject widget, Game item, Action <Game, int> action, Server.TokenAndId tai)
    {
        GameListItem litem = widget.GetComponent <GameListItem>();

        if (item.users.Count >= 1)
        {
            User u = Server.GetUser(tai, item.users[0]);
            litem.firstPlayerName.text = u.login + "(" + u.GetRankString() + ")";
        }
        else
        {
            litem.firstPlayerName.text = "Available";
        }

        if (item.users.Count >= 2)
        {
            User u = Server.GetUser(tai, item.users[1]);
            litem.secondPlayerName.text = u.login + "(" + u.GetRankString() + ")";
        }
        else
        {
            litem.secondPlayerName.text = "Available";
        }

        Settings settings = Settings.Load(item.settings);


        litem.timeControlLabel.text = settings.GetTimeControl();

        /*
         * litem.komiLabel.text = settings.komi+"";
         *
         * Stone stone1 = Stone.BLACK;
         * Stone stone2 = Stone.WHITE;
         *
         * if(settings.firstPlayer == 0){
         *  stone1 = Stone.BLACK;
         *  stone2 = Stone.WHITE;
         * }
         *
         * if (settings.firstPlayer == 1)
         * {
         *  stone1 = Stone.WHITE;
         *  stone2 = Stone.BLACK;
         * }
         *
         * if (settings.firstPlayer == 9)
         * {
         *  stone1 = Stone.UNKNOWN;
         *  stone2 = Stone.UNKNOWN;
         * }
         * */

        //litem.firstPlayerStoneSprite.spriteName = BoardStateParser.GetSprite(stone1);
        //litem.secondPlayerStoneSprite.spriteName = BoardStateParser.GetSprite(stone2);

        litem.joinButton.onClick.Add(new EventDelegate(new EventDelegate.Callback(
                                                           delegate
        {
            action(item, 0);
        }
                                                           )));

        litem.leaveButton.onClick.Add(new EventDelegate(new EventDelegate.Callback(
                                                            delegate
        {
            action(item, 1);
        }
                                                            )));

        litem.backgroundSprite.spriteName = getGameBackground(item.status);

        litem.joinButton.isEnabled  = false;
        litem.leaveButton.isEnabled = false;

        if (item.status.Equals("open"))
        {
            if (!item.users.Contains(me))
            {
                litem.joinButton.isEnabled = true;
            }
            else
            {
                litem.leaveButton.isEnabled = true;
            }
        }
        else
        {
            litem.joinButton.isEnabled = true;
            if (!item.users.Contains(me))
            {
                litem.joinLabel.text = "Observe";
            }
            else
            {
                litem.joinLabel.text = "Join";
            }
        }

        if (item.title.Equals("go"))
        {
            litem.gameTypeLabel.text = "Go";
        }

        if (item.title.Equals("one-color-go"))
        {
            litem.gameTypeLabel.text = "One color Go";
        }

        if (item.title.Equals("blind-go"))
        {
            litem.gameTypeLabel.text = "Blind Go";
        }

        if (item.title.Equals("hidden-move-go"))
        {
            litem.gameTypeLabel.text = "Hidden move Go";
        }

        int size = settings.size;

        litem.gameTypeLabel.text += "\n" + size + "*" + size;

        if (settings.GetHandi())
        {
            litem.handicapLabel.text = "Yes";
        }
        else
        {
            litem.handicapLabel.text = "No";
        }
    }
Example #12
0
 public ChatSocketThreadedJob(Server.TokenAndId tai) : base(SocketManager.CHAT_SERVER, null)
 {
     this.tai      = tai;
     this.callback = MessageCallback;
     this.Write("authorize id=" + tai.id + ";token=" + tai.token);
 }
Example #13
0
    public void SetGameWidgetPart(Server.TokenAndId tai, Game game)
    {
        this.tai   = tai;
        this.game  = game;
        gameWidget = new GameWidget(tai, game);
        CrazyGoTimerControl timerControl = new CrazyGoTimerControl(250, timerScript);

        gameWidget.Controls.timer = timerControl;

        gameWidget.Callbacks.updateGameCallback = delegate(string s, int a)
        {
            UpdateGameCallback(s, a);
        };


        gameWidget.Callbacks.eventCallback = delegate(string message)
        {
            OnEvent(message);
        };


        gameWidget.Callbacks.illegalMoveCallback = delegate
        {
            UnityEngine.Debug.Log("Illegal move");
        };


        gameWidget.Callbacks.gameEndedCallback = delegate(string res)
        {
            this.OnGameEnd(res);
        };

        gameWidget.Callbacks.gameEndedCallback = delegate(string s)
        {
            OnGameEnd(s);
            UnityEngine.Debug.Log("Game ended: result is " + s);
        };

        gameWidget.Callbacks.eventCallback = delegate(string s)
        {
            OnEvent(s);
            //UnityEngine.Debug.Log("Event: " + s);
        };


        moveButton.onClick.Add(new EventDelegate(new EventDelegate.Callback(
                                                     delegate
        {
            //pressButtonSound.Play();
            Point a = this.controller.GetCurrentMoveIndicator();
            if (a != null)
            {
                gameWidget.MakeAMove(a.x + "-" + a.y);
            }
        }
                                                     )));

        resignButton.onClick.Add(new EventDelegate(new EventDelegate.Callback(
                                                       delegate
        {
            pressButtonSound.Play();
            Utils.MakeVisible(resignPopup.transform);
        }
                                                       )));

        yesResignButton.onClick.Add(new EventDelegate(new EventDelegate.Callback(
                                                          delegate
        {
            pressButtonSound.Play();
            Utils.MakeUnvisible(resignPopup.transform);
            gameWidget.MakeAMove("resign");
        }
                                                          )));


        this.yesTry.onClick.Add(new EventDelegate(new EventDelegate.Callback(
                                                      delegate
        {
            pressButtonSound.Play();
            Utils.MakeUnvisible(this.tryPopup.transform);
            gameWidget.MakeAMove("yes");
        }
                                                      )));

        this.noTry.onClick.Add(new EventDelegate(new EventDelegate.Callback(
                                                     delegate
        {
            pressButtonSound.Play();
            Utils.MakeUnvisible(this.tryPopup.transform);
            gameWidget.MakeAMove("no");
        }
                                                     )));


        this.passButton.onClick.Add(new EventDelegate(new EventDelegate.Callback(
                                                          delegate
        {
            pressButtonSound.Play();
            Utils.MakeUnvisible(resignPopup.transform);
            gameWidget.MakeAMove("pass");
        }
                                                          )));

        this.agreeButton.onClick.Add(new EventDelegate(new EventDelegate.Callback(
                                                           delegate
        {
            pressButtonSound.Play();
            Utils.MakeUnvisible(resignPopup.transform);
            gameWidget.MakeAMove("agree");
        }
                                                           )));

        this.askButton.onClick.Add(new EventDelegate(new EventDelegate.Callback(
                                                         delegate
        {
            pressButtonSound.Play();
            Utils.MakeUnvisible(resignPopup.transform);
            gameWidget.MakeAMove("ask");
        }
                                                         )));

        this.goButton.onClick.Add(new EventDelegate(new EventDelegate.Callback(
                                                        delegate
        {
            gameWidget.MakeAMove("go");
        }
                                                        )));

        noResignButton.onClick.Add(new EventDelegate(new EventDelegate.Callback(
                                                         delegate
        {
            pressButtonSound.Play();
            Utils.MakeUnvisible(resignPopup.transform);
            //gameWidget.MakeAMove("resign");
        }
                                                         )));


        exitButton.onClick.Add(new EventDelegate(new EventDelegate.Callback(
                                                     delegate
        {
            GoToLobby();
        }
                                                     )));

        /*
         * this.board.SetUserTogglePoint(delegate (Point a)
         * {
         *  if (a.x >= 0 && a.x < this.board.GetN())
         *  {
         *      if (a.y >= 0 && a.y < this.board.GetN())
         *      {
         *          gameWidget.MakeAMove(a.x + "-" + a.y);
         *      }
         *  }
         * });
         */

        gameWidget.Go();
        SetInitialData();
        StartChat();
    }
Example #14
0
 public GameWidget(Server.TokenAndId tai, Game game) : base()
 {
     this.game = game;
     this.tai  = tai;
     id        = random.Next();
 }
Example #15
0
    public override void SetItem(GameObject widget, User item, Action <User, int> action, Server.TokenAndId tai)
    {
        PlayerListItem litem = widget.GetComponent <PlayerListItem>();

        litem.login.text = item.login + "(" + item.GetRankString() + ")";
        litem.challengeButton.onClick.Add(new EventDelegate(new EventDelegate.Callback(
                                                                delegate
        {
            action(item, item.id);
        }
                                                                )));
    }
Example #16
0
 public void Set(List <T> items, int x, int y, int height, Action <T, int> action, Server.TokenAndId tai)
 {
     slider.alpha = 1.0f;
     RemoveCategory("items");
     for (int i = 0; i < items.Count; i++)
     {
         T          item   = items[i];
         GameObject widget = AddWidget("items", prefab, x, -(height * i + y));
         SetItem(widget, item, action, tai);
     }
 }
Example #17
0
 public abstract void SetItem(GameObject widget, T item, Action <T, int> action, Server.TokenAndId tai);
Example #18
0
 public LobbyWidget(Server.TokenAndId tai)
     : base()
 {
     this.tai = tai;
 }
Example #19
0
 public ChatWidget(Server.TokenAndId tai)
     : base()
 {
     this.tai = tai;
 }