Skip to content
Commits on Source (3)
......@@ -603,6 +603,8 @@ static void users_lastread(int folnum)
int ufile;
ufile=userdb_open(O_RDWR);
if (ufile < 0)
return;
Lock_File(ufile);
while (read(ufile,&usr,sizeof(usr))>0)
{
......
......@@ -80,7 +80,9 @@ void auto_subscribe(int folnum, int state)
struct person *urec = &usr.record;
char buff[10];
ufile=userdb_open(O_RDWR);
ufile = userdb_open(O_RDWR);
if (ufile < 0)
return;
Lock_File(ufile); /*user file*/
while(get_person(ufile, &usr))
{
......
......@@ -36,7 +36,6 @@ extern Alias event_list;
extern Alias onoff_list;
extern Alias ipc_list;
extern struct user *user;
extern struct room myroom;
extern int quietmode;
extern ipc_connection_t *ipcsock;
......@@ -439,8 +438,8 @@ void handle_mesg()
while (msg != NULL) {
if (msg->head.src == SYSTEM_USER) {
strcpy(mesg_user.record.name,"System");
} else {
fetch_user(&mesg_user, msg->head.src);
} else if (fetch_user(&mesg_user, msg->head.src) != 0) {
return;
}
accept_pipe_cmd(msg, &mesg_user);
......@@ -510,7 +509,8 @@ static void display_content(ipc_message_t *msg)
whom = "System";
} else {
msg_posn = msg->head.src;
fetch_user(&msg_user, msg_posn);
if (fetch_user(&msg_user, msg_posn) != 0)
return;
whom = msg_user.record.name;
}
......@@ -976,9 +976,9 @@ static void force_channel(char *newbuff, char *from, unsigned long theirprivs)
talk_send_rawbcast(text);
user->record.chatmode = cm_set(user, CM_ONCHAT);
RoomDestroy(&myroom);
RoomInit(&myroom);
LoadRoom(&myroom, newroom);
RoomDestroy(&user->room);
RoomInit(&user->room);
LoadRoom(&user->room, newroom);
/* force update of user information _before_ scripts are run */
update_user(user);
......@@ -1011,9 +1011,9 @@ static void force_channel(char *newbuff, char *from, unsigned long theirprivs)
snprintf(text,MAXTEXTLENGTH-1,"\03315You have been summoned to room %d by %s.",newroom,from);
display_message(text, 1, 1);
RoomDestroy(&myroom);
RoomInit(&myroom);
LoadRoom(&myroom, newroom);
RoomDestroy(&user->room);
RoomInit(&user->room);
LoadRoom(&user->room, newroom);
enter_room(newroom);
}
}
......
......@@ -49,9 +49,6 @@
#include "bb.h"
#include "userio.h"
#include "who.h"
extern struct room myroom;
#include "alias.h"
extern Alias bind_list;
extern Alias alias_list;
......@@ -734,18 +731,11 @@ int main(int argc, char **argv)
InitParser();
set_rights();
init_colour();
RoomInit(&myroom);
/* if (!(rights&65l)) a pleb - timeout of 10 mins
user->timeout=600; */
RoomInit(&user->room);
update_user(user);
/* run all board init functions */
RunInitFuncs(0);
/* broadcast board logon signal to other users */
broadcast_onoffcode(3, autochat, NULL, NULL);
......@@ -917,7 +907,7 @@ void close_down(int exitmode, char *sourceuser, char *reason)
ScriptCleanup();
RoomDestroy(&myroom);
RoomDestroy(&user->room);
ClearStack();
stop_js();
alarm_cleanup();
......@@ -1768,8 +1758,9 @@ char *part_user(const char *text, int status)
if (status==0)
{
if (file!=0) close(file);
file=userdb_open(O_RDONLY);
file = userdb_open(O_RDONLY);
if (file < 0)
return NULL;
len=strlen(text);
}
......
......@@ -31,9 +31,6 @@
extern struct user *user;
extern Alias alias_list;
extern Alias bind_list;
extern struct room myroom;
/* current script runaway variable */
extern long runaway;
......@@ -388,7 +385,7 @@ void scr_roomnum( struct code *pc, int fargc, char **fargv )
snprintf(rn, 9, "%d", user->record.room);
}
/* if room is not hidden, or locked, then return room number */
else if (myroom.hidden<=0 && myroom.locked<=0)
else if (user->room.hidden <= 0 && user->room.locked <= 0)
{
snprintf(rn, 9, "%d", user->record.room);
}
......
......@@ -53,8 +53,6 @@ extern unsigned long loggedin;
extern int quietmode;
static int runautoexec = 1;
extern struct room myroom;
extern CommandList table[];
extern CommandList chattable[];
......@@ -390,10 +388,10 @@ void t_restart(CommandList *cm, int argc, const char **argv, char *args)
stop_js();
setup_js();
RoomDestroy(&myroom);
RoomDestroy(&user->room);
RoomInit(&myroom);
LoadRoom(&myroom, user->record.room);
RoomInit(&user->room);
LoadRoom(&user->room, user->record.room);
LoadInitFile(NULL);
......@@ -1146,9 +1144,9 @@ void t_chaton(void)
urec->chatmode = cm_set(user, CM_ONCHAT);
update_user(user);
if (myroom.name!=NULL)
if (user->room.name!=NULL)
snprintf(mtext, MAXTEXTLENGTH-1, "\03310%s has just joined talker in %s",
urec->name, myroom.name);
urec->name, user->room.name);
else
snprintf(mtext, MAXTEXTLENGTH-1, "\03310%s has just joined talker room %d",
urec->name, urec->room);
......@@ -1419,9 +1417,9 @@ int ChangeRoom(char *room, int quiet)
user->record.room = i;
update_user(user);
RoomDestroy(&myroom);
RoomInit(&myroom);
LoadRoom(&myroom, user->record.room);
RoomDestroy(&user->room);
RoomInit(&user->room);
LoadRoom(&user->room, user->record.room);
SAFE_FREE(buff);
if (asprintf(&buff, "\03313%s has left to room %d", user->record.name, i) < 0)
......
......@@ -13,7 +13,6 @@
extern struct user *user;
extern int quietmode;
extern struct room myroom;
unsigned long chatmode_describe(unsigned long old, unsigned long new, int ourapl, int theirapl, const char *from)
{
......@@ -180,9 +179,9 @@ unsigned long chatmode_describe(unsigned long old, unsigned long new, int ourapl
set_talk_rights();
if (myroom.name!=NULL)
if (user->room.name != NULL)
snprintf(mtext,MAXTEXTLENGTH-1,"\03310%s has just joined talker in %s",
user->record.name, myroom.name);
user->record.name, user->room.name);
else
snprintf(mtext,MAXTEXTLENGTH-1,"\03310%s has just joined talker room %d",
user->record.name, user->record.room);
......
......@@ -351,6 +351,9 @@ void list_users(int newonly)
long logout_time;
file=userdb_open(O_RDONLY);
if (file < 0)
return;
while (get_person(file, &usr))
{
if (!newonly || ( newonly && !u_reg(&usr) ) )
......@@ -391,6 +394,9 @@ void list_users_since(long date)
long logout_time;
file=userdb_open(O_RDONLY);
if (file < 0)
return;
while (get_person(file, &usr))
{
if (urec->lastlogout > date)
......@@ -434,6 +440,9 @@ static void list_users_flags(int flags, int type, int inv)
int screen_height=screen_h();
file=userdb_open(O_RDONLY);
if (file < 0)
return;
while (get_person(file,&usr))
{
if (type==0) check=urec->status;
......
......@@ -27,7 +27,6 @@
extern int busy;
extern struct user *user;
extern struct room myroom;
char *itime(unsigned long t)
{
......
......@@ -4,8 +4,6 @@
#include "rooms.h"
#include "util.h"
struct room myroom;
int isanum(char *a, int *result, int onlydecimal);
void RoomInit(struct room *room)
......
......@@ -134,19 +134,13 @@ void replay(ipc_connection_t *conn, ipc_message_t *msg)
json_decref(cmd);
/* who are we doing this for */
struct person user;
int users_fd = userdb_open(O_RDONLY);
lseek(users_fd, conn->user, SEEK_SET);
if (read(users_fd, &user, sizeof(user)) <= 0) {
close(users_fd);
struct user user;
if (fetch_user(&user, conn->user) != 0) {
send_error(conn, msg, "Error cannot find your user record");
return;
}
close(users_fd);
struct room room;
RoomInit(&room);
LoadRoom(&room, user.room);
RoomInit(&user.room);
LoadRoom(&user.room, user.record.room);
/* now, go and replay those messages that are appropriate */
for (;idx != store_next; idx = store_wrap( idx + 1 )) {
......@@ -160,18 +154,18 @@ void replay(ipc_connection_t *conn, ipc_message_t *msg)
const char * exclude = json_getstring(j, "exclude");
if (exclude != NULL && strcasecmp(exclude, user.name)==0) {
if (exclude != NULL && strcasecmp(exclude, user.record.name)==0) {
/* thats us ! shhh... */
json_decref(j);
continue;
}
json_decref(j);
if (user.room == store[idx]->head.dst) {
if (user.record.room == store[idx]->head.dst) {
/* right room, send it */
msg_attach(store[idx], conn);
} else
if (room.sproof < 1 && (user.chatmode & CM_GLOBAL)) {
if (user.room.sproof < 1 && (cm_test(&user, CM_GLOBAL))) {
/* room not soundproof, and user has global on */
msg_attach(store[idx], conn);
}
......@@ -184,7 +178,7 @@ void replay(ipc_connection_t *conn, ipc_message_t *msg)
const char * target = json_getstring(j, "target");
if (target!=NULL && strcasecmp(target, user.name)==0) {
if (target!=NULL && strcasecmp(target, user.record.name)==0) {
/* yes, its for us */
msg_attach(store[idx], conn);
}
......@@ -197,7 +191,7 @@ void replay(ipc_connection_t *conn, ipc_message_t *msg)
msg_attach(store[idx], conn);
}
RoomDestroy(&room);
RoomDestroy(&user.room);
return;
}
......@@ -434,8 +434,11 @@ void msg_attach_to_channel(ipc_message_t *msg, int channel, const char * exclude
int users_fd = userdb_open(O_RDONLY);
struct user user;
struct person *urec = &user.record;
struct room room;
if (users_fd < 0)
return;
RoomInit(&room);
LoadRoom(&room, channel);
......@@ -472,8 +475,11 @@ int msg_attach_to_username(ipc_message_t *msg, const char * username)
struct user user;
struct person *urec = &user.record;
int found = 0;
struct list_head *pos;
if (users_fd < 0)
return 0;
list_for_each(pos, &connection_list) {
ipc_connection_t *c = list_entry(pos, ipc_connection_t, list);
if (c->state != IPCSTATE_VALID) continue;
......@@ -497,8 +503,11 @@ void msg_attach_to_all(ipc_message_t *msg)
int users_fd = userdb_open(O_RDONLY);
struct user user;
struct person *urec = &user.record;
struct list_head *pos;
if (users_fd < 0)
return;
list_for_each(pos, &connection_list) {
ipc_connection_t *c = list_entry(pos, ipc_connection_t, list);
if (c->state != IPCSTATE_VALID) continue;
......@@ -683,12 +692,14 @@ void init_server()
ipc_message_t * msg_wholist(void)
{
ipc_message_t * msg = ipcmsg_create(IPC_WHOLIST, SYSTEM_USER);
int users_fd = userdb_open(O_RDONLY);
struct user user;
struct person *urec = &user.record;
if (users_fd < 0)
return NULL;
ipc_message_t * msg = ipcmsg_create(IPC_WHOLIST, SYSTEM_USER);
json_t * list = json_array();
struct list_head *pos;
......@@ -735,8 +746,11 @@ int32_t who_find(const char * username)
{
int users_fd = userdb_open(O_RDONLY);
struct person user;
struct list_head *pos;
if (users_fd < 0)
return -1;
list_for_each(pos, &connection_list) {
ipc_connection_t *c = list_entry(pos, ipc_connection_t, list);
if (c->state != IPCSTATE_VALID) continue;
......
......@@ -13,10 +13,8 @@
int userdb_open(int flags)
{
int ufd = open(USERFILE, flags|O_CREAT, S_IRUSR|S_IWUSR|S_IRGRP);
if (ufd < 0) {
if (ufd < 0)
perror(USERFILE);
exit(-1);
}
return ufd;
}
......@@ -48,20 +46,27 @@ void update_user(struct user *user)
int outfile;
outfile = userdb_open(O_WRONLY|O_CREAT);
if (outfile < 0)
return;
update_user_fd(outfile, user);
close(outfile);
}
void fetch_user(struct user *user, int32_t userposn)
int fetch_user(struct user *user, int32_t userposn)
{
struct person *record = &user->record;
int outfile;
int outfile = userdb_open(O_RDWR|O_CREAT);
if (outfile < 0)
return 1;
outfile=userdb_open(O_RDWR|O_CREAT);
lseek(outfile, userposn, SEEK_SET);
read(outfile,record,sizeof(*record));
if (pread(outfile, record, sizeof(*record), userposn) != sizeof(*record)) {
perror("pread");
close(outfile);
return 1;
}
close(outfile);
user->posn = userposn;
return 0;
}
static int user_find_name(const char *name, struct user *user, int *found)
......
......@@ -2,6 +2,7 @@
#define USER_H
#include <stdint.h>
#include "rooms.h"
#define NAMESIZE 16 /* username */
#define PASSWDSIZE 20 /* password (after encryption) */
......@@ -70,11 +71,12 @@ struct person
struct user {
int32_t posn;
struct person record;
struct room room;
};
extern int userdb_open(int flags);
extern void userdb_write(struct user *user);
extern void fetch_user(struct user *record, int32_t userposn);
extern int fetch_user(struct user *record, int32_t userposn);
extern void update_user(struct user *user);
extern int update_user_fd(int fd, struct user *user);
extern int is_old(const char *name, struct user *user);
......