• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!
  • New resources must be posted under Resources tab. A discussion thread will be created automatically, you can't open threads manually anymore.

[TFS 1.4+] Async HttpClient system

danilopucci

Intermediate OT User
Joined
Nov 22, 2019
Messages
125
Solutions
4
Reaction score
105
GitHub
danilopucci
Hello community,

I would like to introduce a module that I see some guys requesting it here in otland, I started to work some time ago and now it is ready: HttpClient module
You can find full code details on this pull-request.

How does it works?
It is based on http client lib. There is a dedicated thread, very similar to DatabaseTasks which will handle requests both comming from C++ or Lua context.

How to use it in lua?
The syntax is pretty much simple, and it is very similar(and inspired) to Requests lib, from Python.
LUA:
-- define a callback
local function requestCallback(response)
 --[[response is a table with current fields:
    "requestId", "version", "statusCode", "location", "contentType", "responseTimeMs", "headerData", "bodySize", "bodyData", "success", "errorMessage"
    where you can use "contentType" to get if it is a json and parse "bodyData" accordinly
 ]]
end


-- dummy example to get something
local httpClientRequest = HttpClientRequest()
local url = "https://myapi.mydomain.com"
httpClientRequest:get(url, requestCallback)


-- dummy example to post something
local url = "https://myapi.mydomain.com"
local token = "abcdef123456789"
local data = "I want to post something"
local fields = {
    accept = "application/json",
    authorization = "Bearer " .. token
    }
httpClientRequest:post(url, requestCallback, fields, data)

For usage in C++, check the pull-request

For what is this used for?
It can be used to multiple things, the main usage is to make integration to API services, like:
  • chatgpt api, to generate and make things dinamically in game.
  • monitoring services: you can post data to a monitoring service
  • discord API: send things that is happening on realtime to your discord server


Hope you enjoy :)
 
I tried this aswell a few months back, not in a dedicated thread, but this made every request hung the server for a millisecond. Will try this solution, thanks!
 
Yeah, this is indeed very valuable contribution. Best of luck merging it to TFS!
Thank you! Looking forward to see the usages from the community

I tried this aswell a few months back, not in a dedicated thread, but this made every request hung the server for a millisecond. Will try this solution, thanks!
Yeah, I followed this approach to avoid any blocking to game loop, so it is safe in this point of view.
The callback context to parse response is on the dedicated thread too, so you can safely parse and dispatch any other action to the game loop
 
chatgpt api, to generate and make things dinamically in game. what does this means, could you elaborate a bit more please?

nice release, thank you
 
chatgpt api, to generate and make things dinamically in game. what does this means, could you elaborate a bit more please?

nice release, thank you

The most easy example that comes to my mind is on NPC System.
ChatGPT has an API, which you can redirect player message to it, and its response you can send back to the player. If you fine tune it, add the context of your server/game, it can generate content dinamically to your game.

Also, it will generate one different result for each player...

Anyway, it is up to the game creator imagination
 
The most easy example that comes to my mind is on NPC System.
ChatGPT has an API, which you can redirect player message to it, and its response you can send back to the player. If you fine tune it, add the context of your server/game, it can generate content dinamically to your game.

Also, it will generate one different result for each player...

Anyway, it is up to the game creator imagination
It takes time for the response to be generated so if anything, its gonna add lag to NPCs conversation. Also its gonna cost you fuck ton of money (ChatGPT API) if you were to run this on a populated server.
 
It takes time for the response to be generated so if anything, its gonna add lag to NPCs conversation. Also its gonna cost you fuck ton of money (ChatGPT API) if you were to run this on a populated server.

Yeah, indeed... But it still can be done. Of course, add the ChatGPT to all npcs of the server, or add it to the Thais depot is not a good idea.

Also this problems can be solved by inserting it to the game context.
e.g: your NPC can request you a mission, you go back after some minutes and later you give the player reply. Also you can add a cost as game coins to the player, or only premium account players..

Again, it is up to the game creator imagination.
 
Is it possible that they can adapt a version that is compatible with the canary repository?
Yeah, indeed... But it still can be done. Of course, add the ChatGPT to all npcs of the server, or add it to the Thais depot is not a good idea.

Also this problems can be solved by inserting it to the game context.
e.g: your NPC can request you a mission, you go back after some minutes and later you give the player reply. Also you can add a cost as game coins to the player, or only premium account players..

Again, it is up to the game creator imagination.
 
Thank you, I will try it and report any errors so you can help me.
Yeah, I did that.

You can check it here:
Post automatically merged:

I have this error when I already put everything as is and when I want to compile when I want to install OPENSSL:

C++:
[CMake] Could NOT find OpenSSL, try to set the path to OpenSSL root folder in the
1> [CMake] system variable OPENSSL_ROOT_DIR (missing: OPENSSL_CRYPTO_LIBRARY
1> [CMake] OPENSSL_INCLUDE_DIR)
1> [CMake] Call Stack (most recent call first):
1> [CMake] C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.26/Modules/FindPackageHandleStandardArgs.cmake:600 (_FPHSA_FAILURE_MESSAGE)
1> [CMake] C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.26/Modules/FindOpenSSL.cmake:670 (find_package_handle_standard_args)
1> [CMake] C:/Program Files/Microsoft Visual Studio/2022/Community/VC/vcpkg/scripts/buildsystems/vcpkg.cmake:853 (_find_package)
1> [CMake] cmake/modules/BaseConfig.cmake:44 (find_package)
1> [CMake] src/CMakeLists.txt:4 (include)
 
Last edited:
C++:
[CMake] Could NOT find OpenSSL, try to set the path to OpenSSL root folder in the
1> [CMake] src/CMakeLists.txt:4 (include)
Thanks for rising that!
It was missing the openssl dependency on vcpkg.json. I have just pushed a commit that fixes that :D
 
Do you have an example of how to listen once integrated via an API on the web server? Or a way they can listen via the web?
 
Back
Top