int handle_client_connection(t_client_info *client, t_client_info *list, char *cmd, t_channel **channels) { char *buff; buff = strdup(cmd); bzero(cmd, 4096); if (strncmp(buff, "PASS ", 5) == 0) return (0); else if (strncmp(buff, "NICK ", 5) == 0) return (handle_nick(client, buff + 5, list)); else if (strncmp(buff, "USER ", 5) == 0) return (0); else if (strncmp(buff, "JOIN ", 5) == 0) return (join_channel(client, buff + 5, channels)); else if (strncmp(buff, "PART ", 5) == 0) return (part_channel(client, channels)); else if (strncmp(buff, "LIST", 4) == 0) return (list_channels(*channels, cmd, client)); else if (strncmp(buff, "USERS", 5) == 0) return (list_users(client, *channels)); else if (strncmp(buff, "MSG", 3) == 0) return (private_message(client, list, buff)); else return (send_messages(client, *channels, buff)); return (0); }
int command(const char *buf, struct client *cl, char * cmd) { char user[WORD]; char pass[WORD]; char room[WORD]; int ret = 0; matche(buf, "%s", cmd); log_debug("CMD is: %s\n",cmd); if (strcmp(cmd,"/connect") == 0) { matche(buf, "%s %s %s %s", cmd, user, pass, room); log_debug("USER %s is trying to %s: with pass %s\n", user, cmd, pass); ret = check_passwd(user, pass); strncpy(cl->cl_name, user, sizeof(user)); strncpy(cl->cl_room, room, sizeof(room)); return (ret); } if (strcmp(cmd,"/quit") == 0) { log_debug("USER is trying to %s", cmd); return (CLOSE_CONNECTION); } if (strcmp(cmd,"/secret") == 0) { matche(buf, "%s %s", cmd, user); log_debug("USER %s is trying to say a secret to %s\n", cl->cl_name, user); ret = private_message(buf); strncpy(cmd, user, sizeof(user)); return (ret); } if (strcmp(cmd,"/names") == 0) { log_debug("USER wants to know %s", cmd); return (1); } return (ret); }