Raised This Month: $51 Target: $400
 12% 

[EXTENSION] Sockets (2.0.0)


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Olly
Senior Member
Join Date: Mar 2007
Location: UK
Old 04-30-2007 , 16:27   [EXTENSION] Sockets (2.0.0)
Reply With Quote #1

Hi,
I have made this extension so that your server can communicate with other servers, and send and receive data between them. This can be used for downloading through HTTP, creating an irc bot, querying another game server.. List goes on

Any bugs then get me in #sourcemod

Credits:
BAILOPAN, PimpinJuice, devicenull, and anyone else i missed from #sourcemod

Install:
1. Extract 'sockets.ext.dll' to the 'addons/sourcemod/extensions' folder.
2. Extract 'sockets.inc' to the 'addons/sourcemod/scripting/include' folder.


WINDOWS ONLY AT THE MOMENT, LINUX WILL BE TOMOROW


Changed Natives:

/**
* Creates a new socket.
*
* @param protocol The type of socket to create, TCP (default), or UDP
* @param SocketRecieve:rfunc The recieve callback.
* @param SocketError:efunc The error callback.
* @return Handle The socket handle. Returns INVALID_HANDLE on failure
*/
native Handle:CreateSocket(SocketType:protocol=SOCKE T_TCP, SocketRecieve:rfunc, SocketError:efunc);

This has now changed, the SocketRecive, and SocketError callbacks are now paramaters of this native.


/**
* Convert a string to an MD5 hash (used for irc-relay)
*
* @param String:input The input string
* @param Stringutput The output string
* @param size The length of the output buffer
*/
native md5HashString(String:in[], Stringut[], size);

This has nothing todo with sockets, but i needed in in IRC-Relay because SQLite sucks balls



public(String:recieveData[], const dataSize, Handle:arg)

The socketrevieve callback signature is now as above


Plugin Example
I couldnt be bothered to write a new example plugin. But you can check my new IRC Relay which i will be posting after this.

Enjoy

Change Log
Quote:
1.0.0.0
  • Initial Release
1.0.0.1
  • Minor changes (never released)
1.0.1.0
  • Huge overhaull of everything in the plugin (consider this the first release)
1.0.2.0
  • Fixed lots of null pointer crashes ><
  • Fixed the native name in the include for SocketClose
  • Fixed functag
  • Compiled for linux
1.2.0.0
  • Skipped a load of version numbers (because i can)
  • Added SetConnectedCallback, and SetDisconnectCallback
  • CreateSocket now returns a Handle type which needs to be passed to all natives
  • Removed lots of the BS comments
  • Hopefully fixed lots of crashes in linux
  • Added arg argument for all callbacks to identify the socket that called back
2.0.0
  • Fixed lots of bugs
  • Fixed problem with the way i setup the callbacks (thanks bailo)
  • Changed the way that the natives work, less 'set callack' natives, so it works much better
  • The SocketReceive native now has the data that was got from the socket in one of the paramaters, instead of needing to specify a global string of a fixed size.
  • Compiled for Orange-Box
Attached Files
File Type: zip sockets_src.zip (1.11 MB, 543 views)
File Type: zip sockets_v2.0.zip (223.1 KB, 582 views)
File Type: zip sockets_v2.0-OrangeBox.zip (222.8 KB, 484 views)

Last edited by Olly; 02-13-2008 at 15:25. Reason: Because i can
Olly is offline
Send a message via MSN to Olly
API
Veteran Member
Join Date: May 2006
Old 04-30-2007 , 21:37   Re: [EXTENSION] Sockets
Reply With Quote #2

Great job
I will probably find some use for it soon.
API is offline
Send a message via AIM to API
sslice
Senior Member
Join Date: Feb 2005
Location: Texas, USA
Old 04-30-2007 , 21:49   Re: [EXTENSION] Sockets
Reply With Quote #3

Nice, although I would like to see this implemented in a more SM-ish way. Using a Handle and then some callbacks for the different socket interactions like connect, disconnect, receive, maybe error, etc.

Edit: Also maybe use the same naming convention used in SourceMod, rather than all lowercase and underscores.

Last edited by sslice; 04-30-2007 at 22:29.
sslice is offline
Olly
Senior Member
Join Date: Mar 2007
Location: UK
Old 05-01-2007 , 07:38   Re: [EXTENSION] Sockets
Reply With Quote #4

Quote:
Originally Posted by sslice View Post
Nice, although I would like to see this implemented in a more SM-ish way. Using a Handle and then some callbacks for the different socket interactions like connect, disconnect, receive, maybe error, etc.

Edit: Also maybe use the same naming convention used in SourceMod, rather than all lowercase and underscores.
As i said in my first post, this was just the basics that are implimented in the origional sockets extension. I will start to add more advanced things in the near future. But i just wanted to release the basics first, so if anyone needs, they can start writing the plugin sooner rather than later.

But I will be adding callbacks and handles soon
Olly is offline
Send a message via MSN to Olly
API
Veteran Member
Join Date: May 2006
Old 05-01-2007 , 09:43   Re: [EXTENSION] Sockets
Reply With Quote #5

No nix'? If you need help with nix build, ask me.
API is offline
Send a message via AIM to API
Olly
Senior Member
Join Date: Mar 2007
Location: UK
Old 05-04-2007 , 18:32   Re: [EXTENSION] Sockets
Reply With Quote #6

Ok I am doing a major reworking of this plugin.

* Callbacks
* Seperate connect & open socket
* Fixed naming (sslice )
* Added bind
* Gonna add some stuff i havnt written yet
* And i have linux now, so i will be able to provide one when the time comes

Lets just call the current extension a practice run
Olly is offline
Send a message via MSN to Olly
sslice
Senior Member
Join Date: Feb 2005
Location: Texas, USA
Old 05-05-2007 , 00:25   Re: [EXTENSION] Sockets
Reply With Quote #7

Possibly add accept and listen as well? Might not want to give plugins the ability to serve connections though.
__________________
sslice is offline
Olly
Senior Member
Join Date: Mar 2007
Location: UK
Old 05-05-2007 , 20:08   Re: [EXTENSION] Sockets
Reply With Quote #8

added to my todo list

A little note.
This extension is going to change quite drasticly in the next version. So at the moment, pretend this extension isnt here
Olly is offline
Send a message via MSN to Olly
Olly
Senior Member
Join Date: Mar 2007
Location: UK
Old 05-05-2007 , 22:01   Re: [EXTENSION] Sockets
Reply With Quote #9

These are the revised natives for Sockets Ext. There is no more recieve native, because receiving data is handled internally by the extension, but when data is received it will call the recieve callback so stuff can be done to the received data.

I still have some more functions to add, but cant think of them off hand right now, its like 3am


Code:
// Error type codes
#define EMPTY_HOST 1
#define NO_HOST 2
#define CONNECT_ERROR 3
#define SEND_ERROR 4
#define BIND_ERROR 5
// Protocols
#define SOCKET_TCP 1
#define SOCKET_UDP 2
 #define SOCKET_RAW 3

funcenum SocketError
{
    public(errorType, errorNum)
};

funcenum SocketRecieve
{
    // Not decided yet ><
};

/**
 * Creates a new socket.
 *
 * @param    protocol            The type of socket to create, TCP (default), or UDP
 * @return    socket                The socket id (handle).
 */
native CreateSocket(protocol=SOCKET_TCP);

/**
 * Closes the specified socket.
 *
 * @param    socket                The id (handle) of the socket to close.
 */
native CloseSocket(socket);

/**
 * Defines the callback function when an error occurs
 *
 * @param    socket                The id (handle) of the socket to set the callback for.
 * @param    function            The function to use as callback.
 */
native SetErrorCallback(socket, function);

/**
 * Defines the callback function for when data is received though the socket
 *
 * @param    socket                The id (handle) of the socket to set the callback for.
 * @param    function            The function to use as callback.
 */
native SetReceiveCallback(socket, function);

/**
 * Defines the callback function when an error occurs
 *
 * @param    socket                The id (handle) of the socket to connect.
 * @param    hostname            The hostname (or IP) to connect to.
 * @param    port                The port to connect to.
 * @return  true on success
 */
native ConnectSocket(socket, String:hostname[], port);

/**
 * Binds the socket to a local address
 *
 * @param    socket                The id (handle) of the socket to connect.
 * @param    hostname            The hostname (or IP) to bind the socket to.
 * @param    port                The port to bind the socket to.
 * @return  true on success
 */
native SocketBind(socket, String:hostname[], port);

/**
 * Sends a command through the socket.
 *
 * @param    socket            The id (handle) of the socket to send to.
 * @param    command            The command to send to the server.
 * @return                    The length of data sent.
 */
native SocketSend(socket, String:command[]);

Last edited by Olly; 05-05-2007 at 22:09.
Olly is offline
Send a message via MSN to Olly
devicenull
Veteran Member
Join Date: Mar 2004
Location: CT
Old 05-05-2007 , 23:28   Re: [EXTENSION] Sockets
Reply With Quote #10

Use handles!

I have some code that uses them, grab me on IRC.
__________________
Various bits of semi-useful code in a bunch of languages: http://code.devicenull.org/
devicenull is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


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


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