Changeset b919363
- Timestamp:
- 2010-03-27T14:31:03Z (15 years ago)
- Branches:
- master
- Children:
- 2f53ada
- Parents:
- 9b69eb7
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
irc.c
r9b69eb7 rb919363 52 52 irc->nick_user_hash = g_hash_table_new( g_str_hash, g_str_equal ); 53 53 irc->watches = g_hash_table_new( g_str_hash, g_str_equal ); 54 55 strcpy( irc->umode, UMODE );56 54 57 55 irc->iconv = (GIConv) -1; … … 599 597 g_free( iu ); 600 598 601 irc->umode[0] = '\0';602 /*irc_umode_set( irc, "+" UMODE, 1 );*/603 604 599 if( global.conf->runmode == RUNMODE_FORKDAEMON || global.conf->runmode == RUNMODE_DAEMON ) 605 600 ipc_to_master_str( "CLIENT %s %s :%s\r\n", irc->user->host, irc->user->nick, irc->user->fullname ); … … 619 614 irc_send_login( irc ); 620 615 616 irc->umode[0] = '\0'; 617 irc_umode_set( irc, "+" UMODE, TRUE ); 618 621 619 ic = irc_channel_new( irc, ROOT_CHAN ); 622 620 irc_channel_set_topic( ic, CONTROL_TOPIC, irc->root ); … … 631 629 return 0; 632 630 } 631 } 632 633 void irc_umode_set( irc_t *irc, const char *s, gboolean allow_priv ) 634 { 635 /* allow_priv: Set to 0 if s contains user input, 1 if you want 636 to set a "privileged" mode (+o, +R, etc). */ 637 char m[128], st = 1; 638 const char *t; 639 int i; 640 char changes[512], *p, st2 = 2; 641 char badflag = 0; 642 643 memset( m, 0, sizeof( m ) ); 644 645 for( t = irc->umode; *t; t ++ ) 646 if( *t < sizeof( m ) ) 647 m[(int)*t] = 1; 648 649 p = changes; 650 for( t = s; *t; t ++ ) 651 { 652 if( *t == '+' || *t == '-' ) 653 st = *t == '+'; 654 else if( ( st == 0 && ( !strchr( UMODES_KEEP, *t ) || allow_priv ) ) || 655 ( st == 1 && strchr( UMODES, *t ) ) || 656 ( st == 1 && allow_priv && strchr( UMODES_PRIV, *t ) ) ) 657 { 658 if( m[(int)*t] != st) 659 { 660 if( st != st2 ) 661 st2 = st, *p++ = st ? '+' : '-'; 662 *p++ = *t; 663 } 664 m[(int)*t] = st; 665 } 666 else 667 badflag = 1; 668 } 669 *p = '\0'; 670 671 memset( irc->umode, 0, sizeof( irc->umode ) ); 672 673 for( i = 'A'; i <= 'z' && strlen( irc->umode ) < ( sizeof( irc->umode ) - 1 ); i ++ ) 674 if( m[i] ) 675 irc->umode[strlen(irc->umode)] = i; 676 677 if( badflag ) 678 irc_send_num( irc, 501, ":Unknown MODE flag" ); 679 if( *changes ) 680 irc_write( irc, ":%s!%s@%s MODE %s :%s", irc->user->nick, 681 irc->user->user, irc->user->host, irc->user->nick, 682 changes ); 633 683 } 634 684 -
irc.h
r9b69eb7 rb919363 33 33 #define IRC_PING_STRING "PinglBee" 34 34 35 #define UMODES "abisw" 36 #define UMODES_PRIV "Ro" 37 #define CMODES "nt" 38 #define CMODE "t" 39 #define UMODE "s" 40 #define CTYPES "&#" 35 #define UMODES "abisw" /* Allowed umodes (although they mostly do nothing) */ 36 #define UMODES_PRIV "Ro" /* Allowed, but not by user directly */ 37 #define UMODES_KEEP "R" /* Don't allow unsetting using /MODE */ 38 #define CMODES "nt" /* Allowed modes */ 39 #define CMODE "t" /* Default mode */ 40 #define UMODE "s" /* Default mode */ 41 42 #define CTYPES "&#" /* Valid channel name prefixes */ 41 43 42 44 typedef enum … … 144 146 int irc_check_login( irc_t *irc ); 145 147 148 void irc_umode_set( irc_t *irc, const char *s, gboolean allow_priv ); 149 146 150 /* irc_channel.c */ 147 151 irc_channel_t *irc_channel_new( irc_t *irc, const char *name ); … … 151 155 int irc_channel_del_user( irc_channel_t *ic, irc_user_t *iu ); 152 156 int irc_channel_set_topic( irc_channel_t *ic, const char *topic, const irc_user_t *who ); 157 gboolean irc_channel_name_ok( const char *name ); 153 158 154 159 /* irc_commands.c */ -
irc_channel.c
r9b69eb7 rb919363 127 127 return 1; 128 128 } 129 130 gboolean irc_channel_name_ok( const char *name ) 131 { 132 return strchr( CTYPES, name[0] ) != NULL && nick_ok( name + 1 ); 133 } -
irc_commands.c
r9b69eb7 rb919363 184 184 } 185 185 186 static void irc_cmd_mode( irc_t *irc, char **cmd ) 187 { 188 if( irc_channel_name_ok( cmd[1] ) ) 189 { 190 irc_channel_t *ic; 191 192 if( ( ic = irc_channel_by_name( irc, cmd[1] ) ) == NULL ) 193 irc_send_num( irc, 403, "%s :No such channel", cmd[1] ); 194 else if( cmd[2] ) 195 { 196 if( *cmd[2] == '+' || *cmd[2] == '-' ) 197 irc_send_num( irc, 477, "%s :Can't change channel modes", cmd[1] ); 198 else if( *cmd[2] == 'b' ) 199 irc_send_num( irc, 368, "%s :No bans possible", cmd[1] ); 200 } 201 else 202 irc_send_num( irc, 324, "%s +%s", cmd[1], ic->mode ); 203 } 204 else 205 { 206 if( nick_cmp( cmd[1], irc->user->nick ) == 0 ) 207 { 208 if( cmd[2] ) 209 irc_umode_set( irc, cmd[2], 0 ); 210 else 211 irc_send_num( irc, 221, "+%s", irc->umode ); 212 } 213 else 214 irc_send_num( irc, 502, ":Don't touch their modes" ); 215 } 216 } 217 186 218 #if 0 187 219 //#if 0 … … 199 231 { 200 232 irc_send_num( irc, 432, ":Incorrect password" ); 201 }202 }203 204 static void irc_cmd_mode( irc_t *irc, char **cmd )205 {206 if( strchr( CTYPES, *cmd[1] ) )207 {208 if( cmd[2] )209 {210 if( *cmd[2] == '+' || *cmd[2] == '-' )211 irc_send_num( irc, 477, "%s :Can't change channel modes", cmd[1] );212 else if( *cmd[2] == 'b' )213 irc_send_num( irc, 368, "%s :No bans possible", cmd[1] );214 }215 else216 irc_send_num( irc, 324, "%s +%s", cmd[1], CMODE );217 }218 else219 {220 if( nick_cmp( cmd[1], irc->nick ) == 0 )221 {222 if( cmd[2] )223 irc_umode_set( irc, cmd[2], 0 );224 else225 irc_send_num( irc, 221, "+%s", irc->umode );226 }227 else228 irc_send_num( irc, 502, ":Don't touch their modes" );229 233 } 230 234 } … … 566 570 { "whowas", 1, irc_cmd_whowas, IRC_CMD_LOGGED_IN }, 567 571 { "motd", 0, irc_cmd_motd, IRC_CMD_LOGGED_IN }, 572 { "mode", 1, irc_cmd_mode, IRC_CMD_LOGGED_IN }, 568 573 #if 0 569 574 { "oper", 2, irc_cmd_oper, IRC_CMD_LOGGED_IN }, 570 { "mode", 1, irc_cmd_mode, IRC_CMD_LOGGED_IN },571 575 { "invite", 2, irc_cmd_invite, IRC_CMD_LOGGED_IN }, 572 576 { "privmsg", 1, irc_cmd_privmsg, IRC_CMD_LOGGED_IN },
Note: See TracChangeset
for help on using the changeset viewer.