diff options
author | Danny Holman <dholman@gymli.org> | 2023-02-15 22:43:41 -0600 |
---|---|---|
committer | Danny Holman <dholman@gymli.org> | 2023-02-15 22:43:41 -0600 |
commit | ec9f8a5b55663cf5bc21c605787c7c83594f8719 (patch) | |
tree | 2f8d70c325f424b008d217dcf58c0348028d821c /server | |
parent | 960846b6f3e3bbc060a21a9d950ee569ed841ee2 (diff) |
main: add a command line processor
Add a function that processes incoming user commands.
Signed-off-by: Danny Holman <dholman@gymli.org>
Diffstat (limited to 'server')
-rw-r--r-- | server/src/mini-rat.c | 27 |
1 files changed, 24 insertions, 3 deletions
diff --git a/server/src/mini-rat.c b/server/src/mini-rat.c index e0fd5d1..521b269 100644 --- a/server/src/mini-rat.c +++ b/server/src/mini-rat.c @@ -2,12 +2,33 @@ #include <server.h> #include <mini-rat.h> +int running = 1; +int cur_session = 0; + +void parse_cmd(const char *line) { + if (strcmp(line, "exit\n") == 0) { + running = 0; + } else if (strncmp(line, "session ", 8) == 0) { + sprintf(line, "session %d", cur_session); + print("Swapped current session to %d\n", cur_session); + } + return; +} + int main(int argc, char* argv[]) { FILE *logfile = fopen("log.txt", "w"); - init_logging(stderr); - uint16_t port = 21115; + init_logging(logfile); + uint16_t port = 1122; pthread_t listen_thread; pthread_create(&listen_thread, NULL, listener, (void*)&port); - pthread_exit(NULL); + char line[4096]; + while (running) { + printf("mini-rat> "); + fgets(line, 4096, stdin); + parse_cmd(line); + } + + pthread_cancel(listen_thread); + return 0; } |