public static int AddAvatar(ApiAvatar apiAvatar) { if (!InitConnection()) { return(-1); } SerializableApiAvatar avatar = new SerializableApiAvatar( apiAvatar.id, apiAvatar.name, apiAvatar.imageUrl, apiAvatar.authorName, apiAvatar.authorId, apiAvatar.assetUrl, apiAvatar.description, apiAvatar.tags, apiAvatar.version, apiAvatar.unityPackageUrl, apiAvatar.thumbnailImageUrl ); VRCTResponse response = RequestSync(new VRCTRequest("ADD", avatar.AsJson()).AsJson()); if (response.returncode != ReturnCodes.SUCCESS && response.returncode != ReturnCodes.AVATAR_ALREADY_IN_FAV) { if (response.returncode != ReturnCodes.BANNED_ADDRESS && response.returncode != ReturnCodes.BANNED_ACCOUNT) { VRCToolsLogger.Error("Unable to add avatar to favorites: error " + response.returncode); } return(response.returncode); } VRCToolsLogger.Info("Avatar added to favorites sucessfully"); return(ReturnCodes.SUCCESS); }
public static List <object> GetAvatars() { List <object> avatars = new List <object>(); VRCToolsLogger.Info("getAvatars"); if (!InitConnection()) { return(avatars); } VRCTRequest request = new VRCTRequest("GET", ""); VRCTResponse response = RequestSync(request.AsJson()); if (response.returncode != ReturnCodes.SUCCESS) { if (response.returncode != ReturnCodes.BANNED_ACCOUNT && response.returncode != ReturnCodes.BANNED_ADDRESS) { VRCToolsLogger.Error("Unable to get avatars: error code " + response.returncode); } return(avatars); } VRCToolsLogger.Info(response.data); List <SerializableApiAvatar> serializedAvatars = SerializableApiAvatar.ParseJson(response.data); foreach (SerializableApiAvatar serializedAvatar in serializedAvatars) { avatars.Add(serializedAvatar.getDictionary()); } return(avatars); }
/* * private static void Send(String request) * { * byte[] bytesToSend = ASCIIEncoding.ASCII.GetBytes(request + "\n"); * nwStream.Write(bytesToSend, 0, bytesToSend.Length); * nwStream.Flush(); * VRCToolsLogger.Info(">>> " + request); * } * * private static string Receive() * { * String r = ""; * while (true) * { * byte[] bytesToRead = new byte[client.ReceiveBufferSize]; * int bytesRead = nwStream.Read(bytesToRead, 0, client.ReceiveBufferSize); * string text = Encoding.ASCII.GetString(bytesToRead, 0, bytesRead); * r += text; * if (text.EndsWith("\n")) break; * else VRCToolsLogger.Info("response not ending with \\n, continuing reception..."); * } * VRCToolsLogger.Info("<<< " + r); * return r; * } */ private static VRCTResponse RequestSync(String request) { lock (requestLocker) { //Send(request); byte[] bytesToSend = ASCIIEncoding.ASCII.GetBytes(request + "\n"); nwStream.Write(bytesToSend, 0, bytesToSend.Length); nwStream.Flush(); VRCToolsLogger.Info(">>> " + request); //VRCTResponse response = JsonUtility.FromJson<VRCTResponse>(Receive()); String r = ""; while (true) { byte[] bytesToRead = new byte[client.ReceiveBufferSize]; int bytesRead = nwStream.Read(bytesToRead, 0, client.ReceiveBufferSize); string text = Encoding.ASCII.GetString(bytesToRead, 0, bytesRead); r += text; if (text.EndsWith("\n")) { break; } else { VRCToolsLogger.Info("response not ending with \\n, continuing reception..."); } } VRCToolsLogger.Info("<<< " + r); VRCTResponse response = JsonUtility.FromJson <VRCTResponse>(r); //VRCTResponse response = BestHTTP.JSON.Json.Decode(r) as VRCTResponse; if (response.returncode == ReturnCodes.BANNED_ACCOUNT) { VRCToolsLogger.Warn("Request rejected: Account banned (" + response.data + ")"); VRCToolsMainComponent.MessageGUI(Color.red, "Request rejected: Account banned (" + response.data + ")", 3); } else if (response.returncode == ReturnCodes.BANNED_ADDRESS) { VRCToolsLogger.Warn("Request rejected: Address banned (" + response.data + ")"); VRCToolsMainComponent.MessageGUI(Color.red, "Request rejected: Address banned (" + response.data + ")", 3); } return(response); } }
internal static void ShowMOTD() { if (!InitConnection()) { return; } VRCTRequest request = new VRCTRequest("GETMOTD", ""); VRCTResponse response = RequestSync(request.AsJson()); if (response.returncode == ReturnCodes.SUCCESS) { string[] motdLines = response.data.Split(new string[] { "<br />" }, StringSplitOptions.None); foreach (string line in motdLines) { VRCToolsMainComponent.MessageGUI(Color.white, line, 20); } } }
public static string GetLastestVersion() { if (!InitConnection()) { return(VRCToolsMainComponent.VERSION); } VRCTRequest request = new VRCTRequest("GETVERSION", ""); VRCTResponse response = RequestSync(request.AsJson()); if (response.returncode != ReturnCodes.WAITING_FOR_UPDATE && response.data != VRCToolsMainComponent.VERSION) { if (response.returncode != ReturnCodes.BANNED_ADDRESS && response.returncode != ReturnCodes.BANNED_ACCOUNT) { VRCToolsLogger.Warn("Using older version: " + VRCToolsMainComponent.VERSION + " / " + response.data); badVersion = true; } } return(response.data); }