diff options
author | Andrei Karas <akaras@inbox.ru> | 2011-08-27 17:24:16 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2011-08-27 17:24:16 +0300 |
commit | 96ca346fe114804609acea0b13594422f3f09002 (patch) | |
tree | 1f3772b6af8b2e1ee93e475c1aadd4cb47bc1d10 | |
parent | cf8445d68f109a20ec22cee84c7dc06411390900 (diff) | |
download | plus-96ca346fe114804609acea0b13594422f3f09002.tar.gz plus-96ca346fe114804609acea0b13594422f3f09002.tar.bz2 plus-96ca346fe114804609acea0b13594422f3f09002.tar.xz plus-96ca346fe114804609acea0b13594422f3f09002.zip |
Impliment additional guild bot intergration functions.
-rw-r--r-- | src/gui/widgets/guildtab.cpp | 2 | ||||
-rw-r--r-- | src/guildmanager.cpp | 70 | ||||
-rw-r--r-- | src/guildmanager.h | 5 |
3 files changed, 67 insertions, 10 deletions
diff --git a/src/gui/widgets/guildtab.cpp b/src/gui/widgets/guildtab.cpp index d9f61cb43..f4288e228 100644 --- a/src/gui/widgets/guildtab.cpp +++ b/src/gui/widgets/guildtab.cpp @@ -89,7 +89,7 @@ bool GuildTab::handleCommand(const std::string &type, const std::string &args) return false; } - return false; + return true; } void GuildTab::handleInput(const std::string &msg) diff --git a/src/guildmanager.cpp b/src/guildmanager.cpp index 8f480803a..bc4158a12 100644 --- a/src/guildmanager.cpp +++ b/src/guildmanager.cpp @@ -83,6 +83,8 @@ void GuildManager::chat(std::string msg) void GuildManager::getNames(std::vector<std::string> &names) { + Guild *guild = createGuild(); + guild->getNames(names); } void GuildManager::requestGuildInfo() @@ -117,12 +119,22 @@ void GuildManager::updateList() if (name.size() > 1) { int status = atoi(name.substr(name.size() - 1).c_str()); + name = name.substr(0, name.size() - 1); GuildMember *m = guild->addMember(i, 0, name); if (m) { m->setOnline(status & 1); m->setGender(GENDER_UNSPECIFIED); + if (status & 2) + m->setPos(10); + else + m->setPos(0); + if (player_node && name == player_node->getName()) + { + mHavePower = (status & 2); + m->setOnline(true); + } } } ++ it; @@ -131,9 +143,14 @@ void GuildManager::updateList() guild->sort(); if (actorSpriteManager) actorSpriteManager->updatePlayerGuild(); + createTab(guild); } mTempList.clear(); mGotInfo = true; +} + +void GuildManager::createTab(Guild *guild) +{ if (!mTab) { mTab = new GuildTab(); @@ -143,6 +160,16 @@ void GuildManager::updateList() } } +Guild *GuildManager::createGuild() +{ + Guild *guild = Guild::getGuild(1); + if (!guild) + return 0; + + guild->setServerGuild(false); + return guild; +} + bool GuildManager::processGuildMessage(std::string msg) { bool res = process(msg); @@ -158,14 +185,11 @@ bool GuildManager::process(std::string msg) if (msg.size() > 4 && msg[0] == '#' && msg[1] == '#') msg = msg.substr(3); - Guild *guild = Guild::getGuild(1); - if (!guild) - return false; - - guild->setServerGuild(false); - if (findCutLast(msg, " is now Offline.")) { + Guild *guild = createGuild(); + if (!guild) + return false; if (msg.size() < 4) return false; if (msg[0] == '#' && msg[1] == '#') @@ -180,6 +204,9 @@ bool GuildManager::process(std::string msg) } else if (findCutLast(msg, " is now Online.")) { + Guild *guild = createGuild(); + if (!guild) + return false; if (msg.size() < 4) return false; if (msg[0] == '#' && msg[1] == '#') @@ -193,7 +220,10 @@ bool GuildManager::process(std::string msg) } else if (findCutFirst(msg, "Welcome to the ")) { - logger->log("welcome message: %s", msg.c_str()); + Guild *guild = createGuild(); + if (!guild) + return false; +// logger->log("welcome message: %s", msg.c_str()); int pos = msg.find("! ("); if (pos == (int)std::string::npos) return false; @@ -207,6 +237,9 @@ bool GuildManager::process(std::string msg) } else if (findCutFirst(msg, "Player name: ")) { + Guild *guild = createGuild(); + if (!guild) + return false; int pos = msg.find("Access Level: "); if (pos == (int)std::string::npos) return false; @@ -242,7 +275,7 @@ bool GuildManager::process(std::string msg) } else if (findCutFirst(msg, "OL#")) { - logger->log("OL"); +// logger->log("OL"); mTempList.clear(); splitToStringVector(mTempList, msg, '#'); if (msg.size() < 1 || msg[msg.size() - 1] != '#') @@ -252,7 +285,7 @@ bool GuildManager::process(std::string msg) } else if (findCutFirst(msg, "oL#")) { - logger->log("oL"); +// logger->log("oL"); splitToStringVector(mTempList, msg, '#'); if (msg.size() < 1 || msg[msg.size() - 1] != '#') updateList(); @@ -268,6 +301,13 @@ bool GuildManager::process(std::string msg) } else { + Guild *guild = createGuild(); + if (!guild) + return false; + if (!mTab) + { + createTab(guild); + } if (mTab) { std::string::size_type pos = msg.find(": ", 0); @@ -275,6 +315,11 @@ bool GuildManager::process(std::string msg) { std::string sender_name = ((pos == std::string::npos) ? "" : msg.substr(0, pos)); + if (!guild->getMember(sender_name)) + { + mTab->chatLog(msg); + return true; + } msg.erase(0, pos + 2); if (msg.size() > 3 && msg[0] == '#' && msg[1] == '#') @@ -295,16 +340,23 @@ bool GuildManager::process(std::string msg) void GuildManager::kick(std::string msg) { + send("!remove " + msg); } void GuildManager::invite(std::string msg) { + send("!invite " + msg); } void GuildManager::leave() { + send("!leave"); } void GuildManager::notice(std::string msg) { + if (msg.empty()) + send("!removemotd"); + else + send("!setmotd " + msg); } diff --git a/src/guildmanager.h b/src/guildmanager.h index f02368ab6..a46cba915 100644 --- a/src/guildmanager.h +++ b/src/guildmanager.h @@ -27,6 +27,7 @@ #include <string> #include <vector> +class Guild; class GuildTab; class GuildManager @@ -61,6 +62,10 @@ class GuildManager void notice(std::string msg); + void createTab(Guild *guild); + + Guild *createGuild(); + bool havePower() { return mHavePower; } |