{
char aaa[100];
char hold_rm[ROOMNAMELEN];
+ char actual_rm[ROOMNAMELEN];
+ char recipient[256];
long newmsgid;
char *message_in_memory;
struct stat statbuf;
size_t templen;
FILE *fp;
+ struct usersupp userbuf;
/* Measure the message */
lprintf(9, "Measuring the message\n");
free(message_in_memory);
if (newmsgid <= 0L) return;
+ strcpy(actual_rm, CC->quickroom.QRname);
strcpy(hold_rm, "");
+ strcpy(recipient, rec);
/* If the user is a twit, move to the twit room for posting... */
if (TWITDETECT) if (CC->usersupp.axlevel==2) {
- strcpy(hold_rm, CC->cs_room);
- strcpy(CC->cs_room, config.c_twitroom);
+ strcpy(hold_rm, actual_rm);
+ strcpy(actual_rm, config.c_twitroom);
+ }
+
+ /* ...or if this is a private message, go to the target mailbox. */
+ if (strlen(recipient) > 0) {
+ mailtype = alias(recipient);
+ if (mailtype == M_LOCAL) {
+ if (getuser(&userbuf, recipient)!=0) {
+ mtsflag = 1; /* User not found, goto Aide */
+ }
+ else {
+ strcpy(hold_rm, actual_rm);
+ MailboxName(actual_rm, &userbuf, MAILROOM);
+ }
+ }
}
/* ...or if this message is destined for Aide> then go there. */
if (mtsflag) {
- strcpy(hold_rm, CC->cs_room);
- strcpy(CC->cs_room, "Aide");
+ strcpy(hold_rm, actual_rm);
+ strcpy(actual_rm, AIDEROOM);
}
- /* ...or if this is a private message, go to the target mailbox. */
- /* FIX FIX FIX do this! */
/* This call to usergoto() changes rooms if necessary. It also
* causes the latest message list to be read into memory.
*/
lprintf(9, "Changing rooms if necessary...\n");
- usergoto(CC->cs_room, 0);
+ usergoto(actual_rm, 0);
/* read in the quickroom record, obtaining a lock... */
- lprintf(9, "Reading/locking <%s>...\n", CC->cs_room);
- lgetroom(&CC->quickroom, CC->cs_room);
+ lprintf(9, "Reading/locking <%s>...\n", actual_rm);
+ lgetroom(&CC->quickroom, actual_rm);
lprintf(9, "Fetching message list...\n");
get_msglist(&CC->quickroom);
- /* FIX here's where we have to to message expiry!! */
+ /* FIX here's where we have to handle message expiry!! */
/* Now add the new message */
CC->num_msgs = CC->num_msgs + 1;
CC->msglist = realloc(CC->msglist,
((CC->num_msgs) * sizeof(long)) );
if (CC->msglist == NULL) {
- lprintf(3, "ERROR can't realloc message list!\n");
+ lprintf(3, "ERROR: can't realloc message list!\n");
}
SetMessageInList(CC->num_msgs - 1, newmsgid);
/* update quickroom */
CC->quickroom.QRhighest = newmsgid;
- lprintf(9, "Writing/unlocking room <%s>...\n", CC->cs_room);
- lputroom(&CC->quickroom,CC->cs_room);
+ lprintf(9, "Writing/unlocking room <%s>...\n", actual_rm);
+ lputroom(&CC->quickroom, actual_rm);
/* Bump this user's messages posted counter. Also, if the user is a
* twit, give them access to the twit room.
lputuser(&CC->usersupp, CC->curr_user);
/* Network mail - send a copy to the network program. */
- if (mailtype!=M_LOCAL) {
+ if ((strlen(recipient)>0)&&(mailtype != M_LOCAL)) {
sprintf(aaa,"./network/spoolin/nm.%d",getpid());
copy_file(mtmp,aaa);
system("exec nohup ./netproc >/dev/null 2>&1 &");
}
/* get room records, obtaining a lock... */
- lgetroom(&CC->quickroom,CC->cs_room);
+ lgetroom(&CC->quickroom,CC->quickroom.QRname);
get_msglist(&CC->quickroom);
ok = 0;
CC->quickroom.QRhighest = MessageFromList(CC->num_msgs - 1);
put_msglist(&CC->quickroom);
- lputroom(&CC->quickroom,CC->cs_room);
+ lputroom(&CC->quickroom,CC->quickroom.QRname);
if (ok==1) {
cdb_delete(CDB_MSGMAIN, &delnum, sizeof(long));
cprintf("%d Message deleted.\n",OK);
}
/* yank the message out of the current room... */
- lgetroom(&CC->quickroom, CC->cs_room);
+ lgetroom(&CC->quickroom, CC->quickroom.QRname);
get_msglist(&CC->quickroom);
foundit = 0;
put_msglist(&CC->quickroom);
CC->quickroom.QRhighest = MessageFromList((CC->num_msgs)-1);
}
- lputroom(&CC->quickroom,CC->cs_room);
+ lputroom(&CC->quickroom,CC->quickroom.QRname);
if (!foundit) {
cprintf("%d msg %ld does not exist.\n",ERROR,num);
return;
/*
* putroom() - store room data on disk
+ * (if the supplied buffer is NULL, delete the room record)
*/
void putroom(struct quickroom *qrbuf, char *room_name)
{
lowercase_name[a] = tolower(room_name[a]);
}
- time(&qrbuf->QRmtime);
- cdb_store(CDB_QUICKROOM, lowercase_name, strlen(lowercase_name),
- qrbuf, sizeof(struct quickroom));
+ if (qrbuf == NULL) {
+ cdb_delete(CDB_QUICKROOM,
+ lowercase_name, strlen(lowercase_name));
+ }
+ else {
+ time(&qrbuf->QRmtime);
+ cdb_store(CDB_QUICKROOM,
+ lowercase_name, strlen(lowercase_name),
+ qrbuf, sizeof(struct quickroom));
+ }
}
struct cdbdata *cdbfr;
char dbkey[256];
int a;
-
+
+ lprintf(9, "get_msglist() called for <%s>\n", whichroom->QRname);
sprintf(dbkey, "%s%ld", whichroom->QRname, whichroom->QRgen);
for (a=0; a<strlen(dbkey); ++a) dbkey[a]=tolower(dbkey[a]);
-
+ lprintf(9, "database key is <%s>\n", dbkey);
+
+ lprintf(9, "Freeing existing message list\n");
if (CC->msglist != NULL) {
free(CC->msglist);
}
CC->msglist = NULL;
CC->num_msgs = 0;
+ lprintf(9, "calling cdb_fetch\n");
cdbfr = cdb_fetch(CDB_MSGLISTS, dbkey, strlen(dbkey));
+ lprintf(9, "done\n");
if (cdbfr == NULL) {
return;
memcpy(CC->msglist, cdbfr->ptr, cdbfr->len);
CC->num_msgs = cdbfr->len / sizeof(long);
cdb_free(cdbfr);
+ lprintf(9, "Leaving get_msglist()\n");
}
int newmailcount = 0;
struct visit vbuf;
- strcpy(CC->cs_room, where);
- getroom(&CC->quickroom, CC->cs_room);
+ strcpy(CC->quickroom.QRname, where);
+ lprintf(9, "usergoto() fetching room record\n");
+ getroom(&CC->quickroom, where);
+ lprintf(9, "usergoto() fetching user record\n");
lgetuser(&CC->usersupp,CC->curr_user);
+ lprintf(9, "usergoto() fetching relationships\n");
CtdlGetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
vbuf.v_flags = vbuf.v_flags & ~V_FORGET & ~V_LOCKOUT;
CtdlSetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
lputuser(&CC->usersupp,CC->curr_user);
+ lprintf(9, "usergoto() about to check for new mail\n");
/* check for new mail */
newmailcount = NewMailCount();
if (CC->quickroom.QRinfo > vbuf.v_lastseen) info = 1;
get_mm();
+ lprintf(9, "Fetching message list for counting...\n");
get_msglist(&CC->quickroom);
for (a=0; a<CC->num_msgs; ++a) {
if (MessageFromList(a)>0L) {
}
}
}
+ lprintf(9, "...done counting\n");
-
- if (0) rmailflag = 1; /* FIX to handle mail rooms!!! */
+ if (CC->quickroom.QRflags & QR_MAILBOX) rmailflag = 1;
else rmailflag = 0;
if ( (CC->quickroom.QRroomaide == CC->usersupp.usernum)
return;
}
- getroom(&CC->quickroom, CC->cs_room);
+ getroom(&CC->quickroom, CC->quickroom.QRname);
getuser(&CC->usersupp, CC->curr_user);
if ((CC->quickroom.QRflags & QR_DIRECTORY) == 0) {
return;
}
- if ( (!strcasecmp(CC->cs_room, BASEROOM))
- || (!strcasecmp(CC->cs_room, AIDEROOM)) ) {
+ if ( (!strcasecmp(CC->quickroom.QRname, BASEROOM))
+ || (!strcasecmp(CC->quickroom.QRname, AIDEROOM)) ) {
cprintf("%d Can't edit this room.\n",ERROR+NOT_HERE);
return;
}
- getroom(&CC->quickroom, CC->cs_room);
+ getroom(&CC->quickroom, CC->quickroom.QRname);
cprintf("%d%c%s|%s|%s|%d|%d\n",
OK,check_express(),
CC->quickroom.QRname,
return;
}
- if ( (!strcasecmp(CC->cs_room, BASEROOM))
- || (!strcasecmp(CC->cs_room, AIDEROOM)) ) {
+ if ( (!strcasecmp(CC->quickroom.QRname, BASEROOM))
+ || (!strcasecmp(CC->quickroom.QRname, AIDEROOM)) ) {
cprintf("%d Can't edit this room.\n",ERROR+NOT_HERE);
return;
}
}
}
- lgetroom(&CC->quickroom, CC->cs_room);
+ lgetroom(&CC->quickroom, CC->quickroom.QRname);
extract(buf,args,0); buf[ROOMNAMELEN]=0;
strncpy(CC->quickroom.QRname,buf,ROOMNAMELEN-1);
extract(buf,args,1); buf[10]=0;
CC->quickroom.QRfloor = extract_int(args,5);
}
- lputroom(&CC->quickroom, CC->cs_room);
+ lputroom(&CC->quickroom, CC->quickroom.QRname);
/* adjust the floor reference counts */
lgetfloor(&flbuf,old_floor);
return;
}
- if ( (!strcasecmp(CC->cs_room, BASEROOM))
- || (!strcasecmp(CC->cs_room, AIDEROOM)) ) {
+ if ( (!strcasecmp(CC->quickroom.QRname, BASEROOM))
+ || (!strcasecmp(CC->quickroom.QRname, AIDEROOM)) ) {
cprintf("%d Can't edit this room.\n",ERROR+NOT_HERE);
return;
}
newu = usbuf.usernum;
}
- lgetroom(&CC->quickroom, CC->cs_room);
+ lgetroom(&CC->quickroom, CC->quickroom.QRname);
post_notice = 0;
if (CC->quickroom.QRroomaide != newu) {
post_notice = 1;
}
CC->quickroom.QRroomaide = newu;
- lputroom(&CC->quickroom, CC->cs_room);
+ lputroom(&CC->quickroom, CC->quickroom.QRname);
/*
* We have to post the change notice _after_ writing changes to
}
/*
- * aide command: kill the current room
+ * Back end processing to delete a room and everything associated with it
*/
-void cmd_kill(char *argbuf)
-{
+void delete_room(struct quickroom *qrbuf) {
+ struct floor flbuf;
+ long MsgToDelete;
char aaa[100];
int a;
+
+ /* Delete the info file */
+ assoc_file_name(aaa, qrbuf, "info");
+ unlink(aaa);
+
+ /* Delete the image file */
+ assoc_file_name(aaa, qrbuf, "images");
+ unlink(aaa);
+
+ /* first flag the room record as not in use */
+ lgetroom(qrbuf, qrbuf->QRname);
+ qrbuf->QRflags=0;
+
+ /* then delete the messages in the room */
+ lprintf(9, "calling get_msglist()\n");
+ get_msglist(qrbuf);
+ if (CC->num_msgs > 0) for (a=0; a < CC->num_msgs; ++a) {
+ MsgToDelete = MessageFromList(a);
+ lprintf(9, "Deleting message %ld\n", MsgToDelete);
+ cdb_delete(CDB_MSGMAIN, &MsgToDelete, sizeof(long));
+ }
+ lprintf(9, "calling put_msglist()\n");
+ put_msglist(qrbuf);
+ free(CC->msglist);
+ CC->msglist = NULL;
+ CC->num_msgs = 0;
+ lprintf(9, "calling delete_msglist()\n");
+ delete_msglist(qrbuf);
+ lputroom(qrbuf, qrbuf->QRname);
+
+ /* then decrement the reference count for the floor */
+ lgetfloor(&flbuf,(int)(qrbuf->QRfloor));
+ flbuf.f_ref_count = flbuf.f_ref_count - 1;
+ lputfloor(&flbuf,(int)(qrbuf->QRfloor));
+
+ /* Delete the room record from the database! */
+ putroom(NULL, qrbuf->QRname);
+ lprintf(9, "finished with delete_room()\n");
+ }
+
+
+/*
+ * aide command: kill the current room
+ */
+void cmd_kill(char *argbuf) {
+ char aaa[100];
+ char deleted_room_name[ROOMNAMELEN];
int kill_ok;
- struct floor flbuf;
- long MsgToDelete;
kill_ok = extract_int(argbuf,0);
return;
}
- if ( (!strcasecmp(CC->cs_room, BASEROOM))
- || (!strcasecmp(CC->cs_room, AIDEROOM)) ) {
+ if ( (!strcasecmp(CC->quickroom.QRname, BASEROOM))
+ || (!strcasecmp(CC->quickroom.QRname, AIDEROOM)) ) {
cprintf("%d Can't edit this room.\n",ERROR+NOT_HERE);
return;
}
if (kill_ok) {
+ strcpy(deleted_room_name, CC->quickroom.QRname);
+ delete_room(&CC->quickroom); /* Do the dirty work */
+ lprintf(9, "Calling usergoto()\n");
+ usergoto(BASEROOM, 0); /* Return to the Lobby */
- /* Delete the info file */
- assoc_file_name(aaa, &CC->quickroom, "info");
- unlink(aaa);
-
- /* first flag the room record as not in use */
- lgetroom(&CC->quickroom, CC->cs_room);
- CC->quickroom.QRflags=0;
-
- /* then delete the messages in the room */
- get_msglist(&CC->quickroom);
- if (CC->num_msgs > 0) for (a=0; a < CC->num_msgs; ++a) {
- MsgToDelete = MessageFromList(a);
- cdb_delete(CDB_MSGMAIN, &MsgToDelete, sizeof(long));
- }
- put_msglist(&CC->quickroom);
- free(CC->msglist);
- CC->num_msgs = 0;
- delete_msglist(&CC->quickroom);
- lputroom(&CC->quickroom, CC->cs_room);
-
- /* FIX FIX FIX
- * To do at this location in the code:
- * 1. Delete the associated files (info, image)
- * 2. Delete the room record from the database
- */
-
- /* then decrement the reference count for the floor */
- lgetfloor(&flbuf,(int)CC->quickroom.QRfloor);
- flbuf.f_ref_count = flbuf.f_ref_count - 1;
- lputfloor(&flbuf,(int)CC->quickroom.QRfloor);
-
+ lprintf(9, "Composing notice\n");
/* tell the world what we did */
- sprintf(aaa,"%s> killed by %s",CC->quickroom.QRname,CC->curr_user);
+ sprintf(aaa,"%s> killed by %s",
+ deleted_room_name, CC->curr_user);
+ lprintf(9, "Posting notice\n");
aide_message(aaa);
- usergoto(BASEROOM, 0);
- cprintf("%d '%s' deleted.\n",OK,CC->quickroom.QRname);
+ lprintf(9, "done posting notice\n");
+ cprintf("%d '%s' deleted.\n", OK, deleted_room_name);
}
else {
cprintf("%d ok to delete.\n",OK);
if (new_room_type == 1) qrbuf.QRflags=(qrbuf.QRflags|QR_GUESSNAME);
if (new_room_type == 2) qrbuf.QRflags=(qrbuf.QRflags|QR_PASSWORDED);
if (new_room_type == 4) qrbuf.QRflags=(qrbuf.QRflags|QR_MAILBOX);
- qrbuf.QRroomaide = (-1L);
- if ((new_room_type > 0)&&(CREATAIDE==1))
+
+ /* If the room is private, and the system administrator has elected
+ * to automatically grant room aide privileges, do so now; otherwise,
+ * set the room aide to undefined.
+ */
+ if ( (qrbuf.QRflags & QR_PRIVATE) && (CREATAIDE==1) ) {
qrbuf.QRroomaide=CC->usersupp.usernum;
- qrbuf.QRhighest = 0L;
- time(&qrbuf.QRgen);
+ }
+ else {
+ qrbuf.QRroomaide = (-1L);
+ }
+
+ qrbuf.QRhighest = 0L; /* No messages in this room yet */
+ time(&qrbuf.QRgen); /* Use a timestamp as the generation number */
qrbuf.QRfloor = new_room_floor;
/* save what we just did... */
fclose(fp);
/* now update the room index so people will see our new info */
- lgetroom(&CC->quickroom,CC->cs_room); /* lock so no one steps on us */
+ lgetroom(&CC->quickroom,CC->quickroom.QRname); /* lock so no one steps on us */
CC->quickroom.QRinfo = CC->quickroom.QRhighest + 1L;
- lputroom(&CC->quickroom,CC->cs_room);
+ lputroom(&CC->quickroom,CC->quickroom.QRname);
}
*/
int purge_user(char *pname) {
char filename[64];
+ char mailboxname[ROOMNAMELEN];
struct usersupp usbuf;
- int a;
- struct cdbdata *cdbmb;
- long *mailbox;
- int num_mails;
+ struct quickroom qrbuf;
if (getuser(&usbuf, pname) != 0) {
lprintf(5, "Cannot purge user <%s> - not found\n", pname);
/* Perform any purge functions registered by server extensions */
PerformUserHooks(usbuf.fullname, usbuf.usernum, EVT_PURGEUSER);
- /* delete any messages in the user's mailbox */
- cdbmb = cdb_fetch(CDB_MAILBOXES, &usbuf.usernum, sizeof(long));
- if (cdbmb != NULL) {
- num_mails = cdbmb->len / sizeof(long);
- mailbox = (long *) cdbmb->ptr;
- if (num_mails > 0) for (a=0; a<num_mails; ++a) {
- cdb_delete(CDB_MSGMAIN, &mailbox[a], sizeof(long));
- }
- cdb_free(cdbmb);
- /* now delete the mailbox itself */
- cdb_delete(CDB_MAILBOXES, &usbuf.usernum, sizeof(long));
- }
-
/* delete any existing user/room relationships */
cdb_delete(CDB_VISIT, &usbuf.usernum, sizeof(long));
+ /* Delete the user's mailbox and its contents */
+ MailboxName(mailboxname, &usbuf, MAILROOM);
+ if (getroom(&qrbuf, mailboxname)==0) {
+ delete_room(&qrbuf);
+ }
+
/* delete the userlog entry */
cdb_delete(CDB_USERSUPP, pname, strlen(pname));
if (getuser(&CC->usersupp,CC->curr_user)) {
return(ERROR+INTERNAL_ERROR);
}
-
+
/* give the user a private mailbox */
MailboxName(mailboxname, &CC->usersupp, MAILROOM);
create_room(mailboxname, 4, "", 0);
return;
}
- /* FIX - with the new relationships scheme we can lock users out,
- so it'll make sense to remove this routine */
- if ( (op==1) && ((CC->quickroom.QRflags&QR_PRIVATE)==0) ) {
- cprintf("%d Not a private room.\n",ERROR+NOT_HERE);
- return;
- }
-
if (lgetuser(&USscratch,iuser)!=0) {
cprintf("%d No such user.\n",ERROR);
return;
CC->usersupp.fullname);
aide_message(bbb);
- if ((op==0)&&((CC->quickroom.QRflags&QR_PRIVATE)==0)) {
- cprintf("%d Ok. (Not a private room, <Z>ap effect only)\n",OK);
- }
- else {
- cprintf("%d Ok.\n",OK);
- }
+ cprintf("%d %s %s %s.\n",
+ OK, iuser,
+ ((op == 1) ? "invited to" : "kicked out of"),
+ CC->quickroom.QRname);
return;
}
*/
int NewMailCount() {
int num_newmsgs = 0;
- struct cdbdata *cdbmb;
- int num_mails;
- long *mailbox;
- int a;
char mailboxname[32];
MailboxName(mailboxname, &CC->usersupp, MAILROOM);
- for (a=0; a<=strlen(mailboxname); ++a) {
- mailboxname[a] = tolower(mailboxname[a]);
- }
-
- cdbmb = cdb_fetch(CDB_MAILBOXES, mailboxname, strlen(mailboxname));
- if (cdbmb != NULL) {
- num_mails = cdbmb->len / sizeof(long);
- mailbox = (long *) cdbmb->ptr;
- if (num_mails > 0) for (a=0; a<num_mails; ++a) {
- /*
- if (message is new FIX FIX FIX)
- ++num_newmsgs;
- */
- }
- cdb_free(cdbmb);
- }
+
+ /* FIX FIX FIX FIX FIX This needs implementation */
+
return(num_newmsgs);
}