[mw-devel] [Git][milliways/mw][master] Logon/join/leave/logoff improvements

Andrew Price welshbyte at sucs.org
Sat Apr 6 19:01:36 BST 2019


Andrew Price pushed to branch master at milliways / mw


Commits:
3222e3af by Andrew Price at 2019-04-06T17:58:00Z
Logon/join/leave/logoff improvements

Don't send separate messages to announce these events, have mw display
them on receipt of onoff events, if scripted handlers allow it to.

- - - - -


3 changed files:

- src/client/incoming.c
- src/client/main.c
- src/client/talker.c


Changes:

=====================================
src/client/incoming.c
=====================================
@@ -114,6 +114,24 @@ void ClearStack(void) {
 	MesgStacked=0;
 }
 
+static void display_onoff(int action, const char *name, int room)
+{
+	switch (action) {
+	case ONOFF_LEAVE:
+		format_message("\03311* %s has just left the talker.", name);
+		break;
+	case ONOFF_JOIN:
+		format_message("\03310* %s has just joined talker room %d.", name, room);
+		break;
+	case ONOFF_LOGOFF:
+		format_message("\03302* %s has just left the board.", name);
+		break;
+	case ONOFF_LOGON:
+		format_message("\03301* %s has just entered the board.", name);
+		break;
+	}
+}
+
 void DisplayStack(void)
 {
 	struct mstack	*new;
@@ -203,13 +221,14 @@ void DisplayStack(void)
 				};
 				char *onoff_name;
 				const char *uname, *reason;
-				int ccode, isquiet, action, type;
+				int ccode, isquiet, action, type, room = 0;
 				struct mwevent ev = {
 						.ev_type = MWEV_TYPE_ONOFF,
 						.ev_data.onoff = new->msg,
 				};
 				script_output = 1;
-				js_handle_event(&ev);
+				if (cp_test(user, CP_SCRIPT))
+					js_handle_event(&ev);
 
 				/* go through list and find checkonoff function */
 				onoff_name = NULL;
@@ -227,6 +246,8 @@ void DisplayStack(void)
 					reason = json_getstring(j, "reason");
 				else
 					reason = json_getstring(j, "message");
+				if (action == ONOFF_JOIN)
+					room = json_getint(j, "channel");
 
 				if (action >= ONOFF_SIZE)
 					break;
@@ -286,7 +307,10 @@ void DisplayStack(void)
 				a.version[0] = '3';
 				if (reason != NULL)
 					snprintf(a.reason, MAXTEXTLENGTH - 1, "%s", reason);
-				ExecEvent2(onoff_name, "CheckOnOff", new->from, 0, 6, aargs);
+				if (cp_test(user, CP_SCRIPT))
+					ExecEvent2(onoff_name, "CheckOnOff", new->from, 0, 6, aargs);
+				if (script_output && !isquiet)
+					display_onoff(action, uname, room);
 				break;
 			}
 			default:
@@ -554,15 +578,13 @@ static void display_content(ipc_message_t *msg)
 		}
 	} else
 	if (msg->head.type == IPC_CHECKONOFF) {
-		if (cp_test(user, CP_SCRIPT)) {
-			struct mstack *ms;
-
-			ms = calloc(1, sizeof(*ms));
-			ms->flags = MST_SCREV;
-			ms->preamble = EST_CHECKONOFF;
-			ms->from = strdup(whom);
-			InsertMesg(ms, msg);
-		}
+		struct mstack *ms;
+
+		ms = calloc(1, sizeof(*ms));
+		ms->flags = MST_SCREV;
+		ms->preamble = EST_CHECKONOFF;
+		ms->from = strdup(whom);
+		InsertMesg(ms, msg);
 	} else {
 		printf("Unknown message type %4.4s", (char *)&msg->head.type);
 	}
@@ -980,9 +1002,6 @@ static void zod(const char *from, const char *msg)
 	printf(_("%s just sent the Zebedee of Death to you.\n"),from);
 	fflush(stdout);
 
-	/* broadcast leaving message if not quiet */
-	if (!quietmode) broadcast(4|0x100, "\03311%s has just left the talker", user->record.name);
-
 	/* set 'off talker' permissions for commands */
 	set_rights();
 	disable_rl(1);


=====================================
src/client/main.c
=====================================
@@ -633,17 +633,13 @@ int main(int argc, char **argv)
 	if (login_status == 3) /* Autoregistered */
 		broadcast(3, "Auto-registered %s", user->record.name);
 
+	quietmode = 0;
 	if ((s_quiet(user) || u_god(user)) && qflag)
 	{
 		extern int talker_logontype;
 		quietmode=1;
 		talker_logontype |= LOGONMASK_QUIET;
-	}else
-	{
-		broadcast(1, _("\03301%s has just entered the board."),user->record.name);
-		quietmode=0;
 	}
-
 	{
 		struct sockaddr_in sa;
 		socklen_t ss;
@@ -907,9 +903,6 @@ void close_down(int logofftype, char *sourceuser, char *reason)
 	stop_js();
 	alarm_cleanup();
 
-	if (!quietmode && logofftype != LOGOFF_TIMEOUT && logofftype != LOGOFF_EOFS)
-		broadcast(1, "\03302%s has just left the board.", user->record.name);
-
 	mwlog(user, "LOGOUT");
 	sleep(1); //dodgy hack for race condition in checkonoff, cunningly we currently get woken by the very message we're waiting for.
 


=====================================
src/client/talker.c
=====================================
@@ -183,12 +183,8 @@ void t_uptime(CommandList *cm, int argc, const char **argv, char *args)
 
 void t_quit(CommandList *cm, int argc, const char **argv, char *args)
 {
-	char text[MAXTEXTLENGTH];
 	user->record.chatmode = cm_clear(user, CM_ONCHAT);
 	update_user(user);
-	snprintf(text, MAXTEXTLENGTH-1, "\03311%s has just left the talker", user->record.name);
-	if (!quietmode) talk_send_rawbcast(text);
-
 	announce_leave(user->record.name, user->record.room, LEAVE_NORMAL, NULL, NULL, quietmode);
 	set_rights();
 }
@@ -1106,25 +1102,15 @@ void t_uri(CommandList *cm, int argc, const char **argv, char *args)
 void t_chaton(void)
 {
 	struct person *urec = &user->record;
-	char text[MAXTEXTLENGTH];
-	char mtext[MAXTEXTLENGTH];
 
 	set_talk_rights();
-
 	/* set mode to 'on talker', and update whofile for autoexec function */
 	urec->chatmode = cm_set(user, CM_ONCHAT);
 	update_user(user);
 
-	if (user->room.name!=NULL)
-		snprintf(mtext, MAXTEXTLENGTH-1, "\03310%s has just joined talker in %s",
-		         urec->name, user->room.name);
-	else
-		snprintf(mtext, MAXTEXTLENGTH-1, "\03310%s has just joined talker room %d",
-		         urec->name, urec->room);
-	snprintf(text, MAXTEXTLENGTH-1, "\03310%s has just joined talker room %d",
-	         urec->name, urec->room);
-	if (!quietmode) talk_send_rawbcast(text);
-	printf("Now entering the talker. Use \".quit\" to leave and \".help\" for help.\n");
+	format_message("\03310* Joining talker room %d. "
+	               "Use \".quit\" to leave and \".help\" for help.\n",
+	               urec->room);
 
 	/* run the common stuff for entering the talker */
 	enter_talker(1);



View it on GitLab: https://projects.sucs.org/milliways/mw/commit/3222e3aff79e979a45ee3a56c5d5b3279ea71488

-- 
View it on GitLab: https://projects.sucs.org/milliways/mw/commit/3222e3aff79e979a45ee3a56c5d5b3279ea71488
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/20190406/d33d646f/attachment-0001.html>


More information about the mw-devel mailing list