mirror of
https://github.com/WerWolv/ImHex.git
synced 2026-03-29 00:10:02 -05:00
<!-- Please provide as much information as possible about what your PR aims to do. PRs with no description will most likely be closed until more information is provided. If you're planing on changing fundamental behaviour or add big new features, please open a GitHub Issue first before starting to work on it. If it's not something big and you still want to contact us about it, feel free to do so ! --> ### Problem description <!-- Describe the bug that you fixed/feature request that you implemented, or link to an existing issue describing it --> ### Implementation description <!-- Explain what you did to correct the problem --> ### Screenshots <!-- If your change is visual, take a screenshot showing it. Ideally, make before/after sceenshots --> ### Additional things <!-- Anything else you would like to say -->
39 lines
1.0 KiB
C++
39 lines
1.0 KiB
C++
#include <hex/mcp/client.hpp>
|
|
#include <hex/mcp/server.hpp>
|
|
|
|
#include <hex.hpp>
|
|
|
|
#include <string>
|
|
#include <cstdlib>
|
|
|
|
#include <fmt/format.h>
|
|
#include <hex/helpers/logger.hpp>
|
|
#include <nlohmann/json.hpp>
|
|
#include <wolv/net/socket_client.hpp>
|
|
|
|
namespace hex::mcp {
|
|
|
|
int Client::run(std::istream &input, std::ostream &output) {
|
|
wolv::net::SocketClient client(wolv::net::SocketClient::Type::TCP, true);
|
|
client.connect("127.0.0.1", Server::McpInternalPort);
|
|
|
|
if (!client.isConnected()) {
|
|
log::resumeLogging();
|
|
log::error("Cannot connect to ImHex. Do you have an instance running and is the MCP server enabled?");
|
|
return EXIT_FAILURE;
|
|
}
|
|
|
|
while (true) {
|
|
std::string request;
|
|
std::getline(input, request);
|
|
|
|
client.writeString(request);
|
|
auto response = client.readString();
|
|
if (!response.empty() && response.front() != 0x00)
|
|
output << response << '\n';
|
|
}
|
|
|
|
return EXIT_SUCCESS;
|
|
}
|
|
}
|