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