AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Extensions (https://forums.alliedmods.net/forumdisplay.php?f=134)
-   -   [EXTENSION] Socket (3.0.1) (https://forums.alliedmods.net/showthread.php?t=67640)

sfPlayer 02-28-2008 00:22

[EXTENSION] Socket (3.0.1)
 
1 Attachment(s)
latest version: http://forums.alliedmods.net/attachm...chmentid=83286

This extension provides networking functionality for SourceMod scripts. It's a heavily modified fork of Olly's sockets extension 2.0.0.

It's supposed to be stable. If it crashes please post the srcds debug.log and the plugin's sourcecode which makes use of the socket extension.

You need at least SourceMod 1.0.3!

Look at socket.inc for development documentation.


Developer Notes
  • Make sure to use all 3 Set...Callback functions on sockets spawned by listen sockets before using the child sockets.
  • Don't use ports below 1024 for listening sockets due to permission restrictions on linux
  • Do not expect SocketConnect() and SocketSend() to be atomic operations, both might not have finished yet after they were executed. Always use the socket connect-callback as shown in the example to start sending data.
  • Don't forget to close the socket handle

Usage example


The example example.sp downloads a file via http to <modfolder>/dl.htm
The example listenexample.sp provides a simple echo server. Use telnet <serverip> 50000 to connect to it.
The examples are located at addons/sourcemod/scripting in the socket.zip file.


Changelog

Version 2.4.0+
  • check the git(web) shortlog (see sourcecode repository url)
Version 2.3.1
  • fixed an error handling bug
Version 2.3.0
  • Added SocketDisconnect()
  • fixed a crashbug on unload
  • fixed receiving binary data
  • improved error handling
  • stricter condition checking
  • fixed a possible race condition in SocketSetSendqueueEmptyCallback()
Version 2.2.0
  • Added optional SendqueueEmpty callback which allows an application to correctly close the connection after all data has been sent
  • Fixed SocketSend() calculating the packet size 1 byte too large if it was not specified explicitly (thx to olly for finding the bug)
Version 2.1.0
  • Added SocketSetOption()
  • Added optional packet/callback concatenation mechanism to reduze the amount of receive callbacks for large transfers
  • removed Metamod:Source dependency (-> AddGameFrameHook)
  • improved sending of large chunks of data
  • everything should be binary safe now (support for sending/receiving 0x00), read the documentation for details
  • moved sending and connecting into threads
  • a few bugfixes
Version 2.0.0
  • Added SocketBind() and SocketListen() -> listening socket support
  • major API change to unify and optimize the socket usage
  • some additional small changes
Version 1.0.0
  • initial public release

Sourcecode repository


http://player.to/gitweb/index.cgi?p=sm-ext-socket.git

- Clone my public repository:
git clone git://player.to/sm-ext-socket.git <directory>

Download

latest version:
http://forums.alliedmods.net/attachm...chmentid=83286

Extreme_One 02-28-2008 05:33

Re: [EXTENSION] Socket
 
So this is compatible with Olly's new IRCRelay v2.0.0 running on Linux?

sfPlayer 02-28-2008 05:58

Re: [EXTENSION] Socket
 
No, but I've modified it to be compatible.

IRCRelay somehow doesn't work, the initial IRC communication works (nickname, ping-pong, etc.) and it receives everything from the socket but doesn't respond back/react on commands. My debugging shows that it doesn't even call SocketSend() after it receives PRIVMSG, so it's a bug/configuration issue in the plugin and not in the extension.

p3tsin 02-28-2008 11:29

Re: [EXTENSION] Socket
 
Simply awesome. I'm running my cupbot with the extension :wink:.

A few questions tho:
1) In the include file, the native SetSocketArg takes any:arg but the forwards output it as Handle:arg ... why?
2) Does it support sending and receiving the \x00 char?

Good work. :up:

Olly 02-28-2008 13:26

Re: [EXTENSION] Socket
 
Quote:

Originally Posted by sfPlayer (Post 590788)
No, but I've modified it to be compatible.

IRCRelay somehow doesn't work, the initial IRC communication works (nickname, ping-pong, etc.) and it receives everything from the socket but doesn't respond back/react on commands. My debugging shows that it doesn't even call SocketSend() after it receives PRIVMSG, so it's a bug/configuration issue in the plugin and not in the extension.

Well i can tell you that its not the plugin lol, because it works with my sockets extension, and we have had it running for weeks.

All data being sent to the socket in ircrelay is queued, so that relays dont flood off the server.

Also this wont work with a local database, because you removed all of the md5 stuff from the extension.

What happened to BindSocket ?

sfPlayer 02-28-2008 20:08

Re: [EXTENSION] Socket
 
@p3tsin
1) I forgot to update these, output will also be any:arg soon
2) currently not, but i'll look into it

@olly
You are calling send with a closed socket, that can't work as expected (this only seems to happen on startup if somebody didn't set the irc_server cvar before, the irc-relay config seems to require manual execution through the server.cfg). I added additional checking to SocketSend if the socket is closed and it correctly throws an error.

The md5 stuff should go into another extension, it makes no sense to put it in here. You can also store the passwords unhased like you do for SQLite.

BindSocket will be back soon, including some more natives to create server applications on gameservers ;)

sfPlayer 02-29-2008 01:21

Re: [EXTENSION] Socket
 
Version 2 is out :)

kill0r 03-03-2008 03:20

Re: [EXTENSION] Socket
 
Wow, a stable socket-ext for win&lin, finally :D
great job btw

Olly 03-05-2008 12:37

Re: [EXTENSION] Socket (2.1.0)
 
I am going to stop my socket plugin, as yours has more features, more stable, etc....

So im converting IRC Relay to your ext, but it never gets past sending PONG :.....\n\r\n\r

I have checked if the socket is connected, etc, and it seems to be, but it seems your extension is not sending the packet. I have debugged my plugin as far as i can, and I see no problem with sending the 'pong' packet.

sfPlayer 03-05-2008 13:21

Re: [EXTENSION] Socket (2.1.0)
 
My extention is actually only an enhanced version of yours ;)

Please add debug output right before you call SocketSend() and use wireshark (or any other packet sniffer) to check if you actually call SocketSend() and the ext sends the packet.

If neither the error callback gets fired nor a native error gets triggered it's a bug, please send me the sourcecode for further investigation.


All times are GMT -4. The time now is 19:44.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.