Elin Decompiled Documentation EA 23.319 Nightly 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 fn = item.id + ".z";
183 DownloadCahce caches = IO.LoadFile<DownloadCahce>(CorePath.ZoneSaveUser + "cache.txt") ?? new DownloadCahce();
184 if (caches.items.TryGetValue(item.id) == item.date.Replace("\"", "") && File.Exists(path + fn))
185 {
186 Debug.Log("Returning Cache:" + path + fn);
187 return new FileInfo(path + fn);
188 }
189 using UnityWebRequest www = UnityWebRequest.Get(urlUpload + "files/" + idLang + "/" + fn);
190 www.downloadHandler = new DownloadHandlerFile(path + fn);
191 try
192 {
193 await www.SendWebRequest();
194 }
195 catch (Exception ex)
196 {
197 EClass.ui.Say(ex.Message);
198 }
199 FileInfo fileInfo = new FileInfo(path + fn);
200 if (!fileInfo.Exists || www.result != UnityWebRequest.Result.Success)
201 {
202 if (ShowNetError)
203 {
204 EClass.ui.Say(www.error);
205 }
206 return null;
207 }
208 caches.items[item.id] = item.date;
209 IO.SaveFile(CorePath.ZoneSaveUser + "cache.txt", caches);
210 return fileInfo;
211 }
212
213 public static async UniTask<List<DownloadMeta>> GetFileList(string idLang)
214 {
215 List<DownloadMeta> list = new List<DownloadMeta>();
216 using UnityWebRequest www = UnityWebRequest.Get(urlUpload + "files/" + idLang + "/index.txt");
217 try
218 {
219 await www.SendWebRequest();
220 }
221 catch (Exception ex)
222 {
223 EClass.ui.Say(ex.Message);
224 }
225 if (www.result != UnityWebRequest.Result.Success)
226 {
227 if (ShowNetError)
228 {
229 EClass.ui.Say(www.error);
230 }
231 return null;
232 }
233 string[] array = www.downloadHandler.text.SplitNewline();
234 foreach (string obj in array)
235 {
236 string[] array2 = obj.Split(',');
237 if (obj.StartsWith("files") && array2.Length >= 7)
238 {
239 list.Add(new DownloadMeta
240 {
241 path = array2[0],
242 id = WebUtility.HtmlDecode(array2[1]),
243 name = WebUtility.HtmlDecode(array2[2]),
244 title = WebUtility.HtmlDecode(array2[3]),
245 cat = array2[5],
246 date = array2[6].Replace("\"", ""),
247 version = ((array2.Length > 8) ? array2[8].ToInt() : 0),
248 tag = ((array2.Length > 9) ? array2[9] : "")
249 });
250 }
251 }
252 return list;
253 }
254
255 public static async UniTask<bool> SendVote(int id, string idLang)
256 {
257 try
258 {
259 Debug.Log("Start Sending Vote:");
260 WWWForm wWWForm = new WWWForm();
261 wWWForm.AddField("vote", id.ToString() ?? "");
262 wWWForm.AddField("idLang", idLang);
263 wWWForm.AddField("submit", "Send");
264 using UnityWebRequest www = UnityWebRequest.Post(urlVote + "vote.php", wWWForm);
265 await www.SendWebRequest();
266 if (www.result == UnityWebRequest.Result.ConnectionError || www.result == UnityWebRequest.Result.ProtocolError)
267 {
268 if (ShowNetError)
269 {
270 EClass.ui.Say(www.error);
271 }
272 return false;
273 }
274 Debug.Log(www.downloadHandler.text);
275 return true;
276 }
277 catch
278 {
279 return true;
280 }
281 }
282
283 public static async UniTask<List<VoteLog>> GetVote(string idLang)
284 {
285 List<VoteLog> list = new List<VoteLog>();
286 try
287 {
288 string uri = string.Format(urlVote + "logs/data_{0}.txt", idLang);
289 using UnityWebRequest www = UnityWebRequest.Get(uri);
290 await www.SendWebRequest();
291 if (www.result == UnityWebRequest.Result.ConnectionError || www.result == UnityWebRequest.Result.ProtocolError)
292 {
293 if (ShowNetError)
294 {
295 EClass.ui.Say(www.error);
296 }
297 }
298 else
299 {
300 StringReader stringReader = new StringReader(www.downloadHandler.text);
301 int num = 0;
302 for (string text = stringReader.ReadLine(); text != null; text = stringReader.ReadLine())
303 {
304 string[] array = text.Split(',');
305 if (num == 0)
306 {
307 list.Add(new VoteLog
308 {
309 name = array[0].Replace("\"", ""),
310 time = array[2].ToInt(),
311 index = num
312 });
313 }
314 else
315 {
316 list.Add(new VoteLog
317 {
318 name = array[0].Replace("\"", ""),
319 count = array[1].ToInt(),
320 index = num
321 });
322 }
323 num++;
324 }
325 }
326 return list;
327 }
328 catch
329 {
330 return list;
331 }
332 }
333
334 public static async UniTask<bool> SendChat(string name, string msg, ChatCategory cat, string idLang)
335 {
337 {
338 return false;
339 }
341 {
342 return false;
343 }
344 try
345 {
346 if (EClass.debug.enable)
347 {
348 idLang = "DEBUG";
349 }
350 Debug.Log("Start Sending Text:");
351 WWWForm wWWForm = new WWWForm();
352 wWWForm.AddField("submit", "Send");
353 wWWForm.AddField("name", name);
354 wWWForm.AddField("msg", msg);
355 wWWForm.AddField("cat", cat.ToString());
356 wWWForm.AddField("idLang", idLang);
357 try
358 {
359 using UnityWebRequest www = UnityWebRequest.Post(urlChat + "chat.php", wWWForm);
360 await www.SendWebRequest();
361 if (www.result == UnityWebRequest.Result.ConnectionError || www.result == UnityWebRequest.Result.ProtocolError)
362 {
363 if (ShowNetError)
364 {
365 EClass.ui.Say(www.error);
366 }
367 return false;
368 }
369 Debug.Log(www.downloadHandler.text);
370 return true;
371 }
372 catch
373 {
374 }
375 }
376 catch
377 {
378 }
379 return false;
380 }
381
382 public static async UniTask<List<ChatLog>> GetChat(ChatCategory cat, string idLang)
383 {
384 List<ChatLog> list = new List<ChatLog>();
385 try
386 {
387 if (EClass.debug.enable)
388 {
389 idLang = "DEBUG";
390 }
391 string uri = string.Format(urlChat + "logs/all_{0}.json", idLang);
392 using UnityWebRequest www = UnityWebRequest.Get(uri);
393 await www.SendWebRequest();
394 if (www.result == UnityWebRequest.Result.ConnectionError || www.result == UnityWebRequest.Result.ProtocolError)
395 {
396 return null;
397 }
398 Debug.Log("Download Chat Logs: Success");
399 foreach (JToken item in (JArray)JsonConvert.DeserializeObject(www.downloadHandler.text))
400 {
401 list.Add(item.ToObject<ChatLog>());
402 }
403 foreach (ChatLog item2 in list)
404 {
405 item2.msg = item2.msg.Replace("\n", "").Replace("\r", "").Replace("&quot;", "\"")
406 .ToTitleCase();
407 }
408 list.Reverse();
409 return list;
410 }
411 catch
412 {
413 return list;
414 }
415 }
416
417 public static async UniTask<bool> SendBook(string name, string msg, BookCategory cat, string idLang, string msg2, string msg3, string msg4)
418 {
420 {
421 return false;
422 }
423 try
424 {
425 if (EClass.debug.enable)
426 {
427 idLang = "DEBUG";
428 }
429 Debug.Log("Start Sending Book:");
430 WWWForm wWWForm = new WWWForm();
431 wWWForm.AddField("submit", "Send");
432 wWWForm.AddField("name", name);
433 wWWForm.AddField("msg", msg);
434 wWWForm.AddField("cat", cat.ToString());
435 wWWForm.AddField("idLang", idLang);
436 wWWForm.AddField("msg2", msg2);
437 wWWForm.AddField("msg3", msg3);
438 wWWForm.AddField("msg4", msg4);
439 try
440 {
441 using UnityWebRequest www = UnityWebRequest.Post(urlBook + "book.php", wWWForm);
442 await www.SendWebRequest();
443 if (www.result == UnityWebRequest.Result.ConnectionError || www.result == UnityWebRequest.Result.ProtocolError)
444 {
445 if (ShowNetError)
446 {
447 EClass.ui.Say(www.error);
448 }
449 return false;
450 }
451 Debug.Log(www.downloadHandler.text);
452 return true;
453 }
454 catch
455 {
456 }
457 }
458 catch
459 {
460 }
461 return false;
462 }
463
464 public static async UniTask<List<BookData>> GetBook(BookCategory cat, string idLang)
465 {
466 List<BookData> list = new List<BookData>();
467 try
468 {
469 if (EClass.debug.enable)
470 {
471 idLang = "DEBUG";
472 }
473 string uri = string.Format(urlBook + "logs/all_{0}.json", idLang);
474 using UnityWebRequest www = UnityWebRequest.Get(uri);
475 await www.SendWebRequest();
476 if (www.result == UnityWebRequest.Result.ConnectionError || www.result == UnityWebRequest.Result.ProtocolError)
477 {
478 return null;
479 }
480 Debug.Log("Download Book: Success");
481 foreach (JToken item in (JArray)JsonConvert.DeserializeObject(www.downloadHandler.text))
482 {
483 list.Add(item.ToObject<BookData>());
484 }
485 foreach (BookData item2 in list)
486 {
487 item2.msg = item2.msg.Replace("\n", "").Replace("\r", "").Replace("&quot;", "\"")
488 .ToTitleCase();
489 }
490 list.Reverse();
491 return list;
492 }
493 catch
494 {
495 return list;
496 }
497 }
498}
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:619
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:283
static string urlScript
Definition: Net.cs:79
static async UniTask< List< ChatLog > > GetChat(ChatCategory cat, string idLang)
Definition: Net.cs:382
static bool isUploading
Definition: Net.cs:89
static async UniTask< bool > SendVote(int id, string idLang)
Definition: Net.cs:255
static bool ShowNetError
Definition: Net.cs:92
static async UniTask< List< BookData > > GetBook(BookCategory cat, string idLang)
Definition: Net.cs:464
List< ChatLog > chatList
Definition: Net.cs:77
static async UniTask< bool > SendChat(string name, string msg, ChatCategory cat, string idLang)
Definition: Net.cs:334
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:417
static async UniTask< List< DownloadMeta > > GetFileList(string idLang)
Definition: Net.cs:213
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