Your Ad Here

Subscribe
 Post #1
 12th February 2008
Dennab
September 2005
5,541 Posts
This is a full-featured port of LuaSocket for GMod. I've tried a simple socket thing, which worked out just fine.

spbogie posted:
I have modified the Lua files to fix the problems with using the sub-modules (socket.http, socket.ftp, etc...).

Required Changes:
Code:
moved socket.lua to /socket/socket.lua

added socket.lua
    includes /socket/*.lua in necessary order

changed /socket/mime.lua
    removed reqiure( "io" ) - unused, not available in gmod

changed /socket/smtp.lua
    Line 33: DOMAIN = os.getenv("SERVER_NAME") or "localhost"
        to: DOMAIN = "localhost"
    os.getenv not available in gmod
Calling require( "socket" ) will load all sub-modules as well.

Fix is available at http://people.msoe.edu/~bogies/luasocket_fix.zip.
Includes only modifications made, simply extract over existing install.
Installation instructions:

Extract that archive in garrysmod/lua/includes/modules.

You will need the VS2008 runtime libs, or else you'll get a strange error while loading: http://www.microsoft.com/downloads/d...displaylang=en

Don't ask any questions unless you've installed that (and rebooted)

Usage:

Just like LuaSocket, see this for a reference: http://www.tecgraf.puc-rio.br/~diego...reference.html

Don't forget forget to use non-blocking sockets (set timeout to 0) or else GMod freezes while waiting for data!

Source code:

It's a VS 2008 project, should work in the Express version.

Thanks to:

Sechs - helped me with testing in #luahelp
Jinto - provided the Lua import library

Small example:

require("socket")
local s = socket.connect("www.google.com", 80)
s:send("GET / HTTP/1.1\n")
s:send("Host: www.google.com\n")
s:send("User-Agent: GMod10\n")
s:send("Connection: Close\n")
s:send("\n")
local line = s:receive('*line')
print(line)
s:close()

I don't know if that is correct but it should give you an idea about how it's used. You don't even have to use it manually, there are some helper modules too (http, smtp, ftp), but they don't seem to work. they probably would with some modification.
 Post #2
 12th February 2008
Gold Member
anklyne's Avatar
December 2005
4,003 Posts
I'm curious as to what kind of things this could be used for/what it does. I'm guessing this is one of those things that other programmers will use to make something cool and I'm not a programmer, so this is of no use to me.

Is it something you'd use to send commands and info from server-client and back or something?
 Post #3
 12th February 2008
Dennab
September 2005
5,541 Posts
anklyne posted:
I'm curious as to what kind of things this could be used for/what it does. I'm guessing this is one of those things that other programmers will use to make something cool and I'm not a programmer, so this is of no use to me.

Is it something you'd use to send commands and info from server-client and back or something?
You could make anything that uses the internet with this. You could clone a server onto another (send all prop info etc), make a simple web browser, send email, anything...
 Post #4
 12th February 2008
Gold Member
Xera's Avatar
November 2006
8,710 Posts
Awesome. :)
 Post #5
 12th February 2008
Dennab
September 2005
5,541 Posts
I'd really appreciate it if anyone tried this out, I have no idea if it'll even load on other computers.
 Post #6
 12th February 2008
tjl's Avatar
February 2006
1,437 Posts
Woo hoo, now I can finally make mailbomb script.
 Post #7
 12th February 2008
TheFoxz's Avatar
December 2006
1,066 Posts
This will prove useful :D
 Post #8
 13th February 2008
nonedead's Avatar
May 2006
257 Posts
Quick question, I use VS2008E and what type of project (VB, C++, WD)I know it is not C#. Please clarify this for me. I have limited HD space and do not want to delete alot of files.
 Post #9
 13th February 2008
Dennab
September 2005
5,541 Posts
It's C++
 Post #10
 13th February 2008
Sakayd's Avatar
December 2006
301 Posts
Nice job :)
 Post #11
 13th February 2008
Dennab
September 2005
5,541 Posts
nonedead posted:
Quick question, I use VS2008E and what type of project (VB, C++, WD)I know it is not C#. Please clarify this for me. I have limited HD space and do not want to delete alot of files.
You don't need the source code if you're not planning to modify the DLL itself
 Post #12
 14th February 2008
RabidToaster's Avatar
October 2006
589 Posts
With both this and the old gm_socket dll whenever I try and use it, it'll create a socket fine, but when I try and do something it'll tell me the socket is closed.
 Post #13
 14th February 2008
Dennab
September 2005
5,541 Posts
RabidToaster posted:
With both this and the old gm_socket dll whenever I try and use it, it'll create a socket fine, but when I try and do something it'll tell me the socket is closed.
Then you're doing something wrong (show me the source code)
 Post #14
 17th February 2008
Dennab
September 2007
236 Posts
Exactly what I need for cross-server communication.
 Post #15
 18th February 2008
phenex's Avatar
August 2005
1,109 Posts
Excellent work, now I have to make a porn spidering script. I think I'll call it "GPorn".
 Post #16
 23rd February 2008
Dennab
September 2005
5,541 Posts
It was reported to me that the included LUA modules (socket.http) etc aren't found by require(), so you'll have to figure that out if you need those. Shouldn't be too hard I guess.
 Post #17
 27th February 2008
Dennab
September 2005
5,541 Posts
My site is currently down, but I'll upload the stuff somewhere else later!
 Post #18
 28th February 2008
Gold Member
tad2020's Avatar
December 2006
1,656 Posts
Does this one's http module override the gmod one?
 Post #19
 28th February 2008
Dennab
September 2005
5,541 Posts
Probably not
 Post #20
 29th February 2008
hegrec's Avatar
April 2006
333 Posts
How would you create a tcp server on a garrysmod game server and have it listen for incoming data but not lock up?

Basically have the garrysmod server realize 'Hey! someone is connecting' at any point in time without the server locking up.
 Post #21
 1st March 2008
DarkSpider's Avatar
July 2006
1,429 Posts
Anders1 posted:
I'd really appreciate it if anyone tried this out, I have no idea if it'll even load on other computers.

After eight hours of fiddling with this, i can tell you that it works. I have it currently set up for Server 2 Server chat on all my servers. It is much better than a mysql query looking for new text. You are awesome man thanks.
 Post #22
 1st March 2008
Dennab
September 2005
5,541 Posts
hegrec posted:
How would you create a tcp server on a garrysmod game server and have it listen for incoming data but not lock up?

Basically have the garrysmod server realize 'Hey! someone is connecting' at any point in time without the server locking up.
You should do something like :settimeout(0) on the socket, I'm not actually quite sure. See the LuaSocket reference.
 Post #23
 1st March 2008
mattdaemon's Avatar
December 2006
105 Posts
This could be usefull for someone that has two dedicated servers and get them to link each other together. Making it even faster to run like an 8 man server
 Post #24
 1st March 2008
DarkSpider's Avatar
July 2006
1,429 Posts
Or use the udp version and send data between servers and run a 128 man server!
 Post #25
 2nd March 2008
Gold Member
DarKSunrise's Avatar
July 2006
4,206 Posts
This looks too useful for me. Couldn't you upload the files to SpeedyShare or somewhere?
 Post #26
 2nd March 2008
Dennab
September 2005
5,541 Posts
I already uploaded them to garrysmod.org

Edit:

What the hell, seems like the files were deleted...
 Post #27
 2nd March 2008
Neico's Avatar
October 2005
381 Posts
Anders1 posted:
I already uploaded them to garrysmod.org

Edit:

What the hell, seems like the files were deleted...

if you don't mind:

http://neic0.de/gmod/gm_luasocket_rc1.zip
http://neic0.de/gmod/gm_luasocket_source.zip

i think those ones was that files right?
 Post #28
 2nd March 2008
Dennab
September 2005
5,541 Posts
Yep, thanks! Would have had to boot VMware otherwise.
 Post #29
 31st March 2008
Dennab
September 2007
236 Posts
DarkSpider posted:
Or use the udp version and send data between servers and run a 128 man server!
Have fun with that, 128 player deathmatch, and lots of bandwidth consumption.
Not only ridiculously hectic to play in, but also will use a shitload of bandwidth if not optimized fully.

I'm gonna try this module out this weekend if I can, it looks really good for some active communication that I need to do.
 Post #30
 31st March 2008
DarkSpider's Avatar
July 2006
1,429 Posts
Yea, my server starts to stutter if i have 64 in it and they are all firing so i doubt 128 will work. Maybe in a year or so.
 Post #31
 3rd April 2008
SamuraiMush's Avatar
April 2008
47 Posts
Code:
error loading module 'luasocket' from file 'c:\program files\serverdoc\gmod_xdl\
server\srcds\orangebox\garrysmod\lua\includes\modules\gm_luasocket.dll':
        system error 14001
This is what I get when trying to load the module.

EDIT: Sorry I hadn't gotten the libraries. Everything works fine so far, however grasping IRC protocol is somehow too difficult for me. All that works is the USER message, nothing else yields a reply.
 Post #32
 4th April 2008
Anders2's Avatar
January 2006
53 Posts
Here's a small IRC protocol guide:

To connect to the server, port 6667:

USER username . . :The Real Name (appears in whois)
NICK yournick

You should then get a PING somethingrandom, send PONG somethingrandom back

Then you get stuff like

:server.com 001 blahblah, when you get 001 it means you can JOIN channels

use PRIVMSG target :message blah blah to send a message

Code:
< NOTICE AUTH :*** blah blah ignore this stuff
> USER anders . . :Anders
> NICK anders_lua
< PING :123568
> PONG :123568
< lots of junk, ignore this
< :server.com 001 <junk>
> JOIN #anders
< some junk about the channel
> PRIVMSG #anders :hello everyone!
< :anders!anders@anders.com PRIVMSG #anders :hey there anders_lua!
> PRIVMSG #anders :hi anders
Hope this helps

If you use mIRC you can also use /debug @foo to open a window that shows all IRC messages being sent/received
 Post #33
 7th April 2008
SamuraiMush's Avatar
April 2008
47 Posts
Anders2 posted:
Here's a small IRC protocol guide:

To connect to the server, port 6667:

USER username . . :The Real Name (appears in whois)
NICK yournick

You should then get a PING somethingrandom, send PONG somethingrandom back

Then you get stuff like

:server.com 001 blahblah, when you get 001 it means you can JOIN channels

use PRIVMSG target :message blah blah to send a message

Code:
< NOTICE AUTH :*** blah blah ignore this stuff
> USER anders . . :Anders
> NICK anders_lua
< PING :123568
> PONG :123568
< lots of junk, ignore this
< :server.com 001 <junk>
> JOIN #anders
< some junk about the channel
> PRIVMSG #anders :hello everyone!
< :anders!anders@anders.com PRIVMSG #anders :hey there anders_lua!
> PRIVMSG #anders :hi anders
Hope this helps

If you use mIRC you can also use /debug @foo to open a window that shows all IRC messages being sent/received
Yeah I had it going according to specification, it didn't work out because I had forgotten the \n dar
 Post #34
 10th April 2008
Dennab
August 2007
581 Posts
DarkSpider posted:
Or use the udp version and send data between servers and run a 128 man server!
Servers can't handle 64 players in GMod, nevermind 128.
 Post #35
 10th April 2008
DarkSpider's Avatar
July 2006
1,429 Posts
Mine can. As long as nobody is shooting. You only get minor lag but not really that bad.
 Post #36
 10th April 2008
Spacetech's Avatar
January 2006
879 Posts
Hexeh posted:
Servers can't handle 64 players in GMod, nevermind 128.
I was in one of his servers with 64players in it. It was fun.
 Post #37
 23rd April 2008
spbogie's Avatar
June 2006
186 Posts
I have modified the Lua files to fix the problems with using the sub-modules (socket.http, socket.ftp, etc...).

Required Changes:
Code:
moved socket.lua to /socket/socket.lua

added socket.lua
    includes /socket/*.lua in necessary order

changed /socket/mime.lua
    removed reqiure( "io" ) - unused, not available in gmod

changed /socket/smtp.lua
    Line 33: DOMAIN = os.getenv("SERVER_NAME") or "localhost"
        to: DOMAIN = "localhost"
    os.getenv not available in gmod
Calling require( "socket" ) will load all sub-modules as well.

Fix is available at http://people.msoe.edu/~bogies/luasocket_fix.zip.
Includes only modifications made, simply extract over existing install.
 Post #38
 1st May 2008
Fox682's Avatar
August 2005
229 Posts
Some folks at Wiremod.com are playing with this, and it seems to be working!
They've been transmitting Wire Values from one server to another!

But for now were testing it out. So far so good!

Keep up the great work!
 Post #39
 24th May 2008
MrPresident's Avatar
August 2007
188 Posts
I got this working on my Garrysmod locally, but unfortunately my dedicated server host doesn't have the VS2008 files, so this doesn't work for me on my hosted server. I was going to re-create a gmod version of HLSW so that I could monitor prop spawns and other garrysmod specific things that aren't sent with the log normally.

Does anyone know how I might go about getting this to work without my host installing the VS2008? Are there any lua files I can add to my garrysmod bin folder or anything?

Also, I saw someone mention an older gm_socket earlier in this thread, but alas I could not find this anywhere.

Thanks :)
 Post #40
 24th May 2008
Dennab
September 2005
5,541 Posts
You don't need to install VS2008, you just need the latest .dll's. I think with any recent service pack you should already have them.
Reply

All times are GMT. The time now is 12:41AM.

Facepunch Studios 2010 - Server 'MARGE'