Changeset 280c56a


Ignore:
Timestamp:
2010-03-27T17:36:47Z (14 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
74f1cde
Parents:
2f53ada
Message:

Added privmsg handlers to users/channels. root commands are coming back.

Files:
9 edited

Legend:

Unmodified
Added
Removed
  • Makefile

    r2f53ada r280c56a  
    1111# Program variables
    1212#objects = bitlbee.o chat.o dcc.o help.o ipc.o irc.o irc_commands.o nick.o query.o root_commands.o set.o storage.o $(STORAGE_OBJS)
    13 objects = bitlbee.o help.o ipc.o irc.o irc_channel.o irc_commands.o irc_send.o irc_user.o nick.o set.o
     13objects = bitlbee.o help.o ipc.o irc.o irc_channel.o irc_commands.o irc_send.o irc_user.o nick.o root_commands.o set.o
    1414headers = account.h bitlbee.h commands.h conf.h config.h help.h ipc.h irc.h log.h nick.h query.h set.h sock.h storage.h user.h lib/events.h lib/ftutil.h lib/http_client.h lib/ini.h lib/md5.h lib/misc.h lib/proxy.h lib/sha1.h lib/ssl_client.h lib/url.h protocols/ft.h protocols/nogaim.h
    1515subdirs = lib protocols
  • irc.c

    r2f53ada r280c56a  
    114114        iu->host = g_strdup( myhost );
    115115        iu->fullname = g_strdup( ROOT_FN );
     116        iu->f = &irc_user_root_funcs;
    116117       
    117118        iu = irc_user_new( irc, NS_NICK );
    118119        iu->host = g_strdup( myhost );
    119120        iu->fullname = g_strdup( ROOT_FN );
     121        iu->f = &irc_user_root_funcs;
    120122       
    121123        irc->user = g_new0( irc_user_t, 1 );
     
    594596                        irc->user->host = iu->host;
    595597                        irc->user->fullname = iu->fullname;
     598                        irc->user->f = &irc_user_self_funcs;
    596599                        g_free( iu->nick );
    597600                        g_free( iu );
  • irc.h

    r2f53ada r280c56a  
    107107       
    108108        //struct user *b;
     109       
     110        const struct irc_user_funcs *f;
    109111} irc_user_t;
     112
     113struct irc_user_funcs
     114{
     115        gboolean (*privmsg)( irc_user_t *iu, const char *msg );
     116};
     117
     118extern const struct irc_user_funcs irc_user_root_funcs;
     119extern const struct irc_user_funcs irc_user_self_funcs;
    110120
    111121typedef enum
     
    117127{
    118128        irc_t *irc;
     129        char *name;
     130        char mode[8];
    119131        int flags;
    120         char *name;
     132       
    121133        char *topic;
    122134        char *topic_who;
    123135        time_t topic_time;
    124         char mode[8];
     136       
    125137        GSList *users;
    126138        struct set *set;
     139       
     140        const struct irc_channel_funcs *f;
    127141} irc_channel_t;
     142
     143struct irc_channel_funcs
     144{
     145        gboolean (*privmsg)( irc_channel_t *iu, const char *msg );
     146};
    128147
    129148#include "user.h"
     
    175194irc_user_t *irc_user_new( irc_t *irc, const char *nick );
    176195int irc_user_free( irc_t *irc, const char *nick );
    177 irc_user_t *irc_user_find( irc_t *irc, const char *nick );
     196irc_user_t *irc_user_by_name( irc_t *irc, const char *nick );
    178197int irc_user_rename( irc_t *irc, const char *old, const char *new );
    179198gint irc_user_cmp( gconstpointer a_, gconstpointer b_ );
  • irc_channel.c

    r2f53ada r280c56a  
    2626#include "bitlbee.h"
    2727
     28static const struct irc_channel_funcs control_channel_funcs;
     29
    2830irc_channel_t *irc_channel_new( irc_t *irc, const char *name )
    2931{
     
    3436       
    3537        ic = g_new0( irc_channel_t, 1 );
     38        ic->f = &control_channel_funcs;
    3639        ic->irc = irc;
    3740        ic->name = g_strdup( name );
     
    132135        return strchr( CTYPES, name[0] ) != NULL && nick_ok( name + 1 );
    133136}
     137
     138/* Channel-type dependent functions, for control channels: */
     139static gboolean control_channel_privmsg( irc_channel_t *ic, const char *msg )
     140{
     141        root_command_string( ic->irc, msg );
     142       
     143        return TRUE;
     144}
     145
     146static const struct irc_channel_funcs control_channel_funcs = {
     147        control_channel_privmsg,
     148};
  • irc_commands.c

    r2f53ada r280c56a  
    7777                irc_send_num( irc, 438, ":The hand of the deity is upon thee, thy nick may not change" );
    7878        }
    79         else if( irc_user_find( irc, cmd[1] ) )
     79        else if( irc_user_by_name( irc, cmd[1] ) )
    8080        {
    8181                irc_send_num( irc, 433, ":This nick is already in use" );
     
    160160{
    161161        char *nick = cmd[1];
    162         irc_user_t *iu = irc_user_find( irc, nick );
     162        irc_user_t *iu = irc_user_by_name( irc, nick );
    163163       
    164164        if( iu )
     
    220220        char *channel = cmd[1];
    221221        irc_channel_t *ic;
    222         struct groupchat *c;
    223         GList *l;
    224222       
    225223        if( !channel || *channel == '0' || *channel == '*' || !*channel )
     
    231229}
    232230
     231static void irc_cmd_privmsg( irc_t *irc, char **cmd )
     232{
     233        irc_channel_t *ic;
     234        irc_user_t *iu;
     235       
     236        if( !cmd[2] )
     237        {
     238                irc_send_num( irc, 412, ":No text to send" );
     239        }
     240        else if( irc_channel_name_ok( cmd[1] ) &&
     241                 ( ic = irc_channel_by_name( irc, cmd[1] ) ) )
     242        {
     243                if( ic->f->privmsg )
     244                        ic->f->privmsg( ic, cmd[2] );
     245        }
     246        else if( ( iu = irc_user_by_name( irc, cmd[1] ) ) )
     247        {
     248                if( iu->f->privmsg )
     249                        iu->f->privmsg( iu, cmd[2] );
     250        }
     251        else
     252        {
     253                irc_send_num( irc, 401, "%s :No such nick/channel", cmd[1] );
     254        }
     255
     256
    233257#if 0
    234 //#if 0
    235 static void irc_cmd_oper( irc_t *irc, char **cmd )
    236 {
    237         if( global.conf->oper_pass &&
    238             ( strncmp( global.conf->oper_pass, "md5:", 4 ) == 0 ?
    239                 md5_verify_password( cmd[2], global.conf->oper_pass + 4 ) == 0 :
    240                 strcmp( cmd[2], global.conf->oper_pass ) == 0 ) )
    241         {
    242                 irc_umode_set( irc, "+o", 1 );
    243                 irc_send_num( irc, 381, ":Password accepted" );
    244         }
    245         else
    246         {
    247                 irc_send_num( irc, 432, ":Incorrect password" );
    248         }
    249 }
    250 
    251 static void irc_cmd_invite( irc_t *irc, char **cmd )
    252 {
    253         char *nick = cmd[1], *channel = cmd[2];
    254         struct groupchat *c = irc_chat_by_channel( irc, channel );
    255         user_t *u = user_find( irc, nick );
    256        
    257         if( u && c && ( u->ic == c->ic ) )
    258                 if( c->ic && c->ic->acc->prpl->chat_invite )
    259                 {
    260                         c->ic->acc->prpl->chat_invite( c, u->handle, NULL );
    261                         irc_send_num( irc, 341, "%s %s", nick, channel );
    262                         return;
    263                 }
    264        
    265         irc_send_num( irc, 482, "%s :Invite impossible; User/Channel non-existent or incompatible", channel );
    266 }
    267 
    268 static void irc_cmd_privmsg( irc_t *irc, char **cmd )
    269 {
    270         if( !cmd[2] )
    271         {
    272                 irc_send_num( irc, 412, ":No text to send" );
    273         }
    274258        else if( irc->nick && g_strcasecmp( cmd[1], irc->nick ) == 0 )
    275259        {
    276                 irc_write( irc, ":%s!%s@%s %s %s :%s", irc->nick, irc->user, irc->host, cmd[0], cmd[1], cmd[2] );
    277260        }
    278261        else
     
    315298                irc_send( irc, cmd[1], cmd[2], ( g_strcasecmp( cmd[0], "NOTICE" ) == 0 ) ? OPT_AWAY : 0 );
    316299        }
     300#endif
     301}
     302
     303
     304
     305#if 0
     306//#if 0
     307static void irc_cmd_oper( irc_t *irc, char **cmd )
     308{
     309        if( global.conf->oper_pass &&
     310            ( strncmp( global.conf->oper_pass, "md5:", 4 ) == 0 ?
     311                md5_verify_password( cmd[2], global.conf->oper_pass + 4 ) == 0 :
     312                strcmp( cmd[2], global.conf->oper_pass ) == 0 ) )
     313        {
     314                irc_umode_set( irc, "+o", 1 );
     315                irc_send_num( irc, 381, ":Password accepted" );
     316        }
     317        else
     318        {
     319                irc_send_num( irc, 432, ":Incorrect password" );
     320        }
     321}
     322
     323static void irc_cmd_invite( irc_t *irc, char **cmd )
     324{
     325        char *nick = cmd[1], *channel = cmd[2];
     326        struct groupchat *c = irc_chat_by_channel( irc, channel );
     327        user_t *u = user_find( irc, nick );
     328       
     329        if( u && c && ( u->ic == c->ic ) )
     330                if( c->ic && c->ic->acc->prpl->chat_invite )
     331                {
     332                        c->ic->acc->prpl->chat_invite( c, u->handle, NULL );
     333                        irc_send_num( irc, 341, "%s %s", nick, channel );
     334                        return;
     335                }
     336       
     337        irc_send_num( irc, 482, "%s :Invite impossible; User/Channel non-existent or incompatible", channel );
    317338}
    318339
     
    555576        { "mode",        1, irc_cmd_mode,        IRC_CMD_LOGGED_IN },
    556577        { "who",         0, irc_cmd_who,         IRC_CMD_LOGGED_IN },
     578        { "privmsg",     1, irc_cmd_privmsg,     IRC_CMD_LOGGED_IN },
    557579#if 0
    558580        { "oper",        2, irc_cmd_oper,        IRC_CMD_LOGGED_IN },
    559581        { "invite",      2, irc_cmd_invite,      IRC_CMD_LOGGED_IN },
    560         { "privmsg",     1, irc_cmd_privmsg,     IRC_CMD_LOGGED_IN },
    561582        { "notice",      1, irc_cmd_privmsg,     IRC_CMD_LOGGED_IN },
    562583        { "userhost",    1, irc_cmd_userhost,    IRC_CMD_LOGGED_IN },
  • irc_send.c

    r2f53ada r280c56a  
    147147{
    148148        GSList *l;
    149         irc_user_t *iu;
    150149        char namelist[385] = "";
    151         struct groupchat *c = NULL;
    152         char *ops = set_getstr( &ic->irc->b->set, "ops" );
     150        //char *ops = set_getstr( &ic->irc->b->set, "ops" );
    153151       
    154152        /* RFCs say there is no error reply allowed on NAMES, so when the
     
    240238        irc_send_num( irc, 315, "%s :End of /WHO list", channel );
    241239}
     240
     241void irc_send_msg( irc_user_t *iu, const char *type, const char *dst, const char *msg )
     242{
     243        irc_write( iu->irc, ":%s!%s@%s %s %s :%s",
     244                   iu->nick, iu->user, iu->host, type, dst, msg );
     245}
  • irc_user.c

    r2f53ada r280c56a  
    5151        irc_user_t *iu;
    5252       
    53         if( !( iu = irc_user_find( irc, nick ) ) )
     53        if( !( iu = irc_user_by_name( irc, nick ) ) )
    5454                return 0;
    5555       
     
    6868}
    6969
    70 irc_user_t *irc_user_find( irc_t *irc, const char *nick )
     70irc_user_t *irc_user_by_name( irc_t *irc, const char *nick )
    7171{
    7272        char key[strlen(nick)+1];
     
    8181int irc_user_rename( irc_t *irc, const char *old, const char *new )
    8282{
    83         irc_user_t *iu = irc_user_find( irc, old );
     83        irc_user_t *iu = irc_user_by_name( irc, old );
    8484        char key[strlen(new)+1];
    8585       
    8686        strcpy( key, new );
    87         if( iu == NULL || !nick_lc( key ) || irc_user_find( irc, new ) )
     87        if( iu == NULL || !nick_lc( key ) || irc_user_by_name( irc, new ) )
    8888                return 0;
    8989       
     
    113113        return strcmp( a->key, b->key );
    114114}
     115
     116/* User-type dependent functions, for root/NickServ: */
     117static gboolean root_privmsg( irc_user_t *iu, const char *msg )
     118{
     119        root_command_string( iu->irc, msg );
     120       
     121        return TRUE;
     122}
     123
     124const struct irc_user_funcs irc_user_root_funcs = {
     125        root_privmsg,
     126};
     127
     128/* Echo to yourself: */
     129static gboolean self_privmsg( irc_user_t *iu, const char *msg )
     130{
     131        irc_send_msg( iu, "PRIVMSG", iu->nick, msg );
     132       
     133        return TRUE;
     134}
     135
     136const struct irc_user_funcs irc_user_self_funcs = {
     137        self_privmsg,
     138};
  • nick.c

    r2f53ada r280c56a  
    9696        /* Now, find out if the nick is already in use at the moment, and make
    9797           subtle changes to make it unique. */
    98         while( !nick_ok( nick ) || irc_user_find( acc->irc, nick ) )
     98        while( !nick_ok( nick ) || irc_user_by_name( acc->irc, nick ) )
    9999        {
    100100                if( strlen( nick ) < ( MAX_NICK_LENGTH - 1 ) )
  • root_commands.c

    r2f53ada r280c56a  
    3232#include <string.h>
    3333
    34 void root_command_string( irc_t *irc, user_t *u, char *command, int flags )
     34void root_command_string( irc_t *irc, char *command )
    3535{
    3636        char *cmd[IRC_MAX_ARGS];
     
    136136}
    137137
     138#if 0
    138139static void cmd_account( irc_t *irc, char **cmd );
    139140
     
    12171218        }
    12181219}
     1220#endif
    12191221
    12201222const command_t commands[] = {
    12211223        { "help",           0, cmd_help,           0 },
     1224#if 0
    12221225        { "identify",       1, cmd_identify,       0 },
    12231226        { "register",       1, cmd_register,       0 },
     
    12401243        { "chat",           1, cmd_chat,           0 },
    12411244        { "transfer",       0, cmd_transfer,       0 },
     1245#endif
    12421246        { NULL }
    12431247};
Note: See TracChangeset for help on using the changeset viewer.