Advertisement
Guest User

Untitled

a guest
Feb 1st, 2015
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.27 KB | None | 0 0
  1. void JOIN_handler(parselist *list, int sock, char *hn, user* client)
  2. {
  3. printf("Entering JOIN handler\n");
  4. channel* channame = find_channel(list->next->parameter);
  5. if(channame == NULL) {
  6. pthread_mutex_lock(&channel_lock);
  7. channel* new = create_channel(list->next->parameter);
  8. new->channeluser_list = create_channeluser(client, list->next->parameter, NULL);
  9. pthread_mutex_unlock(&channel_lock);
  10.  
  11. char* joinmsg = malloc(510);
  12. sprintf(joinmsg,":%s!%s@%s JOIN %s\r\n",
  13. client->nick,client->username,hn, list->next->parameter);
  14. printf("join message <%s>\n",joinmsg);
  15.  
  16. send_msg(NULL,client->socket,NULL,joinmsg,NULL,client,NULL);
  17.  
  18. char* namreply = malloc(510);
  19. sprintf(namreply,"= #foobar :foobar1 foobar2 foobar3");
  20. send_msg(RPL_NAMREPLY, sock, client->nick,namreply, client,NULL,NULL);
  21.  
  22. char* endofnames = malloc(510);
  23. sprintf(endofnames,"#foobar :End of NAMES list");
  24. send_msg(RPL_ENDOFNAMES, sock, client->nick, endofnames,client,NULL,NULL);
  25.  
  26. free_list(list);
  27. //send messages, JOIN repeat + 332/353/366
  28. } else if (channame != NULL) {
  29. //channel exists! do other stuff here
  30. //check if user is already member of channel
  31. if (find_channeluser(client, channame) != NULL) {
  32. free_list(list);
  33. } else {
  34. //add user to channel's channelusers
  35. pthread_mutex_lock(&channel_lock);
  36. channame->channeluser_list =
  37. create_channeluser(client,list->next->parameter,channame->channeluser_list);
  38. pthread_mutex_unlock(&channel_lock);
  39.  
  40. char* joinmsg = malloc(510);
  41. sprintf(joinmsg,":%s!%s@%s JOIN %s\r\n",
  42. client->nick,client->username,hn, channame->name);
  43. send_msg(NULL,client->socket,NULL,joinmsg,NULL,client,NULL);
  44.  
  45. char* namreply = malloc(510);
  46. sprintf(namreply,"= #foobar :foobar1 foobar2 foobar3");
  47. send_msg(RPL_NAMREPLY, sock, client->nick,namreply, client,NULL,NULL);
  48.  
  49. char* endofnames = malloc(510);
  50. sprintf(endofnames,"#foobar :End of NAMES list");
  51. send_msg(RPL_ENDOFNAMES, sock, client->nick, endofnames,client,NULL,NULL);
  52.  
  53. //send to all channel's users
  54. char* joinmsg1 = malloc(510);
  55. sprintf(joinmsg1,":%s!%s@%s JOIN %s\r\n",
  56. client->nick,client->username,hn, channame->name);
  57. send_msg(NULL,0,NULL,joinmsg1,client,NULL,channame);
  58.  
  59. free_list(list);
  60. }
  61. }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement