aboutsummaryrefslogtreecommitdiff
path: root/src/handler.cpp
diff options
context:
space:
mode:
authorJan200101 <sentrycraft123@gmail.com>2023-10-15 18:57:47 +0200
committerJan200101 <sentrycraft123@gmail.com>2023-10-15 18:57:47 +0200
commit2dace4e0e57df5506a31687b44a48fa94c9f9071 (patch)
treeee64a4c5d875ce43b15835c8790492109583ef80 /src/handler.cpp
parent3583254d59ecc7ca5534c7759224a806de1ff5a8 (diff)
downloadSouthRPC-2dace4e0e57df5506a31687b44a48fa94c9f9071.tar.gz
SouthRPC-2dace4e0e57df5506a31687b44a48fa94c9f9071.zip
Add error checking, local testing, default convar handler
Diffstat (limited to 'src/handler.cpp')
-rw-r--r--src/handler.cpp36
1 files changed, 25 insertions, 11 deletions
diff --git a/src/handler.cpp b/src/handler.cpp
index f82573c..56aea76 100644
--- a/src/handler.cpp
+++ b/src/handler.cpp
@@ -28,18 +28,25 @@ ServerHandler::ServerHandler(Plugin* plugin):
this->init = true;
- /*
- @TODO
+ /* execute_squirrel */
this->register_callback(
- "list_methods",
- [=](rapidjson::Value& params) -> rapidjson::Value
+ "methods",
+ [this](rapidjson::MemoryPoolAllocator<>& allocator, rapidjson::Value& params) -> rapidjson::Value
{
- rapidjson::MemoryPoolAllocator<>& allocator = this->body.GetAllocator();
+ rapidjson::Value method_list;
+ method_list.SetArray();
- return rapidjson::Value(1);
+ for (auto const& [key, val] : this->methods)
+ {
+ rapidjson::Value method_name;
+ method_name.SetString(key.c_str(), key.size(), allocator);
+
+ method_list.PushBack(method_name, allocator);
+ }
+
+ return method_list;
}
);
- */
}
@@ -78,12 +85,19 @@ void ServerHandler::run()
spdlog::info("Running Handler");
// The engine won't have loaded convar data until after the entry
- //Sleep(SLEEP_DURATION);
+ spdlog::info("Waiting for engine to initialize");
+ Sleep(SLEEP_DURATION);
- //int port = this->Convar_Port->GetInt();
- int port = 26503;
+ int port = this->Convar_Port->GetInt();
RPCServer* server = new RPCServer(INADDR_ANY, port);
- Sleep(SLEEP_DURATION);
+
+ if (server->get_http_server().get_socket() == -1)
+ {
+ spdlog::error("HTTP Server failed to start");
+ return;
+ }
+
+ spdlog::info("Launched server on port {}", port);
while (this->running)
{