Index: irc.c
===================================================================
--- irc.c	(revision 823de9d44f262ea2364ac8ec6a1e18e0f7dab658)
+++ irc.c	(revision 435f55271b09102e21228a7add1b897025cdb078)
@@ -29,9 +29,6 @@
 #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;
@@ -81,4 +78,23 @@
 }
 
+static char *set_eval_away_status( set_t *set, char *value )
+{
+	irc_t *irc = set->data;
+	account_t *a;
+	
+	g_free( set->value );
+	set->value = g_strdup( value );
+	
+	for( a = irc->accounts; a; a = a->next )
+	{
+		struct im_connection *ic = a->ic;
+		
+		if( ic && ic->flags & OPT_LOGGED_IN )
+			imc_away_send_update( ic );
+	}
+	
+	return value;
+}
+
 irc_t *irc_new( int fd )
 {
@@ -145,21 +161,20 @@
 
 	irc_connection_list = g_slist_append( irc_connection_list, irc );
-
+	
+	s = set_add( &irc->set, "away", NULL,  set_eval_away_status, irc );
+	s->flags |= SET_NULL_OK;
+	s = set_add( &irc->set, "away_devoice", "true",  set_eval_away_devoice, irc );
 	s = set_add( &irc->set, "auto_connect", "true", set_eval_bool, irc );
-	s = set_add( &irc->set, "auto_reconnect", "false", set_eval_bool, irc );
+	s = set_add( &irc->set, "auto_reconnect", "true", set_eval_bool, irc );
 	s = set_add( &irc->set, "auto_reconnect_delay", "5*3<900", set_eval_account_reconnect_delay, irc );
 	s = set_add( &irc->set, "buddy_sendbuffer", "false", set_eval_bool, irc );
 	s = set_add( &irc->set, "buddy_sendbuffer_delay", "200", set_eval_int, irc );
 	s = set_add( &irc->set, "charset", "utf-8", set_eval_charset, irc );
-	s = set_add( &irc->set, "color_encrypted", "true", set_eval_bool, irc );
 	s = set_add( &irc->set, "debug", "false", set_eval_bool, irc );
 	s = set_add( &irc->set, "default_target", "root", NULL, irc );
 	s = set_add( &irc->set, "display_namechanges", "false", set_eval_bool, irc );
 	s = set_add( &irc->set, "handle_unknown", "root", NULL, irc );
-	s = set_add( &irc->set, "halfop_buddies", "encrypted", set_eval_halfop_buddies, irc );
 	s = set_add( &irc->set, "lcnicks", "true", set_eval_bool, irc );
-	s = set_add( &irc->set, "op_buddies", "trusted", set_eval_op_buddies, irc );
-	s = set_add( &irc->set, "op_root", "true", set_eval_op_root, irc );
-	s = set_add( &irc->set, "otr_policy", "oppurtunistic", set_eval_otr_policy, irc );
+	s = set_add( &irc->set, "ops", "both", set_eval_ops, irc );
 	s = set_add( &irc->set, "password", NULL, set_eval_password, irc );
 	s->flags |= SET_NULL_OK;
@@ -169,13 +184,12 @@
 	s = set_add( &irc->set, "save_on_quit", "true", set_eval_bool, irc );
 	s = set_add( &irc->set, "simulate_netsplit", "true", set_eval_bool, irc );
+	s = set_add( &irc->set, "status", NULL,  set_eval_away_status, irc );
+	s->flags |= SET_NULL_OK;
 	s = set_add( &irc->set, "strip_html", "true", NULL, irc );
 	s = set_add( &irc->set, "to_char", ": ", set_eval_to_char, irc );
 	s = set_add( &irc->set, "typing_notice", "false", set_eval_bool, irc );
-	s = 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" ) );
@@ -329,9 +343,7 @@
 	
 	g_free( irc->last_target );
-
-	otr_free(irc->otr);
 	
 	g_free( irc );
-
+	
 	if( global.conf->runmode == RUNMODE_INETD ||
 	    global.conf->runmode == RUNMODE_FORKDAEMON ||
@@ -418,8 +430,6 @@
 			}
 			
-			if( lines[i] )
-			{
-				if( ( cmd = irc_parse_line( lines[i] ) ) == NULL )
-					continue;
+			if( lines[i] && ( cmd = irc_parse_line( lines[i] ) ) )
+			{
 				irc_exec( irc, cmd );
 				g_free( cmd );
@@ -496,5 +506,5 @@
 	if( line[0] == ':' )
 	{
-		for( i = 0; line[i] != ' '; i ++ );
+		for( i = 0; line[i] && line[i] != ' '; i ++ );
 		line = line + i;
 	}
@@ -704,38 +714,4 @@
 } 
 
-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 )
 {
@@ -743,4 +719,5 @@
 	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
@@ -757,5 +734,10 @@
 			}
 			
-			strcat( namelist, user_mode_prefix(irc, u) );
+			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, u->nick );
 			strcat( namelist, " " );
@@ -768,6 +750,6 @@
 		/* 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 ", set_getbool(&irc->set, "op_root") ? "@" : "", irc->mynick,
-		                                 set_getbool(&irc->set, "op_user") ? "@" : "", irc->nick );
+		sprintf( namelist, "%s%s %s%s ", strcmp( ops, "root" ) == 0 || strcmp( ops, "both" ) ? "@" : "", irc->mynick,
+		                                 strcmp( ops, "user" ) == 0 || strcmp( ops, "both" ) ? "@" : "", irc->nick );
 		
 		for( l = c->in_room; l; l = l->next ) if( ( u = user_findhandle( c->ic, l->data ) ) )
@@ -779,5 +761,4 @@
 			}
 			
-			strcat( namelist, user_mode_prefix(irc, u) );
 			strcat( namelist, u->nick );
 			strcat( namelist, " " );
@@ -821,9 +802,12 @@
 	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=(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_reply( irc,   5, "PREFIX=(ov)@+ CHANTYPES=%s CHANMODES=,,,%s NICKLEN=%d NETWORK=BitlBee "
+	                     "CASEMAPPING=rfc1459 MAXTARGETS=1 WATCH=128 :are supported by this server",
+	                     CTYPES, 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 );
@@ -847,5 +831,10 @@
 	irc_spawn( irc, u );
 	
-	irc_welcome( irc );
+	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." );
 	
 	if( global.conf->runmode == RUNMODE_FORKDAEMON || global.conf->runmode == RUNMODE_DAEMON )
@@ -862,33 +851,4 @@
 		root_command( irc, send_cmd );
 		g_free( send_cmd[1] );
-	}
-}
-
-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 );
 	}
 }
@@ -1085,5 +1045,5 @@
 	user_t *u = NULL;
 	
-	if( *nick == '#' || *nick == '&' )
+	if( strchr( CTYPES, *nick ) )
 	{
 		if( !( c = irc_chat_by_channel( irc, nick ) ) )
