Esempio n. 1
0
        public static void UpdateAccount(int id = 0, bool connected = true)
        {
            if (id != 0 && connected)
            {
                const string query = "INSERT INTO gameconnection SET connected = 1, accountId=@accountid, gameserverid=@gsId";

                Base.Repository.ExecuteQuery(query, RealmDbManager.GetDatabaseConnection(),
                                             (command) =>
                {
                    command.Parameters.Add(new MySqlParameter("@accountid", id));
                    command.Parameters.Add(new MySqlParameter("@gsId", DatabaseProvider.ServerId));
                });
            }
            else if (connected == false && id == 0)
            {
                const string query = "DELETE FROM gameconnection";

                Base.Repository.ExecuteQuery(query, RealmDbManager.GetDatabaseConnection(),
                                             (command) => { });
            }
            else if (connected == false && id != 0)
            {
                const string query = "DELETE FROM gameconnection WHERE accountid=@accountid AND gameserverid=@gsId";

                Base.Repository.ExecuteQuery(query, RealmDbManager.GetDatabaseConnection(),
                                             (command) =>
                {
                    command.Parameters.Add(new MySqlParameter("@accountid", id));
                    command.Parameters.Add(new MySqlParameter("@gsId", DatabaseProvider.ServerId));
                });
            }
        }
Esempio n. 2
0
        private static void LoadAccounts()
        {
            var task = ExecuteQueryLight(RealmDbManager.GetDatabaseConnection(), "SELECT * FROM accounts", "Accounts",
                                         (reader) =>
            {
                while (reader.Read())
                {
                    Accounts.Add(new Account
                    {
                        Id          = reader.GetInt32("id"),
                        Username    = reader.GetString("username"),
                        Password    = reader.GetString("pass"),
                        Pseudo      = reader.GetString("pseudo"),
                        Question    = reader.GetString("question"),
                        Reponse     = reader.GetString("reponse"),
                        GmLevel     = reader.GetInt16("gmLevel"),
                        BannedUntil =
                            Convert.IsDBNull(reader["bannedUntil"])
                                    ? (DateTime?)null
                                    : reader.GetDateTime("bannedUntil"),
                        Subscription =
                            Convert.IsDBNull(reader["subscription"])
                                    ? (DateTime?)null
                                    : reader.GetDateTime("subscription"),
                    });
                }

                return(Accounts.Count);
            });

            task.Wait();
        }
Esempio n. 3
0
        private static void LoadCharactersAccount()
        {
            var task = ExecuteQueryLight(RealmDbManager.GetDatabaseConnection(),
                                         "SELECT * FROM characters WHERE gameserverId =@ServerId", "Characters <<>> Account", (reader) =>
            {
                var tableResults = new List <KeyValuePair <int, int> >();

                while (reader.Read())
                {
                    tableResults.Add(new KeyValuePair <int, int>(
                                         reader.GetInt16("AccountId"),
                                         reader.GetInt16("characterId")
                                         ));
                }

                foreach (var tableResult in tableResults)
                {
                    AccountCharacters.Add(new AccountCharacters
                    {
                        Account   = Accounts.Find(x => x.Id == tableResult.Key),
                        Character = Characters.Find(x => x.Id == tableResult.Value)
                    });
                }

                return(AccountCharacters.Count);
            }, (command) => command.Parameters.Add(new MySqlParameter("@ServerId", ServerId)));

            task.Wait();
        }
Esempio n. 4
0
        public static void UpdateCharactersList(int id)
        {
            const string query = "SELECT * FROM characters WHERE accountId = @accountId AND gameServerId = @gsId";

            var charactersId = new List <int>();

            using (var connection = RealmDbManager.GetDatabaseConnection())
            {
                using (var command = new MySqlCommand(query, connection))
                {
                    command.Parameters.Add(new MySqlParameter("@accountId", id));
                    command.Parameters.Add(new MySqlParameter("@gsId", DatabaseProvider.ServerId));

                    using (var reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            charactersId.Add(reader.GetInt16("characterId"));
                        }
                    }
                }
            }

            const string query2 = "SELECT * FROM characters WHERE FIND_IN_SET(id, @charactersId)";

            using (var connection = GameDbManager.GetDatabaseConnection())
            {
                using (var command = new MySqlCommand(query2, connection))
                {
                    command.Parameters.Add(new MySqlParameter("@charactersId", string.Join(",", charactersId)));

                    using (var reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            var character = DatabaseProvider.Characters.Find(x => x.Id == reader.GetInt16("id"));

                            character.Name        = reader.GetString("name");
                            character.Color1      = reader.GetInt32("color1");
                            character.Color2      = reader.GetInt32("color2");
                            character.Color3      = reader.GetInt32("color3");
                            character.Kamas       = reader.GetInt32("kamas");
                            character.Level       = reader.GetInt16("level");
                            character.Sex         = reader.GetInt16("sex");
                            character.Skin        = reader.GetInt16("skin");
                            character.Map         = DatabaseProvider.Maps.Find(x => x.Id == reader.GetInt32("mapId"));
                            character.MapCell     = reader.GetInt32("cellId");
                            character.Direction   = reader.GetInt16("direction");
                            character.StatsPoints = reader.GetInt32("statsPoints");
                            character.SpellPoints = reader.GetInt32("spellsPoints");
                        }
                    }
                }
            }
        }
        public static void Create(Character character, int accountId)
        {
            const string query =
                "INSERT INTO characters SET id=@id, name=@name, classe=@classe, sex=@sex, color1=@color1, color2=@color2," +
                "color3=@color3, skin=@skin, level=@level, alignmentId=@alignmentId, statsId=@statsId, " +
                "pdvNow=@pdvNow, mapId=@mapId, cellId=@cellId, direction=@direction, channels=@channels, statsPoints=@statsPoints, " +
                "spellsPoints=@spellsPoints, kamas=@kamas";

            Base.Repository.ExecuteQuery(query, GameDbManager.GetDatabaseConnection(),
                                         (command) =>
            {
                command.Parameters.Add(new MySqlParameter("@id", character.Id));
                command.Parameters.Add(new MySqlParameter("@name", character.Name));
                command.Parameters.Add(new MySqlParameter("@classe", (int)character.Classe));
                command.Parameters.Add(new MySqlParameter("@sex", character.Sex));
                command.Parameters.Add(new MySqlParameter("@color1", character.Color1));
                command.Parameters.Add(new MySqlParameter("@color2", character.Color2));
                command.Parameters.Add(new MySqlParameter("@color3", character.Color3));
                command.Parameters.Add(new MySqlParameter("@skin", character.Skin));
                command.Parameters.Add(new MySqlParameter("@level", character.Level));
                command.Parameters.Add(new MySqlParameter("@alignmentId", character.Alignment.Id));
                command.Parameters.Add(new MySqlParameter("@statsId", character.Stats.Id));
                command.Parameters.Add(new MySqlParameter("@pdvNow", character.PdvNow));
                command.Parameters.Add(new MySqlParameter("@mapId", character.Map.Id));
                command.Parameters.Add(new MySqlParameter("@cellId", character.MapCell));
                command.Parameters.Add(new MySqlParameter("@direction", character.Direction));
                command.Parameters.Add(new MySqlParameter("@channels", string.Join("", character.Channels)));
                command.Parameters.Add(new MySqlParameter("@statsPoints", character.StatsPoints));
                command.Parameters.Add(new MySqlParameter("@spellsPoints", character.SpellPoints));
                command.Parameters.Add(new MySqlParameter("@kamas", character.Kamas));
            });

            Logs.LogWritter(Constant.GameFolder, string.Format("Création du personnage {0}", character.Name));

            const string query2 =
                "INSERT INTO characters SET accountId=@accountId, gameserverId=@gameServer, characterId=@id";

            Base.Repository.ExecuteQuery(query2, RealmDbManager.GetDatabaseConnection(),
                                         (command) =>
            {
                command.Parameters.Add(new MySqlParameter("@accountId", accountId));
                command.Parameters.Add(new MySqlParameter("@gameServer", DatabaseProvider.ServerId));
                command.Parameters.Add(new MySqlParameter("@id", character.Id));
            });

            lock (DatabaseProvider.Characters)
                DatabaseProvider.Characters.Add(character);

            lock (DatabaseProvider.AccountCharacters)
                DatabaseProvider.AccountCharacters.Add(new AccountCharacters
                {
                    Account   = DatabaseProvider.Accounts.Find(x => x.Id == accountId),
                    Character = character
                });
        }
Esempio n. 6
0
        private static void LoadServerId()
        {
            var task = ExecuteQueryLight(RealmDbManager.GetDatabaseConnection(),
                                         "SELECT id FROM gameservers WHERE ServerKey=@key LIMIT 1", "Game Server",
                                         (reader) =>
            {
                if (reader.Read())
                {
                    ServerId = reader.GetInt16("id");
                }

                return(1);
            }, (command) => command.Parameters.Add(new MySqlParameter("@key", Config.Get("Game_key"))));

            task.Wait();
        }