[mw-devel] [Git][milliways/mw][master] 2 commits: Don't load mwscript scripts
Andrew Price
welshbyte at sucs.org
Sun Apr 7 08:12:20 BST 2019
Andrew Price pushed to branch master at milliways / mw
Commits:
d4aad6f5 by Andrew Price at 2019-04-07T07:11:16Z
Don't load mwscript scripts
(Or anything that isn't .mwrc or a .js file)
- - - - -
260304b4 by Andrew Price at 2019-04-07T07:11:16Z
No-op all .mwrc commands apart from 'include'
- - - - -
2 changed files:
- src/client/init.c
- src/client/talker.c
Changes:
=====================================
src/client/init.c
=====================================
@@ -49,14 +49,7 @@ void perms_restore(void)
}
}
-static void warn_of_mwscript_death(const char *filename)
-{
- // Slightly obnoxious by design
- printf("*** You are using mwscript scripts: %s\n", filename);
- printf("*** mwscript support will be removed from mw on April 7th 2019.\n");
-}
-
-int do_warn_of_mwscript_death = 0;
+int mwrc_loaded = 0;
static int ReadInitFile(const char *base, const char *filename)
{
FILE *file;
@@ -125,12 +118,11 @@ static int ReadInitFile(const char *base, const char *filename)
return 0; // changed because if an error occured after this point the file exists, the js code has reported the error to the user and returning 1 will report to them that it doesn't exist
}
- /* Warnings for the initial .mwrc are a little OTT for now but warn on
- subsequent mwscript loads */
- if (do_warn_of_mwscript_death)
- warn_of_mwscript_death(filename);
- else
- do_warn_of_mwscript_death = 1;
+ if (mwrc_loaded) {
+ fprintf(stderr, "Warning: file included in .mwrc not supported: %s\n", filename);
+ return 0;
+ } else
+ mwrc_loaded = 1;
lineno=0;
while (!feof(file))
@@ -145,76 +137,6 @@ static int ReadInitFile(const char *base, const char *filename)
if (*a=='#') { free(backup); free(header); continue; }
- /* load command aliases */
- if (!strcasecmp(a,"alias"))
- {
- if ((b=strtok(NULL," \t\n\r"))==NULL)
- {
- printf(_("Malformed alias in %s at line %d\n"),filename,lineno);
- free(backup);
- free(header);
- continue;
- }
- if ((c=strtok(NULL," \t\n\r"))==NULL)
- {
- printf(_("Malformed alias in %s at line %d\n"),filename,lineno);
- free(backup);
- free(header);
- continue;
- }
-
- if (AddLink(&alias_list, b, c))
- {
- printf(_("Alias %s already exists. Redefined at line %d in %s.\n"), b, lineno, filename);
- }
- }else
- /* load function binds */
- if (!strcasecmp(a,"bind"))
- {
- if ((b=strtok(NULL," \t\n\r"))==NULL)
- {
- printf(_("Malformed bind in %s at line %d\n"),filename,lineno);
- free(backup);
- free(header);
- continue;
- }
- if ((c=strtok(NULL," \t\n\r"))==NULL)
- {
- printf(_("Malformed bind in %s at line %d\n"),filename,lineno);
- free(backup);
- free(header);
- continue;
- }
-
- if (AddLink(&bind_list, b, c))
- {
- printf(_("Bind %s already exists. Redefined at line %d in %s.\n"), b, lineno, filename);
- }
- }else
- /* load rpc binds */
- if (!strcasecmp(a,"rpc"))
- {
- if ((b=strtok(NULL," \t\n\r"))==NULL)
- {
- printf(_("Malformed rpc bind in %s at line %d\n"),filename,lineno);
- free(backup);
- free(header);
- continue;
- }
- if ((c=strtok(NULL," \t\n\r"))==NULL)
- {
- printf(_("Malformed rpc bind in %s at line %d\n"),filename,lineno);
- free(backup);
- free(header);
- continue;
- }
-
- if (AddLink(&rpc_list, b, c))
- {
- printf(_("RPC Bind %s already exists. Redefined at line %d in %s.\n"), b, lineno, filename);
- }
- }else
- /* include a seperate script file */
if (!strcasecmp(a, "include"))
{
if ((b=strtok(NULL," \t\n\r"))==NULL)
@@ -232,167 +154,37 @@ static int ReadInitFile(const char *base, const char *filename)
ReadInitFile(base, rpath);
}else
ReadInitFile(base, b);
- }else
- /* check for destroying functions */
- if (!strcasecmp(a, "destroy"))
- {
- if ((b=strtok(NULL," \t\n\r"))==NULL)
- {
- printf(_("Malformed include in %s at line %d\n"),filename,lineno);
- free(backup);
- free(header);
- continue;
- }
- if (!strcasecmp(b, "*")) DestroyAllFunctions(0); else DestroyFunction(b);
- }else
- /* bind event function */
- if (!strcasecmp(a, "event"))
- {
- if ((b=strtok(NULL," \t\n\r"))==NULL)
- {
- printf(_("Malformed event bind in %s at line %d\n"),filename,lineno);
- free(backup);
- free(header);
- continue;
- }
-
- if (AddLink(&event_list, b, ""))
- {
- printf(_("Event bind already exists. Useless instruction at line %d in %s.\n"), lineno, filename);
- }
- }else
- /* bind ipc function */
- if (!strcasecmp(a, "ipc"))
- {
- if ((b=strtok(NULL," \t\n\r"))==NULL)
- {
- printf(_("Malformed ipc in %s at line %d\n"),filename,lineno);
- free(backup);
- free(header);
- continue;
- }
-
- if (AddLink(&ipc_list, b, ""))
- {
- printf(_("IPC bind already exists. Useless instruction at line %d in %s.\n"), lineno, filename);
- }
- }else
- /* allow user to bind log on/off functions */
- if (!strcasecmp(a, "checkonoff"))
- {
- if ((b=strtok(NULL," \t\n\r"))==NULL)
- {
- printf(_("Malformed checkonoff bind in %s at line %d\n"),filename,lineno);
- free(backup);
- free(header);
- continue;
- }
-
- if (AddLink(&onoff_list, b, ""))
- {
- printf(_("Checkonoff bind already exists. Useless instruction at line %d in %s.\n"), lineno, filename);
- }
- }else
- /* allow user to bind shutdown functions */
- if (!strcasecmp(a, "shutdown"))
- {
- if ((b=strtok(NULL," \t\n\r"))==NULL)
- {
- printf(_("Malformed shutdown bind in %s at line %d\n"),filename,lineno);
- free(backup);
- free(header);
- continue;
- }
-
- if (AddLink(&shutdown_list, b, ""))
- {
- printf(_("Shutdown bind already exists. Useless instruction at line %d in %s.\n"), lineno, filename);
- }
- }else
- /* allow user to bind force functions */
- if (!strcasecmp(a, "force"))
- {
- /* force has been removed - this is a no-op */
- }else
- /* load mw-script functions */
- if (!strcasecmp(a,"function"))
- {
- if ((b=strtok(NULL," \t\n\r"))==NULL)
- {
- printf(_("Malformed Script Function declaration in %s at line %d\n"),filename,lineno);
- free(backup);
- free(header);
- continue;
- }
- /* set function to 'normal' */
- LoadFunction(b, header, file, &lineno, filename, 0);
- }else
- /* load mw-script functions (local, hidden function) */
- if (!strcasecmp(a,"lfunction"))
- {
- if ((b=strtok(NULL," \t\n\r"))==NULL)
- {
- printf(_("Malformed Script Function declaration in %s at line %d\n"),filename,lineno);
- free(backup);
- free(header);
- continue;
- }
- /* set function to 'non-interface' (local) */
- LoadFunction(b, header, file, &lineno, filename, FUNCFLAG_LOCAL);
- }else
- /* load mw-script initialisation function */
- if (!strcasecmp(a,"initfunc"))
- {
- if ((b=strtok(NULL," \t\n\r"))==NULL)
- {
- printf(_("Malformed Script Init declaration in %s at line %d\n"),filename,lineno);
- free(backup);
- free(header);
- continue;
- }
- /* set function to 'init' */
- LoadFunction(b, header, file, &lineno, filename, FUNCFLAG_AUTOINIT);
- }else
- /* load a local, hidden mw-script initialisation function */
- if (!strcasecmp(a,"linitfunc"))
- {
- if ((b=strtok(NULL," \t\n\r"))==NULL)
- {
- printf(_("Malformed Script Init declaration in %s at line %d\n"),filename,lineno);
- free(backup);
- free(header);
- continue;
- }
- /* set function to 'init' and 'non-interface'*/
- LoadFunction(b, header, file, &lineno, filename, FUNCFLAG_AUTOINIT | FUNCFLAG_LOCAL);
- }else
- /* load mw-script board initialisation function */
- if (!strcasecmp(a,"boardfunc"))
- {
- if ((b=strtok(NULL," \t\n\r"))==NULL)
- {
- printf(_("Malformed Script BoardInit declaration in %s at line %d\n"),filename,lineno);
- free(backup);
- free(header);
- continue;
- }
- /* set function to 'boardinit' */
- LoadFunction(b, header, file, &lineno, filename, FUNCFLAG_BOARDINIT);
- }else
- /* load a local, hidden mw-script board initialisation function */
- if (!strcasecmp(a,"lboardfunc"))
- {
- if ((b=strtok(NULL," \t\n\r"))==NULL)
- {
- printf(_("Malformed Script BoardInit declaration in %s at line %d\n"),filename,lineno);
- free(backup);
- free(header);
- continue;
- }
- /* set function to 'init' and 'non-interface'*/
- LoadFunction(b, header, file, &lineno, filename, FUNCFLAG_BOARDINIT | FUNCFLAG_LOCAL);
- }else
- printf(_("Loading file %s unrecognised command '%s' on line %d\n"),filename, a, lineno);
+ } else {
+ /* mwscript has gone but we don't want to break old .mwrc's */
+ const char *noopfuncs[] = {
+ "alias",
+ "bind",
+ "rpc",
+ "destroy",
+ "event",
+ "ipc",
+ "checkonoff",
+ "shutdown",
+ "force",
+ "function",
+ "lfunction",
+ "initfunc",
+ "linitfunc",
+ "boardfunc",
+ "lboardfunc",
+ NULL
+ };
+ int noop = 0;
+ for (int i = 0; noopfuncs[i] != NULL; i++) {
+ if (!strcasecmp(a, noopfuncs[i])) {
+ noop = 1;
+ break;
+ }
+ }
+ if (!noop)
+ fprintf(stderr, _("Loading file %s unrecognised command '%s' on line %d\n"),
+ filename, a, lineno);
+ }
free(backup);
free(header);
}
=====================================
src/client/talker.c
=====================================
@@ -338,7 +338,7 @@ void t_mwrc(CommandList *cm, int argc, const char **argv, char *args)
}
}
-extern int do_warn_of_mwscript_death;
+extern int mwrc_loaded;
void t_restart(CommandList *cm, int argc, const char **argv, char *args)
{
extern var_list_t var_list;
@@ -361,7 +361,7 @@ void t_restart(CommandList *cm, int argc, const char **argv, char *args)
RoomDestroy(&user->room);
- do_warn_of_mwscript_death = 0;
+ mwrc_loaded = 0;
RoomInit(&user->room);
LoadRoom(&user->room, user->record.room);
View it on GitLab: https://projects.sucs.org/milliways/mw/compare/3d5db0e9544516cdf710c984ac92679ebd414b98...260304b4e024c0233a549dd1e04330c4e17c0cdc
--
View it on GitLab: https://projects.sucs.org/milliways/mw/compare/3d5db0e9544516cdf710c984ac92679ebd414b98...260304b4e024c0233a549dd1e04330c4e17c0cdc
You're receiving this email because of your account on projects.sucs.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.sucs.org/pipermail/mw-devel/attachments/20190407/49a2c2a0/attachment-0001.html>
More information about the mw-devel
mailing list