Mercurial > hg > nnchat
comparison nnchat.c @ 78:745f670068dc
Add functions to simplify code.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Thu, 18 Dec 2008 14:34:44 +0200 |
parents | e8c9d7d13866 |
children | e36df57c5b0f |
comparison
equal
deleted
inserted
replaced
77:e8c9d7d13866 | 78:745f670068dc |
---|---|
423 (void) sock; | 423 (void) sock; |
424 | 424 |
425 if (!s) return 1; | 425 if (!s) return 1; |
426 *s = 0; | 426 *s = 0; |
427 | 427 |
428 p = decodeStr1(str); | 428 p = doubleDecodeStr(str); |
429 if (!p) return -1; | 429 if (!p) return -1; |
430 | 430 |
431 printMsg("! ˝3˝%s˝0˝ ˝2˝ADDED.˝0˝\n", p); | 431 printMsg("! ˝3˝%s˝0˝ ˝2˝ADDED.˝0˝\n", p); |
432 th_free(p); | 432 th_free(p); |
433 return 0; | 433 return 0; |
441 (void) sock; | 441 (void) sock; |
442 | 442 |
443 if (!s) return 1; | 443 if (!s) return 1; |
444 *s = 0; | 444 *s = 0; |
445 | 445 |
446 p = decodeStr1(str); | 446 p = doubleDecodeStr(str); |
447 if (!p) return -1; | 447 if (!p) return -1; |
448 | 448 |
449 printMsg("! ˝3˝%s˝0˝ ˝1˝DELETED.˝0˝\n", p); | 449 printMsg("! ˝3˝%s˝0˝ ˝1˝DELETED.˝0˝\n", p); |
450 th_free(p); | 450 th_free(p); |
451 return 0; | 451 return 0; |
492 } | 492 } |
493 | 493 |
494 | 494 |
495 int handleUserInput(const int sock, char *buf, size_t bufLen) | 495 int handleUserInput(const int sock, char *buf, size_t bufLen) |
496 { | 496 { |
497 char *tmpStr, *tmpStr2, tmpBuf[4096]; | 497 char *tmpStr, tmpBuf[4096]; |
498 BOOL result; | 498 BOOL result; |
499 | 499 |
500 /* Trim right */ | 500 /* Trim right */ |
501 buf[--bufLen] = 0; | 501 buf[--bufLen] = 0; |
502 while (bufLen > 0 && (buf[bufLen] == '\n' || buf[bufLen] == '\r' || th_isspace(buf[bufLen]))) | 502 while (bufLen > 0 && (buf[bufLen] == '\n' || buf[bufLen] == '\r' || th_isspace(buf[bufLen]))) |
519 int i; | 519 int i; |
520 | 520 |
521 snprintf(tmpBuf, sizeof(tmpBuf), "/prv -to %s -msg . .", | 521 snprintf(tmpBuf, sizeof(tmpBuf), "/prv -to %s -msg . .", |
522 buf+7); | 522 buf+7); |
523 | 523 |
524 tmpStr = encodeStr2(tmpBuf); | 524 tmpStr = doubleEncodeStr(tmpBuf); |
525 if (!tmpStr) return -2; | 525 if (!tmpStr) return -2; |
526 tmpStr2 = encodeStr1(tmpStr); | |
527 if (!tmpStr2) { | |
528 th_free(tmpStr); | |
529 return -3; | |
530 } | |
531 | 526 |
532 result = TRUE; | 527 result = TRUE; |
533 for (i = 0; i < 50 && result; i++) { | 528 for (i = 0; i < 50 && result; i++) { |
534 result = sendUserMsg(sock, optUserName2, "%s", tmpStr2); | 529 result = sendUserMsg(sock, optUserName2, "%s", tmpStr); |
535 usleep(250); | 530 usleep(250); |
536 } | 531 } |
537 | 532 |
538 th_free(tmpStr); | 533 th_free(tmpStr); |
539 th_free(tmpStr2); | |
540 return 0; | 534 return 0; |
541 } else if (!strncmp(buf, "/to ", 4)) { | 535 } else if (!strncmp(buf, "/to ", 4)) { |
542 th_free(setTarget); | 536 th_free(setTarget); |
543 setTarget = strdup(buf + 4); | 537 setTarget = strdup(buf + 4); |
544 printMsg("Set prv target to '%s'\n", setTarget); | 538 printMsg("Set prv target to '%s'\n", setTarget); |
557 } | 551 } |
558 } | 552 } |
559 | 553 |
560 | 554 |
561 /* Send double-encoded */ | 555 /* Send double-encoded */ |
562 tmpStr = encodeStr2(buf); | 556 tmpStr = doubleEncodeStr(buf); |
563 if (!tmpStr) return -2; | 557 if (!tmpStr) return -2; |
564 tmpStr2 = encodeStr1(tmpStr); | 558 |
565 if (!tmpStr2) { | 559 result = sendUserMsg(sock, optUserName2, "%s", tmpStr); |
566 th_free(tmpStr); | |
567 return -3; | |
568 } | |
569 | |
570 result = sendUserMsg(sock, optUserName2, "%s", tmpStr2); | |
571 th_free(tmpStr); | 560 th_free(tmpStr); |
572 th_free(tmpStr2); | |
573 if (result) | 561 if (result) |
574 return 0; | 562 return 0; |
575 else | 563 else |
576 return -1; | 564 return -1; |
577 } | 565 } |
617 int histPos = 0, histMax = 0; | 605 int histPos = 0, histMax = 0; |
618 | 606 |
619 memset(histBuf, 0, sizeof(histBuf)); | 607 memset(histBuf, 0, sizeof(histBuf)); |
620 | 608 |
621 /* Initialize */ | 609 /* Initialize */ |
622 th_init("NNChat", "Newbie Nudes chat client", "0.6.6", | 610 th_init("NNChat", "Newbie Nudes chat client", "0.6.7", |
623 "Written and designed by Anonymous Finnish Guy (C) 2008", | 611 "Written and designed by Anonymous Finnish Guy (C) 2008", |
624 "This software is freeware, use and distribute as you wish."); | 612 "This software is freeware, use and distribute as you wish."); |
625 th_verbosityLevel = 0; | 613 th_verbosityLevel = 0; |
626 | 614 |
627 /* Parse arguments */ | 615 /* Parse arguments */ |
700 THERR("Main connection setup failed!\n"); | 688 THERR("Main connection setup failed!\n"); |
701 goto err_exit; | 689 goto err_exit; |
702 } | 690 } |
703 | 691 |
704 THMSG(1, "Connected, logging in as '%s', site '%s'.\n", optUserName, optSite); | 692 THMSG(1, "Connected, logging in as '%s', site '%s'.\n", optUserName, optSite); |
705 optUserName2 = encodeStr1(optUserName); | 693 optUserName2 = doubleEncodeStr(optUserName); |
706 tmpStr = encodeStr1(optSite); | 694 tmpStr = doubleEncodeStr(optSite); |
707 sendUserMsg(tmpSocket, optUserName2, "%%2Flogin%%20%%2Dsite%%20%s%%20%%2Dpassword%%20%s", tmpStr, optPassword); | 695 sendUserMsg(tmpSocket, optUserName2, "%%2Flogin%%20%%2Dsite%%20%s%%20%%2Dpassword%%20%s", tmpStr, optPassword); |
708 th_free(tmpStr); | 696 th_free(tmpStr); |
709 | 697 |
710 /* Initialize NCurses */ | 698 /* Initialize NCurses */ |
711 if (!optDaemon) { | 699 if (!optDaemon) { |