-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathOsuDataDistributeRestfulPlugin.cs
146 lines (125 loc) · 5.07 KB
/
OsuDataDistributeRestfulPlugin.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
using OsuDataDistributeRestful.Api;
using OsuDataDistributeRestful.Server;
using Sync.Plugins;
using Sync.Tools;
using System;
using System.Linq;
using System.Net;
using System.Net.Sockets;
namespace OsuDataDistributeRestful
{
[SyncSoftRequirePlugin("OsuRTDataProviderPlugin", "RealTimePPDisplayerPlugin", "OsuLiveStatusPanelPlugin")]
[SyncPluginID("50549ae4-8ba8-4b3b-9d18-9828d43c6523", VERSION)]
public class OsuDataDistributeRestfulPlugin : Plugin
{
public const string PLUGIN_NAME = "OsuDataDistributeRestful";
public const string PLUGIN_AUTHOR = "KedamavOvO";
public const string VERSION = "0.7.0";
public static readonly Version MIN_ORTDP_VERSION = Version.Parse("1.6.0");
public static readonly Version MIN_RTPPD_VERSION = Version.Parse("1.8.0");
public ApiServer ApiServer { get; private set; }
private FileServer fileHttpServer;
private PluginConfigurationManager m_config_manager;
public OsuDataDistributeRestfulPlugin() : base(PLUGIN_NAME, PLUGIN_AUTHOR)
{
I18n.Instance.ApplyLanguage(new DefaultLanguage());
m_config_manager = new PluginConfigurationManager(this);
m_config_manager.AddItem(new SettingIni());
ApiServer = new ApiServer(Setting.ApiPort);
EventBus.BindEvent<PluginEvents.ProgramReadyEvent>(e => ApiServer.Start());
if (Setting.AllowLAN)
EventBus.BindEvent<PluginEvents.ProgramReadyEvent>(e => PrintLanAddress());
EventBus.BindEvent<PluginEvents.LoadCompleteEvent>(e => Initialize());
if (Setting.EnableFileHttpServer)
{
fileHttpServer = new FileServer(Setting.FilePort);
fileHttpServer.Start();
}
}
private void PrintLanAddress()
{
//Display IP Address
var ips = Dns.GetHostEntry(Dns.GetHostName()).AddressList.Where(ip => ip.AddressFamily == AddressFamily.InterNetwork).Distinct();
int n = 1;
foreach (var ip in ips)
{
bool recommend = ip.ToString().StartsWith("192.168.");
IO.CurrentIO.WriteColor($"[ODDR]IP {n++}:{ip}", recommend ? ConsoleColor.Green : ConsoleColor.White);
}
}
#region Initializtion
private Plugin ORTDP_Initialize()
{
var plugin = getHoster().EnumPluings().Where(p => p.Name == "OsuRTDataProvider").FirstOrDefault();
if (plugin != null)
{
if (plugin.GetType().Assembly.GetName().Version > MIN_ORTDP_VERSION)
{
ApiServer.RegisterResource(new OrtdpApis(plugin));
return plugin;
}
else
{
IO.DefaultIO.WriteColor(string.Format(DefaultLanguage.MINIMUM_VERSION_HINT, "OsuRTDataProvider", MIN_ORTDP_VERSION), ConsoleColor.Yellow);
}
}
else
{
IO.CurrentIO.WriteColor($"[ODDR]Not Found OsuRTDataProvider", ConsoleColor.Red);
}
return null;
}
private Plugin RTPPD_Initialize()
{
var plugin = getHoster().EnumPluings().Where(p => p.Name == "RealTimePPDisplayer").FirstOrDefault();
if (plugin != null)
{
if (plugin.GetType().Assembly.GetName().Version > MIN_RTPPD_VERSION)
{
ApiServer.RegisterResource(new RtppdApis(plugin));
return plugin;
}
else
{
IO.DefaultIO.WriteColor(string.Format(DefaultLanguage.MINIMUM_VERSION_HINT, "RealTimePPDisplayer", MIN_RTPPD_VERSION), ConsoleColor.Yellow);
}
}
else
{
IO.CurrentIO.WriteColor($"[ODDR]Not Found RealTimePPDisplayer", ConsoleColor.Red);
}
return null;
}
private Plugin OLSP_Initialize()
{
var plugin = getHoster().EnumPluings().Where(p => p.Name == "OsuLiveStatusPanelPlugin").FirstOrDefault();
if (plugin != null)
{
ApiServer.RegisterResource(new OlspApis(plugin));
return plugin;
}
IO.CurrentIO.WriteColor($"[ODDR]Not Found OsuLiveStatusPanel", ConsoleColor.Red);
return null;
}
#endregion Initializtion
private void Initialize()
{
var ortdp = ORTDP_Initialize();
var rtppd = RTPPD_Initialize();
var olsp = OLSP_Initialize();
if(ortdp !=null && rtppd != null)
{
ApiServer.RegisterResource(new ExtraApis(ortdp,rtppd));
}
}
public override void OnEnable()
{
Sync.Tools.IO.CurrentIO.WriteColor(PLUGIN_NAME + " By " + PLUGIN_AUTHOR, ConsoleColor.DarkCyan);
}
public override void OnExit()
{
if (Setting.EnableFileHttpServer)
fileHttpServer?.Stop();
}
}
}