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

[EXTENSION] Sockets (2.0.0)


Post New Thread Reply   
 
Thread Tools Display Modes
sskillz
Member
Join Date: Apr 2005
Old 05-17-2007 , 02:21   Re: [EXTENSION] Sockets
Reply With Quote #21

That will really be great.
sskillz is offline
sskillz
Member
Join Date: Apr 2005
Old 05-26-2007 , 09:04   Re: [EXTENSION] Sockets
Reply With Quote #22

Whats going on with those callbacks ? Sorry, I just have a plugin that I made for amxmodx I have to port to souce which uses sockets, and it must know if a socket closed.
sskillz is offline
sskillz
Member
Join Date: Apr 2005
Old 06-12-2007 , 06:21   Re: [EXTENSION] Sockets
Reply With Quote #23

Hello, Again
This time I tried editing the Socket Extension you made, Here is what I did:

* Added cell_t data type to the Smsocket_t structure like this:
Code:
typedef struct
{
	int socket;
	unsigned int protocol;
	IPluginContext *pCtnxt;
	bool isConnected;
	cell_t errorcallback;
	cell_t disconnectcallback;
	cell_t receivedcallback;
	cell_t receiveddata;
}Smsocket_t;
* After the select call, where you check if the receive is 0, I added to call the disconnection callback, because as I rember if the reading after the socket is 0 than the socket needs to be closed because of the remote peer closing it:

Code:
			if(rcvsize == 0) {
			    //Means Socket has CLOSED  on the other side!
				lSockets[i]->isConnected = false;
				closesocket(lSockets[i]->socket);
				if(&lSockets[i] != NULL)
				{
					if(lSockets[i]->disconnectcallback > -1)
					{
					    //Call disconnect callback function
						IPluginFunction *pF = lSockets[i]->pCtnxt->GetFunctionById(lSockets[i]->disconnectcallback);
						cell_t retrn;
						pF->Execute(&retrn);
					}
				}
				return;
			}
* Added two more natives:
1) A native to set the disconnection call back:

Code:
// native SetDisconnectCallback(socket, Function);
cell_t SetDisconnectCallback(IPluginContext *pContext, const cell_t *params)
{
	lSockets[params[1]]->disconnectcallback = params[2];
	return 1;
}
2) A native to check if the socket is connected (maybe not needed...):

Code:
// native IsSocketConnected(socket, Function);
cell_t IsSocketConnected(IPluginContext *pContext)
{
	if(lSockets[params[1]]->IsConnected) { return 1; }
	return 0;
}
For this I also added that if a socket is closed, after a error, if there is a disconnection, or by a user, changes this Bool value to false.


--------------------


Thats the things I changed, I think it should work, Now can someone please compile it for linux, for me?

Thanks ahead.
Attached Files
File Type: rar sockets_src2.rar (23.5 KB, 172 views)

Last edited by sskillz; 06-12-2007 at 08:41.
sskillz is offline
Olly
Senior Member
Join Date: Mar 2007
Location: UK
Old 06-12-2007 , 13:32   Re: [EXTENSION] Sockets
Reply With Quote #24

Hehehe, nice...

Sorry its taken so long for me to get round to fixing this (i still have a big re-write planned for this) but i have been busy getting sourcebans.net ready for the SM release
__________________
Tumblr Me: http://raspberryteen.tumblr.com


// Yarrrr!
Olly is offline
Send a message via MSN to Olly
sskillz
Member
Join Date: Apr 2005
Old 06-12-2007 , 14:20   Re: [EXTENSION] Sockets
Reply With Quote #25

No problam , sourcebans.net looks nice, Is theres more info about it?

--------
Back to the subject:

So my code will work? :\ (I dont know C++, but I know some other languages..)

If so can you compile my last attachment for the meanwhile?
I know you are planning to rewrite it, and when that happen, ill rewrite my plugin also.

Thanks.
sskillz is offline
Olly
Senior Member
Join Date: Mar 2007
Location: UK
Old 06-13-2007 , 07:00   Re: [EXTENSION] Sockets
Reply With Quote #26

I cant compile it now (dont have VisStudio installed) but no. you wont need to rewrite your plugin. All of the natives will stay the same, and there may be some new ones. 1 thing though, is i am planning on adding Handle support. So you will need to convert any cell index's to Handles

Uhmm, we dont really have any more infomation than its going to be like AMXbans for SourceMod.. Im sure Viper will add some more details soon
__________________
Tumblr Me: http://raspberryteen.tumblr.com


// Yarrrr!
Olly is offline
Send a message via MSN to Olly
Olly
Senior Member
Join Date: Mar 2007
Location: UK
Old 06-16-2007 , 20:29   Re: [EXTENSION] Sockets
Reply With Quote #27

Update - v1.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
  • Re-worked all of the pointer checks because it was horrible in the last version.
Check first post for download

If you have already started making a plugin with Sockets; you will need to make some small changes to the code to get it to work with this version.
  • All callbacks now have an extra arguement (Handle:arg)
    • This is used for internally identifying which socket called the callback if you have more than one socket running in the plugin at once. You can set the arg that will be passed to the callbacks using SetArg native. SetArg should ideally be called before the SocketSend.
  • CreateSocket now returns a Handle:socket which needs to be passed to the first param of any of the related natives. So where before you just had a cell_t you now have a Handle_t
  • You can now call SetConnectedCallback & SetDisconnectCallback Which will obviously trigger a callback when the socket connects, and when it disconnects
I have only tested this on windows, but Hopefully the bugs in linux should be fixed too.

__________________
Tumblr Me: http://raspberryteen.tumblr.com


// Yarrrr!

Last edited by Olly; 06-16-2007 at 20:48.
Olly is offline
Send a message via MSN to Olly
SirCole
Member
Join Date: Nov 2006
Old 06-16-2007 , 22:27   Re: [EXTENSION] Sockets
Reply With Quote #28

yay!
SirCole is offline
sskillz
Member
Join Date: Apr 2005
Old 06-17-2007 , 05:33   Re: [EXTENSION] Sockets
Reply With Quote #29

Great! Thanks a lot!
sskillz is offline
SebiTimeWaster
Junior Member
Join Date: Jun 2007
Old 06-17-2007 , 05:43   Re: [EXTENSION] Sockets
Reply With Quote #30

hi,

when im compiling your example (from the first page), i get the following warnings:

Quote:
test.sp(5 : warning 213: tag mismatch
test.sp(59) : warning 213: tag mismatch
test.sp(62) : warning 213: tag mismatch
test.sp(65) : warning 213: tag mismatch
test.sp(6 : warning 213: tag mismatch
what does that mean?
SebiTimeWaster 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 14:32.


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