Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resurrect ServerAgent for external tool access #6044

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

fluffyfreak
Copy link
Contributor

@fluffyfreak fluffyfreak commented Feb 4, 2025

This is not a new feature but after a discussion on the Discord channel I did promise to take a look at it and to stop me forgetting (again) I'm going to track this here as a WIP 😁

Todo:

  • code is NOT equivalent
  • responding to success is commented out due to me not understanding the JSON changes yet
  • update libcurl from 7.40.0 to something newer
  • add libcurl to CMake build system
  • needs testing

ServerAgent.cpp needs work on JSON Reader and Writer
@@ -153,8 +156,7 @@ void HTTPServerAgent::ThreadMain()
// done with the queue
SDL_UnlockMutex(m_requestQueueLock);

Json::FastWriter writer;
req.buffer = writer.write(req.data);
req.buffer = req.data;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sturnclaw this is one of the two problems I could do with some advice about, this line is not an equivalent replacement for the writer.write(req.data) which used to be there which I believe serialised the data.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You want req.buffer = req.data.dump(); the arguments to the dump function are the amount of indentation and the indent character, neither of which should be used for over-the-wire serialization.

resp.success = reader.parse(resp.buffer, resp.data, false);
if (!resp.success)
resp.buffer = std::string("JSON parse error: " + reader.getFormattedErrorMessages());
//Json::Reader reader;
Copy link
Contributor Author

@fluffyfreak fluffyfreak Feb 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sturnclaw second is this section which I think deserialised a response

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will be resp.data = Json::parse(resp.buffer); resp.success = !resp.data.is_null();. Substitute the !is_null() check for an is_object() or is_array() depending on the wire format of your message type.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'll likely also need to wrap it in a try block or use a non-throwing method; still getting my development environment back up so that's an exercise left to the reader.

@fluffyfreak
Copy link
Contributor Author

Before this could be considered working it will probably need to use updated libcurl, this was written against 7.40.0 which is considerably out of date being from late 2014.

It will also need some testing, and if I recall robn wrote it more as a proof of concept for people to improve and build upon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants