[mw-devel] MW3 r1193 - trunk/src/webclient
arthur at sucs.org
arthur at sucs.org
Fri Oct 8 14:43:38 BST 2010
Author: arthur
Date: 2010-10-08 14:43:38 +0100 (Fri, 08 Oct 2010)
New Revision: 1193
Modified:
trunk/src/webclient/Makefile
trunk/src/webclient/comms.c
trunk/src/webclient/import.c
trunk/src/webclient/import.h
Log:
whoami command
Modified: trunk/src/webclient/Makefile
===================================================================
--- trunk/src/webclient/Makefile 2010-10-08 11:30:05 UTC (rev 1192)
+++ trunk/src/webclient/Makefile 2010-10-08 13:43:38 UTC (rev 1193)
@@ -48,7 +48,7 @@
.PHONY: build install clean test
-mwpoll: mwpoll.o import.o comms.o mwstring.o ../perms.o ../strings.o ../files.o ../ipc.o ../iconv.o
+mwpoll: mwpoll.o import.o comms.o mwstring.o ../perms.o ../strings.o ../files.o ../ipc.o ../iconv.o ../special.o
$(CC) $(LDFLAGS) $(LDLIBS) -o $@ $^
clean:
Modified: trunk/src/webclient/comms.c
===================================================================
--- trunk/src/webclient/comms.c 2010-10-08 11:30:05 UTC (rev 1192)
+++ trunk/src/webclient/comms.c 2010-10-08 13:43:38 UTC (rev 1193)
@@ -15,6 +15,7 @@
#include <strings.h>
#include <talker_privs.h>
+#include <special.h>
#include <ipc.h>
#include <perms.h>
#include <bb.h>
@@ -301,7 +302,7 @@
send(co->fd, mws_cstr(buff), mws_len(buff), 0);
mws_free(buff);
printf("Sending %d items.\n", n);
- return 1;
+ return n>0?1:0;
}
char * json_escape(char *original)
@@ -435,6 +436,38 @@
mws_free(line);
return 1;
}else
+ if (co->authd && strcasecmp(buff, "whoami")==0) {
+ mwstring *line = mws_new(2048);
+ char stats[64];
+ char *tmp;
+ mws_add(line, "{");
+ mws_add(line, "\"username\":\"%s\",", user->name);
+ tmp = json_escape(user->realname);
+ mws_add(line, "\"realname\":\"%s\",", tmp);
+ free(tmp);
+ tmp = json_escape(user->contact);
+ mws_add(line, "\"contact\":\"%s\",", tmp);
+ free(tmp);
+ tmp = json_escape(user->doing);
+ mws_add(line, "\"doing\":\"%s\",", tmp);
+ free(tmp);
+ mws_add(line, "\"lastlogout\":%d,", user->lastlogout);
+ show_user_stats(user->status, stats, 0);
+ mws_add(line, "\"status\":\"%s\",", stats);
+ show_special(user->special, stats, 0);
+ mws_add(line, "\"special\":\"%s\",", stats);
+ show_chatmodes(user->chatmode, stats, 0);
+ mws_add(line, "\"chatmodes\":\"%s\",", stats);
+ show_chatprivs(user->chatprivs, stats, 0);
+ mws_add(line, "\"chatprivs\":\"%s\",", stats);
+
+ mws_add(line, "\"room\":%d,", user->room);
+ mws_add(line, "\"colour\":%d", user->colour);
+ mws_add(line, "}");
+ send(co->fd, mws_cstr(line), mws_len(line), 0);
+ mws_free(line);
+ return 1;
+ }else
if (co->authd && strncasecmp(buff, "say ", 4)==0) {
struct filter_info f_info;
char line[8192];
Modified: trunk/src/webclient/import.c
===================================================================
--- trunk/src/webclient/import.c 2010-10-08 11:30:05 UTC (rev 1192)
+++ trunk/src/webclient/import.c 2010-10-08 13:43:38 UTC (rev 1193)
@@ -183,3 +183,43 @@
ipc_send_to_all(IPC_CHECKONOFF, logofftext, NULL, NULL);
}
+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_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++]='-';
+
+ tmp[i]=0;
+}
+
Modified: trunk/src/webclient/import.h
===================================================================
--- trunk/src/webclient/import.h 2010-10-08 11:30:05 UTC (rev 1192)
+++ trunk/src/webclient/import.h 2010-10-08 13:43:38 UTC (rev 1193)
@@ -8,3 +8,5 @@
char *quotetext(const char *a);
void strip_quote(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);
+void show_chatprivs(unsigned long cp, char *tmp, int flag);
More information about the mw-devel
mailing list