2using System.Collections.Generic;
5using Cysharp.Threading.Tasks;
7using Newtonsoft.Json.Linq;
9using UnityEngine.Networking;
11public class Net : MonoBehaviour
74 public Dictionary<string, string>
items =
new Dictionary<string, string>();
79 public static string urlScript =
"http://elin.cloudfree.jp/script/";
81 public static string urlBook = urlScript +
"book/";
83 public static string urlChat = urlScript +
"chat/";
85 public static string urlVote = urlScript +
"vote/";
87 public static string urlUpload = urlScript +
"uploader/";
105 StringReader stringReader =
new StringReader(logs);
106 for (
string text = stringReader.ReadLine(); text !=
null; text = stringReader.ReadLine())
114 foreach (JToken
item in (JArray)JsonConvert.DeserializeObject(logs))
121 public static async UniTask<bool>
UploadFile(
string id,
string password,
string name,
string title,
string path,
string idLang,
string cat =
"Home",
string tag =
"")
125 EClass.
ui.Say(
"sys_uploadUploading");
130 using (FileStream fileStream = File.OpenRead(path))
132 array =
new byte[fileStream.Length];
133 fileStream.Read(array, 0, (
int)fileStream.Length);
135 WWWForm wWWForm =
new WWWForm();
136 wWWForm.AddField(
"mode", 1);
137 wWWForm.AddField(
"id",
id.RemoveNewline());
138 wWWForm.AddField(
"name", name.RemoveNewline());
139 wWWForm.AddField(
"title",
title.RemoveNewline());
140 wWWForm.AddField(
"cat", cat);
141 wWWForm.AddField(
"tag", tag);
142 wWWForm.AddField(
"idLang", idLang);
143 wWWForm.AddField(
"password", password);
144 wWWForm.AddField(
"submit",
"Send");
146 wWWForm.AddBinaryData(
"file", array,
"file.z");
154 Debug.Log(array.Length);
155 using (UnityWebRequest www = UnityWebRequest.Post(urlUpload +
"uploader.php", wWWForm))
159 await www.SendWebRequest();
160 Debug.Log(www.result.ToString());
161 Debug.Log(www.downloadHandler.ToString());
162 Debug.Log(www.downloadHandler.text);
163 Debug.Log(www.downloadHandler.text.ToString());
170 if (www.result != UnityWebRequest.Result.Success)
172 EClass.
ui.Say((www.responseCode == 401) ?
"sys_uploadConflict" :
"sys_uploadFail");
182 string path2 = item.id +
".z";
183 string fullPath = path + path2.SanitizeFileName();
185 if (caches.
items.TryGetValue(
item.id) ==
item.date.Replace(
"\"",
"") && File.Exists(fullPath))
187 Debug.Log(
"Returning Cache:" + fullPath);
188 return new FileInfo(fullPath);
190 using UnityWebRequest www = UnityWebRequest.Get(urlUpload +
item.path);
191 www.downloadHandler =
new DownloadHandlerFile(fullPath);
194 await www.SendWebRequest();
200 FileInfo fileInfo =
new FileInfo(fullPath);
201 if (!fileInfo.Exists || www.result != UnityWebRequest.Result.Success)
214 public static async UniTask<List<DownloadMeta>>
GetFileList(
string idLang)
216 List<DownloadMeta> list =
new List<DownloadMeta>();
217 using UnityWebRequest www = UnityWebRequest.Get(urlUpload +
"files/" + idLang +
"/index.txt");
220 await www.SendWebRequest();
226 if (www.result != UnityWebRequest.Result.Success)
234 string[] array = www.downloadHandler.text.SplitNewline();
235 foreach (
string obj
in array)
237 string[] array2 = obj.Split(
',');
238 if (obj.StartsWith(
"files") && array2.Length >= 7)
243 id = WebUtility.HtmlDecode(array2[1]),
244 name = WebUtility.HtmlDecode(array2[2]),
245 title = WebUtility.HtmlDecode(array2[3]),
247 date = array2[6].Replace(
"\"",
""),
248 version = ((array2.Length > 8) ? array2[8].ToInt() : 0),
249 tag = ((array2.Length > 9) ? array2[9] :
"")
256 public static async UniTask<bool>
SendVote(
int id,
string idLang)
260 Debug.Log(
"Start Sending Vote:");
261 WWWForm wWWForm =
new WWWForm();
262 wWWForm.AddField(
"vote",
id.ToString() ??
"");
263 wWWForm.AddField(
"idLang", idLang);
264 wWWForm.AddField(
"submit",
"Send");
265 using UnityWebRequest www = UnityWebRequest.Post(urlVote +
"vote.php", wWWForm);
266 await www.SendWebRequest();
267 if (www.result == UnityWebRequest.Result.ConnectionError || www.result == UnityWebRequest.Result.ProtocolError)
275 Debug.Log(www.downloadHandler.text);
284 public static async UniTask<List<VoteLog>>
GetVote(
string idLang)
286 List<VoteLog> list =
new List<VoteLog>();
289 string uri =
string.Format(urlVote +
"logs/data_{0}.txt", idLang);
290 using UnityWebRequest www = UnityWebRequest.Get(uri);
291 await www.SendWebRequest();
292 if (www.result == UnityWebRequest.Result.ConnectionError || www.result == UnityWebRequest.Result.ProtocolError)
301 StringReader stringReader =
new StringReader(www.downloadHandler.text);
303 for (
string text = stringReader.ReadLine(); text !=
null; text = stringReader.ReadLine())
305 string[] array = text.Split(
',');
310 name = array[0].Replace(
"\"",
""),
311 time = array[2].ToInt(),
319 name = array[0].Replace(
"\"",
""),
320 count = array[1].ToInt(),
351 Debug.Log(
"Start Sending Text:");
352 WWWForm wWWForm =
new WWWForm();
353 wWWForm.AddField(
"submit",
"Send");
354 wWWForm.AddField(
"name", name);
355 wWWForm.AddField(
"msg", msg);
356 wWWForm.AddField(
"cat", cat.ToString());
357 wWWForm.AddField(
"idLang", idLang);
360 using UnityWebRequest www = UnityWebRequest.Post(urlChat +
"chat.php", wWWForm);
361 await www.SendWebRequest();
362 if (www.result == UnityWebRequest.Result.ConnectionError || www.result == UnityWebRequest.Result.ProtocolError)
370 Debug.Log(www.downloadHandler.text);
385 List<ChatLog> list =
new List<ChatLog>();
392 string uri =
string.Format(urlChat +
"logs/all_{0}.json", idLang);
393 using UnityWebRequest www = UnityWebRequest.Get(uri);
394 await www.SendWebRequest();
395 if (www.result == UnityWebRequest.Result.ConnectionError || www.result == UnityWebRequest.Result.ProtocolError)
399 Debug.Log(
"Download Chat Logs: Success");
400 foreach (JToken
item in (JArray)JsonConvert.DeserializeObject(www.downloadHandler.text))
404 foreach (
ChatLog item2
in list)
406 item2.msg = item2.
msg.Replace(
"\n",
"").Replace(
"\r",
"").Replace(
""",
"\"")
418 public static async UniTask<bool>
SendBook(
string name,
string msg,
BookCategory cat,
string idLang,
string msg2,
string msg3,
string msg4)
430 Debug.Log(
"Start Sending Book:");
431 WWWForm wWWForm =
new WWWForm();
432 wWWForm.AddField(
"submit",
"Send");
433 wWWForm.AddField(
"name", name);
434 wWWForm.AddField(
"msg", msg);
435 wWWForm.AddField(
"cat", cat.ToString());
436 wWWForm.AddField(
"idLang", idLang);
437 wWWForm.AddField(
"msg2", msg2);
438 wWWForm.AddField(
"msg3", msg3);
439 wWWForm.AddField(
"msg4", msg4);
442 using UnityWebRequest www = UnityWebRequest.Post(urlBook +
"book.php", wWWForm);
443 await www.SendWebRequest();
444 if (www.result == UnityWebRequest.Result.ConnectionError || www.result == UnityWebRequest.Result.ProtocolError)
452 Debug.Log(www.downloadHandler.text);
467 List<BookData> list =
new List<BookData>();
474 string uri =
string.Format(urlBook +
"logs/all_{0}.json", idLang);
475 using UnityWebRequest www = UnityWebRequest.Get(uri);
476 await www.SendWebRequest();
477 if (www.result == UnityWebRequest.Result.ConnectionError || www.result == UnityWebRequest.Result.ProtocolError)
481 Debug.Log(
"Download Book: Success");
482 foreach (JToken
item in (JArray)JsonConvert.DeserializeObject(www.downloadHandler.text))
488 item2.msg = item2.
msg.Replace(
"\n",
"").Replace(
"\r",
"").Replace(
""",
"\"")
static string ZoneSaveUser
Dictionary< string, string > items
void ShowVote(string logs)
static async UniTask< List< VoteLog > > GetVote(string idLang)
static async UniTask< List< ChatLog > > GetChat(ChatCategory cat, string idLang)
static async UniTask< bool > SendVote(int id, string idLang)
static async UniTask< List< BookData > > GetBook(BookCategory cat, string idLang)
static async UniTask< bool > SendChat(string name, string msg, ChatCategory cat, string idLang)
static async UniTask< bool > UploadFile(string id, string password, string name, string title, string path, string idLang, string cat="Home", string tag="")
static async UniTask< FileInfo > DownloadFile(DownloadMeta item, string path, string idLang)
static async UniTask< bool > SendBook(string name, string msg, BookCategory cat, string idLang, string msg2, string msg3, string msg4)
static async UniTask< List< DownloadMeta > > GetFileList(string idLang)
void ShowChat(string logs)
static Version Get(string str)
bool IsBelow(int _major, int _minor, int _batch)
bool IsSameOrBelow(Version v)