| | 5510 | bool ChatHandler::HandleFreezeCommand(const char *args) |
| | 5511 | { |
| | 5512 | std::string name; |
| | 5513 | Player* player; |
| | 5514 | char* TargetName = strtok((char*)args, " "); //get entered name |
| | 5515 | if (!TargetName) //if no name entered use target |
| | 5516 | { |
| | 5517 | player = getSelectedPlayer(); |
| | 5518 | if (player) //prevent crash with creature as target |
| | 5519 | { |
| | 5520 | name = player->GetName(); |
| | 5521 | normalizePlayerName(name); |
| | 5522 | } |
| | 5523 | } |
| | 5524 | else // if name entered |
| | 5525 | { |
| | 5526 | name = TargetName; |
| | 5527 | normalizePlayerName(name); |
| | 5528 | player = objmgr.GetPlayer(name.c_str()); //get player by name |
| | 5529 | } |
| | 5530 | |
| | 5531 | if (!player) |
| | 5532 | { |
| | 5533 | SendSysMessage(LANG_COMMAND_FREEZE_WRONG); |
| | 5534 | return true; |
| | 5535 | } |
| | 5536 | |
| | 5537 | if (player==m_session->GetPlayer()) |
| | 5538 | { |
| | 5539 | SendSysMessage(LANG_COMMAND_FREEZE_ERROR); |
| | 5540 | return true; |
| | 5541 | } |
| | 5542 | |
| | 5543 | //effect |
| | 5544 | if ((player) && (!(player==m_session->GetPlayer()))) |
| | 5545 | { |
| | 5546 | PSendSysMessage(LANG_COMMAND_FREEZE,name.c_str()); |
| | 5547 | |
| | 5548 | //stop combat + make player unattackable + duel stop + stop some spells |
| | 5549 | player->setFaction(35); |
| | 5550 | player->CombatStop(); |
| | 5551 | if(player->IsNonMeleeSpellCasted(true)) |
| | 5552 | player->InterruptNonMeleeSpells(true); |
| | 5553 | player->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NON_ATTACKABLE); |
| | 5554 | player->SetUInt32Value(PLAYER_DUEL_TEAM, 1); |
| | 5555 | |
| | 5556 | //if player class = hunter || warlock remove pet if alive |
| | 5557 | if((player->getClass() == CLASS_HUNTER) || (player->getClass() == CLASS_WARLOCK)) |
| | 5558 | { |
| | 5559 | if(Pet* pet = player->GetPet()) |
| | 5560 | { |
| | 5561 | pet->SavePetToDB(PET_SAVE_AS_CURRENT); |
| | 5562 | // not let dismiss dead pet |
| | 5563 | if(pet && pet->isAlive()) |
| | 5564 | player->RemovePet(pet,PET_SAVE_NOT_IN_SLOT); |
| | 5565 | } |
| | 5566 | } |
| | 5567 | |
| | 5568 | //stop movement and disable spells |
| | 5569 | uint32 spellID = 9454; |
| | 5570 | //m_session->GetPlayer()->CastSpell(player,spellID,false); |
| | 5571 | SpellEntry const *spellInfo = sSpellStore.LookupEntry( spellID ); |
| | 5572 | if(spellInfo) //TODO: Change the duration of the aura to -1 instead of 5000000 |
| | 5573 | { |
| | 5574 | for(uint32 i = 0;i<3;i++) |
| | 5575 | { |
| | 5576 | uint8 eff = spellInfo->Effect[i]; |
| | 5577 | if (eff>=TOTAL_SPELL_EFFECTS) |
| | 5578 | continue; |
| | 5579 | if( eff == SPELL_EFFECT_APPLY_AREA_AURA_PARTY || eff == SPELL_EFFECT_APPLY_AURA || |
| | 5580 | eff == SPELL_EFFECT_PERSISTENT_AREA_AURA || eff == SPELL_EFFECT_APPLY_AREA_AURA_FRIEND || |
| | 5581 | eff == SPELL_EFFECT_APPLY_AREA_AURA_ENEMY) |
| | 5582 | { |
| | 5583 | Aura *Aur = CreateAura(spellInfo, i, NULL, player); |
| | 5584 | player->AddAura(Aur); |
| | 5585 | } |
| | 5586 | } |
| | 5587 | } |
| | 5588 | |
| | 5589 | //save player |
| | 5590 | player->SaveToDB(); |
| | 5591 | } |
| | 5592 | return true; |
| | 5593 | } |
| | 5594 | |
| | 5595 | bool ChatHandler::HandleUnFreezeCommand(const char *args) |
| | 5596 | { |
| | 5597 | std::string name; |
| | 5598 | Player* player; |
| | 5599 | char* TargetName = strtok((char*)args, " "); //get entered name |
| | 5600 | if (!TargetName) //if no name entered use target |
| | 5601 | { |
| | 5602 | player = getSelectedPlayer(); |
| | 5603 | if (player) //prevent crash with creature as target |
| | 5604 | { |
| | 5605 | name = player->GetName(); |
| | 5606 | } |
| | 5607 | } |
| | 5608 | |
| | 5609 | else // if name entered |
| | 5610 | { |
| | 5611 | name = TargetName; |
| | 5612 | normalizePlayerName(name); |
| | 5613 | player = objmgr.GetPlayer(name.c_str()); //get player by name |
| | 5614 | } |
| | 5615 | |
| | 5616 | //effect |
| | 5617 | if (player) |
| | 5618 | { |
| | 5619 | PSendSysMessage(LANG_COMMAND_UNFREEZE,name.c_str()); |
| | 5620 | |
| | 5621 | //Reset player faction + allow combat + allow duels |
| | 5622 | player->setFactionForRace(player->getRace()); |
| | 5623 | player->RemoveFlag (UNIT_FIELD_FLAGS, UNIT_FLAG_NON_ATTACKABLE); |
| | 5624 | |
| | 5625 | //allow movement and spells |
| | 5626 | uint32 spellID = 9454; |
| | 5627 | player->RemoveAurasDueToSpell(spellID); |
| | 5628 | |
| | 5629 | //save player |
| | 5630 | player->SaveToDB(); |
| | 5631 | } |
| | 5632 | |
| | 5633 | if (!player) |
| | 5634 | { |
| | 5635 | if (TargetName) |
| | 5636 | { |
| | 5637 | //check for offline players |
| | 5638 | QueryResult *result = CharacterDatabase.PQuery("SELECT characters.guid FROM `characters` WHERE characters.name = '%s'",name.c_str()); |
| | 5639 | if(!result) |
| | 5640 | { |
| | 5641 | SendSysMessage(LANG_COMMAND_FREEZE_WRONG); |
| | 5642 | return true; |
| | 5643 | } |
| | 5644 | //if player found: delete his freeze aura |
| | 5645 | Field *fields=result->Fetch(); |
| | 5646 | uint64 pguid = fields[0].GetUInt64(); |
| | 5647 | delete result; |
| | 5648 | CharacterDatabase.PQuery("DELETE FROM `character_aura` WHERE character_aura.spell = 9454 AND character_aura.guid = '%u'",pguid); |
| | 5649 | PSendSysMessage(LANG_COMMAND_UNFREEZE,name.c_str()); |
| | 5650 | return true; |
| | 5651 | } |
| | 5652 | else |
| | 5653 | { |
| | 5654 | SendSysMessage(LANG_COMMAND_FREEZE_WRONG); |
| | 5655 | return true; |
| | 5656 | } |
| | 5657 | } |
| | 5658 | |
| | 5659 | return true; |
| | 5660 | } |
| | 5661 | |
| | 5662 | bool ChatHandler::HandleListFreezeCommand(const char* args) |
| | 5663 | { |
| | 5664 | //Get names from DB |
| | 5665 | QueryResult *result = CharacterDatabase.PQuery("SELECT characters.name FROM `characters` LEFT JOIN `character_aura` ON (characters.guid = character_aura.guid) WHERE character_aura.spell = 9454"); |
| | 5666 | if(!result) |
| | 5667 | { |
| | 5668 | SendSysMessage(LANG_COMMAND_NO_FROZEN_PLAYERS); |
| | 5669 | return true; |
| | 5670 | } |
| | 5671 | //Header of the names |
| | 5672 | PSendSysMessage(LANG_COMMAND_LIST_FREEZE); |
| | 5673 | |
| | 5674 | //Output of the results |
| | 5675 | do |
| | 5676 | { |
| | 5677 | Field *fields = result->Fetch(); |
| | 5678 | std::string fplayers = fields[0].GetCppString(); |
| | 5679 | PSendSysMessage(LANG_COMMAND_FROZEN_PLAYERS,fplayers.c_str()); |
| | 5680 | } while (result->NextRow()); |
| | 5681 | |
| | 5682 | delete result; |
| | 5683 | return true; |
| | 5684 | } |
| | 5685 | |