exec { yylval.i = DGLCMD_EXEC; return TYPE_DGLCMD2; }
chpasswd { yylval.i = DGLCMD_CHPASSWD; return TYPE_DGLCMD0; }
chmail { yylval.i = DGLCMD_CHMAIL; return TYPE_DGLCMD0; }
+setprefpath { yylval.i = DGLCMD_SETPREFPATH; return TYPE_DGLCMD1; }
+readprefs { yylval.i = DGLCMD_READPREFS; return TYPE_DGLCMD0; }
+writeprefs { yylval.i = DGLCMD_WRITEPREFS; return TYPE_DGLCMD0; }
watch_menu { yylval.i = DGLCMD_WATCH_MENU; return TYPE_DGLCMD0; }
ask_login { yylval.i = DGLCMD_LOGIN; return TYPE_DGLCMD0; }
ask_register { yylval.i = DGLCMD_REGISTER; return TYPE_DGLCMD0; }
int initplayer = 0;
void (*g_chain_winch)(int);
+struct userpref {
+ char *name;
+ char *value;
+ struct userpref *npref;
+};
+struct userpref *userprefs = NULL;
+
#ifndef USE_SQLITE3
int f_num = 0;
struct dg_user **users = NULL;
{
int retval;
char *buf = NULL;
-
+
if (getenv(name) == NULL || overwrite)
{
size_t len = strlen(name) + 1 + strlen(value) + 1; /* NAME=VALUE\0 */
}
else
retval = -1;
-
- return retval;
+
+ return retval;
}
#else /* use native setenv */
# define mysetenv setenv
fprintf (user_spool, "%s:%s\n", me->username, message);
- /*
+ /*
* Don't unlock the file ourselves, this way it will be done automatically
* after all data has been written. (Using file locking with stdio is icky.)
*/
setproctitle("%s", me->username);
dgl_exec_cmdqueue(globalconfig.cmdqueue[DGLTIME_LOGIN], 0, me);
}
- else
+ else
{
me = NULL;
if (from_ttyplay == 1)
refresh();
sleep(2);
}
- }
+ }
}
/* ************************************************************* */
error = 0;
else
error = 1;
-
+
if (*buf == '\0')
{
free (me->username);
/* ************************************************************* */
+void
+freeprefs()
+{
+ struct userpref *cpref;
+ for (cpref = userprefs; cpref; ) {
+ cpref = cpref->npref;
+ free(userprefs->name);
+ free(userprefs->value);
+ free(userprefs);
+ userprefs = cpref;
+ }
+}
+
+int
+readprefs ()
+{
+ FILE *upf;
+ struct userpref **cpref = &userprefs;
+ int prefcount = 0;
+ char buf[256];
+ char *p;
+ char *nameptr;
+ char *valptr;
+
+ freeprefs();
+ upf = fopen(userpref_path, "r");
+ if (!upf) return -1;
+ while (fgets(buf, 256, upf)) {
+ /* first token is 'name' - must start with letter */
+ /* skip over any leading non-letter garbage */
+ for (p = buf; (*p < 'a' || *p > 'z') && (*p < 'A' || *p > 'Z'); p++)
+ if (p >= buf + 256) {
+ fclose(upf);
+ return prefcount;
+ }
+ nameptr = p;
+ /* rest of name can be alphanum */
+ for ( ; (*p >= 'a' && *p <= 'z')
+ || (*p >= 'A' && *p <= 'Z')
+ || (*p >= '0' && *p <= '9'); p++)
+ if (p >= buf + 256) {
+ fclose(upf);
+ return prefcount;
+ }
+ /* first non-alphanum is delimiter (it should be a space) */
+ *p++ = 0;
+ /* skip extra whitespace */
+ for (; *p == ' ' || *p == '\t'; p++)
+ if (p >= buf + 256) {
+ fclose(upf);
+ return prefcount;
+ }
+ valptr = p;
+ /* can probably acccept anything that's not a newline here */
+ for (; *p; p++)
+ if (p >= buf + 256 || *p == '\n') {
+ *p = 0;
+ break;
+ }
+ *cpref = (struct userpref *)malloc(sizeof(struct userpref));
+ (*cpref)->name = strdup(nameptr);
+ (*cpref)->value = strdup(valptr);
+ cpref = &(*cpref)->npref;
+ prefcount++;
+ }
+ fclose(upf);
+ return prefcount;
+}
+
+int
+writeprefs ()
+{
+ struct userpref *cpref;
+ int prefcount = 0;
+ FILE *upf = fopen (userpref_path, "w");
+ if (!upf) return -1;
+ for (cpref = userprefs; cpref; cpref = cpref->npref) {
+ fprintf (upf, "%s %s\n", cpref->name, cpref->value);
+ prefcount++;
+ }
+ fclose(upf);
+ return prefcount;
+}
+
+/* ************************************************************* */
+
int
readfile (int nolock)
{
for (i = 0; i < argc; i++)
saved_argv[i] = strdup(argv[i]);
saved_argv[i] = '\0';
-
+
compat_init_setproctitle(argc, argv);
argv = saved_argv;
#endif
DGLCMD_UNLINK, /* unlink foo */
DGLCMD_EXEC, /* exec foo bar */
DGLCMD_SETENV, /* setenv foo bar */
+ DGLCMD_SETPREFPATH, /* setprefpath foo */
+ DGLCMD_READPREFS, /* readprefs */
+ DGLCMD_WRITEPREFS, /* writeprefs */
DGLCMD_WATCH_MENU, /* watch_menu */
DGLCMD_LOGIN, /* ask_login */
DGLCMD_REGISTER, /* ask_register */
extern int dgl_local_LINES;
extern char last_ttyrec[512];
+extern char *userpref_path;
/* dgamelaunch.c */
extern void create_config(void);
extern void writefile(int requirenew);
extern void graceful_exit(int status);
extern int purge_stale_locks(int game);
+extern int readprefs(void);
+extern int writeprefs(void);
/*extern int menuloop(void);*/
extern void ttyrec_getpty(void);
#ifndef HAVE_SETENV
int selected_game = 0;
int return_from_submenu = 0;
+char *userpref_path = NULL;
mode_t default_fmode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH;
case DGLCMD_CHMAIL:
if (loggedin) change_email();
break;
+ case DGLCMD_SETPREFPATH:
+ if (loggedin && p1) {
+ free(userpref_path);
+ userpref_path = strdup(dgl_format_str(NULL, me, p1, playername));
+ }
+ break;
+ case DGLCMD_READPREFS:
+ if (loggedin && userpref_path) readprefs();
+ break;
+ case DGLCMD_WRITEPREFS:
+ if (loggedin && userpref_path) writeprefs();
+ break;
case DGLCMD_WATCH_MENU:
inprogressmenu(-1);
break;