/
log.cpp
414 lines (337 loc) · 8.72 KB
/
log.cpp
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
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
// --------------------------------------------------------------------------
// Citadel: Log.CPP
//
// Local log code
#include "ctdl.h"
#pragma hdrstop
#include "net.h"
#include "log.h"
#include "room.h"
// --------------------------------------------------------------------------
// Contents
//
// FindPersonByName() returns slot# of named person else CERROR
// storeLog() stores the current log record.
// normalizepw() This breaks down inits;pw into separate strings
LogTable LogTab; // RAM index of pippuls
#ifdef WINCIT
// these have to go somewhere...
HANDLE LTable::Mutex;
int LTable::UsageCounter;
LTable *LogTable::Table;
#endif
// --------------------------------------------------------------------------
// FindPersonByName(): Returns slot# of named person else CERROR.
#ifdef WINCIT
l_slot TermWindowC::FindPersonByName(const char *name)
{
return (::FindPersonByName(name, LogOrder));
}
#endif
l_slot FindPersonByName(const char *name, const l_slot *Order)
{
label alias;
CopyStringToBuffer(alias, name);
char *ptr = strchr(alias, '.');
if (ptr)
{
*ptr = 0; // tie off
}
// check to see if name is in log table
for (l_slot i = 0; i < cfg.MAXLOGTAB; i++)
{
l_slot S = Order ? Order[i] : i;
if (LogTab[S].IsInuse() &&
(
LogTab[S].IsSameName(name) || LogTab[S].IsSameAlias(alias)
)
)
{
return (i);
}
}
return (CERROR);
}
// --------------------------------------------------------------------------
// nodexists(): Returns slot# of named person else CERROR.
#ifdef WINCIT
l_slot TermWindowC::nodexists(const char *name)
{
return (::nodexists(name, LogOrder));
}
#endif
l_slot nodexists(const char *name, const l_slot *Order)
{
char alias[4];
char locID[5];
Bool addrsearch = FALSE;
if (isaddress(name))
{
parse_address(name, alias, locID, 0);
addrsearch = TRUE;
}
// check to see if name is in log table
for (l_slot i = 0; i < cfg.MAXLOGTAB; i++)
{
l_slot S = Order ? Order[i] : i;
if (LogTab[S].IsInuse() && LogTab[S].IsNode())
{
if (addrsearch)
{
if ( // same alias and...
LogTab[S].IsSameAlias(alias) &&
// either...
(
// not searching locIDs or...
!*locID ||
// it matches, too
LogTab[S].IsSameLocID(locID)
)
)
{
return (i);
}
}
else
{
if (LogTab[S].IsSameName(name))
{
return (i);
}
}
}
}
return (CERROR);
}
// --------------------------------------------------------------------------
// addressexists(): Returns slot# of named person else CERROR.
#ifdef WINCIT
l_slot TermWindowC::addressexists(const char *name)
{
return (::addressexists(name, LogOrder));
}
#endif
l_slot addressexists(const char *name, const l_slot *Order)
{
char alias[4];
char locID[5];
parse_address(name, alias, locID, 0);
// check to see if name is in log table
for (l_slot i = 0; i < cfg.MAXLOGTAB; i++)
{
l_slot S = Order ? Order[i] : i;
if (LogTab[S].IsInuse())
{
if (LogTab[S].IsSameAlias(alias) && LogTab[S].IsSameLocID(locID))
{
return (i);
}
}
}
return (CERROR);
}
// --------------------------------------------------------------------------
// FindPersonByPartialName(): Returns slot # of partial user name, else CERROR
#ifdef WINCIT
l_slot TermWindowC::FindPersonByPartialName(const char *name)
{
return (::FindPersonByPartialName(name, LogOrder));
}
#endif
l_slot FindPersonByPartialName(const char *name, const l_slot *Order)
{
label da_pn;
if (strlen(name) > LABELSIZE)
{
return (CERROR);
}
// Exact match
l_slot i = FindPersonByName(name, Order);
if (i != CERROR)
{
return (i);
}
strcpy(da_pn, deansi(name));
const int length = strlen(da_pn);
if (!length)
{
return (CERROR);
}
// Start of string match
for (i = 0; i < cfg.MAXLOGTAB; i++)
{
l_slot S = Order ? Order[i] : i;
if (LogTab[S].IsInuse())
{
label Buffer;
if (strnicmp(deansi(LogTab[S].GetName(Buffer, sizeof(Buffer))), da_pn, length) == SAMESTRING)
{
return (i);
}
}
}
// Partial match
for (i = 0; i < cfg.MAXLOGTAB; i++)
{
l_slot S = Order ? Order[i] : i;
if (LogTab[S].IsInuse())
{
label Buffer;
if (IsSubstr(LogTab[S].GetName(Buffer, sizeof(Buffer)), da_pn))
{
return (i);
}
}
}
return (CERROR);
}
// --------------------------------------------------------------------------
// normalizepw(): This breaks down inits;pw into separate strings.
void normalizepw(const char *InitPw, char *Initials, char *passWord)
{
const char *inpwptr = InitPw;
char *pwptr = passWord;
char *inptr = Initials;
while (*inpwptr && *inpwptr != ';')
{
*inptr++ = *inpwptr;
inpwptr++;
}
*inptr = 0; // tie off with a null
normalizeString(Initials);
if (*inpwptr == ';')
{
inpwptr++; // step over semicolon
while (*inpwptr != '\0')
{
*pwptr++ = *inpwptr;
inpwptr++;
}
*pwptr = 0; // tie off with a null
normalizeString(passWord);
}
else
{
*passWord = 0;
}
// don't allow anything over LABELSIZE characters
Initials[LABELSIZE] = 0;
passWord[LABELSIZE] = 0;
}
// --------------------------------------------------------------------------
// LogTab::Update(): Logbuf to logtable converter.
void LogTable::Update(l_slot TabSlot, const LogEntry1 *Log, l_index FileIndex)
{
assert(this);
assert(TabSlot >= 0);
assert(TabSlot < TableSize);
assert(IsValid());
if (IsValid())
{
Table[TabSlot].CopyFlags(*Log);
if (Log->IsInuse())
{
label Buffer;
Table[TabSlot].SetInitialsHash(Log->GetInitials(Buffer,
sizeof(Buffer)));
Table[TabSlot].SetPasswordHash(Log->GetPassword(Buffer,
sizeof(Buffer)));
Table[TabSlot].SetName(Log->GetName(Buffer, sizeof(Buffer)));
Table[TabSlot].SetAlias(Log->GetAlias(Buffer, sizeof(Buffer)));
Table[TabSlot].SetLocID(Log->GetLocID(Buffer, sizeof(Buffer)));
Table[TabSlot].SetCallNumber(Log->GetCallNumber());
}
else
{
Table[TabSlot].SetInitialsHash((short) 0);
Table[TabSlot].SetPasswordHash((short) 0);
Table[TabSlot].SetName(ns);
Table[TabSlot].SetAlias(ns);
Table[TabSlot].SetLocID(ns);
Table[TabSlot].SetCallNumber(0);
}
Table[TabSlot].SetLogIndex(FileIndex);
}
}
Bool TERMWINDOWMEMBER LoadPersonByName(const char *name)
{
const l_slot NewPerson = FindPersonByName(name);
if (NewPerson == CERROR)
{
return (FALSE);
}
else
{
ThisSlot = NewPerson;
ThisLog = LTab(NewPerson).GetLogIndex();
return (CurrentUser->Load(ThisLog));
}
}
#ifdef WINCIT
Bool LogEntry::LoadByName(const char *name, l_slot *LogOrder)
#else
Bool LogEntry::LoadByName(const char *name)
#endif
{
l_slot NewPerson;
#ifdef WINCIT
NewPerson = FindPersonByName(name, LogOrder);
#else
NewPerson = FindPersonByName(name);
#endif
if (NewPerson == CERROR)
{
return (FALSE);
}
else
{
return (Load(LTab(NewPerson).GetLogIndex()));
}
}
// --------------------------------------------------------------------------
// storeLog(): Stores the current log record.
void TERMWINDOWMEMBER storeLog(void)
{
if (loggedIn)
{
CurrentUser->Save(ThisLog, thisRoom);
}
}
// --------------------------------------------------------------------------
// LogEntry::CanModerateRoom(): Returns whether the user can moderate a room or not.
//
// Input: RoomIndex Room's index in the database that we want to know about.
//
// Output: return TRUE if the user can moderate it.
// FALSE if he cannot.
Bool LogEntry::CanModerateRoom(r_slot RoomIndex) const
{
assert(RoomIndex < cfg.maxrooms);
assert(RoomIndex >= 0);
assert(RoomTab[RoomIndex].IsInuse());
return
(
IsSysop() ||
(IsAide() && cfg.moderate) ||
(RoomTab[RoomIndex].IsGroupModerates() && HasRoomPrivileges(RoomIndex))
);
}
Bool LogEntry::CanKillMessage(Message *Msg, Bool IsLoggedIn) const
{
return (CanModerateRoom(Msg->GetOriginalRoom()) || (IsLoggedIn && IsSameName(Msg->GetAuthor()) && IsKillOwn()));
}
Bool LogEntry::ShowSystemEvent(SystemEventE Event)
{
switch (Event)
{
case SE_LOGONOFF: return (ShowSELogOnOff());
case SE_NEWMESSAGE: return (ShowSENewMessage());
case SE_EXCLUSIVEMESSAGE: return (ShowSEExclusiveMessage());
case SE_CHATALL: return (ShowSEChatAll());
case SE_CHATUSER: return (ShowSEChatUser());
case SE_CHATGROUP: return (ShowSEChatGroup());
case SE_CHATROOM: return (ShowSEChatRoom());
case SE_ROOMINOUT: return (ShowSERoomInOut());
}
return (TRUE);
}