Ejemplo n.º 1
0
 public void AddSession(Socket s,TcpServer server)
 {
     lock (_lock)
     {
         InternalSession session = new InternalSession(server, s);
         mDicSession[s] = session;
     }
 }
Ejemplo n.º 2
0
 public GameSession(Socket s,TcpServer tcpserver = null)
 {
     server = tcpserver;
     m_Socket = s;
     m_GamePack = new GamePack();
     m_nLastTime = System.Environment.TickCount;
     gameid = IDManager.CreateGameId();
 }
Ejemplo n.º 3
0
 public void AddSession(Socket s, TcpServer server)
 {
     if (IsSession(s))
     {
         Log.Instance().WriteLog("重用套接字..");
     }
     GameSession session = new GameSession(s, server);
     m_DicSession[s] = session;
 }
Ejemplo n.º 4
0
 public void Dispose()
 {
     server = null;
     if (m_Socket != null && m_Socket.Connected)
     {
         m_Socket.Close();
         m_Socket.Dispose();
     }
     m_Socket = null;
     m_GamePack = null;
 }
Ejemplo n.º 5
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;
        }
Ejemplo n.º 6
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;
               }
            }
        }
Ejemplo n.º 7
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();
        }