mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-22 12:05:51 -04:00
Start work on making the core code a plugin.
This commit is contained in:
parent
de79a0e3e4
commit
9d82e5af72
113
CorePlugin/ConnectHandler.cs
Normal file
113
CorePlugin/ConnectHandler.cs
Normal file
@ -0,0 +1,113 @@
|
||||
/*
|
||||
Copyright 2015 MCGalaxy team
|
||||
|
||||
Dual-licensed under the Educational Community License, Version 2.0 and
|
||||
the GNU General Public License, Version 3 (the "Licenses"); you may
|
||||
not use this file except in compliance with the Licenses. You may
|
||||
obtain a copy of the Licenses at
|
||||
|
||||
http://www.opensource.org/licenses/ecl2.php
|
||||
http://www.gnu.org/licenses/gpl-3.0.html
|
||||
|
||||
Unless required by applicable law or agreed to in writing,
|
||||
software distributed under the Licenses are distributed on an "AS IS"
|
||||
BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
|
||||
or implied. See the Licenses for the specific language governing
|
||||
permissions and limitations under the Licenses.
|
||||
*/
|
||||
using System;
|
||||
using System.IO;
|
||||
using MCGalaxy;
|
||||
|
||||
namespace MCGalaxy.Core {
|
||||
|
||||
internal static class ConnectHandler {
|
||||
|
||||
internal static void HandleConnect(Player p) {
|
||||
CheckReviewList(p);
|
||||
if (p.group.commands.Contains("reachdistance"))
|
||||
LoadReach(p);
|
||||
|
||||
LoadWaypoints(p);
|
||||
LoadIgnores(p);
|
||||
CheckOutdatedClient(p);
|
||||
}
|
||||
|
||||
static void CheckReviewList(Player p) {
|
||||
Command cmd = Command.all.Find("review");
|
||||
int perm = CommandOtherPerms.GetPerm(cmd, 1);
|
||||
|
||||
if ((int)p.group.Permission < perm || !p.group.commands.Contains(cmd)) return;
|
||||
int count = Server.reviewlist.Count;
|
||||
if (count == 0) return;
|
||||
|
||||
string suffix = count == 1 ? " player is " : " players are ";
|
||||
p.SendMessage(count + suffix + "waiting for a review. Type %T/review view");
|
||||
}
|
||||
|
||||
static void LoadReach(Player p) {
|
||||
string line = Server.reach.Find(p.name);
|
||||
if (line == null) return;
|
||||
int space = line.IndexOf(' ');
|
||||
if (space == -1) return;
|
||||
string reach = line.Substring(space + 1);
|
||||
|
||||
short reachDist;
|
||||
if (!short.TryParse(reach, out reachDist)) return;
|
||||
p.ReachDistance = reachDist / 32f;
|
||||
if (p.HasCpeExt(CpeExt.ClickDistance))
|
||||
p.Send(Packet.MakeClickDistance(reachDist));
|
||||
}
|
||||
|
||||
static void LoadWaypoints(Player p) {
|
||||
try {
|
||||
p.Waypoints.Load(p);
|
||||
} catch (IOException ex) {
|
||||
p.SendMessage("Error loading waypoints.");
|
||||
Server.ErrorLog(ex);
|
||||
}
|
||||
}
|
||||
|
||||
static void LoadIgnores(Player p) {
|
||||
string path = "ranks/ignore/" + p.name + ".txt";
|
||||
if (!File.Exists(path)) return;
|
||||
|
||||
try {
|
||||
string[] lines = File.ReadAllLines(path);
|
||||
foreach (string line in lines) {
|
||||
if (line == "&global") continue; // deprecated /ignore global
|
||||
if (line == "&all") p.ignoreAll = true;
|
||||
else if (line == "&irc") p.ignoreIRC = true;
|
||||
else if (line == "&titles") p.ignoreTitles = true;
|
||||
else if (line == "&nicks") p.ignoreNicks = true;
|
||||
else p.listignored.Add(line);
|
||||
}
|
||||
} catch (IOException ex) {
|
||||
Server.ErrorLog(ex);
|
||||
Server.s.Log("Failed to load ignore list for: " + p.name);
|
||||
}
|
||||
|
||||
if (p.ignoreAll || p.ignoreIRC || p.ignoreTitles || p.ignoreNicks || p.listignored.Count > 0)
|
||||
p.SendMessage("&cType &a/ignore list &cto see who you are still ignoring");
|
||||
}
|
||||
|
||||
static void CheckOutdatedClient(Player p) {
|
||||
if (p.appName == null || !p.appName.StartsWith("ClassicalSharp ")) return;
|
||||
int spaceIndex = p.appName.IndexOf(' ');
|
||||
string version = p.appName.Substring(spaceIndex, p.appName.Length - spaceIndex);
|
||||
Version ver;
|
||||
try {
|
||||
ver = new Version(version);
|
||||
} catch {
|
||||
return;
|
||||
}
|
||||
|
||||
if (ver < new Version("0.98.6")) {
|
||||
p.SendMessage("%aYou are using an outdated version of ClassicalSharp.");
|
||||
p.SendMessage("%aYou can click %eCheck for updates %ain the launcher to update. " +
|
||||
"(make sure to close the client first)");
|
||||
p.outdatedClient = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
37
CorePlugin/CorePlugin.cs
Normal file
37
CorePlugin/CorePlugin.cs
Normal file
@ -0,0 +1,37 @@
|
||||
/*
|
||||
Copyright 2015 MCGalaxy team
|
||||
|
||||
Dual-licensed under the Educational Community License, Version 2.0 and
|
||||
the GNU General Public License, Version 3 (the "Licenses"); you may
|
||||
not use this file except in compliance with the Licenses. You may
|
||||
obtain a copy of the Licenses at
|
||||
|
||||
http://www.opensource.org/licenses/ecl2.php
|
||||
http://www.gnu.org/licenses/gpl-3.0.html
|
||||
|
||||
Unless required by applicable law or agreed to in writing,
|
||||
software distributed under the Licenses are distributed on an "AS IS"
|
||||
BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
|
||||
or implied. See the Licenses for the specific language governing
|
||||
permissions and limitations under the Licenses.
|
||||
*/
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
namespace MCGalaxy.Core {
|
||||
|
||||
public sealed class CorePlugin : Plugin_Simple {
|
||||
public override string creator { get { return "MCGalaxy team"; } }
|
||||
public override string MCGalaxy_Version { get { return Server.VersionString; } }
|
||||
public override string name { get { return "CorePlugin"; } }
|
||||
|
||||
public override void Load(bool startup) {
|
||||
OnPlayerConnectEvent.Register(ConnectHandler.HandleConnect,
|
||||
Priority.System_Level, this, false);
|
||||
}
|
||||
|
||||
public override void Unload(bool shutdown) {
|
||||
OnPlayerConnectEvent.UnRegister(this);
|
||||
}
|
||||
}
|
||||
}
|
@ -406,6 +406,8 @@
|
||||
<Compile Include="Config\ServerProperties.cs" />
|
||||
<Compile Include="Config\PropertiesFile.cs" />
|
||||
<Compile Include="Config\StringAttributes.cs" />
|
||||
<Compile Include="CorePlugin\CorePlugin.cs" />
|
||||
<Compile Include="CorePlugin\ConnectHandler.cs" />
|
||||
<Compile Include="Database\BlockDB.cs" />
|
||||
<Compile Include="Database\IDatabaseBackend.cs" />
|
||||
<Compile Include="Database\MySQL\MySQLBackend.cs" />
|
||||
@ -722,6 +724,7 @@
|
||||
<Folder Include="Bots" />
|
||||
<Folder Include="Events" />
|
||||
<Folder Include="Chat" />
|
||||
<Folder Include="CorePlugin" />
|
||||
<Folder Include="util\Math" />
|
||||
<Folder Include="Player\Group" />
|
||||
<Folder Include="Player\List" />
|
||||
|
@ -116,7 +116,6 @@ namespace MCGalaxy {
|
||||
}
|
||||
}
|
||||
|
||||
LoadIgnores();
|
||||
byte type = packet[130];
|
||||
if (type == 0x42) { hasCpe = true; SendCpeExtensions(); }
|
||||
|
||||
@ -228,7 +227,6 @@ namespace MCGalaxy {
|
||||
Server.s.Log(alts);
|
||||
}
|
||||
}
|
||||
CheckOutdatedClient();
|
||||
} catch (Exception e) {
|
||||
Server.ErrorLog(e);
|
||||
Chat.MessageAll("An error occurred: {0}", e.Message);
|
||||
@ -284,9 +282,6 @@ namespace MCGalaxy {
|
||||
OnPlayerConnectEvent.Call(this);
|
||||
|
||||
CheckLoginJailed();
|
||||
CheckReviewList();
|
||||
if (group.commands.Contains("reachdistance"))
|
||||
CheckLoginReach();
|
||||
|
||||
if (Server.agreetorulesonentry && group.Permission == LevelPermission.Guest && !Server.agreed.Contains(name)) {
|
||||
SendMessage("&9You must read the &c/rules&9 and &c/agree&9 to them before you can build and use commands!");
|
||||
@ -300,13 +295,6 @@ namespace MCGalaxy {
|
||||
SendMessage("&cPlease complete admin verification with &a/pass [Password]!");
|
||||
}
|
||||
|
||||
try {
|
||||
Waypoints.Load(this);
|
||||
} catch (Exception ex) {
|
||||
SendMessage("Error loading waypoints!");
|
||||
Server.ErrorLog(ex);
|
||||
}
|
||||
|
||||
Server.s.Log(name + " [" + ip + "] has joined the server.");
|
||||
Game.InfectMessages = PlayerDB.GetInfectMessages(this);
|
||||
Server.zombie.PlayerJoinedServer(this);
|
||||
@ -324,18 +312,6 @@ namespace MCGalaxy {
|
||||
Loading = false;
|
||||
}
|
||||
|
||||
void CheckReviewList() {
|
||||
Command cmd = Command.all.Find("review");
|
||||
int perm = CommandOtherPerms.GetPerm(cmd, 1);
|
||||
|
||||
if ((int)group.Permission < perm || !group.commands.Contains(cmd)) return;
|
||||
int count = Server.reviewlist.Count;
|
||||
if (count == 0) return;
|
||||
|
||||
string suffix = count == 1 ? " player is " : " players are ";
|
||||
SendMessage(count + suffix + "waiting for a review. Type %T/review view");
|
||||
}
|
||||
|
||||
void LoadCpeData() {
|
||||
string line = Server.skins.Find(name);
|
||||
if (line != null) {
|
||||
@ -350,25 +326,6 @@ namespace MCGalaxy {
|
||||
}
|
||||
}
|
||||
|
||||
void CheckOutdatedClient() {
|
||||
if (appName == null || !appName.StartsWith("ClassicalSharp ")) return;
|
||||
int spaceIndex = appName.IndexOf(' ');
|
||||
string version = appName.Substring(spaceIndex, appName.Length - spaceIndex);
|
||||
Version ver;
|
||||
try {
|
||||
ver = new Version(version);
|
||||
} catch {
|
||||
return;
|
||||
}
|
||||
|
||||
if (ver < new Version("0.98.6")) {
|
||||
SendMessage("%aYou are using an outdated version of ClassicalSharp.");
|
||||
SendMessage("%aYou can click %eCheck for updates %ain the launcher to update. " +
|
||||
"(make sure to close the client first)");
|
||||
outdatedClient = true;
|
||||
}
|
||||
}
|
||||
|
||||
void InitPlayerStats(DataTable playerDb) {
|
||||
SendMessage("Welcome " + DisplayName + "! This is your first visit.");
|
||||
PlayerData.Create(this);
|
||||
@ -408,19 +365,5 @@ namespace MCGalaxy {
|
||||
Server.ErrorLog(ex);
|
||||
}
|
||||
}
|
||||
|
||||
void CheckLoginReach() {
|
||||
string line = Server.reach.Find(name);
|
||||
if (line == null) return;
|
||||
int space = line.IndexOf(' ');
|
||||
if (space == -1) return;
|
||||
string reach = line.Substring(space + 1);
|
||||
|
||||
short reachDist;
|
||||
if (!short.TryParse(reach, out reachDist)) return;
|
||||
ReachDistance = reachDist / 32f;
|
||||
if (HasCpeExt(CpeExt.ClickDistance))
|
||||
Send(Packet.MakeClickDistance(reachDist));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -538,29 +538,6 @@ namespace MCGalaxy {
|
||||
}
|
||||
}
|
||||
|
||||
void LoadIgnores() {
|
||||
string path = "ranks/ignore/" + name + ".txt";
|
||||
if (!File.Exists(path)) return;
|
||||
|
||||
try {
|
||||
string[] lines = File.ReadAllLines(path);
|
||||
foreach (string line in lines) {
|
||||
if (line == "&global") continue; // deprecated /ignore global
|
||||
if (line == "&all") ignoreAll = true;
|
||||
else if (line == "&irc") ignoreIRC = true;
|
||||
else if (line == "&titles") ignoreTitles = true;
|
||||
else if (line == "&nicks") ignoreNicks = true;
|
||||
else listignored.Add(line);
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
Server.ErrorLog(ex);
|
||||
Server.s.Log("Failed to load ignore list for: " + name);
|
||||
}
|
||||
|
||||
if (ignoreAll || ignoreIRC || ignoreTitles || ignoreNicks || listignored.Count > 0)
|
||||
SendMessage("&cType &a/ignore list &cto see who you are still ignoring");
|
||||
}
|
||||
|
||||
internal void RemoveInvalidUndos() {
|
||||
UndoDrawOpEntry[] items = DrawOps.Items;
|
||||
for (int i = 0; i < items.Length; i++) {
|
||||
|
@ -20,6 +20,7 @@ using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Threading;
|
||||
using MCGalaxy.Core;
|
||||
|
||||
namespace MCGalaxy {
|
||||
/// <summary> This class provides for more advanced modification to MCGalaxy </summary>
|
||||
@ -120,6 +121,8 @@ namespace MCGalaxy {
|
||||
|
||||
/// <summary> Load all plugins </summary>
|
||||
public static void Load() {
|
||||
LoadInternalPlugins();
|
||||
|
||||
if (Directory.Exists("plugins")) {
|
||||
foreach (string path in Directory.GetFiles("plugins", "*.dll")) {
|
||||
string name = Path.GetFileNameWithoutExtension(path);
|
||||
@ -128,12 +131,16 @@ namespace MCGalaxy {
|
||||
} else {
|
||||
Directory.CreateDirectory("plugins");
|
||||
}
|
||||
}
|
||||
|
||||
// Load Internal Plugins
|
||||
CTF.Setup temp = new CTF.Setup();
|
||||
temp.Load(true);
|
||||
Plugin.all.Add(temp);
|
||||
static void LoadInternalPlugins() {
|
||||
CTF.Setup ctf = new CTF.Setup();
|
||||
ctf.Load(true);
|
||||
Plugin.all.Add(ctf);
|
||||
|
||||
CorePlugin core = new CorePlugin();
|
||||
core.Load(true);
|
||||
Plugin.all.Add(core);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user