• 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!

C++ (LUA Lib) - Http Socket on tfs (OTHire)

Discovery

Developing myself
Joined
Apr 16, 2010
Messages
561
Solutions
11
Reaction score
262
Location
Neverland
Hello dears,

Im working in a webhook in LUA script, but I have two things on my mind because I dont finded anything related by that issue in Otland posts

- Have native socket in LUA? If yes, exist example/sample about it?
- I remember existing something in a older TFS version checking a external link (blacklist.xml) with a C++.h lib.

Lua:
function onSay(cid, words, param)
    if(param == "") then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You need to type the parameter.")
        return false
    end

  
    local http=require("socket.http");

    local request_body = [[content=test&username=BOT&avatar_url]]
    local response_body = {}

    local res, code, response_headers = http.request{
        url = "https://discordapp.com/api/webhooks/455742330390183957/AmDojr51rtpi6F8hMfxBe5LJWcvzk4A0982c0EzlZuYIWXfZKbDvHN6Sc1vDsMoQ367M",
        method = "POST",
        headers =
          {
              ["Content-Type"] = "application/x-www-form-urlencoded";
              ["Content-Length"] = #request_body;
          },
          source = ltn12.source.string(request_body),
          sink = ltn12.sink.table(response_body),
    }

    print(res)
    print(code)

    if type(response_headers) == "table" then
      for k, v in pairs(response_headers) do
        print(k, v)
      end
    end

    print("Response body:")
    if type(response_body) == "table" then
      print(table.concat(response_body))
    else
      print("Not a table:", type(response_body))
    end

    return false
end

Somebody tried something like that?

Because I dont know if I need install a new lib in my source, or have a optional lib installed about it.
*I searched in the "OTHire" sources, and I dont know if exist this possibility and lib.lua dependencies.

Regards,
Discovery.

Post-topic:
miss ~~ like metatable:responder in TFS 1.3 :( #sad
 
Last edited:
Solved problem:
I installed directly in sources the socket.lua library. (server to server)

or...
But have a optional method: create a .php file that read your database and search changes with "status" collums like:
if 0 - not sended, 1 - sended.

Sending webhooks with POST.
 
Back
Top