diff --git a/API.cs b/API.cs
new file mode 100644
index 000000000..ca5ff0134
--- /dev/null
+++ b/API.cs
@@ -0,0 +1,14 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace MCGalaxy
+{
+ public class API
+ {
+ public string[] players { get; set; }
+ public int max_players { get; set; }
+ public ChatMessage[] chat { get; set; }
+ }
+}
diff --git a/ChatMessage.cs b/ChatMessage.cs
new file mode 100644
index 000000000..91e9d4c5f
--- /dev/null
+++ b/ChatMessage.cs
@@ -0,0 +1,14 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace MCGalaxy
+{
+ public class ChatMessage
+ {
+ public string text { get; set; }
+ public string time { get; set; }
+ public string username { get; set; }
+ }
+}
diff --git a/Color.cs b/Color.cs
index 20fbbb6a2..0433cafa1 100644
--- a/Color.cs
+++ b/Color.cs
@@ -195,6 +195,14 @@ namespace MCGalaxy
public static void MinecraftToIrcColors(StringBuilder sb)
{
if (sb == null) throw new ArgumentNullException("sb");
+ for (int i = 0; i < 10; i++)
+ {
+ sb.Replace("%" + i, "&" + i);
+ }
+ for (char ch = 'a'; ch <= 'f'; ch++)
+ {
+ sb.Replace("%" + ch, "&" + ch);
+ }
foreach (var codePair in MinecraftToIRCColors)
{
sb.Replace(codePair.Key, codePair.Value);
diff --git a/Commands/CmdEnvironment.cs b/Commands/CmdEnvironment.cs
index 07ff25c11..7fc530202 100644
--- a/Commands/CmdEnvironment.cs
+++ b/Commands/CmdEnvironment.cs
@@ -500,8 +500,8 @@ namespace MCGalaxy.Commands
case "horizon":
case "edge":
case "water":
- byte block = Block.water;
- if (Block.Byte(valueText) != Block.Zero && !(valueText.Equals("normal", StringComparison.OrdinalIgnoreCase) || valueText.Equals("default", StringComparison.OrdinalIgnoreCase)))
+ byte block = Block.Byte(valueText);
+ if (block == Block.Zero && !(valueText.Equals("normal", StringComparison.OrdinalIgnoreCase) || valueText.Equals("default", StringComparison.OrdinalIgnoreCase)))
{
Help(p);
return;
@@ -536,8 +536,8 @@ namespace MCGalaxy.Commands
case "side":
case "border":
case "bedrock":
- byte blockhorizon = Block.blackrock;
- if (Block.Byte(valueText) == Block.Zero && !(valueText.Equals("normal", StringComparison.OrdinalIgnoreCase) || valueText.Equals("default", StringComparison.OrdinalIgnoreCase)))
+ byte blockhorizon = Block.Byte(valueText);
+ if (blockhorizon == Block.Zero && !(valueText.Equals("normal", StringComparison.OrdinalIgnoreCase) || valueText.Equals("default", StringComparison.OrdinalIgnoreCase)))
{
Help(p);
return;
diff --git a/Commands/CmdNewLvl.cs b/Commands/CmdNewLvl.cs
index a3af91343..4d93cf87a 100644
--- a/Commands/CmdNewLvl.cs
+++ b/Commands/CmdNewLvl.cs
@@ -144,7 +144,7 @@ namespace MCGalaxy.Commands
return true;
}
- return false;
+ return true;
}
}
}
diff --git a/Commands/CmdQuit.cs b/Commands/CmdQuit.cs
index f99644c68..ff2f5e404 100644
--- a/Commands/CmdQuit.cs
+++ b/Commands/CmdQuit.cs
@@ -16,6 +16,7 @@ namespace MCGalaxy.Commands
public override void Use(Player p, string message)
{
+ p.totalKicked = p.totalKicked - 1;
if (message != "")
{
p.Kick("Left the game: " + message);
diff --git a/Commands/CmdRagequit.cs b/Commands/CmdRagequit.cs
index d5ca7cdb4..b6f243646 100644
--- a/Commands/CmdRagequit.cs
+++ b/Commands/CmdRagequit.cs
@@ -26,6 +26,7 @@ namespace MCGalaxy.Commands
public override LevelPermission defaultRank { get { return LevelPermission.Banned; } }
public override void Use(Player p, string message)
{
+ p.totalKicked = p.totalKicked - 1;
p.Kick("RAGEQUIT!!");
}
diff --git a/Commands/CmdWhowas.cs b/Commands/CmdWhowas.cs
index e08c8d973..b6bae6ed3 100644
--- a/Commands/CmdWhowas.cs
+++ b/Commands/CmdWhowas.cs
@@ -44,7 +44,7 @@ namespace MCGalaxy.Commands
string FoundRank = Group.findPlayer(message.ToLower());
Database.AddParams("@Name", message);
- DataTable playerDb = Database.fillData("SELECT * FROM Players WHERE Name=@Name");
+ DataTable playerDb = Database.fillData("SELECT * FROM Players WHERE Name=@Name COLLATE NOCASE");
if (playerDb.Rows.Count == 0) { Player.SendMessage(p, Group.Find(FoundRank).color + message + Server.DefaultColor + " has the rank of " + Group.Find(FoundRank).color + FoundRank); return; }
string title = playerDb.Rows[0]["Title"].ToString();
string color = c.Parse(playerDb.Rows[0]["color"].ToString().Trim());
diff --git a/ForgeBot.cs b/ForgeBot.cs
index dee59bb3b..e013cf474 100644
--- a/ForgeBot.cs
+++ b/ForgeBot.cs
@@ -85,26 +85,15 @@ namespace MCGalaxy {
}
public void Say(string message, bool opchat = false, bool color = true) {
if (!Server.irc || !IsConnected()) return;
- StringBuilder sb = new StringBuilder(message);
if(String.IsNullOrEmpty(message.Trim()))
message = ".";
if (color) {
- for (int i = 0; i < 10; i++)
- {
- sb.Replace("%" + i, ColorSignal + c.MCtoIRC("&" + i));
- sb.Replace("&" + i, ColorSignal + c.MCtoIRC("&" + i));
- }
- for (char ch = 'a'; ch <= 'f'; ch++)
- {
- sb.Replace("%" + ch, ColorSignal + c.MCtoIRC("&" + ch));
- sb.Replace("&" + ch, ColorSignal + c.MCtoIRC("&" + ch));
- }
+ message = c.MinecraftToIrcColors(message).Replace("%r", ResetSignal);
}
- sb.Replace("%r", ResetSignal);
- connection.Sender.PublicMessage(opchat ? opchannel : channel, sb.ToString());
+ connection.Sender.PublicMessage(opchat ? opchannel : channel, message);
}
public void Pm(string user, string message) {
if (Server.irc && IsConnected())
@@ -211,10 +200,6 @@ namespace MCGalaxy {
Server.IRC.Say("Unknown command!");
}
}
- for (byte i = 10; i < 16; i++)
- message = message.Replace(ColorSignal + i, c.IRCtoMC(i).Replace('&', '%'));
- for (byte i = 0; i < 10; i++)
- message = message.Replace(ColorSignal + i, c.IRCtoMC(i).Replace('&', '%'));
message = c.IrcToMinecraftColors(message);
if(String.IsNullOrEmpty(message.Trim()))
diff --git a/Heartbeat/ClassiCube.cs b/Heartbeat/ClassiCube.cs
index ce606491e..f0c570c67 100644
--- a/Heartbeat/ClassiCube.cs
+++ b/Heartbeat/ClassiCube.cs
@@ -48,7 +48,6 @@ namespace MCGalaxy
public void OnResponse(string line)
{
-
// Only run the code below if we receive a response
if (!String.IsNullOrEmpty(line.Trim()))
{
diff --git a/Levels/Level.cs b/Levels/Level.cs
index e6bcc2dd3..e2ab87798 100644
--- a/Levels/Level.cs
+++ b/Levels/Level.cs
@@ -481,6 +481,7 @@ namespace MCGalaxy
}
public void SetTile(ushort x, ushort y, ushort z, byte type, Player p = null)
{
+ byte oldType = GetTile(x, y, z);
if (blocks == null) return;
if (!InBound(x, y, z)) return;
blocks[PosToInt(x, y, z)] = type;
@@ -496,6 +497,15 @@ namespace MCGalaxy
else
bP.deleted = false;
blockCache.Add(bP);
+ Player.UndoPos Pos;
+ Pos.x = x;
+ Pos.y = y;
+ Pos.z = z;
+ Pos.mapName = this.name;
+ Pos.type = oldType;
+ Pos.newtype = type;
+ Pos.timePlaced = DateTime.Now;
+ p.UndoBuffer.Add(Pos);
}
}
diff --git a/Levels/Texture_Settings.cs b/Levels/Texture_Settings.cs
index 2677460f2..8960fe504 100644
--- a/Levels/Texture_Settings.cs
+++ b/Levels/Texture_Settings.cs
@@ -374,48 +374,6 @@ namespace MCGalaxy.Levels.Textures
var match = HttpFirstLine.Match(firstLine);
if (match.Success)
{
- string worldName = match.Groups[1].Value;
- bool firstTime = match.Groups[2].Success;
- Level l = Level.Find(worldName);
- if (l != null)
- {
- string cfg = "";
- if (cachecfg == "" || update)
- {
- if (!File.Exists("extra/cfg/" + l.name + ".cfg"))
- l.textures.CreateCFG();
- cfg = GetCFG();
- cachecfg = cfg;
- update = false;
- }
- else
- cfg = cachecfg;
- byte[] content = Encoding.UTF8.GetBytes(cfg);
- textWriter.Write("HTTP/1.1 200 OK");
- textWriter.WriteLine("Date: " + DateTime.UtcNow.ToString("R"));
- textWriter.WriteLine("Server: Apache/2.2.21 (CentOS)");
- textWriter.WriteLine("Last-Modified: " + DateTime.UtcNow.ToString("R"));
- textWriter.WriteLine("Accept-Ranges: bytes");
- textWriter.WriteLine("Content-Length: " + content.Length);
- textWriter.WriteLine("Connection: close");
- textWriter.WriteLine("Content-Type: text/plain");
- textWriter.WriteLine();
- textWriter.WriteLine(cfg);
- }
- else if (isMusic(worldName, p)) {
- byte[] data = getData(worldName);
- textWriter.WriteLine("Date: " + DateTime.UtcNow.ToString("R"));
- textWriter.WriteLine("Server: Apache/2.2.21 (CentOS)");
- textWriter.WriteLine("Last-Modified: " + DateTime.UtcNow.ToString("R"));
- textWriter.WriteLine("Accept-Ranges: bytes");
- textWriter.WriteLine("Content-Length: " + data.Length);
- textWriter.WriteLine("Connection: close");
- textWriter.WriteLine("Content-Type: application/octet-stream");
- textWriter.WriteLine();
- textWriter.WriteLine(data);
- }
- else
- textWriter.WriteLine("HTTP/1.1 404 Not Found");
}
else
textWriter.WriteLine("HTTP/1.1 400 Bad Request");
diff --git a/MCGalaxy_.csproj b/MCGalaxy_.csproj
index a1f5d1929..39e52bdcf 100644
--- a/MCGalaxy_.csproj
+++ b/MCGalaxy_.csproj
@@ -31,8 +31,9 @@
False
False
obj\$(Configuration)\
- v4.0
+ v4.5
+ 88b3a93f
x86
@@ -62,6 +63,7 @@
False
False
Auto
+ x64
Galaxy.ico
@@ -80,12 +82,29 @@
Auto
+
+ packages\EntityFramework.6.0.0\lib\net45\EntityFramework.dll
+
+
+ packages\EntityFramework.6.0.0\lib\net45\EntityFramework.SqlServer.dll
+
Newtonsoft.Json\Newtonsoft.Json.dll
+
+
+ False
+ packages\System.Data.SQLite.Core.1.0.98.1\lib\net45\System.Data.SQLite.dll
+
+
+ packages\System.Data.SQLite.EF6.1.0.98.1\lib\net45\System.Data.SQLite.EF6.dll
+
+
+ packages\System.Data.SQLite.Linq.1.0.98.1\lib\net45\System.Data.SQLite.Linq.dll
+
@@ -103,18 +122,17 @@
MySql.Data.dll
-
- System.Data.SQLite.dll
-
System.Windows.Forms.Ribbon.dll
+
+
@@ -554,6 +572,8 @@
+
+
EcoLevelWindow.cs
@@ -667,6 +687,7 @@
+
Reference.svcmap
@@ -746,4 +767,11 @@
+
+
+
+ This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.
+
+
+
\ No newline at end of file
diff --git a/Player/Group.cs b/Player/Group.cs
index 17ad48679..b1feff0fc 100644
--- a/Player/Group.cs
+++ b/Player/Group.cs
@@ -21,12 +21,14 @@ using System.Globalization;
using System.IO;
using System.Linq;
-namespace MCGalaxy {
+namespace MCGalaxy
+{
///
/// This is the group object
/// Where ranks and there data are stored
///
- public sealed class Group {
+ public sealed class Group
+ {
public delegate void RankSet(Player p, Group newrank);
[Obsolete("Please use OnPlayerRankSetEvent.Register()")]
public static event RankSet OnPlayerRankSet;
@@ -57,7 +59,8 @@ namespace MCGalaxy {
///
/// Create a new group object
///
- public Group() {
+ public Group()
+ {
Permission = LevelPermission.Null;
}
@@ -71,7 +74,8 @@ namespace MCGalaxy {
/// The color of the group (Not including the &)
/// the custom MOTD for the group
/// The file path where the current players of this group are stored
- public Group(LevelPermission Perm, int maxB, long maxUn, string fullName, char newColor, string motd, string file, byte maps = 2) {
+ public Group(LevelPermission Perm, int maxB, long maxUn, string fullName, char newColor, string motd, string file, byte maps = 2)
+ {
Permission = Perm;
maxBlocks = maxB;
maxUndo = maxUn;
@@ -88,7 +92,8 @@ namespace MCGalaxy {
///
/// Fill the commands that this group can use
///
- public void fillCommands() {
+ public void fillCommands()
+ {
CommandList _commands = new CommandList();
GrpCommands.AddCommands(out _commands, Permission);
commands = _commands;
@@ -105,29 +110,40 @@ namespace MCGalaxy {
///
/// Load up all server groups
///
- public static void InitAll() {
+ public static void InitAll()
+ {
GroupList = new List();
- if (File.Exists("properties/ranks.properties")) {
+ if (File.Exists("properties/ranks.properties"))
+ {
string[] lines = File.ReadAllLines("properties/ranks.properties");
Group thisGroup = new Group();
int gots = 0, version = 1;
- if (lines.Length > 0 && lines[0].StartsWith("#Version ")) {
- try { version = int.Parse(lines[0].Remove(0, 9)); } catch { Server.s.Log("The ranks.properties version header is invalid! Ranks may fail to load!"); }
+ if (lines.Length > 0 && lines[0].StartsWith("#Version "))
+ {
+ try { version = int.Parse(lines[0].Remove(0, 9)); }
+ catch { Server.s.Log("The ranks.properties version header is invalid! Ranks may fail to load!"); }
}
- foreach (string s in lines) {
- try {
+ foreach (string s in lines)
+ {
+ try
+ {
if (s == "" || s[0] == '#') continue;
- if (s.Split('=').Length == 2) {
+ if (s.Split('=').Length == 2)
+ {
string property = s.Split('=')[0].Trim();
string value = s.Split('=')[1].Trim();
- if (thisGroup.name == "" && property.ToLower() != "rankname") {
+ if (thisGroup.name == "" && property.ToLower() != "rankname")
+ {
Server.s.Log("Hitting an error at " + s + " of ranks.properties");
- } else {
- switch (property.ToLower()) {
+ }
+ else
+ {
+ switch (property.ToLower())
+ {
case "rankname":
gots = 0;
thisGroup = new Group();
@@ -142,35 +158,44 @@ namespace MCGalaxy {
case "permission":
int foundPermission;
- try {
+ try
+ {
foundPermission = int.Parse(value);
- } catch { Server.s.Log("Invalid permission on " + s); break; }
+ }
+ catch { Server.s.Log("Invalid permission on " + s); break; }
- if (thisGroup.Permission != LevelPermission.Null) {
+ if (thisGroup.Permission != LevelPermission.Null)
+ {
Server.s.Log("Setting permission again on " + s);
gots--;
}
bool allowed = GroupList.Find(grp => grp.Permission == (LevelPermission)foundPermission) == null;
- if (foundPermission > 119 || foundPermission < -50) {
+ if (foundPermission > 119 || foundPermission < -50)
+ {
Server.s.Log("Permission must be between -50 and 119 for ranks");
break;
}
- if (allowed) {
+ if (allowed)
+ {
gots++;
thisGroup.Permission = (LevelPermission)foundPermission;
- } else {
+ }
+ else
+ {
Server.s.Log("Cannot have 2 ranks set at permission level " + value);
}
break;
case "limit":
int foundLimit;
- try {
+ try
+ {
foundLimit = int.Parse(value);
- } catch { Server.s.Log("Invalid limit on " + s); break; }
+ }
+ catch { Server.s.Log("Invalid limit on " + s); break; }
gots++;
thisGroup.maxBlocks = foundLimit;
@@ -178,9 +203,11 @@ namespace MCGalaxy {
case "maxundo":
int foundMax;
- try {
+ try
+ {
foundMax = int.Parse(value);
- } catch { Server.s.Log("Invalid maximum on " + s); break; }
+ }
+ catch { Server.s.Log("Invalid maximum on " + s); break; }
gots++;
thisGroup.maxUndo = foundMax;
@@ -188,19 +215,25 @@ namespace MCGalaxy {
case "color":
char foundChar;
- try {
+ try
+ {
foundChar = char.Parse(value);
- } catch { Server.s.Log("Incorrect color on " + s); break; }
+ }
+ catch { Server.s.Log("Incorrect color on " + s); break; }
- if ((foundChar >= '0' && foundChar <= '9') || (foundChar >= 'a' && foundChar <= 'f')) {
+ if ((foundChar >= '0' && foundChar <= '9') || (foundChar >= 'a' && foundChar <= 'f'))
+ {
gots++;
thisGroup.color = foundChar.ToString(CultureInfo.InvariantCulture);
- } else {
+ }
+ else
+ {
Server.s.Log("Invalid color code at " + s);
}
break;
case "filename":
- if (value.Contains("\\") || value.Contains("/")) {
+ if (value.Contains("\\") || value.Contains("/"))
+ {
Server.s.Log("Invalid filename on " + s);
break;
}
@@ -215,7 +248,7 @@ namespace MCGalaxy {
break;
case "osmaps":
byte osmaps;
- if(byte.TryParse(value, out osmaps) == false)
+ if (byte.TryParse(value, out osmaps) == false)
{ osmaps = 2; }
gots++;
@@ -223,28 +256,33 @@ namespace MCGalaxy {
break;
}
- if ((gots >= 4 && version < 2) || (gots >= 5 && version < 3) || gots >= 6) {
- if (version < 2) {
+ if ((gots >= 4 && version < 2) || (gots >= 5 && version < 3) || gots >= 6)
+ {
+ if (version < 2)
+ {
if ((int)thisGroup.Permission >= 100)
thisGroup.maxUndo = int.MaxValue;
else if ((int)thisGroup.Permission >= 80)
thisGroup.maxUndo = 5400;
}
- GroupList.Add(new Group(thisGroup.Permission,
- thisGroup.maxBlocks,
- thisGroup.maxUndo,
- thisGroup.trueName,
- thisGroup.color[0],
- thisGroup.MOTD,
- thisGroup.fileName,
+ GroupList.Add(new Group(thisGroup.Permission,
+ thisGroup.maxBlocks,
+ thisGroup.maxUndo,
+ thisGroup.trueName,
+ thisGroup.color[0],
+ thisGroup.MOTD,
+ thisGroup.fileName,
thisGroup.OverseerMaps));
}
}
- } else {
+ }
+ else
+ {
Server.s.Log("In ranks.properties, the line " + s + " is wrongly formatted");
}
- } catch (Exception e) { Server.s.Log("Encountered an error at line \"" + s + "\" in ranks.properties"); Server.ErrorLog(e); }
+ }
+ catch (Exception e) { Server.s.Log("Encountered an error at line \"" + s + "\" in ranks.properties"); Server.ErrorLog(e); }
}
}
@@ -257,10 +295,12 @@ namespace MCGalaxy {
GroupList.Add(new Group(LevelPermission.Nobody, 65536, -1, "Nobody", '0', String.Empty, "nobody.txt"));
bool swap = true; Group storedGroup;
- while (swap) {
+ while (swap)
+ {
swap = false;
for (int i = 0; i < GroupList.Count - 1; i++)
- if (GroupList[i].Permission > GroupList[i + 1].Permission) {
+ if (GroupList[i].Permission > GroupList[i + 1].Permission)
+ {
swap = true;
storedGroup = GroupList[i];
GroupList[i] = GroupList[i + 1];
@@ -271,7 +311,8 @@ namespace MCGalaxy {
if (Group.Find(Server.defaultRank) != null) standard = Group.Find(Server.defaultRank);
else standard = Group.findPerm(LevelPermission.Guest);
- foreach (Player pl in Player.players) {
+ foreach (Player pl in Player.players)
+ {
pl.group = GroupList.Find(g => g.name == pl.group.name);
}
if (OnGroupLoad != null)
@@ -283,9 +324,11 @@ namespace MCGalaxy {
/// Save givenList group
///
/// The list of groups to save
- public static void saveGroups(List givenList) {
+ public static void saveGroups(List givenList)
+ {
File.Create("properties/ranks.properties").Dispose();
- using (StreamWriter SW = File.CreateText("properties/ranks.properties")) {
+ using (StreamWriter SW = File.CreateText("properties/ranks.properties"))
+ {
SW.WriteLine("#Version 3");
SW.WriteLine("#RankName = string");
SW.WriteLine("# The name of the rank, use capitalization.");
@@ -319,8 +362,10 @@ namespace MCGalaxy {
SW.WriteLine("# Defaults to 2 if invalid number (number has to be between 0-128");
SW.WriteLine();
SW.WriteLine();
- foreach (Group grp in givenList) {
- if (grp.name != "nobody") {
+ foreach (Group grp in givenList)
+ {
+ if (grp.name != "nobody")
+ {
SW.WriteLine("RankName = " + grp.trueName);
SW.WriteLine("Permission = " + (int)grp.Permission);
SW.WriteLine("Limit = " + grp.maxBlocks);
@@ -342,7 +387,8 @@ namespace MCGalaxy {
///
/// The name of the group to search for
/// Return true if it does exists, returns false if it doesnt
- public static bool Exists(string name) {
+ public static bool Exists(string name)
+ {
name = name.ToLower();
return GroupList.Any(gr => gr.name == name);
}
@@ -351,7 +397,8 @@ namespace MCGalaxy {
///
/// The name of the group
/// The group object with that name
- public static Group Find(string name) {
+ public static Group Find(string name)
+ {
name = name.ToLower();
if (name == "adv") name = "advbuilder";
@@ -366,7 +413,8 @@ namespace MCGalaxy {
///
/// The level permission to search for
/// The group object with that level permission
- public static Group findPerm(LevelPermission Perm) {
+ public static Group findPerm(LevelPermission Perm)
+ {
return GroupList.FirstOrDefault(grp => grp.Permission == Perm);
}
@@ -375,7 +423,8 @@ namespace MCGalaxy {
///
/// The level permission to search for
/// The group object with that level permission
- public static Group findPermInt(int Perm) {
+ public static Group findPermInt(int Perm)
+ {
return GroupList.FirstOrDefault(grp => (int)grp.Permission == Perm);
}
@@ -384,8 +433,10 @@ namespace MCGalaxy {
///
/// The player Name
/// The group name
- public static string findPlayer(string playerName) {
- foreach (Group grp in Group.GroupList.Where(grp => grp.playerList.Contains(playerName))) {
+ public static string findPlayer(string playerName)
+ {
+ foreach (Group grp in Group.GroupList.Where(grp => grp.playerList.Contains(playerName)))
+ {
return grp.name;
}
return Group.standard.name;
@@ -396,21 +447,29 @@ namespace MCGalaxy {
///
/// The player name
/// The group object that the player is in
- public static Group findPlayerGroup(string playerName) {
- foreach (Group grp in Group.GroupList.Where(grp => grp.playerList.Contains(playerName))) {
+ public static Group findPlayerGroup(string playerName)
+ {
+ foreach (Group grp in Group.GroupList.Where(grp => grp.playerList.Contains(playerName)))
+ {
return grp;
}
return Group.standard;
}
- public static string concatList(bool includeColor = true, bool skipExtra = false, bool permissions = false) {
+ public static string concatList(bool includeColor = true, bool skipExtra = false, bool permissions = false)
+ {
string returnString = "";
- foreach (Group grp in Group.GroupList.Where(grp => !skipExtra || (grp.Permission > LevelPermission.Guest && grp.Permission < LevelPermission.Nobody))) {
- if (includeColor) {
+ foreach (Group grp in Group.GroupList.Where(grp => !skipExtra || (grp.Permission > LevelPermission.Guest && grp.Permission < LevelPermission.Nobody)))
+ {
+ if (includeColor)
+ {
returnString += ", " + grp.color + grp.name + Server.DefaultColor;
- } else if (permissions) {
+ }
+ else if (permissions)
+ {
returnString += ", " + ((int)grp.Permission).ToString(CultureInfo.InvariantCulture);
- } else
+ }
+ else
returnString += ", " + grp.name;
}
@@ -420,8 +479,10 @@ namespace MCGalaxy {
}
}
- public class GrpCommands {
- public class rankAllowance {
+ public class GrpCommands
+ {
+ public class rankAllowance
+ {
public string commandName;
public LevelPermission lowestRank;
public List disallow = new List();
@@ -430,39 +491,46 @@ namespace MCGalaxy {
public static List allowedCommands;
public static List foundCommands = new List();
- public static LevelPermission defaultRanks(string command) {
+ public static LevelPermission defaultRanks(string command)
+ {
Command cmd = Command.all.Find(command);
return cmd != null ? cmd.defaultRank : LevelPermission.Null;
}
- public static void fillRanks() {
+ public static void fillRanks()
+ {
foundCommands = Command.all.commandNames();
allowedCommands = new List();
rankAllowance allowVar;
- foreach (Command cmd in Command.all.All()) {
+ foreach (Command cmd in Command.all.All())
+ {
allowVar = new rankAllowance();
allowVar.commandName = cmd.name;
allowVar.lowestRank = cmd.defaultRank;
allowedCommands.Add(allowVar);
}
- if (File.Exists("properties/command.properties")) {
+ if (File.Exists("properties/command.properties"))
+ {
string[] lines = File.ReadAllLines("properties/command.properties");
//if (lines.Length == 0) ; // this is useless?
/*else */
- if (lines[0] == "#Version 2") {
+ if (lines[0] == "#Version 2")
+ {
string[] colon = new[] { " : " };
- foreach (string line in lines) {
+ foreach (string line in lines)
+ {
allowVar = new rankAllowance();
if (line == "" || line[0] == '#') continue;
//Name : Lowest : Disallow : Allow
string[] command = line.Split(colon, StringSplitOptions.None);
- if (!foundCommands.Contains(command[0])) {
+ if (!foundCommands.Contains(command[0]))
+ {
Server.s.Log("Incorrect command name: " + command[0]);
continue;
}
@@ -475,41 +543,56 @@ namespace MCGalaxy {
if (command[3] != "")
allow = command[3].Split(',');
- try {
+ try
+ {
allowVar.lowestRank = (LevelPermission)int.Parse(command[1]);
foreach (string s in disallow) { allowVar.disallow.Add((LevelPermission)int.Parse(s)); }
foreach (string s in allow) { allowVar.allow.Add((LevelPermission)int.Parse(s)); }
- } catch {
+ }
+ catch
+ {
Server.s.Log("Hit an error on the command " + line);
continue;
}
int current = 0;
- foreach (rankAllowance aV in allowedCommands) {
- if (command[0] == aV.commandName) {
+ foreach (rankAllowance aV in allowedCommands)
+ {
+ if (command[0] == aV.commandName)
+ {
allowedCommands[current] = allowVar;
break;
}
current++;
}
}
- } else {
- foreach (string line in lines.Where(line => line != "" && line[0] != '#')) {
+ }
+ else
+ {
+ foreach (string line in lines.Where(line => line != "" && line[0] != '#'))
+ {
allowVar = new rankAllowance();
string key = line.Split('=')[0].Trim().ToLower();
string value = line.Split('=')[1].Trim().ToLower();
- if (!foundCommands.Contains(key)) {
+ if (!foundCommands.Contains(key))
+ {
Server.s.Log("Incorrect command name: " + key);
- } else if (Level.PermissionFromName(value) == LevelPermission.Null) {
+ }
+ else if (Level.PermissionFromName(value) == LevelPermission.Null)
+ {
Server.s.Log("Incorrect value given for " + key + ", using default value.");
- } else {
+ }
+ else
+ {
allowVar.commandName = key;
allowVar.lowestRank = Level.PermissionFromName(value);
int current = 0;
- foreach (rankAllowance aV in allowedCommands) {
- if (key == aV.commandName) {
+ foreach (rankAllowance aV in allowedCommands)
+ {
+ if (key == aV.commandName)
+ {
allowedCommands[current] = allowVar;
break;
}
@@ -519,17 +602,22 @@ namespace MCGalaxy {
}
}
Save(allowedCommands);
- } else Save(allowedCommands);
+ }
+ else Save(allowedCommands);
- foreach (Group grp in Group.GroupList) {
+ foreach (Group grp in Group.GroupList)
+ {
grp.fillCommands();
}
}
- public static void Save(List givenList) {
- try {
+ public static void Save(List givenList)
+ {
+ try
+ {
File.Create("properties/command.properties").Dispose();
- using (StreamWriter w = File.CreateText("properties/command.properties")) {
+ using (StreamWriter w = File.CreateText("properties/command.properties"))
+ {
w.WriteLine("#Version 2");
w.WriteLine("# This file contains a reference to every command found in the server software");
w.WriteLine("# Use this file to specify which ranks get which commands");
@@ -539,28 +627,34 @@ namespace MCGalaxy {
w.WriteLine("# CommandName : LowestRank : Disallow : Allow");
w.WriteLine("# gun : 60 : 80,67 : 40,41,55");
w.WriteLine("");
- foreach (rankAllowance aV in givenList) {
+ foreach (rankAllowance aV in givenList)
+ {
w.WriteLine(aV.commandName + " : " + (int)aV.lowestRank + " : " + getInts(aV.disallow) + " : " + getInts(aV.allow));
}
}
- } catch {
+ }
+ catch
+ {
Server.s.Log("SAVE FAILED! command.properties");
}
}
- public static string getInts(List givenList) {
+ public static string getInts(List givenList)
+ {
string returnString = ""; bool foundOne = false;
- foreach (LevelPermission Perm in givenList) {
+ foreach (LevelPermission Perm in givenList)
+ {
foundOne = true;
returnString += "," + (int)Perm;
}
if (foundOne) returnString = returnString.Remove(0, 1);
return returnString;
}
- public static void AddCommands(out CommandList commands, LevelPermission perm) {
+ public static void AddCommands(out CommandList commands, LevelPermission perm)
+ {
commands = new CommandList();
foreach (rankAllowance aV in allowedCommands.Where(aV => (aV.lowestRank <= perm && !aV.disallow.Contains(perm)) || aV.allow.Contains(perm)))
commands.Add(Command.all.Find(aV.commandName));
}
}
-}
\ No newline at end of file
+}
diff --git a/Player/Player.cs b/Player/Player.cs
index c373bff2d..980b12abe 100644
--- a/Player/Player.cs
+++ b/Player/Player.cs
@@ -1207,7 +1207,9 @@ namespace MCGalaxy {
buffer = null;
}
else
+ {
Player.SendMessage(p1, joinm);
+ }
});
}
}
@@ -2914,17 +2916,6 @@ return;
}
public void SendMap() {
- if (HasExtension("EnvMapAppearance"))
- {
- if (level.textureUrl == "")
- {
- SendSetMapAppearance(Server.defaultTextureUrl, level.EdgeBlock, level.HorizonBlock, level.EdgeLevel);
- }
- else
- {
- SendSetMapAppearance(level.textureUrl, level.EdgeBlock, level.HorizonBlock, level.EdgeLevel);
- }
- }
if ( level.blocks == null ) return;
try {
byte[] buffer = new byte[level.blocks.Length + 4];
@@ -2986,31 +2977,6 @@ return;
{
SendSetMapWeather(level.weather);
}
- }
- public void SendSpawn(byte id, string name, ushort x, ushort y, ushort z, byte rotx, byte roty)
- {
- byte[] buffer = new byte[73]; buffer[0] = id;
- StringFormat(name.TrimEnd('+'), 64).CopyTo(buffer, 1);
- HTNO(x).CopyTo(buffer, 65);
- HTNO(y).CopyTo(buffer, 67);
- HTNO(z).CopyTo(buffer, 69);
- buffer[71] = rotx; buffer[72] = roty;
- SendRaw(7, buffer);
-
- if (HasExtension("ChangeModel"))
- {
- Player.players.ForEach(p =>
- {
- if (p.level == this.level)
- if (p == this) unchecked { SendChangeModel((byte)-1, model); }
- else
- {
- SendChangeModel(p.id, p.model);
- if (p.HasExtension("ChangeModel"))
- p.SendChangeModel(this.id, model);
- }
- });
- }
if (HasExtension("EnvSetColor"))
{
SendEnvSetColor(0, -1, -1, -1);
@@ -3050,6 +3016,42 @@ return;
}
catch { }
}
+ if (HasExtension("EnvMapAppearance"))
+ {
+ if (level.textureUrl == "")
+ {
+ SendSetMapAppearance(Server.defaultTextureUrl, level.EdgeBlock, level.HorizonBlock, level.EdgeLevel);
+ }
+ else
+ {
+ SendSetMapAppearance(level.textureUrl, level.EdgeBlock, level.HorizonBlock, level.EdgeLevel);
+ }
+ }
+ }
+ public void SendSpawn(byte id, string name, ushort x, ushort y, ushort z, byte rotx, byte roty)
+ {
+ byte[] buffer = new byte[73]; buffer[0] = id;
+ StringFormat(name.TrimEnd('+'), 64).CopyTo(buffer, 1);
+ HTNO(x).CopyTo(buffer, 65);
+ HTNO(y).CopyTo(buffer, 67);
+ HTNO(z).CopyTo(buffer, 69);
+ buffer[71] = rotx; buffer[72] = roty;
+ SendRaw(7, buffer);
+
+ if (HasExtension("ChangeModel"))
+ {
+ Player.players.ForEach(p =>
+ {
+ if (p.level == this.level)
+ if (p == this) unchecked { SendChangeModel((byte)-1, model); }
+ else
+ {
+ SendChangeModel(p.id, p.model);
+ if (p.HasExtension("ChangeModel"))
+ p.SendChangeModel(this.id, model);
+ }
+ });
+ }
}
public void SendPos(byte id, ushort x, ushort y, ushort z, byte rotx, byte roty) {
if ( x < 0 ) x = 32;
@@ -3439,7 +3441,15 @@ changed |= 4;*/
return;
}
}
+ if (Last50Chat.Count() == 50)
+ Last50Chat.RemoveAt(0);
+ var chatmessage = new ChatMessage();
+ chatmessage.text = message;
+ chatmessage.username = from.color + from.name;
+ chatmessage.time = DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ss");
+
+ Last50Chat.Add(chatmessage);
if ( showname ) {
String referee = "";
if ( from.referee ) {
@@ -3718,6 +3728,7 @@ changed |= 4;*/
}
});
}
+ public static List Last50Chat = new List();
public static void GlobalMessage(string message) {
GlobalMessage(message, false);
}
@@ -3960,7 +3971,7 @@ changed |= 4;*/
string leavem = "&c- " + color + prefix + name + Server.DefaultColor + " " + File.ReadAllText("text/logout/" + name + ".txt");
if ((Server.guestLeaveNotify && this.group.Permission <= LevelPermission.Guest) || this.group.Permission > LevelPermission.Guest)
{
- Player.players.ForEach(delegate(Player p1)
+ Player.players.ForEach(delegate(Player p1)
{
if (p1.UsingWom)
{
diff --git a/Server.cs b/Server.cs
index ca3726180..18d9801c0 100644
--- a/Server.cs
+++ b/Server.cs
@@ -27,6 +27,7 @@ using System.Threading;
using System.Windows.Forms;
using MCGalaxy.SQL;
using MonoTorrent.Client;
+using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
namespace MCGalaxy
@@ -70,7 +71,8 @@ namespace MCGalaxy
public static Thread blockThread;
public static bool IgnoreOmnibans = false;
//public static List mySQLCommands = new List();
-
+ public static WebServer APIServer;
+ public static WebServer InfoServer;
public static int speedPhysics = 250;
public static Version Version { get { return System.Reflection.Assembly.GetAssembly(typeof(Server)).GetName().Version; } }
@@ -903,7 +905,17 @@ namespace MCGalaxy
}
else File.Create("text/messages.txt").Close();
- // We always construct this to prevent errors...
+ try
+ {
+ APIServer = new WebServer(SendResponse, "http://localhost:8080/api/");
+ APIServer.Run();
+ InfoServer = new WebServer(WhoIsResponse, "http://localhost:8080/whois/");
+ InfoServer.Run();
+ }
+ catch
+ {
+ Server.s.Log("Failed to start local API server");
+ }
IRC = new ForgeBot(Server.ircChannel, Server.ircOpChannel, Server.ircNick, Server.ircServer);
GlobalChat = new GlobalChatBot(GlobalChatNick());
@@ -1030,7 +1042,52 @@ namespace MCGalaxy
BlockQueue.Start();
});
}
-
+ public static string SendResponse(HttpListenerRequest request)
+ {
+ try {
+ string api = "";
+ API API = new API();
+ API.max_players = (int)Server.players;
+ API.players = Player.players.Select(mc => mc.name).ToArray();
+ API.chat = Player.Last50Chat.ToArray();
+ api = JsonConvert.SerializeObject(API, Formatting.Indented);
+ return api;
+ }
+ catch(Exception e)
+ {
+ Logger.WriteError(e);
+ }
+ return "Error";
+ }
+ public static string WhoIsResponse(HttpListenerRequest request)
+ {
+ try
+ {
+ string p = request.QueryString.Get("name");
+ if (p == null || p == "")
+ return "Error";
+ var whois = new WhoWas(p);
+ if (whois.rank.Contains("banned"))
+ whois.banned = true;
+ else
+ whois.banned = Ban.Isbanned(p);
+ string[] bandata;
+ if (whois.banned)
+ {
+ bandata = Ban.Getbandata(p);
+ whois.banned_by = bandata[0];
+ whois.ban_reason = bandata[1].Replace("%20", " ");
+ whois.banned_time = bandata[2].Replace("%20", " ");
+ }
+
+ return JsonConvert.SerializeObject(whois, Formatting.Indented);
+ }
+ catch(Exception e)
+ {
+ Logger.WriteError(e);
+ }
+ return "Error";
+ }
public static void LoadAllSettings()
{
SrvProperties.Load("properties/server.properties");
@@ -1103,7 +1160,8 @@ namespace MCGalaxy
else
Player.Find(p).Kick("Server restarted! Rejoin!");
}
-
+ APIServer.Stop();
+ InfoServer.Stop();
//Player.players.ForEach(delegate(Player p) { p.Kick("Server shutdown. Rejoin in 10 seconds."); });
Player.connections.ForEach(
delegate(Player p)
diff --git a/Service References/TranslateService/MCForge.TranslateService.GetTranslationsResponse.datasource b/Service References/TranslateService/MCForge.TranslateService.GetTranslationsResponse.datasource
index 0e409d5ec..f847ce1a2 100644
--- a/Service References/TranslateService/MCForge.TranslateService.GetTranslationsResponse.datasource
+++ b/Service References/TranslateService/MCForge.TranslateService.GetTranslationsResponse.datasource
@@ -6,5 +6,5 @@
cause the file to be unrecognizable by the program.
-->
- MCGalaxy.TranslateService.GetTranslationsResponse, Service References.TranslateService.Reference.cs, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
+ MCGalaxy.TranslateService.GetTranslationsResponse, Service References.TranslateService.Reference.cs.dll, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
\ No newline at end of file
diff --git a/Service References/TranslateService/MCForge.TranslateService.TranslateArrayResponse.datasource b/Service References/TranslateService/MCForge.TranslateService.TranslateArrayResponse.datasource
index af5039f7b..940d300bf 100644
--- a/Service References/TranslateService/MCForge.TranslateService.TranslateArrayResponse.datasource
+++ b/Service References/TranslateService/MCForge.TranslateService.TranslateArrayResponse.datasource
@@ -6,5 +6,5 @@
cause the file to be unrecognizable by the program.
-->
- MCGalaxy.TranslateService.TranslateArrayResponse, Service References.TranslateService.Reference.cs, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
+ MCGalaxy.TranslateService.TranslateArrayResponse, Service References.TranslateService.Reference.cs.dll, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
\ No newline at end of file
diff --git a/Service References/TranslateService/Reference.cs b/Service References/TranslateService/Reference.cs
index 14cdc61ae..a5f01d037 100644
--- a/Service References/TranslateService/Reference.cs
+++ b/Service References/TranslateService/Reference.cs
@@ -1,7 +1,7 @@
//------------------------------------------------------------------------------
//
// This code was generated by a tool.
-// Runtime Version:4.0.30319.34014
+// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
diff --git a/Starter.csproj b/Starter.csproj
index e61978373..3b256de65 100644
--- a/Starter.csproj
+++ b/Starter.csproj
@@ -10,7 +10,7 @@
Properties
Starter
MCGalaxy
- v4.0
+ v4.5
512
@@ -24,9 +24,10 @@
DEBUG;TRACE
prompt
4
+ false
- x86
+ x64
pdbonly
true
bin\Release\
@@ -34,6 +35,7 @@
prompt
4
false
+ false
Starter.Program
diff --git a/WebServer.cs b/WebServer.cs
new file mode 100644
index 000000000..3efb57eff
--- /dev/null
+++ b/WebServer.cs
@@ -0,0 +1,80 @@
+using System;
+using System.Net;
+using System.Threading;
+using System.Linq;
+using System.Text;
+using System.Net.Mime;
+
+namespace MCGalaxy
+{
+ public class WebServer
+ {
+ private readonly HttpListener _listener = new HttpListener();
+ private readonly Func _responderMethod;
+
+ public WebServer(string[] prefixes, Func method)
+ {
+ if (!HttpListener.IsSupported)
+ throw new NotSupportedException(
+ "Needs Windows XP SP2, Server 2003 or later.");
+
+ // URI prefixes are required, for example
+ // "http://localhost:8080/index/".
+ if (prefixes == null || prefixes.Length == 0)
+ throw new ArgumentException("prefixes");
+
+ // A responder method is required
+ if (method == null)
+ throw new ArgumentException("method");
+
+ foreach (string s in prefixes)
+ _listener.Prefixes.Add(s);
+
+ _responderMethod = method;
+ _listener.Start();
+ }
+
+ public WebServer(Func method, params string[] prefixes)
+ : this(prefixes, method)
+ { }
+
+ public void Run()
+ {
+ ThreadPool.QueueUserWorkItem((o) =>
+ {
+ Console.WriteLine("Webserver running...");
+ try
+ {
+ while (_listener.IsListening)
+ {
+ ThreadPool.QueueUserWorkItem((c) =>
+ {
+ var ctx = c as HttpListenerContext;
+ try
+ {
+ string rstr = _responderMethod(ctx.Request);
+ byte[] buf = Encoding.UTF8.GetBytes(rstr);
+ ctx.Response.ContentType = "application/json";
+ ctx.Response.ContentLength64 = buf.Length;
+ ctx.Response.OutputStream.Write(buf, 0, buf.Length);
+ }
+ catch { } // suppress any exceptions
+ finally
+ {
+ // always close the stream
+ ctx.Response.OutputStream.Close();
+ }
+ }, _listener.GetContext());
+ }
+ }
+ catch { } // suppress any exceptions
+ });
+ }
+
+ public void Stop()
+ {
+ _listener.Stop();
+ _listener.Close();
+ }
+ }
+}
\ No newline at end of file
diff --git a/WhoWas.cs b/WhoWas.cs
new file mode 100644
index 000000000..6e1877be9
--- /dev/null
+++ b/WhoWas.cs
@@ -0,0 +1,40 @@
+using System;
+using System.Collections.Generic;
+using System.Data;
+using System.Linq;
+using System.Text;
+using MCGalaxy.SQL;
+
+namespace MCGalaxy
+{
+ public class WhoWas
+ {
+ public string rank { get; set; }
+ public int modified_blocks { get; set; }
+ public string time { get; set; }
+ public string first_login { get; set; }
+ public string last_login { get; set; }
+ public int total_logins { get; set; }
+ public bool banned { get; set; }
+ public string ban_reason { get; set; }
+ public string banned_by { get; set; }
+ public string banned_time { get; set; }
+ public int kicks { get; set; }
+
+ public WhoWas(string p)
+ {
+ Server.s.Log(p);
+ rank = Group.findPlayer(p);
+ Database.AddParams("@Name", p.ToLower());
+ DataTable playerDb = Database.fillData("SELECT * FROM Players WHERE Name=@Name COLLATE NOCASE");
+ if (playerDb.Rows.Count == 0)
+ return;
+ modified_blocks = int.Parse(playerDb.Rows[0]["totalBlocks"].ToString());
+ time = playerDb.Rows[0]["TimeSpent"].ToString();
+ first_login = playerDb.Rows[0]["FirstLogin"].ToString();
+ last_login = playerDb.Rows[0]["LastLogin"].ToString();
+ total_logins = int.Parse(playerDb.Rows[0]["totalLogin"].ToString());
+ kicks = int.Parse(playerDb.Rows[0]["totalKicked"].ToString());
+ }
+ }
+}
diff --git a/app.config b/app.config
index a3220c38d..f45187e03 100644
--- a/app.config
+++ b/app.config
@@ -1,19 +1,46 @@
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/packages.config b/packages.config
new file mode 100644
index 000000000..b27c1cb87
--- /dev/null
+++ b/packages.config
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/properties/Resources.Designer.cs b/properties/Resources.Designer.cs
index b9e8259a9..e86184eef 100644
--- a/properties/Resources.Designer.cs
+++ b/properties/Resources.Designer.cs
@@ -1,7 +1,7 @@
//------------------------------------------------------------------------------
//
// This code was generated by a tool.
-// Runtime Version:4.0.30319.34014
+// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.