Example #1
0
        public static void ChangePassword(string email, string currentPassword, string newPassword, Action <bool> callback)
        {
            string auth = System.Convert.ToBase64String(Encoding.UTF8.GetBytes("email|" + email + "|" + currentPassword));
            Dictionary <string, string> body = new Dictionary <string, string>();

            body.Add("password", newPassword);
            GamedoniaBackend.RunCoroutine(
                GamedoniaRequest.post("/account/password/change", JsonMapper.ToJson(body), auth, null, null,
                                      delegate(bool success, object data) {
                if (callback != null)
                {
                    callback(success);
                }
            }
                                      )
                );
        }
Example #2
0
 public static void LinkUser(Credentials credentials, Action <bool, GDUserProfile> callback)
 {
     GamedoniaBackend.RunCoroutine(
         GamedoniaRequest.post("/account/link", JsonMapper.ToJson(credentials), null, sessionToken.session_token, null,
                               delegate(bool success, object data) {
         if (success)
         {
             me = DeserializeUserProfile((string)data);
         }
         if (callback != null)
         {
             callback(success, me);
         }
     }
                               )
         );
 }
Example #3
0
        public static void ResetPassword(string email, Action <bool> callback)
        {
            Dictionary <string, string> body = new Dictionary <string, string>();

            body.Add("email", email);

            GamedoniaBackend.RunCoroutine(
                GamedoniaRequest.post("/account/password/reset", JsonMapper.ToJson(body), null, null, null,
                                      delegate(bool success, object data) {
                if (callback != null)
                {
                    callback(success);
                }
            }
                                      )
                );
        }
Example #4
0
        public static void LogoutUser(Action <bool> callback)
        {
            Dictionary <string, string> body = new Dictionary <string, string>();

            body.Add(GamedoniaRequest.GD_SESSION_TOKEN, sessionToken.session_token);

            GamedoniaBackend.RunCoroutine(
                GamedoniaRequest.post("/account/logout", JsonMapper.ToJson(body), null, sessionToken.session_token, null,
                                      delegate(bool success, object data) {
                if (callback != null)
                {
                    callback(success);
                }
            }
                                      )
                );
        }
Example #5
0
        public static void Update(string collection, Dictionary <string, object> entity, Action <bool, IDictionary> callback = null, bool overwrite = false)
        {
            string json = JsonMapper.ToJson(entity);

            if (!overwrite)
            {
                GamedoniaBackend.RunCoroutine(
                    GamedoniaRequest.post("/data/" + collection + "/update", json, null, GamedoniaUsers.GetSessionToken(), null,
                                          delegate(bool success, object data) {
                    if (callback != null)
                    {
                        if (success)
                        {
                            callback(success, Json.Deserialize((string)data) as IDictionary);
                        }
                        else
                        {
                            callback(success, null);
                        }
                    }
                }
                                          )
                    );
            }
            else
            {
                GamedoniaBackend.RunCoroutine(
                    GamedoniaRequest.put("/data/" + collection + "/update", json, null, GamedoniaUsers.GetSessionToken(), null,
                                         delegate(bool success, object data) {
                    if (callback != null)
                    {
                        if (success)
                        {
                            callback(success, Json.Deserialize((string)data) as IDictionary);
                        }
                        else
                        {
                            callback(success, null);
                        }
                    }
                }
                                         )
                    );
            }
        }
Example #6
0
 public static void StartMatch(string matchId, Action <bool, GDMatch> callback = null)
 {
     GamedoniaBackend.RunCoroutine(
         GamedoniaRequest.post("/matchmaking/start/" + matchId, "{}", null, GamedoniaUsers.GetSessionToken(), null,
                               delegate(bool success, object data) {
         GDMatch startedMatch = null;
         if (success)
         {
             startedMatch = DeserializeMatch((string)data);
         }
         if (callback != null)
         {
             callback(success, startedMatch);
         }
     }
                               )
         );
 }
 public static void GetMe(Action <bool, GDUserProfile> callback)
 {
     GamedoniaBackend.RunCoroutine(
         GamedoniaRequest.get("/account/me", sessionToken.session_token,
                              delegate(bool success, object data) {
         //if (success) me = JsonMapper.ToObject<GDUserProfile>((string)data);
         if (success)
         {
             me = DeserializeUserProfile((string)data);
         }
         if (callback != null)
         {
             callback(success, me);
         }
     }
                              )
         );
 }
Example #8
0
        public static void Search(string collection, string query, int limit = 0, string sort = null, int skip = 0, Action <bool, IList> callback = null)
        {
            query = Uri.EscapeDataString(query);
            string url = "/data/" + collection + "/search?query=" + query;

            if (limit > 0)
            {
                url += "&limit=" + limit;
            }
            if (sort != null)
            {
                url += "&sort=" + sort;
            }
            if (skip > 0)
            {
                url += "&skip=" + skip;
            }

            GamedoniaBackend.RunCoroutine(
                GamedoniaRequest.get(url, GamedoniaUsers.GetSessionToken(),
                                     delegate(bool success, object data) {
                if (callback != null)
                {
                    if (success)
                    {
                        if ((data == null) || (data.Equals("[]")))
                        {
                            callback(success, null);
                        }
                        else
                        {
                            callback(success, Json.Deserialize((string)data) as IList);
                        }
                    }
                    else
                    {
                        callback(success, null);
                    }
                }
            }
                                     )
                );
        }
        public static void Search(string query, int limit = 0, string sort = null, int skip = 0, Action <bool, IList> callback = null)
        {
            string url = "/account/search?query=" + query;

            if (limit > 0)
            {
                url += "&limit=" + limit;
            }
            if (sort != null)
            {
                url += "&sort=" + sort;
            }
            if (skip > 0)
            {
                url += "&skip=" + skip;
            }

            GamedoniaBackend.RunCoroutine(
                GamedoniaRequest.get(url, sessionToken.session_token,
                                     delegate(bool success, object data) {
                if (callback != null)
                {
                    if (success)
                    {
                        if ((data == null) || (data.Equals("[]")))
                        {
                            callback(success, null);
                        }
                        else
                        {
                            callback(success, Json.Deserialize((string)data) as IList);
                        }
                    }
                    else
                    {
                        callback(success, null);
                    }
                }
            }
                                     )
                );
        }
Example #10
0
 public static void Get(string collection, string entityId, Action <bool, IDictionary> callback = null)
 {
     GamedoniaBackend.RunCoroutine(
         GamedoniaRequest.get("/data/" + collection + "/get/" + entityId, GamedoniaUsers.GetSessionToken(),
                              delegate(bool success, object data) {
         if (callback != null)
         {
             if (success)
             {
                 callback(success, Json.Deserialize((string)data) as IDictionary);
             }
             else
             {
                 callback(success, null);
             }
         }
     }
                              )
         );
 }
Example #11
0
        public static void CreateMatch(GDMatch match, Action <bool, GDMatch> callback = null)
        {
            string json = JsonMapper.ToJson(match);

            GamedoniaBackend.RunCoroutine(
                GamedoniaRequest.post("/matchmaking/create", json, null, GamedoniaUsers.GetSessionToken(), null,
                                      delegate(bool success, object data) {
                GDMatch createdMatch = null;
                if (success)
                {
                    createdMatch = DeserializeMatch((string)data);
                }
                if (callback != null)
                {
                    callback(success, createdMatch);
                }
            }
                                      )
                );
        }
Example #12
0
 public static void GetMatch(string matchId, Action <bool, GDMatch, List <GDMatchEvent> > callback = null)
 {
     GamedoniaBackend.RunCoroutine(
         GamedoniaRequest.get("/matchmaking/get/" + matchId, GamedoniaUsers.GetSessionToken(),
                              delegate(bool success, object data) {
         GDMatch match = null;
         List <GDMatchEvent> events = new List <GDMatchEvent>();
         if (success)
         {
             Dictionary <string, object> result = (Dictionary <string, object>)Json.Deserialize((string)data);
             match  = DeserializeMatch(result["match"] as Dictionary <string, object>);
             events = DeserializeMatchEvents(result["events"] as List <object>);
         }
         if (callback != null)
         {
             callback(success, match, events);
         }
     }
                              )
         );
 }
Example #13
0
        public static void GetMatches(string state, int limit = 0, string sort = null, int skip = 0, Action <bool, List <GDMatch>, Dictionary <string, List <GDMatchEvent> > > callback = null)
        {
            string queryString = "state=" + state;

            if (limit > 0)
            {
                queryString += "&limit=" + limit;
            }
            if (sort != null)
            {
                queryString += "&sort=" + Uri.EscapeDataString(sort);
            }
            if (skip > 0)
            {
                queryString += "&skip=" + skip;
            }

            string url = "/matchmaking/search?" + queryString;

            Debug.Log(url);
            GamedoniaBackend.RunCoroutine(
                GamedoniaRequest.get(url, GamedoniaUsers.GetSessionToken(),
                                     delegate(bool success, object data) {
                List <GDMatch> matches = new List <GDMatch>();
                Dictionary <string, List <GDMatchEvent> > events = new Dictionary <string, List <GDMatchEvent> >();
                if (success)
                {
                    Debug.Log("GetMatches worked!");
                    Dictionary <string, object> result = (Dictionary <string, object>)Json.Deserialize((string)data);
                    matches = DeserializeMatches(result["matches"] as List <object>);
                    events  = DeserializeMatchEvents(result["events"] as Dictionary <string, object>);
                }
                if (callback != null)
                {
                    callback(success, matches, events);
                }
            }
                                     )
                );
        }
        public static void GetUser(string userId, Action <bool, GDUserProfile> callback)
        {
            Dictionary <string, string> body = new Dictionary <string, string>();

            body.Add("_id", userId);

            GamedoniaBackend.RunCoroutine(
                GamedoniaRequest.post("/account/retrieve", JsonMapper.ToJson(body), null, sessionToken.session_token, null,
                                      delegate(bool success, object data) {
                GDUserProfile user = null;
                if (success)
                {
                    user = DeserializeUserProfile((string)data);
                }
                if (callback != null)
                {
                    callback(success, user);
                }
            }
                                      )
                );
        }
Example #15
0
        private void RequestAndAddDownload(string fileId)
        {
            string url = "/file/get/url/" + fileId;


            GamedoniaBackend.RunCoroutine(
                GamedoniaRequest.get(url, GamedoniaUsers.GetSessionToken(),
                                     delegate(bool success, object data) {
                if (success)
                {
                    //Debug.Log("Before Internal Download URL");
                    IDictionary dataDownload = Json.Deserialize((string)data) as IDictionary;
                    InternalAddDownloadURL(dataDownload["downloadUrl"] as string, fileId);
                }
                else
                {
                    InternalAddDownloadURL(fileId, fileId);
                }
            }
                                     )
                );
        }
        public static void LoginUserWithSessionToken(Action <bool> callback)
        {
            string session_token = PlayerPrefs.GetString("gd_session_token");

            if (session_token != null && session_token.Length > 0)
            {
                string auth = System.Convert.ToBase64String(Encoding.UTF8.GetBytes("session_token|" + session_token));

                Dictionary <string, string> body = new Dictionary <string, string> ();
                body.Add(GamedoniaRequest.GD_AUTH, auth);
                GamedoniaBackend.RunCoroutine(
                    GamedoniaRequest.post("/account/login", JsonMapper.ToJson(body), auth, null, null,
                                          delegate(bool success, object data) {
                    if (success)
                    {
                        sessionToken = JsonMapper.ToObject <GDSessionToken> ((string)data);
                        RegisterDeviceAfterLogin(callback);
                    }
                    else
                    {
                        if (callback != null)
                        {
                            callback(success);
                        }
                    }
                }
                                          )
                    );
            }
            else
            {
                Debug.LogWarning("No sessionToken stored in PlayerPrefs");
                if (callback != null)
                {
                    callback(false);
                }
            }
        }
        public static void Count(string query, Action <bool, int> callback = null)
        {
            string url = "/account/count?query=" + query;

            GamedoniaBackend.RunCoroutine(
                GamedoniaRequest.get(url, sessionToken.session_token, delegate(bool success, object data)
            {
                if (callback != null)
                {
                    if (success)
                    {
                        IDictionary response = Json.Deserialize((string)data) as IDictionary;
                        int count            = int.Parse(response["count"].ToString());
                        callback(success, count);
                    }
                    else
                    {
                        callback(success, -1);
                    }
                }
            })
                );
        }
Example #18
0
        public void Awake()
        {
            //make sure we only have one object with this Gamedonia script at any time
            if (_instance != null)
            {
                Destroy(gameObject);
                return;
            }

            if (ApiKey.Equals("") || Secret.Equals(""))
            {
                Debug.LogError("Gamedonia Error: Missing value for ApiKey / Secret Gamedonia will not work!");
                Destroy(gameObject);
                return;
            }

            _instance = this;
            DontDestroyOnLoad(this);
            GamedoniaRequest.initialize(ApiKey, Secret, ApiServerUrl, ApiVersion.ToString());
            Debug.Log("Gamedonia initialized successfully");

            initJsonMapper();
        }
 public static void UpdateUser(Dictionary <string, object> profile, Action <bool> callback = null, bool overwrite = false)
 {
     if (!overwrite)
     {
         GamedoniaBackend.RunCoroutine(
             GamedoniaRequest.post("/account/update", JsonMapper.ToJson(profile), null, sessionToken.session_token, null,
                                   delegate(bool success, object data) {
             if (success)
             {
                 me = DeserializeUserProfile((string)data);
             }
             if (callback != null)
             {
                 callback(success);
             }
         }
                                   )
             );
     }
     else
     {
         GamedoniaBackend.RunCoroutine(
             GamedoniaRequest.put("/account/update", JsonMapper.ToJson(profile), null, sessionToken.session_token, null,
                                  delegate(bool success, object data) {
             if (success)
             {
                 me = DeserializeUserProfile((string)data);
             }
             if (callback != null)
             {
                 callback(success);
             }
         }
                                  )
             );
     }
 }
Example #20
0
 /*
  * TODO Easy method for matchmaking
  */
 public static void QuickMatch(GDMatch match, string criteria, int requiredPlayers, int searchTime, Action <bool, GDMatch> callback = null)
 {
     GamedoniaMatchMaking.FindMatches(criteria, 0,
                                      delegate(bool success, List <GDMatch> foundMatches) {
         if (success)
         {
             if (foundMatches.Count > 0)
             {
                 //Join Match
                 GamedoniaMatchMaking.JoinMatch(foundMatches[0]._id,
                                                delegate(bool joinSuccess, GDMatch joinedMatch) {
                     if (success)
                     {
                         GamedoniaBackend.RunCoroutine(
                             GamedoniaMatchMaking.IsMatchReady(joinedMatch._id, requiredPlayers, searchTime,
                                                               delegate(bool isReady) {
                             if (isReady)
                             {
                                 GamedoniaMatchMaking.StartMatch(joinedMatch._id,
                                                                 delegate(bool startSucces, GDMatch startedMatch) {
                                     if (startSucces)
                                     {
                                         callback(true, startedMatch);
                                     }
                                     else
                                     {
                                         callback(false, null);
                                     }
                                 }
                                                                 );
                             }
                             else
                             {
                                 callback(false, null);
                             }
                         }
                                                               )
                             );
                     }
                 }
                                                );
             }
             else
             {
                 GamedoniaMatchMaking.CreateMatch(match, delegate(bool successCreate, GDMatch createdMatch) {
                     if (successCreate)
                     {
                         GamedoniaBackend.RunCoroutine(
                             GamedoniaMatchMaking.IsMatchReady(createdMatch._id, requiredPlayers, searchTime,
                                                               delegate(bool isReady) {
                             if (isReady)
                             {
                                 GamedoniaMatchMaking.StartMatch(createdMatch._id,
                                                                 delegate(bool startSucces, GDMatch startedMatch) {
                                     if (startSucces)
                                     {
                                         callback(true, startedMatch);
                                     }
                                     else
                                     {
                                         callback(false, null);
                                     }
                                 }
                                                                 );
                             }
                             else
                             {
                                 callback(false, null);
                             }
                         }
                                                               )
                             );
                     }
                 });
             }
         }
     }
                                      );
 }
Example #21
0
 private void DownloadFile(string tempFilename, string url, long downloadedBytes)
 {
     GamedoniaBackend.RunCoroutine(InternalDownloadFile(tempFilename, url, downloadedBytes));
 }
Example #22
0
 private void GetFileConentLength(string tempFilename, string url, Action <long> callback)
 {
     GamedoniaBackend.RunCoroutine(InternalGetFileConentLength(tempFilename, url, callback));
 }
Example #23
0
        public void Awake()
        {
            //make sure we only have one object with this Gamedonia script at any time
            if (_instance != null)
            {
                Destroy(gameObject);
                return;
            }

            if (ApiKey.Equals("") || Secret.Equals(""))
            {
                Debug.LogError("Gamedonia Error: Missing value for ApiKey / Secret Gamedonia will not work!");
                Destroy(gameObject);
                return;
            }

            _instance = this;
            DontDestroyOnLoad(this);
            GamedoniaRequest.initialize(ApiKey,Secret, ApiServerUrl, ApiVersion.ToString());
            Debug.Log ("Gamedonia initialized successfully");

            initJsonMapper ();
        }
Example #24
0
 public static void isFacebookTokenValid(string accessToken, Action <bool> callback)
 {
     GamedoniaBackend.RunCoroutine(
         _isFacebookTokenValid(accessToken, callback)
         );
 }
Example #25
0
        public static void Authenticate(GamedoniaBackend.CredentialsType authenticationType, Dictionary<string,object> credentials, Action<bool> callback)
        {
            IGamedoniaAuthentication authentication = null;
            switch (authenticationType) {
                case GamedoniaBackend.CredentialsType.GAMECENTER:
                    authentication = new GamecenterAuthentication();
                    break;
                case GamedoniaBackend.CredentialsType.FACEBOOK:
                    authentication = new FacebookAuthentication((string) credentials["fb_uid"], (string) credentials["fb_access_token"]);
                    break;
                case GamedoniaBackend.CredentialsType.SILENT:
                    authentication = new SilentAuthentication();
                    break;
                case GamedoniaBackend.CredentialsType.GOOGLE:
                    authentication = new GoogleAuthentication();
                    break;
                default:
                    authentication = new SessionTokenAuthentication();
                    break;
            }

            authentication.Authenticate(callback);
        }