예제 #1
0
        public bool Init(string strBrokerHost, int nWorkerIndex, string[] listEnableClassNames)
        {
            m_nWorkerIndex  = nWorkerIndex;
            m_strWorkerName = string.Format("worker#{0}", m_nWorkerIndex);
            m_ffrpc         = new FFRpc(m_strWorkerName);
            if (m_ffrpc.Open(strBrokerHost) == false)
            {
                FFLog.Error("worker ffrpc open failed!");
                return(false);
            }

            m_ffrpc.Reg <RouteLogicMsgReq, EmptyMsgRet>(this.OnRouteLogicMsgReq);
            m_ffrpc.Reg <SessionOfflineReq, EmptyMsgRet>(this.OnSessionOfflineReq);
            m_ffrpc.Reg <SessionEnterWorkerReq, EmptyMsgRet>(this.OnSessionEnterWorkerReq);

            string err = Util.InitClassByNames(listEnableClassNames);

            if (err != "")
            {
                FFLog.Error("worker init failed mod=" + err);
                return(false);
            }

            m_listEnableClassNames = listEnableClassNames;

            return(true);
        }
예제 #2
0
파일: main.cs 프로젝트: xcschina/h2engine
        public static void Main(string[] args)
        {
            string   host     = "tcp://127.0.0.1:43210";
            FFBroker ffbroker = new FFBroker();

            ffbroker.Open(host);

            string strServiceName = "worker#0";
            FFRpc  ffrpc          = new FFRpc(strServiceName);

            if (ffrpc.Open(host) == false)
            {
                FFLog.Trace("ffrpc open failed!");
            }
            ffrpc.Reg((SessionEnterWorkerReq req) =>
            {
                FFLog.Trace(string.Format("ffrpc SessionEnterWorkerReq £¡£¡£¡FromGate={0}", req.From_gate));
                return(req);
            });
            Console.ReadKey();
            ffrpc.GetTaskQueue().Post(() =>
            {
                SessionEnterWorkerReq reqMsg = new SessionEnterWorkerReq()
                {
                    From_gate = "gate#0"
                };
                WorkerCallMsgReq reqWorkerCall = new WorkerCallMsgReq();
                //ffrpc.Call(strServiceName, reqMsg);
                reqMsg.From_gate = "gate#1";
                ffrpc.Call(strServiceName, reqWorkerCall, (SessionEnterWorkerReq retMsg) =>
                {
                    FFLog.Trace(string.Format("ffrpc SessionEnterWorkerReq return£¡£¡£¡FromGate={0}", retMsg.From_gate));
                });
            });

            //FFNet.Timerout(1000, Theout);
            //FFNet.Timerout(2000, Theout);
            FFNet.Timerout(100000, () =>
            {
                FFLog.Debug("AAAAAAAAAAAAAAA1");
                ffrpc.Close();
            });
            FFLog.Trace(string.Format("main! {0}", System.Threading.Thread.CurrentThread.ManagedThreadId.ToString()));

            AppDomain.CurrentDomain.ProcessExit += (sender, arg) =>
            {
                FFLog.Trace("exist!!");
            };
            Console.CancelKeyPress += (object sender, ConsoleCancelEventArgs e) => {
                e.Cancel = true;
                FFLog.Trace("exist3!!");

                FFNet.Cleanup();
                FFLog.Cleanup();
            };
            Console.ReadKey();
            FFLog.Trace("exist!!");
            FFNet.Cleanup();
            FFLog.Cleanup();
        }
예제 #3
0
        public bool Init(string strBrokerHost, string strGateListenIpPort, int nGateIndex = 0)
        {
            m_nGateIndex  = nGateIndex;
            m_strGateName = string.Format("gate#{0}", m_nGateIndex);
            m_ffrpc       = new FFRpc(m_strGateName);
            if (m_ffrpc.Open(strBrokerHost) == false)
            {
                FFLog.Error("gate ffrpc open failed!");
                return(false);
            }

            m_ffrpc.Reg <GateChangeLogicNodeReq, EmptyMsgRet>(this.ChangeSessionLogic);
            m_ffrpc.Reg <GateCloseSessionReq, EmptyMsgRet>(this.CloseSession);
            m_ffrpc.Reg <GateRouteMsgToSessionReq, EmptyMsgRet>(this.RouteMsgToSession);
            m_ffrpc.Reg <GateBroadcastMsgToSessionReq, EmptyMsgRet>(this.BroadcastMsgToSession);

            m_acceptor = FFNet.Listen(strGateListenIpPort, new SocketMsgHandler(HandleMsg), new SocketBrokenHandler(HandleBroken));
            if (m_acceptor != null)
            {
                FFLog.Trace(string.Format("FFGate open....{0} ok", strGateListenIpPort));
            }
            else
            {
                FFLog.Error(string.Format("FFGate open....{0} failed", strGateListenIpPort));
            }
            return(true);
        }
예제 #4
0
 public FFGate(string strName = "gate#0")
 {
     m_nIDGenerator = 0;
     m_nGateIndex   = 0;
     m_strGateName  = strName;
     m_ffrpc        = null;
     m_dictClients  = new Dictionary <Int64, ClientInfo>();
     m_msgEmpty     = new EmptyMsgRet();
     m_acceptor     = null;
 }
예제 #5
0
파일: main.cs 프로젝트: zhuanghy/h2engine
        public static void Main(string[] args)
        {
            FFRpc ffrpc = new FFRpc("worker#0");

            if (ffrpc.open("127.0.0.1:43210") == false)
            {
                Console.WriteLine("ffrpc open failed!");
            }
            Console.ReadKey();
        }
예제 #6
0
 public FFWorker()
 {
     m_nIDGenerator         = 0;
     m_nWorkerIndex         = 0;
     m_strWorkerName        = "";
     m_strDefaultGate       = "gate#0";
     m_ffrpc                = null;
     m_dictCmd2Func         = new Dictionary <int, CmdRegInfo>();
     RPC_NONE               = new EmptyMsgRet();
     m_listEnableClassNames = null;
 }
예제 #7
0
        public bool Open(string strBrokerHost, int nWorkerIndex)
        {
            m_nWorkerIndex  = nWorkerIndex;
            m_strWorkerName = string.Format("worker#{0}", m_nWorkerIndex);
            m_ffrpc         = new FFRpc(m_strWorkerName);
            if (m_ffrpc.Open(strBrokerHost) == false)
            {
                FFLog.Error("worker ffrpc open failed!");
                return(false);
            }

            m_ffrpc.Reg <RouteLogicMsgReq, EmptyMsgRet>(this.OnRouteLogicMsgReq);
            m_ffrpc.Reg <SessionOfflineReq, EmptyMsgRet>(this.OnSessionOfflineReq);

            return(true);
        }
예제 #8
0
        public FFWorker()
        {
            m_nIDGenerator   = 0;
            m_nWorkerIndex   = 0;
            m_strWorkerName  = "";
            m_strDefaultGate = "gate#0";
            m_ffrpc          = null;
            m_dictRoles      = new Dictionary <Int64, Role>();
            m_dictCmd2Func   = new Dictionary <int, CmdHandler>();
            RPC_NONE         = new EmptyMsgRet();

            this.BindHandler <Pbmsg.LoginReq>(Pbmsg.ClientCmdDef.CLogin, this.HandleLogin)
            .BindHandler <Pbmsg.RunReq>(Pbmsg.ClientCmdDef.CRun, this.HandleRun)
            .BindHandler <Pbmsg.AttackReq>(Pbmsg.ClientCmdDef.CAttack, this.HandleAttack)
            ;
            int nGenId = 80;

            nGenId++; m_dictRoles[nGenId] = new Monster()
            {
                nSessionID = nGenId, strName = "大怪物1", x = 29, y = 29
            };
            nGenId++; m_dictRoles[nGenId] = new Monster()
            {
                nSessionID = nGenId, strName = "大怪物2", x = 42, y = 27
            };
            nGenId++; m_dictRoles[nGenId] = new Monster()
            {
                nSessionID = nGenId, strName = "大怪物3", x = 48, y = 19
            };
            nGenId++; m_dictRoles[nGenId] = new Monster()
            {
                nSessionID = nGenId, strName = "大怪物4", x = 52, y = 31
            };
            nGenId++; m_dictRoles[nGenId] = new Monster()
            {
                nSessionID = nGenId, strName = "大怪物5", x = 45, y = 45
            };
            nGenId++; m_dictRoles[nGenId] = new Monster()
            {
                nSessionID = nGenId, strName = "大怪物6", x = 51, y = 60
            };
        }
예제 #9
0
        public FFWorker()
        {
            m_nIDGenerator   = 0;
            m_nWorkerIndex   = 0;
            m_strWorkerName  = "";
            m_strDefaultGate = "gate#0";
            m_ffrpc          = null;
            m_dictRoles      = new Dictionary <Int64, Role>();
            m_dictCmd2Func   = new Dictionary <int, CmdHandler>();
            RPC_NONE         = new EmptyMsgRet();

            this.BindHandler <Pbmsg.LoginReq>(Pbmsg.ClientCmdDef.CLogin, this.HandleLogin)
            .BindHandler <Pbmsg.RunReq>(Pbmsg.ClientCmdDef.CRun, this.HandleRun)
            .BindHandler <Pbmsg.AttackReq>(Pbmsg.ClientCmdDef.CAttack, this.HandleAttack)
            ;
            int nGenId = 10000;
            int num    = 0;

            for (int i = 0; i < 3; ++i)
            {
                string strName = string.Format("尸霸{0}", i + 1);
                nGenId++; m_dictRoles[nGenId] = new Monster()
                {
                    nSessionID = nGenId, strName = strName, x = 18 + 20 - (int)MapCfg.CenterX + i * 2, y = 28 + 30 - (int)MapCfg.CenterY - i, apprID = 69
                };
            }
            for (int i = 0; i < num; ++i)
            {
                string strName = string.Format("蓝魔{0}", i + 1);
                nGenId++; m_dictRoles[nGenId] = new Monster()
                {
                    nSessionID = nGenId, strName = strName, x = 12 + 20 - (int)MapCfg.CenterX + i * 2, y = 32 + 30 - (int)MapCfg.CenterY - i, apprID = 102
                };
            }
            for (int i = 0; i < num; ++i)
            {
                string strName = string.Format("山魔{0}", i + 1);
                nGenId++; m_dictRoles[nGenId] = new Monster()
                {
                    nSessionID = nGenId, strName = strName, x = 15 + 20 - (int)MapCfg.CenterX + i * 2, y = 40 + 30 - (int)MapCfg.CenterY - i, apprID = 103
                };
            }
            for (int i = 0; i < num; ++i)
            {
                string strName = string.Format("黑暗魔王{0}", i + 1);
                nGenId++; m_dictRoles[nGenId] = new Monster()
                {
                    nSessionID = nGenId, strName = strName, x = 20 + 20 - (int)MapCfg.CenterX + i * 2, y = 40 + 30 - (int)MapCfg.CenterY - i, apprID = 104
                };
            }
            for (int i = 0; i < num; ++i)
            {
                string strName = string.Format("双足蜥蜴{0}", i + 1);
                nGenId++; m_dictRoles[nGenId] = new Monster()
                {
                    nSessionID = nGenId, strName = strName, x = 25 + 20 - (int)MapCfg.CenterX + i * 2, y = 39 + 30 - (int)MapCfg.CenterY - i, apprID = 105
                };
            }
            for (int i = 0; i < num; ++i)
            {
                string strName = string.Format("变异蜘蛛{0}", i + 1);
                nGenId++; m_dictRoles[nGenId] = new Monster()
                {
                    nSessionID = nGenId, strName = strName, x = 25 + 20 - (int)MapCfg.CenterX + i * 2, y = 28 + 30 - (int)MapCfg.CenterY - i, apprID = 106
                };
            }
            for (int i = 0; i < num; ++i)
            {
                string strName = string.Format("土妖{0}", i + 1);
                nGenId++; m_dictRoles[nGenId] = new Monster()
                {
                    nSessionID = nGenId, strName = strName, x = 16 + 20 - (int)MapCfg.CenterX + i * 2, y = 30 - i, apprID = 100
                };
            }
            //nGenId++; m_dictRoles[nGenId] = new Monster() { nSessionID = nGenId, strName = "大怪物2", x = 42 + xOffset, y = 27 + yOffset, apprID = 10002};
            //nGenId++; m_dictRoles[nGenId] = new Monster() { nSessionID = nGenId, strName = "大怪物3", x = 48 + xOffset, y = 19 + yOffset, apprID = 10003};
            //nGenId++; m_dictRoles[nGenId] = new Monster() { nSessionID = nGenId, strName = "大怪物4", x = 52 + xOffset, y = 31 + yOffset, apprID = 10004};
            //nGenId++; m_dictRoles[nGenId] = new Monster() { nSessionID = nGenId, strName = "大怪物5", x = 45 + xOffset, y = 45 + yOffset, apprID = 10005};
            //nGenId++; m_dictRoles[nGenId] = new Monster() { nSessionID = nGenId, strName = "大怪物6", x = 51 + xOffset, y = 50 + yOffset, apprID = 10006};
            //nGenId++; m_dictRoles[nGenId] = new Monster() { nSessionID = nGenId, strName = "大怪物7", x = 55 + xOffset, y = 55 + yOffset, apprID = 10007 };
        }