SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Plugin Development

Reply
 
Thread Tools Display Modes
Old 16/06/2011, 02:18 AM   #1
langricr
Big Clucker
 
langricr's Avatar
 
Join Date: Jun 2011
Location: Bowmanville, Ontario
Posts: 73
Reputation: 1
Default WinSock Plugin - Beta 1.2

WinSock Plugin - Beta 1.2
This plugin is a functioning, windows-only socket plugin I designed as per a friend's request. This plugin uses assigned IDs to manage multiple connections simultaneously, it uses threading for reading and listening and the main thread for sending data and connecting.
This plugin supports only one connection per socket at any given time, once a connection is accepted by a listening socket it will turn into an active socket, an active socket must be disconnected before it can connect or listen for another connection.

Big credit to StrickenKid for releasing the source to some of his work, an effective tutorial in its own rights.

This version only works under Windows operating systems with support for WinSock 2.2. Modifying it to be cross-platform compatible is currently being considered.
Functions
pawn Code:
native socket_create( id );
// Used to create a socket to be used by the plugin, only one socket with this ID can be used at any given time.

native socket_destroy( id );
// Used to destroy a socket, this will first call the disconnect function and then the ID will be available for use again.

native socket_connect( id, ip[], port);
// Used to make the inactive socket connect to a remote IP address's port.

native socket_disconnect( id );
// Used to make an active socket close.

native socket_send( id, data[] );
// Used to send data over an active socket.

native socket_listen( id, port );
// Used to make the socket listen for an incoming connection on the specified port.

native socket_stoplisten( id );
// Used to make the socket stop listening.

native socket_id_available( id );
// Returns true if the ID is not in use, false otherwise.

native socket_isactive( id );
// Returns true if the ID is in use, false if otherwise or not found

native socket_islistening( id );
// Returns true if the ID is listening, false if otherwise or not found

native socket_getbuffersize( id );
// Returns the size of the socket's buffer

native socket_setbuffersize( id, size );
// Returns true if the buffer size has been set, false otherwise or not found

native socket_cleanstring( source[], dest[] );
// Creates a copy of the source string with all non-printable characters stripped.

Callbacks
pawn Code:
forward onSocketConnect( id, ip[], port );
// Called when a socket connects to a remote host, or when a listening socket accepts a connection and becomes an active socket. The IP and port belong to the remote host.

forward onSocketDisconnect( id );
// Called when a socket disconnects, either on the host or server's end.

forward onSocketReceive( id, data[] );
// Called when a socket receives data from the remote host.



Changelog
Version 1.2
  • + added the ability to specify the buffer size per socket
  • + added socket_getbuffersize( id )
  • + added socket_setbuffersize( id, size )
  • + added a function to return a string stripped of non-printable characters
  • + added socket_cleanstring( source[], dest[] )
  • - removed automatic filtration of non-printable characters
  • - removed a debug message that got left in version 1.1

Version 1.1
  • + added ProcessTick support
  • + added socket_isactive( id )
  • + added socket_islistening( id )
  • + added some comments to the SampSocket class, planning more
  • + added credit where credit is due
  • = moved the core code around a lot




Current Version
SampWinSock 1.2

Older Versions
SampWinSock 1.1
SampWinSock 1.0

Last edited by langricr; 17/06/2011 at 03:46 AM. Reason: Version 1.2 + Better image
langricr is offline   Reply With Quote
Old 16/06/2011, 02:24 AM   #2
Deskoft
Guest
 
Posts: n/a
Default Re: SAMP WinSock Plugin - Beta

This is AWESOME, excellent job, completely intelligent.
Can you release the source of the plugin?
  Reply With Quote
Old 16/06/2011, 02:25 AM   #3
langricr
Big Clucker
 
langricr's Avatar
 
Join Date: Jun 2011
Location: Bowmanville, Ontario
Posts: 73
Reputation: 1
Default Re: SAMP WinSock Plugin - Beta

Quote:
Originally Posted by Deskoft View Post
This is AWESOME, excellent job, completely intelligent.
Can you release the source of the plugin?
The source project is contained within the archive, it was created with Visual Studio 2010, so that would be the easiest solution to opening it.
langricr is offline   Reply With Quote
Old 16/06/2011, 02:27 AM   #4
Deskoft
Guest
 
Posts: n/a
Default Re: SAMP WinSock Plugin - Beta

Thanks for this release, I plan making a remote rcon with custom commands with this.
  Reply With Quote
Old 16/06/2011, 02:32 AM   #5
langricr
Big Clucker
 
langricr's Avatar
 
Join Date: Jun 2011
Location: Bowmanville, Ontario
Posts: 73
Reputation: 1
Default Re: SAMP WinSock Plugin - Beta

Quote:
Originally Posted by Deskoft View Post
Thanks for this release, I plan making a remote rcon with custom commands with this.
No problem

The whole reason I made this was so me and said friend could design a network protocol and create scripts in other languages, the server would run a bare script that executes functions based on the packets received through the connection to a server made in another language.
langricr is offline   Reply With Quote
Old 16/06/2011, 02:38 AM   #6
Deskoft
Guest
 
Posts: n/a
Default Re: SAMP WinSock Plugin - Beta

Quote:
Originally Posted by langricr View Post
No problem

The whole reason I made this was so me and said friend could design a network protocol and create scripts in other languages, the server would run a bare script that executes functions based on the packets received through the connection to a server made in another language.
This can be widely used, although it's not that safe, it can be compared to the TCP/IP system in batch, basic, but very useful.
  Reply With Quote
Old 16/06/2011, 02:51 AM   #7
Ricop522
High-roller
 
Ricop522's Avatar
 
Join Date: Feb 2010
Location: ES
Posts: 2,696
Reputation: 149
Default Re: SAMP WinSock Plugin - Beta

This is AWESOME, excellent job, completely intelligent.²
__________________
"Any fool can write code that a
computer can understand. Good
programmers write code that
humans can understand."

Sistemas de Informação, IFES
Ricop522 is offline   Reply With Quote
Old 16/06/2011, 03:09 AM   #8
StrickenKid
Gangsta
 
Join Date: Feb 2009
Posts: 778
Reputation: 39
Default Re: SAMP WinSock Plugin - Beta

I can see you've stolen code, and the basic architecture from my sockets plugin.
__________________
StrickenKid is offline   Reply With Quote
Old 16/06/2011, 03:17 AM   #9
langricr
Big Clucker
 
langricr's Avatar
 
Join Date: Jun 2011
Location: Bowmanville, Ontario
Posts: 73
Reputation: 1
Default Re: SAMP WinSock Plugin - Beta

Quote:
Originally Posted by StrickenKid View Post
I can see you've stolen code, and the basic architecture from my sockets plugin.
Yes, I did use part of your code as a reference having rarely programmed in C++ before, but when my friend mentioned that your plugin failed to operate and that you weren't willing to repair it ( on top of it only supporting one socket), I opted to create a replacement. The only code I explicitly copied was the GetString method and the basic callback loop when locating amx methods. Other than that, please point out how I've stolen your "basic architecture".
langricr is offline   Reply With Quote
Old 16/06/2011, 03:43 AM   #10
StrickenKid
Gangsta
 
Join Date: Feb 2009
Posts: 778
Reputation: 39
Default Re: SAMP WinSock Plugin - Beta

I'm not going to waste my time over this, but if you put both the projects side by side and compare.... It looks like you've just changed a few things around, changed the order of some functions, and added the functionality of multiple connections.... I've also noticed some problems with yours which will drastically affect the operation of it.

But all that aside, you should have at least given me credit, or even asked for permission... You have just copied code from my work.

Also,

Code:
/**
 *     SA:MP WinSock
 *  (c) Copyright 2010, <__Ethan__>
 *
 **/

#if defined _winsock_inc
	#endinput
#endif

#define _winsock_inc
#pragma library winsock

// plugin natives

native socket_create( id );
native socket_destroy( id );
native socket_id_available( id );

native socket_connect( id, ip[], port);
native socket_disconnect( id );

native socket_listen( id, port );
native socket_stoplisten( id );
native socket_send( id, data[] );

// plugin callbacks
forward onSocketConnect( id, ip[], port );
forward onSocketDisconnect( id );
forward onSocketReceive( id, data[] );
Your include has my copyright?
__________________
StrickenKid is offline   Reply With Quote
Reply

Thread Tools
Display Modes

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
[FilterScript] [FS] IRC Administrator and Echo FS for Jacobs IRC plugin (using zcmd beta) Zezombia Filterscripts 100 21/06/2014 02:39 PM
[Plugin] MapAndreas plugin v1.0 beta Kalcor Plugin Development 256 17/05/2014 09:31 PM
[Plugin] [BETA] SA:MP Sockets Plugin StrickenKid Plugin Development 99 10/02/2013 06:29 PM
[BETA] SA:MP Sockets Plugin SPAWN_METAL Русский/Russian 2 10/05/2011 07:11 AM
Where can i get the beta of samp 0.3 ? reashaun14 Client Support 1 20/09/2009 11:53 PM


All times are GMT. The time now is 02:31 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.