add skeleton functions for write_ctl with documentation, tweak users table

This commit is contained in:
Iris Lightshard 2021-07-02 22:32:10 -06:00
parent edc0e119bc
commit 0cc1835a02
Signed by: Iris Lightshard
GPG key ID: 3B7FBC22144E6398
2 changed files with 87 additions and 10 deletions

View file

@ -25,7 +25,7 @@ This is the working structure of the 9p filesystem:
* `/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).

95
xrxs.c
View file

@ -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 @@ void xrxs_attach(Req* r) {
* 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 @@ void xrxs_attach(Req* r) {
}
if (*usr == 0) {
scpy(username, usr, l + 1);
users_table[i].id = id++;
break;
}
}
@ -129,14 +128,92 @@ int logout(char* 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 @@ void write_ctl(Req* r) {
// load(c);
break;
case CREATE:
// create(c);
// rcreate(c);
break;
case PROTECT:
// protect(c);
@ -164,19 +241,19 @@ void write_ctl(Req* r) {
// 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;