diff options
author | Ben Burwell <bburwell1@gmail.com> | 2013-04-29 16:13:34 -0400 |
---|---|---|
committer | Ben Burwell <bburwell1@gmail.com> | 2013-04-29 16:13:34 -0400 |
commit | ca9e46c937e75df43d2f80f0d957fabb07892c29 (patch) | |
tree | 0d8ae2bc1d1e3e248c746586a5daf7cb58a79463 /user_command.h |
Init
Diffstat (limited to 'user_command.h')
-rw-r--r-- | user_command.h | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/user_command.h b/user_command.h new file mode 100644 index 0000000..1c554e6 --- /dev/null +++ b/user_command.h @@ -0,0 +1,62 @@ +/** + * Localchat + * Ben Burwell + * + * Process user input + */ + +void process_user_command() { + + int i; + + if (strcmp(command, "quit\n") == 0) { + exit(0); + } else if (strcmp(command, "who\n") == 0) { + + // print a list of online peers + pthread_mutex_lock(&peer_table_lock); + + printf(" +---------+-----------------+----------------------------------+ \n"); + printf(" | In Chat | IP | Username | \n"); + printf(" +---------+-----------------+----------------------------------+ \n"); + + for (i = 0; i < num_peers_in_table; i++) { + printf(" | %s | %-15s | %-32s | \n", peers[i].in_chat, peers[i].ip, peers[i].username); + } + + printf(" +---------+-----------------+----------------------------------+ \n"); + + pthread_mutex_unlock(&peer_table_lock); + + } else if (strcmp(command, "chat\n") == 0) { + + char user[32]; + int exists; + + printf("user: "); + fgets(user, 32, stdin); + + user[strlen(user) - 1] = 0; + + exists = check_user_name(user); + + if (exists) { + printf("Sending chat request to %s... \n", user); + send_chat_request(user); + } else { + printf("%s does not exist. \n", user); + } + + + } else if (strcmp(command, "help\n") == 0 || strcmp(command, "?\n") == 0) { + + printf("Command Summary: \n"); + printf(" who: display a list of online peers \n"); + printf(" chat: initiate a chat session \n"); + + } else if (strcmp(command, "\n") == 0) { + // no command, do nothing. + } else { + printf("Unrecognized command. Type `help` or `?` for help. \n"); + } +}
\ No newline at end of file |