Mon, 27 Aug 2001 07:14:08 +0000
[gaim-migrate @ 2181]
one small thing to get the count to 0
| 2086 | 1 | /* |
| 2 | * gaim - IRC Protocol Plugin | |
| 3 | * | |
| 4 | * Copyright (C) 2000-2001, Rob Flynn <rob@tgflinux.com> | |
| 5 | * Copyright (C) 1998-1999, Mark Spencer <markster@marko.net> | |
| 6 | * | |
| 7 | * This program is free software; you can redistribute it and/or modify | |
| 8 | * it under the terms of the GNU General Public License as published by | |
| 9 | * the Free Software Foundation; either version 2 of the License, or | |
| 10 | * (at your option) any later version. | |
| 11 | * | |
| 12 | * This program is distributed in the hope that it will be useful, | |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 15 | * GNU General Public License for more details. | |
| 16 | * | |
| 17 | * You should have received a copy of the GNU General Public License | |
| 18 | * along with this program; if not, write to the Free Software | |
| 19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 20 | * | |
| 21 | */ | |
| 22 | ||
|
2090
bab8b7e309db
[gaim-migrate @ 2100]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2086
diff
changeset
|
23 | #include <config.h> |
| 2086 | 24 | |
| 25 | ||
| 26 | #include <netdb.h> | |
| 27 | #include <unistd.h> | |
| 28 | #include <errno.h> | |
| 29 | #include <netinet/in.h> | |
| 30 | #include <arpa/inet.h> | |
| 31 | #include <fcntl.h> | |
| 32 | #include <string.h> | |
| 33 | #include <stdlib.h> | |
| 34 | #include <stdio.h> | |
| 35 | #include <time.h> | |
| 36 | #include <sys/socket.h> | |
| 37 | #include <sys/stat.h> | |
| 38 | #include <ctype.h> | |
| 39 | #include "multi.h" | |
| 40 | #include "prpl.h" | |
| 41 | #include "gaim.h" | |
| 42 | #include "proxy.h" | |
| 43 | ||
| 44 | #include "pixmaps/free_icon.xpm" | |
| 45 | ||
| 46 | #define IRC_BUF_LEN 4096 | |
| 47 | ||
| 48 | ||
| 49 | #define USEROPT_SERV 0 | |
| 50 | #define USEROPT_PORT 1 | |
| 51 | ||
| 52 | static int chat_id = 0; | |
| 53 | ||
| 54 | struct irc_channel { | |
| 55 | int id; | |
| 56 | gchar *name; | |
| 57 | }; | |
| 58 | ||
| 59 | struct irc_data { | |
| 60 | int fd; | |
| 61 | int inpa; /* used for non-block logins */ | |
| 62 | ||
| 63 | int timer; | |
| 64 | ||
| 65 | int totalblocks; | |
| 66 | int recblocks; | |
| 67 | ||
| 68 | GSList *templist; | |
| 69 | GList *channels; | |
| 70 | }; | |
| 71 | ||
| 72 | static char *irc_name() | |
| 73 | { | |
| 74 | return "IRC"; | |
| 75 | } | |
| 76 | ||
| 77 | static void irc_get_info(struct gaim_connection *gc, char *who); | |
| 78 | ||
| 79 | static void irc_join_chat(struct gaim_connection *gc, int id, char *name) | |
| 80 | { | |
| 81 | struct irc_data *idata = (struct irc_data *)gc->proto_data; | |
| 82 | gchar *buf = (gchar *) g_malloc(IRC_BUF_LEN + 1); | |
| 83 | ||
| 84 | g_snprintf(buf, IRC_BUF_LEN, "JOIN %s\n", name); | |
| 85 | write(idata->fd, buf, strlen(buf)); | |
| 86 | write(idata->fd, buf, strlen(buf)); | |
| 87 | ||
| 88 | g_free(buf); | |
| 89 | } | |
| 90 | ||
| 91 | static void irc_update_user(struct gaim_connection *gc, char *name, int status) | |
| 92 | { | |
| 93 | struct irc_data *idata = (struct irc_data *)gc->proto_data; | |
| 94 | struct irc_channel *u; | |
| 95 | GSList *temp = idata->templist; | |
| 96 | ||
| 97 | /* Loop through our list */ | |
| 98 | ||
| 99 | while (temp) { | |
| 100 | u = (struct irc_channel *)temp->data; | |
| 101 | if (g_strcasecmp(u->name, name) == 0) { | |
| 102 | u->id = status; | |
| 103 | return; | |
| 104 | } | |
| 105 | ||
| 106 | temp = g_slist_next(temp); | |
| 107 | } | |
| 108 | return; | |
| 109 | } | |
| 110 | ||
|
2137
b0c18ea1dee8
[gaim-migrate @ 2147]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2131
diff
changeset
|
111 | static gboolean irc_request_buddy_update(gpointer data) |
| 2086 | 112 | { |
|
2137
b0c18ea1dee8
[gaim-migrate @ 2147]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2131
diff
changeset
|
113 | struct gaim_connection *gc = data; |
| 2086 | 114 | struct irc_data *idata = (struct irc_data *)gc->proto_data; |
| 115 | GSList *grp = gc->groups; | |
| 116 | GSList *person; | |
| 117 | struct group *g; | |
| 118 | struct buddy *b; | |
| 119 | struct irc_channel *u; | |
| 120 | ||
| 121 | if (idata->templist != NULL) | |
|
2137
b0c18ea1dee8
[gaim-migrate @ 2147]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2131
diff
changeset
|
122 | return TRUE; |
| 2086 | 123 | |
| 124 | idata->recblocks = 0; | |
| 125 | idata->totalblocks = 1; | |
| 126 | ||
| 127 | /* First, let's check to see if we have anyone on our buddylist */ | |
| 128 | if (!grp) { | |
|
2131
ef072ae1b2b8
[gaim-migrate @ 2141]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2123
diff
changeset
|
129 | return TRUE; |
| 2086 | 130 | } |
| 131 | ||
| 132 | /* Send the first part of our request */ | |
| 133 | write(idata->fd, "ISON", 4); | |
| 134 | ||
| 135 | /* Step through our list of groups */ | |
| 136 | while (grp) { | |
| 137 | ||
| 138 | g = (struct group *)grp->data; | |
| 139 | person = g->members; | |
| 140 | ||
| 141 | while (person) { | |
| 142 | b = (struct buddy *)person->data; | |
| 143 | ||
| 144 | /* We will store our buddy info here. I know, this is cheap | |
| 145 | * but hey, its the exact same data structure. Why should we | |
| 146 | * bother with making another one */ | |
| 147 | ||
| 148 | u = g_new0(struct irc_channel, 1); | |
| 149 | u->id = 0; /* Assume by default that they're offline */ | |
| 150 | u->name = strdup(b->name); | |
| 151 | ||
| 152 | write(idata->fd, " ", 1); | |
| 153 | write(idata->fd, u->name, strlen(u->name)); | |
| 154 | idata->templist = g_slist_append(idata->templist, u); | |
| 155 | ||
| 156 | person = person->next; | |
| 157 | } | |
| 158 | ||
| 159 | grp = g_slist_next(grp); | |
| 160 | } | |
| 161 | write(idata->fd, "\n", 1); | |
|
2131
ef072ae1b2b8
[gaim-migrate @ 2141]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2123
diff
changeset
|
162 | return TRUE; |
| 2086 | 163 | } |
| 164 | ||
| 165 | ||
|
2123
4cfdde0aa3f1
[gaim-migrate @ 2133]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2100
diff
changeset
|
166 | static int irc_send_im(struct gaim_connection *gc, char *who, char *message, int away) |
| 2086 | 167 | { |
| 168 | ||
| 169 | struct irc_data *idata = (struct irc_data *)gc->proto_data; | |
| 170 | gchar *buf = (gchar *) g_malloc(IRC_BUF_LEN + 1); | |
| 171 | ||
| 172 | if (who[0] == '@' || who[0] == '+') { | |
| 173 | ||
| 174 | /* If the user trys to msg an op or a voice from the channel, the convo will try | |
| 175 | * to send it to @nick or +nick... needless to say, this is undesirable. | |
| 176 | */ | |
| 177 | who++; | |
| 178 | } | |
| 179 | ||
| 180 | /* Before we actually send this, we should check to see if they're trying | |
| 181 | * To issue a command and handle it properly. */ | |
| 182 | ||
| 183 | if (message[0] == '/') { | |
| 184 | /* I'll change the implementation of this a little later :-) */ | |
| 185 | if ((g_strncasecmp(message, "/me ", 4) == 0) && (strlen(message) > 4)) { | |
| 186 | /* We have /me!! We have /me!! :-) */ | |
| 187 | ||
| 188 | gchar *temp = (gchar *) g_malloc(IRC_BUF_LEN + 1); | |
| 189 | strcpy(temp, message + 4); | |
| 190 | g_snprintf(buf, IRC_BUF_LEN, "PRIVMSG %s :%cACTION %s%c\n", who, '\001', temp, | |
| 191 | '\001'); | |
| 192 | g_free(temp); | |
| 193 | } else if (!g_strncasecmp(message, "/whois ", 7) && (strlen(message) > 7)) { | |
| 194 | gchar *temp = (gchar *) g_malloc(IRC_BUF_LEN + 1); | |
| 195 | strcpy(temp, message + 7); | |
| 196 | irc_get_info(gc, temp); | |
| 197 | g_free(temp); | |
| 198 | ||
|
2123
4cfdde0aa3f1
[gaim-migrate @ 2133]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2100
diff
changeset
|
199 | return 0; |
| 2086 | 200 | } |
| 201 | ||
| 202 | } else { | |
| 203 | g_snprintf(buf, IRC_BUF_LEN, "PRIVMSG %s :%s\n", who, message); | |
| 204 | } | |
| 205 | ||
| 206 | write(idata->fd, buf, strlen(buf)); | |
| 207 | ||
| 208 | g_free(buf); | |
|
2123
4cfdde0aa3f1
[gaim-migrate @ 2133]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2100
diff
changeset
|
209 | return 0; |
| 2086 | 210 | } |
| 211 | ||
| 212 | static int find_id_by_name(struct gaim_connection *gc, char *name) | |
| 213 | { | |
| 214 | gchar *temp = (gchar *) g_malloc(IRC_BUF_LEN + 1); | |
| 215 | GList *templist; | |
| 216 | struct irc_channel *channel; | |
| 217 | ||
| 218 | templist = ((struct irc_data *)gc->proto_data)->channels; | |
| 219 | ||
| 220 | while (templist) { | |
| 221 | channel = (struct irc_channel *)templist->data; | |
| 222 | ||
| 223 | g_snprintf(temp, IRC_BUF_LEN, "#%s", channel->name); | |
| 224 | ||
| 225 | if (g_strcasecmp(temp, name) == 0) { | |
| 226 | g_free(temp); | |
| 227 | return channel->id; | |
| 228 | } | |
| 229 | ||
| 230 | templist = templist->next; | |
| 231 | } | |
| 232 | ||
| 233 | g_free(temp); | |
| 234 | ||
| 235 | /* Return -1 if we have no ID */ | |
| 236 | return -1; | |
| 237 | } | |
| 238 | ||
| 239 | static struct irc_channel *find_channel_by_name(struct gaim_connection *gc, char *name) | |
| 240 | { | |
| 241 | gchar *temp = (gchar *) g_malloc(IRC_BUF_LEN + 1); | |
| 242 | GList *templist; | |
| 243 | struct irc_channel *channel; | |
| 244 | ||
| 245 | templist = ((struct irc_data *)gc->proto_data)->channels; | |
| 246 | ||
| 247 | while (templist) { | |
| 248 | channel = (struct irc_channel *)templist->data; | |
| 249 | ||
| 250 | g_snprintf(temp, IRC_BUF_LEN, "%s", channel->name); | |
| 251 | ||
| 252 | if (g_strcasecmp(temp, name) == 0) { | |
| 253 | g_free(temp); | |
| 254 | return channel; | |
| 255 | } | |
| 256 | ||
| 257 | templist = templist->next; | |
| 258 | } | |
| 259 | ||
| 260 | g_free(temp); | |
| 261 | ||
| 262 | /* If we found nothing, return nothing :-) */ | |
| 263 | return NULL; | |
| 264 | } | |
| 265 | ||
| 266 | static struct irc_channel *find_channel_by_id(struct gaim_connection *gc, int id) | |
| 267 | { | |
| 268 | struct irc_data *idata = (struct irc_data *)gc->proto_data; | |
| 269 | struct irc_channel *channel; | |
| 270 | ||
| 271 | GList *temp; | |
| 272 | ||
| 273 | temp = idata->channels; | |
| 274 | ||
| 275 | while (temp) { | |
| 276 | channel = (struct irc_channel *)temp->data; | |
| 277 | ||
| 278 | if (channel->id == id) { | |
| 279 | /* We've found our man */ | |
| 280 | return channel; | |
| 281 | } | |
| 282 | ||
| 283 | temp = temp->next; | |
| 284 | } | |
| 285 | ||
| 286 | ||
| 287 | /* If we didnt find one, return NULL */ | |
| 288 | return NULL; | |
| 289 | } | |
| 290 | ||
| 291 | static struct conversation *find_chat(struct gaim_connection *gc, char *name) | |
| 292 | { | |
| 293 | GSList *bcs = gc->buddy_chats; | |
| 294 | struct conversation *b = NULL; | |
| 295 | char *chat = g_strdup(normalize(name)); | |
| 296 | ||
| 297 | while (bcs) { | |
| 298 | b = bcs->data; | |
| 299 | if (!strcasecmp(normalize(b->name), chat)) | |
| 300 | break; | |
| 301 | b = NULL; | |
| 302 | bcs = bcs->next; | |
| 303 | } | |
| 304 | ||
| 305 | g_free(chat); | |
| 306 | return b; | |
| 307 | } | |
| 308 | ||
| 309 | static void irc_chat_leave(struct gaim_connection *gc, int id); | |
|
2167
cbb558585911
[gaim-migrate @ 2177]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2162
diff
changeset
|
310 | static int irc_chat_send(struct gaim_connection *gc, int id, char *message) |
| 2086 | 311 | { |
| 312 | ||
| 313 | struct irc_data *idata = (struct irc_data *)gc->proto_data; | |
| 314 | struct irc_channel *channel = NULL; | |
| 315 | gchar *buf = (gchar *) g_malloc(IRC_BUF_LEN + 1); | |
| 316 | char **kick; | |
| 317 | gboolean is_command = FALSE; | |
| 318 | /* First lets get our current channel */ | |
| 319 | channel = find_channel_by_id(gc, id); | |
| 320 | ||
| 321 | ||
| 322 | if (!channel) { | |
| 323 | /* If for some reason we've lost our channel, let's bolt */ | |
| 324 | g_free(buf); | |
|
2167
cbb558585911
[gaim-migrate @ 2177]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2162
diff
changeset
|
325 | return -EINVAL; |
| 2086 | 326 | } |
| 327 | ||
| 328 | ||
| 329 | /* Before we actually send this, we should check to see if they're trying | |
| 330 | * To issue a command and handle it properly. */ | |
| 331 | ||
| 332 | if (message[0] == '/') { | |
| 333 | ||
| 334 | if ((g_strncasecmp(message, "/me ", 4) == 0) && (strlen(message) > 4)) { | |
| 335 | /* We have /me!! We have /me!! :-) */ | |
| 336 | ||
| 337 | gchar *temp = (gchar *) g_malloc(IRC_BUF_LEN + 1); | |
| 338 | strcpy(temp, message + 4); | |
| 339 | ||
| 340 | g_snprintf(buf, IRC_BUF_LEN, "PRIVMSG #%s :%cACTION %s%c\n", channel->name, | |
| 341 | '\001', temp, '\001'); | |
| 342 | g_free(temp); | |
| 343 | } else if ((g_strncasecmp(message, "/op ", 4) == 0) && (strlen(message) > 4)) { | |
| 344 | gchar *temp = (gchar *) g_malloc(IRC_BUF_LEN + 1); | |
| 345 | strcpy(temp, message + 4); | |
| 346 | ||
| 347 | g_snprintf(buf, IRC_BUF_LEN, "MODE #%s +o %s\n", channel->name, temp); | |
| 348 | ||
| 349 | g_free(temp); | |
| 350 | is_command = TRUE; | |
| 351 | ||
| 352 | } else if ((g_strncasecmp(message, "/deop ", 6) == 0) && (strlen(message) > 6)) { | |
| 353 | gchar *temp = (gchar *) g_malloc(IRC_BUF_LEN + 1); | |
| 354 | strcpy(temp, message + 6); | |
| 355 | g_snprintf(buf, IRC_BUF_LEN, "MODE #%s -o %s\n", channel->name, temp); | |
| 356 | ||
| 357 | g_free(temp); | |
| 358 | is_command = TRUE; | |
| 359 | } | |
| 360 | ||
| 361 | else if ((g_strncasecmp(message, "/voice ", 7) == 0) && (strlen(message) > 7)) { | |
| 362 | gchar *temp = (gchar *) g_malloc(IRC_BUF_LEN + 1); | |
| 363 | strcpy(temp, message + 7); | |
| 364 | ||
| 365 | g_snprintf(buf, IRC_BUF_LEN, "MODE #%s +v %s\n", channel->name, temp); | |
| 366 | ||
| 367 | g_free(temp); | |
| 368 | is_command = TRUE; | |
| 369 | ||
| 370 | } else if ((g_strncasecmp(message, "/devoice ", 9) == 0) && (strlen(message) > 9)) { | |
| 371 | gchar *temp = (gchar *) g_malloc(IRC_BUF_LEN + 1); | |
| 372 | strcpy(temp, message + 6); | |
| 373 | g_snprintf(buf, IRC_BUF_LEN, "MODE #%s -v %s\n", channel->name, temp); | |
| 374 | ||
| 375 | g_free(temp); | |
| 376 | is_command = TRUE; | |
| 377 | } else if ((g_strncasecmp(message, "/mode ", 6) == 0) && (strlen(message) > 6)) { | |
| 378 | gchar *temp = (gchar *) g_malloc(IRC_BUF_LEN + 1); | |
| 379 | strcpy(temp, message + 6); | |
| 380 | g_snprintf(buf, IRC_BUF_LEN, "MODE #%s %s\n", channel->name, temp); | |
| 381 | g_free(temp); | |
| 382 | is_command = TRUE; | |
| 383 | } | |
| 384 | ||
| 385 | else if (!g_strncasecmp(message, "/whois ", 7) && (strlen(message) > 7)) { | |
| 386 | gchar *temp = (gchar *) g_malloc(IRC_BUF_LEN + 1); | |
| 387 | ||
| 388 | strcpy(temp, message + 7); | |
| 389 | irc_get_info(gc, temp); | |
| 390 | g_free(temp); | |
| 391 | is_command = TRUE; | |
| 392 | ||
| 393 | } | |
| 394 | ||
| 395 | else if (!g_strncasecmp(message, "/topic ", 7) && (strlen(message) > 7)) { | |
| 396 | gchar *temp = (gchar *) g_malloc(IRC_BUF_LEN + 1); | |
| 397 | strcpy(temp, message + 7); | |
| 398 | ||
| 399 | /* Send the chat topic change request */ | |
| 400 | serv_chat_set_topic(gc, id, temp); | |
| 401 | ||
| 402 | g_free(temp); | |
| 403 | is_command = TRUE; | |
| 404 | } | |
| 405 | ||
| 406 | else if (!g_strncasecmp(message, "/part", 5) && (strlen(message) == 5)) { | |
| 407 | ||
| 408 | /* If I'm not mistaken, the chat_leave command was coded under the | |
| 409 | * pretense that it would only occur when someone closed the window. | |
| 410 | * For this reason, the /part command will not close the window. Nor | |
| 411 | * will the window close when the user is /kicked. I'll let you decide | |
| 412 | * the best way to fix it--I'd imagine it'd just be a little line like | |
| 413 | * if (convo) close (convo), but I'll let you decide where to put it. | |
| 414 | */ | |
| 415 | ||
| 416 | irc_chat_leave(gc, id); | |
| 417 | is_command = TRUE; | |
|
2167
cbb558585911
[gaim-migrate @ 2177]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2162
diff
changeset
|
418 | return 0; |
| 2086 | 419 | |
| 420 | ||
| 421 | } | |
| 422 | ||
| 423 | else if (!g_strncasecmp(message, "/join ", 6) && (strlen(message) > 6)) { | |
| 424 | ||
| 425 | gchar *temp = (gchar *) g_malloc(IRC_BUF_LEN + 1); | |
| 426 | ||
| 427 | strcpy(temp, message + 6); | |
| 428 | ||
| 429 | ||
| 430 | irc_join_chat(gc, 0, temp); | |
| 431 | g_free(temp); | |
| 432 | is_command = TRUE; | |
|
2167
cbb558585911
[gaim-migrate @ 2177]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2162
diff
changeset
|
433 | return 0; |
| 2086 | 434 | } |
| 435 | ||
| 436 | else if (!g_strncasecmp(message, "/raw ", 5) && (strlen(message) > 5)) { | |
| 437 | gchar *temp = (gchar *) g_malloc(IRC_BUF_LEN + 1); | |
| 438 | strcpy(temp, message + 5); | |
| 439 | g_snprintf(buf, IRC_BUF_LEN, "%s\r\n", temp); | |
| 440 | g_free(temp); | |
| 441 | is_command = TRUE; | |
| 442 | } | |
| 443 | ||
| 444 | else if (!g_strncasecmp(message, "/quote ", 7) && (strlen(message) > 7)) { | |
| 445 | gchar *temp = (gchar *) g_malloc(IRC_BUF_LEN + 1); | |
| 446 | strcpy(temp, message + 7); | |
| 447 | g_snprintf(buf, IRC_BUF_LEN, "%s\r\n", temp); | |
| 448 | g_free(temp); | |
| 449 | is_command = TRUE; | |
| 450 | } | |
| 451 | ||
| 452 | else if (!g_strncasecmp(message, "/kick ", 6) && (strlen(message) > 6)) { | |
| 453 | gchar *temp = (gchar *) g_malloc(IRC_BUF_LEN + 1); | |
| 454 | strcpy(temp, message + 6); | |
| 455 | kick = g_strsplit(temp, " ", 2); | |
| 456 | g_snprintf(buf, IRC_BUF_LEN, "KICK #%s %s :%s\r\n", channel->name, kick[0], | |
| 457 | kick[1]); | |
| 458 | g_free(temp); | |
| 459 | is_command = TRUE; | |
| 460 | } | |
| 461 | ||
| 462 | /* FIXME: I'll go back in and grab this later. -- Rob */ | |
| 463 | /* | |
| 464 | I THOUGHT THIS WOULD WORK, BUT I WAS WRONG. WOULD SOMEONE KINDLY FIX IT? | |
| 465 | ||
| 466 | ||
| 467 | else if (!g_strncasecmp(message, "/help", 5)) { | |
| 468 | gchar *temp = (gchar *) g_malloc(IRC_BUF_LEN + 1); | |
| 469 | strcpy(temp, message + 5); | |
| 470 | if (temp == "") { | |
| 471 | ||
| 472 | serv_got_chat_in(gc, id, "gAIM", 0, "Available Commands:"); | |
| 473 | serv_got_chat_in(gc, id, "gAIM", 0, " "); | |
| 474 | serv_got_chat_in(gc, id, "gAIM", 0, "<b>op voice kick </b>"); | |
| 475 | serv_got_chat_in(gc, id, "gAIM", 0, "<b>deop devoice whois</b>"); | |
| 476 | serv_got_chat_in(gc, id, "gAIM", 0, "<b>me raw quote</b>"); | |
| 477 | serv_got_chat_in(gc, id, "gAIM", 0, "<b>mode</b>"); | |
| 478 | } | |
| 479 | else { | |
| 480 | serv_got_chat_in(gc, id, "gAIM", 0, "Usage: "); | |
| 481 | if (temp == "op") | |
| 482 | serv_got_chat_in(gc, id, "gAIM", 0, "<b>/op <nick></b> - Gives operator status to user."); | |
| 483 | else if (temp == "deop") | |
| 484 | serv_got_chat_in(gc, id, "gAIM", 0, "<b>/deop <nick></b> - Removes operator status from user."); | |
| 485 | else if (temp == "me") | |
| 486 | serv_got_chat_in(gc, id, "gAIM", 0, "<b>/me <action></b> - Sends an action to the channel."); | |
| 487 | else if (temp == "mode") | |
| 488 | serv_got_chat_in(gc, id, "gAIM", 0, "<b>/mode {[+|-}|o|p|s|i|t|n|b|v} [<limit][<nick>][<ban mask]</b> - Changes channel and user modes."); | |
| 489 | else if (temp == "voice") | |
| 490 | serv_got_chat_in(gc, id, "gAIM", 0, "<b>/voice <nick></b> - Gives voice status to user."); | |
| 491 | else if (temp == "devoice") | |
| 492 | serv_got_chat_in(gc, id, "gAIM", 0, "<b>/devoice <nick></b> - Removes voice status from user."); | |
| 493 | else if (temp == "raw") | |
| 494 | serv_got_chat_in(gc, id, "gAIM", 0, "<b>/raw <text></b> - Sends raw text to the server."); | |
| 495 | else if (temp == "kick") | |
| 496 | serv_got_chat_in(gc, id, "gAIM", 0, "<b>/kick [<comment>]</b> - Kicks a user out of the channel."); | |
| 497 | else if (temp == "whois") | |
| 498 | serv_got_chat_in(gc, id, "gAIM", 0, "<b>/whois <nick></b> - Gets information about user."); | |
| 499 | else if (temp == "quote") | |
| 500 | serv_got_chat_in(gc, id, "gAIM", 0, "<b>/raw <text></b> - Sends raw text to the server."); | |
| 501 | else | |
| 502 | serv_got_chat_in(gc, id, "gAIM", 0, "No such command."); | |
| 503 | } | |
| 504 | ||
| 505 | g_free(temp); | |
| 506 | is_command = TRUE; | |
| 507 | } | |
| 508 | */ | |
| 509 | ||
| 510 | } | |
| 511 | ||
| 512 | else { | |
| 513 | g_snprintf(buf, IRC_BUF_LEN, "PRIVMSG #%s :%s\n", channel->name, message); | |
| 514 | ||
| 515 | } | |
| 516 | ||
| 517 | ||
| 518 | write(idata->fd, buf, strlen(buf)); | |
| 519 | ||
| 520 | /* Since AIM expects us to receive the message we send, we gotta fake it */ | |
| 521 | if (is_command == FALSE) | |
| 522 | serv_got_chat_in(gc, id, gc->username, 0, message, time((time_t) NULL)); | |
| 523 | ||
| 524 | g_free(buf); | |
| 525 | ||
|
2167
cbb558585911
[gaim-migrate @ 2177]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2162
diff
changeset
|
526 | return 0; |
| 2086 | 527 | } |
|
2167
cbb558585911
[gaim-migrate @ 2177]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2162
diff
changeset
|
528 | |
| 2086 | 529 | static struct conversation *find_conversation_by_id(struct gaim_connection *gc, int id) |
| 530 | { | |
| 531 | GSList *bc = gc->buddy_chats; | |
| 532 | struct conversation *b = NULL; | |
| 533 | ||
| 534 | while (bc) { | |
| 535 | b = (struct conversation *)bc->data; | |
| 536 | if (id == b->id) { | |
| 537 | break; | |
| 538 | } | |
| 539 | bc = bc->next; | |
| 540 | b = NULL; | |
| 541 | } | |
| 542 | ||
| 543 | if (!b) { | |
| 544 | return NULL; | |
| 545 | } | |
| 546 | ||
| 547 | return b; | |
| 548 | } | |
| 549 | ||
| 550 | static struct conversation *find_conversation_by_name(struct gaim_connection *gc, char *name) | |
| 551 | { | |
| 552 | GSList *bc = gc->buddy_chats; | |
| 553 | struct conversation *b = NULL; | |
| 554 | ||
| 555 | while (bc) { | |
| 556 | b = (struct conversation *)bc->data; | |
| 557 | ||
| 558 | if (g_strcasecmp(name, b->name) == 0) { | |
| 559 | break; | |
| 560 | } | |
| 561 | bc = bc->next; | |
| 562 | b = NULL; | |
| 563 | } | |
| 564 | ||
| 565 | if (!b) { | |
| 566 | return NULL; | |
| 567 | } | |
| 568 | ||
| 569 | return b; | |
| 570 | } | |
| 571 | ||
| 572 | ||
| 573 | ||
|
2090
bab8b7e309db
[gaim-migrate @ 2100]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2086
diff
changeset
|
574 | static void irc_callback(gpointer data, gint source, GaimInputCondition condition) |
| 2086 | 575 | { |
| 576 | struct gaim_connection *gc = data; | |
| 577 | int i = 0; | |
| 578 | gchar buf[4096]; | |
| 579 | gchar **buf2; | |
| 580 | struct irc_data *idata; | |
| 581 | ||
| 582 | idata = (struct irc_data *)gc->proto_data; | |
| 583 | ||
| 584 | ||
| 585 | do { | |
| 586 | if (read(idata->fd, buf + i, 1) < 0) { | |
| 587 | hide_login_progress(gc, "Read error"); | |
| 588 | signoff(gc); | |
| 589 | return; | |
| 590 | } | |
| 591 | } while (buf[i++] != '\n'); | |
| 592 | ||
| 593 | buf[--i] = '\0'; | |
| 594 | g_strchomp(buf); | |
| 595 | g_print("%s\n", buf); | |
| 596 | ||
| 597 | /* Check for errors */ | |
| 598 | ||
| 599 | if (((strstr(buf, "ERROR :") && (!strstr(buf, "PRIVMSG ")) && | |
| 600 | (!strstr(buf, "NOTICE ")) && (strlen(buf) > 7)))) { | |
| 601 | ||
|
2147
ece6ed1ca236
[gaim-migrate @ 2157]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2137
diff
changeset
|
602 | /* |
|
ece6ed1ca236
[gaim-migrate @ 2157]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2137
diff
changeset
|
603 | * The ERROR command is for use by servers when reporting a serious or |
|
ece6ed1ca236
[gaim-migrate @ 2157]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2137
diff
changeset
|
604 | * fatal error to its operators. It may also be sent from one server to |
|
ece6ed1ca236
[gaim-migrate @ 2157]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2137
diff
changeset
|
605 | * another but must not be accepted from any normal unknown clients. |
|
ece6ed1ca236
[gaim-migrate @ 2157]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2137
diff
changeset
|
606 | * |
|
ece6ed1ca236
[gaim-migrate @ 2157]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2137
diff
changeset
|
607 | * An ERROR message is for use for reporting errors which occur with a |
|
ece6ed1ca236
[gaim-migrate @ 2157]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2137
diff
changeset
|
608 | * server-to-server link only. An ERROR message is sent to the server |
|
ece6ed1ca236
[gaim-migrate @ 2157]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2137
diff
changeset
|
609 | * at the other end (which sends it to all of its connected operators) |
|
ece6ed1ca236
[gaim-migrate @ 2157]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2137
diff
changeset
|
610 | * and to all operators currently connected. It is not to be passed |
|
ece6ed1ca236
[gaim-migrate @ 2157]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2137
diff
changeset
|
611 | * onto any other servers by a server if it is received from a server. |
|
ece6ed1ca236
[gaim-migrate @ 2157]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2137
diff
changeset
|
612 | * |
|
ece6ed1ca236
[gaim-migrate @ 2157]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2137
diff
changeset
|
613 | * When a server sends a received ERROR message to its operators, the |
|
ece6ed1ca236
[gaim-migrate @ 2157]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2137
diff
changeset
|
614 | * message should be encapsulated inside a NOTICE message, indicating |
|
ece6ed1ca236
[gaim-migrate @ 2157]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2137
diff
changeset
|
615 | * that the client was not responsible for the error. |
|
ece6ed1ca236
[gaim-migrate @ 2157]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2137
diff
changeset
|
616 | * |
|
ece6ed1ca236
[gaim-migrate @ 2157]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2137
diff
changeset
|
617 | * |
|
ece6ed1ca236
[gaim-migrate @ 2157]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2137
diff
changeset
|
618 | * Basically, ignore this. |
|
ece6ed1ca236
[gaim-migrate @ 2157]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2137
diff
changeset
|
619 | * |
| 2086 | 620 | gchar *u_errormsg; |
| 621 | ||
|
2147
ece6ed1ca236
[gaim-migrate @ 2157]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2137
diff
changeset
|
622 | * Let's get our error message * |
| 2086 | 623 | u_errormsg = g_strdup(buf + 7); |
| 624 | ||
|
2147
ece6ed1ca236
[gaim-migrate @ 2157]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2137
diff
changeset
|
625 | * We got our error message. Now, let's reaise an |
|
ece6ed1ca236
[gaim-migrate @ 2157]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2137
diff
changeset
|
626 | * error dialog * |
| 2086 | 627 | |
| 628 | do_error_dialog(u_errormsg, "Gaim: IRC Error"); | |
| 629 | ||
|
2147
ece6ed1ca236
[gaim-migrate @ 2157]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2137
diff
changeset
|
630 | * And our necessary garbage collection * |
| 2086 | 631 | g_free(u_errormsg); |
| 632 | return; | |
|
2147
ece6ed1ca236
[gaim-migrate @ 2157]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2137
diff
changeset
|
633 | |
|
ece6ed1ca236
[gaim-migrate @ 2157]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2137
diff
changeset
|
634 | */ |
| 2086 | 635 | } |
| 636 | ||
| 637 | /* This should be a whois response. I only care about the first (311) one. I might do | |
| 638 | * the other's later. They're boring. */ | |
| 639 | ||
| 640 | if (((strstr(buf, " 311 ")) && (!strstr(buf, "PRIVMSG")) && (!strstr(buf, "NOTICE")))) { | |
| 641 | char **res; | |
| 642 | ||
| 643 | res = g_strsplit(buf, " ", 7); | |
| 644 | ||
| 645 | if (!strcmp(res[1], "311")) { | |
| 646 | char buf[8192]; | |
| 647 | ||
| 648 | g_snprintf(buf, 4096, "<b>Nick:</b> %s<br>" | |
| 649 | "<b>Host:</b> %s@%s<br>" | |
| 650 | "<b>Name:</b> %s<br>", res[3], res[4], res[5], res[7] + 1); | |
| 651 | ||
|
2137
b0c18ea1dee8
[gaim-migrate @ 2147]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2131
diff
changeset
|
652 | g_show_info_text(buf, NULL); |
| 2086 | 653 | } |
| 654 | ||
| 655 | g_strfreev(res); | |
| 656 | return; | |
| 657 | } | |
| 658 | ||
| 659 | /* Autoresponse to an away message */ | |
| 660 | if (((strstr(buf, " 301 ")) && (!strstr(buf, "PRIVMSG")) && (!strstr(buf, "NOTICE")))) { | |
| 661 | char **res; | |
| 662 | ||
| 663 | res = g_strsplit(buf, " ", 5); | |
| 664 | ||
| 665 | if (!strcmp(res[1], "301")) | |
| 666 | serv_got_im(gc, res[3], res[4] + 1, 1, time((time_t) NULL)); | |
| 667 | ||
| 668 | g_strfreev(res); | |
| 669 | return; | |
| 670 | } | |
| 671 | ||
| 672 | /* Parse the list of names that we receive when we first sign on to | |
| 673 | * a channel */ | |
| 674 | ||
| 675 | if (((strstr(buf, " 353 ")) && (!strstr(buf, "PRIVMSG")) && (!strstr(buf, "NOTICE")))) { | |
| 676 | gchar u_host[255]; | |
| 677 | gchar u_command[32]; | |
| 678 | gchar u_channel[128]; | |
| 679 | gchar u_names[IRC_BUF_LEN + 1]; | |
| 680 | struct conversation *convo = NULL; | |
| 681 | int j; | |
| 682 | ||
| 683 | for (j = 0, i = 0; buf[i] != ' '; j++, i++) { | |
| 684 | u_host[j] = buf[i]; | |
| 685 | } | |
| 686 | ||
| 687 | u_host[j] = '\0'; | |
| 688 | i++; | |
| 689 | ||
| 690 | for (j = 0; buf[i] != ' '; j++, i++) { | |
| 691 | u_command[j] = buf[i]; | |
| 692 | } | |
| 693 | ||
| 694 | u_command[j] = '\0'; | |
| 695 | i++; | |
| 696 | ||
| 697 | for (j = 0; buf[i] != '#'; j++, i++) { | |
| 698 | } | |
| 699 | i++; | |
| 700 | ||
| 701 | for (j = 0; buf[i] != ':'; j++, i++) { | |
| 702 | u_channel[j] = buf[i]; | |
| 703 | } | |
| 704 | ||
| 705 | u_channel[j - 1] = '\0'; | |
| 706 | i++; | |
| 707 | ||
| 708 | while ((buf[i] == ' ') || (buf[i] == ':')) { | |
| 709 | i++; | |
| 710 | } | |
| 711 | ||
| 712 | strcpy(u_names, buf + i); | |
| 713 | ||
| 714 | buf2 = g_strsplit(u_names, " ", 0); | |
| 715 | ||
| 716 | /* Let's get our conversation window */ | |
| 717 | convo = find_conversation_by_name(gc, u_channel); | |
| 718 | ||
| 719 | if (!convo) { | |
| 720 | return; | |
| 721 | } | |
| 722 | ||
| 723 | /* Now that we've parsed the hell out of this big | |
| 724 | * mess, let's try to split up the names properly */ | |
| 725 | ||
| 726 | for (i = 0; buf2[i] != NULL; i++) | |
| 727 | add_chat_buddy(convo, buf2[i]); | |
| 728 | ||
| 729 | /* And free our pointers */ | |
| 730 | g_strfreev(buf2); | |
| 731 | ||
| 732 | return; | |
| 733 | ||
| 734 | } | |
| 735 | ||
| 736 | /* Receive a list of users that are currently online */ | |
| 737 | ||
| 738 | if (((strstr(buf, " 303 ")) && (!strstr(buf, "PRIVMSG")) && (!strstr(buf, "NOTICE")))) { | |
| 739 | gchar u_host[255]; | |
| 740 | gchar u_command[32]; | |
| 741 | gchar u_names[IRC_BUF_LEN + 1]; | |
| 742 | int j; | |
| 743 | ||
| 744 | for (j = 0, i = 0; buf[i] != ' '; j++, i++) { | |
| 745 | u_host[j] = buf[i]; | |
| 746 | } | |
| 747 | ||
| 748 | u_host[j] = '\0'; | |
| 749 | i++; | |
| 750 | ||
| 751 | for (j = 0; buf[i] != ' '; j++, i++) { | |
| 752 | u_command[j] = buf[i]; | |
| 753 | } | |
| 754 | ||
| 755 | u_command[j] = '\0'; | |
| 756 | i++; | |
| 757 | ||
| 758 | for (j = 0; buf[i] != ':'; j++, i++) { | |
| 759 | /* My Nick */ | |
| 760 | } | |
| 761 | i++; | |
| 762 | ||
| 763 | strcpy(u_names, buf + i); | |
| 764 | ||
| 765 | buf2 = g_strsplit(u_names, " ", 0); | |
| 766 | ||
| 767 | /* Now that we've parsed the hell out of this big | |
| 768 | * mess, let's try to split up the names properly */ | |
| 769 | ||
| 770 | for (i = 0; buf2[i] != NULL; i++) { | |
| 771 | /* If we have a name here then our buddy is online. We should | |
| 772 | * update our temporary gslist accordingly. When we achieve our maximum | |
| 773 | * list of names then we should force an update */ | |
| 774 | ||
| 775 | irc_update_user(gc, buf2[i], 1); | |
| 776 | } | |
| 777 | ||
| 778 | /* Increase our received blocks counter */ | |
| 779 | idata->recblocks++; | |
| 780 | ||
| 781 | /* If we have our total number of blocks */ | |
| 782 | if (idata->recblocks == idata->totalblocks) { | |
| 783 | GSList *temp; | |
| 784 | struct irc_channel *u; | |
| 785 | ||
| 786 | /* Let's grab our list of people and bring them all on or off line */ | |
| 787 | temp = idata->templist; | |
| 788 | ||
| 789 | /* Loop */ | |
| 790 | while (temp) { | |
| 791 | ||
| 792 | u = temp->data; | |
| 793 | ||
| 794 | /* Tell Gaim to bring the person on or off line */ | |
| 795 | serv_got_update(gc, u->name, u->id, 0, 0, 0, 0, 0); | |
| 796 | ||
| 797 | /* Grab the next entry */ | |
| 798 | temp = g_slist_next(temp); | |
| 799 | } | |
| 800 | ||
| 801 | /* And now, let's delete all of our entries */ | |
| 802 | temp = idata->templist; | |
| 803 | while (temp) { | |
| 804 | u = temp->data; | |
| 805 | g_free(u->name); | |
| 806 | temp = g_slist_remove(temp, u); | |
| 807 | } | |
| 808 | ||
| 809 | /* Reset our list */ | |
| 810 | idata->totalblocks = 0; | |
| 811 | idata->recblocks = 0; | |
| 812 | ||
| 813 | idata->templist = NULL; | |
| 814 | ||
| 815 | return; | |
| 816 | } | |
| 817 | ||
| 818 | /* And free our pointers */ | |
| 819 | g_strfreev(buf2); | |
| 820 | ||
| 821 | return; | |
| 822 | ||
| 823 | } | |
| 824 | ||
| 825 | ||
| 826 | if ((strstr(buf, " MODE ")) && (strstr(buf, "!")) | |
| 827 | && (strstr(buf, "+v") || strstr(buf, "-v") || strstr(buf, "-o") || strstr(buf, "+o")) | |
| 828 | && (buf[0] == ':') && (!strstr(buf, " NOTICE "))) { | |
| 829 | ||
| 830 | gchar u_channel[128]; | |
| 831 | gchar u_nick[128]; | |
| 832 | ||
| 833 | gchar u_mode[5]; | |
| 834 | char **people; | |
| 835 | gchar *temp, *temp_new; | |
| 836 | ||
| 837 | ||
| 838 | struct irc_channel *channel; | |
| 839 | int j; | |
| 840 | temp = NULL; | |
| 841 | temp_new = NULL; | |
| 842 | ||
| 843 | ||
| 844 | for (j = 0, i = 1; buf[i] != '!'; j++, i++) { | |
| 845 | u_nick[j] = buf[i]; | |
| 846 | } | |
| 847 | u_nick[j] = '\0'; | |
| 848 | i++; | |
| 849 | ||
| 850 | for (j = 0; buf[i] != '#'; j++, i++) { | |
| 851 | } | |
| 852 | i++; | |
| 853 | ||
| 854 | for (j = 0; buf[i] != ' '; j++, i++) { | |
| 855 | u_channel[j] = buf[i]; | |
| 856 | } | |
| 857 | ||
| 858 | u_channel[j] = '\0'; | |
| 859 | i++; | |
| 860 | ||
| 861 | for (j = 0; buf[i] != ' '; j++, i++) { | |
| 862 | u_mode[j] = buf[i]; | |
| 863 | } | |
| 864 | u_mode[j] = '\0'; | |
| 865 | i++; | |
| 866 | ||
| 867 | ||
| 868 | ||
| 869 | ||
| 870 | people = g_strsplit(buf + i, " ", 3); | |
| 871 | ||
| 872 | ||
| 873 | ||
| 874 | channel = find_channel_by_name(gc, u_channel); | |
| 875 | ||
| 876 | if (!channel) { | |
| 877 | return; | |
| 878 | } | |
| 879 | ||
| 880 | for (j = 0; j < strlen(u_mode) - 1; j++) { | |
| 881 | ||
| 882 | ||
| 883 | struct conversation *convo = NULL; | |
| 884 | convo = find_conversation_by_id(gc, channel->id); | |
| 885 | ||
| 886 | ||
| 887 | ||
| 888 | temp = (gchar *) g_malloc(strlen(people[j]) + 3); | |
| 889 | temp_new = (gchar *) g_malloc(strlen(people[j]) + 3); | |
| 890 | g_snprintf(temp, strlen(people[j]) + 2, "@%s", people[j]); | |
| 891 | ||
| 892 | if (u_mode[1] == 'v' && u_mode[0] == '+') { | |
| 893 | g_snprintf(temp_new, strlen(people[j]) + 2, "+%s", people[j]); | |
| 894 | } else if (u_mode[1] == 'o' && u_mode[0] == '+') { | |
| 895 | g_snprintf(temp_new, strlen(people[j]) + 2, "@%s", people[j]); | |
| 896 | } | |
| 897 | ||
| 898 | else if (u_mode[0] == '-') { | |
| 899 | g_snprintf(temp_new, strlen(people[j]) + 1, "%s", people[j]); | |
| 900 | } | |
| 901 | ||
| 902 | ||
| 903 | ||
| 904 | rename_chat_buddy(convo, temp, temp_new); | |
| 905 | g_snprintf(temp, strlen(people[j]) + 2, "+%s", people[j]); | |
| 906 | rename_chat_buddy(convo, temp, temp_new); | |
| 907 | ||
| 908 | rename_chat_buddy(convo, people[j], temp_new); | |
| 909 | ||
| 910 | ||
| 911 | ||
| 912 | ||
| 913 | ||
| 914 | } | |
| 915 | if (temp) | |
| 916 | g_free(temp); | |
| 917 | if (temp_new) | |
| 918 | g_free(temp_new); | |
| 919 | ||
| 920 | return; | |
| 921 | } | |
| 922 | ||
| 923 | ||
| 924 | if ((strstr(buf, " KICK ")) && (strstr(buf, "!")) && (buf[0] == ':') | |
| 925 | && (!strstr(buf, " NOTICE "))) { | |
| 926 | gchar u_channel[128]; | |
| 927 | gchar u_nick[128]; | |
| 928 | gchar u_comment[128]; | |
| 929 | gchar u_who[128]; | |
| 930 | ||
| 931 | int id; | |
| 932 | ||
| 933 | gchar *temp; | |
| 934 | ||
| 935 | ||
| 936 | ||
| 937 | struct irc_channel *channel; | |
| 938 | int j; | |
| 939 | ||
| 940 | temp = NULL; | |
| 941 | ||
| 942 | for (j = 0, i = 1; buf[i] != '!'; j++, i++) { | |
| 943 | u_nick[j] = buf[i]; | |
| 944 | } | |
| 945 | u_nick[j] = '\0'; | |
| 946 | i++; | |
| 947 | ||
| 948 | for (j = 0; buf[i] != '#'; j++, i++) { | |
| 949 | } | |
| 950 | i++; | |
| 951 | ||
| 952 | for (j = 0; buf[i] != ' '; j++, i++) { | |
| 953 | u_channel[j] = buf[i]; | |
| 954 | } | |
| 955 | ||
| 956 | u_channel[j] = '\0'; | |
| 957 | i++; | |
| 958 | ||
| 959 | for (j = 0; buf[i] != ' '; j++, i++) { | |
| 960 | u_who[j] = buf[i]; | |
| 961 | } | |
| 962 | u_who[j] = '\0'; | |
| 963 | i++; | |
| 964 | i++; | |
| 965 | strcpy(u_comment, buf + i); | |
| 966 | g_strchomp(u_comment); | |
| 967 | ||
| 968 | channel = find_channel_by_name(gc, u_channel); | |
| 969 | ||
| 970 | if (!channel) { | |
| 971 | return; | |
| 972 | } | |
| 973 | ||
| 974 | ||
| 975 | id = find_id_by_name(gc, u_channel); | |
| 976 | ||
| 977 | ||
| 978 | if (g_strcasecmp(u_nick, gc->username) == 0) { | |
| 979 | ||
| 980 | /* It looks like you've been naughty! */ | |
| 981 | ||
| 982 | serv_got_chat_left(gc, channel->id); | |
| 983 | ||
| 984 | idata->channels = g_list_remove(idata->channels, channel); | |
| 985 | } else { | |
| 986 | struct conversation *convo = NULL; | |
| 987 | ||
| 988 | /* Find their conversation window */ | |
| 989 | convo = find_conversation_by_id(gc, channel->id); | |
| 990 | ||
| 991 | if (!convo) { | |
| 992 | /* Some how the window doesn't exist. | |
| 993 | * Let's get out of here */ | |
| 994 | return; | |
| 995 | } | |
| 996 | ||
| 997 | /* And remove their name */ | |
| 998 | /* If the person is an op or voice, this won't work. | |
| 999 | * so we'll just do a nice hack and remove nick and | |
| 1000 | * @nick and +nick. Truly wasteful. | |
| 1001 | */ | |
| 1002 | ||
| 1003 | temp = (gchar *) g_malloc(strlen(u_who) + 3); | |
| 1004 | g_snprintf(temp, strlen(u_who) + 2, "@%s", u_who); | |
| 1005 | remove_chat_buddy(convo, temp); | |
| 1006 | g_free(temp); | |
| 1007 | temp = (gchar *) g_malloc(strlen(u_who) + 3); | |
| 1008 | g_snprintf(temp, strlen(u_who) + 2, "+%s", u_who); | |
| 1009 | remove_chat_buddy(convo, temp); | |
| 1010 | remove_chat_buddy(convo, u_who); | |
| 1011 | ||
| 1012 | g_free(temp); | |
| 1013 | ||
| 1014 | } | |
| 1015 | ||
| 1016 | /* Go Home! */ | |
| 1017 | return; | |
| 1018 | } | |
| 1019 | ||
| 1020 | if ((strstr(buf, " TOPIC ")) && (buf[0] == ':') && (!strstr(buf, " NOTICE "))) { | |
| 1021 | ||
| 1022 | gchar u_channel[128]; | |
| 1023 | gchar u_nick[128]; | |
| 1024 | gchar u_topic[128]; | |
| 1025 | int j; | |
| 1026 | struct conversation *chatroom = NULL; | |
| 1027 | ||
| 1028 | for (j = 0, i = 1; buf[i] != '!'; j++, i++) { | |
| 1029 | u_nick[j] = buf[i]; | |
| 1030 | } | |
| 1031 | u_nick[j] = 0; | |
| 1032 | i++; | |
| 1033 | ||
| 1034 | for (j = 0; buf[i] != '#'; j++, i++) { | |
| 1035 | } | |
| 1036 | i++; | |
| 1037 | ||
| 1038 | for (j = 0; buf[i] != ' '; j++, i++) { | |
| 1039 | if (buf[i] == '\0') | |
| 1040 | break; | |
| 1041 | ||
| 1042 | u_channel[j] = buf[i]; | |
| 1043 | } | |
| 1044 | ||
| 1045 | for (j = 0; buf[i] != ':'; j++, i++) { | |
| 1046 | } | |
| 1047 | i++; | |
| 1048 | ||
| 1049 | strcpy(u_topic, buf + i); | |
| 1050 | g_strchomp(u_topic); | |
| 1051 | ||
| 1052 | chatroom = find_chat(gc, u_channel); | |
| 1053 | ||
| 1054 | if (!chatroom) | |
| 1055 | return; | |
| 1056 | ||
| 1057 | chat_set_topic(chatroom, u_nick, u_topic); | |
| 1058 | ||
| 1059 | return; | |
| 1060 | } | |
| 1061 | ||
| 1062 | ||
| 1063 | if ((strstr(buf, " JOIN ")) && (strstr(buf, "!")) && (buf[0] == ':') | |
| 1064 | && (!strstr(buf, " NOTICE "))) { | |
| 1065 | ||
| 1066 | gchar u_channel[128]; | |
| 1067 | gchar u_nick[128]; | |
| 1068 | ||
| 1069 | struct irc_channel *channel; | |
| 1070 | int j; | |
| 1071 | ||
| 1072 | for (j = 0, i = 1; buf[i] != '!'; j++, i++) { | |
| 1073 | u_nick[j] = buf[i]; | |
| 1074 | } | |
| 1075 | ||
| 1076 | u_nick[j] = '\0'; | |
| 1077 | i++; | |
| 1078 | ||
| 1079 | for (j = 0; buf[i] != '#'; j++, i++) { | |
| 1080 | } | |
| 1081 | ||
| 1082 | i++; | |
| 1083 | ||
| 1084 | strcpy(u_channel, buf + i); | |
| 1085 | ||
| 1086 | g_strchomp(u_channel); | |
| 1087 | ||
| 1088 | /* Looks like we're going to join the channel for real | |
| 1089 | * now. Let's create a valid channel structure and add | |
| 1090 | * it to our list. Let's make sure that | |
| 1091 | * we are not already in a channel first */ | |
| 1092 | ||
| 1093 | channel = find_channel_by_name(gc, u_channel); | |
| 1094 | ||
| 1095 | if (!channel) { | |
| 1096 | ||
| 1097 | chat_id++; | |
| 1098 | ||
| 1099 | channel = g_new0(struct irc_channel, 1); | |
| 1100 | ||
| 1101 | channel->id = chat_id; | |
| 1102 | channel->name = strdup(u_channel); | |
| 1103 | ||
| 1104 | idata->channels = g_list_append(idata->channels, channel); | |
| 1105 | ||
| 1106 | serv_got_joined_chat(gc, chat_id, u_channel); | |
| 1107 | } else { | |
| 1108 | struct conversation *convo = NULL; | |
| 1109 | ||
| 1110 | /* Someone else joined. Find their conversation | |
| 1111 | * window */ | |
| 1112 | convo = find_conversation_by_id(gc, channel->id); | |
| 1113 | ||
| 1114 | /* And add their name to it */ | |
| 1115 | add_chat_buddy(convo, u_nick); | |
| 1116 | ||
| 1117 | } | |
| 1118 | ||
| 1119 | return; | |
| 1120 | } | |
| 1121 | ||
| 1122 | if ((strstr(buf, " NICK ")) && (strstr(buf, "!")) && (buf[0] == ':') | |
| 1123 | && (!strstr(buf, " NOTICE "))) { | |
| 1124 | ||
| 1125 | gchar old[128]; | |
| 1126 | gchar new[128]; | |
| 1127 | ||
| 1128 | GList *templist; | |
| 1129 | gchar *temp, *temp_new; | |
| 1130 | struct irc_channel *channel; | |
| 1131 | int j; | |
| 1132 | temp = temp_new = NULL; | |
| 1133 | for (j = 0, i = 1; buf[i] != '!'; j++, i++) { | |
| 1134 | old[j] = buf[i]; | |
| 1135 | } | |
| 1136 | ||
| 1137 | old[j] = '\0'; | |
| 1138 | i++; | |
| 1139 | ||
| 1140 | for (j = 0; buf[i] != ':'; j++, i++) { | |
| 1141 | } | |
| 1142 | ||
| 1143 | i++; | |
| 1144 | strcpy(new, buf + i); | |
| 1145 | ||
| 1146 | g_strchomp(new); | |
| 1147 | ||
| 1148 | templist = ((struct irc_data *)gc->proto_data)->channels; | |
| 1149 | ||
| 1150 | while (templist) { | |
| 1151 | struct conversation *convo = NULL; | |
| 1152 | channel = templist->data; | |
| 1153 | ||
| 1154 | convo = find_conversation_by_id(gc, channel->id); | |
| 1155 | ||
| 1156 | /* If the person is an op or voice, this won't work. | |
| 1157 | * so we'll just do a nice hack and rename nick and | |
| 1158 | * @nick and +nick. Truly wasteful. | |
| 1159 | */ | |
| 1160 | ||
| 1161 | temp = (gchar *) g_malloc(strlen(old) + 5); | |
| 1162 | temp_new = (gchar *) g_malloc(strlen(new) + 5); | |
| 1163 | g_snprintf(temp_new, strlen(new) + 2, "@%s", new); | |
| 1164 | g_snprintf(temp, strlen(old) + 2, "@%s", old); | |
| 1165 | rename_chat_buddy(convo, temp, temp_new); | |
| 1166 | g_snprintf(temp, strlen(old) + 2, "+%s", old); | |
| 1167 | g_snprintf(temp_new, strlen(new) + 2, "+%s", new); | |
| 1168 | rename_chat_buddy(convo, temp, temp_new); | |
| 1169 | rename_chat_buddy(convo, old, new); | |
| 1170 | if (temp) | |
| 1171 | g_free(temp); | |
| 1172 | if (temp_new) | |
| 1173 | g_free(temp_new); | |
| 1174 | ||
| 1175 | templist = templist->next; | |
| 1176 | } | |
| 1177 | return; | |
| 1178 | } | |
| 1179 | ||
| 1180 | ||
| 1181 | if ((strstr(buf, "QUIT ")) && (buf[0] == ':') && (strstr(buf, "!")) | |
| 1182 | && (!strstr(buf, " NOTICE "))) { | |
| 1183 | ||
| 1184 | gchar u_nick[128]; | |
| 1185 | gchar *temp; | |
| 1186 | GList *templist; | |
| 1187 | ||
| 1188 | struct irc_channel *channel; | |
| 1189 | int j; | |
| 1190 | ||
| 1191 | ||
| 1192 | temp = NULL; | |
| 1193 | for (j = 0, i = 1; buf[i] != '!'; j++, i++) { | |
| 1194 | u_nick[j] = buf[i]; | |
| 1195 | } | |
| 1196 | ||
| 1197 | u_nick[j] = '\0'; | |
| 1198 | ||
| 1199 | templist = ((struct irc_data *)gc->proto_data)->channels; | |
| 1200 | ||
| 1201 | while (templist) { | |
| 1202 | struct conversation *convo = NULL; | |
| 1203 | channel = templist->data; | |
| 1204 | ||
| 1205 | convo = find_conversation_by_id(gc, channel->id); | |
| 1206 | ||
| 1207 | /* If the person is an op or voice, this won't work. | |
| 1208 | * so we'll just do a nice hack and remove nick and | |
| 1209 | * @nick and +nick. Truly wasteful. | |
| 1210 | */ | |
| 1211 | ||
| 1212 | temp = (gchar *) g_malloc(strlen(u_nick) + 2); | |
| 1213 | g_snprintf(temp, strlen(u_nick) + 2, "@%s", u_nick); | |
| 1214 | remove_chat_buddy(convo, temp); | |
| 1215 | g_free(temp); | |
| 1216 | temp = (gchar *) g_malloc(strlen(u_nick) + 2); | |
| 1217 | g_snprintf(temp, strlen(u_nick) + 2, "+%s", u_nick); | |
| 1218 | remove_chat_buddy(convo, temp); | |
| 1219 | remove_chat_buddy(convo, u_nick); | |
| 1220 | ||
| 1221 | ||
| 1222 | ||
| 1223 | templist = templist->next; | |
| 1224 | } | |
| 1225 | ||
| 1226 | g_free(temp); | |
| 1227 | ||
| 1228 | return; | |
| 1229 | } | |
| 1230 | ||
| 1231 | ||
| 1232 | ||
| 1233 | if ((strstr(buf, " PART ")) && (strstr(buf, "!")) && (buf[0] == ':') | |
| 1234 | && (!strstr(buf, " NOTICE "))) { | |
| 1235 | ||
| 1236 | gchar u_channel[128]; | |
| 1237 | gchar u_nick[128]; | |
| 1238 | gchar *temp; | |
| 1239 | struct irc_channel *channel; | |
| 1240 | int j; | |
| 1241 | temp = NULL; | |
| 1242 | for (j = 0, i = 1; buf[i] != '!'; j++, i++) { | |
| 1243 | u_nick[j] = buf[i]; | |
| 1244 | } | |
| 1245 | u_nick[j] = '\0'; | |
| 1246 | ||
| 1247 | i++; | |
| 1248 | ||
| 1249 | for (j = 0; buf[i] != '#'; j++, i++) { | |
| 1250 | } | |
| 1251 | ||
| 1252 | i++; | |
| 1253 | ||
| 1254 | for (j = 0; buf[i] != ' '; j++, i++) { | |
| 1255 | if (buf[i] == '\0') { | |
| 1256 | break; | |
| 1257 | } | |
| 1258 | u_channel[j] = buf[i]; | |
| 1259 | } | |
| 1260 | u_channel[j] = '\0'; | |
| 1261 | ||
| 1262 | /* Now, lets check to see if it was US that was leaving. | |
| 1263 | * If so, do the correct thing by closing up all of our | |
| 1264 | * old channel stuff. Otherwise, | |
| 1265 | * we should just print that someone left */ | |
| 1266 | ||
| 1267 | channel = find_channel_by_name(gc, u_channel); | |
| 1268 | ||
| 1269 | if (!channel) { | |
| 1270 | return; | |
| 1271 | } | |
| 1272 | ||
| 1273 | if (g_strcasecmp(u_nick, gc->username) == 0) { | |
| 1274 | ||
| 1275 | /* Looks like we're going to leave the channel for | |
| 1276 | * real now. Let's create a valid channel structure | |
| 1277 | * and add it to our list */ | |
| 1278 | ||
| 1279 | serv_got_chat_left(gc, channel->id); | |
| 1280 | ||
| 1281 | idata->channels = g_list_remove(idata->channels, channel); | |
| 1282 | } else { | |
| 1283 | struct conversation *convo = NULL; | |
| 1284 | ||
| 1285 | /* Find their conversation window */ | |
| 1286 | convo = find_conversation_by_id(gc, channel->id); | |
| 1287 | ||
| 1288 | if (!convo) { | |
| 1289 | /* Some how the window doesn't exist. | |
| 1290 | * Let's get out of here */ | |
| 1291 | return; | |
| 1292 | } | |
| 1293 | ||
| 1294 | /* And remove their name */ | |
| 1295 | /* If the person is an op or voice, this won't work. | |
| 1296 | * so we'll just do a nice hack and remove nick and | |
| 1297 | * @nick and +nick. Truly wasteful. | |
| 1298 | */ | |
| 1299 | ||
| 1300 | temp = (gchar *) g_malloc(strlen(u_nick) + 3); | |
| 1301 | g_snprintf(temp, strlen(u_nick) + 2, "@%s", u_nick); | |
| 1302 | remove_chat_buddy(convo, temp); | |
| 1303 | g_free(temp); | |
| 1304 | temp = (gchar *) g_malloc(strlen(u_nick) + 3); | |
| 1305 | g_snprintf(temp, strlen(u_nick) + 2, "+%s", u_nick); | |
| 1306 | remove_chat_buddy(convo, temp); | |
| 1307 | g_free(temp); | |
| 1308 | remove_chat_buddy(convo, u_nick); | |
| 1309 | ||
| 1310 | ||
| 1311 | } | |
| 1312 | ||
| 1313 | /* Go Home! */ | |
| 1314 | return; | |
| 1315 | } | |
| 1316 | ||
| 1317 | if ((strstr(buf, " NOTICE ")) && (buf[0] == ':')) { | |
| 1318 | gchar u_nick[128]; | |
| 1319 | gchar u_host[255]; | |
| 1320 | gchar u_command[32]; | |
| 1321 | gchar u_channel[128]; | |
| 1322 | gchar u_message[IRC_BUF_LEN]; | |
| 1323 | int j; | |
| 1324 | ||
| 1325 | for (j = 0, i = 1; buf[i] != '!'; j++, i++) { | |
| 1326 | u_nick[j] = buf[i]; | |
| 1327 | } | |
| 1328 | ||
| 1329 | u_nick[j] = '\0'; | |
| 1330 | i++; | |
| 1331 | ||
| 1332 | for (j = 0; buf[i] != ' '; j++, i++) { | |
| 1333 | u_host[j] = buf[i]; | |
| 1334 | } | |
| 1335 | ||
| 1336 | u_host[j] = '\0'; | |
| 1337 | i++; | |
| 1338 | ||
| 1339 | for (j = 0; buf[i] != ' '; j++, i++) { | |
| 1340 | u_command[j] = buf[i]; | |
| 1341 | } | |
| 1342 | ||
| 1343 | u_command[j] = '\0'; | |
| 1344 | i++; | |
| 1345 | ||
| 1346 | for (j = 0; buf[i] != ':'; j++, i++) { | |
| 1347 | u_channel[j] = buf[i]; | |
| 1348 | } | |
| 1349 | ||
| 1350 | u_channel[j - 1] = '\0'; | |
| 1351 | i++; | |
| 1352 | ||
| 1353 | ||
| 1354 | /* Now that everything is parsed, the rest of this baby must be our message */ | |
| 1355 | strncpy(u_message, buf + i, IRC_BUF_LEN); | |
| 1356 | ||
| 1357 | /* Now, lets check the message to see if there's anything special in it */ | |
| 1358 | if (u_message[0] == '\001') { | |
| 1359 | if ((g_strncasecmp(u_message, "\001PING ", 6) == 0) && (strlen(u_message) > 6)) { | |
| 1360 | /* Someone's triyng to ping us. Let's respond */ | |
| 1361 | gchar u_arg[24]; | |
| 1362 | gchar u_buf[200]; | |
| 1363 | unsigned long tend = time((time_t *) NULL); | |
| 1364 | unsigned long tstart; | |
| 1365 | ||
| 1366 | printf("LA: %s\n", buf); | |
| 1367 | ||
| 1368 | strcpy(u_arg, u_message + 6); | |
| 1369 | u_arg[strlen(u_arg) - 1] = '\0'; | |
| 1370 | ||
| 1371 | tstart = atol(u_arg); | |
| 1372 | ||
| 1373 | g_snprintf(u_buf, sizeof(u_buf), "Ping Reply From %s: [%ld seconds]", | |
| 1374 | u_nick, tend - tstart); | |
| 1375 | ||
| 1376 | do_error_dialog(u_buf, "Gaim IRC - Ping Reply"); | |
| 1377 | ||
| 1378 | return; | |
| 1379 | } | |
| 1380 | } | |
| 1381 | ||
| 1382 | } | |
| 1383 | ||
| 1384 | ||
| 1385 | if ((strstr(buf, " PRIVMSG ")) && (buf[0] == ':')) { | |
| 1386 | gchar u_nick[128]; | |
| 1387 | gchar u_host[255]; | |
| 1388 | gchar u_command[32]; | |
| 1389 | gchar u_channel[128]; | |
| 1390 | gchar u_message[IRC_BUF_LEN]; | |
| 1391 | gboolean is_closing; | |
| 1392 | ||
| 1393 | int j; | |
| 1394 | ||
| 1395 | ||
| 1396 | for (j = 0, i = 1; buf[i] != '!'; j++, i++) { | |
| 1397 | u_nick[j] = buf[i]; | |
| 1398 | } | |
| 1399 | ||
| 1400 | u_nick[j] = '\0'; | |
| 1401 | i++; | |
| 1402 | ||
| 1403 | for (j = 0; buf[i] != ' '; j++, i++) { | |
| 1404 | u_host[j] = buf[i]; | |
| 1405 | } | |
| 1406 | ||
| 1407 | u_host[j] = '\0'; | |
| 1408 | i++; | |
| 1409 | ||
| 1410 | for (j = 0; buf[i] != ' '; j++, i++) { | |
| 1411 | u_command[j] = buf[i]; | |
| 1412 | } | |
| 1413 | ||
| 1414 | u_command[j] = '\0'; | |
| 1415 | i++; | |
| 1416 | ||
| 1417 | for (j = 0; buf[i] != ':'; j++, i++) { | |
| 1418 | u_channel[j] = buf[i]; | |
| 1419 | } | |
| 1420 | ||
| 1421 | u_channel[j - 1] = '\0'; | |
| 1422 | i++; | |
| 1423 | ||
| 1424 | ||
| 1425 | /* Now that everything is parsed, the rest of this baby must be our message */ | |
| 1426 | strncpy(u_message, buf + i, IRC_BUF_LEN); | |
| 1427 | ||
| 1428 | /* Now, lets check the message to see if there's anything special in it */ | |
| 1429 | if (u_message[0] == '\001') { | |
| 1430 | if (g_strncasecmp(u_message, "\001VERSION", 8) == 0) { | |
| 1431 | /* Looks like we have a version request. Let | |
| 1432 | * us handle it thusly */ | |
| 1433 | ||
| 1434 | g_snprintf(buf, IRC_BUF_LEN, | |
| 1435 | "NOTICE %s :%cVERSION GAIM %s:The Pimpin Penguin AIM Clone:%s%c\n", | |
| 1436 | u_nick, '\001', VERSION, WEBSITE, '\001'); | |
| 1437 | ||
| 1438 | write(idata->fd, buf, strlen(buf)); | |
| 1439 | ||
| 1440 | /* And get the heck out of dodge */ | |
| 1441 | return; | |
| 1442 | } | |
| 1443 | ||
| 1444 | if ((g_strncasecmp(u_message, "\001PING ", 6) == 0) && (strlen(u_message) > 6)) { | |
| 1445 | /* Someone's triyng to ping us. Let's respond */ | |
| 1446 | gchar u_arg[24]; | |
| 1447 | ||
| 1448 | strcpy(u_arg, u_message + 6); | |
| 1449 | u_arg[strlen(u_arg) - 1] = '\0'; | |
| 1450 | ||
| 1451 | g_snprintf(buf, IRC_BUF_LEN, "NOTICE %s :%cPING %s%c\n", u_nick, '\001', | |
| 1452 | u_arg, '\001'); | |
| 1453 | ||
| 1454 | write(idata->fd, buf, strlen(buf)); | |
| 1455 | ||
| 1456 | /* And get the heck out of dodge */ | |
| 1457 | return; | |
| 1458 | } | |
| 1459 | ||
| 1460 | if (g_strncasecmp(u_message, "\001ACTION ", 8) == 0) { | |
| 1461 | /* Looks like we have an action. Let's parse it a little */ | |
| 1462 | strcpy(buf, u_message); | |
| 1463 | ||
| 1464 | strcpy(u_message, "/me "); | |
| 1465 | for (j = 4, i = 8; buf[i] != '\001'; i++, j++) { | |
| 1466 | u_message[j] = buf[i]; | |
| 1467 | } | |
| 1468 | u_message[j] = '\0'; | |
| 1469 | } | |
| 1470 | } | |
| 1471 | ||
| 1472 | ||
| 1473 | /* OK, It is a chat or IM message. Here, let's translate the IRC formatting into | |
|
2171
e2fc8477e7ad
[gaim-migrate @ 2181]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2170
diff
changeset
|
1474 | * good ol' fashioned imhtml style hypertext markup. */ |
| 2086 | 1475 | |
| 1476 | ||
| 1477 | is_closing = FALSE; | |
| 1478 | ||
| 1479 | while (strchr(u_message, '\002')) { /* \002 = ^B */ | |
| 1480 | gchar *current; | |
| 1481 | gchar *temp, *free_here; | |
| 1482 | ||
| 1483 | ||
| 1484 | temp = g_strdup(strchr(u_message, '\002')); | |
| 1485 | free_here = temp; | |
| 1486 | temp++; | |
| 1487 | ||
| 1488 | current = strchr(u_message, '\002'); | |
| 1489 | *current = '<'; | |
| 1490 | current++; | |
| 1491 | if (is_closing) { | |
| 1492 | *current = '/'; | |
| 1493 | current++; | |
| 1494 | } | |
| 1495 | *current = 'b'; | |
| 1496 | current++; | |
| 1497 | *current = '>'; | |
| 1498 | current++; | |
| 1499 | ||
| 1500 | ||
| 1501 | while (*temp != '\0') { | |
| 1502 | *current = *temp; | |
| 1503 | current++; | |
| 1504 | temp++; | |
| 1505 | } | |
| 1506 | *current = '\0'; | |
| 1507 | g_free(free_here); | |
| 1508 | ||
| 1509 | is_closing = !is_closing; | |
| 1510 | } | |
| 1511 | ||
| 1512 | is_closing = FALSE; | |
| 1513 | while (strchr(u_message, '\037')) { /* \037 = ^_ */ | |
| 1514 | gchar *current; | |
| 1515 | gchar *temp, *free_here; | |
| 1516 | ||
| 1517 | ||
| 1518 | temp = g_strdup(strchr(u_message, '\037')); | |
| 1519 | free_here = temp; | |
| 1520 | temp++; | |
| 1521 | ||
| 1522 | current = strchr(u_message, '\037'); | |
| 1523 | *current = '<'; | |
| 1524 | current++; | |
| 1525 | if (is_closing) { | |
| 1526 | *current = '/'; | |
| 1527 | current++; | |
| 1528 | } | |
| 1529 | *current = 'u'; | |
| 1530 | current++; | |
| 1531 | *current = '>'; | |
| 1532 | current++; | |
| 1533 | ||
| 1534 | ||
| 1535 | while (*temp != '\0') { | |
| 1536 | *current = *temp; | |
| 1537 | current++; | |
| 1538 | temp++; | |
| 1539 | } | |
| 1540 | *current = '\0'; | |
| 1541 | g_free(free_here); | |
| 1542 | is_closing = !is_closing; | |
| 1543 | ||
| 1544 | } | |
| 1545 | ||
| 1546 | while (strchr(u_message, '\003')) { /* \003 = ^C */ | |
| 1547 | ||
| 1548 | /* This is color formatting. IRC uses its own weird little system | |
| 1549 | * that we must translate to HTML. */ | |
| 1550 | ||
| 1551 | ||
| 1552 | /* The format is something like this: | |
| 1553 | * ^C5 or ^C5,3 | |
| 1554 | * The number before the comma is the foreground color, after is the | |
| 1555 | * background color. Either number can be 1 or two digits. | |
| 1556 | */ | |
| 1557 | ||
| 1558 | gchar *current; | |
| 1559 | gchar *temp, *free_here; | |
| 1560 | gchar *font_tag, *body_tag; | |
| 1561 | int fg_color, bg_color; | |
| 1562 | ||
| 1563 | temp = g_strdup(strchr(u_message, '\003')); | |
| 1564 | free_here = temp; | |
| 1565 | temp++; | |
| 1566 | ||
| 1567 | fg_color = bg_color = -1; | |
| 1568 | body_tag = font_tag = ""; | |
| 1569 | ||
| 1570 | /* Parsing the color information: */ | |
| 1571 | do { | |
| 1572 | if (!isdigit(*temp)) | |
| 1573 | break; /* This translates to </font> */ | |
| 1574 | fg_color = (int)(*temp - 48); | |
| 1575 | temp++; | |
| 1576 | if (isdigit(*temp)) { | |
| 1577 | fg_color = (fg_color * 10) + (int)(*temp - 48); | |
| 1578 | temp++; | |
| 1579 | } | |
| 1580 | if (*temp != ',') | |
| 1581 | break; | |
| 1582 | temp++; | |
| 1583 | if (!isdigit(*temp)) | |
| 1584 | break; /* This translates to </font> */ | |
| 1585 | bg_color = (int)(*temp - 48); | |
| 1586 | temp++; | |
| 1587 | if (isdigit(*temp)) { | |
| 1588 | bg_color = (bg_color * 10) + (int)(*temp - 48); | |
| 1589 | temp++; | |
| 1590 | } | |
| 1591 | } while (FALSE); | |
| 1592 | ||
| 1593 | if (fg_color > 15) | |
| 1594 | fg_color = fg_color % 16; | |
| 1595 | if (bg_color > 15) | |
| 1596 | bg_color = bg_color % 16; | |
| 1597 | ||
| 1598 | switch (fg_color) { | |
| 1599 | case -1: | |
| 1600 | font_tag = "</font></body>"; | |
| 1601 | break; | |
| 1602 | case 0: /* WHITE */ | |
| 1603 | font_tag = "<font color=\"#ffffff\">"; | |
| 1604 | /* If no background color is specified, we're going to make it black anyway. | |
| 1605 | * That's probably what the sender anticipated the background color to be. | |
| 1606 | * White on white would be illegible. | |
| 1607 | */ | |
| 1608 | if (bg_color == -1) { | |
| 1609 | body_tag = "<body bgcolor=\"#000000\">"; | |
| 1610 | } | |
| 1611 | break; | |
| 1612 | case 1: /* BLACK */ | |
| 1613 | font_tag = "<font color=\"#000000\">"; | |
| 1614 | break; | |
| 1615 | case 2: /* NAVY BLUE */ | |
| 1616 | font_tag = "<font color=\"#000066\">"; | |
| 1617 | break; | |
| 1618 | case 3: /* GREEN */ | |
| 1619 | font_tag = "<font color=\"#006600\">"; | |
| 1620 | break; | |
| 1621 | case 4: /* RED */ | |
| 1622 | font_tag = "<font color=\"#ff0000\">"; | |
| 1623 | break; | |
| 1624 | case 5: /* MAROON */ | |
| 1625 | font_tag = "<font color=\"#660000\">"; | |
| 1626 | break; | |
| 1627 | case 6: /* PURPLE */ | |
| 1628 | font_tag = "<font color=\"#660066\">"; | |
| 1629 | break; | |
| 1630 | case 7: /* DISGUSTING PUKE COLOR */ | |
| 1631 | font_tag = "<font color=\"#666600\">"; | |
| 1632 | break; | |
| 1633 | case 8: /* YELLOW */ | |
| 1634 | font_tag = "<font color=\"#cccc00\">"; | |
| 1635 | break; | |
| 1636 | case 9: /* LIGHT GREEN */ | |
| 1637 | font_tag = "<font color=\"#33cc33\">"; | |
| 1638 | break; | |
| 1639 | case 10: /* TEAL */ | |
| 1640 | font_tag = "<font color=\"#00acac\">"; | |
| 1641 | break; | |
| 1642 | case 11: /* CYAN */ | |
| 1643 | font_tag = "<font color=\"#00ccac\">"; | |
| 1644 | break; | |
| 1645 | case 12: /* BLUE */ | |
| 1646 | font_tag = "<font color=\"#0000ff\">"; | |
| 1647 | break; | |
| 1648 | case 13: /* PINK */ | |
| 1649 | font_tag = "<font color=\"#cc00cc\">"; | |
| 1650 | break; | |
| 1651 | case 14: /* GREY */ | |
| 1652 | font_tag = "<font color=\"#666666\">"; | |
| 1653 | break; | |
| 1654 | case 15: /* SILVER */ | |
| 1655 | font_tag = "<font color=\"#00ccac\">"; | |
| 1656 | break; | |
| 1657 | } | |
| 1658 | ||
| 1659 | switch (bg_color) { | |
| 1660 | case 0: /* WHITE */ | |
| 1661 | body_tag = "<body bgcolor=\"#ffffff\">"; | |
| 1662 | break; | |
| 1663 | case 1: /* BLACK */ | |
| 1664 | body_tag = "<body bgcolor=\"#000000\">"; | |
| 1665 | break; | |
| 1666 | case 2: /* NAVY BLUE */ | |
| 1667 | body_tag = "<body bgcolor=\"#000066\">"; | |
| 1668 | break; | |
| 1669 | case 3: /* GREEN */ | |
| 1670 | body_tag = "<body bgcolor=\"#006600\">"; | |
| 1671 | break; | |
| 1672 | case 4: /* RED */ | |
| 1673 | body_tag = "<body bgcolor=\"#ff0000\">"; | |
| 1674 | break; | |
| 1675 | case 5: /* MAROON */ | |
| 1676 | body_tag = "<body bgcolor=\"#660000\">"; | |
| 1677 | break; | |
| 1678 | case 6: /* PURPLE */ | |
| 1679 | body_tag = "<body bgcolor=\"#660066\">"; | |
| 1680 | break; | |
| 1681 | case 7: /* DISGUSTING PUKE COLOR */ | |
| 1682 | body_tag = "<body bgcolor=\"#666600\">"; | |
| 1683 | break; | |
| 1684 | case 8: /* YELLOW */ | |
| 1685 | body_tag = "<body bgcolor=\"#cccc00\">"; | |
| 1686 | break; | |
| 1687 | case 9: /* LIGHT GREEN */ | |
| 1688 | body_tag = "<body bgcolor=\"#33cc33\">"; | |
| 1689 | break; | |
| 1690 | case 10: /* TEAL */ | |
| 1691 | body_tag = "<body bgcolor=\"#00acac\">"; | |
| 1692 | break; | |
| 1693 | case 11: /* CYAN */ | |
| 1694 | body_tag = "<body bgcolor=\"#00ccac\">"; | |
| 1695 | break; | |
| 1696 | case 12: /* BLUE */ | |
| 1697 | body_tag = "<body bgcolor=\"#0000ff\">"; | |
| 1698 | break; | |
| 1699 | case 13: /* PINK */ | |
| 1700 | body_tag = "<body bgcolor=\"#cc00cc\">"; | |
| 1701 | break; | |
| 1702 | case 14: /* GREY */ | |
| 1703 | body_tag = "<body bgcolor=\"#666666\">"; | |
| 1704 | break; | |
| 1705 | case 15: /* SILVER */ | |
| 1706 | body_tag = "<body bgcolor=\"#00ccac\">"; | |
| 1707 | break; | |
| 1708 | } | |
| 1709 | ||
| 1710 | current = strchr(u_message, '\003'); | |
| 1711 | ||
| 1712 | while (*body_tag != '\0') { | |
| 1713 | *current = *body_tag; | |
| 1714 | current++; | |
| 1715 | body_tag++; | |
| 1716 | } | |
| 1717 | ||
| 1718 | while (*font_tag != '\0') { | |
| 1719 | *current = *font_tag; | |
| 1720 | current++; | |
| 1721 | font_tag++; | |
| 1722 | } | |
| 1723 | ||
| 1724 | while (*temp != '\0') { | |
| 1725 | *current = *temp; | |
| 1726 | current++; | |
| 1727 | temp++; | |
| 1728 | } | |
| 1729 | *current = '\0'; | |
| 1730 | g_free(free_here); | |
| 1731 | is_closing = !is_closing; | |
| 1732 | ||
| 1733 | } | |
| 1734 | ||
| 1735 | while (strchr(u_message, '\017')) { /* \017 = ^O */ | |
| 1736 | gchar *current; | |
| 1737 | gchar *temp, *free_here; | |
| 1738 | ||
| 1739 | ||
| 1740 | temp = g_strdup(strchr(u_message, '\017')); | |
| 1741 | free_here = temp; | |
| 1742 | temp++; | |
| 1743 | ||
| 1744 | current = strchr(u_message, '\017'); | |
| 1745 | *current = '<'; | |
| 1746 | current++; | |
| 1747 | *current = '/'; | |
| 1748 | current++; | |
| 1749 | *current = 'b'; | |
| 1750 | current++; | |
| 1751 | *current = '>'; | |
| 1752 | current++; | |
| 1753 | *current = '<'; | |
| 1754 | current++; | |
| 1755 | *current = '/'; | |
| 1756 | current++; | |
| 1757 | *current = 'u'; | |
| 1758 | current++; | |
| 1759 | *current = '>'; | |
| 1760 | current++; | |
| 1761 | ||
| 1762 | while (*temp != '\0') { | |
| 1763 | *current = *temp; | |
| 1764 | current++; | |
| 1765 | temp++; | |
| 1766 | } | |
| 1767 | *current = '\0'; | |
| 1768 | g_free(free_here); | |
| 1769 | } | |
| 1770 | ||
| 1771 | /* Let's check to see if we have a channel on our hands */ | |
| 1772 | if (u_channel[0] == '#') { | |
| 1773 | /* Yup. We have a channel */ | |
| 1774 | int id; | |
| 1775 | ||
| 1776 | id = find_id_by_name(gc, u_channel); | |
| 1777 | if (id != -1) { | |
| 1778 | serv_got_chat_in(gc, id, u_nick, 0, u_message, time((time_t) NULL)); | |
| 1779 | ||
| 1780 | } | |
| 1781 | ||
| 1782 | } else { | |
| 1783 | /* Nope. Let's treat it as a private message */ | |
| 1784 | ||
| 1785 | gchar *temp; | |
| 1786 | temp = NULL; | |
| 1787 | ||
| 1788 | temp = (gchar *) g_malloc(strlen(u_nick) + 5); | |
| 1789 | g_snprintf(temp, strlen(u_nick) + 2, "@%s", u_nick); | |
| 1790 | ||
| 1791 | ||
| 1792 | /* If I get a message from SeanEgn, and I already have a window | |
| 1793 | * open for him as @SeanEgn or +SeanEgn, this will keep it in the | |
| 1794 | * same window. Unfortunately, if SeanEgn loses his op status | |
| 1795 | * (a sad thing indeed), the messages will still appear to come from | |
| 1796 | * @SeanEgn, until that convo is closed. | |
| 1797 | */ | |
| 1798 | ||
| 1799 | if (find_conversation(temp)) { | |
| 1800 | serv_got_im(gc, temp, u_message, 0, time((time_t) NULL)); | |
| 1801 | g_free(temp); | |
| 1802 | return; | |
| 1803 | } else { | |
| 1804 | g_snprintf(temp, strlen(u_nick) + 2, "+%s", u_nick); | |
| 1805 | if (find_conversation(temp)) { | |
| 1806 | serv_got_im(gc, temp, u_message, 0, time((time_t) NULL)); | |
| 1807 | g_free(temp); | |
| 1808 | return; | |
| 1809 | } else { | |
| 1810 | g_free(temp); | |
| 1811 | serv_got_im(gc, u_nick, u_message, 0, time((time_t) NULL)); | |
| 1812 | return; | |
| 1813 | } | |
| 1814 | } | |
| 1815 | } | |
| 1816 | ||
| 1817 | return; | |
| 1818 | } | |
| 1819 | ||
| 1820 | /* Let's parse PING requests so that we wont get booted for inactivity */ | |
| 1821 | ||
| 1822 | if (strncmp(buf, "PING :", 6) == 0) { | |
| 1823 | buf2 = g_strsplit(buf, ":", 1); | |
| 1824 | ||
| 1825 | /* Let's build a new response */ | |
| 1826 | g_snprintf(buf, IRC_BUF_LEN, "PONG :%s\n", buf2[1]); | |
| 1827 | write(idata->fd, buf, strlen(buf)); | |
| 1828 | ||
| 1829 | /* And clean up after ourselves */ | |
| 1830 | g_strfreev(buf2); | |
| 1831 | ||
| 1832 | return; | |
| 1833 | } | |
| 1834 | ||
| 1835 | } | |
| 1836 | ||
| 1837 | static void irc_close(struct gaim_connection *gc) | |
| 1838 | { | |
| 1839 | struct irc_data *idata = (struct irc_data *)gc->proto_data; | |
| 1840 | GList *chats = idata->channels; | |
| 1841 | struct irc_channel *cc; | |
| 1842 | ||
| 1843 | gchar *buf = (gchar *) g_malloc(IRC_BUF_LEN); | |
| 1844 | ||
| 1845 | g_snprintf(buf, IRC_BUF_LEN, "QUIT :Download GAIM [%s]\n", WEBSITE); | |
| 1846 | write(idata->fd, buf, strlen(buf)); | |
| 1847 | ||
| 1848 | g_free(buf); | |
| 1849 | ||
| 1850 | if (idata->timer) | |
|
2131
ef072ae1b2b8
[gaim-migrate @ 2141]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2123
diff
changeset
|
1851 | g_source_remove(idata->timer); |
| 2086 | 1852 | |
| 1853 | while (chats) { | |
| 1854 | cc = (struct irc_channel *)chats->data; | |
| 1855 | g_free(cc->name); | |
| 1856 | chats = g_list_remove(chats, cc); | |
| 1857 | g_free(cc); | |
| 1858 | } | |
| 1859 | ||
| 1860 | if (gc->inpa) | |
|
2090
bab8b7e309db
[gaim-migrate @ 2100]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2086
diff
changeset
|
1861 | gaim_input_remove(gc->inpa); |
| 2086 | 1862 | |
| 1863 | if (idata->inpa) | |
|
2090
bab8b7e309db
[gaim-migrate @ 2100]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2086
diff
changeset
|
1864 | gaim_input_remove(idata->inpa); |
| 2086 | 1865 | |
| 1866 | close(idata->fd); | |
| 1867 | g_free(gc->proto_data); | |
| 1868 | } | |
| 1869 | ||
| 1870 | static void irc_chat_leave(struct gaim_connection *gc, int id) | |
| 1871 | { | |
| 1872 | struct irc_data *idata = (struct irc_data *)gc->proto_data; | |
| 1873 | struct irc_channel *channel; | |
| 1874 | gchar *buf = (gchar *) g_malloc(IRC_BUF_LEN + 1); | |
| 1875 | ||
| 1876 | channel = find_channel_by_id(gc, id); | |
| 1877 | ||
| 1878 | if (!channel) { | |
| 1879 | return; | |
| 1880 | } | |
| 1881 | ||
| 1882 | g_snprintf(buf, IRC_BUF_LEN, "PART #%s\n", channel->name); | |
| 1883 | write(idata->fd, buf, strlen(buf)); | |
| 1884 | ||
| 1885 | g_free(buf); | |
| 1886 | } | |
| 1887 | ||
|
2090
bab8b7e309db
[gaim-migrate @ 2100]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2086
diff
changeset
|
1888 | static void irc_login_callback(gpointer data, gint source, GaimInputCondition condition) |
| 2086 | 1889 | { |
| 1890 | struct gaim_connection *gc = data; | |
| 1891 | struct irc_data *idata; | |
| 1892 | char buf[4096]; | |
| 1893 | ||
| 1894 | if (!g_slist_find(connections, gc)) { | |
| 1895 | close(source); | |
| 1896 | return; | |
| 1897 | } | |
| 1898 | ||
| 1899 | idata = gc->proto_data; | |
| 1900 | ||
| 1901 | if (source == -1) { | |
| 1902 | hide_login_progress(gc, "Write error"); | |
| 1903 | signoff(gc); | |
| 1904 | return; | |
| 1905 | } | |
| 1906 | ||
| 1907 | if (idata->fd != source) | |
| 1908 | idata->fd = source; | |
| 1909 | ||
| 1910 | g_snprintf(buf, 4096, "NICK %s\n USER %s localhost %s :GAIM (%s)\n", | |
| 1911 | gc->username, g_get_user_name(), gc->user->proto_opt[USEROPT_SERV], WEBSITE); | |
| 1912 | ||
| 1913 | if (write(idata->fd, buf, strlen(buf)) < 0) { | |
| 1914 | hide_login_progress(gc, "Write error"); | |
| 1915 | signoff(gc); | |
| 1916 | return; | |
| 1917 | } | |
| 1918 | ||
|
2090
bab8b7e309db
[gaim-migrate @ 2100]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2086
diff
changeset
|
1919 | idata->inpa = gaim_input_add(idata->fd, GAIM_INPUT_READ, irc_callback, gc); |
| 2086 | 1920 | idata->inpa = 0; |
| 1921 | ||
| 1922 | /* Now lets sign ourselves on */ | |
| 1923 | account_online(gc); | |
| 1924 | serv_finish_login(gc); | |
| 1925 | ||
| 1926 | if (bud_list_cache_exists(gc)) | |
| 1927 | do_import(NULL, gc); | |
| 1928 | ||
| 1929 | /* we don't call this now because otherwise some IRC servers might not like us */ | |
|
2131
ef072ae1b2b8
[gaim-migrate @ 2141]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2123
diff
changeset
|
1930 | idata->timer = g_timeout_add(20000, irc_request_buddy_update, gc); |
| 2086 | 1931 | } |
| 1932 | ||
| 1933 | static void irc_login(struct aim_user *user) | |
| 1934 | { | |
| 1935 | char buf[4096]; | |
| 1936 | ||
| 1937 | struct gaim_connection *gc = new_gaim_conn(user); | |
| 1938 | struct irc_data *idata = gc->proto_data = g_new0(struct irc_data, 1); | |
| 1939 | ||
| 1940 | g_snprintf(buf, sizeof(buf), "Signon: %s", gc->username); | |
| 1941 | set_login_progress(gc, 2, buf); | |
| 1942 | ||
| 1943 | idata->fd = proxy_connect(user->proto_opt[USEROPT_SERV], | |
| 1944 | user->proto_opt[USEROPT_PORT][0] ? atoi(user-> | |
| 1945 | proto_opt[USEROPT_PORT]) : | |
| 1946 | 6667, irc_login_callback, gc); | |
| 1947 | if (!user->gc || (idata->fd < 0)) { | |
| 1948 | hide_login_progress(gc, "Unable to create socket"); | |
| 1949 | signoff(gc); | |
| 1950 | return; | |
| 1951 | } | |
| 1952 | } | |
| 1953 | ||
|
2154
7d4835b44b85
[gaim-migrate @ 2164]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2147
diff
changeset
|
1954 | static GList *irc_user_opts() |
| 2086 | 1955 | { |
|
2154
7d4835b44b85
[gaim-migrate @ 2164]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2147
diff
changeset
|
1956 | GList *m = NULL; |
|
7d4835b44b85
[gaim-migrate @ 2164]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2147
diff
changeset
|
1957 | struct proto_user_opt *puo; |
|
7d4835b44b85
[gaim-migrate @ 2164]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2147
diff
changeset
|
1958 | |
|
7d4835b44b85
[gaim-migrate @ 2164]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2147
diff
changeset
|
1959 | puo = g_new0(struct proto_user_opt, 1); |
|
7d4835b44b85
[gaim-migrate @ 2164]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2147
diff
changeset
|
1960 | puo->label = "Server:"; |
|
7d4835b44b85
[gaim-migrate @ 2164]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2147
diff
changeset
|
1961 | puo->def = "irc.mozilla.org"; |
|
7d4835b44b85
[gaim-migrate @ 2164]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2147
diff
changeset
|
1962 | puo->pos = USEROPT_SERV; |
|
7d4835b44b85
[gaim-migrate @ 2164]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2147
diff
changeset
|
1963 | m = g_list_append(m, puo); |
|
7d4835b44b85
[gaim-migrate @ 2164]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2147
diff
changeset
|
1964 | |
|
7d4835b44b85
[gaim-migrate @ 2164]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2147
diff
changeset
|
1965 | puo = g_new0(struct proto_user_opt, 1); |
|
7d4835b44b85
[gaim-migrate @ 2164]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2147
diff
changeset
|
1966 | puo->label = "Port:"; |
|
7d4835b44b85
[gaim-migrate @ 2164]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2147
diff
changeset
|
1967 | puo->def = "6667"; |
|
7d4835b44b85
[gaim-migrate @ 2164]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2147
diff
changeset
|
1968 | puo->pos = USEROPT_PORT; |
|
7d4835b44b85
[gaim-migrate @ 2164]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2147
diff
changeset
|
1969 | m = g_list_append(m, puo); |
|
7d4835b44b85
[gaim-migrate @ 2164]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2147
diff
changeset
|
1970 | |
|
7d4835b44b85
[gaim-migrate @ 2164]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2147
diff
changeset
|
1971 | return m; |
| 2086 | 1972 | } |
| 1973 | ||
| 1974 | static char **irc_list_icon(int uc) | |
| 1975 | { | |
| 1976 | return free_icon_xpm; | |
| 1977 | } | |
| 1978 | ||
| 1979 | /* Send out a ping request to the specified user */ | |
|
2170
5c93594ff522
[gaim-migrate @ 2180]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2167
diff
changeset
|
1980 | static void irc_send_ping(struct gaim_connection *gc, char *who) |
| 2086 | 1981 | { |
| 1982 | struct irc_data *idata = (struct irc_data *)gc->proto_data; | |
| 1983 | char buf[BUF_LEN]; | |
| 1984 | ||
| 1985 | g_snprintf(buf, BUF_LEN, "PRIVMSG %s :%cPING %ld%c\n", who, '\001', time((time_t *) NULL), | |
| 1986 | '\001'); | |
| 1987 | ||
| 1988 | write(idata->fd, buf, strlen(buf)); | |
| 1989 | } | |
| 1990 | ||
| 1991 | /* Do a whois check on someone :-) */ | |
| 1992 | static void irc_get_info(struct gaim_connection *gc, char *who) | |
| 1993 | { | |
| 1994 | struct irc_data *idata = (struct irc_data *)gc->proto_data; | |
| 1995 | char buf[BUF_LEN]; | |
| 1996 | ||
| 1997 | if (((who[0] == '@') || (who[0] == '+')) && (strlen(who) > 1)) | |
| 1998 | g_snprintf(buf, BUF_LEN, "WHOIS %s\n", who + 1); | |
| 1999 | else | |
| 2000 | g_snprintf(buf, BUF_LEN, "WHOIS %s\n", who); | |
| 2001 | write(idata->fd, buf, strlen(buf)); | |
| 2002 | } | |
| 2003 | ||
|
2170
5c93594ff522
[gaim-migrate @ 2180]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2167
diff
changeset
|
2004 | static GList *irc_buddy_menu(struct gaim_connection *gc, char *who) |
| 2086 | 2005 | { |
|
2170
5c93594ff522
[gaim-migrate @ 2180]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2167
diff
changeset
|
2006 | GList *m = NULL; |
|
5c93594ff522
[gaim-migrate @ 2180]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2167
diff
changeset
|
2007 | struct proto_buddy_menu *pbm; |
|
5c93594ff522
[gaim-migrate @ 2180]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2167
diff
changeset
|
2008 | |
|
5c93594ff522
[gaim-migrate @ 2180]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2167
diff
changeset
|
2009 | pbm = g_new0(struct proto_buddy_menu, 1); |
|
5c93594ff522
[gaim-migrate @ 2180]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2167
diff
changeset
|
2010 | pbm->label = _("Ping"); |
|
5c93594ff522
[gaim-migrate @ 2180]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2167
diff
changeset
|
2011 | pbm->callback = irc_send_ping; |
|
5c93594ff522
[gaim-migrate @ 2180]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2167
diff
changeset
|
2012 | pbm->gc = gc; |
|
5c93594ff522
[gaim-migrate @ 2180]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2167
diff
changeset
|
2013 | m = g_list_append(m, pbm); |
|
5c93594ff522
[gaim-migrate @ 2180]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2167
diff
changeset
|
2014 | |
|
5c93594ff522
[gaim-migrate @ 2180]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2167
diff
changeset
|
2015 | pbm = g_new0(struct proto_buddy_menu, 1); |
|
5c93594ff522
[gaim-migrate @ 2180]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2167
diff
changeset
|
2016 | pbm->label = _("Whois"); |
|
5c93594ff522
[gaim-migrate @ 2180]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2167
diff
changeset
|
2017 | pbm->callback = irc_get_info; |
|
5c93594ff522
[gaim-migrate @ 2180]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2167
diff
changeset
|
2018 | pbm->gc = gc; |
|
5c93594ff522
[gaim-migrate @ 2180]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2167
diff
changeset
|
2019 | m = g_list_append(m, pbm); |
|
5c93594ff522
[gaim-migrate @ 2180]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2167
diff
changeset
|
2020 | |
|
5c93594ff522
[gaim-migrate @ 2180]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2167
diff
changeset
|
2021 | return m; |
| 2086 | 2022 | } |
| 2023 | ||
| 2024 | ||
| 2025 | static void irc_set_away(struct gaim_connection *gc, char *state, char *msg) | |
| 2026 | { | |
| 2027 | struct irc_data *idata = (struct irc_data *)gc->proto_data; | |
| 2028 | char buf[BUF_LEN]; | |
| 2029 | ||
| 2030 | if (msg) | |
| 2031 | g_snprintf(buf, BUF_LEN, "AWAY :%s\n", msg); | |
| 2032 | else | |
| 2033 | g_snprintf(buf, BUF_LEN, "AWAY\n"); | |
| 2034 | ||
| 2035 | write(idata->fd, buf, strlen(buf)); | |
| 2036 | } | |
| 2037 | ||
| 2038 | static void irc_fake_buddy(struct gaim_connection *gc, char *who) | |
| 2039 | { | |
| 2040 | /* Heh, there is no buddy list. We fake it. | |
| 2041 | * I just need this here so the add and remove buttons will | |
| 2042 | * show up */ | |
| 2043 | } | |
| 2044 | ||
| 2045 | static void irc_chat_set_topic(struct gaim_connection *gc, int id, char *topic) | |
| 2046 | { | |
| 2047 | struct irc_channel *ic = NULL; | |
| 2048 | struct irc_data *idata = (struct irc_data *)gc->proto_data; | |
| 2049 | char buf[BUF_LEN]; | |
| 2050 | ||
| 2051 | ic = find_channel_by_id(gc, id); | |
| 2052 | ||
| 2053 | /* If we ain't in no channel, foo, gets outta da kitchen beeyotch */ | |
| 2054 | if (!ic) | |
| 2055 | return; | |
| 2056 | ||
| 2057 | /* Prepare our command */ | |
| 2058 | g_snprintf(buf, BUF_LEN, "TOPIC #%s :%s\n", ic->name, topic); | |
| 2059 | ||
| 2060 | /* And send it */ | |
| 2061 | write(idata->fd, buf, strlen(buf)); | |
| 2062 | } | |
| 2063 | ||
| 2064 | static struct prpl *my_protocol = NULL; | |
| 2065 | ||
| 2066 | void irc_init(struct prpl *ret) | |
| 2067 | { | |
| 2068 | ret->protocol = PROTO_IRC; | |
|
2100
58ebaa769cb2
[gaim-migrate @ 2110]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2090
diff
changeset
|
2069 | ret->options = OPT_PROTO_CHAT_TOPIC | OPT_PROTO_NO_PASSWORD; |
| 2086 | 2070 | ret->name = irc_name; |
| 2071 | ret->list_icon = irc_list_icon; | |
| 2072 | ret->buddy_menu = irc_buddy_menu; | |
| 2073 | ret->user_opts = irc_user_opts; | |
| 2074 | ret->login = irc_login; | |
| 2075 | ret->close = irc_close; | |
| 2076 | ret->send_im = irc_send_im; | |
| 2077 | ret->join_chat = irc_join_chat; | |
| 2078 | ret->chat_leave = irc_chat_leave; | |
| 2079 | ret->chat_send = irc_chat_send; | |
| 2080 | ret->get_info = irc_get_info; | |
| 2081 | ret->set_away = irc_set_away; | |
| 2082 | ret->add_buddy = irc_fake_buddy; | |
| 2083 | ret->remove_buddy = irc_fake_buddy; | |
| 2084 | ret->chat_set_topic = irc_chat_set_topic; | |
| 2085 | my_protocol = ret; | |
| 2086 | } | |
| 2087 | ||
| 2088 | #ifndef STATIC | |
| 2089 | ||
| 2090 | char *gaim_plugin_init(GModule *handle) | |
| 2091 | { | |
| 2092 | load_protocol(irc_init, sizeof(struct prpl)); | |
| 2093 | return NULL; | |
| 2094 | } | |
| 2095 | ||
| 2096 | void gaim_plugin_remove() | |
| 2097 | { | |
| 2098 | struct prpl *p = find_prpl(PROTO_IRC); | |
| 2099 | if (p == my_protocol) | |
| 2100 | unload_protocol(p); | |
| 2101 | } | |
| 2102 | ||
| 2103 | char *name() | |
| 2104 | { | |
| 2105 | return "IRC"; | |
| 2106 | } | |
| 2107 | ||
| 2108 | char *description() | |
| 2109 | { | |
|
2162
2a9f076b0af9
[gaim-migrate @ 2172]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2154
diff
changeset
|
2110 | return PRPL_DESC("IRC"); |
| 2086 | 2111 | } |
| 2112 | ||
| 2113 | #endif |