Commit 198a83a2 authored by Andrew Price's avatar Andrew Price

Remove a bunch of mwscript stuff

parent 1e2615b6
Pipeline #565 passed with stage
in 10 minutes and 16 seconds
......@@ -45,7 +45,6 @@
#define RUNAWAY 1200
#define MAXRUNAWAY 5000
#define FLOODLIMIT 15
#define RIGHTS_BBS 0
#define RIGHTS_TALK 1
......
......@@ -150,37 +150,6 @@ struct alarm *alarm_at(const struct timeval *when, void *what, void (*how)(void
return temp;
}
static void set_flag(void *flag)
{
if (flag != NULL) *(int *)flag = 1;
}
void alarm_sleep(struct timeval *delay, int resume)
{
volatile int flag;
struct alarm *alrm;
struct timeval finish;
flag = 0;
do {
alrm = alarm_after(delay->tv_sec, delay->tv_usec, (void *)&flag, &set_flag);
select(0, NULL, NULL, NULL, delay);
if (flag)
timerclear(delay);
else
{
gettimeofday(&finish, NULL);
alrm->how = NULL;
timersub(&alrm->when, &finish, delay);
if (timercmp(delay, &zero_time, <=))
{
delay->tv_sec = 0;
delay->tv_usec = 1;
}
}
} while (!flag && resume);
}
int alarm_select(int maxfd, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout)
{
int nfds;
......
......@@ -21,7 +21,6 @@ void alarm_cleanup(void);
void alarm_handler(int sig);
struct alarm *alarm_at(const struct timeval *when, void *what, void (*how)(void *));
struct alarm *alarm_after(long secs, long usecs, void *what, void (*how)(void *));
void alarm_sleep(struct timeval *delay, int resume);
int alarm_select(int maxfd, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout);
#endif /* ALARM_H */
......@@ -167,7 +167,7 @@ char *list_bind(const char *text, int state)
name = bind->from;
bind = bind->next;
if ((len == 0) || !strncasecmp(name, text, len))
return dupstr(name, "");
return strdup(name);
}
return NULL;
}
......
......@@ -61,7 +61,6 @@ CommandList chattable[]={
{"sa" ,0x0000 ,2, "Usage: sayto <user> <message>", "Talk normally but only to a single user", t_sayto, 1},
{"say" ,0x0000 ,2, "Usage: say <user> <message>", "Talk normally but only to a single user (deprecated)", t_sayto_warn, 0},
{"sayto" ,0x0000 ,2, "Usage: sayto <user> <message>", "Talk normally but only to a single user", t_sayto, 1},
{"scrhelp" ,0x0200 ,0, "Usage: scrhelp [command]", "List available script commands, or help on [command]", t_scrhelp, 1},
{"script" ,0x0200 ,0, "Usage: script [function]", "List script functions, or source code for [function]", t_script, 1},
{"shout" ,0x0000 ,1, "Usage: shout <message>", "Send message to all rooms", t_shout, 1},
{"spy" ,0x0100 ,1, "Usage: spy <on|off>", "Spy mode - see who said what", t_spy, 1},
......@@ -78,7 +77,6 @@ CommandList chattable[]={
{"unprotect" ,0x0020 ,1, "Usage: unprotect <user>", "Remove protection from user", t_unprotect, 1},
{"uptime" ,0x0000 ,0, "Usage: uptime", "Show server uptime", t_uptime, 1},
{"uri" ,0x0000 ,0, "Usage: uri [list [*|username] [n] | delete <id> | nsfw <id> | membersonly <id> | anonymous <id> | displaymode <full|short>]", "View/Edit the uris in the mwuri database", t_uri, 1},
{"variables" ,0x0200 ,0, "Usage: variables [mask]", "List script variables + contents [or starting with mask]", t_showvars, 1},
{"what" ,0x0000 ,0, "Usage: what", "See peoples status", t_what, 1},
{"whisper" ,0x0000 ,2, "Usage: whisper <user> <message>", "Send a message to a single user", t_whisper, 1},
{"who" ,0x0000 ,0, "Usage: who", "See who's about", t_who, 1},
......
This diff is collapsed.
#ifndef EXPAND_H
#define EXPAND_H
#include "script.h"
struct expand_buf
{
char *start, *pos;
int capacity;
};
/*typedef int var_func_t(var_op_t *op, void *arg);*/
extern char parse_error[];
const char *eval_str(char *arg);
/*int call_with_var_op(char *varname, var_func_t *func, void *arg);*/
int eval_var(const char *name, var_op_t *op);
void expand_close(void);
#endif /* EXPAND_H */
......@@ -24,21 +24,6 @@ static struct hashrec *hash_enter(const hash_op_t *op);
/*static struct hashrec *freerecs = 0;*/
static union fieldrec *freefields = NULL;
void hash_setup(void)
{
maxfields = INITIALFIELDS;
fields = calloc(maxfields , sizeof(*fields));
nextfield = 0;
capacity = INITIALBUCKETS;
buckets = calloc(capacity, sizeof(*buckets));
}
void hash_shutdown(void)
{
free(buckets);
free(fields);
}
int hash_alloc(void)
{
int newfield;
......
......@@ -50,8 +50,6 @@ typedef struct {
extern union fieldrec *fields;
extern int code;
extern void hash_setup(void);
extern void hash_shutdown(void);
extern int hash_alloc(void);
void hash_free(int field);
void hash_iterate(struct hashrec ***iter, int field);
......
......@@ -28,6 +28,8 @@
extern struct user * const user;
struct alarm *timeout_event = NULL;
int interrupt = 1;
int js_flood;
int js_flood_limit = JS_FLOOD_LIMIT_DEFAULT;
duk_context *ctx;
......@@ -403,8 +405,8 @@ static duk_ret_t js_say(duk_context *cx)
fprintf(stderr, "mwjs error: say() requires an argument\n");
return DUK_RET_SYNTAX_ERROR;
}
flood++;
if (flood > flood_limit) {
js_flood++;
if (js_flood > js_flood_limit) {
fprintf(stderr, "mwjs error: Script exceeded flood limit\n");
return DUK_RET_ERROR;
}
......
......@@ -26,4 +26,8 @@ enum bindtype {
const char *js_command_name_get(int x);
extern int js_flood;
#define JS_FLOOD_LIMIT_DEFAULT 15
extern int js_flood_limit;
#endif /* JS_H */
......@@ -673,8 +673,6 @@ int main(int argc, char **argv)
* we run the autoexec functions, so wholist etc can arrive */
idle( -1, 1);
/* initialise script variables */
script_init();
setup_js();
/* clear transient talker flags */
......@@ -896,8 +894,6 @@ void close_down(int logofftype, char *sourceuser, char *reason)
DestroyAllLinks(&ipc_list);
DestroyAllLinks(&shutdown_list);
ScriptCleanup();
RoomDestroy(&user->room);
ClearStack();
stop_js();
......@@ -1234,16 +1230,6 @@ void reset_timeout(int secs)
/* start of Readline Commands */
char *dupstr(const char *text, const char *prepend)
{
char *c;
c=(char *)malloc(strlen(text)+1+strlen(prepend));
strcpy(c,prepend);
strcat(c,text);
return(c);
}
static char *strip_commandname(char *line)
{
char *l2 = strdup(line);
......@@ -1565,9 +1551,13 @@ char *list_commands(const char *text, int state)
if (!strncasecmp(name, rtext, len) &&
( table[i].Rights==0 || ((rights&table[i].Rights)==table[i].Rights)))
{
const char *pre = cm_test(user, CM_ONCHAT) ? CMD_BOARD_STR : "";
char *ret;
free(rtext);
i++;
return (dupstr(name, cm_test(user, CM_ONCHAT) ? CMD_BOARD_STR : ""));
asprintf(&ret, "%s%s", pre, name);
return ret;
}
i++;
}
......@@ -1596,8 +1586,12 @@ char *list_chat_commands(const char *text, int state)
(chattable[i].Rights==0 || ((rights&chattable[i].Rights)==chattable[i].Rights)) &&
(chattable[i].Show == 1))
{
const char *pre = cm_test(user, CM_ONCHAT) ? CMD_TALK_STR : "";
char *ret;
i++;
return (dupstr(name, cm_test(user, CM_ONCHAT) ? CMD_TALK_STR:""));
asprintf(&ret, "%s%s", pre, name);
return ret;
}
i++;
}
......@@ -1626,7 +1620,7 @@ char *find_folder(const char *text, int state)
&& (allowed_r(fol,user)
|| allowed_w(fol,user))) /*allowed*/
if (len==0 || !strncasecmp(text,fol->name,len))
return (dupstr(fol->name, ""));
return strdup(fol->name);
}
close(file);
......@@ -1658,7 +1652,7 @@ char *part_user(const char *text, int status)
{
const char *name = usr.record.name;
if (len==0 || !strncasecmp(name, text, len))
return (dupstr(name, ""));
return strdup(name);
}
}
close(file);
......@@ -1682,7 +1676,7 @@ char *part_comm_user(const char *text, int status)
{
if (len==0 || !strncasecmp(partlist_user[ptr], text, len))
{
c=dupstr(partlist_user[ptr],"");
c = strdup(partlist_user[ptr]);
ptr++;
return(c);
}
......@@ -1708,7 +1702,7 @@ char *part_comm_search(const char *text, int status)
{
if (len==0 || !strncasecmp(partlist_search[ptr], text, len))
{
c=dupstr(partlist_search[ptr],"");
c = strdup(partlist_search[ptr]);
ptr++;
return(c);
}
......@@ -1734,7 +1728,7 @@ char *part_comm_folder(const char *text, int status)
{
if (len==0 || !strncasecmp(partlist_folder[ptr], text, len))
{
c=dupstr(partlist_folder[ptr],"");
c = strdup(partlist_folder[ptr]);
ptr++;
return(c);
}
......@@ -1760,7 +1754,7 @@ char *part_comm_mesg(const char *text, int status)
{
if (len==0 || !strncasecmp(partlist_mesg[ptr], text, len))
{
c=dupstr(partlist_mesg[ptr],"");
c = strdup(partlist_mesg[ptr]);
ptr++;
return(c);
}
......
......@@ -8,7 +8,6 @@ void printfile(const char *filename);
void reset_timeout(int secs);
int idle(int fd, int millis);
void set_rights(void);
char *dupstr(const char *text, const char *prepend);
char *part_user(const char *text, int status);
char *part_comm_search(const char *text, int status);
......
This diff is collapsed.
......@@ -218,8 +218,6 @@ struct function {
struct function *next;
};
extern int flood;
extern int flood_limit;
extern int script_terminate;
extern int script_debug;
extern var_list_t var_list;
......@@ -234,12 +232,7 @@ extern int script_offset;
extern volatile int script_output;
extern char *event_user;
char *eval_arg(char *arg, int argc, char **argv);
char ** makeargs(int argc, const char **argv, int offset);
char ** argv_shift(int argc, char **argv, int offset, int *newsize);
void CallFunction(struct code *code, int argc, char **argv);
int ExecInst(char *line);
void scr_devel_msg(struct code *pc, const char *fmt, ...) __attribute__((format(printf,2,3)));
void RunInitFuncs(int talkinit);
int arg_count(var_list_t *list);
......@@ -250,25 +243,16 @@ char *list_script(const char *text, int state);
char *list_mwsfile(const char *text, int state);
int expand_script_dir(char **dir);
void var_str_force_2(const char *name, const char *val);
char *var_str_val(var_op_t *op);
void var_key_dup(var_op_t *op);
extern void DoScript(char *line);
int ExecScript(const char *name, var_list_t *args, int bound);
int ExecEvent(char *script, const char *text, const char *event, const char *who, int pre);
int ExecEvent2(char *script, const char *event, const char *who, int pre, int numargs, char *aargs[]);
void ListScript(const char *name);
void ListVars(const char *srch);
void ScriptCleanup(void);
void DestroyAllFunctions(int debug);
void DestroyFunction(const char *funcname);
void DestroyVariables(int debug);
void script_init(void);
void scr_helpfile(const char *args);
void scr_helplist(void);
#endif /* SCRIPT_H */
This diff is collapsed.
#ifndef SCRIPT_INST_H
#define SCRIPT_INST_H
#include "script.h"
/*** Instruction set for the scripting language */
void scr_base( struct code *, int, char **);
void scr_beep( struct code *, int, char **);
void scr_boolopt( struct code *, int, char **);
void scr_case( struct code *, int, char **);
void scr_clearvars( struct code *, int, char **);
void scr_compare( struct code *, int, char **);
void scr_end( struct code *, int, char **);
void scr_exec( struct code *, int, char **);
void scr_getvar( struct code *, int, char **);
void scr_inlist( struct code *, int, char **);
void scr_input( struct code *, int, char **);
void scr_isanum( struct code *, int, char **);
void scr_ison( struct code *, int, char **);
void scr_jump( struct code *, int, char **);
void scr_listvars( struct code *, int, char **);
void scr_local( struct code *, int, char **);
void scr_logoninfo( struct code *, int, char **);
void scr_makestr( struct code *, int, char **);
void scr_math( struct code *, int, char **);
void scr_math2( struct code *, int, char **);
void scr_output( struct code *, int, char **);
void scr_print( struct code *, int, char **);
void scr_quit( struct code *, int, char **);
void scr_rand( struct code *, int, char **);
void scr_range( struct code *, int, char **);
void scr_regex( struct code *, int, char **);
void scr_return( struct code *, int, char **);
void scr_room( struct code *, int, char **);
void scr_roomnum( struct code *, int, char **);
void scr_say( struct code *, int, char **);
void scr_sayto( struct code *, int, char **);
void scr_sendipc( struct code *, int, char **);
void scr_sendrpc( struct code *, int, char **);
void scr_set( struct code *, int, char **);
void scr_showrunaway( struct code *, int, char **);
void scr_sleep( struct code *, int, char **);
void scr_split( struct code *, int, char **);
void scr_strcat( struct code *, int, char **);
void scr_string( struct code *, int, char **);
void scr_talkpriv( struct code *, int, char **);
void scr_time( struct code *, int, char **);
void scr_unset( struct code *, int, char **);
void scr_user( struct code *, int, char **);
void scr_version( struct code *, int, char **);
void scr_wholist( struct code *, int, char **);
int isanumul(const char *a, unsigned long *result, int onlydecimal);
int isanum(const char *a, int *result, int onlydecimal);
extern Instruction inst_table[];
#endif /* SCRIPT_INST_H */
......@@ -15,7 +15,6 @@
#include "str_util.h"
#include "strings.h"
#include "special.h"
#include "script_inst.h"
#include "js.h"
#include "sqlite.h"
#include "perms.h"
......@@ -35,6 +34,7 @@
#include "incoming.h"
#include "alias.h"
#include "onoff.h"
#include "script.h"
extern int busy; /* if true dont display messages i.e. during new/write */
extern unsigned long rights;
......@@ -194,11 +194,6 @@ void t_script(CommandList *cm, int argc, const char **argv, char *args)
if (argc<2) ListScript(NULL); else ListScript(argv[1]);
}
void t_showvars(CommandList *cm, int argc, const char **argv, char *args)
{
if (argc<2) ListVars(NULL); else ListVars(argv[1]);
}
void t_event(CommandList *cm, int argc, const char **argv, char *args)
{
/* no arguments */
......@@ -240,6 +235,62 @@ void t_unevent(CommandList *cm, int argc, const char **argv, char *args)
}
}
static int isanum(const char *a, int *result, int onlydecimal)
{
char *end;
if (a==NULL || strlen(a)<1) return(0);
*result=strtol(a, &end, 10);
if (*end==0)
{
return (1);
}
else if (!onlydecimal)
{
*result=strtol(a, &end, 16);
if (*end==0)
{
return (1);
}
else
{
return (0);
}
}
else
{
return (0);
}
}
static int isanumul(const char *a, unsigned long *result, int onlydecimal)
{
char *end;
if (a==NULL || strlen(a)<1) return(0);
*result=strtoul(a, &end, 10);
if (*end==0)
{
return (1);
}
else if (!onlydecimal)
{
*result=strtoul(a, &end, 16);
if (*end==0)
{
return (1);
}
else
{
return (0);
}
}
else
{
return (0);
}
}
void t_runaway(CommandList *cm, int argc, const char **argv, char *args)
{
extern unsigned long run_away;
......@@ -283,13 +334,12 @@ void t_runaway(CommandList *cm, int argc, const char **argv, char *args)
void t_flood(CommandList *cm, int argc, const char **argv, char *args)
{
extern int flood_limit;
int num = 0;
if (isanum(argv[1], &num, 1))
{
flood_limit = num;
printf("Flood limit set to value: %d\n", flood_limit);
js_flood_limit = num;
printf("Flood limit set to value: %d\n", js_flood_limit);
}
}
......@@ -341,12 +391,6 @@ void t_mwrc(CommandList *cm, int argc, const char **argv, char *args)
extern int mwrc_loaded;
void t_restart(CommandList *cm, int argc, const char **argv, char *args)
{
extern var_list_t var_list;
DestroyAllFunctions(0);
DestroyVariables(0);
VAR_NEWLIST(&var_list);
DestroyAllLinks(&bind_list); bind_list = NULL;
DestroyAllLinks(&alias_list); alias_list = NULL;
DestroyAllLinks(&rpc_list); rpc_list = NULL;
......@@ -605,15 +649,6 @@ void t_tcunames(CommandList *cm, int argc, const char **argv, char *args)
update_user(user);
}
/* SCRIPT HELP function */
void t_scrhelp(CommandList *cm, int argc, const char **argv, char *args)
{
if (argc>1)
scr_helpfile(argv[1]);
else
scr_helplist();
}
void t_debug(CommandList *cm, int argc, const char **argv, char *args)
{
int z=BoolOpt(argv[1]);
......@@ -1167,57 +1202,6 @@ void set_talk_rights(void)
current_rights = RIGHTS_TALK;
}
void sendipc(const char *to, const char *text, int bcast)
{
int count;
if (bcast)
{
count = ipc_send_to_all(IPC_SCRIPTIPC, text);
}
else
{
count = ipc_send_to_username(to, IPC_SCRIPTIPC, text);
}
if (count==0)
{
printf("User '%s' is not logged on.\n",to);
}else
{
if (bcast)
mwlog(user, "SENDIPB %s", text);
else
mwlog(user, "SENDIPC(%s) %s",to,text);
}
}
void sendrpc(const char *to, const char *type, const char *text, int bcast)
{
char buff[MAXTEXTLENGTH];
int count;
snprintf(buff, MAXTEXTLENGTH, "%s %s", type, text);
if(bcast)
{
count = ipc_send_to_all(IPC_SCRIPTRPC, buff);
}
else
{
count = ipc_send_to_username(to, IPC_SCRIPTRPC, buff);
}
if (count==0)
{
printf("User '%s' is not logged on.\n",to);
}else
{
if (bcast)
mwlog(user, "SENDRPB(%s) %s", type, text);
else
mwlog(user, "SENDRPC(%s, %s) %s", to, type, text);
}
}
void enter_talker(int logontype)
{
extern int autowho;
......
......@@ -6,7 +6,6 @@
/* talker command functions */
void t_bind(CommandList *cm, int argc, const char **argv, char *args);
void t_unbind(CommandList *cm, int argc, const char **argv, char *args);
void t_scrhelp(CommandList *cm, int argc, const char **argv, char *args);
void t_who(CommandList *cm, int argc, const char **argv, char *args);
void t_what(CommandList *cm, int argc, const char **argv, char *args);
void t_help(CommandList *cm, int argc, const char **argv, char *args);
......@@ -51,7 +50,6 @@ void t_sticky(CommandList *cm, int argc, const char **argv, char *args);
void t_tcunames(CommandList *cm, int argc, const char **argv, char *args);
void t_spy(CommandList *cm, int argc, const char **argv, char *args);
void t_sproof(CommandList *cm, int argc, const char **argv, char *args);
void t_showvars(CommandList *cm, int argc, const char **argv, char *args);
void t_linewrap(CommandList *cm, int argc, const char **argv, char *args);
void t_mwrc(CommandList *cm, int argc, const char **argv, char *args);
void t_uri(CommandList *cm, int argc, const char **argv, char *args);
......@@ -72,9 +70,6 @@ void enter_talker(int logontype);
int screen_h(void);
int screen_w(void);
void sendipc(const char *to, const char *text, int broadcast);
void sendrpc(const char *to, const char *type, const char *text, int broadcast);
int ChangeRoom(char *room, int quiet);
void enter_room(int room);
......
......@@ -654,7 +654,7 @@ char *uri_action_tc(const char *text, int state)
}
if(do_tc)
{
c=dupstr(uritable[i].action,"");
c = strdup(uritable[i].action);
i++;
return(c);
}
......@@ -703,7 +703,7 @@ char *uri_arg_tc(const char *text, int state)
{
if ((len==0 || !strncasecmp(uri_displaymodes[ptr], text, len)) && strcmp(uri_displaymodes[ptr], ""))
{
c=dupstr(uri_displaymodes[ptr],"");
c = strdup(uri_displaymodes[ptr]);
ptr++;
return(c);
}
......
/* vars.c
* Functions for manipulating variable lists.
* Includes linked-list and hashtable versions.
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "expand.h"
char *var_str_val(var_op_t *op)
{
static char numtext[20];
if (VAR_TYPE_STR(op))
return ((char *)(**(op)->rec).data.pdata);
else
{
snprintf(numtext, 19, "%d", VAR_INT_VAL(op));
return numtext;
}
}
void var_key_dup(var_op_t *op)
{
op->key = strdup(op->key);
}
int arg_count(var_list_t *list)
{
var_op_t op;
VAR_OP_INIT(&op, list);
VAR_SEARCH(&op, "#");
if (!VAR_FOUND(&op))
return 0;
else if (!VAR_TYPE_INT(&op))
return 0;
else
return VAR_INT_VAL(&op);
}
void var_str_force_2(const char *name, const char *val)
{
var_op_t op;
if (eval_var(name, &op))
{
if (VAR_FOUND(&op))
{
if (script_debug) printf("- updating var $%s (%s) to '%s'\n", name, var_str_val(&op), val);
VAR_STR_UPDATE(&op, val);
} else
{
if (script_debug) printf("- creating var $%s setting to '%s'\n", name, val);
VAR_STR_CREATE(&op, val);
}
VAR_KEY_FREE(&op);
}
}
int var_isanum(var_op_t *op, int *result, int onlydecimal)
{
extern int isanum(char *a, int *result, int onlydecimal);
if (VAR_FOUND(op))
{
if (VAR_TYPE_INT(op))
{
*result = VAR_INT_VAL(op);
return 1;
} else if (VAR_TYPE_STR(op))
{
return isanum(var_str_val(op), result, onlydecimal);
}
}
return 0;
}
......@@ -160,7 +160,7 @@ char *part_who(const char *text, int status)
/* found the one we want */
if (count == index) {
index++;
return dupstr(name,"");
return strdup(name);