示例#1
0
        static void AcceptAsync(IAsyncResult ar)
        {
            sChannel.Trace("Incoming connection");
            EVEServerSocket serverSocket = ar.AsyncState as EVEServerSocket;
            EVEClientSocket clientSocket = serverSocket.EndAccept(ar);

            // put the server in accept state again
            serverSocket.BeginAccept(acceptAsync);

            sConnectionManager.AddUnauthenticatedConnection(clientSocket);
        }
示例#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());
                }
示例#3
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;
                }

                while (true)
                {
                    Thread.Sleep(1);
                }
            }
            catch (Exception e)
            {
                if (sLog == null || sChannel == null)
                {
                    Console.WriteLine(e.ToString());
                }
                else
                {
                    sChannel?.Fatal(e.ToString());
                    sLog?.Flush();
                }
            }
        }
示例#4
0
        static void Main(string[] args)
        {
            try
            {
                // setup logging
                sLog = new Logger();
                // initialize main logging channel
                sChannel = sLog.CreateLogChannel("main");
                // add console log streams
                sLog.AddLogStream(new ConsoleLogStream());

                // load server's configuration
                sConfiguration = General.LoadFromFile("configuration.conf");

                // update logger's configuration
                sLog.SetConfiguration(sConfiguration.Logging);

                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");

                sDatabase = DatabaseConnection.FromConfiguration(sConfiguration.Database, sLog);
                sDatabase.Query("SET global max_allowed_packet=1073741824");
                sLoginQueue = new LoginQueue(sConfiguration.Authentication, sDatabase, sLog);
                sLoginQueue.Start();

                sConnectionManager = new ConnectionManager(sLoginQueue, sDatabase, sLog);

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

                while (true)
                {
                    Thread.Sleep(1);
                }
            }
            catch (Exception e)
            {
                sChannel?.Fatal(e.ToString());
                sLog?.Flush();
            }
        }