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 fn = item.id +
".z";
184 if (caches.
items.TryGetValue(
item.id) ==
item.date.Replace(
"\"",
"") && File.Exists(path + fn))
186 Debug.Log(
"Returning Cache:" + path + fn);
187 return new FileInfo(path + fn);
189 using UnityWebRequest www = UnityWebRequest.Get(urlUpload +
"files/" + idLang +
"/" + fn);
190 www.downloadHandler =
new DownloadHandlerFile(path + fn);
193 await www.SendWebRequest();
199 FileInfo fileInfo =
new FileInfo(path + fn);
200 if (!fileInfo.Exists || www.result != UnityWebRequest.Result.Success)
213 public static async UniTask<List<DownloadMeta>>
GetFileList(
string idLang)
215 List<DownloadMeta> list =
new List<DownloadMeta>();
216 using UnityWebRequest www = UnityWebRequest.Get(urlUpload +
"files/" + idLang +
"/index.txt");
219 await www.SendWebRequest();
225 if (www.result != UnityWebRequest.Result.Success)
233 string[] array = www.downloadHandler.text.SplitNewline();
234 foreach (
string obj
in array)
236 string[] array2 = obj.Split(
',');
237 if (obj.StartsWith(
"files") && array2.Length >= 7)
242 id = WebUtility.HtmlDecode(array2[1]),
243 name = WebUtility.HtmlDecode(array2[2]),
244 title = WebUtility.HtmlDecode(array2[3]),
246 date = array2[6].Replace(
"\"",
""),
247 version = ((array2.Length > 8) ? array2[8].ToInt() : 0),
248 tag = ((array2.Length > 9) ? array2[9] :
"")
255 public static async UniTask<bool>
SendVote(
int id,
string idLang)
259 Debug.Log(
"Start Sending Vote:");
260 WWWForm wWWForm =
new WWWForm();
261 wWWForm.AddField(
"vote",
id.ToString() ??
"");
262 wWWForm.AddField(
"idLang", idLang);
263 wWWForm.AddField(
"submit",
"Send");
264 using UnityWebRequest www = UnityWebRequest.Post(urlVote +
"vote.php", wWWForm);
265 await www.SendWebRequest();
266 if (www.result == UnityWebRequest.Result.ConnectionError || www.result == UnityWebRequest.Result.ProtocolError)
274 Debug.Log(www.downloadHandler.text);
283 public static async UniTask<List<VoteLog>>
GetVote(
string idLang)
285 List<VoteLog> list =
new List<VoteLog>();
288 string uri =
string.Format(urlVote +
"logs/data_{0}.txt", idLang);
289 using UnityWebRequest www = UnityWebRequest.Get(uri);
290 await www.SendWebRequest();
291 if (www.result == UnityWebRequest.Result.ConnectionError || www.result == UnityWebRequest.Result.ProtocolError)
300 StringReader stringReader =
new StringReader(www.downloadHandler.text);
302 for (
string text = stringReader.ReadLine(); text !=
null; text = stringReader.ReadLine())
304 string[] array = text.Split(
',');
309 name = array[0].Replace(
"\"",
""),
310 time = array[2].ToInt(),
318 name = array[0].Replace(
"\"",
""),
319 count = array[1].ToInt(),
350 Debug.Log(
"Start Sending Text:");
351 WWWForm wWWForm =
new WWWForm();
352 wWWForm.AddField(
"submit",
"Send");
353 wWWForm.AddField(
"name", name);
354 wWWForm.AddField(
"msg", msg);
355 wWWForm.AddField(
"cat", cat.ToString());
356 wWWForm.AddField(
"idLang", idLang);
359 using UnityWebRequest www = UnityWebRequest.Post(urlChat +
"chat.php", wWWForm);
360 await www.SendWebRequest();
361 if (www.result == UnityWebRequest.Result.ConnectionError || www.result == UnityWebRequest.Result.ProtocolError)
369 Debug.Log(www.downloadHandler.text);
384 List<ChatLog> list =
new List<ChatLog>();
391 string uri =
string.Format(urlChat +
"logs/all_{0}.json", idLang);
392 using UnityWebRequest www = UnityWebRequest.Get(uri);
393 await www.SendWebRequest();
394 if (www.result == UnityWebRequest.Result.ConnectionError || www.result == UnityWebRequest.Result.ProtocolError)
398 Debug.Log(
"Download Chat Logs: Success");
399 foreach (JToken
item in (JArray)JsonConvert.DeserializeObject(www.downloadHandler.text))
403 foreach (
ChatLog item2
in list)
405 item2.msg = item2.
msg.Replace(
"\n",
"").Replace(
"\r",
"").Replace(
""",
"\"")
417 public static async UniTask<bool>
SendBook(
string name,
string msg,
BookCategory cat,
string idLang,
string msg2,
string msg3,
string msg4)
429 Debug.Log(
"Start Sending Book:");
430 WWWForm wWWForm =
new WWWForm();
431 wWWForm.AddField(
"submit",
"Send");
432 wWWForm.AddField(
"name", name);
433 wWWForm.AddField(
"msg", msg);
434 wWWForm.AddField(
"cat", cat.ToString());
435 wWWForm.AddField(
"idLang", idLang);
436 wWWForm.AddField(
"msg2", msg2);
437 wWWForm.AddField(
"msg3", msg3);
438 wWWForm.AddField(
"msg4", msg4);
441 using UnityWebRequest www = UnityWebRequest.Post(urlBook +
"book.php", wWWForm);
442 await www.SendWebRequest();
443 if (www.result == UnityWebRequest.Result.ConnectionError || www.result == UnityWebRequest.Result.ProtocolError)
451 Debug.Log(www.downloadHandler.text);
466 List<BookData> list =
new List<BookData>();
473 string uri =
string.Format(urlBook +
"logs/all_{0}.json", idLang);
474 using UnityWebRequest www = UnityWebRequest.Get(uri);
475 await www.SendWebRequest();
476 if (www.result == UnityWebRequest.Result.ConnectionError || www.result == UnityWebRequest.Result.ProtocolError)
480 Debug.Log(
"Download Book: Success");
481 foreach (JToken
item in (JArray)JsonConvert.DeserializeObject(www.downloadHandler.text))
487 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)