all repos — xrxs @ 150b8ae5290a9afbb818426705bc909d8b02e75d

experimental networked application/game server with 9p

finished adding random/scope functions, universe isn't writing...
Iris Lightshard nilix@nilfm.cc
PGP Signature
-----BEGIN PGP SIGNATURE-----

iQIzBAABCAAdFiEEkFh6dA+k/6CXFXU4O3+8IhROY5gFAmD6YTsACgkQO3+8IhRO
Y5j89RAAiHGGLPJYWBWGDfp/xQQG8T5AcO3HO8cKVRJ1G01+GeGpZmVb5Mhc3R3B
OVZr+iphLXovILEE0c9QbCOiOGexx4bRg+ccirTtUJnIvnU8IzzCM+EbPYty6iTS
SpgT/dDfDmAGL0MCKHv83uIZw+k7nSsosC5px8A0aRDz6omy+4H4XO2fnYP2vDZh
mZ/5AoPWXbC/iC73SYINEqhdwyZMw5+RPNQJx1ewE4o/ZiUCNgi+o5+nTRuxN8D5
8UyOsAcnOkWZnPaEpcgFpaz5LB+VXJMjQfy9CPICqTOBmKbavh16Pme1sSB3+iMK
wLjIgCYvWexUbAq7/zJwX/tmtUnAXA52RAbFAAuabiDhdPHBjP7F4FfvXUFyigZP
/LbA7jBQQbJrtgVCIEnaE2DmIxI546w9gFYniA8O0XLqH51fuq3tyyP7Why0ADMb
a/9ghfcaG7D7L2uwRd7Z9uN++M1nODd9LHPbDypyRhmPTW23McrTpUbsV57qZb7F
lPyuu5hX9cPw49nl5uWimmMOPKTDBcHMx4KUYzbvOdo9Wj8JWBgMGDqg33fRg7QC
hxbaDKu+YGTAMyvSrdICG8O60Ts+roT+qB72VQ4+KkB/8z7dHjHeqx7fgBFYRkBa
Dh9oJBNlOuOSuYwhytNgkQXpgbJ9LSg8fvtNptQqRcqW2VAO4ls=
=U8e/
-----END PGP SIGNATURE-----
commit

150b8ae5290a9afbb818426705bc909d8b02e75d

parent

940791631c398464e63264313f5872851d88b974

5 files changed, 133 insertions(+), 9 deletions(-)

jump to
M err.herr.h

@@ -1,2 +1,3 @@

#define EUNAME "username is already taken" -#define EUFULL "users table is full"+#define EUFULL "users table is full" +#define ENOUNI "universe is null"
M realm.crealm.c

@@ -114,7 +114,7 @@

scat(file, "/realm"); f = fopen(file, "w"); if (f != nil) { - fprintf(f, "%hu %s, %llu", self->max, self->master, self->password); + fprintf(f, "%hu %s %llu", self->max, self->master, self->password); fclose(f); save_universe(cart, self->universe, self->name); fprintf(stderr, "saved realm data");
M universe.cuniverse.c

@@ -76,11 +76,18 @@

void set_atom(Universe* self, Atom* atom) { uvlong i = hash(atom->name, 256); Atom* a = self->atoms[i]; + Atom* last; + + if (a == nil) { + self->atoms[i] = atom; + return; + } + while (a != nil) { + last = a; a = a->next; } - a = atom; - atom->next = nil; + last->next = atom; } Atom* get_atom(Universe* self, char* name) {
M user.cuser.c

@@ -121,7 +121,7 @@ } else {

r = parse_realm(u->cart->name, realm_name); if (r == nil) return 0; - if (j <= r->max) + if (j >= r->max) return 0; u->realm = r; return 1;
M xrxs.cxrxs.c

@@ -124,6 +124,7 @@ for (i = 0; i < 15 && i < r->ifcall.count && *c != ' ' && *c != '\n'; i++) {

ccat(key, *c++); } c++; + c++; for (i = 0; i < 63 && i < r->ifcall.count && *c != ' ' && *c != '\n'; i++) { ccat(value, *c++); }

@@ -145,6 +146,27 @@ r->fid->file->dir.length = r->ifcall.count;

respond(r, nil); } +void write_scope(Req* r) { + String* scope = s_new(); + char* c = r->ifcall.data; + UserInfo* u = find_user(users_table, r->fid->uid); + int i; + + for (i = 0; i < r->ifcall.count; i++) { + s_putc(scope, *c++); + } + s_terminate(scope); + + if (u != nil && u->realm != nil && u->realm->universe != nil) { + u->scope = malloc(r->ifcall.count); + memcpy(u->scope, scope->base, r->ifcall.count); + } + s_free(scope); + r->ofcall.count = r->ifcall.count; + r->fid->file->dir.length = r->ifcall.count; + respond(r, nil); +} + void xrxs_write(Req* r) { Aux* a = r->fid->file->aux; switch (a->type) {

@@ -155,7 +177,7 @@ case UNIVERSE:

write_universe(r); break; case SCOPE: - // write_scope(r); + write_scope(r); default: respond(r, nil); break;

@@ -345,6 +367,11 @@ return;

} universe = u->realm->universe; + if (universe == nil) { + respond(r, ENOUNI); + return; + } + for (i = 0; i < 256; i++) { a = universe->atoms[i]; while (a != nil) {

@@ -361,6 +388,95 @@ respond(r, nil);

s_free(data); } +void read_scope(Req* r) { + char* uname = r->fid->uid; + UserInfo* u = find_user(users_table, uname); + String* data = s_new(); + Universe* universe; + Atom* a; + char key[16] = {0}; + char* c = u->scope; + + if (u == nil || u->scope == nil || u->realm == nil) { + respond(r, nil); + return; + } + + universe = u->realm->universe; + if (universe == nil) { + respond(r, ENOUNI); + return; + } + + while (*c) { + while (*c != '\n') { + ccat(key, *c++); + } + a = get_atom(universe, key); + if (a != nil) { + s_append(data, a->value); + s_putc(data, '\n'); + } + *key = '\0'; + c++; + } + + s_terminate(data); + readstr(r, data->base); + respond(r, nil); + s_free(data); +} + +void read_random(Req* r) { + char buf[8] = {0}; + srand(rand()); + sprintf(buf, "%d\n", rand() % 100); + readstr(r, buf); +} + +void read_grandom(Req* r) { + char buf[8] = {0}; + int i; + int reset = 0; + int random; + UserInfo* u = find_user(users_table, r->fid->uid); + UserInfo** usrs = malloc(64 * sizeof(UserInfo*)); + UserInfo* p = users_table; + UserInfo** uu = usrs; + + if (u->realm == nil) + return; + + for (i = 0; i < 64; i++) { + if (scmp(p->realm->name, u->realm->name)) { + *uu++ = p; + if (i < 64) + *uu = nil; + } + } + uu = usrs; + for (i = 0; i < 64; i++) { + if ((*uu) != nil && (*uu)->random >= 0) { + reset = 1; + break; + } + } + if (reset) { + srand(rand()); + random = rand() % 100; + uu = usrs; + for (i = 0; i < 64; i++) { + if ((*uu) != nil) { + (*uu)->random = random; + } + uu++; + } + } + sprintf(buf, "%d\n", u->random); + u->random = -1; + readstr(r, buf); +} + void xrxs_read(Req* r) { Aux* a = r->fid->file->aux; switch (a->type) {

@@ -385,13 +501,13 @@ case UNIVERSE:

read_universe(r); break; case SCOPE: - // read_scope(r); + read_scope(r); break; case RANDOM: - // read_random(r); + read_random(r); break; case GRANDOM: - // read_grandom(r); + read_grandom(r); break; default: respond(r, nil);