Jump to content

using luasocket in a luascript


Recommended Posts

Hi,

 

I am currently trying to get luasocket working in one of my luascripts.

 

I got luasocket compiled against the 32bit liblua53 and moved it to silent/lualibs.

 

I still got following problem though. It seems like silent lua extension does NOT reexport modules like lua_gettop

 

I get: socket/core.so: undefined symbol: lua_gettop

 

i found this: https://github.com/siffiejoe/lua-moon/

 

I am not sure if I just failed to compile it correctly but after requireing sofix in my lua module I still get the same error. (the require works though.)

Edited by belstgut
Link to comment
Share on other sites

Am I blind or is there really no edit function for posts?

 

well anyway,

 

Now the module loads and works and stuff, BUT I cant do http requests.

It always times out.

tcpdump shows a successful TCP Handshake

and after the timeout (eg 10s)

I can see the TCP FIN "handshake"

 

But I do NOT see any actual packages transmitted.

 

any ideas?

 

EDIT: hmm odd. I can edit this post, but not the other one.

 

well after a bit of investigating I came to the conclusion, that while a socket:connect() works (tcp handshake and so on)

 

nothing happens with a socket:send('some data')

 

it just times out.

 

So the problem is not related to the http.lua module. but already at the lowerlevel tcp module.

Edited by belstgut
Link to comment
Share on other sites

  • Management

I think we need to refer to TheSilencerPL with this problem. But just to clarify, do you get that error by only running some "Hello World" test script or does it appear when you load more functionalities from additional libraries?

Link to comment
Share on other sites

I'll get that panic before any lua module gets loaded.

 

log: https://ptpb.pw/xB9r

 

 

ET Legacy v2.74-507-gdc7379e linux-i386 Jan 4 2016

Zone megs: 24
----- FS_Startup -----
Current search path:
/home/gs/wolfet/.testserver/testsilent
/home/gs/wolfet/testsilent
/home/gs/wolfet/testsilent/testsilent-0.9.0.pk3 (528 files)
/home/gs/wolfet/.testserver/etmain
/home/gs/wolfet/.testserver/etmain/warbell.pk3 (242 files)
/home/gs/wolfet/.testserver/etmain/venice.pk3 (330 files)
/home/gs/wolfet/.testserver/etmain/trmfght_beta2.pk3 (197 files)
/home/gs/wolfet/.testserver/etmain/tc_base.pk3 (63 files)
/home/gs/wolfet/.testserver/etmain/sw_oasis_b3.pk3 (45 files)
/home/gs/wolfet/.testserver/etmain/supplydepot2.pk3 (46 files)
/home/gs/wolfet/.testserver/etmain/sp_delivery_te.pk3 (51 files)
/home/gs/wolfet/.testserver/etmain/reactor_final.pk3 (115 files)
/home/gs/wolfet/.testserver/etmain/pirates.pk3 (154 files)
/home/gs/wolfet/.testserver/etmain/parisbastille_b3.pk3 (116 files)
/home/gs/wolfet/.testserver/etmain/mlb_temple.pk3 (83 files)
/home/gs/wolfet/.testserver/etmain/missile_b4.pk3 (89 files)
/home/gs/wolfet/.testserver/etmain/karsiah_te2.pk3 (41 files)
/home/gs/wolfet/.testserver/etmain/italyfp2.pk3 (325 files)
/home/gs/wolfet/.testserver/etmain/goldrush-ga.pk3 (36 files)
/home/gs/wolfet/.testserver/etmain/frostbite.pk3 (99 files)
/home/gs/wolfet/.testserver/etmain/Fata_Morgana.pk3 (73 files)
/home/gs/wolfet/.testserver/etmain/et_mor2_night_final.pk3 (92 files)
/home/gs/wolfet/.testserver/etmain/et_ice.pk3 (61 files)
/home/gs/wolfet/.testserver/etmain/et_carentan_b2.pk3 (130 files)
/home/gs/wolfet/.testserver/etmain/et_beach.pk3 (177 files)
/home/gs/wolfet/.testserver/etmain/erdenberg_t1.pk3 (77 files)
/home/gs/wolfet/.testserver/etmain/element_skye.pk3 (27 files)
/home/gs/wolfet/.testserver/etmain/dubrovnik_final.pk3 (186 files)
/home/gs/wolfet/.testserver/etmain/caen2.pk3 (83 files)
/home/gs/wolfet/.testserver/etmain/bremen_final.pk3 (100 files)
/home/gs/wolfet/.testserver/etmain/braundorf_final.pk3 (76 files)
/home/gs/wolfet/.testserver/etmain/bergen.pk3 (181 files)
/home/gs/wolfet/.testserver/etmain/baserace_desert.pk3 (154 files)
/home/gs/wolfet/.testserver/etmain/axislab_final.pk3 (172 files)
/home/gs/wolfet/.testserver/etmain/adlernest_2.pk3 (120 files)
/home/gs/wolfet/etmain
/home/gs/wolfet/etmain/pak0.pk3 (3725 files)

----------------------
7994 files in pk3 files
execing default.cfg
couldn't exec autoexec.cfg
Hunk_Clear: reset the hunk ok
Not logging server attacks to disk.
Found high quality video and fast CPU
SQLite3 libversion 3.9.2 - database URL 'etl.db' - in-memory
... reading existing database '/home/gs/wolfet/.testserver/etl.db'
... database file '/home/gs/wolfet/.testserver/etl.db' loaded
SQLite3 ET: L database '/home/gs/wolfet/.testserver/etl.db' init
--- Common Initialization Complete ---
IP: 127.0.0.1
IP: 94.23.7.172
IP: 10.8.0.1
Opening IP socket: 0.0.0.0:13337
Network initialized.
execing testserver.cfg
sv_maxclients will be changed upon restarting.
g_gametype will be changed upon restarting.
execing mapvote.cfg
------ Server Initialization ------
Server: sw_oasis_b3
Hunk_Clear: reset the hunk ok
...IRC: connecting to server irc.quakenet.org
----- FS_Startup -----
...Connected to IRC server
Current search path:
/home/gs/wolfet/.testserver/testsilent
/home/gs/wolfet/testsilent
/home/gs/wolfet/testsilent/testsilent-0.9.0.pk3 (528 files)
/home/gs/wolfet/.testserver/etmain
/home/gs/wolfet/.testserver/etmain/warbell.pk3 (242 files)
/home/gs/wolfet/.testserver/etmain/venice.pk3 (330 files)
/home/gs/wolfet/.testserver/etmain/trmfght_beta2.pk3 (197 files)
/home/gs/wolfet/.testserver/etmain/tc_base.pk3 (63 files)
/home/gs/wolfet/.testserver/etmain/sw_oasis_b3.pk3 (45 files)
/home/gs/wolfet/.testserver/etmain/supplydepot2.pk3 (46 files)
/home/gs/wolfet/.testserver/etmain/sp_delivery_te.pk3 (51 files)
/home/gs/wolfet/.testserver/etmain/reactor_final.pk3 (115 files)
/home/gs/wolfet/.testserver/etmain/pirates.pk3 (154 files)
/home/gs/wolfet/.testserver/etmain/parisbastille_b3.pk3 (116 files)
/home/gs/wolfet/.testserver/etmain/mlb_temple.pk3 (83 files)
/home/gs/wolfet/.testserver/etmain/missile_b4.pk3 (89 files)
/home/gs/wolfet/.testserver/etmain/karsiah_te2.pk3 (41 files)
/home/gs/wolfet/.testserver/etmain/italyfp2.pk3 (325 files)
/home/gs/wolfet/.testserver/etmain/goldrush-ga.pk3 (36 files)
/home/gs/wolfet/.testserver/etmain/frostbite.pk3 (99 files)
/home/gs/wolfet/.testserver/etmain/Fata_Morgana.pk3 (73 files)
/home/gs/wolfet/.testserver/etmain/et_mor2_night_final.pk3 (92 files)
/home/gs/wolfet/.testserver/etmain/et_ice.pk3 (61 files)
/home/gs/wolfet/.testserver/etmain/et_carentan_b2.pk3 (130 files)
/home/gs/wolfet/.testserver/etmain/et_beach.pk3 (177 files)
/home/gs/wolfet/.testserver/etmain/erdenberg_t1.pk3 (77 files)
/home/gs/wolfet/.testserver/etmain/element_skye.pk3 (27 files)
/home/gs/wolfet/.testserver/etmain/dubrovnik_final.pk3 (186 files)
/home/gs/wolfet/.testserver/etmain/caen2.pk3 (83 files)
/home/gs/wolfet/.testserver/etmain/bremen_final.pk3 (100 files)
/home/gs/wolfet/.testserver/etmain/braundorf_final.pk3 (76 files)
/home/gs/wolfet/.testserver/etmain/bergen.pk3 (181 files)
/home/gs/wolfet/.testserver/etmain/baserace_desert.pk3 (154 files)
/home/gs/wolfet/.testserver/etmain/axislab_final.pk3 (172 files)
/home/gs/wolfet/.testserver/etmain/adlernest_2.pk3 (120 files)
/home/gs/wolfet/etmain
/home/gs/wolfet/etmain/pak0.pk3 (3725 files)

----------------------
7994 files in pk3 files
Sys_LoadDll(/home/gs/wolfet/.testserver/testsilent/qagame.mp.i386.so)... failed: "/home/gs/wolfet/.testserver/testsilent/qagame.mp.i386.so: cannot open
shared object file: No such file or directory"
Sys_LoadDll(/home/gs/wolfet/testsilent/qagame.mp.i386.so)... succeeded
Sys_LoadDll(testsilent/qagame) found vmMain function at 0xe8f26d80
------- Game Initialization -------
gamename: silEnT
gamedate: Nov 22 2015
*=====Server Installation Check
* Inspecting menu files
Menu files are Ok
* Inspecting assets
Asset files are Ok
* Inspecting server cvars
*=====Server Installation Checked and Found Ok
424 cvars in use.
*===== SCREENSHOTS IN USE
file not found: scripts/our.campaign
------------------------------------------------------------
InitGame: \sv_sac\1\omnibot_playing\0\mod_url\http://mygamingtalk.com/\mod_version\0.9.0\g_axismaxlives\0\g_alliedmaxlives\0\g_maxlivesRespawnPenalty\0
\voteFlags\0\g_balancedteams\0\g_maxGameClients\0\g_bluelimbotime\20000\g_redlimbotime\30000\gamename\silEnT\g_tyranny\1\g_damageXPLevel\70\g_damageXP\
2\g_maxConnsPerIP\4\g_heavyWeaponRestriction\100\g_antilagDelay\0\omnibot_enable\0\g_antilag\1\g_voteFlags\0\g_minGameClients\0\g_needpass\0\g_maxlives
\0\g_friendlyFire\0\sv_floodProtect\1\sv_maxPing\0\sv_minPing\0\sv_dlRate\100\sv_maxRate\50000\sv_maxclients\34\sv_minRate\0\sv_hostname\sKy-e.Beginner
s XPSave\sv_privateClients\2\mapname\sw_oasis_b3\protocol\82\g_gametype\6\timelimit\0\version\ET 2.60b linux-i386 May 8 2006
Start of warmup.
Cheat logfile open: cheat.log
readconfig: loaded 17 levels, 420 bans, 85 subnet bans, 61 commands, 0 warnings and 1 custom votes
Loading Dynamic Server Modules
* Could not load module configuration file "modules.cfg".
Execing default.cfg mapconfig for 0 players.
* Execing commands for player amount between 0 - 12.
* Execed total of 24 commands from the config file.
Execing sw_oasis_b3.cfg mapconfig for 0 players.
* Config file "mapconfigs/sw_oasis_b3.cfg" was not found.
Gametype changed, clearing session data.
serverstats: loaded 45 mapstats
banners: loaded 6 banners
*=====INITIALISING USER DATABASE
* Opening user database file userdb.db.
* Opening user database file userxdb.db.
* User database files open. Caching database.
1 players cached from the user database.
No additional user records in the user database.
* Reading aliases database.
Read total of 1 aliases for 1 players.
*=====DATABASE READY FOR USE
Enable spawning!
Disable spawning!
1 teams with 1 entities
-----------------------------------
Setting MOTD...
Disabling sv_floodprotect
]PANIC: unprotected error in call to Lua API (core and library have incompatible numeric types)
----- Server Shutdown -----
Resolving etmaster.idsoftware.com (IPv4)
etmaster.idsoftware.com resolved to 192.246.40.60:27950
Sending heartbeat to etmaster.idsoftware.com
Resolving master.etlegacy.com (IPv4)
master.etlegacy.com resolved to 5.135.27.11:27950
Sending heartbeat to master.etlegacy.com
Resolving master0.etmaster.net (IPv4)
master0.etmaster.net resolved to 91.220.53.121:27950
Sending heartbeat to master0.etmaster.net
=== ShutdownGame -------------------------------------------
*=====CLOSING DATABASE
Buffers cleaned.
Big Memory Cache cleaned.
*=====DATABASE IS CLOSED
Unloading Dynamic Server Modules
Dynamic Server Modules Unloaded
ShutdownGame: done. Closing log.
------------------------------------------------------------
---------------------------
Sys_Exit warning - PID file doesn't exist /home/gs/wolfet/.testserver/testsilent/etlegacy_server.pid
Network shutdown.

 

Edited by belstgut
Link to comment
Share on other sites

yes. I have compiled it in a 32 chroot.

 

gs@server1 ~/wolfet % file /usr/lib/i386-linux-gnu/liblua.so.5.3 
/usr/lib/i386-linux-gnu/liblua.so.5.3: ELF 32-bit LSB shared object, Intel 80386, version 1 (SYSV), dynamically linked, BuildID[sha1]=e7f186a10367b9209c168d910c84ed19199f6c40, not stripped
 
Full ELF info:
 
Edited by belstgut
Link to comment
Share on other sites

  • Management
// silencer
// LUA_32BITS to get 32-bit integers and 'float' and
// LUA_C89_NUMBERS to get 'long' and 'double, which was the traditional
// combination before 5.3.

/*
@@ LUA_32BITS enables Lua with 32-bit integers and 32-bit floats. You
** can also define LUA_32BITS in the make file, but changing here you
** ensure that all software connected to Lua will be compiled with the
** same configuration.
*/
#define LUA_32BITS


/*
@@ LUA_USE_C89 controls the use of non-ISO-C89 features.
** Define it if you want Lua to avoid the use of a few C99 features
** or Windows-specific features on Windows.
*/
#define LUA_USE_C89

We have these defined at the top of the luaconf.h. Maybe you need them too.

Link to comment
Share on other sites

Btw, luasockets work in the systemwide lua interpreter. (5.3.1 32bit)

 

Lua 5.3.1  Copyright © 1994-2015 Lua.org, PUC-Rio
> http = require'socket.http'
> print(http.request('http://127.0.0.1'))
Hi there
        200     table: 0x80c1600        HTTP/1.1 200 OK
 
 
/usr/bin/lua5.3: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux.so.2, for GNU/Linux 2.6.32, BuildID[sha1]=5c238fe30c288fab06fd2c3e25bbffb575a48700, stripped
 
Link to comment
Share on other sites

So I got everything working now.

 

One problem though,

 

using luasocket http is blocking.

 

Since I am using this in et_clientConnect (not always though) everytime I do the http request the server lags until the request has finished. I return nil or a string based on the result of the request.

 

Is there any way I could make this callback nonblocking? (like let it execute for more than 1 server frame, the client has to wait for the result though)?

Link to comment
Share on other sites

  • Management

I don't think so. The mod and the Lua execute in the same thread. So the et_clientConnect must return for the game to continue and the return value is also used by the game. If you can find a way to create threads within the Lua and have a separate thread for the networking, you might get by with less lags. Of course, you still have synchronization issues.

Link to comment
Share on other sites

having threads in lua should not be a problem, since u can just bind a C module anyway.

 

But I would like to return a ~= nil value based on the result of the request in the et_ClientConnect callback.  how would I do that? I mean even if I fork the networking into a seperate thread, the function would still have to wait for that thread to finish, so I could return sth. I almost think that this would not be possible.

 

So probably just always return nil and then kick based on the result.

 

Still, this could be done more beautifully like calling every callback in its own thread and collecting the return values in an array. when all callbacks are finished, iterate over the results instead of calling the callbacks in a loop.

Edited by belstgut
Link to comment
Share on other sites

  • Management

The return value is used by the game so the game is stuck waiting for it in every case. Adding threading is not something that should be ever done lightly, without considering if there is something wrong in the design that can be fixed to avoid adding threads, especially in this case when it wouldn't change anything in the game. I don't remember, but probably there is only one callback made on client connect, so there aren't even parallel callbacks to be made. On the other hand, you can kick players at any time using Lua.

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...