diff options
| author | Franklin Wei <git@fwei.tk> | 2016-03-28 14:11:22 -0400 |
|---|---|---|
| committer | Franklin Wei <git@fwei.tk> | 2016-03-31 17:09:36 -0400 |
| commit | ed95a5621ac9c4f5002e68a981f8b24d5caaedf4 (patch) | |
| tree | aee87cf74280e8f9dd29aca88d12a638f37b2493 /src/client.c | |
| parent | 13052597a19fd2212efb7f51f19ed73b9f4b6ba4 (diff) | |
| download | netcosm-ed95a5621ac9c4f5002e68a981f8b24d5caaedf4.zip netcosm-ed95a5621ac9c4f5002e68a981f8b24d5caaedf4.tar.gz netcosm-ed95a5621ac9c4f5002e68a981f8b24d5caaedf4.tar.bz2 netcosm-ed95a5621ac9c4f5002e68a981f8b24d5caaedf4.tar.xz | |
kludge things to compile on old linux
Diffstat (limited to 'src/client.c')
| -rw-r--r-- | src/client.c | 70 |
1 files changed, 62 insertions, 8 deletions
diff --git a/src/client.c b/src/client.c index a93ae0e..d66836e 100644 --- a/src/client.c +++ b/src/client.c @@ -20,10 +20,12 @@ #include "auth.h" #include "client.h" +#include "client_reqs.h" #include "hash.h" #include "server.h" #include "room.h" #include "telnet.h" +#include "userdb.h" #include "util.h" bool are_admin = false; @@ -100,6 +102,8 @@ void __attribute__((format(printf,1,2))) out(const char *fmt, ...) if(is_newline) ++ptr; /* skip the newline */ + + /* skip following spaces */ while(*ptr == ' ') ++ptr; last_space = 0; @@ -184,7 +188,7 @@ tryagain: } } -/* still not encrypted, but a bit more secure than echoing the password! */ +/* still not encrypted, but a bit better than echoing the password! */ char *client_read_password(void) { telnet_echo_off(); @@ -194,8 +198,6 @@ char *client_read_password(void) return ret; } -#define WSPACE " \t\r\n" - #define CMD_OK 0 #define CMD_LOGOUT 1 #define CMD_QUIT 2 @@ -206,7 +208,10 @@ int user_cb(char **save) { char *what = strtok_r(NULL, WSPACE, save); if(!what) + { + out("Usage: USER <ADD|DEL|MODIFY|LIST> <ARGS>\n"); return CMD_OK; + } all_upper(what); @@ -304,9 +309,9 @@ int client_cb(char **save) else if(!strcmp(what, "KICK")) { char *pid_s = strtok_r(NULL, WSPACE, save); - all_upper(pid_s); if(pid_s) { + all_upper(pid_s); if(!strcmp(pid_s, "ALL")) { const char *msg = "Kicking everyone...\n"; @@ -336,7 +341,7 @@ int client_cb(char **save) debugf("Success.\n"); } else - out("Usage: CLIENT KICK <PID>\n"); + out("Usage: CLIENT KICK <PID|ALL>\n"); } return CMD_OK; } @@ -402,6 +407,7 @@ int take_cb(char **save) int wait_cb(char **save) { (void) save; + /* debugging */ send_master(REQ_WAIT, NULL, 0); return CMD_OK; } @@ -416,14 +422,61 @@ int go_cb(char **save) client_look(); } else - out("Expected direction after GO.\n"); + out("I don't understand where you want me to go.\n"); return CMD_OK; } int drop_cb(char **save) { char *what = strtok_r(NULL, "", save); - client_drop(what); + if(what) + client_drop(what); + else + out("You must supply an object.\n"); + return CMD_OK; +} + +int chpass_cb(char **save) +{ + out("Enter current password: "); + char *current = client_read_password(); + + struct userdata_t *current_data = auth_check(current_user, current); + + memset(current, 0, strlen(current)); + free(current); + + if(!current_data) + { + out("Password mismatch.\n"); + return CMD_OK; + } + + out("Enter new password: "); + char *pass1 = client_read_password(); + + out("Retype new password: "); + + char *pass2 = client_read_password(); + + if(strcmp(pass1, pass2)) + { + memset(pass1, 0, strlen(pass1)); + memset(pass2, 0, strlen(pass2)); + free(pass1); + free(pass2); + + out("Passwords do not match.\n"); + return CMD_OK; + } + + memset(pass2, 0, strlen(pass2)); + free(pass2); + + auth_user_add(current_user, pass1, current_data->priv); + + memset(pass1, 0, strlen(pass1)); + return CMD_OK; } @@ -442,9 +495,10 @@ static const struct client_cmd { { "LOOK", look_cb, false }, { "INVENTORY", inventory_cb, false }, { "TAKE", take_cb, false }, - { "WAIT", wait_cb, false }, + { "WAIT", wait_cb, true }, { "GO", go_cb, false }, { "DROP", drop_cb, false }, + { "CHPASS", chpass_cb, false }, }; static void *cmd_map = NULL; |