Elin Decompiled Documentation EA 23.102 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 date;
41
42 public int version;
43
44 public bool IsValidVersion()
45 {
47 }
48 }
49
50 public class DownloadCahce
51 {
52 public Dictionary<string, string> items = new Dictionary<string, string>();
53 }
54
55 public List<ChatLog> chatList;
56
57 private const string urlScript = "http://ylva.php.xdomain.jp/script/";
58
59 private const string urlChat = "http://ylva.php.xdomain.jp/script/chat/";
60
61 private const string urlVote = "http://ylva.php.xdomain.jp/script/vote/";
62
63 private const string urlUpload = "http://ylva.php.xdomain.jp/script/uploader/";
64
65 public static bool isUploading;
66
67 public static bool ShowNetError
68 {
69 get
70 {
72 {
73 return EClass.debug.enable;
74 }
75 return true;
76 }
77 }
78
79 public void ShowVote(string logs)
80 {
81 StringReader stringReader = new StringReader(logs);
82 for (string text = stringReader.ReadLine(); text != null; text = stringReader.ReadLine())
83 {
84 Debug.Log(text);
85 }
86 }
87
88 public void ShowChat(string logs)
89 {
90 foreach (JToken item in (JArray)JsonConvert.DeserializeObject(logs))
91 {
92 ChatLog chatLog = item.ToObject<ChatLog>();
93 Debug.Log(chatLog.name + "/" + chatLog.msg);
94 }
95 }
96
97 public static async UniTask<bool> UploadFile(string id, string password, string name, string title, string path, string idLang)
98 {
99 if (isUploading)
100 {
101 EClass.ui.Say("sys_uploadUploading");
102 return false;
103 }
104 EClass.ui.Say("sys_uploadStart");
105 byte[] array;
106 using (FileStream fileStream = File.OpenRead(path))
107 {
108 array = new byte[fileStream.Length];
109 fileStream.Read(array, 0, (int)fileStream.Length);
110 }
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");
120 wWWForm.AddField("version", EClass.core.version.GetInt().ToString() ?? "");
121 wWWForm.AddBinaryData("file", array, "file.z");
122 isUploading = true;
123 Debug.Log(id);
124 Debug.Log(name);
125 Debug.Log(title);
126 Debug.Log(idLang);
127 Debug.Log(password);
128 Debug.Log(array.Length);
129 using (UnityWebRequest www = UnityWebRequest.Post("http://ylva.php.xdomain.jp/script/uploader/uploader.php", wWWForm))
130 {
131 try
132 {
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());
138 }
139 catch (Exception ex)
140 {
141 EClass.ui.Say(ex.Message);
142 }
143 isUploading = false;
144 if (www.result != UnityWebRequest.Result.Success)
145 {
146 EClass.ui.Say((www.responseCode == 401) ? "sys_uploadConflict" : "sys_uploadFail");
147 return false;
148 }
149 }
150 EClass.ui.Say("sys_uploadSuccess");
151 return true;
152 }
153
154 public static async UniTask<FileInfo> DownloadFile(DownloadMeta item, string path, string idLang)
155 {
156 string fn = item.id + ".z";
157 DownloadCahce caches = IO.LoadFile<DownloadCahce>(CorePath.ZoneSaveUser + "cache.txt") ?? new DownloadCahce();
158 if (caches.items.TryGetValue(item.id) == item.date.Replace("\"", "") && File.Exists(path + fn))
159 {
160 Debug.Log("Returning Cache:" + path + fn);
161 return new FileInfo(path + fn);
162 }
163 using UnityWebRequest www = UnityWebRequest.Get("http://ylva.php.xdomain.jp/script/uploader/files/" + idLang + "/" + fn);
164 www.downloadHandler = new DownloadHandlerFile(path + fn);
165 try
166 {
167 await www.SendWebRequest();
168 }
169 catch (Exception ex)
170 {
171 EClass.ui.Say(ex.Message);
172 }
173 FileInfo fileInfo = new FileInfo(path + fn);
174 if (!fileInfo.Exists || www.result != UnityWebRequest.Result.Success)
175 {
176 if (ShowNetError)
177 {
178 EClass.ui.Say(www.error);
179 }
180 return null;
181 }
182 caches.items[item.id] = item.date;
183 IO.SaveFile(CorePath.ZoneSaveUser + "cache.txt", caches);
184 return fileInfo;
185 }
186
187 public static async UniTask<List<DownloadMeta>> GetFileList(string idLang)
188 {
189 List<DownloadMeta> list = new List<DownloadMeta>();
190 using UnityWebRequest www = UnityWebRequest.Get("http://ylva.php.xdomain.jp/script/uploader/files/" + idLang + "/index.txt");
191 try
192 {
193 await www.SendWebRequest();
194 }
195 catch (Exception ex)
196 {
197 EClass.ui.Say(ex.Message);
198 }
199 if (www.result != UnityWebRequest.Result.Success)
200 {
201 if (ShowNetError)
202 {
203 EClass.ui.Say(www.error);
204 }
205 return null;
206 }
207 StringReader stringReader = new StringReader(www.downloadHandler.text);
208 for (string text = stringReader.ReadLine(); text != null; text = stringReader.ReadLine())
209 {
210 if (!string.IsNullOrEmpty(text))
211 {
212 string[] array = text.Split(',');
213 list.Add(new DownloadMeta
214 {
215 path = array[0],
216 id = array[1].Replace("\"", ""),
217 name = array[2],
218 title = array[3],
219 date = array[6].Replace("\"", ""),
220 version = ((array.Length >= 9) ? array[8].ToInt() : 0)
221 });
222 }
223 }
224 return list;
225 }
226
227 public static async UniTask<bool> SendVote(int id, string idLang)
228 {
229 try
230 {
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)
239 {
240 if (ShowNetError)
241 {
242 EClass.ui.Say(www.error);
243 }
244 return false;
245 }
246 Debug.Log(www.downloadHandler.text);
247 return true;
248 }
249 catch
250 {
251 return true;
252 }
253 }
254
255 public static async UniTask<List<VoteLog>> GetVote(string idLang)
256 {
257 List<VoteLog> list = new List<VoteLog>();
258 try
259 {
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)
264 {
265 if (ShowNetError)
266 {
267 EClass.ui.Say(www.error);
268 }
269 }
270 else
271 {
272 StringReader stringReader = new StringReader(www.downloadHandler.text);
273 int num = 0;
274 for (string text = stringReader.ReadLine(); text != null; text = stringReader.ReadLine())
275 {
276 string[] array = text.Split(',');
277 if (num == 0)
278 {
279 list.Add(new VoteLog
280 {
281 name = array[0].Replace("\"", ""),
282 time = array[2].ToInt(),
283 index = num
284 });
285 }
286 else
287 {
288 list.Add(new VoteLog
289 {
290 name = array[0].Replace("\"", ""),
291 count = array[1].ToInt(),
292 index = num
293 });
294 }
295 num++;
296 }
297 }
298 return list;
299 }
300 catch
301 {
302 return list;
303 }
304 }
305
306 public static async UniTask<bool> SendChat(string name, string msg, ChatCategory cat, string idLang)
307 {
309 {
310 return false;
311 }
312 try
313 {
314 if (EClass.debug.enable)
315 {
316 idLang = "DEBUG";
317 }
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);
325 try
326 {
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)
330 {
331 if (ShowNetError)
332 {
333 EClass.ui.Say(www.error);
334 }
335 return false;
336 }
337 Debug.Log(www.downloadHandler.text);
338 return true;
339 }
340 catch
341 {
342 }
343 }
344 catch
345 {
346 }
347 return false;
348 }
349
350 public static async UniTask<List<ChatLog>> GetChat(ChatCategory cat, string idLang)
351 {
352 List<ChatLog> list = new List<ChatLog>();
353 try
354 {
355 if (EClass.debug.enable)
356 {
357 idLang = "DEBUG";
358 }
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)
363 {
364 return null;
365 }
366 Debug.Log("Download Chat Logs: Success");
367 foreach (JToken item in (JArray)JsonConvert.DeserializeObject(www.downloadHandler.text))
368 {
369 list.Add(item.ToObject<ChatLog>());
370 }
371 foreach (ChatLog item2 in list)
372 {
373 item2.msg = item2.msg.Replace("\n", "").Replace("\r", "").Replace("&quot;", "\"")
374 .ToTitleCase();
375 }
376 list.Reverse();
377 return list;
378 }
379 catch
380 {
381 return list;
382 }
383 }
384}
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:52
string path
Definition: Net.cs:38
string id
Definition: Net.cs:36
string title
Definition: Net.cs:34
bool IsValidVersion()
Definition: Net.cs:44
string name
Definition: Net.cs:32
string date
Definition: Net.cs:40
int version
Definition: Net.cs:42
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:79
const string urlChat
Definition: Net.cs:59
static async UniTask< List< VoteLog > > GetVote(string idLang)
Definition: Net.cs:255
static async UniTask< List< ChatLog > > GetChat(ChatCategory cat, string idLang)
Definition: Net.cs:350
static bool isUploading
Definition: Net.cs:65
static async UniTask< bool > SendVote(int id, string idLang)
Definition: Net.cs:227
static bool ShowNetError
Definition: Net.cs:68
List< ChatLog > chatList
Definition: Net.cs:55
static async UniTask< bool > SendChat(string name, string msg, ChatCategory cat, string idLang)
Definition: Net.cs:306
const string urlUpload
Definition: Net.cs:63
static async UniTask< bool > UploadFile(string id, string password, string name, string title, string path, string idLang)
Definition: Net.cs:97
static async UniTask< FileInfo > DownloadFile(DownloadMeta item, string path, string idLang)
Definition: Net.cs:154
const string urlScript
Definition: Net.cs:57
const string urlVote
Definition: Net.cs:61
static async UniTask< List< DownloadMeta > > GetFileList(string idLang)
Definition: Net.cs:187
void ShowChat(string logs)
Definition: Net.cs:88
static Version Get(string str)
Definition: Version.cs:46
bool IsBelow(int _major, int _minor, int _batch)
Definition: Version.cs:31
int GetInt()
Definition: Version.cs:21
bool demo
Definition: Version.cs:14