using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Google.Protobuf.WellKnownTypes; namespace SogClient { public class TestHandlerMgr { private Player m_player; private Dictionary m_packetHandlerTable = new Dictionary(); private List m_packetHandlerList = new List(); public TestHandlerMgr(Player player) { m_player = player; } public void RegisterPacketHandler(int iMsgID, ITestHandler handler) { if (m_packetHandlerTable.ContainsKey(iMsgID)) { TraceLog.Error("msgtype {0} already be registed!", iMsgID); return; } TraceLog.Trace("register MsgID {0} by handler {1}", iMsgID, handler.GetType().FullName); m_packetHandlerTable.Add(iMsgID, handler); } public void RegisterAllPacketHandler() { AddAllHandler(); RegisterAllMsg(); } private void AddAllHandler() { m_packetHandlerTable.Clear(); //AddHandler(new TestSys(m_player, false)); //AddHandler(new TestArena(m_player)); AddHandler(new TestGM(m_player)); // AddHandler(new TestChapter(m_player)); //AddHandler(new TestOpenBox(m_player)); //AddHandler(new TestFriend(m_player)); //AddHandler(new TestLogClient(m_player)); //AddHandler(new TestHangupbonusView(m_player)); //AddHandler(new TestMainlandEnter(m_player)); //AddHandler(new TestMainlandFinish(m_player)); //AddHandler(new TestHeroUpdate(m_player)); //AddHandler(new TestFriendSelfChgNotify(m_player)); //AddHandler(new TestFriendListChgNotify(m_player)); //AddHandler(new TestCampaignMove(m_player)); //AddHandler(new TestTrade(m_player)); //AddHandler(new TestPetPvp(m_player)); } private void AddHandler(ITestHandler handler) { if(handler != null && !m_packetHandlerList.Contains(handler)) { m_packetHandlerList.Add(handler); } } private void RegisterAllMsg() { foreach(var handler in m_packetHandlerList) { handler.RegisterMsg(this); } } public void HandlerMsg(int iMsgID, RequestPacket packet) { ITestHandler handler; m_packetHandlerTable.TryGetValue(iMsgID, out handler); if (handler == null) { TraceLog.Trace("HandlerMsg packet id {0} not handler,please register a ITestHandler first!" , packet.MsgID); return; } handler.HandlerMsg(packet); } public void UpdateAllHandler() { long nowSecond = TimeUtils.GetTimeSecond(); foreach(ITestHandler handler in m_packetHandlerList) { handler.Update(nowSecond); } } } }