From: <rly...@us...> - 2010-12-26 17:20:44
|
Revision: 6620 http://planeshift.svn.sourceforge.net/planeshift/?rev=6620&view=rev Author: rlydontknow Date: 2010-12-26 17:20:35 +0000 (Sun, 26 Dec 2010) Log Message: ----------- refactored msghandler - patch by mikesflowers with the following modifications: - replaced recursive mutex in msghandler with a read-write-mutex - removed the need for NetMessageCallback completely and instead managed it in MessageManager Modified Paths: -------------- trunk/src/client/gui/pawsactivemagicwindow.cpp trunk/src/client/gui/pawsbankwindow.cpp trunk/src/client/gui/pawsbookreadingwindow.cpp trunk/src/client/gui/pawschardescription.cpp trunk/src/client/gui/pawscontainerdescwindow.cpp trunk/src/client/gui/pawscraft.cpp trunk/src/client/gui/pawsexchangewindow.cpp trunk/src/client/gui/pawsglyphwindow.cpp trunk/src/client/gui/pawsgroupwindow.cpp trunk/src/client/gui/pawsguildwindow.cpp trunk/src/client/gui/pawsinfowindow.cpp trunk/src/client/gui/pawsinteractwindow.cpp trunk/src/client/gui/pawsitemdescriptionwindow.cpp trunk/src/client/gui/pawsloading.cpp trunk/src/client/gui/pawsmerchantwindow.cpp trunk/src/client/gui/pawspetstatwindow.cpp trunk/src/client/gui/pawsskillwindow.cpp trunk/src/client/gui/pawsspellbookwindow.cpp trunk/src/client/gui/pawsstoragewindow.cpp trunk/src/client/psclientchar.cpp trunk/src/common/net/msghandler.cpp trunk/src/common/net/msghandler.h trunk/src/common/net/subscriber.h trunk/src/server/actionmanager.cpp trunk/src/server/actionmanager.h trunk/src/server/adminmanager.cpp trunk/src/server/adminmanager.h trunk/src/server/advicemanager.cpp trunk/src/server/advicemanager.h trunk/src/server/authentserver.cpp trunk/src/server/authentserver.h trunk/src/server/bankmanager.cpp trunk/src/server/bankmanager.h trunk/src/server/chatmanager.cpp trunk/src/server/chatmanager.h trunk/src/server/combatmanager.cpp trunk/src/server/combatmanager.h trunk/src/server/creationmanager.cpp trunk/src/server/creationmanager.h trunk/src/server/economymanager.cpp trunk/src/server/economymanager.h trunk/src/server/entitymanager.cpp trunk/src/server/entitymanager.h trunk/src/server/exchangemanager.cpp trunk/src/server/exchangemanager.h trunk/src/server/gem.cpp trunk/src/server/gem.h trunk/src/server/gmeventmanager.cpp trunk/src/server/gmeventmanager.h trunk/src/server/groupmanager.cpp trunk/src/server/groupmanager.h trunk/src/server/guildmanager.cpp trunk/src/server/guildmanager.h trunk/src/server/introductionmanager.cpp trunk/src/server/introductionmanager.h trunk/src/server/minigamemanager.cpp trunk/src/server/minigamemanager.h trunk/src/server/msgmanager.cpp trunk/src/server/msgmanager.h trunk/src/server/npcmanager.cpp trunk/src/server/npcmanager.h trunk/src/server/progressionmanager.cpp trunk/src/server/progressionmanager.h trunk/src/server/psserverchar.cpp trunk/src/server/psserverchar.h trunk/src/server/psserverdr.cpp trunk/src/server/psserverdr.h trunk/src/server/questionmanager.cpp trunk/src/server/questionmanager.h trunk/src/server/questmanager.cpp trunk/src/server/questmanager.h trunk/src/server/slotmanager.cpp trunk/src/server/slotmanager.h trunk/src/server/spawnmanager.cpp trunk/src/server/spawnmanager.h trunk/src/server/spellmanager.cpp trunk/src/server/spellmanager.h trunk/src/server/tutorialmanager.cpp trunk/src/server/tutorialmanager.h trunk/src/server/usermanager.cpp trunk/src/server/usermanager.h trunk/src/server/workmanager.cpp trunk/src/server/workmanager.h Modified: trunk/src/client/gui/pawsactivemagicwindow.cpp =================================================================== --- trunk/src/client/gui/pawsactivemagicwindow.cpp 2010-12-26 15:53:17 UTC (rev 6619) +++ trunk/src/client/gui/pawsactivemagicwindow.cpp 2010-12-26 17:20:35 UTC (rev 6620) @@ -59,8 +59,7 @@ if(!LoadSetting()) return false; - if (!psengine->GetMsgHandler()->Subscribe(this, MSGTYPE_ACTIVEMAGIC)) - return false; + psengine->GetMsgHandler()->Subscribe(this, MSGTYPE_ACTIVEMAGIC); // do something here.... return true; Modified: trunk/src/client/gui/pawsbankwindow.cpp =================================================================== --- trunk/src/client/gui/pawsbankwindow.cpp 2010-12-26 15:53:17 UTC (rev 6619) +++ trunk/src/client/gui/pawsbankwindow.cpp 2010-12-26 17:20:35 UTC (rev 6620) @@ -48,8 +48,7 @@ bool pawsBankWindow::PostSetup() { - if (!psengine->GetMsgHandler()->Subscribe(this, MSGTYPE_BANKING)) - return false; + psengine->GetMsgHandler()->Subscribe(this, MSGTYPE_BANKING); Money = (pawsButton*)(FindWidget("MoneyButton")); if(!Money) Modified: trunk/src/client/gui/pawsbookreadingwindow.cpp =================================================================== --- trunk/src/client/gui/pawsbookreadingwindow.cpp 2010-12-26 15:53:17 UTC (rev 6619) +++ trunk/src/client/gui/pawsbookreadingwindow.cpp 2010-12-26 17:20:35 UTC (rev 6620) @@ -45,8 +45,8 @@ bool pawsBookReadingWindow::PostSetup() { - if (!psengine->GetMsgHandler()->Subscribe(this, MSGTYPE_READ_BOOK)) return false; - if (!psengine->GetMsgHandler()->Subscribe(this, MSGTYPE_CRAFT_INFO)) return false; + psengine->GetMsgHandler()->Subscribe(this, MSGTYPE_READ_BOOK); + psengine->GetMsgHandler()->Subscribe(this, MSGTYPE_CRAFT_INFO); // Store some of our children for easy access later on. name = dynamic_cast<pawsTextBox*> (FindWidget("ItemName")); Modified: trunk/src/client/gui/pawschardescription.cpp =================================================================== --- trunk/src/client/gui/pawschardescription.cpp 2010-12-26 15:53:17 UTC (rev 6619) +++ trunk/src/client/gui/pawschardescription.cpp 2010-12-26 17:20:35 UTC (rev 6620) @@ -71,11 +71,7 @@ void pawsCharDescription::RequestDetails() { - if ( !psengine->GetMsgHandler()->Subscribe( this, MSGTYPE_CHARACTERDETAILS ) ) - { - printf("Couldn't subscribe to MSGTYPE_CHARACTERDETAILS (pawsCharDescription)"); - return; - } + psengine->GetMsgHandler()->Subscribe(this, MSGTYPE_CHARACTERDETAILS); psCharacterDetailsRequestMessage requestMsg(true, true, "pawsCharDescription"); requestMsg.SendMessage(); Modified: trunk/src/client/gui/pawscontainerdescwindow.cpp =================================================================== --- trunk/src/client/gui/pawscontainerdescwindow.cpp 2010-12-26 15:53:17 UTC (rev 6619) +++ trunk/src/client/gui/pawscontainerdescwindow.cpp 2010-12-26 17:20:35 UTC (rev 6620) @@ -65,10 +65,8 @@ bool pawsContainerDescWindow::PostSetup() { - if (!psengine->GetMsgHandler()->Subscribe(this, MSGTYPE_VIEW_CONTAINER)) - return false; - if (!psengine->GetMsgHandler()->Subscribe(this, MSGTYPE_UPDATE_ITEM)) - return false; + psengine->GetMsgHandler()->Subscribe(this, MSGTYPE_VIEW_CONTAINER); + psengine->GetMsgHandler()->Subscribe(this, MSGTYPE_UPDATE_ITEM); // Store some of our children for easy access later on. name = (pawsTextBox*)FindWidget("ItemName"); Modified: trunk/src/client/gui/pawscraft.cpp =================================================================== --- trunk/src/client/gui/pawscraft.cpp 2010-12-26 15:53:17 UTC (rev 6619) +++ trunk/src/client/gui/pawscraft.cpp 2010-12-26 17:20:35 UTC (rev 6620) @@ -31,7 +31,8 @@ bool pawsCraftWindow::PostSetup() { - return psengine->GetMsgHandler()->Subscribe(this, MSGTYPE_CRAFT_INFO); + psengine->GetMsgHandler()->Subscribe(this, MSGTYPE_CRAFT_INFO); + return true; } void pawsCraftWindow::Show() Modified: trunk/src/client/gui/pawsexchangewindow.cpp =================================================================== --- trunk/src/client/gui/pawsexchangewindow.cpp 2010-12-26 15:53:17 UTC (rev 6619) +++ trunk/src/client/gui/pawsexchangewindow.cpp 2010-12-26 17:20:35 UTC (rev 6620) @@ -76,14 +76,14 @@ { csString slotName; - if (!psengine->GetMsgHandler()->Subscribe(this, MSGTYPE_GUIEXCHANGE)) return false; - if (!psengine->GetMsgHandler()->Subscribe(this, MSGTYPE_EXCHANGE_REQUEST)) return false; - if (!psengine->GetMsgHandler()->Subscribe(this, MSGTYPE_EXCHANGE_ADD_ITEM)) return false; - if (!psengine->GetMsgHandler()->Subscribe(this, MSGTYPE_EXCHANGE_REMOVE_ITEM)) return false; - if (!psengine->GetMsgHandler()->Subscribe(this, MSGTYPE_EXCHANGE_ACCEPT)) return false; - if (!psengine->GetMsgHandler()->Subscribe(this, MSGTYPE_EXCHANGE_END)) return false; - if (!psengine->GetMsgHandler()->Subscribe(this, MSGTYPE_EXCHANGE_STATUS)) return false; - if (!psengine->GetMsgHandler()->Subscribe(this, MSGTYPE_EXCHANGE_MONEY)) return false; + psengine->GetMsgHandler()->Subscribe(this, MSGTYPE_GUIEXCHANGE); + psengine->GetMsgHandler()->Subscribe(this, MSGTYPE_EXCHANGE_REQUEST); + psengine->GetMsgHandler()->Subscribe(this, MSGTYPE_EXCHANGE_ADD_ITEM); + psengine->GetMsgHandler()->Subscribe(this, MSGTYPE_EXCHANGE_REMOVE_ITEM); + psengine->GetMsgHandler()->Subscribe(this, MSGTYPE_EXCHANGE_ACCEPT); + psengine->GetMsgHandler()->Subscribe(this, MSGTYPE_EXCHANGE_END); + psengine->GetMsgHandler()->Subscribe(this, MSGTYPE_EXCHANGE_STATUS); + psengine->GetMsgHandler()->Subscribe(this, MSGTYPE_EXCHANGE_MONEY); // the two backgrounds for the offering/receiving frame offeringBG = FindWidget("Offering Frame"); Modified: trunk/src/client/gui/pawsglyphwindow.cpp =================================================================== --- trunk/src/client/gui/pawsglyphwindow.cpp 2010-12-26 15:53:17 UTC (rev 6619) +++ trunk/src/client/gui/pawsglyphwindow.cpp 2010-12-26 17:20:35 UTC (rev 6620) @@ -94,9 +94,9 @@ bool pawsGlyphWindow::PostSetup() { // Subscribe our message types that we are interested in. - if (!psengine->GetMsgHandler()->Subscribe(this, MSGTYPE_GLYPH_REQUEST)) return false; - if (!psengine->GetMsgHandler()->Subscribe(this, MSGTYPE_GLYPH_ASSEMBLE)) return false; - + psengine->GetMsgHandler()->Subscribe(this, MSGTYPE_GLYPH_REQUEST); + psengine->GetMsgHandler()->Subscribe(this, MSGTYPE_GLYPH_ASSEMBLE); + description = dynamic_cast <pawsMessageTextBox*> (FindWidget("SpellDescription")); if ( !description ) return false; Modified: trunk/src/client/gui/pawsgroupwindow.cpp =================================================================== --- trunk/src/client/gui/pawsgroupwindow.cpp 2010-12-26 15:53:17 UTC (rev 6619) +++ trunk/src/client/gui/pawsgroupwindow.cpp 2010-12-26 17:20:35 UTC (rev 6620) @@ -61,8 +61,7 @@ bool pawsGroupWindow::PostSetup() { - if (!psengine->GetMsgHandler()->Subscribe(this, MSGTYPE_GUIGROUP)) - return false; + psengine->GetMsgHandler()->Subscribe(this, MSGTYPE_GUIGROUP); memberList = (pawsListBox*)FindWidget("List"); if ( !memberList ) return false; Modified: trunk/src/client/gui/pawsguildwindow.cpp =================================================================== --- trunk/src/client/gui/pawsguildwindow.cpp 2010-12-26 15:53:17 UTC (rev 6619) +++ trunk/src/client/gui/pawsguildwindow.cpp 2010-12-26 17:20:35 UTC (rev 6620) @@ -169,11 +169,8 @@ bool pawsGuildWindow::PostSetup() { - if (!psengine->GetMsgHandler()->Subscribe(this, MSGTYPE_GUIGUILD)) - return false; - - if (!psengine->GetMsgHandler()->Subscribe(this, MSGTYPE_MOTD)) - return false; + psengine->GetMsgHandler()->Subscribe(this, MSGTYPE_GUIGUILD); + psengine->GetMsgHandler()->Subscribe(this, MSGTYPE_MOTD); //Request a MOTD for the guild psMOTDRequestMessage motdReq; motdReq.SendMessage(); Modified: trunk/src/client/gui/pawsinfowindow.cpp =================================================================== --- trunk/src/client/gui/pawsinfowindow.cpp 2010-12-26 15:53:17 UTC (rev 6619) +++ trunk/src/client/gui/pawsinfowindow.cpp 2010-12-26 17:20:35 UTC (rev 6620) @@ -69,8 +69,7 @@ { pawsControlledWindow::PostSetup(); - if (!psengine->GetMsgHandler()->Subscribe(this,MSGTYPE_MODE)) - return false; + psengine->GetMsgHandler()->Subscribe(this,MSGTYPE_MODE); targetName = (pawsTextBox*)FindWidget( "Targeted" ); if ( !targetName ) Modified: trunk/src/client/gui/pawsinteractwindow.cpp =================================================================== --- trunk/src/client/gui/pawsinteractwindow.cpp 2010-12-26 15:53:17 UTC (rev 6619) +++ trunk/src/client/gui/pawsinteractwindow.cpp 2010-12-26 17:20:35 UTC (rev 6620) @@ -158,7 +158,8 @@ bool pawsInteractWindow::PostSetup() { - return psengine->GetMsgHandler()->Subscribe(this, MSGTYPE_GUIINTERACT); + psengine->GetMsgHandler()->Subscribe(this, MSGTYPE_GUIINTERACT); + return true; } void pawsInteractWindow::HandleMessage( MsgEntry* me ) Modified: trunk/src/client/gui/pawsitemdescriptionwindow.cpp =================================================================== --- trunk/src/client/gui/pawsitemdescriptionwindow.cpp 2010-12-26 15:53:17 UTC (rev 6619) +++ trunk/src/client/gui/pawsitemdescriptionwindow.cpp 2010-12-26 17:20:35 UTC (rev 6620) @@ -50,8 +50,7 @@ bool pawsItemDescriptionWindow::PostSetup() { - if (!psengine->GetMsgHandler()->Subscribe(this, MSGTYPE_VIEW_ITEM)) - return false; + psengine->GetMsgHandler()->Subscribe(this, MSGTYPE_VIEW_ITEM); // Store some of our children for easy access later on. Modified: trunk/src/client/gui/pawsloading.cpp =================================================================== --- trunk/src/client/gui/pawsloading.cpp 2010-12-26 15:53:17 UTC (rev 6619) +++ trunk/src/client/gui/pawsloading.cpp 2010-12-26 17:20:35 UTC (rev 6620) @@ -48,10 +48,8 @@ bool pawsLoadWindow::PostSetup() { + psengine->GetMsgHandler()->Subscribe(this,MSGTYPE_MOTD); - if ( !psengine->GetMsgHandler()->Subscribe(this,MSGTYPE_MOTD)) - return false; - loadingText = (pawsMessageTextBox*)FindWidget("loadtext"); if ( !loadingText ) Modified: trunk/src/client/gui/pawsmerchantwindow.cpp =================================================================== --- trunk/src/client/gui/pawsmerchantwindow.cpp 2010-12-26 15:53:17 UTC (rev 6619) +++ trunk/src/client/gui/pawsmerchantwindow.cpp 2010-12-26 17:20:35 UTC (rev 6620) @@ -103,8 +103,7 @@ bool pawsMerchantWindow::PostSetup() { - if (!psengine->GetMsgHandler()->Subscribe(this, MSGTYPE_GUIMERCHANT)) - return false; + psengine->GetMsgHandler()->Subscribe(this, MSGTYPE_GUIMERCHANT); categoryBox = (pawsListBox*)FindWidget("Categories"); itemsBox = (pawsListBox*)FindWidget("Items"); Modified: trunk/src/client/gui/pawspetstatwindow.cpp =================================================================== --- trunk/src/client/gui/pawspetstatwindow.cpp 2010-12-26 15:53:17 UTC (rev 6619) +++ trunk/src/client/gui/pawspetstatwindow.cpp 2010-12-26 17:20:35 UTC (rev 6620) @@ -77,8 +77,7 @@ bool pawsPetStatWindow::PostSetup() { - if (!psengine->GetMsgHandler()->Subscribe(this, MSGTYPE_PET_SKILL)) - return false; + psengine->GetMsgHandler()->Subscribe(this, MSGTYPE_PET_SKILL); xml = csQueryRegistry<iDocumentSystem > ( PawsManager::GetSingleton().GetObjectRegistry()); Modified: trunk/src/client/gui/pawsskillwindow.cpp =================================================================== --- trunk/src/client/gui/pawsskillwindow.cpp 2010-12-26 15:53:17 UTC (rev 6619) +++ trunk/src/client/gui/pawsskillwindow.cpp 2010-12-26 17:20:35 UTC (rev 6620) @@ -90,14 +90,8 @@ { return false; } - if (!psengine->GetMsgHandler()->Subscribe(this, MSGTYPE_GUISKILL)) - { - return false; - } - if (!psengine->GetMsgHandler()->Subscribe(this, MSGTYPE_FACTION_INFO)) - { - return false; - } + psengine->GetMsgHandler()->Subscribe(this, MSGTYPE_GUISKILL); + psengine->GetMsgHandler()->Subscribe(this, MSGTYPE_FACTION_INFO); xml = csQueryRegistry<iDocumentSystem > ( PawsManager::GetSingleton().GetObjectRegistry()); Modified: trunk/src/client/gui/pawsspellbookwindow.cpp =================================================================== --- trunk/src/client/gui/pawsspellbookwindow.cpp 2010-12-26 15:53:17 UTC (rev 6619) +++ trunk/src/client/gui/pawsspellbookwindow.cpp 2010-12-26 17:20:35 UTC (rev 6620) @@ -53,8 +53,7 @@ bool pawsSpellBookWindow::PostSetup() { - if (!psengine->GetMsgHandler()->Subscribe(this, MSGTYPE_SPELL_BOOK)) - return false; + psengine->GetMsgHandler()->Subscribe(this, MSGTYPE_SPELL_BOOK); spellList = (pawsListBox*)FindWidget("SpellList"); spellDescription = (pawsMessageTextBox*)FindWidget("Description"); Modified: trunk/src/client/gui/pawsstoragewindow.cpp =================================================================== --- trunk/src/client/gui/pawsstoragewindow.cpp 2010-12-26 15:53:17 UTC (rev 6619) +++ trunk/src/client/gui/pawsstoragewindow.cpp 2010-12-26 17:20:35 UTC (rev 6620) @@ -102,8 +102,7 @@ bool pawsStorageWindow::PostSetup() { - if (!psengine->GetMsgHandler()->Subscribe(this, MSGTYPE_GUISTORAGE)) - return false; + psengine->GetMsgHandler()->Subscribe(this, MSGTYPE_GUISTORAGE); categoryBox = (pawsListBox*)FindWidget("Categories"); itemsBox = (pawsListBox*)FindWidget("Items"); Modified: trunk/src/client/psclientchar.cpp =================================================================== --- trunk/src/client/psclientchar.cpp 2010-12-26 15:53:17 UTC (rev 6619) +++ trunk/src/client/psclientchar.cpp 2010-12-26 17:20:35 UTC (rev 6620) @@ -205,25 +205,16 @@ msghandler = msgHandler; cel = GEMSupervisor; - if ( !msghandler->Subscribe(this, MSGTYPE_CHARREJECT) ) - return false; - if ( !msghandler->Subscribe(this, MSGTYPE_EQUIPMENT) ) - return false; - if ( !msghandler->Subscribe(this, MSGTYPE_EFFECT) ) - return false; - if ( !msghandler->Subscribe(this, MSGTYPE_EFFECT_STOP) ) - return false; - if ( !msghandler->Subscribe(this, MSGTYPE_PLAYSOUND) ) - return false; - if (!msghandler->Subscribe(this, MSGTYPE_USERACTION) ) - return false; - if (!msghandler->Subscribe(this, MSGTYPE_GUITARGETUPDATE) ) - return false; - if (!msghandler->Subscribe(this, MSGTYPE_CHANGE_TRAIT) ) - return false; + msghandler->Subscribe(this, MSGTYPE_CHARREJECT); + msghandler->Subscribe(this, MSGTYPE_EQUIPMENT); + msghandler->Subscribe(this, MSGTYPE_EFFECT); + msghandler->Subscribe(this, MSGTYPE_EFFECT_STOP); + msghandler->Subscribe(this, MSGTYPE_PLAYSOUND); + msghandler->Subscribe(this, MSGTYPE_USERACTION); + msghandler->Subscribe(this, MSGTYPE_GUITARGETUPDATE); + msghandler->Subscribe(this, MSGTYPE_CHANGE_TRAIT); charCreation = new psCreationManager( objectReg ); - return true; } Modified: trunk/src/common/net/msghandler.cpp =================================================================== --- trunk/src/common/net/msghandler.cpp 2010-12-26 15:53:17 UTC (rev 6619) +++ trunk/src/common/net/msghandler.cpp 2010-12-26 17:20:35 UTC (rev 6620) @@ -54,26 +54,26 @@ void MsgHandler::Publish(MsgEntry* me) { - CS::Threading::RecursiveMutexScopedLock lock(mutex); - + const int mtype = me->GetType(); + bool handled = false; netbase->LogMessages('R',me); - bool handled = false; + csArray<Subscription> handlers; + { + CS::Threading::ScopedReadLock lock(mutex); + handlers = subscribers.GetAll(mtype); + } - int mtype = me->GetType(); - - for ( size_t x = 0; x < subscribers[mtype].GetSize(); x++ ) + for(size_t i = 0; i < handlers.GetSize(); ++i) { + Subscription& sub = handlers[i]; Client *client; me->Reset(); - // Copy the reference so we can modify it in the loop - MsgEntry *message = me; - if (subscribers[mtype][x]->subscriber->Verify(message,subscribers[mtype][x]->flags,client)) + // Copy the reference so we can modify it in the loop + MsgEntry *message = me; + if(sub.subscriber->Verify(message, sub.flags, client)) { - if (subscribers[mtype][x]->callback) - subscribers[mtype][x]->callback->Call(message,client); - else - subscribers[mtype][x]->subscriber->HandleMessage(message,client); + sub.subscriber->HandleMessage(message, client); } handled = true; } @@ -85,73 +85,35 @@ } } -bool MsgHandler::Subscribe(iNetSubscriber *subscriber, msgtype type,uint32_t flags) +void MsgHandler::Subscribe(iNetSubscriber* subscriber, msgtype type, uint32_t flags) { - Subscription* p = new Subscription; + CS_ASSERT(subscriber); - p->subscriber = subscriber; - p->callback = NULL; - p->type = type; - p->flags = flags; - - CS::Threading::RecursiveMutexScopedLock lock(mutex); - if ( IsSubscribed(p) ) - delete p; - else - subscribers[type].Push(p); - - return true; + CS::Threading::ScopedWriteLock lock(mutex); + subscribers.Delete(type, subscriber); + subscribers.Put(type, Subscription(subscriber, flags)); } -bool MsgHandler::Subscribe(iNetSubscriber *subscriber, MsgtypeCallback *callback, msgtype type,uint32_t flags) +bool MsgHandler::Unsubscribe(iNetSubscriber* subscriber, msgtype type) { - Subscription* p = new Subscription; - - p->subscriber = subscriber; - p->callback = callback; - p->type = type; - p->flags = flags; - - CS::Threading::RecursiveMutexScopedLock lock(mutex); - if ( IsSubscribed(p) ) - { - if (p->callback) - delete p->callback; - delete p; - } - else - subscribers[type].Push(p); - - return true; + CS::Threading::ScopedWriteLock lock(mutex); + return subscribers.Delete(type, subscriber); } -bool MsgHandler::Unsubscribe(iNetSubscriber *subscriber, msgtype type) +bool MsgHandler::UnsubscribeAll(iNetSubscriber *subscriber) { - CS::Threading::RecursiveMutexScopedLock lock(mutex); + CS::Threading::ScopedWriteLock lock(mutex); + bool found = false; - for ( size_t x = 0; x < subscribers[type].GetSize(); x++ ) + csHash<Subscription, msgtype>::GlobalIterator iter = subscribers.GetIterator(); + while(iter.HasNext()) { - if (subscribers[type][x]->subscriber == subscriber) + if(iter.Next().subscriber == subscriber) { - delete subscribers[type][x]->callback; // delete functor if present - subscribers[type].DeleteIndex(x); - return true; - } + subscribers.DeleteElement(iter); + found = true; + } } - - return false; + return found; } - -bool MsgHandler::IsSubscribed( Subscription* sub ) -{ - for ( size_t x = 0; x < subscribers[sub->type].GetSize(); x++ ) - { - if (subscribers[sub->type][x]->subscriber == sub->subscriber) - { - return true; - } - } - - return false; -} Modified: trunk/src/common/net/msghandler.h =================================================================== --- trunk/src/common/net/msghandler.h 2010-12-26 15:53:17 UTC (rev 6619) +++ trunk/src/common/net/msghandler.h 2010-12-26 17:20:35 UTC (rev 6620) @@ -22,6 +22,7 @@ #include <csutil/parray.h> #include <csutil/refcount.h> #include <csutil/threading/thread.h> +#include <csutil/threading/rwmutex.h> #include "net/message.h" #include "net/netbase.h" @@ -31,49 +32,35 @@ class NetBase; class Client; -#define MAX_MESSAGE_TYPES 255 // MSGTYPE enumeration in messages.h has less types than this - -/// Functor base class for direct callbacks on Subscriptions -class MsgtypeCallback -{ -public: - virtual ~MsgtypeCallback() { }; - virtual void operator()(MsgEntry *message, Client *client) = 0; // call using operator - virtual void Call(MsgEntry *message, Client *client) = 0; // call using function -}; - - //----------------------------------------------------------------------------- -template <class Manager> -class NetMessageCallback : public MsgtypeCallback +/** @brief Manages a \ref iNetSubscriber watching a certain message type + * + * Simple class containing data for subscribes that want to be informed of + * messages. + */ +struct Subscription { -private: - void (Manager::*funcptr)(MsgEntry *message, Client *client); // pointer to member function - Manager *thisPtr; // pointer to object + uint32_t flags; /**< Additional flags for detecting if the subscriber should be notified */ + iNetSubscriber* subscriber; /**< The actual subscriber that wants to be notified */ -public: - // constructor - takes pointer to an object and pointer to a member and stores - // them in two private variables - NetMessageCallback(Manager *myObject, void(Manager::*fpt)(MsgEntry *message, Client *client)) - { - thisPtr = myObject; - funcptr = fpt; - } - - virtual ~NetMessageCallback() { }; - - // override operator "()" - virtual void operator()(MsgEntry *message, Client *client) + /**@brief Constructor without a callback + * + * \ref callback is set to NULL + * + * @param nSubscriber Sets \ref subscriber + * @param nFlags Sets \ref flags + */ + Subscription(iNetSubscriber *nSubscriber, uint32_t nFlags = 0x01/*REQUIRE_READY_CLIENT*/) + : flags(nFlags), subscriber(nSubscriber) { - (*thisPtr.*funcptr)(message,client); } - // override function "Call" - virtual void Call(MsgEntry *message, Client *client) + // comparison operator required for usage in csHash + bool operator<(const Subscription& other) const { - (*thisPtr.*funcptr)(message,client); + return subscriber < other.subscriber; } }; @@ -81,26 +68,6 @@ //----------------------------------------------------------------------------- -/// This little struct tracks who is interested in what. -struct Subscription -{ - /// type of the messages this listener listens to - msgtype type; - - /// Flags for central testing - uint32_t flags; - - /// pointer to the subscriber - iNetSubscriber *subscriber; - - /// pointer to functor class callback as alternative to iNetSubscriber - MsgtypeCallback *callback; -}; - - -//----------------------------------------------------------------------------- - - /** * This class holds the structure for guaranteed inbound ordering of certain message * types. We need to track the next sequence number we're expecting (in a range @@ -126,10 +93,8 @@ } }; - //----------------------------------------------------------------------------- - /** * This class is the client's and server's main interface for either sending * network messages out or getting notified about inbound ones which have been @@ -144,15 +109,37 @@ /** Initializes the Handler */ bool Initialize(NetBase *nb, int queuelen = 500); - /** Any subclass of iNetSubscriber can subscribe to incoming network messages - * with this function + /** @brief Subscribes an \ref iNetSubscriber to a specific message type + * + * Subclasses of \ref iNetSubscriber subscribe to incoming network messages + * using this function. Adds the resulting \ref Subscription to + * \ref subscribers. + * + * @param subscriber The subscriber that wants to be informed of messages + * @param type The type of message to monitor + * @param flags Additional flags to determine if the message should be forwarded */ - virtual bool Subscribe(iNetSubscriber *subscriber, msgtype type, uint32_t flags = 0x01/*REQUIRE_READY_CLIENT*/); - virtual bool Subscribe(iNetSubscriber *subscriber, MsgtypeCallback *callback, msgtype type, uint32_t flags = 0x01/*REQUIRE_READY_CLIENT*/); + virtual void Subscribe(iNetSubscriber *subscriber, msgtype type, uint32_t flags = 0x01/*REQUIRE_READY_CLIENT*/); - /// Remove subscriber from list - virtual bool Unsubscribe(iNetSubscriber *subscriber, msgtype type); + /** @brief Unsubscribes a subscriber from a specific message type + * + * If \ref subscribers contains a \ref Subscription that has the specified + * subscriber and the message type key it is removed and true is returned + * + * @param subscriber The subscriber to look for in the hash + * @param type The type of message to search + * @return True if the subscription is found and deleted, false otherwise + */ + virtual bool Unsubscribe(iNetSubscriber *subscriber , msgtype type); + /** + * Searches all message types and deletes any \ref Subscription that has + * the specified subscriber. + * @param subscriber The subscriber to search for and remove + * @return True if at least one Subscription was deleted, false otherwise + */ + virtual bool UnsubscribeAll(iNetSubscriber *subscriber); + /// Distribute message to all subscribers void Publish(MsgEntry *msg); @@ -171,9 +158,6 @@ virtual void Multicast(MsgEntry* msg, csArray<PublishDestination>& multi, int except, float range) { netbase->Multicast(msg, multi, except, range); } - /// Detects multiple subscriptions on the same object - bool IsSubscribed (Subscription* p ); - void AddToLocalQueue(MsgEntry *me) { netbase->QueueMessage(me); } csTicks GetPing() { return netbase->GetPing(); } @@ -186,11 +170,10 @@ MsgQueue *queue; /** - * Each message type now has an array of subscribers so we can publish - * to them directly instead of searching the entire list of all subscribers. + * @brief Stores the hash of all subscribers and the message type they are subscribed to */ - csPDelArray<Subscription> subscribers[MAX_MESSAGE_TYPES]; - CS::Threading::RecursiveMutex mutex; + csHash<Subscription, msgtype> subscribers; + CS::Threading::ReadWriteMutex mutex; /**< @brief Protects \ref subscribers */ }; #endif Modified: trunk/src/common/net/subscriber.h =================================================================== --- trunk/src/common/net/subscriber.h 2010-12-26 15:53:17 UTC (rev 6619) +++ trunk/src/common/net/subscriber.h 2010-12-26 17:20:35 UTC (rev 6620) @@ -32,9 +32,9 @@ */ struct iNetSubscriber : public virtual csRefCount { - virtual bool Verify(MsgEntry *msg,unsigned int flags,Client*& client) = 0; + virtual bool Verify(MsgEntry *msg,unsigned int flags,Client*& client) = 0; - /** + /** * Interprets a received message and executes the command. */ virtual void HandleMessage(MsgEntry* msg,Client *client) = 0; Modified: trunk/src/server/actionmanager.cpp =================================================================== --- trunk/src/server/actionmanager.cpp 2010-12-26 15:53:17 UTC (rev 6619) +++ trunk/src/server/actionmanager.cpp 2010-12-26 17:20:35 UTC (rev 6620) @@ -118,14 +118,13 @@ database = db; // Action Messages from client that need handling - psserver->GetEventManager()->Subscribe( this,new NetMessageCallback<ActionManager>(this,&ActionManager::HandleMapAction), MSGTYPE_MAPACTION, REQUIRE_READY_CLIENT ); + Subscribe(&ActionManager::HandleMapAction, MSGTYPE_MAPACTION, REQUIRE_READY_CLIENT); } ActionManager::~ActionManager() { // Unsubscribe from Messages - psserver->GetEventManager()->Unsubscribe( this, MSGTYPE_MAPACTION ); csHash<psActionLocation *>::GlobalIterator it (actionLocationList.GetIterator ()); while ( it.HasNext () ) Modified: trunk/src/server/actionmanager.h =================================================================== --- trunk/src/server/actionmanager.h 2010-12-26 15:53:17 UTC (rev 6619) +++ trunk/src/server/actionmanager.h 2010-12-26 17:20:35 UTC (rev 6620) @@ -83,7 +83,7 @@ /** Handles the map interaction system. * Used to populate/update/change current action locations. */ -class ActionManager : public MessageManager +class ActionManager : public MessageManager<ActionManager> { public: Modified: trunk/src/server/adminmanager.cpp =================================================================== --- trunk/src/server/adminmanager.cpp 2010-12-26 15:53:17 UTC (rev 6619) +++ trunk/src/server/adminmanager.cpp 2010-12-26 17:20:35 UTC (rev 6620) @@ -96,7 +96,7 @@ class AreaTargetConfirm : public PendingQuestion { public: - AreaTargetConfirm(MessageManager* msgmanager, const csString in_msg, csString in_player, const csString & question, Client *in_client) + AreaTargetConfirm(AdminManager* msgmanager, const csString in_msg, csString in_player, const csString & question, Client *in_client) : PendingQuestion(in_client->GetClientNum(),question, psQuestionMessage::generalConfirm) { //save variables for later use this->command = in_msg; @@ -135,7 +135,7 @@ csString command; ///< The complete command sent from the client originally (without any modification) Client *client; ///< Originating client of the command csString player; ///< Normally this should be the area:x:x command extrapolated from the original command - MessageManager* msgmanager; + AdminManager* msgmanager; }; @@ -143,11 +143,11 @@ { clients = psserver->GetNetManager()->GetConnections(); - psserver->GetEventManager()->Subscribe(this,new NetMessageCallback<AdminManager>(this,&AdminManager::HandleAdminCmdMessage),MSGTYPE_ADMINCMD,REQUIRE_READY_CLIENT); - psserver->GetEventManager()->Subscribe(this,new NetMessageCallback<AdminManager>(this,&AdminManager::HandlePetitionMessage),MSGTYPE_PETITION_REQUEST,REQUIRE_READY_CLIENT); - psserver->GetEventManager()->Subscribe(this,new NetMessageCallback<AdminManager>(this,&AdminManager::HandleGMGuiMessage) ,MSGTYPE_GMGUI,REQUIRE_READY_CLIENT); - psserver->GetEventManager()->Subscribe(this,new NetMessageCallback<AdminManager>(this,&AdminManager::SendSpawnItems) ,MSGTYPE_GMSPAWNITEMS,REQUIRE_READY_CLIENT); - psserver->GetEventManager()->Subscribe(this,new NetMessageCallback<AdminManager>(this,&AdminManager::SpawnItemInv) ,MSGTYPE_GMSPAWNITEM,REQUIRE_READY_CLIENT); + Subscribe(&AdminManager::HandleAdminCmdMessage, MSGTYPE_ADMINCMD, REQUIRE_READY_CLIENT); + Subscribe(&AdminManager::HandlePetitionMessage, MSGTYPE_PETITION_REQUEST, REQUIRE_READY_CLIENT); + Subscribe(&AdminManager::HandleGMGuiMessage, MSGTYPE_GMGUI, REQUIRE_READY_CLIENT); + Subscribe(&AdminManager::SendSpawnItems, MSGTYPE_GMSPAWNITEMS, REQUIRE_READY_CLIENT); + Subscribe(&AdminManager::SpawnItemInv, MSGTYPE_GMSPAWNITEM, REQUIRE_READY_CLIENT); // this makes sure that the player dictionary exists on start up. @@ -162,12 +162,6 @@ AdminManager::~AdminManager() { - psserver->GetEventManager()->Unsubscribe(this,MSGTYPE_ADMINCMD); - psserver->GetEventManager()->Unsubscribe(this,MSGTYPE_PETITION_REQUEST); - psserver->GetEventManager()->Unsubscribe(this,MSGTYPE_GMGUI); - psserver->GetEventManager()->Unsubscribe(this,MSGTYPE_GMSPAWNITEMS); - psserver->GetEventManager()->Unsubscribe(this,MSGTYPE_GMSPAWNITEM); - delete npcdlg; delete pathNetwork; } Modified: trunk/src/server/adminmanager.h =================================================================== --- trunk/src/server/adminmanager.h 2010-12-26 15:53:17 UTC (rev 6619) +++ trunk/src/server/adminmanager.h 2010-12-26 17:20:35 UTC (rev 6620) @@ -77,7 +77,7 @@ /** Admin manager that handles GM commands and general game control. */ -class AdminManager : public MessageManager +class AdminManager : public MessageManager<AdminManager> { public: AdminManager(); Modified: trunk/src/server/advicemanager.cpp =================================================================== --- trunk/src/server/advicemanager.cpp 2010-12-26 15:53:17 UTC (rev 6619) +++ trunk/src/server/advicemanager.cpp 2010-12-26 17:20:35 UTC (rev 6620) @@ -326,7 +326,7 @@ database = db; - psserver->GetEventManager()->Subscribe( this, MSGTYPE_ADVICE,REQUIRE_READY_CLIENT ); + Subscribe(MSGTYPE_ADVICE,REQUIRE_READY_CLIENT); } AdviceManager::~AdviceManager() @@ -334,7 +334,6 @@ csHash<AdviceSession*>::GlobalIterator iter(AdviseeList.GetIterator()); while(iter.HasNext()) delete iter.Next(); - psserver->GetEventManager()->Unsubscribe( this, MSGTYPE_ADVICE ); } void AdviceManager::HandleMessage(MsgEntry *me,Client *client) Modified: trunk/src/server/advicemanager.h =================================================================== --- trunk/src/server/advicemanager.h 2010-12-26 15:53:17 UTC (rev 6619) +++ trunk/src/server/advicemanager.h 2010-12-26 17:20:35 UTC (rev 6620) @@ -71,7 +71,7 @@ * An invitation is pending between the time that the Noob * sends the invitation and when an Advisor sends a response. */ -class AdviceManager : public MessageManager +class AdviceManager : public MessageManager<AdviceManager> { public: Modified: trunk/src/server/authentserver.cpp =================================================================== --- trunk/src/server/authentserver.cpp 2010-12-26 15:53:17 UTC (rev 6619) +++ trunk/src/server/authentserver.cpp 2010-12-26 17:20:35 UTC (rev 6620) @@ -80,25 +80,17 @@ usermanager = usermgr; guildmanager = gm; - psserver->GetEventManager()->Subscribe(this,new NetMessageCallback<AuthenticationServer>(this,&AuthenticationServer::HandlePreAuthent),MSGTYPE_PREAUTHENTICATE,REQUIRE_ANY_CLIENT); - psserver->GetEventManager()->Subscribe(this,new NetMessageCallback<AuthenticationServer>(this,&AuthenticationServer::HandleAuthent),MSGTYPE_AUTHENTICATE,REQUIRE_ANY_CLIENT); - psserver->GetEventManager()->Subscribe(this,new NetMessageCallback<AuthenticationServer>(this,&AuthenticationServer::HandleStringsRequest),MSGTYPE_MSGSTRINGS,REQUIRE_ANY_CLIENT); - psserver->GetEventManager()->Subscribe(this,new NetMessageCallback<AuthenticationServer>(this,&AuthenticationServer::HandleDisconnect),MSGTYPE_DISCONNECT,REQUIRE_ANY_CLIENT); - psserver->GetEventManager()->Subscribe(this,new NetMessageCallback<AuthenticationServer>(this,&AuthenticationServer::HandleAuthCharacter),MSGTYPE_AUTHCHARACTER,REQUIRE_ANY_CLIENT); - psserver->GetEventManager()->Subscribe(this,new NetMessageCallback<AuthenticationServer>(this,&AuthenticationServer::HandleStatusUpdate),MSGTYPE_CLIENTSTATUS,REQUIRE_ANY_CLIENT); + Subscribe(&AuthenticationServer::HandlePreAuthent, MSGTYPE_PREAUTHENTICATE, REQUIRE_ANY_CLIENT); + Subscribe(&AuthenticationServer::HandleAuthent, MSGTYPE_AUTHENTICATE, REQUIRE_ANY_CLIENT); + Subscribe(&AuthenticationServer::HandleStringsRequest, MSGTYPE_MSGSTRINGS, REQUIRE_ANY_CLIENT); + Subscribe(&AuthenticationServer::HandleDisconnect, MSGTYPE_DISCONNECT, REQUIRE_ANY_CLIENT); + Subscribe(&AuthenticationServer::HandleAuthCharacter, MSGTYPE_AUTHCHARACTER, REQUIRE_ANY_CLIENT); + Subscribe(&AuthenticationServer::HandleStatusUpdate, MSGTYPE_CLIENTSTATUS, REQUIRE_ANY_CLIENT); } AuthenticationServer::~AuthenticationServer() { - if (psserver->GetEventManager()) - { - psserver->GetEventManager()->Unsubscribe(this,MSGTYPE_PREAUTHENTICATE); - psserver->GetEventManager()->Unsubscribe(this,MSGTYPE_AUTHENTICATE); - psserver->GetEventManager()->Unsubscribe(this,MSGTYPE_MSGSTRINGS); - psserver->GetEventManager()->Unsubscribe(this,MSGTYPE_DISCONNECT); - psserver->GetEventManager()->Unsubscribe(this,MSGTYPE_AUTHCHARACTER); - psserver->GetEventManager()->Unsubscribe(this,MSGTYPE_CLIENTSTATUS); - } + //do nothing } Modified: trunk/src/server/authentserver.h =================================================================== --- trunk/src/server/authentserver.h 2010-12-26 15:53:17 UTC (rev 6619) +++ trunk/src/server/authentserver.h 2010-12-26 17:20:35 UTC (rev 6620) @@ -74,7 +74,7 @@ * "Not Authorized" message. * */ -class AuthenticationServer : public MessageManager +class AuthenticationServer : public MessageManager<AuthenticationServer> { public: Modified: trunk/src/server/bankmanager.cpp =================================================================== --- trunk/src/server/bankmanager.cpp 2010-12-26 15:53:17 UTC (rev 6619) +++ trunk/src/server/bankmanager.cpp 2010-12-26 17:20:35 UTC (rev 6620) @@ -50,7 +50,7 @@ BankManager::BankManager() { - psserver->GetEventManager()->Subscribe(this,new NetMessageCallback<BankManager>(this,&BankManager::HandleBanking),MSGTYPE_BANKING,REQUIRE_READY_CLIENT); + Subscribe(&BankManager::HandleBanking, MSGTYPE_BANKING, REQUIRE_READY_CLIENT); // Load money events. Result result(db->Select("select * from money_events")); @@ -90,7 +90,7 @@ BankManager::~BankManager() { - psserver->GetEventManager()->Unsubscribe(this,MSGTYPE_BANKING); + //do nothing } psMoneyGameEvent::psMoneyGameEvent(int delayTicks, BankManager *bankMan) Modified: trunk/src/server/bankmanager.h =================================================================== --- trunk/src/server/bankmanager.h 2010-12-26 15:53:17 UTC (rev 6619) +++ trunk/src/server/bankmanager.h 2010-12-26 17:20:35 UTC (rev 6620) @@ -32,7 +32,7 @@ class psMoneyGameEvent; class Client; -class BankManager : public MessageManager +class BankManager : public MessageManager<BankManager> { public: BankManager(); Modified: trunk/src/server/chatmanager.cpp =================================================================== --- trunk/src/server/chatmanager.cpp 2010-12-26 15:53:17 UTC (rev 6619) +++ trunk/src/server/chatmanager.cpp 2010-12-26 17:20:35 UTC (rev 6620) @@ -61,10 +61,10 @@ ChatManager::ChatManager() : nextChannelID(2) { - psserver->GetEventManager()->Subscribe(this,new NetMessageCallback<ChatManager>(this,&ChatManager::HandleChannelJoinMessage),MSGTYPE_CHANNEL_JOIN,REQUIRE_ANY_CLIENT); - psserver->GetEventManager()->Subscribe(this,new NetMessageCallback<ChatManager>(this,&ChatManager::HandleChannelLeaveMessage),MSGTYPE_CHANNEL_LEAVE,REQUIRE_ANY_CLIENT); - psserver->GetEventManager()->Subscribe(this,new NetMessageCallback<ChatManager>(this,&ChatManager::HandleChatMessage),MSGTYPE_CHAT,REQUIRE_ALIVE); - psserver->GetEventManager()->Subscribe(this,new NetMessageCallback<ChatManager>(this,&ChatManager::HandleCacheMessage),MSGTYPE_CACHEFILE,REQUIRE_READY_CLIENT); + Subscribe(&ChatManager::HandleChannelJoinMessage, MSGTYPE_CHANNEL_JOIN, REQUIRE_ANY_CLIENT); + Subscribe(&ChatManager::HandleChannelLeaveMessage, MSGTYPE_CHANNEL_LEAVE, REQUIRE_ANY_CLIENT); + Subscribe(&ChatManager::HandleChatMessage, MSGTYPE_CHAT, REQUIRE_ALIVE); + Subscribe(&ChatManager::HandleCacheMessage, MSGTYPE_CACHEFILE, REQUIRE_READY_CLIENT); // Default channel channelIDs.PutUnique("gossip", 1); @@ -73,10 +73,7 @@ ChatManager::~ChatManager() { - psserver->GetEventManager()->Unsubscribe(this,MSGTYPE_CHANNEL_JOIN); - psserver->GetEventManager()->Unsubscribe(this,MSGTYPE_CHANNEL_LEAVE); - psserver->GetEventManager()->Unsubscribe(this,MSGTYPE_CHAT); - psserver->GetEventManager()->Unsubscribe(this,MSGTYPE_CACHEFILE); + //do nothing } Modified: trunk/src/server/chatmanager.h =================================================================== --- trunk/src/server/chatmanager.h 2010-12-26 15:53:17 UTC (rev 6619) +++ trunk/src/server/chatmanager.h 2010-12-26 17:20:35 UTC (rev 6620) @@ -67,7 +67,7 @@ } }; -class ChatManager : public MessageManager +class ChatManager : public MessageManager<ChatManager> { public: Modified: trunk/src/server/combatmanager.cpp =================================================================== --- trunk/src/server/combatmanager.cpp 2010-12-26 15:53:17 UTC (rev 6619) +++ trunk/src/server/combatmanager.cpp 2010-12-26 17:20:35 UTC (rev 6620) @@ -167,12 +167,11 @@ staminacombat = psserver->GetMathScriptEngine()->FindScript("StaminaCombat"); - psserver->GetEventManager()->Subscribe(this,new NetMessageCallback<CombatManager>(this,&CombatManager::HandleDeathEvent),MSGTYPE_DEATH_EVENT,NO_VALIDATION); + Subscribe(&CombatManager::HandleDeathEvent, MSGTYPE_DEATH_EVENT, NO_VALIDATION); } CombatManager::~CombatManager() { - psserver->GetEventManager()->Unsubscribe(this,MSGTYPE_DEATH_EVENT); if (pvp_region) { delete pvp_region; Modified: trunk/src/server/combatmanager.h =================================================================== --- trunk/src/server/combatmanager.h 2010-12-26 15:53:17 UTC (rev 6619) +++ trunk/src/server/combatmanager.h 2010-12-26 17:20:35 UTC (rev 6620) @@ -51,7 +51,7 @@ * and information from the pspccharacterinfo Prop Classes for both * the attacker and the target. */ -class CombatManager: public MessageManager +class CombatManager: public MessageManager<CombatManager> { public: Modified: trunk/src/server/creationmanager.cpp =================================================================== --- trunk/src/server/creationmanager.cpp 2010-12-26 15:53:17 UTC (rev 6619) +++ trunk/src/server/creationmanager.cpp 2010-12-26 17:20:35 UTC (rev 6620) @@ -76,18 +76,6 @@ CharCreationManager::~CharCreationManager() { - if (psserver->GetEventManager()) - { - psserver->GetEventManager()->Unsubscribe(this, MSGTYPE_CHAR_CREATE_UPLOAD); - psserver->GetEventManager()->Unsubscribe(this, MSGTYPE_CHAR_CREATE_CP); - psserver->GetEventManager()->Unsubscribe(this, MSGTYPE_CHAR_CREATE_PARENTS); - psserver->GetEventManager()->Unsubscribe(this, MSGTYPE_CHAR_CREATE_CHILDHOOD); - psserver->GetEventManager()->Unsubscribe(this, MSGTYPE_CHAR_CREATE_LIFEEVENTS); - psserver->GetEventManager()->Unsubscribe(this, MSGTYPE_CHAR_CREATE_TRAITS); - psserver->GetEventManager()->Unsubscribe(this, MSGTYPE_CHAR_CREATE_NAME); - psserver->GetEventManager()->Unsubscribe(this, MSGTYPE_CHAR_DELETE); - } - delete [] raceCPValues; } @@ -98,15 +86,15 @@ LoadCreationChoices() && LoadLifeEvents()) ) return false; - - psserver->GetEventManager()->Subscribe(this, new NetMessageCallback<CharCreationManager>(this,&CharCreationManager::HandleUploadMessage), MSGTYPE_CHAR_CREATE_UPLOAD,REQUIRE_ANY_CLIENT); - psserver->GetEventManager()->Subscribe(this, new NetMessageCallback<CharCreationManager>(this,&CharCreationManager::HandleCharCreateCP), MSGTYPE_CHAR_CREATE_CP,REQUIRE_ANY_CLIENT); - psserver->GetEventManager()->Subscribe(this, new NetMessageCallback<CharCreationManager>(this,&CharCreationManager::HandleParents), MSGTYPE_CHAR_CREATE_PARENTS,REQUIRE_ANY_CLIENT); - psserver->GetEventManager()->Subscribe(this, new NetMessageCallback<CharCreationManager>(this,&CharCreationManager::HandleChildhood), MSGTYPE_CHAR_CREATE_CHILDHOOD,REQUIRE_ANY_CLIENT); - psserver->GetEventManager()->Subscribe(this, new NetMessageCallback<CharCreationManager>(this,&CharCreationManager::HandleLifeEvents), MSGTYPE_CHAR_CREATE_LIFEEVENTS,REQUIRE_ANY_CLIENT); - psserver->GetEventManager()->Subscribe(this, new NetMessageCallback<CharCreationManager>(this,&CharCreationManager::HandleTraits), MSGTYPE_CHAR_CREATE_TRAITS,REQUIRE_ANY_CLIENT); - psserver->GetEventManager()->Subscribe(this, new NetMessageCallback<CharCreationManager>(this,&CharCreationManager::HandleName), MSGTYPE_CHAR_CREATE_NAME,REQUIRE_ANY_CLIENT); - psserver->GetEventManager()->Subscribe(this, new NetMessageCallback<CharCreationManager>(this,&CharCreationManager::HandleCharDelete), MSGTYPE_CHAR_DELETE,REQUIRE_ANY_CLIENT); + + Subscribe(&CharCreationManager::HandleUploadMessage, MSGTYPE_CHAR_CREATE_UPLOAD, REQUIRE_ANY_CLIENT); + Subscribe(&CharCreationManager::HandleCharCreateCP, MSGTYPE_CHAR_CREATE_CP, REQUIRE_ANY_CLIENT); + Subscribe(&CharCreationManager::HandleParents, MSGTYPE_CHAR_CREATE_PARENTS, REQUIRE_ANY_CLIENT); + Subscribe(&CharCreationManager::HandleChildhood, MSGTYPE_CHAR_CREATE_CHILDHOOD, REQUIRE_ANY_CLIENT); + Subscribe(&CharCreationManager::HandleLifeEvents, MSGTYPE_CHAR_CREATE_LIFEEVENTS, REQUIRE_ANY_CLIENT); + Subscribe(&CharCreationManager::HandleTraits, MSGTYPE_CHAR_CREATE_TRAITS, REQUIRE_ANY_CLIENT); + Subscribe(&CharCreationManager::HandleName, MSGTYPE_CHAR_CREATE_NAME, REQUIRE_ANY_CLIENT); + Subscribe(&CharCreationManager::HandleCharDelete, MSGTYPE_CHAR_DELETE, REQUIRE_ANY_CLIENT); // Other loaders are here. return true; Modified: trunk/src/server/creationmanager.h =================================================================== --- trunk/src/server/creationmanager.h 2010-12-26 15:53:17 UTC (rev 6619) +++ trunk/src/server/creationmanager.h 2010-12-26 17:20:35 UTC (rev 6620) @@ -44,7 +44,7 @@ * character_creation * */ -class CharCreationManager : MessageManager +class CharCreationManager : MessageManager<CharCreationManager> { public: CharCreationManager(GEMSupervisor* gemsupervisor, CacheManager* cachemanager, EntityManager* entitymanager); Modified: trunk/src/server/economymanager.cpp =================================================================== --- trunk/src/server/economymanager.cpp 2010-12-26 15:53:17 UTC (rev 6619) +++ trunk/src/server/economymanager.cpp 2010-12-26 17:20:35 UTC (rev 6620) @@ -64,25 +64,18 @@ EconomyManager::EconomyManager() { - psserver->GetEventManager()->Subscribe(this,MSGTYPE_BUY_EVENT,NO_VALIDATION); - psserver->GetEventManager()->Subscribe(this,MSGTYPE_SELL_EVENT,NO_VALIDATION); - psserver->GetEventManager()->Subscribe(this,MSGTYPE_PICKUP_EVENT,NO_VALIDATION); - psserver->GetEventManager()->Subscribe(this,MSGTYPE_DROP_EVENT,NO_VALIDATION); - psserver->GetEventManager()->Subscribe(this,MSGTYPE_LOOT_EVENT,NO_VALIDATION); + Subscribe(MSGTYPE_BUY_EVENT, NO_VALIDATION); + Subscribe(MSGTYPE_SELL_EVENT, NO_VALIDATION); + Subscribe(MSGTYPE_PICKUP_EVENT, NO_VALIDATION); + Subscribe(MSGTYPE_DROP_EVENT, NO_VALIDATION); + Subscribe(MSGTYPE_LOOT_EVENT, NO_VALIDATION); }; EconomyManager::~EconomyManager() { - if(psserver->GetEventManager()) - { - psserver->GetEventManager()->Unsubscribe(this,MSGTYPE_BUY_EVENT); - psserver->GetEventManager()->Unsubscribe(this,MSGTYPE_SELL_EVENT); - psserver->GetEventManager()->Unsubscribe(this,MSGTYPE_PICKUP_EVENT); - psserver->GetEventManager()->Unsubscribe(this,MSGTYPE_DROP_EVENT); - psserver->GetEventManager()->Unsubscribe(this,MSGTYPE_LOOT_EVENT); - } + //do nothing } void EconomyManager::AddTransaction(TransactionEntity* trans,bool moneyIn, const char* type) Modified: trunk/src/server/economymanager.h =================================================================== --- trunk/src/server/economymanager.h 2010-12-26 15:53:17 UTC (rev 6619) +++ trunk/src/server/economymanager.h 2010-12-26 17:20:35 UTC (rev 6620) @@ -71,7 +71,7 @@ unsigned int sold; }; -class EconomyManager : public MessageManager +class EconomyManager : public MessageManager<EconomyManager> { public: EconomyManager(); Modified: trunk/src/server/entitymanager.cpp =================================================================== --- trunk/src/server/entitymanager.cpp 2010-12-26 15:53:17 UTC (rev 6619) +++ trunk/src/server/entitymanager.cpp 2010-12-26 17:20:35 UTC (rev 6620) @@ -93,17 +93,7 @@ { delete serverdr; - if (psserver->GetEventManager()) { - psserver->GetEventManager()->Unsubscribe(this, MSGTYPE_CELPERSIST); - psserver->GetEventManager()->Unsubscribe(this, MSGTYPE_USERACTION); - psserver->GetEventManager()->Unsubscribe(this, MSGTYPE_PERSIST_WORLD_REQUEST); - psserver->GetEventManager()->Unsubscribe(this, MSGTYPE_PERSIST_ACTOR_REQUEST); - psserver->GetEventManager()->Unsubscribe(this, MSGTYPE_PERSIST_ALL); - psserver->GetEventManager()->Unsubscribe(this, MSGTYPE_REQUESTMOVEMENTS); - } - - { csHash<psAffinityAttribute *>::GlobalIterator it(affinityAttributeList.GetIterator ()); while (it.HasNext ()) { @@ -139,11 +129,11 @@ usermanager = umanager; - psserver->GetEventManager()->Subscribe(this, new NetMessageCallback<EntityManager>(this,&EntityManager::HandleUserAction), MSGTYPE_USERACTION,REQUIRE_READY_CLIENT|REQUIRE_ALIVE); - psserver->GetEventManager()->Subscribe(this, new NetMessageCallback<EntityManager>(this,&EntityManager::HandleWorld) , MSGTYPE_PERSIST_WORLD_REQUEST,REQUIRE_ANY_CLIENT ); - psserver->GetEventManager()->Subscribe(this, new NetMessageCallback<EntityManager>(this,&EntityManager::HandleActor) , MSGTYPE_PERSIST_ACTOR_REQUEST,REQUIRE_ANY_CLIENT ); - psserver->GetEventManager()->Subscribe(this, new NetMessageCallback<EntityManager>(this,&EntityManager::HandleAllRequest), MSGTYPE_PERSIST_ALL,REQUIRE_ANY_CLIENT); - psserver->GetEventManager()->Subscribe(this, new NetMessageCallback<EntityManager>(this,&EntityManager::SendMovementInfo), MSGTYPE_REQUESTMOVEMENTS,REQUIRE_ANY_CLIENT); + Subscribe(&EntityManager::HandleUserAction, MSGTYPE_USERACTION, REQUIRE_READY_CLIENT | REQUIRE_ALIVE); + Subscribe(&EntityManager::HandleWorld, MSGTYPE_PERSIST_WORLD_REQUEST, REQUIRE_ANY_CLIENT ); + Subscribe(&EntityManager::HandleActor, MSGTYPE_PERSIST_ACTOR_REQUEST, REQUIRE_ANY_CLIENT ); + Subscribe(&EntityManager::HandleAllRequest, MSGTYPE_PERSIST_ALL, REQUIRE_ANY_CLIENT); + Subscribe(&EntityManager::SendMovementInfo, MSGTYPE_REQUESTMOVEMENTS, REQUIRE_ANY_CLIENT); EntityManager::clients = clients; Modified: trunk/src/server/entitymanager.h =================================================================== --- trunk/src/server/entitymanager.h 2010-12-26 15:53:17 UTC (rev 6619) +++ trunk/src/server/entitymanager.h 2010-12-26 17:20:35 UTC (rev 6620) @@ -73,10 +73,8 @@ csString MagicalAffinity; }; - - /// Manages CEL entities on the server -class EntityManager : public MessageManager, public Singleton<EntityManager> +class EntityManager : public MessageManager<EntityManager>, public Singleton<EntityManager> { public: EntityManager(); Modified: trunk/src/server/exchangemanager.cpp =================================================================== --- trunk/src/server/exchangemanager.cpp 2010-12-26 15:53:17 UTC (rev 6619) +++ trunk/src/server/exchangemanager.cpp 2010-12-26 17:20:35 UTC (rev 6620) @@ -1348,21 +1348,15 @@ { clients = pClnts; - psserver->GetEventManager()->Subscribe(this, new NetMessageCallback<ExchangeManager>(this,&ExchangeManager::HandleExchangeRequest),MSGTYPE_EXCHANGE_REQUEST, REQUIRE_READY_CLIENT|REQUIRE_ALIVE|REQUIRE_TARGETACTOR); - psserver->GetEventManager()->Subscribe(this, new NetMessageCallback<ExchangeManager>(this,&ExchangeManager::HandleExchangeAccept) ,MSGTYPE_EXCHANGE_ACCEPT, REQUIRE_READY_CLIENT|REQUIRE_ALIVE); - psserver->GetEventManager()->Subscribe(this, new NetMessageCallback<ExchangeManager>(this,&ExchangeManager::HandleExchangeEnd) ,MSGTYPE_EXCHANGE_END, REQUIRE_READY_CLIENT|REQUIRE_ALIVE); - psserver->GetEventManager()->Subscribe(this, new NetMessageCallback<ExchangeManager>(this,&ExchangeManager::HandleAutoGive) ,MSGTYPE_EXCHANGE_AUTOGIVE, REQUIRE_READY_CLIENT|REQUIRE_ALIVE|REQUIRE_TARGETACTOR); + Subscribe(&ExchangeManager::HandleExchangeRequest, MSGTYPE_EXCHANGE_REQUEST, REQUIRE_READY_CLIENT | REQUIRE_ALIVE | REQUIRE_TARGETACTOR); + Subscribe(&ExchangeManager::HandleExchangeAccept, MSGTYPE_EXCHANGE_ACCEPT, REQUIRE_READY_CLIENT | REQUIRE_ALIVE); + Subscribe(&ExchangeManager::HandleExchangeEnd, MSGTYPE_EXCHANGE_END, REQUIRE_READY_CLIENT | REQUIRE_ALIVE); + Subscribe(&ExchangeManager::HandleAutoGive, MSGTYPE_EXCHANGE_AUTOGIVE, REQUIRE_READY_CLIENT | REQUIRE_ALIVE | REQUIRE_TARGETACTOR); } ExchangeManager::~ExchangeManager() { - if (psserver->GetEventManager()) - { - psserver->GetEventManager()->Unsubscribe(this, MSGTYPE_EXCHANGE_REQUEST); - psserver->GetEventManager()->Unsubscribe(this, MSGTYPE_EXCHANGE_ACCEPT); - psserver->GetEventManager()->Unsubscribe(this, MSGTYPE_EXCHANGE_END); - psserver->GetEventManager()->Unsubscribe(this, MSGTYPE_EXCHANGE_AUTOGIVE); - } + //do nothing } void ExchangeManager::StartExchange( Client* client, bool withPlayer, bool automaticExchange ) { Modified: trunk/src/server/exchangemanager.h =================================================================== --- trunk/src/server/exchangemanager.h 2010-12-26 15:53:17 UTC (rev 6619) +++ trunk/src/server/exchangemanager.h 2010-12-26 17:20:35 UTC (rev 6620) @@ -335,7 +335,7 @@ /* Maintains a list of all the exchanges that are ongoing. */ -class ExchangeManager : public MessageManager +class ExchangeManager : public MessageManager<ExchangeManager> { public: Modified: trunk/src/server/gem.cpp =================================================================== --- trunk/src/server/gem.cpp 2010-12-26 15:53:17 UTC (rev 6619) +++ trunk/src/server/gem.cpp 2010-12-26 17:20:35 UTC (rev 6620) @@ -140,9 +140,9 @@ // 90000 enties another scope should be added to cel nextEID = 10000; - psserver->GetEventManager()->Subscribe(this,MSGTYPE_DAMAGE_EVENT,NO_VALIDATION); - psserver->GetEventManager()->Subscribe(this,MSGTYPE_STATDRUPDATE, REQUIRE_READY_CLIENT ); - psserver->GetEventManager()->Subscribe(this,MSGTYPE_STATS, REQUIRE_READY_CLIENT); + Subscribe(MSGTYPE_DAMAGE_EVENT,NO_VALIDATION); + Subscribe(MSGTYPE_STATDRUPDATE, REQUIRE_READY_CLIENT ); + Subscribe(MSGTYPE_STATS, REQUIRE_READY_CLIENT); engine = csQueryRegistry<iEngine> (psserver->GetObjectReg()); } @@ -163,12 +163,6 @@ count = entities_by_eid.GetSize(); continue; } - if (psserver->GetEventManager()) - { - psserver->GetEventManager()->Unsubscribe(this,MSGTYPE_DAMAGE_EVENT); - psserver->GetEventManager()->Unsubscribe(this,MSGTYPE_STATDRUPDATE); - psserver->GetEventManager()->Unsubscribe(this,MSGTYPE_STATS); - } } void GEMSupervisor::HandleMessage(MsgEntry *me,Client *client) Modified: trunk/src/server/gem.h =================================================================== --- trunk/src/server/gem.h 2010-12-26 15:53:17 UTC (rev 6619) +++ trunk/src/server/gem.h 2010-12-26 17:20:35 UTC (rev 6620) @@ -130,7 +130,7 @@ /** * This class holds the refs to the core factories, etc in CEL. */ -class GEMSupervisor : public MessageManager +class GEMSupervisor : public MessageManager<GEMSupervisor> { EntityManager *entityManager; CacheManager *cacheManager; Modified: trunk/src/server/gmeventmanager.cpp =================================================================== --- trunk/src/server/gmeventmanager.cpp 2010-12-26 15:53:17 UTC (rev 6619) +++ trunk/src/server/gmeventmanager.cpp 2010-12-26 17:20:35 UTC (rev 6620) @@ -49,13 +49,11 @@ // initialise gmEvents gmEvents.DeleteAll(); - psserver->GetEventManager()->Subscribe(this,new NetMessageCallback<GMEventManager>(this,&GMEventManager::HandleGMEventCommand), MSGTYPE_GMEVENT_INFO, REQUIRE_READY_CLIENT); + Subscribe(&GMEventManager::HandleGMEventCommand, MSGTYPE_GMEVENT_INFO, REQUIRE_READY_CLIENT); } GMEventManager::~GMEventManager() { - psserver->GetEventManager()->Unsubscribe(this,MSGTYPE_GMEVENT_INFO); - for (size_t e = 0; e < gmEvents.GetSize(); e++) { gmEvents[e]->Player.DeleteAll(); Modified: trunk/src/server/gmeventmanager.h =================================================================== --- trunk/src/server/gmeventmanager.h 2010-12-26 15:53:17 UTC (rev 6619) +++ trunk/src/server/gmeventmanager.h 2010-12-26 17:20:35 UTC (rev 6620) @@ -63,7 +63,7 @@ /** GameMaster Events manager class. */ -class GMEventManager : public MessageManager +class GMEventManager : public MessageManager<GMEventManager> { public: GMEventManager(); Modified: trunk/src/server/groupmanager.cpp =================================================================== --- trunk/src/server/groupmanager.cpp 2010-12-26 15:53:17 UTC (rev 6619) +++ trunk/src/server/groupmanager.cpp 2010-12-26 17:20:35 UTC (rev 6620) @@ -338,13 +338,12 @@ chatserver = chat; // Needed to GROUPSAY things. eventmanager = psserver->GetEventManager(); - psserver->GetEventManager()->Subscribe(this,new NetMessageCallback<GroupManager>(this,&GroupManager::HandleGroupCommand),MSGTYPE_GROUPCMD,REQUIRE_READY_CLIENT|REQUIRE_ALIVE); + Subscribe(&Gro... [truncated message content] |