[mw-devel] MW3 r1320 - in trunk/src: . server
arthur at sucs.org
arthur at sucs.org
Sun Dec 30 19:25:33 GMT 2012
Author: arthur
Date: 2012-12-30 19:25:33 +0000 (Sun, 30 Dec 2012)
New Revision: 1320
Modified:
trunk/src/incoming.c
trunk/src/ipc.h
trunk/src/server/servsock.c
trunk/src/talker.c
Log:
"Shout, Shout, let it all out". .shout command ported
Modified: trunk/src/incoming.c
===================================================================
--- trunk/src/incoming.c 2012-12-30 17:11:56 UTC (rev 1319)
+++ trunk/src/incoming.c 2012-12-30 19:25:33 UTC (rev 1320)
@@ -591,7 +591,7 @@
/* we have global on, prepend the channel number */
if (cm_flags(user->chatmode, CM_GLOBAL, CM_MODE_ALL)) {
if (msg_posn == -1)
- snprintf(tb, len, "*:");
+ snprintf(tb, len, "?:");
else
snprintf(tb, len, "%d:", msg_user.room);
int s = strlen(tb);
@@ -608,6 +608,30 @@
snprintf(tb, len, "%s says: %s", whom, text);
}
force_text(buff, whom);
+ } else
+ if (msg->head.type == IPC_SAYTOALL) {
+ const char * text = json_getstring(j, "text");
+
+ if (text == NULL) {
+ printf("Invalid SAYTOALL message from %s.\n", whom);
+ json_decref(j);
+ return;
+ }
+
+ char buff[MAXTEXTLENGTH];
+ char * tb = buff;
+ int len = MAXTEXTLENGTH;
+
+ /* we have global on, prepend the channel number */
+ if (cm_flags(user->chatmode, CM_GLOBAL, CM_MODE_ALL)) {
+ snprintf(tb, len, "*:");
+ int s = strlen(tb);
+ len -= s;
+ tb += s;
+ }
+
+ snprintf(tb, len, "%s shouts: %s", whom, text);
+ force_text(buff, whom);
} else {
printf("Unknown message type %4.4s", (char *)&msg->head.type);
}
@@ -703,6 +727,7 @@
break;
case IPC_SAYTOROOM:
case IPC_SAYTOUSER:
+ case IPC_SAYTOALL:
display_content(msg);
break;
case IPC_TALKERROR:
Modified: trunk/src/ipc.h
===================================================================
--- trunk/src/ipc.h 2012-12-30 17:11:56 UTC (rev 1319)
+++ trunk/src/ipc.h 2012-12-30 19:25:33 UTC (rev 1320)
@@ -40,6 +40,7 @@
IPC_UPTIME = MKFOURCC('U','P','T','M'),
IPC_SAYTOROOM = MKFOURCC('S','A','Y','R'),
IPC_SAYTOUSER = MKFOURCC('S','A','Y','U'),
+ IPC_SAYTOALL = MKFOURCC('W','A','L','L'),
IPC_TALKERROR = MKFOURCC('T','E','R','R')
};
Modified: trunk/src/server/servsock.c
===================================================================
--- trunk/src/server/servsock.c 2012-12-30 17:11:56 UTC (rev 1319)
+++ trunk/src/server/servsock.c 2012-12-30 19:25:33 UTC (rev 1320)
@@ -278,6 +278,10 @@
return;
}
+ /* message types after this point are only valid if your logged in */
+ if (conn->state != IPCSTATE_VALID) return;
+
+ /* ask the server how long it has been up */
if (msg->head.type == FOURCC("UPTM")) {
time_t now = time(0);
@@ -328,7 +332,7 @@
msg_attach_to(msg, who.pid);
} else
/* room not soundproof, and user has global on */
- if (room.sproof == 0 && (user.chatmode & CM_GLOBAL)) {
+ if (room.sproof < 1 && (user.chatmode & CM_GLOBAL)) {
msg_attach_to(msg, who.pid);
}
}
@@ -376,6 +380,55 @@
return;
}
+ /* send message to everyone (unless this room is soundproof) */
+ if (msg->head.type == FOURCC("WALL")) {
+ /* eventually this should be a server maintained list */
+ int who_fd = openwhofile(O_RDONLY);
+ int users_fd = openuserfile(O_RDONLY);
+ struct who who;
+ struct person user;
+ struct person from;
+
+ /* the sender */
+ lseek(users_fd, conn->user, SEEK_SET);
+ read(users_fd, &from, sizeof(from));
+
+ /* load the senders room to see if its soundproof */
+ struct room room;
+ RoomInit(&room);
+ LoadRoom(&room, from.room);
+
+ printf("Shout from '%s' in %d (%s)\n", from.name, room.num, room.name);
+
+ while (read(who_fd, &who, sizeof(who)) > 0) {
+ if (who.posn < 0) continue;
+ if (who.pid <= 0) continue;
+
+ lseek(users_fd, who.posn, SEEK_SET);
+ if (read(users_fd, &user, sizeof(user)) <= 0) continue;
+
+ /* senders room is soundproof, act as if it was say in this room*/
+ if (room.sproof > 0) {
+ /* room matches, send them a copy */
+ if (user.room == from.room) {
+ msg_attach_to(msg, who.pid);
+ printf("Soundproof %s in %d\n", user.name, user.room);
+ } else
+ printf("Soundproof %s not in %d (is in %d)\n", user.name, from.room, user.room);
+ } else
+ /* room not soundproof, everyone gets it */
+ {
+ msg_attach_to(msg, who.pid);
+ printf("Shout to %s in %d\n", user.name, user.room);
+ }
+ }
+ RoomDestroy(&room);
+ close(who_fd);
+ close(users_fd);
+ ipcmsg_destroy(msg);
+ return;
+ }
+
/* otherwise redistribute this message to intended target */
msg_attach_to(msg, msg->head.dst);
ipcmsg_destroy(msg);
Modified: trunk/src/talker.c
===================================================================
--- trunk/src/talker.c 2012-12-30 17:11:56 UTC (rev 1319)
+++ trunk/src/talker.c 2012-12-30 19:25:33 UTC (rev 1320)
@@ -119,17 +119,13 @@
}
void talk_send_shout(char * text){
- char buff[MAXTEXTLENGTH];
- struct filter_info f_info;
-
- memset(&f_info, 0, sizeof(f_info));
- f_info.channel = user->room;
mwlog("SHOUT %s", text);
- snprintf(buff, MAXTEXTLENGTH, "%s shouts: %s", user->name, text);
- ipc_send_to_all(IPC_TEXT, buff, send_filter_oneroom, &f_info);
- ipc_send_to_all(IPC_TEXT, buff, send_filter_nonglobal, &f_info);
- snprintf(buff, MAXTEXTLENGTH, "*:%s shouts: %s", user->name, text);
- ipc_send_to_all(IPC_TEXT, buff, send_filter_global, &f_info);
+ ipc_message_t * msg = ipcmsg_create(IPC_SAYTOALL, getpid());
+ json_t * j = json_init(NULL);
+ json_addstring(j, "text", text);
+ ipcmsg_json_encode(msg, j);
+ json_decref(j);
+ ipcmsg_transmit(msg);
}
static void talk_send_say(char * text, int channel){
More information about the mw-devel
mailing list