-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfs.c
112 lines (98 loc) · 1.89 KB
/
fs.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#include <u.h>
#include <libc.h>
#include <fcall.h>
#include <thread.h>
#include <9p.h>
#include "gen3dat.h"
#include "colodat.h"
#include "pse.h"
Gen3 gen3;
enum { Qtrainer, Qpokemon };
typedef struct Xfile Xfile;
struct Xfile {
int type;
union {
Pokemon *p;
Invent *i;
Trainer *tr;
};
};
static void
fsread(Req *r)
{
Xfile *f;
char buf[8192];
uchar str[64];
Pokedat pd;
char *p, *e;
f = r->fid->file->aux;
p = buf;
e = buf + sizeof buf;
switch(f->type){
case Qtrainer:
gen3pkstr(str, f->tr->name, sizeof f->tr->name);
seprint(p, e, "%s\t%d\t%d\n", (char*)str, f->tr->id, f->tr->secretid);
break;
case Qpokemon:
decryptpokemon(&pd, f->p);
gen3pkstr(str, f->p->name, sizeof f->p->name);
seprint(p, e, "%s\t%d\n", (char*)str, pd.g.species);
break;
}
readstr(r, buf);
respond(r, nil);
}
Srv fs = {
.read = fsread,
};
static void
usage(void)
{
fprint(2, "usage: %s [-s srv] [-m mtpt] file.sav\n", argv0);
exits("usage");
}
void
main(int argc, char **argv)
{
int fd;
int j;
Xfile *xf;
File *box;
char *user;
char *mtpt, *srvname;
srvname = nil;
mtpt = "/mnt/pse";
ARGBEGIN{
case 's':
srvname = EARGF(usage());
break;
case 'm':
mtpt = EARGF(usage());
break;
default:
usage();
}ARGEND;
if(argc < 1)
usage();
fd = open(argv[0], OREAD);
if(fd < 0)
sysfatal("open: %r");
getgen3(fd, &gen3);
user = getenv("user");
fs.tree = alloctree(user, "sys", DMDIR|0555, nil);
box = createfile(fs.tree->root, "box", user, DMDIR|0555, nil);
xf = mallocz(sizeof *xf, 1);
xf->type = Qtrainer;
xf->tr = &gen3.tr;
createfile(fs.tree->root, "trainer", user, 0444, xf);
for(j = 0; j < 420; j++){
if(gen3.pc.box[j].personality == 0 && gen3.pc.box[j].otid == 0)
continue;
xf = mallocz(sizeof *xf, 1);
xf->type = Qpokemon;
xf->p = &gen3.pc.box[j];
createfile(box, smprint("%d", j), user, 0444, xf);
}
postmountsrv(&fs, srvname, mtpt, MREPL);
exits(nil);
}