[mw-devel] [Git][arthur/mw][master] js-duk: Implement exit events
Andrew Price
welshbyte at sucs.org
Mon Nov 5 23:19:11 GMT 2018
Andrew Price pushed to branch master at Justin Mitchell / mw
Commits:
b1196d3a by Andrew Price at 2018-11-05T23:14:30+00:00
js-duk: Implement exit events
Replaces bind(K_BIND_SHUTDOWN, ...)
function handler(ev)
{
switch (ev.type) {
...
case "exit":
mrodder = ev.data;
if (mrodder)
mw.print("Your mw session was killed by " + mrodder);
break;
...
}
}
mw.onevent.push(handler);
- - - - -
5 changed files:
- src/client/event.h
- src/client/incoming.c
- src/client/incoming.h
- src/client/js-duk.c
- src/client/main.c
Changes:
=====================================
src/client/event.h
=====================================
--- a/src/client/event.h
+++ b/src/client/event.h
@@ -8,6 +8,7 @@ typedef enum {
MWEV_TYPE_MSG,
MWEV_TYPE_ONOFF,
MWEV_TYPE_INPUT,
+ MWEV_TYPE_EXIT,
} mwev_type_t;
struct mwevent {
@@ -16,6 +17,7 @@ struct mwevent {
ipc_message_t *msg; /* MWEV_TYPE_MSG */
ipc_message_t *onoff; /* MWEV_TYPE_ONOFF */
const char *input; /* MWEV_TYPE_INPUT */
+ const char *mrodder; /* MWEV_TYPE_EXIT */
} ev_data;
};
=====================================
src/client/incoming.c
=====================================
--- a/src/client/incoming.c
+++ b/src/client/incoming.c
@@ -41,7 +41,6 @@ extern ipc_connection_t *ipcsock;
int new_mail_waiting=0;
int mesg_waiting = 0;
-char *mrod_user=NULL;
static int MesgStacked=0;
static struct mstack *MesgStack=NULL;
@@ -1006,10 +1005,6 @@ static void mrod(char *from, char *msg)
display_message(mrod_message, 1, 1);
}
fflush(stdout);
-
fix_terminal();
-
- mrod_user = malloc(sizeof(char) * (strlen(from) + 1));
- strcpy(mrod_user, from);
close_down(LOGOFF_MROD, from, msg);
}
=====================================
src/client/incoming.h
=====================================
--- a/src/client/incoming.h
+++ b/src/client/incoming.h
@@ -27,7 +27,6 @@ struct mstack
};
extern int new_mail_waiting;
-extern char *mrod_user;
void incoming_mesg(int ignore);
void handle_mesg(void);
=====================================
src/client/js-duk.c
=====================================
--- a/src/client/js-duk.c
+++ b/src/client/js-duk.c
@@ -901,6 +901,14 @@ static int js_push_event(struct mwevent *ev)
duk_put_prop_string(ctx, idx, "data");
ret = 0;
break;
+ case MWEV_TYPE_EXIT:
+ duk_require_stack(ctx, 2);
+ duk_push_string(ctx, "exit");
+ duk_put_prop_string(ctx, idx, "type");
+ duk_push_string(ctx, ev->ev_data.mrodder);
+ duk_put_prop_string(ctx, idx, "data");
+ ret = 0;
+ break;
case MWEV_TYPE_NONE:
/* Fall through */
default:
=====================================
src/client/main.c
=====================================
--- a/src/client/main.c
+++ b/src/client/main.c
@@ -855,14 +855,20 @@ void close_down(int logofftype, char *sourceuser, char *reason)
/* if scripts are available */
if (cp_test(user, CP_SCRIPT))
{
+ struct mwevent ev = {
+ .ev_type = MWEV_TYPE_EXIT,
+ .ev_data.mrodder = sourceuser,
+ };
char *shutdown_name;
+ js_handle_event(&ev);
/* find the shutdown function */
shutdown_name = NULL;
if ((shutdown_name = NextLink(shutdown_list, shutdown_name)) != NULL)
{
/* if SU, give user who kicked us off if present */
- if (u_god(user)) ExecEvent(shutdown_name, "", "ShutDown", mrod_user, 0);
+ if (u_god(user))
+ ExecEvent(shutdown_name, "", "ShutDown", sourceuser, 0);
/* otherwise, no info given */
else ExecEvent(shutdown_name, "", "ShutDown", NULL, 0);
}
@@ -881,7 +887,6 @@ void close_down(int logofftype, char *sourceuser, char *reason)
destroy_colours();
if (event_user != NULL) free(event_user);
if (event_body_text != NULL) free(event_body_text);
- if (mrod_user != NULL) free(mrod_user);
if (saved_rl_text != NULL) free(saved_rl_text);
colour_free();
DestroyAllLinks(&bind_list);
View it on GitLab: https://projects.sucs.org/arthur/mw/commit/b1196d3a4d48111e3c67e2763c381f943be3057d
--
View it on GitLab: https://projects.sucs.org/arthur/mw/commit/b1196d3a4d48111e3c67e2763c381f943be3057d
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/20181105/95211be6/attachment-0001.html>
More information about the mw-devel
mailing list