[mw-devel] MW3 r1176 - trunk/src/webclient

arthur at sucs.org arthur at sucs.org
Wed Oct 6 16:36:30 BST 2010


Author: arthur
Date: 2010-10-06 16:36:30 +0100 (Wed, 06 Oct 2010)
New Revision: 1176

Modified:
   trunk/src/webclient/Makefile
   trunk/src/webclient/comms.c
   trunk/src/webclient/comms.h
   trunk/src/webclient/import.c
   trunk/src/webclient/import.h
   trunk/src/webclient/mwpoll.c
Log:
announce arrive/depart from web talker


Modified: trunk/src/webclient/Makefile
===================================================================
--- trunk/src/webclient/Makefile	2010-10-06 12:40:41 UTC (rev 1175)
+++ trunk/src/webclient/Makefile	2010-10-06 15:36:30 UTC (rev 1176)
@@ -7,9 +7,8 @@
 HOMEPATH := $(libdir)/mw
 
 # cflags for standard 'cc' compiler
-CFLAGS+= -Wall -pedantic -fpie -std=gnu99 -D_GNU_SOURCE -I..
-LDFLAGS+= -pie
-LDLIBS+=
+CFLAGS= -Wall -pedantic --std=gnu99 -D_GNU_SOURCE -I..
+#LDFLAGS+= -pie
 
 # info strings, do not edit.
 DEFS:= -DBUILD_DATE=\"$(shell date +%Y%m%d)\"
@@ -27,7 +26,7 @@
 CFLAGS+= -ggdb -g -D__NO_STRING_INLINE -fstack-protector-all -std=c99
 
 ### Optimisation - uncomment for release & extra testing
-CFLAGS+=-O3
+#CFLAGS+=-O3
 
 ### Only ever uncomment for final release versions
 DEFS+= -DRELEASE

Modified: trunk/src/webclient/comms.c
===================================================================
--- trunk/src/webclient/comms.c	2010-10-06 12:40:41 UTC (rev 1175)
+++ trunk/src/webclient/comms.c	2010-10-06 15:36:30 UTC (rev 1176)
@@ -2,6 +2,7 @@
 #include <fcntl.h>
 #include <unistd.h>
 #include <stdio.h>
+#include <stdarg.h>
 #include <stdlib.h>
 #include <unistd.h>
 #include <time.h>
@@ -24,7 +25,7 @@
 extern int incoming_pipe;
 int command_sock;
 
-static int die = 0;
+int die = 0;
 
 #define min(a,b) a<b?a:b
 #define max(a,b) a>b?a:b
@@ -60,7 +61,9 @@
 
 struct list_head connlist;
 
+
 char * json_escape(char *in);
+static void handle_mesg();
 
 /* unix socket to accept control commands from */
 void open_command_socket()
@@ -107,9 +110,34 @@
         return (usr->room == f_info->channel);
 }
 
+static int send_filter_nonglobal(const struct person * usr, const struct who * who, const void * info) {
+        // Everyone outside a room with global turned off
+        struct filter_info *    f_info = (struct filter_info *) info;
 
+        if ((f_info->noloopback) && (getpid() == who->pid)) return 0;
+        if (! cm_flags(usr->chatmode, CM_ONCHAT, CM_MODE_ALL)) return 0;
+        if (cm_flags(usr->chatmode, CM_GLOBAL, CM_MODE_ALL)) return 0;
+
+        return (usr->room != f_info->channel);
+}
+
+static int send_filter_global(const struct person * usr, const struct who * who, const void * info) {
+        // Everyone with global turned on
+        struct filter_info *    f_info = (struct filter_info *) info;
+
+        if ((f_info->noloopback) && (getpid() == who->pid)) return 0;
+        if (! cm_flags(usr->chatmode, CM_ONCHAT, CM_MODE_ALL)) return 0;
+        if (! cm_flags(usr->chatmode, CM_GLOBAL, CM_MODE_ALL)) return 0;
+
+        if (usr->room == f_info->channel) return 1; // Users on the channel always get it
+        return 1;
+}
+
+
+
+
 /* we got a message */
-void accept_pipe_cmd(enum ipc_types state, char *newbuff, int mesg_pid, struct person *mesg_user)
+static void accept_pipe_cmd(enum ipc_types state, char *newbuff, int mesg_pid, struct person *mesg_user)
 {
 	MESG *msg = malloc(sizeof(MESG));
 	msg->state = state;
@@ -265,7 +293,7 @@
 
 		snprintf(&buff[len], sizeof(buff)-len, "{\"state\":%d,\"pid\":%d,\"username\":\"%s\",\"text\":\"%s\"}", tmp->state, tmp->pid, tmp->user.name, tmp->text);
 
-		if (tmp->state == IPC_KICK) die=1;
+		if (tmp->state == IPC_KICK) die=3;
 		free(tmp->text);
 		free(tmp);
 		n++;
@@ -382,7 +410,7 @@
 	return 0;
 }
 
-void handle_mesg()
+static void handle_mesg()
 {
         static uint32_t mesg_pid;
         long mesg_posn;
@@ -458,3 +486,33 @@
 	snprintf(path, UNIX_PATH_MAX, "/tmp/mwnoddy.%d", getpid());
 	unlink(path);
 }
+
+void talk_rawbcast(char *fmt, ...)
+{
+	va_list va;
+	struct filter_info f_info;
+	char *text = NULL;
+	char *form;
+
+
+	form = malloc(strlen(fmt) + 10);
+	snprintf(form, strlen(fmt) + 10, "*:%s", fmt);
+
+	bzero(&f_info, sizeof f_info);
+	f_info.channel = user->room;
+	f_info.noloopback = 1;
+
+	va_start(va, fmt);
+	vasprintf(&text, fmt, va);
+	va_end(va);
+	ipc_send_to_all(IPC_TEXT, text, send_filter_oneroom, &f_info);
+	ipc_send_to_all(IPC_TEXT, text, send_filter_nonglobal, &f_info);
+	free(text); text=NULL;
+	va_start(va, fmt);
+	vasprintf(&text, form, va);
+	va_end(va);
+	ipc_send_to_all(IPC_TEXT, text, send_filter_global, &f_info);
+	free(text);
+	free(form);
+
+}

Modified: trunk/src/webclient/comms.h
===================================================================
--- trunk/src/webclient/comms.h	2010-10-06 12:40:41 UTC (rev 1175)
+++ trunk/src/webclient/comms.h	2010-10-06 15:36:30 UTC (rev 1176)
@@ -2,7 +2,7 @@
 
 /* comms.c */
 void open_command_socket(void);
-void accept_pipe_cmd(enum ipc_types state, char *newbuff, int mesg_pid, struct person *mesg_user);
 int mainloop(int millis);
-void handle_mesg(void);
+char *json_escape(char *original);
 void close_cmd(void);
+void talk_rawbcast(char *fmt, ...);

Modified: trunk/src/webclient/import.c
===================================================================
--- trunk/src/webclient/import.c	2010-10-06 12:40:41 UTC (rev 1175)
+++ trunk/src/webclient/import.c	2010-10-06 15:36:30 UTC (rev 1176)
@@ -164,3 +164,22 @@
         *end = '\0';
 }
 
+void broadcast_onoffcode(int code, int method, const char *sourceuser, const char *reason)
+{
+        char            logofftext[MAXTEXTLENGTH];
+
+        /* create the broadcast string */
+        snprintf(logofftext, MAXTEXTLENGTH-1, "%d,%d,%d,%s", code, method, 0, sourceuser);
+
+        /* add an optional reason */
+        if (reason != NULL)
+        {
+                char    reasontext[MAXTEXTLENGTH];
+                snprintf(reasontext, MAXTEXTLENGTH - 1, "%s,%s", logofftext, reason);
+                snprintf(logofftext, MAXTEXTLENGTH - 1, "%s", reasontext);
+        }
+
+        /* send the message */
+        ipc_send_to_all(IPC_CHECKONOFF, logofftext, NULL, NULL);
+}
+

Modified: trunk/src/webclient/import.h
===================================================================
--- trunk/src/webclient/import.h	2010-10-06 12:40:41 UTC (rev 1175)
+++ trunk/src/webclient/import.h	2010-10-06 15:36:30 UTC (rev 1176)
@@ -1,13 +1,10 @@
-#include <ipc.h>
-
 /* import.c */
 int get_person(int file, struct person *tmp);
-char *get_pipe_name(int pid);
-void create_pipe(void);
 void update_user(struct person *record, int32_t userposn);
 unsigned long cm_flags(unsigned long cm, unsigned long flags, int mode);
-void open_fifo(void);
-void close_fifo(void);
-int ipc_send_to_pid(pid_t dest, enum ipc_types msgtype, const char *data);
 int32_t get_who_userposn(int pid);
 void fetch_user(struct person *record, int32_t userposn);
+void who_delete(int pid);
+char *quotetext(const char *a);
+void strip_quote(char *a);
+void broadcast_onoffcode(int code, int method, const char *sourceuser, const char *reason);

Modified: trunk/src/webclient/mwpoll.c
===================================================================
--- trunk/src/webclient/mwpoll.c	2010-10-06 12:40:41 UTC (rev 1175)
+++ trunk/src/webclient/mwpoll.c	2010-10-06 15:36:30 UTC (rev 1176)
@@ -29,6 +29,7 @@
 time_t lastcomm = 0;
 
 char *authtext = NULL;
+extern int die;
 
 int mydaemon(void)
 {
@@ -146,18 +147,46 @@
 	who_add(getpid(),userposn);
 	lastcomm = time(NULL);
 
+	/* spock, announce us please... */
+	//broadcast_onoffcode(3, 0, user->name, NULL);
+	talk_rawbcast("\03310%s has just joined web talker room %d", user->name);
+	broadcast_onoffcode(1, 0, user->name, NULL);
+
 	/* the main loop */
 	while (mainloop(1000)==0) {
 		time_t now = time(NULL);
 		update_user(user,userposn);
 		if ((now - lastcomm) > clientidle) {
 			printf("Client Idle out.\n");
+			die = 2;
 			break;
 		}
 	};
 
 	user->idletime=time(0);
+	user->chatmode=cm_flags(user->chatmode, CM_ONCHAT, CM_MODE_CLEAR);
 	update_user(user,userposn);
+	talk_rawbcast("\03311%s has just left web talker", user->name);
+	broadcast_onoffcode(0,0,user->name,NULL);
+#if 0
+	switch (die) {
+		case 1: /* requested logout */
+			broadcast_onoffcode(2, 0, user->name, NULL);
+			break;
+		case 2: /* idle out */
+			broadcast_onoffcode(2, 1, user->name, NULL);
+			break;
+		case 3: /* mrod/zod */
+			broadcast_onoffcode(2, 3, user->name, NULL);
+			break;
+		default:
+			broadcast_onoffcode(2, 0, user->name, NULL);
+			break;
+	}
+#endif
+
+	user->idletime=time(0);
+	update_user(user,userposn);
 	who_delete(getpid());
 	close_fifo();
 	close_cmd();




More information about the mw-devel mailing list