Exemple #1
0
 public void _RestoreOfflineSessions()
 {
     string[] _paths = Directory.GetFiles(RaqnStorage.DataPath() + "cache");
     for (int i = 0; i < _paths.Length; ++i)
     {
         string _dir  = Path.GetDirectoryName(_paths[i]);
         string _name = _paths[i].Substring(_dir.Length + 1);
         if (_name.StartsWith(Raqn.Dix.Id + "_L$") && _name.EndsWith(".json"))
         {
             RaqnPlaySession _pl = RaqnPlaySession.Load <RaqnPlaySession>(_name);
             if (_pl == null)
             {
                 File.Delete(_paths[i]);
             }
             else
             {
                 _pl.Sync(() =>
                 {
                     Debug.Log("Playsession synced OK!");
                     File.Delete(_paths[i]);
                 }, (_err) =>
                 {
                     Debug.Log("Error syncing playsession, until next time!");
                 });
             }
         }
     }
 }
 static public bool StartOfflinePlay()
 {
     if (PlaySession != null || local_login == null || local_license == null || local_license.energy <= local_license.per_session)
     {
         return(false);
     }
     if (ApiSession == null)
     {
         ApiSession = new RaqnApiSession();
         ApiSession.logins.Add(local_login);
     }
     if (PlaySession == null)
     {
         PlaySession         = new RaqnPlaySession();
         PlaySession.dix     = Dix.Id;
         PlaySession.license = local_license.id;
         RaqnPlayer _p = new RaqnPlayer();
         _p.id       = local_login.user.id;
         _p.nickname = local_login.user.profile.nickname;
         _p.avatar   = local_login.user.profile.avatar;
         PlaySession.players.Add(_p);
         PlaySession.InitSessionData(ApiSession.id, Dix.Id, Dix.Package);
         ApiSession.play = PlaySession.id;
     }
     ExpendEnergy(License.per_session);
     RaqnStorage.SaveJson <RaqnLicense>("cache/license.dat", local_license, false, Dix.Secret);
     return(true);
 }
        protected void OnPlay_Success()
        {
            //ApiSession = Api.GetSession();
            PlaySession = Api.GetPlaySession();
            if (PlaySession == null)
            {
                OnPlay_Error(ResponseStatus.ERR_FORMATTING);
            }
            //init session data for all players
            PlaySession.InitSessionData(ApiSession.id, Dix.Id, Dix.Package);
            RaqnStorage.SaveJson <RaqnLicense>("cache/license.dat", local_license, false, Dix.Secret);

            ExpendEnergy(License.per_session);
            GameData.UpdateStatDelta("RAQN.TotalUses", 1);
            OnSync += () =>
            {
                Api.LicenseCurrent(Dix.Id, (lic) =>
                {
                    local_license = lic;
                });
            };
            SyncJob();
            if (OnPlay != null)
            {
                OnPlay();
            }
        }
Exemple #4
0
        public Coroutine SyncPlaySession(RaqnPlaySession _ps, Action <RaqnPlaySession> OnReady = null, Action <string> OnError = null)
        {
            RaqnRequest _req = new RaqnRequest("/play/sync");

            _req.SetField <RaqnPlaySession>("playsession", _ps);
            _req.SetField <string>("time", RaqnTime.LocalNow());
            if (OnReady != null)
            {
                _req.OnSuccess += RaqnUtils.ComposeAction <RaqnResponse, RaqnPlaySession>(OnReady, _ResponseParser <RaqnPlaySession>("_playsession"));
            }
            if (OnError != null)
            {
                _req.OnError += OnError;
            }
            return(Raqn.Instance.StartCoroutine(SendRequest(_req)));
        }
Exemple #5
0
        protected void _UpdateFromResponse(RaqnResponse _res)
        {
            string          _auth;
            RaqnApiSession  _session;
            RaqnPlaySession _playSession;

            if (_res.TryGetData <string>("_auth", out _auth))
            {
                this.auth = _auth;
            }
            if (_res.TryGetData <RaqnApiSession>("_session", out _session))
            {
                this.session = _session;
            }
            if (_res.TryGetData <RaqnPlaySession>("_playsession", out _playSession))
            {
                this.playSession = _playSession;
            }
        }
 public RaqnPlayDataController(string _player_id, RaqnPlaySession _playsession)
 {
     player_id   = _player_id;
     playsession = _playsession;
 }
 public RaqnPlayDataController()
 {
     player_id   = null;
     playsession = null;
 }