summaryrefslogtreecommitdiff
path: root/vchat-protocol.c
diff options
context:
space:
mode:
Diffstat (limited to 'vchat-protocol.c')
-rwxr-xr-xvchat-protocol.c140
1 files changed, 74 insertions, 66 deletions
diff --git a/vchat-protocol.c b/vchat-protocol.c
index 1a29b07..55c8b55 100755
--- a/vchat-protocol.c
+++ b/vchat-protocol.c
@@ -31,6 +31,7 @@
31 31
32/* local includes */ 32/* local includes */
33#include "vchat.h" 33#include "vchat.h"
34#include "vchat-user.h"
34#include "vchat-ssl.h" 35#include "vchat-ssl.h"
35 36
36/* version of this module */ 37/* version of this module */
@@ -208,6 +209,7 @@ pubaction (char *message)
208 nick = strchr (message, ' '); 209 nick = strchr (message, ' ');
209 nick[0] = '\0'; 210 nick[0] = '\0';
210 nick++; 211 nick++;
212 ul_public_action(nick);
211 213
212 action = strchr (nick, ' '); 214 action = strchr (nick, ' ');
213 action[0] = '\0'; 215 action[0] = '\0';
@@ -228,11 +230,12 @@ pubthoughts (char *message)
228 nick = strchr (message, ' '); 230 nick = strchr (message, ' ');
229 nick[0] = '\0'; 231 nick[0] = '\0';
230 nick++; 232 nick++;
233 ul_public_action(nick);
231 234
232 thoughts = strchr (nick, ' '); 235 thoughts = strchr (nick, ' ');
233 thoughts[0] = '\0'; 236 thoughts[0] = '\0';
234 thoughts++; 237 thoughts++;
235 238
236 snprintf(tmpstr,TMPSTRSIZE,getformatstr(FS_PUBTHOUGHT),nick,thoughts); 239 snprintf(tmpstr,TMPSTRSIZE,getformatstr(FS_PUBTHOUGHT),nick,thoughts);
237 writechan (tmpstr); 240 writechan (tmpstr);
238} 241}
@@ -269,7 +272,7 @@ static void
269topicinfo (char *message) 272topicinfo (char *message)
270{ 273{
271 char *channel = NULL, *topic = NULL; 274 char *channel = NULL, *topic = NULL;
272 int tmpchan = 0; 275 int tmpchan = 0, ownchan = own_channel_get();
273 276
274 /* search start of channel number */ 277 /* search start of channel number */
275 channel = strchr (message, ' '); 278 channel = strchr (message, ' ');
@@ -283,12 +286,12 @@ topicinfo (char *message)
283 /* convert channel number to integer */ 286 /* convert channel number to integer */
284 tmpchan = atoi (channel); 287 tmpchan = atoi (channel);
285 288
286 if (tmpchan == chan) { 289 if (tmpchan == ownchan ) {
287 /* show change in topic window */ 290 /* show change in topic window */
288 if (strlen(topic)) 291 if (strlen(topic))
289 snprintf (topicstr, TOPICSTRSIZE, getformatstr(FS_TOPICW), chan, topic); 292 snprintf (topicstr, TOPICSTRSIZE, getformatstr(FS_TOPICW), ownchan, topic);
290 else 293 else
291 snprintf (topicstr, TOPICSTRSIZE, getformatstr(FS_NOTOPICW), chan); 294 snprintf (topicstr, TOPICSTRSIZE, getformatstr(FS_NOTOPICW), ownchan );
292 topicline(NULL); 295 topicline(NULL);
293 } 296 }
294 297
@@ -308,11 +311,12 @@ static void
308topicchange (char *message) 311topicchange (char *message)
309{ 312{
310 char *nick = NULL, *topic = NULL; 313 char *nick = NULL, *topic = NULL;
311 int len; 314 int len, ownchan = own_channel_get();
312 315
313 /* search start of nickname */ 316 /* search start of nickname */
314 nick = strchr (message, ' '); 317 nick = strchr (message, ' ');
315 nick++; 318 nick++;
319 ul_public_action(nick);
316 320
317 /* search start of message before topic, terminate nick */ 321 /* search start of message before topic, terminate nick */
318 topic = strchr (nick, ' '); 322 topic = strchr (nick, ' ');
@@ -330,7 +334,7 @@ topicchange (char *message)
330 topic[len-1] = '\0'; 334 topic[len-1] = '\0';
331 335
332 /* show change in topic window */ 336 /* show change in topic window */
333 snprintf (topicstr, TOPICSTRSIZE, getformatstr(FS_TOPICW), chan, topic); 337 snprintf (topicstr, TOPICSTRSIZE, getformatstr(FS_TOPICW), ownchan, topic);
334 topicline(NULL); 338 topicline(NULL);
335 339
336 /* announce change in channel window */ 340 /* announce change in channel window */
@@ -356,15 +360,14 @@ justloggedin (char *message)
356 str2++; 360 str2++;
357 361
358 /* if we have a new nick, store it */ 362 /* if we have a new nick, store it */
359 if (!nick || strcasecmp (nick, str1)) 363 own_nick_set( str1 );
360 setstroption(CF_NICK,str1);
361 364
362 /* show change in console window */ 365 /* show change in console window */
363 snprintf (consolestr, CONSOLESTRSIZE, getformatstr(FS_CONSOLE), nick, getstroption (CF_SERVERHOST), getstroption (CF_SERVERPORT)); 366 snprintf (consolestr, CONSOLESTRSIZE, getformatstr(FS_CONSOLE), str1, getstroption (CF_SERVERHOST), getstroption (CF_SERVERPORT));
364 consoleline (NULL); 367 consoleline (NULL);
365 368
366 /* announce login as servermessage */ 369 /* announce login as servermessage */
367 snprintf (tmpstr, TMPSTRSIZE, getformatstr(FS_SIGNON), nick, str2); 370 snprintf (tmpstr, TMPSTRSIZE, getformatstr(FS_SIGNON), str1, str2);
368 writechan (tmpstr); 371 writechan (tmpstr);
369 372
370 /* we're not logged in, change status and request nicks */ 373 /* we're not logged in, change status and request nicks */
@@ -380,31 +383,15 @@ justloggedin (char *message)
380void 383void
381ownjoin (int channel) 384ownjoin (int channel)
382{ 385{
383 /* change global channel info */
384 chan = channel;
385 networkoutput(".t"); 386 networkoutput(".t");
386 snprintf(tmpstr, TMPSTRSIZE, ".S %d",chan); 387 snprintf(tmpstr, TMPSTRSIZE, ".S %d",channel);
387 networkoutput(tmpstr); 388 networkoutput(tmpstr);
388} 389}
389 390
390/* this user leaves a channel */
391void
392ownleave (int channel)
393{
394 /* change global channel info */
395 chan = 0;
396}
397
398/* this user changes his nick */ 391/* this user changes his nick */
399void 392void
400ownnickchange (char *newnick) 393ownnickchange (char *newnick)
401{ 394{
402 /* free old nick, store copy of new nick */
403 setstroption(CF_NICK,newnick);
404
405 /* show change in console window */
406 snprintf (consolestr, CONSOLESTRSIZE, getformatstr(FS_CONSOLE), nick, getstroption (CF_SERVERHOST), getstroption (CF_SERVERPORT));
407 consoleline (NULL);
408} 395}
409 396
410/* parse and handle a nick error message 397/* parse and handle a nick error message
@@ -431,12 +418,13 @@ nickerr (char *message)
431 if (!loggedin) 418 if (!loggedin)
432 { 419 {
433 /* free bogus nick */ 420 /* free bogus nick */
434 setstroption(CF_NICK,NULL); 421 own_nick_set(NULL);
422
435 /* get new nick via vchat-ui.c */ 423 /* get new nick via vchat-ui.c */
436 nickprompt (); 424 nickprompt ();
437 425
438 /* form login message and send it to server */ 426 /* form login message and send it to server */
439 snprintf (tmpstr, TMPSTRSIZE, ".l %s %s %d", nick, getstroption (CF_FROM), getintoption (CF_CHANNEL)); 427 snprintf (tmpstr, TMPSTRSIZE, ".l %s %s %d", own_nick_get(), getstroption (CF_FROM), getintoption (CF_CHANNEL));
440 networkoutput (tmpstr); 428 networkoutput (tmpstr);
441 } 429 }
442} 430}
@@ -455,13 +443,13 @@ login (char *message) {
455 writecf (FS_SERV,&message[2]); 443 writecf (FS_SERV,&message[2]);
456 444
457 /* we don't know our nick? */ 445 /* we don't know our nick? */
458 if (!nick) { 446 if (!own_nick_get() ) {
459 /* find message after nick */ 447 /* find message after nick */
460 msg = strchr (&message[4], ' '); 448 msg = strchr (&message[4], ' ');
461 if (msg) { 449 if (msg) {
462 /* terminate string before message and copy nick */ 450 /* terminate string before message and copy nick */
463 msg[0] = '\0'; 451 msg[0] = '\0';
464 setstroption(CF_NICK,&message[4]); 452 own_nick_set(&message[4]);
465 } else { 453 } else {
466 /* no string in servers message (huh?), ask user for nick */ 454 /* no string in servers message (huh?), ask user for nick */
467 nickprompt (); 455 nickprompt ();
@@ -469,7 +457,7 @@ login (char *message) {
469 } 457 }
470 458
471 /* form login message and send it to server */ 459 /* form login message and send it to server */
472 snprintf (tmpstr, TMPSTRSIZE, ".l %s %s %d", nick, getstroption (CF_FROM), getintoption (CF_CHANNEL)); 460 snprintf (tmpstr, TMPSTRSIZE, ".l %s %s %d", own_nick_get(), getstroption (CF_FROM), getintoption (CF_CHANNEL));
473 networkoutput (tmpstr); 461 networkoutput (tmpstr);
474} 462}
475 463
@@ -485,11 +473,11 @@ anonlogin (char *message)
485 writecf (FS_SERV,&message[2]); 473 writecf (FS_SERV,&message[2]);
486 474
487 /* we don't know our nick? ask for it! */ 475 /* we don't know our nick? ask for it! */
488 if (!nick) 476 if (!own_nick_get())
489 nickprompt (); 477 nickprompt ();
490 478
491 /* form login message and send it to server */ 479 /* form login message and send it to server */
492 snprintf (tmpstr, TMPSTRSIZE, ".l %s %s %d", nick, getstroption (CF_FROM), getintoption (CF_CHANNEL)); 480 snprintf (tmpstr, TMPSTRSIZE, ".l %s %s %d", own_nick_get(), getstroption (CF_FROM), getintoption (CF_CHANNEL));
493 networkoutput (tmpstr); 481 networkoutput (tmpstr);
494} 482}
495 483
@@ -497,49 +485,53 @@ anonlogin (char *message)
497 * format: 119 %s .. 485 * format: 119 %s ..
498 * vars: %s nick - a users nick */ 486 * vars: %s nick - a users nick */
499static void 487static void
500receivenicks (char *message) 488receivenicks (char *message) {
501{
502 char *str1 = NULL, *str2 = NULL; 489 char *str1 = NULL, *str2 = NULL;
503 int mychan = 0; 490 int chanflag = -1;
504 void (*ul_myfunc)(char*,int);
505 491
506 /* show message to user */ 492 /* show message to user */
507 snprintf (tmpstr, TMPSTRSIZE, getformatstr(FS_USONLINE), &message[4]); 493 snprintf (tmpstr, TMPSTRSIZE, getformatstr(FS_USONLINE), &message[4]);
508 writechan (tmpstr); 494 writechan (tmpstr);
509 495
510 /* search for channelnumber */ 496 /* search for channelnumber */
511 str1 = strchr (message, ' '); 497 if( !(str1 = strchr (message, ' ') ) ) return;
512 str1++; 498 str1++;
499
513 if (str1[0] == '*') { 500 if (str1[0] == '*') {
514 if (nicks) return; 501 ul_rebuild_list();
515 ul_myfunc = ul_add;
516 str1++; 502 str1++;
517 } else { 503 } else {
504 int mychan;
518 str2 = str1; 505 str2 = str1;
519 str1 = strchr(str2,' '); 506 str1 = strchr(str2,' ');
520 str1[0] = '\0'; 507 str1[0] = '\0';
521 mychan = atoi(str2); 508 mychan = atoi(str2);
522 ul_myfunc = ul_moveuser; 509 if( mychan != own_channel_get() )
510 return;
511
512 /* Kick all users from the IN_MY_CHANNEL list */
513 own_channel_set( own_channel_get() );
514 chanflag = 1;
523 } 515 }
524 str1++; 516 str1++;
525 517
526 /* while user .. */ 518 /* while user .. */
527 while (str1) 519 while (str1) {
528 { 520 /* search next user */
529 /* search next user */ 521 str2 = strchr (str1, ' ');
530 str2 = strchr (str1, ' '); 522 /* there is another user? terminate this one */
531 /* there is another user? terminate this one */ 523 if (str2) {
532 if (str2) { 524 str2[0] = '\0';
533 str2[0] = '\0'; 525 str2++;
534 str2++; 526 }
535 }
536 527
537 /* add this user via vchat-user.c */ 528 /* add this user via vchat-user.c */
538 ul_myfunc (str1,mychan); 529 ul_add(str1, chanflag);
539 530
540 /* next user .. */ 531 /* next user .. */
541 str1 = str2; 532 str1 = str2;
542 } 533 }
534 ul_clean();
543} 535}
544 536
545/* parse and handle a login message 537/* parse and handle a login message
@@ -581,11 +573,13 @@ usersignoff (char *message)
581 573
582 /* search start of message, terminate nick */ 574 /* search start of message, terminate nick */
583 msg = strchr (nick, ' '); 575 msg = strchr (nick, ' ');
584 msg[0] = '\0'; 576 if( msg ) {
585 msg++; 577 msg[0] = '\0';
578 msg++;
579 }
586 580
587 /* delete this user via vchat-user.c */ 581 /* delete this user via vchat-user.c */
588 ul_del (nick, 0); 582 ul_del (nick);
589 583
590 /* show message to user */ 584 /* show message to user */
591 snprintf (tmpstr, TMPSTRSIZE, getformatstr(FS_SIGNOFF), nick, msg); 585 snprintf (tmpstr, TMPSTRSIZE, getformatstr(FS_SIGNOFF), nick, msg);
@@ -620,8 +614,13 @@ userjoin (char *message)
620 /* convert channel to integer */ 614 /* convert channel to integer */
621 chan = atoi (channel); 615 chan = atoi (channel);
622 616
617 /* is it myself joining */
618 if( own_nick_check(nick) )
619 own_channel_set(chan);
620
623 /* notice channel join via vchat-user.c */ 621 /* notice channel join via vchat-user.c */
624 ul_join (nick, chan); 622 if( own_channel_get() == chan )
623 ul_enter_chan(nick);
625 624
626 /* show message to user */ 625 /* show message to user */
627 snprintf (tmpstr, TMPSTRSIZE, getformatstr(FS_JOIN), nick, msg, chan); 626 snprintf (tmpstr, TMPSTRSIZE, getformatstr(FS_JOIN), nick, msg, chan);
@@ -657,7 +656,7 @@ userleave (char *message)
657 chan = atoi (channel); 656 chan = atoi (channel);
658 657
659 /* notice channel leave via vchat-user.c */ 658 /* notice channel leave via vchat-user.c */
660 ul_leave (nick, chan); 659 ul_leave_chan(nick);
661 660
662 /* show message to user */ 661 /* show message to user */
663 snprintf (tmpstr, TMPSTRSIZE, getformatstr(FS_LEAVE), nick, msg, chan); 662 snprintf (tmpstr, TMPSTRSIZE, getformatstr(FS_LEAVE), nick, msg, chan);
@@ -689,7 +688,13 @@ usernickchange (char *message)
689 msg++; 688 msg++;
690 689
691 /* notice nickchange via vchat-user.c */ 690 /* notice nickchange via vchat-user.c */
692 ul_nickchange (oldnick, newnick); 691 ul_rename (oldnick, newnick);
692
693 if( own_nick_check(newnick) ) {
694 /* show change in console window */
695 snprintf (consolestr, CONSOLESTRSIZE, getformatstr(FS_CONSOLE), newnick, getstroption (CF_SERVERHOST), getstroption (CF_SERVERPORT));
696 consoleline (NULL);
697 }
693 698
694 /* show message to user */ 699 /* show message to user */
695 snprintf (tmpstr, TMPSTRSIZE, getformatstr(FS_NICKCHANGE), oldnick, newnick, msg); 700 snprintf (tmpstr, TMPSTRSIZE, getformatstr(FS_NICKCHANGE), oldnick, newnick, msg);
@@ -710,11 +715,13 @@ parsemsg (char *message)
710 str2[0] = '\0'; 715 str2[0] = '\0';
711 str2++; 716 str2++;
712 if (str2[0] == ' ') str2++; 717 if (str2[0] == ' ') str2++;
713 if (!strncasecmp(nick,str2,strlen(nick))) 718 if (own_nick_check(str1))
714 snprintf(tmpstr,TMPSTRSIZE,getformatstr(FS_MYPUBMSG),str1,str2); 719 snprintf(tmpstr,TMPSTRSIZE,getformatstr(FS_MYPUBMSG),str1,str2);
715 else 720 else
716 snprintf(tmpstr,TMPSTRSIZE,getformatstr(FS_RXPUBMSG),str1,str2); 721 snprintf(tmpstr,TMPSTRSIZE,getformatstr(FS_RXPUBMSG),str1,str2);
717 writechan (tmpstr); 722 writechan (tmpstr);
723
724 ul_public_action(str1);
718 } 725 }
719 else if (message[0] == '[') 726 else if (message[0] == '[')
720 { 727 {
@@ -723,10 +730,11 @@ parsemsg (char *message)
723 str2[0] = '\0'; 730 str2[0] = '\0';
724 str2++; 731 str2++;
725 if (str2[0] == ' ') str2++; 732 if (str2[0] == ' ') str2++;
726 if (!strncasecmp(nick,str2,strlen(nick))) 733 if (own_nick_check( str1 ))
727 snprintf(tmpstr,TMPSTRSIZE,getformatstr(FS_MYPUBURL),str1,str2); 734 snprintf(tmpstr,TMPSTRSIZE,getformatstr(FS_MYPUBURL),str1,str2);
728 else 735 else
729 snprintf(tmpstr,TMPSTRSIZE,getformatstr(FS_RXPUBURL),str1,str2); 736 snprintf(tmpstr,TMPSTRSIZE,getformatstr(FS_RXPUBURL),str1,str2);
737 ul_public_action(str1);
730 writechan (tmpstr); 738 writechan (tmpstr);
731 } 739 }
732 /* message starts with '*'? must be private */ 740 /* message starts with '*'? must be private */
@@ -739,7 +747,7 @@ parsemsg (char *message)
739 if (str2[0] == ' ') str2++; 747 if (str2[0] == ' ') str2++;
740 snprintf(tmpstr,TMPSTRSIZE,getformatstr(FS_RXPRIVMSG),str1,str2); 748 snprintf(tmpstr,TMPSTRSIZE,getformatstr(FS_RXPRIVMSG),str1,str2);
741 writepriv (tmpstr, 1); 749 writepriv (tmpstr, 1);
742 ul_msgfrom(str1); 750 ul_private_action(str1);
743 } 751 }
744 /* message starts with a number? must be a servermessage */ 752 /* message starts with a number? must be a servermessage */
745 else if ((message[0] >= '0') && (message[0] <= '9')) 753 else if ((message[0] >= '0') && (message[0] <= '9'))