1using System.Globalization;
2using System.Security.Cryptography;
16 public const string fName =
"CommunityContentManager";
43 public static void List(
string cursor,
46 string moderationFilter,
52 Action<Exception> failure) {
58 Dictionary<string, string> dictionary =
new();
59 Dictionary<string, string> Header =
new() { {
"Content-Type",
"application/x-www-form-urlencoded" } };
60 dictionary.Add(
"Action",
"list");
61 dictionary.Add(
"Cursor", cursor ??
string.Empty);
62 dictionary.Add(
"UserId", userFilter ??
string.Empty);
63 dictionary.Add(
"Type", typeFilter ??
string.Empty);
64 dictionary.Add(
"Moderation", moderationFilter ??
string.Empty);
65 dictionary.Add(
"SortOrder", sortOrder ??
string.Empty);
69 dictionary.Add(
"key", keySearch);
70 dictionary.Add(
"SearchType", searchType);
72 $
"{CommunityServerManager.CurrentChineseInfo.ApiUrl}com/list",
77 delegate(
byte[] result) {
79 string data = Encoding.UTF8.GetString(result, 0, result.Length);
83 foreach (XElement item
in xElement.Elements()) {
109 success(list, attributeValue);
111 catch (Exception obj) {
125 Action<Exception> failure) {
136 delegate(
byte[] data) {
139 new MemoryStream(data),
142 delegate(
string downloadedName) {
157 delegate(Exception error) {
173 delegate(Exception error) {
197 Action<Exception> failure) {
211 delegate(
byte[] data) {
214 $
"{CommunityServerManager.CurrentChineseInfo.ApiUrl}com/list",
218 new Dictionary<string, string> {
219 {
"Action",
"publish" },
220 {
"UserId", userId },
223 {
"Type", type.ToString() },
225 {
"Size", data.Length.ToString(CultureInfo.InvariantCulture) },
226 {
"Platform", VersionsManager.PlatformString },
227 {
"Version", VersionsManager.Version }
231 delegate { success(); },
246 Dictionary<string, string> dictionary =
new() {
247 {
"Action",
"delete" },
248 {
"UserId", userId },
254 $
"{CommunityServerManager.CurrentChineseInfo.ApiUrl}com/list",
259 delegate { success(); },
264 public static void Rate(
string address,
string userId,
int rating,
CancellableProgress progress, Action success, Action<Exception> failure) {
265 rating = Math.Clamp(rating, 1, 5);
269 rating.ToString(CultureInfo.InvariantCulture),
279 public static void Report(
string address,
284 Action<Exception> failure) {
303 Action<Exception> failure) {
307 Math.Round(time).ToString(CultureInfo.InvariantCulture),
321 Action<
byte[]> success,
322 Action<Exception> failure) {
329 delegate(
byte[] data) {
331 new MemoryStream(data),
334 delegate(
string downloadedName) {
347 string feedbackParameter,
353 Action<Exception> failure) {
359 Dictionary<string, string> dictionary =
new() { {
"Action",
"feedback" }, {
"Feedback", feedback } };
360 if (feedbackParameter !=
null) {
361 dictionary.Add(
"FeedbackParameter", feedbackParameter);
363 dictionary.Add(
"UserId", userId);
364 if (address !=
null) {
365 dictionary.Add(
"Url", address);
368 dictionary.Add(
"Hash", hash);
371 dictionary.Add(
"Size", size.ToString(CultureInfo.InvariantCulture));
376 $
"{CommunityServerManager.CurrentChineseInfo.ApiUrl}com/list",
382 string key = MakeFeedbackCacheKey(address, feedback, userId);
383 if (!m_feedbackCache.TryAdd(key, true)) {
386 Task.Delay(1500).Wait();
387 failure(new InvalidOperationException(LanguageControl.Get(fName,
"3")));
492 Action<
byte[]> success,
493 Action<Exception> failure) {
499 Dictionary<string, string> header =
new() { {
"Content-Type",
"application/x-www-form-urlencoded" } };
500 Dictionary<string, string> dictionary =
new() {
501 {
"Action",
"UpdateLockState" },
502 {
"Id",
id.ToString() },
504 {
"LockState", lockState.ToString() },
505 {
"Duration", duration.ToString() },
509 $
"{CommunityServerManager.CurrentChineseInfo.ApiUrl}/com/api/zh/userList",
525 Dictionary<string, string> header =
new() { {
"Content-Type",
"application/x-www-form-urlencoded" } };
526 Dictionary<string, string> dictionary =
new() {
530 $
"{CommunityServerManager.CurrentChineseInfo.ApiUrl}/com/api/zh/userList",
544 Action<
byte[]> success,
545 Action<Exception> failure) {
551 Dictionary<string, string> header =
new() { {
"Content-Type",
"application/x-www-form-urlencoded" } };
552 Dictionary<string, string> dictionary =
new() {
556 $
"{CommunityServerManager.CurrentChineseInfo.ApiUrl}/com/api/zh/boutique",
572 Dictionary<string, string> header =
new() { {
"Content-Type",
"application/x-www-form-urlencoded" } };
573 Dictionary<string, string> dictionary =
new() {
577 $
"{CommunityServerManager.CurrentChineseInfo.ApiUrl}/com/api/zh/hide",
593 Dictionary<string, string> header =
new() { {
"Content-Type",
"application/x-www-form-urlencoded" } };
596 $
"{CommunityServerManager.CurrentChineseInfo.ApiUrl}/com/api/zh/deleteFile",
612 Dictionary<string, string> header =
new() { {
"Content-Type",
"application/x-www-form-urlencoded" } };
615 $
"{CommunityServerManager.CurrentChineseInfo.ApiUrl}/com/api/zh/isadmin",
620 delegate(
byte[] data) {
624 success(property.Value.GetString() ==
"Y");
636 public static string MakeFeedbackCacheKey(
string address,
string feedback,
string userId) => $
"{address}\n{feedback}\n{userId}";
645 IEnumerable<XElement> feedbackElements = xElement.Element(
"Feedback")?.Elements();
646 if (feedbackElements !=
null) {
647 foreach (XElement item
in feedbackElements) {
652 IEnumerable<XElement> contentElements = xElement.Element(
"Content")?.Elements();
653 if (contentElements !=
null) {
654 foreach (XElement item2
in contentElements) {
662 catch (Exception e) {
669 XElement xElement =
new(
"Cache");
670 XElement xElement2 =
new(
"Feedback");
671 xElement.Add(xElement2);
673 XElement xElement3 =
new(
"Item");
675 xElement2.Add(xElement3);
677 XElement xElement4 =
new(
"Content");
678 xElement.Add(xElement4);
680 XElement xElement5 =
new(
"Item");
683 xElement4.Add(xElement5);
688 catch (Exception e) {
static Stream OpenFile(string path, OpenFileMode openFileMode)
static bool FileExists(string path)
static Action Deactivated
static Action< string > BlocksTextureDeleted
static Action< string > CharacterSkinDeleted
static void ReportExceptionToUser(string additionalMessage, Exception e)
static void ImportExternalContent(Stream stream, ExternalContentType type, string name, Action< string > success, Action< Exception > failure)
static void DeleteExternalContent(ExternalContentType type, string name)
static Action< string > FurniturePackDeleted
static readonly JsonDocumentOptions DefaultJsonOptions
static string Get(string className, int key)
获取在当前语言类名键对应的字符串
static string ScpboxAccessToken
static string PlatformString
static void Post(string address, Dictionary< string, string > parameters, Dictionary< string, string > headers, Stream data, CancellableProgress progress, Action< byte[]> success, Action< Exception > failure)
static bool IsInternetConnectionAvailable()
static MemoryStream UrlParametersToStream(Dictionary< string, string > values)
static void Get(string address, Dictionary< string, string > parameters, Dictionary< string, string > headers, CancellableProgress progress, Action< byte[]> success, Action< Exception > failure)
static Action< string > WorldDeleted
static string CommunityContentCachePath
static string APIVersionString
static void SetAttributeValue(XElement node, string attributeName, object value)
static object GetAttributeValue(XElement node, string attributeName, Type type)
static XElement LoadXmlFromStream(Stream stream, Encoding encoding, bool throwOnError)
static XElement LoadXmlFromString(string data, bool throwOnError)
static void SaveXmlToStream(XElement node, Stream stream, Encoding encoding, bool throwOnError)