private IEnumerator RestorePlayerDataActions(string dataKey) { string URL = "/app/player/unlock"; IDictionary <string, object> reqBody = WebData.QuickDict("uid", Uid, "key", dataKey); WWW req = SignedWWW(URL, SigningKey, reqBody); yield return(req); }
private WWW LoginWWW() { IDictionary <string, object> loginBody = WebData.QuickDict( "uid", Uid, "now", UnixUtcNow()); return(SignedWWW("/app/multi/login", Encoding.UTF8.GetBytes(SecretKey), loginBody)); }
/// <summary> /// get list of previous players based on device id /// </summary> /// <returns></returns> private IEnumerator SearchPreviousPlayersActions() { string URL = "/app/player/device"; IDictionary <string, object> reqbody = WebData.QuickDict("dev", GetUniqueDeviceID()); Debug.Log(GetUniqueDeviceID()); byte[] appKey = Encoding.UTF8.GetBytes(ApplicationKey); yield return(SignedWWW(URL, appKey, reqbody)); }
private IEnumerator UnsignedRequestActions(string path, object reqBody, string appKey) { Dictionary <string, string> headers = new Dictionary <string, string>(); headers["x-tsumanga-app"] = appKey; WWW req = new WWW(WebServiceHost + path, Encoding.UTF8.GetBytes(WebData.JsonSerialise(reqBody)), headers); yield return(req); }
/// <summary> /// Checks the verified purchase result. /// </summary> /// <returns><c>true</c>, if purchase result matches the provided nonce, <c>false</c> otherwise.</returns> /// <param name="result">Result of the IRequest returned from VerifyPurchase</param> /// <param name="nonce">Nonce string from the original request.</param> public bool CheckVerifiedPurchaseResult(IDictionary <string, object> result, string nonce) { if (!result.ContainsKey("ver")) { return(false); } string ver = result["ver"] as String; byte[] key = Encoding.UTF8.GetBytes(ApplicationKey); string expected = WebData.HexDigest(key, nonce + "OK"); return(expected == ver); }
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); } }
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); } }
private IEnumerator ChangeNicknameActions(string newNick) { // send request to change nickname IDictionary <string, object> reqBody = WebData.QuickDict("uid", Uid, "nik", newNick); WWW req = SignedWWW("/app/multi/rename", SigningKey, reqBody); yield return(req); if (String.IsNullOrEmpty(req.error)) { Nick = newNick; Banned = false; } }
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)); } } }
/// <summary> /// A WWW with an x-tsumanga-sign header signing the POST data /// using the specified key. /// </summary> /// <returns> /// The WWW object /// </returns> /// <param name='url'> /// URL (to be appended to the host from the constructor) /// </param> /// <param name='key'> /// A byte array that will be the HMAC key used to sign the data. /// </param> /// <param name='body'> /// An object that will be serialised to JSON and encoded as UTF8, /// which will then be used with the key to make an HMAC signature. /// </param> internal WWW SignedWWW(string url, byte[] key, object body, string methodOverride) { string json = (body is string) ? body as string : WebData.JsonSerialise(body); Dictionary <string, string> headers = new Dictionary <string, string>(); headers["Content-Type"] = "application/json"; byte[] data = Encoding.UTF8.GetBytes(json); // now use gzip content encoding if it makes the request smaller byte[] zippedData = WebData.Gzip(data); if (zippedData.Length < data.Length) { data = zippedData; headers["Content-Encoding"] = "gzip"; } headers["x-tsumanga-sign"] = WebData.HexDigest(key, data); if (methodOverride != null) { headers["X-HTTP-Method-Override"] = methodOverride; } return(new WWW(WebServiceHost + url, data, headers)); }
private IEnumerator RatePlayerActions(string to, string mesg, string board, int amount) { IDictionary <string, object> body = WebData.QuickDict("uid", Uid, "to", to, "msg", mesg, "inc", amount); yield return(SignedWWW("/app/message/rate/" + UrlEncode(board), SigningKey, body)); }
private IEnumerator RecvMessagesActions(int limit = 100) { IDictionary <string, object> body = WebData.QuickDict("uid", Uid, "lim", limit); yield return(SignedWWW("/app/message/recv", SigningKey, body)); }
private IEnumerator SendMessageActions(string to, string mesg) { IDictionary <string, object> body = WebData.QuickDict("uid", Uid, "to", to, "msg", mesg); yield return(SignedWWW("/app/message/send", SigningKey, body)); }
private IEnumerator PostScoreActions(string board, int score) { IDictionary <string, object> body = WebData.QuickDict("score", score); yield return(SignedWWW(String.Format("/app/player/{0}/score/{1}", Uid, UrlEncode(board)), SigningKey, body)); }
private IEnumerator UnlinkPlayerActions(string other) { IDictionary <string, object> linkBody = WebData.QuickDict("uid", Uid, "lnk", other); yield return(SignedWWW("/app/player/unlink", SigningKey, linkBody)); }