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