[mw-devel] MW3 r1400 - in trunk/src: . client server
arthur at sucs.org
arthur at sucs.org
Mon Oct 5 15:17:29 BST 2015
Author: arthur
Date: 2015-10-05 15:17:29 +0100 (Mon, 05 Oct 2015)
New Revision: 1400
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/gags.c
trunk/src/gags.h
trunk/src/server/PROTOCOL
trunk/src/server/actions.c
Log:
Turn gag command into a new format action
Modified: trunk/src/client/incoming.c
===================================================================
--- trunk/src/client/incoming.c 2015-10-05 10:23:24 UTC (rev 1399)
+++ trunk/src/client/incoming.c 2015-10-05 14:17:29 UTC (rev 1400)
@@ -915,14 +915,17 @@
static void force_gag(char *newbuff, unsigned long theirprivs, const char *from)
{
- unsigned long mm, mm2;
int ourapl = (user->chatprivs & CP_PROTMASK) >> CP_PROTSHIFT;
int theirapl = (theirprivs & CP_PROTMASK) >> CP_PROTSHIFT;
if (!cm_flags(theirprivs, CP_PROTECT, CM_MODE_ALL)) theirapl = 0;
- mm=cm_setbycode(user->chatmode, "-12345678");
- mm2=cm_setbycode(mm, newbuff);
- user->chatmode=chatmode_describe(user->chatmode, mm2, ourapl, theirapl, from);
+
+ unsigned long newcm = user->chatmode & ~CM_GAGMASK;
+ if (newbuff[0]=='+')
+ newcm |= atoi(&newbuff[1]) << CM_GAGSHIFT;
+
+ user->chatmode=chatmode_describe(user->chatmode, newcm, ourapl, theirapl, from);
+
disable_rl(1);
}
Modified: trunk/src/client/talker.c
===================================================================
--- trunk/src/client/talker.c 2015-10-05 10:23:24 UTC (rev 1399)
+++ trunk/src/client/talker.c 2015-10-05 14:17:29 UTC (rev 1400)
@@ -884,59 +884,25 @@
void t_gag(CommandList *cm, int argc, const char **argv, char *args)
{
- char text[MAXTEXTLENGTH];
- char num[5];
- int type=0;
-
- if (argc<3) type = 1; else type = gag_code(argv[2]);
-
- if (type==0)
- {
- snprintf(text,MAXTEXTLENGTH-1,"Unknown gag type '%s'",argv[2]);
- display_message(text, 1, 1);
- }else
- {
- int i,j;
-
- snprintf(text,MAXTEXTLENGTH-1,"+");
- j=1;
- for(i=1;i<=MAX_GAG_FLAG;i++)
- {
- if (type & j)
- {
- snprintf(num, 4, "%d", i);
- strncat(text, num, MAXTEXTLENGTH - strlen(text) - 1);
- }
- j+=j;
- }
-
- ipc_send_to_username(argv[1], IPC_GAG, text);
- snprintf(text,MAXTEXTLENGTH-1,"\03315%s has just tried to %s %s.",user->name, gag_type(type), argv[1]);
- talk_send_raw(text,user->room);
- }
+ 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", "gag");
+ json_addstring(j, "gag", argv[2]);
+ ipcmsg_json_encode(msg, j);
+ json_decref(j);
+ ipcmsg_transmit(msg);
}
void t_ungag(CommandList *cm, int argc, const char **argv, char *args)
{
- char text[MAXTEXTLENGTH];
- int32_t gpos;
- struct person gusr;
-
- if (!is_old(&gusr,argv[1],&gpos))
- {
- printf("Username %s not found.\n", argv[1]);
- return;
- }
-
- if (argc>2)
- {
- printf("Usage: ungag <user>\n");
- return;
- }
-
- ipc_send_to_username(argv[1], IPC_GAG, "-12345678");
- snprintf(text,MAXTEXTLENGTH-1,"\03315%s has just tried to %s %s.",user->name, ungag_name(gusr.chatmode), argv[1]);
- talk_send_raw(text,user->room);
+ 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", "ungag");
+ ipcmsg_json_encode(msg, j);
+ json_decref(j);
+ ipcmsg_transmit(msg);
}
void t_ignorelist(CommandList *cm, int argc, const char **argv, char *args)
Modified: trunk/src/client/talker_privs.c
===================================================================
--- trunk/src/client/talker_privs.c 2015-10-05 10:23:24 UTC (rev 1399)
+++ trunk/src/client/talker_privs.c 2015-10-05 14:17:29 UTC (rev 1400)
@@ -9,88 +9,13 @@
#include "main.h"
#include "user.h"
#include <gags.h>
+#include <util.h>
extern struct person *user;
extern long userposn;
extern int quietmode;
extern struct room myroom;
-int gag_code(const char *str)
-{
- GagInfo *gi = gaglist;
- int count = 0;
-
- while(gi->name)
- {
- count++;
- if (!strcasecmp(str, gi->name)) return(count);
- gi++;
- }
- return(0);
-}
-
-const char *gag_type(int type)
-{
- GagInfo *gi = gaglist;
- int count = 0;
-
- while(gi->name)
- {
- count++;
- if (count == type) return(gi->text);
- gi++;
- }
- return("Unknown");
-}
-
-const char *ungag_name(unsigned long chatmode)
-{
- GagInfo *gi;
-
- gi = gaglist;
- while(gi->name)
- {
- if (flag_match(chatmode, gi->name)) return(gi->untext);
- gi++;
- }
- return("Ungag");
-}
-
-static unsigned long gag_flags(const char *str)
-{
- int i,j, type;
- unsigned long p=0;
-
- type = gag_code(str);
-
- j=1;
- for(i=1;i<=MAX_GAG_FLAG;i++)
- {
- if (type & j)
- {
- switch (i)
- {
- 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;
- }
- }
- j+=j;
- }
- return(p);
-}
-
-int flag_match(unsigned long val, const char *filter)
-{
- unsigned long flags = gag_flags(filter);
- unsigned long new = val&cm_setbycode(val, "12345678");
-
- return(new==flags);
-}
-
unsigned long chatmode_describe(unsigned long old, unsigned long new, int ourapl, int theirapl, const char *from)
{
static char message[81];
@@ -102,14 +27,14 @@
int oldp, oldep, newp, newep, difp;
/* get new and old gag flags */
- newg = new & cm_setbycode(new, "12345678");
- oldg = old & cm_setbycode(old, "12345678");
+ newg = (new & CM_GAGMASK) >> CM_GAGSHIFT;
+ oldg = (old & CM_GAGMASK) >> CM_GAGSHIFT;
/* get new and old protection flags */
newp = (new & CM_PROTMASK) >> CM_PROTSHIFT;
oldp = (old & CM_PROTMASK) >> CM_PROTSHIFT;
- dif= old^new;
+ dif = old^new;
difg = oldg^newg;
difp = newp-oldp;
/* Protection level changes don't count as flags added/removed. */
@@ -201,44 +126,24 @@
/* check for a new gag */
if (difg!=0)
{
- GagInfo *gi;
- char *buff=NULL;
+ GagInfo *gi = gag_find(newg);
- gi = gaglist;
- while(gi->name)
+ if (gi!=NULL)
{
- if (flag_match(newg, gi->name))
- {
- if (buff!=NULL) free(buff);
- buff = malloc(sizeof(char) * (strlen(gi->gag) + 5));
- sprintf(buff, "*** %s", gi->gag);
- }
- gi++;
- }
-
- if (buff!=NULL)
- {
+ /* gag was enabled */
+ AUTOFREE_BUFFER buff=NULL;
+ asprintf(&buff, "*** %s", gi->gag);
display_message(buff, 1, 1);
- free(buff);
}
else
{
- gi = gaglist;
- while(gi->name)
+ /* gag was disabled, what -used- to be set */
+ gi = gag_find(oldg);
+ if (gi!=NULL)
{
- if (flag_match(oldg, gi->name))
- {
- if (buff!=NULL) free(buff);
- buff = malloc(sizeof(char) * (strlen(gi->ungag) + 5));
- sprintf(buff, "*** %s", gi->ungag);
- }
- gi++;
- }
-
- if (buff!=NULL)
- {
+ AUTOFREE_BUFFER buff=NULL;
+ asprintf(&buff, "*** %s", gi->ungag);
display_message(buff, 1, 1);
- free(buff);
}
}
}
Modified: trunk/src/client/talker_privs.h
===================================================================
--- trunk/src/client/talker_privs.h 2015-10-05 10:23:24 UTC (rev 1399)
+++ trunk/src/client/talker_privs.h 2015-10-05 14:17:29 UTC (rev 1400)
@@ -3,11 +3,6 @@
#include <talker_privs.h>
-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);
-
char *part_gag_filter(const char *text, int state);
unsigned long chatmode_describe(unsigned long old, unsigned long new, int ourapl, int theirapl, const char *from);
Modified: trunk/src/gags.c
===================================================================
--- trunk/src/gags.c 2015-10-05 10:23:24 UTC (rev 1399)
+++ trunk/src/gags.c 2015-10-05 14:17:29 UTC (rev 1400)
@@ -8,6 +8,7 @@
#include "gagtable.h"
#include "user.h"
#include "talker_privs.h"
+#include "gags.h"
/* should be defined by strings.h */
char *strfry(char *string);
@@ -405,6 +406,52 @@
return(c);
}
+const char *gag_type(int type)
+{
+ GagInfo *gi = gag_find(type);
+
+ if (gi != NULL) return(gi->text);
+ return("Unknown");
+}
+
+GagInfo * gag_find(int num)
+{
+ GagInfo *gi = gaglist;
+ int count = 0;
+
+ while(gi->name)
+ {
+ count++;
+ if (count == num) return(gi);
+ gi++;
+ }
+ return NULL;
+}
+
+int gag_code(const char *str)
+{
+ GagInfo *gi = gaglist;
+ int count = 0;
+
+ while(gi->name)
+ {
+ count++;
+ if (!strcasecmp(str, gi->name)) return(count);
+ gi++;
+ }
+ return(0);
+}
+
+const char *ungag_name(unsigned long chatmode)
+{
+ int gnum = (chatmode & CM_GAGMASK) >> CM_GAGSHIFT;
+ return gag_type(gnum);
+}
+
+/***************************************************************
+ * the gag filters
+ */
+
/* tnarg dyslexication filter */
void gag_tnarg(char *text)
{
Modified: trunk/src/gags.h
===================================================================
--- trunk/src/gags.h 2015-10-05 10:23:24 UTC (rev 1399)
+++ trunk/src/gags.h 2015-10-05 14:17:29 UTC (rev 1400)
@@ -19,5 +19,9 @@
extern GagInfo gaglist[];
char * apply_gag(struct person *speaker, const char *text);
+GagInfo *gag_find(int num);
+int gag_code(const char *str);
+const char *gag_type(int type);
+const char *ungag_name(unsigned long chatmode);
#endif /* GAGS_H */
Modified: trunk/src/server/PROTOCOL
===================================================================
--- trunk/src/server/PROTOCOL 2015-10-05 10:23:24 UTC (rev 1399)
+++ trunk/src/server/PROTOCOL 2015-10-05 14:17:29 UTC (rev 1400)
@@ -89,13 +89,20 @@
Header:
room number to be told, -1 for all
Body: (json)
- type - type of event that occured
- target - who did the event happen to
+ type - type of event that occured
+ target - who did the event happen to
success=0|1 - did it work
- text - prefered text for announcement
+ text - prefered text for announcement
verbose - additional (amusing) texts
- reason - justification (if any) the attacker gave
+ reason - justification (if any) the attacker gave
+ List of types, and any additional fields
+ zod - Zebedee of Death
+ mrod - Magic Roundabout of Death
+ gag - Apply gagging filter to user
+ gag - name of gag to Apply
+ ungag - remove gagging filters
+
IPC_ACTION - user requests an action
Body: (json)
type - type of event that occured
Modified: trunk/src/server/actions.c
===================================================================
--- trunk/src/server/actions.c 2015-10-05 10:23:24 UTC (rev 1399)
+++ trunk/src/server/actions.c 2015-10-05 14:17:29 UTC (rev 1400)
@@ -22,6 +22,7 @@
#include <talker_privs.h>
#include <ipc.h>
#include <perms.h>
+#include <gags.h>
#include "servsock.h"
#include "replay.h"
@@ -51,6 +52,7 @@
struct person victim;
int32_t toid = who_find(victim_username);
+ /* user needs to be actually logged in */
if (toid < 0) {
send_error(conn, msg, "User '%s' not found", victim_username);
return;
@@ -87,7 +89,7 @@
json_addstring(ej, "type", "mrod");
if (success) {
- json_addstring(ej, "text", "%s has just dropped the Magic Roundabout of Death on %s.", attacker.name, victim.name);
+ json_addstring(ej, "text", "%s has just dropped the Magic Roundabout of Death on %s", attacker.name, victim.name);
json_addstring(ej, "verbose", "You 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...");
// kick the person
@@ -105,7 +107,7 @@
ipcmsg_destroy(update);
} else {
- json_addstring(ej, "text", "%s just tried to MROD %s and failed.", attacker.name, victim.name);
+ json_addstring(ej, "text", "%s just tried to MROD %s and failed", attacker.name, victim.name);
}
ipcmsg_json_encode(event, ej);
json_decref(ej);
@@ -126,8 +128,8 @@
json_addstring(ej, "type", "zod");
if (success) {
- json_addstring(ej, "text", "%s has just sent the Zebedee of Death to %s.", attacker.name, victim.name);
- json_addstring(ej, "verbose", "You hear a boing in the distance.");
+ json_addstring(ej, "text", "%s has just sent the Zebedee of Death to %s", attacker.name, victim.name);
+ json_addstring(ej, "verbose", "You hear a boing in the distance");
// kick the person
AUTOFREE_BUFFER buff=NULL;
@@ -144,7 +146,7 @@
msg_attach_to_username(update, victim_username);
ipcmsg_destroy(update);
} else {
- json_addstring(ej, "text", "%s just tried to ZoD %s and failed.", attacker.name, victim.name);
+ json_addstring(ej, "text", "%s just tried to ZoD %s and failed", attacker.name, victim.name);
}
ipcmsg_json_encode(event, ej);
json_decref(ej);
@@ -154,5 +156,78 @@
return;
}
+ if (strcasecmp(command, "gag")==0) {
+ const char *gagtype = json_getstring(j, "gag");
+
+ if (gagtype == NULL) {
+ send_error(conn, msg, "Missing gag type");
+ return;
+ }
+
+ int gtnum = gag_code(gagtype);
+
+ if (gtnum == 0) {
+ send_error(conn, msg, "Gag type '%s' not found", gagtype);
+ return;
+ }
+
+ ipc_message_t * event = ipcmsg_create(IPC_EVENT, msg->head.src);
+ ipcmsg_destination(event, -1);
+ json_t * ej = json_init(NULL);
+ json_addstring(ej, "target", victim_username);
+ json_addint(ej, "success", success);
+ json_addstring(ej, "type", "gag");
+
+ if (success) {
+ json_addstring(ej, "text", "%s has just gagged %s with %s", attacker.name, victim.name, gag_type(gtnum));
+
+ // change users mode
+ AUTOFREE_BUFFER buff=NULL;
+ asprintf(&buff,"+%d", gtnum);
+ ipc_message_t *update = ipcmsg_create(IPC_GAG, msg->head.src);
+ ipcmsg_destination(update, toid);
+ ipcmsg_append(update, buff, strlen(buff));
+ msg_attach_to_username(update, victim_username);
+ ipcmsg_destroy(update);
+ } else {
+ json_addstring(ej, "text", "%s just tried to gag %s with %s and failed", attacker.name, victim.name, gag_type(gtnum));
+ }
+ ipcmsg_json_encode(event, ej);
+ json_decref(ej);
+
+ // annouce what happened to everyone else
+ process_msg(conn, event);
+ return;
+ }
+
+ if (strcasecmp(command, "ungag")==0) {
+ ipc_message_t * event = ipcmsg_create(IPC_EVENT, msg->head.src);
+ ipcmsg_destination(event, -1);
+ json_t * ej = json_init(NULL);
+ json_addstring(ej, "target", victim_username);
+ json_addint(ej, "success", success);
+ json_addstring(ej, "type", "ungag");
+
+ if (success) {
+ json_addstring(ej, "text", "%s has just ungagged %s", attacker.name, victim.name);
+
+ // change users mode
+ AUTOFREE_BUFFER buff=NULL;
+ asprintf(&buff,"-");
+ ipc_message_t *update = ipcmsg_create(IPC_GAG, msg->head.src);
+ ipcmsg_destination(update, toid);
+ ipcmsg_append(update, buff, strlen(buff));
+ msg_attach_to_username(update, victim_username);
+ ipcmsg_destroy(update);
+ } else {
+ json_addstring(ej, "text", "%s just tried to ungag %s and failed", attacker.name, victim.name);
+ }
+ ipcmsg_json_encode(event, ej);
+ json_decref(ej);
+
+ // annouce what happened to everyone else
+ process_msg(conn, event);
+ return;
+ }
send_error(conn, msg, "Command '%s' not understood", command);
}
More information about the mw-devel
mailing list