public FFWorker BindHandler <OBJ_TYPE, T>(object cmdregO, PbHandler <OBJ_TYPE, T> method) where T : pb::IMessage, new() where OBJ_TYPE : new() { int cmdreg = (int)cmdregO; m_dictCmd2Func[cmdreg] = new CmdRegInfo() { cmdName = cmdregO.ToString(), cmdHandler = (Int64 sid, int cmdSrc, byte[] data) => { int cmd = cmdSrc; if ((cmd & 0x4000) != 0) { cmd &= ~(0x4000); } T reqMsg = Util.Byte2Pb <T>(data); if (funcSessionID2Object != null) { object o = funcSessionID2Object(sid, cmdSrc, data); if (o != null && o is OBJ_TYPE) { OBJ_TYPE obj = (OBJ_TYPE)o; method(obj, reqMsg); } } } }; return(this); }
public FFWorker BindHandler <T>(object cmdregO, PbHandlerSession <T> method) where T : pb::IMessage, new() { int cmdreg = (int)cmdregO; m_dictCmd2Func[cmdreg] = new CmdRegInfo() { cmdName = cmdregO.ToString(), cmdHandler = (Int64 sid, int cmdSrc, byte[] data) => { T reqMsg = Util.Byte2Pb <T>(data); method(sid, reqMsg); } }; return(this); }
public EmptyMsgRet OnRouteLogicMsgReq(RouteLogicMsgReq reqMsg) { Int64 nBeginUs = DateTime.Now.Ticks / 10; int cmd = reqMsg.Cmd; if ((cmd & 0x4000) != 0) { cmd &= ~(0x4000); } Int64 nSessionID = reqMsg.SessionId; if (m_dictCmd2Func.ContainsKey(cmd) == false) { FFLog.Error(string.Format("worker cmd invalid! {0}", cmd)); return(RPC_NONE); } CmdRegInfo cmdRegInfo = m_dictCmd2Func[cmd]; cmdRegInfo.cmdHandler(nSessionID, reqMsg.Cmd, reqMsg.Body); PerfMonitor.Instance().AddPerf(string.Format("cmd={0}", cmdRegInfo.cmdName), DateTime.Now.Ticks / 10 - nBeginUs); return(RPC_NONE); }