Elin Decompiled Documentation EA 23.130 Nightly
Loading...
Searching...
No Matches
Net.cs
Go to the documentation of this file.
1using System;
2using System.Collections.Generic;
3using System.IO;
4using Cysharp.Threading.Tasks;
5using Newtonsoft.Json;
6using Newtonsoft.Json.Linq;
7using UnityEngine;
8using UnityEngine.Networking;
9
10public class Net : MonoBehaviour
11{
12 public class ChatLog
13 {
14 public string name;
15
16 public string msg;
17 }
18
19 public class VoteLog
20 {
21 public string name;
22
23 public int count;
24
25 public int index;
26
27 public int time;
28 }
29
30 public class DownloadMeta
31 {
32 public string name;
33
34 public string title;
35
36 public string id;
37
38 public string path;
39
40 public string cat;
41
42 public string date;
43
44 public int version;
45
46 public bool IsValidVersion()
47 {
49 {
51 }
52 return false;
53 }
54 }
55
56 public class DownloadCahce
57 {
58 public Dictionary<string, string> items = new Dictionary<string, string>();
59 }
60
61 public List<ChatLog> chatList;
62
63 private const string urlScript = "http://ylva.php.xdomain.jp/script/";
64
65 private const string urlChat = "http://ylva.php.xdomain.jp/script/chat/";
66
67 private const string urlVote = "http://ylva.php.xdomain.jp/script/vote/";
68
69 private const string urlUpload = "http://ylva.php.xdomain.jp/script/uploader/";
70
71 public static bool isUploading;
72
73 public static bool ShowNetError
74 {
75 get
76 {
78 {
79 return EClass.debug.enable;
80 }
81 return true;
82 }
83 }
84
85 public void ShowVote(string logs)
86 {
87 StringReader stringReader = new StringReader(logs);
88 for (string text = stringReader.ReadLine(); text != null; text = stringReader.ReadLine())
89 {
90 Debug.Log(text);
91 }
92 }
93
94 public void ShowChat(string logs)
95 {
96 foreach (JToken item in (JArray)JsonConvert.DeserializeObject(logs))
97 {
98 ChatLog chatLog = item.ToObject<ChatLog>();
99 Debug.Log(chatLog.name + "/" + chatLog.msg);
100 }
101 }
102
103 public static async UniTask<bool> UploadFile(string id, string password, string name, string title, string path, string idLang, string cat = "Home")
104 {
105 if (isUploading)
106 {
107 EClass.ui.Say("sys_uploadUploading");
108 return false;
109 }
110 EClass.ui.Say("sys_uploadStart");
111 byte[] array;
112 using (FileStream fileStream = File.OpenRead(path))
113 {
114 array = new byte[fileStream.Length];
115 fileStream.Read(array, 0, (int)fileStream.Length);
116 }
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");
126 wWWForm.AddField("version", EClass.core.version.GetInt().ToString() ?? "");
127 wWWForm.AddBinaryData("file", array, "file.z");
128 isUploading = true;
129 Debug.Log(id);
130 Debug.Log(name);
131 Debug.Log(title);
132 Debug.Log(idLang);
133 Debug.Log(password);
134 Debug.Log(array.Length);
135 using (UnityWebRequest www = UnityWebRequest.Post("http://ylva.php.xdomain.jp/script/uploader/uploader.php", wWWForm))
136 {
137 try
138 {
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());
144 }
145 catch (Exception ex)
146 {
147 EClass.ui.Say(ex.Message);
148 }
149 isUploading = false;
150 if (www.result != UnityWebRequest.Result.Success)
151 {
152 EClass.ui.Say((www.responseCode == 401) ? "sys_uploadConflict" : "sys_uploadFail");
153 return false;
154 }
155 }
156 EClass.ui.Say("sys_uploadSuccess");
157 return true;
158 }
159
160 public static async UniTask<FileInfo> DownloadFile(DownloadMeta item, string path, string idLang)
161 {
162 string fn = item.id + ".z";
163 DownloadCahce caches = IO.LoadFile<DownloadCahce>(CorePath.ZoneSaveUser + "cache.txt") ?? new DownloadCahce();
164 if (caches.items.TryGetValue(item.id) == item.date.Replace("\"", "") && File.Exists(path + fn))
165 {
166 Debug.Log("Returning Cache:" + path + fn);
167 return new FileInfo(path + fn);
168 }
169 using UnityWebRequest www = UnityWebRequest.Get("http://ylva.php.xdomain.jp/script/uploader/files/" + idLang + "/" + fn);
170 www.downloadHandler = new DownloadHandlerFile(path + fn);
171 try
172 {
173 await www.SendWebRequest();
174 }
175 catch (Exception ex)
176 {
177 EClass.ui.Say(ex.Message);
178 }
179 FileInfo fileInfo = new FileInfo(path + fn);
180 if (!fileInfo.Exists || www.result != UnityWebRequest.Result.Success)
181 {
182 if (ShowNetError)
183 {
184 EClass.ui.Say(www.error);
185 }
186 return null;
187 }
188 caches.items[item.id] = item.date;
189 IO.SaveFile(CorePath.ZoneSaveUser + "cache.txt", caches);
190 return fileInfo;
191 }
192
193 public static async UniTask<List<DownloadMeta>> GetFileList(string idLang)
194 {
195 List<DownloadMeta> list = new List<DownloadMeta>();
196 using UnityWebRequest www = UnityWebRequest.Get("http://ylva.php.xdomain.jp/script/uploader/files/" + idLang + "/index.txt");
197 try
198 {
199 await www.SendWebRequest();
200 }
201 catch (Exception ex)
202 {
203 EClass.ui.Say(ex.Message);
204 }
205 if (www.result != UnityWebRequest.Result.Success)
206 {
207 if (ShowNetError)
208 {
209 EClass.ui.Say(www.error);
210 }
211 return null;
212 }
213 StringReader stringReader = new StringReader(www.downloadHandler.text);
214 for (string text = stringReader.ReadLine(); text != null; text = stringReader.ReadLine())
215 {
216 if (!string.IsNullOrEmpty(text))
217 {
218 string[] array = text.Split(',');
219 list.Add(new DownloadMeta
220 {
221 path = array[0],
222 id = array[1].Replace("\"", ""),
223 name = array[2],
224 title = array[3],
225 cat = array[5],
226 date = array[6].Replace("\"", ""),
227 version = ((array.Length >= 9) ? array[8].ToInt() : 0)
228 });
229 }
230 }
231 return list;
232 }
233
234 public static async UniTask<bool> SendVote(int id, string idLang)
235 {
236 try
237 {
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)
246 {
247 if (ShowNetError)
248 {
249 EClass.ui.Say(www.error);
250 }
251 return false;
252 }
253 Debug.Log(www.downloadHandler.text);
254 return true;
255 }
256 catch
257 {
258 return true;
259 }
260 }
261
262 public static async UniTask<List<VoteLog>> GetVote(string idLang)
263 {
264 List<VoteLog> list = new List<VoteLog>();
265 try
266 {
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)
271 {
272 if (ShowNetError)
273 {
274 EClass.ui.Say(www.error);
275 }
276 }
277 else
278 {
279 StringReader stringReader = new StringReader(www.downloadHandler.text);
280 int num = 0;
281 for (string text = stringReader.ReadLine(); text != null; text = stringReader.ReadLine())
282 {
283 string[] array = text.Split(',');
284 if (num == 0)
285 {
286 list.Add(new VoteLog
287 {
288 name = array[0].Replace("\"", ""),
289 time = array[2].ToInt(),
290 index = num
291 });
292 }
293 else
294 {
295 list.Add(new VoteLog
296 {
297 name = array[0].Replace("\"", ""),
298 count = array[1].ToInt(),
299 index = num
300 });
301 }
302 num++;
303 }
304 }
305 return list;
306 }
307 catch
308 {
309 return list;
310 }
311 }
312
313 public static async UniTask<bool> SendChat(string name, string msg, ChatCategory cat, string idLang)
314 {
316 {
317 return false;
318 }
319 try
320 {
321 if (EClass.debug.enable)
322 {
323 idLang = "DEBUG";
324 }
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);
332 try
333 {
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)
337 {
338 if (ShowNetError)
339 {
340 EClass.ui.Say(www.error);
341 }
342 return false;
343 }
344 Debug.Log(www.downloadHandler.text);
345 return true;
346 }
347 catch
348 {
349 }
350 }
351 catch
352 {
353 }
354 return false;
355 }
356
357 public static async UniTask<List<ChatLog>> GetChat(ChatCategory cat, string idLang)
358 {
359 List<ChatLog> list = new List<ChatLog>();
360 try
361 {
362 if (EClass.debug.enable)
363 {
364 idLang = "DEBUG";
365 }
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)
370 {
371 return null;
372 }
373 Debug.Log("Download Chat Logs: Success");
374 foreach (JToken item in (JArray)JsonConvert.DeserializeObject(www.downloadHandler.text))
375 {
376 list.Add(item.ToObject<ChatLog>());
377 }
378 foreach (ChatLog item2 in list)
379 {
380 item2.msg = item2.msg.Replace("\n", "").Replace("\r", "").Replace("&quot;", "\"")
381 .ToTitleCase();
382 }
383 list.Reverse();
384 return list;
385 }
386 catch
387 {
388 return list;
389 }
390 }
391}
ChatCategory
Definition: ChatCategory.cs:2
item3. title
Definition: UIBook.cs:616
Version version
Definition: BaseCore.cs:17
Version versionMoongate
Definition: BaseCore.cs:19
bool enable
Definition: CoreDebug.cs:285
static string ZoneSaveUser
Definition: CorePath.cs:198
CoreConfig config
Definition: Core.cs:70
Definition: EClass.cs:5
static Core core
Definition: EClass.cs:6
static CoreDebug debug
Definition: EClass.cs:48
static UI ui
Definition: EClass.cs:16
string name
Definition: Net.cs:14
string msg
Definition: Net.cs:16
Dictionary< string, string > items
Definition: Net.cs:58
string path
Definition: Net.cs:38
string id
Definition: Net.cs:36
string title
Definition: Net.cs:34
string cat
Definition: Net.cs:40
bool IsValidVersion()
Definition: Net.cs:46
string name
Definition: Net.cs:32
string date
Definition: Net.cs:42
int version
Definition: Net.cs:44
int index
Definition: Net.cs:25
int time
Definition: Net.cs:27
string name
Definition: Net.cs:21
int count
Definition: Net.cs:23
Definition: Net.cs:11
void ShowVote(string logs)
Definition: Net.cs:85
const string urlChat
Definition: Net.cs:65
static async UniTask< List< VoteLog > > GetVote(string idLang)
Definition: Net.cs:262
static async UniTask< List< ChatLog > > GetChat(ChatCategory cat, string idLang)
Definition: Net.cs:357
static bool isUploading
Definition: Net.cs:71
static async UniTask< bool > SendVote(int id, string idLang)
Definition: Net.cs:234
static bool ShowNetError
Definition: Net.cs:74
List< ChatLog > chatList
Definition: Net.cs:61
static async UniTask< bool > SendChat(string name, string msg, ChatCategory cat, string idLang)
Definition: Net.cs:313
const string urlUpload
Definition: Net.cs:69
static async UniTask< FileInfo > DownloadFile(DownloadMeta item, string path, string idLang)
Definition: Net.cs:160
const string urlScript
Definition: Net.cs:63
const string urlVote
Definition: Net.cs:67
static async UniTask< List< DownloadMeta > > GetFileList(string idLang)
Definition: Net.cs:193
static async UniTask< bool > UploadFile(string id, string password, string name, string title, string path, string idLang, string cat="Home")
Definition: Net.cs:103
void ShowChat(string logs)
Definition: Net.cs:94
static Version Get(string str)
Definition: Version.cs:55
bool IsBelow(int _major, int _minor, int _batch)
Definition: Version.cs:31
int GetInt()
Definition: Version.cs:21
bool IsSameOrBelow(Version v)
Definition: Version.cs:41
bool demo
Definition: Version.cs:14