/* Thor Server 2.0 Project - Codenamed "Stockholm" Copyright 2008 - 2009 Joe Hegarty This file is part of The Thor Server 2.0 Project - Codenamed "Stockholm". The Thor Server 2.0 Project - Codenamed "Stockholm" is free software: you can redistribute it and/or modify it under the terms of the Microsoft Public License The Thor Server Project 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 Microsoft Public License for more details. You should have received a copy of the Microsoft Public License along with The Thor Server Project. If not, see http://www.opensource.org/licenses/ms-pl.html */ using System; using System.Collections.Generic; using StockholmLibrary.Game.Flats; using StockholmLibrary.Game.Sessions; using StockholmLibrary.Net; using StockholmLibrary.Game.Packets.Client; using Wintellect.PowerCollections; namespace StockholmLibrary.Game.Entities.Components { //------------------------------------ public abstract class EntityComponent { object _listenersLock = new object(); Entity _entity; MultiDictionary _listeners; //********************************************** public void Initialise(Entity entity) { _entity = entity; _listeners = new MultiDictionary(false); } //********************************************** public virtual void FlatInitiailise(Flat flat) { } //********************************************** public virtual void UserInitiailise(Session userSession) { } //********************************************** public virtual void UserDeinitiailise(Session userSession) { } //********************************************** public virtual void FlatDeinitiailise(Flat flat) { } //********************************************** public virtual void PostInitialise() { } //********************************************** public virtual void Pulse() { } //********************************************** protected Entity GetParentEntity() { return _entity; } //********************************************** protected void RegisterSessionHandler(Session session, EClientPacket packetType, PacketRoutingInfo.ProcessPacketDelegate receiverDelegate) { PacketRoutingInfo info = Stockholm.Get().PacketManager.RegisterPeerHandler(session.Peer, packetType, receiverDelegate, true); lock (_listenersLock) { _listeners.Add(session, info); } } //********************************************** protected void CleanupSessionHandlers(Session session) { lock (_listenersLock) { foreach (var info in _listeners[session]) { Stockholm.Get().PacketManager.RemoveHandler(info); } _listeners.Remove(session); } } } }