示例#1
0
 /// <summary>
 /// Creates a new <see cref="PlayerFactory"/> instance.
 /// </summary>
 /// <param name="serviceProvider">Service provider.</param>
 /// <param name="database">Rhisis database access layer.</param>
 /// <param name="gameResources">Game resources.</param>
 /// <param name="mapManager">Map manager.</param>
 /// <param name="behaviorManager">Behavior manager.</param>
 /// <param name="itemFactory">Item factory.</param>
 public PlayerFactory(IServiceProvider serviceProvider, IRhisisDatabase database, IGameResources gameResources, IMapManager mapManager, IBehaviorManager behaviorManager, IItemFactory itemFactory)
 {
     _serviceProvider = serviceProvider;
     _database        = database;
     _gameResources   = gameResources;
     _mapManager      = mapManager;
     _behaviorManager = behaviorManager;
     _itemFactory     = itemFactory;
     _playerFactory   = ActivatorUtilities.CreateFactory(typeof(PlayerEntity), Type.EmptyTypes);
 }
示例#2
0
 /// <summary>
 /// Creates a new <see cref="InventorySystem"/> instance.
 /// </summary>
 /// <param name="logger">Logger.</param>
 /// <param name="database">Rhisis database.</param>
 /// <param name="itemFactory">Item factory.</param>
 /// <param name="inventoryPacketFactory">Inventory packet factory.</param>
 /// <param name="inventoryItemUsage">Inventory item usage system.</param>
 /// <param name="dropSystem">Drop system.</param>
 /// <param name="textPacketFactory">Text packet factory.</param>
 public InventorySystem(ILogger <InventorySystem> logger, IRhisisDatabase database, IItemFactory itemFactory, IInventoryPacketFactory inventoryPacketFactory, IInventoryItemUsage inventoryItemUsage, IDropSystem dropSystem, ITextPacketFactory textPacketFactory)
 {
     _logger                 = logger;
     _database               = database;
     _itemFactory            = itemFactory;
     _inventoryPacketFactory = inventoryPacketFactory;
     _inventoryItemUsage     = inventoryItemUsage;
     _dropSystem             = dropSystem;
     _textPacketFactory      = textPacketFactory;
 }
示例#3
0
        /// <summary>
        /// Creates a new <see cref="ServiceTestBase{TService}"/>.
        /// </summary>
        protected ServiceTestBase()
        {
            LoggerMock = new Mock <ILogger <TService> >();
            Faker      = new Faker();

            var options = new DbContextOptionsBuilder <RhisisDatabaseContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString())
                          .Options;

            Database = new RhisisDatabaseContext(options);
        }
示例#4
0
        /// <inheritdoc />
        //protected override IPacketProcessor PacketProcessor { get; } = new FlyffPacketProcessor();

        /// <summary>
        /// Creates a new <see cref="LoginServer"/> instance.
        /// </summary>
        /// <param name="logger">Logger</param>
        /// <param name="loginConfiguration">Login server configuration.</param>
        /// <param name="iscConfiguration">ISC configuration.</param>
        /// <param name="serviceProvider">Service provider.</param>
        public LoginServer(ILogger <LoginServer> logger, IOptions <LoginConfiguration> loginConfiguration, IServiceProvider serviceProvider, IRhisisDatabase database)
        {
            _logger             = logger;
            _loginConfiguration = loginConfiguration.Value;
            _serviceProvider    = serviceProvider;
            _database           = database;
            PacketProcessor     = new FlyffPacketProcessor();
            ServerConfiguration = new NetServerConfiguration(_loginConfiguration.Host,
                                                             _loginConfiguration.Port,
                                                             ClientBacklog,
                                                             ClientBufferSize);
        }
示例#5
0
 /// <summary>
 /// Creates a new <see cref="ClusterServer"/> instance.
 /// </summary>
 /// <param name="logger">Logger.</param>
 /// <param name="clusterConfiguration">Cluster Server configuration.</param>
 /// <param name="gameResources">Game resources.</param>
 /// <param name="serviceProvider">Service provider.</param>
 public ClusterServer(ILogger <ClusterServer> logger, IOptions <ClusterConfiguration> clusterConfiguration, IGameResources gameResources, IServiceProvider serviceProvider, IRhisisDatabase database)
 {
     _logger = logger;
     ClusterConfiguration = clusterConfiguration.Value;
     _gameResources       = gameResources;
     _serviceProvider     = serviceProvider;
     _database            = database;
     PacketProcessor      = new FlyffPacketProcessor();
     ServerConfiguration  = new NetServerConfiguration(ClusterConfiguration.Host,
                                                       ClusterConfiguration.Port,
                                                       ClientBacklog,
                                                       ClientBufferSize);
 }
示例#6
0
 public SkillSystem(ILogger <SkillSystem> logger, IRhisisDatabase database, IGameResources gameResources, IBattleSystem battleSystem, IInventorySystem inventorySystem, IProjectileSystem projectileSystem, ISkillPacketFactory skillPacketFactory, ITextPacketFactory textPacketFactory, ISpecialEffectPacketFactory specialEffectPacketFactory, IMoverPacketFactory moverPacketFactory)
 {
     _logger                     = logger;
     _database                   = database;
     _gameResources              = gameResources;
     _battleSystem               = battleSystem;
     _inventorySystem            = inventorySystem;
     _projectileSystem           = projectileSystem;
     _skillPacketFactory         = skillPacketFactory;
     _textPacketFactory          = textPacketFactory;
     _specialEffectPacketFactory = specialEffectPacketFactory;
     _moverPacketFactory         = moverPacketFactory;
 }
示例#7
0
        public void OnExecute()
        {
            if (string.IsNullOrEmpty(DatabaseConfigurationFile))
            {
                DatabaseConfigurationFile = ConfigurationConstants.DatabasePath;
            }

            var dbConfig = ConfigurationHelper.Load <DatabaseConfiguration>(DatabaseConfigurationFile, ConfigurationConstants.DatabaseConfiguration);

            if (dbConfig is null)
            {
                Console.WriteLine("Couldn't load database configuration file during execution of user show command.");
                return;
            }

            using IRhisisDatabase database = _databaseFactory.CreateDatabaseInstance(dbConfig);

            DbUser user = database.Users.Include(x => x.Characters).FirstOrDefault(x => x.Username.Equals(Username, StringComparison.OrdinalIgnoreCase));

            if (user == null)
            {
                Console.WriteLine($"Cannot find user with username: '******'.");
            }
            else
            {
                Console.WriteLine("#########################");
                Console.WriteLine("#   User information   #");
                Console.WriteLine("#########################");
                Console.WriteLine($"Username: {user.Username}");
                Console.WriteLine($"Email: {user.Email}");
                Console.WriteLine($"Authority: {user.Authority.ToString()}");
                Console.WriteLine($"Deleted: {user.IsDeleted}");
                Console.WriteLine($"Last connection: {user.LastConnectionTime:yyyy/MM/dd HH:mm:ss}");
                Console.WriteLine($"Play time: {TimeSpan.FromSeconds(user.PlayTime):hh\\:mm\\:ss}");
                Console.WriteLine($"Number of characters: {user.Characters.Count}");

                if (user.Characters.Any())
                {
                    for (int i = 0; i < user.Characters.Count; i++)
                    {
                        DbCharacter character = user.Characters.ElementAt(i);

                        Console.WriteLine("-------------------------");
                        Console.WriteLine($"Character name: {character.Name} (id: {character.Id})");
                        Console.WriteLine($"Deleted: {character.IsDeleted}");
                    }
                }
            }
        }
示例#8
0
 public QuestSystem(ILogger <QuestSystem> logger, IRhisisDatabase database, IGameResources gameResources,
                    IPlayerDataSystem playerDataSystem, IInventorySystem inventorySystem, IExperienceSystem experienceSystem, IJobSystem jobSystem,
                    IQuestPacketFactory questPacketFactory, INpcDialogPacketFactory npcDialogPacketFactory, ITextPacketFactory textPacketFactory)
 {
     _logger                 = logger;
     _database               = database;
     _gameResources          = gameResources;
     _playerDataSystem       = playerDataSystem;
     _inventorySystem        = inventorySystem;
     _experienceSystem       = experienceSystem;
     _jobSystem              = jobSystem;
     _questPacketFactory     = questPacketFactory;
     _npcDialogPacketFactory = npcDialogPacketFactory;
     _textPacketFactory      = textPacketFactory;
 }
示例#9
0
 /// <summary>
 /// Creates a new <see cref="WorldServer"/> instance.
 /// </summary>
 public WorldServer(ILogger <WorldServer> logger, IOptions <WorldConfiguration> worldConfiguration,
                    IWorldServerTaskManager worldServerTaskManager,
                    IGameResources gameResources, IServiceProvider serviceProvider,
                    IMapManager mapManager, IBehaviorManager behaviorManager, IChatCommandManager chatCommandManager, IRhisisDatabase database)
 {
     _logger = logger;
     _worldServerTaskManager = worldServerTaskManager;
     _worldConfiguration     = worldConfiguration.Value;
     _gameResources          = gameResources;
     _serviceProvider        = serviceProvider;
     _mapManager             = mapManager;
     _behaviorManager        = behaviorManager;
     _chatCommandManager     = chatCommandManager;
     _database           = database;
     PacketProcessor     = new FlyffPacketProcessor();
     ServerConfiguration = new NetServerConfiguration(_worldConfiguration.Host, _worldConfiguration.Port, ClientBacklog, ClientBufferSize);
 }
示例#10
0
        /// <summary>
        /// Executes the "database update" command.
        /// </summary>
        public void OnExecute()
        {
            try
            {
                if (string.IsNullOrEmpty(DatabaseConfigurationFile))
                {
                    DatabaseConfigurationFile = ConfigurationConstants.DatabasePath;
                }

                DatabaseConfiguration dbConfig = ConfigurationHelper.Load <DatabaseConfiguration>(DatabaseConfigurationFile);

                if (dbConfig is null)
                {
                    Console.WriteLine("Couldn't load database configuration file during execution of update command.");
                    return;
                }

                using IRhisisDatabase database = _databaseFactory.CreateDatabaseInstance(dbConfig);

                Console.WriteLine("Starting database structure update...");

                if (database.Exists())
                {
                    database.Migrate();
                    Console.WriteLine("Database updated.");
                }
                else
                {
                    Console.WriteLine("Database does not exist yet!");
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
示例#11
0
 /// <summary>
 /// Creates a new <see cref="LoginHandler"/> instance.
 /// </summary>
 /// <param name="logger">Logger.</param>
 /// <param name="loginConfiguration">Login server configuration.</param>
 /// <param name="loginServer">Login server instance.</param>
 /// <param name="database">Database service.</param>
 /// <param name="coreServer">Core server.</param>
 /// <param name="loginPacketFactory">Login server packet factory.</param>
 public LoginHandler(ILogger <LoginHandler> logger, IOptions <LoginConfiguration> loginConfiguration, ILoginServer loginServer, IRhisisDatabase database, ICoreServer coreServer, ILoginPacketFactory loginPacketFactory)
 {
     _logger             = logger;
     _loginConfiguration = loginConfiguration.Value;
     _loginServer        = loginServer;
     _database           = database;
     _coreServer         = coreServer;
     _loginPacketFactory = loginPacketFactory;
 }
示例#12
0
 /// <summary>
 /// Creates a new <see cref="TaskbarSystem"/> instance.
 /// </summary>
 /// <param name="logger">Logger.</param>
 /// <param name="database">Rhisis database access layer.</param>
 public TaskbarSystem(ILogger <TaskbarSystem> logger, IRhisisDatabase database)
 {
     _logger   = logger;
     _database = database;
 }
示例#13
0
        public void OnExecute()
        {
            if (string.IsNullOrEmpty(DatabaseConfigurationFile))
            {
                DatabaseConfigurationFile = ConfigurationConstants.DatabasePath;
            }

            var dbConfig = ConfigurationHelper.Load <DatabaseConfiguration>(DatabaseConfigurationFile, ConfigurationConstants.DatabaseConfiguration);

            if (dbConfig is null)
            {
                Console.WriteLine("Couldn't load database configuration file during execution of user create command.");
                return;
            }

            Console.Write("Username to update: ");
            string username = Console.ReadLine();

            if (string.IsNullOrWhiteSpace(username))
            {
                Console.WriteLine("You must type a username.");
                return;
            }

            using IRhisisDatabase database = _databaseFactory.CreateDatabaseInstance(dbConfig);
            DbUser user = database.Users.FirstOrDefault(x => x.Username == username);

            if (user == null)
            {
                Console.WriteLine($"Could not locate any username named '{username}'.");
                return;
            }

            bool response = _consoleHelper.AskConfirmation($"Are you sure you want to update the account '{user.Username}'");

            if (!response)
            {
                return;
            }

            bool changeEmail = _consoleHelper.AskConfirmation($"Would you like to change the email? '{user.Email}'");

            if (changeEmail)
            {
                Console.Write("Type the new email: ");
                user.Email = Console.ReadLine();
            }

            bool   changePassword       = _consoleHelper.AskConfirmation("Would you like to change the password?");
            string passwordConfirmation = string.Empty;
            string passwordSalt         = string.Empty;

            if (changePassword)
            {
                Console.Write("New password: "******"New password confirmation: ");
                passwordConfirmation = _consoleHelper.ReadPassword();

                Console.Write("Password salt: ");
                passwordSalt = _consoleHelper.ReadStringOrDefault();
            }

            bool changeAuthority = _consoleHelper.AskConfirmation("Would you like to change the account authority?");

            if (changeAuthority)
            {
                Console.WriteLine("New authority: ");
                _consoleHelper.DisplayEnum <AuthorityType>();
                user.Authority = (int)_consoleHelper.ReadEnum <AuthorityType>();
            }

            Console.WriteLine("--------------------------------");
            Console.WriteLine("User account information:");
            Console.WriteLine($"Username: {user.Username}");
            Console.WriteLine($"Email: {user.Email}");
            Console.WriteLine($"Authority: {(AuthorityType)user.Authority}");
            Console.WriteLine("--------------------------------");

            bool updateUser = (changeEmail || changePassword || changeAuthority) && _consoleHelper.AskConfirmation("Update user?");

            if (updateUser)
            {
                if (changeEmail)
                {
                    if (!user.Email.IsValidEmail())
                    {
                        Console.WriteLine($"Email '{user.Email}' is not valid.");
                        return;
                    }

                    if (database.Users.Any(x => x.Email.Equals(user.Email, StringComparison.InvariantCultureIgnoreCase)))
                    {
                        Console.WriteLine($"Email '{user.Email}' is already used.");
                        return;
                    }
                }

                if (changePassword)
                {
                    if (!user.Password.Equals(passwordConfirmation))
                    {
                        Console.WriteLine("Passwords doesn't match.");
                        return;
                    }

                    user.Password = MD5.GetMD5Hash(passwordSalt, user.Password);
                }

                database.Users.Update(user);
                database.SaveChanges();
                Console.WriteLine($"User '{user.Username}' has been updated.");
            }
        }
示例#14
0
        public void OnExecute()
        {
            if (string.IsNullOrEmpty(DatabaseConfigurationFile))
            {
                DatabaseConfigurationFile = ConfigurationConstants.DatabasePath;
            }

            var dbConfig = ConfigurationHelper.Load <DatabaseConfiguration>(DatabaseConfigurationFile, ConfigurationConstants.DatabaseConfiguration);

            if (dbConfig is null)
            {
                Console.WriteLine("Couldn't load database configuration file during execution of user create command.");
                return;
            }

            var user = new DbUser();

            Console.Write("Username: "******"Email: ");
            user.Email = Console.ReadLine();

            Console.Write("Password: "******"Password confirmation: ");
            string passwordConfirmation = _consoleHelper.ReadPassword();

            Console.Write("Password salt: ");
            string passwordSalt = _consoleHelper.ReadStringOrDefault();

            Console.WriteLine("Authority: ");
            _consoleHelper.DisplayEnum <AuthorityType>();
            user.Authority = (int)_consoleHelper.ReadEnum <AuthorityType>();

            Console.WriteLine("--------------------------------");
            Console.WriteLine("User account information:");
            Console.WriteLine($"Username: {user.Username}");
            Console.WriteLine($"Email: {user.Email}");
            Console.WriteLine($"Authority: {(AuthorityType)user.Authority}");
            Console.WriteLine("--------------------------------");

            bool response = _consoleHelper.AskConfirmation("Create user?");

            if (response)
            {
                using IRhisisDatabase database = _databaseFactory.CreateDatabaseInstance(dbConfig);

                if (database.Users.Any(x => x.Username.Equals(user.Username, StringComparison.OrdinalIgnoreCase)))
                {
                    Console.WriteLine($"User '{user.Username}' is already used.");
                    return;
                }

                if (!user.Email.IsValidEmail())
                {
                    Console.WriteLine($"Email '{user.Email}' is not valid.");
                    return;
                }

                if (database.Users.Any(x => x.Email.Equals(user.Email, StringComparison.OrdinalIgnoreCase)))
                {
                    Console.WriteLine($"Email '{user.Email}' is already used.");
                    return;
                }

                if (!user.Password.Equals(passwordConfirmation))
                {
                    Console.WriteLine("Passwords doesn't match.");
                    return;
                }

                user.Password = MD5.GetMD5Hash(passwordSalt, user.Password);

                database.Users.Add(user);
                database.SaveChanges();

                Console.WriteLine($"User '{user.Username}' created.");
            }
        }