all repos — xrxs @ 0cc1835a02348eb0fd89e59cdc663d90a0fb0fbf

experimental networked application/game server with 9p

add skeleton functions for write_ctl with documentation, tweak users table
Iris Lightshard nilix@nilfm.cc
PGP Signature
-----BEGIN PGP SIGNATURE-----

iQIzBAABCAAdFiEEkFh6dA+k/6CXFXU4O3+8IhROY5gFAmDf6EoACgkQO3+8IhRO
Y5gY4Q/+KJ5elAFnSum74BK+EpKzr9rzVGrewKlD17a+30zyZSjCLjwxU5tCiLmJ
RdUaefzg6b9dJgtAgwTKCkZfD+QhCBQxsV5GYbVNfOchozafrUzH3qfLoV9oijSj
3NBcLq/ozLy/Kyg1RlP1ByKMPnWN+7nDQYiD9nRbF6sSYuJpv3SX3SGH690BI7uS
Om5w82DVIW+LJsyNPMVjvM5WV7XUqWqaGAfJEYixj3GhtlJxn/MlShnLz68PYEql
U3yiQPlX8NuSUsLHQBirF3x1tKe7ziO4cQSj2AFCmss4GaTyr8dik6F+AXjWCWy9
gThnNrDSKFI+aUc3225FsZCf5j51QcVLDihEkT1v5D1w1W2zE9SYIW279k/cGTod
ZaysZLFGP/NcyCjRgL1bQp9M0gGmCvkOkiGZXp/VAG36s3cT+5XCYftWiM+KOK0u
uR4cBsK3w/gx4m8Vbjl7rZV2Fs/EedDOhPHy5GAk3YGOnjs2qCVri80ORTv3N9PV
DEqouQOPY4qb59dRwbTPoetXFYsNQtKTKfoW+2yFKmhIJZrfxibRrDduC409lgt3
fn+JI3SdxIbxG+5fqOQQijCTwlVKdImLpv2Hb0Yr34YUgDNCSIQ/xoTLtrW1x7+r
Auu7WaT916X3mNjr1nUMGn2trzj0G1Q+9ytz1hnWrk/L4Ohi8TA=
=/mj8
-----END PGP SIGNATURE-----
commit

0cc1835a02348eb0fd89e59cdc663d90a0fb0fbf

parent

edc0e119bc21c056bcc4ac62def9dda27274d7e8

2 files changed, 87 insertions(+), 10 deletions(-)

jump to
M README.mdREADME.md

@@ -25,7 +25,7 @@ * `/carts`: Available game/app cartridges for this server, read only; Carts are listed per line upon reading the file. It is backed by files on the server in a directory structure like `carts/<cart_name>/{<cart_name.rom>, data/}`.

* `/slot`: After loading the cartridge, its ROM is read from here; Read-only. -* `/data/`: Any supporting data that comes with the cartridge will be found here; read only +* `/data/`: Any supporting data that comes with the cartridge will be found here; to serve different files to different users, perhaps all resources of one filetype should be concatenated (ie, one file for all sprite data, one file for all text data, one file for all sound data) and let the client read whatever offset/length they need; read only * `/realms`: Open/saved realms, read-only. Realms and their associated universe are backed by real files on the server so that they can be preserved across service instantiations, in a directory structure like: `realms/<realm_name>/{realm, universe}`. Realms can either be solo, open, or protected; Open or protected realms can have limited member numbers. Depending on the cartridge, these settings can be user-managed or managed by the cartridge itself. Realms are listed per line upon reading the file like: `realmx 1 4 1`. `realmx` would be the name of the realm. The first number is number of members, second is member limit, third is 1 if protected, 0 if not. `0 1 1` represents a protected solo realm that is empty (saved game with password). `0 1 0` represents an unprotected solo realm that is empty (saved game with no password).
M xrxs.cxrxs.c

@@ -68,7 +68,8 @@ typedef struct UserInfo UserInfo;

struct UserInfo { char name[32]; uvlong password; - ushort id; + char realm[32]; + char cart[32]; }; static UserInfo users_table[64];

@@ -89,7 +90,6 @@ * until the server restarts. We have to figure out some way

* to detect a detach to remove them... You can't delay respond() * or the attach will never complete. */ - static ushort id = 1; int i = 0; int l = 0; char* usr;

@@ -107,7 +107,6 @@ return;

} if (*usr == 0) { scpy(username, usr, l + 1); - users_table[i].id = id++; break; } }

@@ -129,14 +128,92 @@ fprintf(stderr, uname);

for (i = 0; i < 64; i++) { if (scmp(uname, users_table[i].name)) { *(users_table[i].name) = 0; - users_table[i].id = 0; users_table[i].password = 0; + *(users_table[i].realm) = 0; return 1; } } return 0; } +int load(char* cart) { + /* 1. get file handle to cartridge file + * 2. make cartridge file available in CART.data for this user + * 3. add cartridge name to user's UserInfo + * 4. if cartridge data dir is not empty, walk it + * 5. for each file in data dir, create corresponding + * data file in DATA/ for this user, grab a file handle, and make + * the data available in DATA.data + */ + return 1; +} + +int rcreate(char* realm) { // create is taken in the libc header! + /* 1. split input by space -- if 2+ elements, second element + * is the max number of members (default 4) + * 2. check if realm exists; return 0 if it does + * 3. create real files in the realms directory and fill as + * appropriate + */ + return 1; +} + +int protect(char* password) { + /* 1. if current realm has a password already, return 0; + * 2. otherwise, hash the password and put it after the + * member limit in the realm file + */ + return 1; +} + +int enter(char* realm) { + /* 1. get password for realm; if none, skip to 3 + * 2. check password for current user against it; + * return 0 if different + * 3. if member limit already met, return 0 + * 4. otherwise, insert username in the realm + * and the realm name in the user's UserInfo + */ + return 1; +} + +int leave(char* uname) { + /* 1. if not in a realm, return 0; + * 2. else remove self from realm file + * and remove realm from user's UserInfo + */ + return 1; +} + +int save(char* uname) { + /* 1. flush this user's universe to the realm; + * maybe this is not needed + */ + return 1; +} + +int reset(char* uname) { + /* 1. save + * 2. leave + * 3. clear this user's password + * 4. the client should now be able to restart execution + * of the cartridge safely + */ + return 1; +} + +int unload(char* uname) { + /* 1. reset + * 2. clear cartridge data from CART->data for this user + * 3. destroy all files in DATA/ for this user + * 4. remove cartridge from UserInfo for thi user + * 5. the client should now be able to unload + * the cartridge from memory safely and restart + * the 'firmware' ROM execution + */ + return 1; +} + void write_ctl(Req* r) { char cmd[16] = {0}; char* c = r->ifcall.data;

@@ -155,7 +232,7 @@ case LOAD:

// load(c); break; case CREATE: - // create(c); + // rcreate(c); break; case PROTECT: // protect(c);

@@ -164,19 +241,19 @@ case ENTER:

// enter(c); break; case LEAVE: - // leave(c); + // leave(r->fid->uid); break; case LOGOUT: logout(r->fid->uid); break; case SAVE: - // save(); + // save(r->fid->uid); break; case RESET: - // reset(); + // reset(r->fid->uid); break; case UNLOAD: - // unload(); + // unload(r->fid->uid); break; } r->ofcall.count = r->ifcall.count;