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

arthur at sucs.org arthur at sucs.org
Tue Sep 29 11:28:10 BST 2015


Author: arthur
Date: 2015-09-29 11:28:10 +0100 (Tue, 29 Sep 2015)
New Revision: 1395

Modified:
   trunk/src/client/incoming.c
   trunk/src/client/talker.c
   trunk/src/client/talker_privs.c
   trunk/src/client/talker_privs.h
   trunk/src/client/user.c
   trunk/src/client/user.h
   trunk/src/server/PROTOCOL
   trunk/src/socket.c
   trunk/src/socket.h
   trunk/src/talker_privs.h
   trunk/src/user.c
   trunk/src/user.h
   trunk/src/webclient/import.c
   trunk/src/webclient/import.h
   trunk/src/who.c
Log:
Gradually moving towards full server mode,
this moves (most of) the mrod and zod commands to the server


Modified: trunk/src/client/incoming.c
===================================================================
--- trunk/src/client/incoming.c	2015-09-25 16:00:41 UTC (rev 1394)
+++ trunk/src/client/incoming.c	2015-09-29 10:28:10 UTC (rev 1395)
@@ -1015,48 +1015,19 @@
 {
 	char	*msg = NULL;
 	char	type;
-	int	theirapl = (theirprivs & CP_PROTMASK) >> CP_PROTSHIFT;
-	int	prot = (user->chatmode & CM_PROTMASK) >> CM_PROTSHIFT;
-
-	if (!cm_flags(theirprivs, CP_PROTECT, CM_MODE_ALL)) theirapl = 0;
-	if (prot == 0 && cm_flags(user->chatmode, CM_PROTECTED, CM_MODE_ALL)) prot = 1;
-
+	
 	type = *newbuff;
 	if (newbuff[1] == 'r') msg = &newbuff[2];
 
-	if (type=='z' && cm_flags(user->chatmode,CM_ONCHAT,CM_MODE_ANY))
+	if (type=='z')
 	{
-		/* zod, must be on talker */
-		char text[MAXTEXTLENGTH];
-
-		if (prot>theirapl)
-		{
-			snprintf(text,MAXTEXTLENGTH-1,"*** \03315%s just tried to ZoD you.",from);
-			display_message(text, 1, 1);
-			snprintf(text,MAXTEXTLENGTH-1,"\03314%s just tried to ZoD %s, and failed.",from,user->name);
-			talk_send_rawbcast(text);
-		}else
-		{
-			zod(from, msg);
-		}
+		zod(from, msg);
 	}else
 	if (type=='m')
 	{
-		/* mrod */
-		char text[MAXTEXTLENGTH];
-
-		if (prot>theirapl)
-		{
-			snprintf(text,MAXTEXTLENGTH-1,"*** \03315%s just tried to MRoD you.",from);
-			display_message(text, 1, 1);
-			snprintf(text,MAXTEXTLENGTH-1,"\03314%s just tried to MRoD %s, and failed.",from,user->name);
-			talk_send_rawbcast(text);
-		}else
-		{
-			mrod(from, msg);
-		}
+		mrod(from, msg);
 	} else
-	if (type=='k' && cm_flags(user->chatmode,CM_ONCHAT,CM_MODE_ANY))
+	if (type=='k')
 	{
 		zod(from, msg);
 	}else
@@ -1085,17 +1056,6 @@
 	printf(_("%s just sent the Zebedee of Death to you.\n"),from);
 	fflush(stdout);
 
-	/* tell other people what happened */
-	snprintf(text, MAXTEXTLENGTH-1, "\03314You hear a boing in the distance");
-	talk_send_raw(text, user->room);
-	snprintf(text, MAXTEXTLENGTH-1, "\03315%s just sent the Zebedee of Death to %s.", from, user->name);
-	talk_send_raw(text, user->room);
-	if (msg != NULL)
-	{
-		snprintf(text, MAXTEXTLENGTH-1, "\03314\"%s\" says Zebedee", msg);
-		talk_send_raw(text, user->room);
-	}
-
 	/* broadcast leaving message if not quiet */
 	if (!quietmode) broadcast(4|0x100, "\03311%s has just left the talker", user->name);
 
@@ -1126,10 +1086,6 @@
 	}
 	fflush(stdout);
 
-	broadcast(1|0x100, "\03314You hear a boing in the distance, closely followed by the distant wail of a hurdy-gurdy, which is suddenly terminated by a blood curdling scream, a C major chord explosion and a few curious springing noises...");
-	broadcast(1|0x100, "\03315%s has just dropped the Magic Roundabout of Death on %s.",from,user->name);
-	if (msg!=NULL) broadcast(1|0x100, "\03314\"%s\" says Zebedee", msg);
-
 	fix_terminal();
 	
 	mrod_user = malloc(sizeof(char) * (strlen(from) + 1));

Modified: trunk/src/client/talker.c
===================================================================
--- trunk/src/client/talker.c	2015-09-25 16:00:41 UTC (rev 1394)
+++ trunk/src/client/talker.c	2015-09-29 10:28:10 UTC (rev 1395)
@@ -1196,6 +1196,14 @@
 	}
 	else strncat(buff, "-", MAXTEXTLENGTH - 2);
 	ipc_send_to_username(argv[1], IPC_KICK ,buff);
+
+	ipc_message_t * msg = ipcmsg_create(IPC_ACTION, userposn);
+	json_t * j = json_init(NULL);
+	json_addstring(j, "target", argv[1]);
+	json_addstring(j, "type", "mrod");
+	ipcmsg_json_encode(msg, j);
+	json_decref(j);
+	ipcmsg_transmit(msg);
 }
 
 void t_kick(CommandList *cm, int argc, const char **argv, char *args)

Modified: trunk/src/client/talker_privs.c
===================================================================
--- trunk/src/client/talker_privs.c	2015-09-25 16:00:41 UTC (rev 1394)
+++ trunk/src/client/talker_privs.c	2015-09-29 10:28:10 UTC (rev 1395)
@@ -138,116 +138,6 @@
 	}
 }
 
-/* chatmode flags, as in currently active modes */
-unsigned long cm_flags(unsigned long cm, unsigned long flags, int mode)
-{
-	if (mode==CM_MODE_CLEAR) return( cm & (~flags) ); 
-	else
-	if (mode==CM_MODE_SET) return(cm | flags); 
-	else
-	if (mode==CM_MODE_ANY) {
-		return ((cm & flags) > 0);
-	} else
-	if (mode==CM_MODE_ALL) {
-		return ((cm & flags) == flags);
-	}
-	return(0);
-}
-
-char *display_cmflags(unsigned long cm)
-{
-	static char s[40];
-	
-	s[0]=0;
-	if (cm & CM_ONCHAT) strcat(s,"c");
-	if (cm & CM_GLOBAL) strcat(s,"o");
-	if (cm & CM_PROTECTED) strcat(s,"p");
-	if (cm & CM_FROZEN) strcat(s,"f");
-	if (cm & CM_SPY) strcat(s,"y");
-	if (cm & CM_VERBOSE) strcat(s,"v");
-	if (cm & CM_STICKY) strcat(s,"k");
-	if (cm & CM_GAG1) strcat(s,"1");
-	if (cm & CM_GAG2) strcat(s,"2");
-	if (cm & CM_GAG3) strcat(s,"3");
-	if (cm & CM_GAG4) strcat(s,"4");
-	if (cm & CM_GAG5) strcat(s,"5");
-	if (cm & CM_GAG6) strcat(s,"6");
-	return (s);
-}
-
-void show_chatmodes(unsigned long cm, char *tmp, int flag)
-{
-	int i=0;
-	
-	if (cm & CM_ONCHAT) tmp[i++]='c'; else if (flag) tmp[i++]='-';
-	if (cm & CM_GLOBAL) tmp[i++]='o'; else if (flag) tmp[i++]='-';
-	if (cm & CM_PROTECTED) tmp[i++]='p'; else if (flag) tmp[i++]='-';
-	if (cm & CM_FROZEN) tmp[i++]='f'; else if (flag) tmp[i++]='-';
-	if (cm & CM_SPY) tmp[i++]='y'; else if (flag) tmp[i++]='-';
-	if (cm & CM_VERBOSE) tmp[i++]='v'; else if (flag) tmp[i++]='-';
-	if (cm & CM_STICKY) tmp[i++]='k'; else if (flag) tmp[i++]='-';
-	if (cm & CM_GAG1) tmp[i++]='1'; else if (flag) tmp[i++]='-';
-	if (cm & CM_GAG2) tmp[i++]='2'; else if (flag) tmp[i++]='-';
-	if (cm & CM_GAG3) tmp[i++]='3'; else if (flag) tmp[i++]='-';
-	if (cm & CM_GAG4) tmp[i++]='4'; else if (flag) tmp[i++]='-';
-	if (cm & CM_GAG5) tmp[i++]='5'; else if (flag) tmp[i++]='-';
-	if (cm & CM_GAG6) tmp[i++]='6'; else if (flag) tmp[i++]='-';
-	tmp[i]=0;
-}
-
-void show_protection(unsigned long cm, unsigned long cp, char *tmp, int ourapl)
-{
-	int cpl = (cm & CM_PROTMASK) >> CM_PROTSHIFT;
-	int apl = (cp & CP_PROTMASK) >> CP_PROTSHIFT;
-
-/*
-	if (cpl > ourapl) cpl = 9;
-	if (apl > ourapl) apl = 9;
-	snprintf(tmp, 4, "%d/%d", cpl, apl);
-	tmp[4]=0;
-*/
-
-	if ((cpl <= ourapl) && (apl <= ourapl))
-		snprintf(tmp, 4, "%d/%d", cpl, apl);
-	else if ((cpl > ourapl) && (apl <= ourapl))
-		snprintf(tmp, 4, "?/%d", apl);
-	else if ((cpl <= ourapl) && (apl > ourapl))
-		snprintf(tmp, 4, "%d/?", cpl);
-	else
-		snprintf(tmp, 4, "?/?");
-}
-
-unsigned long cm_setbycode(unsigned long stat, const char *string)
-{
-	int mode=0;
-	int i;
-	unsigned long p=0; /*pattern buffer */
-	for (i=0;i<strlen(string);i++)
-		switch (string[i])
-		{
-			case '=': mode=0;break;
-			case '+': mode=-1;break;
-			case '-': mode=1;break;
-			case 'c': p=p|CM_ONCHAT;break;
-			case 'o': p=p|CM_GLOBAL;break;
-			case 'p': p=p|CM_PROTECTED;break;
-			case 'y': p=p|CM_SPY;break;
-			case 'v': p=p|CM_VERBOSE;break;
-			case 'f': p=p|CM_FROZEN;break;
-			case 'k': p=p|CM_STICKY;break;
-			case '1': p=p|CM_GAG1;break;
-			case '2': p=p|CM_GAG2;break;
-			case '3': p=p|CM_GAG3;break;
-			case '4': p=p|CM_GAG4;break;
-			case '5': p=p|CM_GAG5;break;
-			case '6': p=p|CM_GAG6;break;
-		};
-	if (mode==0) return(p);
-	else if (mode==-1) return(stat|p);
-	else if (mode==1) return(stat&(~p));
-	else return(p);
-}
-
 int gag_code(const char *str)
 {
 	GagInfo *gi = gaglist;
@@ -529,94 +419,6 @@
 /***************************/
 /* user->chatprivs options */
 
-unsigned long cp_flags(unsigned long cm, unsigned long flags, int mode)
-{
-	if (mode==CM_MODE_SET) return( cm | flags ); 
-	else
-	if (mode==CM_MODE_CLEAR) return( cm & (~flags) ); 
-	else
-	if (mode==CM_MODE_ANY) { 
-		return ((cm & flags) > 0);
-	} else
-	if (mode==CM_MODE_ALL) {
-		return ((cm & flags) == flags);
-	}
-	return(0);
-}
-
-char *display_cpflags(unsigned long cm)
-{
-	static char s[40];
-	
-	s[0]=0;
-	if (cm & CP_CANRAW) strcat(s,"R");
-	if (cm & CP_CANGAG) strcat(s,"G");
-	if (cm & CP_CANZOD) strcat(s,"Z");
-	if (cm & CP_CANMROD) strcat(s,"M");
-	if (cm & CP_CANGLOBAL) strcat(s,"O");
-	if (cm & CP_PROTECT) strcat(s, "P");
-	if (cm & CP_FREEZE) strcat(s, "F");
-	if (cm & CP_SUMMON) strcat(s, "S");
-	if (cm & CP_SPY) strcat(s, "Y");
-	if (cm & CP_SCRIPT) strcat(s, "s");
-	if (cm & CP_ADVSCR) strcat(s, "A");
-	if (cm & CP_DEVEL) strcat(s, "D");
-	if (cm & CP_TOPIC) strcat(s, "t");
-	return (s);
-}
-
-void show_chatprivs(unsigned long cp, char *tmp, int flag)
-{
-	int i=0;
-
-	if (cp & CP_CANRAW) tmp[i++]='R'; else if (flag) tmp[i++]='-';
-	if (cp & CP_CANGAG) tmp[i++]='G'; else if (flag) tmp[i++]='-';
-	if (cp & CP_CANZOD) tmp[i++]='Z'; else if (flag) tmp[i++]='-';
-	if (cp & CP_CANMROD) tmp[i++]='M'; else if (flag) tmp[i++]='-';
-	if (cp & CP_CANGLOBAL) tmp[i++]='O'; else if (flag) tmp[i++]='-';
-	if (cp & CP_PROTECT) tmp[i++]='P'; else if (flag) tmp[i++]='-';
-	if (cp & CP_FREEZE) tmp[i++]='F'; else if (flag) tmp[i++]='-';
-	if (cp & CP_SUMMON) tmp[i++]='S'; else if (flag) tmp[i++]='-';
-	if (cp & CP_SPY) tmp[i++]='Y'; else if (flag) tmp[i++]='-';
-	if (cp & CP_SCRIPT) tmp[i++]='s'; else if (flag) tmp[i++]='-';
-	if (cp & CP_ADVSCR) tmp[i++]='A'; else if (flag) tmp[i++]='-';
-	if (cp & CP_DEVEL) tmp[i++]='D'; else if (flag) tmp[i++]='-';
-	if (cp & CP_TOPIC) tmp[i++]='t'; else if (flag) tmp[i++]='-';
-
-	tmp[i]=0;
-}
-
-unsigned long cp_setbycode(unsigned long stat, const char *string)
-{
-	int mode=0;
-	int i;
-	unsigned long p=0; /*pattern buffer */
-	for (i=0;i<strlen(string);i++)
-		switch (string[i])
-		{
-			case '=': mode=0;break;
-			case '+': mode=-1;break;
-			case '-': mode=1;break;
-			case 'R': p=p|CP_CANRAW;break;
-			case 'G': p=p|CP_CANGAG;break;
-			case 'Z': p=p|CP_CANZOD;break;
-			case 'M': p=p|CP_CANMROD;break;
-			case 'O': p=p|CP_CANGLOBAL;break;
-			case 'P': p=p|CP_PROTECT;break;
-			case 'F': p=p|CP_FREEZE;break;
-			case 'S': p=p|CP_SUMMON;break;
-			case 'Y': p=p|CP_SPY;break;
-			case 's': p=p|CP_SCRIPT;break;
-			case 'A': p=p|CP_ADVSCR;break;
-			case 'D': p=p|CP_DEVEL;break;
-			case 't': p=p|CP_TOPIC;break;
-		};
-	if (mode==0) return(p);
-	else if (mode==-1) return(stat|p);
-	else if (mode==1) return(stat&(~p));
-	else return(p);
-}
-
 char *part_gag_filter(const char *text, int state)
 {
  	static int ptr=0;

Modified: trunk/src/client/talker_privs.h
===================================================================
--- trunk/src/client/talker_privs.h	2015-09-25 16:00:41 UTC (rev 1394)
+++ trunk/src/client/talker_privs.h	2015-09-29 10:28:10 UTC (rev 1395)
@@ -3,19 +3,8 @@
 
 #include <talker_privs.h>
 
-unsigned long cm_flags(unsigned long cm, unsigned long flags, int mode);
-unsigned long cm_setbycode(unsigned long stat, const char *string);
-unsigned long cp_setbycode(unsigned long stat, const char *string);
-
-char *display_cpflags(unsigned long cm);
-char *display_cmflags(unsigned long cm);
-
-void show_chatmodes(unsigned long cm, char *tmp, int flag);
-void show_chatprivs(unsigned long cp, char *tmp, int flag);
-void show_protection(unsigned long cm, unsigned long cp, char *tmp, int ourapl);
-
-int gag_code(const char *str);
 const char *gag_type(int type);
+int gag_code(const char *str);
 const char *ungag_name(unsigned long chatmode);
 int flag_match(unsigned long val, const char *filter);
 extern void apply_gag(char *text);

Modified: trunk/src/client/user.c
===================================================================
--- trunk/src/client/user.c	2015-09-25 16:00:41 UTC (rev 1394)
+++ trunk/src/client/user.c	2015-09-29 10:28:10 UTC (rev 1395)
@@ -59,16 +59,6 @@
 	close(outfile);
 }
 
-void fetch_user(struct person *record, int32_t userposn)
-{
-	int outfile;
-	
-	outfile=userdb_open(O_RDWR|O_CREAT);
-	lseek(outfile,userposn,0);
-	read(outfile,record,sizeof(*record));
-	close(outfile);
-}
-
 static int old_usr(struct person *usr)
 {
 	char salt[3],passwd[PASSWDSIZE];

Modified: trunk/src/client/user.h
===================================================================
--- trunk/src/client/user.h	2015-09-25 16:00:41 UTC (rev 1394)
+++ trunk/src/client/user.h	2015-09-29 10:28:10 UTC (rev 1395)
@@ -15,7 +15,6 @@
 void strip_name(char *string);
 void pick_salt(char *salt);
 void search(const char *args, const char *ptr);
-void fetch_user(struct person *record, int32_t userposn);
 int is_old(struct person *usr, const char *name, int32_t *userposn);
 
 #endif

Modified: trunk/src/server/PROTOCOL
===================================================================
--- trunk/src/server/PROTOCOL	2015-09-25 16:00:41 UTC (rev 1394)
+++ trunk/src/server/PROTOCOL	2015-09-29 10:28:10 UTC (rev 1395)
@@ -91,12 +91,16 @@
 	Body: (json)
 		type - type of event that occured
 		target - who did the event happen to
+		success=0|1 - did it work
 		text - prefered text for announcement
+		verbose - additional (amusing) texts
+		reason - justification (if any) the attacker gave
 
 IPC_ACTION - user requests an action
 	Body: (json)
 		type - type of event that occured
 		target - who did the event happen to
+		reason - optional reason why you did this
 	Response:
 		type - command request
 		target - victim

Modified: trunk/src/socket.c
===================================================================
--- trunk/src/socket.c	2015-09-25 16:00:41 UTC (rev 1394)
+++ trunk/src/socket.c	2015-09-29 10:28:10 UTC (rev 1395)
@@ -8,6 +8,7 @@
 #include <errno.h>
 
 #include "socket.h"
+#include "util.h"
 
 /* create an empty message */
 ipc_message_t * ipcmsg_create(uint32_t type, uint32_t src)
@@ -295,18 +296,26 @@
 
 
 /** add/replace a string value in the base object */
-int json_addstring(json_t * js, const char * key, const char * value)
+
+int json_addstring(json_t * js, const char * key, const char * value, ...) __attribute__((format (printf, 3, 4)));
+
+int json_addstring(json_t * js, const char * key, const char * value, ...)
 {
 	json_t * tmp;
+	va_list va;
+	va_start(va, value);
+	AUTOFREE_BUFFER text = NULL;
+	vasprintf(&text, value, va);
+	va_end(va);
 
 	tmp = json_object_get(js, key);
 	if (tmp == NULL) {
-		tmp = json_string(value);
+		tmp = json_string(text);
 		if (tmp == NULL) return -1;
 		json_object_set_new(js, key, tmp);
 	} else {
 		if (!json_is_string(tmp)) return -1;
-		json_string_set(tmp, value);
+		json_string_set(tmp, text);
 	}
 	return 0;
 }

Modified: trunk/src/socket.h
===================================================================
--- trunk/src/socket.h	2015-09-25 16:00:41 UTC (rev 1394)
+++ trunk/src/socket.h	2015-09-29 10:28:10 UTC (rev 1395)
@@ -78,7 +78,7 @@
 json_t *ipcmsg_json_decode(ipc_message_t *msg);
 int ipcmsg_json_encode(ipc_message_t *msg, json_t *js);
 json_t *json_init(ipc_message_t *msg);
-int json_addstring(json_t *js, const char *key, const char *value);
+int json_addstring(json_t *js, const char *key, const char *value, ...);
 int json_addint(json_t *js, const char *key, int value);
 const char *json_getstring(json_t *js, const char *key);
 int json_getint(json_t *js, const char *key);

Modified: trunk/src/talker_privs.h
===================================================================
--- trunk/src/talker_privs.h	2015-09-25 16:00:41 UTC (rev 1394)
+++ trunk/src/talker_privs.h	2015-09-29 10:28:10 UTC (rev 1395)
@@ -48,5 +48,17 @@
 
 #define CP_PROTSHIFT	13
 
+/* talker_privs.c */
+unsigned long cm_flags(unsigned long cm, unsigned long flags, int mode);
+unsigned long cp_flags(unsigned long cm, unsigned long flags, int mode);
+unsigned long cm_setbycode(unsigned long stat, const char *string);
+unsigned long cp_setbycode(unsigned long stat, const char *string);
+
+char *display_cmflags(unsigned long cm);
+char *display_cpflags(unsigned long cm);
+
+void show_chatmodes(unsigned long cm, char *tmp, int flag);
+void show_chatprivs(unsigned long cp, char *tmp, int flag);
+void show_protection(unsigned long cm, unsigned long cp, char *tmp, int ourapl);
+
 #endif /* TALKER_PRIVS_H */
-

Modified: trunk/src/user.c
===================================================================
--- trunk/src/user.c	2015-09-25 16:00:41 UTC (rev 1394)
+++ trunk/src/user.c	2015-09-29 10:28:10 UTC (rev 1395)
@@ -27,3 +27,14 @@
 	Unlock_File(outfile);
 	close(outfile);
 }
+
+void fetch_user(struct person *record, int32_t userposn)
+{       
+        int outfile;
+        
+        outfile=userdb_open(O_RDWR|O_CREAT);
+        lseek(outfile,userposn,0);
+        read(outfile,record,sizeof(*record));
+        close(outfile);
+}       
+

Modified: trunk/src/user.h
===================================================================
--- trunk/src/user.h	2015-09-25 16:00:41 UTC (rev 1394)
+++ trunk/src/user.h	2015-09-29 10:28:10 UTC (rev 1395)
@@ -52,5 +52,7 @@
 
 extern int userdb_open(int flags);
 extern void userdb_write(struct person *record, int32_t *userposn);
+extern void fetch_user(struct person *record, int32_t userposn);
 
+
 #endif

Modified: trunk/src/webclient/import.c
===================================================================
--- trunk/src/webclient/import.c	2015-09-25 16:00:41 UTC (rev 1394)
+++ trunk/src/webclient/import.c	2015-09-29 10:28:10 UTC (rev 1395)
@@ -64,16 +64,6 @@
         return(0);
 }
 
-void fetch_user(struct person *record, int32_t userposn)
-{
-        int outfile;  
- 
-        outfile=userdb_open(O_RDWR|O_CREAT);
-        lseek(outfile,userposn,0);
-        read(outfile,record,sizeof(*record));
-        close(outfile);
-}
-
 void broadcast_onoffcode(int code, int method, const char *sourceuser, const char *reason)
 {
         char            logofftext[MAXTEXTLENGTH];

Modified: trunk/src/webclient/import.h
===================================================================
--- trunk/src/webclient/import.h	2015-09-25 16:00:41 UTC (rev 1394)
+++ trunk/src/webclient/import.h	2015-09-29 10:28:10 UTC (rev 1395)
@@ -6,7 +6,6 @@
 int get_person(int file, struct person *tmp);
 void update_user(struct person *record, int32_t userposn);
 unsigned long cm_flags(unsigned long cm, unsigned long flags, int mode);
-void fetch_user(struct person *record, int32_t userposn);
 char *quotetext(const char *a);
 void broadcast_onoffcode(int code, int method, const char *sourceuser, const char *reason);
 void show_chatmodes(unsigned long cm, char *tmp, int flag);

Modified: trunk/src/who.c
===================================================================
--- trunk/src/who.c	2015-09-25 16:00:41 UTC (rev 1394)
+++ trunk/src/who.c	2015-09-29 10:28:10 UTC (rev 1395)
@@ -49,6 +49,7 @@
 	Unlock_File(wfd);
 }
 
+/* find userid of logged in users */
 long who_find(const char * username)
 {
 	int             who_fd;




More information about the mw-devel mailing list