Routine bugfixes

master
Aadhavan Srinivasan 2 years ago
parent a5ac16f884
commit 42e12def81

@ -33,7 +33,7 @@ int main() {
fd_set read_fd_set; fd_set read_fd_set;
int conn_sockets[MAX_CONNECTIONS] = {-1}; int conn_sockets[MAX_CONNECTIONS] = {-1};
User* dest_users[MAX_CONNECTIONS] = {NULL}; User* to_user[MAX_CONNECTIONS] = {NULL};
FD_ZERO(&read_fd_set); FD_ZERO(&read_fd_set);
char buffer[BUFFER_SIZE]; char buffer[BUFFER_SIZE];
@ -73,15 +73,15 @@ int main() {
if (num_bytes_read <= 0) { if (num_bytes_read <= 0) {
close(conn_sockets[i]); close(conn_sockets[i]);
conn_sockets[i] = 0; conn_sockets[i] = 0;
dest_users[i] = NULL; to_user[i] = NULL;
} else { } else {
if (dest_users[i] == NULL) { if (to_user[i] == NULL) {
dest_users[i] = fetch_user(user_string(buffer)); to_user[i] = fetch_user(fetch_dest_user_string(buffer));
if (dest_users[i] == NULL) { if (to_user[i] == NULL) {
printf("Invalid message format or User\n"); printf("Invalid message format or User\n");
exit(241); exit(241);
} else { } else {
printf("Message intended for %s\n",dest_users[i]->username); printf("Message intended for %s\n",to_user[i]->username);
exit(0); exit(0);
} }
@ -133,9 +133,9 @@ User** create_user_list(char* filename) {
token = strtok(file_str," \r\n"); token = strtok(file_str," \r\n");
for (int i=0;i<num_users;i++) { for (int i=0;i<num_users;i++) {
users[i]->username = strdup(token); (*(users + i))->username = strdup(token);
token = strtok(NULL," \r\n"); token = strtok(NULL," \r\n");
users[i]->password = strdup(token); (*(users + i))->password = strdup(token);
token = strtok(NULL," \r\n"); token = strtok(NULL," \r\n");
} }

Loading…
Cancel
Save