Advertisement
Guest User

Untitled

a guest
Mar 19th, 2017
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. char **usernames = {"paul","andrei","cipri","truta"};
  2. char **passwords = {"1","1","1","1"};
  3. int userCount = 4;
  4.  
  5. while((rlen = read(cli->connfd, buff_in, sizeof(buff_in)-1)) > 0){
  6. buff_in[rlen] = '\0';
  7. buff_out[0] = '\0';
  8. strip_newline(buff_in);
  9.  
  10. /* Ignore empty buffer */
  11. if(!strlen(buff_in)){
  12. continue;
  13. }
  14.  
  15. /* Special options */
  16. if(buff_in[0] == '\\'){
  17. char *command, *username, *password;
  18. command = strtok(buff_in," ");
  19. if(!strcmp(command, "\\LOGIN")){
  20. username = strtok(NULL, " ");
  21. password = strtok(NULL, " ");
  22. if(username&&password){
  23. if(checkLogin(username,password)){
  24. cli->login=1;
  25. strcpy(cli->name,username);
  26. sprintf(buff_out, "<<%s loged in \r\n", cli->name);
  27. send_message_all(buff_out);
  28. }else{
  29. send_message_self("<<WRONG USERNAME/PASSWORD\r\n", cli->connfd);
  30. }
  31. }else{
  32. send_message_self("<<WRONG USERNAME/PASSWORD\r\n", cli->connfd);
  33. }
  34. }else{
  35. send_message_self("<<UNKOWN COMMAND\r\n", cli->connfd);
  36. }
  37. }else{
  38. /* Send message */
  39. sprintf(buff_out, "[%s] %s\r\n", cli->name, buff_in);
  40. send_message(buff_out, cli->uid);
  41. }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement