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) {
|
||||
string type = args.Length == 1 ? "" : args[1].ToLower();
|
||||
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);
|
||||
} else if (type == "database" || type == "sql" || type == "db") {
|
||||
// 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);
|
||||
} else if (type == "allbutdb" || type == "files" || type == "file") {
|
||||
// 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);
|
||||
} 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);
|
||||
} 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") {
|
||||
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;
|
||||
@ -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 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 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, " %Hdb - Only backups 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, " %Hlitedb - Backups database, except BlockDB tables.");
|
||||
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");
|
||||
}
|
||||
|
@ -54,6 +54,18 @@ namespace MCGalaxy {
|
||||
}
|
||||
|
||||
|
||||
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) {
|
||||
if (hasCP437) WriteCP437(str, array, offset);
|
||||
else WriteAscii(str, array, offset);
|
||||
|
@ -68,13 +68,13 @@ namespace MCGalaxy {
|
||||
public int customBlockSupportLevel;
|
||||
|
||||
void HandleExtInfo(byte[] packet) {
|
||||
appName = GetString(packet, 1);
|
||||
appName = NetUtils.ReadString(packet, 1);
|
||||
extensionCount = packet[66];
|
||||
CheckReadAllExtensions(); // in case client supports 0 CPE packets
|
||||
}
|
||||
|
||||
void HandleExtEntry(byte[] packet) {
|
||||
AddExtension(GetString(packet, 1), NetUtils.ReadI32(packet, 65));
|
||||
AddExtension(NetUtils.ReadString(packet, 1), NetUtils.ReadI32(packet, 65));
|
||||
extensionCount--;
|
||||
CheckReadAllExtensions();
|
||||
}
|
||||
@ -106,17 +106,6 @@ namespace MCGalaxy {
|
||||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
byte[] buffer = new [] { (byte)id };
|
||||
|
@ -485,7 +485,7 @@ namespace MCGalaxy {
|
||||
void HandleChat(byte[] packet) {
|
||||
if (!loggedIn) return;
|
||||
byte continued = packet[1];
|
||||
string text = GetString(packet, 2);
|
||||
string text = NetUtils.ReadString(packet, 2);
|
||||
LastAction = DateTime.UtcNow;
|
||||
if (FilterChat(ref text, continued)) return;
|
||||
|
||||
|
@ -29,11 +29,11 @@ namespace MCGalaxy {
|
||||
byte version = packet[1];
|
||||
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;
|
||||
if (Server.ClassicubeAccountPlus) name += "+";
|
||||
|
||||
string mppass = enc.GetString(packet, 66, 32).Trim();
|
||||
string mppass = NetUtils.ReadString(packet, 66);
|
||||
if (PlayerConnecting != null) PlayerConnecting(this, mppass);
|
||||
OnPlayerConnectingEvent.Call(this, mppass);
|
||||
if (cancelconnecting) { cancelconnecting = false; return; }
|
||||
|
Loading…
x
Reference in New Issue
Block a user