all repos — xrxs @ 41c96c5127be0196e9f4b29f8fb723d8e06a643d

experimental networked application/game server with 9p

fix errors reading and writing universe
Iris Lightshard nilix@nilfm.cc
PGP Signature
-----BEGIN PGP SIGNATURE-----

iQIzBAABCAAdFiEEkFh6dA+k/6CXFXU4O3+8IhROY5gFAmEA8BgACgkQO3+8IhRO
Y5htDw/8CcpiM6IhveeqaGqb7iLJOG11E9XxsAA5v9m5kWxXDX3L6X2a7PaITV+K
/o8drVFHEocTWUCl7CPCGusbZWj515khZJ2hSklE04dvWAd/m7llsy7jdE3d8DrZ
K/nh2lfYQE5HiP5YdwSOP8jZ44J421zKq6oVWnqqHB8vNwPw4EWj1Wua2Akbp1Ic
VsN8FTnCDrw0bX9i5LEC8xK9YPIMNvVSU/dBu/XcuqotvXnJOX5dzaRJZgSTsBwr
1zOOlQtbm0AEWxM4fDccun0Dm5vpI+VlEClMk4FAB0n8szpjxZYQ5EKBr0/LzJd1
agnyNuvZGKQPuOa4HZdQz48EVDhil5fOqMMCckCr1ECRCyTevpHIirnlCNp0zyoc
O0+zs3k1jDlA2ehglqbx+Am4ykxZGfJFCpY4lMfOghleM/kmEYJSdqBkdmssSHUt
ObJjdOchCEndvEbZBVCTJ2xoj5IJChUUzi8h0ts9vfibgqHTZbTiDZ/r8TSnO1nx
Xs9+cdc/Igt8EHA6dPeygrDKCoePiO1VX0u7DFRg9vYbCbWPdBCtcyltAS3VPOSQ
UlnNy8OWSxyF+K/agAQKugkUGCO46k7edTGfNiMwLBstrqf83m2PCk+S/svGIgAK
xopWlRix3d0LzvnU/i79Nwx5oxhV32Jv2AD/9hWEAE4St9xUVaQ=
=YYXH
-----END PGP SIGNATURE-----
commit

41c96c5127be0196e9f4b29f8fb723d8e06a643d

parent

150b8ae5290a9afbb818426705bc909d8b02e75d

4 files changed, 29 insertions(+), 21 deletions(-)

jump to
M realm.crealm.c

@@ -55,9 +55,9 @@

Realm* parse_realm(char* cart, char* name) { Realm* self; FILE* f; - char path[128]; - char file[128]; - char buf[256]; + char path[128] = {0}; + char file[128] = {0}; + char buf[256] = {0}; scat(path, "carts/"); scat(path, cart); scat(path, "/realms/");

@@ -65,6 +65,8 @@ scat(path, name);

scpy(path, file, 128); scat(file, "/realm"); + + fprintf(stderr, "realm path: %s\n", file); f = fopen(file, "r"); if (f != nil) { if (fgets(buf, 256, f)) {

@@ -85,7 +87,7 @@ }

scpy(path, file, 128); scat(file, "/universe"); - self->universe = parse_universe(path); + self->universe = parse_universe(cart, name); return self; }
M universe.cuniverse.c

@@ -13,7 +13,7 @@ }

return self; } -Universe* parse_universe(char* realm_name) { +Universe* parse_universe(char* cart, char* realm_name) { char path[64] = {0}; char buf[256] = {0}; char name[16] = {0};

@@ -22,9 +22,12 @@ FILE* f;

Atom* a; Universe* self; - scat(path, "realms/"); + scat(path, "carts/"); + scat(path, cart); + scat(path, "/realms/"); scat(path, realm_name); scat(path, "/universe"); + fprintf(stderr, "universe path: %s\n", path); f = fopen(path, "r"); if (f != nil) {
M universe.huniverse.h

@@ -13,7 +13,7 @@ Atom* atoms[256];

} Universe; Universe* create_universe(); -Universe* parse_universe(char* realm_name); +Universe* parse_universe(char* cart, char* realm_name); void save_universe(char* cart, Universe* self, char* realm_name); void set_atom(Universe* self, Atom* atom); Atom* get_atom(Universe* self, char* name);
M xrxs.cxrxs.c

@@ -116,19 +116,23 @@ void write_universe(Req* r) {

char key[16] = {0}; char value[64] = {0}; char* c = r->ifcall.data; + char buffer[1024] = {0}; UserInfo* u = find_user(users_table, r->fid->uid); Atom* a; int i; - 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++); - } + scpy(r->ifcall.data, buffer, r->ifcall.count); + sscanf(buffer, "%15s = %63s", key, value); + /* 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++); + } + */ if (u != nil && u->realm != nil && u->realm->universe != nil) { a = get_atom(u->realm->universe, key); if (a != nil) {

@@ -217,7 +221,7 @@ int i = 0;

char* c; if ((dir = opendir(path)) != NULL) { while ((ent = readdir(dir)) != NULL) { - if (i = size) { + if (i == size) { size *= 2; self = realloc(self, size * sizeof(String*)); }

@@ -239,12 +243,9 @@ return self;

} void s_freemany(String** ss) { - int i; String** s = ss; - for (i = 0; i < 128; i++) { - if (*s != nil) { - s_free(*s); - } + while (*s != nil) { + s_free(*s++); } free(ss); }

@@ -362,12 +363,14 @@ Atom* a;

int i; if (u == nil || u->realm == nil) { + fprintf(stderr, "realm nil, wtf\n"); respond(r, nil); return; } universe = u->realm->universe; if (universe == nil) { + fprintf(stderr, "no universe, oh noes!!\n"); respond(r, ENOUNI); return; }