linuxdcpp-team team mailing list archive
-
linuxdcpp-team team
-
Mailing list archive
-
Message #06223
[Branch ~dcplusplus-team/dcplusplus/trunk] Rev 3102: dev plugin: save status & handle /raw
------------------------------------------------------------
revno: 3102
committer: poy <poy@xxxxxxxxxx>
branch nick: trunk
timestamp: Thu 2012-11-01 20:51:00 +0100
message:
dev plugin: save status & handle /raw
modified:
plugins/Dev/Plugin.cpp
plugins/Dev/Plugin.h
plugins/Dev/Util.cpp
plugins/Dev/Util.h
--
lp:dcplusplus
https://code.launchpad.net/~dcplusplus-team/dcplusplus/trunk
Your team Dcplusplus-team is subscribed to branch lp:dcplusplus.
To unsubscribe from this branch go to https://code.launchpad.net/~dcplusplus-team/dcplusplus/trunk/+edit-subscription
=== modified file 'plugins/Dev/Plugin.cpp'
--- plugins/Dev/Plugin.cpp 2012-10-29 18:19:03 +0000
+++ plugins/Dev/Plugin.cpp 2012-11-01 19:51:00 +0000
@@ -74,6 +74,10 @@
return instance->onConnectionDataIn(reinterpret_cast<ConnectionDataPtr>(pObject), reinterpret_cast<char*>(pData)); }, nullptr);
events[HOOK_NETWORK_CONN_OUT] = hooks->bind_hook(HOOK_NETWORK_CONN_OUT, [](dcptr_t pObject, dcptr_t pData, dcptr_t, Bool*) {
return instance->onConnectionDataOut(reinterpret_cast<ConnectionDataPtr>(pObject), reinterpret_cast<char*>(pData)); }, nullptr);
+ events[HOOK_UI_PROCESS_CHAT_CMD] = hooks->bind_hook(HOOK_UI_PROCESS_CHAT_CMD, [](dcptr_t pObject, dcptr_t pData, dcptr_t, Bool*) {
+ auto cmd = reinterpret_cast<CommandDataPtr>(pData);
+ if(cmd->isPrivate) { return False; }
+ return instance->onChatCommand(reinterpret_cast<HubDataPtr>(pObject), cmd); }, nullptr);
}
void Plugin::clearHooks() {
@@ -85,9 +89,11 @@
void Plugin::start() {
dialog.create();
addHooks();
+ Util::setConfig("Enabled", true);
}
void Plugin::close() {
+ Util::setConfig("Enabled", false);
clearHooks();
dialog.close();
}
@@ -99,6 +105,7 @@
auto utils = reinterpret_cast<DCUtilsPtr>(core->query_interface(DCINTF_DCPP_UTILS, DCINTF_DCPP_UTILS_VER));
auto config = reinterpret_cast<DCConfigPtr>(core->query_interface(DCINTF_CONFIG, DCINTF_CONFIG_VER));
auto logger = reinterpret_cast<DCLogPtr>(core->query_interface(DCINTF_LOGGING, DCINTF_LOGGING_VER));
+ hubs = reinterpret_cast<DCHubPtr>(core->query_interface(DCINTF_DCPP_HUBS, DCINTF_DCPP_HUBS_VER));
ui = reinterpret_cast<DCUIPtr>(core->query_interface(DCINTF_DCPP_UI, DCINTF_DCPP_UI_VER));
if(!utils || !config || !logger || !ui) {
@@ -109,12 +116,15 @@
Util::initialize(core->host_name(), utils, config, logger);
if(install) {
- /// @todo config enabled/disabled
-
- Util::logMessage("The dev plugin has been installed; check the \"" + string(switchText) + "\" command.");
- }
-
- start();
+ Util::setConfig("Enabled", true);
+
+ Util::logMessage("The dev plugin has been installed; check the \"" + string(switchText) + "\" command and the /raw chat command.");
+ }
+
+ if(Util::getBoolConfig("Enabled")) {
+ start();
+ }
+
ui->add_command(switchText, [] { instance->onSwitched(); });
}
@@ -145,3 +155,18 @@
dialog.write(false, true, hConn->ip, "User" /** @todo get user's nick */, message);
return False;
}
+
+Bool Plugin::onChatCommand(HubDataPtr hub, CommandDataPtr cmd) {
+ if(stricmp(cmd->command, "help") == 0) {
+ hubs->local_message(hub, "/raw <message>", MSG_SYSTEM);
+
+ } else if(stricmp(cmd->command, "raw") == 0) {
+ if(strlen(cmd->params) == 0) {
+ hubs->local_message(hub, "Specify a message to send", MSG_SYSTEM);
+ } else {
+ hubs->send_protocol_cmd(hub, cmd->params);
+ }
+ }
+
+ return False;
+}
=== modified file 'plugins/Dev/Plugin.h'
--- plugins/Dev/Plugin.h 2012-10-29 18:19:03 +0000
+++ plugins/Dev/Plugin.h 2012-11-01 19:51:00 +0000
@@ -49,11 +49,13 @@
Bool onHubDataOut(HubDataPtr hHub, const char* message);
Bool onConnectionDataIn(ConnectionDataPtr hConn, const char* message);
Bool onConnectionDataOut(ConnectionDataPtr hConn, const char* message);
+ Bool onChatCommand(HubDataPtr hub, CommandDataPtr cmd);
map<string, subsHandle> events;
DCCorePtr dcpp;
DCHooksPtr hooks;
+ DCHubPtr hubs;
DCUIPtr ui;
Dialog dialog;
=== modified file 'plugins/Dev/Util.cpp'
--- plugins/Dev/Util.cpp 2012-08-02 17:49:34 +0000
+++ plugins/Dev/Util.cpp 2012-11-01 19:51:00 +0000
@@ -19,8 +19,6 @@
#include "stdafx.h"
#include "Util.h"
-#include "version.h"
-
string Util::appName;
DCUtilsPtr Util::utils = nullptr;
@@ -28,12 +26,13 @@
DCLogPtr Util::logger = nullptr;
void Util::setConfig(const char* name, const char* value) {
- ConfigStr val;
- memset(&val, 0, sizeof(ConfigStr));
+ ConfigStr val = { CFG_TYPE_STRING, value };
+ setConfig(name, val);
+}
- val.type = CFG_TYPE_STRING;
- val.value = value;
- config->set_cfg(PLUGIN_GUID, name, (ConfigValuePtr)&val);
+void Util::setConfig(const char* name, bool value) {
+ ConfigBool val = { CFG_TYPE_BOOL, value ? True : False };
+ setConfig(name, val);
}
string Util::getConfig(const char *name) {
=== modified file 'plugins/Dev/Util.h'
--- plugins/Dev/Util.h 2012-08-02 17:49:34 +0000
+++ plugins/Dev/Util.h 2012-11-01 19:51:00 +0000
@@ -19,6 +19,8 @@
#ifndef PLUGINS_DEV_UTIL_H
#define PLUGINS_DEV_UTIL_H
+#include "version.h"
+
#ifdef _WIN32
# define PATH_SEPARATOR '\\'
# define PATH_SEPARATOR_STR "\\"
@@ -83,9 +85,13 @@
logger->log(message.c_str());
}
+ /// @todo SFINAE to ensure that ConfigT is a ConfigStr/Bool/etc?
+ template<typename ConfigT> static void setConfig(const char* name, ConfigT& val) {
+ config->set_cfg(PLUGIN_GUID, name, reinterpret_cast<ConfigValuePtr>(&val));
+ }
static void setConfig(const char* name, const char* value);
static void setConfig(const char* name, const string& value) { setConfig(name, value.c_str()); }
- static void setConfig(const char* name, bool state) { setConfig(name, string(state ? "1" : "0")); }
+ static void setConfig(const char* name, bool state);
static string getConfig(const char *name);
static bool getBoolConfig(const char* name);