2using System.Collections.Generic;
4using Cysharp.Threading.Tasks;
6using Newtonsoft.Json.Linq;
8using UnityEngine.Networking;
10public class Net : MonoBehaviour
60 public Dictionary<string, string>
items =
new Dictionary<string, string>();
65 public static string urlScript =
"http://elin.cloudfree.jp/script/";
89 StringReader stringReader =
new StringReader(logs);
90 for (
string text = stringReader.ReadLine(); text !=
null; text = stringReader.ReadLine())
98 foreach (JToken
item in (JArray)JsonConvert.DeserializeObject(logs))
105 public static async UniTask<bool>
UploadFile(
string id,
string password,
string name,
string title,
string path,
string idLang,
string cat =
"Home",
string tag =
"")
109 EClass.
ui.Say(
"sys_uploadUploading");
114 using (FileStream fileStream = File.OpenRead(path))
116 array =
new byte[fileStream.Length];
117 fileStream.Read(array, 0, (
int)fileStream.Length);
119 WWWForm wWWForm =
new WWWForm();
120 wWWForm.AddField(
"mode", 1);
121 wWWForm.AddField(
"id",
id);
122 wWWForm.AddField(
"name", name);
123 wWWForm.AddField(
"title",
title);
124 wWWForm.AddField(
"cat", cat);
125 wWWForm.AddField(
"tag", tag);
126 wWWForm.AddField(
"idLang", idLang);
127 wWWForm.AddField(
"password", password);
128 wWWForm.AddField(
"submit",
"Send");
130 wWWForm.AddBinaryData(
"file", array,
"file.z");
138 Debug.Log(array.Length);
139 using (UnityWebRequest www = UnityWebRequest.Post(
urlUpload +
"uploader.php", wWWForm))
143 await www.SendWebRequest();
144 Debug.Log(www.result.ToString());
145 Debug.Log(www.downloadHandler.ToString());
146 Debug.Log(www.downloadHandler.text);
147 Debug.Log(www.downloadHandler.text.ToString());
154 if (www.result != UnityWebRequest.Result.Success)
156 EClass.
ui.Say((www.responseCode == 401) ?
"sys_uploadConflict" :
"sys_uploadFail");
166 string fn = item.id +
".z";
168 if (caches.
items.TryGetValue(
item.id) ==
item.date.Replace(
"\"",
"") && File.Exists(path + fn))
170 Debug.Log(
"Returning Cache:" + path + fn);
171 return new FileInfo(path + fn);
173 using UnityWebRequest www = UnityWebRequest.Get(
urlUpload +
"files/" + idLang +
"/" + fn);
174 www.downloadHandler =
new DownloadHandlerFile(path + fn);
177 await www.SendWebRequest();
183 FileInfo fileInfo =
new FileInfo(path + fn);
184 if (!fileInfo.Exists || www.result != UnityWebRequest.Result.Success)
197 public static async UniTask<List<DownloadMeta>>
GetFileList(
string idLang)
199 List<DownloadMeta> list =
new List<DownloadMeta>();
200 using UnityWebRequest www = UnityWebRequest.Get(
urlUpload +
"files/" + idLang +
"/index.txt");
203 await www.SendWebRequest();
209 if (www.result != UnityWebRequest.Result.Success)
217 StringReader stringReader =
new StringReader(www.downloadHandler.text);
218 for (
string text = stringReader.ReadLine(); text !=
null; text = stringReader.ReadLine())
220 if (!
string.IsNullOrEmpty(text))
222 string[] array = text.Split(
',');
226 id = Path.GetFileNameWithoutExtension(array[0]),
230 date = array[6].Replace(
"\"",
""),
231 version = ((array.Length >= 9) ? array[8].ToInt() : 0),
232 tag = ((array.Length >= 10) ? array[9] :
"")
239 public static async UniTask<bool>
SendVote(
int id,
string idLang)
243 Debug.Log(
"Start Sending Vote:");
244 WWWForm wWWForm =
new WWWForm();
245 wWWForm.AddField(
"vote",
id.ToString() ??
"");
246 wWWForm.AddField(
"idLang", idLang);
247 wWWForm.AddField(
"submit",
"Send");
248 using UnityWebRequest www = UnityWebRequest.Post(
urlVote +
"vote.php", wWWForm);
249 await www.SendWebRequest();
250 if (www.result == UnityWebRequest.Result.ConnectionError || www.result == UnityWebRequest.Result.ProtocolError)
258 Debug.Log(www.downloadHandler.text);
267 public static async UniTask<List<VoteLog>>
GetVote(
string idLang)
269 List<VoteLog> list =
new List<VoteLog>();
272 string uri =
string.Format(
urlVote +
"logs/data_{0}.txt", idLang);
273 using UnityWebRequest www = UnityWebRequest.Get(uri);
274 await www.SendWebRequest();
275 if (www.result == UnityWebRequest.Result.ConnectionError || www.result == UnityWebRequest.Result.ProtocolError)
284 StringReader stringReader =
new StringReader(www.downloadHandler.text);
286 for (
string text = stringReader.ReadLine(); text !=
null; text = stringReader.ReadLine())
288 string[] array = text.Split(
',');
293 name = array[0].Replace(
"\"",
""),
294 time = array[2].ToInt(),
302 name = array[0].Replace(
"\"",
""),
303 count = array[1].ToInt(),
330 Debug.Log(
"Start Sending Text:");
331 WWWForm wWWForm =
new WWWForm();
332 wWWForm.AddField(
"submit",
"Send");
333 wWWForm.AddField(
"name", name);
334 wWWForm.AddField(
"msg", msg);
335 wWWForm.AddField(
"cat", cat.ToString());
336 wWWForm.AddField(
"idLang", idLang);
339 using UnityWebRequest www = UnityWebRequest.Post(
urlChat +
"chat.php", wWWForm);
340 await www.SendWebRequest();
341 if (www.result == UnityWebRequest.Result.ConnectionError || www.result == UnityWebRequest.Result.ProtocolError)
349 Debug.Log(www.downloadHandler.text);
364 List<ChatLog> list =
new List<ChatLog>();
371 string uri =
string.Format(
urlChat +
"logs/all_{0}.json", idLang);
372 using UnityWebRequest www = UnityWebRequest.Get(uri);
373 await www.SendWebRequest();
374 if (www.result == UnityWebRequest.Result.ConnectionError || www.result == UnityWebRequest.Result.ProtocolError)
378 Debug.Log(
"Download Chat Logs: Success");
379 foreach (JToken
item in (JArray)JsonConvert.DeserializeObject(www.downloadHandler.text))
383 foreach (
ChatLog item2
in list)
385 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< 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< 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)