2using System.Collections.Generic;
4using Cysharp.Threading.Tasks;
6using Newtonsoft.Json.Linq;
8using UnityEngine.Networking;
10public class Net : MonoBehaviour
58 public Dictionary<string, string>
items =
new Dictionary<string, string>();
63 private const string urlScript =
"http://ylva.php.xdomain.jp/script/";
65 private const string urlChat =
"http://ylva.php.xdomain.jp/script/chat/";
67 private const string urlVote =
"http://ylva.php.xdomain.jp/script/vote/";
69 private const string urlUpload =
"http://ylva.php.xdomain.jp/script/uploader/";
87 StringReader stringReader =
new StringReader(logs);
88 for (
string text = stringReader.ReadLine(); text !=
null; text = stringReader.ReadLine())
96 foreach (JToken
item in (JArray)JsonConvert.DeserializeObject(logs))
103 public static async UniTask<bool>
UploadFile(
string id,
string password,
string name,
string title,
string path,
string idLang,
string cat =
"Home")
107 EClass.
ui.Say(
"sys_uploadUploading");
112 using (FileStream fileStream = File.OpenRead(path))
114 array =
new byte[fileStream.Length];
115 fileStream.Read(array, 0, (
int)fileStream.Length);
117 WWWForm wWWForm =
new WWWForm();
118 wWWForm.AddField(
"mode", 1);
119 wWWForm.AddField(
"id",
id);
120 wWWForm.AddField(
"name", name);
121 wWWForm.AddField(
"title",
title);
122 wWWForm.AddField(
"cat", cat);
123 wWWForm.AddField(
"idLang", idLang);
124 wWWForm.AddField(
"password", password);
125 wWWForm.AddField(
"submit",
"Send");
127 wWWForm.AddBinaryData(
"file", array,
"file.z");
134 Debug.Log(array.Length);
135 using (UnityWebRequest www = UnityWebRequest.Post(
"http://ylva.php.xdomain.jp/script/uploader/uploader.php", wWWForm))
139 await www.SendWebRequest();
140 Debug.Log(www.result.ToString());
141 Debug.Log(www.downloadHandler.ToString());
142 Debug.Log(www.downloadHandler.text);
143 Debug.Log(www.downloadHandler.text.ToString());
150 if (www.result != UnityWebRequest.Result.Success)
152 EClass.
ui.Say((www.responseCode == 401) ?
"sys_uploadConflict" :
"sys_uploadFail");
162 string fn = item.id +
".z";
164 if (caches.
items.TryGetValue(
item.id) ==
item.date.Replace(
"\"",
"") && File.Exists(path + fn))
166 Debug.Log(
"Returning Cache:" + path + fn);
167 return new FileInfo(path + fn);
169 using UnityWebRequest www = UnityWebRequest.Get(
"http://ylva.php.xdomain.jp/script/uploader/files/" + idLang +
"/" + fn);
170 www.downloadHandler =
new DownloadHandlerFile(path + fn);
173 await www.SendWebRequest();
179 FileInfo fileInfo =
new FileInfo(path + fn);
180 if (!fileInfo.Exists || www.result != UnityWebRequest.Result.Success)
193 public static async UniTask<List<DownloadMeta>>
GetFileList(
string idLang)
195 List<DownloadMeta> list =
new List<DownloadMeta>();
196 using UnityWebRequest www = UnityWebRequest.Get(
"http://ylva.php.xdomain.jp/script/uploader/files/" + idLang +
"/index.txt");
199 await www.SendWebRequest();
205 if (www.result != UnityWebRequest.Result.Success)
213 StringReader stringReader =
new StringReader(www.downloadHandler.text);
214 for (
string text = stringReader.ReadLine(); text !=
null; text = stringReader.ReadLine())
216 if (!
string.IsNullOrEmpty(text))
218 string[] array = text.Split(
',');
222 id = array[1].Replace(
"\"",
""),
226 date = array[6].Replace(
"\"",
""),
227 version = ((array.Length >= 9) ? array[8].ToInt() : 0)
234 public static async UniTask<bool>
SendVote(
int id,
string idLang)
238 Debug.Log(
"Start Sending Vote:");
239 WWWForm wWWForm =
new WWWForm();
240 wWWForm.AddField(
"vote",
id.ToString() ??
"");
241 wWWForm.AddField(
"idLang", idLang);
242 wWWForm.AddField(
"submit",
"Send");
243 using UnityWebRequest www = UnityWebRequest.Post(
"http://ylva.php.xdomain.jp/script/vote/vote.php", wWWForm);
244 await www.SendWebRequest();
245 if (www.result == UnityWebRequest.Result.ConnectionError || www.result == UnityWebRequest.Result.ProtocolError)
253 Debug.Log(www.downloadHandler.text);
262 public static async UniTask<List<VoteLog>>
GetVote(
string idLang)
264 List<VoteLog> list =
new List<VoteLog>();
267 string uri =
$"http://ylva.php.xdomain.jp/script/vote/logs/data_{idLang}.txt";
268 using UnityWebRequest www = UnityWebRequest.Get(uri);
269 await www.SendWebRequest();
270 if (www.result == UnityWebRequest.Result.ConnectionError || www.result == UnityWebRequest.Result.ProtocolError)
279 StringReader stringReader =
new StringReader(www.downloadHandler.text);
281 for (
string text = stringReader.ReadLine(); text !=
null; text = stringReader.ReadLine())
283 string[] array = text.Split(
',');
288 name = array[0].Replace(
"\"",
""),
289 time = array[2].ToInt(),
297 name = array[0].Replace(
"\"",
""),
298 count = array[1].ToInt(),
325 Debug.Log(
"Start Sending Text:");
326 WWWForm wWWForm =
new WWWForm();
327 wWWForm.AddField(
"submit",
"Send");
328 wWWForm.AddField(
"name", name);
329 wWWForm.AddField(
"msg", msg);
330 wWWForm.AddField(
"cat", cat.ToString());
331 wWWForm.AddField(
"idLang", idLang);
334 using UnityWebRequest www = UnityWebRequest.Post(
"http://ylva.php.xdomain.jp/script/chat/chat.php", wWWForm);
335 await www.SendWebRequest();
336 if (www.result == UnityWebRequest.Result.ConnectionError || www.result == UnityWebRequest.Result.ProtocolError)
344 Debug.Log(www.downloadHandler.text);
359 List<ChatLog> list =
new List<ChatLog>();
366 string uri =
$"http://ylva.php.xdomain.jp/script/chat/logs/all_{idLang}.json";
367 using UnityWebRequest www = UnityWebRequest.Get(uri);
368 await www.SendWebRequest();
369 if (www.result == UnityWebRequest.Result.ConnectionError || www.result == UnityWebRequest.Result.ProtocolError)
373 Debug.Log(
"Download Chat Logs: Success");
374 foreach (JToken
item in (JArray)JsonConvert.DeserializeObject(www.downloadHandler.text))
378 foreach (
ChatLog item2
in list)
380 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< FileInfo > DownloadFile(DownloadMeta item, string path, string idLang)
static async UniTask< List< DownloadMeta > > GetFileList(string idLang)
static async UniTask< bool > UploadFile(string id, string password, string name, string title, string path, string idLang, string cat="Home")
void ShowChat(string logs)
static Version Get(string str)
bool IsBelow(int _major, int _minor, int _batch)
bool IsSameOrBelow(Version v)