[mw-devel] MW3 r1393 - in trunk/src: . client server webclient

arthur at sucs.org arthur at sucs.org
Thu Sep 24 10:30:00 BST 2015


Author: arthur
Date: 2015-09-24 10:30:00 +0100 (Thu, 24 Sep 2015)
New Revision: 1393

Modified:
   trunk/src/client/folders.c
   trunk/src/client/main.c
   trunk/src/client/mesg.c
   trunk/src/client/script_inst.c
   trunk/src/client/talker.c
   trunk/src/client/who.c
   trunk/src/ipc.c
   trunk/src/ipc.h
   trunk/src/server/replay.c
   trunk/src/server/servsock.c
   trunk/src/server/servsock.h
   trunk/src/socket.h
   trunk/src/webclient/comms.c
   trunk/src/webclient/import.c
   trunk/src/who.c
   trunk/src/who.h
Log:
Purge the old mechanisms that sent messages to each user individually


Modified: trunk/src/client/folders.c
===================================================================
--- trunk/src/client/folders.c	2015-09-24 09:28:17 UTC (rev 1392)
+++ trunk/src/client/folders.c	2015-09-24 09:30:00 UTC (rev 1393)
@@ -89,5 +89,5 @@
 	Unlock_File(ufile);
 	close(ufile);
 	snprintf(buff,9,"%d:%d", folnum, 0);
-	ipc_send_to_all(IPC_LASTREAD, buff, NULL, NULL);
+	ipc_send_to_all(IPC_LASTREAD, buff);
 }

Modified: trunk/src/client/main.c
===================================================================
--- trunk/src/client/main.c	2015-09-24 09:28:17 UTC (rev 1392)
+++ trunk/src/client/main.c	2015-09-24 09:30:00 UTC (rev 1393)
@@ -1832,13 +1832,8 @@
 		lseek(ufile,w.posn,0);
 		read(ufile,&uu,sizeof(uu));
 
-		/* check they are still alive and show info */
-		if (! ipc_send_to_pid(w.pid, IPC_NOOP, NULL))
-		{
-			if (len==0 || !strncasecmp(uu.name,text,len))
-				return(dupstr(uu.name, ""));
-				/*return(duplstr(uu.name)); */
-		}
+		if (len==0 || !strncasecmp(uu.name,text,len))
+			return(dupstr(uu.name, ""));
 	}
 
 	close(wfile);
@@ -1875,14 +1870,9 @@
 		lseek(ufile,w.posn,0);
 		read(ufile,&uu,sizeof(uu));
 
-		/* check they are still alive and show info */
-		if (! ipc_send_to_pid(w.pid, IPC_NOOP, NULL))
-		{
-			if (cm_flags(uu.chatmode, CM_ONCHAT, CM_MODE_ALL) &&
-			   (len==0 || !strncasecmp(uu.name,text,len)))
-				return(dupstr(uu.name, ""));
-				/*return(duplstr(uu.name));*/
-		}
+		if (cm_flags(uu.chatmode, CM_ONCHAT, CM_MODE_ALL) &&
+		   (len==0 || !strncasecmp(uu.name,text,len)))
+			return(dupstr(uu.name, ""));
 	}
 
 	close(wfile);
@@ -2059,5 +2049,5 @@
 	}
 
 	/* send the message */
-	ipc_send_to_all(IPC_CHECKONOFF, logofftext, NULL, NULL);
+	ipc_send_to_all(IPC_CHECKONOFF, logofftext);
 }

Modified: trunk/src/client/mesg.c
===================================================================
--- trunk/src/client/mesg.c	2015-09-24 09:28:17 UTC (rev 1392)
+++ trunk/src/client/mesg.c	2015-09-24 09:30:00 UTC (rev 1393)
@@ -12,6 +12,10 @@
 #include "bb.h"
 #include "user.h"
 
+extern int32_t userposn;
+extern struct person *user;
+
+
 void send_mesg(char *from, const char *to, char *text, int wiz)
 {
 	char buff[MAXTEXTLENGTH];
@@ -55,47 +59,13 @@
 void postinfo(struct person *who, struct folder *fol, struct Header *mesg)
 {
         char buff[MAXTEXTLENGTH];
-        struct person user;
-        struct who w;
-        int ufile,wfile;
 
-        wfile=who_open(O_RDONLY);
-        ufile=userdb_open(O_RDONLY);
-        
-        while (read(wfile,&w,sizeof(w)))
-        {
-		/* Skip invalid entries */
-		if (w.posn < 0)
-			continue;
-
-                lseek(ufile,w.posn,0);
-		read(ufile,&user,sizeof(user));
-		
-		if (w.pid!=getpid() && s_postinfo(user.special))
-		{
-
-			/* destination user must be able to read the folder
-			  must be subscribed to it
-			  if private, must be addressed to them
-		   	  if moderated, just dont bother */
-			if (!allowed_r(fol, &user) 
-			|| !get_subscribe(&user, foldernumber(fol->name))
-			|| (is_private(fol,&user) && strcasecmp(mesg->to,user.name)) 
-			|| is_moderated(fol, &user))
-			{
-				continue;
-			}
-
-			if (is_private(fol,&user)) {
-				snprintf(buff, MAXTEXTLENGTH,"\03305INFO: New mail from %s in folder %s", who->name, fol->name);
-			} else {
-				snprintf(buff, MAXTEXTLENGTH,"\03303INFO: %s has just posted in folder %s", who->name, fol->name);
-			}
-			ipc_send_to_pid(w.pid, IPC_WIZ, buff);
-		}
+	if (is_private(fol,who)) {
+		snprintf(buff, MAXTEXTLENGTH,"\03305INFO: New mail from %s in folder %s", who->name, fol->name);
+	} else {
+		snprintf(buff, MAXTEXTLENGTH,"\03303INFO: %s has just posted in folder %s", who->name, fol->name);
 	}
-	close(ufile);
-	close(wfile);
+	ipc_send_to_all(IPC_TEXT, buff);
 }
 
 /* broadcast state  
@@ -111,9 +81,6 @@
 {
 	char buff[MAXTEXTLENGTH];
 	char text[MAXTEXTLENGTH];
-	struct person user;
-	struct who w;
-	int ufile,wfile;
 	va_list va;
 	int israw;
 
@@ -129,58 +96,39 @@
 	else if (state==2) mwlog("WIZ %s", text);
 	else if (state==5) mwlog("STATUS %s", text);
 
-	wfile=who_open(O_RDONLY);
-	ufile=userdb_open(O_RDONLY);
-	 
-	while (read(wfile,&w,sizeof(w)))
-	{
-		/* Skip invalid entries */
-		if (w.posn < 0)
-			continue;
+	switch (state) {
+		case 1:
+			snprintf(buff, MAXTEXTLENGTH, "\03304%s%s", israw?"":"SYSTEM: ", text);
+			ipc_send_to_all(IPC_TEXT, buff);
+			break;
+		case 2:
+			snprintf(buff, MAXTEXTLENGTH, "\03306%s%s", israw?"":"Wiz: ", text);
+			ipc_send_to_all(IPC_WIZ, buff);
+			break;
+		case 3:
+			snprintf(buff, MAXTEXTLENGTH, "\03303%s%s", israw?"":"CHANGE: ", text);
+			ipc_send_to_all(IPC_WIZ, buff);
+			break;
+		case 4:
+			snprintf(buff, MAXTEXTLENGTH, "\03304%s%s", israw?"":"SYSTEM: ", text);
+			ipc_send_to_all(IPC_TEXT, buff);
+			break;
+		case 5:
+			/* doing messages */
+			snprintf(buff, MAXTEXTLENGTH, "\03304STATUS: \03314%s",text);
+			ipc_message_t * msg = ipcmsg_create(IPC_SAYTOROOM, userposn);
+			ipcmsg_destination(msg, user->room);
+			json_t * j = json_init(NULL);
+			json_addstring(j, "text", buff);
+			ipcmsg_json_encode(msg, j);
+			json_decref(j);
+			ipcmsg_transmit(msg);
 
-		lseek(ufile,w.posn,0);
-		read(ufile,&user,sizeof(user));
-		switch (state) {
-			case 1:
-				if (!u_inform(user.status))
-				{
-					snprintf(buff, MAXTEXTLENGTH, "\03304%s%s", israw?"":"SYSTEM: ", text);
-					ipc_send_to_pid(w.pid, IPC_WIZ, buff);
-				}
-				break;
-			case 2:
-				if (s_wizchat(user.special) && !s_chatoff(user.special))
-				{
-					snprintf(buff, MAXTEXTLENGTH, "\03306%s%s", israw?"":"Wiz: ", text);
-					ipc_send_to_pid(w.pid, IPC_WIZ, buff);
-				}
-				break;
-			case 3:
-				if (s_changeinfo(user.special))
-				{
-					snprintf(buff, MAXTEXTLENGTH, "\03303%s%s", israw?"":"CHANGE: ", text);
-					ipc_send_to_pid(w.pid, IPC_WIZ, buff);
-				}
-				break;
-			case 4:
-				if ((!u_inform(user.status)) && (cm_flags(user.chatmode,CM_ONCHAT,CM_MODE_ALL)))
-				{
-					snprintf(buff, MAXTEXTLENGTH, "\03304%s%s", israw?"":"SYSTEM: ", text);
-					ipc_send_to_pid(w.pid, IPC_WIZ, buff);
-				}
-				break;
-			case 5:
-				snprintf(buff, MAXTEXTLENGTH, "\03304STATUS: \03314%s",text);
-				ipc_send_to_pid(w.pid, IPC_WIZ, buff);
-				break;
-			default:
-				snprintf(buff, MAXTEXTLENGTH, "\03304%s%s", israw?"":"SYSTEM: ", text);
-				ipc_send_to_pid(w.pid, IPC_WIZ, buff);
-		}
+			break;
+		default:
+			snprintf(buff, MAXTEXTLENGTH, "\03304%s%s", israw?"":"SYSTEM: ", text);
+			ipc_send_to_all(IPC_TEXT, buff);
 	}
-
-	close(ufile);
-	close(wfile);
 }
 
 

Modified: trunk/src/client/script_inst.c
===================================================================
--- trunk/src/client/script_inst.c	2015-09-24 09:28:17 UTC (rev 1392)
+++ trunk/src/client/script_inst.c	2015-09-24 09:30:00 UTC (rev 1393)
@@ -195,7 +195,7 @@
 			if (!strcasecmp(u2.name, uname))
 			{
 				/* check they are still alive and show info */
-				if (w.pid>-1 && (! ipc_send_to_pid(w.pid, IPC_NOOP, NULL)))
+				if (w.pid>-1 )
 				{
 					snprintf(value, MAXTEXTLENGTH - 1, "%ld", (long)time(0) - u2.idletime);
 					if (script_debug) printf("- %s: Idletime is %ld\n", pc->inst->name, (long)time(0) - u2.idletime);
@@ -378,7 +378,7 @@
 		read(ufile,&u2,sizeof(u2));
 
 		/* check they are still alive and show info */
-		if (w.pid>-1 && (! ipc_send_to_pid(w.pid, IPC_NOOP, NULL)))
+		if (w.pid>-1 )
 		{
 			if (cm_flags(u2.chatmode,CM_ONCHAT,CM_MODE_ANY))
 			{
@@ -476,7 +476,7 @@
 			if (!strcasecmp(u2.name, uname))
 			{
 				/* check they are still alive and show info */
-				if (w.pid>-1 && (! ipc_send_to_pid(w.pid, IPC_NOOP, NULL)))
+				if (w.pid>-1 )
 				{
 					/* do validity checks */
 					if (cm_flags(u2.chatmode,CM_ONCHAT,CM_MODE_ANY))
@@ -648,7 +648,7 @@
 				read(ufile,&p,sizeof(p));
 
 				/* check they are still alive and show info */
-				if (w.pid>-1 && (! ipc_send_to_pid(w.pid, IPC_NOOP, NULL)))
+				if (w.pid>-1 )
 				{
 					if (cm_flags(p.chatmode,CM_ONCHAT,CM_MODE_ANY))
 					{

Modified: trunk/src/client/talker.c
===================================================================
--- trunk/src/client/talker.c	2015-09-24 09:28:17 UTC (rev 1392)
+++ trunk/src/client/talker.c	2015-09-24 09:30:00 UTC (rev 1393)
@@ -61,54 +61,6 @@
 
 extern int g_boTermCap;
 
-struct filter_info {
-	int	channel;
-	int	noloopback;
-};
-
-static int send_filter_oneroom(const struct person * usr, const struct who * who, const void * info) {
-	// Everyone in a room except people 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;
-	
-	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
-	// Except if the room is soundproof - in that case only people in
-	// the room with global turned on.
-	struct filter_info *	f_info = (struct filter_info *) info;
-	int			sproof=0;
-	struct room		tmp_room;
-
-	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
-
-	RoomInit(&tmp_room);
-	if (LoadRoom(&tmp_room, f_info->channel) && (tmp_room.sproof>0)) sproof=1;
-	RoomDestroy(&tmp_room);
-	
-	return (! sproof);
-}
-
 static void talk_send_to_room(const char * text, int channel, const char * type, int plural) {
 	ipc_message_t * msg = ipcmsg_create(IPC_SAYTOROOM, userposn);
 	ipcmsg_destination(msg, channel);
@@ -144,17 +96,8 @@
 }
 
 void talk_send_rawbcast(char * text){
-	char			buff[MAXTEXTLENGTH];
-	struct filter_info	f_info;
-	
-	memset(&f_info, 0, sizeof(f_info));
-	f_info.channel = user->room;
-	f_info.noloopback = 1;
 	mwlog("RAWBCAST %s", text);
-	ipc_send_to_all(IPC_TEXT, text, send_filter_oneroom, &f_info);
-	ipc_send_to_all(IPC_TEXT, text, send_filter_nonglobal, &f_info);
-	snprintf(buff, MAXTEXTLENGTH, "*:%s", text);
-	ipc_send_to_all(IPC_TEXT, buff, send_filter_global, &f_info);
+	ipc_send_to_all(IPC_TEXT, text);
 }
 
 void talk_send_emote(char * text, int channel, int plural){
@@ -1069,9 +1012,6 @@
 			lseek(ufile,w.posn,0);
 			read(ufile,&p,sizeof(p));
 
-			/* check they are still alive and show info */
-			if (! ipc_send_to_pid(w.pid, IPC_NOOP, NULL))
-			{
 				if (cm_flags(p.chatmode,CM_ONCHAT,CM_MODE_ANY))
 				{
 					if (is_ignored(p.name, NULL))
@@ -1087,7 +1027,6 @@
 						ignored = newnode;
 					}
 				}
-			}
 		}
 		close(ufile);
 		close(wfile);
@@ -1566,7 +1505,7 @@
 
 	if (broadcast) 
 	{
-		count = ipc_send_to_all(IPC_SCRIPTIPC, text, NULL, NULL);
+		count = ipc_send_to_all(IPC_SCRIPTIPC, text);
 	}
 	else
 	{
@@ -1592,7 +1531,7 @@
 	snprintf(buff, MAXTEXTLENGTH, "%s %s", type, text);
 	if(broadcast)
 	{
-		count = ipc_send_to_all(IPC_SCRIPTRPC, buff, NULL, NULL); 
+		count = ipc_send_to_all(IPC_SCRIPTRPC, buff); 
 	}
 	else
 	{

Modified: trunk/src/client/who.c
===================================================================
--- trunk/src/client/who.c	2015-09-24 09:28:17 UTC (rev 1392)
+++ trunk/src/client/who.c	2015-09-24 09:30:00 UTC (rev 1393)
@@ -97,7 +97,6 @@
 			chat=' ';
 	
 		/* check they are still alive and show info */
-		if (! ipc_send_to_pid(w.pid, IPC_NOOP, NULL))
 		{
 			if (mode == 1) {
 				if (u.dowhen && u.doing[0] != 0)
@@ -202,7 +201,7 @@
 	while (read(wfile,&w,sizeof(w)))
 	{
 		if (w.posn >= 0 &&
-		    (pid==-w.pid || (pid==w.pid && (! ipc_send_to_pid(w.pid, IPC_NOOP, NULL)))))
+		    (pid==-w.pid || pid==w.pid ))
 		{
 			found=w.posn;
 			break;
@@ -249,7 +248,7 @@
 			lseek(ufile,w.posn,0);
 			read(ufile,&user,sizeof(user));
 
-			if (w.pid>-1 && (! ipc_send_to_pid(w.pid, IPC_NOOP, NULL)))
+			if (w.pid>-1)
 			{
 				rwhocli_userlogin(user.name,user.name,user.lastlogout);
 			}else
@@ -279,7 +278,7 @@
 	while(read(file,&u,sizeof(u))>0)
 	{
 		if (u.pid>0 && u.posn==where) {
-			if (! ipc_send_to_pid(u.pid, IPC_NOOP, NULL)) count++;
+			count++;
 		}
 	}
 

Modified: trunk/src/ipc.c
===================================================================
--- trunk/src/ipc.c	2015-09-24 09:28:17 UTC (rev 1392)
+++ trunk/src/ipc.c	2015-09-24 09:30:00 UTC (rev 1393)
@@ -104,105 +104,45 @@
 	return ipcsock->fd;
 }
 
-
 /*
- * Send a message to a remote process addressed by PID
- * Returns:
- *	0	- Success.
- *	-1	- Remote process doesn't exist
- *	-2	- Some other failure (maybe the FIFO is full?)
- *
- * The message format is:
- *	"abbbbC|"
- * Where:
- *	a	- 1 octet containing the message type identifier
- *	bbbb	- 4 octets containing our PID
- *	C	- An arbitrary length of data
+ * Send a message to a remote process addressed by username.
+ * Returns the number of processes successfuly sent messages
  */
-int ipc_send_to_pid(pid_t dest, enum ipc_types msgtype, const char * data) {
+unsigned int ipc_send_to_username(const char * dest, enum ipc_types msgtype, const char * data) {
 	int	ret = 0;
 
-	if (dest < 1) return -1;	// Invalid PID
 	if (! data) data = "";
 
-	if (msgtype != IPC_NOOP) {
-		char	buff[MAXTEXTLENGTH];
-		snprintf(buff, MAXTEXTLENGTH - 1, "%s",data);
-		//ensure text (everything after the first 5 bytes) going into the pipes is clean utf-8 after all the truncating etc. that might have happened to it.
-		//
+	char	buff[MAXTEXTLENGTH];
+	snprintf(buff, MAXTEXTLENGTH - 1, "%s",data);
+	//ensure text (everything after the first 5 bytes) going into the pipes is clean utf-8 after all the truncating etc. that might have happened to it.
+	//
+	//
+	long uposn = SYSTEM_USER;
+	if (dest) uposn = who_find(dest);
+	if (uposn == -1) return 0;
 
-		ipc_check();
-		if(utf8_cleanup(buff)>=0) {
-			ssize_t dgram_len = strlen(buff);
-			ipc_message_t *msg = ipcmsg_create(msgtype, userposn);
-			ipcmsg_destination(msg, dest);
-			ipcmsg_append(msg, buff, dgram_len);
-			ipcmsg_send(msg, ipcsock);
-		} else {
-			fprintf(stderr, "Failed to utf8_cleanup the message\n"); 
-		}
+	ipc_check();
+	if(utf8_cleanup(buff)>=0) {
+		ssize_t dgram_len = strlen(buff);
+		ipc_message_t *msg = ipcmsg_create(msgtype, userposn);
+		ipcmsg_destination(msg, uposn);
+		ipcmsg_append(msg, buff, dgram_len);
+		ipcmsg_send(msg, ipcsock);
+	} else {
+		fprintf(stderr, "Failed to utf8_cleanup the message\n"); 
 	}
 	return ret;
 }
 
 /*
- * Send a message to a remote process addressed by username
- * or all processes if "dest" is NULL.
- * If filter is not NULL, it is called for each process and
- * must return 0 (don't send) or non-zero (send).
- * Returns the number of processes successfuly sent messages
- */
-static unsigned int ipc_send_to_processes(const char * dest, enum ipc_types msgtype, const char * data, send_filter * filter, const void * filterinfo) {
-	int		who_fd;
-	int		users_fd = -1;
-	struct who	who;
-	struct person	user;
-	unsigned int	count = 0;
-
-	who_fd = who_open(O_RDONLY);
-	if (who_fd < 0) return 0;
-
-	users_fd = userdb_open(O_RDONLY);
-	if (users_fd < 0) {
-		close(who_fd);
-		return 0;
-	}
-
-	ipc_check();
-
-	while (read(who_fd, &who, sizeof(who)) > 0) {
-		if (who.posn < 0) continue;
-		if (who.pid  <= 0) continue;
-
-		lseek(users_fd, who.posn, SEEK_SET);
-		if (read(users_fd, &user, sizeof(user)) <= 0) continue;
-		if ((dest) && strcasecmp(user.name, dest)) continue;
-		if ((filter) && (! filter(&user, &who, filterinfo))) continue;
-		if (! ipc_send_to_pid(who.pid, msgtype, data)) count++;
-		else if (dest) fprintf(stderr, "Write to PID %u failed.\n", who.pid);
-	}
-	close(who_fd);
-	if (users_fd >= 0) close(users_fd);
-	return count;
-}
-
-/*
- * Send a message to a remote process addressed by username.
- * Returns the number of processes successfuly sent messages
- */
-unsigned int ipc_send_to_username(const char * dest, enum ipc_types msgtype, const char * data) {
-	if (! dest) return 0;
-	return ipc_send_to_processes(dest, msgtype, data, NULL, NULL);
-}
-
-/*
  * Send a message to all remote processes
  * If filter is not NULL, it is called for each process and
  * must return 0 (don't send) or non-zero (send).
  * Returns the number of processes successfuly sent messages
  */
-unsigned int ipc_send_to_all(enum ipc_types msgtype, const char * data, send_filter * filter, const void * filterinfo) {
-	return ipc_send_to_processes(NULL, msgtype, data, filter, filterinfo);
+unsigned int ipc_send_to_all(enum ipc_types msgtype, const char * data) {
+	return ipc_send_to_username(NULL, msgtype, data);
 }
 
 

Modified: trunk/src/ipc.h
===================================================================
--- trunk/src/ipc.h	2015-09-24 09:28:17 UTC (rev 1392)
+++ trunk/src/ipc.h	2015-09-24 09:30:00 UTC (rev 1393)
@@ -64,9 +64,8 @@
 void ipc_check(void);
 void ipc_close(void);
 int ipc_getfd(void);
-int ipc_send_to_pid(pid_t dest, enum ipc_types msgtype, const char * data);
 unsigned int ipc_send_to_username(const char * dest, enum ipc_types msgtype, const char * data);
-unsigned int ipc_send_to_all(enum ipc_types msgtype, const char * data, send_filter * filter, const void * filterinfo);
+unsigned int ipc_send_to_all(enum ipc_types msgtype, const char * data);
 void ipcmsg_transmit(ipc_message_t * msg);
 int msg_queue(ipc_message_t *msg, ipc_connection_t *conn);
 

Modified: trunk/src/server/replay.c
===================================================================
--- trunk/src/server/replay.c	2015-09-24 09:28:17 UTC (rev 1392)
+++ trunk/src/server/replay.c	2015-09-24 09:30:00 UTC (rev 1393)
@@ -55,6 +55,11 @@
 		store_len = 0;
 	}
 
+	/* only store info/message, not actions */
+	if (msg->head.type <= 26 && 
+	   !( msg->head.type == IPC_TEXT || msg->head.type == IPC_WIZ))
+		return;
+
 	if (store_len >= STORE_SIZE) {
 		/* store is full, discard oldest, 
 		 * it will have wrapped, so store_next is the last one */
@@ -108,20 +113,19 @@
 	if (json_object_get(cmd, "since")!=NULL) {
 		/* everything after {unixtime} */
 		int64_t want = json_getint(cmd, "since");
-		for (;idx != store_next;idx=store_wrap(idx+1)) {
-			if (store[idx]==NULL) continue;
+		while (idx != store_next) {
 			/* list will be in date order */
-			if (store[idx]->head.when >= want) break;
+			if (store[idx]!=NULL && 
+				store[idx]->head.when >= want) break;
+			idx = store_wrap(idx+1);
 		}
 		/* if it fails you get nothing as there is
 		 * nothing newer (larger) than the date you gave */
 	}else
 	if (json_object_get(cmd, "count")!=NULL) {
 		int want = json_getint(cmd, "count");
-		if (want < store_len) {
-			idx -= store_len - want;
-			idx = store_wrap( idx );
-		}
+		if (want > store_len) want = store_len;
+		idx = store_wrap( store_next - want );
 	} else {
 		json_decref(cmd);
 		send_error(conn, msg, "Invalid replay command");
@@ -193,6 +197,7 @@
 		}
 
 		/* send them everything else */
+		if (store[idx]->head.dst)
 		msg_attach(store[idx], conn);
 	}
 

Modified: trunk/src/server/servsock.c
===================================================================
--- trunk/src/server/servsock.c	2015-09-24 09:28:17 UTC (rev 1392)
+++ trunk/src/server/servsock.c	2015-09-24 09:30:00 UTC (rev 1393)
@@ -350,11 +350,11 @@
 
 			/* room matches, send them a copy */
 			if (user.room == msg->head.dst) {
-				msg_attach_to(msg, who.pid);
+				msg_attach_to_pid(msg, who.pid);
 			} else
 			/* room not soundproof, and user has global on */
 			if (room.sproof < 1 && (user.chatmode & CM_GLOBAL)) {
-				msg_attach_to(msg, who.pid);
+				msg_attach_to_pid(msg, who.pid);
 			}
 		}
 		RoomDestroy(&room);
@@ -383,10 +383,9 @@
 
 			lseek(users_fd, who.posn, SEEK_SET);
 			if (read(users_fd, &user, sizeof(user)) <= 0) continue;
-
 			/* is this the username we are looking for */
 			if (strcasecmp(target, user.name)==0) {
-				msg_attach_to(msg, who.pid);
+				msg_attach_to_pid(msg, who.pid);
 				found++;
 			}
 		}
@@ -402,7 +401,7 @@
 	}
 
 	/* send message to everyone (unless this room is soundproof) */
-	if (msg->head.type == IPC_SAYTOALL) {
+	if (msg->head.type == IPC_SAYTOALL ) {
 		/* eventually this should be a server maintained list */
 		int who_fd = who_open(O_RDONLY);
 		int users_fd = userdb_open(O_RDONLY);
@@ -432,14 +431,14 @@
 			if (room.sproof > 0) {
 				/* room matches, send them a copy */
 				if (user.room == from.room) {
-					msg_attach_to(msg, who.pid);
+					msg_attach_to_pid(msg, who.pid);
 					printf("Soundproof %s in %d\n", user.name, user.room);
 				} else
 					printf("Soundproof %s not in %d (is in %d)\n", user.name, from.room, user.room);
 			} else
 			/* room not soundproof, everyone gets it */
 			{
-				msg_attach_to(msg, who.pid);
+				msg_attach_to_pid(msg, who.pid);
 				printf("Shout to %s in %d\n", user.name, user.room);
 			}
 		}
@@ -457,22 +456,41 @@
 		return;
 	}
 
+	/* it was a broadcast message */
+        if (msg->head.dst == SYSTEM_USER) {
+		int who_fd = who_open(O_RDONLY);
+		int users_fd = userdb_open(O_RDONLY);
+		struct who who;
+		struct person user;
+
+		while (read(who_fd, &who, sizeof(who)) > 0) {
+			if (who.posn < 0) continue;
+			if (who.pid <= 0) continue;
+
+			lseek(users_fd, who.posn, SEEK_SET);
+			if (read(users_fd, &user, sizeof(user)) <= 0) continue;
+
+			msg_attach_to_pid(msg, who.pid);
+			printf("Broadcast to %s in %d\n", user.name, user.room);
+		}
+	}
+
 	/* otherwise redistribute this message to intended target */
-	msg_attach_to(msg, msg->head.dst);
+	msg_attach_to_user(msg, msg->head.dst);
 	ipcmsg_destroy(msg);
 }
 
-void msg_attach_to(ipc_message_t *msg, uint32_t dest)
+void msg_attach_to_pid(ipc_message_t *msg, uint32_t pid)
 {
 	struct list_head *pos;
 	list_for_each(pos, &connection_list) {
 		ipc_connection_t *c = list_entry(pos, ipc_connection_t, list);
 		if (c->state == IPCSTATE_VALID) {
-			if (dest == 0) {
+			if (pid == 0) {
 				/* broadcast */
 				msg_attach(msg, c);
 			} else
-			if (dest == c->addr) {
+			if (pid == c->addr) {
 				/* unicast */
 				msg_attach(msg, c);
 			}
@@ -480,6 +498,23 @@
 	}
 }
 
+void msg_attach_to_user(ipc_message_t *msg, uint32_t userposn)
+{
+	struct list_head *pos;
+	list_for_each(pos, &connection_list) {
+		ipc_connection_t *c = list_entry(pos, ipc_connection_t, list);
+		if (c->state == IPCSTATE_VALID) {
+			if (userposn == SYSTEM_USER) {
+				/* broadcast */
+				msg_attach(msg, c);
+			} else
+			if (userposn == c->user) {
+				/* unicast */
+				msg_attach(msg, c);
+			}
+		}
+	}
+}
 
 void msg_attach(ipc_message_t *msg, ipc_connection_t *conn)
 {

Modified: trunk/src/server/servsock.h
===================================================================
--- trunk/src/server/servsock.h	2015-09-24 09:28:17 UTC (rev 1392)
+++ trunk/src/server/servsock.h	2015-09-24 09:30:00 UTC (rev 1393)
@@ -6,7 +6,8 @@
 void watch_mainsock(int mainsock);
 void write_socket(ipc_connection_t *conn);
 void process_msg(ipc_connection_t *conn, ipc_message_t *msg);
-void msg_attach_to(ipc_message_t *msg, uint32_t dest);
+void msg_attach_to_pid(ipc_message_t *msg, uint32_t pid);
+void msg_attach_to_user(ipc_message_t *msg, uint32_t userposn);
 void msg_attach(ipc_message_t *msg, ipc_connection_t *conn);
 void init_server(void);
 void send_error(ipc_connection_t *conn, ipc_message_t *orig, const char *format, ...);

Modified: trunk/src/socket.h
===================================================================
--- trunk/src/socket.h	2015-09-24 09:28:17 UTC (rev 1392)
+++ trunk/src/socket.h	2015-09-24 09:30:00 UTC (rev 1393)
@@ -21,12 +21,12 @@
 
 /* packed struct for socket ipc */
 typedef struct {
-	uint32_t src;
-	uint32_t dst;
-	uint32_t type;
-	uint32_t len;
-	uint64_t serial;
-	 int64_t when;
+	uint32_t src;		// sending userid
+	uint32_t dst;		// destination user/room
+	uint32_t type;		// message type
+	uint32_t len;		// bytes of body
+	uint64_t serial;	// sequence number
+	 int64_t when;		// unixtime of sending
 } __attribute__((packed)) ipc_msghead_t;
 
 typedef struct {

Modified: trunk/src/webclient/comms.c
===================================================================
--- trunk/src/webclient/comms.c	2015-09-24 09:28:17 UTC (rev 1392)
+++ trunk/src/webclient/comms.c	2015-09-24 09:30:00 UTC (rev 1393)
@@ -1,7 +1,8 @@
+#include <stdio.h>
+
 #include <files.h>
 #include <fcntl.h>
 #include <unistd.h>
-#include <stdio.h>
 #include <stdarg.h>
 #include <stdlib.h>
 #include <unistd.h>
@@ -96,49 +97,6 @@
 	INIT_LIST_HEAD(&connlist);
 }
 
-struct filter_info {
-        int     channel;
-        int     noloopback;
-};
-
-static int send_filter_oneroom(const struct person * usr, const struct who * who, const void * info) {
-// Everyone in a room except people with global turned on
-        struct filter_info *    f_info = (struct filter_info *) info;
-
-	printf("filter: user '%s' pid=%d\n", usr->name, who->pid);
-        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_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 */
 static void accept_pipe_cmd(ipc_message_t *ipc, struct person *mesg_user)
 {
@@ -399,7 +357,6 @@
 		return 0; // dont close
 	}else
 	if (strncasecmp(buff, "channel ", 8)==0) {
-                struct filter_info f_info;
                 char line[8192];
 		int oldroom;
 		int newroom;
@@ -409,18 +366,13 @@
 		if (newroom == oldroom) {
 			return 1;
 		}else{
-	                memset(&f_info, 0, sizeof(f_info));
-			f_info.channel = oldroom;
 			user->room = newroom;
 			snprintf(line, sizeof line, "\03313%s has left to room %d", user->name, newroom);
-			ipc_send_to_all(IPC_TEXT, line, send_filter_oneroom, &f_info);
-                	f_info.channel = user->room;
+			talk_send_to_room(line, oldroom, "raw", -1); 
                         snprintf(line, sizeof line, "\03314Leaving room %d for room %d",oldroom,newroom);
                         ipc_send_to_username(user->name,IPC_TEXT,line);
 	                snprintf(line, sizeof line, "\03312%s has just arrived in room %d", user->name, user->room);
-        	        ipc_send_to_all(IPC_TEXT, line, send_filter_oneroom, &f_info);
-			ipc_send_to_all(IPC_TEXT, line, send_filter_global, &f_info);
-			//(asprintf(&buff, "Leaving room %d for room %d", oldroom, user->room)
+        	        talk_send_to_room(line, newroom, "raw", -1);
 			snprintf(buff, sizeof buff, "{\"channel\":%d}", user->room);
 			send(co->fd, buff, strlen(buff), 0);
 			return 1; // dont close
@@ -432,10 +384,7 @@
 		char duser[17];
 		char msg[8192];
 		char *tmpu;
-		//struct filter_info f_info;
                 char line[8192];
-		//memset(&f_info, 0, sizeof(f_info));
-		//f_info.channel = user->room;
 		tmp = remove_first_word(buff);
 		tmpm = remove_first_word(tmp);
 		tmpu = strtok(tmp," ");
@@ -589,30 +538,13 @@
 void talk_rawbcast(const 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);
+	ipc_send_to_all(IPC_TEXT, text);
 	free(text);
-	free(form);
 
 }
 

Modified: trunk/src/webclient/import.c
===================================================================
--- trunk/src/webclient/import.c	2015-09-24 09:28:17 UTC (rev 1392)
+++ trunk/src/webclient/import.c	2015-09-24 09:30:00 UTC (rev 1393)
@@ -90,7 +90,7 @@
         }
 
         /* send the message */
-        ipc_send_to_all(IPC_CHECKONOFF, logofftext, NULL, NULL);
+        ipc_send_to_all(IPC_CHECKONOFF, logofftext);
 }
 
 void show_chatmodes(unsigned long cm, char *tmp, int flag)

Modified: trunk/src/who.c
===================================================================
--- trunk/src/who.c	2015-09-24 09:28:17 UTC (rev 1392)
+++ trunk/src/who.c	2015-09-24 09:30:00 UTC (rev 1393)
@@ -1,9 +1,11 @@
 #include <unistd.h>
 #include <fcntl.h>
 #include <stdio.h>
+#include <strings.h>
 
 #include "who.h"
 #include "files.h"
+#include "user.h"
 
 int who_open(int flags)
 {
@@ -46,3 +48,37 @@
 	}
 	Unlock_File(wfd);
 }
+
+long who_find(const char * username)
+{
+	int             who_fd;
+	int             users_fd = -1;
+	struct who      who;
+	struct person   user;
+	long 		where = -1;
+
+	who_fd = who_open(O_RDONLY);
+	if (who_fd < 0) return -1;
+
+	users_fd = userdb_open(O_RDONLY);
+	if (users_fd < 0) {
+		close(who_fd);
+		return -1;
+	}
+
+	while (read(who_fd, &who, sizeof(who)) > 0) {
+		if (who.posn < 0) continue;
+		if (who.pid  <= 0) continue;
+
+		lseek(users_fd, who.posn, SEEK_SET);
+		if (read(users_fd, &user, sizeof(user)) <= 0) continue;
+		if (strcasecmp(user.name, username)==0) {
+			where = who.posn;
+			break;
+		}
+	}
+	close(who_fd);
+	close(users_fd);
+
+	return where;
+}

Modified: trunk/src/who.h
===================================================================
--- trunk/src/who.h	2015-09-24 09:28:17 UTC (rev 1392)
+++ trunk/src/who.h	2015-09-24 09:30:00 UTC (rev 1393)
@@ -14,5 +14,7 @@
 extern int who_open(int mode);
 extern void who_add(int wfd, int pid, int32_t posn);
 extern void who_delete(int wfd, int pid);
+extern long who_find(const char * username);
 
+
 #endif /* WHO_H */




More information about the mw-devel mailing list