Skip to content

Commit

Permalink
Add account flags for admins, banned accounts, preventing password or…
Browse files Browse the repository at this point in the history
… email changing.

git-svn-id: svn://katsu.triplehelix.org/dgamelaunch/trunk@581 db0b04b0-f4d1-0310-9a6d-de3e77497b0e
  • Loading branch information
paxed committed Jan 29, 2011
1 parent 643bebe commit 7223417
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 8 deletions.
4 changes: 0 additions & 4 deletions TODO
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@

-remove editoptions() and the editor compiled into dgl.

-move the games[] array into shmem?

-$MTIME(filename)
Expand Down Expand Up @@ -32,8 +30,6 @@
key not defined in other commands):
commands[default] = ...

-in watching-menu, maybe we shouldn't pick players who have been
idle for too long when randomly choosing one to watch.
-change dgl-banner handling; we only use the top line of it nowadays...
(maybe make that info config line: bannerline = "## $SERVERID" or something)
-allow the admin to config the watching menu:
Expand Down
38 changes: 36 additions & 2 deletions dgamelaunch.c
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,17 @@ signals_release()

/* ************************************************************* */

char *
get_mainmenu_name()
{
if (loggedin) {
if (me && (me->flags & DGLACCT_ADMIN)) return "mainmenu_admin";
return "mainmenu_user";
}
return "mainmenu_anon";
}


char*
gen_ttyrec_filename ()
{
Expand Down Expand Up @@ -1089,6 +1100,13 @@ change_email ()

clear();

if (me->flags & DGLACCT_EMAIL_LOCK) {
drawbanner(&banner, 1, 1);
mvprintw(5, 1, "Sorry, you cannot change the email.--More--");
dgl_getch();
return;
}

for (;;)
{
drawbanner(&banner, 1,1);
Expand Down Expand Up @@ -1146,6 +1164,14 @@ changepw (int dowrite)
graceful_exit (122); /* Die. */
}

if (me->flags & DGLACCT_PASSWD_LOCK) {
clear();
drawbanner(&banner, 1, 1);
mvprintw(5, 1, "Sorry, you cannot change the password.--More--");
dgl_getch();
return 0;
}

while (error)
{
char repeatbuf[DGL_PASSWDLEN+1];
Expand Down Expand Up @@ -1420,7 +1446,7 @@ autologin (char* user, char *pass)
tmp = userexist(user, 0);
if (tmp) {
me = cpy_me(tmp);
if (passwordgood(pass)) {
if (passwordgood(pass) && !(me->flags & DGLACCT_LOGIN_LOCK)) {
loggedin = 1;
setproctitle ("%s", me->username);
dgl_exec_cmdqueue(globalconfig.cmdqueue[DGLTIME_LOGIN], 0, me);
Expand Down Expand Up @@ -1488,6 +1514,13 @@ loginprompt (int from_ttyplay)

if (passwordgood (pw_buf))
{
if (me->flags & DGLACCT_LOGIN_LOCK) {
clear ();
mvprintw(5, 1, "Sorry, that account has been banned.--More--");
dgl_getch();
return;
}

loggedin = 1;
if (from_ttyplay)
setproctitle("%s [watching %s]", me->username, chosen_name);
Expand Down Expand Up @@ -1651,6 +1684,7 @@ newuser ()

me->email = strdup (buf);
me->env = calloc (1, 1);
me->flags = 0;

loggedin = 1;

Expand Down Expand Up @@ -2507,7 +2541,7 @@ main (int argc, char** argv)
idle_alarm_set_enabled(1);

while (1) {
if (runmenuloop(dgl_find_menu(loggedin ? "mainmenu_user" : "mainmenu_anon")))
if (runmenuloop(dgl_find_menu(get_mainmenu_name())))
break;
}

Expand Down
11 changes: 10 additions & 1 deletion dgamelaunch.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@
# define CLR_RED 0
#endif

typedef enum
{
DGLACCT_ADMIN = 0x01, /* admin account */
DGLACCT_LOGIN_LOCK = 0x02, /* account is banned and cannot login */
DGLACCT_PASSWD_LOCK = 0x04, /* account password cannot be changed */
DGLACCT_EMAIL_LOCK = 0x08 /* account email cannot be changed */
} dgl_acct_flag;

typedef enum
{
DGLTIME_DGLSTART = 0, /* when someone telnets in */
Expand Down Expand Up @@ -58,7 +66,7 @@ struct dg_user
char *email;
char *env;
char *password;
int flags;
int flags; /* dgl_acct_flag bitmask */
};

struct dg_banner
Expand Down Expand Up @@ -231,6 +239,7 @@ extern int dgl_local_LINES;
/* dgamelaunch.c */
extern void create_config(void);
extern void ttyrec_getmaster(void);
extern char *get_mainmenu_name(void);
extern char *gen_ttyrec_filename(void);
extern char *gen_inprogress_lock(int game, pid_t pid, char *ttyrec_filename);
extern void catch_sighup(int signum);
Expand Down
2 changes: 1 addition & 1 deletion dgl-common.c
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ dgl_exec_cmdqueue(struct dg_cmdpart *queue, int game, struct dg_user *me)
break;
case DGLCMD_LOGIN:
if (!loggedin) loginprompt(0);
if (loggedin) runmenuloop(dgl_find_menu("mainmenu_user"));
if (loggedin) runmenuloop(dgl_find_menu(get_mainmenu_name()));
break;
case DGLCMD_REGISTER:
if (!loggedin && globalconfig.allow_registration) newuser();
Expand Down

0 comments on commit 7223417

Please sign in to comment.