mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/LCEMP-Server.git
synced 2026-09-23 10:03:39 +00:00
Initial commit
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
#include "stdafx.h"
|
||||
#include "BanCommand.h"
|
||||
#include "ServerCommand.h"
|
||||
#include "../../Minecraft.Client/MinecraftServer.h"
|
||||
#include "../../Minecraft.Client/ConsoleInputSource.h"
|
||||
#include "../../Minecraft.Client/PlayerList.h"
|
||||
#include "../../Minecraft.Client/ServerPlayer.h"
|
||||
#include "../../Minecraft.Client/PlayerConnection.h"
|
||||
#include "../../Minecraft.World/DisconnectPacket.h"
|
||||
#include "../Core/ServerLists.h"
|
||||
#include "ServerTextList.h"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
void BanCommand::execute(const wstring& args, ConsoleInputSource *src, MinecraftServer *server)
|
||||
{
|
||||
wstringstream ss(args);
|
||||
wstring playerName;
|
||||
if (!(ss >> playerName))
|
||||
{
|
||||
src->warn(L"Usage: /ban <player>");
|
||||
return;
|
||||
}
|
||||
|
||||
ServerLists_GetBannedPlayers()->add(playerName);
|
||||
ServerCommand::notifyAdmins(src, server, L"Banned player " + playerName);
|
||||
|
||||
shared_ptr<ServerPlayer> player = server->getPlayers()->getPlayer(playerName);
|
||||
if (player)
|
||||
player->connection->disconnect(DisconnectPacket::eDisconnect_Banned);
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
#pragma once
|
||||
#include "ServerCommand.h"
|
||||
|
||||
class BanCommand : public ServerCommand
|
||||
{
|
||||
public:
|
||||
wstring getName() { return L"ban"; }
|
||||
wstring getUsage() { return L"/ban <player> - Bans a player from the server"; }
|
||||
void execute(const wstring& args, ConsoleInputSource *src, MinecraftServer *server);
|
||||
};
|
||||
@@ -0,0 +1,97 @@
|
||||
#include "stdafx.h"
|
||||
#include "BanIpCommand.h"
|
||||
#include "ServerCommand.h"
|
||||
#include "../../Minecraft.Client/ConsoleInputSource.h"
|
||||
#include "../../Minecraft.Client/MinecraftServer.h"
|
||||
#include "../../Minecraft.Client/PlayerList.h"
|
||||
#include "../../Minecraft.Client/ServerPlayer.h"
|
||||
#include "../../Minecraft.Client/PlayerConnection.h"
|
||||
#include "../../Minecraft.World/DisconnectPacket.h"
|
||||
#include "../../Minecraft.World/Connection.h"
|
||||
#include "../../Minecraft.World/Socket.h"
|
||||
#include "../../Minecraft.Client/Windows64/Network/WinsockNetLayer.h"
|
||||
#include "../Core/ServerLists.h"
|
||||
#include "ServerTextList.h"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
static bool isValidIP(const wstring& str)
|
||||
{
|
||||
int dots = 0;
|
||||
for (size_t i = 0; i < str.size(); i++)
|
||||
{
|
||||
if (str[i] == L'.') dots++;
|
||||
else if (str[i] < L'0' || str[i] > L'9') return false;
|
||||
}
|
||||
return dots == 3 && str.size() >= 7;
|
||||
}
|
||||
|
||||
static wstring narrowToWide(const std::string& s)
|
||||
{
|
||||
return wstring(s.begin(), s.end());
|
||||
}
|
||||
|
||||
void BanIpCommand::execute(const wstring& args, ConsoleInputSource *src, MinecraftServer *server)
|
||||
{
|
||||
wstringstream ss(args);
|
||||
wstring arg;
|
||||
if (!(ss >> arg))
|
||||
{
|
||||
src->warn(L"Usage: " + getUsage());
|
||||
return;
|
||||
}
|
||||
|
||||
wstring ip;
|
||||
if (isValidIP(arg))
|
||||
{
|
||||
ip = arg;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!server || !server->getPlayers())
|
||||
{
|
||||
src->warn(L"Cannot resolve player name, no players online");
|
||||
return;
|
||||
}
|
||||
shared_ptr<ServerPlayer> target = server->getPlayers()->getPlayer(arg);
|
||||
if (!target || !target->connection)
|
||||
{
|
||||
src->warn(L"Cannot find player \"" + arg + L"\"");
|
||||
return;
|
||||
}
|
||||
Connection *conn = target->connection->connection;
|
||||
if (!conn || !conn->getSocket())
|
||||
{
|
||||
src->warn(L"Cannot determine IP for \"" + arg + L"\"");
|
||||
return;
|
||||
}
|
||||
BYTE smallId = conn->getSocket()->getSmallId();
|
||||
std::string ipStr = WinsockNetLayer::GetIPForSmallId(smallId);
|
||||
if (ipStr.empty())
|
||||
{
|
||||
src->warn(L"Cannot determine IP for \"" + arg + L"\"");
|
||||
return;
|
||||
}
|
||||
ip = narrowToWide(ipStr);
|
||||
}
|
||||
|
||||
ServerLists_GetBannedIPs()->add(ip);
|
||||
ServerCommand::notifyAdmins(src, server, L"Banned IP address " + ip);
|
||||
|
||||
if (server && server->getPlayers())
|
||||
{
|
||||
vector<shared_ptr<ServerPlayer>>& pl = server->getPlayers()->players;
|
||||
for (unsigned int i = 0; i < pl.size(); i++)
|
||||
{
|
||||
if (!pl[i] || !pl[i]->connection) continue;
|
||||
Connection *conn = pl[i]->connection->connection;
|
||||
if (!conn || !conn->getSocket()) continue;
|
||||
BYTE sid = conn->getSocket()->getSmallId();
|
||||
std::string pIp = WinsockNetLayer::GetIPForSmallId(sid);
|
||||
if (narrowToWide(pIp) == ip)
|
||||
{
|
||||
server->getPlayers()->kickPlayerByShortId(sid);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
#pragma once
|
||||
#include "ServerCommand.h"
|
||||
|
||||
class BanIpCommand : public ServerCommand
|
||||
{
|
||||
public:
|
||||
wstring getName() { return L"ban-ip"; }
|
||||
wstring getUsage() { return L"/ban-ip <address|name> - Bans an IP address"; }
|
||||
void execute(const wstring& args, ConsoleInputSource *src, MinecraftServer *server);
|
||||
};
|
||||
@@ -0,0 +1,45 @@
|
||||
#include "stdafx.h"
|
||||
#include "BanListCommand.h"
|
||||
#include "ServerTextList.h"
|
||||
#include "../../Minecraft.Client/ConsoleInputSource.h"
|
||||
#include "../../Minecraft.Client/MinecraftServer.h"
|
||||
#include "../Core/ServerLists.h"
|
||||
#include "ServerTextList.h"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
void BanListCommand::execute(const wstring& args, ConsoleInputSource *src, MinecraftServer *server)
|
||||
{
|
||||
wstringstream ss(args);
|
||||
wstring type;
|
||||
ss >> type;
|
||||
|
||||
if (type == L"ips")
|
||||
{
|
||||
const set<wstring>& entries = ServerLists_GetBannedIPs()->getEntries();
|
||||
wchar_t buf[128];
|
||||
swprintf_s(buf, 128, L"There are %d banned IP addresses:", (int)entries.size());
|
||||
src->info(wstring(buf));
|
||||
wstring list;
|
||||
for (set<wstring>::const_iterator it = entries.begin(); it != entries.end(); ++it)
|
||||
{
|
||||
if (!list.empty()) list += L", ";
|
||||
list += *it;
|
||||
}
|
||||
if (!list.empty()) src->info(list);
|
||||
}
|
||||
else
|
||||
{
|
||||
const set<wstring>& entries = ServerLists_GetBannedPlayers()->getEntries();
|
||||
wchar_t buf[128];
|
||||
swprintf_s(buf, 128, L"There are %d banned players:", (int)entries.size());
|
||||
src->info(wstring(buf));
|
||||
wstring list;
|
||||
for (set<wstring>::const_iterator it = entries.begin(); it != entries.end(); ++it)
|
||||
{
|
||||
if (!list.empty()) list += L", ";
|
||||
list += *it;
|
||||
}
|
||||
if (!list.empty()) src->info(list);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
#pragma once
|
||||
#include "ServerCommand.h"
|
||||
|
||||
class BanListCommand : public ServerCommand
|
||||
{
|
||||
public:
|
||||
wstring getName() { return L"banlist"; }
|
||||
wstring getUsage() { return L"/banlist [ips|players] - Shows the ban list"; }
|
||||
void execute(const wstring& args, ConsoleInputSource *src, MinecraftServer *server);
|
||||
};
|
||||
@@ -0,0 +1,31 @@
|
||||
#include "stdafx.h"
|
||||
#include "ConsoleCommandDispatcher.h"
|
||||
#include "../../Minecraft.Client/ConsoleInputSource.h"
|
||||
|
||||
ConsoleCommandDispatcher::~ConsoleCommandDispatcher()
|
||||
{
|
||||
for (AUTO_VAR(it, commandsByName.begin()); it != commandsByName.end(); ++it)
|
||||
delete it->second;
|
||||
commandsByName.clear();
|
||||
}
|
||||
|
||||
void ConsoleCommandDispatcher::addCommand(ServerCommand *command)
|
||||
{
|
||||
commandsByName[command->getName()] = command;
|
||||
}
|
||||
|
||||
bool ConsoleCommandDispatcher::performCommand(const wstring& name, const wstring& args, ConsoleInputSource *src, MinecraftServer *server)
|
||||
{
|
||||
AUTO_VAR(it, commandsByName.find(name));
|
||||
if (it != commandsByName.end())
|
||||
{
|
||||
it->second->execute(args, src, server);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
const map<wstring, ServerCommand *>& ConsoleCommandDispatcher::getCommands() const
|
||||
{
|
||||
return commandsByName;
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
#pragma once
|
||||
|
||||
#include "ServerCommand.h"
|
||||
#include <map>
|
||||
|
||||
class ConsoleCommandDispatcher
|
||||
{
|
||||
private:
|
||||
map<wstring, ServerCommand *> commandsByName;
|
||||
|
||||
public:
|
||||
~ConsoleCommandDispatcher();
|
||||
|
||||
void addCommand(ServerCommand *command);
|
||||
bool performCommand(const wstring& name, const wstring& args, ConsoleInputSource *src, MinecraftServer *server);
|
||||
const map<wstring, ServerCommand *>& getCommands() const;
|
||||
};
|
||||
@@ -0,0 +1,13 @@
|
||||
#include "stdafx.h"
|
||||
#include "ConsoleCommandSender.h"
|
||||
#include "../../Minecraft.Client/ConsoleInputSource.h"
|
||||
|
||||
void ConsoleCommandSender::sendMessage(const wstring& message, ChatPacket::EChatPacketMessage type, int customData, const wstring& additionalMessage)
|
||||
{
|
||||
src->info(message);
|
||||
}
|
||||
|
||||
bool ConsoleCommandSender::hasPermission(EGameCommand command)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
#pragma once
|
||||
|
||||
#include "../../Minecraft.World/CommandSender.h"
|
||||
|
||||
class ConsoleInputSource;
|
||||
|
||||
class ConsoleCommandSender : public CommandSender
|
||||
{
|
||||
private:
|
||||
ConsoleInputSource *src;
|
||||
|
||||
public:
|
||||
ConsoleCommandSender(ConsoleInputSource *src) : src(src) {}
|
||||
|
||||
void sendMessage(const wstring& message, ChatPacket::EChatPacketMessage type = ChatPacket::e_ChatCustom, int customData = -1, const wstring& additionalMessage = L"");
|
||||
bool hasPermission(EGameCommand command);
|
||||
};
|
||||
@@ -0,0 +1,36 @@
|
||||
#include "stdafx.h"
|
||||
#include "DeOpCommand.h"
|
||||
#include "ServerCommand.h"
|
||||
#include "../../Minecraft.Client/ConsoleInputSource.h"
|
||||
#include "../../Minecraft.Client/MinecraftServer.h"
|
||||
#include "../../Minecraft.Client/PlayerList.h"
|
||||
#include "../../Minecraft.Client/ServerPlayer.h"
|
||||
#include "../../Minecraft.World/net.minecraft.network.packet.h"
|
||||
#include "../Core/ServerLists.h"
|
||||
#include "ServerTextList.h"
|
||||
|
||||
void DeOpCommand::execute(const wstring& args, ConsoleInputSource *src, MinecraftServer *server)
|
||||
{
|
||||
wstring name = args;
|
||||
size_t start = name.find_first_not_of(L" \t");
|
||||
if (start == wstring::npos || name.empty())
|
||||
{
|
||||
src->warn(L"Usage: /deop <player>");
|
||||
return;
|
||||
}
|
||||
name = name.substr(start);
|
||||
size_t end = name.find_first_of(L" \t");
|
||||
if (end != wstring::npos)
|
||||
name = name.substr(0, end);
|
||||
|
||||
ServerLists_GetOps()->remove(name);
|
||||
|
||||
shared_ptr<ServerPlayer> player = server->getPlayers()->getPlayer(name);
|
||||
if (player != nullptr)
|
||||
{
|
||||
player->setPlayerGamePrivilege(Player::ePlayerGamePrivilege_Op, 0);
|
||||
server->getPlayers()->broadcastAll(shared_ptr<PlayerInfoPacket>(new PlayerInfoPacket(player)));
|
||||
}
|
||||
|
||||
ServerCommand::notifyAdmins(src, server, L"De-opped " + name);
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
#pragma once
|
||||
#include "ServerCommand.h"
|
||||
|
||||
class DeOpCommand : public ServerCommand
|
||||
{
|
||||
public:
|
||||
wstring getName() { return L"deop"; }
|
||||
wstring getUsage() { return L"/deop <player> - Removes operator status from a player"; }
|
||||
void execute(const wstring& args, ConsoleInputSource *src, MinecraftServer *server);
|
||||
};
|
||||
@@ -0,0 +1,55 @@
|
||||
#include "stdafx.h"
|
||||
#include "DebugCommand.h"
|
||||
#include "ServerCommand.h"
|
||||
#include "../../Minecraft.Client/MinecraftServer.h"
|
||||
#include "../../Minecraft.Client/ConsoleInputSource.h"
|
||||
|
||||
#include <sstream>
|
||||
#include <time.h>
|
||||
|
||||
static bool s_profiling = false;
|
||||
static time_t s_profilingStart = 0;
|
||||
static int s_profilingStartTick = 0;
|
||||
|
||||
void DebugCommand::execute(const wstring& args, ConsoleInputSource *src, MinecraftServer *server)
|
||||
{
|
||||
wstringstream ss(args);
|
||||
wstring subCmd;
|
||||
if (!(ss >> subCmd))
|
||||
{
|
||||
src->warn(L"Usage: /debug <start|stop>");
|
||||
return;
|
||||
}
|
||||
|
||||
if (subCmd == L"start")
|
||||
{
|
||||
if (s_profiling)
|
||||
{
|
||||
src->warn(L"Debug profiling is already started");
|
||||
return;
|
||||
}
|
||||
s_profiling = true;
|
||||
s_profilingStart = time(NULL);
|
||||
s_profilingStartTick = server->tickCount;
|
||||
ServerCommand::notifyAdmins(src, server, L"Starting debug profiling");
|
||||
}
|
||||
else if (subCmd == L"stop")
|
||||
{
|
||||
if (!s_profiling)
|
||||
{
|
||||
src->warn(L"Debug profiling is not started");
|
||||
return;
|
||||
}
|
||||
s_profiling = false;
|
||||
time_t elapsed = time(NULL) - s_profilingStart;
|
||||
int ticks = server->tickCount - s_profilingStartTick;
|
||||
float tps = elapsed > 0 ? (float)ticks / (float)elapsed : 0.0f;
|
||||
wchar_t buf[256];
|
||||
swprintf_s(buf, 256, L"Stopped debug profiling after %.2f seconds and %d ticks (%.2f ticks per second)", (float)elapsed, ticks, tps);
|
||||
ServerCommand::notifyAdmins(src, server, wstring(buf));
|
||||
}
|
||||
else
|
||||
{
|
||||
src->warn(L"Usage: /debug <start|stop>");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
#pragma once
|
||||
#include "ServerCommand.h"
|
||||
|
||||
class DebugCommand : public ServerCommand
|
||||
{
|
||||
public:
|
||||
wstring getName() { return L"debug"; }
|
||||
wstring getUsage() { return L"/debug <start|stop> - Starts or stops a debugging session"; }
|
||||
void execute(const wstring& args, ConsoleInputSource *src, MinecraftServer *server);
|
||||
};
|
||||
@@ -0,0 +1,36 @@
|
||||
#include "stdafx.h"
|
||||
#include "DefaultGameModeCommand.h"
|
||||
#include "ServerCommand.h"
|
||||
#include "../../Minecraft.Client/MinecraftServer.h"
|
||||
#include "../../Minecraft.Client/ConsoleInputSource.h"
|
||||
#include "../../Minecraft.Client/PlayerList.h"
|
||||
#include "../../Minecraft.World/LevelSettings.h"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
void DefaultGameModeCommand::execute(const wstring& args, ConsoleInputSource *src, MinecraftServer *server)
|
||||
{
|
||||
wstringstream ss(args);
|
||||
wstring modeStr;
|
||||
if (!(ss >> modeStr))
|
||||
{
|
||||
src->warn(L"Usage: /defaultgamemode <mode>");
|
||||
return;
|
||||
}
|
||||
|
||||
GameType *mode = NULL;
|
||||
if (modeStr == L"0" || modeStr == L"s" || modeStr == L"survival")
|
||||
mode = GameType::SURVIVAL;
|
||||
else if (modeStr == L"1" || modeStr == L"c" || modeStr == L"creative")
|
||||
mode = GameType::CREATIVE;
|
||||
else if (modeStr == L"2" || modeStr == L"a" || modeStr == L"adventure")
|
||||
mode = GameType::ADVENTURE;
|
||||
else
|
||||
{
|
||||
src->warn(L"Unknown game mode: " + modeStr);
|
||||
return;
|
||||
}
|
||||
|
||||
server->getPlayers()->setOverrideGameMode(mode);
|
||||
ServerCommand::notifyAdmins(src, server, L"The world's default game mode is now " + mode->getName());
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
#pragma once
|
||||
#include "ServerCommand.h"
|
||||
|
||||
class DefaultGameModeCommand : public ServerCommand
|
||||
{
|
||||
public:
|
||||
wstring getName() { return L"defaultgamemode"; }
|
||||
wstring getUsage() { return L"/defaultgamemode <mode> - Sets the default game mode"; }
|
||||
void execute(const wstring& args, ConsoleInputSource *src, MinecraftServer *server);
|
||||
};
|
||||
@@ -0,0 +1,48 @@
|
||||
#include "stdafx.h"
|
||||
#include "EnchantServerCommand.h"
|
||||
#include "ConsoleCommandSender.h"
|
||||
|
||||
#include "../../Minecraft.Client/MinecraftServer.h"
|
||||
#include "../../Minecraft.Client/ConsoleInputSource.h"
|
||||
#include "../../Minecraft.Client/PlayerList.h"
|
||||
#include "../../Minecraft.Client/ServerPlayer.h"
|
||||
#include "../../Minecraft.World/CommandDispatcher.h"
|
||||
#include "../../Minecraft.World/ByteArrayOutputStream.h"
|
||||
#include "../../Minecraft.World/DataOutputStream.h"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
void EnchantServerCommand::execute(const wstring& args, ConsoleInputSource *src, MinecraftServer *server)
|
||||
{
|
||||
wstringstream ss(args);
|
||||
wstring playerName;
|
||||
int enchantmentId = 0;
|
||||
int enchantmentLevel = 1;
|
||||
|
||||
if (!(ss >> playerName >> enchantmentId))
|
||||
{
|
||||
src->warn(L"\u00A7cUsage: /enchant <player> <enchantment ID> [level]");
|
||||
return;
|
||||
}
|
||||
|
||||
ss >> enchantmentLevel;
|
||||
|
||||
PlayerList *players = server->getPlayers();
|
||||
shared_ptr<ServerPlayer> player = players->getPlayer(playerName);
|
||||
if (!player)
|
||||
{
|
||||
src->warn(L"\u00A7cThat player cannot be found");
|
||||
return;
|
||||
}
|
||||
|
||||
ByteArrayOutputStream baos;
|
||||
DataOutputStream dos(&baos);
|
||||
|
||||
dos.writePlayerUID(player->getXuid());
|
||||
dos.writeInt(enchantmentId);
|
||||
dos.writeInt(enchantmentLevel);
|
||||
|
||||
shared_ptr<ConsoleCommandSender> sender(new ConsoleCommandSender(src));
|
||||
CommandDispatcher *dispatcher = server->getCommandDispatcher();
|
||||
dispatcher->performCommand(sender, eGameCommand_EnchantItem, baos.toByteArray());
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
#include "ServerCommand.h"
|
||||
|
||||
class EnchantServerCommand : public ServerCommand
|
||||
{
|
||||
public:
|
||||
wstring getName() { return L"enchant"; }
|
||||
wstring getUsage() { return L"/enchant <player> <enchantment ID> [level]"; }
|
||||
void execute(const wstring& args, ConsoleInputSource *src, MinecraftServer *server);
|
||||
};
|
||||
@@ -0,0 +1,56 @@
|
||||
#include "stdafx.h"
|
||||
#include "GameModeServerCommand.h"
|
||||
#include "ServerCommand.h"
|
||||
#include "ConsoleCommandSender.h"
|
||||
|
||||
#include "../../Minecraft.Client/MinecraftServer.h"
|
||||
#include "../../Minecraft.Client/ConsoleInputSource.h"
|
||||
#include "../../Minecraft.Client/PlayerList.h"
|
||||
#include "../../Minecraft.Client/ServerPlayer.h"
|
||||
#include "../../Minecraft.World/LevelSettings.h"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
void GameModeServerCommand::execute(const wstring& args, ConsoleInputSource *src, MinecraftServer *server)
|
||||
{
|
||||
wstringstream ss(args);
|
||||
wstring modeStr;
|
||||
|
||||
if (!(ss >> modeStr))
|
||||
{
|
||||
src->warn(L"\u00A7cUsage: /gamemode <mode> [player]");
|
||||
return;
|
||||
}
|
||||
|
||||
GameType *mode = NULL;
|
||||
if (modeStr == L"0" || modeStr == L"s" || modeStr == L"survival")
|
||||
mode = GameType::SURVIVAL;
|
||||
else if (modeStr == L"1" || modeStr == L"c" || modeStr == L"creative")
|
||||
mode = GameType::CREATIVE;
|
||||
else if (modeStr == L"2" || modeStr == L"a" || modeStr == L"adventure")
|
||||
mode = GameType::ADVENTURE;
|
||||
else
|
||||
{
|
||||
src->warn(L"\u00A7cUnknown game mode: " + modeStr);
|
||||
return;
|
||||
}
|
||||
|
||||
wstring playerName;
|
||||
if (!(ss >> playerName))
|
||||
{
|
||||
src->warn(L"\u00A7cYou must specify which player you wish to perform this action on.");
|
||||
return;
|
||||
}
|
||||
|
||||
PlayerList *players = server->getPlayers();
|
||||
shared_ptr<ServerPlayer> player = players->getPlayer(playerName);
|
||||
if (!player)
|
||||
{
|
||||
src->warn(L"\u00A7cThat player cannot be found");
|
||||
return;
|
||||
}
|
||||
player->setGameMode(mode);
|
||||
wchar_t buf[256];
|
||||
swprintf_s(buf, 256, L"Set %s's game mode to %s", player->name.c_str(), mode->getName().c_str());
|
||||
ServerCommand::notifyAdmins(src, server, wstring(buf));
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
#include "ServerCommand.h"
|
||||
|
||||
class GameModeServerCommand : public ServerCommand
|
||||
{
|
||||
public:
|
||||
wstring getName() { return L"gamemode"; }
|
||||
wstring getUsage() { return L"/gamemode <mode> [player]"; }
|
||||
void execute(const wstring& args, ConsoleInputSource *src, MinecraftServer *server);
|
||||
};
|
||||
@@ -0,0 +1,59 @@
|
||||
#include "stdafx.h"
|
||||
#include "GiveServerCommand.h"
|
||||
#include "ConsoleCommandSender.h"
|
||||
|
||||
#include "../../Minecraft.Client/MinecraftServer.h"
|
||||
#include "../../Minecraft.Client/ConsoleInputSource.h"
|
||||
#include "../../Minecraft.Client/PlayerList.h"
|
||||
#include "../../Minecraft.Client/ServerPlayer.h"
|
||||
#include "../../Minecraft.World/CommandDispatcher.h"
|
||||
#include "../../Minecraft.World/ByteArrayOutputStream.h"
|
||||
#include "../../Minecraft.World/DataOutputStream.h"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
void GiveServerCommand::execute(const wstring& args, ConsoleInputSource *src, MinecraftServer *server)
|
||||
{
|
||||
wstringstream ss(args);
|
||||
wstring playerName;
|
||||
int item = 0;
|
||||
int amount = 1;
|
||||
int aux = 0;
|
||||
|
||||
if (!(ss >> playerName >> item))
|
||||
{
|
||||
src->warn(L"\u00A7cUsage: /give <player> <item id> [amount] [data]");
|
||||
return;
|
||||
}
|
||||
|
||||
if (ss >> amount)
|
||||
{
|
||||
if (amount < 1 || amount > 64)
|
||||
{
|
||||
src->warn(L"\u00A7cItem amount must be between 1 and 64");
|
||||
return;
|
||||
}
|
||||
}
|
||||
ss >> aux;
|
||||
|
||||
PlayerList *players = server->getPlayers();
|
||||
shared_ptr<ServerPlayer> player = players->getPlayer(playerName);
|
||||
if (!player)
|
||||
{
|
||||
src->warn(L"\u00A7cThat player cannot be found");
|
||||
return;
|
||||
}
|
||||
|
||||
ByteArrayOutputStream baos;
|
||||
DataOutputStream dos(&baos);
|
||||
|
||||
dos.writePlayerUID(player->getXuid());
|
||||
dos.writeInt(item);
|
||||
dos.writeInt(amount);
|
||||
dos.writeInt(aux);
|
||||
dos.writeUTF(L"");
|
||||
|
||||
shared_ptr<ConsoleCommandSender> sender(new ConsoleCommandSender(src));
|
||||
CommandDispatcher *dispatcher = server->getCommandDispatcher();
|
||||
dispatcher->performCommand(sender, eGameCommand_Give, baos.toByteArray());
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
#include "ServerCommand.h"
|
||||
|
||||
class GiveServerCommand : public ServerCommand
|
||||
{
|
||||
public:
|
||||
wstring getName() { return L"give"; }
|
||||
wstring getUsage() { return L"/give <player> <item id> [amount] [data]"; }
|
||||
void execute(const wstring& args, ConsoleInputSource *src, MinecraftServer *server);
|
||||
};
|
||||
@@ -0,0 +1,73 @@
|
||||
#include "stdafx.h"
|
||||
#include "HelpCommand.h"
|
||||
#include "ConsoleCommandDispatcher.h"
|
||||
|
||||
#include "../../Minecraft.Client/ConsoleInputSource.h"
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
|
||||
HelpCommand::HelpCommand(ConsoleCommandDispatcher *dispatcher)
|
||||
: dispatcher(dispatcher)
|
||||
{
|
||||
}
|
||||
|
||||
void HelpCommand::execute(const wstring& args, ConsoleInputSource *src, MinecraftServer *server)
|
||||
{
|
||||
const map<wstring, ServerCommand *>& commandMap = dispatcher->getCommands();
|
||||
|
||||
vector<ServerCommand *> list;
|
||||
for (AUTO_VAR(it, commandMap.begin()); it != commandMap.end(); ++it)
|
||||
list.push_back(it->second);
|
||||
|
||||
sort(list.begin(), list.end(), [](ServerCommand *a, ServerCommand *b) {
|
||||
return a->getName() < b->getName();
|
||||
});
|
||||
|
||||
int itemsPerPage = 7;
|
||||
int totalPages = (int)list.size() / itemsPerPage;
|
||||
int page = 0;
|
||||
|
||||
wstringstream ss(args);
|
||||
wstring arg;
|
||||
if (ss >> arg)
|
||||
{
|
||||
wstringstream numTest(arg);
|
||||
int num;
|
||||
if (numTest >> num && numTest.eof())
|
||||
{
|
||||
if (num < 1) num = 1;
|
||||
if (num > totalPages + 1) num = totalPages + 1;
|
||||
page = num - 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (size_t i = 0; i < arg.size(); i++)
|
||||
arg[i] = towlower(arg[i]);
|
||||
|
||||
AUTO_VAR(it, commandMap.find(arg));
|
||||
if (it != commandMap.end())
|
||||
{
|
||||
src->info(L"\u00A7cUsage: " + it->second->getUsage());
|
||||
return;
|
||||
}
|
||||
|
||||
src->warn(L"\u00A7cUnknown command. Try /help for a list of commands");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
int endIndex = (int)list.size();
|
||||
if ((page + 1) * itemsPerPage < endIndex)
|
||||
endIndex = (page + 1) * itemsPerPage;
|
||||
|
||||
wchar_t buf[256];
|
||||
swprintf_s(buf, 256, L"\u00A72--- Showing help page %d of %d (/help <page>) ---", page + 1, totalPages + 1);
|
||||
src->info(wstring(buf));
|
||||
|
||||
for (int k = page * itemsPerPage; k < endIndex; k++)
|
||||
src->info(list[k]->getUsage());
|
||||
|
||||
if (page == 0)
|
||||
src->info(L"\u00A7aTip: Use the <tab> key while typing a command to auto-complete the command or its arguments");
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
|
||||
#include "ServerCommand.h"
|
||||
|
||||
class ConsoleCommandDispatcher;
|
||||
|
||||
class HelpCommand : public ServerCommand
|
||||
{
|
||||
private:
|
||||
ConsoleCommandDispatcher *dispatcher;
|
||||
|
||||
public:
|
||||
HelpCommand(ConsoleCommandDispatcher *dispatcher);
|
||||
|
||||
wstring getName() { return L"help"; }
|
||||
wstring getUsage() { return L"/help [page|command name]"; }
|
||||
void execute(const wstring& args, ConsoleInputSource *src, MinecraftServer *server);
|
||||
};
|
||||
@@ -0,0 +1,45 @@
|
||||
#include "stdafx.h"
|
||||
#include "KickServerCommand.h"
|
||||
#include "ServerCommand.h"
|
||||
|
||||
#include "../../Minecraft.Client/MinecraftServer.h"
|
||||
#include "../../Minecraft.Client/ConsoleInputSource.h"
|
||||
#include "../../Minecraft.Client/PlayerList.h"
|
||||
#include "../../Minecraft.Client/ServerPlayer.h"
|
||||
#include "../../Minecraft.Client/PlayerConnection.h"
|
||||
#include "../../Minecraft.World/DisconnectPacket.h"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
void KickServerCommand::execute(const wstring& args, ConsoleInputSource *src, MinecraftServer *server)
|
||||
{
|
||||
wstringstream ss(args);
|
||||
wstring playerName;
|
||||
|
||||
if (!(ss >> playerName))
|
||||
{
|
||||
src->warn(L"\u00A7cUsage: /kick <player> [reason ...]");
|
||||
return;
|
||||
}
|
||||
|
||||
PlayerList *players = server->getPlayers();
|
||||
shared_ptr<ServerPlayer> player = players->getPlayer(playerName);
|
||||
if (!player)
|
||||
{
|
||||
src->warn(L"\u00A7cThat player cannot be found");
|
||||
return;
|
||||
}
|
||||
|
||||
wstring reason;
|
||||
getline(ss, reason);
|
||||
size_t rstart = reason.find_first_not_of(L" \t");
|
||||
if (rstart != wstring::npos) reason = reason.substr(rstart);
|
||||
else reason.clear();
|
||||
|
||||
player->connection->disconnect(DisconnectPacket::eDisconnect_Kicked);
|
||||
|
||||
if (!reason.empty())
|
||||
ServerCommand::notifyAdmins(src, server, L"Kicked player " + player->name + L": " + reason);
|
||||
else
|
||||
ServerCommand::notifyAdmins(src, server, L"Kicked player " + player->name);
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
#include "ServerCommand.h"
|
||||
|
||||
class KickServerCommand : public ServerCommand
|
||||
{
|
||||
public:
|
||||
wstring getName() { return L"kick"; }
|
||||
wstring getUsage() { return L"/kick <player> [reason ...]"; }
|
||||
void execute(const wstring& args, ConsoleInputSource *src, MinecraftServer *server);
|
||||
};
|
||||
@@ -0,0 +1,33 @@
|
||||
#include "stdafx.h"
|
||||
#include "KillServerCommand.h"
|
||||
|
||||
#include "../../Minecraft.Client/MinecraftServer.h"
|
||||
#include "../../Minecraft.Client/ConsoleInputSource.h"
|
||||
#include "../../Minecraft.Client/PlayerList.h"
|
||||
#include "../../Minecraft.Client/ServerPlayer.h"
|
||||
#include "../../Minecraft.World/DamageSource.h"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
void KillServerCommand::execute(const wstring& args, ConsoleInputSource *src, MinecraftServer *server)
|
||||
{
|
||||
wstringstream ss(args);
|
||||
wstring playerName;
|
||||
|
||||
if (!(ss >> playerName))
|
||||
{
|
||||
src->warn(L"\u00A7cYou must specify which player you wish to perform this action on.");
|
||||
return;
|
||||
}
|
||||
|
||||
PlayerList *players = server->getPlayers();
|
||||
shared_ptr<ServerPlayer> player = players->getPlayer(playerName);
|
||||
if (!player)
|
||||
{
|
||||
src->warn(L"\u00A7cThat player cannot be found");
|
||||
return;
|
||||
}
|
||||
|
||||
player->hurt(DamageSource::outOfWorld, 1000);
|
||||
src->info(L"Ouch. That look like it hurt.");
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
#include "ServerCommand.h"
|
||||
|
||||
class KillServerCommand : public ServerCommand
|
||||
{
|
||||
public:
|
||||
wstring getName() { return L"kill"; }
|
||||
wstring getUsage() { return L"/kill <player>"; }
|
||||
void execute(const wstring& args, ConsoleInputSource *src, MinecraftServer *server);
|
||||
};
|
||||
@@ -0,0 +1,19 @@
|
||||
#include "stdafx.h"
|
||||
#include "ListServerCommand.h"
|
||||
|
||||
#include "../../Minecraft.Client/MinecraftServer.h"
|
||||
#include "../../Minecraft.Client/ConsoleInputSource.h"
|
||||
#include "../../Minecraft.Client/PlayerList.h"
|
||||
#include "../../Minecraft.Client/ServerPlayer.h"
|
||||
|
||||
void ListServerCommand::execute(const wstring& args, ConsoleInputSource *src, MinecraftServer *server)
|
||||
{
|
||||
PlayerList *playerList = server->getPlayers();
|
||||
int count = playerList->getPlayerCount();
|
||||
int max = playerList->getMaxPlayers();
|
||||
|
||||
wchar_t buf[128];
|
||||
swprintf_s(buf, 128, L"There are %d/%d players online:", count, max);
|
||||
src->info(wstring(buf));
|
||||
src->info(playerList->getPlayerNames());
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
#include "ServerCommand.h"
|
||||
|
||||
class ListServerCommand : public ServerCommand
|
||||
{
|
||||
public:
|
||||
wstring getName() { return L"list"; }
|
||||
wstring getUsage() { return L"/list"; }
|
||||
void execute(const wstring& args, ConsoleInputSource *src, MinecraftServer *server);
|
||||
};
|
||||
@@ -0,0 +1,18 @@
|
||||
#include "stdafx.h"
|
||||
#include "MeCommand.h"
|
||||
#include "../../Minecraft.Client/MinecraftServer.h"
|
||||
#include "../../Minecraft.Client/ConsoleInputSource.h"
|
||||
#include "../../Minecraft.Client/PlayerList.h"
|
||||
#include "../../Minecraft.World/ChatPacket.h"
|
||||
|
||||
void MeCommand::execute(const wstring& args, ConsoleInputSource *src, MinecraftServer *server)
|
||||
{
|
||||
if (args.empty())
|
||||
{
|
||||
src->warn(L"Usage: /me <action ...>");
|
||||
return;
|
||||
}
|
||||
wstring msg = L"* Server " + args;
|
||||
server->getPlayers()->broadcastAll(shared_ptr<Packet>(new ChatPacket(msg)));
|
||||
src->info(msg);
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
#pragma once
|
||||
#include "ServerCommand.h"
|
||||
|
||||
class MeCommand : public ServerCommand
|
||||
{
|
||||
public:
|
||||
wstring getName() { return L"me"; }
|
||||
wstring getUsage() { return L"/me <action ...> - Performs the specified action"; }
|
||||
void execute(const wstring& args, ConsoleInputSource *src, MinecraftServer *server);
|
||||
};
|
||||
@@ -0,0 +1,41 @@
|
||||
#include "stdafx.h"
|
||||
#include "OpCommand.h"
|
||||
#include "ServerCommand.h"
|
||||
#include "../../Minecraft.Client/ConsoleInputSource.h"
|
||||
#include "../../Minecraft.Client/MinecraftServer.h"
|
||||
#include "../../Minecraft.Client/PlayerList.h"
|
||||
#include "../../Minecraft.Client/ServerPlayer.h"
|
||||
#include "../../Minecraft.World/net.minecraft.network.packet.h"
|
||||
#include "../Core/ServerLists.h"
|
||||
#include "ServerTextList.h"
|
||||
|
||||
void OpCommand::execute(const wstring& args, ConsoleInputSource *src, MinecraftServer *server)
|
||||
{
|
||||
wstring name = args;
|
||||
size_t start = name.find_first_not_of(L" \t");
|
||||
if (start == wstring::npos || name.empty())
|
||||
{
|
||||
src->warn(L"Usage: /op <player>");
|
||||
return;
|
||||
}
|
||||
name = name.substr(start);
|
||||
size_t end = name.find_first_of(L" \t");
|
||||
if (end != wstring::npos)
|
||||
name = name.substr(0, end);
|
||||
|
||||
ServerLists_GetOps()->add(name);
|
||||
|
||||
shared_ptr<ServerPlayer> player = server->getPlayers()->getPlayer(name);
|
||||
if (player != nullptr)
|
||||
{
|
||||
player->setPlayerGamePrivilege(Player::ePlayerGamePrivilege_Op, 1); // idfk if this works
|
||||
server->getPlayers()->broadcastAll(shared_ptr<PlayerInfoPacket>(new PlayerInfoPacket(player)));
|
||||
}
|
||||
|
||||
ServerCommand::notifyAdmins(src, server, L"Opped " + name);
|
||||
}
|
||||
|
||||
bool IsPlayerOp(const wstring& name)
|
||||
{
|
||||
return ServerLists_IsPlayerOp(name);
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
#pragma once
|
||||
#include "ServerCommand.h"
|
||||
|
||||
class OpCommand : public ServerCommand
|
||||
{
|
||||
public:
|
||||
wstring getName() { return L"op"; }
|
||||
wstring getUsage() { return L"/op <player> - Grants operator status to a player"; }
|
||||
void execute(const wstring& args, ConsoleInputSource *src, MinecraftServer *server);
|
||||
};
|
||||
@@ -0,0 +1,23 @@
|
||||
#include "stdafx.h"
|
||||
#include "PardonCommand.h"
|
||||
#include "ServerCommand.h"
|
||||
#include "../../Minecraft.Client/ConsoleInputSource.h"
|
||||
#include "../../Minecraft.Client/MinecraftServer.h"
|
||||
#include "../Core/ServerLists.h"
|
||||
#include "ServerTextList.h"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
void PardonCommand::execute(const wstring& args, ConsoleInputSource *src, MinecraftServer *server)
|
||||
{
|
||||
wstringstream ss(args);
|
||||
wstring playerName;
|
||||
if (!(ss >> playerName))
|
||||
{
|
||||
src->warn(L"Usage: /pardon <player>");
|
||||
return;
|
||||
}
|
||||
|
||||
ServerLists_GetBannedPlayers()->remove(playerName);
|
||||
ServerCommand::notifyAdmins(src, server, L"Unbanned player " + playerName);
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
#pragma once
|
||||
#include "ServerCommand.h"
|
||||
|
||||
class PardonCommand : public ServerCommand
|
||||
{
|
||||
public:
|
||||
wstring getName() { return L"pardon"; }
|
||||
wstring getUsage() { return L"/pardon <player> - Unbans a player"; }
|
||||
void execute(const wstring& args, ConsoleInputSource *src, MinecraftServer *server);
|
||||
};
|
||||
@@ -0,0 +1,23 @@
|
||||
#include "stdafx.h"
|
||||
#include "PardonIpCommand.h"
|
||||
#include "ServerCommand.h"
|
||||
#include "../../Minecraft.Client/ConsoleInputSource.h"
|
||||
#include "../../Minecraft.Client/MinecraftServer.h"
|
||||
#include "../Core/ServerLists.h"
|
||||
#include "ServerTextList.h"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
void PardonIpCommand::execute(const wstring& args, ConsoleInputSource *src, MinecraftServer *server)
|
||||
{
|
||||
wstringstream ss(args);
|
||||
wstring ip;
|
||||
if (!(ss >> ip))
|
||||
{
|
||||
src->warn(L"Usage: /pardon-ip <ip>");
|
||||
return;
|
||||
}
|
||||
|
||||
ServerLists_GetBannedIPs()->remove(ip);
|
||||
ServerCommand::notifyAdmins(src, server, L"Unbanned IP address " + ip);
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
#pragma once
|
||||
#include "ServerCommand.h"
|
||||
|
||||
class PardonIpCommand : public ServerCommand
|
||||
{
|
||||
public:
|
||||
wstring getName() { return L"pardon-ip"; }
|
||||
wstring getUsage() { return L"/pardon-ip <ip> - Unbans an IP address"; }
|
||||
void execute(const wstring& args, ConsoleInputSource *src, MinecraftServer *server);
|
||||
};
|
||||
@@ -0,0 +1,22 @@
|
||||
#include "stdafx.h"
|
||||
#include "SaveAllCommand.h"
|
||||
#include "ServerCommand.h"
|
||||
#include "../../Minecraft.Client/MinecraftServer.h"
|
||||
#include "../../Minecraft.Client/ConsoleInputSource.h"
|
||||
#include "../../Minecraft.Client/PlayerList.h"
|
||||
#include "../../Minecraft.Client/ServerLevel.h"
|
||||
|
||||
void SaveAllCommand::execute(const wstring& args, ConsoleInputSource *src, MinecraftServer *server)
|
||||
{
|
||||
ServerCommand::notifyAdmins(src, server, L"Forcing save..");
|
||||
PlayerList *players = server->getPlayers();
|
||||
if (players)
|
||||
players->saveAll(NULL);
|
||||
for (unsigned int i = 0; i < server->levels.length; i++)
|
||||
{
|
||||
ServerLevel *level = server->levels[i];
|
||||
if (level)
|
||||
level->save(true, NULL);
|
||||
}
|
||||
ServerCommand::notifyAdmins(src, server, L"Save complete.");
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
#pragma once
|
||||
#include "ServerCommand.h"
|
||||
|
||||
class SaveAllCommand : public ServerCommand
|
||||
{
|
||||
public:
|
||||
wstring getName() { return L"save-all"; }
|
||||
wstring getUsage() { return L"/save-all - Forces the server to save"; }
|
||||
void execute(const wstring& args, ConsoleInputSource *src, MinecraftServer *server);
|
||||
};
|
||||
@@ -0,0 +1,17 @@
|
||||
#include "stdafx.h"
|
||||
#include "SaveOffCommand.h"
|
||||
#include "ServerCommand.h"
|
||||
#include "../../Minecraft.Client/MinecraftServer.h"
|
||||
#include "../../Minecraft.Client/ConsoleInputSource.h"
|
||||
#include "../../Minecraft.Client/ServerLevel.h"
|
||||
|
||||
void SaveOffCommand::execute(const wstring& args, ConsoleInputSource *src, MinecraftServer *server)
|
||||
{
|
||||
for (unsigned int i = 0; i < server->levels.length; i++)
|
||||
{
|
||||
ServerLevel *level = server->levels[i];
|
||||
if (level)
|
||||
level->noSave = true;
|
||||
}
|
||||
ServerCommand::notifyAdmins(src, server, L"Turned off world auto-saving");
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
#pragma once
|
||||
#include "ServerCommand.h"
|
||||
|
||||
class SaveOffCommand : public ServerCommand
|
||||
{
|
||||
public:
|
||||
wstring getName() { return L"save-off"; }
|
||||
wstring getUsage() { return L"/save-off - Disables automatic server saves"; }
|
||||
void execute(const wstring& args, ConsoleInputSource *src, MinecraftServer *server);
|
||||
};
|
||||
@@ -0,0 +1,17 @@
|
||||
#include "stdafx.h"
|
||||
#include "SaveOnCommand.h"
|
||||
#include "ServerCommand.h"
|
||||
#include "../../Minecraft.Client/MinecraftServer.h"
|
||||
#include "../../Minecraft.Client/ConsoleInputSource.h"
|
||||
#include "../../Minecraft.Client/ServerLevel.h"
|
||||
|
||||
void SaveOnCommand::execute(const wstring& args, ConsoleInputSource *src, MinecraftServer *server)
|
||||
{
|
||||
for (unsigned int i = 0; i < server->levels.length; i++)
|
||||
{
|
||||
ServerLevel *level = server->levels[i];
|
||||
if (level)
|
||||
level->noSave = false;
|
||||
}
|
||||
ServerCommand::notifyAdmins(src, server, L"Turned on world auto-saving");
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
#pragma once
|
||||
#include "ServerCommand.h"
|
||||
|
||||
class SaveOnCommand : public ServerCommand
|
||||
{
|
||||
public:
|
||||
wstring getName() { return L"save-on"; }
|
||||
wstring getUsage() { return L"/save-on - Enables automatic server saves"; }
|
||||
void execute(const wstring& args, ConsoleInputSource *src, MinecraftServer *server);
|
||||
};
|
||||
@@ -0,0 +1,18 @@
|
||||
#include "stdafx.h"
|
||||
#include "SayCommand.h"
|
||||
#include "../../Minecraft.Client/MinecraftServer.h"
|
||||
#include "../../Minecraft.Client/ConsoleInputSource.h"
|
||||
#include "../../Minecraft.Client/PlayerList.h"
|
||||
#include "../../Minecraft.World/ChatPacket.h"
|
||||
|
||||
void SayCommand::execute(const wstring& args, ConsoleInputSource *src, MinecraftServer *server)
|
||||
{
|
||||
if (args.empty())
|
||||
{
|
||||
src->warn(L"Usage: /say <message ...>");
|
||||
return;
|
||||
}
|
||||
wstring msg = L"[Server] " + args;
|
||||
server->getPlayers()->broadcastAll(shared_ptr<Packet>(new ChatPacket(msg)));
|
||||
src->info(L"\u00A7d[Server] " + args);
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
#pragma once
|
||||
#include "ServerCommand.h"
|
||||
|
||||
class SayCommand : public ServerCommand
|
||||
{
|
||||
public:
|
||||
wstring getName() { return L"say"; }
|
||||
wstring getUsage() { return L"/say <message ...> - Broadcasts a message to all players"; }
|
||||
void execute(const wstring& args, ConsoleInputSource *src, MinecraftServer *server);
|
||||
};
|
||||
@@ -0,0 +1,14 @@
|
||||
#include "stdafx.h"
|
||||
#include "SeedCommand.h"
|
||||
#include "../../Minecraft.Client/MinecraftServer.h"
|
||||
#include "../../Minecraft.Client/ConsoleInputSource.h"
|
||||
#include "../../Minecraft.Client/ServerLevel.h"
|
||||
#include "../../Minecraft.World/Level.h"
|
||||
|
||||
void SeedCommand::execute(const wstring& args, ConsoleInputSource *src, MinecraftServer *server)
|
||||
{
|
||||
__int64 seed = server->getLevel(0)->getSeed();
|
||||
wchar_t buf[64];
|
||||
swprintf_s(buf, 64, L"Seed: %lld", seed);
|
||||
src->info(wstring(buf));
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
#pragma once
|
||||
#include "ServerCommand.h"
|
||||
|
||||
class SeedCommand : public ServerCommand
|
||||
{
|
||||
public:
|
||||
wstring getName() { return L"seed"; }
|
||||
wstring getUsage() { return L"/seed - Displays the world seed"; }
|
||||
void execute(const wstring& args, ConsoleInputSource *src, MinecraftServer *server);
|
||||
};
|
||||
@@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
class MinecraftServer;
|
||||
class ConsoleInputSource;
|
||||
|
||||
class ServerCommand
|
||||
{
|
||||
public:
|
||||
virtual ~ServerCommand() {}
|
||||
virtual wstring getName() = 0;
|
||||
virtual wstring getUsage() = 0;
|
||||
virtual void execute(const wstring& args, ConsoleInputSource *src, MinecraftServer *server) = 0;
|
||||
|
||||
static void notifyAdmins(ConsoleInputSource *src, MinecraftServer *server, const wstring& message);
|
||||
};
|
||||
@@ -0,0 +1,186 @@
|
||||
#include "stdafx.h"
|
||||
#include "ServerCommands.h"
|
||||
#include "ConsoleCommandDispatcher.h"
|
||||
#include "../../Minecraft.Client/PlayerList.h"
|
||||
#include "../../Minecraft.Client/MinecraftServer.h"
|
||||
#include "../../Minecraft.Client/ServerPlayer.h"
|
||||
|
||||
#include "StopCommand.h"
|
||||
#include "HelpCommand.h"
|
||||
#include "TpCommand.h"
|
||||
#include "TimeServerCommand.h"
|
||||
#include "ToggleDownfallServerCommand.h"
|
||||
#include "GiveServerCommand.h"
|
||||
#include "EnchantServerCommand.h"
|
||||
#include "KillServerCommand.h"
|
||||
#include "GameModeServerCommand.h"
|
||||
#include "ListServerCommand.h"
|
||||
#include "KickServerCommand.h"
|
||||
#include "SayCommand.h"
|
||||
#include "MeCommand.h"
|
||||
#include "SeedCommand.h"
|
||||
#include "XpCommand.h"
|
||||
#include "DefaultGameModeCommand.h"
|
||||
#include "SaveAllCommand.h"
|
||||
#include "SaveOffCommand.h"
|
||||
#include "SaveOnCommand.h"
|
||||
#include "DebugCommand.h"
|
||||
#include "OpCommand.h"
|
||||
#include "DeOpCommand.h"
|
||||
#include "BanCommand.h"
|
||||
#include "PardonCommand.h"
|
||||
#include "BanIpCommand.h"
|
||||
#include "PardonIpCommand.h"
|
||||
#include "BanListCommand.h"
|
||||
#include "WhitelistCommand.h"
|
||||
|
||||
#include "../../Minecraft.Client/ConsoleInputSource.h"
|
||||
|
||||
void ServerCommand::notifyAdmins(ConsoleInputSource *src, MinecraftServer *server, const wstring& message)
|
||||
{
|
||||
src->info(message);
|
||||
if (server && server->getPlayers())
|
||||
server->getPlayers()->broadcastToAllOps(L"\u00A77\u00A7o[" + src->getConsoleName() + L": " + message + L"]");
|
||||
}
|
||||
|
||||
static ConsoleCommandDispatcher *s_dispatcher = NULL;
|
||||
|
||||
ConsoleCommandDispatcher *CreateConsoleCommandDispatcher()
|
||||
{
|
||||
ConsoleCommandDispatcher *dispatcher = new ConsoleCommandDispatcher();
|
||||
|
||||
dispatcher->addCommand(new StopCommand());
|
||||
dispatcher->addCommand(new TpCommand());
|
||||
|
||||
dispatcher->addCommand(new TimeServerCommand());
|
||||
dispatcher->addCommand(new ToggleDownfallServerCommand());
|
||||
dispatcher->addCommand(new GiveServerCommand());
|
||||
dispatcher->addCommand(new EnchantServerCommand());
|
||||
dispatcher->addCommand(new KillServerCommand());
|
||||
dispatcher->addCommand(new GameModeServerCommand());
|
||||
dispatcher->addCommand(new ListServerCommand());
|
||||
dispatcher->addCommand(new KickServerCommand());
|
||||
dispatcher->addCommand(new SayCommand());
|
||||
dispatcher->addCommand(new MeCommand());
|
||||
dispatcher->addCommand(new SeedCommand());
|
||||
dispatcher->addCommand(new XpCommand());
|
||||
dispatcher->addCommand(new DefaultGameModeCommand());
|
||||
dispatcher->addCommand(new SaveAllCommand());
|
||||
dispatcher->addCommand(new SaveOffCommand());
|
||||
dispatcher->addCommand(new SaveOnCommand());
|
||||
dispatcher->addCommand(new DebugCommand());
|
||||
dispatcher->addCommand(new OpCommand());
|
||||
dispatcher->addCommand(new DeOpCommand());
|
||||
dispatcher->addCommand(new BanCommand());
|
||||
dispatcher->addCommand(new PardonCommand());
|
||||
dispatcher->addCommand(new BanIpCommand());
|
||||
dispatcher->addCommand(new PardonIpCommand());
|
||||
dispatcher->addCommand(new BanListCommand());
|
||||
dispatcher->addCommand(new WhitelistCommand());
|
||||
|
||||
dispatcher->addCommand(new HelpCommand(dispatcher));
|
||||
|
||||
return dispatcher;
|
||||
}
|
||||
|
||||
bool HandleServerCommand(const wstring& rawCmd, ConsoleInputSource *src, MinecraftServer *server)
|
||||
{
|
||||
wstring cmd = rawCmd;
|
||||
|
||||
size_t start = cmd.find_first_not_of(L" \t");
|
||||
if (start == wstring::npos) return false;
|
||||
cmd = cmd.substr(start);
|
||||
size_t end = cmd.find_last_not_of(L" \t");
|
||||
if (end != wstring::npos) cmd = cmd.substr(0, end + 1);
|
||||
|
||||
if (!cmd.empty() && cmd[0] == L'/') cmd = cmd.substr(1);
|
||||
if (cmd.empty()) return false;
|
||||
|
||||
wstring cmdName;
|
||||
wstring cmdArgs;
|
||||
size_t spacePos = cmd.find(L' ');
|
||||
if (spacePos != wstring::npos)
|
||||
{
|
||||
cmdName = cmd.substr(0, spacePos);
|
||||
cmdArgs = cmd.substr(spacePos + 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
cmdName = cmd;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < cmdName.size(); i++)
|
||||
cmdName[i] = towlower(cmdName[i]);
|
||||
|
||||
if (!s_dispatcher)
|
||||
s_dispatcher = CreateConsoleCommandDispatcher();
|
||||
|
||||
if (cmdName == L"?")
|
||||
cmdName = L"help";
|
||||
|
||||
if (!s_dispatcher->performCommand(cmdName, cmdArgs, src, server))
|
||||
{
|
||||
src->warn(L"Unknown command: " + cmdName + L". Type \"help\" for help.");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
vector<wstring> GetServerCommandCompletions(const wstring& input, MinecraftServer *server)
|
||||
{
|
||||
vector<wstring> results;
|
||||
|
||||
if (!s_dispatcher)
|
||||
s_dispatcher = CreateConsoleCommandDispatcher();
|
||||
|
||||
wstring trimmed = input;
|
||||
if (!trimmed.empty() && trimmed[0] == L'/')
|
||||
trimmed = trimmed.substr(1);
|
||||
|
||||
size_t spacePos = trimmed.find(L' ');
|
||||
|
||||
if (spacePos == wstring::npos)
|
||||
{
|
||||
wstring partial = trimmed;
|
||||
for (size_t i = 0; i < partial.size(); i++)
|
||||
partial[i] = towlower(partial[i]);
|
||||
|
||||
const map<wstring, ServerCommand *>& cmds = s_dispatcher->getCommands();
|
||||
for (map<wstring, ServerCommand *>::const_iterator it = cmds.begin(); it != cmds.end(); ++it)
|
||||
{
|
||||
if (it->first.find(partial) == 0)
|
||||
results.push_back(it->first);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
wstring lastWord;
|
||||
size_t lastSpacePos = trimmed.find_last_of(L' ');
|
||||
if (lastSpacePos != wstring::npos && lastSpacePos + 1 < trimmed.size())
|
||||
lastWord = trimmed.substr(lastSpacePos + 1);
|
||||
|
||||
wstring partialLower = lastWord;
|
||||
for (size_t i = 0; i < partialLower.size(); i++)
|
||||
partialLower[i] = towlower(partialLower[i]);
|
||||
|
||||
if (server)
|
||||
{
|
||||
PlayerList *playerList = server->getPlayers();
|
||||
if (playerList)
|
||||
{
|
||||
for (size_t i = 0; i < playerList->players.size(); i++)
|
||||
{
|
||||
wstring pname = playerList->players[i]->name;
|
||||
wstring pnameLower = pname;
|
||||
for (size_t j = 0; j < pnameLower.size(); j++)
|
||||
pnameLower[j] = towlower(pnameLower[j]);
|
||||
|
||||
if (pnameLower.find(partialLower) == 0)
|
||||
results.push_back(pname);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
|
||||
class MinecraftServer;
|
||||
class ConsoleInputSource;
|
||||
class ConsoleCommandDispatcher;
|
||||
|
||||
ConsoleCommandDispatcher *CreateConsoleCommandDispatcher();
|
||||
bool HandleServerCommand(const wstring& cmd, ConsoleInputSource *src, MinecraftServer *server);
|
||||
vector<wstring> GetServerCommandCompletions(const wstring& input, MinecraftServer *server);
|
||||
@@ -0,0 +1,67 @@
|
||||
#pragma once
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include <fstream>
|
||||
|
||||
class ServerTextList
|
||||
{
|
||||
private:
|
||||
std::wstring filename;
|
||||
std::set<std::wstring> entries;
|
||||
|
||||
public:
|
||||
ServerTextList(const std::wstring& filename) : filename(filename) { load(); }
|
||||
|
||||
void load()
|
||||
{
|
||||
entries.clear();
|
||||
std::wifstream file(
|
||||
#ifdef __linux__
|
||||
std::string(filename.begin(), filename.end()).c_str()
|
||||
#else
|
||||
filename.c_str()
|
||||
#endif
|
||||
);
|
||||
if (!file.is_open()) return;
|
||||
std::wstring line;
|
||||
while (std::getline(file, line))
|
||||
{
|
||||
if (!line.empty())
|
||||
entries.insert(line);
|
||||
}
|
||||
}
|
||||
|
||||
void save()
|
||||
{
|
||||
std::wofstream file(
|
||||
#ifdef __linux__
|
||||
std::string(filename.begin(), filename.end()).c_str()
|
||||
#else
|
||||
filename.c_str()
|
||||
#endif
|
||||
);
|
||||
if (!file.is_open()) return;
|
||||
for (std::set<std::wstring>::const_iterator it = entries.begin(); it != entries.end(); ++it)
|
||||
file << *it << L"\n";
|
||||
}
|
||||
|
||||
bool contains(const std::wstring& entry) const
|
||||
{
|
||||
return entries.find(entry) != entries.end();
|
||||
}
|
||||
|
||||
void add(const std::wstring& entry)
|
||||
{
|
||||
entries.insert(entry);
|
||||
save();
|
||||
}
|
||||
|
||||
void remove(const std::wstring& entry)
|
||||
{
|
||||
entries.erase(entry);
|
||||
save();
|
||||
}
|
||||
|
||||
const std::set<std::wstring>& getEntries() const { return entries; }
|
||||
int size() const { return (int)entries.size(); }
|
||||
};
|
||||
@@ -0,0 +1,12 @@
|
||||
#include "stdafx.h"
|
||||
#include "StopCommand.h"
|
||||
#include "ServerCommand.h"
|
||||
|
||||
#include "../../Minecraft.Client/MinecraftServer.h"
|
||||
#include "../../Minecraft.Client/ConsoleInputSource.h"
|
||||
|
||||
void StopCommand::execute(const wstring& args, ConsoleInputSource *src, MinecraftServer *server)
|
||||
{
|
||||
ServerCommand::notifyAdmins(src, server, L"Stopping the server");
|
||||
MinecraftServer::HaltServer();
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
#include "ServerCommand.h"
|
||||
|
||||
class StopCommand : public ServerCommand
|
||||
{
|
||||
public:
|
||||
wstring getName() { return L"stop"; }
|
||||
wstring getUsage() { return L"/stop"; }
|
||||
void execute(const wstring& args, ConsoleInputSource *src, MinecraftServer *server);
|
||||
};
|
||||
@@ -0,0 +1,93 @@
|
||||
#include "stdafx.h"
|
||||
#include "TimeServerCommand.h"
|
||||
#include "ServerCommand.h"
|
||||
#include "ConsoleCommandSender.h"
|
||||
|
||||
#include "../../Minecraft.Client/MinecraftServer.h"
|
||||
#include "../../Minecraft.Client/ServerLevel.h"
|
||||
#include "../../Minecraft.Client/ConsoleInputSource.h"
|
||||
#include "../../Minecraft.World/GameCommandPacket.h"
|
||||
#include "../../Minecraft.World/TimeCommand.h"
|
||||
#include "../../Minecraft.World/ByteArrayOutputStream.h"
|
||||
#include "../../Minecraft.World/DataOutputStream.h"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
void TimeServerCommand::execute(const wstring& args, ConsoleInputSource *src, MinecraftServer *server)
|
||||
{
|
||||
wstringstream ss(args);
|
||||
wstring subCmd;
|
||||
if (!(ss >> subCmd))
|
||||
{
|
||||
src->warn(L"\u00A7cUsage: /time <set|add> <value>");
|
||||
return;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < subCmd.size(); i++)
|
||||
subCmd[i] = towlower(subCmd[i]);
|
||||
|
||||
if (subCmd == L"set")
|
||||
{
|
||||
wstring valueStr;
|
||||
if (!(ss >> valueStr))
|
||||
{
|
||||
src->warn(L"\u00A7cUsage: /time <set|add> <value>");
|
||||
return;
|
||||
}
|
||||
|
||||
int value;
|
||||
if (valueStr == L"day")
|
||||
value = 0;
|
||||
else if (valueStr == L"night")
|
||||
value = 12500;
|
||||
else
|
||||
{
|
||||
value = _wtoi(valueStr.c_str());
|
||||
if (value < 0)
|
||||
{
|
||||
wchar_t errBuf[256];
|
||||
swprintf_s(errBuf, 256, L"\u00A7cThe number you have entered (%d) is too small, it must be at least 0", value);
|
||||
src->warn(wstring(errBuf));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < (int)server->levels.length; i++)
|
||||
server->levels[i]->setTimeAndAdjustTileTicks(value);
|
||||
|
||||
wchar_t buf[128];
|
||||
swprintf_s(buf, 128, L"Set the time to %d", value);
|
||||
ServerCommand::notifyAdmins(src, server, wstring(buf));
|
||||
}
|
||||
else if (subCmd == L"add")
|
||||
{
|
||||
wstring valueStr;
|
||||
if (!(ss >> valueStr))
|
||||
{
|
||||
src->warn(L"\u00A7cUsage: /time <set|add> <value>");
|
||||
return;
|
||||
}
|
||||
int value = _wtoi(valueStr.c_str());
|
||||
if (value < 0)
|
||||
{
|
||||
wchar_t errBuf[256];
|
||||
swprintf_s(errBuf, 256, L"\u00A7cThe number you have entered (%d) is too small, it must be at least 0", value);
|
||||
src->warn(wstring(errBuf));
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; i < (int)server->levels.length; i++)
|
||||
{
|
||||
ServerLevel *level = server->levels[i];
|
||||
level->setTimeAndAdjustTileTicks(level->getTime() + value);
|
||||
}
|
||||
|
||||
wchar_t buf[128];
|
||||
swprintf_s(buf, 128, L"Added %d to the time", value);
|
||||
ServerCommand::notifyAdmins(src, server, wstring(buf));
|
||||
}
|
||||
else
|
||||
{
|
||||
src->warn(L"\u00A7cUsage: /time <set|add> <value>");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
#include "ServerCommand.h"
|
||||
|
||||
class TimeServerCommand : public ServerCommand
|
||||
{
|
||||
public:
|
||||
wstring getName() { return L"time"; }
|
||||
wstring getUsage() { return L"/time <set|add> <value>"; }
|
||||
void execute(const wstring& args, ConsoleInputSource *src, MinecraftServer *server);
|
||||
};
|
||||
@@ -0,0 +1,17 @@
|
||||
#include "stdafx.h"
|
||||
#include "ToggleDownfallServerCommand.h"
|
||||
#include "ServerCommand.h"
|
||||
#include "ConsoleCommandSender.h"
|
||||
|
||||
#include "../../Minecraft.Client/MinecraftServer.h"
|
||||
#include "../../Minecraft.Client/ConsoleInputSource.h"
|
||||
#include "../../Minecraft.World/CommandDispatcher.h"
|
||||
#include "../../Minecraft.World/ByteArrayOutputStream.h"
|
||||
|
||||
void ToggleDownfallServerCommand::execute(const wstring& args, ConsoleInputSource *src, MinecraftServer *server)
|
||||
{
|
||||
shared_ptr<ConsoleCommandSender> sender(new ConsoleCommandSender(src));
|
||||
CommandDispatcher *dispatcher = server->getCommandDispatcher();
|
||||
dispatcher->performCommand(sender, eGameCommand_ToggleDownfall, byteArray());
|
||||
ServerCommand::notifyAdmins(src, server, L"Toggled downfall");
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
#include "ServerCommand.h"
|
||||
|
||||
class ToggleDownfallServerCommand : public ServerCommand
|
||||
{
|
||||
public:
|
||||
wstring getName() { return L"toggledownfall"; }
|
||||
wstring getUsage() { return L"/toggledownfall"; }
|
||||
void execute(const wstring& args, ConsoleInputSource *src, MinecraftServer *server);
|
||||
};
|
||||
@@ -0,0 +1,67 @@
|
||||
#include "stdafx.h"
|
||||
#include "TpCommand.h"
|
||||
#include "ServerCommand.h"
|
||||
|
||||
#include "../../Minecraft.Client/MinecraftServer.h"
|
||||
#include "../../Minecraft.Client/ConsoleInputSource.h"
|
||||
#include "../../Minecraft.Client/PlayerList.h"
|
||||
#include "../../Minecraft.Client/ServerPlayer.h"
|
||||
#include "../../Minecraft.Client/PlayerConnection.h"
|
||||
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
|
||||
void TpCommand::execute(const wstring& args, ConsoleInputSource *src, MinecraftServer *server)
|
||||
{
|
||||
wstringstream ss(args);
|
||||
vector<wstring> tokens;
|
||||
wstring token;
|
||||
while (ss >> token)
|
||||
tokens.push_back(token);
|
||||
|
||||
PlayerList *players = server->getPlayers();
|
||||
|
||||
if (tokens.size() == 2)
|
||||
{
|
||||
shared_ptr<ServerPlayer> subject = players->getPlayer(tokens[0]);
|
||||
if (!subject)
|
||||
{
|
||||
src->warn(L"\u00A7cThat player cannot be found");
|
||||
return;
|
||||
}
|
||||
shared_ptr<ServerPlayer> dest = players->getPlayer(tokens[1]);
|
||||
if (!dest)
|
||||
{
|
||||
src->warn(L"\u00A7cThat player cannot be found");
|
||||
return;
|
||||
}
|
||||
subject->moveTo(dest->x, dest->y, dest->z, dest->yRot, dest->xRot);
|
||||
if (subject->connection)
|
||||
subject->connection->teleport(dest->x, dest->y, dest->z, dest->yRot, dest->xRot);
|
||||
wchar_t buf[256];
|
||||
swprintf_s(buf, 256, L"Teleported %s to %s", subject->name.c_str(), dest->name.c_str());
|
||||
ServerCommand::notifyAdmins(src, server, wstring(buf));
|
||||
}
|
||||
else if (tokens.size() == 4)
|
||||
{
|
||||
shared_ptr<ServerPlayer> subject = players->getPlayer(tokens[0]);
|
||||
if (!subject)
|
||||
{
|
||||
src->warn(L"\u00A7cThat player cannot be found");
|
||||
return;
|
||||
}
|
||||
int x = _wtoi(tokens[1].c_str());
|
||||
int y = _wtoi(tokens[2].c_str());
|
||||
int z = _wtoi(tokens[3].c_str());
|
||||
subject->moveTo(x + 0.5, (double)y, z + 0.5, subject->yRot, subject->xRot);
|
||||
if (subject->connection)
|
||||
subject->connection->teleport(x + 0.5, (double)y, z + 0.5, subject->yRot, subject->xRot);
|
||||
wchar_t buf[256];
|
||||
swprintf_s(buf, 256, L"Teleported %s to %d, %d, %d", subject->name.c_str(), x, y, z);
|
||||
ServerCommand::notifyAdmins(src, server, wstring(buf));
|
||||
}
|
||||
else
|
||||
{
|
||||
src->warn(L"\u00A7cUsage: /tp [player] <x> <y> <z> OR /tp [player] <player>");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
#include "ServerCommand.h"
|
||||
|
||||
class TpCommand : public ServerCommand
|
||||
{
|
||||
public:
|
||||
wstring getName() { return L"tp"; }
|
||||
wstring getUsage() { return L"/tp [player] <x> <y> <z> OR /tp [player] <player>"; }
|
||||
void execute(const wstring& args, ConsoleInputSource *src, MinecraftServer *server);
|
||||
};
|
||||
@@ -0,0 +1,84 @@
|
||||
#include "stdafx.h"
|
||||
#include "WhitelistCommand.h"
|
||||
#include "ServerCommand.h"
|
||||
#include "ServerTextList.h"
|
||||
#include "../../Minecraft.Client/ConsoleInputSource.h"
|
||||
#include "../../Minecraft.Client/MinecraftServer.h"
|
||||
#include "../Core/ServerLists.h"
|
||||
#include "ServerTextList.h"
|
||||
|
||||
#include <sstream>
|
||||
#include <cwctype>
|
||||
|
||||
void WhitelistCommand::execute(const wstring& args, ConsoleInputSource *src, MinecraftServer *server)
|
||||
{
|
||||
wstringstream ss(args);
|
||||
wstring subCmd;
|
||||
if (!(ss >> subCmd))
|
||||
{
|
||||
src->warn(L"Usage: /whitelist <on|off|list|add|remove|reload>");
|
||||
return;
|
||||
}
|
||||
|
||||
if (subCmd == L"on")
|
||||
{
|
||||
ServerLists_SetWhitelistEnabled(true);
|
||||
ServerCommand::notifyAdmins(src, server, L"Turned on the whitelist");
|
||||
}
|
||||
else if (subCmd == L"off")
|
||||
{
|
||||
ServerLists_SetWhitelistEnabled(false);
|
||||
ServerCommand::notifyAdmins(src, server, L"Turned off the whitelist");
|
||||
}
|
||||
else if (subCmd == L"list")
|
||||
{
|
||||
const set<wstring>& entries = ServerLists_GetWhitelist()->getEntries();
|
||||
wchar_t buf[128];
|
||||
swprintf_s(buf, 128, L"There are %d whitelisted players:", (int)entries.size());
|
||||
src->info(wstring(buf));
|
||||
wstring list;
|
||||
for (set<wstring>::const_iterator it = entries.begin(); it != entries.end(); ++it)
|
||||
{
|
||||
if (!list.empty()) list += L", ";
|
||||
list += *it;
|
||||
}
|
||||
if (!list.empty()) src->info(list);
|
||||
}
|
||||
else if (subCmd == L"add")
|
||||
{
|
||||
wstring playerName;
|
||||
if (!(ss >> playerName))
|
||||
{
|
||||
src->warn(L"Usage: /whitelist add <player>");
|
||||
return;
|
||||
}
|
||||
wstring lower = playerName;
|
||||
for (size_t i = 0; i < lower.size(); i++)
|
||||
lower[i] = towlower(lower[i]);
|
||||
ServerLists_GetWhitelist()->add(lower);
|
||||
ServerCommand::notifyAdmins(src, server, L"Added " + playerName + L" to the whitelist");
|
||||
}
|
||||
else if (subCmd == L"remove")
|
||||
{
|
||||
wstring playerName;
|
||||
if (!(ss >> playerName))
|
||||
{
|
||||
src->warn(L"Usage: /whitelist remove <player>");
|
||||
return;
|
||||
}
|
||||
wstring lower = playerName;
|
||||
for (size_t i = 0; i < lower.size(); i++)
|
||||
lower[i] = towlower(lower[i]);
|
||||
ServerLists_GetWhitelist()->remove(lower);
|
||||
ServerCommand::notifyAdmins(src, server, L"Removed " + playerName + L" from the whitelist");
|
||||
}
|
||||
else if (subCmd == L"reload")
|
||||
{
|
||||
ServerLists_GetWhitelist()->load();
|
||||
ServerCommand::notifyAdmins(src, server, L"Reloaded the whitelist");
|
||||
}
|
||||
else
|
||||
{
|
||||
src->warn(L"Usage: /whitelist <on|off|list|add|remove|reload>");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
#pragma once
|
||||
#include "ServerCommand.h"
|
||||
|
||||
class WhitelistCommand : public ServerCommand
|
||||
{
|
||||
public:
|
||||
wstring getName() { return L"whitelist"; }
|
||||
wstring getUsage() { return L"/whitelist <on|off|list|add|remove|reload> [player] - Manages the whitelist"; }
|
||||
void execute(const wstring& args, ConsoleInputSource *src, MinecraftServer *server);
|
||||
};
|
||||
@@ -0,0 +1,62 @@
|
||||
#include "stdafx.h"
|
||||
#include "XpCommand.h"
|
||||
#include "ServerCommand.h"
|
||||
#include "../../Minecraft.Client/MinecraftServer.h"
|
||||
#include "../../Minecraft.Client/ConsoleInputSource.h"
|
||||
#include "../../Minecraft.Client/PlayerList.h"
|
||||
#include "../../Minecraft.Client/ServerPlayer.h"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
void XpCommand::execute(const wstring& args, ConsoleInputSource *src, MinecraftServer *server)
|
||||
{
|
||||
wstringstream ss(args);
|
||||
wstring amountStr;
|
||||
if (!(ss >> amountStr))
|
||||
{
|
||||
src->warn(L"Usage: /xp <amount> [player] OR /xp <amount>L [player]");
|
||||
return;
|
||||
}
|
||||
|
||||
bool isLevels = false;
|
||||
if (!amountStr.empty() && (amountStr.back() == L'l' || amountStr.back() == L'L'))
|
||||
{
|
||||
isLevels = true;
|
||||
amountStr = amountStr.substr(0, amountStr.size() - 1);
|
||||
}
|
||||
|
||||
int amount = _wtoi(amountStr.c_str());
|
||||
|
||||
wstring playerName;
|
||||
if (!(ss >> playerName))
|
||||
{
|
||||
src->warn(L"Usage: /xp <amount> <player>");
|
||||
return;
|
||||
}
|
||||
|
||||
PlayerList *players = server->getPlayers();
|
||||
shared_ptr<ServerPlayer> player = players->getPlayer(playerName);
|
||||
if (!player)
|
||||
{
|
||||
src->warn(L"Player not found: " + playerName);
|
||||
return;
|
||||
}
|
||||
|
||||
wchar_t buf[256];
|
||||
if (isLevels)
|
||||
{
|
||||
player->withdrawExperienceLevels(-amount);
|
||||
swprintf_s(buf, 256, L"Given %d experience levels to %s", amount, player->name.c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
if (amount < 0)
|
||||
{
|
||||
src->warn(L"Cannot give negative experience points");
|
||||
return;
|
||||
}
|
||||
player->increaseXp(amount);
|
||||
swprintf_s(buf, 256, L"Given %d experience to %s", amount, player->name.c_str());
|
||||
}
|
||||
ServerCommand::notifyAdmins(src, server, wstring(buf));
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
#pragma once
|
||||
#include "ServerCommand.h"
|
||||
|
||||
class XpCommand : public ServerCommand
|
||||
{
|
||||
public:
|
||||
wstring getName() { return L"xp"; }
|
||||
wstring getUsage() { return L"/xp <amount> [player] OR /xp <amount>L [player] - Gives experience"; }
|
||||
void execute(const wstring& args, ConsoleInputSource *src, MinecraftServer *server);
|
||||
};
|
||||
Reference in New Issue
Block a user