Ejemplo n.º 1
0
        public long LoadSolarSystem(int solarSystemID)
        {
            if (this.IsSolarSystemLoaded(solarSystemID) == true)
            {
                return(this.mLoadedSolarSystems[solarSystemID]);
            }

            // sort nodes by amount of loaded solar systems and get the one with less solar systems in it
            List <NodeConnection> sortedList = this.ConnectionManager.Nodes.Values.OrderBy(x => x.SolarSystemLoadedCount).ToList();
            NodeConnection        node       = sortedList.First();

            node.SolarSystemLoadedCount++;

            this.MarkSolarSystemAsLoaded(solarSystemID, node.NodeID);

            return(node.NodeID);
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            try
            {
                sContainer = new Container();

                sContainer.Register <Logger>(Lifestyle.Singleton);
                sContainer.Register <DatabaseConnection>(Lifestyle.Singleton);
                sContainer.Register <LoginQueue>(Lifestyle.Singleton);
                sContainer.Register <ConnectionManager>(Lifestyle.Singleton);
                sContainer.Register <SystemManager>(Lifestyle.Singleton);
                sContainer.RegisterInstance(General.LoadFromFile("configuration.conf", sContainer));

                sContainer.Register <AccountDB>(Lifestyle.Singleton);
                sContainer.Register <GeneralDB>(Lifestyle.Singleton);
                sContainer.Register <SolarSystemDB>(Lifestyle.Singleton);
                // disable auto-verification on the container as it triggers creation of instances before they're needed
                sContainer.Options.EnableAutoVerification = false;

                // setup logging
                sLog = sContainer.GetInstance <Logger>();
                // initialize main logging channel
                sChannel = sLog.CreateLogChannel("main");
                // add console log streams
                sLog.AddLogStream(new ConsoleLogStream());

                // load server's configuration
                sConfiguration = sContainer.GetInstance <General>();

                if (sConfiguration.LogLite.Enabled == true)
                {
                    sLog.AddLogStream(new LogLiteStream("ClusterController", sLog, sConfiguration.LogLite));
                }
                if (sConfiguration.FileLog.Enabled == true)
                {
                    sLog.AddLogStream(new FileLogStream(sConfiguration.FileLog));
                }

                // run a thread for log flushing
                new Thread(() =>
                {
                    while (true)
                    {
                        sLog.Flush();
                        Thread.Sleep(1);
                    }
                }).Start();

                sChannel.Info("Initializing EVESharp Cluster Controler and Proxy");
                sChannel.Fatal("Initializing EVESharp Cluster Controler and Proxy");
                sChannel.Error("Initializing EVESharp Cluster Controler and Proxy");
                sChannel.Warning("Initializing EVESharp Cluster Controler and Proxy");
                sChannel.Debug("Initializing EVESharp Cluster Controler and Proxy");
                sChannel.Trace("Initializing EVESharp Cluster Controler and Proxy");

                sConnectionManager = sContainer.GetInstance <ConnectionManager>();

                // initialize system manager information
                sContainer.GetInstance <SystemManager>().Init(sConnectionManager);

                Listening listening = sContainer.GetInstance <Listening>();

                try
                {
                    sChannel.Trace($"Initializing server socket on port {listening.Port}...");
                    sServerSocket = new EVEServerSocket(listening.Port, sLog.CreateLogChannel("ServerSocket"));
                    sServerSocket.Listen();
                    sServerSocket.BeginAccept(acceptAsync);
                    sChannel.Debug($"Waiting for incoming connections on port {listening.Port}");
                }
                catch (Exception e)
                {
                    sChannel.Error($"Error listening on port {listening.Port}: {e.Message}");
                    throw;
                }

                long lastPickedNodeID = 0;

                while (true)
                {
                    // sleep for ten minutes
                    Thread.Sleep(1000 * 60 * 10);

                    // check for any nodes available and pick one from the list to handle timed events
                    lock (sConnectionManager.Nodes)
                    {
                        // ignore the timed events if there's no nodes to handle them
                        if (sConnectionManager.Nodes.Count == 0)
                        {
                            continue;
                        }

                        // get the first available node and request it to handle the timed events
                        // TODO: ASSIGN SOME KIND OF LOAD INDICATION TO NODES TO ENSURE THAT ONLY LOW-LOADED ONES ARE USED?
                        NodeConnection node = null;
                        try
                        {
                            // get the next node available
                            node = sConnectionManager.Nodes.First(x => x.Key > lastPickedNodeID).Value;
                        }
                        catch (InvalidOperationException)
                        {
                            // no extra node was found, so the first one has to be used
                            node = sConnectionManager.Nodes.First().Value;
                        }

                        lastPickedNodeID = node.NodeID;

                        sConnectionManager.NotifyNode(lastPickedNodeID, "OnClusterTimer", new PyTuple(0));
                        sChannel.Info($"Requested node {lastPickedNodeID} to handle cluster-wide timed events");
                    }
                }
            }
            catch (Exception e)
            {
                if (sLog is null || sChannel is null)
                {
                    Console.WriteLine(e.ToString());
                }
Ejemplo n.º 3
0
 public void RemoveNodeConnection(NodeConnection connection)
 {
     // TODO: CHECK FOR PROXY NODE BEING DELETED AND TRY TO ASSIGN ANY OTHER
     lock (this.Nodes)
         this.Nodes.Remove(connection.NodeID);
 }