Changeset 85d7b85 for irc_commands.c
- Timestamp:
- 2008-04-02T14:22:57Z (17 years ago)
- Branches:
- master
- Children:
- f9dbc99
- Parents:
- 875ad42 (diff), dd34575 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
irc_commands.c
r875ad42 r85d7b85 30 30 static void irc_cmd_pass( irc_t *irc, char **cmd ) 31 31 { 32 if( global.conf->auth_pass && strcmp( cmd[1], global.conf->auth_pass ) == 0 ) 33 { 34 irc->status = USTATUS_AUTHORIZED; 32 if( irc->status & USTATUS_LOGGED_IN ) 33 { 34 char *send_cmd[] = { "identify", cmd[1], NULL }; 35 36 /* We're already logged in, this client seems to send the PASS 37 command last. (Possibly it won't send it at all if it turns 38 out we don't require it, which will break this feature.) 39 Try to identify using the given password. */ 40 return root_command( irc, send_cmd ); 41 } 42 /* Handling in pre-logged-in state, first see if this server is 43 password-protected: */ 44 else if( global.conf->auth_pass && 45 ( strncmp( global.conf->auth_pass, "md5:", 4 ) == 0 ? 46 md5_verify_password( cmd[1], global.conf->auth_pass + 4 ) == 0 : 47 strcmp( cmd[1], global.conf->auth_pass ) == 0 ) ) 48 { 49 irc->status |= USTATUS_AUTHORIZED; 35 50 irc_check_login( irc ); 36 51 } 37 else 52 else if( global.conf->auth_pass ) 38 53 { 39 54 irc_reply( irc, 464, ":Incorrect password" ); 55 } 56 else 57 { 58 /* Remember the password and try to identify after USER/NICK. */ 59 irc_setpass( irc, cmd[1] ); 60 irc_check_login( irc ); 40 61 } 41 62 } … … 88 109 static void irc_cmd_oper( irc_t *irc, char **cmd ) 89 110 { 90 if( global.conf->oper_pass && strcmp( cmd[2], global.conf->oper_pass ) == 0 ) 111 if( global.conf->oper_pass && 112 ( strncmp( global.conf->oper_pass, "md5:", 4 ) == 0 ? 113 md5_verify_password( cmd[2], global.conf->oper_pass + 4 ) == 0 : 114 strcmp( cmd[2], global.conf->oper_pass ) == 0 ) ) 91 115 { 92 116 irc_umode_set( irc, "+o", 1 ); … … 119 143 if( cmd[2] ) 120 144 irc_umode_set( irc, cmd[2], 0 ); 145 else 146 irc_reply( irc, 221, "+%s", irc->umode ); 121 147 } 122 148 else … … 132 158 static void irc_cmd_part( irc_t *irc, char **cmd ) 133 159 { 134 struct conversation*c;160 struct groupchat *c; 135 161 136 162 if( g_strcasecmp( cmd[1], irc->channel ) == 0 ) … … 142 168 irc_join( irc, u, irc->channel ); 143 169 } 144 else if( ( c = conv_findchannel(cmd[1] ) ) )170 else if( ( c = irc_chat_by_channel( irc, cmd[1] ) ) ) 145 171 { 146 172 user_t *u = user_find( irc, irc->nick ); … … 148 174 irc_part( irc, u, c->channel ); 149 175 150 if( c-> gc && c->gc->prpl)176 if( c->ic ) 151 177 { 152 178 c->joined = 0; 153 c-> gc->prpl->chat_leave( c->gc, c->id);179 c->ic->acc->prpl->chat_leave( c ); 154 180 } 155 181 } … … 171 197 user_t *u = user_find( irc, cmd[1] + 1 ); 172 198 173 if( u && u-> gc && u->gc->prpl && u->gc->prpl->chat_open)199 if( u && u->ic && u->ic->acc->prpl->chat_with ) 174 200 { 175 201 irc_reply( irc, 403, "%s :Initializing groupchat in a different channel", cmd[1] ); 176 202 177 if( !u-> gc->prpl->chat_open( u->gc, u->handle ) )203 if( !u->ic->acc->prpl->chat_with( u->ic, u->handle ) ) 178 204 { 179 irc_usermsg( irc, "Could not open a groupchat with %s , maybe you don't have a connection to him/her yet?", u->nick );205 irc_usermsg( irc, "Could not open a groupchat with %s.", u->nick ); 180 206 } 181 207 } … … 199 225 { 200 226 char *nick = cmd[1], *channel = cmd[2]; 201 struct conversation *c = conv_findchannel(channel );227 struct groupchat *c = irc_chat_by_channel( irc, channel ); 202 228 user_t *u = user_find( irc, nick ); 203 229 204 if( u && c && ( u-> gc == c->gc ) )205 if( c-> gc && c->gc->prpl && c->gc->prpl->chat_invite )206 { 207 c-> gc->prpl->chat_invite( c->gc, c->id, "", u->handle);230 if( u && c && ( u->ic == c->ic ) ) 231 if( c->ic && c->ic->acc->prpl->chat_invite ) 232 { 233 c->ic->acc->prpl->chat_invite( c, u->handle, NULL ); 208 234 irc_reply( irc, 341, "%s %s", nick, channel ); 209 235 return; … … 228 254 { 229 255 unsigned int i; 230 char *t = set_getstr( irc, "default_target" );256 char *t = set_getstr( &irc->set, "default_target" ); 231 257 232 258 if( g_strcasecmp( t, "last" ) == 0 && irc->last_target ) … … 252 278 if( cmd[1] != irc->last_target ) 253 279 { 254 if( irc->last_target ) 255 g_free( irc->last_target ); 280 g_free( irc->last_target ); 256 281 irc->last_target = g_strdup( cmd[1] ); 257 282 } … … 261 286 irc->is_private = 1; 262 287 } 263 irc_send( irc, cmd[1], cmd[2], ( g_strcasecmp( cmd[0], "NOTICE" ) == 0 ) ? IM_FLAG_AWAY : 0 );288 irc_send( irc, cmd[1], cmd[2], ( g_strcasecmp( cmd[0], "NOTICE" ) == 0 ) ? OPT_AWAY : 0 ); 264 289 } 265 290 } … … 269 294 char *channel = cmd[1]; 270 295 user_t *u = irc->users; 271 struct conversation*c;296 struct groupchat *c; 272 297 GList *l; 273 298 … … 285 310 u = u->next; 286 311 } 287 else if( ( c = conv_findchannel(channel ) ) )312 else if( ( c = irc_chat_by_channel( irc, channel ) ) ) 288 313 for( l = c->in_room; l; l = l->next ) 289 314 { 290 if( ( u = user_findhandle( c-> gc, l->data ) ) )315 if( ( u = user_findhandle( c->ic, l->data ) ) ) 291 316 irc_reply( irc, 352, "%s %s %s %s %s %c :0 %s", channel, u->user, u->host, irc->myhost, u->nick, u->away ? 'G' : 'H', u->realname ); 292 317 } … … 331 356 for( i = 1; cmd[i]; i ++ ) 332 357 { 333 if( ( u = user_find( irc, cmd[i] ) ) && u->online ) 334 { 335 /* [SH] Make sure we don't use too much buffer space. */ 336 lenleft -= strlen( u->nick ) + 1; 337 338 if( lenleft < 0 ) 358 char *this, *next; 359 360 this = cmd[i]; 361 while( *this ) 362 { 363 if( ( next = strchr( this, ' ' ) ) ) 364 *next = 0; 365 366 if( ( u = user_find( irc, this ) ) && u->online ) 367 { 368 lenleft -= strlen( u->nick ) + 1; 369 370 if( lenleft < 0 ) 371 break; 372 373 strcat( buff, u->nick ); 374 strcat( buff, " " ); 375 } 376 377 if( next ) 378 { 379 *next = ' '; 380 this = next + 1; 381 } 382 else 339 383 { 340 384 break; 341 } 342 343 /* [SH] Add the nick to the buffer. Note 344 * that an extra space is always added. Even 345 * if it's the last nick in the list. Who 346 * cares? 347 */ 348 349 strcat( buff, u->nick ); 350 strcat( buff, " " ); 351 } 352 } 353 354 /* [WvG] Well, maybe someone cares, so why not remove it? */ 385 } 386 } 387 388 /* *sigh* */ 389 if( lenleft < 0 ) 390 break; 391 } 392 355 393 if( strlen( buff ) > 0 ) 356 394 buff[strlen(buff)-1] = '\0'; … … 406 444 static void irc_cmd_topic( irc_t *irc, char **cmd ) 407 445 { 408 if( cmd[2] ) 409 irc_reply( irc, 482, "%s :Cannot change topic", cmd[1] ); 410 else 411 irc_topic( irc, cmd[1] ); 446 char *channel = cmd[1]; 447 char *topic = cmd[2]; 448 449 if( topic ) 450 { 451 /* Send the topic */ 452 struct groupchat *c = irc_chat_by_channel( irc, channel ); 453 if( c && c->ic && c->ic->acc->prpl->chat_topic ) 454 c->ic->acc->prpl->chat_topic( c, topic ); 455 } 456 else 457 { 458 /* Get the topic */ 459 irc_topic( irc, channel ); 460 } 412 461 } 413 462 … … 445 494 for( a = irc->accounts; a; a = a->next ) 446 495 { 447 struct gaim_connection *gc = a->gc;448 449 if( gc && gc->flags & OPT_LOGGED_IN )450 bim_set_away( gc, u->away );496 struct im_connection *ic = a->ic; 497 498 if( ic && ic->flags & OPT_LOGGED_IN ) 499 imc_set_away( ic, u->away ); 451 500 } 452 501 } … … 461 510 irc_reply( irc, 311, "%s %s %s * :%s", u->nick, u->user, u->host, u->realname ); 462 511 463 if( u->gc ) 464 irc_reply( irc, 312, "%s %s.%s :%s network", u->nick, u->gc->user->username, 465 *u->gc->user->proto_opt[0] ? u->gc->user->proto_opt[0] : "", u->gc->prpl->name ); 512 if( u->ic ) 513 irc_reply( irc, 312, "%s %s.%s :%s network", u->nick, u->ic->acc->user, 514 u->ic->acc->server && *u->ic->acc->server ? u->ic->acc->server : "", 515 u->ic->acc->prpl->name ); 466 516 else 467 517 irc_reply( irc, 312, "%s %s :%s", u->nick, irc->myhost, IRCD_INFO ); … … 529 579 530 580 for( h = global.help; h; h = h->next ) 531 irc_privmsg( irc, u, "NOTICE", irc->nick, "COMPLETIONS help ", h-> string);581 irc_privmsg( irc, u, "NOTICE", irc->nick, "COMPLETIONS help ", h->title ); 532 582 533 583 for( s = irc->set; s; s = s->next ) … … 544 594 ipc_to_master( cmd ); 545 595 546 #ifndef _WIN32 547 irc_reply( irc, 382, "%s :Rehashing", CONF_FILE ); 548 #endif 596 irc_reply( irc, 382, "%s :Rehashing", global.conf_file ); 549 597 } 550 598 551 599 static const command_t irc_commands[] = { 552 { "pass", 1, irc_cmd_pass, IRC_CMD_PRE_LOGIN},600 { "pass", 1, irc_cmd_pass, 0 }, 553 601 { "user", 4, irc_cmd_user, IRC_CMD_PRE_LOGIN }, 554 602 { "nick", 1, irc_cmd_nick, 0 }, … … 579 627 { "die", 0, NULL, IRC_CMD_OPER_ONLY | IRC_CMD_TO_MASTER }, 580 628 { "wallops", 1, NULL, IRC_CMD_OPER_ONLY | IRC_CMD_TO_MASTER }, 581 { " lilo", 1, NULL, IRC_CMD_OPER_ONLY | IRC_CMD_TO_MASTER },629 { "wall", 1, NULL, IRC_CMD_OPER_ONLY | IRC_CMD_TO_MASTER }, 582 630 { "rehash", 0, irc_cmd_rehash, IRC_CMD_OPER_ONLY }, 583 631 { "restart", 0, NULL, IRC_CMD_OPER_ONLY | IRC_CMD_TO_MASTER }, … … 599 647 for( n_arg = 0; cmd[n_arg]; n_arg ++ ); n_arg --; 600 648 601 if( irc_commands[i].flags & IRC_CMD_PRE_LOGIN && irc->status >=USTATUS_LOGGED_IN )649 if( irc_commands[i].flags & IRC_CMD_PRE_LOGIN && irc->status & USTATUS_LOGGED_IN ) 602 650 { 603 651 irc_reply( irc, 462, ":Only allowed before logging in" ); 604 652 } 605 else if( irc_commands[i].flags & IRC_CMD_LOGGED_IN && irc->status < USTATUS_LOGGED_IN)653 else if( irc_commands[i].flags & IRC_CMD_LOGGED_IN && !( irc->status & USTATUS_LOGGED_IN ) ) 606 654 { 607 655 irc_reply( irc, 451, ":Register first" ); … … 626 674 } 627 675 628 break; 629 } 630 } 676 return; 677 } 678 679 if( irc->status >= USTATUS_LOGGED_IN ) 680 irc_reply( irc, 421, "%s :Unknown command", cmd[0] ); 681 }
Note: See TracChangeset
for help on using the changeset viewer.