public bool Start()
        {
            if (IsListening)
            {
                return(false);
            }
            try
            {
                string script   = Tool.Combine(Config.Path, "script");
                string cdb      = Tool.Combine(Config.Path, "cards.cdb");
                string windb    = Tool.Combine(Config.Path, "win.db");
                string lflist   = Tool.Combine(Config.Path, "lflist.conf");
                string namelist = Tool.Combine(Program.Config.Path, "namelist.txt");
                string msgfile  = Tool.Combine(Program.Config.Path, "server_msg.txt");
                //	Logger.Debug("script:"+script);
                //	Logger.Debug("windb:"+windb);
                //	Logger.Debug("lflist:"+lflist);
                Api.Init(Config.Path, script, cdb);
                BanlistManager.Init(lflist);
                WinInfo.Init(windb);
                RoomManager.init(namelist);
                Messages.Init(msgfile);
                if (Config.ApiPort > 0)
                {
                    Logger.Info("Connecting api server.");
                    if (!ServerApi.Init(Config.ApiPort))
                    {
                        Logger.Warn("connect api server fail.");
                    }
                    else
                    {
                        Logger.Info("Connect api server ok");
                    }
                }
                m_listener            = new AsyncTcpListener <GameSession>(IPAddress.Any, Config.ServerPort, banmode: Config.isBanIP);
                m_listener.OnConnect += new AsyncTcpListener <GameSession> .ConnectEventHandler(Listener_OnConnect);

                m_listener.OnReceive += new AsyncTcpListener <GameSession> .ReceiveEventHandler(Listener_OnReceive);

                m_listener.OnDisconnect += new AsyncTcpListener <GameSession> .DisconnectEventHandler(Listener_OnDisconnect);

                m_listener.OnCheckClient += new AsyncTcpListener <GameSession> .CheckEventHandler(Listener_OnCheckClient);

                m_listener.Start();
                ServerApi.OnServerInfo(this);
                IsListening = true;
            }
            catch (SocketException)
            {
                Logger.Warn("The " + Config.ServerPort + " port is currently in use.");
                return(false);
            }
            catch (Exception e)
            {
                Logger.Error(e);
                return(false);
            }
            Logger.Info("Listening on port " + Config.ServerPort);
            return(true);
        }
Esempio n. 2
0
		public bool Start()
		{
			if(IsListening) return false;
			try
			{
				string script = Tool.Combine(Config.Path, "script");
				string cdb = Tool.Combine(Config.Path, "cards.cdb");
				string windb = Tool.Combine(Config.Path, "win.db");
				string lflist= Tool.Combine(Config.Path, "lflist.conf");
				string namelist = Tool.Combine(Program.Config.Path, "namelist.txt");
				string msgfile = Tool.Combine(Program.Config.Path, "server_msg.txt");
				//	Logger.Debug("script:"+script);
				//	Logger.Debug("windb:"+windb);
				//	Logger.Debug("lflist:"+lflist);
				Api.Init(Config.Path, script, cdb);
				BanlistManager.Init(lflist);
				WinInfo.Init(windb);
				RoomManager.init(namelist);
				Messages.Init(msgfile);
				if(Config.ApiPort > 0){
					Logger.Info("Connecting api server.");
					if(!ServerApi.Init(Config.ApiPort)){
						Logger.Warn("connect api server fail.");
					}else{
						Logger.Info("Connect api server ok");
					}
				}
				m_listener = new AsyncTcpListener<GameSession>(IPAddress.Any, Config.ServerPort, banmode:Config.isBanIP);
				m_listener.OnConnect    += new AsyncTcpListener<GameSession>.ConnectEventHandler(Listener_OnConnect);
				m_listener.OnReceive    += new AsyncTcpListener<GameSession>.ReceiveEventHandler(Listener_OnReceive);
				m_listener.OnDisconnect += new AsyncTcpListener<GameSession>.DisconnectEventHandler(Listener_OnDisconnect);
				m_listener.OnCheckClient +=new AsyncTcpListener<GameSession>.CheckEventHandler(Listener_OnCheckClient);
				m_listener.Start();
				ServerApi.OnServerInfo(this);
				IsListening = true;
			}
			catch (SocketException)
			{
				Logger.Warn("The " + Config.ServerPort + " port is currently in use.");
				return false;
			}
			catch (Exception e)
			{
				Logger.Error(e);
				return false;
			}
			Logger.Info("Listening on port " + Config.ServerPort);
			return true;
		}
 public bool Start()
 {
     if (IsListening)
     {
         return(true);
     }
     IsListening = true;
     Config.Load();
     //本地api
     InitDeulListener();
     try
     {
         m_apilistener.Start();
     }
     catch (Exception e)
     {
         Logger.Error(e);
     }
     if (Config.Ports != null)
     {
         foreach (int port in Config.Ports)
         {
             ServerProcess server = new ServerProcess(port, Config.ApiPort, Config.ServerExe, Config.Config);
             server.Start();
             Porcess.Add(server);
         }
     }
     else
     {
         Logger.Error("no configs");
     }
     InitRoomListener();
     try
     {
         m_listener.Start();
     }
     catch (Exception e)
     {
         Logger.Error(e);
         Stop();
     }
     if (IsListening)
     {
         infoTimer.Start();
     }
     return(IsListening);
 }