コード例 #1
0
        public ServerListeningThread(ServerConfiguration conf, CommunicationManager commManager,
            WorldSimulation worldSim)
        {
            if (conf == null)
                throw new ArgumentNullException("conf");

            serverConfiguration = conf;

            if (commManager == null)
                throw new ArgumentNullException("commManager");

            serverCommunicationManager = commManager;

            if (worldSim == null)
                throw new ArgumentNullException("worldSim");

            serverWorldSimulation = worldSim;
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: ago1024/Calindor
        public static void Main(string[] args)
        {
            // Starting server...

            // Setting up culture
            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
            Thread.CurrentThread.CurrentUICulture = CultureInfo.InvariantCulture;

            // Setting working directory
            try
            {
                string workingDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
                Directory.SetCurrentDirectory(workingDirectory);
            }
            catch (Exception ex)
            {
                // Could not set working directory. Exit.
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Working directory not set. Reason: " + ex.ToString());
                Console.ForegroundColor = ConsoleColor.Gray;
                Console.ReadLine();
                return;
            }

            // Parsing command line
            parseCMDLine(args);

            if (shouldExitAfterParsingCommandLine)
                return;

            // Creating logger
            ILogger logger = null;

            try
            {
                logger = new MultiThreadedLogger(Directory.GetCurrentDirectory());
            }
            catch(Exception ex)
            {
                // Logger not created... exiting
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Logger not created. Reason: " + ex.ToString());
                Console.ForegroundColor = ConsoleColor.Gray;
                Console.ReadLine();
                return;
            }

            logger.LogProgress(LogSource.Server, "Calindor v" + ServerVersion.GetVersion());

            logger.LogProgress(LogSource.Server, "Starting up...");

            // Loading configuration
            ServerConfiguration conf = new ServerConfiguration();
            conf.Logger = logger;
            if (!conf.Load("./server_config.xml"))
            {
                logger.LogError(LogSource.Server, "Configuration not loaded. Exiting (press ENTER).", null);
                Console.ReadLine();
                return;
            }

            // Loading maps
            MapManager mapManager = new MapManager(conf);
            mapManager.Logger = logger;
            if (!mapManager.LoadMaps())
            {
                logger.LogError(LogSource.Server, "Maps not scanned. Exiting (press ENTER).", null);
                Console.ReadLine();
                return;
            }
            if (!mapManager.IsStartingMapLoaded())
            {
                logger.LogError(LogSource.Server, "Default map not loaded. Exiting (press ENTER).", null);
                Console.ReadLine();
                return;
            }
            if (!mapManager.IsStartPointWalkable())
            {
                logger.LogError(LogSource.Server, "Default start point not walkable. Exiting (press ENTER).", null);
                Console.ReadLine();
                return;
            }

            // Creating world simulation thread
            worldSim = new WorldSimulation(conf, mapManager);
            worldSim.Logger = logger;
            if (!worldSim.StartSimulation())
            {
                logger.LogError(LogSource.Server, "WorldSimuation not started. Exiting  (press ENTER).", null);
                Console.ReadLine();
                return;
            }

            // Creating communication manager thread
            commManager = new CommunicationManager();
            commManager.Logger = logger;
            commManager.LogNormalOperation = conf.LogNormalOperation;
            commManager.StartManager();

            // Creating server listening thread
            slThread = new ServerListeningThread(conf, commManager, worldSim);
            slThread.Logger = logger;
            if (!slThread.StartListening())
            {
                logger.LogError(LogSource.Server, "Listener not started. Exiting  (press ENTER).", null);
                worldSim.StopSimulation();
                commManager.StopManager();
                Console.ReadLine();
                return;
            }

            logger.LogProgress(LogSource.Server, "Server started.");
        }