Elin Decompiled Documentation EA 23.333 Myaightly Patch 1
Loading...
Searching...
No Matches
Net.cs
Go to the documentation of this file.
1using System;
2using System.Collections.Generic;
3using System.IO;
4using System.Net;
5using Cysharp.Threading.Tasks;
6using Newtonsoft.Json;
7using Newtonsoft.Json.Linq;
8using UnityEngine;
9using UnityEngine.Networking;
10
11public class Net : MonoBehaviour
12{
13 public class ChatLog
14 {
15 public string name;
16
17 public string msg;
18 }
19
20 public class BookData
21 {
22 public string name;
23
24 public string msg;
25
26 public string msg2;
27
28 public string msg3;
29
30 public string msg4;
31 }
32
33 public class VoteLog
34 {
35 public string name;
36
37 public int count;
38
39 public int index;
40
41 public int time;
42 }
43
44 public class DownloadMeta
45 {
46 public string name;
47
48 public string title;
49
50 public string id;
51
52 public string path;
53
54 public string cat;
55
56 public string tag;
57
58 public string date;
59
60 public int version;
61
62 public bool IsValidVersion()
63 {
65 {
67 }
68 return false;
69 }
70 }
71
72 public class DownloadCahce
73 {
74 public Dictionary<string, string> items = new Dictionary<string, string>();
75 }
76
77 public List<ChatLog> chatList;
78
79 public static string urlScript = "http://elin.cloudfree.jp/script/";
80
81 public static string urlBook = urlScript + "book/";
82
83 public static string urlChat = urlScript + "chat/";
84
85 public static string urlVote = urlScript + "vote/";
86
87 public static string urlUpload = urlScript + "uploader/";
88
89 public static bool isUploading;
90
91 public static bool ShowNetError
92 {
93 get
94 {
96 {
97 return EClass.debug.enable;
98 }
99 return true;
100 }
101 }
102
103 public void ShowVote(string logs)
104 {
105 StringReader stringReader = new StringReader(logs);
106 for (string text = stringReader.ReadLine(); text != null; text = stringReader.ReadLine())
107 {
108 Debug.Log(text);
109 }
110 }
111
112 public void ShowChat(string logs)
113 {
114 foreach (JToken item in (JArray)JsonConvert.DeserializeObject(logs))
115 {
116 ChatLog chatLog = item.ToObject<ChatLog>();
117 Debug.Log(chatLog.name + "/" + chatLog.msg);
118 }
119 }
120
121 public static async UniTask<bool> UploadFile(string id, string password, string name, string title, string path, string idLang, string cat = "Home", string tag = "")
122 {
123 if (isUploading)
124 {
125 EClass.ui.Say("sys_uploadUploading");
126 return false;
127 }
128 EClass.ui.Say("sys_uploadStart");
129 byte[] array;
130 using (FileStream fileStream = File.OpenRead(path))
131 {
132 array = new byte[fileStream.Length];
133 fileStream.Read(array, 0, (int)fileStream.Length);
134 }
135 WWWForm wWWForm = new WWWForm();
136 wWWForm.AddField("mode", 1);
137 wWWForm.AddField("id", id.RemoveNewline());
138 wWWForm.AddField("name", name.RemoveNewline());
139 wWWForm.AddField("title", title.RemoveNewline());
140 wWWForm.AddField("cat", cat);
141 wWWForm.AddField("tag", tag);
142 wWWForm.AddField("idLang", idLang);
143 wWWForm.AddField("password", password);
144 wWWForm.AddField("submit", "Send");
145 wWWForm.AddField("version", EClass.core.version.GetInt().ToString() ?? "");
146 wWWForm.AddBinaryData("file", array, "file.z");
147 isUploading = true;
148 Debug.Log(id);
149 Debug.Log(name);
150 Debug.Log(title);
151 Debug.Log(idLang);
152 Debug.Log(password);
153 Debug.Log(tag);
154 Debug.Log(array.Length);
155 using (UnityWebRequest www = UnityWebRequest.Post(urlUpload + "uploader.php", wWWForm))
156 {
157 try
158 {
159 await www.SendWebRequest();
160 Debug.Log(www.result.ToString());
161 Debug.Log(www.downloadHandler.ToString());
162 Debug.Log(www.downloadHandler.text);
163 Debug.Log(www.downloadHandler.text.ToString());
164 }
165 catch (Exception ex)
166 {
167 EClass.ui.Say(ex.Message);
168 }
169 isUploading = false;
170 if (www.result != UnityWebRequest.Result.Success)
171 {
172 EClass.ui.Say((www.responseCode == 401) ? "sys_uploadConflict" : "sys_uploadFail");
173 return false;
174 }
175 }
176 EClass.ui.Say("sys_uploadSuccess");
177 return true;
178 }
179
180 public static async UniTask<FileInfo> DownloadFile(DownloadMeta item, string path, string idLang)
181 {
182 string path2 = item.id + ".z";
183 string fullPath = path + path2.SanitizeFileName();
184 DownloadCahce caches = IO.LoadFile<DownloadCahce>(CorePath.ZoneSaveUser + "cache.txt") ?? new DownloadCahce();
185 if (caches.items.TryGetValue(item.id) == item.date.Replace("\"", "") && File.Exists(fullPath))
186 {
187 Debug.Log("Returning Cache:" + fullPath);
188 return new FileInfo(fullPath);
189 }
190 using UnityWebRequest www = UnityWebRequest.Get(urlUpload + item.path);
191 www.downloadHandler = new DownloadHandlerFile(fullPath);
192 try
193 {
194 await www.SendWebRequest();
195 }
196 catch (Exception ex)
197 {
198 EClass.ui.Say(ex.Message);
199 }
200 FileInfo fileInfo = new FileInfo(fullPath);
201 if (!fileInfo.Exists || www.result != UnityWebRequest.Result.Success)
202 {
203 if (ShowNetError)
204 {
205 EClass.ui.Say(www.error);
206 }
207 return null;
208 }
209 caches.items[item.id] = item.date;
210 IO.SaveFile(CorePath.ZoneSaveUser + "cache.txt", caches);
211 return fileInfo;
212 }
213
214 public static async UniTask<List<DownloadMeta>> GetFileList(string idLang)
215 {
216 List<DownloadMeta> list = new List<DownloadMeta>();
217 using UnityWebRequest www = UnityWebRequest.Get(urlUpload + "files/" + idLang + "/index.txt");
218 try
219 {
220 await www.SendWebRequest();
221 }
222 catch (Exception ex)
223 {
224 EClass.ui.Say(ex.Message);
225 }
226 if (www.result != UnityWebRequest.Result.Success)
227 {
228 if (ShowNetError)
229 {
230 EClass.ui.Say(www.error);
231 }
232 return null;
233 }
234 string[] array = www.downloadHandler.text.SplitNewline();
235 foreach (string obj in array)
236 {
237 string[] array2 = obj.Split(',');
238 if (obj.StartsWith("files") && array2.Length >= 7)
239 {
240 list.Add(new DownloadMeta
241 {
242 path = array2[0],
243 id = WebUtility.HtmlDecode(array2[1]),
244 name = WebUtility.HtmlDecode(array2[2]),
245 title = WebUtility.HtmlDecode(array2[3]),
246 cat = array2[5],
247 date = array2[6].Replace("\"", ""),
248 version = ((array2.Length > 8) ? array2[8].ToInt() : 0),
249 tag = ((array2.Length > 9) ? array2[9] : "")
250 });
251 }
252 }
253 return list;
254 }
255
256 public static async UniTask<bool> SendVote(int id, string idLang)
257 {
258 try
259 {
260 Debug.Log("Start Sending Vote:");
261 WWWForm wWWForm = new WWWForm();
262 wWWForm.AddField("vote", id.ToString() ?? "");
263 wWWForm.AddField("idLang", idLang);
264 wWWForm.AddField("submit", "Send");
265 using UnityWebRequest www = UnityWebRequest.Post(urlVote + "vote.php", wWWForm);
266 await www.SendWebRequest();
267 if (www.result == UnityWebRequest.Result.ConnectionError || www.result == UnityWebRequest.Result.ProtocolError)
268 {
269 if (ShowNetError)
270 {
271 EClass.ui.Say(www.error);
272 }
273 return false;
274 }
275 Debug.Log(www.downloadHandler.text);
276 return true;
277 }
278 catch
279 {
280 return true;
281 }
282 }
283
284 public static async UniTask<List<VoteLog>> GetVote(string idLang)
285 {
286 List<VoteLog> list = new List<VoteLog>();
287 try
288 {
289 string uri = string.Format(urlVote + "logs/data_{0}.txt", idLang);
290 using UnityWebRequest www = UnityWebRequest.Get(uri);
291 await www.SendWebRequest();
292 if (www.result == UnityWebRequest.Result.ConnectionError || www.result == UnityWebRequest.Result.ProtocolError)
293 {
294 if (ShowNetError)
295 {
296 EClass.ui.Say(www.error);
297 }
298 }
299 else
300 {
301 StringReader stringReader = new StringReader(www.downloadHandler.text);
302 int num = 0;
303 for (string text = stringReader.ReadLine(); text != null; text = stringReader.ReadLine())
304 {
305 string[] array = text.Split(',');
306 if (num == 0)
307 {
308 list.Add(new VoteLog
309 {
310 name = array[0].Replace("\"", ""),
311 time = array[2].ToInt(),
312 index = num
313 });
314 }
315 else
316 {
317 list.Add(new VoteLog
318 {
319 name = array[0].Replace("\"", ""),
320 count = array[1].ToInt(),
321 index = num
322 });
323 }
324 num++;
325 }
326 }
327 return list;
328 }
329 catch
330 {
331 return list;
332 }
333 }
334
335 public static async UniTask<bool> SendChat(string name, string msg, ChatCategory cat, string idLang)
336 {
338 {
339 return false;
340 }
342 {
343 return false;
344 }
345 try
346 {
347 if (EClass.debug.enable)
348 {
349 idLang = "DEBUG";
350 }
351 Debug.Log("Start Sending Text:");
352 WWWForm wWWForm = new WWWForm();
353 wWWForm.AddField("submit", "Send");
354 wWWForm.AddField("name", name);
355 wWWForm.AddField("msg", msg);
356 wWWForm.AddField("cat", cat.ToString());
357 wWWForm.AddField("idLang", idLang);
358 try
359 {
360 using UnityWebRequest www = UnityWebRequest.Post(urlChat + "chat.php", wWWForm);
361 await www.SendWebRequest();
362 if (www.result == UnityWebRequest.Result.ConnectionError || www.result == UnityWebRequest.Result.ProtocolError)
363 {
364 if (ShowNetError)
365 {
366 EClass.ui.Say(www.error);
367 }
368 return false;
369 }
370 Debug.Log(www.downloadHandler.text);
371 return true;
372 }
373 catch
374 {
375 }
376 }
377 catch
378 {
379 }
380 return false;
381 }
382
383 public static async UniTask<List<ChatLog>> GetChat(ChatCategory cat, string idLang)
384 {
385 List<ChatLog> list = new List<ChatLog>();
386 try
387 {
388 if (EClass.debug.enable)
389 {
390 idLang = "DEBUG";
391 }
392 string uri = string.Format(urlChat + "logs/all_{0}.json", idLang);
393 using UnityWebRequest www = UnityWebRequest.Get(uri);
394 await www.SendWebRequest();
395 if (www.result == UnityWebRequest.Result.ConnectionError || www.result == UnityWebRequest.Result.ProtocolError)
396 {
397 return null;
398 }
399 Debug.Log("Download Chat Logs: Success");
400 foreach (JToken item in (JArray)JsonConvert.DeserializeObject(www.downloadHandler.text))
401 {
402 list.Add(item.ToObject<ChatLog>());
403 }
404 foreach (ChatLog item2 in list)
405 {
406 item2.msg = item2.msg.Replace("\n", "").Replace("\r", "").Replace("&quot;", "\"")
407 .ToTitleCase();
408 }
409 list.Reverse();
410 return list;
411 }
412 catch
413 {
414 return list;
415 }
416 }
417
418 public static async UniTask<bool> SendBook(string name, string msg, BookCategory cat, string idLang, string msg2, string msg3, string msg4)
419 {
421 {
422 return false;
423 }
424 try
425 {
426 if (EClass.debug.enable)
427 {
428 idLang = "DEBUG";
429 }
430 Debug.Log("Start Sending Book:");
431 WWWForm wWWForm = new WWWForm();
432 wWWForm.AddField("submit", "Send");
433 wWWForm.AddField("name", name);
434 wWWForm.AddField("msg", msg);
435 wWWForm.AddField("cat", cat.ToString());
436 wWWForm.AddField("idLang", idLang);
437 wWWForm.AddField("msg2", msg2);
438 wWWForm.AddField("msg3", msg3);
439 wWWForm.AddField("msg4", msg4);
440 try
441 {
442 using UnityWebRequest www = UnityWebRequest.Post(urlBook + "book.php", wWWForm);
443 await www.SendWebRequest();
444 if (www.result == UnityWebRequest.Result.ConnectionError || www.result == UnityWebRequest.Result.ProtocolError)
445 {
446 if (ShowNetError)
447 {
448 EClass.ui.Say(www.error);
449 }
450 return false;
451 }
452 Debug.Log(www.downloadHandler.text);
453 return true;
454 }
455 catch
456 {
457 }
458 }
459 catch
460 {
461 }
462 return false;
463 }
464
465 public static async UniTask<List<BookData>> GetBook(BookCategory cat, string idLang)
466 {
467 List<BookData> list = new List<BookData>();
468 try
469 {
470 if (EClass.debug.enable)
471 {
472 idLang = "DEBUG";
473 }
474 string uri = string.Format(urlBook + "logs/all_{0}.json", idLang);
475 using UnityWebRequest www = UnityWebRequest.Get(uri);
476 await www.SendWebRequest();
477 if (www.result == UnityWebRequest.Result.ConnectionError || www.result == UnityWebRequest.Result.ProtocolError)
478 {
479 return null;
480 }
481 Debug.Log("Download Book: Success");
482 foreach (JToken item in (JArray)JsonConvert.DeserializeObject(www.downloadHandler.text))
483 {
484 list.Add(item.ToObject<BookData>());
485 }
486 foreach (BookData item2 in list)
487 {
488 item2.msg = item2.msg.Replace("\n", "").Replace("\r", "").Replace("&quot;", "\"")
489 .ToTitleCase();
490 }
491 list.Reverse();
492 return list;
493 }
494 catch
495 {
496 return list;
497 }
498 }
499}
BookCategory
Definition: BookCategory.cs:2
ChatCategory
Definition: ChatCategory.cs:2
item3. title
Definition: UIBook.cs:640
Version version
Definition: BaseCore.cs:17
Version versionMoongate
Definition: BaseCore.cs:19
NetSetting net
Definition: CoreConfig.cs:621
bool enable
Definition: CoreDebug.cs:301
static string ZoneSaveUser
Definition: CorePath.cs:194
CoreConfig config
Definition: Core.cs:70
Definition: EClass.cs:6
static Core core
Definition: EClass.cs:7
static CoreDebug debug
Definition: EClass.cs:49
static UI ui
Definition: EClass.cs:17
string msg
Definition: Net.cs:24
string msg2
Definition: Net.cs:26
string msg3
Definition: Net.cs:28
string msg4
Definition: Net.cs:30
string name
Definition: Net.cs:22
string name
Definition: Net.cs:15
string msg
Definition: Net.cs:17
Dictionary< string, string > items
Definition: Net.cs:74
string path
Definition: Net.cs:52
string id
Definition: Net.cs:50
string tag
Definition: Net.cs:56
string title
Definition: Net.cs:48
string cat
Definition: Net.cs:54
bool IsValidVersion()
Definition: Net.cs:62
string name
Definition: Net.cs:46
string date
Definition: Net.cs:58
int version
Definition: Net.cs:60
int index
Definition: Net.cs:39
int time
Definition: Net.cs:41
string name
Definition: Net.cs:35
int count
Definition: Net.cs:37
Definition: Net.cs:12
void ShowVote(string logs)
Definition: Net.cs:103
static async UniTask< List< VoteLog > > GetVote(string idLang)
Definition: Net.cs:284
static string urlScript
Definition: Net.cs:79
static async UniTask< List< ChatLog > > GetChat(ChatCategory cat, string idLang)
Definition: Net.cs:383
static bool isUploading
Definition: Net.cs:89
static async UniTask< bool > SendVote(int id, string idLang)
Definition: Net.cs:256
static bool ShowNetError
Definition: Net.cs:92
static async UniTask< List< BookData > > GetBook(BookCategory cat, string idLang)
Definition: Net.cs:465
List< ChatLog > chatList
Definition: Net.cs:77
static async UniTask< bool > SendChat(string name, string msg, ChatCategory cat, string idLang)
Definition: Net.cs:335
static string urlChat
Definition: Net.cs:83
static async UniTask< bool > UploadFile(string id, string password, string name, string title, string path, string idLang, string cat="Home", string tag="")
Definition: Net.cs:121
static async UniTask< FileInfo > DownloadFile(DownloadMeta item, string path, string idLang)
Definition: Net.cs:180
static string urlUpload
Definition: Net.cs:87
static string urlBook
Definition: Net.cs:81
static async UniTask< bool > SendBook(string name, string msg, BookCategory cat, string idLang, string msg2, string msg3, string msg4)
Definition: Net.cs:418
static async UniTask< List< DownloadMeta > > GetFileList(string idLang)
Definition: Net.cs:214
void ShowChat(string logs)
Definition: Net.cs:112
static string urlVote
Definition: Net.cs:85
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