Example #1
0
        private void AfterLogin(WWW login)
        {
            IDictionary <string, object> result = WebData.DictFromBytes(login.bytes);

            SigningKey = Encoding.UTF8.GetBytes(result["key"] as string);
            object ttl = result["ttl"];

            if (ttl is double)
            {
                Int64 ttlTicks = (Int64)((double)ttl * TicksPerSecond);                   //  ten million ticks per second (100ns)
                LoginExpiry = DateTime.UtcNow + new TimeSpan(ttlTicks);
            }
        }
Example #2
0
        private IEnumerator RegisterPlayerActions(string nick, string locale, bool reclaim = false)
        {
            // This is the player's initial nickname
            Nick = nick;

            // generate secret key for new player
            RandomNumberGenerator gen = RandomNumberGenerator.Create();

            byte[] secretBytes = new byte[32];
            gen.GetBytes(secretBytes);
            SecretKey = WebData.BytesToHex(secretBytes);
            byte[] appKey = Encoding.UTF8.GetBytes(ApplicationKey);

            // yield a WWW object to get the new player's UUID
            IDictionary <string, object> reqBody = WebData.QuickDict(
                "nik", nick,
                "key", SecretKey,
                "dev", GetUniqueDeviceID(),
                "loc", locale
                );

            // if we want to re-register same name on same device as previously...
            if (reclaim)
            {
                reqBody["rec"] = true;
            }

            WWW req = SignedWWW("/app/multi/register", appKey, reqBody);

            yield return(req);

            if (String.IsNullOrEmpty(req.error))
            {
                IDictionary <string, object> resDict = WebData.DictFromBytes(req.bytes);
                if (resDict != null)
                {
                    Uid    = resDict["uid"] as string;
                    Banned = resDict.ContainsKey("ban") && (bool)(resDict["ban"]);
                }
                else
                {
                    Uid = null;
                    yield return(RequestStatus.FAIL_UNKNOWN);
                }
            }
            else
            {
                Debug.LogError("RegisterPlayer: " + req.error);
            }
        }
Example #3
0
        private IEnumerator GetServerTimeActions()
        {
            WWW req = new WWW(WebServiceHost + "/app/multi/time");

            yield return(req);

            if (String.IsNullOrEmpty(req.error))
            {
                IDictionary <string, object> result = WebData.DictFromBytes(req.bytes);
                if (result.ContainsKey("now"))
                {
                    double server_now = (double)result["now"];
                    double local_now  = UnixUtcNow();
                    double correction = server_now - local_now;
                    TimeOffsetFromServer += new TimeSpan((long)(correction * TicksPerSecond));
                }
            }
        }