void OnAfterJoinRoom(JoinRoomEvent e) { if (cbSavePass.value) { if (IsClickButtonLogin) { StoreGame.SaveString(StoreGame.EType.SAVE_USERNAME, lableUsername.value); StoreGame.SaveString(StoreGame.EType.SAVE_PASSWORD, lablePassword.value); } } //else //{ // StoreGame.Remove(StoreGame.EType.SAVE_ACCESSTOKEN); // StoreGame.Remove(StoreGame.EType.SAVE_USERNAME); // StoreGame.SaveString(StoreGame.EType.SAVE_PASSWORD, lablePassword.text); //} //OK Next Scene if (GameManager.Instance.selectedLobby.gameId != 0) { return; } WaitingView.Hide(); NotificationView.Instance.HideMessageView(); GameManager.LoadScene(ESceneName.HallSceen); }
void ProcessAfterRecharge(bool isDone, WWW response, IDictionary json) { if (isDone && json.Contains("code")) { if (json.Contains("code") && json["code"].ToString() == "1") { serial.value = ""; cardCode.value = ""; } else { if (string.IsNullOrEmpty(json["message"].ToString())) { NotificationView.ShowMessage("Có lỗi trong quá trình nạp thẻ. Bạn vui lòng thử lại!"); } else { NotificationView.ShowMessage(json["message"].ToString()); } WaitingView.Hide(); } } else { NotificationView.ShowMessage("Thông tin thẻ nạp không hợp lệ!"); WaitingView.Hide(); } flag = false; //WaitingView.Hide(); }
IEnumerator _ProressAfterLoginFacebook(bool isDone, WWW textResponse, IDictionary json) { if (isDone) { WaitingView.Hide(); switch (json["code"].ToString()) { case "1": WaitingView.Show("Đang đăng nhập"); GameManager.Instance.accessToken = json["accessToken"].ToString(); GameManager.Instance.userNameLogin = json["username"].ToString(); GameManager.Server.DoLogin(); break; case "-1": reLoginFaceBook(); break; case "-2": if (Application.isWebPlayer) { GameManager.Instance.UpdateCookieString(); while (GameManager.Instance.Cookie.Length == 0) { yield return(new WaitForEndOfFrame()); } string[] arr = GameManager.Instance.Cookie.Split(';'); Array.ForEach(arr, c => { if (c.Contains("PHPSESSID")) { cookie = c; } }); } else { cookie = textResponse.responseHeaders[ServerWeb.PHP_COOKIE]; } if (GameObject.Find("LoginScreen Code") != null) { GameObject.Find("LoginScreen Code").gameObject.GetComponent <LoginScreenView>().formRegister.GetComponent <RegisterView>().SessionId = cookie; GameObject.Find("LoginScreen Code").gameObject.GetComponent <LoginScreenView>().formRegister.GetComponent <RegisterView>().iUsername.value = json["suggestUser"].ToString(); if (GameObject.Find("LoginScreen Code").gameObject.GetComponent <LoginScreenView>().IsFormRegisterHide) { GameObject.Find("LoginScreen Code").gameObject.GetComponent <LoginScreenView>().ShowFormRegister(); } } //RegisterView.Create(cookie, json["suggestUser"].ToString()); break; } } }
/// <summary> /// Sự kiện xảy ra khi bạn logout ứng dụng /// </summary> public void DoLogOut() { StoreGame.Remove(StoreGame.EType.DEBUG_LOG); //REMOVE DEBUG_LOG StoreGame.SaveString(StoreGame.EType.BOOL_SEND_LOG_TO_SERVER, "false"); //REMOVE DEBUG_LOG WaitingView.Hide(); if (Application.loadedLevelName == ESceneName.LoginScreen.ToString()) { Disconnect(); return; } //DoLeaveCurrentRoom(); LogOutRequest logOutRequest = new LogOutRequest(); DoRequest(logOutRequest); #region BUILD WEB ESIMO COMMENT VAO KHI BUILD CHO FACEBOOK #if UNITY_WEBPLAYER switch (GameSettings.Instance.TypeBuildFor) { case GameSettings.EBuildType.esimo: case GameSettings.EBuildType.web_esimo: Application.ExternalEval("window.location = \"/site/logout\""); break; } #endif #endregion StoreGame.Remove(StoreGame.EType.SAVE_USERNAME); StoreGame.Remove(StoreGame.EType.SAVE_PASSWORD); StoreGame.Remove(StoreGame.EType.SAVE_ACCESSTOKEN); if (es.Engine.Connected) { es.Engine.Close(); } if ((FB.IsLoggedIn || !string.IsNullOrEmpty(FB.AccessToken)) && !Application.isWebPlayer) { FB.Logout(); } Disconnect(); GameManager.LoadScene(ESceneName.LoginScreen); }
private void OnAfterJoinRoom(JoinRoomEvent e) { WaitingView.Hide(); //lưu lại thông tin channel select to back button GameManager.Instance.channelRoom = new RoomInfo(e.ZoneId, e.RoomId); switch (e.RoomName.ToLower()) { case "phom": GameManager.LoadScene(ESceneName.ChannelPhom); break; case "tlmn": GameManager.LoadScene(ESceneName.ChannelTLMN); break; case "chan": GameManager.LoadScene(ESceneName.ChannelChan); break; default: Debug.LogError("Cannot find any game"); break; } }
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"); } } }
IEnumerator _DoConnection(CallBackFunction callback) { //Đặt biến không cho gửi kết nối nữa. mustThreadConnecting = true; es.Engine.Queueing = EsEngine.QueueDispatchType.External; Server server = new Server(CServer.SERVER_ID); //if (es.Engine.Servers.Contains(server) == false) server.AddAvailableConnection(new AvailableConnection(CServer.HOST_NAME, System.Convert.ToInt32(CServer.PORT), TYPE_CONNECT)); es.Engine.AddServer(server); log4net.Config.BasicConfigurator.Configure(); #if UNITY_WEBPLAYER if (!Application.isEditor && Application.isWebPlayer) { if (!Security.PrefetchSocketPolicy(CServer.HOST_NAME, System.Convert.ToInt32(CServer.PORT), 999)) { Debug.LogError("Security Exception. Policy file load failed!"); } } #endif //Set là chưa có thông tin phản hồi về kết nối bool?connectionResponseSuccessful = null; WaitingView.Show("Kết nối đến máy chủ"); threadConnect = new System.Threading.Thread(delegate() { es.Engine.Connect(); connectionResponseSuccessful = es.Engine.Connected; }); threadConnect.Start(); while (connectionResponseSuccessful == null) { yield return(new WaitForEndOfFrame()); } if (isLogged) { WaitingView.Instance.Close(); } if (!es.Engine.Connected) { WaitingView.Hide(); NotificationView.ShowConfirm( "Lỗi kết nối TCP/IP.", "Không thể kết nối đến máy chủ.\n\n Bạn có muốn thực hiện lại hành động vừa rồi ?", delegate() { DoConnection(callback); }, null); } else { callback(); } mustThreadConnecting = false; }