From 7d605e5abc230fc33df929e3d3063773f8f2f375 Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Mon, 28 Sep 1998 03:42:48 +0000 Subject: [PATCH] * BOTH the old and new generation systems are being written to at this point. Code that reads stuff is still using the old system. --- citadel/ChangeLog | 4 ++ citadel/room_ops.c | 23 ++++++-- citadel/user_ops.c | 138 +++++++++++++++++++++++++++++++++++++++++++++ citadel/user_ops.h | 6 ++ 4 files changed, 167 insertions(+), 4 deletions(-) diff --git a/citadel/ChangeLog b/citadel/ChangeLog index c104af448..a301744c2 100644 --- a/citadel/ChangeLog +++ b/citadel/ChangeLog @@ -1,3 +1,7 @@ +Sun Sep 27 23:41:29 EDT 1998 Art Cancro + * BOTH the old and new generation systems are being written to at + this point. Code that reads stuff is still using the old system. + Sun Sep 27 16:10:49 EDT 1998 Art Cancro * Changed all "generation" variables from char to long, in preparation for removing MAXROOMS. Generations for new rooms are now timestamps. diff --git a/citadel/room_ops.c b/citadel/room_ops.c index 7392623e4..205cc1659 100644 --- a/citadel/room_ops.c +++ b/citadel/room_ops.c @@ -504,12 +504,21 @@ void usergoto(int where, int display_result) int rmailflag; int raideflag; int newmailcount = 0; + struct visit vbuf; CC->curr_rm=where; getroom(&CC->quickroom,CC->curr_rm); lgetuser(&CC->usersupp,CC->curr_user); + CtdlGetRelationship(&vbuf, &CC->usersupp, &CC->quickroom); + + /* old method - remove when we're ready */ CC->usersupp.forget[CC->curr_rm]=(-1); CC->usersupp.generation[CC->curr_rm]=CC->quickroom.QRgen; + + /* new method */ + vbuf.v_flags = vbuf.v_flags & ~V_FORGET & ~V_LOCKOUT; + + CtdlSetRelationship(&vbuf, &CC->usersupp, &CC->quickroom); lputuser(&CC->usersupp,CC->curr_user); /* check for new mail */ @@ -826,11 +835,11 @@ void cmd_setr(char *args) { ||(CC->quickroom.QRflags & QR_PASSWORDED)) CC->quickroom.QRflags |= QR_PRIVATE; - /* Kick everyone out if the client requested it */ + /* Kick everyone out if the client requested it (by changing the + * room's generation number) + */ if (extract_int(args,4)) { - ++CC->quickroom.QRgen; - if (CC->quickroom.QRgen==100) time(&CC->quickroom.QRgen); - + time(&CC->quickroom.QRgen); } old_floor = CC->quickroom.QRfloor; @@ -1060,6 +1069,7 @@ unsigned create_room(int free_slot, char *new_room_name, int new_room_type, char { struct quickroom qrbuf; struct floor flbuf; + struct visit vbuf; lgetroom(&qrbuf,free_slot); strncpy(qrbuf.QRname,new_room_name,19); @@ -1085,8 +1095,13 @@ unsigned create_room(int free_slot, char *new_room_name, int new_room_type, char /* be sure not to kick the creator out of the room! */ lgetuser(&CC->usersupp,CC->curr_user); + CtdlGetRelationship(&vbuf, &CC->usersupp, &qrbuf); + /* (old method) */ CC->usersupp.generation[free_slot] = qrbuf.QRgen; CC->usersupp.forget[free_slot] = (-1); + /* (new method) */ + vbuf.v_flags = vbuf.v_flags & ~V_FORGET & ~V_LOCKOUT; + CtdlSetRelationship(&vbuf, &CC->usersupp, &qrbuf); lputuser(&CC->usersupp,CC->curr_user); /* resume our happy day */ diff --git a/citadel/user_ops.c b/citadel/user_ops.c index 3e7f044b6..9a6f4501d 100644 --- a/citadel/user_ops.c +++ b/citadel/user_ops.c @@ -100,6 +100,104 @@ void lputuser(struct usersupp *usbuf, char *name) { } +/* + * Define a relationship between a user and a room + */ +void CtdlSetRelationship(struct visit *newvisit, + struct usersupp *rel_user, + struct quickroom *rel_room) { + + struct cdbdata *cdbvisit; + struct visit *visits; + int num_visits; + int a; + int replaced = 0; + + cdbvisit = cdb_fetch(CDB_VISIT, &rel_user->usernum, sizeof(long)); + if (cdbvisit != NULL) { + num_visits = cdbvisit->len / sizeof(struct visit); + visits = (struct visit *) + malloc(num_visits * sizeof(struct visit)); + memcpy(visits, cdbvisit->ptr, + (num_visits * sizeof(struct visit))); + cdb_free(cdbvisit); + } + else { + num_visits = 0; + visits = NULL; + } + + /* Replace an existing relationship if possible */ + if (num_visits > 0) for (a=0; aQRname)) + && (visits[a].v_generation == rel_room->QRgen) ) { + memcpy(&visits[a], newvisit, sizeof(struct visit)); + replaced = 1; + } + } + + /* Otherwise, define a new one */ + if (replaced == 0) { + ++num_visits; + visits = realloc(visits, + (num_visits * sizeof(struct visit))); + memcpy(&visits[num_visits-1], newvisit, sizeof(struct visit)); + } + + /* Now write the relationship back to disk */ + cdb_store(CDB_VISIT, + &rel_user->usernum, sizeof(long), + visits, + (num_visits * sizeof(struct visit))); + free(visits); + } + +/* + * Locate a relationship between a user and a room + */ +void CtdlGetRelationship(struct visit *vbuf, + struct usersupp *rel_user, + struct quickroom *rel_room) { + + struct cdbdata *cdbvisit; + struct visit *visits; + int num_visits = 0; + int a; + + bzero(vbuf, sizeof(struct visit)); + strcpy(vbuf->v_roomname, rel_room->QRname); + vbuf->v_generation = rel_room->QRgen; + + cdbvisit = cdb_fetch(CDB_VISIT, &rel_user->usernum, sizeof(long)); + if (cdbvisit != NULL) { + num_visits = cdbvisit->len / sizeof(struct visit); + visits = (struct visit *) + malloc(num_visits * sizeof(struct visit)); + memcpy(visits, cdbvisit->ptr, + (num_visits * sizeof(struct visit))); + cdb_free(cdbvisit); + } + + if (num_visits == 0) return; + + for (a=0; aQRname)) + && (visits[a].v_generation == rel_room->QRgen) ) { + memcpy(vbuf, &visits[a], sizeof(struct visit)); + } + } + + free(visits); + } + + /* * Is the user currently logged in an Aide? */ @@ -223,6 +321,9 @@ void session_startup(void) { /* A room's generation number changes each time it is recycled. Users are kept * out of private rooms or forget rooms by matching the generation numbers. To * avoid an accidental matchup, unmatched numbers are set to -1 here. + * + * FIX - This can get removed once the new relationships system is in place. + * */ for (a=0; alogged_in)) { cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN); @@ -596,7 +701,15 @@ void cmd_slrp(char *new_ptr) } lgetuser(&CC->usersupp, CC->curr_user); + + /* old method - remove */ CC->usersupp.lastseen[CC->curr_rm] = newlr; + + /* new method */ + CtdlGetRelationship(&vbuf, &CC->usersupp, &CC->quickroom); + vbuf.v_lastseen = newlr; + CtdlSetRelationship(&vbuf, &CC->usersupp, &CC->quickroom); + lputuser(&CC->usersupp, CC->curr_user); cprintf("%d %ld\n",OK,newlr); } @@ -610,6 +723,7 @@ void cmd_invt_kick(char *iuser, int op) { /* 1 = invite, 0 = kick out */ struct usersupp USscratch; char bbb[256]; + struct visit vbuf; if (!(CC->logged_in)) { cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN); @@ -627,6 +741,8 @@ void cmd_invt_kick(char *iuser, int op) 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; @@ -637,16 +753,28 @@ void cmd_invt_kick(char *iuser, int op) return; } + CtdlGetRelationship(&vbuf, &USscratch, &CC->quickroom); + if (op==1) { + /* old method -- FIX remove this when we're ready */ USscratch.generation[CC->curr_rm]=CC->quickroom.QRgen; USscratch.forget[CC->curr_rm]=(-1); + + /* new method */ + vbuf.v_flags = vbuf.v_flags & ~V_FORGET & ~V_LOCKOUT; } if (op==0) { + /* old method -- FIX remove this when we're ready */ USscratch.generation[CC->curr_rm]=(-1); USscratch.forget[CC->curr_rm]=CC->quickroom.QRgen; + + /* new method */ + vbuf.v_flags = vbuf.v_flags | V_FORGET | V_LOCKOUT; } + CtdlSetRelationship(&vbuf, &USscratch, &CC->quickroom); + lputuser(&USscratch,iuser); /* post a message in Aide> saying what we just did */ @@ -671,6 +799,8 @@ void cmd_invt_kick(char *iuser, int op) * forget (Zap) the current room */ void cmd_forg(void) { + struct visit vbuf; + if (!(CC->logged_in)) { cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN); return; @@ -692,8 +822,16 @@ void cmd_forg(void) { } lgetuser(&CC->usersupp,CC->curr_user); + CtdlGetRelationship(&vbuf, &CC->usersupp, &CC->quickroom); + + /* old method -- FIX remove this when we're ready */ CC->usersupp.forget[CC->curr_rm] = CC->quickroom.QRgen; CC->usersupp.generation[CC->curr_rm] = (-1); + + /* new method */ + vbuf.v_flags = vbuf.v_flags | V_FORGET; + + CtdlSetRelationship(&vbuf, &CC->usersupp, &CC->quickroom); lputuser(&CC->usersupp,CC->curr_user); cprintf("%d Ok\n",OK); CC->curr_rm = (-1); diff --git a/citadel/user_ops.h b/citadel/user_ops.h index ac6ef7c8b..2725053fd 100644 --- a/citadel/user_ops.h +++ b/citadel/user_ops.h @@ -34,3 +34,9 @@ void cmd_lbio (void); void cmd_agup (char *cmdbuf); void cmd_asup (char *cmdbuf); int NewMailCount(void); +void CtdlGetRelationship(struct visit *vbuf, + struct usersupp *rel_user, + struct quickroom *rel_room); +void CtdlSetRelationship(struct visit *newvisit, + struct usersupp *rel_user, + struct quickroom *rel_room); -- 2.39.2