|
|
|
@ -20,6 +20,8 @@
|
|
|
|
|
User** create_user_list(char* filename);
|
|
|
|
|
void sigint_handler(int dummy);
|
|
|
|
|
User* fetch_user(char* username);
|
|
|
|
|
int user_to_index(User* user);
|
|
|
|
|
bool user_equals(User* this, User* other);
|
|
|
|
|
|
|
|
|
|
User** users;
|
|
|
|
|
int num_users;
|
|
|
|
@ -120,10 +122,17 @@ int main() {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
printf("Your message is: %s\n",message_string);
|
|
|
|
|
Message message = new_message(message_string,from_user[i],to_user[i]);
|
|
|
|
|
|
|
|
|
|
if (user_to_index(to_user[i]) < 0) {
|
|
|
|
|
printf("Recipient user does not exist!\n");
|
|
|
|
|
return -20;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Message* message = new_message(message_string,from_user[i],to_user[i]);
|
|
|
|
|
stack_push( message_stack[user_to_index(to_user[i])],message );
|
|
|
|
|
|
|
|
|
|
printf("Message has been pushed onto stack for %s\n",to_user[i]->username);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
close(conn_sockets[i]);
|
|
|
|
@ -205,7 +214,7 @@ User* fetch_user(char* username) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int user_to_index(User* user) {
|
|
|
|
|
int index = 0;
|
|
|
|
|
int index = -1;
|
|
|
|
|
for (int i=0;i < num_users; i++) {
|
|
|
|
|
if (user_equals(users[i],user) == true) {
|
|
|
|
|
index = i;
|
|
|
|
|