Start() public method

public Start ( String sBindIP, int nPort ) : bool
sBindIP String
nPort int
return bool
示例#1
0
        public static System.Timers.Timer m_LogicTimer; //逻辑处理定时器
        static void Main(string[] args)
        {
            //日志路径
            Log.Instance().Init("./Accserver");
            //异常
            GameBase.Core.GlobalException.InitException();


            //读取全局配置
            MemIniFile ini = new MemIniFile();

            if (!ini.LoadFromFile(TextDefine.GoldConfig))
            {
                return;
            }
            String sIP   = ini.ReadValue(TextDefine.ACCServerSection, TextDefine.NormalIPKey, TextDefine.NormalIP);
            int    nPort = ini.ReadValue(TextDefine.ACCServerSection, TextDefine.NormalPortKey, TextDefine.AccServerPort);

            Console.Title = "AccServer";
            // m_DicSession = new Dictionary<Socket, GameBase.Network.GameSession>();
            //m_DicSession.Clear();
            server.onConnect += new GameBase.Network.TcpServerEvent.OnConnectEventHandler(OnConnect);
            server.onReceive += new GameBase.Network.TcpServerEvent.OnReceiveEventHandler(OnRecv);
            server.onClose   += new GameBase.Network.TcpServerEvent.OnCloseEventHandler(OnClose);
            //启动服务器
            Log.Instance().WriteLog("bind ip:" + sIP + "bindport:" + nPort.ToString());
            if (!server.Start(sIP, nPort))
            {
                Log.Instance().WriteLog("start tcpserver error!");
            }
            Log.Instance().WriteLog("start server success!!");
            //数据包处理
            m_LogicTimer          = new System.Timers.Timer(1);
            m_LogicTimer.Elapsed += new ElapsedEventHandler(LogicTimer);
            m_LogicTimer.Enabled  = true;
            while (true)
            {
                String command = Console.ReadLine();
                if (command == "quit" || command == "exit")
                {
                    server.Stop();
                    Log.Instance().Dispose();
                    break;
                }
            }
        }
示例#2
0
        public static bool Start()
        {
            bool ret = true;
            Log.Instance().Init("./MapServer");
            GlobalException.InitException();
            //载入配置文件
            try
            {
                ConfigManager.Instance().LoadConfig();
                MemIniFile ini = new MemIniFile();
                if (!ini.LoadFromFile(TextDefine.GoldConfig))
                {
                    Log.Instance().WriteLog("load golbalconfig error!");
                    return false;
                }
                String sIP = ini.ReadValue(TextDefine.GameServerSetion, TextDefine.NormalIPKey, TextDefine.NormalIP);
                int nPort = ini.ReadValue(TextDefine.GameServerSetion, TextDefine.NormalPortKey, TextDefine.GameServerPort);

                mTcpServer = new TcpServer();
                mTcpServer.onConnect += new TcpServerEvent.OnConnectEventHandler(OnConnect);
                mTcpServer.onClose += new TcpServerEvent.OnCloseEventHandler(OnClose);
                mTcpServer.onReceive += new TcpServerEvent.OnReceiveEventHandler(OnReceive);
                if (!mTcpServer.Start(sIP, nPort))
                {
                    return false;
                }

            }
            catch (System.Exception ex)
            {
                Log.Instance().WriteLog("启动服务器失败");
                Log.Instance().WriteLog(ex.Message);
                Log.Instance().WriteLog(ex.StackTrace);
                return false;

            }

            return ret;
        }
示例#3
0
        static void Main(string[] args)
        {
            //日志路径
            Log.Instance().Init("./LogicServer");
            //异常
            GameBase.Core.GlobalException.InitException();
            MemIniFile ini = new MemIniFile();
            if (!ini.LoadFromFile(TextDefine.GoldConfig))
            {
                return;
            }
            m_DicSession = new Dictionary<Socket, GameBase.Network.GameSession>();
            m_DicSession.Clear();

            String sIP = ini.ReadValue(TextDefine.LogicServerSection, TextDefine.NormalIPKey, TextDefine.NormalIP);
            int nPort = ini.ReadValue(TextDefine.LogicServerSection, TextDefine.NormalPortKey, TextDefine.LoginServerPort);
            m_Key = ini.ReadValue(TextDefine.GlobalSection, TextDefine.EncodeKey, System.Environment.TickCount);
            m_Key2 = ini.ReadValue(TextDefine.GlobalSection, TextDefine.EncodeKey2, System.Environment.TickCount);
            m_GameServerIP = ini.ReadValue(TextDefine.GameServerSetion,TextDefine.NormalIPKey, TextDefine.NormalIP);
            m_GameServerPort = ini.ReadValue(TextDefine.GameServerSetion, TextDefine.NormalPortKey, TextDefine.GameServerPort);
            server = new TcpServer();
            server.onConnect += new TcpServerEvent.OnConnectEventHandler(OnConnect);
            server.onReceive += new TcpServerEvent.OnReceiveEventHandler(OnReceive);
            server.onClose += new TcpServerEvent.OnCloseEventHandler(OnClose);
            if (!server.Start(sIP, nPort))
            {
                Console.WriteLine("start server error!");
                return;
            }

            //连接dbserver
            mDBPacket = new InternalPacket();
            GenerateKey.Init(m_Key, m_Key2);
            sIP = ini.ReadValue(TextDefine.DBServerSestion, TextDefine.NormalIPKey, TextDefine.NormalIP);
            nPort = ini.ReadValue(TextDefine.DBServerSestion, TextDefine.NormalPortKey, TextDefine.DBServerPort);
            mTcpClient = new GameBase.Network.TcpClient();
            mTcpClient.onConnect += new TcpClientEvent.OnConnectEventHandler(OnDBConnect);
            mTcpClient.onReceive += new TcpClientEvent.OnReceiveEventHandler(OnDBReceive);
            mTcpClient.onClose += new TcpClientEvent.OnCloseEventHandler(OnDBClose);
            mTcpClient.Connect(sIP, nPort);
            //逻辑处理
            Thread logicThread = new Thread(new ThreadStart(LogicTimer));
            logicThread.IsBackground = true;
            logicThread.Start();

            while (true)
            {
               String command = Console.ReadLine();
               if (command == "exit")
               {
                   break;
               }
            }
        }
示例#4
0
        static void Main(string[] args)
        {
            //日志路径
            Log.Instance().Init("./DBServer");
            //异常
            GameBase.Core.GlobalException.InitException();
            MemIniFile ini = new MemIniFile();

            if (!ini.LoadFromFile(TextDefine.GoldConfig))
            {
                return;
            }
            //载入名称过滤文件
            if (!Filter.Instance().LoadFilterNameFile(TextDefine.CONFIG_FILTERNAME))
            {
                Log.Instance().WriteLog("载入名称过滤文件失败");
            }
            //连接mysql
            String sip = ini.ReadValue(TextDefine.MysqlSection, "IP", "127.0.0.1");
            int nPort = ini.ReadValue(TextDefine.MysqlSection, "Port", 3306);
            String sUser = ini.ReadValue(TextDefine.MysqlSection, "User", "root");
            String sPaswd = ini.ReadValue(TextDefine.MysqlSection, "Passwd", "test");
            String sDataBase = ini.ReadValue(TextDefine.MysqlSection, "database", "soul");
            if (!MysqlConn.Connect(sip, nPort, sUser, sPaswd, sDataBase))
            {
                Log.Instance().WriteLog("connect mysql error!");
                return;
            }

            LoadGameKernel();
            //启动tcp服务器=
            sip = ini.ReadValue(TextDefine.DBServerSestion, "IP", "0.0.0.0");
            nPort = ini.ReadValue(TextDefine.DBServerSestion, "Port", 1500);
            mTcpServer = new TcpServer();
            mTcpServer.onConnect += new TcpServerEvent.OnConnectEventHandler(OnConnect);
            mTcpServer.onReceive += new TcpServerEvent.OnReceiveEventHandler(OnReceive);
            mTcpServer.onClose += new TcpServerEvent.OnCloseEventHandler(OnClose);
            if (!mTcpServer.Start(sip, nPort))
            {
                Console.WriteLine("start server error!");
                MysqlConn.Dispose();
                return;
            }
            //启动工作线程-

            Thread logicThread = new Thread(new ThreadStart(LogicRun));
            logicThread.IsBackground = true;
            logicThread.Start();

            while (true)
            {
                String sCommand = Console.ReadLine();
                if(sCommand == "quit" ||
                    sCommand == "exit")
                {
                    break;
                }
            }
            MysqlConn.Dispose();
        }