mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-24 05:03:34 -04:00
Core: accept trailing 0x00s in login, add /server backup litedb
This commit is contained in:
parent
70a2771399
commit
48c57549eb
@ -84,19 +84,22 @@ namespace MCGalaxy.Commands {
|
|||||||
void DoBackup(Player p, string[] args) {
|
void DoBackup(Player p, string[] args) {
|
||||||
string type = args.Length == 1 ? "" : args[1].ToLower();
|
string type = args.Length == 1 ? "" : args[1].ToLower();
|
||||||
if (type == "" || type == "all") {
|
if (type == "" || type == "all") {
|
||||||
Player.Message(p, "Server backup (Everything) started. Please wait while backup finishes.");
|
Player.Message(p, "Server backup started. Please wait while backup finishes.");
|
||||||
Backup.CreatePackage(p, true, true, false);
|
Backup.CreatePackage(p, true, true, false);
|
||||||
} else if (type == "database" || type == "sql" || type == "db") {
|
} else if (type == "database" || type == "sql" || type == "db") {
|
||||||
// Creates CREATE TABLE and INSERT statements for all tables and rows in the database
|
// Creates CREATE TABLE and INSERT statements for all tables and rows in the database
|
||||||
Player.Message(p, "Server backup (Database) started. Please wait while backup finishes.");
|
Player.Message(p, "Database backup started. Please wait while backup finishes.");
|
||||||
Backup.CreatePackage(p, false, true, false);
|
Backup.CreatePackage(p, false, true, false);
|
||||||
} else if (type == "allbutdb" || type == "files" || type == "file") {
|
} else if (type == "allbutdb" || type == "files" || type == "file") {
|
||||||
// Saves all files and folders to a .zip
|
// Saves all files and folders to a .zip
|
||||||
Player.Message(p, "Server backup (Everything but Database) started. Please wait while backup finishes.");
|
Player.Message(p, "All files backup started. Please wait while backup finishes.");
|
||||||
Backup.CreatePackage(p, true, false, false);
|
Backup.CreatePackage(p, true, false, false);
|
||||||
} else if (type == "lite") {
|
} else if (type == "lite") {
|
||||||
Player.Message(p, "Server backup (Everything but BlockDB tables and undo files) started. Please wait while backup finishes.");
|
Player.Message(p, "Server backup (except BlockDB and undo data) started. Please wait while backup finishes.");
|
||||||
Backup.CreatePackage(p, true, true, true);
|
Backup.CreatePackage(p, true, true, true);
|
||||||
|
} else if (type == "litedb") {
|
||||||
|
Player.Message(p, "Database backup (except BlockDB tables) started. Please wait while backup finishes.");
|
||||||
|
Backup.CreatePackage(p, false, true, true);
|
||||||
} else if (type == "table") {
|
} else if (type == "table") {
|
||||||
if (args.Length == 2) { Player.Message(p, "You need to provide the table name to backup."); return; }
|
if (args.Length == 2) { Player.Message(p, "You need to provide the table name to backup."); return; }
|
||||||
if (!Formatter.ValidName(p, args[2], "table")) return;
|
if (!Formatter.ValidName(p, args[2], "table")) return;
|
||||||
@ -170,11 +173,12 @@ namespace MCGalaxy.Commands {
|
|||||||
Player.Message(p, "%T/server reload %H- Reload the server files. (May require restart) (Owner only)");
|
Player.Message(p, "%T/server reload %H- Reload the server files. (May require restart) (Owner only)");
|
||||||
Player.Message(p, "%T/server public/private %H- Make the server public or private.");
|
Player.Message(p, "%T/server public/private %H- Make the server public or private.");
|
||||||
Player.Message(p, "%T/server restore %H- Restore the server from a backup.");
|
Player.Message(p, "%T/server restore %H- Restore the server from a backup.");
|
||||||
Player.Message(p, "%T/server backup all/db/files/lite %H- Make a backup.");
|
Player.Message(p, "%T/server backup all/db/files/lite/litedb %H- Make a backup.");
|
||||||
Player.Message(p, " %Hall - Backups everything (default)");
|
Player.Message(p, " %Hall - Backups everything (default)");
|
||||||
Player.Message(p, " %Hdb - Only backups the database.");
|
Player.Message(p, " %Hdb - Only backups the database.");
|
||||||
Player.Message(p, " %Hfiles - Backups everything, except the database.");
|
Player.Message(p, " %Hfiles - Backups everything, except the database.");
|
||||||
Player.Message(p, " %Hlite - Backups everything, except BlockDB and undo files.");
|
Player.Message(p, " %Hlite - Backups everything, except BlockDB and undo files.");
|
||||||
|
Player.Message(p, " %Hlitedb - Backups database, except BlockDB tables.");
|
||||||
Player.Message(p, "%T/server backup table [name] %H- Backups that database table");
|
Player.Message(p, "%T/server backup table [name] %H- Backups that database table");
|
||||||
Player.Message(p, "%T/server import [name] %H- Imports a backed up database table");
|
Player.Message(p, "%T/server import [name] %H- Imports a backed up database table");
|
||||||
}
|
}
|
||||||
|
@ -51,8 +51,20 @@ namespace MCGalaxy {
|
|||||||
array[index++] = (byte)(value >> 16);
|
array[index++] = (byte)(value >> 16);
|
||||||
array[index++] = (byte)(value >> 8);
|
array[index++] = (byte)(value >> 8);
|
||||||
array[index++] = (byte)(value);
|
array[index++] = (byte)(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public unsafe static string ReadString(byte[] data, int offset) {
|
||||||
|
int length = 0;
|
||||||
|
char* characters = stackalloc char[64];
|
||||||
|
for (int i = 63; i >= 0; i--) {
|
||||||
|
byte code = data[i + offset];
|
||||||
|
if( length == 0 && !(code == 0x00 || code == 0x20))
|
||||||
|
length = i + 1;
|
||||||
|
characters[i] = (char)code;
|
||||||
|
}
|
||||||
|
return new String(characters, 0, length);
|
||||||
|
}
|
||||||
|
|
||||||
public static void Write(string str, byte[] array, int offset, bool hasCP437) {
|
public static void Write(string str, byte[] array, int offset, bool hasCP437) {
|
||||||
if (hasCP437) WriteCP437(str, array, offset);
|
if (hasCP437) WriteCP437(str, array, offset);
|
||||||
|
@ -68,13 +68,13 @@ namespace MCGalaxy {
|
|||||||
public int customBlockSupportLevel;
|
public int customBlockSupportLevel;
|
||||||
|
|
||||||
void HandleExtInfo(byte[] packet) {
|
void HandleExtInfo(byte[] packet) {
|
||||||
appName = GetString(packet, 1);
|
appName = NetUtils.ReadString(packet, 1);
|
||||||
extensionCount = packet[66];
|
extensionCount = packet[66];
|
||||||
CheckReadAllExtensions(); // in case client supports 0 CPE packets
|
CheckReadAllExtensions(); // in case client supports 0 CPE packets
|
||||||
}
|
}
|
||||||
|
|
||||||
void HandleExtEntry(byte[] packet) {
|
void HandleExtEntry(byte[] packet) {
|
||||||
AddExtension(GetString(packet, 1), NetUtils.ReadI32(packet, 65));
|
AddExtension(NetUtils.ReadString(packet, 1), NetUtils.ReadI32(packet, 65));
|
||||||
extensionCount--;
|
extensionCount--;
|
||||||
CheckReadAllExtensions();
|
CheckReadAllExtensions();
|
||||||
}
|
}
|
||||||
@ -105,18 +105,7 @@ namespace MCGalaxy {
|
|||||||
finishedCpeLogin = true;
|
finishedCpeLogin = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
char[] characters = new char[64];
|
|
||||||
string GetString( byte[] data, int offset ) {
|
|
||||||
int length = 0;
|
|
||||||
for( int i = 63; i >= 0; i-- ) {
|
|
||||||
byte code = data[i + offset];
|
|
||||||
if( length == 0 && !( code == 0 || code == 0x20 ) )
|
|
||||||
length = i + 1;
|
|
||||||
characters[i] = (char)code;
|
|
||||||
}
|
|
||||||
return new String( characters, 0, length );
|
|
||||||
}
|
|
||||||
|
|
||||||
public void SendRaw(int id) {
|
public void SendRaw(int id) {
|
||||||
byte[] buffer = new [] { (byte)id };
|
byte[] buffer = new [] { (byte)id };
|
||||||
|
@ -485,7 +485,7 @@ namespace MCGalaxy {
|
|||||||
void HandleChat(byte[] packet) {
|
void HandleChat(byte[] packet) {
|
||||||
if (!loggedIn) return;
|
if (!loggedIn) return;
|
||||||
byte continued = packet[1];
|
byte continued = packet[1];
|
||||||
string text = GetString(packet, 2);
|
string text = NetUtils.ReadString(packet, 2);
|
||||||
LastAction = DateTime.UtcNow;
|
LastAction = DateTime.UtcNow;
|
||||||
if (FilterChat(ref text, continued)) return;
|
if (FilterChat(ref text, continued)) return;
|
||||||
|
|
||||||
|
@ -29,11 +29,11 @@ namespace MCGalaxy {
|
|||||||
byte version = packet[1];
|
byte version = packet[1];
|
||||||
if (version != Server.version) { Leave(null, "Wrong version!", true); return; }
|
if (version != Server.version) { Leave(null, "Wrong version!", true); return; }
|
||||||
|
|
||||||
name = enc.GetString(packet, 2, 64).Trim();
|
name = NetUtils.ReadString(packet, 2);
|
||||||
skinName = name; DisplayName = name; truename = name;
|
skinName = name; DisplayName = name; truename = name;
|
||||||
if (Server.ClassicubeAccountPlus) name += "+";
|
if (Server.ClassicubeAccountPlus) name += "+";
|
||||||
|
|
||||||
string mppass = enc.GetString(packet, 66, 32).Trim();
|
string mppass = NetUtils.ReadString(packet, 66);
|
||||||
if (PlayerConnecting != null) PlayerConnecting(this, mppass);
|
if (PlayerConnecting != null) PlayerConnecting(this, mppass);
|
||||||
OnPlayerConnectingEvent.Call(this, mppass);
|
OnPlayerConnectingEvent.Call(this, mppass);
|
||||||
if (cancelconnecting) { cancelconnecting = false; return; }
|
if (cancelconnecting) { cancelconnecting = false; return; }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user