private static void Main() { JsonConvert.DefaultSettings = () => new JsonSerializerSettings { Converters = new List <JsonConverter> { new IPEndPointConverter() } }; AppDomain.CurrentDomain.UnhandledException += OnUnhandledException; TaskScheduler.UnobservedTaskException += OnUnobservedTaskException; AuthDatabase.Initialize(); Logger.Info("Starting server..."); AuthServer.Initialize(new Configuration()); AuthServer.Instance.Listen(Config.Instance.Listener); s_apiEventLoopGroup = new MultithreadEventLoopGroup(1); s_apiHost = new ServerBootstrap() .Group(s_apiEventLoopGroup) .Channel <TcpServerSocketChannel>() .Handler(new ActionChannelInitializer <IChannel>(ch => { })) .ChildHandler(new ActionChannelInitializer <IChannel>(ch => { ch.Pipeline.AddLast(new APIServerHandler()); })) .BindAsync(Config.Instance.API.Listener).WaitEx(); Logger.Info("Ready for connections!"); if (Config.Instance.NoobMode) { Logger.Warn("!!! 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; } } Exit(); }
private static string GetNickname(ulong id) { // fast path var plr = GameServer.Instance.PlayerManager[id]; if (plr != null) { return(plr.Account.Nickname); } // if player is not online use a database lookup using (var db = AuthDatabase.Open()) return(db.Get(new AccountDto { Id = (int)id })?.Nickname ?? ""); }
private static void Main() { JsonConvert.DefaultSettings = () => new JsonSerializerSettings { Converters = new List <JsonConverter> { new IPEndPointConverter() } }; AppDomain.CurrentDomain.UnhandledException += OnUnhandledException; TaskScheduler.UnobservedTaskException += OnUnobservedTaskException; AuthDatabase.Initialize(); Logger.Info("Starting server..."); AuthServer.Instance.Start(Config.Instance.Listener); s_apiHost = new APIServer(); s_apiHost.Start(Config.Instance.API.Listener); Logger.Info("Ready for connections!"); if (Config.Instance.NoobMode) { Logger.Warn("!!! 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; } } Exit(); }
internal Deny(PlayerDenyDto dto) { ExistsInDatabase = true; Id = dto.Id; DenyId = (ulong)dto.DenyPlayerId; // Try a fast lookup first in case the player is currently online // otherwise get the name from the database Nickname = GameServer.Instance.PlayerManager[DenyId]?.Account.Nickname; if (Nickname == null) { using (var db = AuthDatabase.Open()) { Nickname = db.Get(new AccountDto { Id = (int)DenyId })?.Nickname ?? "<Player not found>"; } } }
public async Task <bool> SendAsync(string receiver, string title, string message) { // ToDo consume pen // ToDo check for ignore AccountDto account; using (var db = AuthDatabase.Open()) { account = (await db.FindAsync <AccountDto>(statement => statement .Where($"{nameof(AccountDto.Nickname):C} = @{nameof(receiver)}") .WithParameters(new { receiver })) .ConfigureAwait(false)) .FirstOrDefault(); } if (account == null) { return(false); } using (var db = GameDatabase.Open()) { var mailDto = new PlayerMailDto { PlayerId = account.Id, SenderPlayerId = (int)Player.Account.Id, SentDate = DateTimeOffset.Now.ToUnixTimeSeconds(), Title = title, Message = message, IsMailNew = true, IsMailDeleted = false }; await db.InsertAsync(mailDto).ConfigureAwait(false); var plr = GameServer.Instance.PlayerManager.Get(receiver); plr?.Mailbox.Add(new Mail(mailDto)); return(true); } }
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; AuthDatabase.Initialize(); Log.Information("Starting server..."); AuthServer.Initialize(new Configuration()); AuthServer.Instance.Listen(Config.Instance.Listener); s_apiEventLoopGroup = new MultithreadEventLoopGroup(2); s_loginapiHost = new ServerBootstrap() .Group(s_apiEventLoopGroup) .Channel <TcpServerSocketChannel>() .Handler(new ActionChannelInitializer <IChannel>(ch => { })) .ChildHandler(new ActionChannelInitializer <IChannel>(ch => { ch.Pipeline.AddLast(new LoginServerHandler()); })) .BindAsync(Config.Instance.AuthAPI.Listener).WaitEx(); s_apiHost = new ServerBootstrap() .Group(s_apiEventLoopGroup) .Channel <TcpServerSocketChannel>() .Handler(new ActionChannelInitializer <IChannel>(ch => { })) .ChildHandler(new ActionChannelInitializer <IChannel>(ch => { ch.Pipeline.AddLast(new APIServerHandler()); })) .BindAsync(Config.Instance.API.Listener).WaitEx(); 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; } } Exit(); }
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() } }; 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(); }
private static void Main() { JsonConvert.DefaultSettings = () => new JsonSerializerSettings { Converters = new List <JsonConverter> { new IPEndPointConverter() } }; Config <Config> .Initialize("auth.hjson", "NETSPHEREPIRATES_AUTHCONF"); var jsonlog = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "auth.json"); var logfile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "auth.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; try { AuthDatabase.Initialize(Config.Instance.Database.Auth); } 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); } Log.Information("Starting server..."); AuthServer.Initialize(new ProudNet.Configuration { SocketListenerThreads = new MultithreadEventLoopGroup(1), SocketWorkerThreads = new MultithreadEventLoopGroup(1), WorkerThread = new SingleThreadEventLoop() }); AuthServer.Instance.Listen(Config.Instance.Listener); s_apiEventLoopGroup = new MultithreadEventLoopGroup(1); s_apiHost = new ServerBootstrap() .Group(s_apiEventLoopGroup) .Channel <TcpServerSocketChannel>() .Handler(new ActionChannelInitializer <IChannel>(ch => { })) .ChildHandler(new ActionChannelInitializer <IChannel>(ch => { ch.Pipeline.AddLast(new APIServerHandler()); })) .BindAsync(Config.Instance.API.Listener).WaitEx(); 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; } } Exit(); }
private static void Main() { JsonConvert.DefaultSettings = () => new JsonSerializerSettings { Converters = new List <JsonConverter> { new IPEndPointConverter() } }; AppDomain.CurrentDomain.UnhandledException += OnUnhandledException; TaskScheduler.UnobservedTaskException += OnUnobservedTaskException; AuthDatabase.Initialize(); GameDatabase.Initialize(); FillShop(); ItemIdGenerator.Initialize(); CharacterIdGenerator.Initialize(); LicenseIdGenerator.Initialize(); DenyIdGenerator.Initialize(); Logger.Info("Starting server..."); GameServer.Instance.Start(Config.Instance.Listener); Logger.Info("Ready for connections!"); if (Config.Instance.NoobMode) { Logger.Warn("!!! 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(); }
public PlayerClubInfoDto LoadClubInfo(Player plr) { _ClubInfo[plr] = null; using (var db = GameDatabase.Open()) using (var adb = AuthDatabase.Open()) { var member = db.Find <ClubMembersDto>(smtp => smtp .Where($"{nameof(ClubMembersDto.Id):C} = @Player") .WithParameters(new { Player = plr.Account.Id }) ).FirstOrDefault(); if (member == null) { return(null); } var Club = db.Find <ClubDto>(smtp => smtp .Where($"{nameof(ClubDto.Id):C} = @Id") .WithParameters(new { Id = member.ClubId }) ).FirstOrDefault(); if (Club == null) { throw new InvalidOperationException("Club don't exist"); } var Moderator = adb.Find <AccountDto>(stmp => stmp .Include <NicknameHistoryDto>(join => join.LeftOuterJoin()) .Where($"{nameof(AccountDto.Id):C} = @Id") .WithParameters(new { Id = Club.Moderator }) ).FirstOrDefault(); var hasNickNameChanger = from nick in Moderator.NicknameHistory where nick.ExpireDate == -1 || nick.ExpireDate > DateTimeOffset.Now.ToUnixTimeSeconds() orderby nick.Id descending select nick.Nickname; if (hasNickNameChanger.Any()) { Moderator.Nickname = hasNickNameChanger.First(); } _ClubInfo[plr] = new PlayerClubInfoDto { Unk1 = member.State, Unk2 = 2, Unk3 = 3, Unk4 = 4, Unk5 = 5, Unk6 = 6, Unk7 = "Cadena1", Unk8 = "Cadena2", Unk11 = "Cadena3", Unk12 = Club.Notice, ClanName = Club.Name, ClanMark = Club.Mark, ModeratorName = Moderator.Nickname }; return(_ClubInfo[plr]); } }