2using System.Collections.Generic;
4using Cysharp.Threading.Tasks;
6using Newtonsoft.Json.Linq;
8using UnityEngine.Networking;
10public class Net : MonoBehaviour
73 public Dictionary<string, string>
items =
new Dictionary<string, string>();
78 public static string urlScript =
"http://elin.cloudfree.jp/script/";
104 StringReader stringReader =
new StringReader(logs);
105 for (
string text = stringReader.ReadLine(); text !=
null; text = stringReader.ReadLine())
113 foreach (JToken
item in (JArray)JsonConvert.DeserializeObject(logs))
120 public static async UniTask<bool>
UploadFile(
string id,
string password,
string name,
string title,
string path,
string idLang,
string cat =
"Home",
string tag =
"")
124 EClass.
ui.Say(
"sys_uploadUploading");
129 using (FileStream fileStream = File.OpenRead(path))
131 array =
new byte[fileStream.Length];
132 fileStream.Read(array, 0, (
int)fileStream.Length);
134 WWWForm wWWForm =
new WWWForm();
135 wWWForm.AddField(
"mode", 1);
136 wWWForm.AddField(
"id",
id);
137 wWWForm.AddField(
"name", name);
138 wWWForm.AddField(
"title",
title);
139 wWWForm.AddField(
"cat", cat);
140 wWWForm.AddField(
"tag", tag);
141 wWWForm.AddField(
"idLang", idLang);
142 wWWForm.AddField(
"password", password);
143 wWWForm.AddField(
"submit",
"Send");
145 wWWForm.AddBinaryData(
"file", array,
"file.z");
153 Debug.Log(array.Length);
154 using (UnityWebRequest www = UnityWebRequest.Post(
urlUpload +
"uploader.php", wWWForm))
158 await www.SendWebRequest();
159 Debug.Log(www.result.ToString());
160 Debug.Log(www.downloadHandler.ToString());
161 Debug.Log(www.downloadHandler.text);
162 Debug.Log(www.downloadHandler.text.ToString());
169 if (www.result != UnityWebRequest.Result.Success)
171 EClass.
ui.Say((www.responseCode == 401) ?
"sys_uploadConflict" :
"sys_uploadFail");
181 string fn = item.id +
".z";
183 if (caches.
items.TryGetValue(
item.id) ==
item.date.Replace(
"\"",
"") && File.Exists(path + fn))
185 Debug.Log(
"Returning Cache:" + path + fn);
186 return new FileInfo(path + fn);
188 using UnityWebRequest www = UnityWebRequest.Get(
urlUpload +
"files/" + idLang +
"/" + fn);
189 www.downloadHandler =
new DownloadHandlerFile(path + fn);
192 await www.SendWebRequest();
198 FileInfo fileInfo =
new FileInfo(path + fn);
199 if (!fileInfo.Exists || www.result != UnityWebRequest.Result.Success)
212 public static async UniTask<List<DownloadMeta>>
GetFileList(
string idLang)
214 List<DownloadMeta> list =
new List<DownloadMeta>();
215 using UnityWebRequest www = UnityWebRequest.Get(
urlUpload +
"files/" + idLang +
"/index.txt");
218 await www.SendWebRequest();
224 if (www.result != UnityWebRequest.Result.Success)
232 StringReader stringReader =
new StringReader(www.downloadHandler.text);
233 for (
string text = stringReader.ReadLine(); text !=
null; text = stringReader.ReadLine())
235 if (!
string.IsNullOrEmpty(text))
237 string[] array = text.Split(
',');
241 id = Path.GetFileNameWithoutExtension(array[0]),
245 date = array[6].Replace(
"\"",
""),
246 version = ((array.Length >= 9) ? array[8].ToInt() : 0),
247 tag = ((array.Length >= 10) ? array[9] :
"")
254 public static async UniTask<bool>
SendVote(
int id,
string idLang)
258 Debug.Log(
"Start Sending Vote:");
259 WWWForm wWWForm =
new WWWForm();
260 wWWForm.AddField(
"vote",
id.ToString() ??
"");
261 wWWForm.AddField(
"idLang", idLang);
262 wWWForm.AddField(
"submit",
"Send");
263 using UnityWebRequest www = UnityWebRequest.Post(
urlVote +
"vote.php", wWWForm);
264 await www.SendWebRequest();
265 if (www.result == UnityWebRequest.Result.ConnectionError || www.result == UnityWebRequest.Result.ProtocolError)
273 Debug.Log(www.downloadHandler.text);
282 public static async UniTask<List<VoteLog>>
GetVote(
string idLang)
284 List<VoteLog> list =
new List<VoteLog>();
287 string uri =
string.Format(
urlVote +
"logs/data_{0}.txt", idLang);
288 using UnityWebRequest www = UnityWebRequest.Get(uri);
289 await www.SendWebRequest();
290 if (www.result == UnityWebRequest.Result.ConnectionError || www.result == UnityWebRequest.Result.ProtocolError)
299 StringReader stringReader =
new StringReader(www.downloadHandler.text);
301 for (
string text = stringReader.ReadLine(); text !=
null; text = stringReader.ReadLine())
303 string[] array = text.Split(
',');
308 name = array[0].Replace(
"\"",
""),
309 time = array[2].ToInt(),
317 name = array[0].Replace(
"\"",
""),
318 count = array[1].ToInt(),
349 Debug.Log(
"Start Sending Text:");
350 WWWForm wWWForm =
new WWWForm();
351 wWWForm.AddField(
"submit",
"Send");
352 wWWForm.AddField(
"name", name);
353 wWWForm.AddField(
"msg", msg);
354 wWWForm.AddField(
"cat", cat.ToString());
355 wWWForm.AddField(
"idLang", idLang);
358 using UnityWebRequest www = UnityWebRequest.Post(
urlChat +
"chat.php", wWWForm);
359 await www.SendWebRequest();
360 if (www.result == UnityWebRequest.Result.ConnectionError || www.result == UnityWebRequest.Result.ProtocolError)
368 Debug.Log(www.downloadHandler.text);
383 List<ChatLog> list =
new List<ChatLog>();
390 string uri =
string.Format(
urlChat +
"logs/all_{0}.json", idLang);
391 using UnityWebRequest www = UnityWebRequest.Get(uri);
392 await www.SendWebRequest();
393 if (www.result == UnityWebRequest.Result.ConnectionError || www.result == UnityWebRequest.Result.ProtocolError)
397 Debug.Log(
"Download Chat Logs: Success");
398 foreach (JToken
item in (JArray)JsonConvert.DeserializeObject(www.downloadHandler.text))
402 foreach (
ChatLog item2
in list)
404 item2.msg = item2.
msg.Replace(
"\n",
"").Replace(
"\r",
"").Replace(
""",
"\"")
416 public static async UniTask<bool>
SendBook(
string name,
string msg,
BookCategory cat,
string idLang,
string msg2,
string msg3,
string msg4)
428 Debug.Log(
"Start Sending Book:");
429 WWWForm wWWForm =
new WWWForm();
430 wWWForm.AddField(
"submit",
"Send");
431 wWWForm.AddField(
"name", name);
432 wWWForm.AddField(
"msg", msg);
433 wWWForm.AddField(
"cat", cat.ToString());
434 wWWForm.AddField(
"idLang", idLang);
435 wWWForm.AddField(
"msg2", msg2);
436 wWWForm.AddField(
"msg3", msg3);
437 wWWForm.AddField(
"msg4", msg4);
440 using UnityWebRequest www = UnityWebRequest.Post(
urlBook +
"book.php", wWWForm);
441 await www.SendWebRequest();
442 if (www.result == UnityWebRequest.Result.ConnectionError || www.result == UnityWebRequest.Result.ProtocolError)
450 Debug.Log(www.downloadHandler.text);
465 List<BookData> list =
new List<BookData>();
472 string uri =
string.Format(
urlBook +
"logs/all_{0}.json", idLang);
473 using UnityWebRequest www = UnityWebRequest.Get(uri);
474 await www.SendWebRequest();
475 if (www.result == UnityWebRequest.Result.ConnectionError || www.result == UnityWebRequest.Result.ProtocolError)
479 Debug.Log(
"Download Book: Success");
480 foreach (JToken
item in (JArray)JsonConvert.DeserializeObject(www.downloadHandler.text))
486 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)