public override void OnSelectTabbarAtIndex(int index)
    {
        numberPeddingBuddies.gameObject.SetActive(index != 2);
        numberMessageSystem.gameObject.SetActive(index != 1);

        if (index == 1)
        {
            //List<int> list = new List<int>();
            List <string> list = new List <string>();
            GameManager.Instance.ListMessageSystem.FindAll(m => m.read == false && m.sender == 0).ForEach(mess =>
            {
                list.Add(mess.id);
                mess.read = true;
            });

            if (list.Count > 0)
            {
                GameManager.Server.DoRequestPlugin(Utility.SetEsObject("readMessage", new object[] {
                    "listId", list.ToArray()
                }));
                MessageSystemCache.SaveCache();
            }
        }

        panelTitle.gameObject.SetActive(index != 0);
        if (panelTitle.gameObject.activeSelf)
        {
            if (index == 1)
            {
                Title.text = "Tin nhắn hệ thống";
            }
            else if (index == 2)
            {
                Title.text = "Lời mời kết bạn";
            }
            else
            {
                Title.text = Utility.Convert.ToTitleCase(((PrefabMessageFriendView)tabbarButtons[index]).username.text);
            }
        }
    }
Esempio n. 2
0
    void ProcessGeneral(string command, string action, EsObject eso)
    {
        if (command == Fields.RESPONSE.CREATE_GAME)
        {
            #region CREATE_GAME
            if (eso.getBoolean("successful"))
            {
                GameManager.Instance.selectedLobby.SetDataJoinLobby(eso);
            }
            else
            {
                NotificationView.ShowMessage("Lỗi! Tạo bàn chơi không thành công.", 3f);
            }
            #endregion
        }
        else if (command == "joinGame")
        {
            #region JOIN GAME
            if (EventLoadSence != null)
            {
                EventLoadSence();
            }
            GameManager.Instance.selectedLobby.SetDataJoinLobby(eso);
            WaitingView.Hide();
            PlaySameDevice.SaveDeviceWhenJoinGame();
            #endregion
        }
        else if (command == "removeFriend")
        {
            #region REMOVE FRIEND
            EsObject obj = eso.getEsObject("user");

            User pendingUser = GameManager.Instance.mInfo.pendingBuddies.Find(user => user.username == (obj.variableExists("username") ? obj.getString("username") : obj.getString(Fields.PLAYER.USERNAME)));
            if (pendingUser != null)
            {
                GameManager.Instance.mInfo.pendingBuddies.Remove(pendingUser);

                if (EventFriendPendingChanged != null)
                {
                    EventFriendPendingChanged(pendingUser, true);
                }
            }
            else
            {
                pendingUser = GameManager.Instance.mInfo.buddies.Find(user => user.username == (obj.variableExists("username") ? obj.getString("username") : obj.getString(Fields.PLAYER.USERNAME)));
                GameManager.Instance.mInfo.buddies.Remove(pendingUser);

                if (EventFriendChanged != null)
                {
                    EventFriendChanged(pendingUser, true);
                }
            }
            #endregion
        }
        else if (command == "acceptFriendRequest")
        {
            #region ACCEPT FRIEND REQUEST
            EsObject obj  = eso.getEsObject("user");
            User     user = new User(obj);

            if (GameManager.Instance.mInfo.requestBuddies.Find(u => u.username == user.username) != null)
            {
                GameManager.Instance.mInfo.requestBuddies.Remove(GameManager.Instance.mInfo.requestBuddies.Find(u => u.username == user.username));
            }

            if (GameManager.Instance.mInfo.buddies.Find(u => u.username == user.username) == null)
            {
                User pendingUser = GameManager.Instance.mInfo.pendingBuddies.Find(u => u.username == user.username);
                if (pendingUser != null)
                {
                    GameManager.Instance.mInfo.pendingBuddies.Remove(pendingUser);
                }

                GameManager.Instance.mInfo.buddies.Add(user);
                if (EventFriendChanged != null)
                {
                    EventFriendChanged(user, false);
                }
            }
            #endregion
        }
        else if (command == "friendRequest")
        {
            #region FRIEND REQUEST
            EsObject obj  = eso.getEsObject("user");
            User     user = new User(obj);
            GameManager.Instance.mInfo.pendingBuddies.Add(user);

            if (EventFriendPendingChanged != null)
            {
                EventFriendPendingChanged(user, false);
            }
            #endregion
        }
        else if (command == "inComingMessage")
        {
            #region INCOME MESSAGE
            Messages message = new Messages(eso.getEsObject("message"));
            GameManager.Instance.mInfo.messages.Add(message);

            RegisterEventMessageChanged(message, false);
            #endregion
        }
        else if (command == "outGoingMessage")
        {
            #region OUT GOING MESSAGE
            Messages mess = new Messages();
            mess.SetDataOutGoing(eso);
            GameManager.Instance.mInfo.messages.Add(mess);
            RegisterEventMessageChanged(mess, true);
            #endregion
        }
        else if (command == "systemMessage")
        {
            #region SYSTEM MESSAGE
            Messages message = new Messages(eso.getEsObject("message"));

            message.sender        = 0;
            message.read          = false;
            message.receiver      = GameManager.Instance.mInfo.id;
            message.receiver_name = GameManager.Instance.mInfo.username;

            MessageSystemCache.SaveCache(new Hashtable[] { message.ParseToHashtable });

            if (message.type != 0)
            {
                ServerMessagesView.MessageServer(message.content);
            }
            else
            {
                RegisterEventMessageChanged(message, false);
            }
            #endregion
        }
        else if (command == "invitePlayGame")
        {
            #region INVITE PLAY GAME
            string actionInvited = "joinGame";
            if (eso.variableExists("action"))
            {
                actionInvited = eso.getString("action");
            }

            if (actionInvited == "createGame")
            {
                NotificationView.ShowConfirm("Xác nhận", "Bạn có muốn tạo phòng mới hay không?",
                                             delegate()
                {
                    GameManager.Server.DoRequestPlugin(Utility.SetEsObject(Fields.RESPONSE.CREATE_GAME,
                                                                           new object[] { "config", createRoom() }));
                }, delegate()
                {
                    GameManager.Server.DoRequestCommand("abortInvitation");
                });
            }
            else
            {
                #region INVITE PLAYER
                string userName = eso.getString(Fields.PLAYER.USERNAME);
                int    gameId   = eso.getInteger("gameId");
                string password = eso.variableExists("password") ? eso.getString("password") : "";
                if (password.Length == 0 && eso.variableExists("config"))
                {
                    EsObject esoConfig = eso.getEsObject("config");
                    if (esoConfig.variableExists("password"))
                    {
                        password = esoConfig.getString("password");
                    }
                }
                int roomId    = eso.getInteger("roomId");
                int zoneId    = eso.getInteger("zoneId");
                int gameIndex = eso.getInteger("gameIndex");

                if (GameManager.CurrentScene == ESceneName.LobbyChan || GameManager.CurrentScene == ESceneName.LobbyPhom || GameManager.CurrentScene == ESceneName.LobbyTLMN)
                {
                    string contentMsg = "Bạn nhận được một lời mời chơi!";
                    if (userName.Length > 0)
                    {
                        contentMsg = "\"" + Utility.Convert.ToTitleCase(userName) +
                                     "\" gửi bạn một lời mời tham gia vào bàn chơi số " + gameIndex + ".\n\n";
                    }
                    NotificationView.ShowConfirm("Mời chơi",
                                                 contentMsg,
                                                 delegate()
                    {
                        //GameManager.Instance.selectedLobby = GameManager.CurrentScene == ESceneName.LobbyChan ? new LobbyChan(zoneId, roomId, gameId) : GameManager.CurrentScene == ESceneName.LobbyPhom ? new LobbyPhom(zoneId, roomId, gameId) : new LobbyTLMN(zoneId, roomId, gameId);
                        if (GameManager.CurrentScene == ESceneName.LobbyPhom)
                        {
                            GameManager.Instance.selectedLobby = new LobbyPhom(zoneId, roomId, gameId);
                        }
                        else if (GameManager.CurrentScene == ESceneName.LobbyChan)
                        {
                            GameManager.Instance.selectedLobby = new LobbyChan(zoneId, roomId, gameId);
                        }
                        else
                        {
                            GameManager.Instance.selectedLobby = new LobbyTLMN(zoneId, roomId, gameId);
                        }
                        GameManager.Server.DoJoinGame(password);
                    }, delegate()
                    {
                        GameManager.Server.DoRequestCommand("abortInvitation");
                    });
                }
                #endregion
            }
            #endregion
        }
        else if (command == "updateUserInfo")
        {
            #region CẬP NHẬT THÔNG TIN USERS
            if (eso.variableExists("userName") && eso.getString("userName") == GameManager.Instance.mInfo.username)
            {
                if (eso.variableExists("field"))
                {
                    string field = eso.getString("field");

                    if (field == "money")
                    {
                        string moneyType = "";
                        if (eso.variableExists("moneyType"))
                        {
                            moneyType = eso.getString("moneyType");
                        }
                        if (moneyType != "" && moneyType == "chip")
                        {
                            long.TryParse(eso.getString("value"), out GameManager.Instance.mInfo.chip);
                        }
                        else if (moneyType != "" && moneyType == "gold")
                        {
                            long.TryParse(eso.getString("value"), out GameManager.Instance.mInfo.gold);
                        }
                    }
                    else if (field == "experience")
                    {
                        GameManager.Instance.mInfo.SetDataUser(eso.getEsObject("userInfo"));
                    }

                    if (EventUpdateUserInfo != null)
                    {
                        EventUpdateUserInfo();
                    }
                }
            }
            else if (eso.variableExists("userName") && eso.getString("userName") != GameManager.Instance.mInfo.username)
            {
                if (GameManager.CurrentScene == ESceneName.GameplayChan && eso.variableExists("field"))
                {
                    string field = eso.getString("field");
                    if (field == "experience")
                    {
                        if (GameModelChan.GetPlayer(eso.getString("userName")) != null)
                        {
                            GameModelChan.GetPlayer(eso.getString("userName")).SetDataUser(eso.getEsObject("userInfo"));
                        }
                    }
                }
            }
            #endregion
        }
        else if (command == "updateConfigClient")
        {
            #region CẬP NHẬT THÔNG TIN CONFIG
            if (eso.variableExists("config"))
            {
                IDictionary obj  = (IDictionary)JSON.JsonDecode(eso.getString("config"));
                string      type = obj[Fields.CONFIGCLIENT.KEY_TYPE_REAL_TIME].ToString();
                switch (type)
                {
                case Fields.CONFIGCLIENT.VALUE_ADS:
                    Announcement announce = new Announcement(
                        Convert.ToInt32(obj["index"]),
                        obj["description"].ToString(),
                        obj["scenes"].ToString() == "lobby"
                                ? Announcement.Scene.lobby
                                : obj["scenes"].ToString() == "login"
                                ? Announcement.Scene.login
                                : Announcement.Scene.announce,
                        obj["url"].ToString(),
                        obj["image"].ToString(),
                        obj["type"].ToString() == "Ads" ? Announcement.Type.Advertisement : Announcement.Type.Event
                        );
                    GameManager.Instance.ListAnnouncement.Remove(GameManager.Instance.ListAnnouncement.Find(ads => ads.show == announce.show && ads.type == Announcement.Type.Advertisement));
                    GameManager.Instance.ListAnnouncement.Add(announce);
                    if (EventAdsChanged != null)
                    {
                        EventAdsChanged(obj);
                    }
                    break;

                case Fields.CONFIGCLIENT.VALUE_HELP:
                    StoreGame.Remove(StoreGame.EType.CACHE_HELP);
                    GameManager.Instance.ListHelp.Clear();
                    StoreGame.SaveString(StoreGame.EType.CACHE_HELP, JSON.JsonEncode(obj[Fields.RESPONSE.PHP_RESPONSE_ITEMS]));
                    ArrayList list = (ArrayList)obj[Fields.RESPONSE.PHP_RESPONSE_ITEMS];
                    foreach (Hashtable item in list)
                    {
                        GameManager.Instance.ListHelp.Add(item);
                    }
                    if (EventHelpChanged != null)
                    {
                        EventHelpChanged(obj);
                    }
                    break;

                case Fields.CONFIGCLIENT.VALUE_CONFIG_CLIENT:
                    ArrayList items = (ArrayList)obj[Fields.RESPONSE.PHP_RESPONSE_ITEMS];
                    foreach (Hashtable item in items)
                    {
                        GameManager.Setting.Platform.AddOrUpdatePlatformConfig(item);
                    }
                    if (GameManager.Setting.Platform.GetConfigByType(PlatformType.url_ping) != null)
                    {
                        ServerWeb.URL_PING = GameManager.Setting.Platform.GetConfigByType(PlatformType.url_ping).Value;
                    }
                    if (EventConfigClientChanged != null)
                    {
                        EventConfigClientChanged(obj);
                    }
                    break;
                }
            }
            #endregion
        }
        else if (command == Fields.RESPONSE.DAYLY_GIFT)
        {
            #region Thông tin trả về khi nhận quà tặng
            //AnnouncementView.Instance.Close();
            if (eso.variableExists("textNotification"))
            {
                if (GameObject.Find("__Announcement") != null)
                {
                    AnnouncementView.Instance.SetCenterOnNextCurrentDay();
                }
                GameManager.Instance.FunctionDelay(delegate()
                {
                    string text = eso.getString("textNotification");
                    NotificationView.ShowMessage(text);
                }, 1f);
                GameManager.Instance.ListAnnouncement.RemoveAll(a => a.show == Announcement.Scene.announce && a.type == Announcement.Type.Gift);
            }
            #endregion
        }
        else if (command == Fields.RESPONSE.GET_MESSAGE)
        {
            #region LẤY THÔNG TIN TIN NHẮN TỪ SERVER
            WaitingView.Hide();
            //disable total count khi chưa load messeage
            this.totalMesseageCount = -1;
            if (eso.variableExists("messages"))
            {
                EsObject[] array = eso.getEsObjectArray("messages");
                System.Array.ForEach <EsObject>(array, o => { GameManager.Instance.mInfo.messages.Add(new Messages(o)); });

                List <Messages> systemMessage = GameManager.Instance.mInfo.messages.FindAll(m => m.sender == 0);
                GameManager.Instance.ListMessageSystem.Clear();
                while (systemMessage.Count > 0)
                {
                    GameManager.Instance.ListMessageSystem.Add(systemMessage[0]);
                    GameManager.Instance.mInfo.messages.Remove(systemMessage[0]);
                    systemMessage.RemoveAt(0);
                }
                if (EventGetMessageCallBack != null)
                {
                    EventGetMessageCallBack();
                }
            }
            #endregion
        }
        else if (command == Fields.RESPONSE.GET_BUDDIES)
        {
            #region LẤY THÔNG TIN DANH SÁCH BẠN BÈ
            WaitingView.Hide();
            GameManager.Instance.mInfo.SetDataUser(eso);
            if (EventGetBuddiesCallBack != null)
            {
                EventGetBuddiesCallBack();
            }
            #endregion
        }
        else if (command == "getLevel")
        {
            if (eso.variableExists("level"))
            {
                GameManager.Instance.mInfo.level = eso.getInteger("level");
            }
            if (eso.variableExists("experience"))
            {
                GameManager.Instance.mInfo.experience = eso.getInteger("experience");
            }
            if (eso.variableExists("expMinCurrentLevel"))
            {
                GameManager.Instance.mInfo.expMinCurrentLevel = eso.getInteger("expMinCurrentLevel");
            }
            if (eso.variableExists("expMinNextLevel"))
            {
                GameManager.Instance.mInfo.expMinNextLevel = eso.getInteger("expMinNextLevel");
            }
        }
    }