Lua Socket: Difference between revisions
From Spring
Jump to navigationJump to search
| Line 1: | Line 1: | ||
==config | ==config== | ||
All LuaSocket related config is readonly for LuaWidgets. They can be only changed through unitsync. | All LuaSocket related config is readonly for LuaWidgets. They can be only changed through unitsync. | ||
| Line 6: | Line 6: | ||
<code><pre>TCPAllowConnect springrts.com:80</pre></code> | <code><pre>TCPAllowConnect springrts.com:80</pre></code> | ||
has to be set. | has to be set. | ||
===possible config values=== | |||
{| | {| | ||
Revision as of 10:43, 28 March 2012
config
All LuaSocket related config is readonly for LuaWidgets. They can be only changed through unitsync.
As default, socket access is restricted, as default no connections are allowed. To allow a connection / sending a packet, the destination has to the corresponding allow rule. For example, if a lua widget wants to connect to springrts.com at port 80,
TCPAllowConnect springrts.com:80
has to be set.
possible config values
| LuaSocketEnabled = 1 | Default is 0 means, all Socket functions are disabled |
| TCPAllowConnect | allow TCP-connections to the listed hosts, for example: "springrts.com:80 springfiles.com:80" which allows luasockets to connect to springrts.com at port 80 and springfiles.com at port 80. |
| TCPAllowListen | Server TCP-sockets are allowed on this port, for example: "localhost:1234 0.0.0.0:12345" |
| UDPAllowConnect | see TCPAllowConnect |
| UDPAllowConnect | see TCPAllowListen |
example code
Notes / known issues / TODO
- only ipv4 is supported (could be solved by using unstable luasocket2: http://code.matthewwild.co.uk/luasocket2-hg/)
- dns resolving is blocking, solutions: worker thread or some lib:
- adns http://www.chiark.greenend.org.uk/~ian/adns/
- dns.c http://25thandclement.com/~william/projects/dns.c.html
- tadns http://adns.sourceforge.net/
- or a lua implementation? biggest problem would be to find the local dns-server
- most lua scripts from luasocket won't work as they are blocking! rewriting them non-blocking is required! (should be in most cases few work, as parsing stuff can be reused)
- config file should be better protected, see https://github.com/spring/spring/blob/develop/rts/System/Config/ConfigHandler.cpp#L289 + https://github.com/spring/spring/commit/948d6fb9d1c95b99b5cc7929cf3e0de0f9d6d93e maybe just locking the file is best?! see also http://springrts.com/mantis/view.php?id=2891 (private report)
- access to autohost interface / game host is denied
documentation
- http://w3.impa.br/~diego/software/luasocket/socket.html
- http://w3.impa.br/~diego/software/luasocket/tcp.html
- http://w3.impa.br/~diego/software/luasocket/udp.html