int userLogin() { char szUserName[8]={'\0'}; char szPasswd[8]={'\0'}; userCheck(szUserName,szPasswd); return -1; }
int handle_data(char * data, char * ret){ /* Data structured as: [head] tail Returns 1 to self-broadcast 2 to broadcast to all */ char head[200]; char tail[600]; int offset = 0; offset += getNext(data+offset, head); if(!strcmp(head, "LOGIN")){ char user[200]; char pass[200]; offset += getNext(data+offset, user); offset += getNext(data+offset, pass); int login = verifyLogin(user, pass); if(login) { strcpy(ret, "[LOGIN_CHK_1] [You have logged in]\n"); printf("server: %s logged in\n", user); } else { strcpy(ret, "[LOGIN_CHK_0] [Incorrect username/password]\n"); } return BROADCAST_SELF; } else if(!strcmp(head, "CREATE_ACCT")) { char user[200]; char pass[200]; offset += getNext(data+offset, user); offset += getNext(data+offset, pass); createAcct(user, pass); strcpy(ret, "[ACCT_CREATED] [Account succesfully created]\n"); return BROADCAST_SELF; } else if(!strcmp(head, "CHK_USR")){ char user[200]; offset += getNext(data+offset, user); int user_exst = userCheck(user); if(user_exst){ strcpy(ret, "[USR_CHK_1] [User exists]\n"); } else { strcpy(ret, "[USR_CHK_0] [Username is valid]\n"); } return BROADCAST_SELF; } else if(!strcmp(head, "JOIN")){ char user[200]; char ts[50]; offset += getNext(data+offset, user); offset += getNext(data+offset, ts); strjoin(ret, "[JOINED] [", user, "] [", ts, "]\n", NULL); strcpy(user_list[currfd], user); ol_list[currfd] = 1; //printf("Setting user %d to %s\n", currfd, user); return BROADCAST_OTHERS; } else if(!strcmp(head, "LEAVE")){ char user[200]; char ts[50]; offset += getNext(data+offset, user); offset += getNext(data+offset, ts); strjoin(ret, "[LEFT] [", user, "] [", ts, "]\n", NULL); user_list[currfd][0] = 0; ol_list[currfd] = 0; return BROADCAST_OTHERS; } else if(!strcmp(head, "MSG")){ char user[200]; char ts[50]; char msg[200]; offset += getNext(data+offset, user); offset += getNext(data+offset, ts); offset += getNext(data+offset, msg); strjoin(ret, "[MSG] [", user, "] [", ts, "] [", msg, "]\n", NULL); return BROADCAST_ALL; } else if(!strcmp(head, "OL")){ strcpy(ret, "[ONLINE]"); pollOnline(ret); return BROADCAST_SELF; } else if(!strcmp(head, "PM")){ //printf("server: Got pm\n"); char target[200]; char user[200]; char ts[50]; char msg[200]; offset += getNext(data+offset, target); strcpy(pm_global, target); offset += getNext(data+offset, user); offset += getNext(data+offset, ts); offset += getNext(data+offset, msg); strjoin(ret, "[PMR] [", user, "] [", ts, "] [", msg, "]\n", NULL); return BROADCAST_ONE; } }