diff options
| author | Franklin Wei <frankhwei536@gmail.com> | 2016-01-31 19:53:45 -0500 |
|---|---|---|
| committer | Franklin Wei <frankhwei536@gmail.com> | 2016-01-31 19:53:45 -0500 |
| commit | 0730fc3924dd4e04efbe51287d1d69850404d05f (patch) | |
| tree | 495d79d0dc26e39c9065c6ceb7d16b9a3e76561d /src/client.c | |
| parent | 8405274a91e3652ee98a423608a8496ead1edc05 (diff) | |
| download | netcosm-0.5.0-rc1.zip netcosm-0.5.0-rc1.tar.gz netcosm-0.5.0-rc1.tar.bz2 netcosm-0.5.0-rc1.tar.xz | |
bump version to 0.5.0-rc10.5.0-rc1
* implements objects using reference counts rather than copying
* implements both room-local and global verbs
* refactors the world_* functions into a separate module
* numerous other changes
Diffstat (limited to 'src/client.c')
| -rw-r--r-- | src/client.c | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/src/client.c b/src/client.c index e67cfb6..1de6818 100644 --- a/src/client.c +++ b/src/client.c @@ -171,7 +171,7 @@ void send_master(unsigned char cmd, const void *data, size_t sz) free(req); } -#define BUFSZ 128 +#define CLIENT_READ_SZ 128 char *client_read(void) { @@ -179,11 +179,9 @@ char *client_read(void) size_t bufidx; tryagain: - buf = malloc(BUFSZ); + buf = calloc(1, CLIENT_READ_SZ); bufidx = 0; - memset(buf, 0, BUFSZ); - /* set of the client fd and the pipe from our parent */ struct pollfd fds[2]; @@ -209,11 +207,11 @@ tryagain: } else if(fds[i].fd == client_fd) { - ssize_t len = read(client_fd, buf + bufidx, BUFSZ - bufidx - 1); + ssize_t len = read(client_fd, buf + bufidx, CLIENT_READ_SZ - bufidx - 1); if(len <= 0) error("lost connection (%d)", fds[i].revents); - buf[BUFSZ - 1] = '\0'; + buf[CLIENT_READ_SZ - 1] = '\0'; enum telnet_status ret = telnet_parse_data((unsigned char*)buf + bufidx, len); @@ -298,7 +296,7 @@ bool poll_requests(void) reqdata_type = TYPE_BOOLEAN; returned_reqdata.boolean = status; if(!status) - out("Cannot go that way.\n"); + out("You cannot go that way.\n"); break; } case REQ_GETUSERDATA: @@ -529,17 +527,20 @@ auth: else client_change_state(STATE_LOGGEDIN); - /* authenticated */ + /* authenticated, begin main command loop */ debugf("client: Authenticated as %s\n", current_user); client_change_user(current_user); current_room = 0; + client_change_room(current_room); + client_look(); + while(1) { out(">> "); char *cmd = client_read(); - + char *orig = strdup(cmd); char *save = NULL; char *tok = strtok_r(cmd, WSPACE, &save); @@ -754,10 +755,17 @@ auth: char *what = strtok_r(NULL, " ", &save); client_drop(what); } + else + { + /* we can't handle it, send it to the master */ + + send_master(REQ_EXECVERB, orig, strlen(orig) + 1); + } next_cmd: free(cmd); + free(orig); } done: |