From ca2e5b8e133a144cae0534f7e3f413376edcb55f Mon Sep 17 00:00:00 2001 From: Derek Stevens Date: Sun, 17 Oct 2021 17:41:18 -0600 Subject: [PATCH] v0.1; add -v flag to print version info and /version file for client to know the version as well --- README.md | 4 +++- server/aux.h | 3 ++- server/xrxs.c | 17 +++++++++++++++++ 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 6685458..1663da1 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ The client is a specialized [uxn](https://wiki.xxiivv.com/site/uxn.html) ROM tha This is the working structure of the 9p filesystem: -* `/ctl`: Read/write control file for inputing system commands. Reading the file shows the status of the last input command: 1 for success, 0 for failure; `logout` is a special case, and the status code will be -1 if it was succesful. the following are valid command syntax: + * `/ctl`: Read/write control file for inputing system commands. Reading the file shows the status of the last input command: 1 for success, 0 for failure; `logout` is a special case, and the status code will be -1 if it was succesful. the following are valid command syntax: * `login PW`: Authenticate with `xrxs` -- password is hashed against realm password hash. * `logout`: Gracefully remove yourself from the users table. * `load CART`: Load a cartridge. @@ -39,6 +39,8 @@ This is the working structure of the 9p filesystem: * `/grandom`: Read-only, get a random number from 0 to 99 -- These are doled out on a per-realm basis, and the number stays the same until everyone in the realm has had a chance to read it. If you've already read it this round or aren't in a realm, it will be empty. +* `/version`: Read-only, outputs the version of the `xrxs` server. + ### realm format Each realm directory on the server should have the following files: diff --git a/server/aux.h b/server/aux.h index ddf49e9..539fdf5 100644 --- a/server/aux.h +++ b/server/aux.h @@ -11,6 +11,7 @@ typedef enum { SCOPE, RANDOM, GRANDOM, + VERSION } FileType; typedef struct Aux { @@ -19,4 +20,4 @@ typedef struct Aux { int count; } Aux; -Aux* create_aux(FileType t); \ No newline at end of file +Aux* create_aux(FileType t); diff --git a/server/xrxs.c b/server/xrxs.c index 0f84c5e..b5b9da3 100644 --- a/server/xrxs.c +++ b/server/xrxs.c @@ -17,6 +17,8 @@ #include "realm.h" #include "user.h" +char version[] = "0.1"; + int chatty9p = 0; static Tree* tree; @@ -524,6 +526,13 @@ void read_grandom(Req* r) { respond(r, nil); } +void read_version(Req* r) { + char buf[16]; + sprintf(buf, "%s\n", version); + readstr(r, buf); + respond(r, nil); +} + void xrxs_read(Req* r) { Aux* a = r->fid->file->aux; switch (a->type) { @@ -559,6 +568,9 @@ void xrxs_read(Req* r) { case GRANDOM: read_grandom(r); break; + case VERSION: + read_version(r); + break; default: respond(r, nil); break; @@ -610,12 +622,17 @@ void threadmain(int argc, char* argv[]) { if (scmp(argv[i], "-d")) { chatty9p = 1; } + if (scmp(argv[i], "-v")) { + printf("xrxs v%s\n", version); + threadexits(0); + } } fs.foreground = 1; fs.tree = alloctree(nil, nil, DMDIR | 0777, fs_destroy_file); tree = fs.tree; + closefile(createfile(tree->root, "version", nil, 0400, create_aux(VERSION))); closefile( createfile(tree->root, "ctl", nil, DMAPPEND | 0600, create_aux(CTL))); closefile(createfile(tree->root, "carts", nil, 0400, create_aux(CARTS)));