Changeset 5ebff60 for irc_send.c
- Timestamp:
- 2015-02-20T22:50:54Z (9 years ago)
- Branches:
- master
- Children:
- 0b9daac, 3d45471, 7733b8c
- Parents:
- af359b4
- git-author:
- Indent <please@…> (19-02-15 05:47:20)
- git-committer:
- dequis <dx@…> (20-02-15 22:50:54)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
irc_send.c
raf359b4 r5ebff60 1 1 /********************************************************************\ 2 2 * BitlBee -- An IRC to other IM-networks gateway * 3 3 * * … … 26 26 #include "bitlbee.h" 27 27 28 void irc_send_num( irc_t *irc, int code, char *format, ...)28 void irc_send_num(irc_t *irc, int code, char *format, ...) 29 29 { 30 30 char text[IRC_MAX_LINE]; 31 31 va_list params; 32 33 va_start( params, format);34 g_vsnprintf( text, IRC_MAX_LINE, format, params);35 va_end( params);36 37 irc_write( irc, ":%s %03d %s %s", irc->root->host, code, irc->user->nick ? : "*", text);38 } 39 40 void irc_send_login( irc_t *irc)41 { 42 irc_send_num( irc, 1, ":Welcome to the %s gateway, %s", PACKAGE, irc->user->nick);43 irc_send_num( 44 PACKAGE, BITLBEE_VERSION, ARCH, CPU);45 irc_send_num( irc, 3, ":%s", IRCD_INFO);46 irc_send_num( irc, 4, "%s %s %s %s", irc->root->host, BITLBEE_VERSION, UMODES UMODES_PRIV, CMODES);47 irc_send_num( 48 49 50 CTYPES, CMODES, MAX_NICK_LENGTH - 1, MAX_NICK_LENGTH - 1);51 irc_send_motd( irc);52 } 53 54 void irc_send_motd( irc_t *irc)32 33 va_start(params, format); 34 g_vsnprintf(text, IRC_MAX_LINE, format, params); 35 va_end(params); 36 37 irc_write(irc, ":%s %03d %s %s", irc->root->host, code, irc->user->nick ? : "*", text); 38 } 39 40 void irc_send_login(irc_t *irc) 41 { 42 irc_send_num(irc, 1, ":Welcome to the %s gateway, %s", PACKAGE, irc->user->nick); 43 irc_send_num(irc, 2, ":Host %s is running %s %s %s/%s.", irc->root->host, 44 PACKAGE, BITLBEE_VERSION, ARCH, CPU); 45 irc_send_num(irc, 3, ":%s", IRCD_INFO); 46 irc_send_num(irc, 4, "%s %s %s %s", irc->root->host, BITLBEE_VERSION, UMODES UMODES_PRIV, CMODES); 47 irc_send_num(irc, 5, "PREFIX=(ohv)@%%+ CHANTYPES=%s CHANMODES=,,,%s NICKLEN=%d CHANNELLEN=%d " 48 "NETWORK=BitlBee SAFELIST CASEMAPPING=rfc1459 MAXTARGETS=1 WATCH=128 " 49 "FLOOD=0/9999 :are supported by this server", 50 CTYPES, CMODES, MAX_NICK_LENGTH - 1, MAX_NICK_LENGTH - 1); 51 irc_send_motd(irc); 52 } 53 54 void irc_send_motd(irc_t *irc) 55 55 { 56 56 char motd[2048]; 57 57 size_t len; 58 58 int fd; 59 60 fd = open( global.conf->motdfile, O_RDONLY ); 61 if( fd == -1 || ( len = read( fd, motd, sizeof( motd ) - 1 ) ) <= 0 ) 62 { 63 irc_send_num( irc, 422, ":We don't need MOTDs." ); 64 } 65 else 66 { 59 60 fd = open(global.conf->motdfile, O_RDONLY); 61 if (fd == -1 || (len = read(fd, motd, sizeof(motd) - 1)) <= 0) { 62 irc_send_num(irc, 422, ":We don't need MOTDs."); 63 } else { 67 64 char linebuf[80]; 68 65 char *add = "", max, *in; 69 66 70 67 in = motd; 71 68 motd[len] = '\0'; 72 69 linebuf[79] = len = 0; 73 max = sizeof( linebuf ) - 1; 74 75 irc_send_num( irc, 375, ":- %s Message Of The Day - ", irc->root->host ); 76 while( ( linebuf[len] = *(in++) ) ) 77 { 78 if( linebuf[len] == '\n' || len == max ) 79 { 70 max = sizeof(linebuf) - 1; 71 72 irc_send_num(irc, 375, ":- %s Message Of The Day - ", irc->root->host); 73 while ((linebuf[len] = *(in++))) { 74 if (linebuf[len] == '\n' || len == max) { 80 75 linebuf[len] = 0; 81 irc_send_num( irc, 372, ":- %s", linebuf);76 irc_send_num(irc, 372, ":- %s", linebuf); 82 77 len = 0; 78 } else if (linebuf[len] == '%') { 79 linebuf[len] = *(in++); 80 if (linebuf[len] == 'h') { 81 add = irc->root->host; 82 } else if (linebuf[len] == 'v') { 83 add = BITLBEE_VERSION; 84 } else if (linebuf[len] == 'n') { 85 add = irc->user->nick; 86 } else if (linebuf[len] == '\0') { 87 in--; 88 } else { 89 add = "%"; 90 } 91 92 strncpy(linebuf + len, add, max - len); 93 while (linebuf[++len]) { 94 ; 95 } 96 } else if (len < max) { 97 len++; 83 98 } 84 else if( linebuf[len] == '%' ) 85 { 86 linebuf[len] = *(in++); 87 if( linebuf[len] == 'h' ) 88 add = irc->root->host; 89 else if( linebuf[len] == 'v' ) 90 add = BITLBEE_VERSION; 91 else if( linebuf[len] == 'n' ) 92 add = irc->user->nick; 93 else if( linebuf[len] == '\0' ) 94 in --; 95 else 96 add = "%"; 97 98 strncpy( linebuf + len, add, max - len ); 99 while( linebuf[++len] ); 100 } 101 else if( len < max ) 102 { 103 len ++; 104 } 105 } 106 irc_send_num( irc, 376, ":End of MOTD" ); 107 } 108 109 if( fd != -1 ) 110 close( fd ); 99 } 100 irc_send_num(irc, 376, ":End of MOTD"); 101 } 102 103 if (fd != -1) { 104 close(fd); 105 } 111 106 } 112 107 … … 114 109 this person in /query or in a control channel. WARNING: callers rely on 115 110 this returning a pointer at irc->user_nick, not a copy of it. */ 116 const char *irc_user_msgdest( irc_user_t *iu)111 const char *irc_user_msgdest(irc_user_t *iu) 117 112 { 118 113 irc_t *irc = iu->irc; 119 114 irc_channel_t *ic = NULL; 120 115 121 if( iu->last_channel ) 122 { 123 if( iu->last_channel->flags & IRC_CHANNEL_JOINED ) 116 if (iu->last_channel) { 117 if (iu->last_channel->flags & IRC_CHANNEL_JOINED) { 124 118 ic = iu->last_channel; 125 else 126 ic = irc_channel_with_user( irc, iu ); 127 } 128 129 if( ic ) 119 } else { 120 ic = irc_channel_with_user(irc, iu); 121 } 122 } 123 124 if (ic) { 130 125 return ic->name; 131 else126 } else { 132 127 return irc->user->nick; 128 } 133 129 } 134 130 135 131 /* cmd = "PRIVMSG" or "NOTICE" */ 136 static void irc_usermsg_( const char *cmd, irc_user_t *iu, const char *format, va_list params)132 static void irc_usermsg_(const char *cmd, irc_user_t *iu, const char *format, va_list params) 137 133 { 138 134 char text[2048]; 139 135 const char *dst; 140 141 g_vsnprintf( text, sizeof( text ), format, params);142 143 dst = irc_user_msgdest( iu);144 irc_send_msg( iu, cmd, dst, text, NULL);145 } 146 147 void irc_usermsg(irc_user_t *iu, char *format, ... 136 137 g_vsnprintf(text, sizeof(text), format, params); 138 139 dst = irc_user_msgdest(iu); 140 irc_send_msg(iu, cmd, dst, text, NULL); 141 } 142 143 void irc_usermsg(irc_user_t *iu, char *format, ...) 148 144 { 149 145 va_list params; 150 va_start( params, format ); 151 irc_usermsg_( "PRIVMSG", iu, format, params ); 152 va_end( params ); 153 } 154 155 void irc_usernotice(irc_user_t *iu, char *format, ... ) 146 147 va_start(params, format); 148 irc_usermsg_("PRIVMSG", iu, format, params); 149 va_end(params); 150 } 151 152 void irc_usernotice(irc_user_t *iu, char *format, ...) 156 153 { 157 154 va_list params; 158 va_start( params, format ); 159 irc_usermsg_( "NOTICE", iu, format, params ); 160 va_end( params ); 161 } 162 163 void irc_rootmsg( irc_t *irc, char *format, ... ) 155 156 va_start(params, format); 157 irc_usermsg_("NOTICE", iu, format, params); 158 va_end(params); 159 } 160 161 void irc_rootmsg(irc_t *irc, char *format, ...) 164 162 { 165 163 va_list params; 166 va_start( params, format ); 167 irc_usermsg_( "PRIVMSG", irc->root, format, params ); 168 va_end( params ); 169 } 170 171 void irc_send_join( irc_channel_t *ic, irc_user_t *iu ) 164 165 va_start(params, format); 166 irc_usermsg_("PRIVMSG", irc->root, format, params); 167 va_end(params); 168 } 169 170 void irc_send_join(irc_channel_t *ic, irc_user_t *iu) 172 171 { 173 172 irc_t *irc = ic->irc; 174 175 irc_write( irc, ":%s!%s@%s JOIN :%s", iu->nick, iu->user, iu->host, ic->name);176 177 if ( iu == irc->user )178 {179 irc_ write( irc, ":%s MODE %s +%s", irc->root->host, ic->name, ic->mode);180 i rc_send_names( ic );181 if( ic->topic && *ic->topic )182 irc_send_topic( ic, FALSE );183 } 184 } 185 186 void irc_send_part( irc_channel_t *ic, irc_user_t *iu, const char *reason)187 { 188 irc_write( ic->irc, ":%s!%s@%s PART %s :%s", iu->nick, iu->user, iu->host, ic->name, reason ? : "");189 } 190 191 void irc_send_quit( irc_user_t *iu, const char *reason)192 { 193 irc_write( iu->irc, ":%s!%s@%s QUIT :%s", iu->nick, iu->user, iu->host, reason ? : "");194 } 195 196 void irc_send_kick( irc_channel_t *ic, irc_user_t *iu, irc_user_t *kicker, const char *reason)197 { 198 irc_write( 199 kicker->host, ic->name, iu->nick, reason ? : "");200 } 201 202 void irc_send_names( irc_channel_t *ic)173 174 irc_write(irc, ":%s!%s@%s JOIN :%s", iu->nick, iu->user, iu->host, ic->name); 175 176 if (iu == irc->user) { 177 irc_write(irc, ":%s MODE %s +%s", irc->root->host, ic->name, ic->mode); 178 irc_send_names(ic); 179 if (ic->topic && *ic->topic) { 180 irc_send_topic(ic, FALSE); 181 } 182 } 183 } 184 185 void irc_send_part(irc_channel_t *ic, irc_user_t *iu, const char *reason) 186 { 187 irc_write(ic->irc, ":%s!%s@%s PART %s :%s", iu->nick, iu->user, iu->host, ic->name, reason ? : ""); 188 } 189 190 void irc_send_quit(irc_user_t *iu, const char *reason) 191 { 192 irc_write(iu->irc, ":%s!%s@%s QUIT :%s", iu->nick, iu->user, iu->host, reason ? : ""); 193 } 194 195 void irc_send_kick(irc_channel_t *ic, irc_user_t *iu, irc_user_t *kicker, const char *reason) 196 { 197 irc_write(ic->irc, ":%s!%s@%s KICK %s %s :%s", kicker->nick, kicker->user, 198 kicker->host, ic->name, iu->nick, reason ? : ""); 199 } 200 201 void irc_send_names(irc_channel_t *ic) 203 202 { 204 203 GSList *l; 205 204 char namelist[385] = ""; 206 205 207 206 /* RFCs say there is no error reply allowed on NAMES, so when the 208 207 channel is invalid, just give an empty reply. */ 209 for( l = ic->users; l; l = l->next ) 210 { 208 for (l = ic->users; l; l = l->next) { 211 209 irc_channel_user_t *icu = l->data; 212 210 irc_user_t *iu = icu->iu; 213 214 if( strlen( namelist ) + strlen( iu->nick ) > sizeof( namelist ) - 4 ) 215 { 216 irc_send_num( ic->irc, 353, "= %s :%s", ic->name, namelist ); 211 212 if (strlen(namelist) + strlen(iu->nick) > sizeof(namelist) - 4) { 213 irc_send_num(ic->irc, 353, "= %s :%s", ic->name, namelist); 217 214 *namelist = 0; 218 215 } 219 220 if ( icu->flags & IRC_CHANNEL_USER_OP )221 strcat( namelist, "@");222 else if( icu->flags & IRC_CHANNEL_USER_HALFOP )223 strcat( namelist, "%");224 else if( icu->flags & IRC_CHANNEL_USER_VOICE )225 strcat( namelist, "+");226 227 strcat( namelist, iu->nick ); 228 strcat( namelist, " ");229 }230 231 if( *namelist ) 232 irc_send_num( ic->irc, 353, "= %s :%s", ic->name, namelist );233 234 irc_send_num( ic->irc, 366, "%s :End of /NAMES list", ic->name );235 } 236 237 void irc_send_topic( irc_channel_t *ic, gboolean topic_change ) 238 { 239 if( topic_change && ic->topic_who)240 241 irc_write( ic->irc, ":%s TOPIC %s :%s", ic->topic_who,242 ic->name, ic->topic && *ic->topic ? ic->topic : "" );243 }244 else if( ic->topic )245 {246 i rc_send_num( ic->irc, 332, "%s :%s", ic->name, ic->topic );247 if( ic->topic_who )248 irc_send_num( ic->irc, 333, "%s %s %d",249 ic->name, ic->topic_who, (int) ic->topic_time );250 } 251 else252 irc_send_num( ic->irc, 331, "%s :No topic for this channel", ic->name );253 } 254 255 void irc_send_whois( irc_user_t *iu)216 217 if (icu->flags & IRC_CHANNEL_USER_OP) { 218 strcat(namelist, "@"); 219 } else if (icu->flags & IRC_CHANNEL_USER_HALFOP) { 220 strcat(namelist, "%"); 221 } else if (icu->flags & IRC_CHANNEL_USER_VOICE) { 222 strcat(namelist, "+"); 223 } 224 225 strcat(namelist, iu->nick); 226 strcat(namelist, " "); 227 } 228 229 if (*namelist) { 230 irc_send_num(ic->irc, 353, "= %s :%s", ic->name, namelist); 231 } 232 233 irc_send_num(ic->irc, 366, "%s :End of /NAMES list", ic->name); 234 } 235 236 void irc_send_topic(irc_channel_t *ic, gboolean topic_change) 237 { 238 if (topic_change && ic->topic_who) { 239 irc_write(ic->irc, ":%s TOPIC %s :%s", ic->topic_who, 240 ic->name, ic->topic && *ic->topic ? ic->topic : ""); 241 } else if (ic->topic) { 242 irc_send_num(ic->irc, 332, "%s :%s", ic->name, ic->topic); 243 if (ic->topic_who) { 244 irc_send_num(ic->irc, 333, "%s %s %d", 245 ic->name, ic->topic_who, (int) ic->topic_time); 246 } 247 } else { 248 irc_send_num(ic->irc, 331, "%s :No topic for this channel", ic->name); 249 } 250 } 251 252 void irc_send_whois(irc_user_t *iu) 256 253 { 257 254 irc_t *irc = iu->irc; 258 259 irc_send_num( irc, 311, "%s %s %s * :%s", 260 iu->nick, iu->user, iu->host, iu->fullname ); 261 262 if( iu->bu ) 263 { 255 256 irc_send_num(irc, 311, "%s %s %s * :%s", 257 iu->nick, iu->user, iu->host, iu->fullname); 258 259 if (iu->bu) { 264 260 bee_user_t *bu = iu->bu; 265 266 irc_send_num( irc, 312, "%s %s.%s :%s network", iu->nick, bu->ic->acc->user, 267 bu->ic->acc->server && *bu->ic->acc->server ? bu->ic->acc->server : "", 268 bu->ic->acc->prpl->name ); 269 270 if( ( bu->status && *bu->status ) || 271 ( bu->status_msg && *bu->status_msg ) ) 272 { 261 262 irc_send_num(irc, 312, "%s %s.%s :%s network", iu->nick, bu->ic->acc->user, 263 bu->ic->acc->server && *bu->ic->acc->server ? bu->ic->acc->server : "", 264 bu->ic->acc->prpl->name); 265 266 if ((bu->status && *bu->status) || 267 (bu->status_msg && *bu->status_msg)) { 273 268 int num = bu->flags & BEE_USER_AWAY ? 301 : 320; 274 275 if( bu->status && bu->status_msg ) 276 irc_send_num( irc, num, "%s :%s (%s)", iu->nick, bu->status, bu->status_msg ); 277 else 278 irc_send_num( irc, num, "%s :%s", iu->nick, bu->status ? : bu->status_msg ); 279 } 280 else if( !( bu->flags & BEE_USER_ONLINE ) ) 281 { 282 irc_send_num( irc, 301, "%s :%s", iu->nick, "User is offline" ); 283 } 284 285 if( bu->idle_time || bu->login_time ) 286 { 287 irc_send_num( irc, 317, "%s %d %d :seconds idle, signon time", 288 iu->nick, 289 bu->idle_time ? (int) ( time( NULL ) - bu->idle_time ) : 0, 290 (int) bu->login_time ); 291 } 292 } 293 else 294 { 295 irc_send_num( irc, 312, "%s %s :%s", iu->nick, irc->root->host, IRCD_INFO ); 296 } 297 298 irc_send_num( irc, 318, "%s :End of /WHOIS list", iu->nick ); 299 } 300 301 void irc_send_who( irc_t *irc, GSList *l, const char *channel ) 302 { 303 gboolean is_channel = strchr( CTYPES, channel[0] ) != NULL; 304 305 while( l ) 306 { 269 270 if (bu->status && bu->status_msg) { 271 irc_send_num(irc, num, "%s :%s (%s)", iu->nick, bu->status, bu->status_msg); 272 } else { 273 irc_send_num(irc, num, "%s :%s", iu->nick, bu->status ? : bu->status_msg); 274 } 275 } else if (!(bu->flags & BEE_USER_ONLINE)) { 276 irc_send_num(irc, 301, "%s :%s", iu->nick, "User is offline"); 277 } 278 279 if (bu->idle_time || bu->login_time) { 280 irc_send_num(irc, 317, "%s %d %d :seconds idle, signon time", 281 iu->nick, 282 bu->idle_time ? (int) (time(NULL) - bu->idle_time) : 0, 283 (int) bu->login_time); 284 } 285 } else { 286 irc_send_num(irc, 312, "%s %s :%s", iu->nick, irc->root->host, IRCD_INFO); 287 } 288 289 irc_send_num(irc, 318, "%s :End of /WHOIS list", iu->nick); 290 } 291 292 void irc_send_who(irc_t *irc, GSList *l, const char *channel) 293 { 294 gboolean is_channel = strchr(CTYPES, channel[0]) != NULL; 295 296 while (l) { 307 297 irc_user_t *iu = l->data; 308 if( is_channel ) 309 iu = ((irc_channel_user_t*)iu)->iu; 298 if (is_channel) { 299 iu = ((irc_channel_user_t *) iu)->iu; 300 } 310 301 /* TODO(wilmer): Restore away/channel information here */ 311 irc_send_num( 312 313 314 iu->fullname);302 irc_send_num(irc, 352, "%s %s %s %s %s %c :0 %s", 303 is_channel ? channel : "*", iu->user, iu->host, irc->root->host, 304 iu->nick, iu->flags & IRC_USER_AWAY ? 'G' : 'H', 305 iu->fullname); 315 306 l = l->next; 316 307 } 317 318 irc_send_num( irc, 315, "%s :End of /WHO list", channel);319 } 320 321 void irc_send_msg( irc_user_t *iu, const char *type, const char *dst, const char *msg, const char *prefix)308 309 irc_send_num(irc, 315, "%s :End of /WHO list", channel); 310 } 311 312 void irc_send_msg(irc_user_t *iu, const char *type, const char *dst, const char *msg, const char *prefix) 322 313 { 323 314 char last = 0; 324 315 const char *s = msg, *line = msg; 325 char raw_msg[strlen(msg)+1024]; 326 327 while( !last ) 328 { 329 if( *s == '\r' && *(s+1) == '\n' ) 316 char raw_msg[strlen(msg) + 1024]; 317 318 while (!last) { 319 if (*s == '\r' && *(s + 1) == '\n') { 330 320 s++; 331 if( *s == '\n' )332 {321 } 322 if (*s == '\n') { 333 323 last = s[1] == 0; 334 } 335 else 336 { 324 } else { 337 325 last = s[0] == 0; 338 326 } 339 if( *s == 0 || *s == '\n' ) 340 { 341 if( g_strncasecmp( line, "/me ", 4 ) == 0 && ( !prefix || !*prefix ) && 342 g_strcasecmp( type, "PRIVMSG" ) == 0 ) 343 { 344 strcpy( raw_msg, "\001ACTION " ); 345 strncat( raw_msg, line + 4, s - line - 4 ); 346 strcat( raw_msg, "\001" ); 347 irc_send_msg_raw( iu, type, dst, raw_msg ); 348 } 349 else 350 { 327 if (*s == 0 || *s == '\n') { 328 if (g_strncasecmp(line, "/me ", 4) == 0 && (!prefix || !*prefix) && 329 g_strcasecmp(type, "PRIVMSG") == 0) { 330 strcpy(raw_msg, "\001ACTION "); 331 strncat(raw_msg, line + 4, s - line - 4); 332 strcat(raw_msg, "\001"); 333 irc_send_msg_raw(iu, type, dst, raw_msg); 334 } else { 351 335 *raw_msg = '\0'; 352 if( prefix && *prefix ) 353 strcpy( raw_msg, prefix ); 354 strncat( raw_msg, line, s - line ); 355 irc_send_msg_raw( iu, type, dst, raw_msg ); 336 if (prefix && *prefix) { 337 strcpy(raw_msg, prefix); 338 } 339 strncat(raw_msg, line, s - line); 340 irc_send_msg_raw(iu, type, dst, raw_msg); 356 341 } 357 342 line = s + 1; 358 343 } 359 s 360 } 361 } 362 363 void irc_send_msg_raw( irc_user_t *iu, const char *type, const char *dst, const char *msg)364 { 365 irc_write( 366 iu->nick, iu->user, iu->host, type, dst, msg && *msg ? msg : " ");367 } 368 369 void irc_send_msg_f( irc_user_t *iu, const char *type, const char *dst, const char *format, ...)344 s++; 345 } 346 } 347 348 void irc_send_msg_raw(irc_user_t *iu, const char *type, const char *dst, const char *msg) 349 { 350 irc_write(iu->irc, ":%s!%s@%s %s %s :%s", 351 iu->nick, iu->user, iu->host, type, dst, msg && *msg ? msg : " "); 352 } 353 354 void irc_send_msg_f(irc_user_t *iu, const char *type, const char *dst, const char *format, ...) 370 355 { 371 356 char text[IRC_MAX_LINE]; 372 357 va_list params; 373 374 va_start( params, format);375 g_vsnprintf( text, IRC_MAX_LINE, format, params);376 va_end( params);377 378 irc_write( 379 iu->nick, iu->user, iu->host, type, dst, text);380 } 381 382 void irc_send_nick( irc_user_t *iu, const char *new)383 { 384 irc_write( 385 iu->nick, iu->user, iu->host, new);358 359 va_start(params, format); 360 g_vsnprintf(text, IRC_MAX_LINE, format, params); 361 va_end(params); 362 363 irc_write(iu->irc, ":%s!%s@%s %s %s :%s", 364 iu->nick, iu->user, iu->host, type, dst, text); 365 } 366 367 void irc_send_nick(irc_user_t *iu, const char *new) 368 { 369 irc_write(iu->irc, ":%s!%s@%s NICK %s", 370 iu->nick, iu->user, iu->host, new); 386 371 } 387 372 388 373 /* Send an update of a user's mode inside a channel, compared to what it was. */ 389 void irc_send_channel_user_mode_diff( 390 irc_channel_user_flags_t old, irc_channel_user_flags_t new)391 { 392 char changes[3 *(5+strlen(iu->nick))];393 char from[strlen(ic->irc->root->nick) +strlen(ic->irc->root->user)+strlen(ic->irc->root->host)+3];374 void irc_send_channel_user_mode_diff(irc_channel_t *ic, irc_user_t *iu, 375 irc_channel_user_flags_t old, irc_channel_user_flags_t new) 376 { 377 char changes[3 * (5 + strlen(iu->nick))]; 378 char from[strlen(ic->irc->root->nick) + strlen(ic->irc->root->user) + strlen(ic->irc->root->host) + 3]; 394 379 int n; 395 380 396 381 *changes = '\0'; n = 0; 397 if( ( old & IRC_CHANNEL_USER_OP ) != ( new & IRC_CHANNEL_USER_OP ) ) 398 { 399 n ++; 400 if( new & IRC_CHANNEL_USER_OP ) 401 strcat( changes, "+o" ); 402 else 403 strcat( changes, "-o" ); 404 } 405 if( ( old & IRC_CHANNEL_USER_HALFOP ) != ( new & IRC_CHANNEL_USER_HALFOP ) ) 406 { 407 n ++; 408 if( new & IRC_CHANNEL_USER_HALFOP ) 409 strcat( changes, "+h" ); 410 else 411 strcat( changes, "-h" ); 412 } 413 if( ( old & IRC_CHANNEL_USER_VOICE ) != ( new & IRC_CHANNEL_USER_VOICE ) ) 414 { 415 n ++; 416 if( new & IRC_CHANNEL_USER_VOICE ) 417 strcat( changes, "+v" ); 418 else 419 strcat( changes, "-v" ); 420 } 421 while( n ) 422 { 423 strcat( changes, " " ); 424 strcat( changes, iu->nick ); 425 n --; 426 } 427 428 if( set_getbool( &ic->irc->b->set, "simulate_netsplit" ) ) 429 g_snprintf( from, sizeof( from ), "%s", ic->irc->root->host ); 430 else 431 g_snprintf( from, sizeof( from ), "%s!%s@%s", ic->irc->root->nick, 432 ic->irc->root->user, ic->irc->root->host ); 433 434 if( *changes ) 435 irc_write( ic->irc, ":%s MODE %s %s", from, ic->name, changes ); 436 } 437 438 void irc_send_invite( irc_user_t *iu, irc_channel_t *ic ) 382 if ((old & IRC_CHANNEL_USER_OP) != (new & IRC_CHANNEL_USER_OP)) { 383 n++; 384 if (new & IRC_CHANNEL_USER_OP) { 385 strcat(changes, "+o"); 386 } else { 387 strcat(changes, "-o"); 388 } 389 } 390 if ((old & IRC_CHANNEL_USER_HALFOP) != (new & IRC_CHANNEL_USER_HALFOP)) { 391 n++; 392 if (new & IRC_CHANNEL_USER_HALFOP) { 393 strcat(changes, "+h"); 394 } else { 395 strcat(changes, "-h"); 396 } 397 } 398 if ((old & IRC_CHANNEL_USER_VOICE) != (new & IRC_CHANNEL_USER_VOICE)) { 399 n++; 400 if (new & IRC_CHANNEL_USER_VOICE) { 401 strcat(changes, "+v"); 402 } else { 403 strcat(changes, "-v"); 404 } 405 } 406 while (n) { 407 strcat(changes, " "); 408 strcat(changes, iu->nick); 409 n--; 410 } 411 412 if (set_getbool(&ic->irc->b->set, "simulate_netsplit")) { 413 g_snprintf(from, sizeof(from), "%s", ic->irc->root->host); 414 } else { 415 g_snprintf(from, sizeof(from), "%s!%s@%s", ic->irc->root->nick, 416 ic->irc->root->user, ic->irc->root->host); 417 } 418 419 if (*changes) { 420 irc_write(ic->irc, ":%s MODE %s %s", from, ic->name, changes); 421 } 422 } 423 424 void irc_send_invite(irc_user_t *iu, irc_channel_t *ic) 439 425 { 440 426 irc_t *irc = iu->irc; 441 442 irc_write( 443 iu->nick, iu->user, iu->host, irc->user->nick, ic->name);444 } 427 428 irc_write(iu->irc, ":%s!%s@%s INVITE %s :%s", 429 iu->nick, iu->user, iu->host, irc->user->nick, ic->name); 430 }
Note: See TracChangeset
for help on using the changeset viewer.