mirror of
https://github.com/OpenFusionProject/OpenFusion.git
synced 2024-11-22 13:30:06 +00:00
minor command refactor
This commit is contained in:
parent
316239dadc
commit
a852c26e5e
@ -15,7 +15,8 @@ std::vector<std::string> parseArgs(std::string full) {
|
|||||||
return std::vector<std::string>(begin, end);
|
return std::vector<std::string>(begin, end);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool runCmd(std::string full, std::vector<std::string> args, CNSocket* sock) {
|
bool runCmd(std::string full, CNSocket* sock) {
|
||||||
|
std::vector<std::string> args = parseArgs(full);
|
||||||
std::string cmd = args[0].substr(1, args[0].size() - 1);
|
std::string cmd = args[0].substr(1, args[0].size() - 1);
|
||||||
|
|
||||||
// check if the command exists
|
// check if the command exists
|
||||||
@ -37,7 +38,7 @@ bool runCmd(std::string full, std::vector<std::string> args, CNSocket* sock) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void testCommand(std::string full, std::vector<std::string> args, CNSocket* sock) {
|
void testCommand(std::string full, std::vector<std::string>& args, CNSocket* sock) {
|
||||||
ChatManager::sendServerMessage(sock, "Test command is working! Here are your passed args:");
|
ChatManager::sendServerMessage(sock, "Test command is working! Here are your passed args:");
|
||||||
|
|
||||||
for (std::string arg : args) {
|
for (std::string arg : args) {
|
||||||
@ -45,7 +46,7 @@ void testCommand(std::string full, std::vector<std::string> args, CNSocket* sock
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void accessCommand(std::string full, std::vector<std::string> args, CNSocket* sock) {
|
void accessCommand(std::string full, std::vector<std::string>& args, CNSocket* sock) {
|
||||||
ChatManager::sendServerMessage(sock, "Your access level is " + std::to_string(PlayerManager::getPlayer(sock)->accountLevel));
|
ChatManager::sendServerMessage(sock, "Your access level is " + std::to_string(PlayerManager::getPlayer(sock)->accountLevel));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -71,10 +72,9 @@ void ChatManager::chatHandler(CNSocket* sock, CNPacketData* data) {
|
|||||||
Player* plr = PlayerManager::getPlayer(sock);
|
Player* plr = PlayerManager::getPlayer(sock);
|
||||||
|
|
||||||
std::string fullChat = U16toU8(chat->szFreeChat);
|
std::string fullChat = U16toU8(chat->szFreeChat);
|
||||||
std::vector<std::string> args = parseArgs(fullChat);
|
|
||||||
|
|
||||||
if (args.size() > 0 && args[0][0] == CMD_PREFIX) { // PREFIX
|
if (fullChat.length() > 1 && fullChat[0] == CMD_PREFIX) { // PREFIX
|
||||||
runCmd(fullChat, args, sock);
|
runCmd(fullChat, sock);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
#define CMD_PREFIX '/'
|
#define CMD_PREFIX '/'
|
||||||
|
|
||||||
typedef void (*CommandHandler)(std::string fullString, std::vector<std::string> args, CNSocket* sock);
|
typedef void (*CommandHandler)(std::string fullString, std::vector<std::string>& args, CNSocket* sock);
|
||||||
|
|
||||||
struct ChatCommand {
|
struct ChatCommand {
|
||||||
int requiredAccLevel;
|
int requiredAccLevel;
|
||||||
|
Loading…
Reference in New Issue
Block a user