From 07c2eb8ffd62fe69f410cc045efc837441a6b6d4 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Mon, 22 Aug 2011 00:42:03 +0300 Subject: Replace typo dont to don't. --- src/net/tmwa/beinghandler.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/net') diff --git a/src/net/tmwa/beinghandler.cpp b/src/net/tmwa/beinghandler.cpp index 17503a406..5016b2f8c 100644 --- a/src/net/tmwa/beinghandler.cpp +++ b/src/net/tmwa/beinghandler.cpp @@ -552,7 +552,7 @@ void BeingHandler::processPlayerMoveUpdate(Net::MessageIn &msg, int msgType) dstBeing->setTileCoords(srcX, srcY); dstBeing->setDestination(dstX, dstY); - // because server dont send direction in move packet, + // because server don't send direction in move packet, // we fixing it if (srcX != dstX || srcY != dstY) -- 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/net') 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 106180f42f536f4b898a72f36af1b2be28d1a8ed Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sun, 28 Aug 2011 00:18:58 +0300 Subject: Fix guild name reset on players from time. --- src/being.cpp | 1 - src/net/ea/beinghandler.cpp | 4 +++- 2 files changed, 3 insertions(+), 2 deletions(-) (limited to 'src/net') diff --git a/src/being.cpp b/src/being.cpp index 36aa00689..2d9194c6e 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -760,7 +760,6 @@ void Being::setGuildName(const std::string &name) mGuildName = name; } - void Being::setGuildPos(const std::string &pos A_UNUSED) { // logger->log("Got guild position \"%s\" for being %s(%i)", pos.c_str(), mName.c_str(), mId); diff --git a/src/net/ea/beinghandler.cpp b/src/net/ea/beinghandler.cpp index 06e86f8a4..2714f94ce 100644 --- a/src/net/ea/beinghandler.cpp +++ b/src/net/ea/beinghandler.cpp @@ -29,6 +29,7 @@ #include "client.h" #include "effectmanager.h" #include "guild.h" +#include "guildmanager.h" #include "keyboardconfig.h" #include "localplayer.h" #include "logger.h" @@ -661,7 +662,8 @@ void BeingHandler::processPlayerGuilPartyInfo(Net::MessageIn &msg) if ((dstBeing = actorSpriteManager->findBeing(msg.readInt32()))) { dstBeing->setPartyName(msg.readString(24)); - dstBeing->setGuildName(msg.readString(24)); + if (!guildManager || !guildManager->getEnableGuildBot()) + dstBeing->setGuildName(msg.readString(24)); dstBeing->setGuildPos(msg.readString(24)); dstBeing->addToCache(); msg.readString(24); // Discard this -- cgit v1.2.3-70-g09d2 From 9f752d5431364c052b364045015d3574da2c320c Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Tue, 30 Aug 2011 01:57:05 +0300 Subject: Dont create guild manager instance if guild bot support not enabled. --- src/client.cpp | 4 +--- src/game.cpp | 11 ++++------- src/gui/setup_other.cpp | 3 +++ src/gui/socialwindow.cpp | 4 ++-- src/guildmanager.cpp | 7 ++++++- src/guildmanager.h | 6 +++--- src/net/ea/beinghandler.cpp | 2 +- src/net/ea/chathandler.cpp | 2 +- 8 files changed, 21 insertions(+), 18 deletions(-) (limited to 'src/net') diff --git a/src/client.cpp b/src/client.cpp index 60af41ed3..2e3652188 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -794,9 +794,7 @@ int Client::exec() if (mumbleManager) mumbleManager->setServer(mCurrentServer.hostname); - if (!guildManager) - guildManager = new GuildManager(); - guildManager->init(); + GuildManager::init(); if (!mConfigAutoSaved) { diff --git a/src/game.cpp b/src/game.cpp index 8df48b775..303c59edb 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -177,11 +177,7 @@ static void initEngines() commandHandler = new CommandHandler; channelManager = new ChannelManager; effectManager = new EffectManager; - if (!guildManager) - { - guildManager = new GuildManager; - guildManager->init(); - } + GuildManager::init(); particleEngine = new Particle(NULL); particleEngine->setupEngine(); @@ -338,7 +334,7 @@ static void destroyGuiWindows() Mana::Event::trigger(CHANNEL_GAME, Mana::Event(EVENT_GUIWINDOWSUNLOADED)); - if (guildManager && guildManager->getEnableGuildBot()) + if (guildManager && GuildManager::getEnableGuildBot()) guildManager->reload(); } @@ -406,7 +402,7 @@ Game::Game(): setupWindow->setInGame(true); clearKeysArray(); - if (guildManager && guildManager->getEnableGuildBot()) + if (guildManager && GuildManager::getEnableGuildBot()) guildManager->requestGuildInfo(); Mana::Event::trigger(CHANNEL_GAME, Mana::Event(EVENT_CONSTRUCTED)); @@ -437,6 +433,7 @@ Game::~Game() del_0(mCurrentMap) del_0(spellManager) del_0(spellShortcut) + del_0(guildManager) del_0(mumbleManager) Being::clearCache(); diff --git a/src/gui/setup_other.cpp b/src/gui/setup_other.cpp index 05ec9d672..1cad4c594 100644 --- a/src/gui/setup_other.cpp +++ b/src/gui/setup_other.cpp @@ -147,6 +147,9 @@ Setup_Other::Setup_Other() new SetupItemLabel(_("Bots support"), "", this); + new SetupItemCheckBox(_("Enable auction bot support"), "", + "enableAuctionBot", this, "enableAuctionBotEvent", false); + new SetupItemCheckBox(_("Enable guild bot support and disable native " "guild support"), "", "enableGuildBot", this, "enableGuildBotEvent", false); diff --git a/src/gui/socialwindow.cpp b/src/gui/socialwindow.cpp index ca52ea283..b9c8cb365 100644 --- a/src/gui/socialwindow.cpp +++ b/src/gui/socialwindow.cpp @@ -1311,7 +1311,7 @@ void SocialWindow::action(const gcn::ActionEvent &event) strprintf(_("Accepted guild invite from %s."), mPartyInviter.c_str())); } - if (!guildManager || !guildManager->getEnableGuildBot()) + if (!guildManager || !GuildManager::getEnableGuildBot()) Net::getGuildHandler()->inviteResponse(mGuildInvited, true); else guildManager->inviteResponse(true); @@ -1324,7 +1324,7 @@ void SocialWindow::action(const gcn::ActionEvent &event) strprintf(_("Rejected guild invite from %s."), mPartyInviter.c_str())); } - if (!guildManager || !guildManager->getEnableGuildBot()) + if (!guildManager || !GuildManager::getEnableGuildBot()) Net::getGuildHandler()->inviteResponse(mGuildInvited, false); else guildManager->inviteResponse(false); diff --git a/src/guildmanager.cpp b/src/guildmanager.cpp index 77324e67e..2c55caefa 100644 --- a/src/guildmanager.cpp +++ b/src/guildmanager.cpp @@ -38,9 +38,9 @@ #include "debug.h" +bool GuildManager::mEnableGuildBot = false; GuildManager::GuildManager() : - mEnableGuildBot(false), mGotInfo(false), mGotName(false), mHavePower(false), @@ -57,6 +57,9 @@ GuildManager::~GuildManager() void GuildManager::init() { + if (guildManager) + return; + int val = serverConfig.getValue("enableGuildBot", -1); if (val == -1) { @@ -67,6 +70,8 @@ void GuildManager::init() serverConfig.setValue("enableGuildBot", val); } mEnableGuildBot = val; + if (mEnableGuildBot) + guildManager = new GuildManager(); } void GuildManager::reload() diff --git a/src/guildmanager.h b/src/guildmanager.h index d0ee7fb62..80014e352 100644 --- a/src/guildmanager.h +++ b/src/guildmanager.h @@ -37,7 +37,7 @@ class GuildManager ~GuildManager(); - void init(); + static void init(); void chat(std::string msg); @@ -51,7 +51,7 @@ class GuildManager void updateList(); - bool getEnableGuildBot() + static bool getEnableGuildBot() { return mEnableGuildBot; } void kick(std::string msg); @@ -80,7 +80,7 @@ class GuildManager private: bool process(std::string msg); - bool mEnableGuildBot; + static bool mEnableGuildBot; bool mGotInfo; bool mGotName; bool mHavePower; diff --git a/src/net/ea/beinghandler.cpp b/src/net/ea/beinghandler.cpp index 2714f94ce..4a5cfb841 100644 --- a/src/net/ea/beinghandler.cpp +++ b/src/net/ea/beinghandler.cpp @@ -662,7 +662,7 @@ void BeingHandler::processPlayerGuilPartyInfo(Net::MessageIn &msg) if ((dstBeing = actorSpriteManager->findBeing(msg.readInt32()))) { dstBeing->setPartyName(msg.readString(24)); - if (!guildManager || !guildManager->getEnableGuildBot()) + if (!guildManager || !GuildManager::getEnableGuildBot()) dstBeing->setGuildName(msg.readString(24)); dstBeing->setGuildPos(msg.readString(24)); dstBeing->addToCache(); diff --git a/src/net/ea/chathandler.cpp b/src/net/ea/chathandler.cpp index e430dfc0f..5737cc2b2 100644 --- a/src/net/ea/chathandler.cpp +++ b/src/net/ea/chathandler.cpp @@ -162,7 +162,7 @@ void ChatHandler::processWhisper(Net::MessageIn &msg) if (nick != "Server") { - if (guildManager && guildManager->getEnableGuildBot() + if (guildManager && GuildManager::getEnableGuildBot() && nick == "guild" && guildManager->processGuildMessage(chatMsg)) { return; -- cgit v1.2.3-70-g09d2 From c24c0389a9942efffe3090744b592b73b7e6a3bc Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Tue, 30 Aug 2011 11:56:26 +0300 Subject: Don't report about clothes color change packet in log. --- src/net/tmwa/beinghandler.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/net') diff --git a/src/net/tmwa/beinghandler.cpp b/src/net/tmwa/beinghandler.cpp index 5016b2f8c..ce2db733f 100644 --- a/src/net/tmwa/beinghandler.cpp +++ b/src/net/tmwa/beinghandler.cpp @@ -331,6 +331,9 @@ void BeingHandler::processBeingChangeLook(Net::MessageIn &msg, bool look2) dstBeing->setSpriteColor(SPRITE_HAIR, ColorDB::getHairColor(id)); break; + case 7: // Clothes color + // ignoring it + break; case 8: // eAthena LOOK_SHIELD if (!config.getBoolValue("hideShield")) { -- cgit v1.2.3-70-g09d2 From b8cdabbd20690d57930dce9dda949fca21a6233a Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Thu, 1 Sep 2011 20:04:35 +0300 Subject: Eliminate asserts from most files. --- src/actorsprite.cpp | 4 ---- src/animatedsprite.cpp | 4 ---- src/being.cpp | 1 - src/client.cpp | 2 -- src/graphics.cpp | 2 -- src/gui/charselectdialog.cpp | 5 ++--- src/gui/popupmenu.cpp | 2 -- src/gui/quitdialog.cpp | 15 +++++---------- src/gui/widgets/layout.cpp | 7 +++++-- src/gui/widgets/window.cpp | 3 ++- src/joystick.cpp | 5 ++--- src/localplayer.cpp | 2 -- src/net/manaserv/messagehandler.cpp | 2 -- src/net/tmwa/generalhandler.cpp | 1 - src/particlecontainer.cpp | 2 -- src/resources/imageloader.cpp | 4 ---- src/resources/itemdb.cpp | 14 +++++++------- src/resources/mapreader.cpp | 6 +++--- src/resources/resource.cpp | 2 -- 19 files changed, 26 insertions(+), 57 deletions(-) (limited to 'src/net') diff --git a/src/actorsprite.cpp b/src/actorsprite.cpp index 848e84e0f..2b133eca5 100644 --- a/src/actorsprite.cpp +++ b/src/actorsprite.cpp @@ -477,9 +477,6 @@ void ActorSprite::loadTargetCursor(const std::string &filename, if (size < TC_SMALL || size >= NUM_TC) return; -// assert(size > -1); -// assert(size < 3); - ResourceManager *resman = ResourceManager::getInstance(); ImageSet *currentImageSet = resman->getImageSet(filename, width, height); @@ -493,7 +490,6 @@ void ActorSprite::loadTargetCursor(const std::string &filename, for (unsigned int i = 0; i < currentImageSet->size(); ++i) { -// anim->addFrame(currentImageSet->get(i), 0, anim->addFrame(currentImageSet->get(i), 75, (16 - (currentImageSet->getWidth() / 2)), (16 - (currentImageSet->getHeight() / 2)), diff --git a/src/animatedsprite.cpp b/src/animatedsprite.cpp index 7414c94bc..27be02e36 100644 --- a/src/animatedsprite.cpp +++ b/src/animatedsprite.cpp @@ -32,8 +32,6 @@ #include "utils/xml.h" -#include - #include "debug.h" AnimatedSprite::AnimatedSprite(SpriteDef *sprite): @@ -46,8 +44,6 @@ AnimatedSprite::AnimatedSprite(SpriteDef *sprite): mAnimation(0), mFrame(0) { -// assert(mSprite); - mAlpha = 1.0f; // Take possession of the sprite diff --git a/src/being.cpp b/src/being.cpp index 2d9194c6e..6d35f1df0 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -79,7 +79,6 @@ #include "utils/stringutils.h" #include "utils/xml.h" -#include #include #include "debug.h" diff --git a/src/client.cpp b/src/client.cpp index 843f7c961..ab176c00b 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -114,7 +114,6 @@ #endif #include -#include #include #include @@ -260,7 +259,6 @@ Client::Client(const Options &options): mMouseFocused(true), mGuiAlpha(1.0f) { - assert(!mInstance); mInstance = this; logger = new Logger; diff --git a/src/graphics.cpp b/src/graphics.cpp index c5dc38b72..abd7341e2 100644 --- a/src/graphics.cpp +++ b/src/graphics.cpp @@ -20,8 +20,6 @@ * along with this program. If not, see . */ -#include - #include "graphics.h" #include "graphicsvertexes.h" diff --git a/src/gui/charselectdialog.cpp b/src/gui/charselectdialog.cpp index 28c7a083c..1942ebaeb 100644 --- a/src/gui/charselectdialog.cpp +++ b/src/gui/charselectdialog.cpp @@ -60,7 +60,6 @@ #include #include -#include #include "debug.h" @@ -342,8 +341,8 @@ void CharSelectDialog::setCharacters(const Net::Characters &characters) void CharSelectDialog::lock() { - assert(!mLocked); - setLocked(true); + if (!mLocked) + setLocked(true); } void CharSelectDialog::unlock() diff --git a/src/gui/popupmenu.cpp b/src/gui/popupmenu.cpp index 6db4a408f..0eac0a4f9 100644 --- a/src/gui/popupmenu.cpp +++ b/src/gui/popupmenu.cpp @@ -78,8 +78,6 @@ #include "utils/gettext.h" #include "utils/stringutils.h" -#include - #include "debug.h" std::string tradePartnerName(""); diff --git a/src/gui/quitdialog.cpp b/src/gui/quitdialog.cpp index f66872b5d..04f43fb88 100644 --- a/src/gui/quitdialog.cpp +++ b/src/gui/quitdialog.cpp @@ -41,23 +41,17 @@ #include "utils/gettext.h" -#include - #include "debug.h" QuitDialog::QuitDialog(QuitDialog** pointerToMe): Window(_("Quit"), true, NULL), mMyPointer(pointerToMe) { -// int width = 200; -// int height = 120; - mForceQuit = new RadioButton(_("Quit"), "quitdialog"); mLogoutQuit = new RadioButton(_("Quit"), "quitdialog"); mSwitchAccountServer = new RadioButton(_("Switch server"), "quitdialog"); mSwitchCharacter = new RadioButton(_("Switch character"), "quitdialog"); mOkButton = new Button(_("OK"), "ok", this); mCancelButton = new Button(_("Cancel"), "cancel", this); -// setContentSize(width, height); addKeyListener(this); @@ -149,10 +143,11 @@ void QuitDialog::action(const gcn::ActionEvent &event) } else if (mSwitchCharacter->isSelected()) { - assert(Client::getState() == STATE_GAME); - - Net::getCharHandler()->switchCharacter(); - Client::closeDialogs(); + if (Client::getState() == STATE_GAME) + { + Net::getCharHandler()->switchCharacter(); + Client::closeDialogs(); + } } } scheduleDelete(); diff --git a/src/gui/widgets/layout.cpp b/src/gui/widgets/layout.cpp index 382d169dc..a14b416ce 100644 --- a/src/gui/widgets/layout.cpp +++ b/src/gui/widgets/layout.cpp @@ -68,7 +68,9 @@ LayoutArray &LayoutCell::getArray() void LayoutCell::reflow(int nx, int ny, int nw, int nh) { - assert(mType != NONE); + if (mType == NONE) + return; + nx += mHPadding; ny += mVPadding; nw -= 2 * mHPadding; @@ -81,7 +83,8 @@ void LayoutCell::reflow(int nx, int ny, int nw, int nh) void LayoutCell::computeSizes() { - assert(mType == ARRAY); + if (mType != ARRAY) + return; std::vector< std::vector< LayoutCell * > >::iterator i = mArray->mCells.begin(); diff --git a/src/gui/widgets/window.cpp b/src/gui/widgets/window.cpp index 7508d4e4b..0a3779307 100644 --- a/src/gui/widgets/window.cpp +++ b/src/gui/widgets/window.cpp @@ -663,7 +663,8 @@ void Window::setModal(bool modal) void Window::loadWindowState() { const std::string &name = mWindowName; - assert(!name.empty()); + if (name.empty()) + return; setPosition(config.getValueInt(name + "WinX", mDefaultX), config.getValueInt(name + "WinY", mDefaultY)); diff --git a/src/joystick.cpp b/src/joystick.cpp index 8f808a2d1..f45729351 100644 --- a/src/joystick.cpp +++ b/src/joystick.cpp @@ -24,8 +24,6 @@ #include "joystick.h" #include "logger.h" -#include - #include "debug.h" int Joystick::joystickCount = 0; @@ -48,7 +46,8 @@ Joystick::Joystick(int no): mCalibrating(false), mEnabled(false) { - assert(no < joystickCount); + if (no >= joystickCount) + no = joystickCount; mJoystick = SDL_JoystickOpen(no); diff --git a/src/localplayer.cpp b/src/localplayer.cpp index 5192390bc..e9386a5ee 100644 --- a/src/localplayer.cpp +++ b/src/localplayer.cpp @@ -78,8 +78,6 @@ #include "utils/gettext.h" #include "utils/stringutils.h" -#include - #include "mumblemanager.h" #include "debug.h" diff --git a/src/net/manaserv/messagehandler.cpp b/src/net/manaserv/messagehandler.cpp index 7524c95e8..2e9603f19 100644 --- a/src/net/manaserv/messagehandler.cpp +++ b/src/net/manaserv/messagehandler.cpp @@ -24,8 +24,6 @@ #include "net/manaserv/network.h" -#include - namespace ManaServ { diff --git a/src/net/tmwa/generalhandler.cpp b/src/net/tmwa/generalhandler.cpp index 746cb6620..5ebeb5da9 100644 --- a/src/net/tmwa/generalhandler.cpp +++ b/src/net/tmwa/generalhandler.cpp @@ -67,7 +67,6 @@ #include "utils/gettext.h" -#include #include #include "debug.h" diff --git a/src/particlecontainer.cpp b/src/particlecontainer.cpp index d00c68a63..70b1e2c84 100644 --- a/src/particlecontainer.cpp +++ b/src/particlecontainer.cpp @@ -20,8 +20,6 @@ * along with this program. If not, see . */ -#include - #include "particle.h" #include "particlecontainer.h" diff --git a/src/resources/imageloader.cpp b/src/resources/imageloader.cpp index c63d33c00..72a839573 100644 --- a/src/resources/imageloader.cpp +++ b/src/resources/imageloader.cpp @@ -29,8 +29,6 @@ #include -#include - #include "debug.h" #ifdef free @@ -79,12 +77,10 @@ int ProxyImage::getHeight() const return mImage->mBounds.h; else return 0; -// return mSDLImage ? mSDLImage->h : mImage->getHeight(); } gcn::Color ProxyImage::getPixel(int x, int y) { - assert(mSDLImage); return gcn::SDLgetPixel(mSDLImage, x, y); } diff --git a/src/resources/itemdb.cpp b/src/resources/itemdb.cpp index 394aa74be..733c12958 100644 --- a/src/resources/itemdb.cpp +++ b/src/resources/itemdb.cpp @@ -36,8 +36,6 @@ #include -#include - #include "debug.h" namespace @@ -435,7 +433,8 @@ void ItemDB::unload() bool ItemDB::exists(int id) { - assert(mLoaded); + if (!mLoaded) + return false; ItemInfos::const_iterator i = mItemInfos.find(id); @@ -444,7 +443,8 @@ bool ItemDB::exists(int id) const ItemInfo &ItemDB::get(int id) { - assert(mLoaded); + if (!mLoaded) + load(); ItemInfos::const_iterator i = mItemInfos.find(id); @@ -459,7 +459,8 @@ const ItemInfo &ItemDB::get(int id) const ItemInfo &ItemDB::get(const std::string &name) { - assert(mLoaded); + if (!mLoaded) + load(); NamedItemInfos::const_iterator i = mNamedItemInfos.find(normalize(name)); @@ -597,7 +598,7 @@ void loadSoundRef(ItemInfo *itemInfo, xmlNodePtr node) else { logger->log("ItemDB: Ignoring unknown sound event '%s'", - event.c_str()); + event.c_str()); } } @@ -656,7 +657,6 @@ void loadReplaceSprite(ItemInfo *itemInfo, xmlNodePtr replaceNode) } case -2: { - logger->log("parse -2"); for_each_xml_child_node(itemNode, replaceNode) { if (xmlStrEqual(itemNode->name, BAD_CAST "item")) diff --git a/src/resources/mapreader.cpp b/src/resources/mapreader.cpp index 70c45054f..685d415ff 100644 --- a/src/resources/mapreader.cpp +++ b/src/resources/mapreader.cpp @@ -37,7 +37,6 @@ #include "utils/stringutils.h" #include "utils/xml.h" -#include #include #include @@ -110,7 +109,8 @@ int inflateMemory(unsigned char *in, unsigned int inLength, } ret = inflate(&strm, Z_NO_FLUSH); - assert(ret != Z_STREAM_ERROR); + if (ret == Z_STREAM_ERROR) + return ret; switch (ret) { @@ -140,7 +140,7 @@ int inflateMemory(unsigned char *in, unsigned int inLength, } } while (ret != Z_STREAM_END); - assert(strm.avail_in == 0); +// assert(strm.avail_in == 0); outLength = bufferSize - strm.avail_out; (void) inflateEnd(&strm); diff --git a/src/resources/resource.cpp b/src/resources/resource.cpp index b180712c1..552af06ec 100644 --- a/src/resources/resource.cpp +++ b/src/resources/resource.cpp @@ -27,8 +27,6 @@ #include "resources/resourcemanager.h" -#include - #include "debug.h" Resource::~Resource() -- cgit v1.2.3-70-g09d2 From a4c4a2c804f34b64aefce1847ba837a41b849fea Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Thu, 1 Sep 2011 22:26:09 +0300 Subject: Remove party name from players if leave party. --- src/net/ea/partyhandler.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/net') diff --git a/src/net/ea/partyhandler.cpp b/src/net/ea/partyhandler.cpp index 045a2332b..bd6f19d97 100644 --- a/src/net/ea/partyhandler.cpp +++ b/src/net/ea/partyhandler.cpp @@ -359,6 +359,7 @@ void PartyHandler::processPartyLeave(Net::MessageIn &msg) if (socialWindow && Ea::taParty) socialWindow->removeTab(Ea::taParty); + player_node->setPartyName(""); } else { @@ -372,7 +373,10 @@ void PartyHandler::processPartyLeave(Net::MessageIn &msg) { Being *b = actorSpriteManager->findBeing(id); if (b && b->getType() == Being::PLAYER) + { b->setParty(0); + b->setPartyName(""); + } } if (Ea::taParty) Ea::taParty->removeMember(id); -- cgit v1.2.3-70-g09d2 From b17d7d87918b76323e08c0a5c09abd8fa1f3ed71 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Fri, 2 Sep 2011 15:45:57 +0300 Subject: Add to status window attribute "damage per second". --- src/net/ea/playerhandler.cpp | 14 ++++++++++++-- src/net/ea/playerhandler.h | 2 ++ src/net/manaserv/playerhandler.cpp | 5 +++++ src/net/manaserv/playerhandler.h | 1 + src/net/playerhandler.h | 2 ++ src/net/tmwa/generalhandler.cpp | 4 +++- src/playerinfo.cpp | 20 ++++++++++++++++++++ src/playerinfo.h | 7 +++++-- 8 files changed, 50 insertions(+), 5 deletions(-) (limited to 'src/net') diff --git a/src/net/ea/playerhandler.cpp b/src/net/ea/playerhandler.cpp index 4198c14ad..3af237b5b 100644 --- a/src/net/ea/playerhandler.cpp +++ b/src/net/ea/playerhandler.cpp @@ -359,9 +359,11 @@ void PlayerHandler::processPlayerStatUpdate1(Net::MessageIn &msg) case 0x0029: PlayerInfo::setStatBase(EA_ATK, value); + PlayerInfo::updateAttrs(); break; case 0x002a: PlayerInfo::setStatMod(EA_ATK, value); + PlayerInfo::updateAttrs(); break; case 0x002b: @@ -402,8 +404,9 @@ void PlayerHandler::processPlayerStatUpdate1(Net::MessageIn &msg) case 0x0035: player_node->setAttackSpeed(value); - PlayerInfo::setStatBase(ATTACK_SPEED, value); - PlayerInfo::setStatMod(ATTACK_SPEED, 0); + PlayerInfo::setStatBase(ATTACK_DELAY, value); + PlayerInfo::setStatMod(ATTACK_DELAY, 0); + PlayerInfo::updateAttrs(); break; case 0x0037: @@ -484,6 +487,8 @@ void PlayerHandler::processPlayerStatUpdate3(Net::MessageIn &msg) PlayerInfo::setStatBase(type, base, false); PlayerInfo::setStatMod(type, bonus); + if (type == EA_ATK || type == ATTACK_DELAY) + PlayerInfo::updateAttrs(); } void PlayerHandler::processPlayerStatUpdate4(Net::MessageIn &msg) @@ -552,6 +557,7 @@ void PlayerHandler::processPlayerStatUpdate5(Net::MessageIn &msg) PlayerInfo::setStatBase(EA_ATK, msg.readInt16(), false); PlayerInfo::setStatMod(EA_ATK, msg.readInt16()); + PlayerInfo::updateAttrs(); val = msg.readInt16(); PlayerInfo::setStatBase(EA_MATK, val, false); @@ -636,4 +642,8 @@ int PlayerHandler::getJobLocation() const return EA_JOB; } +int PlayerHandler::getAttackLocation() const +{ + return EA_ATK; +} } // namespace Ea diff --git a/src/net/ea/playerhandler.h b/src/net/ea/playerhandler.h index 8b8751630..57bcbdcd5 100644 --- a/src/net/ea/playerhandler.h +++ b/src/net/ea/playerhandler.h @@ -55,6 +55,8 @@ class PlayerHandler : public Net::PlayerHandler int getJobLocation() const; + int getAttackLocation() const; + void processWalkResponse(Net::MessageIn &msg); void processPlayerWarp(Net::MessageIn &msg); diff --git a/src/net/manaserv/playerhandler.cpp b/src/net/manaserv/playerhandler.cpp index 3dfddb436..da8958044 100644 --- a/src/net/manaserv/playerhandler.cpp +++ b/src/net/manaserv/playerhandler.cpp @@ -432,6 +432,11 @@ int PlayerHandler::getJobLocation() const return -1; } +int PlayerHandler::getAttackLocation() const +{ + return -1; +} + Vector PlayerHandler::getDefaultWalkSpeed() const { // Return translation in pixels per ticks. diff --git a/src/net/manaserv/playerhandler.h b/src/net/manaserv/playerhandler.h index dcd05d5fc..f00fea42a 100644 --- a/src/net/manaserv/playerhandler.h +++ b/src/net/manaserv/playerhandler.h @@ -74,6 +74,7 @@ class PlayerHandler : public MessageHandler, public Net::PlayerHandler bool canCorrectAttributes() const; int getJobLocation() const; + int getAttackLocation() const; Vector getDefaultWalkSpeed() const; diff --git a/src/net/playerhandler.h b/src/net/playerhandler.h index 2abd12d57..47d666036 100644 --- a/src/net/playerhandler.h +++ b/src/net/playerhandler.h @@ -68,6 +68,8 @@ class PlayerHandler virtual int getJobLocation() const = 0; + virtual int getAttackLocation() const = 0; + virtual Vector getDefaultWalkSpeed() const = 0; }; diff --git a/src/net/tmwa/generalhandler.cpp b/src/net/tmwa/generalhandler.cpp index 5ebeb5da9..e1b565399 100644 --- a/src/net/tmwa/generalhandler.cpp +++ b/src/net/tmwa/generalhandler.cpp @@ -272,12 +272,14 @@ void GeneralHandler::event(Mana::Channels channel, statusWindow->addAttribute(FLEE, _("% Evade"), false, ""); // xgettext:no-c-format statusWindow->addAttribute(CRIT, _("% Critical"), false, ""); - statusWindow->addAttribute(ATTACK_SPEED, _("Attack Delay"), + statusWindow->addAttribute(ATTACK_DELAY, _("Attack Delay"), false, ""); statusWindow->addAttribute(WALK_SPEED, _("Walk Delay"), false, ""); statusWindow->addAttribute(ATTACK_RANGE, _("Attack Range"), false, ""); + statusWindow->addAttribute(ATTACK_SPEED, _("Damage per sec."), + false, ""); } else if (event.getName() == Mana::EVENT_GUIWINDOWSUNLOADING) { diff --git a/src/playerinfo.cpp b/src/playerinfo.cpp index 3bb196921..769d24a16 100644 --- a/src/playerinfo.cpp +++ b/src/playerinfo.cpp @@ -31,6 +31,9 @@ #include "resources/itemdb.h" #include "resources/iteminfo.h" +#include "net/net.h" +#include "net/playerhandler.h" + #include "debug.h" namespace PlayerInfo @@ -280,6 +283,23 @@ void setTrading(bool trading) } } +void updateAttrs() +{ + int attr = Net::getPlayerHandler()->getAttackLocation(); + if (attr != -1 && getStatBase(ATTACK_DELAY)) + { + setStatBase(ATTACK_SPEED, getStatBase(attr) * 1000 / getStatBase( + ATTACK_DELAY), false); + setStatMod(ATTACK_SPEED, getStatMod(attr) * 1000 / getStatBase( + ATTACK_DELAY), true); + } + else + { + setStatBase(ATTACK_SPEED, 0, false); + setStatMod(ATTACK_SPEED, 0, true); + } +} + class PlayerInfoListener : Mana::Listener { public: diff --git a/src/playerinfo.h b/src/playerinfo.h index 401dd26e0..b90e47ce9 100644 --- a/src/playerinfo.h +++ b/src/playerinfo.h @@ -45,9 +45,10 @@ enum Attribute SKILL_POINTS, CHAR_POINTS, CORR_POINTS, - ATTACK_SPEED = 100, + ATTACK_DELAY = 100, ATTACK_RANGE = 101, - WALK_SPEED = 102 + WALK_SPEED = 102, + ATTACK_SPEED = 103 }; /** @@ -218,6 +219,8 @@ namespace PlayerInfo */ void setTrading(bool trading); + void updateAttrs(); + /** * Initializes some internals. */ -- cgit v1.2.3-70-g09d2 From 8e3c48f9ed3dfe6dc2665f8b867e637cfc4d32ee Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Fri, 2 Sep 2011 21:11:16 +0300 Subject: Fix compilation with different flags. --- src/compoundsprite.cpp | 4 ++++ src/net/manaserv/adminhandler.cpp | 3 ++- src/net/manaserv/adminhandler.h | 1 + 3 files changed, 7 insertions(+), 1 deletion(-) (limited to 'src/net') diff --git a/src/compoundsprite.cpp b/src/compoundsprite.cpp index 99fae4f88..c6921b2e8 100644 --- a/src/compoundsprite.cpp +++ b/src/compoundsprite.cpp @@ -410,7 +410,11 @@ void CompoundSprite::setAlpha(float alpha) { if (alpha != mAlpha) { +#ifdef USE_OPENGL if (mEnableAlphaFix && Image::mUseOpenGL == 0 && size() > 3) +#else + if (mEnableAlphaFix && size() > 3) +#endif { SpriteConstIterator it, it_end; for (it = begin(), it_end = end(); it != it_end; ++ it) diff --git a/src/net/manaserv/adminhandler.cpp b/src/net/manaserv/adminhandler.cpp index 2c76e99a3..a8860d73b 100644 --- a/src/net/manaserv/adminhandler.cpp +++ b/src/net/manaserv/adminhandler.cpp @@ -91,7 +91,8 @@ void AdminHandler::mute(int playerId A_UNUSED, int type A_UNUSED, // TODO } -void AdminHandler::warp(std::string map, int x, int y) +void AdminHandler::warp(std::string map A_UNUSED, + int x A_UNUSED, int y A_UNUSED) { // TODO } diff --git a/src/net/manaserv/adminhandler.h b/src/net/manaserv/adminhandler.h index 65e9ea2b0..17d296bd6 100644 --- a/src/net/manaserv/adminhandler.h +++ b/src/net/manaserv/adminhandler.h @@ -24,6 +24,7 @@ #define NET_MANASERV_ADMINHANDLER_H #include "net/adminhandler.h" +#include "string" #ifdef __GNUC__ #define A_UNUSED __attribute__ ((unused)) -- cgit v1.2.3-70-g09d2