-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathLOServerList.cs
98 lines (90 loc) · 3.58 KB
/
LOServerList.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
namespace Pcap
{
public enum ServerType
{
List, Login, Gate, Rank, Chat, Battle, Error
}
public static class LOServerList
{
private static readonly string ListServerIP = "livelolistserveralb-140120882.ap-northeast-2.elb.amazonaws.com"; //불변 리스트 서버
private static string GateServerVersion { get; set; }
private static string LoginServerIP { get; set; }
private static string LoginServerPort { get; set; }
private static string GateServerIP { get; set; }
private static string GateServerPort { get; set; }
private static string RankServerIP { get; set; }
private static string RankServerPort { get; set; }
private static string ChatServerIP { get; set; }
private static string ChatServerPort { get; set; }
private static readonly Dictionary<ServerType, string[]> ServerIPList = new Dictionary<ServerType, string[]>();
static LOServerList()
{
ServerIPList.Add(ServerType.List, Dns2IPArray(ListServerIP));
}
private static string[] Dns2IPArray(string dns)
{
try
{
return Dns.GetHostAddresses(dns).Select(ip => ip.ToString()).ToArray();
}
catch
{
return null;
}
}
public static void ParseServer(string body)
{
JObject json = JObject.Parse(body);
JToken error = json["ErrorCode"];
if ((int)error == 27)
{
CLI.PrintQueueLog(Channel.Zero, "서버 점검중", ConsoleColor.Red);
}
else if ((int)error == 0)
{
JToken token = json["Result"][0];
GateServerVersion = (string)token["GateServerVersion"];
LoginServerIP = (string)token["LoginServerIP"];
LoginServerPort = (string)token["LoginServerPort"];
GateServerIP = (string)token["GateServerIP"];
GateServerPort = (string)token["GateServerPort"];
RankServerIP = (string)token["RankServerIP"];
RankServerPort = (string)token["RankServerPort"];
ChatServerIP = (string)token["ChatServerIP"];
ChatServerPort = (string)token["ChatServerPort"];
ServerIPList[ServerType.Login] = Dns2IPArray(LoginServerIP);
ServerIPList[ServerType.Gate] = Dns2IPArray(GateServerIP);
ServerIPList[ServerType.Rank] = Dns2IPArray(RankServerIP);
ServerIPList[ServerType.Chat] = Dns2IPArray(ChatServerIP);
CLI.PrintQueueLog(Channel.Zero, "서버 주소 확인",ConsoleColor.White);
}
}
public static void ParserBattleServer(string body)
{
JObject json = JObject.Parse(body);
JToken token = json["ServerIP"];
ServerIPList[ServerType.Battle] = new string[] { (string)token };
}
public static ServerType GetServerType(params string[] ip)
{
foreach (KeyValuePair<ServerType, string[]> i in ServerIPList)
{
if (i.Value == null)
{
continue;
}
//Console.WriteLine(i.Key);
if (i.Value.Any((str) => ip.Any((arr) => str.Equals(arr))))
{
return i.Key;
}
}
return ServerType.Error;
}
}
}