diff options
Diffstat (limited to 'irc.c')
| -rw-r--r-- | irc.c | 106 | 
1 files changed, 85 insertions, 21 deletions
| @@ -28,8 +28,11 @@  #include "sock.h"  #include "crypting.h"  #include "ipc.h" +#include <sys/types.h> +#include <sys/wait.h>  static gboolean irc_userping( gpointer _irc, int fd, b_input_condition cond ); +static void irc_welcome( irc_t *irc );  GSList *irc_connection_list = NULL; @@ -134,20 +137,24 @@ irc_t *irc_new( int fd )  	irc_write( irc, ":%s NOTICE AUTH :%s", irc->myhost, "BitlBee-IRCd initialized, please go on" );  	irc_connection_list = g_slist_append( irc_connection_list, irc ); -	 -	set_add( &irc->set, "away_devoice", "true",  set_eval_away_devoice, irc ); +  	set_add( &irc->set, "auto_connect", "true", set_eval_bool, irc );  	set_add( &irc->set, "auto_reconnect", "false", set_eval_bool, irc );  	set_add( &irc->set, "auto_reconnect_delay", "300", set_eval_int, irc );  	set_add( &irc->set, "buddy_sendbuffer", "false", set_eval_bool, irc );  	set_add( &irc->set, "buddy_sendbuffer_delay", "200", set_eval_int, irc );  	set_add( &irc->set, "charset", "utf-8", set_eval_charset, irc ); +	set_add( &irc->set, "color_encrypted", "true", set_eval_bool, irc );  	set_add( &irc->set, "debug", "false", set_eval_bool, irc );  	set_add( &irc->set, "default_target", "root", NULL, irc );  	set_add( &irc->set, "display_namechanges", "false", set_eval_bool, irc );  	set_add( &irc->set, "handle_unknown", "root", NULL, irc ); +	set_add( &irc->set, "halfop_buddies", "encrypted", set_eval_halfop_buddies, irc );  	set_add( &irc->set, "lcnicks", "true", set_eval_bool, irc ); -	set_add( &irc->set, "ops", "both", set_eval_ops, irc ); +	set_add( &irc->set, "op_buddies", "trusted", set_eval_op_buddies, irc ); +	set_add( &irc->set, "op_root", "true", set_eval_op_root, irc ); +	set_add( &irc->set, "op_user", "true", set_eval_op_user, irc ); +	set_add( &irc->set, "otr_policy", "opportunistic", set_eval_otr_policy, irc );  	set_add( &irc->set, "password", NULL, passchange, irc );  	set_add( &irc->set, "private", "true", set_eval_bool, irc );  	set_add( &irc->set, "query_order", "lifo", NULL, irc ); @@ -157,8 +164,11 @@ irc_t *irc_new( int fd )  	set_add( &irc->set, "strip_html", "true", NULL, irc );  	set_add( &irc->set, "to_char", ": ", set_eval_to_char, irc );  	set_add( &irc->set, "typing_notice", "false", set_eval_bool, irc ); +	set_add( &irc->set, "voice_buddies", "notaway",  set_eval_voice_buddies, irc );  	conf_loaddefaults( irc ); + +	irc->otr = otr_new();  	/* Evaluator sets the iconv/oconv structures. */  	set_eval_charset( set_find( &irc->set, "charset" ), set_getstr( &irc->set, "charset" ) ); @@ -312,6 +322,8 @@ void irc_free( irc_t * irc )  	g_free( irc->last_target ); +	otr_free(irc->otr); +	  	g_free( irc );  	if( global.conf->runmode == RUNMODE_INETD || @@ -684,12 +696,45 @@ void irc_write_all( int now, char *format, ... )  	return;  }  +const char *user_mode_prefix( irc_t *irc, user_t *u ) +{ +	static char op[] = "@"; +	static char halfop[] = "%"; +	static char voice[] = "+"; +	static char none[] = ""; + +	int or = set_getbool(&irc->set, "op_root"); +	int ou = set_getbool(&irc->set, "op_user"); +	char *ob = set_getstr(&irc->set, "op_buddies"); +	char *hb = set_getstr(&irc->set, "halfop_buddies"); +	char *vb = set_getstr(&irc->set, "voice_buddies"); + +	if( (!strcmp(u->nick, irc->mynick) && or) || +	    (!strcmp(u->nick, irc->nick) && ou) || +        (!u->away && !strcmp(ob, "notaway")) || +        (u->encrypted && !strcmp(ob, "encrypted")) || +        (u->encrypted>1 && !strcmp(ob, "trusted")) +      ) +		return op; +	else if( (!u->away && !strcmp(hb, "notaway")) || +             (u->encrypted && !strcmp(hb, "encrypted")) || +             (u->encrypted>1 && !strcmp(hb, "trusted")) +	       ) +		return halfop; +	else if( (!u->away && !strcmp(vb, "notaway")) || +             (u->encrypted && !strcmp(vb, "encrypted")) || +             (u->encrypted>1 && !strcmp(vb, "trusted")) +	       ) +		return voice; +	else +		return none; +} +			  void irc_names( irc_t *irc, char *channel )  {  	user_t *u;  	char namelist[385] = "";  	struct groupchat *c = NULL; -	char *ops = set_getstr( &irc->set, "ops" );  	/* RFCs say there is no error reply allowed on NAMES, so when the  	   channel is invalid, just give an empty reply. */ @@ -704,12 +749,7 @@ void irc_names( irc_t *irc, char *channel )  				*namelist = 0;  			} -			if( u->ic && !u->away && set_getbool( &irc->set, "away_devoice" ) ) -				strcat( namelist, "+" ); -			else if( ( strcmp( u->nick, irc->mynick ) == 0 && ( strcmp( ops, "root" ) == 0 || strcmp( ops, "both" ) == 0 ) ) || -			         ( strcmp( u->nick, irc->nick ) == 0 && ( strcmp( ops, "user" ) == 0 || strcmp( ops, "both" ) == 0 ) ) ) -				strcat( namelist, "@" ); -			 +			strcat( namelist, user_mode_prefix(irc, u) );  			strcat( namelist, u->nick );  			strcat( namelist, " " );  		} @@ -720,8 +760,8 @@ void irc_names( irc_t *irc, char *channel )  		/* root and the user aren't in the channel userlist but should  		   show up in /NAMES, so list them first: */ -		sprintf( namelist, "%s%s %s%s ", strcmp( ops, "root" ) == 0 || strcmp( ops, "both" ) ? "@" : "", irc->mynick, -		                                 strcmp( ops, "user" ) == 0 || strcmp( ops, "both" ) ? "@" : "", irc->nick ); +		sprintf( namelist, "%s%s %s%s ", set_getbool(&irc->set, "op_root") ? "@" : "", irc->mynick, +		                                 set_getbool(&irc->set, "op_user") ? "@" : "", irc->nick );  		for( l = c->in_room; l; l = l->next ) if( ( u = user_findhandle( c->ic, l->data ) ) )  		{ @@ -731,6 +771,7 @@ void irc_names( irc_t *irc, char *channel )  				*namelist = 0;  			} +			strcat( namelist, user_mode_prefix(irc, u) );  			strcat( namelist, u->nick );  			strcat( namelist, " " );  		} @@ -772,12 +813,11 @@ void irc_login( irc_t *irc )  	irc_reply( irc,   2, ":Host %s is running BitlBee " BITLBEE_VERSION " " ARCH "/" CPU ".", irc->myhost );  	irc_reply( irc,   3, ":%s", IRCD_INFO );  	irc_reply( irc,   4, "%s %s %s %s", irc->myhost, BITLBEE_VERSION, UMODES UMODES_PRIV, CMODES ); -	irc_reply( irc,   5, "PREFIX=(ov)@+ CHANTYPES=#& CHANMODES=,,,%s NICKLEN=%d NETWORK=BitlBee CASEMAPPING=rfc1459 MAXTARGETS=1 WATCH=128 :are supported by this server", CMODES, MAX_NICK_LENGTH - 1 ); +	irc_reply( irc,   5, "PREFIX=(ohv)@%%+ CHANTYPES=#& CHANMODES=,,,%s NICKLEN=%d NETWORK=BitlBee CASEMAPPING=rfc1459 MAXTARGETS=1 WATCH=128 :are supported by this server", CMODES, MAX_NICK_LENGTH - 1 );  	irc_motd( irc );  	irc->umode[0] = '\0';  	irc_umode_set( irc, "+" UMODE, 1 ); - -	u = user_add( irc, irc->mynick ); +u = user_add( irc, irc->mynick );  	u->host = g_strdup( irc->myhost );  	u->realname = g_strdup( ROOT_FN );  	u->online = 1; @@ -799,12 +839,7 @@ void irc_login( irc_t *irc )  	u->online = 1;  	irc_spawn( irc, u ); -	irc_usermsg( irc, "Welcome to the BitlBee gateway!\n\n" -	                  "If you've never used BitlBee before, please do read the help " -	                  "information using the \x02help\x02 command. Lots of FAQs are " -	                  "answered there.\n" -	                  "If you already have an account on this server, just use the " -	                  "\x02identify\x02 command to identify yourself." ); +	irc_welcome( irc );  	if( global.conf->runmode == RUNMODE_FORKDAEMON || global.conf->runmode == RUNMODE_DAEMON )  		ipc_to_master_str( "CLIENT %s %s :%s\r\n", irc->host, irc->nick, irc->realname ); @@ -822,6 +857,35 @@ void irc_login( irc_t *irc )  	}  } +static void irc_welcome( irc_t *irc ) +{ +	FILE *f; +	 +	f = fopen( global.conf->welcomefile, "r" ); +	if( !f ) +	{ +		irc_usermsg( irc, "Welcome to the BitlBee gateway!\n\n" +	        	          "If you've never used BitlBee before, please do read the help " +		                  "information using the \x02help\x02 command. Lots of FAQs are " +		                  "answered there.\n" +				  "OTR users please note: Private key files are owned by the user " +				  "BitlBee is running as.\n" +		                  "If you already have an account on this server, just use the " +		                  "\x02identify\x02 command to identify yourself." ); +	} +	else +	{ +		char linebuf[380]; +		 +		while( fgets( linebuf, 380, f ) ) +		{ +			irc_usermsg( irc, linebuf ); +		} +		 +		fclose( f ); +	} +} +  void irc_motd( irc_t *irc )  {  	int fd; | 
