Changeset b95932e


Ignore:
Timestamp:
2010-03-27T03:39:23Z (14 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
83e92bf
Parents:
63a520b
Message:

Added WHOIS command.

Files:
5 edited

Legend:

Unmodified
Added
Removed
  • irc.c

    r63a520b rb95932e  
    594594                        irc->user = irc_user_new( irc, iu->nick );
    595595                        irc->user->user = iu->user;
     596                        irc->user->host = iu->host;
    596597                        irc->user->fullname = iu->fullname;
    597                         g_free( iu->fullname );
    598598                        g_free( iu->nick );
    599                         g_free( iu->host );
    600599                        g_free( iu );
    601600                       
  • irc.h

    r63a520b rb95932e  
    8787typedef struct irc_user
    8888{
     89        irc_t *irc;
     90       
    8991        char *nick;
    9092        char *user;
     
    159161void irc_send_names( irc_channel_t *ic );
    160162void irc_send_topic( irc_channel_t *ic );
     163void irc_send_whois( irc_user_t *iu );
    161164
    162165/* irc_user.c */
  • irc_commands.c

    r63a520b rb95932e  
    155155                irc_send_num( irc, 442, "%s :You're not on that channel", cmd[1] );
    156156        }
     157}
     158
     159static void irc_cmd_whois( irc_t *irc, char **cmd )
     160{
     161        char *nick = cmd[1];
     162        irc_user_t *iu = irc_user_find( irc, nick );
     163       
     164        if( iu )
     165                irc_send_whois( iu );
     166        else
     167                irc_send_num( irc, 401, "%s :Nick does not exist", nick );
     168}
     169
     170static void irc_cmd_whowas( irc_t *irc, char **cmd )
     171{
     172        /* For some reason irssi tries a whowas when whois fails. We can
     173           ignore this, but then the user never gets a "user not found"
     174           message from irssi which is a bit annoying. So just respond
     175           with not-found and irssi users will get better error messages */
     176       
     177        irc_send_num( irc, 406, "%s :Nick does not exist", cmd[1] );
     178        irc_send_num( irc, 369, "%s :End of WHOWAS", cmd[1] );
    157179}
    158180
     
    475497}
    476498
    477 static void irc_cmd_whois( irc_t *irc, char **cmd )
    478 {
    479         char *nick = cmd[1];
    480         user_t *u = user_find( irc, nick );
    481        
    482         if( u )
    483         {
    484                 irc_send_num( irc, 311, "%s %s %s * :%s", u->nick, u->user, u->host, u->realname );
    485                
    486                 if( u->ic )
    487                         irc_send_num( irc, 312, "%s %s.%s :%s network", u->nick, u->ic->acc->user,
    488                                    u->ic->acc->server && *u->ic->acc->server ? u->ic->acc->server : "",
    489                                    u->ic->acc->prpl->name );
    490                 else
    491                         irc_send_num( irc, 312, "%s %s :%s", u->nick, irc->myhost, IRCD_INFO );
    492                
    493                 if( !u->online )
    494                         irc_send_num( irc, 301, "%s :%s", u->nick, "User is offline" );
    495                 else if( u->away )
    496                         irc_send_num( irc, 301, "%s :%s", u->nick, u->away );
    497                 if( u->status_msg )
    498                         irc_send_num( irc, 333, "%s :Status: %s", u->nick, u->status_msg );
    499                
    500                 irc_send_num( irc, 318, "%s :End of /WHOIS list", nick );
    501         }
    502         else
    503         {
    504                 irc_send_num( irc, 401, "%s :Nick does not exist", nick );
    505         }
    506 }
    507 
    508 static void irc_cmd_whowas( irc_t *irc, char **cmd )
    509 {
    510         /* For some reason irssi tries a whowas when whois fails. We can
    511            ignore this, but then the user never gets a "user not found"
    512            message from irssi which is a bit annoying. So just respond
    513            with not-found and irssi users will get better error messages */
    514        
    515         irc_send_num( irc, 406, "%s :Nick does not exist", cmd[1] );
    516         irc_send_num( irc, 369, "%s :End of WHOWAS", cmd[1] );
    517 }
    518 
    519499static void irc_cmd_nickserv( irc_t *irc, char **cmd )
    520500{
     
    583563        { "names",       1, irc_cmd_names,       IRC_CMD_LOGGED_IN },
    584564        { "part",        1, irc_cmd_part,        IRC_CMD_LOGGED_IN },
     565        { "whois",       1, irc_cmd_whois,       IRC_CMD_LOGGED_IN },
     566        { "whowas",      1, irc_cmd_whowas,      IRC_CMD_LOGGED_IN },
    585567#if 0
    586568        { "oper",        2, irc_cmd_oper,        IRC_CMD_LOGGED_IN },
     
    595577        { "topic",       1, irc_cmd_topic,       IRC_CMD_LOGGED_IN },
    596578        { "away",        0, irc_cmd_away,        IRC_CMD_LOGGED_IN },
    597         { "whois",       1, irc_cmd_whois,       IRC_CMD_LOGGED_IN },
    598         { "whowas",      1, irc_cmd_whowas,      IRC_CMD_LOGGED_IN },
    599579        { "nickserv",    1, irc_cmd_nickserv,    IRC_CMD_LOGGED_IN },
    600580        { "ns",          1, irc_cmd_nickserv,    IRC_CMD_LOGGED_IN },
  • irc_send.c

    r63a520b rb95932e  
    189189                irc_send_num( ic->irc, 331, "%s :No topic for this channel", ic->name );
    190190}
     191
     192void irc_send_whois( irc_user_t *iu )
     193{
     194        irc_t *irc = iu->irc;
     195       
     196        irc_send_num( irc, 311, "%s %s %s * :%s",
     197                      iu->nick, iu->user, iu->host, iu->fullname );
     198       
     199        /*
     200        if( u->ic )
     201                irc_send_num( irc, 312, "%s %s.%s :%s network", u->nick, u->ic->acc->user,
     202                           u->ic->acc->server && *u->ic->acc->server ? u->ic->acc->server : "",
     203                           u->ic->acc->prpl->name );
     204        else
     205                irc_send_num( irc, 312, "%s %s :%s", u->nick, irc->myhost, IRCD_INFO );
     206        */
     207       
     208        /*
     209        if( u->away )
     210                irc_send_num( irc, 301, "%s :%s", u->nick, u->away );
     211        if( u->status_msg )
     212                irc_send_num( irc, 333, "%s :Status: %s", u->nick, u->status_msg );
     213        */
     214       
     215        irc_send_num( irc, 318, "%s :End of /WHOIS list", iu->nick );
     216}
  • irc_user.c

    r63a520b rb95932e  
    3030        irc_user_t *iu = g_new0( irc_user_t, 1 );
    3131       
     32        iu->irc = irc;
    3233        iu->nick = g_strdup( nick );
    3334        iu->user = iu->host = iu->fullname = iu->nick;
Note: See TracChangeset for help on using the changeset viewer.