internal Deny(ulong accountId, string nickname)
 {
     Id       = DenyIdGenerator.GetNextId();
     DenyId   = accountId;
     Nickname = nickname;
 }
Exemple #2
0
        private static void Main()
        {
            JsonConvert.DefaultSettings = () => new JsonSerializerSettings
            {
                Converters = new List <JsonConverter> {
                    new IPEndPointConverter()
                }
            };

            var jsonlog = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "auth.json");
            var logfile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "auth.log");

            Log.Logger = new LoggerConfiguration()
                         .WriteTo.File(new JsonFormatter(), jsonlog)
                         .WriteTo.File(logfile)
                         .WriteTo.Console(outputTemplate: "[{Level} {SourceContext}] {Message}{NewLine}{Exception}")
                         .MinimumLevel.Verbose()
                         .CreateLogger();

            AppDomain.CurrentDomain.UnhandledException += OnUnhandledException;
            TaskScheduler.UnobservedTaskException      += OnUnobservedTaskException;

            Log.Information("Initializing...");

            AuthDatabase.Initialize();
            GameDatabase.Initialize();

            ItemIdGenerator.Initialize();
            CharacterIdGenerator.Initialize();
            LicenseIdGenerator.Initialize();
            DenyIdGenerator.Initialize();

            ChatServer.Initialize(new Configuration());
            RelayServer.Initialize(new Configuration());
            GameServer.Initialize(new Configuration());

            FillShop();

            Log.Information("Starting server...");

            var listenerThreads = new MultithreadEventLoopGroup(Config.Instance.ListenerThreads);
            var workerThreads   = new MultithreadEventLoopGroup(Config.Instance.WorkerThreads);

            ChatServer.Instance.Listen(Config.Instance.ChatListener, listenerEventLoopGroup: listenerThreads, workerEventLoopGroup: workerThreads);
            RelayServer.Instance.Listen(Config.Instance.RelayListener, IPAddress.Parse(Config.Instance.IP), Config.Instance.RelayUdpPorts, listenerThreads, workerThreads);
            GameServer.Instance.Listen(Config.Instance.Listener, listenerEventLoopGroup: listenerThreads, workerEventLoopGroup: workerThreads);

            Log.Information("Ready for connections!");

            if (Config.Instance.NoobMode)
            {
                Log.Warning("!!! NOOB MODE IS ENABLED! EVERY LOGIN SUCCEEDS AND OVERRIDES ACCOUNT LOGIN DETAILS !!!");
            }

            Console.CancelKeyPress += OnCancelKeyPress;
            while (true)
            {
                var input = Console.ReadLine();
                if (input == null)
                {
                    break;
                }

                if (input.Equals("exit", StringComparison.InvariantCultureIgnoreCase) ||
                    input.Equals("quit", StringComparison.InvariantCultureIgnoreCase) ||
                    input.Equals("stop", StringComparison.InvariantCultureIgnoreCase))
                {
                    break;
                }

                var args = input.GetArgs();
                if (args.Length == 0)
                {
                    continue;
                }

                if (!GameServer.Instance.CommandManager.Execute(null, args))
                {
                    Console.WriteLine("Unknown command");
                }
            }

            Exit();
        }
Exemple #3
0
        private static void Main()
        {
            JsonConvert.DefaultSettings = () => new JsonSerializerSettings
            {
                Converters = new List <JsonConverter> {
                    new IPEndPointConverter()
                }
            };

            Config <Config> .Initialize("game.hjson", "NETSPHEREPIRATES_GAMECONF");

            var jsonlog = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "game.json");
            var logfile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "game.log");

            Log.Logger = new LoggerConfiguration()
                         .Destructure.ByTransforming <IPEndPoint>(endPoint => endPoint.ToString())
                         .Destructure.ByTransforming <EndPoint>(endPoint => endPoint.ToString())
                         .WriteTo.File(new JsonFormatter(), jsonlog)
                         .WriteTo.File(logfile)
                         .WriteTo.Console(outputTemplate: "[{Level} {SourceContext}] {Message}{NewLine}{Exception}")
                         .MinimumLevel.Debug()
                         .CreateLogger();

            AppDomain.CurrentDomain.UnhandledException += OnUnhandledException;
            TaskScheduler.UnobservedTaskException      += OnUnobservedTaskException;

            Log.Information("Initializing...");

            try
            {
                AuthDatabase.Initialize(Config.Instance.Database.Auth);
                GameDatabase.Initialize(Config.Instance.Database.Game);
            }
            catch (DatabaseNotFoundException ex)
            {
                Log.Error("Database {Name} not found", ex.Name);
                Environment.Exit(1);
            }
            catch (DatabaseVersionMismatchException ex)
            {
                Log.Error("Invalid version. Database={CurrentVersion} Required={RequiredVersion}. Run the DatabaseMigrator to update your database.",
                          ex.CurrentVersion, ex.RequiredVersion);
                Environment.Exit(1);
            }

            ItemIdGenerator.Initialize();
            CharacterIdGenerator.Initialize();
            LicenseIdGenerator.Initialize();
            DenyIdGenerator.Initialize();
            Club.Initialize();

            var listenerThreads = new MultithreadEventLoopGroup(Config.Instance.ListenerThreads);
            var workerThreads   = new MultithreadEventLoopGroup(Config.Instance.WorkerThreads);
            var workerThread    = new SingleThreadEventLoop();

            ChatServer.Initialize(new ProudNet.Configuration
            {
                SocketListenerThreads = listenerThreads,
                SocketWorkerThreads   = workerThreads,
                WorkerThread          = workerThread
            });
            RelayServer.Initialize(new ProudNet.Configuration
            {
                SocketListenerThreads = listenerThreads,
                SocketWorkerThreads   = workerThreads,
                WorkerThread          = workerThread
            });
            GameServer.Initialize(new ProudNet.Configuration
            {
                SocketListenerThreads = listenerThreads,
                SocketWorkerThreads   = workerThreads,
                WorkerThread          = workerThread
            });

            FillShop();

            Log.Information("Starting server...");

            ChatServer.Instance.Listen(Config.Instance.ChatListener);
            RelayServer.Instance.Listen(Config.Instance.RelayListener, IPAddress.Parse(Config.Instance.IP), Config.Instance.RelayUdpPorts);
            GameServer.Instance.Listen(Config.Instance.Listener);

            Log.Information("Ready for connections!");

            if (Config.Instance.NoobMode)
            {
                Log.Warning("!!! NOOB MODE IS ENABLED! EVERY LOGIN SUCCEEDS AND OVERRIDES ACCOUNT LOGIN DETAILS !!!");
            }

            Console.CancelKeyPress += OnCancelKeyPress;
            while (true)
            {
                var input = Console.ReadLine();
                if (input == null)
                {
                    break;
                }

                if (input.Equals("exit", StringComparison.InvariantCultureIgnoreCase) ||
                    input.Equals("quit", StringComparison.InvariantCultureIgnoreCase) ||
                    input.Equals("stop", StringComparison.InvariantCultureIgnoreCase))
                {
                    break;
                }

                var args = input.GetArgs();
                if (args.Length == 0)
                {
                    continue;
                }

                if (!GameServer.Instance.CommandManager.Execute(null, args))
                {
                    Console.WriteLine("Unknown command");
                }
            }

            Exit();
        }
        private static void Main()
        {
            JsonConvert.DefaultSettings = () => new JsonSerializerSettings
            {
                Converters = new List <JsonConverter> {
                    new IPEndPointConverter()
                }
            };

            Shaolinq.Logging.LogProvider.IsDisabled = true;

            AppDomain.CurrentDomain.UnhandledException += OnUnhandledException;
            TaskScheduler.UnobservedTaskException      += OnUnobservedTaskException;

            Logger.Info()
            .Message("Checking database...")
            .Write();

            AuthDatabase.Instance.CreateIfNotExist();

            using (var scope = new DataAccessScope(DataAccessIsolationLevel.Unspecified, TimeSpan.FromMinutes(5)))
                GameDatabase.Instance.CreateIfNotExist();

            FillShop();

            ItemIdGenerator.Initialize();
            CharacterIdGenerator.Initialize();
            LicenseIdGenerator.Initialize();
            DenyIdGenerator.Initialize();

            Logger.Info()
            .Message("Starting server...")
            .Write();

            GameServer.Instance.Start(Config.Instance.Listener);

            Logger.Info()
            .Message("Ready for connections!")
            .Write();

            if (Config.Instance.NoobMode)
            {
                Logger.Warn()
                .Message("!!! NOOB MODE IS ENABLED! EVERY LOGIN SUCCEEDS AND OVERRIDES ACCOUNT LOGIN DETAILS !!!")
                .Write();
            }

            Console.CancelKeyPress += OnCancelKeyPress;
            while (true)
            {
                var input = Console.ReadLine();
                if (input == null)
                {
                    break;
                }

                if (input.Equals("exit", StringComparison.InvariantCultureIgnoreCase) ||
                    input.Equals("quit", StringComparison.InvariantCultureIgnoreCase) ||
                    input.Equals("stop", StringComparison.InvariantCultureIgnoreCase))
                {
                    break;
                }

                var args = input.GetArgs();
                if (args.Length == 0)
                {
                    continue;
                }

                if (!GameServer.Instance.CommandManager.Execute(null, args))
                {
                    Console.WriteLine("Unknown command");
                }
            }

            Exit();
        }