login plugin works yoy
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
#include "../../../world/level/Level.h"
|
||||
#include "../../../network/RakNetInstance.h"
|
||||
#include "../../../network/ServerSideNetworkHandler.h"
|
||||
#include "../../../network/packet/MessagePacket.h"
|
||||
#include "../../../network/packet/ChatPacket.h"
|
||||
#include "../../../platform/log.h"
|
||||
#include "util/StringUtils.h"
|
||||
|
||||
@@ -63,25 +63,25 @@ void ConsoleScreen::execute()
|
||||
return minecraft->setScreen(NULL);
|
||||
}
|
||||
|
||||
if (_input[0] == '/') {
|
||||
// Command
|
||||
_input = Util::stringTrim(_input.substr(1));
|
||||
// if (_input[0] == '/') {
|
||||
// // Command
|
||||
// _input = Util::stringTrim(_input.substr(1));
|
||||
|
||||
std::istringstream iss(minecraft->commandManager().execute(*minecraft, *minecraft->player, _input));
|
||||
for (std::string line; std::getline(iss, line); ) {
|
||||
minecraft->gui.addMessage(line);
|
||||
}
|
||||
} else {
|
||||
// std::istringstream iss(minecraft->commandManager().execute(*minecraft, *minecraft->player, _input));
|
||||
// for (std::string line; std::getline(iss, line); ) {
|
||||
// minecraft->gui.addMessage(line);
|
||||
// }
|
||||
// } else {
|
||||
// @ai @rewrite
|
||||
if (minecraft->netCallback && minecraft->raknetInstance->isServer()) {
|
||||
static_cast<ServerSideNetworkHandler*>(minecraft->netCallback)->displayGameMessage(_input);
|
||||
} else if (minecraft->netCallback) {
|
||||
MessagePacket chatPkt(_input.c_str());
|
||||
ChatPacket chatPkt(_input);
|
||||
minecraft->raknetInstance->send(chatPkt);
|
||||
} else {
|
||||
minecraft->gui.addMessage("<" + minecraft->player->name + "> " + _input);
|
||||
}
|
||||
}
|
||||
// }
|
||||
|
||||
minecraft->setScreen(NULL);
|
||||
}
|
||||
|
||||
@@ -234,13 +234,13 @@ int main(int numArguments, char* pszArgs[]) {
|
||||
} else {
|
||||
throw std::runtime_error("Cannot open banned players list.");
|
||||
}
|
||||
PluginsManager::get().emit("ServerShutdown");
|
||||
|
||||
((MAIN_CLASS*)g_app)->level->saveLevelData();
|
||||
|
||||
delete app;
|
||||
appContext.platform->finish();
|
||||
delete appContext.platform;
|
||||
PluginsManager::get().emit("ServerShutdown");
|
||||
|
||||
std::cout << "Quit correctly" << std::endl;
|
||||
return g_exitCode;
|
||||
|
||||
@@ -166,9 +166,11 @@ void ServerSideNetworkHandler::handle(const RakNet::RakNetGUID& source, ChatPack
|
||||
// This is a command
|
||||
auto cmd = Util::stringTrim(packet->message.substr(1));
|
||||
|
||||
if (PluginsManager::get().emitCommands(cmd, LuaPlayer(source))) {
|
||||
if (PluginsManager::get().emitCommands(cmd, source)) {
|
||||
ChatPacket resp(minecraft->commandManager().execute(*minecraft, *player, cmd));
|
||||
return sendPrivate(resp, source);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,42 @@
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
int PluginsManager::emitCommands(std::string command, const RakNet::RakNetGUID& source) {
|
||||
std::vector<std::string> args;
|
||||
std::string cmd;
|
||||
|
||||
int i = 0;
|
||||
std::string word;
|
||||
std::stringstream ss(command);
|
||||
|
||||
while (ss >> word) {
|
||||
if (i == 0) {
|
||||
cmd = word;
|
||||
} else {
|
||||
args.push_back(word);
|
||||
}
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
std::cout << cmd << " " << " ff" << std::endl;
|
||||
|
||||
auto it = m_luaCommands.find(cmd);
|
||||
|
||||
if (it == m_luaCommands.end()) return 1;
|
||||
|
||||
for (auto& callback : it->second) {
|
||||
sol::protected_function_result result = callback(LuaPlayer(source), sol::as_table(args));
|
||||
|
||||
if (!result.valid()) {
|
||||
sol::error err = result;
|
||||
std::cout << err.what() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void PluginsManager::init(Minecraft& minecraft) {
|
||||
m_lua.open_libraries(sol::lib::base, sol::lib::package, sol::lib::string, sol::lib::math, sol::lib::table, sol::lib::io);
|
||||
registerTypes();
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
#include <plugins/LuaServer.hpp>
|
||||
#include <raknet/RakNetTypes.h>
|
||||
|
||||
class Minecraft;
|
||||
|
||||
@@ -42,23 +43,8 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
int emitCommands(std::string event, Args&&... args) {
|
||||
auto it = m_luaCommands.find(event);
|
||||
int emitCommands(std::string command, const RakNet::RakNetGUID& source);
|
||||
|
||||
if (it == m_luaCommands.end()) return 1;
|
||||
|
||||
for (auto& callback : it->second) {
|
||||
sol::protected_function_result result = callback(std::forward<Args>(args)...);
|
||||
|
||||
if (!result.valid()) {
|
||||
sol::error err = result;
|
||||
std::cout << err.what() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
Minecraft* getMinecraft() { return m_minecraft; }
|
||||
private:
|
||||
std::unordered_map<std::string, std::vector<sol::function>> m_callbacks;
|
||||
|
||||
Reference in New Issue
Block a user