-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMODMAIN.C
344 lines (301 loc) · 10.2 KB
/
MODMAIN.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
/*
BHZ Skeleton Module main source
Mark Seelye (bhz) (c)2023
burninghorizon.com, bhz.co
Simple module source that can be used as boilerplate for a new module.
Has some simple examples user input handling, msg reading, and database access.
*/
#include "gcomm.h"
#include "majorbbs.h"
#include "moddefs.h"
static int bhz_sttrou(void);
static void bhz_finrou(void);
static int bhz_stub_lonrou(void);
static void bhz_stub_stsrou(void);
static int bhz_stub_injrou(void);
static int bhz_stub_lofrou(void);
static void bhz_stub_huprou(void);
static void bhz_stub_mcurou(void);
static void bhz_stub_dlarou(void);
/*
Module Structure Block
See: Page 30, "The Major BBS Developer's Guide"
*/
struct module ptrmodule = { /* module interface block */
"", /* name used to refer to this module */
bhz_stub_lonrou, /* user logon supplemental routine */
bhz_sttrou, /* input routine if selected */
bhz_stub_stsrou, /* status-input routine if selected (dfsthn) */
bhz_stub_injrou, /* Reprompting routine for this module */
bhz_stub_lofrou, /* user logoff supplemental routine */
bhz_stub_huprou, /* hangup (lost carrier) routine */
bhz_stub_mcurou, /* midnight cleanup routine */
bhz_stub_dlarou, /* delete-account routine */
bhz_finrou /* finish-up (sys shutdown) routine */
};
int statecode;
FILE *mbkptr = NULL;
BTVFILE *bbptr = NULL;
/*
Module Initialization Routine
See: Page 29, "The Major BBS Developer's Guide"
"The Major BBS Developer's Guide"
stzcpy: Page 175 - Copy a string with limit and null termination
register_module: Page 30 - Register a module structure, returns state code
opnmsg: Page 65 - Open a new MCV file, returns pointer
opnbtv: Page 150 - Open a btrieve database file for I/O, returns pointer
setmbk: Page 66 - Set current MCV file block pointer
shocst: Page 148 - Log message to Audit Trail, summary (<= 32 chars), details (<= 65 chars)
rstmbk: Page 66 - Restore to previous MCV from before last setmbk() call
*/
// handles init__[DEVID][MODID] see moddefs.h
void init(void) {
stzcpy(ptrmodule.descrp, gmdnam(MODMDF), MNMSIZ);
statecode = register_module(&ptrmodule);
mbkptr = opnmsg(MODMCV);
bbptr = opnbtv(MODDAT, sizeof(BHZ_DBRECORD));
setmbk(mbkptr);
shocst(spr("%s %s %s", MODNAM, MODVER, getmsg(STARTING)),
spr("%s %s %s", ptrmodule.descrp, MODVER, getmsg(STARTING)));
rstmbk();
}
/*
Insert a record into the database.
Add in current userid too
"The Major BBS Developer's Guide"
stzcpy: Page 175 - Copy a string with limit and null termination
prfmsg: Pages 65,69 - Works like printf/prf, control string from current MCV file
ncdate/nctime: Page 178 - Encode date/time into: "MM/DD/YY" / "HH:MM:SS"
dinsbtv: Page 152 - Failure tolerant insert routine, returns l=inserted O=duplicate collision
*/
static void insert_rec(BHZ_DBRECORD *rec) {
stzcpy(rec->userid, usaptr->userid, UIDSIZ);
prfmsg(INSREC,
ncdate(rec->date), rec->date,
nctime(rec->time), rec->time,
rec->userid,
rec->data1,
rec->data2);
if (!dinsbtv(rec)) {
prfmsg(INSFAIL);
}
}
/*
Create a new record for the database.
Use date and time as key (see BCR)
Set data1 to default, or to word after option "2" input.
Set data2 to default, or to everything after data1.
Example user input:
2 1234567890 Hey there, how are you doing?
Would insert:
data1:1234567
data2:Hey there, how are you do
As data1 is max DATA1SIZE, data2 is max DATA2SIZE (with \0s on each)
"The Major BBS Developer's Guide"
today/now: Page 178 - Find out today's date / current time as long int.
stzcpy: Page 175 - Copy a string with limit and null termination
rstrin: Page 74 - Restore parsed input line (undo effects of parsin)
*/
static void insert_new() {
BHZ_DBRECORD rec;
memset(&rec, 0, sizeof(rec));
rec.date = today();
rec.time = now();
if (margc > 1) {
stzcpy(rec.data1, margv[1], DATA1SIZE);
} else {
stzcpy(rec.data1, getmsg(DEFDATA1), DATA1SIZE);
}
if (margc > 2) {
// This will copy margv[2...] after rstrin() is called, up to DATA2SIZE
rstrin();
stzcpy(rec.data2, margv[2], DATA2SIZE);
} else {
stzcpy(rec.data2, getmsg(DEFDATA2), DATA2SIZE);
}
insert_rec(&rec);
}
/*
Print out a passed db record with index
Converts date and time from ints back to strings
"The Major BBS Developer's Guide"
prfmsg: Pages 65,69 - Works like printf/prf, control string from current MCV file
ncdate/nctime: Page 178 - Encode date/time into: "MM/DD/YY" / "HH:MM:SS"
*/
static void out_next_rec(int recn, BHZ_DBRECORD *rec) {
prfmsg(OUTREC, recn,
rec->date, ncdate(rec->date),
rec->time, nctime(rec->time),
rec->userid,
rec->data1, rec->data2);
}
/*
Loop through the database dumping all records.
Displays DB empty message if no records.
"The Major BBS Developer's Guide"
prfmsg: Pages 65,69 - Works like printf/prf, control string from current MCV file
*/
static void out_records() {
BHZ_DBRECORD rec;
int recn = 1;
if(slobtv((char*)&rec)) {
do {
out_next_rec(recn++, &rec);
} while (snxbtv((char*)&rec));
} else {
prfmsg(DBEMPTY);
}
}
/*
Input routine.
Very simple, handles user selecting 1, 2, 3, or X.
Allows for extra input when selecting option 2.
See: Page 69, "The Major BBS Developer's Guide"
Handle options 1, 2, 3, and X
Otherwise echoes input.
"The Major BBS Developer's Guide"
setmbk: Page 66 - Set current MCV file block pointer
rstmbk: Page 66 - Restore to previous MCV from before last setmbk call
setbtv: Page 150 - Set BTVFILE ptr for subsequent ops
rstbtv: Page 150 - Restore to previous BTVFILE from before last setbtv call
prfmsg/prf: Pages 65,69 - Works like printf/prf, control string from current MCV file
outprf: Pages 65,69 - Send prfbuf to a channel & clear user number
sameas: Page 174 - Case-ignoring string match
rstrin: Page 74 - Restore parsed input line (undo effects of parsin)
stzcpy: Page 175 - Copy a string with limit and null termination
*/
static int bhz_sttrou(void) {
int rc = 1;
setmbk(mbkptr);
setbtv(bbptr);
if (usrptr->substt == 0) {
prfmsg(MENU);
usrptr->substt = 1;
rc = 1;
} else {
if (margc > 0) {
if (sameas(margv[0], "1")) {
prf("%s %s\n", MODNAM, MODVER);
prfmsg(OPT1);
} else if (sameas(margv[0], "2")) {
prfmsg(OPT2);
insert_new();
} else if (sameas(margv[0], "3")) {
prfmsg(OPT3);
out_records();
} else if (sameas(margv[0], "x")) {
rc = 0; // 0 tells mbbs to exit module
} else {
prfmsg(OUTPUT);
// Set prf buffer to original input value
rstrin();
stzcpy(prfptr, input, inplen + 1);
prfptr += inplen;
}
} else {
prfmsg(MENU);
}
}
prfmsg(SHMENU); // Show the "Selection" message
rstmbk();
rstbtv();
outprf(usrnum);
return rc;
}
/*
System shutdown routine.
Close out msg file and database.
See: Page 38, "The Major BBS Developer's Guide"
"The Major BBS Developer's Guide"
spr: Page 175 - sprintf-like string formatter utility
clsmsg: Page 67 - Close an MCV file
clsbtv: Page 153 - Close a Btrieve file when finished
*/
static void bhz_finrou(void) {
shocst(MODNAM, spr("%s %s session ending.", ptrmodule.descrp, MODVER));
if (mbkptr != NULL) {
clsmsg(mbkptr);
mbkptr = NULL;
}
if (bbptr != NULL) {
clsbtv(bbptr);
bbptr = NULL;
}
}
/*
Module hook stub routines
These are all stub routines, they show up in the audit.
They are here to serve as boilerplate for a module.
stub_called is just a convenience function they all use
here to output to the audit.
"The Major BBS Developer's Guide"
shocst: Page 148 - Log message to Audit Trail, summary (<= 32 chars), details (<= 65 chars)
spr: Page 175 - sprintf-like string formatter utility
cncall: Page 77 - expect a variable-length word sequence (consume all remaining input)
*/
static void stub_called(char *rtnnam) {
static char stub_msg[] = STUB;
shocst(spr("%s %srou %s", MODNAM, rtnnam, stub_msg),
spr("%s %srou %s", ptrmodule.descrp, rtnnam, stub_msg));
}
/*
lonrou - Log on input service routine.
See: Page 38, "The Major BBS Developer's Guide"
*/
static int bhz_stub_lonrou(void) {
stub_called("lon");
cncall();
return 0;
}
/*
stsrou - Status handler routine.
dfsthn - Default status handler.
See: Page 35, "The Major BBS Developer's Guide"
*/
static void bhz_stub_stsrou(void) {
stub_called("sts");
dfsthn();
}
/*
injrou - Reprompting routine.
See: Page 35, "The Major BBS Developer's Guide"
*/
static int bhz_stub_injrou(void) {
stub_called("inj");
cncall();
return 0;
}
/*
lofrou - Log off input service routine.
See: Page 38, "The Major BBS Developer's Guide"
*/
static int bhz_stub_lofrou(void) {
stub_called("lof");
cncall();
return 0;
}
/*
huprou - User disconnect (hang-up) routine.
See: Page 38, "The Major BBS Developer's Guide"
*/
static void bhz_stub_huprou(void) {
stub_called("hup");
cncall();
}
/*
mcurou - Auto-cleanup routine.
See: Page 38, "The Major BBS Developer's Guide"
*/
static void bhz_stub_mcurou(void) {
stub_called("mcu");
cncall();
}
/*
dlarou - Delete user account routine.
See: Page 38, "The Major BBS Developer's Guide"
*/
static void bhz_stub_dlarou(void) {
stub_called("dla");
cncall();
}