Raised This Month: $ Target: $400
 0% 

Keeping socket open beyong map changes


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Horst Arnold
Junior Member
Join Date: Jan 2013
Old 01-27-2013 , 11:42   Keeping socket open beyong map changes
Reply With Quote #1

Hi,

so I'm using the default sockets module to create a TCP connection to an IRC server.

(The socket object is declared globally at the beginning of the script, the socked is opened in plugin_init() or via console command.)

Now when the map changes, apparently the entire plugin is reloaded, resulting in the socket being closed (?) and reopened on the next map.

How can I keep the socket open on map changes and maintain the connection continuously?

Obviously, I don't want to have the IRC bot reconnect whenever the map is changed.

Thank you for your input and any hints you can share with me.
Horst Arnold is offline
Sylwester
Veteran Member
Join Date: Oct 2006
Location: Poland
Old 01-27-2013 , 13:11   Re: Keeping socket open beyong map changes
Reply With Quote #2

Check IRC Server :). It says in description that you don't lose connection on mapchange, so see how hackziner coded it.
__________________
Impossible is Nothing
Sylwester is offline
Horst Arnold
Junior Member
Join Date: Jan 2013
Old 01-27-2013 , 13:38   Re: Keeping socket open beyong map changes
Reply With Quote #3

Thank you for your reponse.

I've studied the code (as well as the code of two other IRC client plugins) but I'm unable to figure out what's to be done differently. :(
Horst Arnold is offline
Horst Arnold
Junior Member
Join Date: Jan 2013
Old 01-28-2013 , 13:17   Re: Keeping socket open beyong map changes
Reply With Quote #4

Alright, someone on the AMXX IRC channel pointed out that the socket object is stored in a cvar which then is accessed after the map has changed.

So the basic code is something along these lines:

PHP Code:
public plugin_init() {
   
// (...)
   
register_cvar("irc_socket""8888"FCVAR_PROTECTED FCVAR_UNLOGGED); // note: the flags are taken from the other IRC plugins
   
irc_connect();
}

public 
irc_connect() {
   if (
get_cvar_num("irc_socket") == 8888) {
      
sock socket_open(SERVERPORTSOCKET_TCPerror);
      
set_cvar_num("irc_socket"sock);
   }
   else {
      
sock get_cvar_num("irc_socket");
   }


Last edited by Horst Arnold; 01-28-2013 at 13:33.
Horst Arnold is offline
Old 01-28-2013, 13:32
Horst Arnold
This message has been deleted by Horst Arnold.
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 01-28-2013 , 20:31   Re: Keeping socket open beyong map changes
Reply With Quote #5

So, is that the answer to your question then? If yes, this means that the socket is not closed on map change by default I guess.
__________________
fysiks is offline
Horst Arnold
Junior Member
Join Date: Jan 2013
Old 01-29-2013 , 11:01   Re: Keeping socket open beyong map changes
Reply With Quote #6

Yes, that was the answer to my question, I'm sorry if I wasn't being clear enough.

In my initial post I said "resulting in the socket being closed (?)" because I suspected it wasn't an accurate description.

I guess you could say that the socket is not closed but you just lose its handle which you store in a cvar.
Horst Arnold 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 20:31.


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