[mw-devel] [Git][arthur/mw][master] Move ownership of gags to the server
Andrew Price
welshbyte at sucs.org
Sat Jul 29 18:21:47 BST 2017
Andrew Price pushed to branch master at Justin Mitchell / mw
Commits:
01e20578 by Andrew Price at 2017-07-29T18:18:36+01:00
Move ownership of gags to the server
The client now just caches a simple list of gag names that the server
sends it via a new IPC_GAGLIST message.
- - - - -
15 changed files:
- src/client/completion.c
- + src/client/gaglist.c
- + src/client/gaglist.h
- src/client/incoming.c
- src/client/script.c
- src/client/talker_privs.c
- src/client/talker_privs.h
- src/ipc.c
- src/ipc.h
- src/server/actions.c
- src/gags.c → src/server/gags.c
- src/gags.h → src/server/gags.h
- src/gagtable.c → src/server/gagtable.c
- src/gagtable.h → src/server/gagtable.h
- src/server/servsock.c
Changes:
=====================================
src/client/completion.c
=====================================
--- a/src/client/completion.c
+++ b/src/client/completion.c
@@ -4,6 +4,7 @@
#include "talker_privs.h"
#include "alias.h"
#include "who.h"
+#include "gaglist.h"
/*
modes: 0 - commands
@@ -48,7 +49,7 @@ CompletionList tctable[]={
{"emote's" ,1 ,1 ,-1 ,part_who_talk},
{"event" ,1 ,1 ,1 ,list_script},
{"freeze" ,1 ,1 ,1 ,part_who_talk},
-{"gag" ,1 ,2 ,2 ,part_gag_filter},
+{"gag" ,1 ,2 ,2 ,gaglist_tc_filter},
{"gag" ,1 ,1 ,2 ,part_who_talk},
{"kick" ,1 ,1 ,1 ,part_who_talk},
{"load" ,1 ,1 ,1 ,list_mwsfile},
=====================================
src/client/gaglist.c
=====================================
--- /dev/null
+++ b/src/client/gaglist.c
@@ -0,0 +1,51 @@
+#include <stdlib.h>
+#include <string.h>
+
+#include "gaglist.h"
+
+char **gaglist;
+size_t gaglist_len;
+
+int gaglist_append(const char *gagname)
+{
+ char **tmp;
+
+ if (gaglist_len == GAGLIST_MAX_ENTRIES)
+ return 1;
+ tmp = realloc(gaglist, sizeof(*gaglist) * (gaglist_len + 1));
+ if (tmp == NULL) {
+ free(gaglist);
+ gaglist_len = 0;
+ return 1;
+ }
+ gaglist = tmp;
+ gaglist[gaglist_len++] = strdup(gagname);
+ return 0;
+}
+
+void gaglist_destroy(void)
+{
+ for (size_t i = 0; i < gaglist_len; i++)
+ free(gaglist[i]);
+ free(gaglist);
+}
+
+char *gaglist_tc_filter(const char *text, int state)
+{
+ static size_t len = 0;
+ static size_t i = 0;
+
+ if (state == 0) {
+ i = 0;
+ len = strlen(text);
+ }
+
+ for (; i < gaglist_len; i++) {
+ if (*gaglist[i] == '\0')
+ continue;
+ if (len == 0 || !strncasecmp(gaglist[i], text, len))
+ return strdup(gaglist[i++]);
+ }
+ return NULL;
+}
+
=====================================
src/client/gaglist.h
=====================================
--- /dev/null
+++ b/src/client/gaglist.h
@@ -0,0 +1,10 @@
+#ifndef GAGLIST_H
+#define GAGLIST_H
+
+#define GAGLIST_MAX_ENTRIES (128)
+
+extern int gaglist_append(const char *gagname);
+extern void gaglist_destroy(void);
+extern char *gaglist_tc_filter(const char *text, int state);
+
+#endif /* GAGLIST_H */
=====================================
src/client/incoming.c
=====================================
--- a/src/client/incoming.c
+++ b/src/client/incoming.c
@@ -28,6 +28,7 @@
#include "user.h"
#include "util.h"
#include "incoming.h"
+#include "gaglist.h"
#include <jansson.h>
#include <str_util.h>
@@ -667,6 +668,20 @@ static void display_content(ipc_message_t *msg)
force_vtext(msg, whom, "%s gives the reason \"%s\".", whom, reason);
}
}
+ } else
+ if (msg->head.type == IPC_GAGLIST) {
+ json_t *jgag;
+ size_t i = 0;
+
+ if (j== NULL || !json_is_array(j)) {
+ printf("Invalid GAGLIST message from %s.\n", whom);
+ json_decref(j);
+ return;
+ }
+ gaglist_destroy();
+ json_array_foreach(j, i, jgag) {
+ gaglist_append(json_string_value(jgag));
+ }
} else {
printf("Unknown message type %4.4s", (char *)&msg->head.type);
}
@@ -716,6 +731,9 @@ static void accept_pipe_cmd(ipc_message_t *msg, struct user *mesg_user)
case IPC_GAG:
force_gag(newbuff, mesg_user->record.chatprivs, mesg_user->record.name);
break;
+ case IPC_GAGLIST:
+ display_content(msg);
+ break;
case IPC_PROTLEVEL:
force_protlevel(newbuff, mesg_user->record.chatprivs, mesg_user->record.name);
break;
=====================================
src/client/script.c
=====================================
--- a/src/client/script.c
+++ b/src/client/script.c
@@ -23,6 +23,7 @@
#include "user.h"
#include "userio.h"
#include "who.h"
+#include "gaglist.h"
#include <util.h>
#define MAX_ARGC 128
@@ -138,7 +139,7 @@ FuncNames scrtc[]={
{"talkname" ,part_who_talk},
{"whoname" ,part_who},
{"username" ,part_user},
-{"gag" ,part_gag_filter},
+{"gag" ,gaglist_tc_filter},
{"bind" ,list_bind},
{"boardexec" ,list_commands},
{"exec" ,list_chat_commands},
=====================================
src/client/talker_privs.c
=====================================
--- a/src/client/talker_privs.c
+++ b/src/client/talker_privs.c
@@ -5,7 +5,6 @@
#include "talker.h"
#include "bb.h"
#include "rooms.h"
-#include <gags.h>
#include "main.h"
#include "user.h"
#include <util.h>
@@ -17,22 +16,16 @@ unsigned long chatmode_describe(unsigned long old, unsigned long new, int ourapl
{
static char message[81];
unsigned long add, sub, dif;
- unsigned long oldg, newg, difg;
/* oldp, newp are permanent protection levels. oldep, newep are
* effective levels, which include temporarary protection.
*/
int oldp, oldep, newp, newep, difp;
- /* get new and old gag flags */
- 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;
- difg = oldg^newg;
difp = newp-oldp;
/* Protection level changes don't count as flags added/removed. */
add = new & dif & ~CM_PROTMASK;
@@ -120,31 +113,6 @@ unsigned long chatmode_describe(unsigned long old, unsigned long new, int ourapl
return(old);
}
- /* check for a new gag */
- if (difg!=0)
- {
- GagInfo *gi = gag_find(newg);
-
- if (gi!=NULL)
- {
- /* gag was enabled */
- _autofree char *buff=NULL;
- asprintf(&buff, "*** %s", gi->gag);
- display_message(buff, 1, 1);
- }
- else
- {
- /* gag was disabled, what -used- to be set */
- gi = gag_find(oldg);
- if (gi!=NULL)
- {
- _autofree char *buff=NULL;
- asprintf(&buff, "*** %s", gi->ungag);
- display_message(buff, 1, 1);
- }
- }
- }
-
if (add & CM_VERBOSE)
display_message("*** You have just been verbosed!", 1, 1);
if (sub & CM_VERBOSE)
@@ -196,33 +164,3 @@ unsigned long chatmode_describe(unsigned long old, unsigned long new, int ourapl
return(new);
}
-
-
-/***************************/
-/* user->chatprivs options */
-
-char *part_gag_filter(const char *text, int state)
-{
- static int ptr=0;
- static int len=0;
- char *c;
-
- if (state==0)
- {
- ptr=0;
- len=strlen(text);
- }
-
- while (gaglist[ptr].name!=NULL)
- {
- if ((len==0 || !strncasecmp(gaglist[ptr].name, text, len)) && strcmp(gaglist[ptr].name, ""))
- {
- c=dupstr(gaglist[ptr].name,"");
- ptr++;
- return(c);
- }
- ptr++;
- }
- return(NULL);
-}
-
=====================================
src/client/talker_privs.h
=====================================
--- a/src/client/talker_privs.h
+++ b/src/client/talker_privs.h
@@ -3,7 +3,6 @@
#include <talker_privs.h>
-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);
#endif /* CLIENT_TALKER_PRIVS_H */
=====================================
src/ipc.c
=====================================
--- a/src/ipc.c
+++ b/src/ipc.c
@@ -193,6 +193,7 @@ const char * ipc_nametype(enum ipc_types msgtype)
case IPC_CHANNEL: return "IPC_CHANNEL"; break;
case IPC_WIZ: return "IPC_WIZ"; break;
case IPC_GAG: return "IPC_GAG"; break;
+ case IPC_GAGLIST: return "IPC_GAGLIST"; break;
case IPC_SCRIPTIPC: return "IPC_SCRIPTIPC"; break;
case IPC_SCRIPTRPC: return "IPC_SCRIPTRPC"; break;
case IPC_CHECKONOFF: return "IPC_CHECKONOFF"; break;
=====================================
src/ipc.h
=====================================
--- a/src/ipc.h
+++ b/src/ipc.h
@@ -35,6 +35,7 @@ enum ipc_types {
IPC_CHANNEL = 16,
IPC_WIZ = 17,
IPC_GAG = 18,
+ IPC_GAGLIST = 19,
IPC_SCRIPTIPC = 21,
IPC_SCRIPTRPC = 22,
IPC_CHECKONOFF = 23,
=====================================
src/server/actions.c
=====================================
--- a/src/server/actions.c
+++ b/src/server/actions.c
@@ -21,8 +21,8 @@
#include <talker_privs.h>
#include <ipc.h>
#include <perms.h>
-#include <gags.h>
+#include "gags.h"
#include "servsock.h"
#include "replay.h"
#include "actions.h"
@@ -194,6 +194,16 @@ void accept_action(ipc_connection_t *conn, ipc_message_t *msg)
ipcmsg_append(update, buff, strlen(buff));
msg_attach_to_username(update, victim_name);
ipcmsg_destroy(update);
+
+ ipc_message_t *gm = ipcmsg_create(IPC_EVENT, msg->head.src);
+ json_t * gj = json_init(NULL);
+ json_addstring(gj, "target", victim_name);
+ json_addint(gj, "success", success);
+ json_addstring(gj, "type", "gag");
+ json_vaddstring(gj, "text", "%s", gag_gag_msg(gtnum));
+ ipcmsg_json_encode(gm, gj);
+ msg_attach_to_username(gm, victim_name);
+ ipcmsg_destroy(gm);
} else {
json_vaddstring(ej, "text", "%s just tried to gag %s with %s and failed",
attacker_name, victim_name, gag_type(gtnum));
@@ -215,7 +225,11 @@ void accept_action(ipc_connection_t *conn, ipc_message_t *msg)
json_addstring(ej, "type", "ungag");
if (success) {
- json_vaddstring(ej, "text", "%s has just ungagged %s", attacker_name, victim_name);
+ unsigned long old = victim.record.chatmode;
+ unsigned long oldg = (old & CM_GAGMASK) >> CM_GAGSHIFT;
+
+ json_vaddstring(ej, "text", "%s has just ungagged %s",
+ attacker_name, victim_name);
// change users mode
_autofree char *buff=NULL;
@@ -225,6 +239,16 @@ void accept_action(ipc_connection_t *conn, ipc_message_t *msg)
ipcmsg_append(update, buff, strlen(buff));
msg_attach_to_username(update, victim_name);
ipcmsg_destroy(update);
+
+ ipc_message_t *gm = ipcmsg_create(IPC_EVENT, msg->head.src);
+ json_t * gj = json_init(NULL);
+ json_addstring(gj, "target", victim_name);
+ json_addint(gj, "success", success);
+ json_addstring(gj, "type", "ungag");
+ json_vaddstring(gj, "text", "%s", gag_ungag_msg(oldg));
+ ipcmsg_json_encode(gm, gj);
+ msg_attach_to_username(gm, victim_name);
+ ipcmsg_destroy(gm);
} else {
json_vaddstring(ej, "text", "%s just tried to ungag %s and failed",
attacker_name, victim_name);
=====================================
src/gags.c → src/server/gags.c
=====================================
--- a/src/gags.c
+++ b/src/server/gags.c
@@ -433,6 +433,20 @@ GagInfo * gag_find(int num)
return NULL;
}
+const char *gag_gag_msg(int type)
+{
+ GagInfo *gi = gag_find(type);
+
+ return gi ? gi->gag : "Unknown";
+}
+
+const char *gag_ungag_msg(int type)
+{
+ GagInfo *gi = gag_find(type);
+
+ return gi ? gi->ungag : "Unknown";
+}
+
int gag_code(const char *str)
{
GagInfo *gi = gaglist;
=====================================
src/gags.h → src/server/gags.h
=====================================
--- a/src/gags.h
+++ b/src/server/gags.h
@@ -22,5 +22,7 @@ char * apply_gag(struct user *speaker, const char *text);
GagInfo *gag_find(int num);
int gag_code(const char *str);
const char *gag_type(int type);
+const char *gag_gag_msg(int type);
+const char *gag_ungag_msg(int type);
#endif /* GAGS_H */
=====================================
src/gagtable.c → src/server/gagtable.c
=====================================
=====================================
src/gagtable.h → src/server/gagtable.h
=====================================
=====================================
src/server/servsock.c
=====================================
--- a/src/server/servsock.c
+++ b/src/server/servsock.c
@@ -25,8 +25,8 @@
#include "servsock.h"
#include "replay.h"
#include "actions.h"
+#include "gags.h"
#include <folders.h>
-#include <gags.h>
#include <perms.h>
#include <special.h>
@@ -267,6 +267,18 @@ void send_error(ipc_connection_t *conn, ipc_message_t *orig, const char *format,
json_decref(j);
}
+static ipc_message_t *msg_gaglist(void)
+{
+ ipc_message_t * msg = ipcmsg_create(IPC_GAGLIST, SYSTEM_USER);
+ json_t *arr = json_array();
+
+ for (GagInfo *gi = gaglist; gi->name != NULL; gi++)
+ json_array_append_new(arr, json_string(gi->name));
+
+ ipcmsg_json_encode(msg, arr);
+ json_decref(arr);
+ return msg;
+}
void process_msg(ipc_connection_t *conn, ipc_message_t *msg)
{
@@ -308,6 +320,10 @@ void process_msg(ipc_connection_t *conn, ipc_message_t *msg)
ipc_message_t * whoinfo = msg_wholist();
msg_attach_to_all(whoinfo);
ipcmsg_destroy(whoinfo);
+
+ ipc_message_t *gaginfo = msg_gaglist();
+ msg_attach(gaginfo, conn);
+ ipcmsg_destroy(gaginfo);
return;
}
View it on GitLab: https://projects.sucs.org/arthur/mw/commit/01e20578fe6f38bee46a10be2852c48cbfdca5df
---
View it on GitLab: https://projects.sucs.org/arthur/mw/commit/01e20578fe6f38bee46a10be2852c48cbfdca5df
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/20170729/672e37f8/attachment-0001.html>
More information about the mw-devel
mailing list