[mw-devel] MW3 r1248 - trunk/src

arthur at sucs.org arthur at sucs.org
Tue Apr 12 17:13:46 BST 2011


Author: arthur
Date: 2011-04-12 17:13:46 +0100 (Tue, 12 Apr 2011)
New Revision: 1248

Modified:
   trunk/src/chattable.c
   trunk/src/rooms.c
   trunk/src/talker.c
   trunk/src/talker.h
Log:
Allow the setting and clearing of channel topics


Modified: trunk/src/chattable.c
===================================================================
--- trunk/src/chattable.c	2011-03-04 15:54:44 UTC (rev 1247)
+++ trunk/src/chattable.c	2011-04-12 16:13:46 UTC (rev 1248)
@@ -70,6 +70,7 @@
 {"sticky"	,0x0000	,1, "Usage: sticky <on|off>", "Log back on to the room you logged off from", t_sticky, 1},
 {"summon"	,0x0080	,2, "Usage: summon <room> <user> [<user>...]", "Force user(s) to move into a room", t_summon, 1},
 {"tcunames"	,0x0000, 1, "Usage: tcunames <on|off>", "Allow tab-completion of username on talker", t_tcunames, 1},
+{"topic"	,0x0800, 0, "Usage: topic [topic]", "Set/view channel topic", t_topic, 1},
 {"unbind"	,0x0200, 1, "Usage: unbind <bind | *>", "Remove the bind from the current session", t_unbind, 1},
 {"unevent"	,0x0200	,1, "Usage: unevent <function | *>", "Unset [all] text event handler function(s)", t_unevent, 1},
 {"unfreeze"	,0x0040	,1, "Usage: unfreeze <user>", "Allow user to change rooms again", t_unfreeze, 1},

Modified: trunk/src/rooms.c
===================================================================
--- trunk/src/rooms.c	2011-03-04 15:54:44 UTC (rev 1247)
+++ trunk/src/rooms.c	2011-04-12 16:13:46 UTC (rev 1248)
@@ -146,16 +146,28 @@
 			RoomInit(&myroom);
 			LoadRoom(&myroom, user->room);
 
-			if (asprintf(&buff, "\03313%s has left to room %d", user->name, i) > 0)
+			SAFE_FREE(buff);
+			if (asprintf(&buff, "\03313%s has left to room %d", user->name, i) < 0)
 			{
 				return 5;
 			}
 			if (!quiet) talk_send_raw(buff, oldroom);
+			SAFE_FREE(buff);
 			if (asprintf(&buff, "Leaving room %d for room %d", oldroom, user->room) < 0)
 			{
 				return 5;
 			}
 			if (!quiet) display_message(buff, 1, 1);
+
+			{
+				char *topic = db_room_get(user->room, "topic");
+				if (topic != NULL && *topic != 0) {
+					SAFE_FREE(buff);
+					asprintf(&buff, "Topic: %s\n", topic);
+					display_message(buff, 1, 1);
+				}
+				if (topic != NULL) free(topic);
+			}
 		}
 	}
 	else

Modified: trunk/src/talker.c
===================================================================
--- trunk/src/talker.c	2011-03-04 15:54:44 UTC (rev 1247)
+++ trunk/src/talker.c	2011-04-12 16:13:46 UTC (rev 1248)
@@ -1365,6 +1365,39 @@
 	update_user(user,userposn);
 }
 
+void t_topic(CommandList *cm, int argc, char **argv, char *args)
+{
+	AUTOFREE_BUFFER buff=NULL;
+
+	if (argc == 1) {
+		char *topic;
+
+		topic = db_room_get(user->room, "topic");
+		if (topic != NULL && *topic != 0) {
+			asprintf(&buff, "Topic: %s\n", topic);
+		} else {
+			asprintf(&buff, "No Topic is set for channel %d.\n", user->room);
+		}
+		display_message(buff, 0, 1);
+		if (topic != NULL) free(topic);
+		return;
+	} else {
+		char text[MAXTEXTLENGTH];
+		const char *topic;
+
+		db_room_set(user->room, "topic", args);
+		topic = db_room_get(user->room, "topic");
+		if (topic == NULL || *topic == 0) {
+			snprintf(text,MAXTEXTLENGTH-1,"\03314%s has cleared the channel topic.",user->name);
+			mwlog("TOPIC <empty>");
+		} else {
+			snprintf(text,MAXTEXTLENGTH-1,"\03314%s has set the topic to \"%s\".",user->name, topic);
+			mwlog("TOPIC %s", topic);
+		}
+		talk_send_raw(text,user->room);
+	}
+}
+
 void t_uri(CommandList *cm, int argc, char **argv, char *args)
 {
 	uriActionList *al = uritable;
@@ -1431,6 +1464,14 @@
 
 	/* give an entrance broadcast */
 	broadcast_onoffcode(1, 0, NULL, NULL);
+
+	char *topic = db_room_get(user->room, "topic");
+	if (topic != NULL && *topic != 0) {
+		AUTOFREE_BUFFER buff=NULL;
+		asprintf(&buff, "Topic: %s\n", topic);
+		display_message(buff, 0, 1);
+	}
+	if (topic != NULL) free(topic);
 }
 
 /**** actual talker utilities *****/

Modified: trunk/src/talker.h
===================================================================
--- trunk/src/talker.h	2011-03-04 15:54:44 UTC (rev 1247)
+++ trunk/src/talker.h	2011-04-12 16:13:46 UTC (rev 1248)
@@ -59,6 +59,7 @@
 void t_linewrap(CommandList *cm, int argc, char **argv, char *args);
 void t_mwrc(CommandList *cm, int argc, char **argv, char *args);
 void t_uri(CommandList *cm, int argc, char **argv, char *args);
+void t_topic(CommandList *cm, int argc, char **argv, char *args);
 void t_chaton(void);
 
 void chat_say(char *text);




More information about the mw-devel mailing list