Example #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;
        }
Example #2
0
        public WorldSimulation(ServerConfiguration conf, MapManager maps)
        {
            if (conf == null)
                throw new ArgumentNullException("conf");

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

            serverConfiguration = conf;
            mapManager = maps;
            timeBasedActionsManager = new TimeBasedActionsManager();

            pcSerializer = new PlayerCharacterSerializer(serverConfiguration.DataStoragePath);
            pcDeserializer = new PlayerCharacterDeserializer(serverConfiguration.DataStoragePath);
            pcAuthentication = new PlayerCharacterAuthentication(serverConfiguration.DataStoragePath);
        }
Example #3
0
        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.");
        }
Example #4
0
        public static void Main(string[] args)
        {
            // Setting invariant culture
            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
            Thread.CurrentThread.CurrentUICulture = CultureInfo.InvariantCulture;

            initializeVersions();

            // 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.Other, "Calindor Storage Updater v" + CSUVersion.GetVersion());

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

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

            // Start
            logger.LogProgress(LogSource.Other, "BE SURE TO MANUALLY BACKUP STORAGE AT: " + conf.DataStoragePath);
            logger.LogProgress(LogSource.Other, "Press ENTER to continue");
            Console.ReadLine();

            if (op == Operation.Upgrade)
                versions.UpgradeStorage(versionFrom, versionTo, logger, conf.DataStoragePath);

            logger.LogProgress(LogSource.Other, "Finished. (press ENTER)");
            Console.ReadLine();
        }