Пример #1
0
        private void LoadCharacterBaseStats(IWhisperDatasource datasource)
        {
            log.Info("loading character base stats...");
            datasource.ExecuteQuery("select race, class, level, health, mana, strength, agility, stamina, intellect, spirit from character_base_stats", reader =>
            {
                var defs = new Dictionary <Race, IDictionary <Class, IDictionary <byte, CharacterBaseStats> > >();

                int count = 0;
                while (reader.Read())
                {
                    CharacterBaseStats cbs = new CharacterBaseStats((Race)reader.GetByte(0), (Class)reader.GetByte(1), reader.GetByte(2), reader.GetInt32(3), reader.GetInt32(4), reader.GetInt32(5), reader.GetInt32(6), reader.GetInt32(7), reader.GetInt32(8), reader.GetInt32(9));

                    if (!defs.ContainsKey(cbs.Race))
                    {
                        defs.Add(cbs.Race, new Dictionary <Class, IDictionary <byte, CharacterBaseStats> >());
                    }
                    if (!defs[cbs.Race].ContainsKey(cbs.Class))
                    {
                        defs[cbs.Race].Add(cbs.Class, new Dictionary <byte, CharacterBaseStats>());
                    }

                    defs[cbs.Race][cbs.Class].Add(cbs.Level, cbs);
                    ++count;
                }

                CharacterBaseStats = defs;
                log.DebugFormat("loaded {0} character base stats", count);
            });
        }
Пример #2
0
 /// <summary>
 /// Initializes a new instance of the World class, loading and caching its contents from the provided datasource.
 /// </summary>
 /// <param name="wworld">A datasource to a static world database. Needs read access only. The SQL used to initialize this database is located under Whisper.Daemon.Shard.SQL.World.</param>
 public World(IWhisperDatasource wworld)
 {
     LoadRaceDefinitions(wworld);
     LoadCharacterTemplates(wworld);
     LoadCharacterBaseStats(wworld);
     LoadModelDefinitions(wworld);
 }
Пример #3
0
 public ShardServer(IWhisperComposerFactory <ShardRequest> composerFactory, IRandomSource randomSource, IWhisperDatasource wauth, IWhisperDatasource wshard, World world, Game.World.Shard shard, ShardConfig configuration) : base(composerFactory)
 {
     AppConfig    = configuration;
     SecureRandom = randomSource;
     AuthDB       = wauth;
     ShardDB      = wshard;
     World        = world;
     Shard        = shard;
 }
Пример #4
0
        public void UpdateCharacter(IWhisperDatasource wshard, Character character)
        {
            log.InfoFormat("saving character '{0}'", character.Name);

            // TODO: action buttons, spells, player_fields
            int result = wshard.ExecuteNonQuery("update `character` set level = ?, position_x = ?, position_y = ?, position_z = ?, orientation = ?, map_id = ?, zone_id = ?, fields = ? where id = ?",
                                                character.Level, character.Position.X, character.Position.Y, character.Position.Z, character.Position.Orientation, character.MapID, character.ZoneID, character.GetRawFields(), character.ID.ID);

            if (result != 1)
            {
                log.ErrorFormat("expected 1 character row updated from UpdateCharacter but got {0}", result);
            }
        }
Пример #5
0
        private void LoadCharacterTemplates(IWhisperDatasource datasource)
        {
            log.Info("loading character templates...");
            datasource.ExecuteQuery("select race, class, map_id, zone_id, position_x, position_y, position_z, orientation from character_template", ctReader =>
            {
                var templates = new Dictionary <Race, IDictionary <Class, CharacterTemplate> >();

                while (ctReader.Read())
                {
                    byte race   = ctReader.GetByte(0);
                    byte @class = ctReader.GetByte(1);

                    int buttonCount = 0;
                    ActionButton[] actionButtons = new ActionButton[Character.MaxActionButtons];
                    datasource.ExecuteQuery("select button, action, type from character_template_action_button where race = ? and class = ? limit ?", new object[] { race, @class, Character.MaxActionButtons }, abReader =>
                    {
                        while (abReader.Read())
                        {
                            actionButtons[abReader.GetInt16(0)] = new ActionButton(abReader.GetInt32(1), (ActionButton.Type)abReader.GetByte(2));
                            ++buttonCount;
                        }
                    });

                    IList <int> spells = new List <int>();
                    datasource.ExecuteQuery("select spell_id from character_template_spell where race = ? and class = ?", new object[] { race, @class }, sReader =>
                    {
                        while (sReader.Read())
                        {
                            spells.Add(sReader.GetInt32(0));
                        }
                    });

                    CharacterTemplate template = new CharacterTemplate(race, @class, ctReader.GetInt32(2), ctReader.GetInt32(3), ctReader.GetFloat(4), ctReader.GetFloat(5), ctReader.GetFloat(6), ctReader.GetFloat(7), actionButtons, spells);

                    if (!templates.ContainsKey(template.Race))
                    {
                        templates.Add(template.Race, new Dictionary <Class, CharacterTemplate>());
                    }

                    templates[template.Race].Add(template.Class, template);
                    log.DebugFormat("loaded character template for {0} {1} with {2} spells and {3} buttons", template.Race, template.Class, template.SpellIDs.Count, buttonCount);
                }

                CharacterTemplates = templates;
            });
        }
Пример #6
0
        private void LoadModelDefinitions(IWhisperDatasource datasource)
        {
            log.Info("loading model definitions...");
            datasource.ExecuteQuery("select id, bounding_radius, combat_reach from model_definition", reader =>
            {
                var defs = new Dictionary <int, ModelDefinition>();

                while (reader.Read())
                {
                    ModelDefinition md = new ModelDefinition(reader.GetInt32(0), reader.GetFloat(1), reader.GetFloat(2));
                    defs.Add(md.ModelID, md);
                }

                ModelDefinitions = defs;
                log.DebugFormat("loaded {0} model definitions", defs.Count);
            });
        }
Пример #7
0
        private void LoadRaceDefinitions(IWhisperDatasource datasource)
        {
            log.Info("loading race definitions...");
            datasource.ExecuteQuery("select id, name, flags, display_id_male, display_id_female, first_login_cinematic_id, faction_id from race_definition", reader =>
            {
                var defs = new Dictionary <Race, RaceDefinition>();

                while (reader.Read())
                {
                    RaceDefinition rd = new RaceDefinition((Race)reader.GetByte(0), reader.GetString(1), reader.GetInt32(6), (RaceFlags)reader.GetInt32(2), reader.GetInt32(3), reader.GetInt32(4), reader.GetInt32(5));
                    defs.Add(rd.Race, rd);

                    log.DebugFormat("loaded race definition for {0}", rd.Name);
                }

                RaceDefinitions = defs;
            });
        }
Пример #8
0
 public ShardPinger(IWhisperDatasource wauth, ShardConfig config)
 {
     this.config    = config;
     authDatasource = wauth;
 }
Пример #9
0
 public AuthServer(IWhisperComposerFactory <AuthRequest> composerFactory, IRandomSource randomSource, IWhisperDatasource wauth, AuthConfig configuration) : base(composerFactory)
 {
     AppConfig    = configuration;
     SecureRandom = randomSource;
     AuthDB       = wauth;
 }
Пример #10
0
        public Character GetCharacterByID(IWhisperDatasource wshard, ObjectID characterId)
        {
            if (characterId.ObjectType != ObjectID.Type.Player)
            {
                throw new ArgumentException("GetCharacterByID called on ObjectID that is not a Player", "characterId");
            }

            log.InfoFormat("loading character {0}", characterId);

            IList <ActionButton> actionButtons = new List <ActionButton>();

            wshard.ExecuteQuery("select action, type from character_action_button where character_id = ? order by button asc", characterId.ID, result =>
            {
                while (result.Read())
                {
                    actionButtons.Add(new ActionButton(result.GetInt32(0), (ActionButton.Type)result.GetByte(1)));
                }
            });

            IList <Character.Spell> spells = new List <Character.Spell>();

            wshard.ExecuteQuery("select spell_id, enabled from character_spell where character_id = ?", characterId.ID, result =>
            {
                while (result.Read())
                {
                    spells.Add(new Character.Spell()
                    {
                        SpellID = result.GetInt32(0), Enabled = result.GetBoolean(1)
                    });
                }
            });

            // TODO: player_fields
            //                                 0     1     2      3    4     5     6           7           8            9      10          11          12          13           14      15       16            17
            return(wshard.ExecuteQuery("select name, race, class, sex, skin, face, hair_style, hair_color, facial_hair, level, position_x, position_y, position_z, orientation, map_id, zone_id, player_flags, fields from `character` where id = ?", characterId.ID, result =>
            {
                if (result.Read())
                {
                    Character character = new Character(characterId, result.GetString(0), actionButtons, spells);

                    // set fields first. following updates could clobber information in that array
                    if (result.IsDBNull(17))
                    {
                        // new characters don't have field arrays yet
                        character.FirstLogin = true;
                    }
                    else
                    {
                        int size = character.FieldCount * sizeof(uint);
                        byte[] buffer = new byte[size];
                        long fieldsResult = result.GetBytes(17, 0, buffer, 0, size);

                        if (fieldsResult == size)
                        {
                            character.SetRawFields(buffer);
                        }
                        else
                        {
                            // did not read the correct amount of bytes. corruption?
                            throw new InvalidDataException($"character.fields had incorrect number of bytes. expected {size}, but got {fieldsResult}");
                        }
                    }

                    character.Position = new OrientedVector3(result.GetFloat(10), result.GetFloat(11), result.GetFloat(12), result.GetFloat(13));
                    character.MapID = result.GetInt32(14);
                    character.ZoneID = result.GetInt32(15);

                    Race raceEnum;
                    if (Enum.TryParse(result.GetByte(1).ToString(), out raceEnum))
                    {
                        character.Race = raceEnum;
                    }
                    else
                    {
                        throw new ArgumentException($"cannot load character with invalid race {result.GetByte(1)}");
                    }

                    Class classEnum;
                    if (Enum.TryParse(result.GetByte(2).ToString(), out classEnum))
                    {
                        character.Class = classEnum;
                    }
                    else
                    {
                        throw new ArgumentException($"cannot load character with invalid class {result.GetByte(2)}");
                    }

                    Sex sexEnum;
                    if (Enum.TryParse(result.GetByte(3).ToString(), out sexEnum))
                    {
                        character.Sex = sexEnum;
                    }
                    else
                    {
                        throw new ArgumentException($"cannot load character with invalid sex {result.GetByte(3)}");
                    }

                    character.Skin = result.GetByte(4);
                    character.Face = result.GetByte(5);
                    character.HairStyle = result.GetByte(6);
                    character.HairColor = result.GetByte(7);
                    character.FaceExtra = result.GetByte(8);
                    character.Level = result.GetByte(9);

                    return character;
                }
                else
                {
                    throw new ArgumentException("GetCharacterByID called on ObjectID that does not exist", nameof(characterId));
                }
            }));
        }