Beispiel #1
0
 /// <summary>
 /// ユーザーデータをGameSparkより引き出してStaticフィールドに反映します
 /// </summary>
 /// <returns><c>true</c>, ロード成功, <c>false</c> ロード失敗.</returns>
 public void LoadUserInfo()
 {
     //とりあえず保存先ユーザー指定,認証
     new AuthenticationRequest()
     .SetPassword("0000")
     .SetUserName(StaticInfo.userInfo.userName)
     .Send((response) => {
         if (!response.HasErrors)
         {
             Debug.Log("Login successfully");
         }
         else
         {
             Debug.Log("Error login");
         }
     });
     //イベントリクエスト
     new LogEventRequest()
     .SetEventKey("LoadPlayerData")
     .Send((response) => {
         if (!response.HasErrors)
         {
             GameSparks.Core.GSData scriptData = response.ScriptData.GetGSData("data");
             PlayerData playerData             = new PlayerData {
                 rate = (int)scriptData.GetInt("rate"),
                 gold = (int)scriptData.GetInt("gold")
             };
             //スタティックフィールドに反映
             StaticInfo.userData.rate = playerData.rate;
             StaticInfo.userData.gold = playerData.gold;
             Debug.Log("Load user data (rate:" + playerData.rate + "gold:" + playerData.gold + ")");
             StaticInfo.callback = "Loaded data";
         }
         else
         {
             Debug.Log("Error Load Player Data");
         }
     });
 }
Beispiel #2
0
        private void Handshake(GSObject response, GSConnection connection)
        {
            if (response.ContainsKey("error"))
            {
                GSPlatform.DebugMsg(response.GetString("error"));

                ShutDown(null);
            }
            else if (response.ContainsKey("nonce"))
            {
                SendHandshake(response, connection);
            }
            else
            {
                if (response.ContainsKey("sessionId"))
                {
                    _sessionId = response.GetString("sessionId");

                    connection.SessionId = _sessionId;

                    if (response.ContainsKey("authToken"))
                    {
                        GSPlatform.ExecuteOnMainThread(() =>
                        {
                            GSPlatform.AuthToken = response.GetString("authToken");
                        });
                    }
                    else
                    {
                        GSPlatform.ExecuteOnMainThread(() =>
                        {
                            GSPlatform.AuthToken = "0";
                            GSPlatform.UserId    = "";
                        });
                    }

                    if (response.ContainsKey("clientConfig"))
                    {
                        GSData clientConfig = response.GetGSData("clientConfig");

                        RetryBase                 = clientConfig.GetInt("retryBase").GetValueOrDefault(GS.RetryBase);
                        RetryMax                  = clientConfig.GetInt("retryMax").GetValueOrDefault(GS.RetryMax);
                        RequestTimeout            = clientConfig.GetInt("requestTimeout").GetValueOrDefault(GS.RequestTimeout);
                        DurableConcurrentRequests = clientConfig.GetInt("durableConcurrentRequests").GetValueOrDefault(GS.DurableConcurrentRequests);
                        DurableDrainInterval      = clientConfig.GetInt("durableDrainInterval").GetValueOrDefault(GS.DurableDrainInterval);
                        HandshakeOffset           = clientConfig.GetInt("handshakeOffset").GetValueOrDefault(GS.HandshakeOffset);
                    }
                    else
                    {
                        RetryBase                 = GS.RetryBase;
                        RetryMax                  = GS.RetryMax;
                        RequestTimeout            = GS.RequestTimeout;
                        DurableConcurrentRequests = GS.DurableConcurrentRequests;
                        DurableDrainInterval      = GS.DurableDrainInterval;
                        HandshakeOffset           = GS.HandshakeOffset;
                    }

                    //We want availability to be triggered before authenticated
                    GSPlatform.DebugMsg("Available");

                    connection.Ready = true;

                    setAvailability(true);

                    if (response.ContainsKey("userId"))
                    {
                        SetUserId(response.GetString("userId"));
                    }

                    CalcNewReconnectionTimeout(0);
                }
            }
        }
Beispiel #3
0
    void playerdata()
    {
        new AuthenticationRequest()
        .SetPassword("0000")
        .SetUserName("26337")
        .Send((response) => {
            if (!response.HasErrors)
            {
                Debug.Log("Login successfully");
            }
            else
            {
                Debug.Log("Error login");
            }
        });

        //Item item = new Item { name = "test1", cnt = 1 };
        //Item item2 = new Item { name = "test2", cnt = 3 };
        //StaticInfo.userData.items = item;
        //Debug.Log(StaticInfo.userData.items.name);
        //StaticInfo.userData.items.Add(item2);
        Debug.Log("Saving");
        PlayerData player = new PlayerData {
            gold = 2,
            rate = 0
        };
        string jsonData = JsonUtility.ToJson(player);

        GameSparks.Core.GSRequestData data = new GameSparks.Core.GSRequestData(jsonData);
        Debug.Log(jsonData);
        new LogEventRequest()
        .SetEventKey("SavePlayerData")
        .SetEventAttribute("playerData", data)
        .Send((response) => {
            if (!response.HasErrors)
            {
                Debug.Log("Save data successfully");
            }
            else
            {
                Debug.Log("Error Save Player Data");
            }
        });

        new LogEventRequest()
        .SetEventKey("LoadPlayerData")
        .Send((response) => {
            if (!response.HasErrors)
            {
                GameSparks.Core.GSData scriptData = response.ScriptData.GetGSData("data");
                PlayerData playerData             = new PlayerData {
                    rate = (int)scriptData.GetInt("rate"),
                    gold = (int)scriptData.GetInt("gold")
                };
                Debug.Log("rate:" + playerData.rate + "gold:" + playerData.gold);
            }
            else
            {
                Debug.Log("Error Load Player Data");
            }
        });
    }
        /// <summary>
        /// User Login
        /// </summary>>
        /// <param name="username"></param>
        /// <param name="password"></param>
        /// <param name="eventName"></param>
        public static void Login(string username, string password, string eventName)
        {
            if (DataController.GetValue <string>("LastValidusername") != username)
            {
                if (DataController.GetValue <string>("LastValidusername") != "")
                {
                    Login(DataController.GetValue <string>("LastValidusername"), DataController.GetValue <string>("LastValidPassword"), null);
                }
            }

            DataController.SaveValue("username", username);

            StatsList = new List <long>();

            EquipmentList = new List <long>();

            OtherStuffList = new List <long>();

            StatsList = new List <long>();

            EquipmentList = new List <long>();

            PrimaryStuffList = new List <long>();

            if (DataController.GetValue <int>("Rating") >= 0)
            {
                var newRequest = new GameSparks.Api.Requests.LogEventRequest();// DataController.GetValue<int>("Rating"));

                newRequest.SetEventKey("RATING_UPDATE").SetEventAttribute("Rating", DataController.GetValue <int>("Rating")).Send(response =>
                {
                });
            }

            var newRequest1 = new GameSparks.Api.Requests.LeaderboardDataRequest();

            newRequest1.SetLeaderboardShortCode("LeaderboardRating").SetEntryCount(35).Send(response =>
            {
                Debug.Log(response.BaseData.JSON);

                LeaderBoardsScript.Ranks = new List <long?>();

                LeaderBoardsScript.Names = new List <string>();

                LeaderBoardsScript.Ratings = new List <long?>();

                foreach (var gd in response.BaseData.GetGSDataList("data"))
                {
                    LeaderBoardsScript.Ranks.Add(gd.GetLong("rank"));

                    LeaderBoardsScript.Names.Add(gd.GetString("userName"));

                    LeaderBoardsScript.Ratings.Add(gd.GetLong("Rating"));

                    //Debug.Log(gd.GetString("userName"));

                    //Debug.Log(gd.GetLong("Rating"));
                }
            });

            Debug.Log("Authentication...");
            var loginRequest = new AuthenticationRequest();


            GameSparks.Core.GSRequestData data = new GameSparks.Core.GSRequestData();
            if (DataController.GetValue <int>("GSNotSynced" + username) > 0 && DataController.GetValue <string>("LastValidusername") == username)
            {
                foreach (string attr in ServerNamz)
                {
                    Debug.Log(DataController.GetValue <int>(attr + "Mine"));
                    StatsList.Add((long)DataController.GetValue <int>(attr + "Mine"));
                }
                data.AddNumberList("Stats", StatsList);

                foreach (string TypeItem in Equipment.ForInvLoad)
                {
                    foreach (string Name in EquipmentNames)
                    {
                        EquipmentList.Add((long)DataController.GetValue <int>(Name + TypeItem + "ammount"));
                    }
                }
                data.AddNumberList("Equipment", EquipmentList);

                int tempNum = 0;

                foreach (int num in CelebrationAnimation.Prices)
                {
                    Debug.Log(num);

                    if (DataController.GetValue <int>("WinAnimNumberMine" + tempNum + "ammount") > 0)
                    {
                        OtherStuffList.Add(1);
                    }
                    else
                    {
                        OtherStuffList.Add(0);
                    }
                    tempNum += 1;
                }

                PrimaryStuffList.Add(DataController.GetValue <int>("Exp"));

                PrimaryStuffList.Add(DataController.GetValue <int>("Bread"));

                PrimaryStuffList.Add(DataController.GetValue <int>("SkillPoints"));

                PrimaryStuffList.Add(DataController.GetValue <int>("Rating"));

                Debug.Log(DataController.GetValue <int>("SkillPoints"));

                data.AddNumberList("OtherStuffList", OtherStuffList);

                data.AddNumberList("PrimaryStuffList", PrimaryStuffList);
            }

            loginRequest.SetUserName(username);
            loginRequest.SetPassword(password);
            loginRequest.SetScriptData(data);


            loginRequest.Send(response =>
            {
                if (!response.HasErrors)
                {
                    GameSparks.Core.GSData GSList = response.ScriptData;
                    foreach (string atributeName in ServerNamz)
                    {
                        DataController.SaveValue(atributeName + "Mine", (int)GSList.GetInt(atributeName));
                    }
                    foreach (string TypeItem in Equipment.ForInvLoad)
                    {
                        foreach (string Name in EquipmentNames)
                        {
                            if (GSList.GetGSData("BoughtOrNot").ContainsKey(Name + TypeItem))
                            {
                                if (GSList.GetGSData("BoughtOrNot").GetInt(Name + TypeItem) > 0)
                                {
                                    DataController.SaveValue(Name + TypeItem + "ammount", 1);
                                }
                                else
                                {
                                    DataController.SaveValue(Name + TypeItem + "ammount", 0);
                                }
                            }
                            else
                            {
                                DataController.SaveValue(Name + TypeItem + "ammount", 0);
                            }
                        }
                    }
                    foreach (var vg in GSList.GetGSDataList("VirtualGoodsList"))
                    {
                        foreach (string modifier in EqModifiers)
                        {
                            if (vg.GetGSData("currencyCosts").GetInt(modifier) != null)
                            {
                                DataController.SaveValue(vg.GetString("name") + modifier, (int)vg.GetGSData("currencyCosts").GetInt(modifier));
                                //Debug.Log(vg.GetString("name"));
                            }
                        }
                        //Debug.Log(vg.GetString("name"));
                        DataController.SaveValue(vg.GetString("name") + "Price", (int)vg.GetGSData("currencyCosts").GetInt("Bread"));
                        DataController.SaveValue(vg.GetString("name") + "SellPrice", (int)vg.GetGSData("currencyCosts").GetInt("BreadPrice"));
                    }

                    int tempNum = 0;
                    long?value  = GSList.GetLong("Anim" + tempNum);
                    while (value != null)
                    {
                        DataController.SaveValue("WinAnimNumberMine" + tempNum + "ammount", (int)value);
                        tempNum += 1;
                        value    = GSList.GetLong("Anim" + tempNum);
                    }

                    for (int i = tempNum; i < CelebrationAnimation.Prices.Count; i++)
                    {
                        DataController.SaveValue("WinAnimNumberMine" + i + "ammount", 0);
                    }

                    long?Exp = GSList.GetLong("TotalExp");
                    DataController.SaveValue("Exp", (int)Exp);

                    long?Bread = GSList.GetLong("TotalBread");
                    DataController.SaveValue("Bread", (int)Bread);

                    long?SkillPoints = GSList.GetLong("TotalSkillPoints");
                    DataController.SaveValue("SkillPoints", (int)SkillPoints);

                    long?Rating = GSList.GetLong("Rating");
                    DataController.SaveValue("Rating", (int)Rating);

                    Debug.Log(DataController.GetValue <int>("SkillPoints"));


                    DataController.SaveValue("GSNotSynced" + username, 0);
                    Debug.Log("Player authenticated! \n Name:" + response.DisplayName + response.ScriptData.JSON);// + response.ScriptData);//.ScriptData.JSON.ToString());


                    IsUserLoggedIn = false;

                    EventManager.TriggerEvent(eventName, response.DisplayName);

                    DataController.SaveValue("LastValidPassword" + username, password);

                    DataController.SaveValue("LastValidusername", username);
                }
                else
                {
                    ResetPassword.instance.Warning.SetActive(true);

                    PopUpMessage.ActivatePopUp(delegate { UIController.SetActivePanel(UI_Element.Login); }, LocalisationSystem.GetLocalisedValue("loginerror1"));

                    Debug.Log("Error authenticating player.../n" + response.Errors.JSON.ToString());

                    EventManager.TriggerEvent(eventName, "");
                }
            });
        }
Beispiel #5
0
    public void SetScroll(GameSparks.Core.GSData data, long time_now)
    {
        for (int i = 0; i < 4; i++)
        {
            string scroll_type_num = "scroll" + i + "_type";
            scroll_type_num = data.GetString(scroll_type_num);
            if (scroll_type_num == "r_null")
            {
                scroll_rarity[i] = rarity.r_null;
                scroll_go[i].SetActive(false);
            }
            else
            {
                if (scroll_type_num == "r_common")
                {
                    scroll_rarity[i] = rarity.r_common;
                }
                else if (scroll_type_num == "r_uncommon")
                {
                    scroll_rarity[i] = rarity.r_uncommon;
                }
                else if (scroll_type_num == "r_rare")
                {
                    scroll_rarity[i] = rarity.r_rare;
                }

                string scroll_finish = "scroll" + i + "_finish";
                string scroll_start  = "scroll" + i + "_start";

                long time_finish = (long)data.GetLong(scroll_finish);
                long time_start  = (long)data.GetLong(scroll_start);

                active_scroll_index = (int)data.GetInt("active_scroll");

                if (i == active_scroll_index)
                {
                    if (time_finish - time_now <= 0)
                    {
                        timer[i]          = 0;
                        timer_txt[i].text = "Ready";
                    }
                    else
                    {
                        timer[i] = (time_finish - time_now) / 1000;
                    }
                }
                else
                {
                    //if (time_finish != 0)
                    //{
                    //    if (time_finish - time_now <= 0)
                    //    {
                    //        timer[i] = 0;
                    //        timer_txt[i].text = "Ready";
                    //    }
                    //}
                    //else
                    //{
                    switch (scroll_rarity[i])
                    {
                    case rarity.r_common:
                        timer[i] = 3600 * 2;
                        break;

                    case rarity.r_uncommon:
                        timer[i] = 3600 * 6;
                        break;

                    case rarity.r_rare:
                        timer[i] = 3600 * 24;
                        break;
                    }
                    //}
                }

                scroll_go[i].SetActive(true);
            }
            Debug.Log("/n Rarity: " + scroll_type_num);
        }
    }