summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorPatrick Griffis <tingping@tingping.se>2016-11-08 22:34:31 -0500
committertomek <eustachy.kapusta@gmail.com>2016-11-09 17:29:23 +0100
commit85bdb06cad4e8a58509f7421610ef9c82bbabc02 (patch)
tree49520316d27cb45e4a0f9d8dc2fe9705dfdb4c7f /src
parenta0e80ebda2bc9270beb4818a2438d7555593b6fd (diff)
Convert doat to an internal command
- Trivial plugin
- Useful for many users
- Was under a dumb license
Diffstat (limited to 'src')
-rw-r--r--src/common/outbound.c36
-rw-r--r--src/common/plugin.c118
-rw-r--r--src/common/plugin.h1
3 files changed, 99 insertions, 56 deletions
diff --git a/src/common/outbound.c b/src/common/outbound.c
index 61626821..3c717526 100644
--- a/src/common/outbound.c
+++ b/src/common/outbound.c
@@ -1448,6 +1448,41 @@ cmd_dns (struct session *sess, char *tbuf, char *word[], char *word_eol[])
 }
 
 static int
+cmd_doat (struct session *sess, char *tbuf, char *word[], char *word_eol[])
+{
+	GStrv channels;
+	guint i;
+
+	if (!word[2] || !*word[2] || !word[3] || !*word[3])
+		return FALSE;
+
+	channels = g_strsplit (word[2], ",", -1);
+	for (i = 0; channels[i] && *channels[i]; ++i)
+	{
+		char *chan = channels[i];
+		char *serv;
+		session *ctx;
+
+		/* Split channel and network, either may be empty */
+		if ((serv = strchr (chan, '/')))
+		{
+			*serv = '\0';
+			serv++;
+			if (!strlen (serv))
+				serv = NULL;
+		}
+		if (!strlen (chan))
+			chan = NULL;
+
+		if ((ctx = plugin_find_context (serv, chan, sess->server)))
+			handle_command (ctx, word_eol[3], FALSE);
+	}
+	g_strfreev (channels);
+
+	return TRUE;
+}
+
+static int
 cmd_echo (struct session *sess, char *tbuf, char *word[], char *word_eol[])
 {
 	PrintText (sess, word_eol[2]);
@@ -3931,6 +3966,7 @@ const struct commands xc_cmds[] = {
 	 N_("DEVOICE <nick>, removes voice status from the nick on the current channel (needs chanop)")},
 	{"DISCON", cmd_discon, 0, 0, 1, N_("DISCON, Disconnects from server")},
 	{"DNS", cmd_dns, 0, 0, 1, N_("DNS <nick|host|ip>, Resolves an IP or hostname")},
+	{"DOAT", cmd_doat, 0, 0, 1, N_("DOAT <channel,list,/network> <command>")},
 	{"ECHO", cmd_echo, 0, 0, 1, N_("ECHO <text>, Prints text locally")},
 #ifndef WIN32
 	{"EXEC", cmd_exec, 0, 0, 1,
diff --git a/src/common/plugin.c b/src/common/plugin.c
index 07012736..b49afd96 100644
--- a/src/common/plugin.c
+++ b/src/common/plugin.c
@@ -452,7 +452,6 @@ plugin_auto_load (session *sess)
 	/* a long list of bundled plugins that should be loaded automatically,
 	 * user plugins should go to <config>, leave Program Files alone! */
 	for_files (lib_dir, "hcchecksum.dll", plugin_auto_load_cb);
-	for_files (lib_dir, "hcdoat.dll", plugin_auto_load_cb);
 	for_files (lib_dir, "hcexec.dll", plugin_auto_load_cb);
 	for_files (lib_dir, "hcfishlim.dll", plugin_auto_load_cb);
 	for_files(lib_dir, "hclua.dll", plugin_auto_load_cb);
@@ -871,6 +870,67 @@ plugin_show_help (session *sess, char *cmd)
 	return 0;
 }
 
+session *
+plugin_find_context (const char *servname, const char *channel, server *current_server)
+{
+	GSList *slist, *clist, *sessions = NULL;
+	server *serv;
+	session *sess;
+	char *netname;
+
+	if (servname == NULL && channel == NULL)
+		return current_sess;
+
+	slist = serv_list;
+	while (slist)
+	{
+		serv = slist->data;
+		netname = server_get_network (serv, TRUE);
+
+		if (servname == NULL ||
+			 rfc_casecmp (servname, serv->servername) == 0 ||
+			 g_ascii_strcasecmp (servname, serv->hostname) == 0 ||
+			 g_ascii_strcasecmp (servname, netname) == 0)
+		{
+			if (channel == NULL)
+				return serv->front_session;
+
+			clist = sess_list;
+			while (clist)
+			{
+				sess = clist->data;
+				if (sess->server == serv)
+				{
+					if (rfc_casecmp (channel, sess->channel) == 0)
+					{
+						if (sess->server == current_server)
+						{
+							g_slist_free (sessions);
+							return sess;
+						} else
+						{
+							sessions = g_slist_prepend (sessions, sess);
+						}
+					}
+				}
+				clist = clist->next;
+			}
+		}
+		slist = slist->next;
+	}
+
+	if (sessions)
+	{
+		sessions = g_slist_reverse (sessions);
+		sess = sessions->data;
+		g_slist_free (sessions);
+		return sess;
+	}
+
+	return NULL;
+}
+
+
 /* ========================================================= */
 /* ===== these are the functions plugins actually call ===== */
 /* ========================================================= */
@@ -1038,61 +1098,7 @@ hexchat_set_context (hexchat_plugin *ph, hexchat_context *context)
 hexchat_context *
 hexchat_find_context (hexchat_plugin *ph, const char *servname, const char *channel)
 {
-	GSList *slist, *clist, *sessions = NULL;
-	server *serv;
-	session *sess;
-	char *netname;
-
-	if (servname == NULL && channel == NULL)
-		return current_sess;
-
-	slist = serv_list;
-	while (slist)
-	{
-		serv = slist->data;
-		netname = server_get_network (serv, TRUE);
-
-		if (servname == NULL ||
-			 rfc_casecmp (servname, serv->servername) == 0 ||
-			 g_ascii_strcasecmp (servname, serv->hostname) == 0 ||
-			 g_ascii_strcasecmp (servname, netname) == 0)
-		{
-			if (channel == NULL)
-				return serv->front_session;
-
-			clist = sess_list;
-			while (clist)
-			{
-				sess = clist->data;
-				if (sess->server == serv)
-				{
-					if (rfc_casecmp (channel, sess->channel) == 0)
-					{
-						if (sess->server == ph->context->server)
-						{
-							g_slist_free (sessions);
-							return sess;
-						} else
-						{
-							sessions = g_slist_prepend (sessions, sess);
-						}
-					}
-				}
-				clist = clist->next;
-			}
-		}
-		slist = slist->next;
-	}
-
-	if (sessions)
-	{
-		sessions = g_slist_reverse (sessions);
-		sess = sessions->data;
-		g_slist_free (sessions);
-		return sess;
-	}
-
-	return NULL;
+	return plugin_find_context (servname, channel, ph->context->server);
 }
 
 const char *
diff --git a/src/common/plugin.h b/src/common/plugin.h
index 5743f39a..76ce97a3 100644
--- a/src/common/plugin.h
+++ b/src/common/plugin.h
@@ -179,5 +179,6 @@ int plugin_emit_keypress (session *sess, unsigned int state, unsigned int keyval
 GList* plugin_command_list(GList *tmp_list);
 int plugin_show_help (session *sess, char *cmd);
 void plugin_command_foreach (session *sess, void *userdata, void (*cb) (session *sess, void *userdata, char *name, char *usage));
+session *plugin_find_context (const char *servname, const char *channel, server *current_server);
 
 #endif