Merge remote branch 'origin/master' into 330

This commit is contained in:
tomrus88 2010-03-28 16:01:46 +04:00
commit 94cd6abe6f
13 changed files with 130 additions and 121 deletions

View file

@ -21,7 +21,7 @@
DROP TABLE IF EXISTS `character_db_version`;
CREATE TABLE `character_db_version` (
`required_9632_01_characters_characters` bit(1) default NULL
`required_9634_01_characters_corpse` bit(1) default NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8 ROW_FORMAT=FIXED COMMENT='Last applied sql update to DB';
--
@ -893,10 +893,8 @@ CREATE TABLE `corpse` (
`position_y` float NOT NULL default '0',
`position_z` float NOT NULL default '0',
`orientation` float NOT NULL default '0',
`zone` int(11) unsigned NOT NULL default '38' COMMENT 'Zone Identifier',
`map` int(11) unsigned NOT NULL default '0' COMMENT 'Map Identifier',
`phaseMask` smallint(5) unsigned NOT NULL default '1',
`data` longtext,
`time` bigint(20) unsigned NOT NULL default '0',
`corpse_type` tinyint(3) unsigned NOT NULL default '0',
`instance` int(11) unsigned NOT NULL default '0',

View file

@ -0,0 +1,5 @@
ALTER TABLE character_db_version CHANGE COLUMN required_9632_01_characters_characters required_9634_01_characters_corpse bit;
ALTER TABLE corpse
DROP COLUMN data,
DROP COLUMN zone;

View file

@ -93,6 +93,7 @@ pkgdata_DATA = \
9622_01_mangos_gameobject.sql \
9630_01_characters_characters.sql \
9632_01_characters_characters.sql \
9634_01_characters_corpse.sql \
README
## Additional files to include when running 'make dist'
@ -166,4 +167,5 @@ EXTRA_DIST = \
9622_01_mangos_gameobject.sql \
9630_01_characters_characters.sql \
9632_01_characters_characters.sql \
9634_01_characters_corpse.sql \
README

View file

@ -105,18 +105,14 @@ void Corpse::SaveToDB()
DeleteFromDB();
std::ostringstream ss;
ss << "INSERT INTO corpse (guid,player,position_x,position_y,position_z,orientation,zone,map,data,time,corpse_type,instance,phaseMask) VALUES ("
ss << "INSERT INTO corpse (guid,player,position_x,position_y,position_z,orientation,map,time,corpse_type,instance,phaseMask) VALUES ("
<< GetGUIDLow() << ", "
<< GUID_LOPART(GetOwnerGUID()) << ", "
<< GetPositionX() << ", "
<< GetPositionY() << ", "
<< GetPositionZ() << ", "
<< GetOrientation() << ", "
<< GetZoneId() << ", "
<< GetMapId() << ", '";
for(uint16 i = 0; i < m_valuesCount; ++i )
ss << GetUInt32Value(i) << " ";
ss << "',"
<< GetMapId() << ", "
<< uint64(m_time) <<", "
<< uint32(GetType()) << ", "
<< int(GetInstanceId()) << ", "
@ -149,55 +145,23 @@ void Corpse::DeleteFromDB()
CharacterDatabase.PExecute("DELETE FROM corpse WHERE player = '%d' AND corpse_type <> '0'", GUID_LOPART(GetOwnerGUID()));
}
bool Corpse::LoadFromDB(uint32 guid, QueryResult *result)
{
bool external = (result != NULL);
if (!external)
// 0 1 2 3 4 5 6 7 8 9
result = CharacterDatabase.PQuery("SELECT position_x,position_y,position_z,orientation,map,data,time,corpse_type,instance,phaseMask FROM corpse WHERE guid = '%u'",guid);
if( !result )
{
sLog.outError("Corpse (GUID: %u) not found in table `corpse`, can't load. ",guid);
return false;
}
Field *fields = result->Fetch();
if(!LoadFromDB(guid, fields))
{
if (!external)
delete result;
return false;
}
if (!external)
delete result;
return true;
}
bool Corpse::LoadFromDB(uint32 guid, Field *fields)
{
// 0 1 2 3 4 5 6 7 8 9
//result = CharacterDatabase.PQuery("SELECT position_x,position_y,position_z,orientation,map,data,time,corpse_type,instance,phaseMask FROM corpse WHERE guid = '%u'",guid);
float positionX = fields[0].GetFloat();
float positionY = fields[1].GetFloat();
float positionZ = fields[2].GetFloat();
float ort = fields[3].GetFloat();
uint32 mapid = fields[4].GetUInt32();
//// 0 1 2 3 4 5 6
//QueryResult *result = CharacterDatabase.Query("SELECT corpse.guid, player, corpse.position_x, corpse.position_y, corpse.position_z, corpse.orientation, corpse.map,"
//// 7 8 9 10 11 12 13 14 15 16 17 18
// "time, corpse_type, instance, phaseMask, gender, race, class, playerBytes, playerBytes2, equipmentCache, guildId, playerFlags FROM corpse"
uint32 playerGuid = fields[1].GetUInt32();
float positionX = fields[2].GetFloat();
float positionY = fields[3].GetFloat();
float positionZ = fields[4].GetFloat();
float orientation = fields[5].GetFloat();
uint32 mapid = fields[6].GetUInt32();
Object::_Create(guid, 0, HIGHGUID_CORPSE);
if(!LoadValues( fields[5].GetString() ))
{
sLog.outError("Corpse #%d have broken data in `data` field. Can't be loaded.",guid);
return false;
}
m_time = time_t(fields[6].GetUInt64());
m_type = CorpseType(fields[7].GetUInt32());
m_time = time_t(fields[7].GetUInt64());
m_type = CorpseType(fields[8].GetUInt32());
if(m_type >= MAX_CORPSE_TYPE)
{
@ -205,17 +169,70 @@ bool Corpse::LoadFromDB(uint32 guid, Field *fields)
return false;
}
uint32 instanceid = fields[8].GetUInt32();
uint32 phaseMask = fields[9].GetUInt32();
uint32 instanceid = fields[9].GetUInt32();
uint32 phaseMask = fields[10].GetUInt32();
uint8 gender = fields[11].GetUInt8();
uint8 race = fields[12].GetUInt8();
uint8 _class = fields[13].GetUInt8();
uint32 playerBytes = fields[14].GetUInt32();
uint32 playerBytes2 = fields[15].GetUInt32();
uint32 guildId = fields[17].GetUInt32();
uint32 playerFlags = fields[18].GetUInt32();
// overwrite possible wrong/corrupted guid
SetUInt64Value(OBJECT_FIELD_GUID, MAKE_NEW_GUID(guid, 0, HIGHGUID_CORPSE));
SetUInt64Value(CORPSE_FIELD_OWNER, MAKE_NEW_GUID(playerGuid, 0, HIGHGUID_PLAYER));
SetFloatValue( OBJECT_FIELD_SCALE_X, 1.0f );
PlayerInfo const *info = sObjectMgr.GetPlayerInfo(race, _class);
if(!info)
{
sLog.outError("Player %u has incorrect race/class pair.", GetGUIDLow());
return false;
}
SetUInt32Value(CORPSE_FIELD_DISPLAY_ID, gender == GENDER_FEMALE ? info->displayId_f : info->displayId_m);
// Load equipment
Tokens data = StrSplit(fields[16].GetCppString(), " ");
for (uint8 slot = 0; slot < EQUIPMENT_SLOT_END; slot++)
{
uint32 visualbase = slot * 2;
uint32 item_id = GetUInt32ValueFromArray(data, visualbase);
const ItemPrototype * proto = ObjectMgr::GetItemPrototype(item_id);
if(!proto)
{
SetUInt32Value(CORPSE_FIELD_ITEM + slot, 0);
continue;
}
SetUInt32Value(CORPSE_FIELD_ITEM + slot, proto->DisplayInfoID | (proto->InventoryType << 24));
}
uint8 skin = (uint8)(playerBytes);
uint8 face = (uint8)(playerBytes >> 8);
uint8 hairstyle = (uint8)(playerBytes >> 16);
uint8 haircolor = (uint8)(playerBytes >> 24);
uint8 facialhair = (uint8)(playerBytes2);
SetUInt32Value( CORPSE_FIELD_BYTES_1, ((0x00) | (race << 8) | (gender << 16) | (skin << 24)) );
SetUInt32Value( CORPSE_FIELD_BYTES_2, ((face) | (hairstyle << 8) | (haircolor << 16) | (facialhair << 24)) );
SetUInt32Value(CORPSE_FIELD_GUILD, guildId);
uint32 flags = CORPSE_FLAG_UNK2;
if(playerFlags & PLAYER_FLAGS_HIDE_HELM)
flags |= CORPSE_FLAG_HIDE_HELM;
if(playerFlags & PLAYER_FLAGS_HIDE_CLOAK)
flags |= CORPSE_FLAG_HIDE_CLOAK;
SetUInt32Value( CORPSE_FIELD_FLAGS, flags );
// no need to mark corpse as lootable, because corpses are not saved in battle grounds
// place
SetLocationInstanceId(instanceid);
SetLocationMapId(mapid);
SetPhaseMask(phaseMask, false);
Relocate(positionX, positionY, positionZ, ort);
Relocate(positionX, positionY, positionZ, orientation);
if(!IsPositionValid())
{

View file

@ -59,7 +59,6 @@ class Corpse : public WorldObject
bool Create( uint32 guidlow, Player *owner );
void SaveToDB();
bool LoadFromDB(uint32 guid, QueryResult *result);
bool LoadFromDB(uint32 guid, Field *fields);
void DeleteBonesFromWorld();

View file

@ -3961,7 +3961,7 @@ bool ChatHandler::HandleExploreCheatCommand(const char* args)
ChatHandler(chr).PSendSysMessage(LANG_YOURS_EXPLORE_SET_NOTHING,GetNameLink().c_str());
}
for (uint8 i=0; i<128; ++i)
for (uint8 i=0; i<PLAYER_EXPLORED_ZONES_SIZE; ++i)
{
if (flag != 0)
{
@ -4118,7 +4118,7 @@ bool ChatHandler::HandleShowAreaCommand(const char* args)
int offset = area / 32;
uint32 val = (uint32)(1 << (area % 32));
if(area<0 || offset >= 128)
if(area<0 || offset >= PLAYER_EXPLORED_ZONES_SIZE)
{
SendSysMessage(LANG_BAD_VALUE);
SetSentErrorMessage(true);
@ -4149,7 +4149,7 @@ bool ChatHandler::HandleHideAreaCommand(const char* args)
int offset = area / 32;
uint32 val = (uint32)(1 << (area % 32));
if(area<0 || offset >= 128)
if(area<0 || offset >= PLAYER_EXPLORED_ZONES_SIZE)
{
SendSysMessage(LANG_BAD_VALUE);
SetSentErrorMessage(true);

View file

@ -6254,8 +6254,12 @@ std::string ObjectMgr::GeneratePetName(uint32 entry)
void ObjectMgr::LoadCorpses()
{
uint32 count = 0;
// 0 1 2 3 4 5 6 7 8 10
QueryResult *result = CharacterDatabase.Query("SELECT position_x, position_y, position_z, orientation, map, data, time, corpse_type, instance, guid FROM corpse WHERE corpse_type <> 0");
// 0 1 2 3 4 5 6
QueryResult *result = CharacterDatabase.Query("SELECT corpse.guid, player, corpse.position_x, corpse.position_y, corpse.position_z, corpse.orientation, corpse.map, "
// 7 8 9 10 11 12 13 14 15 16 17 18
"time, corpse_type, instance, phaseMask, gender, race, class, playerBytes, playerBytes2, equipmentCache, guildId, playerFlags FROM corpse "
"JOIN characters ON player = characters.guid "
"LEFT JOIN guild_member ON player=guild_member.guid WHERE corpse_type <> 0");
if( !result )
{
@ -6276,7 +6280,7 @@ void ObjectMgr::LoadCorpses()
Field *fields = result->Fetch();
uint32 guid = fields[result->GetFieldCount()-1].GetUInt32();
uint32 guid = fields[0].GetUInt32();
Corpse *corpse = new Corpse;
if(!corpse->LoadFromDB(guid,fields))

View file

@ -609,10 +609,10 @@ bool Player::Create( uint32 guidlow, const std::string& name, uint8 race, uint8
SetUInt32Value( PLAYER_GUILDRANK, 0 );
SetUInt32Value( PLAYER_GUILD_TIMESTAMP, 0 );
SetUInt64Value( PLAYER__FIELD_KNOWN_TITLES, 0 ); // 0=disabled
SetUInt64Value( PLAYER__FIELD_KNOWN_TITLES1, 0 ); // 0=disabled
SetUInt64Value( PLAYER__FIELD_KNOWN_TITLES2, 0 ); // 0=disabled
for(int i = 0; i < KNOWN_TITLES_SIZE; ++i)
SetUInt64Value(PLAYER__FIELD_KNOWN_TITLES + i, 0); // 0=disabled
SetUInt32Value( PLAYER_CHOSEN_TITLE, 0 );
SetUInt32Value( PLAYER_FIELD_KILLS, 0 );
SetUInt32Value( PLAYER_FIELD_LIFETIME_HONORBALE_KILLS, 0 );
SetUInt32Value( PLAYER_FIELD_TODAY_CONTRIBUTION, 0 );
@ -5919,9 +5919,9 @@ void Player::CheckExploreSystem()
return;
int offset = areaFlag / 32;
if(offset >= 128)
if(offset >= PLAYER_EXPLORED_ZONES_SIZE)
{
sLog.outError("Wrong area flag %u in map data for (X: %f Y: %f) point to field PLAYER_EXPLORED_ZONES_1 + %u ( %u must be < 128 ).",areaFlag,GetPositionX(),GetPositionY(),offset,offset);
sLog.outError("Wrong area flag %u in map data for (X: %f Y: %f) point to field PLAYER_EXPLORED_ZONES_1 + %u ( %u must be < %u ).",areaFlag,GetPositionX(),GetPositionY(),offset,offset, PLAYER_EXPLORED_ZONES_SIZE);
return;
}
@ -14664,56 +14664,21 @@ bool Player::LoadPositionFromDB(uint32& mapid, float& x,float& y,float& z,float&
return true;
}
uint32 Player::GetUInt32ValueFromArray(Tokens const& data, uint16 index)
{
if(index >= data.size())
return 0;
return (uint32)atoi(data[index].c_str());
}
float Player::GetFloatValueFromArray(Tokens const& data, uint16 index)
{
float result;
uint32 temp = Player::GetUInt32ValueFromArray(data,index);
memcpy(&result, &temp, sizeof(result));
return result;
}
void Player::_LoadExploredZones(const char* data)
void Player::_LoadIntoDataField(const char* data, uint32 startOffset, uint32 count)
{
if(!data)
return;
Tokens tokens = StrSplit(data, " ");
if(tokens.size() != 128)
if(tokens.size() != count)
return;
Tokens::iterator iter;
int index;
for (iter = tokens.begin(), index = 0; index < 128; ++iter, ++index)
uint32 index;
for (iter = tokens.begin(), index = 0; index < count; ++iter, ++index)
{
m_uint32Values[PLAYER_EXPLORED_ZONES_1 + index] = atol((*iter).c_str());
}
}
void Player::_LoadKnownTitles(const char* data)
{
if(!data)
return;
Tokens tokens = StrSplit(data, " ");
if(tokens.size() != 6)
return;
Tokens::iterator iter;
int index;
for (iter = tokens.begin(), index = 0; index < 6; ++iter, ++index)
{
m_uint32Values[PLAYER__FIELD_KNOWN_TITLES + index] = atol((*iter).c_str());
m_uint32Values[startOffset + index] = atol((*iter).c_str());
}
}
@ -14776,8 +14741,9 @@ bool Player::LoadFromDB( uint32 guid, SqlQueryHolder *holder )
SetUInt32Value(UNIT_FIELD_LEVEL, fields[6].GetUInt8());
SetUInt32Value(PLAYER_XP, fields[7].GetUInt32());
_LoadExploredZones(fields[60].GetString());
_LoadKnownTitles(fields[63].GetString());
_LoadIntoDataField(fields[60].GetString(), PLAYER_EXPLORED_ZONES_1, PLAYER_EXPLORED_ZONES_SIZE);
_LoadIntoDataField(fields[63].GetString(), PLAYER__FIELD_KNOWN_TITLES, KNOWN_TITLES_SIZE*2);
SetFloatValue(UNIT_FIELD_BOUNDINGRADIUS, DEFAULT_WORLD_OBJECT_SIZE);
SetFloatValue(UNIT_FIELD_COMBATREACH, 1.5f);
SetFloatValue(UNIT_FIELD_HOVERHEIGHT, 1.0f);
@ -16398,7 +16364,7 @@ void Player::SaveToDB()
ss << ", ";
ss << uint32(m_specsCount) << ", ";
ss << uint32(m_activeSpec) << ", '";
for(uint32 i = 0; i < 128; ++i )
for(uint32 i = 0; i < PLAYER_EXPLORED_ZONES_SIZE; ++i )
{
ss << GetUInt32Value(PLAYER_EXPLORED_ZONES_1 + i) << " ";
}
@ -16411,7 +16377,7 @@ void Player::SaveToDB()
ss << "',";
ss << GetUInt32Value(PLAYER_AMMO_ID) << ", '";
for(uint32 i = 0; i < 6; ++i )
for(uint32 i = 0; i < KNOWN_TITLES_SIZE*2; ++i )
{
ss << GetUInt32Value(PLAYER__FIELD_KNOWN_TITLES + i) << " ";
}

View file

@ -59,6 +59,7 @@ typedef std::deque<Mail*> PlayerMails;
#define PLAYER_MAX_SKILLS 127
#define PLAYER_MAX_DAILY_QUESTS 25
#define PLAYER_EXPLORED_ZONES_SIZE 128
// Note: SPELLMOD_* values is aura types in fact
enum SpellModType
@ -548,7 +549,8 @@ enum PlayerFlags
#define PLAYER_TITLE_HAND_OF_ADAL UI64LIT(0x0000008000000000) // 39
#define PLAYER_TITLE_VENGEFUL_GLADIATOR UI64LIT(0x0000010000000000) // 40
#define MAX_TITLE_INDEX (3*64) // 3 uint64 fields
#define KNOWN_TITLES_SIZE 3
#define MAX_TITLE_INDEX (KNOWN_TITLES_SIZE*64) // 3 uint64 fields
// used in PLAYER_FIELD_BYTES values
enum PlayerFieldByteFlags
@ -1415,8 +1417,6 @@ class MANGOS_DLL_SPEC Player : public Unit
bool LoadFromDB(uint32 guid, SqlQueryHolder *holder);
static uint32 GetUInt32ValueFromArray(Tokens const& data, uint16 index);
static float GetFloatValueFromArray(Tokens const& data, uint16 index);
static uint32 GetZoneIdFromDB(uint64 guid);
static uint32 GetLevelFromDB(uint64 guid);
static bool LoadPositionFromDB(uint32& mapid, float& x,float& y,float& z,float& o, bool& in_flight, uint64 guid);
@ -2325,8 +2325,7 @@ class MANGOS_DLL_SPEC Player : public Unit
void _LoadEquipmentSets(QueryResult *result);
void _LoadBGData(QueryResult* result);
void _LoadGlyphs(QueryResult *result);
void _LoadExploredZones(const char* data);
void _LoadKnownTitles(const char* data);
void _LoadIntoDataField(const char* data, uint32 startOffset, uint32 count);
/*********************************************************/
/*** SAVE SYSTEM ***/

View file

@ -81,6 +81,23 @@ Tokens StrSplit(const std::string &src, const std::string &sep)
return r;
}
uint32 GetUInt32ValueFromArray(Tokens const& data, uint16 index)
{
if(index >= data.size())
return 0;
return (uint32)atoi(data[index].c_str());
}
float GetFloatValueFromArray(Tokens const& data, uint16 index)
{
float result;
uint32 temp = GetUInt32ValueFromArray(data,index);
memcpy(&result, &temp, sizeof(result));
return result;
}
void stripLineInvisibleChars(std::string &str)
{
static std::string invChars = " \t\7\n";

View file

@ -27,6 +27,8 @@
typedef std::vector<std::string> Tokens;
Tokens StrSplit(const std::string &src, const std::string &sep);
uint32 GetUInt32ValueFromArray(Tokens const& data, uint16 index);
float GetFloatValueFromArray(Tokens const& data, uint16 index);
void stripLineInvisibleChars(std::string &src);

View file

@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__
#define __REVISION_NR_H__
#define REVISION_NR "9632"
#define REVISION_NR "9634"
#endif // __REVISION_NR_H__

View file

@ -1,6 +1,6 @@
#ifndef __REVISION_SQL_H__
#define __REVISION_SQL_H__
#define REVISION_DB_CHARACTERS "required_9632_01_characters_characters"
#define REVISION_DB_CHARACTERS "required_9634_01_characters_corpse"
#define REVISION_DB_MANGOS "required_9622_01_mangos_gameobject"
#define REVISION_DB_REALMD "required_9010_01_realmd_realmlist"
#endif // __REVISION_SQL_H__