-
Notifications
You must be signed in to change notification settings - Fork 1
/
Server.cs
185 lines (171 loc) · 5.8 KB
/
Server.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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
/*
*
* _ __ _ _ ____ ____
*\ \ / / _ _ __(_) | _____ / ___/ ___|
* \ V / | | | '__| | |/ / _ \ _____| | \___ \
* | || |_| | | | | < (_) |_____| |___ ___) |
* |_| \__,_|_| |_|_|\_\___/ \____|____/
*
* Yuriko-CS, brand a new Minecraft: Pocket Edition
* server software in C#
* Copyright 2016 ItalianDevs4PM.
*
* See LICENSE.md for the license applied to this file/project
*
*
* @author ItalianDevs4PM
* @link http://github.com/ItalianDevs4PM
*
*
*/
using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Threading;
namespace YurikoCS {
class Server {
//Client Protocol Constants
public static readonly byte[] OFFLINE_MESSAGE_DATA_ID = new byte[]{0x00, 0xff, 0xff, 0x00, 0xfe, 0xfe, 0xfe, 0xfe, 0xfd, 0xfd, 0xfd, 0xfd, 0x12, 0x34, 0x56, 0x78};
public const string MCPE_VERSION = "0.14.0.7";
public const byte MCPE_PROTOCOL_ID = 0x45;
private static Server Instance;
private static Config Cfg;
private static string Motd;
private static int MaxPlayers;
private Thread UDPServerThread;
public List<Player> OnlinePlayers = new List<Player>();
private ConsoleSender ConsSender;
public Server(){
if(Instance == null){
Instance = this;
new Logger();
String cwd = Directory.GetCurrentDirectory();
//Yuriko-CS Logo! :D
Logger.GetLogger().Info("§e***************************************************");
Logger.GetLogger().Info("§e* §a _ __ _ _ ____ ____ §e*");
Logger.GetLogger().Info("§e* §a\\ \\ / / _ _ __(_) | _____ / ___/ ___| §e*");
Logger.GetLogger().Info("§e* §a \\ V / | | | '__| | |/ / _ \\ _____| | \\___ \\ §e*");
Logger.GetLogger().Info("§e* §a | || |_| | | | | < (_) |_____| |___ ___) | §e*");
Logger.GetLogger().Info("§e* §a |_| \\__,_|_| |_|_|\\_\\___/ \\____|____/ §e*");
Logger.GetLogger().Info("§e* §e*");
Logger.GetLogger().Info("§e***************************************************");
Logger.GetLogger().Info("Starting Yuriko-CS §bv" + Version.YURIKO_CS_VERSION + " §f[§bAPI " + Version.YURIKO_CS_API_VERSION + "§f][Build §b#" + Version.YURIKO_CS_BUILD + "§f]");
if(!Directory.Exists(cwd + "/players")){
Directory.CreateDirectory(cwd + "/players");
}
if(!Directory.Exists(cwd + "/plugins")){
Directory.CreateDirectory(cwd + "/plugins");
}
if(!Directory.Exists(cwd + "/worlds")){
Directory.CreateDirectory(cwd + "/worlds");
}
Config serverprop = new PropertiesConfig("server.properties");
if(!serverprop.exists("server-name")){
serverprop.set("server-name", "Yuriko-CS Server");
}
if(!serverprop.exists("server-port")){
serverprop.set("server-port", 19132);
}
if(!serverprop.exists("gamemode")){
serverprop.set("gamemode", 1);
}
if(!serverprop.exists("max-players")){
serverprop.set("max-players", 20);
}
MaxPlayers = serverprop.getInt("max-players");
if(!serverprop.exists("motd")){
serverprop.set("motd", "§aYuriko-CS§f Minecraft: Pocket Edition Server");
}
Motd = serverprop.getString("motd");
if(!serverprop.exists("spawn-protection")){
serverprop.set("spawn-protection", 10);
}
if(!serverprop.exists("whitelist")){
serverprop.set("whitelist", false);
}
if(!serverprop.exists("enable-autosave")){
serverprop.set("enable-autosave", true);
}
if(!serverprop.exists("gamemode")){
serverprop.set("gamemode", 0);
}
if(!serverprop.exists("force-gamemode")){
serverprop.set("force-gamemode", false);
}
if(!serverprop.exists("enable-pvp")){
serverprop.set("enable-pvp", true);
}
if(!serverprop.exists("difficulty")){
serverprop.set("difficulty", 2);
}
if(!serverprop.exists("world-name")){
serverprop.set("world-name", "world");
}
if(!serverprop.exists("world-generator")){
serverprop.set("world-generator", "NORMAL");
}
//if(!serverprop.exists("world-seed")){
// serverprop.set("world-seed", "");
//}
if(!serverprop.exists("announce-achievements")){
serverprop.set("announce-achievements", true);
}
if(!serverprop.exists("enable-query")){
serverprop.set("enable-query", true);
}
if(!serverprop.exists("enable-rcon")){
serverprop.set("enable-rcon", false);
}
if(!serverprop.exists("rcon-port")){
serverprop.set("rcon-port", 18345);
}
if(!serverprop.exists("rcon-password")){
serverprop.set("rcon-password", "random");
}
serverprop.save("server.properties");
Cfg = serverprop;
ConsSender = new ConsoleSender();
DefaultPermissions.RestoreDefaultPermissions();
DefaultCommands.RestoreDefaultCommands();
Logger.GetLogger().Info("Starting Server on port: §b" + GetPort());
Logger.GetLogger().Info("Starting UDP Server thread");
PacketHandler pk = new PacketHandler(GetPort());
pk.Start();
Thread UDPServerSenderThread = new Thread(new ThreadStart(pk.StartSendThread));
UDPServerSenderThread.Start();
waitConsoleInput();
}else{
Logger.GetLogger().Critical("Server already initialized!");
}
}
private void waitConsoleInput(){
Console.Write(">");
string cmd = Console.ReadLine();
Command.Execute(GetConsoleSender(), cmd);
waitConsoleInput();
}
public string GetMotd(){
return Motd;
}
public int GetPort(){
return Cfg.getInt("server-port");
}
public int GetMaxPlayers(){
return MaxPlayers;
}
public static Server GetInstance(){
return Instance;
}
public void SendPacket(IPAddress ipaddress){
}
public void SendPacket(string ipaddress){
}
public List<Player> GetOnlinePlayers(){
return OnlinePlayers;
}
public ConsoleSender GetConsoleSender(){
return ConsSender;
}
}
}