From a71ca293fbb942277403c262997d46e11f591a48 Mon Sep 17 00:00:00 2001 From: theluda Date: Wed, 4 Oct 2006 19:26:21 +0000 Subject: [PATCH] [2358] Applied MaNGOS coding style (see trunk/bcpp.cfg). --- src/framework/Platform/CompilerDefs.h | 1 - src/framework/Platform/Define.h | 2 +- src/game/ConfusedMovementGenerator.cpp | 2 +- src/game/DynamicObject.cpp | 1 - src/game/DynamicObject.h | 1 - src/game/GridNotifiers.h | 2 +- src/game/GridNotifiersImpl.h | 5 +- src/game/Item.cpp | 99 ++- src/game/MiscHandler.cpp | 21 +- src/game/NPCHandler.cpp | 10 +- src/game/ObjectMgr.cpp | 2 +- src/game/Player.cpp | 102 +-- src/game/Player.h | 36 +- src/game/Spell.cpp | 2 +- src/game/SpellAuras.cpp | 6 +- src/game/SpellEffects.cpp | 4 +- src/game/Unit.cpp | 16 +- src/game/World.cpp | 1320 ++++++++++++++++---------------- src/shared/Database/DBCStores.cpp | 2 +- 19 files changed, 814 insertions(+), 820 deletions(-) diff --git a/src/framework/Platform/CompilerDefs.h b/src/framework/Platform/CompilerDefs.h index bf6858f3..e54d37f7 100644 --- a/src/framework/Platform/CompilerDefs.h +++ b/src/framework/Platform/CompilerDefs.h @@ -55,5 +55,4 @@ # pragma warning( disable : 4267 ) // conversion from 'size_t' to 'int', possible loss of data # pragma warning( disable : 4786 ) // identifier was truncated to '255' characters in the debug information #endif - #endif diff --git a/src/framework/Platform/Define.h b/src/framework/Platform/Define.h index b9cf3e02..f3c31f9c 100644 --- a/src/framework/Platform/Define.h +++ b/src/framework/Platform/Define.h @@ -41,7 +41,7 @@ #if defined(__APPLE_CC__) && defined(BIG_ENDIAN) #define MANGOS_IMPORT __attribute__ ((longcall)) -#else +#else #define MANGOS_IMPORT __attribute__ ((cdecl)) #endif diff --git a/src/game/ConfusedMovementGenerator.cpp b/src/game/ConfusedMovementGenerator.cpp index cba05390..5b01c1b6 100644 --- a/src/game/ConfusedMovementGenerator.cpp +++ b/src/game/ConfusedMovementGenerator.cpp @@ -46,7 +46,7 @@ ConfusedMovementGenerator::Initialize(Creature &creature) { const float wanderX=((wander_distance*rand())/RAND_MAX)-wander_distance/2; const float wanderY=((wander_distance*rand())/RAND_MAX)-wander_distance/2; - + i_waypoints[idx][0] = x + wanderX; i_waypoints[idx][1] = y + wanderY; diff --git a/src/game/DynamicObject.cpp b/src/game/DynamicObject.cpp index 1ec5c656..b53a5495 100644 --- a/src/game/DynamicObject.cpp +++ b/src/game/DynamicObject.cpp @@ -95,7 +95,6 @@ void DynamicObject::Update(uint32 p_time) cell_lock->Visit(cell_lock, object_notifier, *MapManager::Instance().GetMap(m_caster->GetMapId())); } - void DynamicObject::Delete() { WorldPacket data; diff --git a/src/game/DynamicObject.h b/src/game/DynamicObject.h index 6599cd34..921555bf 100644 --- a/src/game/DynamicObject.h +++ b/src/game/DynamicObject.h @@ -52,5 +52,4 @@ class DynamicObject : public Object float m_radius; AffectedSet m_affected; }; - #endif diff --git a/src/game/GridNotifiers.h b/src/game/GridNotifiers.h index 3755ab69..a7a2bfbc 100644 --- a/src/game/GridNotifiers.h +++ b/src/game/GridNotifiers.h @@ -219,7 +219,7 @@ namespace MaNGOS }; template - struct MANGOS_DLL_DECL UnitSearcher + struct MANGOS_DLL_DECL UnitSearcher { Unit* &i_object; Check & i_check; diff --git a/src/game/GridNotifiersImpl.h b/src/game/GridNotifiersImpl.h index 76f8508f..1a5dcb33 100644 --- a/src/game/GridNotifiersImpl.h +++ b/src/game/GridNotifiersImpl.h @@ -182,7 +182,7 @@ MaNGOS::CreatureRelocationNotifier::Visit(std::map &m) } template<> -inline void +inline void MaNGOS::DynamicObjectUpdater::Visit(std::map &m) { for(std::map::iterator itr=m.begin(); itr != m.end(); ++itr) @@ -205,7 +205,7 @@ MaNGOS::DynamicObjectUpdater::Visit(std::map &m) } template<> -inline void +inline void MaNGOS::DynamicObjectUpdater::Visit(std::map &m) { for(std::map::iterator itr=m.begin(); itr != m.end(); ++itr) @@ -260,5 +260,4 @@ void MaNGOS::UnitSearcher::Visit(std::map &m) } i_object = i_check.GetResult(); } - #endif // MANGOS_GRIDNOTIFIERSIMPL_H diff --git a/src/game/Item.cpp b/src/game/Item.cpp index 6c216b8a..a0cb3480 100644 --- a/src/game/Item.cpp +++ b/src/game/Item.cpp @@ -583,12 +583,11 @@ uint32 Item::GetSpell() return 0; } -bool Item::IsEquipped() const -{ - return GetSlot() < EQUIPMENT_SLOT_END; +bool Item::IsEquipped() const +{ + return GetSlot() < EQUIPMENT_SLOT_END; } - void Item::SetItemRandomProperties() { /* @@ -656,7 +655,7 @@ void Item::SetItemRandomProperties() } else if(itemProto->Class == ITEM_CLASS_WEAPON) { - if((itemProto->SubClass == ITEM_SUBCLASS_WEAPON_GUN || itemProto->SubClass == ITEM_SUBCLASS_WEAPON_BOW + if((itemProto->SubClass == ITEM_SUBCLASS_WEAPON_GUN || itemProto->SubClass == ITEM_SUBCLASS_WEAPON_BOW || itemProto->SubClass == ITEM_SUBCLASS_WEAPON_THROWN) && irand(1,100) <= 50) { random_id = 1704 + uint32((1741-1704)/60*itemProto->ItemLevel);// of Marksmanship @@ -692,53 +691,53 @@ void Item::SetItemRandomProperties() else if(itemProto->SubClass == ITEM_SUBCLASS_WEAPON_GUN) enchant_id_1 = 174 + uint32(itemProto->ItemLevel/10); else if(itemProto->SubClass == ITEM_SUBCLASS_WEAPON_BOW) - enchant_id_1 = 181 + uint32(itemProto->ItemLevel/10); - random_id = 120; - }break; - default:break; - } - } - } - } + enchant_id_1 = 181 + uint32(itemProto->ItemLevel/10); + random_id = 120; + }break; + default:break; + } + } + } + } - if(itemProto->ItemLevel <= 10 && !random_id) - { - random_id = irand(1,80); - } - else if(itemProto->ItemLevel <= 20 && !random_id) - { - random_id = irand(81,156); - } - else if(itemProto->ItemLevel <= 30 && !random_id) - { - random_id = irand(167,220); - } - else if(itemProto->ItemLevel <= 50 && !random_id) - { - random_id = irand(308,434); - } - else if(itemProto->ItemLevel <= 60 && !random_id) - { - random_id = irand(1267,1296); - } + if(itemProto->ItemLevel <= 10 && !random_id) + { + random_id = irand(1,80); + } + else if(itemProto->ItemLevel <= 20 && !random_id) + { + random_id = irand(81,156); + } + else if(itemProto->ItemLevel <= 30 && !random_id) + { + random_id = irand(167,220); + } + else if(itemProto->ItemLevel <= 50 && !random_id) + { + random_id = irand(308,434); + } + else if(itemProto->ItemLevel <= 60 && !random_id) + { + random_id = irand(1267,1296); + } - ItemRandomProperties *item_rand = sItemRandomPropertiesStore.LookupEntry(random_id); + ItemRandomProperties *item_rand = sItemRandomPropertiesStore.LookupEntry(random_id); - if(item_rand) - { - if(random_id == 120) - { - SetUInt32Value(ITEM_FIELD_RANDOM_PROPERTIES_ID,120); - SetUInt32Value(ITEM_FIELD_ENCHANTMENT+9,enchant_id_1); - return; - } - SetUInt32Value(ITEM_FIELD_RANDOM_PROPERTIES_ID,item_rand->ID); - SetUInt32Value(ITEM_FIELD_ENCHANTMENT+9,item_rand->enchant_id_1); - SetUInt32Value(ITEM_FIELD_ENCHANTMENT+12,item_rand->enchant_id_2); - SetUInt32Value(ITEM_FIELD_ENCHANTMENT+15,item_rand->enchant_id_3); - } - } - } + if(item_rand) + { + if(random_id == 120) + { + SetUInt32Value(ITEM_FIELD_RANDOM_PROPERTIES_ID,120); + SetUInt32Value(ITEM_FIELD_ENCHANTMENT+9,enchant_id_1); + return; + } + SetUInt32Value(ITEM_FIELD_RANDOM_PROPERTIES_ID,item_rand->ID); + SetUInt32Value(ITEM_FIELD_ENCHANTMENT+9,item_rand->enchant_id_1); + SetUInt32Value(ITEM_FIELD_ENCHANTMENT+12,item_rand->enchant_id_2); + SetUInt32Value(ITEM_FIELD_ENCHANTMENT+15,item_rand->enchant_id_3); + } + } + } } */ -} \ No newline at end of file +} diff --git a/src/game/MiscHandler.cpp b/src/game/MiscHandler.cpp index 70b621db..21bc71ad 100644 --- a/src/game/MiscHandler.cpp +++ b/src/game/MiscHandler.cpp @@ -362,23 +362,22 @@ void WorldSession::HandleZoneUpdateOpcode( WorldPacket & recv_data ) uint32 newZone; WPAssert(GetPlayer()); - // if player is resting stop resting + // if player is resting stop resting if(GetPlayer()->HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_RESTING)) { - if(GetPlayer()->GetRestType()==2) //rest in city - { - //speed collect rest bonus (section/in hour) - float bubble=1;//0% Blizzlike - GetPlayer()->SetRestBonus( GetPlayer()->GetRestBonus()+ (time(NULL)-GetPlayer()->GetTimeInnEter())*0.0142108*bubble ); - if(GetPlayer()->GetRestBonus()>1534)GetPlayer()->SetRestBonus(1534); - GetPlayer()->RemoveFlag(PLAYER_FLAGS, PLAYER_FLAGS_RESTING); - } + if(GetPlayer()->GetRestType()==2) //rest in city + { + //speed collect rest bonus (section/in hour) + float bubble=1; //0% Blizzlike + GetPlayer()->SetRestBonus( GetPlayer()->GetRestBonus()+ (time(NULL)-GetPlayer()->GetTimeInnEter())*0.0142108*bubble ); + if(GetPlayer()->GetRestBonus()>1534)GetPlayer()->SetRestBonus(1534); + GetPlayer()->RemoveFlag(PLAYER_FLAGS, PLAYER_FLAGS_RESTING); + } } - recv_data >> newZone; sLog.outDetail("WORLD: Recvd ZONE_UPDATE: %u", newZone); - switch(newZone) + switch(newZone) { case 1497: case 1519: diff --git a/src/game/NPCHandler.cpp b/src/game/NPCHandler.cpp index 48a898f8..691fb93c 100644 --- a/src/game/NPCHandler.cpp +++ b/src/game/NPCHandler.cpp @@ -271,11 +271,11 @@ void WorldSession::HandleTrainerBuySpellOpcode( WorldPacket & recv_data ) SendPacket( &data ); _player->ModifyMoney( -int32(proto->spellcost) ); - if(spellInfo->powerType == 2) - { - _player->addSpell(spellId,4);// ative = 4 for spell book of hunter's pet - return; - } + if(spellInfo->powerType == 2) + { + _player->addSpell(spellId,4); // ative = 4 for spell book of hunter's pet + return; + } Spell *spell; if(proto->spell->SpellVisual == 222) diff --git a/src/game/ObjectMgr.cpp b/src/game/ObjectMgr.cpp index e663275c..422dd553 100644 --- a/src/game/ObjectMgr.cpp +++ b/src/game/ObjectMgr.cpp @@ -404,7 +404,7 @@ void ObjectMgr::LoadLvlUpGains() sLog.outError("Wrong class %u in `player_levelupgains` table, ignoring.",current_class); continue; } - + uint8 current_race = fields[0].GetUInt8(); if(current_race >= MAX_RACES) { diff --git a/src/game/Player.cpp b/src/game/Player.cpp index dc91d1ab..a9a57920 100644 --- a/src/game/Player.cpp +++ b/src/game/Player.cpp @@ -138,14 +138,14 @@ Player::Player (WorldSession *session): Unit() m_WeaponProficiency = 0; m_ArmorProficiency = 0; m_canParry = false; - ////////////////////Rest System///////////////////// + ////////////////////Rest System///////////////////// time_inn_enter=0; inn_pos_x=0; inn_pos_y=0; inn_pos_z=0; rest_bonus=0; rest_type=0; - ////////////////////Rest System///////////////////// + ////////////////////Rest System///////////////////// } Player::~Player () @@ -813,15 +813,15 @@ void Player::Update( uint32 p_time ) if(HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_RESTING)) { - if(GetRestType()==1) //rest in tavern + if(GetRestType()==1) //rest in tavern { - if(sqrt((GetPositionX()-GetInnPosX())*(GetPositionX()-GetInnPosX())+(GetPositionY()-GetInnPosY())*(GetPositionY()-GetInnPosY())+(GetPositionZ()-GetInnPosZ())*(GetPositionZ()-GetInnPosZ()))>40) - { - //speed collect rest bonus (section/in hour) - float bubble=1;//0% Blizzlike - if(GetTimeInnEter()>0)SetRestBonus( GetRestBonus()+ (time(NULL)-GetTimeInnEter())*0.0142108*bubble ); - RemoveFlag(PLAYER_FLAGS, PLAYER_FLAGS_RESTING); - } + if(sqrt((GetPositionX()-GetInnPosX())*(GetPositionX()-GetInnPosX())+(GetPositionY()-GetInnPosY())*(GetPositionY()-GetInnPosY())+(GetPositionZ()-GetInnPosZ())*(GetPositionZ()-GetInnPosZ()))>40) + { + //speed collect rest bonus (section/in hour) + float bubble=1; //0% Blizzlike + if(GetTimeInnEter()>0)SetRestBonus( GetRestBonus()+ (time(NULL)-GetTimeInnEter())*0.0142108*bubble ); + RemoveFlag(PLAYER_FLAGS, PLAYER_FLAGS_RESTING); + } } } @@ -1405,7 +1405,7 @@ void Player::GiveLevel() SetMaxHealth(uint32(newHP)); // only integer part for(int i = STAT_STRENGTH; i < MAX_STATS; ++i) - SetStat(Stats(i), uint32(newStats[i])); // only integer part + SetStat(Stats(i), uint32(newStats[i])); // only integer part // update dependent from level part BlockChanceWithoutMods = 5 + (GetDefenceSkillValue() - getLevel()*5)*0.04); UpdateBlockPercentage(0,1); @@ -2696,25 +2696,25 @@ void Player::UpdateCombatSkills(Unit *pVictim, WeaponAttackType attType, MeleeHi { switch(outcome) { - case MELEE_HIT_CRIT: - return; - case MELEE_HIT_DODGE: - return; - case MELEE_HIT_PARRY: - return; - case MELEE_HIT_BLOCK: - return; + case MELEE_HIT_CRIT: + return; + case MELEE_HIT_DODGE: + return; + case MELEE_HIT_PARRY: + return; + case MELEE_HIT_BLOCK: + return; - default: - break; + default: + break; } - - uint32 plevel = getLevel(); // if defence than pVictim == attacker + + uint32 plevel = getLevel(); // if defence than pVictim == attacker uint32 greylevel = MaNGOS::XP::GetGrayLevel(plevel); uint32 moblevel = pVictim->getLevel(); if(moblevel < greylevel) return; - + if (moblevel > plevel + 5) moblevel = plevel + 5; @@ -2724,7 +2724,7 @@ void Player::UpdateCombatSkills(Unit *pVictim, WeaponAttackType attType, MeleeHi uint32 skilldif = 5 * plevel - (defence ? GetPureDefenceSkillValue() : GetPureWeaponSkillValue(attType)); if(skilldif <= 0) - return; + return; float chance = 3 * lvldif * skilldif / plevel; if(!defence) @@ -2733,16 +2733,16 @@ void Player::UpdateCombatSkills(Unit *pVictim, WeaponAttackType attType, MeleeHi chance *= 0.1 * GetStat(STAT_INTELLECT); } - chance = chance < 1 ? 1 : chance; //minimum chance to increase skill is 1% - + chance = chance < 1 ? 1 : chance; //minimum chance to increase skill is 1% + if(chance > urand(0,100)) { if(defence) UpdateDefense(); else UpdateWeaponSkill(attType); - } - else + } + else return; } @@ -4448,19 +4448,20 @@ void Player::AddWeather() uint32 Player::GetXPRestBonus(uint32 xp) { - float xp_bl = (float)GetUInt32Value(PLAYER_NEXT_LEVEL_XP) / 20; //xp for 1 section - float blpoint_bl=0;//rested bonuse for 1 section + //xp for 1 section + float xp_bl = (float)GetUInt32Value(PLAYER_NEXT_LEVEL_XP) / 20; + float blpoint_bl=0; //rested bonuse for 1 section switch (getLevel()) { - case 1: {blpoint_bl=50.9;break;} - case 2: {blpoint_bl=51.05;break;} - case 3: {blpoint_bl=51.1;break;} - case 4: {blpoint_bl=51.1;break;} - default: {blpoint_bl=51.15;break;} + case 1: {blpoint_bl=50.9;break;} + case 2: {blpoint_bl=51.05;break;} + case 3: {blpoint_bl=51.1;break;} + case 4: {blpoint_bl=51.1;break;} + default: {blpoint_bl=51.15;break;} } - float rested_xp = (xp_bl/blpoint_bl) * GetRestBonus(); //xp for each rested bonus + float rested_xp = (xp_bl/blpoint_bl) * GetRestBonus(); //xp for each rested bonus - float rest_xp_percent = rested_xp / ((float)xp / 100); //% rest bonuse from total rest bonus + float rest_xp_percent = rested_xp / ((float)xp / 100); //% rest bonuse from total rest bonus if(rest_xp_percent>100)rest_xp_percent=100; sLog.outDetail("XP_GAIN: %f, value1=%f, rest_xp_percent=%f",(float)xp,(xp_bl/blpoint_bl),rest_xp_percent); @@ -6275,8 +6276,8 @@ uint8 Player::CanEquipItem( uint8 slot, uint16 &dest, Item *pItem, bool swap, bo if(mainItem->GetProto()->InventoryType == INVTYPE_2HWEAPON) return EQUIP_ERR_CANT_EQUIP_WITH_TWOHANDED; }else - // not let equip offhand item if mainhand not equiped - return EQUIP_ERR_ITEM_CANT_BE_EQUIPPED; + // not let equip offhand item if mainhand not equiped + return EQUIP_ERR_ITEM_CANT_BE_EQUIPPED; } @@ -8606,7 +8607,6 @@ void Player::KilledMonster( uint32 entry, uint64 guid ) reqkill = qInfo->ReqCreatureOrGOId[j]; - if ( reqkill == entry ) { reqkillcount = qInfo->ReqCreatureOrGOCount[j]; @@ -8653,7 +8653,6 @@ void Player::CastedCreature( uint32 entry, uint64 guid, uint32 spell_id ) reqCast = qInfo->ReqCreatureOrGOId[j]; - if ( reqCast == entry ) { reqCastCount = qInfo->ReqCreatureOrGOCount[j]; @@ -8955,13 +8954,13 @@ bool Player::LoadFromDB( uint32 guid ) rest_bonus = fields[20].GetFloat(); //speed collect rest bonus in offline, in logaut, far from tavern, city (section/in hour) - float bubble=0.0416; //100% Blizzlike + float bubble=0.0416; //100% Blizzlike //speed collect rest bonus in offline, in logaut, far from tavern, city (section/in hour) - float bubble1=0.083; //100% Blizzlike + float bubble1=0.083; //100% Blizzlike if((int)fields[22].GetUInt32()==1&&(int)fields[21].GetUInt32()>0) - SetRestBonus( GetRestBonus() + (time(NULL)-(int)fields[21].GetUInt32())*0.0142108*bubble1); + SetRestBonus( GetRestBonus() + (time(NULL)-(int)fields[21].GetUInt32())*0.0142108*bubble1); if((int)fields[22].GetUInt32()==0&&(int)fields[21].GetUInt32()>0) - SetRestBonus( GetRestBonus() + (time(NULL)-(int)fields[21].GetUInt32())*0.0142108*bubble); + SetRestBonus( GetRestBonus() + (time(NULL)-(int)fields[21].GetUInt32())*0.0142108*bubble); if(!IsPositionValid()) { @@ -9325,8 +9324,9 @@ void Player::SaveToDB() uint32 tmp_flags = GetUInt32Value(UNIT_FIELD_FLAGS); uint32 tmp_pflags = GetUInt32Value(PLAYER_FLAGS); - int is_logout_resting=0;//logaut far from tavern\city - if(!IsInWorld()&&HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_RESTING))is_logout_resting=1;//logaut, but in tavern\city + int is_logout_resting=0; //logaut far from tavern\city + //logaut, but in tavern\city + if(!IsInWorld()&&HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_RESTING))is_logout_resting=1; // Set player sit state to standing on save RemoveFlag(UNIT_FIELD_BYTES_1,PLAYER_STATE_SIT); @@ -9794,7 +9794,7 @@ void Player::PetSpellInitialize() data << uint16 (2) << uint16(State << 8) << uint16 (1) << uint16(State << 8) << uint16 (0) << uint16(State << 8); if(pet->GetUInt32Value(UNIT_FIELD_PETNUMBER)) - for(PlayerSpellMap::iterator itr = m_spells.begin();itr != m_spells.end();itr++) + for(PlayerSpellMap::iterator itr = m_spells.begin();itr != m_spells.end();itr++) { if(itr->second->active != 4) continue; @@ -9803,7 +9803,7 @@ void Player::PetSpellInitialize() data << uint8(addlist); if(pet->GetUInt32Value(UNIT_FIELD_PETNUMBER)) - for(PlayerSpellMap::iterator itr = m_spells.begin();itr != m_spells.end();itr++) + for(PlayerSpellMap::iterator itr = m_spells.begin();itr != m_spells.end();itr++) { if(itr->second->active != 4) continue; @@ -9826,7 +9826,7 @@ void Player::PetSpellInitialize() data << uint16(0x01); } } - + data << uint8(0x01) << uint32(0x6010) << uint32(0x00) << uint32(0x00) << uint16(0x00); GetSession()->SendPacket(&data); diff --git a/src/game/Player.h b/src/game/Player.h index 72a22f51..17243802 100644 --- a/src/game/Player.h +++ b/src/game/Player.h @@ -447,47 +447,47 @@ class MANGOS_DLL_SPEC Player : public Unit CastSpell(this,SPELL_PASSIVE_BATTLE_STANCE,true); } }; - - void InnEnter (int time,float x,float y,float z) + + void InnEnter (int time,float x,float y,float z) { - inn_pos_x = x; - inn_pos_y = y; - inn_pos_z = z; - time_inn_enter = time; + inn_pos_x = x; + inn_pos_y = y; + inn_pos_z = z; + time_inn_enter = time; }; void SetRestBonus (float rest_bonus_new) { - if(rest_bonus_new<0)rest_bonus_new=0; - if(rest_bonus_new>1534)rest_bonus_new=1534; - rest_bonus = rest_bonus_new; + if(rest_bonus_new<0)rest_bonus_new=0; + if(rest_bonus_new>1534)rest_bonus_new=1534; + rest_bonus = rest_bonus_new; }; void SetRestType(int n_r_type) { - rest_type = n_r_type; + rest_type = n_r_type; }; float GetInnPosX () { - return inn_pos_x; + return inn_pos_x; }; float GetInnPosY () { - return inn_pos_y; + return inn_pos_y; }; float GetInnPosZ () { - return inn_pos_z; + return inn_pos_z; }; float GetRestBonus () { - return rest_bonus; + return rest_bonus; }; int GetTimeInnEter () { - return time_inn_enter; + return time_inn_enter; }; int GetRestType () { - return rest_type; + return rest_type; }; void UnsummonPet(Creature* pet = NULL); @@ -1170,14 +1170,14 @@ class MANGOS_DLL_SPEC Player : public Unit uint32 m_ArmorProficiency; bool m_canParry; bool m_canDualWield; - ////////////////////Rest System///////////////////// + ////////////////////Rest System///////////////////// int time_inn_enter; float inn_pos_x; float inn_pos_y; float inn_pos_z; float rest_bonus; int rest_type; -////////////////////Rest System///////////////////// + ////////////////////Rest System///////////////////// }; int irand(int min, int max); diff --git a/src/game/Spell.cpp b/src/game/Spell.cpp index be3048aa..e9d8d8b5 100644 --- a/src/game/Spell.cpp +++ b/src/game/Spell.cpp @@ -658,7 +658,7 @@ void Spell::cast() } //if( ( IsAutoRepeat() || m_rangedShoot ) && m_caster->GetTypeId() == TYPEID_PLAYER ) - //((Player*)m_caster)->UpdateWeaponSkill(RANGED_ATTACK); + //((Player*)m_caster)->UpdateWeaponSkill(RANGED_ATTACK); } if(m_spellState != SPELL_STATE_CASTING) diff --git a/src/game/SpellAuras.cpp b/src/game/SpellAuras.cpp index 65d2cf0d..f4d2d734 100644 --- a/src/game/SpellAuras.cpp +++ b/src/game/SpellAuras.cpp @@ -245,7 +245,7 @@ Aura::~Aura() { } -AreaAura::AreaAura(SpellEntry* spellproto, uint32 eff, Unit *target, +AreaAura::AreaAura(SpellEntry* spellproto, uint32 eff, Unit *target, Unit *caster, Item* castItem) : Aura(spellproto, eff, target, caster, castItem) { m_isAreaAura = true; @@ -255,7 +255,7 @@ AreaAura::~AreaAura() { } -PersistentAreaAura::PersistentAreaAura(SpellEntry* spellproto, uint32 eff, Unit *target, +PersistentAreaAura::PersistentAreaAura(SpellEntry* spellproto, uint32 eff, Unit *target, Unit *caster, Item* castItem) : Aura(spellproto, eff, target, caster, castItem) { m_isPersistent = true; @@ -507,7 +507,7 @@ void PersistentAreaAura::Update(uint32 diff) } else remove = true; - + Aura::Update(diff); if(remove) diff --git a/src/game/SpellEffects.cpp b/src/game/SpellEffects.cpp index 1c40f29b..0a9ec4e5 100644 --- a/src/game/SpellEffects.cpp +++ b/src/game/SpellEffects.cpp @@ -1026,12 +1026,11 @@ void Spell::EffectEnchantItemTmp(uint32 i) if(uint32 old_enchant_id = itemTarget->GetUInt32Value(ITEM_FIELD_ENCHANTMENT+1*3)) { p_caster->AddItemEnchant(itemTarget,old_enchant_id,false); - // duration == 0 wiil remove EnchantDuration + // duration == 0 wiil remove EnchantDuration p_caster->AddEnchantDuration(itemTarget,1,0); } } - for(int x=0;x<3;x++) itemTarget->SetUInt32Value(ITEM_FIELD_ENCHANTMENT+3+x,0); @@ -1582,7 +1581,6 @@ void Spell::EffectEnchantHeldItem(uint32 i) if(!itemTarget->IsEquipped()) return; - if (m_spellInfo->EffectMiscValue[i]) { uint32 enchant_id = m_spellInfo->EffectMiscValue[i]; diff --git a/src/game/Unit.cpp b/src/game/Unit.cpp index 94392c51..787c8576 100644 --- a/src/game/Unit.cpp +++ b/src/game/Unit.cpp @@ -767,9 +767,9 @@ void Unit::DoAttackDamage (Unit *pVictim, uint32 *damage, uint32 *blocked_amount *damage += CalculateDamage (attType); if(GetTypeId() == TYPEID_PLAYER && pVictim->GetTypeId() != TYPEID_PLAYER && ((Creature*)pVictim)->GetCreatureInfo()->type != 8 ) - ((Player*)this)->UpdateCombatSkills(pVictim, attType, outcome, false); + ((Player*)this)->UpdateCombatSkills(pVictim, attType, outcome, false); if(GetTypeId() != TYPEID_PLAYER && pVictim->GetTypeId() == TYPEID_PLAYER) - ((Player*)pVictim)->UpdateCombatSkills(this, attType, outcome, true); + ((Player*)pVictim)->UpdateCombatSkills(this, attType, outcome, true); switch (outcome) { @@ -1162,7 +1162,7 @@ MeleeHitOutcome Unit::RollMeleeOutcomeAgainst (const Unit *pVictim, WeaponAttack // mobs can score crushing blows if they're 3 or more levels above victim // or when their weapon skill is 15 or more above victim's defense skill tmp = pVictim->GetDefenceSkillValue(); - uint32 tmpmax = pVictim->getLevel() * 5; + uint32 tmpmax = pVictim->getLevel() * 5; // having defense above your maximum (from items, talents etc.) has no effect tmp = tmp > tmpmax ? tmpmax : tmp; // tmp = mob's level * 5 - player's current defense skill @@ -1249,7 +1249,8 @@ int32 Unit::SpellMissChanceCalc(Unit *pVictim) const if(!pVictim) return 0; - int32 chance = pVictim->GetTypeId() == TYPEID_PLAYER ? 700 : 1100; // PvP : PvE spell misschances per leveldif > 2 + // PvP : PvE spell misschances per leveldif > 2 + int32 chance = pVictim->GetTypeId() == TYPEID_PLAYER ? 700 : 1100; int32 leveldif = pVictim->getLevel() - getLevel(); if(leveldif < 0) @@ -1269,9 +1270,10 @@ int32 Unit::MeleeMissChanceCalc(const Unit *pVictim) const if(!pVictim) return 0; - int32 misschance = haveOffhandWeapon() ? 2400 : 500; //base misschance for DW : melee attacks + int32 misschance = haveOffhandWeapon() ? 2400 : 500; //base misschance for DW : melee attacks - int32 chance = pVictim->GetTypeId() == TYPEID_PLAYER ? 500 : 700; // PvP : PvE melee misschances per leveldif > 2 + // PvP : PvE melee misschances per leveldif > 2 + int32 chance = pVictim->GetTypeId() == TYPEID_PLAYER ? 500 : 700; int32 leveldif = pVictim->getLevel() - getLevel(); if(leveldif < 0) @@ -1281,7 +1283,7 @@ int32 Unit::MeleeMissChanceCalc(const Unit *pVictim) const misschance += leveldif * 100 - m_modHitChance*100; else misschance += (leveldif - 2) * chance - m_modHitChance*100; - + return misschance > 6000 ? 6000 : misschance; } diff --git a/src/game/World.cpp b/src/game/World.cpp index 5398f8e0..1ba693d9 100644 --- a/src/game/World.cpp +++ b/src/game/World.cpp @@ -1,660 +1,660 @@ -/* - * Copyright (C) 2005,2006 MaNGOS - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include "Common.h" -#include "Database/DatabaseEnv.h" -#include "Config/ConfigEnv.h" -#include "Log.h" -#include "Opcodes.h" -#include "WorldSocket.h" -#include "WorldSession.h" -#include "WorldPacket.h" -#include "Weather.h" -#include "Player.h" -#include "World.h" -#include "ObjectMgr.h" -#include "Group.h" -#include "UpdateData.h" -#include "Chat.h" -#include "Database/DBCStores.h" -#include "ChannelMgr.h" -#include "LootMgr.h" -#include "MapManager.h" -#include "ScriptCalls.h" -#include "CreatureAIRegistry.h" // need for Game::Initialize() -#include "Policies/SingletonImp.h" -#include "EventSystem.h" -#include "GlobalEvents.h" -#include "BattleGroundMgr.h" -#include "SystemConfig.h" -#include "AddonHandler.h" -#include "zlib/zlib.h" - -#include - -INSTANTIATE_SINGLETON_1( World ); - -volatile bool World::m_stopEvent = false; - -World::World() -{ - m_playerLimit = 0; - m_allowMovement = true; - m_Last_tick = time(NULL); - m_ShutdownTimer = 0; -} - -World::~World() -{ - for (WeatherMap::iterator itr = m_weathers.begin(); itr != m_weathers.end(); ++itr) - delete itr->second; - m_weathers.clear(); -} - -Player* World::FindPlayerInZone(uint32 zone) -{ - SessionMap::iterator itr, next; - for (itr = m_sessions.begin(); itr != m_sessions.end(); itr = next) - { - next = itr; - next++; - - if(!itr->second) - continue; - Player *player = itr->second->GetPlayer(); - if(!player) - continue; - if( player->IsInWorld() && player->GetZoneId() == zone ) - { - return player; - } - } - return NULL; -} - -WorldSession* World::FindSession(uint32 id) const -{ - SessionMap::const_iterator itr = m_sessions.find(id); - - if(itr != m_sessions.end()) - return itr->second; - else - return 0; -} - -void World::RemoveSession(uint32 id) -{ - SessionMap::iterator itr = m_sessions.find(id); - - if(itr != m_sessions.end()) - { - delete itr->second; - m_sessions.erase(itr); - } -} - -void World::AddSession(WorldSession* s) -{ - ASSERT(s); - m_sessions[s->GetAccountId()] = s; -} - -Weather* World::FindWeather(uint32 id) const -{ - WeatherMap::const_iterator itr = m_weathers.find(id); - - if(itr != m_weathers.end()) - return itr->second; - else - return 0; -} - -void World::RemoveWeather(uint32 id) -{ - WeatherMap::iterator itr = m_weathers.find(id); - - if(itr != m_weathers.end()) - { - delete itr->second; - m_weathers.erase(itr); - } -} - -void World::AddWeather(Weather* w) -{ - ASSERT(w); - m_weathers[w->GetZone()] = w; -} - -void World::SetInitialWorldSettings() -{ - std::string dataPath="./"; - - srand((unsigned int)time(NULL)); - m_lastTick = time(NULL); - - time_t tiempo; - char hour[3]; - char minute[3]; - char second[3]; - struct tm *tmPtr; - tiempo = time(NULL); - tmPtr = localtime(&tiempo); - strftime( hour, 3, "%H", tmPtr ); - strftime( minute, 3, "%M", tmPtr ); - strftime( second, 3, "%S", tmPtr ); - - if(!sConfig.GetString("DataDir",&dataPath)) - dataPath="./"; - else - { - if((dataPath.at(dataPath.length()-1)!='/') && (dataPath.at(dataPath.length()-1)!='\\')) - dataPath.append("/"); - } - sLog.outString("Using DataDir %s ...",dataPath.c_str()); - - // Non-critical warning about conf file version - uint32 confVersion = sConfig.GetIntDefault("ConfVersion", 0); - if(!confVersion) - { - sLog.outError("*****************************************************************************"); - sLog.outError(" WARNING: mangosd.conf does not include a ConfVersion variable."); - sLog.outError(" Your conf file may be out of date!"); - sLog.outError("*****************************************************************************"); - clock_t pause = 3000 + clock(); - while (pause > clock()); - } - else - { - if (confVersion < _MANGOSDCONFVERSION) - { - sLog.outError("*****************************************************************************"); - sLog.outError(" WARNING: Your mangosd.conf version indicates your conf file is out of date!"); - sLog.outError(" Please check for updates, as your current default values may cause"); - sLog.outError(" strange behavior."); - sLog.outError("*****************************************************************************"); - clock_t pause = 3000 + clock(); - while (pause > clock()); - } - } - - regen_values[RATE_HEALTH] = sConfig.GetFloatDefault("Rate.Health", 1); - regen_values[RATE_POWER_MANA] = sConfig.GetFloatDefault("Rate.Power1", 1); - regen_values[RATE_POWER_RAGE] = sConfig.GetFloatDefault("Rate.Power2", 1); - regen_values[RATE_POWER_FOCUS] = sConfig.GetFloatDefault("Rate.Power3", 1); - regen_values[RATE_DROP_ITEMS] = sConfig.GetFloatDefault("Rate.Drop.Items", 1); - regen_values[RATE_DROP_MONEY] = sConfig.GetFloatDefault("Rate.Drop.Money", 1); - regen_values[RATE_XP_KILL] = sConfig.GetFloatDefault("Rate.XP.Kill", 1); - regen_values[RATE_XP_QUEST] = sConfig.GetFloatDefault("Rate.XP.Quest", 1); - regen_values[RATE_XP_EXPLORE] = sConfig.GetFloatDefault("Rate.XP.Explore", 1); - regen_values[RATE_CREATURE_NORMAL_DAMAGE] = sConfig.GetFloatDefault("Rate.Creature.Normal.Damage", 1); - regen_values[RATE_CREATURE_ELITE_ELITE_DAMAGE] = sConfig.GetFloatDefault("Rate.Creature.Elite.Elite.Damage", 1); - regen_values[RATE_CREATURE_ELITE_RAREELITE_DAMAGE] = sConfig.GetFloatDefault("Rate.Creature.Elite.RAREELITE.Damage", 1); - regen_values[RATE_CREATURE_ELITE_WORLDBOSS_DAMAGE] = sConfig.GetFloatDefault("Rate.Creature.Elite.WORLDBOSS.Damage", 1); - regen_values[RATE_CREATURE_ELITE_RARE_DAMAGE] = sConfig.GetFloatDefault("Rate.Creature.Elite.RARE.Damage", 1); - regen_values[RATE_CREATURE_NORMAL_HP] = sConfig.GetFloatDefault("Rate.Creature.Normal.HP", 1); - regen_values[RATE_CREATURE_ELITE_ELITE_HP] = sConfig.GetFloatDefault("Rate.Creature.Elite.Elite.HP", 1); - regen_values[RATE_CREATURE_ELITE_RAREELITE_HP] = sConfig.GetFloatDefault("Rate.Creature.Elite.RAREELITE.HP", 1); - regen_values[RATE_CREATURE_ELITE_WORLDBOSS_HP] = sConfig.GetFloatDefault("Rate.Creature.Elite.WORLDBOSS.HP", 1); - regen_values[RATE_CREATURE_ELITE_RARE_HP] = sConfig.GetFloatDefault("Rate.Creature.Elite.RARE.HP", 1); - regen_values[RATE_CREATURE_AGGRO] = sConfig.GetFloatDefault("Rate.Creature.Aggro", 1); - m_configs[CONFIG_LOG_LEVEL] = sConfig.GetIntDefault("LogLevel", 0); - m_configs[CONFIG_LOG_WORLD] = sConfig.GetIntDefault("LogWorld", 0); - m_configs[CONFIG_COMPRESSION] = sConfig.GetIntDefault("Compression", 1); - if(m_configs[CONFIG_COMPRESSION] < 1 || m_configs[CONFIG_COMPRESSION] > 9) - { - sLog.outError("Compression level (%i) must be in range 1..9. Using default compression level (1),.",m_configs[CONFIG_COMPRESSION]); - m_configs[CONFIG_COMPRESSION] = 1; - } - m_configs[CONFIG_GRID_UNLOAD] = sConfig.GetIntDefault("GridUnload", 1); - m_configs[CONFIG_INTERVAL_SAVE] = sConfig.GetIntDefault("PlayerSaveInterval", 900000); - m_configs[CONFIG_INTERVAL_GRIDCLEAN] = sConfig.GetIntDefault("GridCleanUpDelay", 300000); - m_configs[CONFIG_INTERVAL_MAPUPDATE] = sConfig.GetIntDefault("MapUpdateInterval", 100); - m_configs[CONFIG_INTERVAL_CHANGEWEATHER] = sConfig.GetIntDefault("ChangeWeatherInterval", 600000); - m_configs[CONFIG_PORT_WORLD] = sConfig.GetIntDefault("WorldServerPort", 8085); - m_configs[CONFIG_PORT_REALM] = sConfig.GetIntDefault("RealmServerPort", 3724); - m_configs[CONFIG_SOCKET_SELECTTIME] = sConfig.GetIntDefault("SocketSelectTime", 10000); - m_configs[CONFIG_GROUP_XP_DISTANCE] = sConfig.GetIntDefault("MaxGroupXPDistance", 74); - m_configs[CONFIG_GROUP_XP_DISTANCE] = m_configs[CONFIG_GROUP_XP_DISTANCE]*m_configs[CONFIG_GROUP_XP_DISTANCE]; - m_configs[CONFIG_GROUP_XP_LEVELDIFF] = sConfig.GetIntDefault("MaxGroupXPLevelDiff", 10); - m_configs[CONFIG_SIGHT_MONSTER] = sConfig.GetIntDefault("MonsterSight", 400); - m_configs[CONFIG_SIGHT_GUARDER] = sConfig.GetIntDefault("GuarderSight", 500); - m_configs[CONFIG_GAME_TYPE] = sConfig.GetIntDefault("GameType", 0); - m_configs[CONFIG_ALLOW_TWO_SIDE_ACCOUNTS] = sConfig.GetIntDefault("AllowTwoSide.Accounts", 0); - m_configs[CONFIG_ALLOW_TWO_SIDE_INTERACTION] = sConfig.GetIntDefault("AllowTwoSide.Interaction",0); - m_configs[CONFIG_ALLOW_TWO_SIDE_WHO_LIST] = sConfig.GetIntDefault("AllowTwoSide.WhoList", 0); - m_configs[CONFIG_MAX_PLAYER_LEVEL] = sConfig.GetIntDefault("MaxPlayerLevel", 60); - m_configs[CONFIG_MAX_PRIMARY_TRADE_SKILL] = sConfig.GetIntDefault("MaxPrimaryTradeSkill", 2); - m_configs[CONFIG_WISPERING_TO_GM] = sConfig.GetIntDefault("WhisperingToGM",0); - - m_gameTime = (3600*atoi(hour))+(atoi(minute)*60)+(atoi(second)); - - // check existance map files (startup race areas). - if( !MapManager::ExistMAP(0,-6240.32, 331.033) - ||!MapManager::ExistMAP(0,-8949.95,-132.493) - ||!MapManager::ExistMAP(0,-8949.95,-132.493) - ||!MapManager::ExistMAP(1,-618.518,-4251.67) - ||!MapManager::ExistMAP(0, 1676.35, 1677.45) - ||!MapManager::ExistMAP(1, 10311.3, 832.463) - ||!MapManager::ExistMAP(1,-2917.58,-257.98)) - { - sLog.outError("Correct *.map files not found by path '%smap'. Please place *.map files in directory by this path or correct DataDir value in mangosd.conf file.",dataPath.c_str()); - exit(1); - } - - //duplicate - //sDatabase.PExecute("UPDATE `character` SET `online` = 0"); - - //Update realm list - loginDatabase.PExecute("UPDATE `realmlist` SET `icon` = %u WHERE `id` = '%d'", m_configs[CONFIG_GAME_TYPE],sConfig.GetIntDefault("RealmID", 1)); - - // remove bones after restart - sDatabase.PExecute("DELETE FROM `corpse` WHERE `bones_flag` = '1'"); - - new ChannelMgr; - - sLog.outString("Initialize data stores..."); - LoadDBCStores(dataPath); - - sLog.outString( "Loading levelup stat gains..." ); - objmgr.LoadLvlUpGains(); - - sLog.outString( "Loading Quests..." ); - objmgr.LoadQuests(); - - sLog.outString( "Loading NPC Texts..." ); - objmgr.LoadGossipText(); - - sLog.outString( "Loading Quest Area Triggers..." ); - objmgr.LoadAreaTriggerPoints(); - - sLog.outString( "Loading Items..." ); - objmgr.LoadItemPrototypes(); - objmgr.LoadAuctions(); - objmgr.LoadAuctionItems(); - objmgr.LoadMailedItems(); - - sLog.outString( "Loading Creature templates..." ); - objmgr.LoadCreatureTemplates(); - - sLog.outString( "Loading Guilds..." ); - objmgr.LoadGuilds(); - - sLog.outString( "Loading Teleport Coords..." ); - objmgr.LoadTeleportCoords(); - - objmgr.SetHighestGuids(); - - sLog.outString( "Loading Loot Tables..." ); - LoadLootTables(); - - sLog.outString( "Loading Game Object Templates..." ); - objmgr.LoadGameobjectInfo(); - - sLog.outString( "Initializing Scripts..." ); - if(!LoadScriptingModule()) - exit(1); - - m_timers[WUPDATE_OBJECTS].SetInterval(0); - m_timers[WUPDATE_SESSIONS].SetInterval(0); - m_timers[WUPDATE_WEATHERS].SetInterval(1000); - m_timers[WUPDATE_AUCTIONS].SetInterval(1000); - - sLog.outString( "WORLD: Starting BattleGround System" ); - sBattleGroundMgr.CreateInitialBattleGrounds(); - - MaNGOS::Game::Initialize(); - sLog.outString( "WORLD: SetInitialWorldSettings done" ); - - sLog.outString( "WORLD: Starting Event System" ); - StartEventSystem(); - - //Start Addon stuff - bool temp = sConfig.GetBoolDefault("AddonDefault", 1); - sLog.outString( "WORLD: Starting Addon System, AddonDefault:%d (%s all addons not registered in DB)", temp, temp? "Enabled" : "Disabled" ); - sAddOnHandler.SetAddonDefault(temp); - sAddOnHandler._LoadFromDB(); - - sLog.outString( "WORLD: Starting Corpse Handler" ); - // global event to erase corpses/bones - // deleting expired bones time > 20 minutes and corpses > 3 days - // it is run each 20 minutes - // need good tests on windows - AddEvent(&HandleCorpsesErase,NULL,20*60,false,true); -} - -void World::Update(time_t diff) -{ - for(int i = 0; i < WUPDATE_COUNT; i++) - if(m_timers[i].GetCurrent()>=0) - m_timers[i].Update(diff); - else m_timers[i].SetCurrent(0); - - _UpdateGameTime(); - - if (m_timers[WUPDATE_AUCTIONS].Passed()) - { - m_timers[WUPDATE_AUCTIONS].Reset(); - ObjectMgr::AuctionEntryMap::iterator itr,next; - for (itr = objmgr.GetAuctionsBegin(); itr != objmgr.GetAuctionsEnd();itr = next) - { - next = itr; - next++; - if (time(NULL) > (itr->second->time)) - { - if (itr->second->bidder == 0) // if noone bidded auction... - { - Item *it = objmgr.GetAItem(itr->second->item); - if(it) - { - Mail *m = new Mail; - m->receiver = itr->second->owner; - m->body = ""; - m->sender = itr->second->owner; - m->checked = 0; - m->COD = 0; // there might be deposit - m->messageID = objmgr.GenerateMailID(); - m->money = 0; - m->time = time(NULL) + (29 * 3600); - m->subject = "Your item failed to sell"; - m->item = itr->second->item; - objmgr.AddMItem(it); - - std::ostringstream ss; - ss << "INSERT INTO `mail_item` (`guid`,`data`) VALUES (" - << it->GetGUIDLow() << ", '"; - for(uint16 i = 0; i < it->GetValuesCount(); i++ ) - { - ss << it->GetUInt32Value(i) << " "; - } - ss << "' )"; - sDatabase.Execute( ss.str().c_str() ); - - sDatabase.PExecute("DELETE FROM `mail` WHERE `id` = '%u'",m->messageID); - sDatabase.PExecute("INSERT INTO `mail` (`id`,`sender`,`receiver`,`subject`,`body`,`item`,`time`,`money`,`cod`,`checked`) VALUES ('%u', '%u', '%u', '%s', '%s', '%u', '" I64FMTD "', '%u', '%u', '%u')", m->messageID, m->sender, m->receiver, m->subject.c_str(), m->body.c_str(), m->item, (uint64)m->time, m->money, 0, 0); - - Player *rpl = objmgr.GetPlayer(m->receiver); - if (rpl) - { - rpl->AddMail(m); - } - else - delete m; - } - else - sLog.outError("Auction item %u not found, and lost.",itr->second->item); - - sDatabase.PExecute("DELETE FROM `auctionhouse` WHERE `itemowner` = '%u'",itr->second->owner); - sDatabase.PExecute("DELETE FROM `auctionhouse` WHERE `id` = '%u'",itr->second->Id); - sDatabase.PExecute("DELETE FROM `auctionhouse_item` WHERE `guid` = '%u'",itr->second->item); - - objmgr.RemoveAItem(itr->second->item); - objmgr.RemoveAuction(itr->second->Id); - } - else - { - Mail *m = new Mail; - m->receiver = itr->second->owner; - m->body = ""; - m->sender = itr->second->bidder; - m->checked = 0; - m->COD = 0; - m->messageID = objmgr.GenerateMailID(); - m->money = itr->second->bid; - m->time = time(NULL) + (29 * 3600); - m->subject = "Your item sold!"; - m->item = 0; - - sDatabase.PExecute("DELETE FROM `mail` WHERE `id` = '%u'",m->messageID); - sDatabase.PExecute("INSERT INTO `mail` (`id`,`sender`,`receiver`,`subject`,`body`,`item`,`time`,`money`,`cod`,`checked`) VALUES ('%u', '%u', '%u', '%s', '%s', '%u', '" I64FMTD "', '%u', '%u', '%u')", m->messageID, m->sender, m->receiver, m->subject.c_str(), m->body.c_str(), m->item, (uint64)m->time, m->money, 0, 0); - - Player *rpl = objmgr.GetPlayer(m->receiver); - if (rpl) - { - rpl->AddMail(m); - } - else - delete m; - - Mail *mn = new Mail; - mn->receiver = itr->second->bidder; - mn->body = ""; - mn->sender = itr->second->owner; - mn->checked = 0; - mn->COD = 0; - mn->messageID = objmgr.GenerateMailID(); - mn->money = 0; - mn->time = time(NULL) + (29 * 3600); - mn->subject = "Your won an item!"; - mn->item = itr->second->item; - Item *it = objmgr.GetAItem(itr->second->item); - objmgr.AddMItem(it); - - std::ostringstream ss; - ss << "INSERT INTO `mail_item` (`guid`,`data`) VALUES (" - << it->GetGUIDLow() << ", '"; - for(uint16 i = 0; i < it->GetValuesCount(); i++ ) - { - ss << it->GetUInt32Value(i) << " "; - } - ss << "' )"; - sDatabase.Execute( ss.str().c_str() ); - - sDatabase.PExecute("DELETE FROM `mail` WHERE `id` = '%u'", mn->messageID); - sDatabase.PExecute("INSERT INTO `mail` (`id`,`sender`,`receiver`,`subject`,`body`,`item`,`time`,`money`,`cod`,`checked`) VALUES ('%u', '%u', '%u', '%s', '%s', '%u', '" I64FMTD "', '%u', '%u', '%u')", mn->messageID, mn->sender, mn->receiver, mn->subject.c_str(), mn->body.c_str(), mn->item, (uint64)mn->time, mn->money, 0, 0); - - Player *rpl1 = objmgr.GetPlayer(mn->receiver); - if (rpl1) - { - rpl1->AddMail(mn); - } - else - delete mn; - - sDatabase.PExecute("DELETE FROM `auctionhouse` WHERE `id` = '%u'",itr->second->Id); - sDatabase.PExecute("DELETE FROM `auctionhouse_item` WHERE `guid` = '%u'",itr->second->item); - - objmgr.RemoveAItem(itr->second->item); - objmgr.RemoveAuction(itr->second->Id); - } - } - } - } - if (m_timers[WUPDATE_SESSIONS].Passed()) - { - m_timers[WUPDATE_SESSIONS].Reset(); - - SessionMap::iterator itr, next; - for (itr = m_sessions.begin(); itr != m_sessions.end(); itr = next) - { - next = itr; - next++; - - if(!itr->second->Update(diff)) - { - delete itr->second; - m_sessions.erase(itr); - } - } - } - - if (m_timers[WUPDATE_WEATHERS].Passed()) - { - m_timers[WUPDATE_WEATHERS].Reset(); - - WeatherMap::iterator itr, next; - for (itr = m_weathers.begin(); itr != m_weathers.end(); itr = next) - { - next = itr; - next++; - - if(!itr->second->Update(diff)) - { - delete itr->second; - m_weathers.erase(itr); - } - } - } - - if (m_timers[WUPDATE_OBJECTS].Passed()) - { - m_timers[WUPDATE_OBJECTS].Reset(); - MapManager::Instance().Update(diff); - } - - // move all creatures with delayed move and remove and delete all objects with delayed remove - ObjectAccessor::Instance().DoDelayedMovesAndRemoves(); -} - -void World::SendGlobalMessage(WorldPacket *packet, WorldSession *self) -{ - SessionMap::iterator itr; - for (itr = m_sessions.begin(); itr != m_sessions.end(); itr++) - { - if (itr->second->GetPlayer() && - itr->second->GetPlayer()->IsInWorld() - && itr->second != self) - { - itr->second->SendPacket(packet); - } - } -} - -void World::SendWorldText(const char* text, WorldSession *self) -{ - WorldPacket data; - sChatHandler.FillSystemMessageData(&data, 0, text); - SendGlobalMessage(&data, self); -} - -void World::SendZoneMessage(uint32 zone, WorldPacket *packet, WorldSession *self) -{ - SessionMap::iterator itr; - for (itr = m_sessions.begin(); itr != m_sessions.end(); itr++) - { - Player *player = itr->second->GetPlayer(); - if ( player && player->IsInWorld() && player->GetZoneId() == zone && itr->second != self) - { - itr->second->SendPacket(packet); - } - } -} - -void World::SendZoneText(uint32 zone, const char* text, WorldSession *self) -{ - WorldPacket data; - sChatHandler.FillSystemMessageData(&data, 0, text); - SendZoneMessage(zone, &data, self); -} - -void World::KickPlayer(char* playerName) -{ - SessionMap::iterator itr, next; - WorldSession *playerToKick = 0; - - int y = 0; - while (!playerName[y] == 0) - { - if ((playerName[y] >= 'a') && (playerName[y] <= 'z')) - playerName[y] -= 'a' - 'A'; - y++; - } - - for (itr = m_sessions.begin(); itr != m_sessions.end(); itr = next) - { - next = itr; - next++; - if(!itr->second) - continue; - Player *player = itr->second->GetPlayer(); - if(!player) - continue; - if( player->IsInWorld() ) - { - char *tmpPlayerName = new char[strlen(player->GetName()) + 1]; - strcpy(tmpPlayerName, player->GetName()); - y = 0; - while (!tmpPlayerName[y] == 0) - { - if ((tmpPlayerName[y] >= 'a') && (tmpPlayerName[y] <= 'z')) - tmpPlayerName[y] -= 'a' - 'A'; - y++; - } - if (strcmp(playerName, tmpPlayerName) == 0) - playerToKick = itr->second; - delete[] tmpPlayerName; - } - } - if (playerToKick) - { - playerToKick->LogoutPlayer(true); - } -} - -time_t World::_UpdateGameTime() -{ - time_t thisTime = time(NULL); - - if(m_lastTick == 0) - m_lastTick = thisTime; - - uint32 elapsed = uint32(thisTime - m_Last_tick); - - if(m_ShutdownTimer > 0 && elapsed > 0) - { - if( m_ShutdownTimer <= elapsed ) - { - m_stopEvent = true; - } - else - { - m_ShutdownTimer -= elapsed; - ShuttDownMsg(); - } - } - - m_gameTime += elapsed; - - m_Last_tick = thisTime; - - return m_gameTime; -} - -void World::ShutdownServ(uint32 time) -{ - m_ShutdownTimer = time; -} - -void World::ShuttDownMsg() -{ - WorldPacket data; - - data.Initialize(SMSG_SERVER_MESSAGE); - - std::ostringstream ss; - ss << m_ShutdownTimer << " Second(s)."; - - data << uint32(1) << ss.str().c_str() << (uint8)0x00; - - SendGlobalMessage( &data ); - - data.clear(); - ss.clear(); - - DEBUG_LOG("Server is shuttingdown in %d seconds",m_ShutdownTimer); -} +/* + * Copyright (C) 2005,2006 MaNGOS + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "Common.h" +#include "Database/DatabaseEnv.h" +#include "Config/ConfigEnv.h" +#include "Log.h" +#include "Opcodes.h" +#include "WorldSocket.h" +#include "WorldSession.h" +#include "WorldPacket.h" +#include "Weather.h" +#include "Player.h" +#include "World.h" +#include "ObjectMgr.h" +#include "Group.h" +#include "UpdateData.h" +#include "Chat.h" +#include "Database/DBCStores.h" +#include "ChannelMgr.h" +#include "LootMgr.h" +#include "MapManager.h" +#include "ScriptCalls.h" +#include "CreatureAIRegistry.h" // need for Game::Initialize() +#include "Policies/SingletonImp.h" +#include "EventSystem.h" +#include "GlobalEvents.h" +#include "BattleGroundMgr.h" +#include "SystemConfig.h" +#include "AddonHandler.h" +#include "zlib/zlib.h" + +#include + +INSTANTIATE_SINGLETON_1( World ); + +volatile bool World::m_stopEvent = false; + +World::World() +{ + m_playerLimit = 0; + m_allowMovement = true; + m_Last_tick = time(NULL); + m_ShutdownTimer = 0; +} + +World::~World() +{ + for (WeatherMap::iterator itr = m_weathers.begin(); itr != m_weathers.end(); ++itr) + delete itr->second; + m_weathers.clear(); +} + +Player* World::FindPlayerInZone(uint32 zone) +{ + SessionMap::iterator itr, next; + for (itr = m_sessions.begin(); itr != m_sessions.end(); itr = next) + { + next = itr; + next++; + + if(!itr->second) + continue; + Player *player = itr->second->GetPlayer(); + if(!player) + continue; + if( player->IsInWorld() && player->GetZoneId() == zone ) + { + return player; + } + } + return NULL; +} + +WorldSession* World::FindSession(uint32 id) const +{ + SessionMap::const_iterator itr = m_sessions.find(id); + + if(itr != m_sessions.end()) + return itr->second; + else + return 0; +} + +void World::RemoveSession(uint32 id) +{ + SessionMap::iterator itr = m_sessions.find(id); + + if(itr != m_sessions.end()) + { + delete itr->second; + m_sessions.erase(itr); + } +} + +void World::AddSession(WorldSession* s) +{ + ASSERT(s); + m_sessions[s->GetAccountId()] = s; +} + +Weather* World::FindWeather(uint32 id) const +{ + WeatherMap::const_iterator itr = m_weathers.find(id); + + if(itr != m_weathers.end()) + return itr->second; + else + return 0; +} + +void World::RemoveWeather(uint32 id) +{ + WeatherMap::iterator itr = m_weathers.find(id); + + if(itr != m_weathers.end()) + { + delete itr->second; + m_weathers.erase(itr); + } +} + +void World::AddWeather(Weather* w) +{ + ASSERT(w); + m_weathers[w->GetZone()] = w; +} + +void World::SetInitialWorldSettings() +{ + std::string dataPath="./"; + + srand((unsigned int)time(NULL)); + m_lastTick = time(NULL); + + time_t tiempo; + char hour[3]; + char minute[3]; + char second[3]; + struct tm *tmPtr; + tiempo = time(NULL); + tmPtr = localtime(&tiempo); + strftime( hour, 3, "%H", tmPtr ); + strftime( minute, 3, "%M", tmPtr ); + strftime( second, 3, "%S", tmPtr ); + + if(!sConfig.GetString("DataDir",&dataPath)) + dataPath="./"; + else + { + if((dataPath.at(dataPath.length()-1)!='/') && (dataPath.at(dataPath.length()-1)!='\\')) + dataPath.append("/"); + } + sLog.outString("Using DataDir %s ...",dataPath.c_str()); + + // Non-critical warning about conf file version + uint32 confVersion = sConfig.GetIntDefault("ConfVersion", 0); + if(!confVersion) + { + sLog.outError("*****************************************************************************"); + sLog.outError(" WARNING: mangosd.conf does not include a ConfVersion variable."); + sLog.outError(" Your conf file may be out of date!"); + sLog.outError("*****************************************************************************"); + clock_t pause = 3000 + clock(); + while (pause > clock()); + } + else + { + if (confVersion < _MANGOSDCONFVERSION) + { + sLog.outError("*****************************************************************************"); + sLog.outError(" WARNING: Your mangosd.conf version indicates your conf file is out of date!"); + sLog.outError(" Please check for updates, as your current default values may cause"); + sLog.outError(" strange behavior."); + sLog.outError("*****************************************************************************"); + clock_t pause = 3000 + clock(); + while (pause > clock()); + } + } + + regen_values[RATE_HEALTH] = sConfig.GetFloatDefault("Rate.Health", 1); + regen_values[RATE_POWER_MANA] = sConfig.GetFloatDefault("Rate.Power1", 1); + regen_values[RATE_POWER_RAGE] = sConfig.GetFloatDefault("Rate.Power2", 1); + regen_values[RATE_POWER_FOCUS] = sConfig.GetFloatDefault("Rate.Power3", 1); + regen_values[RATE_DROP_ITEMS] = sConfig.GetFloatDefault("Rate.Drop.Items", 1); + regen_values[RATE_DROP_MONEY] = sConfig.GetFloatDefault("Rate.Drop.Money", 1); + regen_values[RATE_XP_KILL] = sConfig.GetFloatDefault("Rate.XP.Kill", 1); + regen_values[RATE_XP_QUEST] = sConfig.GetFloatDefault("Rate.XP.Quest", 1); + regen_values[RATE_XP_EXPLORE] = sConfig.GetFloatDefault("Rate.XP.Explore", 1); + regen_values[RATE_CREATURE_NORMAL_DAMAGE] = sConfig.GetFloatDefault("Rate.Creature.Normal.Damage", 1); + regen_values[RATE_CREATURE_ELITE_ELITE_DAMAGE] = sConfig.GetFloatDefault("Rate.Creature.Elite.Elite.Damage", 1); + regen_values[RATE_CREATURE_ELITE_RAREELITE_DAMAGE] = sConfig.GetFloatDefault("Rate.Creature.Elite.RAREELITE.Damage", 1); + regen_values[RATE_CREATURE_ELITE_WORLDBOSS_DAMAGE] = sConfig.GetFloatDefault("Rate.Creature.Elite.WORLDBOSS.Damage", 1); + regen_values[RATE_CREATURE_ELITE_RARE_DAMAGE] = sConfig.GetFloatDefault("Rate.Creature.Elite.RARE.Damage", 1); + regen_values[RATE_CREATURE_NORMAL_HP] = sConfig.GetFloatDefault("Rate.Creature.Normal.HP", 1); + regen_values[RATE_CREATURE_ELITE_ELITE_HP] = sConfig.GetFloatDefault("Rate.Creature.Elite.Elite.HP", 1); + regen_values[RATE_CREATURE_ELITE_RAREELITE_HP] = sConfig.GetFloatDefault("Rate.Creature.Elite.RAREELITE.HP", 1); + regen_values[RATE_CREATURE_ELITE_WORLDBOSS_HP] = sConfig.GetFloatDefault("Rate.Creature.Elite.WORLDBOSS.HP", 1); + regen_values[RATE_CREATURE_ELITE_RARE_HP] = sConfig.GetFloatDefault("Rate.Creature.Elite.RARE.HP", 1); + regen_values[RATE_CREATURE_AGGRO] = sConfig.GetFloatDefault("Rate.Creature.Aggro", 1); + m_configs[CONFIG_LOG_LEVEL] = sConfig.GetIntDefault("LogLevel", 0); + m_configs[CONFIG_LOG_WORLD] = sConfig.GetIntDefault("LogWorld", 0); + m_configs[CONFIG_COMPRESSION] = sConfig.GetIntDefault("Compression", 1); + if(m_configs[CONFIG_COMPRESSION] < 1 || m_configs[CONFIG_COMPRESSION] > 9) + { + sLog.outError("Compression level (%i) must be in range 1..9. Using default compression level (1),.",m_configs[CONFIG_COMPRESSION]); + m_configs[CONFIG_COMPRESSION] = 1; + } + m_configs[CONFIG_GRID_UNLOAD] = sConfig.GetIntDefault("GridUnload", 1); + m_configs[CONFIG_INTERVAL_SAVE] = sConfig.GetIntDefault("PlayerSaveInterval", 900000); + m_configs[CONFIG_INTERVAL_GRIDCLEAN] = sConfig.GetIntDefault("GridCleanUpDelay", 300000); + m_configs[CONFIG_INTERVAL_MAPUPDATE] = sConfig.GetIntDefault("MapUpdateInterval", 100); + m_configs[CONFIG_INTERVAL_CHANGEWEATHER] = sConfig.GetIntDefault("ChangeWeatherInterval", 600000); + m_configs[CONFIG_PORT_WORLD] = sConfig.GetIntDefault("WorldServerPort", 8085); + m_configs[CONFIG_PORT_REALM] = sConfig.GetIntDefault("RealmServerPort", 3724); + m_configs[CONFIG_SOCKET_SELECTTIME] = sConfig.GetIntDefault("SocketSelectTime", 10000); + m_configs[CONFIG_GROUP_XP_DISTANCE] = sConfig.GetIntDefault("MaxGroupXPDistance", 74); + m_configs[CONFIG_GROUP_XP_DISTANCE] = m_configs[CONFIG_GROUP_XP_DISTANCE]*m_configs[CONFIG_GROUP_XP_DISTANCE]; + m_configs[CONFIG_GROUP_XP_LEVELDIFF] = sConfig.GetIntDefault("MaxGroupXPLevelDiff", 10); + m_configs[CONFIG_SIGHT_MONSTER] = sConfig.GetIntDefault("MonsterSight", 400); + m_configs[CONFIG_SIGHT_GUARDER] = sConfig.GetIntDefault("GuarderSight", 500); + m_configs[CONFIG_GAME_TYPE] = sConfig.GetIntDefault("GameType", 0); + m_configs[CONFIG_ALLOW_TWO_SIDE_ACCOUNTS] = sConfig.GetIntDefault("AllowTwoSide.Accounts", 0); + m_configs[CONFIG_ALLOW_TWO_SIDE_INTERACTION] = sConfig.GetIntDefault("AllowTwoSide.Interaction",0); + m_configs[CONFIG_ALLOW_TWO_SIDE_WHO_LIST] = sConfig.GetIntDefault("AllowTwoSide.WhoList", 0); + m_configs[CONFIG_MAX_PLAYER_LEVEL] = sConfig.GetIntDefault("MaxPlayerLevel", 60); + m_configs[CONFIG_MAX_PRIMARY_TRADE_SKILL] = sConfig.GetIntDefault("MaxPrimaryTradeSkill", 2); + m_configs[CONFIG_WISPERING_TO_GM] = sConfig.GetIntDefault("WhisperingToGM",0); + + m_gameTime = (3600*atoi(hour))+(atoi(minute)*60)+(atoi(second)); + + // check existance map files (startup race areas). + if( !MapManager::ExistMAP(0,-6240.32, 331.033) + ||!MapManager::ExistMAP(0,-8949.95,-132.493) + ||!MapManager::ExistMAP(0,-8949.95,-132.493) + ||!MapManager::ExistMAP(1,-618.518,-4251.67) + ||!MapManager::ExistMAP(0, 1676.35, 1677.45) + ||!MapManager::ExistMAP(1, 10311.3, 832.463) + ||!MapManager::ExistMAP(1,-2917.58,-257.98)) + { + sLog.outError("Correct *.map files not found by path '%smap'. Please place *.map files in directory by this path or correct DataDir value in mangosd.conf file.",dataPath.c_str()); + exit(1); + } + + //duplicate + //sDatabase.PExecute("UPDATE `character` SET `online` = 0"); + + //Update realm list + loginDatabase.PExecute("UPDATE `realmlist` SET `icon` = %u WHERE `id` = '%d'", m_configs[CONFIG_GAME_TYPE],sConfig.GetIntDefault("RealmID", 1)); + + // remove bones after restart + sDatabase.PExecute("DELETE FROM `corpse` WHERE `bones_flag` = '1'"); + + new ChannelMgr; + + sLog.outString("Initialize data stores..."); + LoadDBCStores(dataPath); + + sLog.outString( "Loading levelup stat gains..." ); + objmgr.LoadLvlUpGains(); + + sLog.outString( "Loading Quests..." ); + objmgr.LoadQuests(); + + sLog.outString( "Loading NPC Texts..." ); + objmgr.LoadGossipText(); + + sLog.outString( "Loading Quest Area Triggers..." ); + objmgr.LoadAreaTriggerPoints(); + + sLog.outString( "Loading Items..." ); + objmgr.LoadItemPrototypes(); + objmgr.LoadAuctions(); + objmgr.LoadAuctionItems(); + objmgr.LoadMailedItems(); + + sLog.outString( "Loading Creature templates..." ); + objmgr.LoadCreatureTemplates(); + + sLog.outString( "Loading Guilds..." ); + objmgr.LoadGuilds(); + + sLog.outString( "Loading Teleport Coords..." ); + objmgr.LoadTeleportCoords(); + + objmgr.SetHighestGuids(); + + sLog.outString( "Loading Loot Tables..." ); + LoadLootTables(); + + sLog.outString( "Loading Game Object Templates..." ); + objmgr.LoadGameobjectInfo(); + + sLog.outString( "Initializing Scripts..." ); + if(!LoadScriptingModule()) + exit(1); + + m_timers[WUPDATE_OBJECTS].SetInterval(0); + m_timers[WUPDATE_SESSIONS].SetInterval(0); + m_timers[WUPDATE_WEATHERS].SetInterval(1000); + m_timers[WUPDATE_AUCTIONS].SetInterval(1000); + + sLog.outString( "WORLD: Starting BattleGround System" ); + sBattleGroundMgr.CreateInitialBattleGrounds(); + + MaNGOS::Game::Initialize(); + sLog.outString( "WORLD: SetInitialWorldSettings done" ); + + sLog.outString( "WORLD: Starting Event System" ); + StartEventSystem(); + + //Start Addon stuff + bool temp = sConfig.GetBoolDefault("AddonDefault", 1); + sLog.outString( "WORLD: Starting Addon System, AddonDefault:%d (%s all addons not registered in DB)", temp, temp? "Enabled" : "Disabled" ); + sAddOnHandler.SetAddonDefault(temp); + sAddOnHandler._LoadFromDB(); + + sLog.outString( "WORLD: Starting Corpse Handler" ); + // global event to erase corpses/bones + // deleting expired bones time > 20 minutes and corpses > 3 days + // it is run each 20 minutes + // need good tests on windows + AddEvent(&HandleCorpsesErase,NULL,20*60,false,true); +} + +void World::Update(time_t diff) +{ + for(int i = 0; i < WUPDATE_COUNT; i++) + if(m_timers[i].GetCurrent()>=0) + m_timers[i].Update(diff); + else m_timers[i].SetCurrent(0); + + _UpdateGameTime(); + + if (m_timers[WUPDATE_AUCTIONS].Passed()) + { + m_timers[WUPDATE_AUCTIONS].Reset(); + ObjectMgr::AuctionEntryMap::iterator itr,next; + for (itr = objmgr.GetAuctionsBegin(); itr != objmgr.GetAuctionsEnd();itr = next) + { + next = itr; + next++; + if (time(NULL) > (itr->second->time)) + { + if (itr->second->bidder == 0) // if noone bidded auction... + { + Item *it = objmgr.GetAItem(itr->second->item); + if(it) + { + Mail *m = new Mail; + m->receiver = itr->second->owner; + m->body = ""; + m->sender = itr->second->owner; + m->checked = 0; + m->COD = 0; // there might be deposit + m->messageID = objmgr.GenerateMailID(); + m->money = 0; + m->time = time(NULL) + (29 * 3600); + m->subject = "Your item failed to sell"; + m->item = itr->second->item; + objmgr.AddMItem(it); + + std::ostringstream ss; + ss << "INSERT INTO `mail_item` (`guid`,`data`) VALUES (" + << it->GetGUIDLow() << ", '"; + for(uint16 i = 0; i < it->GetValuesCount(); i++ ) + { + ss << it->GetUInt32Value(i) << " "; + } + ss << "' )"; + sDatabase.Execute( ss.str().c_str() ); + + sDatabase.PExecute("DELETE FROM `mail` WHERE `id` = '%u'",m->messageID); + sDatabase.PExecute("INSERT INTO `mail` (`id`,`sender`,`receiver`,`subject`,`body`,`item`,`time`,`money`,`cod`,`checked`) VALUES ('%u', '%u', '%u', '%s', '%s', '%u', '" I64FMTD "', '%u', '%u', '%u')", m->messageID, m->sender, m->receiver, m->subject.c_str(), m->body.c_str(), m->item, (uint64)m->time, m->money, 0, 0); + + Player *rpl = objmgr.GetPlayer(m->receiver); + if (rpl) + { + rpl->AddMail(m); + } + else + delete m; + } + else + sLog.outError("Auction item %u not found, and lost.",itr->second->item); + + sDatabase.PExecute("DELETE FROM `auctionhouse` WHERE `itemowner` = '%u'",itr->second->owner); + sDatabase.PExecute("DELETE FROM `auctionhouse` WHERE `id` = '%u'",itr->second->Id); + sDatabase.PExecute("DELETE FROM `auctionhouse_item` WHERE `guid` = '%u'",itr->second->item); + + objmgr.RemoveAItem(itr->second->item); + objmgr.RemoveAuction(itr->second->Id); + } + else + { + Mail *m = new Mail; + m->receiver = itr->second->owner; + m->body = ""; + m->sender = itr->second->bidder; + m->checked = 0; + m->COD = 0; + m->messageID = objmgr.GenerateMailID(); + m->money = itr->second->bid; + m->time = time(NULL) + (29 * 3600); + m->subject = "Your item sold!"; + m->item = 0; + + sDatabase.PExecute("DELETE FROM `mail` WHERE `id` = '%u'",m->messageID); + sDatabase.PExecute("INSERT INTO `mail` (`id`,`sender`,`receiver`,`subject`,`body`,`item`,`time`,`money`,`cod`,`checked`) VALUES ('%u', '%u', '%u', '%s', '%s', '%u', '" I64FMTD "', '%u', '%u', '%u')", m->messageID, m->sender, m->receiver, m->subject.c_str(), m->body.c_str(), m->item, (uint64)m->time, m->money, 0, 0); + + Player *rpl = objmgr.GetPlayer(m->receiver); + if (rpl) + { + rpl->AddMail(m); + } + else + delete m; + + Mail *mn = new Mail; + mn->receiver = itr->second->bidder; + mn->body = ""; + mn->sender = itr->second->owner; + mn->checked = 0; + mn->COD = 0; + mn->messageID = objmgr.GenerateMailID(); + mn->money = 0; + mn->time = time(NULL) + (29 * 3600); + mn->subject = "Your won an item!"; + mn->item = itr->second->item; + Item *it = objmgr.GetAItem(itr->second->item); + objmgr.AddMItem(it); + + std::ostringstream ss; + ss << "INSERT INTO `mail_item` (`guid`,`data`) VALUES (" + << it->GetGUIDLow() << ", '"; + for(uint16 i = 0; i < it->GetValuesCount(); i++ ) + { + ss << it->GetUInt32Value(i) << " "; + } + ss << "' )"; + sDatabase.Execute( ss.str().c_str() ); + + sDatabase.PExecute("DELETE FROM `mail` WHERE `id` = '%u'", mn->messageID); + sDatabase.PExecute("INSERT INTO `mail` (`id`,`sender`,`receiver`,`subject`,`body`,`item`,`time`,`money`,`cod`,`checked`) VALUES ('%u', '%u', '%u', '%s', '%s', '%u', '" I64FMTD "', '%u', '%u', '%u')", mn->messageID, mn->sender, mn->receiver, mn->subject.c_str(), mn->body.c_str(), mn->item, (uint64)mn->time, mn->money, 0, 0); + + Player *rpl1 = objmgr.GetPlayer(mn->receiver); + if (rpl1) + { + rpl1->AddMail(mn); + } + else + delete mn; + + sDatabase.PExecute("DELETE FROM `auctionhouse` WHERE `id` = '%u'",itr->second->Id); + sDatabase.PExecute("DELETE FROM `auctionhouse_item` WHERE `guid` = '%u'",itr->second->item); + + objmgr.RemoveAItem(itr->second->item); + objmgr.RemoveAuction(itr->second->Id); + } + } + } + } + if (m_timers[WUPDATE_SESSIONS].Passed()) + { + m_timers[WUPDATE_SESSIONS].Reset(); + + SessionMap::iterator itr, next; + for (itr = m_sessions.begin(); itr != m_sessions.end(); itr = next) + { + next = itr; + next++; + + if(!itr->second->Update(diff)) + { + delete itr->second; + m_sessions.erase(itr); + } + } + } + + if (m_timers[WUPDATE_WEATHERS].Passed()) + { + m_timers[WUPDATE_WEATHERS].Reset(); + + WeatherMap::iterator itr, next; + for (itr = m_weathers.begin(); itr != m_weathers.end(); itr = next) + { + next = itr; + next++; + + if(!itr->second->Update(diff)) + { + delete itr->second; + m_weathers.erase(itr); + } + } + } + + if (m_timers[WUPDATE_OBJECTS].Passed()) + { + m_timers[WUPDATE_OBJECTS].Reset(); + MapManager::Instance().Update(diff); + } + + // move all creatures with delayed move and remove and delete all objects with delayed remove + ObjectAccessor::Instance().DoDelayedMovesAndRemoves(); +} + +void World::SendGlobalMessage(WorldPacket *packet, WorldSession *self) +{ + SessionMap::iterator itr; + for (itr = m_sessions.begin(); itr != m_sessions.end(); itr++) + { + if (itr->second->GetPlayer() && + itr->second->GetPlayer()->IsInWorld() + && itr->second != self) + { + itr->second->SendPacket(packet); + } + } +} + +void World::SendWorldText(const char* text, WorldSession *self) +{ + WorldPacket data; + sChatHandler.FillSystemMessageData(&data, 0, text); + SendGlobalMessage(&data, self); +} + +void World::SendZoneMessage(uint32 zone, WorldPacket *packet, WorldSession *self) +{ + SessionMap::iterator itr; + for (itr = m_sessions.begin(); itr != m_sessions.end(); itr++) + { + Player *player = itr->second->GetPlayer(); + if ( player && player->IsInWorld() && player->GetZoneId() == zone && itr->second != self) + { + itr->second->SendPacket(packet); + } + } +} + +void World::SendZoneText(uint32 zone, const char* text, WorldSession *self) +{ + WorldPacket data; + sChatHandler.FillSystemMessageData(&data, 0, text); + SendZoneMessage(zone, &data, self); +} + +void World::KickPlayer(char* playerName) +{ + SessionMap::iterator itr, next; + WorldSession *playerToKick = 0; + + int y = 0; + while (!playerName[y] == 0) + { + if ((playerName[y] >= 'a') && (playerName[y] <= 'z')) + playerName[y] -= 'a' - 'A'; + y++; + } + + for (itr = m_sessions.begin(); itr != m_sessions.end(); itr = next) + { + next = itr; + next++; + if(!itr->second) + continue; + Player *player = itr->second->GetPlayer(); + if(!player) + continue; + if( player->IsInWorld() ) + { + char *tmpPlayerName = new char[strlen(player->GetName()) + 1]; + strcpy(tmpPlayerName, player->GetName()); + y = 0; + while (!tmpPlayerName[y] == 0) + { + if ((tmpPlayerName[y] >= 'a') && (tmpPlayerName[y] <= 'z')) + tmpPlayerName[y] -= 'a' - 'A'; + y++; + } + if (strcmp(playerName, tmpPlayerName) == 0) + playerToKick = itr->second; + delete[] tmpPlayerName; + } + } + if (playerToKick) + { + playerToKick->LogoutPlayer(true); + } +} + +time_t World::_UpdateGameTime() +{ + time_t thisTime = time(NULL); + + if(m_lastTick == 0) + m_lastTick = thisTime; + + uint32 elapsed = uint32(thisTime - m_Last_tick); + + if(m_ShutdownTimer > 0 && elapsed > 0) + { + if( m_ShutdownTimer <= elapsed ) + { + m_stopEvent = true; + } + else + { + m_ShutdownTimer -= elapsed; + ShuttDownMsg(); + } + } + + m_gameTime += elapsed; + + m_Last_tick = thisTime; + + return m_gameTime; +} + +void World::ShutdownServ(uint32 time) +{ + m_ShutdownTimer = time; +} + +void World::ShuttDownMsg() +{ + WorldPacket data; + + data.Initialize(SMSG_SERVER_MESSAGE); + + std::ostringstream ss; + ss << m_ShutdownTimer << " Second(s)."; + + data << uint32(1) << ss.str().c_str() << (uint8)0x00; + + SendGlobalMessage( &data ); + + data.clear(); + ss.clear(); + + DEBUG_LOG("Server is shuttingdown in %d seconds",m_ShutdownTimer); +} diff --git a/src/shared/Database/DBCStores.cpp b/src/shared/Database/DBCStores.cpp index 44a72551..91efb4f0 100644 --- a/src/shared/Database/DBCStores.cpp +++ b/src/shared/Database/DBCStores.cpp @@ -70,7 +70,7 @@ inline void LoadDBC(barGoLink& bar, StoreProblemList& errlist, DBCStorage& st errlist.push_back(filename + buf); fclose(f); }else - errlist.push_back(filename); + errlist.push_back(filename); } } -- 2.11.4.GIT