From 94b3b6b32bc8b996c9689fb89a381cf216353641 Mon Sep 17 00:00:00 2001 From: LaG1924 Date: Thu, 17 Jun 2021 01:56:25 +0500 Subject: Implemented main menu in Rml and improved RmlUi support --- src/Plugin.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'src/Plugin.cpp') diff --git a/src/Plugin.cpp b/src/Plugin.cpp index d7a9820..13045e1 100644 --- a/src/Plugin.cpp +++ b/src/Plugin.cpp @@ -74,6 +74,27 @@ namespace PluginApi { void RegisterDimension(int dimId, Dimension dim) { RegisterNewDimension(dimId, dim); } + + void ConnectToServer(std::string host, std::string username) { + size_t index = host.find_last_of(':'); + unsigned short port; + if (index == std::string::npos) + port = 25565; + else { + try { + port = std::stoi(host.substr(index + 1)); + } + catch (std::exception& e) { + port = 25565; + LOG(WARNING) << "Incorrect host format: " << host; + } + } + PUSH_EVENT("ConnectToServer", std::make_tuple(host.substr(0, index), port, username)); + } + + void Exit() { + PUSH_EVENT("Exit", 0); + } } int LoadFileRequire(lua_State* L) { @@ -212,6 +233,8 @@ void PluginSystem::Init() { apiTable["GetGameState"] = PluginApi::GetGameState; apiTable["RegisterBlock"] = PluginApi::RegisterBlock; apiTable["RegisterDimension"] = PluginApi::RegisterDimension; + apiTable["ConnectToServer"] = PluginApi::ConnectToServer; + apiTable["Exit"] = PluginApi::Exit; } lua_State* PluginSystem::GetLuaState() { -- cgit v1.2.3