← Back to team overview

linuxdcpp-team team mailing list archive

[Branch ~dcplusplus-team/dcpp-plugin-sdk-cpp/LoLPlugin] Rev 24: use OID instead of LOL

 

------------------------------------------------------------
revno: 24
committer: poy <poy@xxxxxxxxxx>
branch nick: LoLPlugin
timestamp: Sun 2013-05-19 17:45:47 +0200
message:
  use OID instead of LOL
modified:
  src/AdcCommand.h
  src/Plugin.cpp


--
lp:~dcplusplus-team/dcpp-plugin-sdk-cpp/LoLPlugin
https://code.launchpad.net/~dcplusplus-team/dcpp-plugin-sdk-cpp/LoLPlugin

Your team Dcplusplus-team is subscribed to branch lp:~dcplusplus-team/dcpp-plugin-sdk-cpp/LoLPlugin.
To unsubscribe from this branch go to https://code.launchpad.net/~dcplusplus-team/dcpp-plugin-sdk-cpp/LoLPlugin/+edit-subscription
=== modified file 'src/AdcCommand.h'
--- src/AdcCommand.h	2013-05-16 17:47:44 +0000
+++ src/AdcCommand.h	2013-05-19 15:45:47 +0000
@@ -109,7 +109,7 @@
 	C(RNT, 'R','N','T');
 	C(ZON, 'Z','O','N');
 	C(ZOF, 'Z','O','F');
-	C(LOL, 'L','O','L');
+	C(OID, 'O','I','D');
 #undef C
 
 	static const uint32_t HUB_SID = 0xffffffff;		// No client will have this sid

=== modified file 'src/Plugin.cpp'
--- src/Plugin.cpp	2013-05-16 17:47:44 +0000
+++ src/Plugin.cpp	2013-05-19 15:45:47 +0000
@@ -46,11 +46,11 @@
 
 using dcpp::AdcCommand;
 
-const string feat = "LOLI";
-
 const string Plugin::defLink = "http://quickfind.kassad.in/profile/<server>/<summoner>/";
 const string Plugin::servers[7] = { "br", "eune", "euw", "kr", "na", "ru", "tr" };
 
+const string lolServ = "LoL"; // the service identifier of the ADC OID command.
+
 const size_t MAX_CACHE = 10;
 
 Plugin::Plugin() {
@@ -146,15 +146,17 @@
 				AdcCommand(AdcCommand::CMD_CMD, AdcCommand::TYPE_INFO)
 				.addParam("Open LoL profile")
 				.addParam("CT", "14" /* 2 + 4 + 8 */)
-				.addParam("TT", "DLOL %[mySID] %[userSID]\n")
+				.addParam("TT", "DOID %[mySID] %[userSID] " + lolServ + "\n")
 				.addParam("CO", "1")
 				.toString().c_str());
 
-		} else if(cmd.getCommand() == AdcCommand::CMD_LOL && cmd.getType() == AdcCommand::TYPE_DIRECT) {
-			if(cmd.getParameters().empty()) {
+		} else if(cmd.getCommand() == AdcCommand::CMD_OID && cmd.getType() == AdcCommand::TYPE_DIRECT && cmd.getParam(0) == lolServ) {
+
+			if(cmd.getParameters().size() == 1) {
 				// answer with our LoL info.
 				Hubs::handle()->send_protocol_cmd(hub,
-					AdcCommand(AdcCommand::CMD_LOL, cmd.getFrom(), AdcCommand::TYPE_DIRECT)
+					AdcCommand(AdcCommand::CMD_OID, cmd.getFrom(), AdcCommand::TYPE_DIRECT)
+					.addParam(lolServ)
 					.addParam("SE", Config::getConfig("Server"))
 					.addParam("SU", Config::getConfig("Summoner"))
 					.toString(cmd.getTo()).c_str());
@@ -162,7 +164,7 @@
 			} else {
 				if(std::find(cache.begin(), cache.end(), cmd.getFrom()) != cache.end()) {
 					string server, summoner;
-					if(cmd.getParam("SE", 0, server) && cmd.getParam("SU", 0, summoner)) {
+					if(cmd.getParam("SE", 1, server) && cmd.getParam("SU", 1, summoner)) {
 						auto link = Config::getConfig("Link");
 						boost::ireplace_first(link, "<server>", server);
 						boost::ireplace_first(link, "<summoner>", summoner);
@@ -180,18 +182,15 @@
 
 bool Plugin::onHubDataOut(HubDataPtr hub, char* message) {
 	if(hub->protocol == PROTOCOL_ADC) {
-		auto cmd = AdcCommand(message);
-
-		if(cmd.getCommand() == AdcCommand::CMD_INF) {
-			// add the feature to INF SU.
-			auto& params = cmd.getParameters();
-			for(auto& param: params) {
-				if(AdcCommand::toCode(param.c_str()) == AdcCommand::toCode("SU") && param.find(feat) == string::npos) {
-					param += ',' + feat;
-				}
-			}
-
-		} else if(cmd.getCommand() == AdcCommand::CMD_LOL) {
+		// AdcCommand doesn't like the terminating \n...
+		string msg = message;
+		if(msg.empty()) { return false; }
+		auto last = msg.end() - 1;
+		if(*last == '\n') { msg.erase(last); }
+		auto cmd = AdcCommand(msg);
+
+		if(cmd.getCommand() == AdcCommand::CMD_OID && cmd.getParam(0) == lolServ && cmd.getParameters().size() == 1) {
+			// we are requesting LoL info; add the peer to the cache.
 			if(cache.size() > MAX_CACHE) {
 				cache.erase(cache.begin(), cache.begin() + MAX_CACHE / 2);
 			}