[mw-devel] MW3 r1175 - trunk/src/webclient
arthur at sucs.org
arthur at sucs.org
Wed Oct 6 13:40:41 BST 2010
Author: arthur
Date: 2010-10-06 13:40:41 +0100 (Wed, 06 Oct 2010)
New Revision: 1175
Modified:
trunk/src/webclient/comms.c
Log:
add channel and kick support
Modified: trunk/src/webclient/comms.c
===================================================================
--- trunk/src/webclient/comms.c 2010-10-06 11:31:43 UTC (rev 1174)
+++ trunk/src/webclient/comms.c 2010-10-06 12:40:41 UTC (rev 1175)
@@ -264,6 +264,8 @@
list_del(pos);
snprintf(&buff[len], sizeof(buff)-len, "{\"state\":%d,\"pid\":%d,\"username\":\"%s\",\"text\":\"%s\"}", tmp->state, tmp->pid, tmp->user.name, tmp->text);
+
+ if (tmp->state == IPC_KICK) die=1;
free(tmp->text);
free(tmp);
n++;
@@ -278,16 +280,17 @@
}
-char * json_escape(char *in)
+char * json_escape(char *original)
{
- int maxlen = (strlen(in)*2) + 1;
+ int maxlen = (strlen(original)*2) + 1;
char *line = malloc(maxlen);
line[0] = 0;
int i;
char *out = line;
+ unsigned char *in = (unsigned char *)original;
- for (i=0;i<strlen(in);i++) {
- switch (in[i]) {
+ for (i=0;i<strlen(original);i++) {
+ switch (*in) {
case '\b': snprintf(out, maxlen, "\\b"); out+=2; maxlen-=2; break;
case '\n': snprintf(out, maxlen, "\\n"); out+=2; maxlen-=2; break;
case '\r': snprintf(out, maxlen, "\\r"); out+=2; maxlen-=2; break;
@@ -296,11 +299,12 @@
case '\\': snprintf(out, maxlen, "\\\\"); out+=2; maxlen-=2; break;
case '/': snprintf(out, maxlen, "\\/"); out+=2; maxlen-=2; break;
default:
- if (in[i] < ' ') {
- snprintf(out, maxlen, "\\u%04x", in[i]); out+=6; maxlen-=6; break;
+ if (*in < ' ') {
+ snprintf(out, maxlen, "\\u%04x", *in); out+=6; maxlen-=6; break;
}else
- snprintf(out, maxlen, "%c", in[i]); out+=1; maxlen-=1; break;
+ snprintf(out, maxlen, "%c", *in); out+=1; maxlen-=1; break;
}
+ in++;
if (maxlen < 2) break;
}
*out = 0;
@@ -350,6 +354,12 @@
send(co->fd, buff, strlen(buff), 0);
return 0; // dont close
}else
+ if (strncasecmp(buff, "channel ", 8)==0) {
+ user->room = atoi(&buff[8]);
+ snprintf(buff, sizeof buff, "{\"channel\":%d}", user->room);
+ send(co->fd, buff, strlen(buff), 0);
+ return 0; // dont close
+ }else
if (co->authd && strncasecmp(buff, "say ", 4)==0) {
struct filter_info f_info;
char line[8192];
More information about the mw-devel
mailing list