public static void Find(ServervilleClient server, string id, Action <KeyData> onDone) { if (server == null) { throw new Exception("Must supply a server"); } if (id == null) { if (server.GetUserInfo() == null) { throw new Exception("Server not yet logged in"); } id = server.GetUserInfo().user_id; } server.GetKeyDataRecord(id, delegate(KeyDataInfo info) { KeyData inst = new KeyData(server, info); if (onDone != null) { onDone(inst); } }, delegate(ErrorReply reply) { if (onDone != null) { onDone(null); } }); }
public ServervilleWS(ServervilleClient sv) { SV = sv; ReplyQueue = new Queue <string>(); SwapQueue = new Queue <string>(); }
private KeyData(ServervilleClient server, KeyDataInfo info) { Server = server; Id = info.id; RecordInfo = info; Keys = new Dictionary<string, DataItemReply>(); DirtyKeys = new Dictionary<string, DataItemReply>(); }
private KeyData(ServervilleClient server, KeyDataInfo info) { Server = server; Id = info.id; RecordInfo = info; Keys = new Dictionary <string, DataItemReply>(); DirtyKeys = new Dictionary <string, DataItemReply>(); }
public static void Load(ServervilleClient server, string id, Action<KeyData> onDone) { Find(server, id, delegate(KeyData obj) { if(obj == null) { onDone(null); return; } obj.LoadAll( delegate(bool success) { onDone(obj); } ); } ); }
public static void Load(ServervilleClient server, string id, Action <KeyData> onDone) { Find(server, id, delegate(KeyData obj) { if (obj == null) { onDone(null); return; } obj.LoadAll(delegate(bool success) { onDone(obj); } ); } ); }
// Use this for initialization void Start() { ConsoleText.text = ""; string url = "ws://localhost:8000"; Log("Connecting to " + url); ServervilleClient sv = new ServervilleClient(url); sv.Init(delegate(SignInReply userInfo, ErrorReply initErr) { if (initErr != null) { Log("Got an error: " + initErr.errorMessage); return; } else if (userInfo != null) { Log("Signed in"); return; } else { Log("Initted"); } Debug.Log("Signing into test account"); sv.SignIn("testuser1", null, "testuser1", delegate(SignInReply reply) { Log("Signed in with session " + reply.session_id); }, delegate(ErrorReply err) { Log("Error signing in " + err.errorMessage); } ); }); }
// Use this for initialization void Start () { ConsoleText.text = ""; string url = "ws://localhost:8000"; Log("Connecting to "+url); ServervilleClient sv = new ServervilleClient(url); sv.Init(delegate(SignInReply userInfo, ErrorReply initErr) { if(initErr != null) { Log("Got an error: "+initErr.errorMessage); return; } else if(userInfo != null) { Log("Signed in"); return; } else { Log("Initted"); } Debug.Log("Signing into test account"); sv.SignIn("testuser1", null, "testuser1", delegate(SignInReply reply) { Log("Signed in with session "+reply.session_id); }, delegate(ErrorReply err) { Log("Error signing in "+err.errorMessage); } ); }); }
public static void Find(ServervilleClient server, string id, Action<KeyData> onDone) { if(server == null) throw new Exception("Must supply a server"); if(id == null) { if(server.GetUserInfo() == null) throw new Exception("Server not yet logged in"); id = server.GetUserInfo().user_id; } server.GetKeyDataRecord(id, delegate(KeyDataInfo info) { KeyData inst = new KeyData(server, info); if(onDone != null) onDone(inst); }, delegate(ErrorReply reply) { if(onDone != null) onDone(null); }); }
private void GetNotifications(ServervilleClient sv) { string url = sv.ServerURL + "/notifications"; StartCoroutine(PostJSON(sv, url, "{}", typeof(PendingNotificationList), sv.SessionId, delegate(object reply) { PendingNotificationList notifications = (PendingNotificationList)reply; if (notifications.notifications == null) { return; } foreach (PendingNotification note in notifications.notifications) { sv.OnServerNotification(note.notification_type, note.body); } }, delegate(ErrorReply err) { Debug.LogError("Error getting notifications" + err.errorMessage); } )); }
public IEnumerator PostJSON(ServervilleClient sv, string url, string request, Type replyType, string sessionId, Action <object> onSuccess, OnErrorReply onError) { using (UnityWebRequest www = new UnityWebRequest(url)) { www.method = UnityWebRequest.kHttpVerbPOST; UploadHandlerRaw upload = new UploadHandlerRaw(Encoding.UTF8.GetBytes(request)); upload.contentType = "application/json"; www.uploadHandler = upload; www.disposeUploadHandlerOnDispose = true; DownloadHandlerBuffer buffer = new DownloadHandlerBuffer(); www.downloadHandler = buffer; www.disposeDownloadHandlerOnDispose = true; if (sessionId != null) { www.SetRequestHeader("Authorization", sessionId); } if (sv.LogMessages) { Debug.Log("HTTP<- " + request); } yield return(www.Send()); if (www.isError) { ErrorReply err = ErrorReply.makeClientErrorCode(-2, www.error); if (onError != null) { onError(err); } yield break; } if (sv.LogMessages) { Debug.Log("HTTP-> " + buffer.text); } if (www.responseCode >= 200 && www.responseCode < 400) { object reply = JsonConvert.DeserializeObject(buffer.text, replyType, ServervilleHttp.JsonSettings); if (onSuccess != null) { onSuccess(reply); } } else { ErrorReply err = JsonConvert.DeserializeObject <ErrorReply>(buffer.text, ServervilleHttp.JsonSettings); sv.OnServerError(err); if (onError != null) { onError(err); } } if (www.GetResponseHeader("X-Notifications") != null) { // Pending notifications from the server! GetNotifications(sv); } } }
public ServervilleHttp(ServervilleClient sv) { SV = sv; }