comparison plugins/irc.c @ 1848:e246a4bd1141

[gaim-migrate @ 1858] More bug fixen. IRC colorus work properly too. committer: Tailor Script <tailor@pidgin.im>
author Rob Flynn <gaim@robflynn.com>
date Tue, 15 May 2001 00:43:51 +0000
parents 029cc08d9c54
children 5cb89cf24f45
comparison
equal deleted inserted replaced
1847:029cc08d9c54 1848:e246a4bd1141
852 struct conversation *convo = NULL; 852 struct conversation *convo = NULL;
853 convo = find_conversation_by_id(gc, channel->id); 853 convo = find_conversation_by_id(gc, channel->id);
854 854
855 855
856 856
857 temp = (gchar *)g_malloc(strlen(people[j]) + 1); 857 temp = (gchar *)g_malloc(strlen(people[j]) + 3);
858 temp_new = (gchar *)g_malloc(strlen(people[j]) + 1); 858 temp_new = (gchar *)g_malloc(strlen(people[j]) + 3);
859 g_snprintf(temp, strlen(people[j]) + 2, "@%s", people[j]); 859 g_snprintf(temp, strlen(people[j]) + 2, "@%s", people[j]);
860 860
861 if (u_mode[1] == 'v' && u_mode[0] == '+') { 861 if (u_mode[1] == 'v' && u_mode[0] == '+') {
862 g_snprintf(temp_new, strlen(people[j]) + 2, "+%s", people[j]); 862 g_snprintf(temp_new, strlen(people[j]) + 2, "+%s", people[j]);
863 } 863 }
968 /* If the person is an op or voice, this won't work. 968 /* If the person is an op or voice, this won't work.
969 * so we'll just do a nice hack and remove nick and 969 * so we'll just do a nice hack and remove nick and
970 * @nick and +nick. Truly wasteful. 970 * @nick and +nick. Truly wasteful.
971 */ 971 */
972 972
973 temp = (gchar *) g_malloc(strlen(u_who) + 1); 973 temp = (gchar *) g_malloc(strlen(u_who) + 3);
974 g_snprintf(temp, strlen(u_who) + 2, "@%s", u_who); 974 g_snprintf(temp, strlen(u_who) + 2, "@%s", u_who);
975 remove_chat_buddy(convo, temp); 975 remove_chat_buddy(convo, temp);
976 g_free(temp);
977 temp = (gchar *) g_malloc(strlen(u_who) + 3);
976 g_snprintf(temp, strlen(u_who) + 2, "+%s", u_who); 978 g_snprintf(temp, strlen(u_who) + 2, "+%s", u_who);
977 remove_chat_buddy(convo, temp); 979 remove_chat_buddy(convo, temp);
978 remove_chat_buddy(convo, u_who); 980 remove_chat_buddy(convo, u_who);
979 981
980 if (temp) 982 g_free(temp);
981 g_free(temp);
982 983
983 } 984 }
984 985
985 /* Go Home! */ 986 /* Go Home! */
986 return; 987 return;
1134 */ 1135 */
1135 1136
1136 temp = (gchar *) g_malloc(strlen(u_nick) + 2); 1137 temp = (gchar *) g_malloc(strlen(u_nick) + 2);
1137 g_snprintf(temp, strlen(u_nick) + 2, "@%s", u_nick); 1138 g_snprintf(temp, strlen(u_nick) + 2, "@%s", u_nick);
1138 remove_chat_buddy(convo, temp); 1139 remove_chat_buddy(convo, temp);
1140 g_free(temp);
1141 temp = (gchar *) g_malloc(strlen(u_nick) + 2);
1139 g_snprintf(temp, strlen(u_nick) + 2, "+%s", u_nick); 1142 g_snprintf(temp, strlen(u_nick) + 2, "+%s", u_nick);
1140 remove_chat_buddy(convo, temp); 1143 remove_chat_buddy(convo, temp);
1141 remove_chat_buddy(convo, u_nick); 1144 remove_chat_buddy(convo, u_nick);
1142 1145
1143 1146
1144 1147
1145 templist = templist->next; 1148 templist = templist->next;
1146 } 1149 }
1147 1150
1148 if (temp) 1151 g_free(temp);
1149 g_free(temp);
1150 1152
1151 return; 1153 return;
1152 } 1154 }
1153 1155
1154 1156
1191 if (!channel) { 1193 if (!channel) {
1192 return; 1194 return;
1193 } 1195 }
1194 1196
1195 if (g_strcasecmp(u_nick, gc->username) == 0) { 1197 if (g_strcasecmp(u_nick, gc->username) == 0) {
1196 1198
1197 /* Looks like we're going to leave the channel for 1199 /* Looks like we're going to leave the channel for
1198 * real now. Let's create a valid channel structure 1200 * real now. Let's create a valid channel structure
1199 * and add it to our list */ 1201 * and add it to our list */
1200 1202
1201 serv_got_chat_left(gc, channel->id); 1203 serv_got_chat_left(gc, channel->id);
1202 1204
1203 idata->channels = g_list_remove(idata->channels, channel); 1205 idata->channels = g_list_remove(idata->channels, channel);
1204 } else { 1206 }
1205 struct conversation *convo = NULL; 1207 else {
1206 1208 struct conversation *convo = NULL;
1207 /* Find their conversation window */ 1209
1208 convo = find_conversation_by_id(gc, channel->id); 1210 /* Find their conversation window */
1209 1211 convo = find_conversation_by_id(gc, channel->id);
1210 if (!convo) { 1212
1213 if (!convo) {
1211 /* Some how the window doesn't exist. 1214 /* Some how the window doesn't exist.
1212 * Let's get out of here */ 1215 * Let's get out of here */
1213 return; 1216 return;
1214 } 1217 }
1215 1218
1216 /* And remove their name */ 1219 /* And remove their name */
1217 /* If the person is an op or voice, this won't work. 1220 /* If the person is an op or voice, this won't work.
1218 * so we'll just do a nice hack and remove nick and 1221 * so we'll just do a nice hack and remove nick and
1219 * @nick and +nick. Truly wasteful. 1222 * @nick and +nick. Truly wasteful.
1220 */ 1223 */
1221 1224
1222 temp = (gchar *) g_malloc(strlen(u_nick) + 2); 1225 temp = (gchar *) g_malloc(strlen(u_nick) + 3);
1223 g_snprintf(temp, strlen(u_nick) + 2, "@%s", u_nick); 1226 g_snprintf(temp, strlen(u_nick) + 2, "@%s", u_nick);
1224 remove_chat_buddy(convo, temp); 1227 remove_chat_buddy(convo, temp);
1225 g_snprintf(temp, strlen(u_nick) + 2, "+%s", u_nick); 1228 g_free(temp);
1226 remove_chat_buddy(convo, temp); 1229 temp = (gchar *) g_malloc(strlen(u_nick) + 3);
1227 remove_chat_buddy(convo, u_nick); 1230 g_snprintf(temp, strlen(u_nick) + 2, "+%s", u_nick);
1228 1231 remove_chat_buddy(convo, temp);
1229 if (temp) 1232 g_free(temp);
1230 g_free(temp); 1233 remove_chat_buddy(convo, u_nick);
1231 1234
1232 } 1235
1233 1236 }
1237
1234 /* Go Home! */ 1238 /* Go Home! */
1235 return; 1239 return;
1236 } 1240 }
1237 1241
1238 if ((strstr(buf, " NOTICE ")) && (buf[0] == ':')) { 1242 if ((strstr(buf, " NOTICE ")) && (buf[0] == ':')) {
1239 gchar u_nick[128]; 1243 gchar u_nick[128];
1240 gchar u_host[255]; 1244 gchar u_host[255];
1241 gchar u_command[32]; 1245 gchar u_command[32];
1242 gchar u_channel[128]; 1246 gchar u_channel[128];
1306 gchar u_nick[128]; 1310 gchar u_nick[128];
1307 gchar u_host[255]; 1311 gchar u_host[255];
1308 gchar u_command[32]; 1312 gchar u_command[32];
1309 gchar u_channel[128]; 1313 gchar u_channel[128];
1310 gchar u_message[IRC_BUF_LEN]; 1314 gchar u_message[IRC_BUF_LEN];
1315 gboolean is_closing;
1316
1311 int j; 1317 int j;
1312 1318
1313 1319
1314 for (j = 0, i = 1; buf[i] != '!'; j++, i++) { 1320 for (j = 0, i = 1; buf[i] != '!'; j++, i++) {
1315 u_nick[j] = buf[i]; 1321 u_nick[j] = buf[i];
1389 1395
1390 1396
1391 /* OK, It is a chat or IM message. Here, let's translate the IRC formatting into 1397 /* OK, It is a chat or IM message. Here, let's translate the IRC formatting into
1392 * good ol' fashioned gtkimhtml style hypertext markup. */ 1398 * good ol' fashioned gtkimhtml style hypertext markup. */
1393 1399
1400
1401 is_closing = FALSE;
1402
1394 while(strchr(u_message, '\002')) { // \002 = ^B 1403 while(strchr(u_message, '\002')) { // \002 = ^B
1395 gchar *current; 1404 gchar *current;
1396 gchar *temp, *free_here; 1405 gchar *temp, *free_here;
1397 1406
1398 1407
1401 temp++; 1410 temp++;
1402 1411
1403 current = strchr(u_message, '\002'); 1412 current = strchr(u_message, '\002');
1404 *current = '<'; 1413 *current = '<';
1405 current++; 1414 current++;
1415 if (is_closing) {
1416 *current = '/';
1417 current++;
1418 }
1406 *current = 'b'; 1419 *current = 'b';
1407 current++; 1420 current++;
1408 *current = '>'; 1421 *current = '>';
1409 current++; 1422 current++;
1410 1423
1415 temp++; 1428 temp++;
1416 } 1429 }
1417 *current = '\0'; 1430 *current = '\0';
1418 g_free(free_here); 1431 g_free(free_here);
1419 1432
1433 is_closing = !is_closing;
1420 } 1434 }
1421 1435
1436 is_closing = FALSE;
1422 while(strchr(u_message, '\037')) { // \037 = ^_ 1437 while(strchr(u_message, '\037')) { // \037 = ^_
1423 gchar *current; 1438 gchar *current;
1424 gchar *temp, *free_here; 1439 gchar *temp, *free_here;
1425 1440
1426 1441
1429 temp++; 1444 temp++;
1430 1445
1431 current = strchr(u_message, '\037'); 1446 current = strchr(u_message, '\037');
1432 *current = '<'; 1447 *current = '<';
1433 current++; 1448 current++;
1449 if (is_closing) {
1450 *current = '/';
1451 current++;
1452 }
1434 *current = 'u'; 1453 *current = 'u';
1435 current++; 1454 current++;
1436 *current = '>'; 1455 *current = '>';
1437 current++; 1456 current++;
1438 1457
1441 *current = *temp; 1460 *current = *temp;
1442 current++; 1461 current++;
1443 temp++; 1462 temp++;
1444 } 1463 }
1445 *current = '\0'; 1464 *current = '\0';
1446 g_free(free_here); 1465 g_free(free_here);
1466 is_closing = !is_closing;
1467
1468 }
1469
1470 while(strchr(u_message, '\003')) { // \003 = ^C
1471
1472 /* This is color formatting. IRC uses its own weird little system
1473 * that we must translate to HTML. */
1474
1475
1476 /* The format is something like this:
1477 * ^C5 or ^C5,3
1478 * The number before the comma is the foreground color, after is the
1479 * background color. Either number can be 1 or two digits.
1480 */
1481
1482 gchar *current;
1483 gchar *temp, *free_here;
1484 gchar *font_tag, *body_tag;
1485 int fg_color, bg_color;
1486
1487 temp = g_strdup(strchr(u_message, '\003'));
1488 free_here = temp;
1489 temp++;
1490
1491 fg_color = bg_color = -1;
1492 body_tag = font_tag = "";
1493
1494 /* Parsing the color information: */
1495 do {
1496 if (!isdigit(*temp)) break; // This translates to </font>
1497 fg_color = (int)(*temp - 48);
1498 temp++;
1499 if (isdigit(*temp)) {
1500 fg_color = (fg_color * 10) + (int)(*temp - 48);
1501 temp++;
1502 }
1503 if (*temp != ',') break;
1504 temp++;
1505 if (!isdigit(*temp)) break; // This translates to </font>
1506 bg_color = (int)(*temp - 48);
1507 temp++;
1508 if (isdigit(*temp)) {
1509 bg_color = (bg_color * 10) + (int)(*temp - 48);
1510 temp++;
1511 }
1512 }while (FALSE);
1513
1514 if (fg_color > 15)
1515 fg_color = fg_color % 16;
1516 if (bg_color > 15)
1517 bg_color = bg_color % 16;
1518
1519 switch (fg_color) {
1520 case -1:
1521 font_tag = "</font></body>";
1522 break;
1523 case 0: // WHITE
1524 font_tag = "<font color=\"#ffffff\">";
1525 /* If no background color is specified, we're going to make it black anyway.
1526 * That's probably what the sender anticipated the background color to be.
1527 * White on white would be illegible.
1528 */
1529 if (bg_color == -1) {
1530 body_tag = "<body bgcolor=\"#000000\">";
1531 }
1532 break;
1533 case 1: // BLACK
1534 font_tag = "<font color=\"#000000\">";
1535 break;
1536 case 2: // NAVY BLUE
1537 font_tag = "<font color=\"#000066\">";
1538 break;
1539 case 3: // GREEN
1540 font_tag = "<font color=\"#006600\">";
1541 break;
1542 case 4: // RED
1543 font_tag = "<font color=\"#ff0000\">";
1544 break;
1545 case 5: // MAROON
1546 font_tag = "<font color=\"#660000\">";
1547 break;
1548 case 6: // PURPLE
1549 font_tag = "<font color=\"#660066\">";
1550 break;
1551 case 7: // DISGUSTING PUKE COLOR
1552 font_tag = "<font color=\"#666600\">";
1553 break;
1554 case 8: // YELLOW
1555 font_tag = "<font color=\"#cccc00\">";
1556 break;
1557 case 9: // LIGHT GREEN
1558 font_tag = "<font color=\"#33cc33\">";
1559 break;
1560 case 10: // TEAL
1561 font_tag = "<font color=\"#00acac\">";
1562 break;
1563 case 11: // CYAN
1564 font_tag = "<font color=\"#00ccac\">";
1565 break;
1566 case 12: // BLUE
1567 font_tag = "<font color=\"#0000ff\">";
1568 break;
1569 case 13: // PINK
1570 font_tag = "<font color=\"#cc00cc\">";
1571 break;
1572 case 14: // GREY
1573 font_tag = "<font color=\"#666666\">";
1574 break;
1575 case 15: // SILVER
1576 font_tag = "<font color=\"#00ccac\">";
1577 break;
1578 }
1579
1580 switch (bg_color) {
1581 case 0: // WHITE
1582 body_tag = "<body bgcolor=\"#ffffff\">";
1583 break;
1584 case 1: // BLACK
1585 body_tag = "<body bgcolor=\"#000000\">";
1586 break;
1587 case 2: // NAVY BLUE
1588 body_tag = "<body bgcolor=\"#000066\">";
1589 break;
1590 case 3: // GREEN
1591 body_tag = "<body bgcolor=\"#006600\">";
1592 break;
1593 case 4: // RED
1594 body_tag = "<body bgcolor=\"#ff0000\">";
1595 break;
1596 case 5: // MAROON
1597 body_tag = "<body bgcolor=\"#660000\">";
1598 break;
1599 case 6: // PURPLE
1600 body_tag = "<body bgcolor=\"#660066\">";
1601 break;
1602 case 7: // DISGUSTING PUKE COLOR
1603 body_tag = "<body bgcolor=\"#666600\">";
1604 break;
1605 case 8: // YELLOW
1606 body_tag = "<body bgcolor=\"#cccc00\">";
1607 break;
1608 case 9: // LIGHT GREEN
1609 body_tag = "<body bgcolor=\"#33cc33\">";
1610 break;
1611 case 10: // TEAL
1612 body_tag = "<body bgcolor=\"#00acac\">";
1613 break;
1614 case 11: // CYAN
1615 body_tag = "<body bgcolor=\"#00ccac\">";
1616 break;
1617 case 12: // BLUE
1618 body_tag = "<body bgcolor=\"#0000ff\">";
1619 break;
1620 case 13: // PINK
1621 body_tag = "<body bgcolor=\"#cc00cc\">";
1622 break;
1623 case 14: // GREY
1624 body_tag = "<body bgcolor=\"#666666\">";
1625 break;
1626 case 15: // SILVER
1627 body_tag = "<body bgcolor=\"#00ccac\">";
1628 break;
1629 }
1630
1631 current = strchr(u_message, '\003');
1632
1633 while (*body_tag != '\0') {
1634 *current = *body_tag;
1635 current++;
1636 body_tag++;
1637 }
1638
1639 while (*font_tag != '\0') {
1640 *current = *font_tag;
1641 current++;
1642 font_tag++;
1643 }
1644
1645 while (*temp != '\0') {
1646 *current = *temp;
1647 current++;
1648 temp++;
1649 }
1650 *current = '\0';
1651 g_free(free_here);
1652 is_closing = !is_closing;
1653
1447 } 1654 }
1448 1655
1449 while(strchr(u_message, '\017')) { // \017 = ^O 1656 while(strchr(u_message, '\017')) { // \017 = ^O
1450 gchar *current; 1657 gchar *current;
1451 gchar *temp, *free_here; 1658 gchar *temp, *free_here;
1510 * @SeanEgn, until that convo is closed. 1717 * @SeanEgn, until that convo is closed.
1511 */ 1718 */
1512 1719
1513 if (find_conversation(temp)){ 1720 if (find_conversation(temp)){
1514 serv_got_im(gc, temp, u_message, 0, time((time_t)NULL)); 1721 serv_got_im(gc, temp, u_message, 0, time((time_t)NULL));
1515 if (temp) 1722 g_free(temp);
1516 g_free(temp); 1723 return;
1517 } 1724 }
1518 else { 1725 else {
1519 g_snprintf(temp, strlen(u_nick) + 2, "+%s", u_nick); 1726 g_snprintf(temp, strlen(u_nick) + 2, "+%s", u_nick);
1520 if (find_conversation(temp)) { 1727 if (find_conversation(temp)) {
1521 serv_got_im(gc, temp, u_message, 0, time((time_t)NULL)); 1728 serv_got_im(gc, temp, u_message, 0, time((time_t)NULL));
1522 if (temp) 1729 g_free(temp);
1523 g_free(temp); 1730 return;
1524 } 1731 }
1525 else { 1732 else {
1526 g_free(temp); 1733 g_free(temp);
1527 serv_got_im(gc, u_nick, u_message, 0, time((time_t)NULL)); 1734 serv_got_im(gc, u_nick, u_message, 0, time((time_t)NULL));
1528 1735 return;
1529 } 1736 }
1530 } 1737 }
1531 } 1738 }
1532 1739
1533 return; 1740 return;