Esempio n. 1
0
        public static void FindMatches(string query, int limit = 0, Action <bool, List <GDMatch> > callback = null)
        {
            string url = "/matchmaking/find?query=" + query;

            if (limit > 0)
            {
                url += "&limit=" + limit;
            }

            GamedoniaBackend.RunCoroutine(
                GamedoniaRequest.get(url, GamedoniaUsers.GetSessionToken(),
                                     delegate(bool success, object data) {
                if (callback != null)
                {
                    if (success)
                    {
                        if ((data == null) || (data.Equals("[]")))
                        {
                            callback(success, new List <GDMatch>());
                        }
                        else
                        {
                            List <GDMatch> matches = DeserializeMatches((string)data);
                            callback(success, matches);
                        }
                    }
                    else
                    {
                        callback(success, null);
                    }
                }
            }
                                     )
                );
        }
Esempio n. 2
0
        public static void Run(string script, Dictionary <string, object> parameters, Action <bool, object> callback = null)
        {
            string json = "{}";

            if (parameters != null)
            {
                json = JsonMapper.ToJson(parameters);
            }

            GamedoniaBackend.RunCoroutine(
                GamedoniaRequest.post("/run/" + script, json, null, GamedoniaUsers.GetSessionToken(), null,
                                      delegate(bool success, object data) {
                if (callback != null)
                {
                    if (success)
                    {
                        string strData = data as String;
                        if (strData.Length > 0)
                        {
                            callback(success, Json.Deserialize(strData));
                        }
                        else
                        {
                            callback(success, null);
                        }
                    }
                    else
                    {
                        callback(success, null);
                    }
                }
            }
                                      )
                );
        }
        public void Authenticate(Action <bool> callback)
        {
            if (GamedoniaBackend.INSTANCE.debug)
            {
                Debug.Log("Facebook Authentication");
            }
            _callback = callback;

            if (!String.IsNullOrEmpty(_fb_uid) && !String.IsNullOrEmpty(_fb_access_token))
            {
                GDUser      user        = new GDUser();
                Credentials credentials = new Credentials();
                credentials.fb_uid          = _fb_uid;
                credentials.fb_access_token = _fb_access_token;
                user.credentials            = credentials;

                GamedoniaUsers.CreateUser(user, ProcessCreateUser);
            }
            else
            {
                Debug.LogError("Facebook id or token not present impossible to perform login with it");
                if (_callback != null)
                {
                    _callback(false);
                }
            }
        }
Esempio n. 4
0
        public static void Count(string collection, string query, Action <bool, int> callback = null)
        {
            query = Uri.EscapeDataString(query);
            string url = "/data/" + collection + "/count?query=" + query;

            GamedoniaBackend.RunCoroutine(
                GamedoniaRequest.get(url, GamedoniaUsers.GetSessionToken(),
                                     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);
                    }
                }
            }
                                     )
                );
        }
 void ProcessLogin(bool success)
 {
     if (success)
     {
         if (GamedoniaUsers.me == null)
         {
             GamedoniaUsers.GetMe(HandleGetMe);
         }
         else
         {
             if (this.callback != null)
             {
                 callback(success);
             }
         }
     }
     else
     {
         Debug.LogError("Gamedonia session couldn't be started!");
         if (this.callback != null)
         {
             callback(false);
         }
     }
 }
 void ProcessCreateUser(bool success)
 {
     if (Social.localUser.authenticated)
     {
         //Login with gamecenter id
         GamedoniaUsers.LoginUserWithGameCenterId(Social.localUser.id, ProcessLogin);
     }
     else
     {
         //Login with open_udid
         GamedoniaUsers.LoginUserWithOpenUDID(OpenUDIDPlugin.GetOpenUDID(), null);
     }
 }
Esempio n. 7
0
        public static void VerifyPurchase(Dictionary <string, object> parameters, Action <bool> callback = null)
        {
            string json = JsonMapper.ToJson(parameters);

            GamedoniaBackend.RunCoroutine(
                GamedoniaRequest.post("/purchase/verify", json, null, GamedoniaUsers.GetSessionToken(), null,
                                      delegate(bool success, object data) {
                if (callback != null)
                {
                    callback(success);
                }
            }
                                      )
                );
        }
        void ProcessAuthentication(bool success)
        {
            GDUser      user        = new GDUser();
            Credentials credentials = new Credentials();

            credentials.open_udid = OpenUDIDPlugin.GetOpenUDID();
            user.credentials      = credentials;

            if (success)
            {
                credentials.gamecenter_id = Social.localUser.id;
            }

            GamedoniaUsers.CreateUser(user, ProcessCreateUser);
        }
        public void Authenticate(Action <bool> callback)
        {
            if (GamedoniaBackend.INSTANCE.debug)
            {
                Debug.Log("Silent Authentication");
            }
            this.callback = callback;

            GDUser      user        = new GDUser();
            Credentials credentials = new Credentials();

            credentials.open_udid = GamedoniaSilent.GetSilentId();
            user.credentials      = credentials;

            GamedoniaUsers.CreateUser(user, ProcessCreateUser);
        }
Esempio n. 10
0
        public static void Delete(string collection, List <string> entities, bool all, Action <bool, int> callback = null)
        {
            string sessionToken = null;

            if (GamedoniaUsers.isLoggedIn())
            {
                sessionToken = GamedoniaUsers.GetSessionToken();
            }
            //string sessionToken =

            if (all)
            {
                GamedoniaBackend.RunCoroutine(
                    GamedoniaRequest.delete("/data/" + collection + "/delete?all=true", sessionToken,
                                            delegate(bool success, object data) {
                    IDictionary response = Json.Deserialize((string)data) as IDictionary;
                    if (success)
                    {
                        callback(success, int.Parse(response["deleted"].ToString()));
                    }
                    else
                    {
                        callback(success, 0);
                    }
                }
                                            )
                    );
            }
            else
            {
                GamedoniaBackend.RunCoroutine(
                    GamedoniaRequest.delete("/data/" + collection + "/delete?keys=" + String.Join(",", entities.ToArray()), sessionToken,
                                            delegate(bool success, object data) {
                    IDictionary response = Json.Deserialize((string)data) as IDictionary;
                    if (success)
                    {
                        callback(success, int.Parse(response["deleted"].ToString()));
                    }
                    else
                    {
                        callback(success, 0);
                    }
                }
                                            )
                    );
            }
        }
Esempio n. 11
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);
         }
     }
                               )
         );
 }
Esempio n. 12
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);
                    }
                }
            }
                                     )
                );
        }
Esempio n. 13
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);
                }
            }
                                      )
                );
        }
Esempio n. 14
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);
             }
         }
     }
                              )
         );
 }
Esempio n. 15
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);
         }
     }
                              )
         );
 }
Esempio n. 16
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);
                }
            }
                                     )
                );
        }
Esempio n. 17
0
        public void Authenticate(Action <bool> callback)
        {
            if (GamedoniaBackend.INSTANCE.debug)
            {
                Debug.Log("Session Token Authentication");
            }
            this.callback = callback;
            string session_token = PlayerPrefs.GetString("gd_session_token");

            if (!String.IsNullOrEmpty(session_token))
            {
                GamedoniaUsers.LoginUserWithSessionToken(ProcessLogin);
            }
            else
            {
                Debug.LogError("Session Token not present impossible to perform login with it");
                if (this.callback != null)
                {
                    callback(false);
                }
            }
        }
Esempio n. 18
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);
                }
            }
                                     )
                );
        }
Esempio n. 19
0
        void OnGoogleSignIn(bool success, bool userCancelled, string message)
        {
            if (success)
            {
                Debug.Log(">>>>>> OnGoogleSignIn");
                _google_token_id = message;
                GDUser      user        = new GDUser();
                Credentials credentials = new Credentials();
                credentials.google_token_id = _google_token_id;
                user.credentials            = credentials;

                GamedoniaUsers.CreateUser(user, ProcessCreateUser);
            }
            else
            {
                Debug.LogError("Gamedonia session couldn't be started!");
                if (this.callback != null)
                {
                    callback(false);
                }
            }
        }
Esempio n. 20
0
        public static void Create(string collection, Dictionary <string, object> entity, Action <bool, IDictionary> callback = null)
        {
            string json = JsonMapper.ToJson(entity);

            GamedoniaBackend.RunCoroutine(
                GamedoniaRequest.post("/data/" + collection + "/create", 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);
                    }
                }
            }
                                      )
                );
        }
Esempio n. 21
0
 void ProcessCreateUser(bool success)
 {
     //Login with open_udid
     GamedoniaUsers.LoginUserWithFacebook(_fb_uid, _fb_access_token, ProcessLogin);
 }
Esempio n. 22
0
        public static void FinishMatch(string matchId, string winnerUserId = "", Action <bool, GDMatch> callback = null)
        {
            IDictionary <string, object> inputData = new Dictionary <string, object> ();

            if ("".Equals(winnerUserId))
            {
                inputData.Add("winnerId", winnerUserId);
            }

            GamedoniaBackend.RunCoroutine(
                GamedoniaRequest.post("/matchmaking/finish/" + matchId, Json.Serialize(inputData), null, GamedoniaUsers.GetSessionToken(), null,
                                      delegate(bool success, object data) {
                GDMatch finishedMatch = null;
                if (success)
                {
                    finishedMatch = DeserializeMatch((string)data);
                }
                if (callback != null)
                {
                    callback(success, finishedMatch);
                }
            }
                                      )
                );
        }
Esempio n. 23
0
 void ProcessCreateUser(bool success)
 {
     //Login with open_udid
     GamedoniaUsers.LoginUserWithOpenUDID(GamedoniaSilent.GetSilentId(), ProcessLogin);
 }
Esempio n. 24
0
 private static void RegisterDeviceAfterLogin(Action <bool> callback)
 {
     //if (GamedoniaBackend.INSTANCE.IsDeviceRegisterNeeded()) {
     GamedoniaDevices.GetProfile(
         delegate(bool successDevProfile, GDDeviceProfile device) {
         if (successDevProfile)
         {
             //switch(device.deviceType) {
             //case "ios":
             //case "android":
             if (GamedoniaUsers.me == null)
             {
                 GamedoniaUsers.GetMe(
                     delegate(bool success, GDUserProfile profile) {
                     if (success)
                     {
                         GamedoniaDevices.device.uid = GamedoniaUsers.me._id;
                         GamedoniaDevices.Register(device,
                                                   delegate(bool successRegister) {
                             if (callback != null)
                             {
                                 callback(successRegister);
                             }
                         }
                                                   );
                     }
                     else
                     {
                         if (callback != null)
                         {
                             callback(success);
                         }
                     }
                 }
                     );
             }
             else
             {
                 GamedoniaDevices.device.uid = GamedoniaUsers.me._id;
                 GamedoniaDevices.Register(device,
                                           delegate(bool successRegister) {
                     if (callback != null)
                     {
                         callback(successRegister);
                     }
                 }
                                           );
             }
             //break;
             //default:
             //if (callback != null) callback(successDevProfile);
             //break;
             //}
         }
         else
         {
             Debug.LogWarning("The device has not been registered due to an error");
             if (callback != null)
             {
                 callback(successDevProfile);
             }
         }
     }
         );
     //}else {
     //	if (callback != null) callback(true);
     //}
 }
Esempio n. 25
0
 void ProcessCreateUser(bool success)
 {
     Debug.Log(">>>>>> ProcessCreateUser");
     //Login with open_udid
     GamedoniaUsers.LoginUserWithGoogle(_google_token_id, ProcessLogin);
 }
Esempio n. 26
0
 public static void Delete(string collection, string entityId, Action <bool> callback = null)
 {
     GamedoniaBackend.RunCoroutine(
         GamedoniaRequest.delete("/data/" + collection + "/delete/" + entityId, GamedoniaUsers.GetSessionToken(),
                                 delegate(bool success, object data) {
         callback(success);
     }
                                 )
         );
 }