Exemplo n.º 1
0
        private void InitCluster()
        {
            m_clusterTCPServer = new TCPServer();
            m_tcpObjectContainer.Add(m_clusterTCPServer);

            m_clusterTCPClient = new TCPClient();
            m_tcpObjectContainer.Add(m_clusterTCPClient);

            ClusterServer_Init clusterServerInit = new ClusterServer_Init();

            clusterServerInit.tcp_server_id = m_clusterTCPServer.GetObjectId();
            int clusterServerId = SparkServerUtility.NewService("SparkServer.Framework.Service.ClusterServer.ClusterServer",
                                                                "clusterServer",
                                                                clusterServerInit.encode());

            ClusterClient_Init clusterClientInit = new ClusterClient_Init();

            clusterClientInit.tcp_client_id  = m_clusterTCPClient.GetObjectId();
            clusterClientInit.cluster_config = m_bootConfig["ClusterConfig"].ToString();
            int clusterClientId = SparkServerUtility.NewService("SparkServer.Framework.Service.ClusterClient.ClusterClient",
                                                                "clusterClient",
                                                                clusterClientInit.encode());

            m_clusterTCPServer.Start(m_clusterServerIp, m_clusterServerPort, 30, clusterServerId,
                                     OnSessionError, OnReadPacketComplete, OnAcceptComplete);
            m_clusterTCPClient.Start(clusterClientId, OnSessionError, OnReadPacketComplete, OnConnectedComplete);
        }
Exemplo n.º 2
0
        protected override void Init()
        {
            base.Init();

            for (int i = 0; i < 100; i++)
            {
                SparkServerUtility.NewService("SparkServer.Game.Process.TestSender.Sender");
            }
        }
Exemplo n.º 3
0
        private void TestSendSkynetRequest()
        {
            BootServices boot = delegate()
            {
                SparkServerUtility.NewService("SparkServer.Test.SendSkynetRequest.SkynetMessageSender", "SendSkynetMsg");
            };
            Server server = new Server();

            server.Run("../../Test/SendSkynetRequest/Resource/Config/Startup.json", boot);
        }
Exemplo n.º 4
0
        private void RPCTestClient()
        {
            BootServices boot = delegate()
            {
                SparkServerUtility.NewService("SparkServer.Test.RPC.TestClient.TestClient", "RPCTestClient");
            };
            Server server = new Server();

            server.Run("../../Test/RPC/Resource/Config/TestClientStartup.json", boot);
        }
Exemplo n.º 5
0
        static void Main(string[] args)
        {
            string inputMode = args[0];
            int    mode      = 0;

            if (inputMode == "TestCases")
            {
                mode = 1;
            }
            else if (inputMode == "SparkServer")
            {
                mode = 2;
            }
            else
            {
                Console.WriteLine("Unknow input mode {0}", inputMode);
                return;
            }

            switch (mode)
            {
            case 1:
            {
                string caseName = args[1];

                TestCases testCases = new TestCases();
                testCases.Run(caseName);
            } break;

            case 2:
            {
                string bootService     = args[1];
                string bootPath        = args[2];
                string bootServiceName = "";

                if (args.Length >= 4)
                {
                    bootServiceName = args[3];
                }

                BootServices startFunc = delegate()
                {
                    SparkServerUtility.NewService(bootService, bootServiceName);
                };

                Server battleServer = new Server();
                battleServer.Run(bootPath, startFunc);
            } break;

            default:
            {
                Console.WriteLine("Mode:{0} not supported", mode);
            } break;
            }
        }
Exemplo n.º 6
0
        protected override void Init()
        {
            base.Init();

            for (int i = 0; i < 8; i++)
            {
                int serviceId = SparkServerUtility.NewService("SparkServer.Game.Process.Battle.BattleTaskConsumer");
                m_consumerList.Add(serviceId);
            }

            RegisterServiceMethods("OnBattleRequest", OnBattleRequest);
        }
Exemplo n.º 7
0
        private void InitGateway()
        {
            string gatewayClass = m_bootConfig["Gateway"]["Class"].ToString();
            string gatewayName  = m_bootConfig["Gateway"]["Name"].ToString();

            m_tcpGate = new TCPServer();
            m_tcpObjectContainer.Add(m_tcpGate);

            Gateway_Init gateInit = new Gateway_Init();

            gateInit.tcp_server_id = m_tcpGate.GetObjectId();

            int gatewayId = SparkServerUtility.NewService(gatewayClass, gatewayName, gateInit.encode());

            m_tcpGate.Start(m_gateIp, m_gatePort, 30, gatewayId, OnSessionError, OnReadPacketComplete, OnAcceptComplete);
        }
Exemplo n.º 8
0
        private void Boot(BootServices customBoot)
        {
            // create global instance first
            m_globalMQ     = GlobalMQ.GetInstance();
            m_serviceSlots = ServiceSlots.GetInstance();
            m_netpackQueue = NetworkPacketQueue.GetInstance();
            m_timer        = SSTimer.GetInstance();

            NetProtocol.GetInstance();

            // create logger service second
            Logger_Init loggerInit = new Logger_Init();

            if (m_bootConfig.ContainsKey("Logger"))
            {
                if (Directory.Exists(m_bootConfig["Logger"].ToString()))
                {
                    loggerInit.logger_path = Path.GetFullPath(m_bootConfig["Logger"].ToString());
                }
                else
                {
                    DirectoryInfo di = Directory.CreateDirectory(m_bootConfig["Logger"].ToString());
                    if (di.Exists)
                    {
                        loggerInit.logger_path = Path.GetFullPath(m_bootConfig["Logger"].ToString());
                    }
                    else
                    {
                        loggerInit.logger_path = "../";
                    }
                }
            }
            else
            {
                loggerInit.logger_path = "../";
            }
            SparkServerUtility.NewService("SparkServer.Framework.Service.Logger.LoggerService", "logger", loggerInit.encode());

            m_tcpObjectContainer = new TCPObjectContainer();
            if (m_bootConfig.ContainsKey("ClusterConfig"))
            {
                InitCluster();
            }

            if (m_bootConfig.ContainsKey("Gateway"))
            {
                InitGateway();
            }

            customBoot();

            LoggerHelper.Info(0, "Start SparkServer Server...");

            for (int i = 0; i < m_workerNum; i++)
            {
                Thread thread = new Thread(new ThreadStart(ThreadWorker));
                thread.Start();
            }

            Thread timerThread = new Thread(new ThreadStart(ThreadTimer));

            timerThread.Start();
        }