2using System.Collections.Generic;
4using Cysharp.Threading.Tasks;
6using Newtonsoft.Json.Linq;
8using UnityEngine.Networking;
10public class Net : MonoBehaviour
52 public Dictionary<string, string>
items =
new Dictionary<string, string>();
57 private const string urlScript =
"http://ylva.php.xdomain.jp/script/";
59 private const string urlChat =
"http://ylva.php.xdomain.jp/script/chat/";
61 private const string urlVote =
"http://ylva.php.xdomain.jp/script/vote/";
63 private const string urlUpload =
"http://ylva.php.xdomain.jp/script/uploader/";
81 StringReader stringReader =
new StringReader(logs);
82 for (
string text = stringReader.ReadLine(); text !=
null; text = stringReader.ReadLine())
90 foreach (JToken
item in (JArray)JsonConvert.DeserializeObject(logs))
97 public static async UniTask<bool>
UploadFile(
string id,
string password,
string name,
string title,
string path,
string idLang)
101 EClass.
ui.Say(
"sys_uploadUploading");
106 using (FileStream fileStream = File.OpenRead(path))
108 array =
new byte[fileStream.Length];
109 fileStream.Read(array, 0, (
int)fileStream.Length);
111 WWWForm wWWForm =
new WWWForm();
112 wWWForm.AddField(
"mode", 1);
113 wWWForm.AddField(
"id",
id);
114 wWWForm.AddField(
"name", name);
115 wWWForm.AddField(
"title",
title);
116 wWWForm.AddField(
"cat",
"Home");
117 wWWForm.AddField(
"idLang", idLang);
118 wWWForm.AddField(
"password", password);
119 wWWForm.AddField(
"submit",
"Send");
121 wWWForm.AddBinaryData(
"file", array,
"file.z");
128 Debug.Log(array.Length);
129 using (UnityWebRequest www = UnityWebRequest.Post(
"http://ylva.php.xdomain.jp/script/uploader/uploader.php", wWWForm))
133 await www.SendWebRequest();
134 Debug.Log(www.result.ToString());
135 Debug.Log(www.downloadHandler.ToString());
136 Debug.Log(www.downloadHandler.text);
137 Debug.Log(www.downloadHandler.text.ToString());
144 if (www.result != UnityWebRequest.Result.Success)
146 EClass.
ui.Say((www.responseCode == 401) ?
"sys_uploadConflict" :
"sys_uploadFail");
156 string fn = item.id +
".z";
158 if (caches.
items.TryGetValue(
item.id) ==
item.date.Replace(
"\"",
"") && File.Exists(path + fn))
160 Debug.Log(
"Returning Cache:" + path + fn);
161 return new FileInfo(path + fn);
163 using UnityWebRequest www = UnityWebRequest.Get(
"http://ylva.php.xdomain.jp/script/uploader/files/" + idLang +
"/" + fn);
164 www.downloadHandler =
new DownloadHandlerFile(path + fn);
167 await www.SendWebRequest();
173 FileInfo fileInfo =
new FileInfo(path + fn);
174 if (!fileInfo.Exists || www.result != UnityWebRequest.Result.Success)
187 public static async UniTask<List<DownloadMeta>>
GetFileList(
string idLang)
189 List<DownloadMeta> list =
new List<DownloadMeta>();
190 using UnityWebRequest www = UnityWebRequest.Get(
"http://ylva.php.xdomain.jp/script/uploader/files/" + idLang +
"/index.txt");
193 await www.SendWebRequest();
199 if (www.result != UnityWebRequest.Result.Success)
207 StringReader stringReader =
new StringReader(www.downloadHandler.text);
208 for (
string text = stringReader.ReadLine(); text !=
null; text = stringReader.ReadLine())
210 if (!
string.IsNullOrEmpty(text))
212 string[] array = text.Split(
',');
216 id = array[1].Replace(
"\"",
""),
219 date = array[6].Replace(
"\"",
""),
220 version = ((array.Length >= 9) ? array[8].ToInt() : 0)
227 public static async UniTask<bool>
SendVote(
int id,
string idLang)
231 Debug.Log(
"Start Sending Vote:");
232 WWWForm wWWForm =
new WWWForm();
233 wWWForm.AddField(
"vote",
id.ToString() ??
"");
234 wWWForm.AddField(
"idLang", idLang);
235 wWWForm.AddField(
"submit",
"Send");
236 using UnityWebRequest www = UnityWebRequest.Post(
"http://ylva.php.xdomain.jp/script/vote/vote.php", wWWForm);
237 await www.SendWebRequest();
238 if (www.result == UnityWebRequest.Result.ConnectionError || www.result == UnityWebRequest.Result.ProtocolError)
246 Debug.Log(www.downloadHandler.text);
255 public static async UniTask<List<VoteLog>>
GetVote(
string idLang)
257 List<VoteLog> list =
new List<VoteLog>();
260 string uri =
$"http://ylva.php.xdomain.jp/script/vote/logs/data_{idLang}.txt";
261 using UnityWebRequest www = UnityWebRequest.Get(uri);
262 await www.SendWebRequest();
263 if (www.result == UnityWebRequest.Result.ConnectionError || www.result == UnityWebRequest.Result.ProtocolError)
272 StringReader stringReader =
new StringReader(www.downloadHandler.text);
274 for (
string text = stringReader.ReadLine(); text !=
null; text = stringReader.ReadLine())
276 string[] array = text.Split(
',');
281 name = array[0].Replace(
"\"",
""),
282 time = array[2].ToInt(),
290 name = array[0].Replace(
"\"",
""),
291 count = array[1].ToInt(),
318 Debug.Log(
"Start Sending Text:");
319 WWWForm wWWForm =
new WWWForm();
320 wWWForm.AddField(
"submit",
"Send");
321 wWWForm.AddField(
"name", name);
322 wWWForm.AddField(
"msg", msg);
323 wWWForm.AddField(
"cat", cat.ToString());
324 wWWForm.AddField(
"idLang", idLang);
327 using UnityWebRequest www = UnityWebRequest.Post(
"http://ylva.php.xdomain.jp/script/chat/chat.php", wWWForm);
328 await www.SendWebRequest();
329 if (www.result == UnityWebRequest.Result.ConnectionError || www.result == UnityWebRequest.Result.ProtocolError)
337 Debug.Log(www.downloadHandler.text);
352 List<ChatLog> list =
new List<ChatLog>();
359 string uri =
$"http://ylva.php.xdomain.jp/script/chat/logs/all_{idLang}.json";
360 using UnityWebRequest www = UnityWebRequest.Get(uri);
361 await www.SendWebRequest();
362 if (www.result == UnityWebRequest.Result.ConnectionError || www.result == UnityWebRequest.Result.ProtocolError)
366 Debug.Log(
"Download Chat Logs: Success");
367 foreach (JToken
item in (JArray)JsonConvert.DeserializeObject(www.downloadHandler.text))
371 foreach (
ChatLog item2
in list)
373 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)
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)