Changeset 280c56a
- Timestamp:
- 2010-03-27T17:36:47Z (15 years ago)
- Branches:
- master
- Children:
- 74f1cde
- Parents:
- 2f53ada
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
Makefile
r2f53ada r280c56a 11 11 # Program variables 12 12 #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.o13 objects = 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 14 14 headers = 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 15 15 subdirs = lib protocols -
irc.c
r2f53ada r280c56a 114 114 iu->host = g_strdup( myhost ); 115 115 iu->fullname = g_strdup( ROOT_FN ); 116 iu->f = &irc_user_root_funcs; 116 117 117 118 iu = irc_user_new( irc, NS_NICK ); 118 119 iu->host = g_strdup( myhost ); 119 120 iu->fullname = g_strdup( ROOT_FN ); 121 iu->f = &irc_user_root_funcs; 120 122 121 123 irc->user = g_new0( irc_user_t, 1 ); … … 594 596 irc->user->host = iu->host; 595 597 irc->user->fullname = iu->fullname; 598 irc->user->f = &irc_user_self_funcs; 596 599 g_free( iu->nick ); 597 600 g_free( iu ); -
irc.h
r2f53ada r280c56a 107 107 108 108 //struct user *b; 109 110 const struct irc_user_funcs *f; 109 111 } irc_user_t; 112 113 struct irc_user_funcs 114 { 115 gboolean (*privmsg)( irc_user_t *iu, const char *msg ); 116 }; 117 118 extern const struct irc_user_funcs irc_user_root_funcs; 119 extern const struct irc_user_funcs irc_user_self_funcs; 110 120 111 121 typedef enum … … 117 127 { 118 128 irc_t *irc; 129 char *name; 130 char mode[8]; 119 131 int flags; 120 char *name;132 121 133 char *topic; 122 134 char *topic_who; 123 135 time_t topic_time; 124 char mode[8];136 125 137 GSList *users; 126 138 struct set *set; 139 140 const struct irc_channel_funcs *f; 127 141 } irc_channel_t; 142 143 struct irc_channel_funcs 144 { 145 gboolean (*privmsg)( irc_channel_t *iu, const char *msg ); 146 }; 128 147 129 148 #include "user.h" … … 175 194 irc_user_t *irc_user_new( irc_t *irc, const char *nick ); 176 195 int irc_user_free( irc_t *irc, const char *nick ); 177 irc_user_t *irc_user_ find( irc_t *irc, const char *nick );196 irc_user_t *irc_user_by_name( irc_t *irc, const char *nick ); 178 197 int irc_user_rename( irc_t *irc, const char *old, const char *new ); 179 198 gint irc_user_cmp( gconstpointer a_, gconstpointer b_ ); -
irc_channel.c
r2f53ada r280c56a 26 26 #include "bitlbee.h" 27 27 28 static const struct irc_channel_funcs control_channel_funcs; 29 28 30 irc_channel_t *irc_channel_new( irc_t *irc, const char *name ) 29 31 { … … 34 36 35 37 ic = g_new0( irc_channel_t, 1 ); 38 ic->f = &control_channel_funcs; 36 39 ic->irc = irc; 37 40 ic->name = g_strdup( name ); … … 132 135 return strchr( CTYPES, name[0] ) != NULL && nick_ok( name + 1 ); 133 136 } 137 138 /* Channel-type dependent functions, for control channels: */ 139 static 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 146 static const struct irc_channel_funcs control_channel_funcs = { 147 control_channel_privmsg, 148 }; -
irc_commands.c
r2f53ada r280c56a 77 77 irc_send_num( irc, 438, ":The hand of the deity is upon thee, thy nick may not change" ); 78 78 } 79 else if( irc_user_ find( irc, cmd[1] ) )79 else if( irc_user_by_name( irc, cmd[1] ) ) 80 80 { 81 81 irc_send_num( irc, 433, ":This nick is already in use" ); … … 160 160 { 161 161 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 ); 163 163 164 164 if( iu ) … … 220 220 char *channel = cmd[1]; 221 221 irc_channel_t *ic; 222 struct groupchat *c;223 GList *l;224 222 225 223 if( !channel || *channel == '0' || *channel == '*' || !*channel ) … … 231 229 } 232 230 231 static 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 233 257 #if 0 234 //#if 0235 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 else246 {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 }274 258 else if( irc->nick && g_strcasecmp( cmd[1], irc->nick ) == 0 ) 275 259 { 276 irc_write( irc, ":%s!%s@%s %s %s :%s", irc->nick, irc->user, irc->host, cmd[0], cmd[1], cmd[2] );277 260 } 278 261 else … … 315 298 irc_send( irc, cmd[1], cmd[2], ( g_strcasecmp( cmd[0], "NOTICE" ) == 0 ) ? OPT_AWAY : 0 ); 316 299 } 300 #endif 301 } 302 303 304 305 #if 0 306 //#if 0 307 static 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 323 static 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 ); 317 338 } 318 339 … … 555 576 { "mode", 1, irc_cmd_mode, IRC_CMD_LOGGED_IN }, 556 577 { "who", 0, irc_cmd_who, IRC_CMD_LOGGED_IN }, 578 { "privmsg", 1, irc_cmd_privmsg, IRC_CMD_LOGGED_IN }, 557 579 #if 0 558 580 { "oper", 2, irc_cmd_oper, IRC_CMD_LOGGED_IN }, 559 581 { "invite", 2, irc_cmd_invite, IRC_CMD_LOGGED_IN }, 560 { "privmsg", 1, irc_cmd_privmsg, IRC_CMD_LOGGED_IN },561 582 { "notice", 1, irc_cmd_privmsg, IRC_CMD_LOGGED_IN }, 562 583 { "userhost", 1, irc_cmd_userhost, IRC_CMD_LOGGED_IN }, -
irc_send.c
r2f53ada r280c56a 147 147 { 148 148 GSList *l; 149 irc_user_t *iu;150 149 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" ); 153 151 154 152 /* RFCs say there is no error reply allowed on NAMES, so when the … … 240 238 irc_send_num( irc, 315, "%s :End of /WHO list", channel ); 241 239 } 240 241 void 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 51 51 irc_user_t *iu; 52 52 53 if( !( iu = irc_user_ find( irc, nick ) ) )53 if( !( iu = irc_user_by_name( irc, nick ) ) ) 54 54 return 0; 55 55 … … 68 68 } 69 69 70 irc_user_t *irc_user_ find( irc_t *irc, const char *nick )70 irc_user_t *irc_user_by_name( irc_t *irc, const char *nick ) 71 71 { 72 72 char key[strlen(nick)+1]; … … 81 81 int irc_user_rename( irc_t *irc, const char *old, const char *new ) 82 82 { 83 irc_user_t *iu = irc_user_ find( irc, old );83 irc_user_t *iu = irc_user_by_name( irc, old ); 84 84 char key[strlen(new)+1]; 85 85 86 86 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 ) ) 88 88 return 0; 89 89 … … 113 113 return strcmp( a->key, b->key ); 114 114 } 115 116 /* User-type dependent functions, for root/NickServ: */ 117 static gboolean root_privmsg( irc_user_t *iu, const char *msg ) 118 { 119 root_command_string( iu->irc, msg ); 120 121 return TRUE; 122 } 123 124 const struct irc_user_funcs irc_user_root_funcs = { 125 root_privmsg, 126 }; 127 128 /* Echo to yourself: */ 129 static 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 136 const struct irc_user_funcs irc_user_self_funcs = { 137 self_privmsg, 138 }; -
nick.c
r2f53ada r280c56a 96 96 /* Now, find out if the nick is already in use at the moment, and make 97 97 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 ) ) 99 99 { 100 100 if( strlen( nick ) < ( MAX_NICK_LENGTH - 1 ) ) -
root_commands.c
r2f53ada r280c56a 32 32 #include <string.h> 33 33 34 void root_command_string( irc_t *irc, user_t *u, char *command, int flags)34 void root_command_string( irc_t *irc, char *command ) 35 35 { 36 36 char *cmd[IRC_MAX_ARGS]; … … 136 136 } 137 137 138 #if 0 138 139 static void cmd_account( irc_t *irc, char **cmd ); 139 140 … … 1217 1218 } 1218 1219 } 1220 #endif 1219 1221 1220 1222 const command_t commands[] = { 1221 1223 { "help", 0, cmd_help, 0 }, 1224 #if 0 1222 1225 { "identify", 1, cmd_identify, 0 }, 1223 1226 { "register", 1, cmd_register, 0 }, … … 1240 1243 { "chat", 1, cmd_chat, 0 }, 1241 1244 { "transfer", 0, cmd_transfer, 0 }, 1245 #endif 1242 1246 { NULL } 1243 1247 };
Note: See TracChangeset
for help on using the changeset viewer.