From dddfb405de9d04f50d3a95cc3b0ebc3e49884a65 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Mon, 22 Aug 2011 03:07:13 +0300 Subject: Add highlight list option. Before in highlight was only player nick. --- src/utils/stringutils.cpp | 17 +++++++++++++++-- src/utils/stringutils.h | 5 ++++- 2 files changed, 19 insertions(+), 3 deletions(-) (limited to 'src/utils') diff --git a/src/utils/stringutils.cpp b/src/utils/stringutils.cpp index 13170092e..0243c4315 100644 --- a/src/utils/stringutils.cpp +++ b/src/utils/stringutils.cpp @@ -181,9 +181,9 @@ unsigned long findI(std::string str, std::string subStr) return str.find(subStr); } -unsigned long findI(std::string str, std::vector &list) +unsigned long findI(std::string &text, std::vector &list) { - str = toLower(str); + std::string str = toLower(text); unsigned long idx; for (std::vector::iterator i = list.begin(); i != list.end(); ++i) @@ -414,6 +414,19 @@ std::list splitToStringList(const std::string &text, return tokens; } +void splitToStringVector(std::vector &tokens, + const std::string &text, char separator) +{ + std::stringstream ss(text); + std::string item; + while(std::getline(ss, item, separator)) + { + item = trim(item); + if (!item.empty()) + tokens.push_back(item); + } +} + std::string combineDye(std::string file, std::string dye) { if (dye.empty()) diff --git a/src/utils/stringutils.h b/src/utils/stringutils.h index 94747d2fe..4fe6369e9 100644 --- a/src/utils/stringutils.h +++ b/src/utils/stringutils.h @@ -133,7 +133,7 @@ bool isWordSeparator(char chr); unsigned long findI(std::string str, std::string subStr); -unsigned long findI(std::string str, std::vector &list); +unsigned long findI(std::string &text, std::vector &list); const std::string encodeStr(unsigned int value, unsigned int size = 0); @@ -176,6 +176,9 @@ std::list splitToIntList(const std::string &text, char separator); std::list splitToStringList(const std::string &text, char separator); +void splitToStringVector(std::vector &tokens, + const std::string &text, char separator); + std::string combineDye(std::string file, std::string dye); std::string combineDye2(std::string file, std::string dye); -- cgit v1.2.3-70-g09d2 From 12bf548533867a2eb3a1c354b778ef7f9157322a Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Fri, 26 Aug 2011 16:57:05 +0300 Subject: Basic support for guild bot integration. Not working context menu actions, chat commands, auto complete. --- manaplus.cbp | 4 + src/CMakeLists.txt | 4 + src/Makefile.am | 4 + src/being.cpp | 6 +- src/client.cpp | 16 +++ src/client.h | 2 + src/game.cpp | 24 ++-- src/gui/chatwindow.cpp | 6 +- src/gui/popupmenu.cpp | 77 ++++++++--- src/gui/setup_other.cpp | 6 + src/gui/socialwindow.cpp | 111 +++++++++++++++- src/gui/widgets/guildtab.cpp | 127 ++++++++++++++++++ src/gui/widgets/guildtab.h | 52 ++++++++ src/guild.cpp | 6 +- src/guild.h | 9 +- src/guildmanager.cpp | 309 +++++++++++++++++++++++++++++++++++++++++++ src/guildmanager.h | 81 ++++++++++++ src/net/ea/chathandler.cpp | 7 + src/net/ea/guildhandler.cpp | 1 + src/utils/stringutils.cpp | 54 ++++++++ src/utils/stringutils.h | 8 ++ 21 files changed, 878 insertions(+), 36 deletions(-) create mode 100644 src/gui/widgets/guildtab.cpp create mode 100644 src/gui/widgets/guildtab.h create mode 100644 src/guildmanager.cpp create mode 100644 src/guildmanager.h (limited to 'src/utils') diff --git a/manaplus.cbp b/manaplus.cbp index 8ed18dbed..d05cccd3b 100644 --- a/manaplus.cbp +++ b/manaplus.cbp @@ -310,6 +310,8 @@ + + @@ -394,6 +396,8 @@ + + diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 413a72f65..7f59135b8 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -137,6 +137,8 @@ SET(SRCS gui/widgets/emoteshortcutcontainer.h gui/widgets/flowcontainer.cpp gui/widgets/flowcontainer.h + gui/widgets/guildtab.cpp + gui/widgets/guildtab.h gui/widgets/horizontcontainer.cpp gui/widgets/horizontcontainer.h gui/widgets/icon.cpp @@ -508,6 +510,8 @@ SET(SRCS guichanfwd.h guild.cpp guild.h + guildmanager.cpp + guildmanager.h imageparticle.cpp imageparticle.h imagesprite.cpp diff --git a/src/Makefile.am b/src/Makefile.am index 57bb4e620..7d0c1634b 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -140,6 +140,8 @@ manaplus_SOURCES += gui/widgets/avatarlistbox.cpp \ gui/widgets/emoteshortcutcontainer.h \ gui/widgets/flowcontainer.cpp \ gui/widgets/flowcontainer.h \ + gui/widgets/guildtab.cpp \ + gui/widgets/guildtab.h \ gui/widgets/horizontcontainer.cpp \ gui/widgets/horizontcontainer.h \ gui/widgets/icon.cpp \ @@ -515,6 +517,8 @@ manaplus_SOURCES += gui/widgets/avatarlistbox.cpp \ guichanfwd.h \ guild.cpp \ guild.h \ + guildmanager.cpp \ + guildmanager.h \ imageparticle.cpp \ imageparticle.h \ imagesprite.cpp \ diff --git a/src/being.cpp b/src/being.cpp index cc88d8f6e..1924a8944 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -871,8 +871,12 @@ void Being::updateGuild() return; } if (guild->getMember(getName())) + { setGuild(guild); - updateColors(); + if (!guild->getName().empty()) + mGuildName = guild->getName(); + updateColors(); + } } void Being::setGuild(Guild *guild) diff --git a/src/client.cpp b/src/client.cpp index 0e871ed91..385af99ad 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -30,6 +30,7 @@ #include "event.h" #include "game.h" #include "guild.h" +#include "guildmanager.h" #include "graphicsvertexes.h" #include "itemshortcut.h" #include "keyboardconfig.h" @@ -793,6 +794,10 @@ int Client::exec() if (mumbleManager) mumbleManager->setServer(mCurrentServer.hostname); + if (!guildManager) + guildManager = new GuildManager(); + guildManager->init(); + if (!mConfigAutoSaved) { mConfigAutoSaved = true; @@ -2180,3 +2185,14 @@ void Client::closeDialogs() NpcDialog::closeAll(); SellDialog::closeAll(); } + +bool Client::isTmw() +{ + if (getServerName() == "server.themanaworld.org" + || Client::getServerName() == "themanaworld.org" + || Client::getServerName() == "81.161.192.4") + { + return true; + } + return false; +} diff --git a/src/client.h b/src/client.h index 986e06cfb..3edf12674 100644 --- a/src/client.h +++ b/src/client.h @@ -260,6 +260,8 @@ public: static void setFramerate(int fpsLimit); + static bool isTmw(); + void optionChanged(const std::string &name); void action(const gcn::ActionEvent &event); diff --git a/src/game.cpp b/src/game.cpp index 82f919976..c933378e6 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -31,14 +31,13 @@ #include "client.h" #include "commandhandler.h" #include "configuration.h" +#include "dropshortcut.h" #include "effectmanager.h" -#include "event.h" -#include "spellmanager.h" #include "emoteshortcut.h" +#include "event.h" +#include "guildmanager.h" #include "graphics.h" #include "itemshortcut.h" -#include "dropshortcut.h" -#include "spellshortcut.h" #include "joystick.h" #include "keyboardconfig.h" #include "localplayer.h" @@ -47,6 +46,8 @@ #include "particle.h" #include "playerrelations.h" #include "sound.h" +#include "spellmanager.h" +#include "spellshortcut.h" #include "gui/botcheckerwindow.h" #include "gui/buyselldialog.h" @@ -156,6 +157,7 @@ Particle *particleEngine = NULL; EffectManager *effectManager = NULL; SpellManager *spellManager = NULL; Viewport *viewport = NULL; /**< Viewport on the map. */ +GuildManager *guildManager = NULL; ChatTab *localChatTab = NULL; ChatTab *debugChatTab = NULL; @@ -175,6 +177,8 @@ static void initEngines() commandHandler = new CommandHandler; channelManager = new ChannelManager; effectManager = new EffectManager; + if (!guildManager) + guildManager = new GuildManager; particleEngine = new Particle(NULL); particleEngine->setupEngine(); @@ -393,6 +397,9 @@ Game::Game(): setupWindow->setInGame(true); clearKeysArray(); + if (guildManager && guildManager->getEnableGuildBot()) + guildManager->requestGuildInfo(); + Mana::Event::trigger(CHANNEL_GAME, Mana::Event(EVENT_CONSTRUCTED)); } @@ -411,16 +418,17 @@ Game::~Game() del_0(actorSpriteManager) if (Client::getState() != STATE_CHANGE_MAP) del_0(player_node) + del_0(guildManager) del_0(channelManager) del_0(commandHandler) - del_0(effectManager); + del_0(effectManager) del_0(joystick) del_0(particleEngine) del_0(viewport) del_0(mCurrentMap) - del_0(spellManager); - del_0(spellShortcut); - del_0(mumbleManager); + del_0(spellManager) + del_0(spellShortcut) + del_0(mumbleManager) Being::clearCache(); diff --git a/src/gui/chatwindow.cpp b/src/gui/chatwindow.cpp index 8896ca028..9c75320a6 100644 --- a/src/gui/chatwindow.cpp +++ b/src/gui/chatwindow.cpp @@ -1459,12 +1459,8 @@ void ChatWindow::saveState() std::string ChatWindow::doReplace(const std::string &msg) { - if (Client::getServerName() == "server.themanaworld.org" - || Client::getServerName() == "themanaworld.org" - || Client::getServerName() == "81.161.192.4") - { + if (Client::isTmw()) return msg; - } std::string str = msg; replaceSpecialChars(str); diff --git a/src/gui/popupmenu.cpp b/src/gui/popupmenu.cpp index 61769bc7e..a3041fcf7 100644 --- a/src/gui/popupmenu.cpp +++ b/src/gui/popupmenu.cpp @@ -27,6 +27,7 @@ #include "being.h" #include "dropshortcut.h" #include "guild.h" +#include "guildmanager.h" #include "flooritem.h" #include "graphics.h" #include "item.h" @@ -224,14 +225,22 @@ void PopupMenu::showPopup(int x, int y, Being *being) { mBrowserBox->addRow(strprintf( "@@guild-kick|%s@@", _("Kick from guild"))); - mBrowserBox->addRow(strprintf("@@guild-pos|%s >@@", - _("Change pos in guild"))); + if (guild2->getServerGuild()) + { + mBrowserBox->addRow(strprintf( + "@@guild-pos|%s >@@", + _("Change pos in guild"))); + } } } else { - mBrowserBox->addRow(strprintf( - "@@guild|%s@@", _("Invite to guild"))); + if (guild2->getServerGuild() + || (guildManager && guildManager->havePower())) + { + mBrowserBox->addRow(strprintf( + "@@guild|%s@@", _("Invite to guild"))); + } } } @@ -435,15 +444,26 @@ void PopupMenu::showPlayerPopup(int x, int y, std::string nick) { if (guild2->getMember(mNick)) { - mBrowserBox->addRow(strprintf( - "@@guild-kick|%s@@", _("Kick from guild"))); - mBrowserBox->addRow(strprintf( - "@@guild-pos|%s >@@", _("Change pos in guild"))); + if (guild2->getServerGuild() || (guildManager + && guildManager->havePower())) + { + mBrowserBox->addRow(strprintf( + "@@guild-kick|%s@@", _("Kick from guild"))); + } + if (guild2->getServerGuild()) + { + mBrowserBox->addRow(strprintf( + "@@guild-pos|%s >@@", _("Change pos in guild"))); + } } else { - mBrowserBox->addRow(strprintf( - "@@guild|%s@@", _("Invite to guild"))); + if (guild2->getServerGuild() || (guildManager + && guildManager->havePower())) + { + mBrowserBox->addRow(strprintf( + "@@guild|%s@@", _("Invite to guild"))); + } } } @@ -725,16 +745,27 @@ void PopupMenu::showChatPopup(int x, int y, ChatTab *tab) { if (guild1->getId() == guild2->getId()) { - mBrowserBox->addRow(strprintf( - "@@guild-kick|%s@@", _("Kick from guild"))); - mBrowserBox->addRow(strprintf( - "@@guild-pos|%s >@@", _("Change pos in guild"))); + if (guild2->getServerGuild() || (guildManager + && guildManager->havePower())) + { + mBrowserBox->addRow(strprintf( + "@@guild-kick|%s@@", _("Kick from guild"))); + } + if (guild2->getServerGuild()) + { + mBrowserBox->addRow(strprintf("@@guild-pos|%s >@@", + _("Change pos in guild"))); + } } } else { - mBrowserBox->addRow(strprintf( - "@@guild|%s@@", _("Invite to guild"))); + if (guild2->getServerGuild() || (guildManager + && guildManager->havePower())) + { + mBrowserBox->addRow(strprintf( + "@@guild|%s@@", _("Invite to guild"))); + } } } } @@ -897,7 +928,12 @@ void PopupMenu::handleLink(const std::string &link, { const Guild *guild = player_node->getGuild(); if (guild) - Net::getGuildHandler()->invite(guild->getId(), mNick); + { + if (guild->getServerGuild()) + Net::getGuildHandler()->invite(guild->getId(), mNick); + else if (guildManager) + guildManager->invite(mNick); + } } } else if (link == "nuke" && being) @@ -1263,7 +1299,12 @@ void PopupMenu::handleLink(const std::string &link, { const Guild *guild = player_node->getGuild(); if (guild) - Net::getGuildHandler()->kick(guild->getMember(mNick)); + { + if (guild->getServerGuild()) + Net::getGuildHandler()->kick(guild->getMember(mNick)); + else if (guildManager) + guildManager->kick(mNick); + } } } else if (link == "enable highlight" && mTab) diff --git a/src/gui/setup_other.cpp b/src/gui/setup_other.cpp index b405f5045..05ec9d672 100644 --- a/src/gui/setup_other.cpp +++ b/src/gui/setup_other.cpp @@ -145,6 +145,12 @@ Setup_Other::Setup_Other() this, "logNpcInGuiEvent"); + new SetupItemLabel(_("Bots support"), "", this); + + new SetupItemCheckBox(_("Enable guild bot support and disable native " + "guild support"), "", "enableGuildBot", this, + "enableGuildBotEvent", false); + new SetupItemLabel(_("Other"), "", this); new SetupItemCheckBox(_("Enable server side attack"), "", diff --git a/src/gui/socialwindow.cpp b/src/gui/socialwindow.cpp index e3aa69b30..aa26fa051 100644 --- a/src/gui/socialwindow.cpp +++ b/src/gui/socialwindow.cpp @@ -206,6 +206,109 @@ private: Guild *mGuild; }; +class GuildTab2 : public SocialTab, public gcn::ActionListener +{ +public: + GuildTab2(Guild *guild): + mGuild(guild) + { + setCaption(_("Guild")); + + setTabColor(&Theme::getThemeColor(Theme::GUILD_SOCIAL_TAB)); + + mList = new AvatarListBox(guild); + mScroll = new ScrollArea(mList); + + mScroll->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_AUTO); + mScroll->setVerticalScrollPolicy(gcn::ScrollArea::SHOW_ALWAYS); + } + + ~GuildTab2() + { + delete mList; + mList = 0; + delete mScroll; + mScroll = 0; + } + + void action(const gcn::ActionEvent &event) + { +/* + if (event.getId() == "do invite") + { + std::string name = mInviteDialog->getText(); + Net::getGuildHandler()->invite(mGuild->getId(), name); + + if (localChatTab) + { + localChatTab->chatLog(strprintf( + _("Invited user %s to guild %s."), + name.c_str(), mGuild->getName().c_str()), BY_SERVER); + } + mInviteDialog = 0; + } + else if (event.getId() == "~do invite") + { + mInviteDialog = 0; + } + else if (event.getId() == "yes") + { + Net::getGuildHandler()->leave(mGuild->getId()); + if (localChatTab) + { + localChatTab->chatLog(strprintf(_("Guild %s quit requested."), + mGuild->getName().c_str()), BY_SERVER); + } + mConfirmDialog = 0; + } + else if (event.getId() == "~yes") + { + mConfirmDialog = 0; + } +*/ + } + + void updateList() + { + } + + void updateAvatar(std::string name A_UNUSED) + { + } + + void resetDamage(std::string name A_UNUSED) + { + } + +protected: + void invite() + { +/* + mInviteDialog = new TextDialog(_("Member Invite to Guild"), + strprintf(_("Who would you like to invite to guild %s?"), + mGuild->getName().c_str()), + socialWindow); + mInviteDialog->setActionEventId("do invite"); + mInviteDialog->addActionListener(this); +*/ + } + + void leave() + { +/* + mConfirmDialog = new ConfirmDialog(_("Leave Guild?"), + strprintf(_("Are you sure you want to leave guild %s?"), + mGuild->getName().c_str()), + socialWindow); + + mConfirmDialog->addActionListener(this); +*/ + } + +private: + Guild *mGuild; +}; + class PartyTab : public SocialTab, public gcn::ActionListener { public: @@ -1106,9 +1209,13 @@ bool SocialWindow::addTab(Guild *guild) if (mGuilds.find(guild) != mGuilds.end()) return false; - GuildTab *tab = new GuildTab(guild); - mGuilds[guild] = tab; + SocialTab *tab = 0; + if (guild->getServerGuild()) + tab = new GuildTab(guild); + else + tab = new GuildTab2(guild); + mGuilds[guild] = tab; mTabs->addTab(tab, tab->mScroll); updateButtons(); diff --git a/src/gui/widgets/guildtab.cpp b/src/gui/widgets/guildtab.cpp new file mode 100644 index 000000000..d9f61cb43 --- /dev/null +++ b/src/gui/widgets/guildtab.cpp @@ -0,0 +1,127 @@ +/* + * The ManaPlus Client + * Copyright (C) 2008-2009 The Mana World Development Team + * Copyright (C) 2009-2010 The Mana Developers + * Copyright (C) 2011 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "gui/widgets/guildtab.h" + +#include "chatlogger.h" +#include "commandhandler.h" +#include "guild.h" +#include "guildmanager.h" +#include "localplayer.h" + +#include "gui/theme.h" + +#include "resources/iteminfo.h" +#include "resources/itemdb.h" + +#include "utils/dtor.h" +#include "utils/gettext.h" +#include "utils/stringutils.h" + +#include "debug.h" + +GuildTab::GuildTab() : + ChatTab(_("Guild")) +{ + setTabColor(&Theme::getThemeColor(Theme::GUILD_CHAT_TAB)); +} + +GuildTab::~GuildTab() +{ +} + +bool GuildTab::handleCommand(const std::string &type, const std::string &args) +{ + if (type == "help") + { + if (args == "invite") + { + chatLog(_("Command: /invite ")); + chatLog(_("This command invites to the guild you're in.")); + chatLog(_("If the has spaces in it, enclose it in " + "double quotes (\").")); + } + else if (args == "leave") + { + chatLog(_("Command: /leave")); + chatLog(_("This command causes the player to leave the guild.")); + } + else + return false; + } + else if (type == "invite" && guildManager) + { + guildManager->invite(args); + } + else if (type == "leave" && guildManager) + { + guildManager->leave(); + } + else if (type == "kick" && guildManager) + { + guildManager->kick(args); + } + else if (type == "notice" && guildManager) + { + guildManager->notice(args); + } + else + { + return false; + } + + return false; +} + +void GuildTab::handleInput(const std::string &msg) +{ + if (!guildManager) + return; + + if (chatWindow) + guildManager->chat(chatWindow->doReplace(msg)); + else + guildManager->chat(msg); +} + +void GuildTab::showHelp() +{ + chatLog(_("/help > Display this help.")); + chatLog(_("/invite > Invite a player to your guild")); + chatLog(_("/leave > Leave the guild you are in")); + chatLog(_("/kick > Kick some one from the guild you are in")); +} + +void GuildTab::getAutoCompleteList(std::vector &names) const +{ + if (!guildManager) + return; + + guildManager->getNames(names); + names.push_back("/notice "); +} + +void GuildTab::saveToLogFile(std::string &msg) +{ + if (chatLogger) + chatLogger->log("#Guild", msg); +} diff --git a/src/gui/widgets/guildtab.h b/src/gui/widgets/guildtab.h new file mode 100644 index 000000000..a7f0aa766 --- /dev/null +++ b/src/gui/widgets/guildtab.h @@ -0,0 +1,52 @@ +/* + * The ManaPlus Client + * Copyright (C) 2009 The Mana World Development Team + * Copyright (C) 2009-2010 The Mana Developers + * Copyright (C) 2011 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef GUI_GUILDTAB_H +#define GUI_GUILDTAB_H + +#include "gui/widgets/chattab.h" + +/** + * A tab for a guild chat channel. + */ +class GuildTab : public ChatTab +{ + public: + GuildTab(); + + ~GuildTab(); + + bool handleCommand(const std::string &type, const std::string &args); + + void showHelp(); + + void saveToLogFile(std::string &msg); + + int getType() const { return ChatTab::TAB_GUILD; } + + protected: + void handleInput(const std::string &msg); + + void getAutoCompleteList(std::vector &names) const; +}; + +#endif diff --git a/src/guild.cpp b/src/guild.cpp index b84602858..e36b68863 100644 --- a/src/guild.cpp +++ b/src/guild.cpp @@ -36,6 +36,9 @@ class SortGuildFunctor if (m1->getPos() != m2->getPos()) return m1->getPos() < m2->getPos(); +// if (m1->getOnline() != m2->getOnline()) +// return m1->getOnline() > m2->getOnline(); + return m1->getName() < m2->getName(); } } guildSorter; @@ -66,7 +69,8 @@ Guild::GuildMap Guild::guilds; Guild::Guild(short id): mId(id), mCanInviteUsers(false), - mEmblemId(0) + mEmblemId(0), + mServerGuild(true) { guilds[id] = this; } diff --git a/src/guild.h b/src/guild.h index 7986eb5d3..62135e9ad 100644 --- a/src/guild.h +++ b/src/guild.h @@ -178,11 +178,17 @@ public: void setEmblemId(int id) { mEmblemId = id; } - int getEmblemId() + int getEmblemId() const { return mEmblemId; } static void clearGuilds(); + void setServerGuild(bool b) + { mServerGuild = b; } + + bool getServerGuild() const + { return mServerGuild; } + private: typedef std::map GuildMap; static GuildMap guilds; @@ -199,6 +205,7 @@ private: bool mCanInviteUsers; int mEmblemId; PositionsMap mPositions; + bool mServerGuild; }; #endif // GUILD_H diff --git a/src/guildmanager.cpp b/src/guildmanager.cpp new file mode 100644 index 000000000..ec9de2506 --- /dev/null +++ b/src/guildmanager.cpp @@ -0,0 +1,309 @@ +/* + * The ManaPlus Client + * Copyright (C) 2011 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "guildmanager.h" + +#include "actorspritemanager.h" +#include "client.h" +#include "configuration.h" +#include "guild.h" +#include "localplayer.h" + +#include "gui/socialwindow.h" + +#include "gui/widgets/guildtab.h" + +#include "net/chathandler.h" +#include "net/net.h" + +#include "utils/stringutils.h" + +#include "debug.h" + + +GuildManager::GuildManager() : + mEnableGuildBot(false), + mGotInfo(false), + mGotName(false), + mHavePower(false), + mTab(0), + mRequest(false) +{ +} + +GuildManager::~GuildManager() +{ + mTab = 0; +} + +void GuildManager::init() +{ + int val = serverConfig.getValue("enableGuildBot", -1); + if (val == -1) + { + if (Client::isTmw()) + val = 1; + else + val = 0; + serverConfig.setValue("enableGuildBot", val); + } + mEnableGuildBot = val; +} + +void GuildManager::send(std::string msg) +{ + Net::getChatHandler()->privateMessage("guild", msg); +} + +void GuildManager::chat(std::string msg) +{ + if (!player_node || !mTab) + return; + + Net::getChatHandler()->privateMessage("guild", msg); + mTab->chatLog(player_node->getName(), msg); +} + +void GuildManager::getNames(std::vector &names) +{ +} + +void GuildManager::requestGuildInfo() +{ + if (mRequest) + return; + + if (!mGotName) + { + send("!info"); + mRequest = true; + } + else if (!mGotInfo) + { + send("!getonlineinfo"); + mRequest = true; + } +} + +void GuildManager::updateList() +{ + Guild *guild = Guild::getGuild(1); + if (guild) + { + logger->log("filling player"); + guild->setServerGuild(false); + std::vector::iterator it = mTempList.begin(); + std::vector::iterator it_end = mTempList.end(); + int i = 0; + while (it != it_end) + { + std::string name = *it; + 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); + } + } + ++ it; + i ++; + } + guild->sort(); + if (actorSpriteManager) + actorSpriteManager->updatePlayerGuild(); + } + mTempList.clear(); + mGotInfo = true; + if (!mTab) + { + mTab = new GuildTab(); + mTab->loadFromLogFile("#Guild"); + if (player_node) + player_node->addGuild(guild); + } +} + +bool GuildManager::processGuildMessage(std::string msg) +{ + bool res = process(msg); + + if (!mRequest) + requestGuildInfo(); + + return res; +} + +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.")) + { + if (msg.size() < 4) + return false; + if (msg[0] == '#' && msg[1] == '#') + msg = msg.substr(3); + + GuildMember *m = guild->getMember(msg); + if (m) + m->setOnline(false); + mRequest = false; + return true; + } + else if (findCutLast(msg, " is now Online.")) + { + if (msg.size() < 4) + return false; + if (msg[0] == '#' && msg[1] == '#') + msg = msg.substr(3); + GuildMember *m = guild->getMember(msg); + if (m) + m->setOnline(true); + mRequest = false; + return true; + } + else if (findCutFirst(msg, "Welcome to the ")) + { + logger->log("welcome message: %s", msg.c_str()); + int pos = msg.find("! ("); + if (pos == (int)std::string::npos) + return false; + msg = msg.substr(0, pos); + guild->setName(msg); + if (player_node) + player_node->setGuildName(msg); + mGotName = true; + mRequest = false; + return true; + } + else if (findCutFirst(msg, "Player name: ")) + { + int pos = msg.find("Access Level: "); + if (pos == (int)std::string::npos) + return false; + + msg = msg.substr(pos); + if (!findCutFirst(msg, "Access Level: ")) + return false; + + pos = msg.find(", Guild:"); + if (pos == (int)std::string::npos) + return false; + + int level = atoi(msg.substr(0, pos).c_str()); + if (level >= 10) + mHavePower = true; + else + mHavePower = false; + + msg = msg.substr(pos + strlen(", Guild:")); + pos = msg.find(", No. Of Online Players: "); + if (pos == (int)std::string::npos) + return false; + + msg = msg.substr(0, pos); +// logger->log("guild name: %s", msg.c_str()); + + guild->setName(msg); + if (player_node) + player_node->setGuildName(msg); + mGotName = true; + mRequest = false; + return true; + } + else if (findCutFirst(msg, "OL#")) + { + logger->log("OL"); + mTempList.clear(); + splitToStringVector(mTempList, msg, '#'); + if (msg.size() < 1 || msg[msg.size() - 1] != '#') + updateList(); + mRequest = false; + return true; + } + else if (findCutFirst(msg, "oL#")) + { + logger->log("oL"); + splitToStringVector(mTempList, msg, '#'); + if (msg.size() < 1 || msg[msg.size() - 1] != '#') + updateList(); + mRequest = false; + return true; + } + else if (msg == "You are currently not in a guild. For more information " + "or to discuss the possibility of adding you own guild " + "please contact Jero.") + { + mRequest = true; + return true; + } + else + { + if (mTab) + { + std::string::size_type pos = msg.find(": ", 0); + if (pos != std::string::npos) + { + std::string sender_name = ((pos == std::string::npos) + ? "" : msg.substr(0, pos)); + + msg.erase(0, pos + 2); + if (msg.size() > 3 && msg[0] == '#' && msg[1] == '#') + msg.erase(0, 3); + + trim(msg); + mTab->chatLog(sender_name, msg); + } + else + { + mTab->chatLog(msg); + } + return true; + } + } + return false; +} + +void GuildManager::kick(std::string msg) +{ +} + +void GuildManager::invite(std::string msg) +{ +} + +void GuildManager::leave() +{ +} + +void GuildManager::notice(std::string msg) +{ +} diff --git a/src/guildmanager.h b/src/guildmanager.h new file mode 100644 index 000000000..f02368ab6 --- /dev/null +++ b/src/guildmanager.h @@ -0,0 +1,81 @@ +/* + * The ManaPlus Client + * Copyright (C) 2011 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef GUILDMANAGER_H +#define GUILDMANAGER_H + +#include "utils/dtor.h" + +#include +#include +#include + +class GuildTab; + +class GuildManager +{ + public: + GuildManager(); + + ~GuildManager(); + + void init(); + + void chat(std::string msg); + + void send(std::string msg); + + bool processGuildMessage(std::string msg); + + void getNames(std::vector &names); + + void requestGuildInfo(); + + void updateList(); + + bool getEnableGuildBot() + { return mEnableGuildBot; } + + void kick(std::string msg); + + void invite(std::string msg); + + void leave(); + + void notice(std::string msg); + + bool havePower() + { return mHavePower; } + + private: + bool process(std::string msg); + + bool mEnableGuildBot; + bool mGotInfo; + bool mGotName; + bool mHavePower; + std::vector mTempList; + GuildTab *mTab; + bool mRequest; +}; + +extern GuildManager *guildManager; + +#endif // GUILDMANAGER_H diff --git a/src/net/ea/chathandler.cpp b/src/net/ea/chathandler.cpp index c188a2204..e430dfc0f 100644 --- a/src/net/ea/chathandler.cpp +++ b/src/net/ea/chathandler.cpp @@ -25,6 +25,7 @@ #include "actorspritemanager.h" #include "being.h" #include "configuration.h" +#include "guildmanager.h" #include "localplayer.h" #include "playerrelations.h" #include "logger.h" @@ -161,6 +162,12 @@ void ChatHandler::processWhisper(Net::MessageIn &msg) if (nick != "Server") { + if (guildManager && guildManager->getEnableGuildBot() + && nick == "guild" && guildManager->processGuildMessage(chatMsg)) + { + return; + } + if (player_relations.hasPermission( nick, PlayerRelation::WHISPER)) { diff --git a/src/net/ea/guildhandler.cpp b/src/net/ea/guildhandler.cpp index 0210a76ff..2accb1f1d 100644 --- a/src/net/ea/guildhandler.cpp +++ b/src/net/ea/guildhandler.cpp @@ -125,6 +125,7 @@ void GuildHandler::processGuildPositionInfo(Net::MessageIn &msg) if (!guildTab && chatWindow) { guildTab = new GuildTab(); + guildTab->loadFromLogFile("#Guild"); if (player_node) player_node->addGuild(taGuild); memberList(guildId); diff --git a/src/utils/stringutils.cpp b/src/utils/stringutils.cpp index 0243c4315..317d88f2d 100644 --- a/src/utils/stringutils.cpp +++ b/src/utils/stringutils.cpp @@ -524,3 +524,57 @@ void deleteCharLeft(std::string &str, unsigned *pos) break; } } + +bool findLast(std::string &str1, std::string str2) +{ + const unsigned s1 = str1.size(); + const unsigned s2 = str2.size(); + if (s1 < s2) + return false; + std::string tmp = str1.substr(s1 - s2); + if (tmp == str2) + return true; + return false; +} + +bool findFirst(std::string &str1, std::string str2) +{ + const unsigned s1 = str1.size(); + const unsigned s2 = str2.size(); + if (s1 < s2) + return false; + std::string tmp = str1.substr(0, s2); + if (tmp == str2) + return true; + return false; +} + +bool findCutLast(std::string &str1, std::string str2) +{ + const unsigned s1 = str1.size(); + const unsigned s2 = str2.size(); + if (s1 < s2) + return false; + std::string tmp = str1.substr(s1 - s2); + if (tmp == str2) + { + str1 = str1.substr(0, s1 - s2); + return true; + } + return false; +} + +bool findCutFirst(std::string &str1, std::string str2) +{ + const unsigned s1 = str1.size(); + const unsigned s2 = str2.size(); + if (s1 < s2) + return false; + std::string tmp = str1.substr(0, s2); + if (tmp == str2) + { + str1 = str1.substr(s2); + return true; + } + return false; +} diff --git a/src/utils/stringutils.h b/src/utils/stringutils.h index 4fe6369e9..25e038a89 100644 --- a/src/utils/stringutils.h +++ b/src/utils/stringutils.h @@ -193,4 +193,12 @@ std::string stringToHexPath(const std::string &str); void deleteCharLeft(std::string &str, unsigned *pos); +bool findLast(std::string &str1, std::string str2); + +bool findFirst(std::string &str1, std::string str2); + +bool findCutLast(std::string &str1, std::string str2); + +bool findCutFirst(std::string &str1, std::string str2); + #endif // UTILS_STRINGUTILS_H -- cgit v1.2.3-70-g09d2 From 88487446af6f9e01fe27b63e7710c991b998d4b9 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sat, 27 Aug 2011 05:57:14 +0300 Subject: Fix lower chars issue. --- src/utils/stringutils.cpp | 2 +- src/utils/stringutils.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src/utils') diff --git a/src/utils/stringutils.cpp b/src/utils/stringutils.cpp index 317d88f2d..361bc860c 100644 --- a/src/utils/stringutils.cpp +++ b/src/utils/stringutils.cpp @@ -181,7 +181,7 @@ unsigned long findI(std::string str, std::string subStr) return str.find(subStr); } -unsigned long findI(std::string &text, std::vector &list) +unsigned long findI(std::string text, std::vector &list) { std::string str = toLower(text); unsigned long idx; diff --git a/src/utils/stringutils.h b/src/utils/stringutils.h index 25e038a89..c0457bc52 100644 --- a/src/utils/stringutils.h +++ b/src/utils/stringutils.h @@ -133,7 +133,7 @@ bool isWordSeparator(char chr); unsigned long findI(std::string str, std::string subStr); -unsigned long findI(std::string &text, std::vector &list); +unsigned long findI(std::string text, std::vector &list); const std::string encodeStr(unsigned int value, unsigned int size = 0); -- cgit v1.2.3-70-g09d2 From a9345c0e74408538488b0a329202ce611a4a0072 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sun, 28 Aug 2011 21:52:49 +0300 Subject: Add support for auto download content fixes. --- src/gui/updaterwindow.cpp | 76 +++++++++++++++++++++++++++++++++++++++++------ src/gui/updaterwindow.h | 13 +++++++- src/utils/stringutils.cpp | 8 +++++ src/utils/stringutils.h | 2 ++ 4 files changed, 89 insertions(+), 10 deletions(-) (limited to 'src/utils') diff --git a/src/gui/updaterwindow.cpp b/src/gui/updaterwindow.cpp index 7534b12a9..ba482919e 100644 --- a/src/gui/updaterwindow.cpp +++ b/src/gui/updaterwindow.cpp @@ -54,6 +54,7 @@ const std::string xmlUpdateFile = "resources.xml"; const std::string txtUpdateFile = "resources2.txt"; +const std::string updateServer2 = "http://download.evolonline.org/manaplus/updates/"; std::vector loadXMLFile(const std::string &fileName); std::vector loadTxtFile(const std::string &fileName); @@ -137,6 +138,7 @@ UpdaterWindow::UpdaterWindow(const std::string &updateHost, mDownloadStatus(UPDATE_NEWS), mUpdateHost(updateHost), mUpdatesDir(updatesDir), + mUpdatesDirReal(updatesDir), mCurrentFile("news.txt"), mDownloadProgress(0.0f), mCurrentChecksum(0), @@ -147,6 +149,7 @@ UpdaterWindow::UpdaterWindow(const std::string &updateHost, mMemoryBuffer(NULL), mDownload(NULL), mUpdateIndex(0), + mUpdateIndexOffset(0), mLoadUpdates(applyUpdates), mUpdateType(updateType) { @@ -181,6 +184,10 @@ UpdaterWindow::UpdaterWindow(const std::string &updateHost, setVisible(true); mCancelButton->requestFocus(); + mUpdateServerPath = mUpdateHost; + removeProtocol(mUpdateServerPath); + logger->log("mUpdateServerPath: %s, %s", mUpdateHost.c_str(), mUpdateServerPath.c_str()); + // Try to download the updates list download(); } @@ -539,8 +546,9 @@ void UpdaterWindow::logic() mProgressBar->setProgress(mDownloadProgress); if (mUpdateFiles.size() && mUpdateIndex <= mUpdateFiles.size()) { - mProgressBar->setText(strprintf("%d/%d", - mUpdateIndex + 1, (int)mUpdateFiles.size() + 1)); + mProgressBar->setText(strprintf("%d/%d", mUpdateIndex + + mUpdateIndexOffset + 1, (int)mUpdateFiles.size() + + (int)mTempUpdateFiles.size() + 1)); } else { @@ -582,13 +590,12 @@ void UpdaterWindow::logic() // Parse current memory buffer as news and dispose of the data loadPatch(); -/* - mCurrentFile = "news.txt"; - mStoreInMemory = true; - mDownloadStatus = UPDATE_NEWS; - download(); // download() changes mDownloadComplete to false -*/ - mDownloadStatus = UPDATE_COMPLETE; + mUpdateHost = updateServer2 + mUpdateServerPath; + mUpdatesDir += "/fix"; + mCurrentFile = xmlUpdateFile; + mStoreInMemory = false; + mDownloadStatus = UPDATE_LIST2; + download(); } break; @@ -681,7 +688,58 @@ void UpdaterWindow::logic() } } break; + case UPDATE_LIST2: + if (mDownloadComplete) + { + if (mCurrentFile == xmlUpdateFile) + { + mTempUpdateFiles = loadXMLFile( + mUpdatesDir + "/" + xmlUpdateFile); + } + mUpdateIndexOffset = mUpdateIndex; + mUpdateIndex = 0; + mStoreInMemory = false; + mDownloadStatus = UPDATE_RESOURCES2; + download(); + } + break; + case UPDATE_RESOURCES2: + if (mDownloadComplete) + { + if (mUpdateIndex < mTempUpdateFiles.size()) + { + updateFile thisFile = mTempUpdateFiles[mUpdateIndex]; + mCurrentFile = thisFile.name; + std::string checksum; + checksum = thisFile.hash; + std::stringstream ss(checksum); + ss >> std::hex >> mCurrentChecksum; + + std::ifstream temp( + (mUpdatesDir + "/" + mCurrentFile).c_str()); + + if (!temp.is_open() || !validateFile(mUpdatesDir + "/" + + mCurrentFile, mCurrentChecksum)) + { + temp.close(); + download(); + } + else + { + temp.close(); + logger->log("%s already here", mCurrentFile.c_str()); + } + mUpdateIndex++; + } + else + { + mUpdatesDir = mUpdatesDirReal; + mDownloadStatus = UPDATE_COMPLETE; + } + } + break; case UPDATE_COMPLETE: + mUpdatesDir = mUpdatesDirReal; enable(); setLabel(_("Completed")); break; diff --git a/src/gui/updaterwindow.h b/src/gui/updaterwindow.h index a1dc556d5..e9a45241f 100644 --- a/src/gui/updaterwindow.h +++ b/src/gui/updaterwindow.h @@ -146,7 +146,9 @@ private: UPDATE_COMPLETE, UPDATE_NEWS, UPDATE_RESOURCES, - UPDATE_PATCH + UPDATE_PATCH, + UPDATE_LIST2, + UPDATE_RESOURCES2 }; /** Status of the current download. */ @@ -158,6 +160,8 @@ private: /** Place where the updates are stored (absolute path). */ std::string mUpdatesDir; + std::string mUpdatesDirReal; + /** The file currently downloading. */ std::string mCurrentFile; @@ -194,9 +198,15 @@ private: /** List of files to download. */ std::vector mUpdateFiles; + /** List of temp files to download. */ + std::vector mTempUpdateFiles; + /** Index of the file to be downloaded. */ unsigned int mUpdateIndex; + /** Index offset for disaplay downloaded file. */ + unsigned int mUpdateIndexOffset; + /** Tells ~UpdaterWindow() if it should load updates */ bool mLoadUpdates; @@ -208,6 +218,7 @@ private: ProgressBar *mProgressBar; /**< Update progress bar. */ BrowserBox *mBrowserBox; /**< Box to display news. */ ScrollArea *mScrollArea; /**< Used to scroll news box. */ + std::string mUpdateServerPath; }; #endif diff --git a/src/utils/stringutils.cpp b/src/utils/stringutils.cpp index 361bc860c..176c5499c 100644 --- a/src/utils/stringutils.cpp +++ b/src/utils/stringutils.cpp @@ -578,3 +578,11 @@ bool findCutFirst(std::string &str1, std::string str2) } return false; } + +std::string &removeProtocol(std::string &url) +{ + int i = url.find("://"); + if (i != (int)std::string::npos) + url = url.substr(i + 3); + return url; +} diff --git a/src/utils/stringutils.h b/src/utils/stringutils.h index c0457bc52..25fe11e2d 100644 --- a/src/utils/stringutils.h +++ b/src/utils/stringutils.h @@ -201,4 +201,6 @@ bool findCutLast(std::string &str1, std::string str2); bool findCutFirst(std::string &str1, std::string str2); +std::string &removeProtocol(std::string &url); + #endif // UTILS_STRINGUTILS_H -- cgit v1.2.3-70-g09d2