Example #1
0
 /// <summary>
 /// Create a new key database in a location.
 /// </summary>
 public EncryptionKeyDB(string folderName)
 {
     Instance = this;
     this.folderName = folderName;
     //Load mek files (matrix encryption keys)
     if (!Directory.Exists(folderName)) Directory.CreateDirectory(folderName);
     var files = Directory.GetFiles(this.folderName, "*.mek");
     if(files.Length == 0)
     {
         //Generate a new key
         AES newKey = new AES(Encoding.UTF8);
         newKey.KeyToFile(this.folderName+"/DefaultKey.mek");
         File.WriteAllText(this.folderName+"/DefaultKey.txt", "There were no keys, so this default key was generated for you.");
         files = Directory.GetFiles(this.folderName, "*.mek");
     }
     foreach(var file in files)
     {
         using (var md5 = MD5.Create())
         {
             using (var stream = File.OpenRead(file))
             {
                 var hash = md5.ComputeHash(stream);
                 keys[hash] = new AES(Encoding.UTF8, file);
             }
         }
     }
 }
Example #2
0
        public static void Main(string[] args)
        {
            log4net.Config.XmlConfigurator.Configure();
            log.Info("=== Matrix Master Server Launching ===");

            keyDb = new EncryptionKeyDB("EncryptionKeys");

            manager = new NodeManager("CompiledNodes");
            manager.Initialize();
            manager.LogLoadedModules();

            INodeController controller = manager.InstantiateNodeController();
            if(controller == null)
            {
                log.Error("No INodeController found, the server will not do anything! Exiting...");
                manager.Shutdown();
                Console.ReadLine();
                return;
            }
            hostInterface = new HostInterface(Settings.Default.Port, controller);
            pool = new NodePool(hostInterface);
            hostInterface.Startup();

            nodeLibraryManager = new NodeLibraryManager("CompiledNodes");
            nodeLibraryManager.Initialize();

            host = new NodeHost("CompiledNodes");
            log.Debug("Test download uri: "+host.GetDownloadUrl("MMOController.dll"));

            var controllerRmiType = manager.ControllerRMIType();
            if(controllerRmiType == null)
            {
                log.Error("The node controller does not have an RMI interface! It will not function properly!");
            }
            else
                pool.RegisterNode(new NodeInfo()
                {
                    HostID = new byte[1],
                    Id = 0,
                    RMITypeName = controllerRmiType.FullName,
                    RMIResolvedType = controllerRmiType
                });

            var webServer = NodeWebServer.Create(Settings.Default.HTTPPort);

            Console.WriteLine("Press any key to quit...");
            Console.ReadLine();

            Console.WriteLine("Shutting down...");
            webServer.Stop();
            manager.Shutdown();
            Console.WriteLine("Manager shutdown...");
            hostInterface.Shutdown();
        }