Skip to content

Commit

Permalink
Use BuildChatPacket() in battlefields and add condition check placeho…
Browse files Browse the repository at this point in the history
…lder

Also add creature 15214 in WG definition as the source of emotes and
fix some NULL values and alignment issues

Signed-off-by: Xfurry <xfurry.cmangos@outlook.com>
  • Loading branch information
xfurry committed Jan 14, 2018
1 parent 0821f68 commit 008567e
Show file tree
Hide file tree
Showing 5 changed files with 285 additions and 274 deletions.
54 changes: 23 additions & 31 deletions src/game/Battlefield/Battlefield.cpp
Expand Up @@ -26,6 +26,7 @@
#include "Maps/MapManager.h"
#include "Spells/SpellAuras.h"
#include "Entities/Unit.h"
#include "Chat/Chat.h"

Battlefield::Battlefield() : OutdoorPvP(), m_battleFieldId(0)
{
Expand Down Expand Up @@ -55,7 +56,7 @@ void Battlefield::HandlePlayerEnterZone(Player* player, bool isMainZone)
{
if (GetBattlefieldStatus() == BF_STATUS_IN_PROGRESS)
{
m_invitedPlayers[GetTeamIndexByTeamId(player->GetTeam())][player->GetObjectGuid()] = time(NULL) + BF_TIME_TO_ACCEPT;
m_invitedPlayers[GetTeamIndexByTeamId(player->GetTeam())][player->GetObjectGuid()] = time(nullptr) + BF_TIME_TO_ACCEPT;
player->GetSession()->SendBattlefieldWarInvite(m_battleFieldId, m_zoneId, BF_TIME_TO_ACCEPT);
}
else if (GetBattlefieldStatus() == BF_STATUS_COOLDOWN && m_timer < m_startInviteDelay)
Expand Down Expand Up @@ -92,7 +93,7 @@ void Battlefield::HandlePlayerLeaveZone(Player* player, bool isMainZone)
if (HasPlayer(itr->first))
{
player->GetSession()->SendBattlefieldLeaveMessage(m_battleFieldId, BATTLEFIELD_LEAVE_REASON_EXITED);
itr->second->removeTime = time(NULL);
itr->second->removeTime = time(nullptr);
itr->second->removeDelay = BF_UNACCEPTED_REMOVE_DELAY;
}
else
Expand Down Expand Up @@ -184,7 +185,7 @@ void Battlefield::UpdateBattlefieldPlayers()
bool bRemoved = false;
for (BattlefieldPlayerMap::iterator itr = m_activePlayers.begin(); itr != m_activePlayers.end();)
{
if (itr->second->removeTime && itr->second->removeTime + itr->second->removeDelay < time(NULL))
if (itr->second->removeTime && itr->second->removeTime + itr->second->removeDelay < time(nullptr))
{
delete itr->second;
if (Player* player = sObjectMgr.GetPlayer(itr->first))
Expand Down Expand Up @@ -215,7 +216,7 @@ Function that starts battlefield battle
*/
void Battlefield::StartBattle(Team defender)
{
m_startTime = time(NULL);
m_startTime = time(nullptr);
m_status = BF_STATUS_IN_PROGRESS;
m_timer = m_battleDuration;
m_zoneOwner = defender;
Expand Down Expand Up @@ -253,7 +254,7 @@ void Battlefield::StartBattle(Team defender)

if (itr2 != m_queuedPlayers[idx].end())
{
m_invitedPlayers[idx][itr->first] = time(NULL) + BF_TIME_TO_ACCEPT;
m_invitedPlayers[idx][itr->first] = time(nullptr) + BF_TIME_TO_ACCEPT;
plr->GetSession()->SendBattlefieldWarInvite(m_battleFieldId, m_zoneId, BF_TIME_TO_ACCEPT);
m_queuedPlayers[idx].erase(itr2);
}
Expand All @@ -263,7 +264,7 @@ void Battlefield::StartBattle(Team defender)
SendRemoveWorldStates(plr);
if (m_activePlayers.find(itr->first) != m_activePlayers.end())
{
m_activePlayers[itr->first]->removeTime = time(NULL);
m_activePlayers[itr->first]->removeTime = time(nullptr);
m_activePlayers[itr->first]->removeDelay = BF_UNACCEPTED_REMOVE_DELAY;
}
}
Expand All @@ -276,7 +277,7 @@ void Battlefield::StartBattle(Team defender)
{
if (Player* plr = sObjectMgr.GetPlayer(*itr, true))
{
m_invitedPlayers[i][plr->GetObjectGuid()] = time(NULL) + BF_TIME_TO_ACCEPT;
m_invitedPlayers[i][plr->GetObjectGuid()] = time(nullptr) + BF_TIME_TO_ACCEPT;
plr->GetSession()->SendBattlefieldWarInvite(m_battleFieldId, m_zoneId, BF_TIME_TO_ACCEPT);
}

Expand Down Expand Up @@ -347,7 +348,7 @@ void Battlefield::Update(uint32 diff)
{
for (std::map<ObjectGuid, time_t>::iterator itr = m_invitedPlayers[i].begin(); itr != m_invitedPlayers[i].end();)
{
if (itr->second < time(NULL))
if (itr->second < time(nullptr))
{
if (Player* player = sObjectMgr.GetPlayer(itr->first))
player->GetSession()->SendBattlefieldLeaveMessage(m_battleFieldId, BATTLEFIELD_LEAVE_REASON_EXITED);
Expand Down Expand Up @@ -594,7 +595,7 @@ void Battlefield::HandleBattlefieldGroupDisband(Player* player)

if (m_activePlayers.find(player->GetObjectGuid()) != m_activePlayers.end())
{
m_activePlayers[player->GetObjectGuid()]->removeTime = time(NULL);
m_activePlayers[player->GetObjectGuid()]->removeTime = time(nullptr);
m_activePlayers[player->GetObjectGuid()]->removeDelay = BF_UNACCEPTED_REMOVE_DELAY;
}
}
Expand Down Expand Up @@ -656,7 +657,7 @@ void Battlefield::HandleQueueInviteResponse(Player* player, bool accepted)
{
if (GetBattlefieldStatus() == BF_STATUS_IN_PROGRESS)
{
m_invitedPlayers[teamIdx][player->GetObjectGuid()] = time(NULL) + BF_TIME_TO_ACCEPT;
m_invitedPlayers[teamIdx][player->GetObjectGuid()] = time(nullptr) + BF_TIME_TO_ACCEPT;
player->GetSession()->SendBattlefieldWarInvite(m_battleFieldId, m_zoneId, BF_TIME_TO_ACCEPT);
}
else
Expand Down Expand Up @@ -715,7 +716,7 @@ void Battlefield::HandleWarInviteResponse(Player* player, bool accepted)
player->GetSession()->SendBattlefieldLeaveMessage(m_battleFieldId, BATTLEFIELD_LEAVE_REASON_EXITED);
if (m_activePlayers.find(player->GetObjectGuid()) != m_activePlayers.end())
{
m_activePlayers[player->GetObjectGuid()]->removeTime = time(NULL);
m_activePlayers[player->GetObjectGuid()]->removeTime = time(nullptr);
m_activePlayers[player->GetObjectGuid()]->removeDelay = BF_UNACCEPTED_REMOVE_DELAY;
}
}
Expand All @@ -738,7 +739,7 @@ void Battlefield::HandleExitRequest(Player* player)

if (m_activePlayers.find(player->GetObjectGuid()) != m_activePlayers.end())
{
m_activePlayers[player->GetObjectGuid()]->removeTime = time(NULL);
m_activePlayers[player->GetObjectGuid()]->removeTime = time(nullptr);
m_activePlayers[player->GetObjectGuid()]->removeDelay = BF_UNACCEPTED_REMOVE_DELAY;
}
}
Expand All @@ -754,7 +755,7 @@ void Battlefield::HandleExitRequest(Player* player)

if (m_activePlayers.find(player->GetObjectGuid()) != m_activePlayers.end())
{
m_activePlayers[player->GetObjectGuid()]->removeTime = time(NULL);
m_activePlayers[player->GetObjectGuid()]->removeTime = time(nullptr);
m_activePlayers[player->GetObjectGuid()]->removeDelay = BF_UNACCEPTED_REMOVE_DELAY;
}
}
Expand All @@ -765,8 +766,9 @@ void Battlefield::HandleExitRequest(Player* player)
Function that sends a zone wide warning to all players
@param text id
@param source object. Can be null
*/
void Battlefield::SendZoneWarning(int32 entry)
void Battlefield::SendZoneWarning(int32 entry, WorldObject* source)
{
for (GuidZoneMap::iterator itr = m_zonePlayers.begin(); itr != m_zonePlayers.end(); ++itr)
{
Expand All @@ -780,23 +782,13 @@ void Battlefield::SendZoneWarning(int32 entry)
if (player->GetZoneId() != m_zoneId)
continue;

int32 loc_idx = player->GetSession()->GetSessionDbLocaleIndex();

char const* text = sObjectMgr.GetMangosString(entry, loc_idx);

WorldPacket data(SMSG_MESSAGECHAT, 200);
data << uint8(CHAT_MSG_RAID_BOSS_EMOTE);
data << uint32(LANG_UNIVERSAL);
data << ObjectGuid();
data << uint32(0);
data << uint32(1);
data << uint8(0);
data << ObjectGuid();
data << uint32(strlen(text) + 1);
data << text;
data << uint8(0);
data << float(0.0f);
data << uint8(0);
int32 locIdx = player->GetSession()->GetSessionDbLocaleIndex();

char const* text = sObjectMgr.GetMangosString(entry, locIdx);

WorldPacket data;
ChatHandler::BuildChatPacket(data, CHAT_MSG_RAID_BOSS_EMOTE, text, LANG_UNIVERSAL, CHAT_TAG_NONE,
source ? source->GetObjectGuid() : ObjectGuid(), source ? source->GetName() : "", player->GetObjectGuid(), player->GetName());

player->GetSession()->SendPacket(data);
}
Expand Down
4 changes: 2 additions & 2 deletions src/game/Battlefield/Battlefield.h
Expand Up @@ -169,7 +169,7 @@ class Battlefield : public OutdoorPvP
void UpdateBattlefieldPlayers();

// sends a raid warning to all players in the zone
void SendZoneWarning(int32 /*entry*/);
void SendZoneWarning(int32 /*entry*/, WorldObject* source = nullptr);

// update the graveyard on capture event
virtual void UpdateGraveyardOwner(uint8 id, PvpTeamIndex newOwner) {};
Expand All @@ -178,7 +178,7 @@ class Battlefield : public OutdoorPvP
virtual void RewardPlayersOnBattleEnd(Team /*winner*/) {};

// ToDo!!! for review!
void QuestCreditTeam(uint32 credit, Team team, WorldObject* source = NULL, float radius = -1.0f);
void QuestCreditTeam(uint32 credit, Team team, WorldObject* source = nullptr, float radius = -1.0f);

// Group system
bool CanAddPlayerToRaid(Player* /*player*/);
Expand Down
2 changes: 1 addition & 1 deletion src/game/Battlefield/BattlefieldHandler.cpp
Expand Up @@ -37,7 +37,7 @@ void WorldSession::SendBattlefieldWarInvite(uint32 battlefieldId, uint32 zoneId,
WorldPacket data(SMSG_BATTLEFIELD_MANAGER_ENTRY_INVITE, 12);
data << uint32(battlefieldId);
data << uint32(zoneId);
data << uint32(time(NULL) + acceptDelay);
data << uint32(time(nullptr) + acceptDelay);

SendPacket(data);
}
Expand Down
10 changes: 10 additions & 0 deletions src/game/Battlefield/BattlefieldWG.cpp
Expand Up @@ -262,3 +262,13 @@ bool BattlefieldWG::HandleDestructibleBuildingEvent(uint32 eventId, GameObject*
{
return false;
}

bool BattlefieldWG::IsConditionFulfilled(Player const* source, uint32 conditionId, WorldObject const* conditionSource, uint32 conditionSourceType)
{
return false;
}

void BattlefieldWG::HandleConditionStateChange(uint32 conditionId, bool state)
{

}

14 comments on commit 008567e

@Rog360
Copy link

@Rog360 Rog360 commented on 008567e Jan 15, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

crash on login with characters with pets and not allowed opcode after commit [Update SD2 SQL for latest Maraudon scripts] and this commit. Not sure which one it started doing it on.

ERROR:SESSION: received not allowed opcode CMSG_LFG_GET_STATUS (0x0296)

@xfurry
Copy link
Member Author

@xfurry xfurry commented on 008567e Jan 15, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please provide the crash log. I didn't experience any crashes recently.
That error has been showing up for a very long time and it's unrelated to battlefields.

@Rog360
Copy link

@Rog360 Rog360 commented on 008567e Jan 15, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do asap. Really late here. Thanks.

@xfurry
Copy link
Member Author

@xfurry xfurry commented on 008567e Jan 15, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Rog360 are you talking about a server or a client crash?
Client crashes can happen under certain circumstances, because of vehicles and of the desynchronization of the passenger position relative to the vehicle.
If you think that the crash is related to the latest commits, please try to turn off the Wintergrasp script from the config file.

@Rog360
Copy link

@Rog360 Rog360 commented on 008567e Jan 15, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Server crash. I'll try your suggestion in the morning and post back then. Thanks for your work... :)

@xfurry
Copy link
Member Author

@xfurry xfurry commented on 008567e Jan 15, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Rog360 please provide the crash log when you have the chance. We need to address this issue, regardless if it's related to my latest changes or to something else.

@Rog360
Copy link

@Rog360 Rog360 commented on 008567e Jan 15, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not getting a crash report. I'm compiling core in debug mode now to see if I can get more info on crash or a crash report. I can log in with character with no pet, But, as soon as I call pet. Server crashes... :(

UPDATE: Even with debug compile no crash report. Only thing I can find is "ERROR:Pet::InitStatsForLevel> No owner for creature pet Pet (Petnumber: 1061 Guid: 1) !"
Do you want me to post event viewer log for error?

@xfurry
Copy link
Member Author

@xfurry xfurry commented on 008567e Jan 15, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Warlockbugs I think this is something for you.
@Rog360 yes, anything can be useful.

@Rog360
Copy link

@Rog360 Rog360 commented on 008567e Jan 15, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry not more info... :)

Log Name:      Application
Source:        Application Error
Date:          1/15/2018 1:49:34 PM
Event ID:      1000
Task Category: (100)
Level:         Error
Keywords:      Classic
User:          N/A
Computer:      WoW-Server-7
Description:
Faulting application name: mangosd.exe, version: 0.0.0.0, time stamp: 0x5a5ce9e5
Faulting module name: mangosd.exe, version: 0.0.0.0, time stamp: 0x5a5ce9e5
Exception code: 0xc0000005
Fault offset: 0x00a12bd6
Faulting process id: 0xeac
Faulting application start time: 0x01d38e31099fd2f7
Faulting application path: C:\Program Files\WotLK 3.3.5\mangosd.exe
Faulting module path: C:\Program Files\WotLK 3.3.5\mangosd.exe
Report Id: d3c2706a-fa24-11e7-9dda-00132016d8f6
Event Xml:
<Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
  <System>
    <Provider Name="Application Error" />
    <EventID Qualifiers="0">1000</EventID>
    <Level>2</Level>
    <Task>100</Task>
    <Keywords>0x80000000000000</Keywords>
    <TimeCreated SystemTime="2018-01-15T18:49:34.000000000Z" />
    <EventRecordID>154317</EventRecordID>
    <Channel>Application</Channel>
    <Computer>WoW-Server-7</Computer>
    <Security />
  </System>
  <EventData>
    <Data>mangosd.exe</Data>
    <Data>0.0.0.0</Data>
    <Data>5a5ce9e5</Data>
    <Data>mangosd.exe</Data>
    <Data>0.0.0.0</Data>
    <Data>5a5ce9e5</Data>
    <Data>c0000005</Data>
    <Data>00a12bd6</Data>
    <Data>eac</Data>
    <Data>01d38e31099fd2f7</Data>
    <Data>C:\Program Files\WotLK 3.3.5\mangosd.exe</Data>
    <Data>C:\Program Files\WotLK 3.3.5\mangosd.exe</Data>
    <Data>d3c2706a-fa24-11e7-9dda-00132016d8f6</Data>
  </EventData>
</Event>

@xfurry
Copy link
Member Author

@xfurry xfurry commented on 008567e Jan 15, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Rog360 give us more details about how to replicate the crash.
Which DB do you use? I guess you updated the core to the latest version already.
Which type of character do you use to login and crash the server? Which is the pet?
What zone are you in? Character level and skills, maybe equipment if you have something special? What are the enable pet spells?

@Rog360
Copy link

@Rog360 Rog360 commented on 008567e Jan 15, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To replicate the crash. Log in with a hunter or a char with any pet & call pet. char with pet already in game causes instant crash. Using database PSDB with latest core. Doesn't seem to matter where your char is located or char level as I have another player client on different pc with different account.
Core was working fine on core compile commit 1727323 [Update SD2 SQL for latest Maraudon scripts]. Even tried using char backups from different daily backups with no special equipment or spells.

@xfurry
Copy link
Member Author

@xfurry xfurry commented on 008567e Jan 15, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be something with 60828af or 25ca64b
These 2 are pet related.

@Warlockbugs
Copy link
Member

@Warlockbugs Warlockbugs commented on 008567e Jan 15, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've located the issue.
It happens when pet is being loaded from the DB in:

void Pet::CastPetAuras(bool current)
{
    ...
    Unit* owner = GetOwner();

    for (PetAuraSet::const_iterator itr = owner->m_petAuras.begin(); itr != owner->m_petAuras.end();)

This circumstance was introduced as a side effect by 25ca64b, because at the time of pet loading, the pet itself (as accessor) is not placed on the map yet. This set of protections is used in ObjectAccessor::GetUnit(). However, reverting said protection brings back random crashes when unit was actually removed from the world described in cmangos/issues#1535.

That's a bit of a head-scratcher there. This usecase (pet loading) stands out of all others.
I am open to any ideas while i am thinking about possible non-ugly solution.

@Warlockbugs
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be dealt with as of b3f477f for wrath.

For future reference, please, report issues in the tracker at https://github.com/cmangos/issues so it can tracked more easily.

Please sign in to comment.