Jump to content

using luasocket in a luascript


Recommended Posts

  • Management

In that way, yes there can be several parallel calls to it. It's still wrong to address it with threading. Furthermore, every one core VPS out there would suffer even more performance degradation coming from multiple context switches and added synchronization. Do also note, that every call made from the scripts to the game, would need added work also, to make them safe to use. Even on multiple cores, the result in this case would reduce performance, when the same player and same data is handled in multiple threads, which would mean that even the parallel threads would end up synchronizing accesses and validating the data at every possible moment. It's just a plain bad idea.

Link to comment
Share on other sites

Since I got this running now, I wanted to share on how to do it.

 

u need https://github.com/siffiejoe/lua-moon/blob/master/examples/sofix.c compiled as shared Object with

-DMOON_DLFIX_LIBNAME=/path/to/silent/qagame.mp.i386.so

 

example: gcc -DMOON_DLFIX_LIBNAME='"/home/gs/wolfet/silent/qagame.mp.i386.so"' -m32 -Wall -Wextra -I.. -fpic -shared -Os -o sofix.so sofix.c

 

Luasocket (precompiled for 32bit): https://ptpb.pw/gyb_.zip

 

Copas: https://github.com/keplerproject/copas/tree/master/src

 

copy/extract luasocket, sofix.so and copas to: silent/lualibs/

 

after that create your luamodule. example:

require('sofix') -- needs to be required before any other C based module

local copas = require('copas')
local asynchttp = require('copas.http').request

-- random callback
-- makes http request at every player connect (probably not what u wanna do)
function et_ClientConnect(clientNum, firstTime, isBot)
    copas.addthread(function()
        local body, c, h = asynchttp('http://example.org/')
        if c ~= 200 then
            et.G_LogPrint(("HTTP Error: %d"):format(c))
            return
        end
        -- use body and headers here. eg:
        et.G_LogPrint(body)
    end)
end

-- "Using gameloop as event loop"
function et_RunFrame(levelTime)
    if levelTime % 500 ~= 0 then
        return
    end
    copas.step()
end

I am currently using a structure like that and haven't experienced any lags till now.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...