Ported .Net Core commits:
hondacrx: - Initial commit: Switch to .Net Core 2.0 - Fix build and removed not needed files Fabi: - Updated solution platforms. - Changed folder structure. - Change library target framework to netstandard2.0. - Updated solution platforms again... - Removed windows specific kernel32 function usage (Ctrl-C handler).
This commit is contained in:
@@ -0,0 +1,980 @@
|
||||
/*
|
||||
* Copyright (C) 2012-2017 CypherCore <http://github.com/CypherCore>
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using Framework.Collections;
|
||||
using Framework.Constants;
|
||||
using Framework.Database;
|
||||
using Game.DataStorage;
|
||||
using Game.Entities;
|
||||
using Game.Maps;
|
||||
using Game.Network.Packets;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace Game.Chat
|
||||
{
|
||||
public class Channel
|
||||
{
|
||||
public Channel(uint channelId, Team team = 0, AreaTableRecord zoneEntry = null)
|
||||
{
|
||||
_channelFlags = ChannelFlags.General;
|
||||
_channelId = channelId;
|
||||
_channelTeam = team;
|
||||
_zoneEntry = zoneEntry;
|
||||
|
||||
ChatChannelsRecord channelEntry = CliDB.ChatChannelsStorage.LookupByKey(channelId);
|
||||
if (channelEntry.Flags.HasAnyFlag(ChannelDBCFlags.Trade)) // for trade channel
|
||||
_channelFlags |= ChannelFlags.Trade;
|
||||
|
||||
if (channelEntry.Flags.HasAnyFlag(ChannelDBCFlags.CityOnly2)) // for city only channels
|
||||
_channelFlags |= ChannelFlags.City;
|
||||
|
||||
if (channelEntry.Flags.HasAnyFlag(ChannelDBCFlags.Lfg)) // for LFG channel
|
||||
_channelFlags |= ChannelFlags.Lfg;
|
||||
else // for all other channels
|
||||
_channelFlags |= ChannelFlags.NotLfg;
|
||||
}
|
||||
|
||||
public Channel(string name, Team team = 0)
|
||||
{
|
||||
_announceEnabled = true;
|
||||
_ownershipEnabled = true;
|
||||
_channelFlags = ChannelFlags.Custom;
|
||||
_channelTeam = team;
|
||||
_channelName = name;
|
||||
|
||||
// If storing custom channels in the db is enabled either load or save the channel
|
||||
if (WorldConfig.GetBoolValue(WorldCfg.PreserveCustomChannels))
|
||||
{
|
||||
PreparedStatement stmt = DB.Characters.GetPreparedStatement(CharStatements.SEL_CHANNEL);
|
||||
stmt.AddValue(0, _channelName);
|
||||
stmt.AddValue(1, _channelTeam);
|
||||
SQLResult result = DB.Characters.Query(stmt);
|
||||
|
||||
if (!result.IsEmpty()) //load
|
||||
{
|
||||
_channelName = result.Read<string>(0); // re-get channel name. MySQL table collation is case insensitive
|
||||
_announceEnabled = result.Read<bool>(1);
|
||||
_ownershipEnabled = result.Read<bool>(2);
|
||||
_channelPassword = result.Read<string>(3);
|
||||
string bannedList = result.Read<string>(4);
|
||||
|
||||
if (string.IsNullOrEmpty(bannedList))
|
||||
{
|
||||
var tokens = new StringArray(bannedList, ' ');
|
||||
for (var i = 0; i < tokens.Length; ++i)
|
||||
{
|
||||
ObjectGuid bannedGuid = new ObjectGuid();
|
||||
bannedGuid.SetRawValue(ulong.Parse(tokens[i].Substring(0, 16)), ulong.Parse(tokens[i].Substring(16)));
|
||||
if (!bannedGuid.IsEmpty())
|
||||
{
|
||||
Log.outDebug(LogFilter.ChatSystem, "Channel({0}) loaded bannedStore guid:{1}", _channelName, bannedGuid);
|
||||
_bannedStore.Add(bannedGuid);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else // save
|
||||
{
|
||||
stmt = DB.Characters.GetPreparedStatement(CharStatements.INS_CHANNEL);
|
||||
stmt.AddValue(0, _channelName);
|
||||
stmt.AddValue(1, _channelTeam);
|
||||
DB.Characters.Execute(stmt);
|
||||
Log.outDebug(LogFilter.ChatSystem, "Channel({0}) saved in database", _channelName);
|
||||
}
|
||||
|
||||
_persistentChannel = true;
|
||||
}
|
||||
}
|
||||
|
||||
public static void GetChannelName(ref string channelName, uint channelId, LocaleConstant locale, AreaTableRecord zoneEntry)
|
||||
{
|
||||
if (channelId != 0)
|
||||
{
|
||||
ChatChannelsRecord channelEntry = CliDB.ChatChannelsStorage.LookupByKey(channelId);
|
||||
if (!channelEntry.Flags.HasAnyFlag(ChannelDBCFlags.Global))
|
||||
{
|
||||
if (channelEntry.Flags.HasAnyFlag(ChannelDBCFlags.CityOnly))
|
||||
channelName = string.Format(channelEntry.Name[locale].ConvertFormatSyntax(), Global.ObjectMgr.GetCypherString(CypherStrings.ChannelCity, locale));
|
||||
else
|
||||
channelName = string.Format(channelEntry.Name[locale].ConvertFormatSyntax(), zoneEntry.AreaName[locale]);
|
||||
}
|
||||
else
|
||||
channelName = channelEntry.Name[locale];
|
||||
}
|
||||
}
|
||||
|
||||
public string GetName(LocaleConstant locale = LocaleConstant.enUS)
|
||||
{
|
||||
string result = _channelName;
|
||||
GetChannelName(ref result, _channelId, locale, _zoneEntry);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void UpdateChannelInDB()
|
||||
{
|
||||
if (_persistentChannel)
|
||||
{
|
||||
string banlist = "";
|
||||
foreach (var iter in _bannedStore)
|
||||
banlist += iter.GetRawValue().ToHexString() + ' ';
|
||||
|
||||
PreparedStatement stmt = DB.Characters.GetPreparedStatement(CharStatements.UPD_CHANNEL);
|
||||
stmt.AddValue(0, _announceEnabled);
|
||||
stmt.AddValue(1, _ownershipEnabled);
|
||||
stmt.AddValue(2, _channelPassword);
|
||||
stmt.AddValue(3, banlist);
|
||||
stmt.AddValue(4, _channelName);
|
||||
stmt.AddValue(5, _channelTeam);
|
||||
DB.Characters.Execute(stmt);
|
||||
|
||||
Log.outDebug(LogFilter.ChatSystem, "Channel({0}) updated in database", _channelName);
|
||||
}
|
||||
}
|
||||
|
||||
void UpdateChannelUseageInDB()
|
||||
{
|
||||
PreparedStatement stmt = DB.Characters.GetPreparedStatement(CharStatements.UPD_CHANNEL_USAGE);
|
||||
stmt.AddValue(0, _channelName);
|
||||
stmt.AddValue(1, _channelTeam);
|
||||
DB.Characters.Execute(stmt);
|
||||
}
|
||||
|
||||
public static void CleanOldChannelsInDB()
|
||||
{
|
||||
if (WorldConfig.GetIntValue(WorldCfg.PreserveCustomChannelDuration) > 0)
|
||||
{
|
||||
PreparedStatement stmt = DB.Characters.GetPreparedStatement(CharStatements.DEL_OLD_CHANNELS);
|
||||
stmt.AddValue(0, WorldConfig.GetIntValue(WorldCfg.PreserveCustomChannelDuration) * Time.Day);
|
||||
DB.Characters.Execute(stmt);
|
||||
|
||||
Log.outDebug(LogFilter.ChatSystem, "Cleaned out unused custom chat channels.");
|
||||
}
|
||||
}
|
||||
|
||||
public void JoinChannel(Player player, string pass)
|
||||
{
|
||||
ObjectGuid guid = player.GetGUID();
|
||||
if (IsOn(guid))
|
||||
{
|
||||
// Do not send error message for built-in channels
|
||||
if (!IsConstant())
|
||||
{
|
||||
var builder = new ChannelNameBuilder(this, new PlayerAlreadyMemberAppend(guid));
|
||||
SendToOne(builder, guid);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (IsBanned(guid))
|
||||
{
|
||||
var builder = new ChannelNameBuilder(this, new BannedAppend());
|
||||
SendToOne(builder, guid);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(_channelPassword) && pass != _channelPassword)
|
||||
{
|
||||
var builder = new ChannelNameBuilder(this, new WrongPasswordAppend());
|
||||
SendToOne(builder, guid);
|
||||
return;
|
||||
}
|
||||
|
||||
if (HasFlag(ChannelFlags.Lfg) && WorldConfig.GetBoolValue(WorldCfg.RestrictedLfgChannel) &&
|
||||
Global.AccountMgr.IsPlayerAccount(player.GetSession().GetSecurity()) && //FIXME: Move to RBAC
|
||||
player.GetGroup())
|
||||
{
|
||||
var builder = new ChannelNameBuilder(this, new NotInLFGAppend());
|
||||
SendToOne(builder, guid);
|
||||
return;
|
||||
}
|
||||
|
||||
player.JoinedChannel(this);
|
||||
|
||||
if (_announceEnabled && !player.GetSession().HasPermission(RBACPermissions.SilentlyJoinChannel))
|
||||
{
|
||||
var builder = new ChannelNameBuilder(this, new JoinedAppend(guid));
|
||||
SendToAll(builder);
|
||||
}
|
||||
|
||||
bool newChannel = _playersStore.Empty();
|
||||
|
||||
PlayerInfo playerInfo = new PlayerInfo();
|
||||
playerInfo.SetInvisible(!player.isGMVisible());
|
||||
_playersStore[guid] = playerInfo;
|
||||
|
||||
/*
|
||||
ChannelNameBuilder<YouJoinedAppend> builder = new ChannelNameBuilder(this, new YouJoinedAppend());
|
||||
SendToOne(builder, guid);
|
||||
*/
|
||||
|
||||
SendToOne(new ChannelNotifyJoinedBuilder(this), guid);
|
||||
|
||||
JoinNotify(player);
|
||||
|
||||
// Custom channel handling
|
||||
if (!IsConstant())
|
||||
{
|
||||
// Update last_used timestamp in db
|
||||
if (!_playersStore.Empty())
|
||||
UpdateChannelUseageInDB();
|
||||
|
||||
// If the channel has no owner yet and ownership is allowed, set the new owner.
|
||||
// or if the owner was a GM with .gm visible off
|
||||
// don't do this if the new player is, too, an invis GM, unless the channel was empty
|
||||
if (_ownershipEnabled && (newChannel || !playerInfo.IsInvisible()) && (_ownerGuid.IsEmpty() || _isOwnerInvisible))
|
||||
{
|
||||
_isOwnerInvisible = playerInfo.IsInvisible();
|
||||
|
||||
SetOwner(guid, !newChannel && !_isOwnerInvisible);
|
||||
_playersStore[guid].SetModerator(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void LeaveChannel(Player player, bool send = true)
|
||||
{
|
||||
ObjectGuid guid = player.GetGUID();
|
||||
if (!IsOn(guid))
|
||||
{
|
||||
if (send)
|
||||
{
|
||||
var builder = new ChannelNameBuilder(this, new NotMemberAppend());
|
||||
SendToOne(builder, guid);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
player.LeftChannel(this);
|
||||
|
||||
if (send)
|
||||
{
|
||||
/*
|
||||
ChannelNameBuilder<YouLeftAppend> builder = new ChannelNameBuilder(this, new YouLeftAppend());
|
||||
SendToOne(builder, guid);
|
||||
*/
|
||||
|
||||
SendToOne(new ChannelNotifyLeftBuilder(this), guid);
|
||||
}
|
||||
|
||||
PlayerInfo info = _playersStore.LookupByKey(guid);
|
||||
bool changeowner = info.IsOwner();
|
||||
_playersStore.Remove(guid);
|
||||
|
||||
if (_announceEnabled && !player.GetSession().HasPermission(RBACPermissions.SilentlyJoinChannel))
|
||||
{
|
||||
var builder = new ChannelNameBuilder(this, new LeftAppend(guid));
|
||||
SendToAll(builder);
|
||||
}
|
||||
|
||||
LeaveNotify(player);
|
||||
|
||||
if (!IsConstant())
|
||||
{
|
||||
// Update last_used timestamp in db
|
||||
UpdateChannelUseageInDB();
|
||||
|
||||
// If the channel owner left and there are still playersStore inside, pick a new owner
|
||||
// do not pick invisible gm owner unless there are only invisible gms in that channel (rare)
|
||||
if (changeowner && _ownershipEnabled && !_playersStore.Empty())
|
||||
{
|
||||
ObjectGuid newowner = ObjectGuid.Empty;
|
||||
foreach (var key in _playersStore.Keys)
|
||||
{
|
||||
if (!_playersStore[key].IsInvisible())
|
||||
{
|
||||
newowner = key;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (newowner.IsEmpty())
|
||||
newowner = _playersStore.First().Key;
|
||||
|
||||
_playersStore[newowner].SetModerator(true);
|
||||
|
||||
SetOwner(newowner);
|
||||
|
||||
// if the new owner is invisible gm, set flag to automatically choose a new owner
|
||||
if (_playersStore[newowner].IsInvisible())
|
||||
_isOwnerInvisible = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void KickOrBan(Player player, string badname, bool ban)
|
||||
{
|
||||
ObjectGuid good = player.GetGUID();
|
||||
|
||||
if (!IsOn(good))
|
||||
{
|
||||
ChannelNameBuilder builder = new ChannelNameBuilder(this, new NotMemberAppend());
|
||||
SendToOne(builder, good);
|
||||
return;
|
||||
}
|
||||
|
||||
PlayerInfo info = _playersStore.LookupByKey(good);
|
||||
if (!info.IsModerator() && !player.GetSession().HasPermission(RBACPermissions.ChangeChannelNotModerator))
|
||||
{
|
||||
ChannelNameBuilder builder = new ChannelNameBuilder(this, new NotModeratorAppend());
|
||||
SendToOne(builder, good);
|
||||
return;
|
||||
}
|
||||
|
||||
Player bad = Global.ObjAccessor.FindPlayerByName(badname);
|
||||
ObjectGuid victim = bad ? bad.GetGUID() : ObjectGuid.Empty;
|
||||
if (victim.IsEmpty() || !IsOn(victim))
|
||||
{
|
||||
ChannelNameBuilder builder = new ChannelNameBuilder(this, new PlayerNotFoundAppend(badname));
|
||||
SendToOne(builder, good);
|
||||
return;
|
||||
}
|
||||
|
||||
bool changeowner = _ownerGuid == victim;
|
||||
|
||||
if (!player.GetSession().HasPermission(RBACPermissions.ChangeChannelNotModerator) && changeowner && good != _ownerGuid)
|
||||
{
|
||||
ChannelNameBuilder builder = new ChannelNameBuilder(this, new NotOwnerAppend());
|
||||
SendToOne(builder, good);
|
||||
return;
|
||||
}
|
||||
|
||||
if (ban && !IsBanned(victim))
|
||||
{
|
||||
_bannedStore.Add(victim);
|
||||
UpdateChannelInDB();
|
||||
|
||||
if (!player.GetSession().HasPermission(RBACPermissions.SilentlyJoinChannel))
|
||||
{
|
||||
ChannelNameBuilder builder = new ChannelNameBuilder(this, new PlayerBannedAppend(good, victim));
|
||||
SendToAll(builder);
|
||||
}
|
||||
|
||||
}
|
||||
else if (!player.GetSession().HasPermission(RBACPermissions.SilentlyJoinChannel))
|
||||
{
|
||||
ChannelNameBuilder builder = new ChannelNameBuilder(this, new PlayerKickedAppend(good, victim));
|
||||
SendToAll(builder);
|
||||
}
|
||||
|
||||
_playersStore.Remove(victim);
|
||||
bad.LeftChannel(this);
|
||||
|
||||
if (changeowner && _ownershipEnabled && !_playersStore.Empty())
|
||||
{
|
||||
info.SetModerator(true);
|
||||
SetOwner(good);
|
||||
}
|
||||
}
|
||||
|
||||
public void UnBan(Player player, string badname)
|
||||
{
|
||||
ObjectGuid good = player.GetGUID();
|
||||
|
||||
if (!IsOn(good))
|
||||
{
|
||||
ChannelNameBuilder builder = new ChannelNameBuilder(this, new NotMemberAppend());
|
||||
SendToOne(builder, good);
|
||||
return;
|
||||
}
|
||||
|
||||
PlayerInfo info = _playersStore.LookupByKey(good);
|
||||
if (!info.IsModerator() && !player.GetSession().HasPermission(RBACPermissions.ChangeChannelNotModerator))
|
||||
{
|
||||
ChannelNameBuilder builder = new ChannelNameBuilder(this, new NotModeratorAppend());
|
||||
SendToOne(builder, good);
|
||||
return;
|
||||
}
|
||||
|
||||
Player bad = Global.ObjAccessor.FindPlayerByName(badname);
|
||||
ObjectGuid victim = bad ? bad.GetGUID() : ObjectGuid.Empty;
|
||||
|
||||
if (victim.IsEmpty() || !IsBanned(victim))
|
||||
{
|
||||
ChannelNameBuilder builder = new ChannelNameBuilder(this, new PlayerNotFoundAppend(badname));
|
||||
SendToOne(builder, good);
|
||||
return;
|
||||
}
|
||||
|
||||
_bannedStore.Remove(victim);
|
||||
|
||||
ChannelNameBuilder builder1 = new ChannelNameBuilder(this, new PlayerUnbannedAppend(good, victim));
|
||||
SendToAll(builder1);
|
||||
|
||||
UpdateChannelInDB();
|
||||
}
|
||||
|
||||
public void Password(Player player, string pass)
|
||||
{
|
||||
ObjectGuid guid = player.GetGUID();
|
||||
|
||||
if (!IsOn(guid))
|
||||
{
|
||||
ChannelNameBuilder builder = new ChannelNameBuilder(this, new NotMemberAppend());
|
||||
SendToOne(builder, guid);
|
||||
return;
|
||||
}
|
||||
|
||||
PlayerInfo info = _playersStore.LookupByKey(guid);
|
||||
if (!info.IsModerator() && !player.GetSession().HasPermission(RBACPermissions.ChangeChannelNotModerator))
|
||||
{
|
||||
ChannelNameBuilder builder = new ChannelNameBuilder(this, new NotModeratorAppend());
|
||||
SendToOne(builder, guid);
|
||||
return;
|
||||
}
|
||||
|
||||
_channelPassword = pass;
|
||||
|
||||
ChannelNameBuilder builder1 = new ChannelNameBuilder(this, new PasswordChangedAppend(guid));
|
||||
SendToAll(builder1);
|
||||
|
||||
UpdateChannelInDB();
|
||||
}
|
||||
|
||||
void SetMode(Player player, string p2n, bool mod, bool set)
|
||||
{
|
||||
ObjectGuid guid = player.GetGUID();
|
||||
|
||||
if (!IsOn(guid))
|
||||
{
|
||||
ChannelNameBuilder builder = new ChannelNameBuilder(this, new NotMemberAppend());
|
||||
SendToOne(builder, guid);
|
||||
return;
|
||||
}
|
||||
|
||||
PlayerInfo info = _playersStore.LookupByKey(guid);
|
||||
if (!info.IsModerator() && !player.GetSession().HasPermission(RBACPermissions.ChangeChannelNotModerator))
|
||||
{
|
||||
ChannelNameBuilder builder = new ChannelNameBuilder(this, new NotModeratorAppend());
|
||||
SendToOne(builder, guid);
|
||||
return;
|
||||
}
|
||||
|
||||
if (guid == _ownerGuid && p2n == player.GetName() && mod)
|
||||
return;
|
||||
|
||||
Player newp = Global.ObjAccessor.FindPlayerByName(p2n);
|
||||
ObjectGuid victim = newp ? newp.GetGUID() : ObjectGuid.Empty;
|
||||
|
||||
if (victim.IsEmpty() || !IsOn(victim) ||
|
||||
(player.GetTeam() != newp.GetTeam() &&
|
||||
(!player.GetSession().HasPermission(RBACPermissions.TwoSideInteractionChannel) ||
|
||||
!newp.GetSession().HasPermission(RBACPermissions.TwoSideInteractionChannel))))
|
||||
{
|
||||
ChannelNameBuilder builder = new ChannelNameBuilder(this, new PlayerNotFoundAppend(p2n));
|
||||
SendToOne(builder, guid);
|
||||
return;
|
||||
}
|
||||
|
||||
if (_ownerGuid == victim && _ownerGuid != guid)
|
||||
{
|
||||
ChannelNameBuilder builder = new ChannelNameBuilder(this, new NotOwnerAppend());
|
||||
SendToOne(builder, guid);
|
||||
return;
|
||||
}
|
||||
|
||||
if (mod)
|
||||
SetModerator(newp.GetGUID(), set);
|
||||
else
|
||||
SetMute(newp.GetGUID(), set);
|
||||
}
|
||||
|
||||
public void SetInvisible(Player player, bool on)
|
||||
{
|
||||
var playerInfo = _playersStore.LookupByKey(player.GetGUID());
|
||||
if (playerInfo == null)
|
||||
return;
|
||||
|
||||
playerInfo.SetInvisible(on);
|
||||
|
||||
// we happen to be owner too, update flag
|
||||
if (_ownerGuid == player.GetGUID())
|
||||
_isOwnerInvisible = on;
|
||||
}
|
||||
|
||||
public void SetOwner(Player player, string newname)
|
||||
{
|
||||
ObjectGuid guid = player.GetGUID();
|
||||
|
||||
if (!IsOn(guid))
|
||||
{
|
||||
ChannelNameBuilder builder = new ChannelNameBuilder(this, new NotMemberAppend());
|
||||
SendToOne(builder, guid);
|
||||
return;
|
||||
}
|
||||
if (!player.GetSession().HasPermission(RBACPermissions.ChangeChannelNotModerator) && guid != _ownerGuid)
|
||||
{
|
||||
ChannelNameBuilder builder = new ChannelNameBuilder(this, new NotOwnerAppend());
|
||||
SendToOne(builder, guid);
|
||||
return;
|
||||
}
|
||||
|
||||
Player newp = Global.ObjAccessor.FindPlayerByName(newname);
|
||||
ObjectGuid victim = newp ? newp.GetGUID() : ObjectGuid.Empty;
|
||||
|
||||
if (victim.IsEmpty() || !IsOn(victim) ||
|
||||
(player.GetTeam() != newp.GetTeam() &&
|
||||
(!player.GetSession().HasPermission(RBACPermissions.TwoSideInteractionChannel) ||
|
||||
!newp.GetSession().HasPermission(RBACPermissions.TwoSideInteractionChannel))))
|
||||
{
|
||||
ChannelNameBuilder builder = new ChannelNameBuilder(this, new PlayerNotFoundAppend(newname));
|
||||
SendToOne(builder, guid);
|
||||
return;
|
||||
}
|
||||
|
||||
_playersStore[victim].SetModerator(true);
|
||||
SetOwner(victim);
|
||||
}
|
||||
|
||||
public void SendWhoOwner(Player player)
|
||||
{
|
||||
ObjectGuid guid = player.GetGUID();
|
||||
if (IsOn(guid))
|
||||
{
|
||||
ChannelNameBuilder builder = new ChannelNameBuilder(this, new ChannelOwnerAppend(this, _ownerGuid));
|
||||
SendToOne(builder, guid);
|
||||
}
|
||||
else
|
||||
{
|
||||
ChannelNameBuilder builder = new ChannelNameBuilder(this, new NotMemberAppend());
|
||||
SendToOne(builder, guid);
|
||||
}
|
||||
}
|
||||
|
||||
public void List(Player player)
|
||||
{
|
||||
ObjectGuid guid = player.GetGUID();
|
||||
|
||||
if (!IsOn(guid))
|
||||
{
|
||||
ChannelNameBuilder builder = new ChannelNameBuilder(this, new NotMemberAppend());
|
||||
SendToOne(builder, guid);
|
||||
return;
|
||||
}
|
||||
|
||||
string channelName = GetName(player.GetSession().GetSessionDbcLocale());
|
||||
Log.outDebug(LogFilter.ChatSystem, "SMSG_CHANNEL_LIST {0} Channel: {1}", player.GetSession().GetPlayerInfo(), channelName);
|
||||
|
||||
ChannelListResponse list = new ChannelListResponse();
|
||||
list.Display = true; /// always true?
|
||||
list.Channel = channelName;
|
||||
list.ChannelFlags = GetFlags();
|
||||
|
||||
uint gmLevelInWhoList = WorldConfig.GetUIntValue(WorldCfg.GmLevelInWhoList);
|
||||
|
||||
foreach (var pair in _playersStore)
|
||||
{
|
||||
Player member = Global.ObjAccessor.FindConnectedPlayer(pair.Key);
|
||||
|
||||
// PLAYER can't see MODERATOR, GAME MASTER, ADMINISTRATOR characters
|
||||
// MODERATOR, GAME MASTER, ADMINISTRATOR can see all
|
||||
if (member && (player.GetSession().HasPermission(RBACPermissions.WhoSeeAllSecLevels) ||
|
||||
member.GetSession().GetSecurity() <= (AccountTypes)gmLevelInWhoList) &&
|
||||
member.IsVisibleGloballyFor(player))
|
||||
{
|
||||
list.Members.Add(new ChannelListResponse.ChannelPlayer(pair.Key, Global.WorldMgr.GetVirtualRealmAddress(), pair.Value.GetFlags()));
|
||||
}
|
||||
}
|
||||
|
||||
player.SendPacket(list);
|
||||
}
|
||||
|
||||
public void Announce(Player player)
|
||||
{
|
||||
ObjectGuid guid = player.GetGUID();
|
||||
|
||||
if (!IsOn(guid))
|
||||
{
|
||||
ChannelNameBuilder builder = new ChannelNameBuilder(this, new NotMemberAppend());
|
||||
SendToOne(builder, guid);
|
||||
return;
|
||||
}
|
||||
|
||||
PlayerInfo playerInfo = _playersStore.LookupByKey(guid);
|
||||
if (!playerInfo.IsModerator() && !player.GetSession().HasPermission(RBACPermissions.ChangeChannelNotModerator))
|
||||
{
|
||||
ChannelNameBuilder builder = new ChannelNameBuilder(this, new NotModeratorAppend());
|
||||
SendToOne(builder, guid);
|
||||
return;
|
||||
}
|
||||
|
||||
_announceEnabled = !_announceEnabled;
|
||||
|
||||
if (_announceEnabled)
|
||||
{
|
||||
ChannelNameBuilder builder = new ChannelNameBuilder(this, new AnnouncementsOnAppend(guid));
|
||||
SendToAll(builder);
|
||||
}
|
||||
else
|
||||
{
|
||||
ChannelNameBuilder builder = new ChannelNameBuilder(this, new AnnouncementsOffAppend(guid));
|
||||
SendToAll(builder);
|
||||
}
|
||||
|
||||
UpdateChannelInDB();
|
||||
}
|
||||
|
||||
public void Say(ObjectGuid guid, string what, Language lang)
|
||||
{
|
||||
if (string.IsNullOrEmpty(what))
|
||||
return;
|
||||
|
||||
// TODO: Add proper RBAC check
|
||||
if (WorldConfig.GetBoolValue(WorldCfg.AllowTwoSideInteractionChannel))
|
||||
lang = Language.Universal;
|
||||
|
||||
if (!IsOn(guid))
|
||||
{
|
||||
ChannelNameBuilder builder = new ChannelNameBuilder(this, new NotMemberAppend());
|
||||
SendToOne(builder, guid);
|
||||
return;
|
||||
}
|
||||
|
||||
PlayerInfo playerInfo = _playersStore.LookupByKey(guid);
|
||||
if (playerInfo.IsMuted())
|
||||
{
|
||||
ChannelNameBuilder builder = new ChannelNameBuilder(this, new MutedAppend());
|
||||
SendToOne(builder, guid);
|
||||
return;
|
||||
}
|
||||
|
||||
SendToAll(new ChannelSayBuilder(this, lang, what, guid), !playerInfo.IsModerator() ? guid : ObjectGuid.Empty);
|
||||
}
|
||||
|
||||
public void AddonSay(ObjectGuid guid, string prefix, string what)
|
||||
{
|
||||
if (what.IsEmpty())
|
||||
return;
|
||||
|
||||
if (!IsOn(guid))
|
||||
{
|
||||
NotMemberAppend appender;
|
||||
ChannelNameBuilder builder = new ChannelNameBuilder(this, appender);
|
||||
SendToOne(builder, guid);
|
||||
return;
|
||||
}
|
||||
|
||||
PlayerInfo playerInfo = _playersStore.LookupByKey(guid);
|
||||
if (playerInfo.IsMuted())
|
||||
{
|
||||
MutedAppend appender;
|
||||
ChannelNameBuilder builder = new ChannelNameBuilder(this, appender);
|
||||
SendToOne(builder, guid);
|
||||
return;
|
||||
}
|
||||
|
||||
SendToAllWithAddon(new ChannelWhisperBuilder(this, Language.Addon, what, prefix, guid), prefix, !playerInfo.IsModerator() ? guid : ObjectGuid.Empty);
|
||||
}
|
||||
|
||||
public void Invite(Player player, string newname)
|
||||
{
|
||||
ObjectGuid guid = player.GetGUID();
|
||||
|
||||
if (!IsOn(guid))
|
||||
{
|
||||
ChannelNameBuilder builder = new ChannelNameBuilder(this, new NotMemberAppend());
|
||||
SendToOne(builder, guid);
|
||||
return;
|
||||
}
|
||||
|
||||
Player newp = Global.ObjAccessor.FindPlayerByName(newname);
|
||||
if (!newp || !newp.isGMVisible())
|
||||
{
|
||||
ChannelNameBuilder builder = new ChannelNameBuilder(this, new PlayerNotFoundAppend(newname));
|
||||
SendToOne(builder, guid);
|
||||
return;
|
||||
}
|
||||
|
||||
if (IsBanned(newp.GetGUID()))
|
||||
{
|
||||
ChannelNameBuilder builder = new ChannelNameBuilder(this, new PlayerInviteBannedAppend(newname));
|
||||
SendToOne(builder, guid);
|
||||
return;
|
||||
}
|
||||
|
||||
if (newp.GetTeam() != player.GetTeam() &&
|
||||
(!player.GetSession().HasPermission(RBACPermissions.TwoSideInteractionChannel) ||
|
||||
!newp.GetSession().HasPermission(RBACPermissions.TwoSideInteractionChannel)))
|
||||
{
|
||||
ChannelNameBuilder builder = new ChannelNameBuilder(this, new InviteWrongFactionAppend());
|
||||
SendToOne(builder, guid);
|
||||
return;
|
||||
}
|
||||
|
||||
if (IsOn(newp.GetGUID()))
|
||||
{
|
||||
ChannelNameBuilder builder = new ChannelNameBuilder(this, new PlayerAlreadyMemberAppend(newp.GetGUID()));
|
||||
SendToOne(builder, guid);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!newp.GetSocial().HasIgnore(guid))
|
||||
{
|
||||
ChannelNameBuilder builder = new ChannelNameBuilder(this, new InviteAppend(guid));
|
||||
SendToOne(builder, newp.GetGUID());
|
||||
}
|
||||
|
||||
ChannelNameBuilder builder1 = new ChannelNameBuilder(this, new PlayerInvitedAppend(newp.GetName()));
|
||||
SendToOne(builder1, guid);
|
||||
}
|
||||
|
||||
public void SetOwner(ObjectGuid guid, bool exclaim = true)
|
||||
{
|
||||
if (!_ownerGuid.IsEmpty())
|
||||
{
|
||||
// [] will re-add player after it possible removed
|
||||
var playerInfo = _playersStore.LookupByKey(_ownerGuid);
|
||||
if (playerInfo != null)
|
||||
playerInfo.SetOwner(false);
|
||||
}
|
||||
|
||||
_ownerGuid = guid;
|
||||
if (!_ownerGuid.IsEmpty())
|
||||
{
|
||||
ChannelMemberFlags oldFlag = GetPlayerFlags(_ownerGuid);
|
||||
var playerInfo = _playersStore.LookupByKey(_ownerGuid);
|
||||
if (playerInfo == null)
|
||||
return;
|
||||
|
||||
playerInfo.SetModerator(true);
|
||||
playerInfo.SetOwner(true);
|
||||
|
||||
ChannelNameBuilder builder = new ChannelNameBuilder(this, new ModeChangeAppend(_ownerGuid, oldFlag, GetPlayerFlags(_ownerGuid)));
|
||||
SendToAll(builder);
|
||||
|
||||
if (exclaim)
|
||||
{
|
||||
ChannelNameBuilder ownerChangedBuilder = new ChannelNameBuilder(this, new OwnerChangedAppend(_ownerGuid));
|
||||
SendToAll(ownerChangedBuilder);
|
||||
}
|
||||
|
||||
UpdateChannelInDB();
|
||||
}
|
||||
}
|
||||
|
||||
public void SilenceAll(Player player, string name) { }
|
||||
|
||||
public void UnsilenceAll(Player player, string name) { }
|
||||
|
||||
public void DeclineInvite(Player player) { }
|
||||
|
||||
void JoinNotify(Player player)
|
||||
{
|
||||
ObjectGuid guid = player.GetGUID();
|
||||
|
||||
if (IsConstant())
|
||||
SendToAllButOne(new ChannelUserlistAddBuilder(this, guid), guid);
|
||||
else
|
||||
SendToAll(new ChannelUserlistUpdateBuilder(this, guid));
|
||||
}
|
||||
|
||||
void LeaveNotify(Player player)
|
||||
{
|
||||
ObjectGuid guid = player.GetGUID();
|
||||
|
||||
var builder = new ChannelUserlistRemoveBuilder(this, guid);
|
||||
|
||||
if (IsConstant())
|
||||
SendToAllButOne(builder, guid);
|
||||
else
|
||||
SendToAll(builder);
|
||||
}
|
||||
|
||||
void SetModerator(ObjectGuid guid, bool set)
|
||||
{
|
||||
if (!IsOn(guid))
|
||||
return;
|
||||
|
||||
PlayerInfo playerInfo = _playersStore.LookupByKey(guid);
|
||||
if (playerInfo.IsModerator() != set)
|
||||
{
|
||||
ChannelMemberFlags oldFlag = _playersStore[guid].GetFlags();
|
||||
playerInfo.SetModerator(set);
|
||||
|
||||
ChannelNameBuilder builder = new ChannelNameBuilder(this, new ModeChangeAppend(guid, oldFlag, playerInfo.GetFlags()));
|
||||
SendToAll(builder);
|
||||
}
|
||||
}
|
||||
|
||||
void SetMute(ObjectGuid guid, bool set)
|
||||
{
|
||||
if (!IsOn(guid))
|
||||
return;
|
||||
|
||||
PlayerInfo playerInfo = _playersStore.LookupByKey(guid);
|
||||
if (playerInfo.IsMuted() != set)
|
||||
{
|
||||
ChannelMemberFlags oldFlag = _playersStore[guid].GetFlags();
|
||||
playerInfo.SetMuted(set);
|
||||
|
||||
ChannelNameBuilder builder = new ChannelNameBuilder(this, new ModeChangeAppend(guid, oldFlag, playerInfo.GetFlags()));
|
||||
SendToAll(builder);
|
||||
}
|
||||
}
|
||||
|
||||
void SendToAll(MessageBuilder builder, ObjectGuid guid = default(ObjectGuid))
|
||||
{
|
||||
LocalizedPacketDo localizer = new LocalizedPacketDo(builder);
|
||||
|
||||
foreach (var pair in _playersStore)
|
||||
{
|
||||
Player player = Global.ObjAccessor.FindConnectedPlayer(pair.Key);
|
||||
if (player)
|
||||
if (guid.IsEmpty() || !player.GetSocial().HasIgnore(guid))
|
||||
localizer.Invoke(player);
|
||||
}
|
||||
}
|
||||
|
||||
void SendToAllButOne(MessageBuilder builder, ObjectGuid who)
|
||||
{
|
||||
LocalizedPacketDo localizer = new LocalizedPacketDo(builder);
|
||||
|
||||
foreach (var pair in _playersStore)
|
||||
{
|
||||
if (pair.Key != who)
|
||||
{
|
||||
Player player = Global.ObjAccessor.FindConnectedPlayer(pair.Key);
|
||||
if (player)
|
||||
localizer.Invoke(player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SendToOne(MessageBuilder builder, ObjectGuid who)
|
||||
{
|
||||
LocalizedPacketDo localizer = new LocalizedPacketDo(builder);
|
||||
|
||||
Player player = Global.ObjAccessor.FindConnectedPlayer(who);
|
||||
if (player)
|
||||
localizer.Invoke(player);
|
||||
}
|
||||
|
||||
void SendToAllWithAddon(MessageBuilder builder, string addonPrefix, ObjectGuid guid = default(ObjectGuid))
|
||||
{
|
||||
LocalizedPacketDo localizer = new LocalizedPacketDo(builder);
|
||||
|
||||
foreach (var pair in _playersStore)
|
||||
{
|
||||
Player player = Global.ObjAccessor.FindConnectedPlayer(pair.Key);
|
||||
if (player)
|
||||
if (player.GetSession().IsAddonRegistered(addonPrefix) && (guid.IsEmpty() || !player.GetSocial().HasIgnore(guid)))
|
||||
localizer.Invoke(player);
|
||||
}
|
||||
}
|
||||
|
||||
public uint GetChannelId() { return _channelId; }
|
||||
public bool IsConstant() { return _channelId != 0; }
|
||||
|
||||
public bool IsLFG() { return GetFlags().HasAnyFlag(ChannelFlags.Lfg); }
|
||||
bool IsAnnounce() { return _announceEnabled; }
|
||||
void SetAnnounce(bool nannounce) { _announceEnabled = nannounce; }
|
||||
|
||||
string GetPassword() { return _channelPassword; }
|
||||
void SetPassword(string npassword) { _channelPassword = npassword; }
|
||||
|
||||
public uint GetNumPlayers() { return (uint)_playersStore.Count; }
|
||||
|
||||
public ChannelFlags GetFlags() { return _channelFlags; }
|
||||
bool HasFlag(ChannelFlags flag) { return _channelFlags.HasAnyFlag(flag); }
|
||||
|
||||
public AreaTableRecord GetZoneEntry() { return _zoneEntry; }
|
||||
|
||||
public void Kick(Player player, string badname) { KickOrBan(player, badname, false); }
|
||||
public void Ban(Player player, string badname) { KickOrBan(player, badname, true); }
|
||||
|
||||
public void SetModerator(Player player, string newname) { SetMode(player, newname, true, true); }
|
||||
public void UnsetModerator(Player player, string newname) { SetMode(player, newname, true, false); }
|
||||
public void SetMute(Player player, string newname) { SetMode(player, newname, false, true); }
|
||||
public void UnsetMute(Player player, string newname) { SetMode(player, newname, false, false); }
|
||||
|
||||
public void SetOwnership(bool ownership) { _ownershipEnabled = ownership; }
|
||||
|
||||
bool IsOn(ObjectGuid who) { return _playersStore.ContainsKey(who); }
|
||||
bool IsBanned(ObjectGuid guid) { return _bannedStore.Contains(guid); }
|
||||
|
||||
public ChannelMemberFlags GetPlayerFlags(ObjectGuid guid)
|
||||
{
|
||||
var info = _playersStore.LookupByKey(guid);
|
||||
return info != null ? info.GetFlags() : 0;
|
||||
}
|
||||
|
||||
bool _announceEnabled;
|
||||
bool _ownershipEnabled;
|
||||
bool _persistentChannel;
|
||||
bool _isOwnerInvisible;
|
||||
|
||||
ChannelFlags _channelFlags;
|
||||
uint _channelId;
|
||||
Team _channelTeam;
|
||||
ObjectGuid _ownerGuid;
|
||||
string _channelName;
|
||||
string _channelPassword;
|
||||
Dictionary<ObjectGuid, PlayerInfo> _playersStore = new Dictionary<ObjectGuid, PlayerInfo>();
|
||||
List<ObjectGuid> _bannedStore = new List<ObjectGuid>();
|
||||
|
||||
AreaTableRecord _zoneEntry;
|
||||
|
||||
public class PlayerInfo
|
||||
{
|
||||
public ChannelMemberFlags GetFlags() { return flags; }
|
||||
|
||||
public bool IsInvisible() { return _invisible; }
|
||||
public void SetInvisible(bool on) { _invisible = on; }
|
||||
|
||||
public bool HasFlag(ChannelMemberFlags flag) { return flags.HasAnyFlag(flag); }
|
||||
|
||||
public void SetFlag(ChannelMemberFlags flag) { flags |= flag; }
|
||||
|
||||
public void RemoveFlag(ChannelMemberFlags flag) { flags &= ~flag; }
|
||||
|
||||
public bool IsOwner() { return HasFlag(ChannelMemberFlags.Owner); }
|
||||
|
||||
public void SetOwner(bool state)
|
||||
{
|
||||
if (state)
|
||||
SetFlag(ChannelMemberFlags.Owner);
|
||||
else
|
||||
RemoveFlag(ChannelMemberFlags.Owner);
|
||||
}
|
||||
|
||||
public bool IsModerator() { return HasFlag(ChannelMemberFlags.Moderator); }
|
||||
|
||||
public void SetModerator(bool state)
|
||||
{
|
||||
if (state)
|
||||
SetFlag(ChannelMemberFlags.Moderator);
|
||||
else
|
||||
RemoveFlag(ChannelMemberFlags.Moderator);
|
||||
}
|
||||
|
||||
public bool IsMuted() { return HasFlag(ChannelMemberFlags.Muted); }
|
||||
|
||||
public void SetMuted(bool state)
|
||||
{
|
||||
if (state)
|
||||
SetFlag(ChannelMemberFlags.Muted);
|
||||
else
|
||||
RemoveFlag(ChannelMemberFlags.Muted);
|
||||
}
|
||||
|
||||
ChannelMemberFlags flags;
|
||||
bool _invisible;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,716 @@
|
||||
/*
|
||||
* Copyright (C) 2012-2017 CypherCore <http://github.com/CypherCore>
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using Framework.Constants;
|
||||
using Game.Entities;
|
||||
using Game.Network;
|
||||
using Game.Network.Packets;
|
||||
|
||||
namespace Game.Chat
|
||||
{
|
||||
interface IChannelAppender
|
||||
{
|
||||
void Append(ChannelNotify data);
|
||||
ChatNotify GetNotificationType();
|
||||
}
|
||||
|
||||
// initial packet data (notify type and channel name)
|
||||
class ChannelNameBuilder : MessageBuilder
|
||||
{
|
||||
public ChannelNameBuilder(Channel source, IChannelAppender modifier)
|
||||
{
|
||||
_source = source;
|
||||
_modifier = modifier;
|
||||
}
|
||||
|
||||
public override ServerPacket Invoke(LocaleConstant locale = LocaleConstant.enUS)
|
||||
{
|
||||
// LocalizedPacketDo sends client DBC locale, we need to get available to server locale
|
||||
LocaleConstant localeIdx = Global.WorldMgr.GetAvailableDbcLocale(locale);
|
||||
|
||||
ChannelNotify data = new ChannelNotify();
|
||||
data.Type = _modifier.GetNotificationType();
|
||||
data.Channel = _source.GetName(localeIdx);
|
||||
_modifier.Append(data);
|
||||
return data;
|
||||
}
|
||||
|
||||
Channel _source;
|
||||
IChannelAppender _modifier;
|
||||
}
|
||||
|
||||
class ChannelNotifyJoinedBuilder : MessageBuilder
|
||||
{
|
||||
public ChannelNotifyJoinedBuilder(Channel source)
|
||||
{
|
||||
_source = source;
|
||||
}
|
||||
|
||||
public override ServerPacket Invoke(LocaleConstant locale = LocaleConstant.enUS)
|
||||
{
|
||||
LocaleConstant localeIdx = Global.WorldMgr.GetAvailableDbcLocale(locale);
|
||||
|
||||
ChannelNotifyJoined notify = new ChannelNotifyJoined();
|
||||
//notify->ChannelWelcomeMsg = "";
|
||||
notify.ChatChannelID = (int)_source.GetChannelId();
|
||||
//notify->InstanceID = 0;
|
||||
notify.ChannelFlags = _source.GetFlags();
|
||||
notify.Channel = _source.GetName(localeIdx);
|
||||
return notify;
|
||||
}
|
||||
|
||||
Channel _source;
|
||||
}
|
||||
|
||||
class ChannelNotifyLeftBuilder : MessageBuilder
|
||||
{
|
||||
public ChannelNotifyLeftBuilder(Channel source)
|
||||
{
|
||||
_source = source;
|
||||
}
|
||||
|
||||
public override ServerPacket Invoke(LocaleConstant locale = LocaleConstant.enUS)
|
||||
{
|
||||
LocaleConstant localeIdx = Global.WorldMgr.GetAvailableDbcLocale(locale);
|
||||
|
||||
ChannelNotifyLeft notify = new ChannelNotifyLeft();
|
||||
notify.Channel = _source.GetName(localeIdx);
|
||||
notify.ChatChannelID = 0;
|
||||
//notify->Suspended = false;
|
||||
return notify;
|
||||
}
|
||||
|
||||
Channel _source;
|
||||
}
|
||||
|
||||
class ChannelSayBuilder : MessageBuilder
|
||||
{
|
||||
public ChannelSayBuilder(Channel source, Language lang, string what, ObjectGuid guid)
|
||||
{
|
||||
_source = source;
|
||||
_lang = lang;
|
||||
_what = what;
|
||||
_guid = guid;
|
||||
}
|
||||
|
||||
public override ServerPacket Invoke(LocaleConstant locale = LocaleConstant.enUS)
|
||||
{
|
||||
LocaleConstant localeIdx = Global.WorldMgr.GetAvailableDbcLocale(locale);
|
||||
|
||||
ChatPkt packet = new ChatPkt();
|
||||
Player player = Global.ObjAccessor.FindConnectedPlayer(_guid);
|
||||
if (player)
|
||||
packet.Initialize(ChatMsg.Channel, _lang, player, player, _what, 0, _source.GetName(localeIdx));
|
||||
else
|
||||
{
|
||||
packet.Initialize(ChatMsg.Channel, _lang, null, null, _what, 0, _source.GetName(localeIdx));
|
||||
packet.SenderGUID = _guid;
|
||||
packet.TargetGUID = _guid;
|
||||
}
|
||||
|
||||
return packet;
|
||||
}
|
||||
|
||||
Channel _source;
|
||||
Language _lang;
|
||||
string _what;
|
||||
ObjectGuid _guid;
|
||||
}
|
||||
|
||||
class ChannelWhisperBuilder : MessageBuilder
|
||||
{
|
||||
public ChannelWhisperBuilder(Channel source, Language lang, string what, string prefix, ObjectGuid guid)
|
||||
{
|
||||
_source = source;
|
||||
_lang = lang;
|
||||
_what = what;
|
||||
_prefix = prefix;
|
||||
_guid = guid;
|
||||
}
|
||||
|
||||
public override ServerPacket Invoke(LocaleConstant locale = LocaleConstant.enUS)
|
||||
{
|
||||
LocaleConstant localeIdx = Global.WorldMgr.GetAvailableDbcLocale(locale);
|
||||
|
||||
ChatPkt packet = new ChatPkt();
|
||||
Player player = Global.ObjAccessor.FindConnectedPlayer(_guid);
|
||||
if (player)
|
||||
packet.Initialize(ChatMsg.Channel, Language.Addon, player, player, _what, 0, _source.GetName(localeIdx), LocaleConstant.enUS, _prefix);
|
||||
else
|
||||
{
|
||||
packet.Initialize(ChatMsg.Channel, Language.Addon, null, null, _what, 0, _source.GetName(localeIdx), LocaleConstant.enUS, _prefix);
|
||||
packet.SenderGUID = _guid;
|
||||
packet.TargetGUID = _guid;
|
||||
}
|
||||
|
||||
return packet;
|
||||
}
|
||||
|
||||
Channel _source;
|
||||
Language _lang;
|
||||
string _what;
|
||||
string _prefix;
|
||||
ObjectGuid _guid;
|
||||
}
|
||||
|
||||
class ChannelUserlistAddBuilder : MessageBuilder
|
||||
{
|
||||
public ChannelUserlistAddBuilder(Channel source, ObjectGuid guid)
|
||||
{
|
||||
_source = source;
|
||||
_guid = guid;
|
||||
}
|
||||
|
||||
public override ServerPacket Invoke(LocaleConstant locale = LocaleConstant.enUS)
|
||||
{
|
||||
LocaleConstant localeIdx = Global.WorldMgr.GetAvailableDbcLocale(locale);
|
||||
|
||||
UserlistAdd userlistAdd = new UserlistAdd();
|
||||
userlistAdd.AddedUserGUID = _guid;
|
||||
userlistAdd.ChannelFlags = _source.GetFlags();
|
||||
userlistAdd.UserFlags = _source.GetPlayerFlags(_guid);
|
||||
userlistAdd.ChannelID = _source.GetChannelId();
|
||||
userlistAdd.ChannelName = _source.GetName(localeIdx);
|
||||
return userlistAdd;
|
||||
}
|
||||
|
||||
Channel _source;
|
||||
ObjectGuid _guid;
|
||||
}
|
||||
|
||||
class ChannelUserlistUpdateBuilder : MessageBuilder
|
||||
{
|
||||
public ChannelUserlistUpdateBuilder(Channel source, ObjectGuid guid)
|
||||
{
|
||||
_source = source;
|
||||
_guid = guid;
|
||||
}
|
||||
|
||||
public override ServerPacket Invoke(LocaleConstant locale = LocaleConstant.enUS)
|
||||
{
|
||||
LocaleConstant localeIdx = Global.WorldMgr.GetAvailableDbcLocale(locale);
|
||||
|
||||
UserlistUpdate userlistUpdate = new UserlistUpdate();
|
||||
userlistUpdate.UpdatedUserGUID = _guid;
|
||||
userlistUpdate.ChannelFlags = _source.GetFlags();
|
||||
userlistUpdate.UserFlags = _source.GetPlayerFlags(_guid);
|
||||
userlistUpdate.ChannelID = _source.GetChannelId();
|
||||
userlistUpdate.ChannelName = _source.GetName(localeIdx);
|
||||
return userlistUpdate;
|
||||
}
|
||||
|
||||
Channel _source;
|
||||
ObjectGuid _guid;
|
||||
}
|
||||
|
||||
class ChannelUserlistRemoveBuilder : MessageBuilder
|
||||
{
|
||||
public ChannelUserlistRemoveBuilder(Channel source, ObjectGuid guid)
|
||||
{
|
||||
_source = source;
|
||||
_guid = guid;
|
||||
}
|
||||
|
||||
public override ServerPacket Invoke(LocaleConstant locale = LocaleConstant.enUS)
|
||||
{
|
||||
LocaleConstant localeIdx = Global.WorldMgr.GetAvailableDbcLocale(locale);
|
||||
|
||||
UserlistRemove userlistRemove = new UserlistRemove();
|
||||
userlistRemove.RemovedUserGUID = _guid;
|
||||
userlistRemove.ChannelFlags = _source.GetFlags();
|
||||
userlistRemove.ChannelID = _source.GetChannelId();
|
||||
userlistRemove.ChannelName = _source.GetName(localeIdx);
|
||||
return userlistRemove;
|
||||
}
|
||||
|
||||
Channel _source;
|
||||
ObjectGuid _guid;
|
||||
}
|
||||
|
||||
//Appenders
|
||||
struct JoinedAppend : IChannelAppender
|
||||
{
|
||||
public JoinedAppend(ObjectGuid guid)
|
||||
{
|
||||
_guid = guid;
|
||||
}
|
||||
|
||||
public ChatNotify GetNotificationType() => ChatNotify.JoinedNotice;
|
||||
|
||||
public void Append(ChannelNotify data)
|
||||
{
|
||||
data.SenderGuid = _guid;
|
||||
}
|
||||
|
||||
ObjectGuid _guid;
|
||||
}
|
||||
|
||||
struct LeftAppend : IChannelAppender
|
||||
{
|
||||
public LeftAppend(ObjectGuid guid)
|
||||
{
|
||||
_guid = guid;
|
||||
}
|
||||
|
||||
public ChatNotify GetNotificationType() => ChatNotify.LeftNotice;
|
||||
|
||||
public void Append(ChannelNotify data)
|
||||
{
|
||||
data.SenderGuid = _guid;
|
||||
}
|
||||
|
||||
ObjectGuid _guid;
|
||||
}
|
||||
|
||||
struct YouJoinedAppend : IChannelAppender
|
||||
{
|
||||
public YouJoinedAppend(Channel channel)
|
||||
{
|
||||
_channel = channel;
|
||||
}
|
||||
|
||||
public ChatNotify GetNotificationType() => ChatNotify.YouJoinedNotice;
|
||||
|
||||
public void Append(ChannelNotify data)
|
||||
{
|
||||
data.ChatChannelID = (int)_channel.GetChannelId();
|
||||
}
|
||||
|
||||
Channel _channel;
|
||||
}
|
||||
|
||||
struct YouLeftAppend : IChannelAppender
|
||||
{
|
||||
public YouLeftAppend(Channel channel)
|
||||
{
|
||||
_channel = channel;
|
||||
}
|
||||
|
||||
public ChatNotify GetNotificationType() => ChatNotify.YouLeftNotice;
|
||||
|
||||
public void Append(ChannelNotify data)
|
||||
{
|
||||
data.ChatChannelID = (int)_channel.GetChannelId();
|
||||
}
|
||||
|
||||
Channel _channel;
|
||||
}
|
||||
|
||||
struct WrongPasswordAppend : IChannelAppender
|
||||
{
|
||||
public ChatNotify GetNotificationType() => ChatNotify.WrongPasswordNotice;
|
||||
|
||||
public void Append(ChannelNotify data) { }
|
||||
}
|
||||
|
||||
struct NotMemberAppend : IChannelAppender
|
||||
{
|
||||
public ChatNotify GetNotificationType() => ChatNotify.NotMemberNotice;
|
||||
|
||||
public void Append(ChannelNotify data) { }
|
||||
}
|
||||
|
||||
struct NotModeratorAppend : IChannelAppender
|
||||
{
|
||||
public ChatNotify GetNotificationType() => ChatNotify.NotModeratorNotice;
|
||||
|
||||
public void Append(ChannelNotify data) { }
|
||||
}
|
||||
|
||||
struct PasswordChangedAppend : IChannelAppender
|
||||
{
|
||||
public PasswordChangedAppend(ObjectGuid guid)
|
||||
{
|
||||
_guid = guid;
|
||||
}
|
||||
|
||||
public ChatNotify GetNotificationType() => ChatNotify.PasswordChangedNotice;
|
||||
|
||||
public void Append(ChannelNotify data)
|
||||
{
|
||||
data.SenderGuid = _guid;
|
||||
}
|
||||
|
||||
ObjectGuid _guid;
|
||||
}
|
||||
|
||||
struct OwnerChangedAppend : IChannelAppender
|
||||
{
|
||||
public OwnerChangedAppend(ObjectGuid guid)
|
||||
{
|
||||
_guid = guid;
|
||||
}
|
||||
|
||||
public ChatNotify GetNotificationType() => ChatNotify.OwnerChangedNotice;
|
||||
|
||||
public void Append(ChannelNotify data)
|
||||
{
|
||||
data.SenderGuid = _guid;
|
||||
}
|
||||
|
||||
ObjectGuid _guid;
|
||||
}
|
||||
|
||||
struct PlayerNotFoundAppend : IChannelAppender
|
||||
{
|
||||
public PlayerNotFoundAppend(string playerName)
|
||||
{
|
||||
_playerName = playerName;
|
||||
}
|
||||
|
||||
public ChatNotify GetNotificationType() => ChatNotify.PlayerNotFoundNotice;
|
||||
|
||||
public void Append(ChannelNotify data)
|
||||
{
|
||||
data.Sender = _playerName;
|
||||
}
|
||||
|
||||
string _playerName;
|
||||
}
|
||||
|
||||
struct NotOwnerAppend : IChannelAppender
|
||||
{
|
||||
public ChatNotify GetNotificationType() => ChatNotify.NotOwnerNotice;
|
||||
|
||||
public void Append(ChannelNotify data) { }
|
||||
}
|
||||
|
||||
struct ChannelOwnerAppend : IChannelAppender
|
||||
{
|
||||
public ChannelOwnerAppend(Channel channel, ObjectGuid ownerGuid)
|
||||
{
|
||||
_channel = channel;
|
||||
_ownerGuid = ownerGuid;
|
||||
_ownerName = "";
|
||||
|
||||
CharacterInfo characterInfo = Global.WorldMgr.GetCharacterInfo(_ownerGuid);
|
||||
if (characterInfo != null)
|
||||
_ownerName = characterInfo.Name;
|
||||
}
|
||||
|
||||
public ChatNotify GetNotificationType() => ChatNotify.ChannelOwnerNotice;
|
||||
|
||||
public void Append(ChannelNotify data)
|
||||
{
|
||||
data.Sender = ((_channel.IsConstant() || _ownerGuid.IsEmpty()) ? "Nobody" : _ownerName);
|
||||
}
|
||||
|
||||
Channel _channel;
|
||||
ObjectGuid _ownerGuid;
|
||||
|
||||
string _ownerName;
|
||||
}
|
||||
|
||||
struct ModeChangeAppend : IChannelAppender
|
||||
{
|
||||
public ModeChangeAppend(ObjectGuid guid, ChannelMemberFlags oldFlags, ChannelMemberFlags newFlags)
|
||||
{
|
||||
_guid = guid;
|
||||
_oldFlags = oldFlags;
|
||||
_newFlags = newFlags;
|
||||
}
|
||||
|
||||
public ChatNotify GetNotificationType() => ChatNotify.ModeChangeNotice;
|
||||
|
||||
public void Append(ChannelNotify data)
|
||||
{
|
||||
data.SenderGuid = _guid;
|
||||
data.OldFlags = _oldFlags;
|
||||
data.NewFlags = _newFlags;
|
||||
}
|
||||
|
||||
ObjectGuid _guid;
|
||||
ChannelMemberFlags _oldFlags;
|
||||
ChannelMemberFlags _newFlags;
|
||||
}
|
||||
|
||||
struct AnnouncementsOnAppend : IChannelAppender
|
||||
{
|
||||
public AnnouncementsOnAppend(ObjectGuid guid)
|
||||
{
|
||||
_guid = guid;
|
||||
}
|
||||
|
||||
public ChatNotify GetNotificationType() => ChatNotify.AnnouncementsOnNotice;
|
||||
|
||||
public void Append(ChannelNotify data)
|
||||
{
|
||||
data.SenderGuid = _guid;
|
||||
}
|
||||
|
||||
ObjectGuid _guid;
|
||||
}
|
||||
|
||||
struct AnnouncementsOffAppend : IChannelAppender
|
||||
{
|
||||
public AnnouncementsOffAppend(ObjectGuid guid)
|
||||
{
|
||||
_guid = guid;
|
||||
}
|
||||
|
||||
public ChatNotify GetNotificationType() => ChatNotify.AnnouncementsOffNotice;
|
||||
|
||||
public void Append(ChannelNotify data)
|
||||
{
|
||||
data.SenderGuid = _guid;
|
||||
}
|
||||
|
||||
ObjectGuid _guid;
|
||||
}
|
||||
|
||||
struct MutedAppend : IChannelAppender
|
||||
{
|
||||
public ChatNotify GetNotificationType() => ChatNotify.MutedNotice;
|
||||
|
||||
public void Append(ChannelNotify data) { }
|
||||
}
|
||||
|
||||
struct PlayerKickedAppend : IChannelAppender
|
||||
{
|
||||
public PlayerKickedAppend(ObjectGuid kicker, ObjectGuid kickee)
|
||||
{
|
||||
_kicker = kicker;
|
||||
_kickee = kickee;
|
||||
}
|
||||
|
||||
public ChatNotify GetNotificationType() => ChatNotify.PlayerKickedNotice;
|
||||
|
||||
public void Append(ChannelNotify data)
|
||||
{
|
||||
data.SenderGuid = _kicker;
|
||||
data.TargetGuid = _kickee;
|
||||
}
|
||||
|
||||
ObjectGuid _kicker;
|
||||
ObjectGuid _kickee;
|
||||
}
|
||||
|
||||
struct BannedAppend : IChannelAppender
|
||||
{
|
||||
public ChatNotify GetNotificationType() => ChatNotify.BannedNotice;
|
||||
|
||||
public void Append(ChannelNotify data) { }
|
||||
}
|
||||
|
||||
struct PlayerBannedAppend : IChannelAppender
|
||||
{
|
||||
public PlayerBannedAppend(ObjectGuid moderator, ObjectGuid banned)
|
||||
{
|
||||
_moderator = moderator;
|
||||
_banned = banned;
|
||||
}
|
||||
|
||||
public ChatNotify GetNotificationType() => ChatNotify.PlayerBannedNotice;
|
||||
|
||||
public void Append(ChannelNotify data)
|
||||
{
|
||||
data.SenderGuid = _moderator;
|
||||
data.TargetGuid = _banned;
|
||||
}
|
||||
|
||||
ObjectGuid _moderator;
|
||||
ObjectGuid _banned;
|
||||
}
|
||||
|
||||
struct PlayerUnbannedAppend : IChannelAppender
|
||||
{
|
||||
public PlayerUnbannedAppend(ObjectGuid moderator, ObjectGuid unbanned)
|
||||
{
|
||||
_moderator = moderator;
|
||||
_unbanned = unbanned;
|
||||
}
|
||||
|
||||
public ChatNotify GetNotificationType() => ChatNotify.PlayerUnbannedNotice;
|
||||
|
||||
public void Append(ChannelNotify data)
|
||||
{
|
||||
data.SenderGuid = _moderator;
|
||||
data.TargetGuid = _unbanned;
|
||||
}
|
||||
|
||||
ObjectGuid _moderator;
|
||||
ObjectGuid _unbanned;
|
||||
}
|
||||
|
||||
struct PlayerNotBannedAppend : IChannelAppender
|
||||
{
|
||||
public PlayerNotBannedAppend(string playerName)
|
||||
{
|
||||
_playerName = playerName;
|
||||
}
|
||||
|
||||
public ChatNotify GetNotificationType() => ChatNotify.PlayerNotBannedNotice;
|
||||
|
||||
public void Append(ChannelNotify data)
|
||||
{
|
||||
data.Sender = _playerName;
|
||||
}
|
||||
|
||||
string _playerName;
|
||||
}
|
||||
|
||||
struct PlayerAlreadyMemberAppend : IChannelAppender
|
||||
{
|
||||
public PlayerAlreadyMemberAppend(ObjectGuid guid)
|
||||
{
|
||||
_guid = guid;
|
||||
}
|
||||
|
||||
public ChatNotify GetNotificationType() => ChatNotify.PlayerAlreadyMemberNotice;
|
||||
|
||||
public void Append(ChannelNotify data)
|
||||
{
|
||||
data.SenderGuid = _guid;
|
||||
}
|
||||
|
||||
ObjectGuid _guid;
|
||||
}
|
||||
|
||||
struct InviteAppend : IChannelAppender
|
||||
{
|
||||
public InviteAppend(ObjectGuid guid)
|
||||
{
|
||||
_guid = guid;
|
||||
}
|
||||
|
||||
public ChatNotify GetNotificationType() => ChatNotify.InviteNotice;
|
||||
|
||||
public void Append(ChannelNotify data)
|
||||
{
|
||||
data.SenderGuid = _guid;
|
||||
}
|
||||
|
||||
ObjectGuid _guid;
|
||||
}
|
||||
|
||||
struct InviteWrongFactionAppend : IChannelAppender
|
||||
{
|
||||
public ChatNotify GetNotificationType() => ChatNotify.InviteWrongFactionNotice;
|
||||
|
||||
public void Append(ChannelNotify data) { }
|
||||
}
|
||||
|
||||
struct WrongFactionAppend : IChannelAppender
|
||||
{
|
||||
public ChatNotify GetNotificationType() => ChatNotify.WrongFactionNotice;
|
||||
|
||||
public void Append(ChannelNotify data) { }
|
||||
}
|
||||
|
||||
struct InvalidNameAppend : IChannelAppender
|
||||
{
|
||||
public ChatNotify GetNotificationType() => ChatNotify.InvalidNameNotice;
|
||||
|
||||
public void Append(ChannelNotify data) { }
|
||||
}
|
||||
|
||||
struct NotModeratedAppend : IChannelAppender
|
||||
{
|
||||
public ChatNotify GetNotificationType() => ChatNotify.NotModeratedNotice;
|
||||
|
||||
public void Append(ChannelNotify data) { }
|
||||
}
|
||||
|
||||
struct PlayerInvitedAppend : IChannelAppender
|
||||
{
|
||||
public PlayerInvitedAppend(string playerName)
|
||||
{
|
||||
_playerName = playerName;
|
||||
}
|
||||
|
||||
public ChatNotify GetNotificationType() => ChatNotify.PlayerInvitedNotice;
|
||||
|
||||
public void Append(ChannelNotify data)
|
||||
{
|
||||
data.Sender = _playerName;
|
||||
}
|
||||
|
||||
string _playerName;
|
||||
}
|
||||
|
||||
struct PlayerInviteBannedAppend : IChannelAppender
|
||||
{
|
||||
public PlayerInviteBannedAppend(string playerName)
|
||||
{
|
||||
_playerName = playerName;
|
||||
}
|
||||
|
||||
public ChatNotify GetNotificationType() => ChatNotify.PlayerInviteBannedNotice;
|
||||
|
||||
public void Append(ChannelNotify data)
|
||||
{
|
||||
data.Sender = _playerName;
|
||||
}
|
||||
|
||||
string _playerName;
|
||||
}
|
||||
|
||||
struct ThrottledAppend : IChannelAppender
|
||||
{
|
||||
public ChatNotify GetNotificationType() => ChatNotify.ThrottledNotice;
|
||||
|
||||
public void Append(ChannelNotify data) { }
|
||||
}
|
||||
|
||||
struct NotInAreaAppend : IChannelAppender
|
||||
{
|
||||
public ChatNotify GetNotificationType() => ChatNotify.NotInAreaNotice;
|
||||
|
||||
public void Append(ChannelNotify data) { }
|
||||
}
|
||||
|
||||
struct NotInLFGAppend : IChannelAppender
|
||||
{
|
||||
public ChatNotify GetNotificationType() => ChatNotify.NotInLfgNotice;
|
||||
|
||||
public void Append(ChannelNotify data) { }
|
||||
}
|
||||
|
||||
struct VoiceOnAppend : IChannelAppender
|
||||
{
|
||||
public VoiceOnAppend(ObjectGuid guid)
|
||||
{
|
||||
_guid = guid;
|
||||
}
|
||||
|
||||
public ChatNotify GetNotificationType() => ChatNotify.VoiceOnNotice;
|
||||
|
||||
public void Append(ChannelNotify data)
|
||||
{
|
||||
data.SenderGuid = _guid;
|
||||
}
|
||||
|
||||
ObjectGuid _guid;
|
||||
}
|
||||
|
||||
struct VoiceOffAppend : IChannelAppender
|
||||
{
|
||||
public VoiceOffAppend(ObjectGuid guid)
|
||||
{
|
||||
_guid = guid;
|
||||
}
|
||||
|
||||
public ChatNotify GetNotificationType() => ChatNotify.VoiceOffNotice;
|
||||
|
||||
public void Append(ChannelNotify data)
|
||||
{
|
||||
data.SenderGuid = _guid;
|
||||
}
|
||||
|
||||
ObjectGuid _guid;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,166 @@
|
||||
/*
|
||||
* Copyright (C) 2012-2017 CypherCore <http://github.com/CypherCore>
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using Framework.Constants;
|
||||
using Game.DataStorage;
|
||||
using Game.Entities;
|
||||
using Game.Network.Packets;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Game.Chat
|
||||
{
|
||||
public class ChannelManager
|
||||
{
|
||||
public ChannelManager(Team team)
|
||||
{
|
||||
_team = team;
|
||||
}
|
||||
|
||||
public static ChannelManager ForTeam(Team team)
|
||||
{
|
||||
if (WorldConfig.GetBoolValue(WorldCfg.AllowTwoSideInteractionChannel))
|
||||
return allianceChannelMgr; // cross-faction
|
||||
|
||||
if (team == Team.Alliance)
|
||||
return allianceChannelMgr;
|
||||
|
||||
if (team == Team.Horde)
|
||||
return hordeChannelMgr;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Channel GetChannelForPlayerByNamePart(string namePart, Player playerSearcher)
|
||||
{
|
||||
foreach (Channel channel in playerSearcher.GetJoinedChannels())
|
||||
{
|
||||
string chanName = channel.GetName(playerSearcher.GetSession().GetSessionDbcLocale());
|
||||
if (chanName.ToLower().Equals(namePart.ToLower()))
|
||||
return channel;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public Channel GetJoinChannel(uint channelId, string name, AreaTableRecord zoneEntry = null)
|
||||
{
|
||||
if (channelId != 0) // builtin
|
||||
{
|
||||
ChatChannelsRecord channelEntry = CliDB.ChatChannelsStorage.LookupByKey(channelId);
|
||||
uint zoneId = zoneEntry != null ? zoneEntry.Id : 0;
|
||||
if (channelEntry.Flags.HasAnyFlag(ChannelDBCFlags.Global | ChannelDBCFlags.CityOnly))
|
||||
zoneId = 0;
|
||||
|
||||
Tuple<uint, uint> key = Tuple.Create(channelId, zoneId);
|
||||
var channel = _channels.LookupByKey(key);
|
||||
if (channel != null)
|
||||
return channel;
|
||||
|
||||
Channel newChannel = new Channel(channelId, _team, zoneEntry);
|
||||
_channels[key] = newChannel;
|
||||
return newChannel;
|
||||
}
|
||||
else // custom
|
||||
{
|
||||
var channel = _customChannels.LookupByKey(name.ToLower());
|
||||
if (channel != null)
|
||||
return channel;
|
||||
|
||||
Channel newChannel = new Channel(name, _team);
|
||||
_customChannels[name.ToLower()] = newChannel;
|
||||
return newChannel;
|
||||
}
|
||||
}
|
||||
|
||||
public Channel GetChannel(uint channelId, string name, Player player, bool notify = true, AreaTableRecord zoneEntry = null)
|
||||
{
|
||||
Channel result = null;
|
||||
if (channelId != 0) // builtin
|
||||
{
|
||||
ChatChannelsRecord channelEntry = CliDB.ChatChannelsStorage.LookupByKey(channelId);
|
||||
uint zoneId = zoneEntry != null ? zoneEntry.Id : 0;
|
||||
if (channelEntry.Flags.HasAnyFlag(ChannelDBCFlags.Global | ChannelDBCFlags.CityOnly))
|
||||
zoneId = 0;
|
||||
|
||||
Tuple<uint, uint> key = Tuple.Create(channelId, zoneId);
|
||||
var channel = _channels.LookupByKey(key);
|
||||
if (channel != null)
|
||||
result = channel;
|
||||
}
|
||||
else // custom
|
||||
{
|
||||
var channel = _customChannels.LookupByKey(name.ToLower());
|
||||
if (channel != null)
|
||||
result = channel;
|
||||
}
|
||||
|
||||
if (result == null && notify)
|
||||
{
|
||||
string channelName = name;
|
||||
Channel.GetChannelName(ref channelName, channelId, player.GetSession().GetSessionDbcLocale(), zoneEntry);
|
||||
|
||||
SendNotOnChannelNotify(player, channelName);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public void LeftChannel(string name)
|
||||
{
|
||||
string channelName = name.ToLower();
|
||||
|
||||
var channel = _customChannels.LookupByKey(channelName);
|
||||
if (channel == null)
|
||||
return;
|
||||
|
||||
if (channel.GetNumPlayers() == 0)
|
||||
_customChannels.Remove(channelName);
|
||||
}
|
||||
|
||||
public void LeftChannel(uint channelId, AreaTableRecord zoneEntry)
|
||||
{
|
||||
ChatChannelsRecord channelEntry = CliDB.ChatChannelsStorage.LookupByKey(channelId);
|
||||
uint zoneId = zoneEntry != null ? zoneEntry.Id : 0;
|
||||
if (channelEntry.Flags.HasAnyFlag(ChannelDBCFlags.Global | ChannelDBCFlags.CityOnly))
|
||||
zoneId = 0;
|
||||
|
||||
Tuple<uint, uint> key = Tuple.Create(channelId, zoneId);
|
||||
var channel = _channels.LookupByKey(key);
|
||||
if (channel == null)
|
||||
return;
|
||||
|
||||
if (channel.GetNumPlayers() == 0)
|
||||
_channels.Remove(key);
|
||||
}
|
||||
|
||||
public static void SendNotOnChannelNotify(Player player, string name)
|
||||
{
|
||||
ChannelNotify notify = new ChannelNotify();
|
||||
notify.Type = ChatNotify.NotMemberNotice;
|
||||
notify.Channel = name;
|
||||
player.SendPacket(notify);
|
||||
}
|
||||
|
||||
Dictionary<string, Channel> _customChannels = new Dictionary<string, Channel>();
|
||||
Dictionary<Tuple<uint /*channelId*/, uint /*zoneId*/>, Channel> _channels = new Dictionary<Tuple<uint, uint>, Channel>();
|
||||
Team _team;
|
||||
|
||||
static ChannelManager allianceChannelMgr = new ChannelManager(Team.Alliance);
|
||||
static ChannelManager hordeChannelMgr = new ChannelManager(Team.Horde);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Copyright (C) 2012-2017 CypherCore <http://github.com/CypherCore>
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using Framework.Constants;
|
||||
using System;
|
||||
|
||||
namespace Game.Chat
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Method)]
|
||||
public class CommandAttribute : Attribute
|
||||
{
|
||||
public CommandAttribute(string command, RBACPermissions rbac, bool allowConsole = false)
|
||||
{
|
||||
Name = command.ToLower();
|
||||
Help = "";
|
||||
RBAC = rbac;
|
||||
AllowConsole = allowConsole;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Command's name.
|
||||
/// </summary>
|
||||
public string Name { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Help text for command.
|
||||
/// </summary>
|
||||
public string Help { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Allow Console?
|
||||
/// </summary>
|
||||
public bool AllowConsole { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Minimum user level required to invoke the command.
|
||||
/// </summary>
|
||||
public RBACPermissions RBAC { get; set; }
|
||||
}
|
||||
|
||||
[AttributeUsage(AttributeTargets.Class)]
|
||||
public class CommandGroupAttribute : CommandAttribute
|
||||
{
|
||||
public CommandGroupAttribute(string command, RBACPermissions rbac, bool allowConsole = false) : base(command, rbac, allowConsole) { }
|
||||
}
|
||||
|
||||
[AttributeUsage(AttributeTargets.Method)]
|
||||
public class CommandNonGroupAttribute : CommandAttribute
|
||||
{
|
||||
public CommandNonGroupAttribute(string command, RBACPermissions rbac, bool allowConsole = false) : base(command, rbac, allowConsole) { }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,877 @@
|
||||
/*
|
||||
* Copyright (C) 2012-2017 CypherCore <http://github.com/CypherCore>
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using Framework.Collections;
|
||||
using Framework.Constants;
|
||||
using Framework.IO;
|
||||
using Game.DataStorage;
|
||||
using Game.Entities;
|
||||
using Game.Groups;
|
||||
using Game.Maps;
|
||||
using Game.Network.Packets;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace Game.Chat
|
||||
{
|
||||
public class CommandHandler
|
||||
{
|
||||
public CommandHandler(WorldSession session = null)
|
||||
{
|
||||
_session = session;
|
||||
}
|
||||
|
||||
public bool ParseCommand(string fullCmd)
|
||||
{
|
||||
if (string.IsNullOrEmpty(fullCmd))
|
||||
return false;
|
||||
|
||||
string text = fullCmd;
|
||||
// chat case (.command or !command format)
|
||||
if (_session != null)
|
||||
{
|
||||
if (text[0] != '!' && text[0] != '.')
|
||||
return false;
|
||||
}
|
||||
|
||||
if (text.Length < 2)
|
||||
return false;
|
||||
|
||||
/// ignore messages staring from many dots.
|
||||
if ((text[0] == '.' && text[1] == '.') || (text[0] == '!' && text[1] == '!'))
|
||||
return false;
|
||||
|
||||
/// skip first . or ! (in console allowed use command with . and ! and without its)
|
||||
if (text[0] == '!' || text[0] == '.')
|
||||
text = text.Substring(1);
|
||||
|
||||
if (!ExecuteCommandInTable(CommandManager.GetCommands(), text, fullCmd))
|
||||
{
|
||||
if (_session != null && !_session.HasPermission(RBACPermissions.CommandsNotifyCommandNotFoundError))
|
||||
return false;
|
||||
|
||||
SendSysMessage(CypherStrings.NoCmd);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool ExecuteCommandInTable(List<ChatCommand> table, string text, string fullcmd)
|
||||
{
|
||||
string oldtext = text;
|
||||
StringArguments args = new StringArguments(text);
|
||||
string cmd = args.NextString();
|
||||
|
||||
foreach (var command in table)
|
||||
{
|
||||
if (!hasStringAbbr(command.Name, cmd))
|
||||
continue;
|
||||
|
||||
bool match = false;
|
||||
if (command.Name.Length > cmd.Length)
|
||||
{
|
||||
foreach (var command2 in table)
|
||||
{
|
||||
if (!hasStringAbbr(command2.Name, cmd))
|
||||
continue;
|
||||
|
||||
if (command2.Name.Equals(cmd))
|
||||
{
|
||||
match = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (match)
|
||||
continue;
|
||||
|
||||
if (!command.ChildCommands.Empty())
|
||||
{
|
||||
if (!ExecuteCommandInTable(command.ChildCommands, args.NextString(""), fullcmd))
|
||||
{
|
||||
string arg = args.NextString("");
|
||||
if (!arg.IsEmpty())
|
||||
SendSysMessage(CypherStrings.NoSubcmd);
|
||||
else
|
||||
SendSysMessage(CypherStrings.CmdSyntax);
|
||||
|
||||
ShowHelpForCommand(command.ChildCommands, arg);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// must be available and have handler
|
||||
if (command.Handler == null || !IsAvailable(command))
|
||||
continue;
|
||||
|
||||
_sentErrorMessage = false;
|
||||
if (command.Handler(new StringArguments(!command.Name.IsEmpty() ? args.NextString("") : oldtext), this))
|
||||
{
|
||||
if (GetSession() == null) // ignore console
|
||||
return true;
|
||||
|
||||
Player player = GetPlayer();
|
||||
if (!Global.AccountMgr.IsPlayerAccount(GetSession().GetSecurity()))
|
||||
{
|
||||
ObjectGuid guid = player.GetTarget();
|
||||
uint areaId = player.GetAreaId();
|
||||
string areaName = "Unknown";
|
||||
string zoneName = "Unknown";
|
||||
|
||||
AreaTableRecord area = CliDB.AreaTableStorage.LookupByKey(areaId);
|
||||
if (area != null)
|
||||
{
|
||||
var locale = GetSessionDbcLocale();
|
||||
areaName = area.AreaName[locale];
|
||||
AreaTableRecord zone = CliDB.AreaTableStorage.LookupByKey(area.ParentAreaID);
|
||||
if (zone != null)
|
||||
zoneName = zone.AreaName[locale];
|
||||
}
|
||||
|
||||
Log.outCommand(GetSession().GetAccountId(), "Command: {0} [Player: {1} ({2}) (Account: {3}) Postion: {4} Map: {5} ({6}) Area: {7} ({8}) Zone: {9} Selected: {10} ({11})]",
|
||||
fullcmd, player.GetName(), player.GetGUID().ToString(), GetSession().GetAccountId(), player.GetPosition(), player.GetMapId(),
|
||||
player.GetMap() ? player.GetMap().GetMapName() : "Unknown", areaId, areaName, zoneName, (player.GetSelectedUnit()) ? player.GetSelectedUnit().GetName() : "", guid.ToString());
|
||||
}
|
||||
}
|
||||
else if (!HasSentErrorMessage())
|
||||
{
|
||||
if (!command.Help.IsEmpty())
|
||||
SendSysMessage(command.Help);
|
||||
else
|
||||
SendSysMessage(CypherStrings.CmdSyntax);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool ShowHelpForCommand(List<ChatCommand> table, string text)
|
||||
{
|
||||
StringArguments args = new StringArguments(text);
|
||||
if (!args.Empty())
|
||||
{
|
||||
string cmd = args.NextString();
|
||||
foreach (var command in table)
|
||||
{
|
||||
// must be available (ignore handler existence for show command with possible available subcommands)
|
||||
if (!IsAvailable(command))
|
||||
continue;
|
||||
|
||||
if (!hasStringAbbr(command.Name, cmd))
|
||||
continue;
|
||||
|
||||
// have subcommand
|
||||
string subcmd = !cmd.IsEmpty() ? args.NextString() : "";
|
||||
if (!command.ChildCommands.Empty() && !subcmd.IsEmpty())
|
||||
{
|
||||
if (ShowHelpForCommand(command.ChildCommands, subcmd))
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!command.Help.IsEmpty())
|
||||
SendSysMessage(command.Help);
|
||||
|
||||
if (!command.ChildCommands.Empty())
|
||||
if (ShowHelpForSubCommands(command.ChildCommands, command.Name, subcmd))
|
||||
return true;
|
||||
|
||||
return !command.Help.IsEmpty();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (var command in table)
|
||||
{
|
||||
// must be available (ignore handler existence for show command with possible available subcommands)
|
||||
if (!IsAvailable(command))
|
||||
continue;
|
||||
|
||||
if (!command.Name.IsEmpty())
|
||||
continue;
|
||||
|
||||
if (!command.Help.IsEmpty())
|
||||
SendSysMessage(command.Help);
|
||||
|
||||
if (!command.ChildCommands.Empty())
|
||||
if (ShowHelpForSubCommands(command.ChildCommands, "", ""))
|
||||
return true;
|
||||
|
||||
return !command.Help.IsEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
return ShowHelpForSubCommands(table, "", text);
|
||||
}
|
||||
|
||||
public bool ShowHelpForSubCommands(List<ChatCommand> table, string cmd, string subcmd)
|
||||
{
|
||||
string list = "";
|
||||
foreach (var command in table)
|
||||
{
|
||||
// must be available (ignore handler existence for show command with possible available subcommands)
|
||||
if (!IsAvailable(command))
|
||||
continue;
|
||||
|
||||
// for empty subcmd show all available
|
||||
if (!subcmd.IsEmpty() && !hasStringAbbr(command.Name, subcmd))
|
||||
continue;
|
||||
|
||||
if (GetSession() != null)
|
||||
list += "\n ";
|
||||
else
|
||||
list += "\n\r ";
|
||||
|
||||
list += command.Name;
|
||||
|
||||
if (!command.ChildCommands.Empty())
|
||||
list += " ...";
|
||||
}
|
||||
|
||||
if (list.IsEmpty())
|
||||
return false;
|
||||
|
||||
if (table == CommandManager.GetCommands())
|
||||
{
|
||||
SendSysMessage(CypherStrings.AvailableCmd);
|
||||
SendSysMessage(list);
|
||||
}
|
||||
else
|
||||
SendSysMessage(CypherStrings.SubcmdsList, cmd, list);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public virtual bool IsAvailable(ChatCommand cmd)
|
||||
{
|
||||
return HasPermission(cmd.Permission);
|
||||
}
|
||||
|
||||
public virtual bool HasPermission(RBACPermissions permission) { return _session.HasPermission(permission); }
|
||||
|
||||
public string extractKeyFromLink(StringArguments args, params string[] linkType)
|
||||
{
|
||||
int throwaway;
|
||||
return extractKeyFromLink(args, linkType, out throwaway);
|
||||
}
|
||||
public string extractKeyFromLink(StringArguments args, string[] linkType, out int found_idx)
|
||||
{
|
||||
string throwaway;
|
||||
return extractKeyFromLink(args, linkType, out found_idx, out throwaway);
|
||||
}
|
||||
public string extractKeyFromLink(StringArguments args, string[] linkType, out int found_idx, out string something1)
|
||||
{
|
||||
found_idx = 0;
|
||||
something1 = null;
|
||||
|
||||
// skip empty
|
||||
if (args.Empty())
|
||||
return null;
|
||||
|
||||
// return non link case
|
||||
if (args[0] != '|')
|
||||
return args.NextString();
|
||||
|
||||
if (args[1] == 'c')
|
||||
{
|
||||
string check = args.NextString("|");
|
||||
if (string.IsNullOrEmpty(check))
|
||||
return null;
|
||||
}
|
||||
else
|
||||
args.NextChar();
|
||||
|
||||
string cLinkType = args.NextString(":");
|
||||
if (string.IsNullOrEmpty(cLinkType))
|
||||
return null;
|
||||
|
||||
for (var i = 0; i < linkType.Length; ++i)
|
||||
{
|
||||
if (cLinkType == linkType[i])
|
||||
{
|
||||
string cKey = args.NextString(":|"); // extract key
|
||||
|
||||
something1 = args.NextString(":|"); // extract something
|
||||
|
||||
args.NextString("]"); // restart scan tail and skip name with possible spaces
|
||||
args.NextString(); // skip link tail (to allow continue strtok(NULL, s) use after return from function
|
||||
found_idx = i;
|
||||
return cKey;
|
||||
}
|
||||
}
|
||||
|
||||
args.NextString();
|
||||
SendSysMessage(CypherStrings.WrongLinkType);
|
||||
return null;
|
||||
}
|
||||
|
||||
public void extractOptFirstArg(StringArguments args, out string arg1, out string arg2)
|
||||
{
|
||||
string p1 = args.NextString();
|
||||
string p2 = args.NextString();
|
||||
|
||||
if (string.IsNullOrEmpty(p2))
|
||||
{
|
||||
p2 = p1;
|
||||
p1 = null;
|
||||
}
|
||||
|
||||
arg1 = p1;
|
||||
arg2 = p2;
|
||||
}
|
||||
|
||||
public GameTele extractGameTeleFromLink(StringArguments args)
|
||||
{
|
||||
string cId = extractKeyFromLink(args, "Htele");
|
||||
if (string.IsNullOrEmpty(cId))
|
||||
return null;
|
||||
|
||||
uint id;
|
||||
if (!uint.TryParse(cId, out id))
|
||||
return null;
|
||||
|
||||
return Global.ObjectMgr.GetGameTele(id);
|
||||
}
|
||||
|
||||
public string extractQuotedArg(string str)
|
||||
{
|
||||
if (string.IsNullOrEmpty(str))
|
||||
return null;
|
||||
|
||||
if (!str.Contains("\""))
|
||||
return null;
|
||||
|
||||
return str.Replace("\"", String.Empty);
|
||||
}
|
||||
string extractPlayerNameFromLink(StringArguments args)
|
||||
{
|
||||
// |color|Hplayer:name|h[name]|h|r
|
||||
string name = extractKeyFromLink(args, "Hplayer");
|
||||
if (name.IsEmpty())
|
||||
return "";
|
||||
|
||||
if (!ObjectManager.NormalizePlayerName(ref name))
|
||||
return "";
|
||||
|
||||
return name;
|
||||
}
|
||||
public bool extractPlayerTarget(StringArguments args, out Player player)
|
||||
{
|
||||
ObjectGuid guid;
|
||||
string name;
|
||||
return extractPlayerTarget(args, out player, out guid, out name);
|
||||
}
|
||||
public bool extractPlayerTarget(StringArguments args, out Player player, out ObjectGuid playerGuid)
|
||||
{
|
||||
string name;
|
||||
return extractPlayerTarget(args, out player, out playerGuid, out name);
|
||||
}
|
||||
|
||||
public bool extractPlayerTarget(StringArguments args, out Player player, out ObjectGuid playerGuid, out string playerName)
|
||||
{
|
||||
player = null;
|
||||
playerGuid = ObjectGuid.Empty;
|
||||
playerName = "";
|
||||
|
||||
if (!args.Empty())
|
||||
{
|
||||
string name = extractPlayerNameFromLink(args);
|
||||
if (string.IsNullOrEmpty(name))
|
||||
{
|
||||
SendSysMessage(CypherStrings.PlayerNotFound);
|
||||
_sentErrorMessage = true;
|
||||
return false;
|
||||
}
|
||||
|
||||
player = Global.ObjAccessor.FindPlayerByName(name);
|
||||
ObjectGuid guid = player == null ? ObjectManager.GetPlayerGUIDByName(name) : ObjectGuid.Empty;
|
||||
|
||||
playerGuid = player != null ? player.GetGUID() : guid;
|
||||
playerName = player != null || !guid.IsEmpty() ? name : "";
|
||||
}
|
||||
else
|
||||
{
|
||||
player = getSelectedPlayer();
|
||||
playerGuid = player != null ? player.GetGUID() : ObjectGuid.Empty;
|
||||
playerName = player != null ? player.GetName() : "";
|
||||
}
|
||||
|
||||
if (player == null && playerGuid.IsEmpty() && string.IsNullOrEmpty(playerName))
|
||||
{
|
||||
SendSysMessage(CypherStrings.PlayerNotFound);
|
||||
_sentErrorMessage = true;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
public ulong extractLowGuidFromLink(StringArguments args, ref HighGuid guidHigh)
|
||||
{
|
||||
int type;
|
||||
|
||||
string[] guidKeys =
|
||||
{
|
||||
"Hplayer",
|
||||
"Hcreature",
|
||||
"Hgameobject"
|
||||
};
|
||||
// |color|Hcreature:creature_guid|h[name]|h|r
|
||||
// |color|Hgameobject:go_guid|h[name]|h|r
|
||||
// |color|Hplayer:name|h[name]|h|r
|
||||
string idS = extractKeyFromLink(args, guidKeys, out type);
|
||||
if (string.IsNullOrEmpty(idS))
|
||||
return 0;
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
guidHigh = HighGuid.Player;
|
||||
if (!ObjectManager.NormalizePlayerName(ref idS))
|
||||
return 0;
|
||||
|
||||
Player player = Global.ObjAccessor.FindPlayerByName(idS);
|
||||
if (player)
|
||||
return player.GetGUID().GetCounter();
|
||||
|
||||
ObjectGuid guid = ObjectManager.GetPlayerGUIDByName(idS);
|
||||
if (guid.IsEmpty())
|
||||
return 0;
|
||||
|
||||
return guid.GetCounter();
|
||||
}
|
||||
case 1:
|
||||
{
|
||||
guidHigh = HighGuid.Creature;
|
||||
ulong lowguid = ulong.Parse(idS);
|
||||
return lowguid;
|
||||
}
|
||||
case 2:
|
||||
{
|
||||
guidHigh = HighGuid.GameObject;
|
||||
ulong lowguid = ulong.Parse(idS);
|
||||
return lowguid;
|
||||
}
|
||||
}
|
||||
|
||||
// unknown type?
|
||||
return 0;
|
||||
}
|
||||
|
||||
static string[] spellKeys =
|
||||
{
|
||||
"Hspell", // normal spell
|
||||
"Htalent", // talent spell
|
||||
"Henchant", // enchanting recipe spell
|
||||
"Htrade", // profession/skill spell
|
||||
"Hglyph", // glyph
|
||||
};
|
||||
public uint extractSpellIdFromLink(StringArguments args)
|
||||
{
|
||||
// number or [name] Shift-click form |color|Henchant:recipe_spell_id|h[prof_name: recipe_name]|h|r
|
||||
// number or [name] Shift-click form |color|Hglyph:glyph_slot_id:glyph_prop_id|h[value]|h|r
|
||||
// number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r
|
||||
// number or [name] Shift-click form |color|Htalent:talent_id, rank|h[name]|h|r
|
||||
// number or [name] Shift-click form |color|Htrade:spell_id, skill_id, max_value, cur_value|h[name]|h|r
|
||||
int type = 0;
|
||||
string param1_str = null;
|
||||
string idS = extractKeyFromLink(args, spellKeys, out type, out param1_str);
|
||||
if (string.IsNullOrEmpty(idS))
|
||||
return 0;
|
||||
|
||||
uint id = uint.Parse(idS);
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case 0:
|
||||
return id;
|
||||
case 1:
|
||||
{
|
||||
// talent
|
||||
TalentRecord talentEntry = CliDB.TalentStorage.LookupByKey(id);
|
||||
if (talentEntry == null)
|
||||
return 0;
|
||||
|
||||
return talentEntry.SpellID;
|
||||
}
|
||||
case 2:
|
||||
case 3:
|
||||
return id;
|
||||
case 4:
|
||||
{
|
||||
uint glyph_prop_id = !string.IsNullOrEmpty(param1_str) ? uint.Parse(param1_str) : 0;
|
||||
|
||||
GlyphPropertiesRecord glyphPropEntry = CliDB.GlyphPropertiesStorage.LookupByKey(glyph_prop_id);
|
||||
if (glyphPropEntry == null)
|
||||
return 0;
|
||||
|
||||
return glyphPropEntry.SpellID;
|
||||
}
|
||||
}
|
||||
|
||||
// unknown type?
|
||||
return 0;
|
||||
}
|
||||
|
||||
public Player getSelectedPlayer()
|
||||
{
|
||||
if (_session == null)
|
||||
return null;
|
||||
|
||||
ObjectGuid selected = _session.GetPlayer().GetTarget();
|
||||
|
||||
if (selected.IsEmpty())
|
||||
return _session.GetPlayer();
|
||||
|
||||
return Global.ObjAccessor.FindPlayer(selected);
|
||||
}
|
||||
public Unit getSelectedUnit()
|
||||
{
|
||||
if (_session == null)
|
||||
return null;
|
||||
|
||||
ObjectGuid selected = _session.GetPlayer().GetTarget();
|
||||
|
||||
if (selected.IsEmpty())
|
||||
return _session.GetPlayer();
|
||||
|
||||
return Global.ObjAccessor.GetUnit(_session.GetPlayer(), selected);
|
||||
}
|
||||
public WorldObject GetSelectedObject()
|
||||
{
|
||||
if (_session == null)
|
||||
return null;
|
||||
|
||||
ObjectGuid selected = _session.GetPlayer().GetTarget();
|
||||
|
||||
if (selected.IsEmpty())
|
||||
return GetNearbyGameObject();
|
||||
|
||||
return Global.ObjAccessor.GetUnit(_session.GetPlayer(), selected);
|
||||
}
|
||||
public Creature getSelectedCreature()
|
||||
{
|
||||
if (_session == null)
|
||||
return null;
|
||||
|
||||
return ObjectAccessor.GetCreatureOrPetOrVehicle(_session.GetPlayer(), _session.GetPlayer().GetTarget());
|
||||
}
|
||||
public Player getSelectedPlayerOrSelf()
|
||||
{
|
||||
if (_session == null)
|
||||
return null;
|
||||
|
||||
ObjectGuid selected = _session.GetPlayer().GetTarget();
|
||||
if (selected.IsEmpty())
|
||||
return _session.GetPlayer();
|
||||
|
||||
// first try with selected target
|
||||
Player targetPlayer = Global.ObjAccessor.FindConnectedPlayer(selected);
|
||||
// if the target is not a player, then return self
|
||||
if (!targetPlayer)
|
||||
targetPlayer = _session.GetPlayer();
|
||||
|
||||
return targetPlayer;
|
||||
}
|
||||
|
||||
public GameObject GetObjectFromPlayerMapByDbGuid(ulong lowguid)
|
||||
{
|
||||
if (_session == null)
|
||||
return null;
|
||||
|
||||
var bounds = _session.GetPlayer().GetMap().GetGameObjectBySpawnIdStore().LookupByKey(lowguid);
|
||||
if (!bounds.Empty())
|
||||
return bounds.First();
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public Creature GetCreatureFromPlayerMapByDbGuid(ulong lowguid)
|
||||
{
|
||||
if (!_session)
|
||||
return null;
|
||||
|
||||
// Select the first alive creature or a dead one if not found
|
||||
Creature creature = null;
|
||||
var bounds = _session.GetPlayer().GetMap().GetCreatureBySpawnIdStore().LookupByKey(lowguid);
|
||||
foreach (var it in bounds)
|
||||
{
|
||||
creature = it;
|
||||
if (it.IsAlive())
|
||||
break;
|
||||
}
|
||||
|
||||
return creature;
|
||||
}
|
||||
GameObject GetNearbyGameObject()
|
||||
{
|
||||
if (_session == null)
|
||||
return null;
|
||||
|
||||
Player pl = _session.GetPlayer();
|
||||
NearestGameObjectCheck check = new NearestGameObjectCheck(pl);
|
||||
GameObjectLastSearcher searcher = new GameObjectLastSearcher(pl, check);
|
||||
Cell.VisitGridObjects(pl, searcher, MapConst.SizeofGrids);
|
||||
return searcher.GetTarget();
|
||||
}
|
||||
|
||||
public string playerLink(string name, bool console = false)
|
||||
{
|
||||
return console ? name : "|cffffffff|Hplayer:" + name + "|h[" + name + "]|h|r";
|
||||
}
|
||||
public virtual string GetNameLink()
|
||||
{
|
||||
return GetNameLink(_session.GetPlayer());
|
||||
}
|
||||
public string GetNameLink(Player obj)
|
||||
{
|
||||
return playerLink(obj.GetName());
|
||||
}
|
||||
public virtual bool needReportToTarget(Player chr)
|
||||
{
|
||||
Player pl = _session.GetPlayer();
|
||||
return pl != chr && pl.IsVisibleGloballyFor(chr);
|
||||
}
|
||||
public bool HasLowerSecurity(Player target, ObjectGuid guid, bool strong = false)
|
||||
{
|
||||
WorldSession target_session = null;
|
||||
uint target_account = 0;
|
||||
|
||||
if (target != null)
|
||||
target_session = target.GetSession();
|
||||
else if (!guid.IsEmpty())
|
||||
target_account = ObjectManager.GetPlayerAccountIdByGUID(guid);
|
||||
|
||||
if (target_session == null && target_account == 0)
|
||||
{
|
||||
SendSysMessage(CypherStrings.PlayerNotFound);
|
||||
_sentErrorMessage = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
return HasLowerSecurityAccount(target_session, target_account, strong);
|
||||
}
|
||||
public bool HasLowerSecurityAccount(WorldSession target, uint target_account, bool strong = false)
|
||||
{
|
||||
AccountTypes target_ac_sec;
|
||||
|
||||
// allow everything from console and RA console
|
||||
if (_session == null)
|
||||
return false;
|
||||
|
||||
// ignore only for non-players for non strong checks (when allow apply command at least to same sec level)
|
||||
if (!Global.AccountMgr.IsPlayerAccount(_session.GetSecurity()) && !strong && !WorldConfig.GetBoolValue(WorldCfg.GmLowerSecurity))
|
||||
return false;
|
||||
|
||||
if (target != null)
|
||||
target_ac_sec = target.GetSecurity();
|
||||
else if (target_account != 0)
|
||||
target_ac_sec = Global.AccountMgr.GetSecurity(target_account);
|
||||
else
|
||||
return true; // caller must report error for (target == NULL && target_account == 0)
|
||||
|
||||
if (_session.GetSecurity() < target_ac_sec || (strong && _session.GetSecurity() <= target_ac_sec))
|
||||
{
|
||||
SendSysMessage(CypherStrings.YoursSecurityIsLow);
|
||||
_sentErrorMessage = true;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool hasStringAbbr(string name, string part)
|
||||
{
|
||||
// non "" command
|
||||
if (!name.IsEmpty())
|
||||
{
|
||||
// "" part from non-"" command
|
||||
if (part.IsEmpty())
|
||||
return false;
|
||||
|
||||
int partIndex = 0;
|
||||
while (true)
|
||||
{
|
||||
if (partIndex >= part.Length)
|
||||
return true;
|
||||
else if (partIndex >= name.Length)
|
||||
return false;
|
||||
else if (char.ToLower(name[partIndex]) != char.ToLower(part[partIndex]))
|
||||
return false;
|
||||
++partIndex;
|
||||
}
|
||||
}
|
||||
// allow with any for ""
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public WorldSession GetSession()
|
||||
{
|
||||
return _session;
|
||||
}
|
||||
public Player GetPlayer()
|
||||
{
|
||||
return _session.GetPlayer();
|
||||
}
|
||||
public string GetCypherString(CypherStrings str)
|
||||
{
|
||||
return Global.ObjectMgr.GetCypherString(str);
|
||||
}
|
||||
|
||||
public virtual LocaleConstant GetSessionDbcLocale()
|
||||
{
|
||||
return _session.GetSessionDbcLocale();
|
||||
}
|
||||
public virtual byte GetSessionDbLocaleIndex()
|
||||
{
|
||||
return (byte)_session.GetSessionDbLocaleIndex();
|
||||
}
|
||||
public string GetParsedString(CypherStrings cypherString, params object[] args)
|
||||
{
|
||||
return string.Format(Global.ObjectMgr.GetCypherString(cypherString), args);
|
||||
}
|
||||
|
||||
public void SendSysMessage(CypherStrings cypherString, params object[] args)
|
||||
{
|
||||
SendSysMessage(Global.ObjectMgr.GetCypherString(cypherString), args);
|
||||
}
|
||||
public virtual void SendSysMessage(string str, params object[] args)
|
||||
{
|
||||
_sentErrorMessage = true;
|
||||
string msg = string.Format(str, args);
|
||||
|
||||
ChatPkt messageChat = new ChatPkt();
|
||||
|
||||
var lines = new StringArray(msg, "\n", "\r");
|
||||
for (var i = 0; i < lines.Length; ++i)
|
||||
{
|
||||
messageChat.Initialize(ChatMsg.System, Language.Universal, null, null, lines[i]);
|
||||
_session.SendPacket(messageChat);
|
||||
}
|
||||
}
|
||||
|
||||
public void SendNotification(CypherStrings str, params object[] args)
|
||||
{
|
||||
_session.SendNotification(str, args);
|
||||
}
|
||||
|
||||
public void SendGlobalSysMessage(string str)
|
||||
{
|
||||
// Chat output
|
||||
ChatPkt data = new ChatPkt();
|
||||
data.Initialize(ChatMsg.System, Language.Universal, null, null, str);
|
||||
Global.WorldMgr.SendGlobalMessage(data);
|
||||
}
|
||||
|
||||
public void SendGlobalGMSysMessage(string str)
|
||||
{
|
||||
// Chat output
|
||||
ChatPkt data = new ChatPkt();
|
||||
data.Initialize(ChatMsg.System, Language.Universal, null, null, str);
|
||||
Global.WorldMgr.SendGlobalGMMessage(data);
|
||||
}
|
||||
|
||||
public bool GetPlayerGroupAndGUIDByName(string name, out Player player, out Group group, out ObjectGuid guid, bool offline = false)
|
||||
{
|
||||
player = null;
|
||||
guid = ObjectGuid.Empty;
|
||||
group = null;
|
||||
|
||||
if (!name.IsEmpty())
|
||||
{
|
||||
if (!ObjectManager.NormalizePlayerName(ref name))
|
||||
{
|
||||
SendSysMessage(CypherStrings.PlayerNotFound);
|
||||
return false;
|
||||
}
|
||||
|
||||
player = Global.ObjAccessor.FindPlayerByName(name);
|
||||
if (offline)
|
||||
guid = ObjectManager.GetPlayerGUIDByName(name);
|
||||
}
|
||||
|
||||
if (player)
|
||||
{
|
||||
group = player.GetGroup();
|
||||
if (guid.IsEmpty() || !offline)
|
||||
guid = player.GetGUID();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (getSelectedPlayer())
|
||||
player = getSelectedPlayer();
|
||||
else
|
||||
player = _session.GetPlayer();
|
||||
|
||||
if (guid.IsEmpty() || !offline)
|
||||
guid = player.GetGUID();
|
||||
group = player.GetGroup();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool HasSentErrorMessage() { return _sentErrorMessage; }
|
||||
|
||||
internal bool _sentErrorMessage;
|
||||
WorldSession _session;
|
||||
}
|
||||
|
||||
public class ConsoleHandler : CommandHandler
|
||||
{
|
||||
public override bool IsAvailable(ChatCommand cmd)
|
||||
{
|
||||
return cmd.AllowConsole;
|
||||
}
|
||||
|
||||
public override bool HasPermission(RBACPermissions permission)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public override void SendSysMessage(string str, params object[] args)
|
||||
{
|
||||
_sentErrorMessage = true;
|
||||
string msg = string.Format(str, args);
|
||||
|
||||
Log.outInfo(LogFilter.Server, msg);
|
||||
}
|
||||
|
||||
public override string GetNameLink()
|
||||
{
|
||||
return GetCypherString(CypherStrings.ConsoleCommand);
|
||||
}
|
||||
|
||||
public override bool needReportToTarget(Player chr)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public override LocaleConstant GetSessionDbcLocale()
|
||||
{
|
||||
return Global.WorldMgr.GetDefaultDbcLocale();
|
||||
}
|
||||
|
||||
public override byte GetSessionDbLocaleIndex()
|
||||
{
|
||||
return (byte)Global.WorldMgr.GetDefaultDbcLocale();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,197 @@
|
||||
/*
|
||||
* Copyright (C) 2012-2017 CypherCore <http://github.com/CypherCore>
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using Framework.Configuration;
|
||||
using Framework.Constants;
|
||||
using Framework.Database;
|
||||
using Framework.IO;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
|
||||
namespace Game.Chat
|
||||
{
|
||||
public class CommandManager
|
||||
{
|
||||
static CommandManager()
|
||||
{
|
||||
try
|
||||
{
|
||||
foreach (var type in Assembly.GetExecutingAssembly().GetTypes())
|
||||
{
|
||||
if (type.Attributes.HasAnyFlag(TypeAttributes.NestedPrivate))
|
||||
continue;
|
||||
|
||||
var groupAttribute = type.GetCustomAttribute<CommandGroupAttribute>(true);
|
||||
if (groupAttribute != null)
|
||||
{
|
||||
_commands.Add(groupAttribute.Name, new ChatCommand(type, groupAttribute));
|
||||
}
|
||||
|
||||
foreach (var method in type.GetMethods(BindingFlags.Static | BindingFlags.NonPublic))
|
||||
{
|
||||
var commandAttribute = method.GetCustomAttribute<CommandNonGroupAttribute>(true);
|
||||
if (commandAttribute != null)
|
||||
_commands.Add(commandAttribute.Name, new ChatCommand(commandAttribute, (HandleCommandDelegate)method.CreateDelegate(typeof(HandleCommandDelegate))));
|
||||
}
|
||||
}
|
||||
|
||||
PreparedStatement stmt = DB.World.GetPreparedStatement(WorldStatements.SEL_COMMANDS);
|
||||
SQLResult result = DB.World.Query(stmt);
|
||||
if (!result.IsEmpty())
|
||||
{
|
||||
do
|
||||
{
|
||||
string name = result.Read<string>(0);
|
||||
SetDataForCommandInTable(GetCommands(), name, result.Read<uint>(1), result.Read<string>(2), name);
|
||||
}
|
||||
while (result.NextRow());
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.outException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
static bool SetDataForCommandInTable(List<ChatCommand> table, string text, uint permission, string help, string fullcommand)
|
||||
{
|
||||
StringArguments args = new StringArguments(text);
|
||||
string cmd = args.NextString().ToLower();
|
||||
|
||||
foreach (var command in table)
|
||||
{
|
||||
// for data fill use full explicit command names
|
||||
if (command.Name != cmd)
|
||||
continue;
|
||||
|
||||
// select subcommand from child commands list (including "")
|
||||
if (!command.ChildCommands.Empty())
|
||||
{
|
||||
var arg = args.NextString("");
|
||||
if (SetDataForCommandInTable(command.ChildCommands, arg, permission, help, fullcommand))
|
||||
return true;
|
||||
else if (!arg.IsEmpty())
|
||||
return false;
|
||||
|
||||
// fail with "" subcommands, then use normal level up command instead
|
||||
}
|
||||
// expected subcommand by full name DB content
|
||||
else if (!args.NextString().IsEmpty())
|
||||
{
|
||||
Log.outError(LogFilter.Sql, "Table `command` have unexpected subcommand '{0}' in command '{1}', skip.", text, fullcommand);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (command.Permission != (RBACPermissions)permission)
|
||||
Log.outInfo(LogFilter.Misc, "Table `command` overwrite for command '{0}' default permission ({1}) by {2}", fullcommand, command.Permission, permission);
|
||||
|
||||
command.Permission = (RBACPermissions)permission;
|
||||
command.Help = help;
|
||||
return true;
|
||||
}
|
||||
|
||||
// in case "" command let process by caller
|
||||
if (!cmd.IsEmpty())
|
||||
{
|
||||
if (table == GetCommands())
|
||||
Log.outError(LogFilter.Sql, "Table `command` have not existed command '{0}', skip.", cmd);
|
||||
else
|
||||
Log.outError(LogFilter.Sql, "Table `command` have not existed subcommand '{0}' in command '{1}', skip.", cmd, fullcommand);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void InitConsole()
|
||||
{
|
||||
if (ConfigMgr.GetDefaultValue("BeepAtStart", true))
|
||||
Console.Beep();
|
||||
|
||||
Console.ForegroundColor = ConsoleColor.Green;
|
||||
Console.Write("Cypher>> ");
|
||||
|
||||
var handler = new ConsoleHandler();
|
||||
while (!Global.WorldMgr.IsStopped)
|
||||
{
|
||||
handler.ParseCommand(Console.ReadLine());
|
||||
Console.ForegroundColor = ConsoleColor.Green;
|
||||
Console.Write("Cypher>> ");
|
||||
}
|
||||
}
|
||||
|
||||
public static List<ChatCommand> GetCommands()
|
||||
{
|
||||
return _commands.Values.ToList();
|
||||
}
|
||||
|
||||
static SortedDictionary<string, ChatCommand> _commands = new SortedDictionary<string, ChatCommand>();
|
||||
}
|
||||
|
||||
public delegate bool HandleCommandDelegate(StringArguments args, CommandHandler handler);
|
||||
|
||||
public class ChatCommand
|
||||
{
|
||||
public ChatCommand(CommandAttribute attribute, HandleCommandDelegate handler)
|
||||
{
|
||||
Name = attribute.Name;
|
||||
Permission = attribute.RBAC;
|
||||
AllowConsole = attribute.AllowConsole;
|
||||
Handler = handler;
|
||||
Help = attribute.Help;
|
||||
}
|
||||
|
||||
public ChatCommand(Type type, CommandAttribute attribute)
|
||||
{
|
||||
Name = attribute.Name;
|
||||
Permission = attribute.RBAC;
|
||||
AllowConsole = attribute.AllowConsole;
|
||||
Help = attribute.Help;
|
||||
|
||||
foreach (var method in type.GetMethods(BindingFlags.Static | BindingFlags.NonPublic))
|
||||
{
|
||||
CommandAttribute commandAttribute = method.GetCustomAttribute<CommandAttribute>(false);
|
||||
if (commandAttribute == null)
|
||||
continue;
|
||||
|
||||
if (commandAttribute.GetType() == typeof(CommandNonGroupAttribute))
|
||||
continue;
|
||||
|
||||
ChildCommands.Add(new ChatCommand(commandAttribute, (HandleCommandDelegate)method.CreateDelegate(typeof(HandleCommandDelegate))));
|
||||
}
|
||||
|
||||
foreach (var nestedType in type.GetNestedTypes(BindingFlags.NonPublic))
|
||||
{
|
||||
var groupAttribute = nestedType.GetCustomAttribute<CommandGroupAttribute>(true);
|
||||
if (groupAttribute == null)
|
||||
continue;
|
||||
|
||||
ChildCommands.Add(new ChatCommand(nestedType, groupAttribute));
|
||||
}
|
||||
|
||||
ChildCommands = ChildCommands.OrderBy(p => string.IsNullOrEmpty(p.Name)).ThenBy(p => p.Name).ToList();
|
||||
}
|
||||
|
||||
public string Name;
|
||||
public RBACPermissions Permission;
|
||||
public bool AllowConsole;
|
||||
public HandleCommandDelegate Handler;
|
||||
public string Help;
|
||||
public List<ChatCommand> ChildCommands = new List<ChatCommand>();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,815 @@
|
||||
/*
|
||||
* Copyright (C) 2012-2017 CypherCore <http://github.com/CypherCore>
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using Framework.Constants;
|
||||
using Framework.Database;
|
||||
using Framework.IO;
|
||||
using Game.Accounts;
|
||||
using Game.Entities;
|
||||
using System;
|
||||
|
||||
namespace Game.Chat
|
||||
{
|
||||
[CommandGroup("account", RBACPermissions.CommandAccount, true)]
|
||||
class AccountCommands
|
||||
{
|
||||
[Command("", RBACPermissions.CommandAccount)]
|
||||
static bool HandleAccountCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
if (handler.GetSession() == null)
|
||||
return false;
|
||||
|
||||
// GM Level
|
||||
AccountTypes gmLevel = handler.GetSession().GetSecurity();
|
||||
handler.SendSysMessage(CypherStrings.AccountLevel, gmLevel);
|
||||
|
||||
// Security level required
|
||||
WorldSession session = handler.GetSession();
|
||||
bool hasRBAC = (session.HasPermission(RBACPermissions.EmailConfirmForPassChange) ? true : false);
|
||||
uint pwConfig = 0; // 0 - PW_NONE, 1 - PW_EMAIL, 2 - PW_RBAC
|
||||
|
||||
handler.SendSysMessage(CypherStrings.AccountSecType, (pwConfig == 0 ? "Lowest level: No Email input required." :
|
||||
pwConfig == 1 ? "Highest level: Email input required." : pwConfig == 2 ? "Special level: Your account may require email input depending on settings. That is the case if another lien is printed." :
|
||||
"Unknown security level: Notify technician for details."));
|
||||
|
||||
// RBAC required display - is not displayed for console
|
||||
if (pwConfig == 2 && session != null && hasRBAC)
|
||||
handler.SendSysMessage(CypherStrings.RbacEmailRequired);
|
||||
|
||||
// Email display if sufficient rights
|
||||
if (session.HasPermission(RBACPermissions.MayCheckOwnEmail))
|
||||
{
|
||||
string emailoutput;
|
||||
uint accountId = session.GetAccountId();
|
||||
|
||||
PreparedStatement stmt = DB.Login.GetPreparedStatement(LoginStatements.GET_EMAIL_BY_ID);
|
||||
stmt.AddValue(0, accountId);
|
||||
SQLResult result = DB.Login.Query(stmt);
|
||||
|
||||
if (!result.IsEmpty())
|
||||
{
|
||||
emailoutput = result.Read<string>(0);
|
||||
handler.SendSysMessage(CypherStrings.CommandEmailOutput, emailoutput);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("addon", RBACPermissions.CommandAccountAddon)]
|
||||
static bool HandleAccountAddonCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
if (args.Empty())
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.CmdSyntax);
|
||||
return false;
|
||||
}
|
||||
|
||||
uint accountId = handler.GetSession().GetAccountId();
|
||||
|
||||
int expansion = args.NextInt32(); //get int anyway (0 if error)
|
||||
if (expansion < 0 || expansion > WorldConfig.GetIntValue(WorldCfg.Expansion))
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.ImproperValue);
|
||||
return false;
|
||||
}
|
||||
|
||||
PreparedStatement stmt = DB.Login.GetPreparedStatement(LoginStatements.UPD_EXPANSION);
|
||||
stmt.AddValue(0, expansion);
|
||||
stmt.AddValue(1, accountId);
|
||||
DB.Login.Execute(stmt);
|
||||
|
||||
handler.SendSysMessage(CypherStrings.AccountAddon, expansion);
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("create", RBACPermissions.CommandAccountCreate, true)]
|
||||
static bool HandleAccountCreateCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
if (args.Empty())
|
||||
return false;
|
||||
|
||||
var accountName = args.NextString().ToUpper();
|
||||
var password = args.NextString();
|
||||
string email = "";
|
||||
|
||||
if (string.IsNullOrEmpty(accountName) || string.IsNullOrEmpty(password))
|
||||
return false;
|
||||
|
||||
if (accountName.Contains("@"))
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.AccountUseBnetCommands);
|
||||
return false;
|
||||
}
|
||||
|
||||
AccountOpResult result = Global.AccountMgr.CreateAccount(accountName, password, email);
|
||||
switch (result)
|
||||
{
|
||||
case AccountOpResult.Ok:
|
||||
handler.SendSysMessage(CypherStrings.AccountCreated, accountName);
|
||||
if (handler.GetSession() != null)
|
||||
{
|
||||
Log.outInfo(LogFilter.Player, "Account: {0} (IP: {1}) Character:[{2}] (GUID: {3}) created Account {4} (Email: '{5}')",
|
||||
handler.GetSession().GetAccountId(), handler.GetSession().GetRemoteAddress(),
|
||||
handler.GetSession().GetPlayer().GetName(), handler.GetSession().GetPlayer().GetGUID().ToString(),
|
||||
accountName, email);
|
||||
}
|
||||
break;
|
||||
case AccountOpResult.NameTooLong:
|
||||
handler.SendSysMessage(CypherStrings.AccountNameTooLong);
|
||||
return false;
|
||||
case AccountOpResult.PassTooLong:
|
||||
handler.SendSysMessage(CypherStrings.AccountPassTooLong);
|
||||
return false;
|
||||
case AccountOpResult.NameAlreadyExist:
|
||||
handler.SendSysMessage(CypherStrings.AccountAlreadyExist);
|
||||
return false;
|
||||
case AccountOpResult.DBInternalError:
|
||||
handler.SendSysMessage(CypherStrings.AccountNotCreatedSqlError, accountName);
|
||||
return false;
|
||||
default:
|
||||
handler.SendSysMessage(CypherStrings.AccountNotCreated, accountName);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("delete", RBACPermissions.CommandAccountDelete, true)]
|
||||
static bool HandleAccountDeleteCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
if (args.Empty())
|
||||
return false;
|
||||
|
||||
string accountName = args.NextString();
|
||||
|
||||
if (string.IsNullOrEmpty(accountName))
|
||||
return false;
|
||||
|
||||
uint accountId = Global.AccountMgr.GetId(accountName);
|
||||
if (accountId == 0)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.AccountNotExist, accountName);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (handler.HasLowerSecurityAccount(null, accountId, true))
|
||||
return false;
|
||||
|
||||
AccountOpResult result = Global.AccountMgr.DeleteAccount(accountId);
|
||||
switch (result)
|
||||
{
|
||||
case AccountOpResult.Ok:
|
||||
handler.SendSysMessage(CypherStrings.AccountDeleted, accountName);
|
||||
break;
|
||||
case AccountOpResult.NameNotExist:
|
||||
handler.SendSysMessage(CypherStrings.AccountNotExist, accountName);
|
||||
return false;
|
||||
case AccountOpResult.DBInternalError:
|
||||
handler.SendSysMessage(CypherStrings.AccountNotDeletedSqlError, accountName);
|
||||
return false;
|
||||
default:
|
||||
handler.SendSysMessage(CypherStrings.AccountNotDeleted, accountName);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("email", RBACPermissions.CommandAccountSetSecEmail)]
|
||||
static bool HandleAccountEmailCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
if (args.Empty())
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.CmdSyntax);
|
||||
return false;
|
||||
}
|
||||
|
||||
string oldEmail = args.NextString();
|
||||
string password = args.NextString();
|
||||
string email = args.NextString();
|
||||
string emailConfirmation = args.NextString();
|
||||
|
||||
if (string.IsNullOrEmpty(oldEmail) || string.IsNullOrEmpty(password)
|
||||
|| string.IsNullOrEmpty(email) || string.IsNullOrEmpty(emailConfirmation))
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.CmdSyntax);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!Global.AccountMgr.CheckEmail(handler.GetSession().GetAccountId(), oldEmail))
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.CommandWrongemail);
|
||||
Log.outInfo(LogFilter.Player, "Account: {0} (IP: {1}) Character:[{2}] (GUID: {3}) Tried to change email, but the provided email [{4}] is not equal to registration email [{5}].",
|
||||
handler.GetSession().GetAccountId(), handler.GetSession().GetRemoteAddress(),
|
||||
handler.GetSession().GetPlayer().GetName(), handler.GetSession().GetPlayer().GetGUID().ToString(),
|
||||
email, oldEmail);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!Global.AccountMgr.CheckPassword(handler.GetSession().GetAccountId(), password))
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.CommandWrongoldpassword);
|
||||
Log.outInfo(LogFilter.Player, "Account: {0} (IP: {1}) Character:[{2}] (GUID: {3}) Tried to change email, but the provided password is wrong.",
|
||||
handler.GetSession().GetAccountId(), handler.GetSession().GetRemoteAddress(),
|
||||
handler.GetSession().GetPlayer().GetName(), handler.GetSession().GetPlayer().GetGUID().ToString());
|
||||
return false;
|
||||
}
|
||||
|
||||
if (email == oldEmail)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.OldEmailIsNewEmail);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (email != emailConfirmation)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.NewEmailsNotMatch);
|
||||
Log.outInfo(LogFilter.Player, "Account: {0} (IP: {1}) Character:[{2}] (GUID: {3}) Tried to change email, but the provided password is wrong.",
|
||||
handler.GetSession().GetAccountId(), handler.GetSession().GetRemoteAddress(),
|
||||
handler.GetSession().GetPlayer().GetName(), handler.GetSession().GetPlayer().GetGUID().ToString());
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
AccountOpResult result = Global.AccountMgr.ChangeEmail(handler.GetSession().GetAccountId(), email);
|
||||
switch (result)
|
||||
{
|
||||
case AccountOpResult.Ok:
|
||||
handler.SendSysMessage(CypherStrings.CommandEmail);
|
||||
Log.outInfo(LogFilter.Player, "Account: {0} (IP: {1}) Character:[{2}] (GUID: {3}) Changed Email from [{4}] to [{5}].",
|
||||
handler.GetSession().GetAccountId(), handler.GetSession().GetRemoteAddress(),
|
||||
handler.GetSession().GetPlayer().GetName(), handler.GetSession().GetPlayer().GetGUID().ToString(),
|
||||
oldEmail, email);
|
||||
break;
|
||||
case AccountOpResult.EmailTooLong:
|
||||
handler.SendSysMessage(CypherStrings.EmailTooLong);
|
||||
return false;
|
||||
default:
|
||||
handler.SendSysMessage(CypherStrings.CommandNotchangeemail);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("password", RBACPermissions.CommandAccountPassword)]
|
||||
static bool HandleAccountPasswordCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
// If no args are given at all, we can return false right away.
|
||||
if (args.Empty())
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.CmdSyntax);
|
||||
return false;
|
||||
}
|
||||
|
||||
// First, we check config. What security type (sec type) is it ? Depending on it, the command branches out
|
||||
uint pwConfig = WorldConfig.GetUIntValue(WorldCfg.AccPasschangesec); // 0 - PW_NONE, 1 - PW_EMAIL, 2 - PW_RBAC
|
||||
|
||||
// Command is supposed to be: .account password [$oldpassword] [$newpassword] [$newpasswordconfirmation] [$emailconfirmation]
|
||||
string oldPassword = args.NextString(); // This extracts [$oldpassword]
|
||||
string newPassword = args.NextString(); // This extracts [$newpassword]
|
||||
string passwordConfirmation = args.NextString(); // This extracts [$newpasswordconfirmation]
|
||||
string emailConfirmation = args.NextString(); // This defines the emailConfirmation variable, which is optional depending on sec type.
|
||||
|
||||
//Is any of those variables missing for any reason ? We return false.
|
||||
if (string.IsNullOrEmpty(oldPassword) || string.IsNullOrEmpty(newPassword)
|
||||
|| string.IsNullOrEmpty(passwordConfirmation))
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.CmdSyntax);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// We compare the old, saved password to the entered old password - no chance for the unauthorized.
|
||||
if (!Global.AccountMgr.CheckPassword(handler.GetSession().GetAccountId(), oldPassword))
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.CommandWrongoldpassword);
|
||||
|
||||
Log.outInfo(LogFilter.Player, "Account: {0} (IP: {1}) Character:[{2}] (GUID: {3}) Tried to change password, but the provided old password is wrong.",
|
||||
handler.GetSession().GetAccountId(), handler.GetSession().GetRemoteAddress(),
|
||||
handler.GetSession().GetPlayer().GetName(), handler.GetSession().GetPlayer().GetGUID().ToString());
|
||||
return false;
|
||||
}
|
||||
// This compares the old, current email to the entered email - however, only...
|
||||
if ((pwConfig == 1 || (pwConfig == 2 && handler.GetSession().HasPermission(RBACPermissions.EmailConfirmForPassChange))) // ...if either PW_EMAIL or PW_RBAC with the Permission is active...
|
||||
&& !Global.AccountMgr.CheckEmail(handler.GetSession().GetAccountId(), emailConfirmation)) // ... and returns false if the comparison fails.
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.CommandWrongemail);
|
||||
|
||||
Log.outInfo(LogFilter.Player, "Account: {0} (IP: {1}) Character:[{2}] (GUID: {3}) Tried to change password, but the entered email [{4}] is wrong.",
|
||||
handler.GetSession().GetAccountId(), handler.GetSession().GetRemoteAddress(),
|
||||
handler.GetSession().GetPlayer().GetName(), handler.GetSession().GetPlayer().GetGUID().ToString(),
|
||||
emailConfirmation);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Making sure that newly entered password is correctly entered.
|
||||
if (newPassword != passwordConfirmation)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.NewPasswordsNotMatch);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Changes password and prints result.
|
||||
AccountOpResult result = Global.AccountMgr.ChangePassword(handler.GetSession().GetAccountId(), newPassword);
|
||||
switch (result)
|
||||
{
|
||||
case AccountOpResult.Ok:
|
||||
handler.SendSysMessage(CypherStrings.CommandPassword);
|
||||
Log.outInfo(LogFilter.Player, "Account: {0} (IP: {1}) Character:[{2}] (GUID: {3}) Changed Password.",
|
||||
handler.GetSession().GetAccountId(), handler.GetSession().GetRemoteAddress(),
|
||||
handler.GetSession().GetPlayer().GetName(), handler.GetSession().GetPlayer().GetGUID().ToString());
|
||||
break;
|
||||
case AccountOpResult.PassTooLong:
|
||||
handler.SendSysMessage(CypherStrings.PasswordTooLong);
|
||||
return false;
|
||||
default:
|
||||
handler.SendSysMessage(CypherStrings.CommandNotchangepassword);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("onlinelist", RBACPermissions.CommandAccountOnlineList, true)]
|
||||
static bool HandleAccountOnlineListCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
// Get the list of accounts ID logged to the realm
|
||||
PreparedStatement stmt = DB.Characters.GetPreparedStatement(CharStatements.SEL_CHARACTER_ONLINE);
|
||||
|
||||
SQLResult result = DB.Characters.Query(stmt);
|
||||
|
||||
if (result.IsEmpty())
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.AccountListEmpty);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Display the list of account/characters online
|
||||
handler.SendSysMessage(CypherStrings.AccountListBarHeader);
|
||||
handler.SendSysMessage(CypherStrings.AccountListHeader);
|
||||
handler.SendSysMessage(CypherStrings.AccountListBar);
|
||||
|
||||
// Cycle through accounts
|
||||
do
|
||||
{
|
||||
string name = result.Read<string>(0);
|
||||
uint account = result.Read<uint>(1);
|
||||
|
||||
// Get the username, last IP and GM level of each account
|
||||
// No SQL injection. account is uint32.
|
||||
stmt = DB.Login.GetPreparedStatement(LoginStatements.SEL_ACCOUNT_INFO);
|
||||
stmt.AddValue(0, account);
|
||||
SQLResult resultLogin = DB.Login.Query(stmt);
|
||||
|
||||
if (!resultLogin.IsEmpty())
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.AccountListLine, resultLogin.Read<string>(0),
|
||||
name, resultLogin.Read<string>(1), result.Read<ushort>(2), result.Read<ushort>(3),
|
||||
resultLogin.Read<byte>(3), resultLogin.Read<byte>(2));
|
||||
}
|
||||
else
|
||||
handler.SendSysMessage(CypherStrings.AccountListError, name);
|
||||
}
|
||||
while (result.NextRow());
|
||||
|
||||
handler.SendSysMessage(CypherStrings.AccountListBar);
|
||||
return true;
|
||||
}
|
||||
|
||||
[CommandGroup("set", RBACPermissions.CommandAccountSet, true)]
|
||||
class SetCommands
|
||||
{
|
||||
[Command("password", RBACPermissions.CommandAccountSetPassword, true)]
|
||||
static bool HandleSetPasswordCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
if (args.Empty())
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.CmdSyntax);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Get the command line arguments
|
||||
string accountName = args.NextString();
|
||||
string password = args.NextString();
|
||||
string passwordConfirmation = args.NextString();
|
||||
|
||||
if (string.IsNullOrEmpty(accountName) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(passwordConfirmation))
|
||||
return false;
|
||||
|
||||
uint targetAccountId = Global.AccountMgr.GetId(accountName);
|
||||
if (targetAccountId == 0)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.AccountNotExist, accountName);
|
||||
return false;
|
||||
}
|
||||
|
||||
// can set password only for target with less security
|
||||
// This also restricts setting handler's own password
|
||||
if (handler.HasLowerSecurityAccount(null, targetAccountId, true))
|
||||
return false;
|
||||
|
||||
if (!password.Equals(passwordConfirmation))
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.NewPasswordsNotMatch);
|
||||
return false;
|
||||
}
|
||||
|
||||
AccountOpResult result = Global.AccountMgr.ChangePassword(targetAccountId, password);
|
||||
switch (result)
|
||||
{
|
||||
case AccountOpResult.Ok:
|
||||
handler.SendSysMessage(CypherStrings.CommandPassword);
|
||||
break;
|
||||
case AccountOpResult.NameNotExist:
|
||||
handler.SendSysMessage(CypherStrings.AccountNotExist, accountName);
|
||||
return false;
|
||||
case AccountOpResult.PassTooLong:
|
||||
handler.SendSysMessage(CypherStrings.PasswordTooLong);
|
||||
return false;
|
||||
default:
|
||||
handler.SendSysMessage(CypherStrings.CommandNotchangepassword);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("addon", RBACPermissions.CommandAccountSetAddon, true)]
|
||||
static bool HandleSetAddonCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
if (args.Empty())
|
||||
return false;
|
||||
|
||||
// Get the command line arguments
|
||||
string account = args.NextString();
|
||||
string exp = args.NextString();
|
||||
|
||||
if (string.IsNullOrEmpty(account))
|
||||
return false;
|
||||
|
||||
string accountName;
|
||||
uint accountId;
|
||||
|
||||
if (string.IsNullOrEmpty(exp))
|
||||
{
|
||||
Player player = handler.getSelectedPlayer();
|
||||
if (!player)
|
||||
return false;
|
||||
|
||||
accountId = player.GetSession().GetAccountId();
|
||||
Global.AccountMgr.GetName(accountId, out accountName);
|
||||
exp = account;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Convert Account name to Upper Format
|
||||
accountName = account.ToUpper();
|
||||
|
||||
accountId = Global.AccountMgr.GetId(accountName);
|
||||
if (accountId == 0)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.AccountNotExist, accountName);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Let set addon state only for lesser (strong) security level
|
||||
// or to self account
|
||||
if (handler.GetSession() != null && handler.GetSession().GetAccountId() != accountId &&
|
||||
handler.HasLowerSecurityAccount(null, accountId, true))
|
||||
return false;
|
||||
|
||||
byte expansion = byte.Parse(exp); //get int anyway (0 if error)
|
||||
if (expansion > WorldConfig.GetIntValue(WorldCfg.Expansion))
|
||||
return false;
|
||||
|
||||
PreparedStatement stmt = DB.Login.GetPreparedStatement(LoginStatements.UPD_EXPANSION);
|
||||
|
||||
stmt.AddValue(0, expansion);
|
||||
stmt.AddValue(1, accountId);
|
||||
|
||||
DB.Login.Execute(stmt);
|
||||
|
||||
handler.SendSysMessage(CypherStrings.AccountSetaddon, accountName, accountId, expansion);
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("gmlevel", RBACPermissions.CommandAccountSetGmlevel, true)]
|
||||
static bool HandleSetGmLevelCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
if (args.Empty())
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.CmdSyntax);
|
||||
return false;
|
||||
}
|
||||
|
||||
string targetAccountName = "";
|
||||
uint targetAccountId = 0;
|
||||
AccountTypes targetSecurity = 0;
|
||||
uint gm = 0;
|
||||
string arg1 = args.NextString();
|
||||
string arg2 = args.NextString();
|
||||
string arg3 = args.NextString();
|
||||
bool isAccountNameGiven = true;
|
||||
|
||||
if (string.IsNullOrEmpty(arg3))
|
||||
{
|
||||
if (!handler.getSelectedPlayer())
|
||||
return false;
|
||||
isAccountNameGiven = false;
|
||||
}
|
||||
|
||||
if (!isAccountNameGiven && string.IsNullOrEmpty(arg2))
|
||||
return false;
|
||||
|
||||
if (isAccountNameGiven)
|
||||
{
|
||||
targetAccountName = arg1;
|
||||
if (Global.AccountMgr.GetId(targetAccountName) == 0)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.AccountNotExist, targetAccountName);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Check for invalid specified GM level.
|
||||
gm = isAccountNameGiven ? uint.Parse(arg2) : uint.Parse(arg1);
|
||||
if (gm > (uint)AccountTypes.Console)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.BadValue);
|
||||
return false;
|
||||
}
|
||||
|
||||
// command.getSession() == NULL only for console
|
||||
targetAccountId = (isAccountNameGiven) ? Global.AccountMgr.GetId(targetAccountName) : handler.getSelectedPlayer().GetSession().GetAccountId();
|
||||
int gmRealmID = (isAccountNameGiven) ? int.Parse(arg3) : int.Parse(arg2);
|
||||
AccountTypes playerSecurity;
|
||||
if (handler.GetSession() != null)
|
||||
playerSecurity = Global.AccountMgr.GetSecurity(handler.GetSession().GetAccountId(), gmRealmID);
|
||||
else
|
||||
playerSecurity = AccountTypes.Console;
|
||||
|
||||
// can set security level only for target with less security and to less security that we have
|
||||
// This is also reject self apply in fact
|
||||
targetSecurity = Global.AccountMgr.GetSecurity(targetAccountId, gmRealmID);
|
||||
if (targetSecurity >= playerSecurity || (AccountTypes)gm >= playerSecurity)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.YoursSecurityIsLow);
|
||||
return false;
|
||||
}
|
||||
PreparedStatement stmt;
|
||||
// Check and abort if the target gm has a higher rank on one of the realms and the new realm is -1
|
||||
if (gmRealmID == -1 && !Global.AccountMgr.IsConsoleAccount(playerSecurity))
|
||||
{
|
||||
stmt = DB.Login.GetPreparedStatement(LoginStatements.SEL_ACCOUNT_ACCESS_GMLEVEL_TEST);
|
||||
stmt.AddValue(0, targetAccountId);
|
||||
stmt.AddValue(1, gm);
|
||||
|
||||
SQLResult result = DB.Login.Query(stmt);
|
||||
|
||||
if (!result.IsEmpty())
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.YoursSecurityIsLow);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Check if provided realmID has a negative value other than -1
|
||||
if (gmRealmID < -1)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.InvalidRealmid);
|
||||
return false;
|
||||
}
|
||||
|
||||
RBACData rbac = isAccountNameGiven ? null : handler.getSelectedPlayer().GetSession().GetRBACData();
|
||||
Global.AccountMgr.UpdateAccountAccess(rbac, targetAccountId, (byte)gm, gmRealmID);
|
||||
handler.SendSysMessage(CypherStrings.YouChangeSecurity, targetAccountName, gm);
|
||||
return true;
|
||||
}
|
||||
|
||||
[CommandGroup("sec", RBACPermissions.CommandAccountSetSec, true)]
|
||||
class SetSecCommands
|
||||
{
|
||||
[Command("email", RBACPermissions.CommandAccountSetSecEmail, true)]
|
||||
static bool HandleSetEmailCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
if (args.Empty())
|
||||
return false;
|
||||
|
||||
// Get the command line arguments
|
||||
string accountName = args.NextString();
|
||||
string email = args.NextString();
|
||||
string emailConfirmation = args.NextString();
|
||||
|
||||
if (string.IsNullOrEmpty(accountName) || string.IsNullOrEmpty(email) || string.IsNullOrEmpty(emailConfirmation))
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.CmdSyntax);
|
||||
return false;
|
||||
}
|
||||
|
||||
uint targetAccountId = Global.AccountMgr.GetId(accountName);
|
||||
if (targetAccountId == 0)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.AccountNotExist, accountName);
|
||||
return false;
|
||||
}
|
||||
|
||||
/// can set email only for target with less security
|
||||
/// This also restricts setting handler's own email.
|
||||
if (handler.HasLowerSecurityAccount(null, targetAccountId, true))
|
||||
return false;
|
||||
|
||||
if (!email.Equals(emailConfirmation))
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.NewEmailsNotMatch);
|
||||
return false;
|
||||
}
|
||||
|
||||
AccountOpResult result = Global.AccountMgr.ChangeEmail(targetAccountId, email);
|
||||
switch (result)
|
||||
{
|
||||
case AccountOpResult.Ok:
|
||||
handler.SendSysMessage(CypherStrings.CommandEmail);
|
||||
Log.outInfo(LogFilter.Player, "ChangeEmail: Account {0} [Id: {1}] had it's email changed to {2}.", accountName, targetAccountId, email);
|
||||
break;
|
||||
case AccountOpResult.NameNotExist:
|
||||
handler.SendSysMessage(CypherStrings.AccountNotExist, accountName);
|
||||
return false;
|
||||
case AccountOpResult.EmailTooLong:
|
||||
handler.SendSysMessage(CypherStrings.EmailTooLong);
|
||||
return false;
|
||||
default:
|
||||
handler.SendSysMessage(CypherStrings.CommandNotchangeemail);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("regmail", RBACPermissions.CommandAccountSetSecRegmail, true)]
|
||||
static bool HandleSetRegEmailCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
if (args.Empty())
|
||||
return false;
|
||||
|
||||
//- We do not want anything short of console to use this by default.
|
||||
//- So we force that.
|
||||
if (handler.GetSession())
|
||||
return false;
|
||||
|
||||
// Get the command line arguments
|
||||
string accountName = args.NextString();
|
||||
string email = args.NextString();
|
||||
string emailConfirmation = args.NextString();
|
||||
|
||||
if (string.IsNullOrEmpty(accountName) || string.IsNullOrEmpty(email) || string.IsNullOrEmpty(emailConfirmation))
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.CmdSyntax);
|
||||
return false;
|
||||
}
|
||||
|
||||
uint targetAccountId = Global.AccountMgr.GetId(accountName);
|
||||
if (targetAccountId == 0)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.AccountNotExist, accountName);
|
||||
return false;
|
||||
}
|
||||
|
||||
/// can set email only for target with less security
|
||||
/// This also restricts setting handler's own email.
|
||||
if (handler.HasLowerSecurityAccount(null, targetAccountId, true))
|
||||
return false;
|
||||
|
||||
if (!email.Equals(emailConfirmation))
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.NewEmailsNotMatch);
|
||||
return false;
|
||||
}
|
||||
|
||||
AccountOpResult result = Global.AccountMgr.ChangeRegEmail(targetAccountId, email);
|
||||
switch (result)
|
||||
{
|
||||
case AccountOpResult.Ok:
|
||||
handler.SendSysMessage(CypherStrings.CommandEmail);
|
||||
Log.outInfo(LogFilter.Player, "ChangeRegEmail: Account {0} [Id: {1}] had it's Registration Email changed to {2}.", accountName, targetAccountId, email);
|
||||
break;
|
||||
case AccountOpResult.NameNotExist:
|
||||
handler.SendSysMessage(CypherStrings.AccountNotExist, accountName);
|
||||
return false;
|
||||
case AccountOpResult.EmailTooLong:
|
||||
handler.SendSysMessage(CypherStrings.EmailTooLong);
|
||||
return false;
|
||||
default:
|
||||
handler.SendSysMessage(CypherStrings.CommandNotchangeemail);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[CommandGroup("lock", RBACPermissions.CommandAccountLock)]
|
||||
class LockCommands
|
||||
{
|
||||
[Command("country", RBACPermissions.CommandAccountLockCountry)]
|
||||
static bool HandleAccountLockCountryCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
if (args.Empty())
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.UseBol);
|
||||
return false;
|
||||
}
|
||||
|
||||
string param = args.NextString();
|
||||
if (!param.IsEmpty())
|
||||
{
|
||||
if (param == "on")
|
||||
{
|
||||
var ipBytes = System.Net.IPAddress.Parse(handler.GetSession().GetRemoteAddress()).GetAddressBytes();
|
||||
Array.Reverse(ipBytes);
|
||||
|
||||
PreparedStatement stmt = DB.Login.GetPreparedStatement(LoginStatements.SEL_LOGON_COUNTRY);
|
||||
stmt.AddValue(0, BitConverter.ToUInt32(ipBytes, 0));
|
||||
|
||||
SQLResult result = DB.Login.Query(stmt);
|
||||
if (!result.IsEmpty())
|
||||
{
|
||||
string country = result.Read<string>(0);
|
||||
stmt = DB.Login.GetPreparedStatement(LoginStatements.UPD_ACCOUNT_LOCK_CONTRY);
|
||||
stmt.AddValue(0, country);
|
||||
stmt.AddValue(1, handler.GetSession().GetAccountId());
|
||||
DB.Login.Execute(stmt);
|
||||
handler.SendSysMessage(CypherStrings.CommandAcclocklocked);
|
||||
}
|
||||
else
|
||||
{
|
||||
handler.SendSysMessage("[IP2NATION] Table empty");
|
||||
Log.outDebug(LogFilter.Server, "[IP2NATION] Table empty");
|
||||
}
|
||||
}
|
||||
else if (param == "off")
|
||||
{
|
||||
PreparedStatement stmt = DB.Login.GetPreparedStatement(LoginStatements.UPD_ACCOUNT_LOCK_CONTRY);
|
||||
stmt.AddValue(0, "00");
|
||||
stmt.AddValue(1, handler.GetSession().GetAccountId());
|
||||
DB.Login.Execute(stmt);
|
||||
handler.SendSysMessage(CypherStrings.CommandAcclockunlocked);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
handler.SendSysMessage(CypherStrings.UseBol);
|
||||
return false;
|
||||
}
|
||||
|
||||
[Command("ip", RBACPermissions.CommandAccountLockIp)]
|
||||
static bool HandleAccountLockIpCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
if (args.Empty())
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.UseBol);
|
||||
return false;
|
||||
}
|
||||
|
||||
string param = args.NextString();
|
||||
if (!string.IsNullOrEmpty(param))
|
||||
{
|
||||
PreparedStatement stmt = DB.Login.GetPreparedStatement(LoginStatements.UPD_ACCOUNT_LOCK);
|
||||
|
||||
if (param == "on")
|
||||
{
|
||||
stmt.AddValue(0, true); // locked
|
||||
handler.SendSysMessage(CypherStrings.CommandAcclocklocked);
|
||||
}
|
||||
else if (param == "off")
|
||||
{
|
||||
stmt.AddValue(0, false); // unlocked
|
||||
handler.SendSysMessage(CypherStrings.CommandAcclockunlocked);
|
||||
}
|
||||
stmt.AddValue(1, handler.GetSession().GetAccountId());
|
||||
|
||||
DB.Login.Execute(stmt);
|
||||
return true;
|
||||
}
|
||||
|
||||
handler.SendSysMessage(CypherStrings.UseBol);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,224 @@
|
||||
/*
|
||||
* Copyright (C) 2012-2017 CypherCore <http://github.com/CypherCore>
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using Framework.Constants;
|
||||
using Framework.IO;
|
||||
|
||||
namespace Game.Chat.Commands
|
||||
{
|
||||
//Holder for now.
|
||||
[CommandGroup("ahbot", RBACPermissions.CommandAhbot)]
|
||||
class AhBotCommands
|
||||
{
|
||||
[Command("rebuild", RBACPermissions.CommandAhbotRebuild, true)]
|
||||
static bool HandleAHBotRebuildCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
/*char* arg = strtok((char*)args, " ");
|
||||
|
||||
bool all = false;
|
||||
if (arg && strcmp(arg, "all") == 0)
|
||||
all = true;
|
||||
|
||||
sAuctionBot->Rebuild(all);*/
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("reload", RBACPermissions.CommandAhbotReload, true)]
|
||||
static bool HandleAHBotReloadCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
//sAuctionBot->ReloadAllConfig();
|
||||
//handler->SendSysMessage(LANG_AHBOT_RELOAD_OK);
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("status", RBACPermissions.CommandAhbotStatus, true)]
|
||||
static bool HandleAHBotStatusCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
/* char* arg = strtok((char*)args, " ");
|
||||
if (!arg)
|
||||
return false;
|
||||
|
||||
bool all = false;
|
||||
if (strcmp(arg, "all") == 0)
|
||||
all = true;
|
||||
|
||||
AuctionHouseBotStatusInfo statusInfo;
|
||||
sAuctionBot->PrepareStatusInfos(statusInfo);
|
||||
|
||||
WorldSession* session = handler->GetSession();
|
||||
|
||||
if (!session)
|
||||
{
|
||||
handler->SendSysMessage(LANG_AHBOT_STATUS_BAR_CONSOLE);
|
||||
handler->SendSysMessage(LANG_AHBOT_STATUS_TITLE1_CONSOLE);
|
||||
handler->SendSysMessage(LANG_AHBOT_STATUS_MIDBAR_CONSOLE);
|
||||
}
|
||||
else
|
||||
handler->SendSysMessage(LANG_AHBOT_STATUS_TITLE1_CHAT);
|
||||
|
||||
public uint fmtId = session ? LANG_AHBOT_STATUS_FORMAT_CHAT : LANG_AHBOT_STATUS_FORMAT_CONSOLE;
|
||||
|
||||
handler->PSendSysMessage(fmtId, handler->GetCypherString(LANG_AHBOT_STATUS_ITEM_COUNT),
|
||||
statusInfo[AUCTION_HOUSE_ALLIANCE].ItemsCount,
|
||||
statusInfo[AUCTION_HOUSE_HORDE].ItemsCount,
|
||||
statusInfo[AUCTION_HOUSE_NEUTRAL].ItemsCount,
|
||||
statusInfo[AUCTION_HOUSE_ALLIANCE].ItemsCount +
|
||||
statusInfo[AUCTION_HOUSE_HORDE].ItemsCount +
|
||||
statusInfo[AUCTION_HOUSE_NEUTRAL].ItemsCount);
|
||||
|
||||
if (all)
|
||||
{
|
||||
handler->PSendSysMessage(fmtId, handler->GetCypherString(LANG_AHBOT_STATUS_ITEM_RATIO),
|
||||
sAuctionBotConfig->GetConfig(CONFIG_AHBOT_ALLIANCE_ITEM_AMOUNT_RATIO),
|
||||
sAuctionBotConfig->GetConfig(CONFIG_AHBOT_HORDE_ITEM_AMOUNT_RATIO),
|
||||
sAuctionBotConfig->GetConfig(CONFIG_AHBOT_NEUTRAL_ITEM_AMOUNT_RATIO),
|
||||
sAuctionBotConfig->GetConfig(CONFIG_AHBOT_ALLIANCE_ITEM_AMOUNT_RATIO) +
|
||||
sAuctionBotConfig->GetConfig(CONFIG_AHBOT_HORDE_ITEM_AMOUNT_RATIO) +
|
||||
sAuctionBotConfig->GetConfig(CONFIG_AHBOT_NEUTRAL_ITEM_AMOUNT_RATIO));
|
||||
|
||||
if (!session)
|
||||
{
|
||||
handler->SendSysMessage(LANG_AHBOT_STATUS_BAR_CONSOLE);
|
||||
handler->SendSysMessage(LANG_AHBOT_STATUS_TITLE2_CONSOLE);
|
||||
handler->SendSysMessage(LANG_AHBOT_STATUS_MIDBAR_CONSOLE);
|
||||
}
|
||||
else
|
||||
handler->SendSysMessage(LANG_AHBOT_STATUS_TITLE2_CHAT);
|
||||
|
||||
for (int i = 0; i < MAX_AUCTION_QUALITY; ++i)
|
||||
handler->PSendSysMessage(fmtId, handler->GetCypherString(ahbotQualityIds[i]),
|
||||
statusInfo[AUCTION_HOUSE_ALLIANCE].QualityInfo[i],
|
||||
statusInfo[AUCTION_HOUSE_HORDE].QualityInfo[i],
|
||||
statusInfo[AUCTION_HOUSE_NEUTRAL].QualityInfo[i],
|
||||
sAuctionBotConfig->GetConfigItemQualityAmount(AuctionQuality(i)));
|
||||
}
|
||||
|
||||
if (!session)
|
||||
handler->SendSysMessage(LANG_AHBOT_STATUS_BAR_CONSOLE);
|
||||
*/
|
||||
return true;
|
||||
}
|
||||
|
||||
[CommandGroup("items", RBACPermissions.CommandAhbotItems)]
|
||||
class ItemsCommands
|
||||
{
|
||||
[Command("", RBACPermissions.CommandAhbotItems, true)]
|
||||
static bool HandleAHBotItemsAmountCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
/*public uint qVals[MAX_AUCTION_QUALITY];
|
||||
char* arg = strtok((char*)args, " ");
|
||||
for (int i = 0; i < MAX_AUCTION_QUALITY; ++i)
|
||||
{
|
||||
if (!arg)
|
||||
return false;
|
||||
qVals[i] = atoi(arg);
|
||||
arg = strtok(NULL, " ");
|
||||
}
|
||||
|
||||
sAuctionBot->SetItemsAmount(qVals);
|
||||
|
||||
for (int i = 0; i < MAX_AUCTION_QUALITY; ++i)
|
||||
handler->PSendSysMessage(LANG_AHBOT_ITEMS_AMOUNT, handler->GetCypherString(ahbotQualityIds[i]), sAuctionBotConfig->GetConfigItemQualityAmount(AuctionQuality(i)));
|
||||
*/
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("blue", RBACPermissions.CommandAhbotItemsBlue, true)]
|
||||
static bool HandleAHBotItemsAmountQualityBlue(StringArguments args, CommandHandler handler) { return true; }
|
||||
|
||||
[Command("gray", RBACPermissions.CommandAhbotItemsGray, true)]
|
||||
static bool HandleAHBotItemsAmountQualityGray(StringArguments args, CommandHandler handler) { return true; }
|
||||
|
||||
[Command("green", RBACPermissions.CommandAhbotItemsGreen, true)]
|
||||
static bool HandleAHBotItemsAmountQualityGreen(StringArguments args, CommandHandler handler) { return true; }
|
||||
|
||||
[Command("orange", RBACPermissions.CommandAhbotItemsOrange, true)]
|
||||
static bool HandleAHBotItemsAmountQualityOrange(StringArguments args, CommandHandler handler) { return true; }
|
||||
|
||||
[Command("purple", RBACPermissions.CommandAhbotItemsPurple, true)]
|
||||
static bool HandleAHBotItemsAmountQualityPurple(StringArguments args, CommandHandler handler) { return true; }
|
||||
|
||||
[Command("white", RBACPermissions.CommandAhbotItemsWhite, true)]
|
||||
static bool HandleAHBotItemsAmountQualityWhite(StringArguments args, CommandHandler handler) { return true; }
|
||||
|
||||
[Command("yellow", RBACPermissions.CommandAhbotItemsYellow, true)]
|
||||
static bool HandleAHBotItemsAmountQualityYellow(StringArguments args, CommandHandler handler) { return true; }
|
||||
|
||||
static bool HandleAHBotItemsAmountQualityCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
/*
|
||||
char* arg = strtok((char*)args, " ");
|
||||
if (!arg)
|
||||
return false;
|
||||
public uint qualityVal = atoi(arg);
|
||||
|
||||
sAuctionBot->SetItemsAmountForQuality(Q, qualityVal);
|
||||
handler->PSendSysMessage(LANG_AHBOT_ITEMS_AMOUNT, handler->GetCypherString(ahbotQualityIds[Q]),
|
||||
sAuctionBotConfig->GetConfigItemQualityAmount(Q));
|
||||
*/
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
[CommandGroup("ratio", RBACPermissions.CommandAhbotRatio)]
|
||||
class RatioCommands
|
||||
{
|
||||
[Command("", RBACPermissions.CommandAhbotRatio, true)]
|
||||
static bool HandleAHBotItemsRatioCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
/*public uint rVal[MAX_AUCTION_QUALITY];
|
||||
char* arg = strtok((char*)args, " ");
|
||||
for (int i = 0; i < MAX_AUCTION_QUALITY; ++i)
|
||||
{
|
||||
if (!arg)
|
||||
return false;
|
||||
rVal[i] = atoi(arg);
|
||||
arg = strtok(NULL, " ");
|
||||
}
|
||||
|
||||
sAuctionBot->SetItemsRatio(rVal[0], rVal[1], rVal[2]);
|
||||
|
||||
for (int i = 0; i < MAX_AUCTION_HOUSE_TYPE; ++i)
|
||||
handler->PSendSysMessage(LANG_AHBOT_ITEMS_RATIO, AuctionBotConfig::GetHouseTypeName(AuctionHouseType(i)), sAuctionBotConfig->GetConfigItemAmountRatio(AuctionHouseType(i)));
|
||||
*/
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("alliance", RBACPermissions.CommandAhbotRatioAlliance, true)]
|
||||
static bool HandleAHBotItemsRatioHouseAlliance(StringArguments args, CommandHandler handler) { return true; }
|
||||
|
||||
[Command("horde", RBACPermissions.CommandAhbotRatioHorde, true)]
|
||||
static bool HandleAHBotItemsRatioHouseHorde(StringArguments args, CommandHandler handler) { return true; }
|
||||
|
||||
[Command("neutral", RBACPermissions.CommandAhbotRatioNeutral, true)]
|
||||
static bool HandleAHBotItemsRatioHouseNeutral(StringArguments args, CommandHandler handler) { return true; }
|
||||
|
||||
static bool HandleAHBotItemsRatioHouseCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
/*char* arg = strtok((char*)args, " ");
|
||||
if (!arg)
|
||||
return false;
|
||||
public uint ratioVal = atoi(arg);
|
||||
|
||||
sAuctionBot->SetItemsRatioForHouse(H, ratioVal);
|
||||
handler->PSendSysMessage(LANG_AHBOT_ITEMS_RATIO, AuctionBotConfig::GetHouseTypeName(H), sAuctionBotConfig->GetConfigItemAmountRatio(H));
|
||||
*/
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,294 @@
|
||||
/*
|
||||
* Copyright (C) 2012-2017 CypherCore <http://github.com/CypherCore>
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using Framework.Constants;
|
||||
using Framework.IO;
|
||||
using Game.Arenas;
|
||||
using Game.Entities;
|
||||
|
||||
namespace Game.Chat
|
||||
{
|
||||
[CommandGroup("arena", RBACPermissions.CommandArena)]
|
||||
class ArenaCommands
|
||||
{
|
||||
[Command("create", RBACPermissions.CommandArenaCreate, true)]
|
||||
static bool HandleArenaCreateCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
if (args.Empty())
|
||||
return false;
|
||||
|
||||
Player target;
|
||||
if (!handler.extractPlayerTarget(args[0] != '"' ? args : null, out target))
|
||||
return false;
|
||||
|
||||
string name = handler.extractQuotedArg(args.NextString());
|
||||
if (string.IsNullOrEmpty(name))
|
||||
return false;
|
||||
|
||||
byte type = args.NextByte();
|
||||
if (type == 0)
|
||||
return false;
|
||||
|
||||
if (Global.ArenaTeamMgr.GetArenaTeamByName(name) != null)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.ArenaErrorNameExists, name);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (type == 2 || type == 3 || type == 5)
|
||||
{
|
||||
if (Player.GetArenaTeamIdFromDB(target.GetGUID(), type) != 0)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.ArenaErrorSize, target.GetName());
|
||||
return false;
|
||||
}
|
||||
|
||||
ArenaTeam arena = new ArenaTeam();
|
||||
|
||||
if (!arena.Create(target.GetGUID(), type, name, 4293102085, 101, 4293253939, 4, 4284049911))
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.BadValue);
|
||||
return false;
|
||||
}
|
||||
|
||||
Global.ArenaTeamMgr.AddArenaTeam(arena);
|
||||
handler.SendSysMessage(CypherStrings.ArenaCreate, arena.GetName(), arena.GetId(), arena.GetArenaType(), arena.GetCaptain());
|
||||
}
|
||||
else
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.BadValue);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("disband", RBACPermissions.CommandArenaDisband, true)]
|
||||
static bool HandleArenaDisbandCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
if (args.Empty())
|
||||
return false;
|
||||
|
||||
uint teamId = args.NextUInt32();
|
||||
if (teamId == 0)
|
||||
return false;
|
||||
|
||||
ArenaTeam arena = Global.ArenaTeamMgr.GetArenaTeamById(teamId);
|
||||
|
||||
if (arena == null)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.ArenaErrorNotFound, teamId);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (arena.IsFighting())
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.ArenaErrorCombat);
|
||||
return false;
|
||||
}
|
||||
|
||||
string name = arena.GetName();
|
||||
arena.Disband();
|
||||
if (handler.GetSession() != null)
|
||||
Log.outDebug(LogFilter.Arena, "GameMaster: {0} [GUID: {1}] disbanded arena team type: {2} [Id: {3}].",
|
||||
handler.GetSession().GetPlayer().GetName(), handler.GetSession().GetPlayer().GetGUID().ToString(), arena.GetArenaType(), teamId);
|
||||
else
|
||||
Log.outDebug(LogFilter.Arena, "Console: disbanded arena team type: {0} [Id: {1}].", arena.GetArenaType(), teamId);
|
||||
|
||||
handler.SendSysMessage(CypherStrings.ArenaDisband, name, teamId);
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("rename", RBACPermissions.CommandArenaRename, true)]
|
||||
static bool HandleArenaRenameCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
if (args.Empty())
|
||||
return false;
|
||||
|
||||
string oldArenaStr = handler.extractQuotedArg(args.NextString());
|
||||
if (string.IsNullOrEmpty(oldArenaStr))
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.BadValue);
|
||||
return false;
|
||||
}
|
||||
|
||||
string newArenaStr = handler.extractQuotedArg(args.NextString());
|
||||
if (string.IsNullOrEmpty(newArenaStr))
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.BadValue);
|
||||
return false;
|
||||
}
|
||||
|
||||
ArenaTeam arena = Global.ArenaTeamMgr.GetArenaTeamByName(oldArenaStr);
|
||||
if (arena == null)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.AreanErrorNameNotFound, oldArenaStr);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (Global.ArenaTeamMgr.GetArenaTeamByName(newArenaStr) != null)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.ArenaErrorNameExists, oldArenaStr);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (arena.IsFighting())
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.ArenaErrorCombat);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!arena.SetName(newArenaStr))
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.BadValue);
|
||||
return false;
|
||||
}
|
||||
|
||||
handler.SendSysMessage(CypherStrings.ArenaRename, arena.GetId(), oldArenaStr, newArenaStr);
|
||||
if (handler.GetSession() != null)
|
||||
Log.outDebug(LogFilter.Arena, "GameMaster: {0} [GUID: {1}] rename arena team \"{2}\"[Id: {3}] to \"{4}\"",
|
||||
handler.GetSession().GetPlayer().GetName(), handler.GetSession().GetPlayer().GetGUID().ToString(), oldArenaStr, arena.GetId(), newArenaStr);
|
||||
else
|
||||
Log.outDebug(LogFilter.Arena, "Console: rename arena team \"{0}\"[Id: {1}] to \"{2}\"", oldArenaStr, arena.GetId(), newArenaStr);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("captain", RBACPermissions.CommandArenaCaptain)]
|
||||
static bool HandleArenaCaptainCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
if (args.Empty())
|
||||
return false;
|
||||
|
||||
string idStr;
|
||||
string nameStr;
|
||||
handler.extractOptFirstArg(args, out idStr, out nameStr);
|
||||
if (string.IsNullOrEmpty(idStr))
|
||||
return false;
|
||||
|
||||
uint teamId = uint.Parse(idStr);
|
||||
if (teamId == 0)
|
||||
return false;
|
||||
|
||||
Player target;
|
||||
ObjectGuid targetGuid;
|
||||
if (!handler.extractPlayerTarget(new StringArguments(nameStr), out target, out targetGuid))
|
||||
return false;
|
||||
|
||||
ArenaTeam arena = Global.ArenaTeamMgr.GetArenaTeamById(teamId);
|
||||
|
||||
if (arena == null)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.ArenaErrorNotFound, teamId);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!target)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.PlayerNotExistOrOffline, nameStr);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (arena.IsFighting())
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.ArenaErrorCombat);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!arena.IsMember(targetGuid))
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.ArenaErrorNotMember, nameStr, arena.GetName());
|
||||
return false;
|
||||
}
|
||||
|
||||
if (arena.GetCaptain() == targetGuid)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.ArenaErrorCaptain, nameStr, arena.GetName());
|
||||
return false;
|
||||
}
|
||||
|
||||
arena.SetCaptain(targetGuid);
|
||||
|
||||
CharacterInfo oldCaptainNameData = Global.WorldMgr.GetCharacterInfo(arena.GetCaptain());
|
||||
if (oldCaptainNameData == null)
|
||||
return false;
|
||||
|
||||
handler.SendSysMessage(CypherStrings.ArenaCaptain, arena.GetName(), arena.GetId(), oldCaptainNameData.Name, target.GetName());
|
||||
if (handler.GetSession() != null)
|
||||
Log.outDebug(LogFilter.Arena, "GameMaster: {0} [GUID: {1}] promoted player: {2} [GUID: {3}] to leader of arena team \"{4}\"[Id: {5}]",
|
||||
handler.GetSession().GetPlayer().GetName(), handler.GetSession().GetPlayer().GetGUID().ToString(), target.GetName(), target.GetGUID().ToString(), arena.GetName(), arena.GetId());
|
||||
else
|
||||
Log.outDebug(LogFilter.Arena, "Console: promoted player: {0} [GUID: {1}] to leader of arena team \"{2}\"[Id: {3}]",
|
||||
target.GetName(), target.GetGUID().ToString(), arena.GetName(), arena.GetId());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("info", RBACPermissions.CommandArenaInfo, true)]
|
||||
static bool HandleArenaInfoCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
if (args.Empty())
|
||||
return false;
|
||||
|
||||
uint teamId = args.NextUInt32();
|
||||
if (teamId == 0)
|
||||
return false;
|
||||
|
||||
ArenaTeam arena = Global.ArenaTeamMgr.GetArenaTeamById(teamId);
|
||||
|
||||
if (arena == null)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.ArenaErrorNotFound, teamId);
|
||||
return false;
|
||||
}
|
||||
|
||||
handler.SendSysMessage(CypherStrings.ArenaInfoHeader, arena.GetName(), arena.GetId(), arena.GetRating(), arena.GetArenaType(), arena.GetArenaType());
|
||||
foreach (var member in arena.GetMembers())
|
||||
handler.SendSysMessage(CypherStrings.ArenaInfoMembers, member.Name, member.Guid, member.PersonalRating, (arena.GetCaptain() == member.Guid ? "- Captain" : ""));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("lookup", RBACPermissions.CommandArenaLookup)]
|
||||
static bool HandleArenaLookupCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
if (args.Empty())
|
||||
return false;
|
||||
|
||||
string name = args.NextString().ToLower();
|
||||
|
||||
bool found = false;
|
||||
foreach (var arena in Global.ArenaTeamMgr.GetArenaTeamMap().Values)
|
||||
{
|
||||
if (arena.GetName() == name)
|
||||
{
|
||||
if (handler.GetSession() != null)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.ArenaLookup, arena.GetName(), arena.GetId(), arena.GetArenaType(), arena.GetArenaType());
|
||||
found = true;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!found)
|
||||
handler.SendSysMessage(CypherStrings.AreanErrorNameNotFound, name);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,429 @@
|
||||
/*
|
||||
* Copyright (C) 2012-2017 CypherCore <http://github.com/CypherCore>
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using Framework.Constants;
|
||||
using Framework.Database;
|
||||
using Framework.IO;
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
namespace Game.Chat.Commands
|
||||
{
|
||||
[CommandGroup("bnetaccount", RBACPermissions.CommandBnetAccount, true)]
|
||||
class BNetAccountCommands
|
||||
{
|
||||
[Command("create", RBACPermissions.CommandBnetAccountCreate, true)]
|
||||
static bool HandleAccountCreateCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
if (args.Empty())
|
||||
return false;
|
||||
|
||||
// Parse the command line arguments
|
||||
string accountName = args.NextString();
|
||||
string password = args.NextString();
|
||||
if (string.IsNullOrEmpty(accountName) || string.IsNullOrEmpty(password))
|
||||
return false;
|
||||
|
||||
if (!accountName.Contains('@'))
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.AccountInvalidBnetName);
|
||||
return false;
|
||||
}
|
||||
|
||||
string createGameAccountParam = args.NextString();
|
||||
bool createGameAccount = true;
|
||||
if (!string.IsNullOrEmpty(createGameAccountParam))
|
||||
createGameAccount = bool.Parse(createGameAccountParam);
|
||||
|
||||
string gameAccountName;
|
||||
switch (Global.BNetAccountMgr.CreateBattlenetAccount(accountName, password, createGameAccount, out gameAccountName))
|
||||
{
|
||||
case AccountOpResult.Ok:
|
||||
if (createGameAccount)
|
||||
handler.SendSysMessage(CypherStrings.AccountCreatedBnetWithGame, accountName, gameAccountName);
|
||||
else
|
||||
handler.SendSysMessage(CypherStrings.AccountCreated, accountName);
|
||||
|
||||
if (handler.GetSession() != null)
|
||||
{
|
||||
Log.outInfo(LogFilter.Player, "Account: {0} (IP: {1}) Character:[{2}] ({3}) created Battle.net account {4}{5}{6}",
|
||||
handler.GetSession().GetAccountId(), handler.GetSession().GetRemoteAddress(), handler.GetSession().GetPlayer().GetName(),
|
||||
handler.GetSession().GetPlayer().GetGUID().ToString(), accountName, createGameAccount ? " with game account " : "", createGameAccount ? gameAccountName : "");
|
||||
}
|
||||
break;
|
||||
case AccountOpResult.NameTooLong:
|
||||
handler.SendSysMessage(CypherStrings.AccountNameTooLong);
|
||||
return false;
|
||||
case AccountOpResult.PassTooLong:
|
||||
handler.SendSysMessage(CypherStrings.AccountPassTooLong);
|
||||
return false;
|
||||
case AccountOpResult.NameAlreadyExist:
|
||||
handler.SendSysMessage(CypherStrings.AccountAlreadyExist);
|
||||
return false;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("gameaccountcreate", RBACPermissions.CommandBnetAccountCreateGame, true)]
|
||||
static bool HandleGameAccountCreateCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
if (args.Empty())
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.CmdSyntax);
|
||||
return false;
|
||||
}
|
||||
|
||||
string bnetAccountName = args.NextString();
|
||||
uint accountId = Global.BNetAccountMgr.GetId(bnetAccountName);
|
||||
if (accountId == 0)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.AccountNotExist, bnetAccountName);
|
||||
return false;
|
||||
}
|
||||
|
||||
byte index = (byte)(Global.BNetAccountMgr.GetMaxIndex(accountId) + 1);
|
||||
string accountName = accountId.ToString() + '#' + index;
|
||||
|
||||
switch (Global.AccountMgr.CreateAccount(accountName, "DUMMY", bnetAccountName, accountId, index))
|
||||
{
|
||||
case AccountOpResult.Ok:
|
||||
handler.SendSysMessage(CypherStrings.AccountCreated, accountName);
|
||||
if (handler.GetSession() != null)
|
||||
{
|
||||
Log.outInfo(LogFilter.Player, "Account: {0} (IP: {1}) Character:[{2}] ({3}) created Account {4} (Email: '{5}')",
|
||||
handler.GetSession().GetAccountId(), handler.GetSession().GetRemoteAddress(), handler.GetSession().GetPlayer().GetName(), handler.GetSession().GetPlayer().GetGUID().ToString(),
|
||||
accountName, bnetAccountName);
|
||||
}
|
||||
break;
|
||||
case AccountOpResult.NameTooLong:
|
||||
handler.SendSysMessage(CypherStrings.AccountNameTooLong);
|
||||
return false;
|
||||
case AccountOpResult.PassTooLong:
|
||||
handler.SendSysMessage(CypherStrings.AccountPassTooLong);
|
||||
return false;
|
||||
case AccountOpResult.NameAlreadyExist:
|
||||
handler.SendSysMessage(CypherStrings.AccountAlreadyExist);
|
||||
return false;
|
||||
case AccountOpResult.DBInternalError:
|
||||
handler.SendSysMessage(CypherStrings.AccountNotCreatedSqlError, accountName);
|
||||
return false;
|
||||
default:
|
||||
handler.SendSysMessage(CypherStrings.AccountNotCreated, accountName);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("link", RBACPermissions.CommandBnetAccountLink, true)]
|
||||
static bool HandleAccountLinkCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
if (args.Empty())
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.CmdSyntax);
|
||||
return false;
|
||||
}
|
||||
|
||||
string bnetAccountName = args.NextString();
|
||||
string gameAccountName = args.NextString();
|
||||
|
||||
switch (Global.BNetAccountMgr.LinkWithGameAccount(bnetAccountName, gameAccountName))
|
||||
{
|
||||
case AccountOpResult.Ok:
|
||||
handler.SendSysMessage(CypherStrings.AccountBnetLinked, bnetAccountName, gameAccountName);
|
||||
break;
|
||||
case AccountOpResult.NameNotExist:
|
||||
handler.SendSysMessage(CypherStrings.AccountOrBnetDoesNotExist, bnetAccountName, gameAccountName);
|
||||
break;
|
||||
case AccountOpResult.BadLink:
|
||||
handler.SendSysMessage( CypherStrings.AccountAlreadyLinked, gameAccountName);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("listgameaccounts", RBACPermissions.CommandBnetAccountListGameAccounts, true)]
|
||||
static bool HandleListGameAccountsCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
if (args.Empty())
|
||||
return false;
|
||||
|
||||
string battlenetAccountName = args.NextString();
|
||||
PreparedStatement stmt = DB.Login.GetPreparedStatement(LoginStatements.SEL_BNET_GAME_ACCOUNT_LIST);
|
||||
stmt.AddValue(0, battlenetAccountName);
|
||||
|
||||
SQLResult accountList = DB.Login.Query(stmt);
|
||||
if (!accountList.IsEmpty())
|
||||
{
|
||||
var formatDisplayName = new Func<string, string>(name =>
|
||||
{
|
||||
int index = name.IndexOf('#');
|
||||
if (index > 0)
|
||||
return "WoW" + name.Substring(++index);
|
||||
else
|
||||
return name;
|
||||
});
|
||||
|
||||
handler.SendSysMessage("----------------------------------------------------");
|
||||
handler.SendSysMessage(CypherStrings.AccountBnetListHeader);
|
||||
handler.SendSysMessage("----------------------------------------------------");
|
||||
do
|
||||
{
|
||||
handler.SendSysMessage("| {10:0} | {1} | {2} |", accountList.Read<uint>(0), accountList.Read<string>(1), formatDisplayName(accountList.Read<string>(1)));
|
||||
} while (accountList.NextRow());
|
||||
handler.SendSysMessage("----------------------------------------------------");
|
||||
}
|
||||
else
|
||||
handler.SendSysMessage(CypherStrings.AccountBnetListNoAccounts, battlenetAccountName);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("password", RBACPermissions.CommandBnetAccountPassword, true)]
|
||||
static bool HandleAccountPasswordCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
// If no args are given at all, we can return false right away.
|
||||
if (args.Empty())
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.CmdSyntax);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Command is supposed to be: .account password [$oldpassword] [$newpassword] [$newpasswordconfirmation] [$emailconfirmation]
|
||||
string oldPassword = args.NextString(); // This extracts [$oldpassword]
|
||||
string newPassword = args.NextString(); // This extracts [$newpassword]
|
||||
string passwordConfirmation = args.NextString(); // This extracts [$newpasswordconfirmation]
|
||||
|
||||
//Is any of those variables missing for any reason ? We return false.
|
||||
if (string.IsNullOrEmpty(oldPassword) || string.IsNullOrEmpty(newPassword) || string.IsNullOrEmpty(passwordConfirmation))
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.CmdSyntax);
|
||||
return false;
|
||||
}
|
||||
|
||||
// We compare the old, saved password to the entered old password - no chance for the unauthorized.
|
||||
if (!Global.BNetAccountMgr.CheckPassword(handler.GetSession().GetBattlenetAccountId(), oldPassword))
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.CommandWrongoldpassword);
|
||||
|
||||
Log.outInfo(LogFilter.Player, "Battle.net account: {0} (IP: {1}) Character:[{2}] ({3}) Tried to change password, but the provided old password is wrong.",
|
||||
handler.GetSession().GetBattlenetAccountId(), handler.GetSession().GetRemoteAddress(), handler.GetSession().GetPlayer().GetName(), handler.GetSession().GetPlayer().GetGUID().ToString());
|
||||
return false;
|
||||
}
|
||||
|
||||
// Making sure that newly entered password is correctly entered.
|
||||
if (newPassword != passwordConfirmation)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.NewPasswordsNotMatch);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Changes password and prints result.
|
||||
AccountOpResult result = Global.BNetAccountMgr.ChangePassword(handler.GetSession().GetBattlenetAccountId(), newPassword);
|
||||
switch (result)
|
||||
{
|
||||
case AccountOpResult.Ok:
|
||||
handler.SendSysMessage(CypherStrings.CommandPassword);
|
||||
Log.outInfo(LogFilter.Player, "Battle.net account: {0} (IP: {1}) Character:[{2}] ({3}) Changed Password.",
|
||||
handler.GetSession().GetBattlenetAccountId(), handler.GetSession().GetRemoteAddress(), handler.GetSession().GetPlayer().GetName(), handler.GetSession().GetPlayer().GetGUID().ToString());
|
||||
break;
|
||||
case AccountOpResult.PassTooLong:
|
||||
handler.SendSysMessage(CypherStrings.PasswordTooLong);
|
||||
return false;
|
||||
default:
|
||||
handler.SendSysMessage(CypherStrings.CommandNotchangepassword);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("unlink", RBACPermissions.CommandBnetAccountUnlink, true)]
|
||||
static bool HandleAccountUnlinkCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
if (args.Empty())
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.CmdSyntax);
|
||||
return false;
|
||||
}
|
||||
|
||||
string gameAccountName = args.NextString();
|
||||
switch (Global.BNetAccountMgr.UnlinkGameAccount(gameAccountName))
|
||||
{
|
||||
case AccountOpResult.Ok:
|
||||
handler.SendSysMessage(CypherStrings.AccountBnetUnlinked, gameAccountName);
|
||||
break;
|
||||
case AccountOpResult.NameNotExist:
|
||||
handler.SendSysMessage(CypherStrings.AccountNotExist, gameAccountName);
|
||||
break;
|
||||
case AccountOpResult.BadLink:
|
||||
handler.SendSysMessage(CypherStrings.AccountBnetNotLinked, gameAccountName);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
[CommandGroup("lock", RBACPermissions.CommandBnetAccount, true)]
|
||||
class LockCommands {
|
||||
[Command("country", RBACPermissions.CommandBnetAccountLockCountry, true)]
|
||||
static bool HandleLockCountryCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
if (args.Empty())
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.UseBol);
|
||||
return false;
|
||||
}
|
||||
|
||||
string param = args.NextString();
|
||||
if (!string.IsNullOrEmpty(param))
|
||||
{
|
||||
if (param == "on")
|
||||
{
|
||||
PreparedStatement stmt = DB.Login.GetPreparedStatement(LoginStatements.SEL_LOGON_COUNTRY);
|
||||
var ipBytes = System.Net.IPAddress.Parse(handler.GetSession().GetRemoteAddress()).GetAddressBytes();
|
||||
Array.Reverse(ipBytes);
|
||||
stmt.AddValue(0, BitConverter.ToUInt32(ipBytes, 0));
|
||||
SQLResult result = DB.Login.Query(stmt);
|
||||
if (!result.IsEmpty())
|
||||
{
|
||||
string country = result.Read<string>(0);
|
||||
stmt = DB.Login.GetPreparedStatement(LoginStatements.UPD_BNET_ACCOUNT_LOCK_CONTRY);
|
||||
stmt.AddValue(0, country);
|
||||
stmt.AddValue(1, handler.GetSession().GetBattlenetAccountId());
|
||||
DB.Login.Execute(stmt);
|
||||
handler.SendSysMessage(CypherStrings.CommandAcclocklocked);
|
||||
}
|
||||
else
|
||||
{
|
||||
handler.SendSysMessage("[IP2NATION] Table empty");
|
||||
Log.outDebug(LogFilter.Server, "[IP2NATION] Table empty");
|
||||
}
|
||||
}
|
||||
else if (param == "off")
|
||||
{
|
||||
PreparedStatement stmt = DB.Login.GetPreparedStatement(LoginStatements.UPD_BNET_ACCOUNT_LOCK_CONTRY);
|
||||
stmt.AddValue(0, "00");
|
||||
stmt.AddValue(1, handler.GetSession().GetBattlenetAccountId());
|
||||
DB.Login.Execute(stmt);
|
||||
handler.SendSysMessage(CypherStrings.CommandAcclockunlocked);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
handler.SendSysMessage(CypherStrings.UseBol);
|
||||
return false;
|
||||
}
|
||||
|
||||
[Command("ip", RBACPermissions.CommandBnetAccountLockIp, true)]
|
||||
static bool HandleLockIpCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
if (args.Empty())
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.UseBol);
|
||||
return false;
|
||||
}
|
||||
|
||||
string param = args.NextString();
|
||||
|
||||
if (!string.IsNullOrEmpty(param))
|
||||
{
|
||||
PreparedStatement stmt = DB.Login.GetPreparedStatement(LoginStatements.UPD_BNET_ACCOUNT_LOCK);
|
||||
if (param == "on")
|
||||
{
|
||||
stmt.AddValue(0, true); // locked
|
||||
handler.SendSysMessage(CypherStrings.CommandAcclocklocked);
|
||||
}
|
||||
else if (param == "off")
|
||||
{
|
||||
stmt.AddValue(0, false); // unlocked
|
||||
handler.SendSysMessage(CypherStrings.CommandAcclockunlocked);
|
||||
}
|
||||
|
||||
stmt.AddValue(1, handler.GetSession().GetBattlenetAccountId());
|
||||
DB.Login.Execute(stmt);
|
||||
return true;
|
||||
}
|
||||
|
||||
handler.SendSysMessage(CypherStrings.UseBol);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
[CommandGroup("set", RBACPermissions.CommandBnetAccountSet, true)]
|
||||
class SetCommands
|
||||
{
|
||||
[Command("password", RBACPermissions.CommandBnetAccountSetPassword, true)]
|
||||
static bool HandleSetPasswordCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
if (args.Empty())
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.CmdSyntax);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Get the command line arguments
|
||||
string accountName = args.NextString();
|
||||
string password = args.NextString();
|
||||
string passwordConfirmation = args.NextString();
|
||||
|
||||
if (string.IsNullOrEmpty(accountName) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(passwordConfirmation))
|
||||
return false;
|
||||
|
||||
uint targetAccountId = Global.BNetAccountMgr.GetId(accountName);
|
||||
if (targetAccountId == 0)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.AccountNotExist, accountName);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (password != passwordConfirmation)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.NewPasswordsNotMatch);
|
||||
return false;
|
||||
}
|
||||
|
||||
AccountOpResult result = Global.BNetAccountMgr.ChangePassword(targetAccountId, password);
|
||||
switch (result)
|
||||
{
|
||||
case AccountOpResult.Ok:
|
||||
handler.SendSysMessage(CypherStrings.CommandPassword);
|
||||
break;
|
||||
case AccountOpResult.NameNotExist:
|
||||
handler.SendSysMessage(CypherStrings.AccountNotExist, accountName);
|
||||
return false;
|
||||
case AccountOpResult.PassTooLong:
|
||||
handler.SendSysMessage(CypherStrings.PasswordTooLong);
|
||||
return false;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,664 @@
|
||||
/*
|
||||
* Copyright (C) 2012-2017 CypherCore <http://github.com/CypherCore>
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using Framework.Constants;
|
||||
using Framework.Database;
|
||||
using Framework.IO;
|
||||
using Game.Entities;
|
||||
using System;
|
||||
using System.Net;
|
||||
|
||||
namespace Game.Chat.Commands
|
||||
{
|
||||
[CommandGroup("ban", RBACPermissions.CommandBan, true)]
|
||||
class BanCommands
|
||||
{
|
||||
[Command("account", RBACPermissions.CommandBanAccount, true)]
|
||||
static bool HandleBanAccountCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
return HandleBanHelper(BanMode.Account, args, handler);
|
||||
}
|
||||
|
||||
[Command("character", RBACPermissions.CommandBanCharacter, true)]
|
||||
static bool HandleBanCharacterCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
if (args.Empty())
|
||||
return false;
|
||||
|
||||
string name = args.NextString();
|
||||
if (string.IsNullOrEmpty(name))
|
||||
return false;
|
||||
|
||||
string durationStr = args.NextString();
|
||||
if (string.IsNullOrEmpty(durationStr))
|
||||
return false;
|
||||
|
||||
uint duration = uint.Parse(durationStr);
|
||||
|
||||
string reasonStr = args.NextString("");
|
||||
if (string.IsNullOrEmpty(reasonStr))
|
||||
return false;
|
||||
|
||||
if (!ObjectManager.NormalizePlayerName(ref name))
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.PlayerNotFound);
|
||||
return false;
|
||||
}
|
||||
|
||||
string author = handler.GetSession() != null ? handler.GetSession().GetPlayerName() : "Server";
|
||||
|
||||
switch (Global.WorldMgr.BanCharacter(name, durationStr, reasonStr, author))
|
||||
{
|
||||
case BanReturn.Success:
|
||||
{
|
||||
if (duration > 0)
|
||||
{
|
||||
if (WorldConfig.GetBoolValue(WorldCfg.ShowBanInWorld))
|
||||
Global.WorldMgr.SendWorldText(CypherStrings.BanCharacterYoubannedmessageWorld, author, name, Time.secsToTimeString(Time.TimeStringToSecs(durationStr), true), reasonStr);
|
||||
else
|
||||
handler.SendSysMessage(CypherStrings.BanYoubanned, name, Time.secsToTimeString(Time.TimeStringToSecs(durationStr), true), reasonStr);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (WorldConfig.GetBoolValue(WorldCfg.ShowBanInWorld))
|
||||
Global.WorldMgr.SendWorldText(CypherStrings.BanCharacterYoupermbannedmessageWorld, author, name, reasonStr);
|
||||
else
|
||||
handler.SendSysMessage(CypherStrings.BanYoupermbanned, name, reasonStr);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case BanReturn.Notfound:
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.BanNotfound, "character", name);
|
||||
|
||||
return false;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("playeraccount", RBACPermissions.CommandBanPlayeraccount, true)]
|
||||
static bool HandleBanAccountByCharCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
return HandleBanHelper(BanMode.Character, args, handler);
|
||||
}
|
||||
|
||||
[Command("ip", RBACPermissions.CommandBanIp, true)]
|
||||
static bool HandleBanIPCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
return HandleBanHelper(BanMode.IP, args, handler);
|
||||
}
|
||||
|
||||
static bool HandleBanHelper(BanMode mode, StringArguments args, CommandHandler handler)
|
||||
{
|
||||
if (args.Empty())
|
||||
return false;
|
||||
|
||||
string nameOrIP = args.NextString();
|
||||
if (string.IsNullOrEmpty(nameOrIP))
|
||||
return false;
|
||||
|
||||
uint duration;
|
||||
string durationStr = args.NextString();
|
||||
if (string.IsNullOrEmpty(durationStr) || !uint.TryParse(durationStr, out duration))
|
||||
return false;
|
||||
|
||||
string reasonStr = args.NextString("");
|
||||
if (string.IsNullOrEmpty(reasonStr))
|
||||
return false;
|
||||
|
||||
switch (mode)
|
||||
{
|
||||
case BanMode.Character:
|
||||
if (!ObjectManager.NormalizePlayerName(ref nameOrIP))
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.PlayerNotFound);
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case BanMode.IP:
|
||||
IPAddress address;
|
||||
if (!IPAddress.TryParse(nameOrIP, out address))
|
||||
return false;
|
||||
break;
|
||||
}
|
||||
|
||||
string author = handler.GetSession() ? handler.GetSession().GetPlayerName() : "Server";
|
||||
switch (Global.WorldMgr.BanAccount(mode, nameOrIP, durationStr, reasonStr, author))
|
||||
{
|
||||
case BanReturn.Success:
|
||||
if (uint.Parse(durationStr) > 0)
|
||||
{
|
||||
if (WorldConfig.GetBoolValue(WorldCfg.ShowBanInWorld))
|
||||
Global.WorldMgr.SendWorldText(CypherStrings.BanAccountYoubannedmessageWorld, author, nameOrIP, Time.secsToTimeString(Time.TimeStringToSecs(durationStr)).ToString(), reasonStr);
|
||||
else
|
||||
handler.SendSysMessage(CypherStrings.BanYoubanned, nameOrIP, Time.secsToTimeString(Time.TimeStringToSecs(durationStr), true), reasonStr);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (WorldConfig.GetBoolValue(WorldCfg.ShowBanInWorld))
|
||||
Global.WorldMgr.SendWorldText(CypherStrings.BanAccountYoupermbannedmessageWorld, author, nameOrIP, reasonStr);
|
||||
else
|
||||
handler.SendSysMessage(CypherStrings.BanYoupermbanned, nameOrIP, reasonStr);
|
||||
}
|
||||
break;
|
||||
case BanReturn.SyntaxError:
|
||||
return false;
|
||||
case BanReturn.Notfound:
|
||||
switch (mode)
|
||||
{
|
||||
default:
|
||||
handler.SendSysMessage(CypherStrings.BanNotfound, "account", nameOrIP);
|
||||
break;
|
||||
case BanMode.Character:
|
||||
handler.SendSysMessage(CypherStrings.BanNotfound, "character", nameOrIP);
|
||||
break;
|
||||
case BanMode.IP:
|
||||
handler.SendSysMessage(CypherStrings.BanNotfound, "ip", nameOrIP);
|
||||
break;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
[CommandGroup("baninfo", RBACPermissions.CommandBaninfo, true)]
|
||||
class BanInfoCommands
|
||||
{
|
||||
[Command("account", RBACPermissions.CommandBaninfoAccount, true)]
|
||||
static bool HandleBanInfoAccountCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
if (args.Empty())
|
||||
return false;
|
||||
|
||||
string accountName = args.NextString("");
|
||||
if (string.IsNullOrEmpty(accountName))
|
||||
return false;
|
||||
|
||||
uint accountId = Global.AccountMgr.GetId(accountName);
|
||||
if (accountId == 0)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.AccountNotExist, accountName);
|
||||
return true;
|
||||
}
|
||||
|
||||
return HandleBanInfoHelper(accountId, accountName, handler);
|
||||
}
|
||||
|
||||
[Command("character", RBACPermissions.CommandBaninfoCharacter, true)]
|
||||
static bool HandleBanInfoCharacterCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
if (args.Empty())
|
||||
return false;
|
||||
|
||||
string name = args.NextString();
|
||||
Player target = Global.ObjAccessor.FindPlayerByName(name);
|
||||
ObjectGuid targetGuid;
|
||||
|
||||
if (!target)
|
||||
{
|
||||
targetGuid = ObjectManager.GetPlayerGUIDByName(name);
|
||||
if (targetGuid.IsEmpty())
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.BaninfoNocharacter);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
targetGuid = target.GetGUID();
|
||||
|
||||
PreparedStatement stmt = DB.Characters.GetPreparedStatement(CharStatements.SEL_BANINFO);
|
||||
stmt.AddValue(0, targetGuid.GetCounter());
|
||||
SQLResult result = DB.Characters.Query(stmt);
|
||||
if (result.IsEmpty())
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.CharNotBanned, name);
|
||||
return true;
|
||||
}
|
||||
|
||||
handler.SendSysMessage(CypherStrings.BaninfoBanhistory, name);
|
||||
do
|
||||
{
|
||||
long unbanDate = result.Read<uint>(3);
|
||||
bool active = false;
|
||||
if (result.Read<bool>(2) && (result.Read<uint>(1) == 0 || unbanDate >= Time.UnixTime))
|
||||
active = true;
|
||||
bool permanent = (result.Read<uint>(1) == 0);
|
||||
string banTime = permanent ? handler.GetCypherString(CypherStrings.BaninfoInfinite) : Time.secsToTimeString(result.Read<uint>(1), true);
|
||||
handler.SendSysMessage(CypherStrings.BaninfoHistoryentry, Time.UnixTimeToDateTime(result.Read<uint>(0)).ToShortTimeString(), banTime,
|
||||
active ? handler.GetCypherString(CypherStrings.Yes) : handler.GetCypherString(CypherStrings.No), result.Read<string>(4), result.Read<string>(5));
|
||||
}
|
||||
while (result.NextRow());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("ip", RBACPermissions.CommandBaninfoIp, true)]
|
||||
static bool HandleBanInfoIPCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
if (args.Empty())
|
||||
return false;
|
||||
|
||||
string ip = args.NextString("");
|
||||
if (string.IsNullOrEmpty(ip))
|
||||
return false;
|
||||
|
||||
SQLResult result = DB.Login.Query("SELECT ip, FROM_UNIXTIME(bandate), FROM_UNIXTIME(unbandate), unbandate-UNIX_TIMESTAMP(), banreason, bannedby, unbandate-bandate FROM ip_banned WHERE ip = '{0}'", ip);
|
||||
if (result.IsEmpty())
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.BaninfoNoip);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool permanent = result.Read<ulong>(6) == 0;
|
||||
handler.SendSysMessage(CypherStrings.BaninfoIpentry, result.Read<string>(0), result.Read<string>(1), permanent ? handler.GetCypherString( CypherStrings.BaninfoNever) : result.Read<string>(2),
|
||||
permanent ? handler.GetCypherString( CypherStrings.BaninfoInfinite) : Time.secsToTimeString(result.Read<ulong>(3), true), result.Read<string>(4), result.Read<string>(5));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool HandleBanInfoHelper(uint accountId, string accountName, CommandHandler handler)
|
||||
{
|
||||
SQLResult result = DB.Login.Query("SELECT FROM_UNIXTIME(bandate), unbandate-bandate, active, unbandate, banreason, bannedby FROM account_banned WHERE id = '{0}' ORDER BY bandate ASC", accountId);
|
||||
if (result.IsEmpty())
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.BaninfoNoaccountban, accountName);
|
||||
return true;
|
||||
}
|
||||
|
||||
handler.SendSysMessage(CypherStrings.BaninfoBanhistory, accountName);
|
||||
do
|
||||
{
|
||||
long unbanDate = result.Read<uint>(3);
|
||||
bool active = false;
|
||||
if (result.Read<bool>(2) && (result.Read<ulong>(1) == 0 || unbanDate >= Time.UnixTime))
|
||||
active = true;
|
||||
bool permanent = (result.Read<ulong>(1) == 0);
|
||||
string banTime = permanent ? handler.GetCypherString(CypherStrings.BaninfoInfinite) : Time.secsToTimeString(result.Read<ulong>(1), true);
|
||||
handler.SendSysMessage(CypherStrings.BaninfoHistoryentry,
|
||||
result.Read<string>(0), banTime, active ? handler.GetCypherString(CypherStrings.Yes) : handler.GetCypherString(CypherStrings.No), result.Read<string>(4), result.Read<string>(5));
|
||||
}
|
||||
while (result.NextRow());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[CommandGroup("banlist", RBACPermissions.CommandBanlist, true)]
|
||||
class BanListCommands
|
||||
{
|
||||
[Command("account", RBACPermissions.CommandBanlistAccount, true)]
|
||||
static bool HandleBanListAccountCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
PreparedStatement stmt = DB.Login.GetPreparedStatement(LoginStatements.DEL_EXPIRED_IP_BANS);
|
||||
DB.Login.Execute(stmt);
|
||||
|
||||
string filterStr = args.NextString();
|
||||
string filter = !string.IsNullOrEmpty(filterStr) ? filterStr : "";
|
||||
|
||||
SQLResult result;
|
||||
if (string.IsNullOrEmpty(filter))
|
||||
{
|
||||
stmt = DB.Login.GetPreparedStatement(LoginStatements.SEL_ACCOUNT_BANNED_ALL);
|
||||
result = DB.Login.Query(stmt);
|
||||
}
|
||||
else
|
||||
{
|
||||
stmt = DB.Login.GetPreparedStatement(LoginStatements.SEL_ACCOUNT_BANNED_BY_USERNAME);
|
||||
stmt.AddValue(0, filter);
|
||||
result = DB.Login.Query(stmt);
|
||||
}
|
||||
|
||||
if (result.IsEmpty())
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.BanlistNoaccount);
|
||||
return true;
|
||||
}
|
||||
|
||||
return HandleBanListHelper(result, handler);
|
||||
}
|
||||
|
||||
[Command("character", RBACPermissions.CommandBanlistCharacter, true)]
|
||||
static bool HandleBanListCharacterCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
if (args.Empty())
|
||||
return false;
|
||||
|
||||
string filter = args.NextString();
|
||||
if (string.IsNullOrEmpty(filter))
|
||||
return false;
|
||||
|
||||
PreparedStatement stmt = DB.Characters.GetPreparedStatement(CharStatements.SEL_GUID_BY_NAME_FILTER);
|
||||
stmt.AddValue(0, filter);
|
||||
SQLResult result = DB.Characters.Query(stmt);
|
||||
if (result.IsEmpty())
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.BanlistNocharacter);
|
||||
return true;
|
||||
}
|
||||
|
||||
handler.SendSysMessage(CypherStrings.BanlistMatchingcharacter);
|
||||
|
||||
// Chat short output
|
||||
if (handler.GetSession())
|
||||
{
|
||||
do
|
||||
{
|
||||
|
||||
PreparedStatement stmt2 = DB.Characters.GetPreparedStatement(CharStatements.SEL_BANNED_NAME);
|
||||
stmt2.AddValue(0, result.Read<ulong>(0));
|
||||
SQLResult banResult = DB.Characters.Query(stmt2);
|
||||
if (!banResult.IsEmpty())
|
||||
handler.SendSysMessage(banResult.Read<string>(0));
|
||||
}
|
||||
while (result.NextRow());
|
||||
}
|
||||
// Console wide output
|
||||
else
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.BanlistCharacters);
|
||||
handler.SendSysMessage(" =============================================================================== ");
|
||||
handler.SendSysMessage(CypherStrings.BanlistCharactersHeader);
|
||||
do
|
||||
{
|
||||
handler.SendSysMessage("-------------------------------------------------------------------------------");
|
||||
|
||||
string char_name = result.Read<string>(1);
|
||||
|
||||
PreparedStatement stmt2 = DB.Characters.GetPreparedStatement(CharStatements.SEL_BANINFO_LIST);
|
||||
stmt2.AddValue(0, result.Read<ulong>(0));
|
||||
SQLResult banInfo = DB.Characters.Query(stmt2);
|
||||
if (!banInfo.IsEmpty())
|
||||
{
|
||||
do
|
||||
{
|
||||
long timeBan = banInfo.Read<uint>(0);
|
||||
DateTime tmBan = Time.UnixTimeToDateTime(timeBan);
|
||||
string bannedby = banInfo.Read<string>(2).Substring(0, 15);
|
||||
string banreason = banInfo.Read<string>(3).Substring(0, 15);
|
||||
|
||||
if (banInfo.Read<uint>(0) == banInfo.Read<uint>(1))
|
||||
{
|
||||
handler.SendSysMessage("|{0}|{1:D2}-{2:D2}-{3:D2} {4:D2}:{5:D2}| permanent |{6}|{7}|",
|
||||
char_name, tmBan.Year % 100, tmBan.Month + 1, tmBan.Day, tmBan.Hour, tmBan.Minute,
|
||||
bannedby, banreason);
|
||||
}
|
||||
else
|
||||
{
|
||||
long timeUnban = banInfo.Read<uint>(1);
|
||||
DateTime tmUnban = Time.UnixTimeToDateTime(timeUnban);
|
||||
handler.SendSysMessage("|{0}|{1:D2}-{2:D2}-{3:D2} {4:D2}:{5:D2}|{6:D2}-{7:D2}-{8:D2} {9:D2}:{10:D2}|{11}|{12}|",
|
||||
char_name, tmBan.Year % 100, tmBan.Month + 1, tmBan.Day, tmBan.Hour, tmBan.Minute,
|
||||
tmUnban.Year % 100, tmUnban.Month + 1, tmUnban.Day, tmUnban.Hour, tmUnban.Minute,
|
||||
bannedby, banreason);
|
||||
}
|
||||
}
|
||||
while (banInfo.NextRow());
|
||||
}
|
||||
}
|
||||
while (result.NextRow());
|
||||
handler.SendSysMessage(" =============================================================================== ");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("ip", RBACPermissions.CommandBanlistIp, true)]
|
||||
static bool HandleBanListIPCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
PreparedStatement stmt = DB.Login.GetPreparedStatement(LoginStatements.DEL_EXPIRED_IP_BANS);
|
||||
DB.Login.Execute(stmt);
|
||||
|
||||
string filterStr = args.NextString();
|
||||
string filter = !string.IsNullOrEmpty(filterStr) ? filterStr : "";
|
||||
|
||||
SQLResult result;
|
||||
|
||||
if (string.IsNullOrEmpty(filter))
|
||||
{
|
||||
stmt = DB.Login.GetPreparedStatement(LoginStatements.SEL_IP_BANNED_ALL);
|
||||
result = DB.Login.Query(stmt);
|
||||
}
|
||||
else
|
||||
{
|
||||
stmt = DB.Login.GetPreparedStatement(LoginStatements.SEL_IP_BANNED_BY_IP);
|
||||
stmt.AddValue(0, filter);
|
||||
result = DB.Login.Query(stmt);
|
||||
}
|
||||
|
||||
if (result.IsEmpty())
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.BanlistNoip);
|
||||
return true;
|
||||
}
|
||||
|
||||
handler.SendSysMessage(CypherStrings.BanlistMatchingip);
|
||||
// Chat short output
|
||||
if (handler.GetSession())
|
||||
{
|
||||
do
|
||||
{
|
||||
handler.SendSysMessage("{0}", result.Read<string>(0));
|
||||
}
|
||||
while (result.NextRow());
|
||||
}
|
||||
// Console wide output
|
||||
else
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.BanlistIps);
|
||||
handler.SendSysMessage(" ===============================================================================");
|
||||
handler.SendSysMessage(CypherStrings.BanlistIpsHeader);
|
||||
do
|
||||
{
|
||||
handler.SendSysMessage("-------------------------------------------------------------------------------");
|
||||
|
||||
long timeBan = result.Read<uint>(1);
|
||||
DateTime tmBan = Time.UnixTimeToDateTime(timeBan);
|
||||
string bannedby = result.Read<string>(3).Substring(0, 15);
|
||||
string banreason = result.Read<string>(4).Substring(0, 15);
|
||||
|
||||
if (result.Read<uint>(1) == result.Read<uint>(2))
|
||||
{
|
||||
handler.SendSysMessage("|{0}|{1:D2}-{2:D2}-{3:D2} {4:D2}:{5:D2}| permanent |{6}|{7}|",
|
||||
result.Read<string>(0), tmBan.Year % 100, tmBan.Month + 1, tmBan.Day, tmBan.Hour, tmBan.Minute,
|
||||
bannedby, banreason);
|
||||
}
|
||||
else
|
||||
{
|
||||
long timeUnban = result.Read<uint>(2);
|
||||
DateTime tmUnban;
|
||||
tmUnban = Time.UnixTimeToDateTime(timeUnban);
|
||||
handler.SendSysMessage("|{0}|{1:D2}-{2:D2}-{3:D2} {4:D2}:{5:D2}|{6:D2}-{7:D2}-{8:D2} {9:D2}:{10:D2}|{11}|{12}|",
|
||||
result.Read<string>(0), tmBan.Year % 100, tmBan.Month + 1, tmBan.Day, tmBan.Hour, tmBan.Minute,
|
||||
tmUnban.Year % 100, tmUnban.Month + 1, tmUnban.Day, tmUnban.Hour, tmUnban.Minute,
|
||||
bannedby, banreason);
|
||||
}
|
||||
}
|
||||
while (result.NextRow());
|
||||
|
||||
handler.SendSysMessage(" ===============================================================================");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool HandleBanListHelper(SQLResult result, CommandHandler handler)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.BanlistMatchingaccount);
|
||||
|
||||
// Chat short output
|
||||
if (handler.GetSession())
|
||||
{
|
||||
do
|
||||
{
|
||||
|
||||
uint accountid = result.Read<uint>(0);
|
||||
|
||||
SQLResult banResult = DB.Login.Query("SELECT account.username FROM account, account_banned WHERE account_banned.id='{0}' AND account_banned.id=account.id", accountid);
|
||||
if (!banResult.IsEmpty())
|
||||
{
|
||||
handler.SendSysMessage(banResult.Read<string>(0));
|
||||
}
|
||||
}
|
||||
while (result.NextRow());
|
||||
}
|
||||
// Console wide output
|
||||
else
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.BanlistAccounts);
|
||||
handler.SendSysMessage(" ===============================================================================");
|
||||
handler.SendSysMessage(CypherStrings.BanlistAccountsHeader);
|
||||
do
|
||||
{
|
||||
handler.SendSysMessage("-------------------------------------------------------------------------------");
|
||||
|
||||
uint accountId = result.Read<uint>(0);
|
||||
|
||||
string accountName;
|
||||
|
||||
// "account" case, name can be get in same query
|
||||
if (result.GetRowCount() > 1)
|
||||
accountName = result.Read<string>(1);
|
||||
// "character" case, name need extract from another DB
|
||||
else
|
||||
Global.AccountMgr.GetName(accountId, out accountName);
|
||||
|
||||
// No SQL injection. id is uint32.
|
||||
SQLResult banInfo = DB.Login.Query("SELECT bandate, unbandate, bannedby, banreason FROM account_banned WHERE id = {0} ORDER BY unbandate", accountId);
|
||||
if (!banInfo.IsEmpty())
|
||||
{
|
||||
do
|
||||
{
|
||||
long timeBan = banInfo.Read<uint>(0);
|
||||
DateTime tmBan;
|
||||
tmBan = Time.UnixTimeToDateTime(timeBan);
|
||||
string bannedby = banInfo.Read<string>(2).Substring(0, 15);
|
||||
string banreason = banInfo.Read<string>(3).Substring(0, 15);
|
||||
|
||||
if (banInfo.Read<uint>(0) == banInfo.Read<uint>(1))
|
||||
{
|
||||
handler.SendSysMessage("|{0}|{1:D2}-{2:D2}-{3:D2} {4:D2}:{5:D2}| permanent |{6}|{7}|",
|
||||
accountName.Substring(0, 15), tmBan.Year % 100, tmBan.Month + 1, tmBan.Day, tmBan.Hour, tmBan.Minute,
|
||||
bannedby, banreason);
|
||||
}
|
||||
else
|
||||
{
|
||||
long timeUnban = banInfo.Read <uint>(1);
|
||||
DateTime tmUnban;
|
||||
tmUnban = Time.UnixTimeToDateTime(timeUnban);
|
||||
handler.SendSysMessage("|{0}|{1:D2}-{2:D2}-{3:D2} {4:D2}:{5:D2}|{6:D2}-{7:D2}-{8:D2} {9:D2}:{10:D2}|{11}|{12}|",
|
||||
accountName.Substring(0, 15), tmBan.Year % 100, tmBan.Month + 1, tmBan.Day, tmBan.Hour, tmBan.Minute,
|
||||
tmUnban.Year % 100, tmUnban.Month + 1, tmUnban.Day, tmUnban.Hour, tmUnban.Minute,
|
||||
bannedby, banreason);
|
||||
}
|
||||
}
|
||||
while (banInfo.NextRow());
|
||||
}
|
||||
}
|
||||
while (result.NextRow());
|
||||
|
||||
handler.SendSysMessage(" ===============================================================================");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
[CommandGroup("unban", RBACPermissions.CommandUnban, true)]
|
||||
class UnBanCommands
|
||||
{
|
||||
[Command("account", RBACPermissions.CommandUnbanAccount, true)]
|
||||
static bool HandleUnBanAccountCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
return HandleUnBanHelper(BanMode.Account, args, handler);
|
||||
}
|
||||
|
||||
[Command("character", RBACPermissions.CommandUnbanCharacter, true)]
|
||||
static bool HandleUnBanCharacterCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
if (args.Empty())
|
||||
return false;
|
||||
|
||||
string name = args.NextString();
|
||||
if (!ObjectManager.NormalizePlayerName(ref name))
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.PlayerNotFound);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!Global.WorldMgr.RemoveBanCharacter(name))
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.PlayerNotFound);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("playeraccount", RBACPermissions.CommandUnbanPlayeraccount, true)]
|
||||
static bool HandleUnBanAccountByCharCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
return HandleUnBanHelper(BanMode.Character, args, handler);
|
||||
}
|
||||
|
||||
[Command("ip", RBACPermissions.CommandUnbanIp, true)]
|
||||
static bool HandleUnBanIPCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
return HandleUnBanHelper(BanMode.IP, args, handler);
|
||||
}
|
||||
|
||||
static bool HandleUnBanHelper(BanMode mode, StringArguments args, CommandHandler handler)
|
||||
{
|
||||
if (args.Empty())
|
||||
return false;
|
||||
|
||||
string nameOrIP = args.NextString();
|
||||
if (string.IsNullOrEmpty(nameOrIP))
|
||||
return false;
|
||||
|
||||
switch (mode)
|
||||
{
|
||||
case BanMode.Character:
|
||||
if (!ObjectManager.NormalizePlayerName(ref nameOrIP))
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.PlayerNotFound);
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case BanMode.IP:
|
||||
IPAddress address;
|
||||
if (!IPAddress.TryParse(nameOrIP, out address))
|
||||
return false;
|
||||
break;
|
||||
}
|
||||
|
||||
if (Global.WorldMgr.RemoveBanAccount(mode, nameOrIP))
|
||||
handler.SendSysMessage(CypherStrings.UnbanUnbanned, nameOrIP);
|
||||
else
|
||||
handler.SendSysMessage(CypherStrings.UnbanError, nameOrIP);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
/*
|
||||
* Copyright (C) 2012-2017 CypherCore <http://github.com/CypherCore>
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using Framework.Constants;
|
||||
using Framework.IO;
|
||||
using Game.BattleFields;
|
||||
|
||||
namespace Game.Chat
|
||||
{
|
||||
[CommandGroup("bf", RBACPermissions.CommandBf)]
|
||||
class BattleFieldCommands
|
||||
{
|
||||
[Command("enable", RBACPermissions.CommandBfEnable)]
|
||||
static bool HandleBattlefieldEnable(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
uint battleid = args.NextUInt32();
|
||||
BattleField bf = Global.BattleFieldMgr.GetBattlefieldByBattleId(battleid);
|
||||
|
||||
if (bf == null)
|
||||
return false;
|
||||
|
||||
if (bf.IsEnabled())
|
||||
{
|
||||
bf.ToggleBattlefield(false);
|
||||
if (battleid == 1)
|
||||
handler.SendGlobalGMSysMessage("Wintergrasp is disabled");
|
||||
}
|
||||
else
|
||||
{
|
||||
bf.ToggleBattlefield(true);
|
||||
if (battleid == 1)
|
||||
handler.SendGlobalGMSysMessage("Wintergrasp is enabled");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("start", RBACPermissions.CommandBfStart)]
|
||||
static bool HandleBattlefieldStart(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
uint battleid = args.NextUInt32();
|
||||
BattleField bf = Global.BattleFieldMgr.GetBattlefieldByBattleId(battleid);
|
||||
|
||||
if (bf == null)
|
||||
return false;
|
||||
|
||||
bf.StartBattle();
|
||||
|
||||
if (battleid == 1)
|
||||
handler.SendGlobalGMSysMessage("Wintergrasp (Command start used)");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("stop", RBACPermissions.CommandBfStop)]
|
||||
static bool HandleBattlefieldEnd(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
uint battleid = args.NextUInt32();
|
||||
BattleField bf = Global.BattleFieldMgr.GetBattlefieldByBattleId(battleid);
|
||||
|
||||
if (bf == null)
|
||||
return false;
|
||||
|
||||
bf.EndBattle(true);
|
||||
|
||||
if (battleid == 1)
|
||||
handler.SendGlobalGMSysMessage("Wintergrasp (Command stop used)");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("switch", RBACPermissions.CommandBfSwitch)]
|
||||
static bool HandleBattlefieldSwitch(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
uint battleid = args.NextUInt32();
|
||||
BattleField bf = Global.BattleFieldMgr.GetBattlefieldByBattleId(battleid);
|
||||
|
||||
if (bf == null)
|
||||
return false;
|
||||
|
||||
bf.EndBattle(false);
|
||||
if (battleid == 1)
|
||||
handler.SendGlobalGMSysMessage("Wintergrasp (Command switch used)");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("timer", RBACPermissions.CommandBfTimer)]
|
||||
static bool HandleBattlefieldTimer(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
uint battleid = args.NextUInt32();
|
||||
BattleField bf = Global.BattleFieldMgr.GetBattlefieldByBattleId(battleid);
|
||||
|
||||
if (bf == null)
|
||||
return false;
|
||||
|
||||
uint time = args.NextUInt32();
|
||||
|
||||
bf.SetTimer(time * Time.InMilliseconds);
|
||||
bf.SendInitWorldStatesToAll();
|
||||
if (battleid == 1)
|
||||
handler.SendGlobalGMSysMessage("Wintergrasp (Command timer used)");
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,248 @@
|
||||
/*
|
||||
* Copyright (C) 2012-2017 CypherCore <http://github.com/CypherCore>
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using Framework.Constants;
|
||||
using Framework.IO;
|
||||
using Game.Entities;
|
||||
using Game.Spells;
|
||||
|
||||
namespace Game.Chat
|
||||
{
|
||||
[CommandGroup("cast", RBACPermissions.CommandCast)]
|
||||
class CastCommands
|
||||
{
|
||||
[Command("", RBACPermissions.CommandCast)]
|
||||
static bool HandleCastCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
if (args.Empty())
|
||||
return false;
|
||||
|
||||
Unit target = handler.getSelectedUnit();
|
||||
if (!target)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.SelectCharOrCreature);
|
||||
return false;
|
||||
}
|
||||
|
||||
// number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
|
||||
uint spellId = handler.extractSpellIdFromLink(args);
|
||||
if (spellId == 0)
|
||||
return false;
|
||||
|
||||
if (!CheckSpellExistsAndIsValid(handler, spellId))
|
||||
return false;
|
||||
|
||||
string triggeredStr = args.NextString();
|
||||
if (!string.IsNullOrEmpty(triggeredStr))
|
||||
{
|
||||
if (triggeredStr != "triggered")
|
||||
return false;
|
||||
}
|
||||
|
||||
bool triggered = (triggeredStr != null);
|
||||
|
||||
handler.GetSession().GetPlayer().CastSpell(target, spellId, triggered);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("back", RBACPermissions.CommandCastBack)]
|
||||
static bool HandleCastBackCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
Creature caster = handler.getSelectedCreature();
|
||||
if (!caster)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.SelectCharOrCreature);
|
||||
return false;
|
||||
}
|
||||
|
||||
// number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
|
||||
uint spellId = handler.extractSpellIdFromLink(args);
|
||||
if (spellId == 0)
|
||||
return false;
|
||||
|
||||
if (CheckSpellExistsAndIsValid(handler, spellId))
|
||||
return false;
|
||||
|
||||
string triggeredStr = args.NextString();
|
||||
if (!string.IsNullOrEmpty(triggeredStr))
|
||||
{
|
||||
if (triggeredStr != "triggered")
|
||||
return false;
|
||||
}
|
||||
|
||||
bool triggered = (triggeredStr != null);
|
||||
|
||||
caster.CastSpell(handler.GetSession().GetPlayer(), spellId, triggered);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("dist", RBACPermissions.CommandCastDist)]
|
||||
static bool HandleCastDistCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
if (args.Empty())
|
||||
return false;
|
||||
|
||||
// number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
|
||||
uint spellId = handler.extractSpellIdFromLink(args);
|
||||
if (spellId == 0)
|
||||
return false;
|
||||
|
||||
if (CheckSpellExistsAndIsValid(handler, spellId))
|
||||
return false;
|
||||
|
||||
float dist = args.NextSingle();
|
||||
|
||||
string triggeredStr = args.NextString();
|
||||
if (!string.IsNullOrEmpty(triggeredStr))
|
||||
{
|
||||
if (triggeredStr != "triggered")
|
||||
return false;
|
||||
}
|
||||
|
||||
bool triggered = (triggeredStr != null);
|
||||
|
||||
float x, y, z;
|
||||
handler.GetSession().GetPlayer().GetClosePoint(out x, out y, out z, dist);
|
||||
|
||||
handler.GetSession().GetPlayer().CastSpell(x, y, z, spellId, triggered);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("self", RBACPermissions.CommandCastSelf)]
|
||||
static bool HandleCastSelfCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
if (args.Empty())
|
||||
return false;
|
||||
|
||||
Unit target = handler.getSelectedUnit();
|
||||
if (!target)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.SelectCharOrCreature);
|
||||
return false;
|
||||
}
|
||||
|
||||
// number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
|
||||
uint spellId = handler.extractSpellIdFromLink(args);
|
||||
if (spellId == 0)
|
||||
return false;
|
||||
|
||||
if (CheckSpellExistsAndIsValid(handler, spellId))
|
||||
return false;
|
||||
|
||||
target.CastSpell(target, spellId, false);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("target", RBACPermissions.CommandCastTarget)]
|
||||
static bool HandleCastTargetCommad(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
Creature caster = handler.getSelectedCreature();
|
||||
if (!caster)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.SelectCharOrCreature);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!caster.GetVictim())
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.SelectedTargetNotHaveVictim);
|
||||
return false;
|
||||
}
|
||||
|
||||
// number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
|
||||
uint spellId = handler.extractSpellIdFromLink(args);
|
||||
if (spellId == 0)
|
||||
return false;
|
||||
|
||||
if (CheckSpellExistsAndIsValid(handler, spellId))
|
||||
return false;
|
||||
|
||||
string triggeredStr = args.NextString();
|
||||
if (!string.IsNullOrEmpty(triggeredStr))
|
||||
{
|
||||
if (triggeredStr != "triggered")
|
||||
return false;
|
||||
}
|
||||
|
||||
bool triggered = (triggeredStr != null);
|
||||
|
||||
caster.CastSpell(caster.GetVictim(), spellId, triggered);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("dest", RBACPermissions.CommandCastDest)]
|
||||
static bool HandleCastDestCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
Unit caster = handler.getSelectedUnit();
|
||||
if (!caster)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.SelectCharOrCreature);
|
||||
return false;
|
||||
}
|
||||
|
||||
// number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
|
||||
uint spellId = handler.extractSpellIdFromLink(args);
|
||||
if (spellId == 0)
|
||||
return false;
|
||||
|
||||
if (CheckSpellExistsAndIsValid(handler, spellId))
|
||||
return false;
|
||||
|
||||
float x = args.NextSingle();
|
||||
float y = args.NextSingle();
|
||||
float z = args.NextSingle();
|
||||
|
||||
if (x == 0f || y == 0f || z == 0f)
|
||||
return false;
|
||||
|
||||
string triggeredStr = args.NextString();
|
||||
if (!string.IsNullOrEmpty(triggeredStr))
|
||||
{
|
||||
if (triggeredStr != "triggered")
|
||||
return false;
|
||||
}
|
||||
|
||||
bool triggered = (triggeredStr != null);
|
||||
|
||||
caster.CastSpell(x, y, z, spellId, triggered);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool CheckSpellExistsAndIsValid(CommandHandler handler, uint spellId)
|
||||
{
|
||||
SpellInfo spellInfo = Global.SpellMgr.GetSpellInfo(spellId);
|
||||
if (spellInfo == null)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.CommandNospellfound);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!Global.SpellMgr.IsSpellValid(spellInfo, handler.GetPlayer()))
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.CommandSpellBroken, spellId);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,897 @@
|
||||
/*
|
||||
* Copyright (C) 2012-2017 CypherCore <http://github.com/CypherCore>
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using Framework.Constants;
|
||||
using Framework.Database;
|
||||
using Framework.IO;
|
||||
using Game.DataStorage;
|
||||
using Game.Entities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Game.Chat
|
||||
{
|
||||
[CommandGroup("character", RBACPermissions.CommandCharacter, true)]
|
||||
class CharacterCommands
|
||||
{
|
||||
[Command("titles", RBACPermissions.CommandCharacterTitles, true)]
|
||||
static bool HandleCharacterTitlesCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
if (args.Empty())
|
||||
return false;
|
||||
|
||||
Player target;
|
||||
if (!handler.extractPlayerTarget(args, out target))
|
||||
return false;
|
||||
|
||||
LocaleConstant loc = handler.GetSessionDbcLocale();
|
||||
string targetName = target.GetName();
|
||||
string knownStr = handler.GetCypherString(CypherStrings.Known);
|
||||
|
||||
// Search in CharTitles.dbc
|
||||
foreach (var titleInfo in CliDB.CharTitlesStorage.Values)
|
||||
{
|
||||
if (target.HasTitle(titleInfo))
|
||||
{
|
||||
string name = (target.GetGender() == Gender.Male ? titleInfo.NameMale : titleInfo.NameFemale)[handler.GetSessionDbcLocale()];
|
||||
if (string.IsNullOrEmpty(name))
|
||||
continue;
|
||||
|
||||
string activeStr = target.GetUInt32Value(PlayerFields.ChosenTitle) == titleInfo.MaskID
|
||||
? handler.GetCypherString(CypherStrings.Active) : "";
|
||||
|
||||
string titleNameStr = string.Format(name.ConvertFormatSyntax(), targetName);
|
||||
|
||||
// send title in "id (idx:idx) - [namedlink locale]" format
|
||||
if (handler.GetSession() != null)
|
||||
handler.SendSysMessage(CypherStrings.TitleListChat, titleInfo.Id, titleInfo.MaskID, titleInfo.Id, titleNameStr, loc, knownStr, activeStr);
|
||||
else
|
||||
handler.SendSysMessage(CypherStrings.TitleListConsole, titleInfo.Id, titleInfo.MaskID, name, loc, knownStr, activeStr);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//rename characters
|
||||
[Command("rename", RBACPermissions.CommandCharacterRename, true)]
|
||||
static bool HandleCharacterRenameCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
Player target;
|
||||
ObjectGuid targetGuid;
|
||||
string targetName;
|
||||
if (!handler.extractPlayerTarget(args, out target, out targetGuid, out targetName))
|
||||
return false;
|
||||
|
||||
string newNameStr = args.NextString();
|
||||
|
||||
if (!string.IsNullOrEmpty(newNameStr))
|
||||
{
|
||||
string playerOldName;
|
||||
string newName = newNameStr;
|
||||
|
||||
if (target)
|
||||
{
|
||||
// check online security
|
||||
if (handler.HasLowerSecurity(target, ObjectGuid.Empty))
|
||||
return false;
|
||||
|
||||
playerOldName = target.GetName();
|
||||
}
|
||||
else
|
||||
{
|
||||
// check offline security
|
||||
if (handler.HasLowerSecurity(null, targetGuid))
|
||||
return false;
|
||||
|
||||
ObjectManager.GetPlayerNameByGUID(targetGuid, out playerOldName);
|
||||
}
|
||||
|
||||
if (!ObjectManager.NormalizePlayerName(ref newName))
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.BadValue);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (ObjectManager.CheckPlayerName(newName, target ? target.GetSession().GetSessionDbcLocale() : Global.WorldMgr.GetDefaultDbcLocale(), true) != ResponseCodes.CharNameSuccess)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.BadValue);
|
||||
return false;
|
||||
}
|
||||
|
||||
WorldSession session = handler.GetSession();
|
||||
if (session != null)
|
||||
{
|
||||
if (!session.HasPermission(RBACPermissions.SkipCheckCharacterCreationReservedname) && Global.ObjectMgr.IsReservedName(newName))
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.ReservedName);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
PreparedStatement stmt = DB.Characters.GetPreparedStatement(CharStatements.SEL_CHECK_NAME);
|
||||
stmt.AddValue(0, newName);
|
||||
SQLResult result = DB.Characters.Query(stmt);
|
||||
if (!result.IsEmpty())
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.RenamePlayerAlreadyExists, newName);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Remove declined name from db
|
||||
stmt = DB.Characters.GetPreparedStatement(CharStatements.DEL_CHAR_DECLINED_NAME);
|
||||
stmt.AddValue(0, targetGuid.GetCounter());
|
||||
DB.Characters.Execute(stmt);
|
||||
|
||||
if (target)
|
||||
{
|
||||
target.SetName(newName);
|
||||
session = target.GetSession();
|
||||
if (session != null)
|
||||
session.KickPlayer();
|
||||
}
|
||||
else
|
||||
{
|
||||
stmt = DB.Characters.GetPreparedStatement(CharStatements.UPD_NAME_BY_GUID);
|
||||
stmt.AddValue(0, newName);
|
||||
stmt.AddValue(1, targetGuid.GetCounter());
|
||||
DB.Characters.Execute(stmt);
|
||||
}
|
||||
|
||||
Global.WorldMgr.UpdateCharacterInfo(targetGuid, newName);
|
||||
|
||||
handler.SendSysMessage(CypherStrings.RenamePlayerWithNewName, playerOldName, newName);
|
||||
|
||||
Player player = handler.GetPlayer();
|
||||
if (player)
|
||||
Log.outCommand(session.GetAccountId(), "GM {0} (Account: {1}) forced rename {2} to player {3} (Account: {4})", player.GetName(), session.GetAccountId(), newName, playerOldName, ObjectManager.GetPlayerAccountIdByGUID(targetGuid));
|
||||
else
|
||||
Log.outCommand(0, "CONSOLE forced rename '{0}' to '{1}' ({2})", playerOldName, newName, targetGuid.ToString());
|
||||
}
|
||||
else
|
||||
{
|
||||
if (target)
|
||||
{
|
||||
// check online security
|
||||
if (handler.HasLowerSecurity(target, ObjectGuid.Empty))
|
||||
return false;
|
||||
|
||||
handler.SendSysMessage(CypherStrings.RenamePlayer, handler.GetNameLink(target));
|
||||
target.SetAtLoginFlag(AtLoginFlags.Rename);
|
||||
}
|
||||
else
|
||||
{
|
||||
// check offline security
|
||||
if (handler.HasLowerSecurity(null, targetGuid))
|
||||
return false;
|
||||
|
||||
string oldNameLink = handler.playerLink(targetName);
|
||||
handler.SendSysMessage(CypherStrings.RenamePlayerGuid, oldNameLink, targetGuid.ToString());
|
||||
|
||||
PreparedStatement stmt = DB.Characters.GetPreparedStatement(CharStatements.UPD_ADD_AT_LOGIN_FLAG);
|
||||
stmt.AddValue(0, AtLoginFlags.Rename);
|
||||
stmt.AddValue(1, targetGuid.GetCounter());
|
||||
DB.Characters.Execute(stmt);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("level", RBACPermissions.CommandCharacterLevel, true)]
|
||||
static bool HandleCharacterLevelCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
string nameStr;
|
||||
string levelStr;
|
||||
handler.extractOptFirstArg(args, out nameStr, out levelStr);
|
||||
if (string.IsNullOrEmpty(levelStr))
|
||||
return false;
|
||||
|
||||
// exception opt second arg: .character level $name
|
||||
if (!levelStr.IsNumber())
|
||||
{
|
||||
nameStr = levelStr;
|
||||
levelStr = null; // current level will used
|
||||
}
|
||||
|
||||
Player target;
|
||||
ObjectGuid targetGuid;
|
||||
string targetName;
|
||||
if (!handler.extractPlayerTarget(new StringArguments(nameStr), out target, out targetGuid, out targetName))
|
||||
return false;
|
||||
|
||||
int oldlevel = (int)(target ? target.getLevel() : Player.GetLevelFromDB(targetGuid));
|
||||
int newlevel = !string.IsNullOrEmpty(levelStr) ? int.Parse(levelStr) : oldlevel;
|
||||
|
||||
if (newlevel < 1)
|
||||
return false; // invalid level
|
||||
|
||||
if (newlevel > SharedConst.StrongMaxLevel) // hardcoded maximum level
|
||||
newlevel = SharedConst.StrongMaxLevel;
|
||||
|
||||
HandleCharacterLevel(target, targetGuid, oldlevel, newlevel, handler);
|
||||
if (handler.GetSession() == null || handler.GetSession().GetPlayer() != target) // including player == NULL
|
||||
{
|
||||
string nameLink = handler.playerLink(targetName);
|
||||
handler.SendSysMessage(CypherStrings.YouChangeLvl, nameLink, newlevel);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// customize characters
|
||||
[Command("customize", RBACPermissions.CommandCharacterCustomize, true)]
|
||||
static bool HandleCharacterCustomizeCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
Player target;
|
||||
ObjectGuid targetGuid;
|
||||
string targetName;
|
||||
if (!handler.extractPlayerTarget(args, out target, out targetGuid, out targetName))
|
||||
return false;
|
||||
|
||||
PreparedStatement stmt = DB.Characters.GetPreparedStatement(CharStatements.UPD_ADD_AT_LOGIN_FLAG);
|
||||
stmt.AddValue(0, AtLoginFlags.Customize);
|
||||
if (target)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.CustomizePlayer, handler.GetNameLink(target));
|
||||
target.SetAtLoginFlag(AtLoginFlags.Customize);
|
||||
stmt.AddValue(1, target.GetGUID().GetCounter());
|
||||
}
|
||||
else
|
||||
{
|
||||
string oldNameLink = handler.playerLink(targetName);
|
||||
stmt.AddValue(1, targetGuid.GetCounter());
|
||||
handler.SendSysMessage(CypherStrings.CustomizePlayerGuid, oldNameLink, targetGuid.ToString());
|
||||
}
|
||||
DB.Characters.Execute(stmt);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("changefaction", RBACPermissions.CommandCharacterChangefaction, true)]
|
||||
static bool HandleCharacterChangeFactionCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
Player target;
|
||||
ObjectGuid targetGuid;
|
||||
string targetName;
|
||||
if (!handler.extractPlayerTarget(args, out target, out targetGuid, out targetName))
|
||||
return false;
|
||||
|
||||
PreparedStatement stmt = DB.Characters.GetPreparedStatement(CharStatements.UPD_ADD_AT_LOGIN_FLAG);
|
||||
stmt.AddValue(0, AtLoginFlags.ChangeFaction);
|
||||
if (target)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.CustomizePlayer, handler.GetNameLink(target));
|
||||
target.SetAtLoginFlag(AtLoginFlags.ChangeFaction);
|
||||
stmt.AddValue(1, target.GetGUID().GetCounter());
|
||||
}
|
||||
else
|
||||
{
|
||||
string oldNameLink = handler.playerLink(targetName);
|
||||
handler.SendSysMessage(CypherStrings.CustomizePlayerGuid, oldNameLink, targetGuid.ToString());
|
||||
stmt.AddValue(1, targetGuid.GetCounter());
|
||||
}
|
||||
DB.Characters.Execute(stmt);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("changerace", RBACPermissions.CommandCharacterChangerace, true)]
|
||||
static bool HandleCharacterChangeRaceCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
Player target;
|
||||
ObjectGuid targetGuid;
|
||||
string targetName;
|
||||
if (!handler.extractPlayerTarget(args, out target, out targetGuid, out targetName))
|
||||
return false;
|
||||
|
||||
PreparedStatement stmt = DB.Characters.GetPreparedStatement(CharStatements.UPD_ADD_AT_LOGIN_FLAG);
|
||||
stmt.AddValue(0, AtLoginFlags.ChangeRace);
|
||||
if (target)
|
||||
{
|
||||
/// @todo add text into database
|
||||
handler.SendSysMessage(CypherStrings.CustomizePlayer, handler.GetNameLink(target));
|
||||
target.SetAtLoginFlag(AtLoginFlags.ChangeRace);
|
||||
stmt.AddValue(1, target.GetGUID().GetCounter());
|
||||
}
|
||||
else
|
||||
{
|
||||
string oldNameLink = handler.playerLink(targetName);
|
||||
/// @todo add text into database
|
||||
handler.SendSysMessage(CypherStrings.CustomizePlayerGuid, oldNameLink, targetGuid.ToString());
|
||||
stmt.AddValue(1, targetGuid.GetCounter());
|
||||
}
|
||||
DB.Characters.Execute(stmt);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("reputation", RBACPermissions.CommandCharacterReputation, true)]
|
||||
static bool HandleCharacterReputationCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
Player target;
|
||||
if (!handler.extractPlayerTarget(args, out target))
|
||||
return false;
|
||||
|
||||
LocaleConstant loc = handler.GetSessionDbcLocale();
|
||||
|
||||
var targetFSL = target.GetReputationMgr().GetStateList();
|
||||
foreach (var pair in targetFSL)
|
||||
{
|
||||
FactionState faction = pair.Value;
|
||||
FactionRecord factionEntry = CliDB.FactionStorage.LookupByKey(faction.ID);
|
||||
string factionName = factionEntry != null ? factionEntry.Name[loc] : "#Not found#";
|
||||
ReputationRank rank = target.GetReputationMgr().GetRank(factionEntry);
|
||||
string rankName = handler.GetCypherString(ReputationMgr.ReputationRankStrIndex[(int)rank]);
|
||||
StringBuilder ss = new StringBuilder();
|
||||
if (handler.GetSession() != null)
|
||||
ss.AppendFormat("{0} - |cffffffff|Hfaction:{0}|h[{1} {2}]|h|r", faction.ID, factionName, loc);
|
||||
else
|
||||
ss.AppendFormat("{0} - {1} {2}", faction.ID, factionName, loc);
|
||||
|
||||
ss.AppendFormat(" {0} ({1})", rankName, target.GetReputationMgr().GetReputation(factionEntry));
|
||||
|
||||
if (faction.Flags.HasAnyFlag(FactionFlags.Visible))
|
||||
ss.Append(handler.GetCypherString(CypherStrings.FactionVisible));
|
||||
if (faction.Flags.HasAnyFlag(FactionFlags.AtWar))
|
||||
ss.Append(handler.GetCypherString(CypherStrings.FactionAtwar));
|
||||
if (faction.Flags.HasAnyFlag(FactionFlags.PeaceForced))
|
||||
ss.Append(handler.GetCypherString(CypherStrings.FactionPeaceForced));
|
||||
if (faction.Flags.HasAnyFlag(FactionFlags.Hidden))
|
||||
ss.Append(handler.GetCypherString(CypherStrings.FactionHidden));
|
||||
if (faction.Flags.HasAnyFlag(FactionFlags.InvisibleForced))
|
||||
ss.Append(handler.GetCypherString(CypherStrings.FactionInvisibleForced));
|
||||
if (faction.Flags.HasAnyFlag(FactionFlags.Inactive))
|
||||
ss.Append(handler.GetCypherString(CypherStrings.FactionInactive));
|
||||
|
||||
handler.SendSysMessage(ss.ToString());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("erase", RBACPermissions.CommandCharacterErase, true)]
|
||||
static bool HandleCharacterEraseCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
if (args.Empty())
|
||||
return false;
|
||||
|
||||
string characterName = args.NextString();
|
||||
if (string.IsNullOrEmpty(characterName))
|
||||
return false;
|
||||
|
||||
if (!ObjectManager.NormalizePlayerName(ref characterName))
|
||||
return false;
|
||||
|
||||
ObjectGuid characterGuid;
|
||||
uint accountId;
|
||||
|
||||
Player player = Global.ObjAccessor.FindPlayerByName(characterName);
|
||||
if (player)
|
||||
{
|
||||
characterGuid = player.GetGUID();
|
||||
accountId = player.GetSession().GetAccountId();
|
||||
player.GetSession().KickPlayer();
|
||||
}
|
||||
else
|
||||
{
|
||||
characterGuid = ObjectManager.GetPlayerGUIDByName(characterName);
|
||||
if (characterGuid.IsEmpty())
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.NoPlayer, characterName);
|
||||
return false;
|
||||
}
|
||||
accountId = ObjectManager.GetPlayerAccountIdByGUID(characterGuid);
|
||||
}
|
||||
|
||||
string accountName;
|
||||
Global.AccountMgr.GetName(accountId, out accountName);
|
||||
|
||||
Player.DeleteFromDB(characterGuid, accountId, true, true);
|
||||
handler.SendSysMessage(CypherStrings.CharacterDeleted, characterName, characterGuid.ToString(), accountName, accountId);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
[CommandGroup("deleted", RBACPermissions.CommandCharacterDeleted, true)]
|
||||
class DeletedCommands
|
||||
{
|
||||
[Command("delete", RBACPermissions.CommandCharacterDeletedDelete, true)]
|
||||
static bool HandleCharacterDeletedDeleteCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
// It is required to submit at least one argument
|
||||
if (args.Empty())
|
||||
return false;
|
||||
|
||||
List<DeletedInfo> foundList = new List<DeletedInfo>();
|
||||
if (!GetDeletedCharacterInfoList(foundList, args.NextString()))
|
||||
return false;
|
||||
|
||||
if (foundList.Empty())
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.CharacterDeletedListEmpty);
|
||||
return false;
|
||||
}
|
||||
|
||||
handler.SendSysMessage(CypherStrings.CharacterDeletedDelete);
|
||||
HandleCharacterDeletedListHelper(foundList, handler);
|
||||
|
||||
// Call the appropriate function to delete them (current account for deleted characters is 0)
|
||||
foreach (var info in foundList)
|
||||
Player.DeleteFromDB(info.guid, 0, false, true);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("list", RBACPermissions.CommandCharacterDeletedList, true)]
|
||||
static bool HandleCharacterDeletedListCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
List<DeletedInfo> foundList = new List<DeletedInfo>();
|
||||
if (!GetDeletedCharacterInfoList(foundList, args.NextString()))
|
||||
return false;
|
||||
|
||||
// if no characters have been found, output a warning
|
||||
if (foundList.Empty())
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.CharacterDeletedListEmpty);
|
||||
return false;
|
||||
}
|
||||
|
||||
HandleCharacterDeletedListHelper(foundList, handler);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("restore", RBACPermissions.CommandCharacterDeletedRestore, true)]
|
||||
static bool HandleCharacterDeletedRestoreCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
// It is required to submit at least one argument
|
||||
if (args.Empty())
|
||||
return false;
|
||||
|
||||
string searchString = args.NextString();
|
||||
string newCharName = args.NextString();
|
||||
uint newAccount = args.NextUInt32();
|
||||
|
||||
List<DeletedInfo> foundList = new List<DeletedInfo>();
|
||||
if (!GetDeletedCharacterInfoList(foundList, searchString))
|
||||
return false;
|
||||
|
||||
if (foundList.Empty())
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.CharacterDeletedListEmpty);
|
||||
return false;
|
||||
}
|
||||
|
||||
handler.SendSysMessage(CypherStrings.CharacterDeletedRestore);
|
||||
HandleCharacterDeletedListHelper(foundList, handler);
|
||||
|
||||
if (newCharName.IsEmpty())
|
||||
{
|
||||
// Drop not existed account cases
|
||||
foreach (var info in foundList)
|
||||
HandleCharacterDeletedRestoreHelper(info, handler);
|
||||
}
|
||||
else if (foundList.Count == 1 && ObjectManager.NormalizePlayerName(ref newCharName))
|
||||
{
|
||||
DeletedInfo delInfo = foundList[0];
|
||||
|
||||
// update name
|
||||
delInfo.name = newCharName;
|
||||
|
||||
// if new account provided update deleted info
|
||||
if (newAccount != 0 && newAccount != delInfo.accountId)
|
||||
{
|
||||
delInfo.accountId = newAccount;
|
||||
Global.AccountMgr.GetName(newAccount, out delInfo.accountName);
|
||||
}
|
||||
|
||||
HandleCharacterDeletedRestoreHelper(delInfo, handler);
|
||||
}
|
||||
else
|
||||
handler.SendSysMessage(CypherStrings.CharacterDeletedErrRename);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("old", RBACPermissions.CommandCharacterDeletedOld, true)]
|
||||
static bool HandleCharacterDeletedOldCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
int keepDays = WorldConfig.GetIntValue(WorldCfg.ChardeleteKeepDays);
|
||||
|
||||
string daysStr = args.NextString();
|
||||
if (!daysStr.IsEmpty())
|
||||
{
|
||||
if (!daysStr.IsNumber())
|
||||
return false;
|
||||
|
||||
keepDays = int.Parse(daysStr);
|
||||
if (keepDays < 0)
|
||||
return false;
|
||||
}
|
||||
// config option value 0 -> disabled and can't be used
|
||||
else if (keepDays <= 0)
|
||||
return false;
|
||||
|
||||
Player.DeleteOldCharacters(keepDays);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool GetDeletedCharacterInfoList(List<DeletedInfo> foundList, string searchString)
|
||||
{
|
||||
SQLResult result;
|
||||
PreparedStatement stmt;
|
||||
if (!searchString.IsEmpty())
|
||||
{
|
||||
// search by GUID
|
||||
if (searchString.IsNumber())
|
||||
{
|
||||
stmt = DB.Characters.GetPreparedStatement(CharStatements.SEL_CHAR_DEL_INFO_BY_GUID);
|
||||
stmt.AddValue(0, ulong.Parse(searchString));
|
||||
result = DB.Characters.Query(stmt);
|
||||
}
|
||||
// search by name
|
||||
else
|
||||
{
|
||||
if (!ObjectManager.NormalizePlayerName(ref searchString))
|
||||
return false;
|
||||
|
||||
stmt = DB.Characters.GetPreparedStatement(CharStatements.SEL_CHAR_DEL_INFO_BY_NAME);
|
||||
stmt.AddValue(0, searchString);
|
||||
result = DB.Characters.Query(stmt);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
stmt = DB.Characters.GetPreparedStatement(CharStatements.SEL_CHAR_DEL_INFO);
|
||||
result = DB.Characters.Query(stmt);
|
||||
}
|
||||
|
||||
if (!result.IsEmpty())
|
||||
{
|
||||
do
|
||||
{
|
||||
DeletedInfo info;
|
||||
|
||||
info.guid = ObjectGuid.Create(HighGuid.Player, result.Read<ulong>(0));
|
||||
info.name = result.Read<string>(1);
|
||||
info.accountId = result.Read<uint>(2);
|
||||
|
||||
// account name will be empty for not existed account
|
||||
Global.AccountMgr.GetName(info.accountId, out info.accountName);
|
||||
info.deleteDate = result.Read<uint>(3);
|
||||
foundList.Add(info);
|
||||
}
|
||||
while (result.NextRow());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
static void HandleCharacterDeletedListHelper(List<DeletedInfo> foundList, CommandHandler handler)
|
||||
{
|
||||
if (handler.GetSession() == null)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.CharacterDeletedListBar);
|
||||
handler.SendSysMessage(CypherStrings.CharacterDeletedListHeader);
|
||||
handler.SendSysMessage(CypherStrings.CharacterDeletedListBar);
|
||||
}
|
||||
|
||||
foreach (var info in foundList)
|
||||
{
|
||||
string dateStr = Time.UnixTimeToDateTime(info.deleteDate).ToShortDateString();
|
||||
|
||||
if (!handler.GetSession())
|
||||
handler.SendSysMessage(CypherStrings.CharacterDeletedListLineConsole,
|
||||
info.guid.ToString(), info.name, info.accountName.IsEmpty() ? "<Not existed>" : info.accountName,
|
||||
info.accountId, dateStr);
|
||||
else
|
||||
handler.SendSysMessage(CypherStrings.CharacterDeletedListLineChat,
|
||||
info.guid.ToString(), info.name, info.accountName.IsEmpty() ? "<Not existed>" : info.accountName,
|
||||
info.accountId, dateStr);
|
||||
}
|
||||
|
||||
if (!handler.GetSession())
|
||||
handler.SendSysMessage(CypherStrings.CharacterDeletedListBar);
|
||||
}
|
||||
static void HandleCharacterDeletedRestoreHelper(DeletedInfo delInfo, CommandHandler handler)
|
||||
{
|
||||
if (delInfo.accountName.IsEmpty()) // account not exist
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.CharacterDeletedSkipAccount, delInfo.name, delInfo.guid.ToString(), delInfo.accountId);
|
||||
return;
|
||||
}
|
||||
|
||||
// check character count
|
||||
uint charcount = Global.AccountMgr.GetCharactersCount(delInfo.accountId);
|
||||
if (charcount >= WorldConfig.GetIntValue(WorldCfg.CharactersPerRealm))
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.CharacterDeletedSkipFull, delInfo.name, delInfo.guid.ToString(), delInfo.accountId);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!ObjectManager.GetPlayerGUIDByName(delInfo.name).IsEmpty())
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.CharacterDeletedSkipName, delInfo.name, delInfo.guid.ToString(), delInfo.accountId);
|
||||
return;
|
||||
}
|
||||
|
||||
PreparedStatement stmt = DB.Characters.GetPreparedStatement(CharStatements.UPD_RESTORE_DELETE_INFO);
|
||||
stmt.AddValue(0, delInfo.name);
|
||||
stmt.AddValue(1, delInfo.accountId);
|
||||
stmt.AddValue(2, delInfo.guid.GetCounter());
|
||||
DB.Characters.Execute(stmt);
|
||||
|
||||
Global.WorldMgr.UpdateCharacterInfoDeleted(delInfo.guid, false, delInfo.name);
|
||||
}
|
||||
|
||||
struct DeletedInfo
|
||||
{
|
||||
public ObjectGuid guid; // the GUID from the character
|
||||
public string name; // the character name
|
||||
public uint accountId; // the account id
|
||||
public string accountName; // the account name
|
||||
public long deleteDate; // the date at which the character has been deleted
|
||||
}
|
||||
}
|
||||
|
||||
[CommandNonGroup("levelup", RBACPermissions.CommandLevelup)]
|
||||
static bool LevelUp(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
string nameStr;
|
||||
string levelStr;
|
||||
handler.extractOptFirstArg(args, out nameStr, out levelStr);
|
||||
|
||||
// exception opt second arg: .character level $name
|
||||
if (!string.IsNullOrEmpty(levelStr) && !levelStr.IsNumber())
|
||||
{
|
||||
nameStr = levelStr;
|
||||
levelStr = null; // current level will used
|
||||
}
|
||||
|
||||
Player target;
|
||||
ObjectGuid targetGuid;
|
||||
string targetName;
|
||||
if (!handler.extractPlayerTarget(new StringArguments(nameStr), out target, out targetGuid, out targetName))
|
||||
return false;
|
||||
|
||||
int oldlevel = (int)(target ? target.getLevel() : Player.GetLevelFromDB(targetGuid));
|
||||
int addlevel = !string.IsNullOrEmpty(levelStr) ? int.Parse(levelStr) : 1;
|
||||
int newlevel = oldlevel + addlevel;
|
||||
|
||||
if (newlevel < 1)
|
||||
newlevel = 1;
|
||||
|
||||
if (newlevel > SharedConst.StrongMaxLevel) // hardcoded maximum level
|
||||
newlevel = SharedConst.StrongMaxLevel;
|
||||
|
||||
HandleCharacterLevel(target, targetGuid, oldlevel, newlevel, handler);
|
||||
|
||||
if (handler.GetSession() == null || handler.GetSession().GetPlayer() != target) // including chr == NULL
|
||||
{
|
||||
string nameLink = handler.playerLink(targetName);
|
||||
handler.SendSysMessage(CypherStrings.YouChangeLvl, nameLink, newlevel);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void HandleCharacterLevel(Player player, ObjectGuid playerGuid, int oldLevel, int newLevel, CommandHandler handler)
|
||||
{
|
||||
if (player)
|
||||
{
|
||||
player.GiveLevel((uint)newLevel);
|
||||
player.InitTalentForLevel();
|
||||
player.SetUInt32Value(PlayerFields.Xp, 0);
|
||||
|
||||
if (handler.needReportToTarget(player))
|
||||
{
|
||||
if (oldLevel == newLevel)
|
||||
player.SendSysMessage(CypherStrings.YoursLevelProgressReset, handler.GetNameLink());
|
||||
else if (oldLevel < newLevel)
|
||||
player.SendSysMessage(CypherStrings.YoursLevelUp, handler.GetNameLink(), newLevel);
|
||||
else // if (oldlevel > newlevel)
|
||||
player.SendSysMessage(CypherStrings.YoursLevelDown, handler.GetNameLink(), newLevel);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Update level and reset XP, everything else will be updated at login
|
||||
PreparedStatement stmt = DB.Characters.GetPreparedStatement(CharStatements.UPD_LEVEL);
|
||||
stmt.AddValue(0, newLevel);
|
||||
stmt.AddValue(1, playerGuid.GetCounter());
|
||||
DB.Characters.Execute(stmt);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[CommandGroup("pdump", RBACPermissions.CommandPdump, true)]
|
||||
class PdumpCommand
|
||||
{
|
||||
[Command("load", RBACPermissions.CommandPdumpLoad, true)]
|
||||
static bool HandlePDumpLoadCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
/*
|
||||
if (args.Empty())
|
||||
return false;
|
||||
|
||||
string fileStr = strtok((char*)args, " ");
|
||||
if (!fileStr)
|
||||
return false;
|
||||
|
||||
char* accountStr = strtok(NULL, " ");
|
||||
if (!accountStr)
|
||||
return false;
|
||||
|
||||
string accountName = accountStr;
|
||||
if (!AccountMgr.normalizeString(accountName))
|
||||
{
|
||||
handler.SendSysMessage(LANG_ACCOUNT_NOT_EXIST, accountName);
|
||||
handler.SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
public uint accountId = AccountMgr.GetId(accountName);
|
||||
if (!accountId)
|
||||
{
|
||||
accountId = atoi(accountStr); // use original string
|
||||
if (!accountId)
|
||||
{
|
||||
handler.SendSysMessage(LANG_ACCOUNT_NOT_EXIST, accountName);
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!AccountMgr.GetName(accountId, accountName))
|
||||
{
|
||||
handler.SendSysMessage(LANG_ACCOUNT_NOT_EXIST, accountName);
|
||||
handler.SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
char* guidStr = NULL;
|
||||
char* nameStr = strtok(NULL, " ");
|
||||
|
||||
string name;
|
||||
if (nameStr)
|
||||
{
|
||||
name = nameStr;
|
||||
// normalize the name if specified and check if it exists
|
||||
if (!ObjectManager.NormalizePlayerName(name))
|
||||
{
|
||||
handler.SendSysMessage(LANG_INVALID_CHARACTER_NAME);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (ObjectMgr.CheckPlayerName(name, true) != CHAR_NAME_SUCCESS)
|
||||
{
|
||||
handler.SendSysMessage(LANG_INVALID_CHARACTER_NAME);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
guidStr = strtok(NULL, " ");
|
||||
}
|
||||
|
||||
public uint guid = 0;
|
||||
|
||||
if (guidStr)
|
||||
{
|
||||
guid = uint32(atoi(guidStr));
|
||||
if (!guid)
|
||||
{
|
||||
handler.SendSysMessage(LANG_INVALID_CHARACTER_GUID);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (Global.ObjectMgr.GetPlayerAccountIdByGUID(guid))
|
||||
{
|
||||
handler.SendSysMessage(LANG_CHARACTER_GUID_IN_USE, guid);
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
switch (PlayerDumpReader().LoadDump(fileStr, accountId, name, guid))
|
||||
{
|
||||
case DUMP_SUCCESS:
|
||||
handler.SendSysMessage(LANG_COMMAND_IMPORT_SUCCESS);
|
||||
break;
|
||||
case DUMP_FILE_OPEN_ERROR:
|
||||
handler.SendSysMessage(LANG_FILE_OPEN_FAIL, fileStr);
|
||||
|
||||
return false;
|
||||
case DUMP_FILE_BROKEN:
|
||||
handler.SendSysMessage(LANG_DUMP_BROKEN, fileStr);
|
||||
|
||||
return false;
|
||||
case DUMP_TOO_MANY_CHARS:
|
||||
handler.SendSysMessage(LANG_ACCOUNT_CHARACTER_LIST_FULL, accountName, accountId);
|
||||
|
||||
return false;
|
||||
default:
|
||||
handler.SendSysMessage(LANG_COMMAND_IMPORT_FAILED);
|
||||
|
||||
return false;
|
||||
}
|
||||
*/
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("write", RBACPermissions.CommandPdumpWrite, true)]
|
||||
static bool HandlePDumpWriteCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
if (args.Empty())
|
||||
return false;
|
||||
/*
|
||||
char* fileStr = strtok((char*)args, " ");
|
||||
char* playerStr = strtok(NULL, " ");
|
||||
|
||||
if (!fileStr || !playerStr)
|
||||
return false;
|
||||
|
||||
uint64 guid;
|
||||
// character name can't start from number
|
||||
if (isNumeric(playerStr))
|
||||
guid = MAKE_NEW_GUID(atoi(playerStr), 0, HIGHGUID_PLAYER);
|
||||
else
|
||||
{
|
||||
string name = handler.extractPlayerNameFromLink(playerStr);
|
||||
if (name.empty())
|
||||
{
|
||||
handler.SendSysMessage(LANG_PLAYER_NOT_FOUND);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
guid = Global.ObjectMgr.GetPlayerGUIDByName(name);
|
||||
}
|
||||
|
||||
if (!Global.ObjectMgr.GetPlayerAccountIdByGUID(guid))
|
||||
{
|
||||
handler.SendSysMessage(LANG_PLAYER_NOT_FOUND);
|
||||
handler.SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (PlayerDumpWriter().WriteDump(fileStr, uint32(guid)))
|
||||
{
|
||||
case DUMP_SUCCESS:
|
||||
handler.SendSysMessage(LANG_COMMAND_EXPORT_SUCCESS);
|
||||
break;
|
||||
case DUMP_FILE_OPEN_ERROR:
|
||||
handler.SendSysMessage(LANG_FILE_OPEN_FAIL, fileStr);
|
||||
|
||||
return false;
|
||||
case DUMP_CHARACTER_DELETED:
|
||||
handler.SendSysMessage(LANG_COMMAND_EXPORT_DELETED_CHAR);
|
||||
|
||||
return false;
|
||||
default:
|
||||
handler.SendSysMessage(LANG_COMMAND_EXPORT_FAILED);
|
||||
|
||||
return false;
|
||||
}
|
||||
*/
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,256 @@
|
||||
/*
|
||||
* Copyright (C) 2012-2017 CypherCore <http://github.com/CypherCore>
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using Framework.Constants;
|
||||
using Framework.IO;
|
||||
using Game.Entities;
|
||||
|
||||
namespace Game.Chat.Commands
|
||||
{
|
||||
[CommandGroup("cheat", RBACPermissions.CommandCheat)]
|
||||
class CheatCommands
|
||||
{
|
||||
[Command("god", RBACPermissions.CommandCheatGod)]
|
||||
static bool HandleGodModeCheat(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
if (handler.GetSession() == null || handler.GetSession().GetPlayer())
|
||||
return false;
|
||||
|
||||
string argstr = args.NextString();
|
||||
if (args.Empty())
|
||||
argstr = (handler.GetSession().GetPlayer().GetCommandStatus(PlayerCommandStates.God)) ? "off" : "on";
|
||||
|
||||
if (argstr == "off")
|
||||
{
|
||||
handler.GetSession().GetPlayer().SetCommandStatusOff(PlayerCommandStates.God);
|
||||
handler.SendSysMessage("Godmode is OFF. You can take damage.");
|
||||
return true;
|
||||
}
|
||||
else if (argstr == "on")
|
||||
{
|
||||
handler.GetSession().GetPlayer().SetCommandStatusOn(PlayerCommandStates.God);
|
||||
handler.SendSysMessage("Godmode is ON. You won't take damage.");
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
[Command("casttime", RBACPermissions.CommandCheatCasttime)]
|
||||
static bool HandleCasttimeCheat(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
if (handler.GetSession() == null || handler.GetSession().GetPlayer())
|
||||
return false;
|
||||
|
||||
string argstr = args.NextString();
|
||||
|
||||
if (args.Empty())
|
||||
argstr = (handler.GetSession().GetPlayer().GetCommandStatus(PlayerCommandStates.Casttime)) ? "off" : "on";
|
||||
|
||||
if (argstr == "off")
|
||||
{
|
||||
handler.GetSession().GetPlayer().SetCommandStatusOff(PlayerCommandStates.Casttime);
|
||||
handler.SendSysMessage("CastTime Cheat is OFF. Your spells will have a casttime.");
|
||||
return true;
|
||||
}
|
||||
else if (argstr == "on")
|
||||
{
|
||||
handler.GetSession().GetPlayer().SetCommandStatusOn(PlayerCommandStates.Casttime);
|
||||
handler.SendSysMessage("CastTime Cheat is ON. Your spells won't have a casttime.");
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
[Command("cooldown", RBACPermissions.CommandCheatCooldown)]
|
||||
static bool HandleCoolDownCheat(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
if (handler.GetSession() == null || handler.GetSession().GetPlayer())
|
||||
return false;
|
||||
|
||||
string argstr = args.NextString();
|
||||
|
||||
if (args.Empty())
|
||||
argstr = (handler.GetSession().GetPlayer().GetCommandStatus(PlayerCommandStates.Cooldown)) ? "off" : "on";
|
||||
|
||||
if (argstr == "off")
|
||||
{
|
||||
handler.GetSession().GetPlayer().SetCommandStatusOff(PlayerCommandStates.Cooldown);
|
||||
handler.SendSysMessage("Cooldown Cheat is OFF. You are on the global cooldown.");
|
||||
return true;
|
||||
}
|
||||
else if (argstr == "on")
|
||||
{
|
||||
handler.GetSession().GetPlayer().SetCommandStatusOn(PlayerCommandStates.Cooldown);
|
||||
handler.SendSysMessage("Cooldown Cheat is ON. You are not on the global cooldown.");
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
[Command("power", RBACPermissions.CommandCheatPower)]
|
||||
static bool HandlePowerCheat(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
if (handler.GetSession() == null || handler.GetSession().GetPlayer())
|
||||
return false;
|
||||
|
||||
string argstr = args.NextString();
|
||||
|
||||
if (args.Empty())
|
||||
argstr = (handler.GetSession().GetPlayer().GetCommandStatus(PlayerCommandStates.Power)) ? "off" : "on";
|
||||
|
||||
if (argstr == "off")
|
||||
{
|
||||
handler.GetSession().GetPlayer().SetCommandStatusOff(PlayerCommandStates.Power);
|
||||
handler.SendSysMessage("Power Cheat is OFF. You need mana/rage/energy to use spells.");
|
||||
return true;
|
||||
}
|
||||
else if (argstr == "on")
|
||||
{
|
||||
handler.GetSession().GetPlayer().SetCommandStatusOn(PlayerCommandStates.Power);
|
||||
handler.SendSysMessage("Power Cheat is ON. You don't need mana/rage/energy to use spells.");
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
[Command("status", RBACPermissions.CommandCheatStatus)]
|
||||
static bool HandleCheatStatus(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
Player player = handler.GetSession().GetPlayer();
|
||||
|
||||
string enabled = "ON";
|
||||
string disabled = "OFF";
|
||||
|
||||
handler.SendSysMessage(CypherStrings.CommandCheatStatus);
|
||||
handler.SendSysMessage(CypherStrings.CommandCheatGod, player.GetCommandStatus(PlayerCommandStates.God) ? enabled : disabled);
|
||||
handler.SendSysMessage(CypherStrings.CommandCheatCd, player.GetCommandStatus(PlayerCommandStates.Cooldown) ? enabled : disabled);
|
||||
handler.SendSysMessage(CypherStrings.CommandCheatCt, player.GetCommandStatus(PlayerCommandStates.Casttime) ? enabled : disabled);
|
||||
handler.SendSysMessage(CypherStrings.CommandCheatPower, player.GetCommandStatus(PlayerCommandStates.Power) ? enabled : disabled);
|
||||
handler.SendSysMessage(CypherStrings.CommandCheatWw, player.GetCommandStatus(PlayerCommandStates.Waterwalk) ? enabled : disabled);
|
||||
handler.SendSysMessage(CypherStrings.CommandCheatTaxinodes, player.isTaxiCheater() ? enabled : disabled);
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("waterwalk", RBACPermissions.CommandCheatWaterwalk)]
|
||||
static bool HandleWaterWalkCheat(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
if (handler.GetSession() == null || handler.GetSession().GetPlayer())
|
||||
return false;
|
||||
|
||||
string argstr = args.NextString();
|
||||
|
||||
Player target = handler.GetSession().GetPlayer();
|
||||
if (args.Empty())
|
||||
argstr = (target.GetCommandStatus(PlayerCommandStates.Waterwalk)) ? "off" : "on";
|
||||
|
||||
if (argstr == "off")
|
||||
{
|
||||
target.SetCommandStatusOff(PlayerCommandStates.Waterwalk);
|
||||
target.SetWaterWalking(false);
|
||||
handler.SendSysMessage("Waterwalking is OFF. You can't walk on water.");
|
||||
return true;
|
||||
}
|
||||
else if (argstr == "on")
|
||||
{
|
||||
target.SetCommandStatusOn(PlayerCommandStates.Waterwalk);
|
||||
target.SetWaterWalking(true);
|
||||
handler.SendSysMessage("Waterwalking is ON. You can walk on water.");
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
[Command("taxi", RBACPermissions.CommandCheatTaxi)]
|
||||
static bool HandleTaxiCheatCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
string argstr = args.NextString();
|
||||
|
||||
Player chr = handler.getSelectedPlayer();
|
||||
if (!chr)
|
||||
chr = handler.GetSession().GetPlayer();
|
||||
else if (handler.HasLowerSecurity(chr, ObjectGuid.Empty)) // check online security
|
||||
return false;
|
||||
|
||||
if (args.Empty())
|
||||
argstr = (chr.isTaxiCheater()) ? "off" : "on";
|
||||
|
||||
if (argstr == "off")
|
||||
{
|
||||
chr.SetTaxiCheater(false);
|
||||
handler.SendSysMessage(CypherStrings.YouRemoveTaxis, handler.GetNameLink(chr));
|
||||
if (handler.needReportToTarget(chr))
|
||||
chr.SendSysMessage(CypherStrings.YoursTaxisRemoved, handler.GetNameLink());
|
||||
|
||||
return true;
|
||||
}
|
||||
else if (argstr == "on")
|
||||
{
|
||||
chr.SetTaxiCheater(true);
|
||||
handler.SendSysMessage(CypherStrings.YouGiveTaxis, handler.GetNameLink(chr));
|
||||
if (handler.needReportToTarget(chr))
|
||||
chr.SendSysMessage(CypherStrings.YoursTaxisAdded, handler.GetNameLink());
|
||||
return true;
|
||||
}
|
||||
|
||||
handler.SendSysMessage(CypherStrings.UseBol);
|
||||
return false;
|
||||
}
|
||||
|
||||
[Command("explore", RBACPermissions.CommandCheatExplore)]
|
||||
static bool HandleExploreCheat(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
if (args.Empty())
|
||||
return false;
|
||||
|
||||
int flag = args.NextInt32();
|
||||
Player chr = handler.getSelectedPlayer();
|
||||
if (!chr)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.NoCharSelected);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (flag != 0)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.YouSetExploreAll, handler.GetNameLink(chr));
|
||||
if (handler.needReportToTarget(chr))
|
||||
chr.SendSysMessage(CypherStrings.YoursExploreSetAll, handler.GetNameLink());
|
||||
}
|
||||
else
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.YouSetExploreNothing, handler.GetNameLink(chr));
|
||||
if (handler.needReportToTarget(chr))
|
||||
chr.SendSysMessage(CypherStrings.YoursExploreSetNothing, handler.GetNameLink());
|
||||
}
|
||||
|
||||
for (ushort i = 0; i < PlayerConst.ExploredZonesSize; ++i)
|
||||
{
|
||||
if (flag != 0)
|
||||
handler.GetSession().GetPlayer().SetFlag(PlayerFields.ExploredZones1 + i, 0xFFFFFFFF);
|
||||
else
|
||||
handler.GetSession().GetPlayer().SetFlag(PlayerFields.ExploredZones1 + i, 0);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,116 @@
|
||||
/*
|
||||
* Copyright (C) 2012-2017 CypherCore <http://github.com/CypherCore>
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using Framework.Constants;
|
||||
using Framework.IO;
|
||||
using Game.Entities;
|
||||
using Game.Spells;
|
||||
|
||||
namespace Game.Chat.Commands
|
||||
{
|
||||
struct Spells
|
||||
{
|
||||
public const uint LFGDundeonDeserter = 71041;
|
||||
public const uint BGDeserter = 26013;
|
||||
}
|
||||
|
||||
[CommandGroup("deserter", RBACPermissions.CommandDeserter)]
|
||||
class DeserterCommands
|
||||
{
|
||||
[CommandGroup("instance", RBACPermissions.CommandDeserterInstance)]
|
||||
class DeserterInstanceCommands
|
||||
{
|
||||
[Command("add", RBACPermissions.CommandDeserterInstanceAdd)]
|
||||
static bool HandleDeserterInstanceAdd(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
return HandleDeserterAdd(args, handler, true);
|
||||
}
|
||||
|
||||
[Command("remove", RBACPermissions.CommandDeserterInstanceRemove)]
|
||||
static bool HandleDeserterInstanceRemove(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
return HandleDeserterRemove(args, handler, true);
|
||||
}
|
||||
}
|
||||
|
||||
[CommandGroup("bg", RBACPermissions.CommandDeserterBg)]
|
||||
class DeserterBGCommands
|
||||
{
|
||||
[Command("add", RBACPermissions.CommandDeserterBgAdd)]
|
||||
static bool HandleDeserterBGAdd(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
return HandleDeserterAdd(args, handler, false);
|
||||
}
|
||||
|
||||
[Command("remove", RBACPermissions.CommandDeserterBgRemove)]
|
||||
static bool HandleDeserterBGRemove(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
return HandleDeserterRemove(args, handler, false);
|
||||
}
|
||||
}
|
||||
|
||||
static bool HandleDeserterAdd(StringArguments args, CommandHandler handler, bool isInstance)
|
||||
{
|
||||
if (args.Empty())
|
||||
return false;
|
||||
|
||||
Player player = handler.getSelectedPlayer();
|
||||
if (!player)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.NoCharSelected);
|
||||
return false;
|
||||
}
|
||||
string timeStr = args.NextString();
|
||||
if (string.IsNullOrEmpty(timeStr))
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.BadValue);
|
||||
return false;
|
||||
}
|
||||
|
||||
uint time = uint.Parse(timeStr);
|
||||
if (time == 0)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.BadValue);
|
||||
return false;
|
||||
}
|
||||
|
||||
Aura aura = player.AddAura(isInstance ? Spells.LFGDundeonDeserter : Spells.BGDeserter, player);
|
||||
if (aura == null)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.BadValue);
|
||||
return false;
|
||||
}
|
||||
aura.SetDuration((int)(time * Time.InMilliseconds));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool HandleDeserterRemove(StringArguments args, CommandHandler handler, bool isInstance)
|
||||
{
|
||||
Player player = handler.getSelectedPlayer();
|
||||
if (!player)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.NoCharSelected);
|
||||
return false;
|
||||
}
|
||||
|
||||
player.RemoveAura(isInstance ? Spells.LFGDundeonDeserter : Spells.BGDeserter);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,360 @@
|
||||
/*
|
||||
* Copyright (C) 2012-2017 CypherCore <http://github.com/CypherCore>
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using Framework.Constants;
|
||||
using Framework.Database;
|
||||
using Framework.IO;
|
||||
using Game.DataStorage;
|
||||
|
||||
namespace Game.Chat.Commands
|
||||
{
|
||||
[CommandGroup("disable", RBACPermissions.CommandDisable)]
|
||||
class DisableCommands
|
||||
{
|
||||
[CommandGroup("add", RBACPermissions.CommandDisableAdd, true)]
|
||||
class DisableAddCommands
|
||||
{
|
||||
static bool HandleAddDisables(StringArguments args, CommandHandler handler, DisableType disableType)
|
||||
{
|
||||
string entryStr = args.NextString();
|
||||
if (string.IsNullOrEmpty(entryStr) || int.Parse(entryStr) == 0)
|
||||
return false;
|
||||
|
||||
string flagsStr = args.NextString();
|
||||
uint flags = !string.IsNullOrEmpty(flagsStr) ? byte.Parse(flagsStr) : 0u;
|
||||
|
||||
string disableComment = args.NextString("");
|
||||
if (string.IsNullOrEmpty(disableComment))
|
||||
return false;
|
||||
|
||||
uint entry = uint.Parse(entryStr);
|
||||
|
||||
string disableTypeStr = "";
|
||||
switch (disableType)
|
||||
{
|
||||
case DisableType.Spell:
|
||||
{
|
||||
if (!Global.SpellMgr.HasSpellInfo(entry))
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.CommandNospellfound);
|
||||
return false;
|
||||
}
|
||||
disableTypeStr = "spell";
|
||||
break;
|
||||
}
|
||||
case DisableType.Quest:
|
||||
{
|
||||
if (Global.ObjectMgr.GetQuestTemplate(entry) == null)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.CommandNoquestfound, entry);
|
||||
return false;
|
||||
}
|
||||
disableTypeStr = "quest";
|
||||
break;
|
||||
}
|
||||
case DisableType.Map:
|
||||
{
|
||||
if (!CliDB.MapStorage.ContainsKey(entry))
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.CommandNomapfound);
|
||||
return false;
|
||||
}
|
||||
disableTypeStr = "map";
|
||||
break;
|
||||
}
|
||||
case DisableType.Battleground:
|
||||
{
|
||||
if (!CliDB.BattlemasterListStorage.ContainsKey(entry))
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.CommandNoBattlegroundFound);
|
||||
return false;
|
||||
}
|
||||
disableTypeStr = "Battleground";
|
||||
break;
|
||||
}
|
||||
case DisableType.Criteria:
|
||||
{
|
||||
if (Global.CriteriaMgr.GetCriteria(entry) == null)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.CommandNoAchievementCriteriaFound);
|
||||
return false;
|
||||
}
|
||||
disableTypeStr = "criteria";
|
||||
break;
|
||||
}
|
||||
case DisableType.OutdoorPVP:
|
||||
{
|
||||
if (entry > (int)OutdoorPvPTypes.Max)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.CommandNoOutdoorPvpForund);
|
||||
return false;
|
||||
}
|
||||
disableTypeStr = "outdoorpvp";
|
||||
break;
|
||||
}
|
||||
case DisableType.VMAP:
|
||||
{
|
||||
if (!CliDB.MapStorage.ContainsKey(entry))
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.CommandNomapfound);
|
||||
return false;
|
||||
}
|
||||
disableTypeStr = "vmap";
|
||||
break;
|
||||
}
|
||||
case DisableType.MMAP:
|
||||
{
|
||||
if (!CliDB.MapStorage.ContainsKey(entry))
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.CommandNomapfound);
|
||||
return false;
|
||||
}
|
||||
disableTypeStr = "mmap";
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
PreparedStatement stmt = DB.World.GetPreparedStatement(WorldStatements.SEL_DISABLES);
|
||||
stmt.AddValue(0, entry);
|
||||
stmt.AddValue(1, disableType);
|
||||
SQLResult result = DB.World.Query(stmt);
|
||||
if (!result.IsEmpty())
|
||||
{
|
||||
handler.SendSysMessage("This {0} (Id: {1}) is already disabled.", disableTypeStr, entry);
|
||||
return false;
|
||||
}
|
||||
|
||||
stmt = DB.World.GetPreparedStatement(WorldStatements.INS_DISABLES);
|
||||
stmt.AddValue(0, entry);
|
||||
stmt.AddValue(1, disableType);
|
||||
stmt.AddValue(2, flags);
|
||||
stmt.AddValue(3, disableComment);
|
||||
DB.World.Execute(stmt);
|
||||
|
||||
handler.SendSysMessage("Add Disabled {0} (Id: {1}) for reason {2}", disableTypeStr, entry, disableComment);
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("spell", RBACPermissions.CommandDisableAddSpell, true)]
|
||||
static bool HandleAddDisableSpellCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
if (args.Empty())
|
||||
return false;
|
||||
|
||||
return HandleAddDisables(args, handler, DisableType.Spell);
|
||||
}
|
||||
|
||||
[Command("quest", RBACPermissions.CommandDisableAddQuest, true)]
|
||||
static bool HandleAddDisableQuestCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
if (args.Empty())
|
||||
return false;
|
||||
|
||||
return HandleAddDisables(args, handler, DisableType.Quest);
|
||||
}
|
||||
|
||||
[Command("map", RBACPermissions.CommandDisableAddMap, true)]
|
||||
static bool HandleAddDisableMapCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
if (args.Empty())
|
||||
return false;
|
||||
|
||||
return HandleAddDisables(args, handler, DisableType.Map);
|
||||
}
|
||||
|
||||
[Command("Battleground", RBACPermissions.CommandDisableAddBattleground, true)]
|
||||
static bool HandleAddDisableBattlegroundCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
if (args.Empty())
|
||||
return false;
|
||||
|
||||
return HandleAddDisables(args, handler, DisableType.Battleground);
|
||||
}
|
||||
|
||||
[Command("criteria", RBACPermissions.CommandDisableAddCriteria, true)]
|
||||
static bool HandleAddDisableCriteriaCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
if (args.Empty())
|
||||
return false;
|
||||
|
||||
return HandleAddDisables(args, handler, DisableType.Criteria);
|
||||
}
|
||||
|
||||
[Command("outdoorpvp", RBACPermissions.CommandDisableAddOutdoorpvp, true)]
|
||||
static bool HandleAddDisableOutdoorPvPCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
if (args.Empty())
|
||||
return false;
|
||||
|
||||
HandleAddDisables(args, handler, DisableType.OutdoorPVP);
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("vmap", RBACPermissions.CommandDisableAddVmap, true)]
|
||||
static bool HandleAddDisableVmapCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
if (args.Empty())
|
||||
return false;
|
||||
|
||||
return HandleAddDisables(args, handler, DisableType.VMAP);
|
||||
}
|
||||
|
||||
[Command("mmap", RBACPermissions.CommandDisableAddMmap, true)]
|
||||
static bool HandleAddDisableMMapCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
if (args.Empty())
|
||||
return false;
|
||||
|
||||
return HandleAddDisables(args, handler, DisableType.MMAP);
|
||||
}
|
||||
}
|
||||
|
||||
[CommandGroup("remove", RBACPermissions.CommandDisableRemove, true)]
|
||||
class DisableRemoveCommands
|
||||
{
|
||||
static bool HandleRemoveDisables(StringArguments args, CommandHandler handler, DisableType disableType)
|
||||
{
|
||||
string entryStr = args.NextString();
|
||||
if (string.IsNullOrEmpty(entryStr) || uint.Parse(entryStr) == 0)
|
||||
return false;
|
||||
|
||||
uint entry = uint.Parse(entryStr);
|
||||
|
||||
string disableTypeStr = "";
|
||||
switch (disableType)
|
||||
{
|
||||
case DisableType.Spell:
|
||||
disableTypeStr = "spell";
|
||||
break;
|
||||
case DisableType.Quest:
|
||||
disableTypeStr = "quest";
|
||||
break;
|
||||
case DisableType.Map:
|
||||
disableTypeStr = "map";
|
||||
break;
|
||||
case DisableType.Battleground:
|
||||
disableTypeStr = "Battleground";
|
||||
break;
|
||||
case DisableType.Criteria:
|
||||
disableTypeStr = "criteria";
|
||||
break;
|
||||
case DisableType.OutdoorPVP:
|
||||
disableTypeStr = "outdoorpvp";
|
||||
break;
|
||||
case DisableType.VMAP:
|
||||
disableTypeStr = "vmap";
|
||||
break;
|
||||
case DisableType.MMAP:
|
||||
disableTypeStr = "mmap";
|
||||
break;
|
||||
}
|
||||
|
||||
PreparedStatement stmt = DB.World.GetPreparedStatement(WorldStatements.SEL_DISABLES);
|
||||
stmt.AddValue(0, entry);
|
||||
stmt.AddValue(1, disableType);
|
||||
SQLResult result = DB.World.Query(stmt);
|
||||
if (result.IsEmpty())
|
||||
{
|
||||
handler.SendSysMessage("This {0} (Id: {1}) is not disabled.", disableTypeStr, entry);
|
||||
return false;
|
||||
}
|
||||
|
||||
stmt = DB.World.GetPreparedStatement(WorldStatements.DEL_DISABLES);
|
||||
stmt.AddValue(0, entry);
|
||||
stmt.AddValue(1, disableType);
|
||||
DB.World.Execute(stmt);
|
||||
|
||||
handler.SendSysMessage("Remove Disabled {0} (Id: {1})", disableTypeStr, entry);
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("spell", RBACPermissions.CommandDisableRemoveSpell, true)]
|
||||
static bool HandleRemoveDisableSpellCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
if (args.Empty())
|
||||
return false;
|
||||
|
||||
return HandleRemoveDisables(args, handler, DisableType.Spell);
|
||||
}
|
||||
|
||||
[Command("quest", RBACPermissions.CommandDisableRemoveQuest, true)]
|
||||
static bool HandleRemoveDisableQuestCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
if (args.Empty())
|
||||
return false;
|
||||
|
||||
return HandleRemoveDisables(args, handler, DisableType.Quest);
|
||||
}
|
||||
|
||||
[Command("map", RBACPermissions.CommandDisableRemoveMap, true)]
|
||||
static bool HandleRemoveDisableMapCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
if (args.Empty())
|
||||
return false;
|
||||
|
||||
return HandleRemoveDisables(args, handler, DisableType.Map);
|
||||
}
|
||||
|
||||
[Command("Battleground", RBACPermissions.CommandDisableRemoveBattleground, true)]
|
||||
static bool HandleRemoveDisableBattlegroundCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
if (args.Empty())
|
||||
return false;
|
||||
|
||||
return HandleRemoveDisables(args, handler, DisableType.Battleground);
|
||||
}
|
||||
|
||||
[Command("criteria", RBACPermissions.CommandDisableRemoveCriteria, true)]
|
||||
static bool HandleRemoveDisableCriteriaCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
if (args.Empty())
|
||||
return false;
|
||||
|
||||
return HandleRemoveDisables(args, handler, DisableType.Criteria);
|
||||
}
|
||||
|
||||
[Command("outdoorpvp", RBACPermissions.CommandDisableRemoveOutdoorpvp, true)]
|
||||
static bool HandleRemoveDisableOutdoorPvPCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
if (args.Empty())
|
||||
return false;
|
||||
|
||||
return HandleRemoveDisables(args, handler, DisableType.OutdoorPVP);
|
||||
}
|
||||
|
||||
[Command("vmap", RBACPermissions.CommandDisableRemoveVmap, true)]
|
||||
static bool HandleRemoveDisableVmapCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
if (args.Empty())
|
||||
return false;
|
||||
|
||||
return HandleRemoveDisables(args, handler, DisableType.VMAP);
|
||||
}
|
||||
|
||||
[Command("mmap", RBACPermissions.CommandDisableRemoveMmap, true)]
|
||||
static bool HandleRemoveDisableMMapCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
if (args.Empty())
|
||||
return false;
|
||||
|
||||
return HandleRemoveDisables(args, handler, DisableType.MMAP);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,180 @@
|
||||
/*
|
||||
* Copyright (C) 2012-2017 CypherCore <http://github.com/CypherCore>
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using Framework.Constants;
|
||||
using Framework.IO;
|
||||
|
||||
namespace Game.Chat
|
||||
{
|
||||
[CommandGroup("event", RBACPermissions.CommandEvent)]
|
||||
class EventCommands
|
||||
{
|
||||
[Command("info", RBACPermissions.CommandEvent, true)]
|
||||
static bool HandleEventInfoCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
if (args.Empty())
|
||||
return false;
|
||||
|
||||
// id or [name] Shift-click form |color|Hgameevent:id|h[name]|h|r
|
||||
string id = handler.extractKeyFromLink(args, "Hgameevent");
|
||||
if (string.IsNullOrEmpty(id))
|
||||
return false;
|
||||
|
||||
ushort eventId = ushort.Parse(id);
|
||||
|
||||
var events = Global.GameEventMgr.GetEventMap();
|
||||
|
||||
if (eventId >= events.Length)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.EventNotExist);
|
||||
return false;
|
||||
}
|
||||
|
||||
GameEventData eventData = events[eventId];
|
||||
if (!eventData.isValid())
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.EventNotExist);
|
||||
return false;
|
||||
}
|
||||
|
||||
var activeEvents = Global.GameEventMgr.GetActiveEventList();
|
||||
bool active = activeEvents.Contains(eventId);
|
||||
string activeStr = active ? Global.ObjectMgr.GetCypherString(CypherStrings.Active) : "";
|
||||
|
||||
string startTimeStr = Time.UnixTimeToDateTime(eventData.start).ToLongDateString();
|
||||
string endTimeStr = Time.UnixTimeToDateTime(eventData.end).ToLongDateString();
|
||||
|
||||
uint delay = Global.GameEventMgr.NextCheck(eventId);
|
||||
long nextTime = Time.UnixTime + delay;
|
||||
string nextStr = nextTime >= eventData.start && nextTime < eventData.end ? Time.UnixTimeToDateTime(Time.UnixTime + delay).ToShortTimeString() : "-";
|
||||
|
||||
string occurenceStr = Time.secsToTimeString(eventData.occurence * Time.Minute);
|
||||
string lengthStr = Time.secsToTimeString(eventData.length * Time.Minute);
|
||||
|
||||
handler.SendSysMessage(CypherStrings.EventInfo, eventId, eventData.description, activeStr,
|
||||
startTimeStr, endTimeStr, occurenceStr, lengthStr, nextStr);
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("activelist", RBACPermissions.CommandEventActivelist, true)]
|
||||
static bool HandleEventActiveListCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
uint counter = 0;
|
||||
|
||||
var events = Global.GameEventMgr.GetEventMap();
|
||||
var activeEvents = Global.GameEventMgr.GetActiveEventList();
|
||||
|
||||
string active = Global.ObjectMgr.GetCypherString(CypherStrings.Active);
|
||||
|
||||
foreach (var eventId in activeEvents)
|
||||
{
|
||||
GameEventData eventData = events[eventId];
|
||||
|
||||
if (handler.GetSession() != null)
|
||||
handler.SendSysMessage(CypherStrings.EventEntryListChat, eventId, eventId, eventData.description, active);
|
||||
else
|
||||
handler.SendSysMessage(CypherStrings.EventEntryListConsole, eventId, eventData.description, active);
|
||||
|
||||
++counter;
|
||||
}
|
||||
|
||||
if (counter == 0)
|
||||
handler.SendSysMessage(CypherStrings.Noeventfound);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("start", RBACPermissions.CommandEventStart, true)]
|
||||
static bool HandleEventStartCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
if (args.Empty())
|
||||
return false;
|
||||
|
||||
// id or [name] Shift-click form |color|Hgameevent:id|h[name]|h|r
|
||||
string id = handler.extractKeyFromLink(args, "Hgameevent");
|
||||
if (string.IsNullOrEmpty(id))
|
||||
return false;
|
||||
|
||||
ushort eventId = ushort.Parse(id);
|
||||
|
||||
var events = Global.GameEventMgr.GetEventMap();
|
||||
|
||||
if (eventId < 1 || eventId >= events.Length)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.EventNotExist);
|
||||
return false;
|
||||
}
|
||||
|
||||
GameEventData eventData = events[eventId];
|
||||
if (!eventData.isValid())
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.EventNotExist);
|
||||
return false;
|
||||
}
|
||||
|
||||
var activeEvents = Global.GameEventMgr.GetActiveEventList();
|
||||
if (activeEvents.Contains(eventId))
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.EventAlreadyActive, eventId);
|
||||
return false;
|
||||
}
|
||||
|
||||
Global.GameEventMgr.StartEvent(eventId, true);
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("stop", RBACPermissions.CommandEventStop, true)]
|
||||
static bool HandleEventStopCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
if (args.Empty())
|
||||
return false;
|
||||
|
||||
// id or [name] Shift-click form |color|Hgameevent:id|h[name]|h|r
|
||||
string id = handler.extractKeyFromLink(args, "Hgameevent");
|
||||
if (string.IsNullOrEmpty(id))
|
||||
return false;
|
||||
|
||||
ushort eventId = ushort.Parse(id);
|
||||
|
||||
var events = Global.GameEventMgr.GetEventMap();
|
||||
|
||||
if (eventId < 1 || eventId >= events.Length)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.EventNotExist);
|
||||
return false;
|
||||
}
|
||||
|
||||
GameEventData eventData = events[eventId];
|
||||
if (!eventData.isValid())
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.EventNotExist);
|
||||
return false;
|
||||
}
|
||||
|
||||
var activeEvents = Global.GameEventMgr.GetActiveEventList();
|
||||
|
||||
if (!activeEvents.Contains(eventId))
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.EventNotActive, eventId);
|
||||
return false;
|
||||
}
|
||||
|
||||
Global.GameEventMgr.StopEvent(eventId, true);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,234 @@
|
||||
/*
|
||||
* Copyright (C) 2012-2017 CypherCore <http://github.com/CypherCore>
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using Framework.Constants;
|
||||
using Framework.Database;
|
||||
using Framework.IO;
|
||||
using Game.Entities;
|
||||
|
||||
namespace Game.Chat
|
||||
{
|
||||
[CommandGroup("gm", RBACPermissions.CommandGm)]
|
||||
class GMCommands
|
||||
{
|
||||
[Command("", RBACPermissions.CommandGm)]
|
||||
static bool HandleGMCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
Player _player = handler.GetSession().GetPlayer();
|
||||
|
||||
if (args.Empty())
|
||||
{
|
||||
handler.SendNotification(_player.IsGameMaster() ? CypherStrings.GmOn : CypherStrings.GmOff);
|
||||
return true;
|
||||
}
|
||||
|
||||
string param = args.NextString();
|
||||
if (param == "on")
|
||||
{
|
||||
_player.SetGameMaster(true);
|
||||
handler.SendNotification(CypherStrings.GmOn);
|
||||
_player.UpdateTriggerVisibility();
|
||||
return true;
|
||||
}
|
||||
if (param == "off")
|
||||
{
|
||||
_player.SetGameMaster(false);
|
||||
handler.SendNotification(CypherStrings.GmOff);
|
||||
_player.UpdateTriggerVisibility();
|
||||
return true;
|
||||
}
|
||||
|
||||
handler.SendSysMessage(CypherStrings.UseBol);
|
||||
return false;
|
||||
}
|
||||
|
||||
[Command("chat", RBACPermissions.CommandGmChat)]
|
||||
static bool HandleGMChatCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
WorldSession session = handler.GetSession();
|
||||
if (session != null)
|
||||
{
|
||||
if (args.Empty())
|
||||
{
|
||||
if (session.HasPermission(RBACPermissions.ChatUseStaffBadge) && session.GetPlayer().isGMChat())
|
||||
session.SendNotification(CypherStrings.GmChatOn);
|
||||
else
|
||||
session.SendNotification(CypherStrings.GmChatOff);
|
||||
return true;
|
||||
}
|
||||
|
||||
string param = args.NextString();
|
||||
|
||||
if (param == "on")
|
||||
{
|
||||
session.GetPlayer().SetGMChat(true);
|
||||
session.SendNotification(CypherStrings.GmChatOn);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (param == "off")
|
||||
{
|
||||
session.GetPlayer().SetGMChat(false);
|
||||
session.SendNotification(CypherStrings.GmChatOff);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
handler.SendSysMessage(CypherStrings.UseBol);
|
||||
return false;
|
||||
}
|
||||
|
||||
[Command("fly", RBACPermissions.CommandGmFly)]
|
||||
static bool HandleGMFlyCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
if (args.Empty())
|
||||
return false;
|
||||
|
||||
Player target = handler.getSelectedPlayer();
|
||||
if (target == null)
|
||||
target = handler.GetPlayer();
|
||||
|
||||
string arg = args.NextString().ToLower();
|
||||
|
||||
if (arg == "on")
|
||||
target.SetCanFly(true);
|
||||
else if (arg == "off")
|
||||
target.SetCanFly(false);
|
||||
else
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.UseBol);
|
||||
return false;
|
||||
}
|
||||
handler.SendSysMessage(CypherStrings.CommandFlymodeStatus, handler.GetNameLink(target), arg);
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("ingame", RBACPermissions.CommandGmIngame, true)]
|
||||
static bool HandleGMListIngameCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
bool first = true;
|
||||
bool footer = false;
|
||||
|
||||
var m = Global.ObjAccessor.GetPlayers();
|
||||
foreach (var pl in m)
|
||||
{
|
||||
AccountTypes accountType = pl.GetSession().GetSecurity();
|
||||
if ((pl.IsGameMaster() ||
|
||||
(pl.GetSession().HasPermission(RBACPermissions.CommandsAppearInGmList) &&
|
||||
accountType <= (AccountTypes)WorldConfig.GetIntValue(WorldCfg.GmLevelInGmList))) &&
|
||||
(handler.GetSession() == null || pl.IsVisibleGloballyFor(handler.GetSession().GetPlayer())))
|
||||
{
|
||||
if (first)
|
||||
{
|
||||
first = false;
|
||||
footer = true;
|
||||
handler.SendSysMessage(CypherStrings.GmsOnSrv);
|
||||
handler.SendSysMessage("========================");
|
||||
}
|
||||
int size = pl.GetName().Length;
|
||||
byte security = (byte)accountType;
|
||||
int max = ((16 - size) / 2);
|
||||
int max2 = max;
|
||||
if ((max + max2 + size) == 16)
|
||||
max2 = max - 1;
|
||||
if (handler.GetSession() != null)
|
||||
handler.SendSysMessage("| {0} GMLevel {1}", pl.GetName(), security);
|
||||
else
|
||||
handler.SendSysMessage("|{0}{1}{2}| {3} |", max, " ", pl.GetName(), max2, " ", security);
|
||||
}
|
||||
}
|
||||
if (footer)
|
||||
handler.SendSysMessage("========================");
|
||||
if (first)
|
||||
handler.SendSysMessage(CypherStrings.GmsNotLogged);
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("list", RBACPermissions.CommandGmList, true)]
|
||||
static bool HandleGMListFullCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
// Get the accounts with GM Level >0
|
||||
PreparedStatement stmt = DB.Login.GetPreparedStatement(LoginStatements.SEL_GM_ACCOUNTS);
|
||||
stmt.AddValue(0, AccountTypes.Moderator);
|
||||
stmt.AddValue(1, Global.WorldMgr.GetRealm().Id.Realm);
|
||||
SQLResult result = DB.Login.Query(stmt);
|
||||
|
||||
if (!result.IsEmpty())
|
||||
{
|
||||
handler.SendSysMessage( CypherStrings.Gmlist);
|
||||
handler.SendSysMessage("========================");
|
||||
// Cycle through them. Display username and GM level
|
||||
do
|
||||
{
|
||||
string name = result.Read<string>(0);
|
||||
byte security = result.Read<byte>(1);
|
||||
int max = (16 - name.Length) / 2;
|
||||
int max2 = max;
|
||||
if ((max + max2 + name.Length) == 16)
|
||||
max2 = max - 1;
|
||||
string padding = "";
|
||||
if (handler.GetSession() != null)
|
||||
handler.SendSysMessage("| {0} GMLevel {1}", name, security);
|
||||
else
|
||||
handler.SendSysMessage("|{0}{1}{2}| {3} |", padding.PadRight(max), name, padding.PadRight(max2), security);
|
||||
} while (result.NextRow());
|
||||
handler.SendSysMessage("========================");
|
||||
}
|
||||
else
|
||||
handler.SendSysMessage( CypherStrings.GmlistEmpty);
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("visible", RBACPermissions.CommandGmVisible)]
|
||||
static bool HandleGMVisibleCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
Player _player = handler.GetSession().GetPlayer();
|
||||
|
||||
if (args.Empty())
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.YouAre, _player.isGMVisible() ? Global.ObjectMgr.GetCypherString(CypherStrings.Visible) : Global.ObjectMgr.GetCypherString(CypherStrings.Invisible));
|
||||
return true;
|
||||
}
|
||||
|
||||
uint VISUAL_AURA = 37800;
|
||||
string param = args.NextString();
|
||||
|
||||
if (param == "on")
|
||||
{
|
||||
if (_player.HasAura(VISUAL_AURA, ObjectGuid.Empty))
|
||||
_player.RemoveAurasDueToSpell(VISUAL_AURA);
|
||||
|
||||
_player.SetGMVisible(true);
|
||||
_player.UpdateObjectVisibility();
|
||||
handler.GetSession().SendNotification(CypherStrings.InvisibleVisible);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (param == "off")
|
||||
{
|
||||
_player.AddAura(VISUAL_AURA, _player);
|
||||
_player.SetGMVisible(false);
|
||||
_player.UpdateObjectVisibility();
|
||||
handler.GetSession().SendNotification(CypherStrings.InvisibleInvisible);
|
||||
return true;
|
||||
}
|
||||
|
||||
handler.SendSysMessage(CypherStrings.UseBol);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,617 @@
|
||||
/*
|
||||
* Copyright (C) 2012-2017 CypherCore <http://github.com/CypherCore>
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using Framework.Constants;
|
||||
using Framework.Database;
|
||||
using Framework.GameMath;
|
||||
using Framework.IO;
|
||||
using Game.DataStorage;
|
||||
using Game.Entities;
|
||||
using Game.Maps;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Game.Chat
|
||||
{
|
||||
[CommandGroup("gobject", RBACPermissions.CommandGobject)]
|
||||
class GameObjectCommands
|
||||
{
|
||||
[Command("activate", RBACPermissions.CommandGobjectActivate)]
|
||||
static bool HandleGameObjectActivateCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
if (args.Empty())
|
||||
return false;
|
||||
|
||||
string id = handler.extractKeyFromLink(args, "Hgameobject");
|
||||
if (string.IsNullOrEmpty(id))
|
||||
return false;
|
||||
|
||||
ulong guidLow = ulong.Parse(id);
|
||||
if (guidLow == 0)
|
||||
return false;
|
||||
|
||||
GameObject obj = handler.GetObjectFromPlayerMapByDbGuid(guidLow);
|
||||
if (!obj)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.CommandObjnotfound, guidLow);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Activate
|
||||
obj.SetLootState(LootState.Ready);
|
||||
obj.UseDoorOrButton(10000, false, handler.GetSession().GetPlayer());
|
||||
|
||||
handler.SendSysMessage("Object activated!");
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("delete", RBACPermissions.CommandGobjectDelete)]
|
||||
static bool HandleGameObjectDeleteCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
// number or [name] Shift-click form |color|Hgameobject:go_guid|h[name]|h|r
|
||||
string id = handler.extractKeyFromLink(args, "Hgameobject");
|
||||
if (string.IsNullOrEmpty(id))
|
||||
return false;
|
||||
|
||||
ulong guidLow = ulong.Parse(id);
|
||||
if (guidLow == 0)
|
||||
return false;
|
||||
|
||||
GameObject obj = handler.GetObjectFromPlayerMapByDbGuid(guidLow);
|
||||
if (!obj)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.CommandObjnotfound, guidLow);
|
||||
return false;
|
||||
}
|
||||
|
||||
ObjectGuid ownerGuid = obj.GetOwnerGUID();
|
||||
if (ownerGuid.IsEmpty())
|
||||
{
|
||||
Unit owner = Global.ObjAccessor.GetUnit(handler.GetPlayer(), ownerGuid);
|
||||
if (!owner || !ownerGuid.IsPlayer())
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.CommandDelobjrefercreature, ownerGuid.ToString(), obj.GetGUID().ToString());
|
||||
return false;
|
||||
}
|
||||
|
||||
owner.RemoveGameObject(obj, false);
|
||||
}
|
||||
|
||||
obj.SetRespawnTime(0); // not save respawn time
|
||||
obj.Delete();
|
||||
obj.DeleteFromDB();
|
||||
|
||||
handler.SendSysMessage(CypherStrings.CommandDelobjmessage, obj.GetGUID().ToString());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("move", RBACPermissions.CommandGobjectMove)]
|
||||
static bool HandleGameObjectMoveCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
// number or [name] Shift-click form |color|Hgameobject:go_guid|h[name]|h|r
|
||||
string id = handler.extractKeyFromLink(args, "Hgameobject");
|
||||
if (string.IsNullOrEmpty(id))
|
||||
return false;
|
||||
|
||||
ulong guidLow = ulong.Parse(id);
|
||||
if (guidLow == 0)
|
||||
return false;
|
||||
|
||||
GameObject obj = handler.GetObjectFromPlayerMapByDbGuid(guidLow);
|
||||
if (!obj)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.CommandObjnotfound, guidLow);
|
||||
return false;
|
||||
}
|
||||
|
||||
string toX = args.NextString();
|
||||
string toY = args.NextString();
|
||||
string toZ = args.NextString();
|
||||
|
||||
float x, y, z;
|
||||
if (string.IsNullOrEmpty(toX))
|
||||
{
|
||||
Player player = handler.GetSession().GetPlayer();
|
||||
player.GetPosition(out x, out y, out z);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (string.IsNullOrEmpty(toY) || string.IsNullOrEmpty(toZ))
|
||||
return false;
|
||||
|
||||
x = float.Parse(toX);
|
||||
y = float.Parse(toY);
|
||||
z = float.Parse(toZ);
|
||||
|
||||
if (!GridDefines.IsValidMapCoord(obj.GetMapId(), x, y, z))
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.InvalidTargetCoord, x, y, obj.GetMapId());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
obj.DestroyForNearbyPlayers();
|
||||
obj.RelocateStationaryPosition(x, y, z, obj.GetOrientation());
|
||||
obj.GetMap().GameObjectRelocation(obj, x, y, z, obj.GetOrientation());
|
||||
|
||||
obj.SaveToDB();
|
||||
|
||||
handler.SendSysMessage(CypherStrings.CommandMoveobjmessage, obj.GetSpawnId(), obj.GetGoInfo().name, obj.GetGUID().ToString());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("near", RBACPermissions.CommandGobjectNear)]
|
||||
static bool HandleGameObjectNearCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
float distance = args.Empty() ? 10.0f : args.NextSingle();
|
||||
uint count = 0;
|
||||
|
||||
Player player = handler.GetPlayer();
|
||||
|
||||
PreparedStatement stmt = DB.World.GetPreparedStatement(WorldStatements.SEL_GAMEOBJECT_NEAREST);
|
||||
stmt.AddValue(0, player.GetPositionX());
|
||||
stmt.AddValue(1, player.GetPositionY());
|
||||
stmt.AddValue(2, player.GetPositionZ());
|
||||
stmt.AddValue(3, player.GetMapId());
|
||||
stmt.AddValue(4, player.GetPositionX());
|
||||
stmt.AddValue(5, player.GetPositionY());
|
||||
stmt.AddValue(6, player.GetPositionZ());
|
||||
stmt.AddValue(7, distance * distance);
|
||||
SQLResult result = DB.World.Query(stmt);
|
||||
|
||||
if (!result.IsEmpty())
|
||||
{
|
||||
do
|
||||
{
|
||||
ulong guid = result.Read<ulong>(0);
|
||||
uint entry = result.Read<uint>(1);
|
||||
float x = result.Read<float>(2);
|
||||
float y = result.Read<float>(3);
|
||||
float z = result.Read<float>(4);
|
||||
ushort mapId = result.Read<ushort>(5);
|
||||
|
||||
GameObjectTemplate gameObjectInfo = Global.ObjectMgr.GetGameObjectTemplate(entry);
|
||||
if (gameObjectInfo == null)
|
||||
continue;
|
||||
|
||||
handler.SendSysMessage(CypherStrings.GoListChat, guid, entry, guid, gameObjectInfo.name, x, y, z, mapId);
|
||||
|
||||
++count;
|
||||
} while (result.NextRow());
|
||||
}
|
||||
|
||||
handler.SendSysMessage(CypherStrings.CommandNearobjmessage, distance, count);
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("target", RBACPermissions.CommandGobjectTarget)]
|
||||
static bool HandleGameObjectTargetCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
Player player = handler.GetSession().GetPlayer();
|
||||
SQLResult result;
|
||||
var activeEventsList = Global.GameEventMgr.GetActiveEventList();
|
||||
|
||||
if (!args.Empty())
|
||||
{
|
||||
// number or [name] Shift-click form |color|Hgameobject_entry:go_id|h[name]|h|r
|
||||
string idStr = handler.extractKeyFromLink(args, "Hgameobject_entry");
|
||||
if (string.IsNullOrEmpty(idStr))
|
||||
return false;
|
||||
|
||||
uint objectId = uint.Parse(idStr);
|
||||
if (objectId != 0)
|
||||
result = DB.World.Query("SELECT guid, id, position_x, position_y, position_z, orientation, map, PhaseId, PhaseGroup, (POW(position_x - '{0}', 2) + POW(position_y - '{1}', 2) + POW(position_z - '{2}', 2)) AS order_ FROM gameobject WHERE map = '{3}' AND id = '{4}' ORDER BY order_ ASC LIMIT 1",
|
||||
player.GetPositionX(), player.GetPositionY(), player.GetPositionZ(), player.GetMapId(), objectId);
|
||||
else
|
||||
{
|
||||
result = DB.World.Query(
|
||||
"SELECT guid, id, position_x, position_y, position_z, orientation, map, PhaseId, PhaseGroup, (POW(position_x - {0}, 2) + POW(position_y - {1}, 2) + POW(position_z - {2}, 2)) AS order_ " +
|
||||
"FROM gameobject LEFT JOIN gameobject_template ON gameobject_template.entry = gameobject.id WHERE map = {3} AND name LIKE CONCAT('%%', '{4}', '%%') ORDER BY order_ ASC LIMIT 1",
|
||||
player.GetPositionX(), player.GetPositionY(), player.GetPositionZ(), player.GetMapId(), objectId);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
StringBuilder eventFilter = new StringBuilder();
|
||||
eventFilter.Append(" AND (eventEntry IS NULL ");
|
||||
bool initString = true;
|
||||
|
||||
foreach (var entry in activeEventsList)
|
||||
{
|
||||
if (initString)
|
||||
{
|
||||
eventFilter.Append("OR eventEntry IN (" + entry);
|
||||
initString = false;
|
||||
}
|
||||
else
|
||||
eventFilter.Append(',' + entry);
|
||||
}
|
||||
|
||||
if (!initString)
|
||||
eventFilter.Append("))");
|
||||
else
|
||||
eventFilter.Append(')');
|
||||
|
||||
result = DB.World.Query("SELECT gameobject.guid, id, position_x, position_y, position_z, orientation, map, PhaseId, PhaseGroup, " +
|
||||
"(POW(position_x - {0}, 2) + POW(position_y - {1}, 2) + POW(position_z - {2}, 2)) AS order_ FROM gameobject " +
|
||||
"LEFT OUTER JOIN game_event_gameobject on gameobject.guid = game_event_gameobject.guid WHERE map = '{3}' {4} ORDER BY order_ ASC LIMIT 10",
|
||||
handler.GetSession().GetPlayer().GetPositionX(), handler.GetSession().GetPlayer().GetPositionY(), handler.GetSession().GetPlayer().GetPositionZ(),
|
||||
handler.GetSession().GetPlayer().GetMapId(), eventFilter.ToString());
|
||||
}
|
||||
|
||||
if (result.IsEmpty())
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.CommandTargetobjnotfound);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool found = false;
|
||||
float x, y, z, o;
|
||||
ulong guidLow;
|
||||
uint id, phaseId, phaseGroup;
|
||||
ushort mapId;
|
||||
uint poolId;
|
||||
|
||||
do
|
||||
{
|
||||
guidLow = result.Read<ulong>(0);
|
||||
id = result.Read<uint>(1);
|
||||
x = result.Read<float>(2);
|
||||
y = result.Read<float>(3);
|
||||
z = result.Read<float>(4);
|
||||
o = result.Read<float>(5);
|
||||
mapId = result.Read<ushort>(6);
|
||||
phaseId = result.Read<uint>(7);
|
||||
phaseGroup = result.Read<uint>(8);
|
||||
poolId = Global.PoolMgr.IsPartOfAPool<GameObject>(guidLow);
|
||||
if (poolId == 0 || Global.PoolMgr.IsSpawnedObject<GameObject>(guidLow))
|
||||
found = true;
|
||||
} while (result.NextRow() && !found);
|
||||
|
||||
if (!found)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.GameobjectNotExist, id);
|
||||
return false;
|
||||
}
|
||||
|
||||
GameObjectTemplate objectInfo = Global.ObjectMgr.GetGameObjectTemplate(id);
|
||||
|
||||
if (objectInfo == null)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.GameobjectNotExist, id);
|
||||
return false;
|
||||
}
|
||||
|
||||
GameObject target = handler.GetObjectFromPlayerMapByDbGuid(guidLow);
|
||||
|
||||
handler.SendSysMessage(CypherStrings.GameobjectDetail, guidLow, objectInfo.name, guidLow, id, x, y, z, mapId, o, phaseId, phaseGroup);
|
||||
|
||||
if (target)
|
||||
{
|
||||
int curRespawnDelay = (int)(target.GetRespawnTimeEx() - Time.UnixTime);
|
||||
if (curRespawnDelay < 0)
|
||||
curRespawnDelay = 0;
|
||||
|
||||
string curRespawnDelayStr = Time.secsToTimeString((uint)curRespawnDelay, true);
|
||||
string defRespawnDelayStr = Time.secsToTimeString(target.GetRespawnDelay(), true);
|
||||
|
||||
handler.SendSysMessage(CypherStrings.CommandRawpawntimes, defRespawnDelayStr, curRespawnDelayStr);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("turn", RBACPermissions.CommandGobjectTurn)]
|
||||
static bool HandleGameObjectTurnCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
// number or [name] Shift-click form |color|Hgameobject:go_id|h[name]|h|r
|
||||
string id = handler.extractKeyFromLink(args, "Hgameobject");
|
||||
if (string.IsNullOrEmpty(id))
|
||||
return false;
|
||||
|
||||
ulong guidLow = ulong.Parse(id);
|
||||
if (guidLow == 0)
|
||||
return false;
|
||||
|
||||
GameObject obj = handler.GetObjectFromPlayerMapByDbGuid(guidLow);
|
||||
if (!obj)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.CommandObjnotfound, guidLow);
|
||||
return false;
|
||||
}
|
||||
|
||||
string orientation = args.NextString();
|
||||
float oz = 0.0f, oy = 0.0f, ox = 0.0f;
|
||||
if (!orientation.IsEmpty())
|
||||
{
|
||||
oz = float.Parse(orientation);
|
||||
|
||||
orientation = args.NextString();
|
||||
if (!orientation.IsEmpty())
|
||||
{
|
||||
oy = float.Parse(orientation);
|
||||
orientation = args.NextString();
|
||||
if (!orientation.IsEmpty())
|
||||
ox = float.Parse(orientation);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Player player = handler.GetPlayer();
|
||||
oz = player.GetOrientation();
|
||||
}
|
||||
|
||||
obj.Relocate(obj.GetPositionX(), obj.GetPositionY(), obj.GetPositionZ());
|
||||
obj.RelocateStationaryPosition(obj.GetPositionX(), obj.GetPositionY(), obj.GetPositionZ(), obj.GetOrientation());
|
||||
obj.SetWorldRotationAngles(oz, oy, ox);
|
||||
obj.DestroyForNearbyPlayers();
|
||||
obj.UpdateObjectVisibility();
|
||||
|
||||
obj.SaveToDB();
|
||||
|
||||
handler.SendSysMessage(CypherStrings.CommandTurnobjmessage, obj.GetSpawnId(), obj.GetGoInfo().name, obj.GetGUID().ToString(), obj.GetOrientation());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("info", RBACPermissions.CommandGobjectInfo)]
|
||||
static bool HandleGameObjectInfoCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
uint entry = 0;
|
||||
GameObjectTypes type = 0;
|
||||
uint displayId = 0;
|
||||
string name;
|
||||
uint lootId = 0;
|
||||
|
||||
if (args.Empty())
|
||||
return false;
|
||||
|
||||
string param1 = handler.extractKeyFromLink(args, "Hgameobject_entry");
|
||||
if (param1.IsEmpty())
|
||||
return false;
|
||||
|
||||
if (param1.Equals("guid"))
|
||||
{
|
||||
string cValue = handler.extractKeyFromLink(args, "Hgameobject");
|
||||
if (cValue.IsEmpty())
|
||||
return false;
|
||||
|
||||
ulong guidLow = ulong.Parse(cValue);
|
||||
GameObjectData data = Global.ObjectMgr.GetGOData(guidLow);
|
||||
if (data == null)
|
||||
return false;
|
||||
entry = data.id;
|
||||
}
|
||||
else
|
||||
entry = uint.Parse(param1);
|
||||
|
||||
GameObjectTemplate gameObjectInfo = Global.ObjectMgr.GetGameObjectTemplate(entry);
|
||||
if (gameObjectInfo == null)
|
||||
return false;
|
||||
|
||||
type = gameObjectInfo.type;
|
||||
displayId = gameObjectInfo.displayId;
|
||||
name = gameObjectInfo.name;
|
||||
lootId = gameObjectInfo.GetLootId();
|
||||
|
||||
handler.SendSysMessage(CypherStrings.GoinfoEntry, entry);
|
||||
handler.SendSysMessage(CypherStrings.GoinfoType, type);
|
||||
handler.SendSysMessage(CypherStrings.GoinfoLootid, lootId);
|
||||
handler.SendSysMessage(CypherStrings.GoinfoDisplayid, displayId);
|
||||
handler.SendSysMessage(CypherStrings.GoinfoName, name);
|
||||
handler.SendSysMessage(CypherStrings.GoinfoSize, gameObjectInfo.size);
|
||||
|
||||
GameObjectTemplateAddon addon = Global.ObjectMgr.GetGameObjectTemplateAddon(entry);
|
||||
if (addon != null)
|
||||
handler.SendSysMessage(CypherStrings.GoinfoAddon, addon.faction, addon.flags);
|
||||
|
||||
GameObjectDisplayInfoRecord modelInfo = CliDB.GameObjectDisplayInfoStorage.LookupByKey(displayId);
|
||||
if (modelInfo != null)
|
||||
handler.SendSysMessage(CypherStrings.GoinfoModel, modelInfo.GeoBoxMax.X, modelInfo.GeoBoxMax.Y, modelInfo.GeoBoxMax.Z, modelInfo.GeoBoxMin.X, modelInfo.GeoBoxMin.Y, modelInfo.GeoBoxMin.Z);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
[CommandGroup("add", RBACPermissions.CommandGobjectAdd)]
|
||||
class AddCommands
|
||||
{
|
||||
[Command("", RBACPermissions.CommandGobjectAdd)]
|
||||
static bool HandleGameObjectAddCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
if (args.Empty())
|
||||
return false;
|
||||
|
||||
// number or [name] Shift-click form |color|Hgameobject_entry:go_id|h[name]|h|r
|
||||
string id = handler.extractKeyFromLink(args, "Hgameobject_entry");
|
||||
if (string.IsNullOrEmpty(id))
|
||||
return false;
|
||||
|
||||
uint objectId = uint.Parse(id);
|
||||
if (objectId == 0)
|
||||
return false;
|
||||
|
||||
uint spawntimeSecs = args.NextUInt32();
|
||||
|
||||
GameObjectTemplate objectInfo = Global.ObjectMgr.GetGameObjectTemplate(objectId);
|
||||
if (objectInfo == null)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.GameobjectNotExist, objectId);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (objectInfo.displayId != 0 && !CliDB.GameObjectDisplayInfoStorage.ContainsKey(objectInfo.displayId))
|
||||
{
|
||||
// report to DB errors log as in loading case
|
||||
Log.outError(LogFilter.Sql, "Gameobject (Entry {0} GoType: {1}) have invalid displayId ({2}), not spawned.", objectId, objectInfo.type, objectInfo.displayId);
|
||||
handler.SendSysMessage(CypherStrings.GameobjectHaveInvalidData, objectId);
|
||||
return false;
|
||||
}
|
||||
|
||||
Player player = handler.GetPlayer();
|
||||
Map map = player.GetMap();
|
||||
|
||||
GameObject obj = new GameObject();
|
||||
|
||||
Quaternion rotation = new Quaternion(Matrix3.fromEulerAnglesZYX(player.GetOrientation(), 0.0f, 0.0f));
|
||||
if (!obj.Create(objectInfo.entry, map, 0, player, rotation, 255, GameObjectState.Ready))
|
||||
return false;
|
||||
|
||||
obj.CopyPhaseFrom(player);
|
||||
|
||||
if (spawntimeSecs != 0)
|
||||
{
|
||||
obj.SetRespawnTime((int)spawntimeSecs);
|
||||
}
|
||||
|
||||
// fill the gameobject data and save to the db
|
||||
obj.SaveToDB(map.GetId(), (byte)(1 << (int)map.GetSpawnMode()), player.GetPhaseMask());
|
||||
ulong spawnId = obj.GetSpawnId();
|
||||
|
||||
// this will generate a new guid if the object is in an instance
|
||||
if (!obj.LoadGameObjectFromDB(spawnId, map))
|
||||
return false;
|
||||
|
||||
// TODO: is it really necessary to add both the real and DB table guid here ?
|
||||
Global.ObjectMgr.AddGameObjectToGrid(spawnId, Global.ObjectMgr.GetGOData(spawnId));
|
||||
handler.SendSysMessage(CypherStrings.GameobjectAdd, objectId, objectInfo.name, spawnId, player.GetPositionX(), player.GetPositionY(), player.GetPositionZ());
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("temp", RBACPermissions.CommandGobjectAddTemp)]
|
||||
static bool HandleGameObjectAddTempCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
if (args.Empty())
|
||||
return false;
|
||||
|
||||
uint id = args.NextUInt32();
|
||||
if (id == 0)
|
||||
return false;
|
||||
|
||||
Player player = handler.GetPlayer();
|
||||
|
||||
uint spawntime = args.NextUInt32();
|
||||
uint spawntm = 300;
|
||||
|
||||
if (spawntime != 0)
|
||||
spawntm = spawntime;
|
||||
|
||||
Quaternion rotation = new Quaternion(Matrix3.fromEulerAnglesZYX(player.GetOrientation(), 0.0f, 0.0f));
|
||||
|
||||
if (Global.ObjectMgr.GetGameObjectTemplate(id) == null)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.GameobjectNotExist, id);
|
||||
return false;
|
||||
}
|
||||
|
||||
player.SummonGameObject(id, player, rotation, spawntm);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
[CommandGroup("set", RBACPermissions.CommandGobjectSet)]
|
||||
class SetCommands
|
||||
{
|
||||
[Command("phase", RBACPermissions.CommandGobjectSetPhase)]
|
||||
static bool HandleGameObjectSetPhaseCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
/*// number or [name] Shift-click form |color|Hgameobject:go_id|h[name]|h|r
|
||||
string id = handler.extractKeyFromLink(args, "Hgameobject");
|
||||
if (string.IsNullOrEmpty(id))
|
||||
return false;
|
||||
|
||||
ulong guidLow = ulong.Parse(id);
|
||||
if (guidLow == 0)
|
||||
return false;
|
||||
|
||||
GameObject obj = null;
|
||||
|
||||
// by DB guid
|
||||
GameObjectData gameObjectData = Global.ObjectMgr.GetGOData(guidLow);
|
||||
if (gameObjectData != null)
|
||||
obj = handler.GetObjectGlobalyWithGuidOrNearWithDbGuid(guidLow, gameObjectData.id);
|
||||
|
||||
if (!obj)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.CommandObjnotfound, guidLow);
|
||||
return false;
|
||||
}
|
||||
|
||||
uint phaseMask = args.NextUInt32();
|
||||
if (phaseMask == 0)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.BadValue);
|
||||
return false;
|
||||
}
|
||||
|
||||
obj.SetPhaseMask(phaseMask, true);
|
||||
obj.SaveToDB();*/
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("state", RBACPermissions.CommandGobjectSetState)]
|
||||
static bool HandleGameObjectSetStateCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
// number or [name] Shift-click form |color|Hgameobject:go_id|h[name]|h|r
|
||||
string id = handler.extractKeyFromLink(args, "Hgameobject");
|
||||
if (string.IsNullOrEmpty(id))
|
||||
return false;
|
||||
|
||||
ulong guidLow = ulong.Parse(id);
|
||||
if (guidLow == 0)
|
||||
return false;
|
||||
|
||||
GameObject obj = handler.GetObjectFromPlayerMapByDbGuid(guidLow);
|
||||
if (!obj)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.CommandObjnotfound, guidLow);
|
||||
return false;
|
||||
}
|
||||
|
||||
string type = args.NextString();
|
||||
if (string.IsNullOrEmpty(type))
|
||||
return false;
|
||||
|
||||
int objectType = int.Parse(type);
|
||||
if (objectType < 0)
|
||||
{
|
||||
if (objectType == -1)
|
||||
obj.SendGameObjectDespawn();
|
||||
else if (objectType == -2)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
string state = args.NextString();
|
||||
if (string.IsNullOrEmpty(state))
|
||||
return false;
|
||||
|
||||
uint objectState = uint.Parse(state);
|
||||
|
||||
if (objectType < 4)
|
||||
obj.SetByteValue(GameObjectFields.Bytes1, (byte)objectType, (byte)objectState);
|
||||
else if (objectType == 4)
|
||||
obj.SendCustomAnim(objectState);
|
||||
|
||||
handler.SendSysMessage("Set gobject type {0} state {1}", objectType, objectState);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,622 @@
|
||||
/*
|
||||
* Copyright (C) 2012-2017 CypherCore <http://github.com/CypherCore>
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using Framework.Constants;
|
||||
using Framework.Database;
|
||||
using Framework.IO;
|
||||
using Game.DataStorage;
|
||||
using Game.Entities;
|
||||
using Game.Maps;
|
||||
using Game.SupportSystem;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.Contracts;
|
||||
|
||||
namespace Game.Chat.Commands
|
||||
{
|
||||
[CommandGroup("go", RBACPermissions.CommandGo)]
|
||||
class GoCommands
|
||||
{
|
||||
[Command("creature", RBACPermissions.CommandGoCreature)]
|
||||
static bool HandleGoCreatureCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
if (args.Empty())
|
||||
return false;
|
||||
|
||||
Player player = handler.GetSession().GetPlayer();
|
||||
|
||||
// "id" or number or [name] Shift-click form |color|Hcreature_entry:creature_id|h[name]|h|r
|
||||
string param1 = handler.extractKeyFromLink(args, "Hcreature");
|
||||
if (string.IsNullOrEmpty(param1))
|
||||
return false;
|
||||
|
||||
string whereClause = "";
|
||||
|
||||
// User wants to teleport to the NPC's template entry
|
||||
if (param1.Equals("id"))
|
||||
{
|
||||
// Get the "creature_template.entry"
|
||||
// number or [name] Shift-click form |color|Hcreature_entry:creature_id|h[name]|h|r
|
||||
string idStr = handler.extractKeyFromLink(args, "Hcreature_entry");
|
||||
if (string.IsNullOrEmpty(idStr))
|
||||
return false;
|
||||
|
||||
int entry = int.Parse(idStr);
|
||||
if (entry == 0)
|
||||
return false;
|
||||
|
||||
whereClause += "WHERE id = '" + entry + '\'';
|
||||
}
|
||||
else
|
||||
{
|
||||
ulong guidLow = ulong.Parse(param1);
|
||||
|
||||
// Number is invalid - maybe the user specified the mob's name
|
||||
if (guidLow == 0)
|
||||
{
|
||||
string name = param1;
|
||||
whereClause += ", creature_template WHERE creature.id = creature_template.entry AND creature_template.name LIKE '" + name + '\'';
|
||||
}
|
||||
else
|
||||
whereClause += "WHERE guid = '" + guidLow + '\'';
|
||||
}
|
||||
|
||||
SQLResult result = DB.World.Query("SELECT position_x, position_y, position_z, orientation, map FROM creature {0}", whereClause);
|
||||
if (result.IsEmpty())
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.CommandGocreatnotfound);
|
||||
return false;
|
||||
}
|
||||
if (result.GetRowCount() > 1)
|
||||
handler.SendSysMessage(CypherStrings.CommandGocreatmultiple);
|
||||
|
||||
float x = result.Read<float>(0);
|
||||
float y = result.Read<float>(1);
|
||||
float z = result.Read<float>(2);
|
||||
float o = result.Read<float>(3);
|
||||
uint mapId = result.Read<ushort>(4);
|
||||
|
||||
if (!GridDefines.IsValidMapCoord(mapId, x, y, z, o) || Global.ObjectMgr.IsTransportMap(mapId))
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.InvalidTargetCoord, x, y, mapId);
|
||||
return false;
|
||||
}
|
||||
|
||||
// stop flight if need
|
||||
if (player.IsInFlight())
|
||||
{
|
||||
player.GetMotionMaster().MovementExpired();
|
||||
player.CleanupAfterTaxiFlight();
|
||||
}
|
||||
// save only in non-flight case
|
||||
else
|
||||
player.SaveRecallPosition();
|
||||
|
||||
player.TeleportTo(mapId, x, y, z, o);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("graveyard", RBACPermissions.CommandGoGraveyard)]
|
||||
static bool HandleGoGraveyardCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
Player player = handler.GetSession().GetPlayer();
|
||||
|
||||
if (args.Empty())
|
||||
return false;
|
||||
|
||||
uint graveyardId = args.NextUInt32();
|
||||
if (graveyardId == 0)
|
||||
return false;
|
||||
|
||||
WorldSafeLocsRecord gy = CliDB.WorldSafeLocsStorage.LookupByKey(graveyardId);
|
||||
if (gy == null)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.CommandGraveyardnoexist, graveyardId);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!GridDefines.IsValidMapCoord(gy.MapID, gy.Loc.X, gy.Loc.Y, gy.Loc.Z))
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.InvalidTargetCoord, gy.Loc.X, gy.Loc.Y, gy.MapID);
|
||||
return false;
|
||||
}
|
||||
|
||||
// stop flight if need
|
||||
if (player.IsInFlight())
|
||||
{
|
||||
player.GetMotionMaster().MovementExpired();
|
||||
player.CleanupAfterTaxiFlight();
|
||||
}
|
||||
// save only in non-flight case
|
||||
else
|
||||
player.SaveRecallPosition();
|
||||
|
||||
player.TeleportTo(gy.MapID, gy.Loc.X, gy.Loc.Y, gy.Loc.Z, (gy.Facing * MathFunctions.PI) / 180); // Orientation is initially in degrees
|
||||
return true;
|
||||
}
|
||||
|
||||
//teleport to grid
|
||||
[Command("grid", RBACPermissions.CommandGoGrid)]
|
||||
static bool HandleGoGridCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
if (args.Empty())
|
||||
return false;
|
||||
|
||||
Player player = handler.GetSession().GetPlayer();
|
||||
|
||||
string gridX = args.NextString();
|
||||
string gridY = args.NextString();
|
||||
string id = args.NextString();
|
||||
|
||||
if (string.IsNullOrEmpty(gridX) || string.IsNullOrEmpty(gridY))
|
||||
return false;
|
||||
|
||||
uint mapId = !string.IsNullOrEmpty(id) ? uint.Parse(id) : player.GetMapId();
|
||||
|
||||
// center of grid
|
||||
float x = (float.Parse(gridX) - MapConst.CenterGridId + 0.5f) * MapConst.SizeofGrids;
|
||||
float y = (float.Parse(gridY) - MapConst.CenterGridId + 0.5f) * MapConst.SizeofGrids;
|
||||
|
||||
if (!GridDefines.IsValidMapCoord(mapId, x, y))
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.InvalidTargetCoord, x, y, mapId);
|
||||
return false;
|
||||
}
|
||||
|
||||
// stop flight if need
|
||||
if (player.IsInFlight())
|
||||
{
|
||||
player.GetMotionMaster().MovementExpired();
|
||||
player.CleanupAfterTaxiFlight();
|
||||
}
|
||||
// save only in non-flight case
|
||||
else
|
||||
player.SaveRecallPosition();
|
||||
|
||||
Map map = Global.MapMgr.CreateBaseMap(mapId);
|
||||
float z = Math.Max(map.GetHeight(x, y, MapConst.MaxHeight), map.GetWaterLevel(x, y));
|
||||
|
||||
player.TeleportTo(mapId, x, y, z, player.GetOrientation());
|
||||
return true;
|
||||
}
|
||||
|
||||
//teleport to gameobject
|
||||
[Command("object", RBACPermissions.CommandGoObject)]
|
||||
static bool HandleGoObjectCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
if (args.Empty())
|
||||
return false;
|
||||
|
||||
Player player = handler.GetSession().GetPlayer();
|
||||
|
||||
// number or [name] Shift-click form |color|Hgameobject:go_guid|h[name]|h|r
|
||||
string id = handler.extractKeyFromLink(args, "Hgameobject");
|
||||
if (string.IsNullOrEmpty(id))
|
||||
return false;
|
||||
|
||||
ulong guidLow = ulong.Parse(id);
|
||||
if (guidLow == 0)
|
||||
return false;
|
||||
|
||||
float x, y, z, o;
|
||||
uint mapId;
|
||||
|
||||
// by DB guid
|
||||
GameObjectData goData = Global.ObjectMgr.GetGOData(guidLow);
|
||||
if (goData != null)
|
||||
{
|
||||
x = goData.posX;
|
||||
y = goData.posY;
|
||||
z = goData.posZ;
|
||||
o = goData.orientation;
|
||||
mapId = goData.mapid;
|
||||
}
|
||||
else
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.CommandGoobjnotfound);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!GridDefines.IsValidMapCoord(mapId, x, y, z, o) || Global.ObjectMgr.IsTransportMap(mapId))
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.InvalidTargetCoord, x, y, mapId);
|
||||
return false;
|
||||
}
|
||||
|
||||
// stop flight if need
|
||||
if (player.IsInFlight())
|
||||
{
|
||||
player.GetMotionMaster().MovementExpired();
|
||||
player.CleanupAfterTaxiFlight();
|
||||
}
|
||||
// save only in non-flight case
|
||||
else
|
||||
player.SaveRecallPosition();
|
||||
|
||||
player.TeleportTo(mapId, x, y, z, o);
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("quest", RBACPermissions.CommandGoQuest)]
|
||||
static bool HandleGoQuestCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
if (args.Empty())
|
||||
return false;
|
||||
|
||||
Player player = handler.GetSession().GetPlayer();
|
||||
|
||||
string id = handler.extractKeyFromLink(args, "Hquest");
|
||||
if (string.IsNullOrEmpty(id))
|
||||
return false;
|
||||
|
||||
uint questID = uint.Parse(id);
|
||||
if (questID == 0)
|
||||
return false;
|
||||
|
||||
if (Global.ObjectMgr.GetQuestTemplate(questID) == null)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.CommandQuestNotfound, questID);
|
||||
return false;
|
||||
}
|
||||
|
||||
float x, y, z = 0;
|
||||
uint mapId = 0;
|
||||
|
||||
var poiData = Global.ObjectMgr.GetQuestPOIList(questID);
|
||||
if (poiData != null)
|
||||
{
|
||||
var data = poiData[0];
|
||||
|
||||
mapId = (uint)data.MapID;
|
||||
|
||||
x = data.points[0].X;
|
||||
y = data.points[0].Y;
|
||||
}
|
||||
else
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.CommandQuestNotfound, questID);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!GridDefines.IsValidMapCoord(mapId, x, y) || Global.ObjectMgr.IsTransportMap(mapId))
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.InvalidTargetCoord, x, y, mapId);
|
||||
return false;
|
||||
}
|
||||
|
||||
// stop flight if need
|
||||
if (player.IsInFlight())
|
||||
{
|
||||
player.GetMotionMaster().MovementExpired();
|
||||
player.CleanupAfterTaxiFlight();
|
||||
}
|
||||
// save only in non-flight case
|
||||
else
|
||||
player.SaveRecallPosition();
|
||||
|
||||
Map map = Global.MapMgr.CreateBaseMap(mapId);
|
||||
z = Math.Max(map.GetHeight(x, y, MapConst.MaxHeight), map.GetWaterLevel(x, y));
|
||||
|
||||
player.TeleportTo(mapId, x, y, z, 0.0f);
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("taxinode", RBACPermissions.CommandGoTaxinode)]
|
||||
static bool HandleGoTaxinodeCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
Player player = handler.GetSession().GetPlayer();
|
||||
|
||||
if (args.Empty())
|
||||
return false;
|
||||
|
||||
string id = handler.extractKeyFromLink(args, "Htaxinode");
|
||||
if (string.IsNullOrEmpty(id))
|
||||
return false;
|
||||
|
||||
uint nodeId = uint.Parse(id);
|
||||
if (nodeId == 0)
|
||||
return false;
|
||||
|
||||
TaxiNodesRecord node = CliDB.TaxiNodesStorage.LookupByKey(nodeId);
|
||||
if (node == null)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.CommandGotaxinodenotfound, nodeId);
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((node.Pos.X == 0.0f && node.Pos.Y == 0.0f && node.Pos.Z == 0.0f) ||
|
||||
!GridDefines.IsValidMapCoord(node.MapID, node.Pos.X, node.Pos.Y, node.Pos.Z))
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.InvalidTargetCoord, node.Pos.X, node.Pos.Y, node.MapID);
|
||||
return false;
|
||||
}
|
||||
|
||||
// stop flight if need
|
||||
if (player.IsInFlight())
|
||||
{
|
||||
player.GetMotionMaster().MovementExpired();
|
||||
player.CleanupAfterTaxiFlight();
|
||||
}
|
||||
// save only in non-flight case
|
||||
else
|
||||
player.SaveRecallPosition();
|
||||
|
||||
player.TeleportTo(node.MapID, node.Pos.X, node.Pos.Y, node.Pos.Z, player.GetOrientation());
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("trigger", RBACPermissions.CommandGoTrigger)]
|
||||
static bool HandleGoTriggerCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
Player player = handler.GetSession().GetPlayer();
|
||||
|
||||
if (args.Empty())
|
||||
return false;
|
||||
|
||||
uint areaTriggerId = args.NextUInt32();
|
||||
if (areaTriggerId == 0)
|
||||
return false;
|
||||
|
||||
AreaTriggerRecord at = CliDB.AreaTriggerStorage.LookupByKey(areaTriggerId);
|
||||
if (at == null)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.CommandGoareatrnotfound, areaTriggerId);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!GridDefines.IsValidMapCoord(at.MapID, at.Pos.X, at.Pos.Y, at.Pos.Z))
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.InvalidTargetCoord, at.Pos.X, at.Pos.Y, at.MapID);
|
||||
return false;
|
||||
}
|
||||
|
||||
// stop flight if need
|
||||
if (player.IsInFlight())
|
||||
{
|
||||
player.GetMotionMaster().MovementExpired();
|
||||
player.CleanupAfterTaxiFlight();
|
||||
}
|
||||
// save only in non-flight case
|
||||
else
|
||||
player.SaveRecallPosition();
|
||||
|
||||
player.TeleportTo(at.MapID, at.Pos.X, at.Pos.Y, at.Pos.Z, player.GetOrientation());
|
||||
return true;
|
||||
}
|
||||
|
||||
//teleport at coordinates
|
||||
[Command("zonexy", RBACPermissions.CommandGoZonexy)]
|
||||
static bool HandleGoZoneXYCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
if (args.Empty())
|
||||
return false;
|
||||
|
||||
Player player = handler.GetSession().GetPlayer();
|
||||
|
||||
string zoneX = args.NextString();
|
||||
string zoneY = args.NextString();
|
||||
|
||||
string id = handler.extractKeyFromLink(args, "Harea"); // string or [name] Shift-click form |color|Harea:area_id|h[name]|h|r
|
||||
|
||||
if (string.IsNullOrEmpty(zoneX) || string.IsNullOrEmpty(zoneY))
|
||||
return false;
|
||||
|
||||
float x = float.Parse(zoneX);
|
||||
float y = float.Parse(zoneY);
|
||||
|
||||
// prevent accept wrong numeric args
|
||||
if ((x == 0.0f && zoneX[0] != '0') || (y == 0.0f && zoneY[0] != '0'))
|
||||
return false;
|
||||
|
||||
uint areaId = !string.IsNullOrEmpty(id) ? uint.Parse(id) : player.GetZoneId();
|
||||
|
||||
AreaTableRecord areaEntry = CliDB.AreaTableStorage.LookupByKey(areaId);
|
||||
|
||||
if (x < 0 || x > 100 || y < 0 || y > 100 || areaEntry == null)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.InvalidZoneCoord, x, y, areaId);
|
||||
return false;
|
||||
}
|
||||
|
||||
// update to parent zone if exist (client map show only zones without parents)
|
||||
AreaTableRecord zoneEntry = areaEntry.ParentAreaID != 0 ? CliDB.AreaTableStorage.LookupByKey(areaEntry.ParentAreaID) : areaEntry;
|
||||
Contract.Assert(zoneEntry != null);
|
||||
|
||||
Map map = Global.MapMgr.CreateBaseMap(zoneEntry.MapId);
|
||||
|
||||
if (map.Instanceable())
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.InvalidZoneMap, areaId, areaEntry.AreaName[handler.GetSessionDbcLocale()], map.GetId(), map.GetMapName());
|
||||
return false;
|
||||
}
|
||||
|
||||
Global.DB2Mgr.Zone2MapCoordinates(areaEntry.ParentAreaID != 0 ? areaEntry.ParentAreaID : areaId, ref x, ref y);
|
||||
|
||||
if (!GridDefines.IsValidMapCoord(zoneEntry.MapId, x, y))
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.InvalidTargetCoord, x, y, zoneEntry.MapId);
|
||||
return false;
|
||||
}
|
||||
|
||||
// stop flight if need
|
||||
if (player.IsInFlight())
|
||||
{
|
||||
player.GetMotionMaster().MovementExpired();
|
||||
player.CleanupAfterTaxiFlight();
|
||||
}
|
||||
// save only in non-flight case
|
||||
else
|
||||
player.SaveRecallPosition();
|
||||
|
||||
float z = Math.Max(map.GetHeight(x, y, MapConst.MaxHeight), map.GetWaterLevel(x, y));
|
||||
|
||||
player.TeleportTo(zoneEntry.MapId, x, y, z, player.GetOrientation());
|
||||
return true;
|
||||
}
|
||||
|
||||
//teleport at coordinates, including Z and orientation
|
||||
[Command("xyz", RBACPermissions.CommandGoXyz)]
|
||||
static bool HandleGoXYZCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
if (args.Empty())
|
||||
return false;
|
||||
|
||||
Player player = handler.GetSession().GetPlayer();
|
||||
|
||||
string goX = args.NextString();
|
||||
string goY = args.NextString();
|
||||
string goZ = args.NextString();
|
||||
string id = args.NextString();
|
||||
string port = args.NextString();
|
||||
|
||||
if (goX.IsEmpty() || goY.IsEmpty())
|
||||
return false;
|
||||
|
||||
float x = float.Parse(goX);
|
||||
float y = float.Parse(goY);
|
||||
float z;
|
||||
float ort = !port.IsEmpty() ? float.Parse(port) : player.GetOrientation();
|
||||
uint mapId = !id.IsEmpty() ? uint.Parse(id) : player.GetMapId();
|
||||
|
||||
if (!goZ.IsEmpty())
|
||||
{
|
||||
z = float.Parse(goZ);
|
||||
if (!GridDefines.IsValidMapCoord(mapId, x, y, z))
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.InvalidTargetCoord, x, y, mapId);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!GridDefines.IsValidMapCoord(mapId, x, y))
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.InvalidTargetCoord, x, y, mapId);
|
||||
return false;
|
||||
}
|
||||
Map map = Global.MapMgr.CreateBaseMap(mapId);
|
||||
z = Math.Max(map.GetHeight(x, y, MapConst.MaxHeight), map.GetWaterLevel(x, y));
|
||||
}
|
||||
|
||||
// stop flight if need
|
||||
if (player.IsInFlight())
|
||||
{
|
||||
player.GetMotionMaster().MovementExpired();
|
||||
player.CleanupAfterTaxiFlight();
|
||||
}
|
||||
// save only in non-flight case
|
||||
else
|
||||
player.SaveRecallPosition();
|
||||
|
||||
player.TeleportTo(mapId, x, y, z, ort);
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("bugticket", RBACPermissions.CommandGoBugTicket)]
|
||||
static bool HandleGoBugTicketCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
return HandleGoTicketCommand<BugTicket>(args, handler);
|
||||
}
|
||||
|
||||
[Command("complaintticket", RBACPermissions.CommandGoComplaintTicket)]
|
||||
static bool HandleGoComplaintTicketCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
return HandleGoTicketCommand<ComplaintTicket>(args, handler);
|
||||
}
|
||||
|
||||
[Command("suggestionticket", RBACPermissions.CommandGoSuggestionTicket)]
|
||||
static bool HandleGoSuggestionTicketCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
return HandleGoTicketCommand<SuggestionTicket>(args, handler);
|
||||
}
|
||||
|
||||
static bool HandleGoTicketCommand<T>(StringArguments args, CommandHandler handler)where T : Ticket
|
||||
{
|
||||
if (args.Empty())
|
||||
return false;
|
||||
|
||||
uint ticketId = args.NextUInt32();
|
||||
if (ticketId == 0)
|
||||
return false;
|
||||
|
||||
T ticket = Global.SupportMgr.GetTicket<T>(ticketId);
|
||||
if (ticket == null)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.CommandTicketnotexist);
|
||||
return true;
|
||||
}
|
||||
|
||||
Player player = handler.GetSession().GetPlayer();
|
||||
if (player.IsInFlight())
|
||||
{
|
||||
player.GetMotionMaster().MovementExpired();
|
||||
player.CleanupAfterTaxiFlight();
|
||||
}
|
||||
else
|
||||
player.SaveRecallPosition();
|
||||
|
||||
ticket.TeleportTo(player);
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("offset", RBACPermissions.CommandGoOffset)]
|
||||
static bool HandleGoOffsetCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
if (args.Empty())
|
||||
return false;
|
||||
|
||||
Player player = handler.GetSession().GetPlayer();
|
||||
|
||||
string goX = args.NextString();
|
||||
string goY = args.NextString();
|
||||
string goZ = args.NextString();
|
||||
string id = args.NextString();
|
||||
string port = args.NextString();
|
||||
|
||||
float x, y, z, o;
|
||||
player.GetPosition(out x, out y, out z, out o);
|
||||
if (!goX.IsEmpty())
|
||||
x += float.Parse(goX);
|
||||
if (!goY.IsEmpty())
|
||||
y += float.Parse(goY);
|
||||
if (!goZ.IsEmpty())
|
||||
z += float.Parse(goZ);
|
||||
if (!port.IsEmpty())
|
||||
o += float.Parse(port);
|
||||
|
||||
if (!GridDefines.IsValidMapCoord(x, y, z, o))
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.InvalidTargetCoord, x, y, player.GetMapId());
|
||||
return false;
|
||||
}
|
||||
|
||||
// stop flight if need
|
||||
if (player.IsInFlight())
|
||||
{
|
||||
player.GetMotionMaster().MovementExpired();
|
||||
player.CleanupAfterTaxiFlight();
|
||||
}
|
||||
// save only in non-flight case
|
||||
else
|
||||
player.SaveRecallPosition();
|
||||
|
||||
player.TeleportTo(player.GetMapId(), x, y, z, o);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,351 @@
|
||||
/*
|
||||
* Copyright (C) 2012-2017 CypherCore <http://github.com/CypherCore>
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using Framework.Constants;
|
||||
using Framework.Database;
|
||||
using Framework.IO;
|
||||
using Game.DataStorage;
|
||||
using Game.DungeonFinding;
|
||||
using Game.Entities;
|
||||
using Game.Groups;
|
||||
using Game.Maps;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Game.Chat
|
||||
{
|
||||
[CommandGroup("group", RBACPermissions.CommandGroup)]
|
||||
class GroupCommands
|
||||
{
|
||||
// Summon group of player
|
||||
[Command("summon", RBACPermissions.CommandGroupSummon)]
|
||||
static bool HandleGroupSummonCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
Player target;
|
||||
if (!handler.extractPlayerTarget(args, out target))
|
||||
return false;
|
||||
|
||||
// check online security
|
||||
if (handler.HasLowerSecurity(target, ObjectGuid.Empty))
|
||||
return false;
|
||||
|
||||
Group group = target.GetGroup();
|
||||
|
||||
string nameLink = handler.GetNameLink(target);
|
||||
|
||||
if (!group)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.NotInGroup, nameLink);
|
||||
return false;
|
||||
}
|
||||
|
||||
Player gmPlayer = handler.GetSession().GetPlayer();
|
||||
Group gmGroup = gmPlayer.GetGroup();
|
||||
Map gmMap = gmPlayer.GetMap();
|
||||
bool toInstance = gmMap.Instanceable();
|
||||
|
||||
// we are in instance, and can summon only player in our group with us as lead
|
||||
if (toInstance && (
|
||||
!gmGroup || group.GetLeaderGUID() != gmPlayer.GetGUID() ||
|
||||
gmGroup.GetLeaderGUID() != gmPlayer.GetGUID()))
|
||||
// the last check is a bit excessive, but let it be, just in case
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.CannotSummonToInst);
|
||||
return false;
|
||||
}
|
||||
|
||||
for (GroupReference refe = group.GetFirstMember(); refe != null; refe = refe.next())
|
||||
{
|
||||
Player player = refe.GetSource();
|
||||
|
||||
if (!player || player == gmPlayer || player.GetSession() == null)
|
||||
continue;
|
||||
|
||||
// check online security
|
||||
if (handler.HasLowerSecurity(player, ObjectGuid.Empty))
|
||||
return false;
|
||||
|
||||
string plNameLink = handler.GetNameLink(player);
|
||||
|
||||
if (player.IsBeingTeleported())
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.IsTeleported, plNameLink);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (toInstance)
|
||||
{
|
||||
Map playerMap = player.GetMap();
|
||||
|
||||
if (playerMap.Instanceable() && playerMap.GetInstanceId() != gmMap.GetInstanceId())
|
||||
{
|
||||
// cannot summon from instance to instance
|
||||
handler.SendSysMessage(CypherStrings.CannotSummonToInst, plNameLink);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
handler.SendSysMessage(CypherStrings.Summoning, plNameLink, "");
|
||||
if (handler.needReportToTarget(player))
|
||||
player.SendSysMessage(CypherStrings.SummonedBy, handler.GetNameLink());
|
||||
|
||||
// stop flight if need
|
||||
if (player.IsInFlight())
|
||||
{
|
||||
player.GetMotionMaster().MovementExpired();
|
||||
player.CleanupAfterTaxiFlight();
|
||||
}
|
||||
// save only in non-flight case
|
||||
else
|
||||
player.SaveRecallPosition();
|
||||
|
||||
// before GM
|
||||
float x, y, z;
|
||||
gmPlayer.GetClosePoint(out x, out y, out z, player.GetObjectSize());
|
||||
player.TeleportTo(gmPlayer.GetMapId(), x, y, z, player.GetOrientation());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("leader", RBACPermissions.CommandGroupLeader)]
|
||||
static bool HandleGroupLeaderCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
Player player = null;
|
||||
Group group = null;
|
||||
ObjectGuid guid = ObjectGuid.Empty;
|
||||
string nameStr = args.NextString();
|
||||
|
||||
if (!handler.GetPlayerGroupAndGUIDByName(nameStr, out player, out group, out guid))
|
||||
return false;
|
||||
|
||||
if (!group)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.GroupNotInGroup, player.GetName());
|
||||
return false;
|
||||
}
|
||||
|
||||
if (group.GetLeaderGUID() != guid)
|
||||
{
|
||||
group.ChangeLeader(guid);
|
||||
group.SendUpdate();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("disband", RBACPermissions.CommandGroupDisband)]
|
||||
static bool HandleGroupDisbandCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
Player player = null;
|
||||
Group group = null;
|
||||
ObjectGuid guid = ObjectGuid.Empty;
|
||||
string nameStr = args.NextString();
|
||||
|
||||
if (!handler.GetPlayerGroupAndGUIDByName(nameStr, out player, out group, out guid))
|
||||
return false;
|
||||
|
||||
if (!group)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.GroupNotInGroup, player.GetName());
|
||||
return false;
|
||||
}
|
||||
|
||||
group.Disband();
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("remove", RBACPermissions.CommandGroupRemove)]
|
||||
static bool HandleGroupRemoveCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
Player player = null;
|
||||
Group group = null;
|
||||
ObjectGuid guid = ObjectGuid.Empty;
|
||||
string nameStr = args.NextString();
|
||||
|
||||
if (!handler.GetPlayerGroupAndGUIDByName(nameStr, out player, out group, out guid))
|
||||
return false;
|
||||
|
||||
if (!group)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.GroupNotInGroup, player.GetName());
|
||||
return false;
|
||||
}
|
||||
|
||||
group.RemoveMember(guid);
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("join", RBACPermissions.CommandGroupJoin)]
|
||||
static bool HandleGroupJoinCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
if (args.Empty())
|
||||
return false;
|
||||
|
||||
Player playerSource = null;
|
||||
Player playerTarget = null;
|
||||
Group groupSource = null;
|
||||
Group groupTarget = null;
|
||||
ObjectGuid guidSource = ObjectGuid.Empty;
|
||||
ObjectGuid guidTarget = ObjectGuid.Empty;
|
||||
string nameplgrStr = args.NextString();
|
||||
string nameplStr = args.NextString();
|
||||
|
||||
if (!handler.GetPlayerGroupAndGUIDByName(nameplgrStr, out playerSource, out groupSource, out guidSource, true))
|
||||
return false;
|
||||
|
||||
if (!groupSource)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.GroupNotInGroup, playerSource.GetName());
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!handler.GetPlayerGroupAndGUIDByName(nameplStr, out playerTarget, out groupTarget, out guidTarget, true))
|
||||
return false;
|
||||
|
||||
if (groupTarget || playerTarget.GetGroup() == groupSource)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.GroupAlreadyInGroup, playerTarget.GetName());
|
||||
return false;
|
||||
}
|
||||
|
||||
if (groupSource.IsFull())
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.GroupFull);
|
||||
return false;
|
||||
}
|
||||
|
||||
groupSource.AddMember(playerTarget);
|
||||
groupSource.BroadcastGroupUpdate();
|
||||
handler.SendSysMessage(CypherStrings.GroupPlayerJoined, playerTarget.GetName(), playerSource.GetName());
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("list", RBACPermissions.CommandGroupList)]
|
||||
static bool HandleGroupListCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
// Get ALL the variables!
|
||||
Player playerTarget;
|
||||
uint phase = 0;
|
||||
ObjectGuid guidTarget;
|
||||
string nameTarget;
|
||||
string zoneName = "";
|
||||
string onlineState = "";
|
||||
|
||||
// Parse the guid to uint32...
|
||||
ObjectGuid parseGUID = ObjectGuid.Create(HighGuid.Player, args.NextUInt64());
|
||||
|
||||
// ... and try to extract a player out of it.
|
||||
if (ObjectManager.GetPlayerNameByGUID(parseGUID, out nameTarget))
|
||||
{
|
||||
playerTarget = Global.ObjAccessor.FindPlayer(parseGUID);
|
||||
guidTarget = parseGUID;
|
||||
}
|
||||
// If not, we return false and end right away.
|
||||
else if (!handler.extractPlayerTarget(args, out playerTarget, out guidTarget, out nameTarget))
|
||||
return false;
|
||||
|
||||
// Next, we need a group. So we define a group variable.
|
||||
Group groupTarget = null;
|
||||
|
||||
// We try to extract a group from an online player.
|
||||
if (playerTarget)
|
||||
groupTarget = playerTarget.GetGroup();
|
||||
|
||||
// If not, we extract it from the SQL.
|
||||
if (!groupTarget)
|
||||
{
|
||||
PreparedStatement stmt = DB.Characters.GetPreparedStatement(CharStatements.SEL_GROUP_MEMBER);
|
||||
stmt.AddValue(0, guidTarget.GetCounter());
|
||||
SQLResult resultGroup = DB.Characters.Query(stmt);
|
||||
if (!resultGroup.IsEmpty())
|
||||
groupTarget = Global.GroupMgr.GetGroupByDbStoreId(resultGroup.Read<uint>(0));
|
||||
}
|
||||
|
||||
// If both fails, players simply has no party. Return false.
|
||||
if (!groupTarget)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.GroupNotInGroup, nameTarget);
|
||||
return false;
|
||||
}
|
||||
|
||||
// We get the group members after successfully detecting a group.
|
||||
var members = groupTarget.GetMemberSlots();
|
||||
|
||||
// To avoid a cluster fuck, namely trying multiple queries to simply get a group member count...
|
||||
handler.SendSysMessage(CypherStrings.GroupType, (groupTarget.isRaidGroup() ? "raid" : "party"), members.Count);
|
||||
// ... we simply move the group type and member count print after retrieving the slots and simply output it's size.
|
||||
|
||||
// While rather dirty codestyle-wise, it saves space (if only a little). For each member, we look several informations up.
|
||||
foreach (var slot in members)
|
||||
{
|
||||
// Check for given flag and assign it to that iterator
|
||||
string flags = "";
|
||||
if (slot.flags.HasAnyFlag(GroupMemberFlags.Assistant))
|
||||
flags = "Assistant";
|
||||
|
||||
if (slot.flags.HasAnyFlag(GroupMemberFlags.MainTank))
|
||||
{
|
||||
if (!string.IsNullOrEmpty(flags))
|
||||
flags += ", ";
|
||||
flags += "MainTank";
|
||||
}
|
||||
|
||||
if (slot.flags.HasAnyFlag(GroupMemberFlags.MainAssist))
|
||||
{
|
||||
if (!string.IsNullOrEmpty(flags))
|
||||
flags += ", ";
|
||||
flags += "MainAssist";
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(flags))
|
||||
flags = "None";
|
||||
|
||||
// Check if iterator is online. If is...
|
||||
Player p = Global.ObjAccessor.FindPlayer(slot.guid);
|
||||
if (p && p.IsInWorld)
|
||||
{
|
||||
// ... than, it prints information like "is online", where he is, etc...
|
||||
onlineState = "online";
|
||||
phase = (!p.IsGameMaster() ? p.GetPhaseMask() : uint.MaxValue);
|
||||
|
||||
AreaTableRecord area = CliDB.AreaTableStorage.LookupByKey(p.GetAreaId());
|
||||
if (area != null)
|
||||
{
|
||||
AreaTableRecord zone = CliDB.AreaTableStorage.LookupByKey(area.ParentAreaID);
|
||||
if (zone != null)
|
||||
zoneName = zone.AreaName[handler.GetSessionDbcLocale()];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// ... else, everything is set to offline or neutral values.
|
||||
zoneName = "<ERROR>";
|
||||
onlineState = "Offline";
|
||||
phase = 0;
|
||||
}
|
||||
|
||||
// Now we can print those informations for every single member of each group!
|
||||
handler.SendSysMessage(CypherStrings.GroupPlayerNameGuid, slot.name, onlineState,
|
||||
zoneName, phase, slot.guid.ToString(), flags, LFGQueue.GetRolesString(slot.roles));
|
||||
}
|
||||
|
||||
// And finish after every iterator is done.
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,226 @@
|
||||
/*
|
||||
* Copyright (C) 2012-2017 CypherCore <http://github.com/CypherCore>
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using Framework.Constants;
|
||||
using Framework.IO;
|
||||
using Game.Entities;
|
||||
using Game.Guilds;
|
||||
|
||||
namespace Game.Chat
|
||||
{
|
||||
[CommandGroup("guild", RBACPermissions.CommandGuild, true)]
|
||||
class GuildCommands
|
||||
{
|
||||
[Command("create", RBACPermissions.CommandGuildCreate, true)]
|
||||
static bool HandleGuildCreateCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
if (args.Empty())
|
||||
return false;
|
||||
|
||||
Player target;
|
||||
if (!handler.extractPlayerTarget(args[0] != '"' ? args : null, out target))
|
||||
return false;
|
||||
|
||||
string guildname = handler.extractQuotedArg(args.NextString());
|
||||
if (string.IsNullOrEmpty(guildname))
|
||||
return false;
|
||||
|
||||
if (target.GetGuildId() != 0)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.PlayerInGuild);
|
||||
return true;
|
||||
}
|
||||
|
||||
Guild guild = new Guild();
|
||||
if (!guild.Create(target, guildname))
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.GuildNotCreated);
|
||||
return false;
|
||||
}
|
||||
|
||||
Global.GuildMgr.AddGuild(guild);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("delete", RBACPermissions.CommandGuildDelete, true)]
|
||||
static bool HandleGuildDeleteCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
string guildName = handler.extractQuotedArg(args.NextString());
|
||||
if (string.IsNullOrEmpty(guildName))
|
||||
return false;
|
||||
|
||||
Guild guild = Global.GuildMgr.GetGuildByName(guildName);
|
||||
if (guild == null)
|
||||
return false;
|
||||
|
||||
guild.Disband();
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("invite", RBACPermissions.CommandGuildInvite, true)]
|
||||
static bool HandleGuildInviteCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
if (args.Empty())
|
||||
return false;
|
||||
|
||||
Player target;
|
||||
if (!handler.extractPlayerTarget(args[0] != '"' ? args : null, out target))
|
||||
return false;
|
||||
|
||||
string guildName = handler.extractQuotedArg(args.NextString());
|
||||
if (string.IsNullOrEmpty(guildName))
|
||||
return false;
|
||||
|
||||
Guild targetGuild = Global.GuildMgr.GetGuildByName(guildName);
|
||||
if (targetGuild == null)
|
||||
return false;
|
||||
|
||||
targetGuild.AddMember(target.GetGUID());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("uninvite", RBACPermissions.CommandGuildUninvite, true)]
|
||||
static bool HandleGuildUninviteCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
Player target;
|
||||
ObjectGuid targetGuid = ObjectGuid.Empty;
|
||||
if (!handler.extractPlayerTarget(args, out target, out targetGuid))
|
||||
return false;
|
||||
|
||||
uint guildId = target != null ? target.GetGuildId() : Player.GetGuildIdFromDB(targetGuid);
|
||||
if (guildId == 0)
|
||||
return false;
|
||||
|
||||
Guild targetGuild = Global.GuildMgr.GetGuildById(guildId);
|
||||
if (targetGuild == null)
|
||||
return false;
|
||||
|
||||
targetGuild.DeleteMember(targetGuid, false, true, true);
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("rank", RBACPermissions.CommandGuildRank, true)]
|
||||
static bool HandleGuildRankCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
string nameStr;
|
||||
string rankStr;
|
||||
handler.extractOptFirstArg(args, out nameStr, out rankStr);
|
||||
if (string.IsNullOrEmpty(rankStr))
|
||||
return false;
|
||||
|
||||
Player target;
|
||||
ObjectGuid targetGuid;
|
||||
string target_name;
|
||||
if (!handler.extractPlayerTarget(new StringArguments(nameStr), out target, out targetGuid, out target_name))
|
||||
return false;
|
||||
|
||||
ulong guildId = target ? target.GetGuildId() : Player.GetGuildIdFromDB(targetGuid);
|
||||
if (guildId == 0)
|
||||
return false;
|
||||
|
||||
Guild targetGuild = Global.GuildMgr.GetGuildById(guildId);
|
||||
if (!targetGuild)
|
||||
return false;
|
||||
|
||||
byte newRank = byte.Parse(rankStr);
|
||||
return targetGuild.ChangeMemberRank(targetGuid, newRank);
|
||||
}
|
||||
|
||||
[Command("rename", RBACPermissions.CommandGuildRename, true)]
|
||||
static bool HandleGuildRenameCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
if (args.Empty())
|
||||
return false;
|
||||
|
||||
string oldGuildStr = handler.extractQuotedArg(args.NextString());
|
||||
if (string.IsNullOrEmpty(oldGuildStr))
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.BadValue);
|
||||
return false;
|
||||
}
|
||||
|
||||
string newGuildStr = handler.extractQuotedArg(args.NextString());
|
||||
if (string.IsNullOrEmpty(newGuildStr))
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.InsertGuildName);
|
||||
return false;
|
||||
}
|
||||
|
||||
Guild guild = Global.GuildMgr.GetGuildByName(oldGuildStr);
|
||||
if (!guild)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.CommandCouldnotfind, oldGuildStr);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (Global.GuildMgr.GetGuildByName(newGuildStr))
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.GuildRenameAlreadyExists, newGuildStr);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!guild.SetName(newGuildStr))
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.BadValue);
|
||||
return false;
|
||||
}
|
||||
|
||||
handler.SendSysMessage(CypherStrings.GuildRenameDone, oldGuildStr, newGuildStr);
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("info", RBACPermissions.CommandGuildInfo, true)]
|
||||
static bool HandleGuildInfoCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
Guild guild = null;
|
||||
Player target = handler.getSelectedPlayerOrSelf();
|
||||
|
||||
if (!args.Empty() && args[0] != '\0')
|
||||
{
|
||||
if (char.IsDigit(args[0]))
|
||||
guild = Global.GuildMgr.GetGuildById(args.NextUInt64());
|
||||
else
|
||||
guild = Global.GuildMgr.GetGuildByName(args.NextString());
|
||||
}
|
||||
else if (target)
|
||||
guild = target.GetGuild();
|
||||
|
||||
if (!guild)
|
||||
return false;
|
||||
|
||||
// Display Guild Information
|
||||
handler.SendSysMessage(CypherStrings.GuildInfoName, guild.GetName(), guild.GetId()); // Guild Id + Name
|
||||
|
||||
string guildMasterName;
|
||||
if (ObjectManager.GetPlayerNameByGUID(guild.GetLeaderGUID(), out guildMasterName))
|
||||
handler.SendSysMessage(CypherStrings.GuildInfoGuildMaster, guildMasterName, guild.GetLeaderGUID().ToString()); // Guild Master
|
||||
|
||||
// Format creation date
|
||||
|
||||
var createdDateTime = Time.UnixTimeToDateTime(guild.GetCreatedDate());
|
||||
handler.SendSysMessage(CypherStrings.GuildInfoCreationDate, createdDateTime.ToLongDateString()); // Creation Date
|
||||
handler.SendSysMessage(CypherStrings.GuildInfoMemberCount, guild.GetMembersCount()); // Number of Members
|
||||
handler.SendSysMessage(CypherStrings.GuildInfoBankGold, guild.GetBankMoney() / 100 / 100); // Bank Gold (in gold coins)
|
||||
handler.SendSysMessage(CypherStrings.GuildInfoLevel, guild.GetLevel()); // Level
|
||||
handler.SendSysMessage(CypherStrings.GuildInfoMotd, guild.GetMOTD()); // Message of the Day
|
||||
handler.SendSysMessage(CypherStrings.GuildInfoExtraInfo, guild.GetInfo()); // Extra Information
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
* Copyright (C) 2012-2017 CypherCore <http://github.com/CypherCore>
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using Framework.Constants;
|
||||
using Framework.IO;
|
||||
using Game.Entities;
|
||||
|
||||
namespace Game.Chat.Commands
|
||||
{
|
||||
[CommandGroup("honor", RBACPermissions.CommandHonor)]
|
||||
class HonorCommands
|
||||
{
|
||||
[Command("update", RBACPermissions.CommandHonorUpdate)]
|
||||
static bool HandleHonorUpdateCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
Player target = handler.getSelectedPlayer();
|
||||
if (!target)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.PlayerNotFound);
|
||||
return false;
|
||||
}
|
||||
|
||||
// check online security
|
||||
if (handler.HasLowerSecurity(target, ObjectGuid.Empty))
|
||||
return false;
|
||||
|
||||
target.UpdateHonorFields();
|
||||
return true;
|
||||
}
|
||||
|
||||
[CommandGroup("add", RBACPermissions.CommandHonorAdd)]
|
||||
class HonorAddCommands
|
||||
{
|
||||
[Command("", RBACPermissions.CommandHonorAdd)]
|
||||
static bool HandleHonorAddCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
if (args.Empty())
|
||||
return false;
|
||||
|
||||
Player target = handler.getSelectedPlayer();
|
||||
if (!target)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.PlayerNotFound);
|
||||
return false;
|
||||
}
|
||||
|
||||
// check online security
|
||||
if (handler.HasLowerSecurity(target, ObjectGuid.Empty))
|
||||
return false;
|
||||
|
||||
int amount = args.NextInt32();
|
||||
target.RewardHonor(null, 1, amount);
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("kill", RBACPermissions.CommandHonorAddKill)]
|
||||
static bool HandleHonorAddKillCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
Unit target = handler.getSelectedUnit();
|
||||
if (!target)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.PlayerNotFound);
|
||||
return false;
|
||||
}
|
||||
|
||||
// check online security
|
||||
Player player = target.ToPlayer();
|
||||
if (player)
|
||||
if (handler.HasLowerSecurity(player, ObjectGuid.Empty))
|
||||
return false;
|
||||
|
||||
handler.GetPlayer().RewardHonor(target, 1);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,273 @@
|
||||
/*
|
||||
* Copyright (C) 2012-2017 CypherCore <http://github.com/CypherCore>
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using Framework.Constants;
|
||||
using Framework.IO;
|
||||
using Game.Entities;
|
||||
using Game.Groups;
|
||||
using Game.Maps;
|
||||
|
||||
namespace Game.Chat
|
||||
{
|
||||
[CommandGroup("instance", RBACPermissions.CommandInstance, true)]
|
||||
class InstanceCommands
|
||||
{
|
||||
[Command("listbinds", RBACPermissions.CommandInstanceListbinds)]
|
||||
static bool HandleInstanceListBinds(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
Player player = handler.getSelectedPlayer();
|
||||
if (!player)
|
||||
player = handler.GetSession().GetPlayer();
|
||||
|
||||
string format = "map: {0} inst: {1} perm: {2} diff: {3} canReset: {4} TTR: {5}";
|
||||
|
||||
uint counter = 0;
|
||||
for (byte i = 0; i < (int)Difficulty.Max; ++i)
|
||||
{
|
||||
var binds = player.GetBoundInstances((Difficulty)i);
|
||||
foreach (var pair in binds)
|
||||
{
|
||||
InstanceSave save = pair.Value.save;
|
||||
string timeleft = Time.GetTimeString(save.GetResetTime() - Time.UnixTime);
|
||||
handler.SendSysMessage(format, pair.Key, save.GetInstanceId(), pair.Value.perm ? "yes" : "no", save.GetDifficultyID(), save.CanReset() ? "yes" : "no", timeleft);
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
handler.SendSysMessage("player binds: {0}", counter);
|
||||
|
||||
counter = 0;
|
||||
Group group = player.GetGroup();
|
||||
if (group)
|
||||
{
|
||||
for (byte i = 0; i < (int)Difficulty.Max; ++i)
|
||||
{
|
||||
var binds = group.GetBoundInstances((Difficulty)i);
|
||||
foreach (var pair in binds)
|
||||
{
|
||||
InstanceSave save = pair.Value.save;
|
||||
string timeleft = Time.GetTimeString(save.GetResetTime() - Time.UnixTime);
|
||||
handler.SendSysMessage(format, pair.Key, save.GetInstanceId(), pair.Value.perm ? "yes" : "no", save.GetDifficultyID(), save.CanReset() ? "yes" : "no", timeleft);
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
}
|
||||
handler.SendSysMessage("group binds: {0}", counter);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("unbind", RBACPermissions.CommandInstanceUnbind)]
|
||||
static bool HandleInstanceUnbind(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
if (args.Empty())
|
||||
return false;
|
||||
|
||||
Player player = handler.getSelectedPlayer();
|
||||
if (!player)
|
||||
player = handler.GetSession().GetPlayer();
|
||||
|
||||
string map = args.NextString();
|
||||
string pDiff = args.NextString();
|
||||
sbyte diff = -1;
|
||||
if (string.IsNullOrEmpty(pDiff))
|
||||
diff = sbyte.Parse(pDiff);
|
||||
ushort counter = 0;
|
||||
ushort MapId = 0;
|
||||
|
||||
if (map != "all")
|
||||
{
|
||||
MapId = ushort.Parse(map);
|
||||
if (MapId == 0)
|
||||
return false;
|
||||
}
|
||||
|
||||
for (byte i = 0; i < (int)Difficulty.Max; ++i)
|
||||
{
|
||||
var binds = player.GetBoundInstances((Difficulty)i);
|
||||
foreach (var pair in binds)
|
||||
{
|
||||
InstanceSave save = pair.Value.save;
|
||||
if (pair.Key != player.GetMapId() && (MapId == 0 || MapId == pair.Key) && (diff == -1 || diff == (sbyte)save.GetDifficultyID()))
|
||||
{
|
||||
string timeleft = Time.GetTimeString(save.GetResetTime() - Time.UnixTime);
|
||||
handler.SendSysMessage("unbinding map: {0} inst: {1} perm: {2} diff: {3} canReset: {4} TTR: {5}", pair.Key, save.GetInstanceId(),
|
||||
pair.Value.perm ? "yes" : "no", save.GetDifficultyID(), save.CanReset() ? "yes" : "no", timeleft);
|
||||
player.UnbindInstance(pair.Key, (Difficulty)i);
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
}
|
||||
handler.SendSysMessage("instances unbound: {0}", counter);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("stats", RBACPermissions.CommandInstanceStats, true)]
|
||||
static bool HandleInstanceStats(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
handler.SendSysMessage("instances loaded: {0}", Global.MapMgr.GetNumInstances());
|
||||
handler.SendSysMessage("players in instances: {0}", Global.MapMgr.GetNumPlayersInInstances());
|
||||
handler.SendSysMessage("instance saves: {0}", Global.InstanceSaveMgr.GetNumInstanceSaves());
|
||||
handler.SendSysMessage("players bound: {0}", Global.InstanceSaveMgr.GetNumBoundPlayersTotal());
|
||||
handler.SendSysMessage("groups bound: {0}", Global.InstanceSaveMgr.GetNumBoundGroupsTotal());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("savedata", RBACPermissions.CommandInstanceSavedata)]
|
||||
static bool HandleInstanceSaveData(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
Player player = handler.GetSession().GetPlayer();
|
||||
InstanceMap map = player.GetMap().ToInstanceMap();
|
||||
if (map == null)
|
||||
{
|
||||
handler.SendSysMessage("Map is not a dungeon.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (map.GetInstanceScript() == null)
|
||||
{
|
||||
handler.SendSysMessage("Map has no instance data.");
|
||||
return false;
|
||||
}
|
||||
|
||||
map.GetInstanceScript().SaveToDB();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("setbossstate", RBACPermissions.CommandInstanceSetBossState)]
|
||||
static bool HandleInstanceSetBossState(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
if (args.Empty())
|
||||
return false;
|
||||
|
||||
string param1 = args.NextString();
|
||||
string param2 = args.NextString();
|
||||
string param3 = args.NextString();
|
||||
uint encounterId = 0;
|
||||
EncounterState state = 0;
|
||||
Player player = null;
|
||||
|
||||
// Character name must be provided when using this from console.
|
||||
if (string.IsNullOrEmpty(param2) || (string.IsNullOrEmpty(param3) && handler.GetSession() == null))
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.CmdSyntax);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(param3))
|
||||
player = handler.GetSession().GetPlayer();
|
||||
else
|
||||
{
|
||||
if (ObjectManager.NormalizePlayerName(ref param3))
|
||||
player = Global.ObjAccessor.FindPlayerByName(param3);
|
||||
}
|
||||
|
||||
if (!player)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.PlayerNotFound);
|
||||
return false;
|
||||
}
|
||||
|
||||
InstanceMap map = player.GetMap().ToInstanceMap();
|
||||
if (map == null)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.NotDungeon);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (map.GetInstanceScript() == null)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.NoInstanceData);
|
||||
return false;
|
||||
}
|
||||
|
||||
encounterId = uint.Parse(param1);
|
||||
state = (EncounterState)int.Parse(param2);
|
||||
|
||||
// Reject improper values.
|
||||
if (state > EncounterState.ToBeDecided || encounterId > map.GetInstanceScript().GetEncounterCount())
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.BadValue);
|
||||
return false;
|
||||
}
|
||||
|
||||
map.GetInstanceScript().SetBossState(encounterId, state);
|
||||
handler.SendSysMessage(CypherStrings.CommandInstSetBossState, encounterId, state);
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("getbossstate", RBACPermissions.CommandInstanceGetBossState)]
|
||||
static bool HandleInstanceGetBossState(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
if (args.Empty())
|
||||
return false;
|
||||
|
||||
string param1 = args.NextString();
|
||||
string param2 = args.NextString();
|
||||
uint encounterId = 0;
|
||||
Player player = null;
|
||||
|
||||
// Character name must be provided when using this from console.
|
||||
if (string.IsNullOrEmpty(param1) || (string.IsNullOrEmpty(param2) && handler.GetSession() == null))
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.CmdSyntax);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(param2))
|
||||
player = handler.GetSession().GetPlayer();
|
||||
else
|
||||
{
|
||||
if (ObjectManager.NormalizePlayerName(ref param2))
|
||||
player = Global.ObjAccessor.FindPlayerByName(param2);
|
||||
}
|
||||
|
||||
if (!player)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.PlayerNotFound);
|
||||
return false;
|
||||
}
|
||||
|
||||
InstanceMap map = player.GetMap().ToInstanceMap();
|
||||
if (map == null)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.NotDungeon);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (map.GetInstanceScript() == null)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.NoInstanceData);
|
||||
return false;
|
||||
}
|
||||
|
||||
encounterId = uint.Parse(param1);
|
||||
|
||||
if (encounterId > map.GetInstanceScript().GetEncounterCount())
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.BadValue);
|
||||
return false;
|
||||
}
|
||||
|
||||
EncounterState state = map.GetInstanceScript().GetBossState(encounterId);
|
||||
handler.SendSysMessage(CypherStrings.CommandInstGetBossState, encounterId, state);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,143 @@
|
||||
/*
|
||||
* Copyright (C) 2012-2017 CypherCore <http://github.com/CypherCore>
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using Framework.Constants;
|
||||
using Framework.Database;
|
||||
using Framework.IO;
|
||||
using Game.DungeonFinding;
|
||||
using Game.Entities;
|
||||
using Game.Groups;
|
||||
|
||||
namespace Game.Chat
|
||||
{
|
||||
[CommandGroup("lfg", RBACPermissions.CommandLfg, true)]
|
||||
class LFGCommands
|
||||
{
|
||||
[Command("player", RBACPermissions.CommandLfgPlayer, true)]
|
||||
static bool HandleLfgPlayerInfoCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
Player target = null;
|
||||
string playerName;
|
||||
ObjectGuid guid;
|
||||
if (!handler.extractPlayerTarget(args, out target, out guid, out playerName))
|
||||
return false;
|
||||
|
||||
GetPlayerInfo(handler, target);
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("group", RBACPermissions.CommandLfgGroup, true)]
|
||||
static bool HandleLfgGroupInfoCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
if (args.Empty())
|
||||
return false;
|
||||
|
||||
Player playerTarget = null;
|
||||
ObjectGuid guidTarget;
|
||||
string nameTarget;
|
||||
|
||||
ObjectGuid parseGUID = ObjectGuid.Create(HighGuid.Player, args.NextUInt64());
|
||||
if (ObjectManager.GetPlayerNameByGUID(parseGUID, out nameTarget))
|
||||
{
|
||||
playerTarget = Global.ObjAccessor.FindPlayer(parseGUID);
|
||||
guidTarget = parseGUID;
|
||||
}
|
||||
else if (!handler.extractPlayerTarget(args, out playerTarget, out guidTarget, out nameTarget))
|
||||
return false;
|
||||
|
||||
Group groupTarget = null;
|
||||
if (playerTarget)
|
||||
groupTarget = playerTarget.GetGroup();
|
||||
else
|
||||
{
|
||||
PreparedStatement stmt = DB.Characters.GetPreparedStatement(CharStatements.SEL_GROUP_MEMBER);
|
||||
stmt.AddValue(0, guidTarget.GetCounter());
|
||||
SQLResult resultGroup = DB.Characters.Query(stmt);
|
||||
if (!resultGroup.IsEmpty())
|
||||
groupTarget = Global.GroupMgr.GetGroupByDbStoreId(resultGroup.Read<uint>(0));
|
||||
}
|
||||
|
||||
if (!groupTarget)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.LfgNotInGroup, nameTarget);
|
||||
return false;
|
||||
}
|
||||
|
||||
ObjectGuid guid = groupTarget.GetGUID();
|
||||
handler.SendSysMessage(CypherStrings.LfgGroupInfo, groupTarget.isLFGGroup(), Global.LFGMgr.GetState(guid), Global.LFGMgr.GetDungeon(guid));
|
||||
|
||||
foreach (var slot in groupTarget.GetMemberSlots())
|
||||
{
|
||||
Player p = Global.ObjAccessor.FindPlayer(slot.guid);
|
||||
if (p)
|
||||
GetPlayerInfo(handler, p);
|
||||
else
|
||||
handler.SendSysMessage("{0} is offline.", slot.name);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("options", RBACPermissions.CommandLfgOptions, true)]
|
||||
static bool HandleLfgOptionsCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
int options = -1;
|
||||
string str = args.NextString();
|
||||
if (!string.IsNullOrEmpty(str))
|
||||
{
|
||||
int tmp = int.Parse(str);
|
||||
if (tmp > -1)
|
||||
options = tmp;
|
||||
}
|
||||
|
||||
if (options != -1)
|
||||
{
|
||||
Global.LFGMgr.SetOptions((LfgOptions)options);
|
||||
handler.SendSysMessage(CypherStrings.LfgOptionsChanged);
|
||||
}
|
||||
handler.SendSysMessage(CypherStrings.LfgOptions, Global.LFGMgr.GetOptions());
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("queue", RBACPermissions.CommandLfgQueue, true)]
|
||||
static bool HandleLfgQueueInfoCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
handler.SendSysMessage(Global.LFGMgr.DumpQueueInfo(args.NextBoolean()));
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("clean", RBACPermissions.CommandLfgClean, true)]
|
||||
static bool HandleLfgCleanCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.LfgClean);
|
||||
Global.LFGMgr.Clean();
|
||||
return true;
|
||||
}
|
||||
|
||||
static void GetPlayerInfo(CommandHandler handler, Player player)
|
||||
{
|
||||
if (!player)
|
||||
return;
|
||||
|
||||
ObjectGuid guid = player.GetGUID();
|
||||
var dungeons = Global.LFGMgr.GetSelectedDungeons(guid);
|
||||
|
||||
handler.SendSysMessage(CypherStrings.LfgPlayerInfo, player.GetName(), Global.LFGMgr.GetState(guid), dungeons.Count, LFGQueue.ConcatenateDungeons(dungeons),
|
||||
LFGQueue.GetRolesString(Global.LFGMgr.GetRoles(guid)));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,348 @@
|
||||
/*
|
||||
* Copyright (C) 2012-2017 CypherCore <http://github.com/CypherCore>
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using Framework.Constants;
|
||||
using Framework.IO;
|
||||
using Game.DataStorage;
|
||||
using Game.Entities;
|
||||
using Game.Spells;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Game.Chat.Commands
|
||||
{
|
||||
[CommandGroup("learn", RBACPermissions.CommandLearn)]
|
||||
class LearnCommands
|
||||
{
|
||||
[Command("", RBACPermissions.CommandLearn)]
|
||||
static bool HandleLearnCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
Player targetPlayer = handler.getSelectedPlayerOrSelf();
|
||||
|
||||
if (!targetPlayer)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.PlayerNotFound);
|
||||
return false;
|
||||
}
|
||||
|
||||
// number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
|
||||
uint spell = handler.extractSpellIdFromLink(args);
|
||||
if (spell == 0 || !Global.SpellMgr.HasSpellInfo(spell))
|
||||
return false;
|
||||
|
||||
string all = args.NextString();
|
||||
bool allRanks = !string.IsNullOrEmpty(all) ? all == "all" : false;
|
||||
|
||||
SpellInfo spellInfo = Global.SpellMgr.GetSpellInfo(spell);
|
||||
if (spellInfo == null || !Global.SpellMgr.IsSpellValid(spellInfo, handler.GetSession().GetPlayer()))
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.CommandSpellBroken, spell);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!allRanks && targetPlayer.HasSpell(spell))
|
||||
{
|
||||
if (targetPlayer == handler.GetSession().GetPlayer())
|
||||
handler.SendSysMessage(CypherStrings.YouKnownSpell);
|
||||
else
|
||||
handler.SendSysMessage(CypherStrings.TargetKnownSpell, handler.GetNameLink(targetPlayer));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (allRanks)
|
||||
targetPlayer.LearnSpellHighestRank(spell);
|
||||
else
|
||||
targetPlayer.LearnSpell(spell, false);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
[CommandGroup("all", RBACPermissions.CommandLearnAll)]
|
||||
class LearnAllCommands
|
||||
{
|
||||
[Command("gm", RBACPermissions.CommandLearnAllGm)]
|
||||
static bool HandleLearnAllGMCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
foreach (var spellInfo in Global.SpellMgr.GetSpellInfoStorage().Values)
|
||||
{
|
||||
if (spellInfo == null || !Global.SpellMgr.IsSpellValid(spellInfo, handler.GetSession().GetPlayer(), false))
|
||||
continue;
|
||||
|
||||
if (!spellInfo.IsAbilityOfSkillType(SkillType.Internal))
|
||||
continue;
|
||||
|
||||
handler.GetSession().GetPlayer().LearnSpell(spellInfo.Id, false);
|
||||
}
|
||||
|
||||
handler.SendSysMessage(CypherStrings.LearningGmSkills);
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("lang", RBACPermissions.CommandLearnAllLang)]
|
||||
static bool HandleLearnAllLangCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
// skipping UNIVERSAL language (0)
|
||||
for (byte i = 1; i < Enum.GetValues(typeof(Language)).Length; ++i)
|
||||
handler.GetSession().GetPlayer().LearnSpell(ObjectManager.lang_description[i].spell_id, false);
|
||||
|
||||
handler.SendSysMessage(CypherStrings.CommandLearnAllLang);
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("default", RBACPermissions.CommandLearnAllDefault)]
|
||||
static bool HandleLearnAllDefaultCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
Player target;
|
||||
if (!handler.extractPlayerTarget(args, out target))
|
||||
return false;
|
||||
|
||||
target.LearnDefaultSkills();
|
||||
target.LearnCustomSpells();
|
||||
target.LearnQuestRewardedSpells();
|
||||
|
||||
handler.SendSysMessage(CypherStrings.CommandLearnAllDefaultAndQuest, handler.GetNameLink(target));
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("crafts", RBACPermissions.CommandLearnAllCrafts)]
|
||||
static bool HandleLearnAllCraftsCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
Player target;
|
||||
if (!handler.extractPlayerTarget(args, out target))
|
||||
return false;
|
||||
|
||||
foreach (var skillInfo in CliDB.SkillLineStorage.Values)
|
||||
{
|
||||
if ((skillInfo.CategoryID == SkillCategory.Profession || skillInfo.CategoryID == SkillCategory.Secondary) && skillInfo.CanLink != 0) // only prof. with recipes have
|
||||
{
|
||||
HandleLearnSkillRecipesHelper(target, skillInfo.Id);
|
||||
}
|
||||
}
|
||||
|
||||
handler.SendSysMessage(CypherStrings.CommandLearnAllCraft);
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("recipes", RBACPermissions.CommandLearnAllRecipes)]
|
||||
static bool HandleLearnAllRecipesCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
// Learns all recipes of specified profession and sets skill to max
|
||||
// Example: .learn all_recipes enchanting
|
||||
|
||||
Player target = handler.getSelectedPlayer();
|
||||
if (!target)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.PlayerNotFound);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (args.Empty())
|
||||
return false;
|
||||
|
||||
// converting string that we try to find to lower case
|
||||
string namePart = args.NextString().ToLower();
|
||||
|
||||
string name = "";
|
||||
uint skillId = 0;
|
||||
foreach (var skillInfo in CliDB.SkillLineStorage.Values)
|
||||
{
|
||||
if ((skillInfo.CategoryID != SkillCategory.Profession &&
|
||||
skillInfo.CategoryID != SkillCategory.Secondary) ||
|
||||
skillInfo.CanLink == 0) // only prof with recipes have set
|
||||
continue;
|
||||
|
||||
LocaleConstant locale = handler.GetSessionDbcLocale();
|
||||
name = skillInfo.DisplayName[locale];
|
||||
if (string.IsNullOrEmpty(name))
|
||||
continue;
|
||||
|
||||
if (!name.Like(namePart))
|
||||
{
|
||||
locale = 0;
|
||||
for (; locale < LocaleConstant.Total; ++locale)
|
||||
{
|
||||
if (locale == handler.GetSessionDbcLocale())
|
||||
continue;
|
||||
|
||||
name = skillInfo.DisplayName[locale];
|
||||
if (name.IsEmpty())
|
||||
continue;
|
||||
|
||||
if (name.Like(namePart))
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (locale < LocaleConstant.Total)
|
||||
{
|
||||
skillId = skillInfo.Id;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (skillId == 0)
|
||||
return false;
|
||||
|
||||
HandleLearnSkillRecipesHelper(target, skillId);
|
||||
|
||||
ushort maxLevel = target.GetPureMaxSkillValue((SkillType)skillId);
|
||||
target.SetSkill(skillId, target.GetSkillStep((SkillType)skillId), maxLevel, maxLevel);
|
||||
handler.SendSysMessage(CypherStrings.CommandLearnAllRecipes, name);
|
||||
return true;
|
||||
}
|
||||
|
||||
static void HandleLearnSkillRecipesHelper(Player player, uint skillId)
|
||||
{
|
||||
uint classmask = player.getClassMask();
|
||||
|
||||
foreach (var skillLine in CliDB.SkillLineAbilityStorage.Values)
|
||||
{
|
||||
// wrong skill
|
||||
if (skillLine.SkillLine != skillId)
|
||||
continue;
|
||||
|
||||
// not high rank
|
||||
if (skillLine.SupercedesSpell != 0)
|
||||
continue;
|
||||
|
||||
// skip racial skills
|
||||
if (skillLine.RaceMask != 0)
|
||||
continue;
|
||||
|
||||
// skip wrong class skills
|
||||
if (skillLine.ClassMask != 0 && (skillLine.ClassMask & classmask) == 0)
|
||||
continue;
|
||||
|
||||
SpellInfo spellInfo = Global.SpellMgr.GetSpellInfo(skillLine.SpellID);
|
||||
if (spellInfo == null || !Global.SpellMgr.IsSpellValid(spellInfo, player, false))
|
||||
continue;
|
||||
|
||||
player.LearnSpell(skillLine.SpellID, false);
|
||||
}
|
||||
}
|
||||
|
||||
[CommandGroup("my", RBACPermissions.CommandLearnAllMy)]
|
||||
class LearnAllMyCommands
|
||||
{
|
||||
[Command("class", RBACPermissions.CommandLearnAllMyClass)]
|
||||
static bool HandleLearnAllMyClassCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
HandleLearnAllMySpellsCommand(args, handler);
|
||||
HandleLearnAllMyTalentsCommand(args, handler);
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("spells", RBACPermissions.CommandLearnAllMySpells)]
|
||||
static bool HandleLearnAllMySpellsCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
ChrClassesRecord classEntry = CliDB.ChrClassesStorage.LookupByKey(handler.GetSession().GetPlayer().GetClass());
|
||||
if (classEntry == null)
|
||||
return true;
|
||||
uint family = classEntry.SpellClassSet;
|
||||
|
||||
foreach (var entry in CliDB.SkillLineAbilityStorage.Values)
|
||||
{
|
||||
SpellInfo spellInfo = Global.SpellMgr.GetSpellInfo(entry.SpellID);
|
||||
if (spellInfo == null)
|
||||
continue;
|
||||
|
||||
// skip server-side/triggered spells
|
||||
if (spellInfo.SpellLevel == 0)
|
||||
continue;
|
||||
|
||||
// skip wrong class/race skills
|
||||
if (!handler.GetSession().GetPlayer().IsSpellFitByClassAndRace(spellInfo.Id))
|
||||
continue;
|
||||
|
||||
// skip other spell families
|
||||
if ((uint)spellInfo.SpellFamilyName != family)
|
||||
continue;
|
||||
|
||||
// skip broken spells
|
||||
if (!Global.SpellMgr.IsSpellValid(spellInfo, handler.GetSession().GetPlayer(), false))
|
||||
continue;
|
||||
|
||||
handler.GetSession().GetPlayer().LearnSpell(spellInfo.Id, false);
|
||||
}
|
||||
|
||||
handler.SendSysMessage(CypherStrings.CommandLearnClassSpells);
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("talents", RBACPermissions.CommandLearnAllMyTalents)]
|
||||
static bool HandleLearnAllMyTalentsCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
Player player = handler.GetSession().GetPlayer();
|
||||
uint playerClass = (uint)player.GetClass();
|
||||
|
||||
foreach (var talentInfo in CliDB.TalentStorage.Values)
|
||||
{
|
||||
if (playerClass != talentInfo.ClassID)
|
||||
continue;
|
||||
|
||||
SpellInfo spellInfo = Global.SpellMgr.GetSpellInfo(talentInfo.SpellID);
|
||||
if (spellInfo == null || !Global.SpellMgr.IsSpellValid(spellInfo, handler.GetSession().GetPlayer(), false))
|
||||
continue;
|
||||
|
||||
// learn highest rank of talent and learn all non-talent spell ranks (recursive by tree)
|
||||
player.LearnSpellHighestRank(talentInfo.SpellID);
|
||||
player.AddTalent(talentInfo, player.GetActiveTalentGroup(), true);
|
||||
}
|
||||
|
||||
handler.SendSysMessage(CypherStrings.CommandLearnClassTalents);
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("pettalents", RBACPermissions.CommandLearnAllMyPettalents)]
|
||||
static bool HandleLearnAllMyPetTalentsCommand(StringArguments args, CommandHandler handler) { return true; }
|
||||
}
|
||||
}
|
||||
|
||||
[CommandNonGroup("unlearn", RBACPermissions.CommandUnlearn)]
|
||||
static bool HandleUnLearnCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
if (args.Empty())
|
||||
return false;
|
||||
|
||||
// number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r
|
||||
uint spellId = handler.extractSpellIdFromLink(args);
|
||||
if (spellId == 0)
|
||||
return false;
|
||||
|
||||
string allStr = args.NextString();
|
||||
bool allRanks = !string.IsNullOrEmpty(allStr) ? allStr == "all" : false;
|
||||
|
||||
Player target = handler.getSelectedPlayer();
|
||||
if (!target)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.NoCharSelected);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (allRanks)
|
||||
spellId = Global.SpellMgr.GetFirstSpellInChain(spellId);
|
||||
|
||||
if (target.HasSpell(spellId))
|
||||
target.RemoveSpell(spellId, false, !allRanks);
|
||||
else
|
||||
handler.SendSysMessage(CypherStrings.ForgetSpell);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,555 @@
|
||||
/*
|
||||
* Copyright (C) 2012-2017 CypherCore <http://github.com/CypherCore>
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using Framework.Constants;
|
||||
using Framework.Database;
|
||||
using Framework.IO;
|
||||
using Game.Entities;
|
||||
using Game.Spells;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Game.Chat.Commands
|
||||
{
|
||||
[CommandGroup("list", RBACPermissions.CommandList, true)]
|
||||
class ListCommands
|
||||
{
|
||||
[Command("auras", RBACPermissions.CommandListAuras)]
|
||||
static bool HandleListAurasCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
Unit unit = handler.getSelectedUnit();
|
||||
if (!unit)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.SelectCharOrCreature);
|
||||
return false;
|
||||
}
|
||||
|
||||
string talentStr = handler.GetCypherString(CypherStrings.Talent);
|
||||
string passiveStr = handler.GetCypherString(CypherStrings.Passive);
|
||||
|
||||
var auras = unit.GetAppliedAuras();
|
||||
handler.SendSysMessage(CypherStrings.CommandTargetListauras, auras.Count);
|
||||
foreach (var pair in auras)
|
||||
{
|
||||
|
||||
AuraApplication aurApp = pair.Value;
|
||||
Aura aura = aurApp.GetBase();
|
||||
string name = aura.GetSpellInfo().SpellName[handler.GetSessionDbcLocale()];
|
||||
bool talent = aura.GetSpellInfo().HasAttribute(SpellCustomAttributes.IsTalent);
|
||||
|
||||
string ss_name = "|cffffffff|Hspell:" + aura.GetId() + "|h[" + name + "]|h|r";
|
||||
|
||||
handler.SendSysMessage(CypherStrings.CommandTargetAuradetail, aura.GetId(), (handler.GetSession() != null ? ss_name : name),
|
||||
aurApp.GetEffectMask(), aura.GetCharges(), aura.GetStackAmount(), aurApp.GetSlot(),
|
||||
aura.GetDuration(), aura.GetMaxDuration(), (aura.IsPassive() ? passiveStr : ""),
|
||||
(talent ? talentStr : ""), aura.GetCasterGUID().IsPlayer() ? "player" : "creature",
|
||||
aura.GetCasterGUID().ToString());
|
||||
}
|
||||
|
||||
for (ushort i = 0; i < (int)AuraType.Total; ++i)
|
||||
{
|
||||
var auraList = unit.GetAuraEffectsByType((AuraType)i);
|
||||
if (auraList.Empty())
|
||||
continue;
|
||||
|
||||
handler.SendSysMessage(CypherStrings.CommandTargetListauratype, auraList.Count, i);
|
||||
|
||||
foreach (var eff in auraList)
|
||||
handler.SendSysMessage(CypherStrings.CommandTargetAurasimple, eff.GetId(), eff.GetEffIndex(), eff.GetAmount());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("creature", RBACPermissions.CommandListCreature, true)]
|
||||
static bool HandleListCreatureCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
if (args.Empty())
|
||||
return false;
|
||||
|
||||
// number or [name] Shift-click form |color|Hcreature_entry:creature_id|h[name]|h|r
|
||||
string id = handler.extractKeyFromLink(args, "Hcreature_entry");
|
||||
if (string.IsNullOrEmpty(id))
|
||||
return false;
|
||||
|
||||
uint creatureId = uint.Parse(id);
|
||||
if (creatureId == 0)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.CommandInvalidcreatureid, creatureId);
|
||||
return false;
|
||||
}
|
||||
|
||||
CreatureTemplate cInfo = Global.ObjectMgr.GetCreatureTemplate(creatureId);
|
||||
if (cInfo == null)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.CommandInvalidcreatureid, creatureId);
|
||||
return false;
|
||||
}
|
||||
|
||||
string countStr = args.NextString();
|
||||
uint count = !string.IsNullOrEmpty(countStr) ? uint.Parse(countStr) : 10;
|
||||
|
||||
if (count == 0)
|
||||
return false;
|
||||
|
||||
uint creatureCount = 0;
|
||||
SQLResult result = DB.World.Query("SELECT COUNT(guid) FROM creature WHERE id='{0}'", creatureId);
|
||||
if (!result.IsEmpty())
|
||||
creatureCount = result.Read<uint>(0);
|
||||
|
||||
if (handler.GetSession() != null)
|
||||
{
|
||||
Player player = handler.GetSession().GetPlayer();
|
||||
result = DB.World.Query("SELECT guid, position_x, position_y, position_z, map, (POW(position_x - '{0}', 2) + POW(position_y - '{1}', 2) + POW(position_z - '{2}', 2)) AS order_ FROM creature WHERE id = '{3}' ORDER BY order_ ASC LIMIT {4}",
|
||||
player.GetPositionX(), player.GetPositionY(), player.GetPositionZ(), creatureId, count);
|
||||
}
|
||||
else
|
||||
result = DB.World.Query("SELECT guid, position_x, position_y, position_z, map FROM creature WHERE id = '{0}' LIMIT {1}",
|
||||
creatureId, count);
|
||||
|
||||
if (!result.IsEmpty())
|
||||
{
|
||||
do
|
||||
{
|
||||
ulong guid = result.Read<ulong>(0);
|
||||
float x = result.Read<float>(1);
|
||||
float y = result.Read<float>(2);
|
||||
float z = result.Read<float>(3);
|
||||
ushort mapId = result.Read<ushort>(4);
|
||||
|
||||
if (handler.GetSession() != null)
|
||||
handler.SendSysMessage(CypherStrings.CreatureListChat, guid, guid, cInfo.Name, x, y, z, mapId);
|
||||
else
|
||||
handler.SendSysMessage(CypherStrings.CreatureListConsole, guid, cInfo.Name, x, y, z, mapId);
|
||||
}
|
||||
while (result.NextRow());
|
||||
}
|
||||
|
||||
handler.SendSysMessage(CypherStrings.CommandListcreaturemessage, creatureId, creatureCount);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("item", RBACPermissions.CommandListItem, true)]
|
||||
static bool HandleListItemCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
if (args.Empty())
|
||||
return false;
|
||||
|
||||
string id = handler.extractKeyFromLink(args, "Hitem");
|
||||
if (string.IsNullOrEmpty(id))
|
||||
return false;
|
||||
|
||||
uint itemId = uint.Parse(id);
|
||||
if (itemId == 0)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.CommandItemidinvalid, itemId);
|
||||
return false;
|
||||
}
|
||||
|
||||
ItemTemplate itemTemplate = Global.ObjectMgr.GetItemTemplate(itemId);
|
||||
if (itemTemplate == null)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.CommandItemidinvalid, itemId);
|
||||
return false;
|
||||
}
|
||||
|
||||
string countStr = args.NextString();
|
||||
uint count = !string.IsNullOrEmpty(countStr) ? uint.Parse(countStr) : 10;
|
||||
|
||||
if (count == 0)
|
||||
return false;
|
||||
|
||||
SQLResult result;
|
||||
|
||||
// inventory case
|
||||
uint inventoryCount = 0;
|
||||
|
||||
PreparedStatement stmt = DB.Characters.GetPreparedStatement(CharStatements.SEL_CHAR_INVENTORY_COUNT_ITEM);
|
||||
stmt.AddValue(0, itemId);
|
||||
result = DB.Characters.Query(stmt);
|
||||
|
||||
if (!result.IsEmpty())
|
||||
inventoryCount = result.Read<uint>(0);
|
||||
|
||||
stmt = DB.Characters.GetPreparedStatement(CharStatements.SEL_CHAR_INVENTORY_ITEM_BY_ENTRY);
|
||||
stmt.AddValue(0, itemId);
|
||||
stmt.AddValue(1, count);
|
||||
result = DB.Characters.Query(stmt);
|
||||
|
||||
if (!result.IsEmpty())
|
||||
{
|
||||
do
|
||||
{
|
||||
ObjectGuid itemGuid = ObjectGuid.Create(HighGuid.Item, result.Read<ulong>(0));
|
||||
uint itemBag = result.Read<uint>(1);
|
||||
byte itemSlot = result.Read<byte>(2);
|
||||
ObjectGuid ownerGuid = ObjectGuid.Create(HighGuid.Player, result.Read<ulong>(3));
|
||||
uint ownerAccountId = result.Read<uint>(4);
|
||||
string ownerName = result.Read<string>(5);
|
||||
|
||||
string itemPos = "";
|
||||
if (Player.IsEquipmentPos((byte)itemBag, itemSlot))
|
||||
itemPos = "[equipped]";
|
||||
else if (Player.IsInventoryPos((byte)itemBag, itemSlot))
|
||||
itemPos = "[in inventory]";
|
||||
else if (Player.IsBankPos((byte)itemBag, itemSlot))
|
||||
itemPos = "[in bank]";
|
||||
else
|
||||
itemPos = "";
|
||||
|
||||
handler.SendSysMessage(CypherStrings.ItemlistSlot, itemGuid.ToString(), ownerName, ownerGuid.ToString(), ownerAccountId, itemPos);
|
||||
}
|
||||
while (result.NextRow());
|
||||
|
||||
uint resultCount = (uint)result.GetRowCount();
|
||||
|
||||
if (count > resultCount)
|
||||
count -= resultCount;
|
||||
else if (count != 0)
|
||||
count = 0;
|
||||
}
|
||||
|
||||
// mail case
|
||||
uint mailCount = 0;
|
||||
|
||||
stmt = DB.Characters.GetPreparedStatement(CharStatements.SEL_MAIL_COUNT_ITEM);
|
||||
stmt.AddValue(0, itemId);
|
||||
result = DB.Characters.Query(stmt);
|
||||
|
||||
if (!result.IsEmpty())
|
||||
mailCount = result.Read<uint>(0);
|
||||
|
||||
if (count > 0)
|
||||
{
|
||||
stmt = DB.Characters.GetPreparedStatement(CharStatements.SEL_MAIL_ITEMS_BY_ENTRY);
|
||||
stmt.AddValue(0, itemId);
|
||||
stmt.AddValue(1, count);
|
||||
result = DB.Characters.Query(stmt);
|
||||
}
|
||||
else
|
||||
result = null;
|
||||
|
||||
if (result != null && !result.IsEmpty())
|
||||
{
|
||||
do
|
||||
{
|
||||
ulong itemGuid = result.Read<ulong>(0);
|
||||
ulong itemSender = result.Read<ulong>(1);
|
||||
ulong itemReceiver = result.Read<ulong>(2);
|
||||
uint itemSenderAccountId = result.Read<uint>(3);
|
||||
string itemSenderName = result.Read<string>(4);
|
||||
uint itemReceiverAccount = result.Read<uint>(5);
|
||||
string itemReceiverName = result.Read<string>(6);
|
||||
|
||||
string itemPos = "[in mail]";
|
||||
|
||||
handler.SendSysMessage(CypherStrings.ItemlistMail, itemGuid, itemSenderName, itemSender, itemSenderAccountId, itemReceiverName, itemReceiver, itemReceiverAccount, itemPos);
|
||||
}
|
||||
while (result.NextRow());
|
||||
|
||||
uint resultCount = (uint)result.GetRowCount();
|
||||
|
||||
if (count > resultCount)
|
||||
count -= resultCount;
|
||||
else if (count != 0)
|
||||
count = 0;
|
||||
}
|
||||
|
||||
// auction case
|
||||
uint auctionCount = 0;
|
||||
|
||||
stmt = DB.Characters.GetPreparedStatement(CharStatements.SEL_AUCTIONHOUSE_COUNT_ITEM);
|
||||
stmt.AddValue(0, itemId);
|
||||
result = DB.Characters.Query(stmt);
|
||||
|
||||
if (!result.IsEmpty())
|
||||
auctionCount = result.Read<uint>(0);
|
||||
|
||||
if (count > 0)
|
||||
{
|
||||
stmt = DB.Characters.GetPreparedStatement(CharStatements.SEL_AUCTIONHOUSE_ITEM_BY_ENTRY);
|
||||
stmt.AddValue(0, itemId);
|
||||
stmt.AddValue(1, count);
|
||||
result = DB.Characters.Query(stmt);
|
||||
}
|
||||
else
|
||||
result = null;
|
||||
|
||||
if (result != null && !result.IsEmpty())
|
||||
{
|
||||
do
|
||||
{
|
||||
ObjectGuid itemGuid = ObjectGuid.Create(HighGuid.Item, result.Read<ulong>(0));
|
||||
ObjectGuid owner = ObjectGuid.Create(HighGuid.Player, result.Read<ulong>(1));
|
||||
uint ownerAccountId = result.Read<uint>(2);
|
||||
string ownerName = result.Read<string>(3);
|
||||
|
||||
string itemPos = "[in auction]";
|
||||
|
||||
handler.SendSysMessage(CypherStrings.ItemlistAuction, itemGuid.ToString(), ownerName, owner.ToString(), ownerAccountId, itemPos);
|
||||
}
|
||||
while (result.NextRow());
|
||||
}
|
||||
|
||||
// guild bank case
|
||||
uint guildCount = 0;
|
||||
|
||||
stmt = DB.Characters.GetPreparedStatement(CharStatements.SEL_GUILD_BANK_COUNT_ITEM);
|
||||
stmt.AddValue(0, itemId);
|
||||
result = DB.Characters.Query(stmt);
|
||||
|
||||
if (!result.IsEmpty())
|
||||
guildCount = result.Read<uint>(0);
|
||||
|
||||
stmt = DB.Characters.GetPreparedStatement(CharStatements.SEL_GUILD_BANK_ITEM_BY_ENTRY);
|
||||
stmt.AddValue(0, itemId);
|
||||
stmt.AddValue(1, count);
|
||||
result = DB.Characters.Query(stmt);
|
||||
|
||||
if (!result.IsEmpty())
|
||||
{
|
||||
do
|
||||
{
|
||||
ObjectGuid itemGuid = ObjectGuid.Create(HighGuid.Item, result.Read<ulong>(0));
|
||||
ObjectGuid guildGuid = ObjectGuid.Create(HighGuid.Guild, result.Read<ulong>(1));
|
||||
string guildName = result.Read<string>(2);
|
||||
|
||||
string itemPos = "[in guild bank]";
|
||||
|
||||
handler.SendSysMessage(CypherStrings.ItemlistGuild, itemGuid.ToString(), guildName, guildGuid.ToString(), itemPos);
|
||||
}
|
||||
while (result.NextRow());
|
||||
|
||||
uint resultCount = (uint)result.GetRowCount();
|
||||
|
||||
if (count > resultCount)
|
||||
count -= resultCount;
|
||||
else if (count != 0)
|
||||
count = 0;
|
||||
}
|
||||
|
||||
if (inventoryCount + mailCount + auctionCount + guildCount == 0)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.CommandNoitemfound);
|
||||
return false;
|
||||
}
|
||||
|
||||
handler.SendSysMessage(CypherStrings.CommandListitemmessage, itemId, inventoryCount + mailCount + auctionCount + guildCount, inventoryCount, mailCount, auctionCount, guildCount);
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("mail", RBACPermissions.CommandListMail, true)]
|
||||
static bool HandleListMailCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
if (args.Empty())
|
||||
return false;
|
||||
|
||||
Player target;
|
||||
ObjectGuid targetGuid;
|
||||
string targetName;
|
||||
PreparedStatement stmt = null;
|
||||
|
||||
ObjectGuid parseGUID = ObjectGuid.Create(HighGuid.Player, args.NextUInt64());
|
||||
if (ObjectManager.GetPlayerNameByGUID(parseGUID, out targetName))
|
||||
{
|
||||
target = Global.ObjAccessor.FindPlayer(parseGUID);
|
||||
targetGuid = parseGUID;
|
||||
}
|
||||
else if (!handler.extractPlayerTarget(args, out target, out targetGuid, out targetName))
|
||||
return false;
|
||||
|
||||
stmt = DB.Characters.GetPreparedStatement(CharStatements.SEL_MAIL_LIST_COUNT);
|
||||
stmt.AddValue(0, targetGuid.GetCounter());
|
||||
SQLResult result = DB.Characters.Query(stmt);
|
||||
if (!result.IsEmpty())
|
||||
{
|
||||
uint countMail = result.Read<uint>(0);
|
||||
|
||||
string nameLink = handler.playerLink(targetName);
|
||||
handler.SendSysMessage(CypherStrings.ListMailHeader, countMail, nameLink, targetGuid.ToString());
|
||||
handler.SendSysMessage(CypherStrings.AccountListBar);
|
||||
|
||||
stmt = DB.Characters.GetPreparedStatement(CharStatements.SEL_MAIL_LIST_INFO);
|
||||
stmt.AddValue(0, targetGuid.GetCounter());
|
||||
SQLResult result1 = DB.Characters.Query(stmt);
|
||||
|
||||
if (!result1.IsEmpty())
|
||||
{
|
||||
do
|
||||
{
|
||||
uint messageId = result1.Read<uint>(0);
|
||||
ulong senderId = result1.Read<ulong>(1);
|
||||
string sender = result1.Read<string>(2);
|
||||
ulong receiverId = result1.Read<ulong>(3);
|
||||
string receiver = result1.Read<string>(4);
|
||||
string subject = result1.Read<string>(5);
|
||||
long deliverTime = result1.Read<uint>(6);
|
||||
long expireTime = result1.Read<uint>(7);
|
||||
ulong money = result1.Read<ulong>(8);
|
||||
byte hasItem = result1.Read<byte>(9);
|
||||
uint gold = (uint)(money / MoneyConstants.Gold);
|
||||
uint silv = (uint)(money % MoneyConstants.Gold) / MoneyConstants.Silver;
|
||||
uint copp = (uint)(money % MoneyConstants.Gold) % MoneyConstants.Silver;
|
||||
string receiverStr = handler.playerLink(receiver);
|
||||
string senderStr = handler.playerLink(sender);
|
||||
handler.SendSysMessage(CypherStrings.ListMailInfo1, messageId, subject, gold, silv, copp);
|
||||
handler.SendSysMessage(CypherStrings.ListMailInfo2, senderStr, senderId, receiverStr, receiverId);
|
||||
handler.SendSysMessage(CypherStrings.ListMailInfo3, Time.UnixTimeToDateTime(deliverTime).ToLongDateString(), Time.UnixTimeToDateTime(expireTime).ToLongDateString());
|
||||
|
||||
if (hasItem == 1)
|
||||
{
|
||||
SQLResult result2 = DB.Characters.Query("SELECT item_guid FROM mail_items WHERE mail_id = '{0}'", messageId);
|
||||
if (!result2.IsEmpty())
|
||||
{
|
||||
do
|
||||
{
|
||||
uint item_guid = result2.Read<uint>(0);
|
||||
stmt = DB.Characters.GetPreparedStatement(CharStatements.SEL_MAIL_LIST_ITEMS);
|
||||
stmt.AddValue(0, item_guid);
|
||||
SQLResult result3 = DB.Characters.Query(stmt);
|
||||
if (!result3.IsEmpty())
|
||||
{
|
||||
do
|
||||
{
|
||||
uint item_entry = result3.Read<uint>(0);
|
||||
uint item_count = result3.Read<uint>(1);
|
||||
SQLResult result4 = DB.World.Query("SELECT name, quality FROM item_template WHERE entry = '{0}'", item_entry);
|
||||
|
||||
string item_name = result4.Read<string>(0);
|
||||
int item_quality = result4.Read<byte>(1);
|
||||
if (handler.GetSession() != null)
|
||||
{
|
||||
uint color = ItemConst.ItemQualityColors[item_quality];
|
||||
string itemStr = "|c" + color + "|Hitem:" + item_entry + ":0:0:0:0:0:0:0:0:0|h[" + item_name + "]|h|r";
|
||||
handler.SendSysMessage(CypherStrings.ListMailInfoItem, itemStr, item_entry, item_guid, item_count);
|
||||
}
|
||||
else
|
||||
handler.SendSysMessage(CypherStrings.ListMailInfoItem, item_name, item_entry, item_guid, item_count);
|
||||
}
|
||||
while (result3.NextRow());
|
||||
}
|
||||
}
|
||||
while (result2.NextRow());
|
||||
}
|
||||
}
|
||||
handler.SendSysMessage(CypherStrings.AccountListBar);
|
||||
}
|
||||
while (result1.NextRow());
|
||||
}
|
||||
else
|
||||
handler.SendSysMessage(CypherStrings.ListMailNotFound);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
handler.SendSysMessage(CypherStrings.ListMailNotFound);
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("object", RBACPermissions.CommandListObject, true)]
|
||||
static bool HandleListObjectCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
if (args.Empty())
|
||||
return false;
|
||||
|
||||
// number or [name] Shift-click form |color|Hgameobject_entry:go_id|h[name]|h|r
|
||||
string id = handler.extractKeyFromLink(args, "Hgameobject_entry");
|
||||
if (string.IsNullOrEmpty(id))
|
||||
return false;
|
||||
|
||||
uint gameObjectId = uint.Parse(id);
|
||||
if (gameObjectId == 0)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.CommandListobjinvalidid, gameObjectId);
|
||||
return false;
|
||||
}
|
||||
|
||||
GameObjectTemplate gInfo = Global.ObjectMgr.GetGameObjectTemplate(gameObjectId);
|
||||
if (gInfo == null)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.CommandListobjinvalidid, gameObjectId);
|
||||
return false;
|
||||
}
|
||||
|
||||
string countStr = args.NextString();
|
||||
uint count = !string.IsNullOrEmpty(countStr) ? uint.Parse(countStr) : 10;
|
||||
|
||||
if (count == 0)
|
||||
return false;
|
||||
|
||||
uint objectCount = 0;
|
||||
SQLResult result = DB.World.Query("SELECT COUNT(guid) FROM gameobject WHERE id='{0}'", gameObjectId);
|
||||
if (!result.IsEmpty())
|
||||
objectCount = result.Read<uint>(0);
|
||||
|
||||
if (handler.GetSession() != null)
|
||||
{
|
||||
Player player = handler.GetSession().GetPlayer();
|
||||
result = DB.World.Query("SELECT guid, position_x, position_y, position_z, map, id, (POW(position_x - '{0}', 2) + POW(position_y - '{1}', 2) + POW(position_z - '{2}', 2)) AS order_ FROM gameobject WHERE id = '{3}' ORDER BY order_ ASC LIMIT {4}",
|
||||
player.GetPositionX(), player.GetPositionY(), player.GetPositionZ(), gameObjectId, count);
|
||||
}
|
||||
else
|
||||
result = DB.World.Query("SELECT guid, position_x, position_y, position_z, map, id FROM gameobject WHERE id = '{0}' LIMIT {1}",
|
||||
gameObjectId, count);
|
||||
|
||||
if (!result.IsEmpty())
|
||||
{
|
||||
do
|
||||
{
|
||||
ulong guid = result.Read<ulong>(0);
|
||||
float x = result.Read<float>(1);
|
||||
float y = result.Read<float>(2);
|
||||
float z = result.Read<float>(3);
|
||||
ushort mapId = result.Read<ushort>(4);
|
||||
uint entry = result.Read<uint>(5);
|
||||
|
||||
if (handler.GetSession() != null)
|
||||
handler.SendSysMessage(CypherStrings.GoListChat, guid, entry, guid, gInfo.name, x, y, z, mapId);
|
||||
else
|
||||
handler.SendSysMessage(CypherStrings.GoListConsole, guid, gInfo.name, x, y, z, mapId);
|
||||
}
|
||||
while (result.NextRow());
|
||||
}
|
||||
|
||||
handler.SendSysMessage(CypherStrings.CommandListobjmessage, gameObjectId, objectCount);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("scenes", RBACPermissions.CommandListScenes)]
|
||||
static bool HandleListScenesCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
Player target = handler.getSelectedPlayer();
|
||||
if (!target)
|
||||
target = handler.GetSession().GetPlayer();
|
||||
|
||||
if (!target)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.PlayerNotFound);
|
||||
return false;
|
||||
}
|
||||
|
||||
var instanceByPackageMap = target.GetSceneMgr().GetSceneTemplateByInstanceMap();
|
||||
|
||||
handler.SendSysMessage(CypherStrings.DebugSceneObjectList, target.GetSceneMgr().GetActiveSceneCount());
|
||||
|
||||
foreach (var instanceByPackage in instanceByPackageMap)
|
||||
handler.SendSysMessage(CypherStrings.DebugSceneObjectDetail, instanceByPackage.Value.ScenePackageId, instanceByPackage.Key);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,261 @@
|
||||
/*
|
||||
* Copyright (C) 2012-2017 CypherCore <http://github.com/CypherCore>
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using Framework.Constants;
|
||||
using Framework.IO;
|
||||
using Game.Entities;
|
||||
using Game.Maps;
|
||||
using Game.Movement;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Game.Chat
|
||||
{
|
||||
[CommandGroup("mmap", RBACPermissions.CommandMmap, true)]
|
||||
class MMapsCommands
|
||||
{
|
||||
[Command("path", RBACPermissions.CommandMmapPath)]
|
||||
static bool PathCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
if (Global.MMapMgr.GetNavMesh(handler.GetPlayer().GetMapId(), handler.GetSession().GetPlayer().GetTerrainSwaps()) == null)
|
||||
{
|
||||
handler.SendSysMessage("NavMesh not loaded for current map.");
|
||||
return true;
|
||||
}
|
||||
|
||||
handler.SendSysMessage("mmap path:");
|
||||
|
||||
// units
|
||||
Player player = handler.GetPlayer();
|
||||
Unit target = handler.getSelectedUnit();
|
||||
if (player == null || target == null)
|
||||
{
|
||||
handler.SendSysMessage("Invalid target/source selection.");
|
||||
return true;
|
||||
}
|
||||
|
||||
string para = args.NextString();
|
||||
|
||||
bool useStraightPath = false;
|
||||
if (para.Equals("true"))
|
||||
useStraightPath = true;
|
||||
|
||||
bool useStraightLine = false;
|
||||
if (para.Equals("line"))
|
||||
useStraightLine = true;
|
||||
|
||||
// unit locations
|
||||
float x, y, z;
|
||||
player.GetPosition(out x, out y, out z);
|
||||
|
||||
// path
|
||||
PathGenerator path = new PathGenerator(target);
|
||||
path.SetUseStraightPath(useStraightPath);
|
||||
bool result = path.CalculatePath(x, y, z, false, useStraightLine);
|
||||
|
||||
var pointPath = path.GetPath();
|
||||
handler.SendSysMessage("{0}'s path to {1}:", target.GetName(), player.GetName());
|
||||
handler.SendSysMessage("Building: {0}", useStraightPath ? "StraightPath" : useStraightLine ? "Raycast" : "SmoothPath");
|
||||
handler.SendSysMessage("Result: {0} - Length: {1} - Type: {2}", (result ? "true" : "false"), pointPath.Length, path.GetPathType());
|
||||
|
||||
var start = path.GetStartPosition();
|
||||
var end = path.GetEndPosition();
|
||||
var actualEnd = path.GetActualEndPosition();
|
||||
|
||||
handler.SendSysMessage("StartPosition ({0:F3}, {1:F3}, {2:F3})", start.X, start.Y, start.Z);
|
||||
handler.SendSysMessage("EndPosition ({0:F3}, {1:F3}, {2:F3})", end.X, end.Y, end.Z);
|
||||
handler.SendSysMessage("ActualEndPosition ({0:F3}, {1:F3}, {2:F3})", actualEnd.X, actualEnd.Y, actualEnd.Z);
|
||||
|
||||
if (!player.IsGameMaster())
|
||||
handler.SendSysMessage("Enable GM mode to see the path points.");
|
||||
|
||||
for (uint i = 0; i < pointPath.Length; ++i)
|
||||
player.SummonCreature(1, pointPath[i].X, pointPath[i].Y, pointPath[i].Z, 0, TempSummonType.TimedDespawn, 9000);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("loc", RBACPermissions.CommandMmapLoc)]
|
||||
static bool LocCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
handler.SendSysMessage("mmap tileloc:");
|
||||
|
||||
// grid tile location
|
||||
Player player = handler.GetPlayer();
|
||||
|
||||
int gx = (int)(32 - player.GetPositionX() / MapConst.SizeofGrids);
|
||||
int gy = (int)(32 - player.GetPositionY() / MapConst.SizeofGrids);
|
||||
|
||||
handler.SendSysMessage("{0:D4}{1:D2}{2:D2}.mmtile", player.GetMapId(), gy, gx);
|
||||
handler.SendSysMessage("gridloc [{0}, {1}]", gx, gy);
|
||||
|
||||
// calculate navmesh tile location
|
||||
Detour.dtNavMesh navmesh = Global.MMapMgr.GetNavMesh(handler.GetPlayer().GetMapId(), handler.GetSession().GetPlayer().GetTerrainSwaps());
|
||||
Detour.dtNavMeshQuery navmeshquery = Global.MMapMgr.GetNavMeshQuery(handler.GetPlayer().GetMapId(), player.GetInstanceId(), handler.GetSession().GetPlayer().GetTerrainSwaps());
|
||||
if (navmesh == null || navmeshquery == null)
|
||||
{
|
||||
handler.SendSysMessage("NavMesh not loaded for current map.");
|
||||
return true;
|
||||
}
|
||||
|
||||
float[] min = navmesh.getParams().orig;
|
||||
float x, y, z;
|
||||
player.GetPosition(out x, out y, out z);
|
||||
float[] location = { y, z, x };
|
||||
float[] extents = { 3.0f, 5.0f, 3.0f };
|
||||
|
||||
int tilex = (int)((y - min[0]) / MapConst.SizeofGrids);
|
||||
int tiley = (int)((x - min[2]) / MapConst.SizeofGrids);
|
||||
|
||||
handler.SendSysMessage("Calc [{0:D2}, {1:D2}]", tilex, tiley);
|
||||
|
||||
// navmesh poly . navmesh tile location
|
||||
Detour.dtQueryFilter filter = new Detour.dtQueryFilter();
|
||||
float[] nothing = new float[3];
|
||||
ulong polyRef = 0;
|
||||
if (Detour.dtStatusFailed(navmeshquery.findNearestPoly(location, extents, filter, ref polyRef, ref nothing)))
|
||||
{
|
||||
handler.SendSysMessage("Dt [??,??] (invalid poly, probably no tile loaded)");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (polyRef == 0)
|
||||
handler.SendSysMessage("Dt [??, ??] (invalid poly, probably no tile loaded)");
|
||||
else
|
||||
{
|
||||
Detour.dtMeshTile tile = new Detour.dtMeshTile();
|
||||
Detour.dtPoly poly = new Detour.dtPoly();
|
||||
if (Detour.dtStatusSucceed(navmesh.getTileAndPolyByRef(polyRef, ref tile, ref poly)))
|
||||
{
|
||||
if (tile != null)
|
||||
{
|
||||
handler.SendSysMessage("Dt [{0:D2},{1:D2}]", tile.header.x, tile.header.y);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
handler.SendSysMessage("Dt [??,??] (no tile loaded)");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("loadedtiles", RBACPermissions.CommandMmapLoadedtiles)]
|
||||
static bool LoadedTilesCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
uint mapid = handler.GetPlayer().GetMapId();
|
||||
Detour.dtNavMesh navmesh = Global.MMapMgr.GetNavMesh(mapid, handler.GetSession().GetPlayer().GetTerrainSwaps());
|
||||
Detour.dtNavMeshQuery navmeshquery = Global.MMapMgr.GetNavMeshQuery(mapid, handler.GetPlayer().GetInstanceId(), handler.GetSession().GetPlayer().GetTerrainSwaps());
|
||||
if (navmesh == null || navmeshquery == null)
|
||||
{
|
||||
handler.SendSysMessage("NavMesh not loaded for current map.");
|
||||
return true;
|
||||
}
|
||||
|
||||
handler.SendSysMessage("mmap loadedtiles:");
|
||||
|
||||
for (int i = 0; i < navmesh.getMaxTiles(); ++i)
|
||||
{
|
||||
Detour.dtMeshTile tile = navmesh.getTile(i);
|
||||
if (tile == null)
|
||||
continue;
|
||||
|
||||
handler.SendSysMessage("[{0:D2}, {1:D2}]", tile.header.x, tile.header.y);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("stats", RBACPermissions.CommandMmapStats)]
|
||||
static bool HandleMmapStatsCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
uint mapId = handler.GetPlayer().GetMapId();
|
||||
handler.SendSysMessage("mmap stats:");
|
||||
handler.SendSysMessage(" global mmap pathfinding is {0}abled", Global.DisableMgr.IsPathfindingEnabled(mapId) ? "En" : "Dis");
|
||||
handler.SendSysMessage(" {0} maps loaded with {1} tiles overall", Global.MMapMgr.getLoadedMapsCount(), Global.MMapMgr.getLoadedTilesCount());
|
||||
|
||||
Detour.dtNavMesh navmesh = Global.MMapMgr.GetNavMesh(handler.GetPlayer().GetMapId(), handler.GetSession().GetPlayer().GetTerrainSwaps());
|
||||
if (navmesh == null)
|
||||
{
|
||||
handler.SendSysMessage("NavMesh not loaded for current map.");
|
||||
return true;
|
||||
}
|
||||
|
||||
uint tileCount = 0;
|
||||
int nodeCount = 0;
|
||||
int polyCount = 0;
|
||||
int vertCount = 0;
|
||||
int triCount = 0;
|
||||
int triVertCount = 0;
|
||||
for (int i = 0; i < navmesh.getMaxTiles(); ++i)
|
||||
{
|
||||
Detour.dtMeshTile tile = navmesh.getTile(i);
|
||||
if (tile == null)
|
||||
continue;
|
||||
|
||||
tileCount++;
|
||||
nodeCount += tile.header.bvNodeCount;
|
||||
polyCount += tile.header.polyCount;
|
||||
vertCount += tile.header.vertCount;
|
||||
triCount += tile.header.detailTriCount;
|
||||
triVertCount += tile.header.detailVertCount;
|
||||
}
|
||||
|
||||
handler.SendSysMessage("Navmesh stats:");
|
||||
handler.SendSysMessage(" {0} tiles loaded", tileCount);
|
||||
handler.SendSysMessage(" {0} BVTree nodes", nodeCount);
|
||||
handler.SendSysMessage(" {0} polygons ({1} vertices)", polyCount, vertCount);
|
||||
handler.SendSysMessage(" {0} triangles ({1} vertices)", triCount, triVertCount);
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("testarea", RBACPermissions.CommandMmapTestarea)]
|
||||
static bool TestArea(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
float radius = 40.0f;
|
||||
WorldObject obj = handler.GetPlayer();
|
||||
|
||||
// Get Creatures
|
||||
List<Unit> creatureList = new List<Unit>();
|
||||
|
||||
var go_check = new AnyUnitInObjectRangeCheck(obj, radius);
|
||||
var go_search = new UnitListSearcher(obj, creatureList, go_check);
|
||||
|
||||
Cell.VisitGridObjects(obj, go_search, radius);
|
||||
if (!creatureList.Empty())
|
||||
{
|
||||
handler.SendSysMessage("Found {0} Creatures.", creatureList.Count);
|
||||
|
||||
uint paths = 0;
|
||||
uint uStartTime = Time.GetMSTime();
|
||||
|
||||
float gx, gy, gz;
|
||||
obj.GetPosition(out gx, out gy, out gz);
|
||||
foreach (var creature in creatureList)
|
||||
{
|
||||
PathGenerator path = new PathGenerator(creature);
|
||||
path.CalculatePath(gx, gy, gz);
|
||||
++paths;
|
||||
}
|
||||
|
||||
uint uPathLoadTime = Time.GetMSTimeDiffToNow(uStartTime);
|
||||
handler.SendSysMessage("Generated {0} paths in {1} ms", paths, uPathLoadTime);
|
||||
}
|
||||
else
|
||||
handler.SendSysMessage("No creatures in {0} yard range.", radius);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,233 @@
|
||||
/*
|
||||
* Copyright (C) 2012-2017 CypherCore <http://github.com/CypherCore>
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using Framework.Constants;
|
||||
using Framework.Database;
|
||||
using Framework.IO;
|
||||
using Game.DataStorage;
|
||||
using Game.Entities;
|
||||
using Game.Network.Packets;
|
||||
using System;
|
||||
|
||||
namespace Game.Chat
|
||||
{
|
||||
class MessageCommands
|
||||
{
|
||||
[CommandNonGroup("nameannounce", RBACPermissions.CommandNameannounce, true)]
|
||||
static bool HandleNameAnnounceCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
if (args.Empty())
|
||||
return false;
|
||||
|
||||
string name = "Console";
|
||||
WorldSession session = handler.GetSession();
|
||||
if (session)
|
||||
name = session.GetPlayer().GetName();
|
||||
|
||||
Global.WorldMgr.SendWorldText(CypherStrings.AnnounceColor, name, args);
|
||||
return true;
|
||||
}
|
||||
|
||||
[CommandNonGroup("gmnameannounce", RBACPermissions.CommandGmnameannounce, true)]
|
||||
static bool HandleGMNameAnnounceCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
if (args.Empty())
|
||||
return false;
|
||||
|
||||
string name = "Console";
|
||||
WorldSession session = handler.GetSession();
|
||||
if (session)
|
||||
name = session.GetPlayer().GetName();
|
||||
|
||||
Global.WorldMgr.SendGMText(CypherStrings.AnnounceColor, name, args);
|
||||
return true;
|
||||
}
|
||||
|
||||
[CommandNonGroup("announce", RBACPermissions.CommandAnnounce, true)]
|
||||
static bool HandleAnnounceCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
if (args.Empty())
|
||||
return false;
|
||||
|
||||
string str = handler.GetParsedString(CypherStrings.Systemmessage, args.NextString(""));
|
||||
Global.WorldMgr.SendServerMessage(ServerMessageType.String, str);
|
||||
return true;
|
||||
}
|
||||
|
||||
[CommandNonGroup("gmannounce", RBACPermissions.CommandGmannounce, true)]
|
||||
static bool HandleGMAnnounceCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
if (args.Empty())
|
||||
return false;
|
||||
|
||||
Global.WorldMgr.SendGMText(CypherStrings.GmBroadcast, args.NextString(""));
|
||||
return true;
|
||||
}
|
||||
|
||||
[CommandNonGroup("notify", RBACPermissions.CommandNotify, true)]
|
||||
static bool HandleNotifyCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
if (args.Empty())
|
||||
return false;
|
||||
|
||||
string str = handler.GetCypherString(CypherStrings.GlobalNotify);
|
||||
str += args.NextString("");
|
||||
|
||||
Global.WorldMgr.SendGlobalMessage(new PrintNotification(str));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
[CommandNonGroup("gmnotify", RBACPermissions.CommandGmnotify, true)]
|
||||
static bool HandleGMNotifyCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
if (args.Empty())
|
||||
return false;
|
||||
|
||||
string str = handler.GetCypherString(CypherStrings.GmNotify);
|
||||
str += args.NextString("");
|
||||
|
||||
Global.WorldMgr.SendGlobalGMMessage(new PrintNotification(str));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
[CommandNonGroup("whispers", RBACPermissions.CommandWhispers)]
|
||||
static bool HandleWhispersCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
if (args.Empty())
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.CommandWhisperaccepting, handler.GetSession().GetPlayer().isAcceptWhispers() ? handler.GetCypherString(CypherStrings.On) : handler.GetCypherString(CypherStrings.Off));
|
||||
return true;
|
||||
}
|
||||
|
||||
string argStr = args.NextString();
|
||||
// whisper on
|
||||
if (argStr == "on")
|
||||
{
|
||||
handler.GetSession().GetPlayer().SetAcceptWhispers(true);
|
||||
handler.SendSysMessage(CypherStrings.CommandWhisperon);
|
||||
return true;
|
||||
}
|
||||
|
||||
// whisper off
|
||||
if (argStr == "off")
|
||||
{
|
||||
// Remove all players from the Gamemaster's whisper whitelist
|
||||
handler.GetSession().GetPlayer().ClearWhisperWhiteList();
|
||||
handler.GetSession().GetPlayer().SetAcceptWhispers(false);
|
||||
handler.SendSysMessage(CypherStrings.CommandWhisperoff);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (argStr == "remove")
|
||||
{
|
||||
string name = args.NextString();
|
||||
if (ObjectManager.NormalizePlayerName(ref name))
|
||||
{
|
||||
Player player = Global.ObjAccessor.FindPlayerByName(name);
|
||||
if (player)
|
||||
{
|
||||
handler.GetSession().GetPlayer().RemoveFromWhisperWhiteList(player.GetGUID());
|
||||
handler.SendSysMessage(CypherStrings.CommandWhisperoffplayer, name);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.PlayerNotFound, name);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
handler.SendSysMessage(CypherStrings.UseBol);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
[CommandGroup("channel", RBACPermissions.CommandChannel, true)]
|
||||
class ChannelCommands
|
||||
{
|
||||
[CommandGroup("set", RBACPermissions.CommandChannelSet, true)]
|
||||
class ChannelSetCommands
|
||||
{
|
||||
[Command("ownership", RBACPermissions.CommandChannelSetOwnership)]
|
||||
static bool HandleChannelSetOwnership(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
if (args.Empty())
|
||||
return false;
|
||||
|
||||
string channelStr = args.NextString();
|
||||
string argStr = args.NextString("");
|
||||
|
||||
if (channelStr.IsEmpty() || argStr.IsEmpty())
|
||||
return false;
|
||||
|
||||
uint channelId = 0;
|
||||
foreach (var channelEntry in CliDB.ChatChannelsStorage.Values)
|
||||
{
|
||||
if (channelEntry.Name[handler.GetSessionDbcLocale()].Equals(channelStr))
|
||||
{
|
||||
channelId = channelEntry.Id;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
AreaTableRecord zoneEntry = null;
|
||||
foreach (var entry in CliDB.AreaTableStorage.Values)
|
||||
{
|
||||
if (entry.AreaName[handler.GetSessionDbcLocale()].Equals(channelStr))
|
||||
{
|
||||
zoneEntry = entry;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Player player = handler.GetSession().GetPlayer();
|
||||
Channel channel = null;
|
||||
|
||||
ChannelManager cMgr = ChannelManager.ForTeam(player.GetTeam());
|
||||
if (cMgr != null)
|
||||
channel = cMgr.GetChannel(channelId, channelStr, player, false, zoneEntry);
|
||||
|
||||
if (argStr.ToLower() == "on")
|
||||
{
|
||||
if (channel != null)
|
||||
channel.SetOwnership(true);
|
||||
PreparedStatement stmt = DB.Characters.GetPreparedStatement(CharStatements.UPD_CHANNEL_OWNERSHIP);
|
||||
stmt.AddValue(0, 1);
|
||||
stmt.AddValue(1, channelStr);
|
||||
DB.Characters.Execute(stmt);
|
||||
handler.SendSysMessage(CypherStrings.ChannelEnableOwnership, channelStr);
|
||||
}
|
||||
else if (argStr.ToLower() == "off")
|
||||
{
|
||||
if (channel != null)
|
||||
channel.SetOwnership(false);
|
||||
PreparedStatement stmt = DB.Characters.GetPreparedStatement(CharStatements.UPD_CHANNEL_OWNERSHIP);
|
||||
stmt.AddValue(0, 0);
|
||||
stmt.AddValue(1, channelStr);
|
||||
DB.Characters.Execute(stmt);
|
||||
handler.SendSysMessage(CypherStrings.ChannelDisableOwnership, channelStr);
|
||||
}
|
||||
else
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,868 @@
|
||||
/*
|
||||
* Copyright (C) 2012-2017 CypherCore <http://github.com/CypherCore>
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using Framework.Constants;
|
||||
using Framework.IO;
|
||||
using Game.DataStorage;
|
||||
using Game.Entities;
|
||||
using Game.Network.Packets;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Game.Chat
|
||||
{
|
||||
[CommandGroup("modify", RBACPermissions.CommandModify)]
|
||||
class ModifyCommand
|
||||
{
|
||||
[Command("hp", RBACPermissions.CommandModifyHp)]
|
||||
static bool HandleModifyHPCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
int hp, hpmax = 0;
|
||||
Player target = handler.getSelectedPlayerOrSelf();
|
||||
if (CheckModifyResources(args, handler, target, out hp, out hpmax))
|
||||
{
|
||||
NotifyModification(handler, target, CypherStrings.YouChangeHp, CypherStrings.YoursHpChanged, hp, hpmax);
|
||||
target.SetMaxHealth((uint)hpmax);
|
||||
target.SetHealth((uint)hp);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
[Command("mana", RBACPermissions.CommandModifyMana)]
|
||||
static bool HandleModifyManaCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
int mana, manamax;
|
||||
Player target = handler.getSelectedPlayerOrSelf();
|
||||
|
||||
if (CheckModifyResources(args, handler, target, out mana, out manamax))
|
||||
{
|
||||
NotifyModification(handler, target, CypherStrings.YouChangeMana, CypherStrings.YoursManaChanged, mana, manamax);
|
||||
target.SetMaxPower(PowerType.Mana, manamax);
|
||||
target.SetPower(PowerType.Mana, mana);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
[Command("energy", RBACPermissions.CommandModifyEnergy)]
|
||||
static bool HandleModifyEnergyCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
int energy, energymax;
|
||||
Player target = handler.getSelectedPlayerOrSelf();
|
||||
byte energyMultiplier = 10;
|
||||
if (CheckModifyResources(args, handler, target, out energy, out energymax, energyMultiplier))
|
||||
{
|
||||
NotifyModification(handler, target, CypherStrings.YouChangeEnergy, CypherStrings.YoursEnergyChanged, energy / energyMultiplier, energymax / energyMultiplier);
|
||||
target.SetMaxPower(PowerType.Energy, energymax);
|
||||
target.SetPower(PowerType.Energy, energy);
|
||||
Log.outDebug(LogFilter.Misc, handler.GetCypherString(CypherStrings.CurrentEnergy), target.GetMaxPower(PowerType.Energy));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
[Command("rage", RBACPermissions.CommandModifyRage)]
|
||||
static bool HandleModifyRageCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
int rage, ragemax;
|
||||
Player target = handler.getSelectedPlayerOrSelf();
|
||||
byte rageMultiplier = 10;
|
||||
if (CheckModifyResources(args, handler, target, out rage, out ragemax, rageMultiplier))
|
||||
{
|
||||
NotifyModification(handler, target, CypherStrings.YouChangeRage, CypherStrings.YoursRageChanged, rage / rageMultiplier, ragemax / rageMultiplier);
|
||||
target.SetMaxPower(PowerType.Rage, ragemax);
|
||||
target.SetPower(PowerType.Rage, rage);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
[Command("runicpower", RBACPermissions.CommandModifyRunicpower)]
|
||||
static bool HandleModifyRunicPowerCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
int rune, runemax;
|
||||
Player target = handler.getSelectedPlayerOrSelf();
|
||||
byte runeMultiplier = 10;
|
||||
if (CheckModifyResources(args, handler, target, out rune, out runemax, runeMultiplier))
|
||||
{
|
||||
NotifyModification(handler, target, CypherStrings.YouChangeRunicPower, CypherStrings.YoursRunicPowerChanged, rune / runeMultiplier, runemax / runeMultiplier);
|
||||
target.SetMaxPower(PowerType.RunicPower, runemax);
|
||||
target.SetPower(PowerType.RunicPower, rune);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
[Command("faction", RBACPermissions.CommandModifyFaction)]
|
||||
static bool HandleModifyFactionCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
string pfactionid = handler.extractKeyFromLink(args, "Hfaction");
|
||||
|
||||
Creature target = handler.getSelectedCreature();
|
||||
if (!target)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.SelectCreature);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(pfactionid))
|
||||
{
|
||||
uint _factionid = target.getFaction();
|
||||
uint _flag = target.GetUInt32Value(UnitFields.Flags);
|
||||
ulong _npcflag = target.GetUInt64Value(UnitFields.NpcFlags);
|
||||
uint _dyflag = target.GetUInt32Value(ObjectFields.DynamicFlags);
|
||||
handler.SendSysMessage(CypherStrings.CurrentFaction, target.GetGUID().ToString(), _factionid, _flag, _npcflag, _dyflag);
|
||||
return true;
|
||||
}
|
||||
|
||||
uint factionid = uint.Parse(pfactionid);
|
||||
uint flag;
|
||||
|
||||
string pflag = args.NextString();
|
||||
if (string.IsNullOrEmpty(pflag))
|
||||
flag = target.GetUInt32Value(UnitFields.Flags);
|
||||
else
|
||||
flag = uint.Parse(pflag);
|
||||
|
||||
string pnpcflag = args.NextString();
|
||||
|
||||
ulong npcflag;
|
||||
if (string.IsNullOrEmpty(pnpcflag))
|
||||
npcflag = target.GetUInt64Value(UnitFields.NpcFlags);
|
||||
else
|
||||
npcflag = ulong.Parse(pnpcflag);
|
||||
|
||||
string pdyflag = args.NextString();
|
||||
|
||||
uint dyflag;
|
||||
if (string.IsNullOrEmpty(pdyflag))
|
||||
dyflag = target.GetUInt32Value(ObjectFields.DynamicFlags);
|
||||
else
|
||||
dyflag = uint.Parse(pdyflag);
|
||||
|
||||
if (!CliDB.FactionTemplateStorage.ContainsKey(factionid))
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.WrongFaction, factionid);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
handler.SendSysMessage(CypherStrings.YouChangeFaction, target.GetGUID().ToString(), factionid, flag, npcflag, dyflag);
|
||||
|
||||
target.SetFaction(factionid);
|
||||
target.SetUInt32Value(UnitFields.Flags, flag);
|
||||
target.SetUInt64Value(UnitFields.NpcFlags, npcflag);
|
||||
target.SetUInt32Value(ObjectFields.DynamicFlags, dyflag);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("spell", RBACPermissions.CommandModifySpell)]
|
||||
static bool HandleModifySpellCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
if (args.Empty())
|
||||
return false;
|
||||
|
||||
byte spellflatid = args.NextByte();
|
||||
if (spellflatid == 0)
|
||||
return false;
|
||||
|
||||
byte op = args.NextByte();
|
||||
if (op == 0)
|
||||
return false;
|
||||
|
||||
ushort val = args.NextUInt16();
|
||||
if (val == 0)
|
||||
return false;
|
||||
|
||||
ushort mark;
|
||||
|
||||
string pmark = args.NextString();
|
||||
if (string.IsNullOrEmpty(pmark))
|
||||
mark = 65535;
|
||||
else
|
||||
mark = ushort.Parse(pmark);
|
||||
|
||||
Player target = handler.getSelectedPlayerOrSelf();
|
||||
if (!target)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.NoCharSelected);
|
||||
return false;
|
||||
}
|
||||
|
||||
// check online security
|
||||
if (handler.HasLowerSecurity(target, ObjectGuid.Empty))
|
||||
return false;
|
||||
|
||||
handler.SendSysMessage(CypherStrings.YouChangeSpellflatid, spellflatid, val, mark, handler.GetNameLink(target));
|
||||
if (handler.needReportToTarget(target))
|
||||
target.SendSysMessage(CypherStrings.YoursSpellflatidChanged, handler.GetNameLink(), spellflatid, val, mark);
|
||||
|
||||
SetSpellModifier packet = new SetSpellModifier(ServerOpcodes.SetFlatSpellModifier);
|
||||
SpellModifierInfo spellMod = new SpellModifierInfo();
|
||||
spellMod.ModIndex = op;
|
||||
SpellModifierData modData;
|
||||
modData.ClassIndex = spellflatid;
|
||||
modData.ModifierValue = val;
|
||||
spellMod.ModifierData.Add(modData);
|
||||
packet.Modifiers.Add(spellMod);
|
||||
target.SendPacket(packet);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("talentpoints", RBACPermissions.CommandModifyTalentpoints)]
|
||||
static bool HandleModifyTalentCommand(StringArguments args, CommandHandler handler) { return false; }
|
||||
|
||||
[Command("scale", RBACPermissions.CommandModifyScale)]
|
||||
static bool HandleModifyScaleCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
float Scale;
|
||||
Unit target = handler.getSelectedUnit();
|
||||
if (CheckModifySpeed(args, handler, target, out Scale, 0.1f, 10.0f, false))
|
||||
{
|
||||
NotifyModification(handler, target, CypherStrings.YouChangeSize, CypherStrings.YoursSizeChanged, Scale);
|
||||
target.SetObjectScale(Scale);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
[Command("mount", RBACPermissions.CommandModifyMount)]
|
||||
static bool HandleModifyMountCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
if (args.Empty())
|
||||
return false;
|
||||
|
||||
string mountStr = args.NextString();
|
||||
if (mountStr.IsEmpty())
|
||||
return false;
|
||||
|
||||
if (uint.TryParse(mountStr, out uint mount))
|
||||
return false;
|
||||
|
||||
if (!CliDB.CreatureDisplayInfoStorage.HasRecord(mount))
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.NoMount);
|
||||
return false;
|
||||
}
|
||||
|
||||
Player target = handler.getSelectedPlayerOrSelf();
|
||||
if (!target)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.NoCharSelected);
|
||||
return false;
|
||||
}
|
||||
|
||||
// check online security
|
||||
if (handler.HasLowerSecurity(target, ObjectGuid.Empty))
|
||||
return false;
|
||||
|
||||
float speed;
|
||||
if (!CheckModifySpeed(args, handler, target, out speed, 0.1f, 50.0f))
|
||||
return false;
|
||||
|
||||
NotifyModification(handler, target, CypherStrings.YouGiveMount, CypherStrings.MountGived);
|
||||
target.Mount(mount);
|
||||
target.SetSpeedRate(UnitMoveType.Run, speed);
|
||||
target.SetSpeedRate(UnitMoveType.Flight, speed);
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("money", RBACPermissions.CommandModifyMoney)]
|
||||
static bool HandleModifyMoneyCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
Player target = handler.getSelectedPlayerOrSelf();
|
||||
if (!target)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.NoCharSelected);
|
||||
return false;
|
||||
}
|
||||
|
||||
// check online security
|
||||
if (handler.HasLowerSecurity(target, ObjectGuid.Empty))
|
||||
return false;
|
||||
|
||||
long moneyToAdd = args.NextInt64();
|
||||
ulong targetMoney = target.GetMoney();
|
||||
|
||||
if (moneyToAdd < 0)
|
||||
{
|
||||
ulong newmoney = (targetMoney + (ulong)moneyToAdd);
|
||||
|
||||
Log.outDebug(LogFilter.ChatSystem, Global.ObjectMgr.GetCypherString(CypherStrings.CurrentMoney), targetMoney, moneyToAdd, newmoney);
|
||||
if (newmoney <= 0)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.YouTakeAllMoney, handler.GetNameLink(target));
|
||||
if (handler.needReportToTarget(target))
|
||||
target.SendSysMessage(CypherStrings.YoursAllMoneyGone, handler.GetNameLink());
|
||||
|
||||
target.SetMoney(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
ulong moneyToAddMsg = (ulong)(moneyToAdd * -1);
|
||||
if (newmoney > PlayerConst.MaxMoneyAmount)
|
||||
newmoney = PlayerConst.MaxMoneyAmount;
|
||||
|
||||
handler.SendSysMessage(CypherStrings.YouTakeMoney, Math.Abs(moneyToAdd), handler.GetNameLink(target));
|
||||
if (handler.needReportToTarget(target))
|
||||
target.SendSysMessage(CypherStrings.YoursMoneyTaken, handler.GetNameLink(), Math.Abs(moneyToAdd));
|
||||
target.SetMoney(newmoney);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.YouGiveMoney, moneyToAdd, handler.GetNameLink(target));
|
||||
if (handler.needReportToTarget(target))
|
||||
target.SendSysMessage(CypherStrings.YoursMoneyGiven, handler.GetNameLink(), moneyToAdd);
|
||||
|
||||
if ((ulong)moneyToAdd >= PlayerConst.MaxMoneyAmount)
|
||||
moneyToAdd = Convert.ToInt64(PlayerConst.MaxMoneyAmount);
|
||||
|
||||
moneyToAdd = Math.Min(moneyToAdd, (long)(PlayerConst.MaxMoneyAmount - targetMoney));
|
||||
|
||||
target.ModifyMoney(moneyToAdd);
|
||||
}
|
||||
|
||||
Log.outDebug(LogFilter.ChatSystem, Global.ObjectMgr.GetCypherString(CypherStrings.NewMoney), targetMoney, moneyToAdd, target.GetMoney());
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("bit", RBACPermissions.CommandModifyBit)]
|
||||
static bool HandleModifyBitCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
if (args.Empty())
|
||||
return false;
|
||||
|
||||
Unit target = handler.getSelectedUnit();
|
||||
if (!target)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.NoCharSelected);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// check online security
|
||||
if (target.IsTypeId(TypeId.Player) && handler.HasLowerSecurity(target.ToPlayer(), ObjectGuid.Empty))
|
||||
return false;
|
||||
|
||||
ushort field = args.NextUInt16();
|
||||
int bit = args.NextInt32();
|
||||
|
||||
if (field < (int)ObjectFields.End || field >= target.valuesCount)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.BadValue);
|
||||
return false;
|
||||
}
|
||||
if (bit < 1 || bit > 32)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.BadValue);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (target.HasFlag(field, (1 << (bit - 1))))
|
||||
{
|
||||
target.RemoveFlag(field, (1 << (bit - 1)));
|
||||
handler.SendSysMessage(CypherStrings.RemoveBit, bit, field);
|
||||
}
|
||||
else
|
||||
{
|
||||
target.SetFlag(field, (1 << (bit - 1)));
|
||||
handler.SendSysMessage(CypherStrings.SetBit, bit, field);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("honor", RBACPermissions.CommandModifyHonor)]
|
||||
static bool HandleModifyHonorCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
if (args.Empty())
|
||||
return false;
|
||||
|
||||
Player target = handler.getSelectedPlayerOrSelf();
|
||||
if (!target)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.PlayerNotFound);
|
||||
return false;
|
||||
}
|
||||
|
||||
// check online security
|
||||
if (handler.HasLowerSecurity(target, ObjectGuid.Empty))
|
||||
return false;
|
||||
|
||||
int amount = args.NextInt32();
|
||||
|
||||
//target.ModifyCurrency(CurrencyTypes.HonorPoints, amount, true, true);
|
||||
handler.SendSysMessage("NOT IMPLEMENTED: {0} honor NOT added.", amount);
|
||||
|
||||
//handler.SendSysMessage(CypherStrings.CommandModifyHonor, handler.GetNameLink(target), target.GetCurrency((uint)CurrencyTypes.HonorPoints));
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("drunk", RBACPermissions.CommandModifyDrunk)]
|
||||
static bool HandleModifyDrunkCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
if (args.Empty())
|
||||
return false;
|
||||
|
||||
byte drunklevel = args.NextByte();
|
||||
if (drunklevel > 100)
|
||||
drunklevel = 100;
|
||||
|
||||
Player target = handler.getSelectedPlayerOrSelf();
|
||||
if (target)
|
||||
target.SetDrunkValue(drunklevel);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("reputation", RBACPermissions.CommandModifyReputation)]
|
||||
static bool HandleModifyRepCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
if (args.Empty())
|
||||
return false;
|
||||
|
||||
Player target = handler.getSelectedPlayerOrSelf();
|
||||
if (!target)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.PlayerNotFound);
|
||||
return false;
|
||||
}
|
||||
|
||||
// check online security
|
||||
if (handler.HasLowerSecurity(target, ObjectGuid.Empty))
|
||||
return false;
|
||||
|
||||
string factionTxt = handler.extractKeyFromLink(args, "Hfaction");
|
||||
if (string.IsNullOrEmpty(factionTxt))
|
||||
return false;
|
||||
|
||||
uint factionId = uint.Parse(factionTxt);
|
||||
|
||||
int amount = 0;
|
||||
string rankTxt = args.NextString();
|
||||
if (factionId == 0 || rankTxt.IsEmpty())
|
||||
return false;
|
||||
|
||||
amount = int.Parse(rankTxt);
|
||||
if ((amount == 0) && !(amount < 0) && !rankTxt.IsNumber())
|
||||
{
|
||||
string rankStr = rankTxt.ToLower();
|
||||
|
||||
int r = 0;
|
||||
amount = -42000;
|
||||
for (; r < (int)ReputationRank.Max; ++r)
|
||||
{
|
||||
string rank = handler.GetCypherString(ReputationMgr.ReputationRankStrIndex[r]);
|
||||
if (string.IsNullOrEmpty(rank))
|
||||
continue;
|
||||
|
||||
if (rank.Equals(rankStr))
|
||||
{
|
||||
string deltaTxt = args.NextString();
|
||||
if (!string.IsNullOrEmpty(deltaTxt))
|
||||
{
|
||||
int delta = int.Parse(deltaTxt);
|
||||
if ((delta < 0) || (delta > ReputationMgr.PointsInRank[r] - 1))
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.CommandFactionDelta, (ReputationMgr.PointsInRank[r] - 1));
|
||||
return false;
|
||||
}
|
||||
amount += delta;
|
||||
}
|
||||
break;
|
||||
}
|
||||
amount += ReputationMgr.PointsInRank[r];
|
||||
}
|
||||
if (r >= (int)ReputationRank.Max)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.CommandFactionInvparam, rankTxt);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
FactionRecord factionEntry = CliDB.FactionStorage.LookupByKey(factionId);
|
||||
if (factionEntry == null)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.CommandFactionUnknown, factionId);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (factionEntry.ReputationIndex < 0)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.CommandFactionNorepError, factionEntry.Name[handler.GetSessionDbcLocale()], factionId);
|
||||
return false;
|
||||
}
|
||||
|
||||
target.GetReputationMgr().SetOneFactionReputation(factionEntry, amount, false);
|
||||
target.GetReputationMgr().SendState(target.GetReputationMgr().GetState(factionEntry));
|
||||
handler.SendSysMessage(CypherStrings.CommandModifyRep, factionEntry.Name[handler.GetSessionDbcLocale()], factionId, handler.GetNameLink(target), target.GetReputationMgr().GetReputation(factionEntry));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("phase", RBACPermissions.CommandModifyPhase)]
|
||||
static bool HandleModifyPhaseCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
if (args.Empty())
|
||||
return false;
|
||||
|
||||
uint phaseId = args.NextUInt32();
|
||||
if (!CliDB.PhaseStorage.ContainsKey(phaseId))
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.PhaseNotfound);
|
||||
return false;
|
||||
}
|
||||
|
||||
Unit target = handler.getSelectedUnit();
|
||||
if (!target)
|
||||
target = handler.GetSession().GetPlayer();
|
||||
|
||||
target.SetInPhase(phaseId, true, !target.IsInPhase(phaseId));
|
||||
|
||||
if (target.IsTypeId(TypeId.Player))
|
||||
target.ToPlayer().SendUpdatePhasing();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("standstate", RBACPermissions.CommandModifyStandstate)]
|
||||
static bool HandleModifyStandStateCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
if (args.Empty())
|
||||
return false;
|
||||
|
||||
uint anim_id = args.NextUInt32();
|
||||
handler.GetSession().GetPlayer().SetUInt32Value(UnitFields.NpcEmotestate, anim_id);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("gender", RBACPermissions.CommandModifyGender)]
|
||||
static bool HandleModifyGenderCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
if (args.Empty())
|
||||
return false;
|
||||
|
||||
Player target = handler.getSelectedPlayerOrSelf();
|
||||
if (!target)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.PlayerNotFound);
|
||||
return false;
|
||||
}
|
||||
|
||||
PlayerInfo info = Global.ObjectMgr.GetPlayerInfo(target.GetRace(), target.GetClass());
|
||||
if (info == null)
|
||||
return false;
|
||||
|
||||
string gender_str = args.NextString();
|
||||
Gender gender;
|
||||
|
||||
if (gender_str == "male") // MALE
|
||||
{
|
||||
if (target.GetGender() == Gender.Male)
|
||||
return true;
|
||||
|
||||
gender = Gender.Male;
|
||||
}
|
||||
else if (gender_str == "female") // FEMALE
|
||||
{
|
||||
if (target.GetGender() == Gender.Female)
|
||||
return true;
|
||||
|
||||
gender = Gender.Female;
|
||||
}
|
||||
else
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.MustMaleOrFemale);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Set gender
|
||||
target.SetByteValue(UnitFields.Bytes0, 3, (byte)gender);
|
||||
target.SetByteValue(PlayerFields.Bytes3, PlayerFieldOffsets.Bytes3OffsetGender, (byte)gender);
|
||||
|
||||
// Change display ID
|
||||
target.InitDisplayIds();
|
||||
|
||||
handler.SendSysMessage(CypherStrings.YouChangeGender, handler.GetNameLink(target), gender);
|
||||
|
||||
if (handler.needReportToTarget(target))
|
||||
target.SendSysMessage(CypherStrings.YourGenderChanged, gender, handler.GetNameLink());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("currency", RBACPermissions.CommandModifyCurrency)]
|
||||
static bool HandleModifyCurrencyCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
if (args.Empty())
|
||||
return false;
|
||||
|
||||
Player target = handler.getSelectedPlayerOrSelf();
|
||||
if (!target)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.PlayerNotFound);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
uint currencyId = args.NextUInt32();
|
||||
if (!CliDB.CurrencyTypesStorage.ContainsKey(currencyId))
|
||||
return false;
|
||||
|
||||
uint amount = args.NextUInt32();
|
||||
if (amount == 0)
|
||||
return false;
|
||||
|
||||
target.ModifyCurrency((CurrencyTypes)currencyId, (int)amount, true, true);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
[CommandNonGroup("morph", RBACPermissions.CommandMorph)]
|
||||
static bool HandleModifyMorphCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
if (args.Empty())
|
||||
return false;
|
||||
|
||||
uint display_id = args.NextUInt32();
|
||||
|
||||
Unit target = handler.getSelectedUnit();
|
||||
if (!target)
|
||||
target = handler.GetSession().GetPlayer();
|
||||
|
||||
// check online security
|
||||
else if (target.IsTypeId(TypeId.Player) && handler.HasLowerSecurity(target.ToPlayer(), ObjectGuid.Empty))
|
||||
return false;
|
||||
|
||||
target.SetDisplayId(display_id);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
[CommandNonGroup("demorph", RBACPermissions.CommandDemorph)]
|
||||
static bool HandleDeMorphCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
Unit target = handler.getSelectedUnit();
|
||||
if (!target)
|
||||
target = handler.GetSession().GetPlayer();
|
||||
|
||||
// check online security
|
||||
else if (target.IsTypeId(TypeId.Player) && handler.HasLowerSecurity(target.ToPlayer(), ObjectGuid.Empty))
|
||||
return false;
|
||||
|
||||
target.DeMorph();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("xp", RBACPermissions.CommandModifyXp)]
|
||||
static bool HandleModifyXPCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
if (args.Empty())
|
||||
return false;
|
||||
|
||||
int xp = args.NextInt32();
|
||||
|
||||
if (xp < 1)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.BadValue);
|
||||
return false;
|
||||
}
|
||||
|
||||
Player target = handler.getSelectedPlayerOrSelf();
|
||||
if (!target)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.NoCharSelected);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (handler.HasLowerSecurity(target, ObjectGuid.Empty))
|
||||
return false;
|
||||
|
||||
// we can run the command
|
||||
target.GiveXP((uint)xp, null);
|
||||
return true;
|
||||
}
|
||||
|
||||
[CommandGroup("speed", RBACPermissions.CommandModifySpeed)]
|
||||
class ModifySpeed
|
||||
{
|
||||
[Command("", RBACPermissions.CommandModifySpeed)]
|
||||
static bool HandleModifySpeedCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
return HandleModifyASpeedCommand(args, handler);
|
||||
}
|
||||
|
||||
[Command("all", RBACPermissions.CommandModifySpeedAll)]
|
||||
static bool HandleModifyASpeedCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
float allSpeed;
|
||||
Player target = handler.getSelectedPlayerOrSelf();
|
||||
if (CheckModifySpeed(args, handler, target, out allSpeed, 0.1f, 50.0f))
|
||||
{
|
||||
NotifyModification(handler, target, CypherStrings.YouChangeAspeed, CypherStrings.YoursAspeedChanged, allSpeed);
|
||||
target.SetSpeedRate(UnitMoveType.Walk, allSpeed);
|
||||
target.SetSpeedRate(UnitMoveType.Run, allSpeed);
|
||||
target.SetSpeedRate(UnitMoveType.Swim, allSpeed);
|
||||
target.SetSpeedRate(UnitMoveType.Flight, allSpeed);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
[Command("swim", RBACPermissions.CommandModifySpeedSwim)]
|
||||
static bool HandleModifySwimCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
float swimSpeed;
|
||||
Player target = handler.getSelectedPlayerOrSelf();
|
||||
if (CheckModifySpeed(args, handler, target, out swimSpeed, 0.1f, 50.0f))
|
||||
{
|
||||
NotifyModification(handler, target, CypherStrings.YouChangeSwimSpeed, CypherStrings.YoursSwimSpeedChanged, swimSpeed);
|
||||
target.SetSpeedRate(UnitMoveType.Swim, swimSpeed);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
[Command("backwalk", RBACPermissions.CommandModifySpeedBackwalk)]
|
||||
static bool HandleModifyBWalkCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
float backSpeed;
|
||||
Player target = handler.getSelectedPlayerOrSelf();
|
||||
if (CheckModifySpeed(args, handler, target, out backSpeed, 0.1f, 50.0f))
|
||||
{
|
||||
NotifyModification(handler, target, CypherStrings.YouChangeBackSpeed, CypherStrings.YoursBackSpeedChanged, backSpeed);
|
||||
target.SetSpeedRate(UnitMoveType.RunBack, backSpeed);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
[Command("fly", RBACPermissions.CommandModifySpeedFly)]
|
||||
static bool HandleModifyFlyCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
float flySpeed;
|
||||
Player target = handler.getSelectedPlayerOrSelf();
|
||||
if (CheckModifySpeed(args, handler, target, out flySpeed, 0.1f, 50.0f, false))
|
||||
{
|
||||
NotifyModification(handler, target, CypherStrings.YouChangeFlySpeed, CypherStrings.YoursFlySpeedChanged, flySpeed);
|
||||
target.SetSpeedRate(UnitMoveType.Flight, flySpeed);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
[Command("walk", RBACPermissions.CommandModifySpeedWalk)]
|
||||
static bool HandleModifyWalkSpeedCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
float Speed;
|
||||
Player target = handler.getSelectedPlayerOrSelf();
|
||||
if (CheckModifySpeed(args, handler, target, out Speed, 0.1f, 50.0f))
|
||||
{
|
||||
NotifyModification(handler, target, CypherStrings.YouChangeSpeed, CypherStrings.YoursSpeedChanged, Speed);
|
||||
target.SetSpeedRate(UnitMoveType.Run, Speed);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
static void NotifyModification(CommandHandler handler, Unit target, CypherStrings resourceMessage, CypherStrings resourceReportMessage, params object[] args)
|
||||
{
|
||||
Player player = target.ToPlayer();
|
||||
if (player)
|
||||
{
|
||||
handler.SendSysMessage(resourceMessage, new object[] { handler.GetNameLink(player) }.Combine(args));
|
||||
if (handler.needReportToTarget(player))
|
||||
player.SendSysMessage(resourceReportMessage, new object[] { handler.GetNameLink() }.Combine(args));
|
||||
}
|
||||
}
|
||||
|
||||
static bool CheckModifyResources(StringArguments args, CommandHandler handler, Player target, out int res, out int resmax, byte multiplier = 1)
|
||||
{
|
||||
res = 0;
|
||||
resmax = 0;
|
||||
|
||||
if (args.Empty())
|
||||
return false;
|
||||
|
||||
res = args.NextInt32() * multiplier;
|
||||
resmax = args.NextInt32() * multiplier;
|
||||
|
||||
if (resmax == 0)
|
||||
resmax = res;
|
||||
|
||||
if (res < 1 || resmax < 1 || resmax < res)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.BadValue);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!target)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.NoCharSelected);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (handler.HasLowerSecurity(target, ObjectGuid.Empty))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool CheckModifySpeed(StringArguments args, CommandHandler handler, Unit target, out float speed, float minimumBound, float maximumBound, bool checkInFlight = true)
|
||||
{
|
||||
speed = 0f;
|
||||
if (args.Empty())
|
||||
return false;
|
||||
|
||||
speed = args.NextSingle();
|
||||
|
||||
if (speed > maximumBound || speed < minimumBound)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.BadValue);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!target)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.NoCharSelected);
|
||||
return false;
|
||||
}
|
||||
|
||||
Player player = target.ToPlayer();
|
||||
if (player)
|
||||
{
|
||||
// check online security
|
||||
if (handler.HasLowerSecurity(player, ObjectGuid.Empty))
|
||||
return false;
|
||||
|
||||
if (player.IsInFlight() && checkInFlight)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.CharInFlight, handler.GetNameLink(player));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,203 @@
|
||||
/*
|
||||
* Copyright (C) 2012-2017 CypherCore <http://github.com/CypherCore>
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using Framework.Constants;
|
||||
using Framework.IO;
|
||||
using Game.Entities;
|
||||
using Game.Spells;
|
||||
|
||||
namespace Game.Chat
|
||||
{
|
||||
[CommandGroup("pet", RBACPermissions.CommandPet)]
|
||||
class PetCommands
|
||||
{
|
||||
[Command("create", RBACPermissions.CommandPetCreate)]
|
||||
static bool HandlePetCreateCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
Player player = handler.GetSession().GetPlayer();
|
||||
Creature creatureTarget = handler.getSelectedCreature();
|
||||
|
||||
if (!creatureTarget || creatureTarget.IsPet() || creatureTarget.IsTypeId(TypeId.Player))
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.SelectCreature);
|
||||
return false;
|
||||
}
|
||||
|
||||
CreatureTemplate creatureTemplate = creatureTarget.GetCreatureTemplate();
|
||||
// Creatures with family CreatureFamily.None crashes the server
|
||||
if (creatureTemplate.Family == CreatureFamily.None)
|
||||
{
|
||||
handler.SendSysMessage("This creature cannot be tamed. (Family id: 0).");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!player.GetPetGUID().IsEmpty())
|
||||
{
|
||||
handler.SendSysMessage("You already have a pet");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Everything looks OK, create new pet
|
||||
Pet pet = new Pet(player, PetType.Hunter);
|
||||
if (!pet.CreateBaseAtCreature(creatureTarget))
|
||||
{
|
||||
handler.SendSysMessage("Error 1");
|
||||
return false;
|
||||
}
|
||||
|
||||
creatureTarget.setDeathState(DeathState.JustDied);
|
||||
creatureTarget.RemoveCorpse();
|
||||
creatureTarget.SetHealth(0); // just for nice GM-mode view
|
||||
|
||||
pet.SetGuidValue(UnitFields.CreatedBy, player.GetGUID());
|
||||
pet.SetUInt32Value(UnitFields.FactionTemplate, player.getFaction());
|
||||
|
||||
if (!pet.InitStatsForLevel(creatureTarget.getLevel()))
|
||||
{
|
||||
Log.outError(LogFilter.ChatSystem, "InitStatsForLevel() in EffectTameCreature failed! Pet deleted.");
|
||||
handler.SendSysMessage("Error 2");
|
||||
return false;
|
||||
}
|
||||
|
||||
// prepare visual effect for levelup
|
||||
pet.SetUInt32Value(UnitFields.Level, creatureTarget.getLevel() - 1);
|
||||
|
||||
pet.GetCharmInfo().SetPetNumber(Global.ObjectMgr.GeneratePetNumber(), true);
|
||||
// this enables pet details window (Shift+P)
|
||||
pet.InitPetCreateSpells();
|
||||
pet.SetFullHealth();
|
||||
|
||||
pet.GetMap().AddToMap(pet.ToCreature());
|
||||
|
||||
// visual effect for levelup
|
||||
pet.SetUInt32Value(UnitFields.Level, creatureTarget.getLevel());
|
||||
|
||||
player.SetMinion(pet, true);
|
||||
pet.SavePetToDB(PetSaveMode.AsCurrent);
|
||||
player.PetSpellInitialize();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("learn", RBACPermissions.CommandPetLearn)]
|
||||
static bool HandlePetLearnCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
if (args.Empty())
|
||||
return false;
|
||||
|
||||
Pet pet = GetSelectedPlayerPetOrOwn(handler);
|
||||
if (!pet)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.SelectPlayerOrPet);
|
||||
return false;
|
||||
}
|
||||
|
||||
uint spellId = handler.extractSpellIdFromLink(args);
|
||||
if (spellId == 0 || !Global.SpellMgr.HasSpellInfo(spellId))
|
||||
return false;
|
||||
|
||||
// Check if pet already has it
|
||||
if (pet.HasSpell(spellId))
|
||||
{
|
||||
handler.SendSysMessage("Pet already has spell: {0}", spellId);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check if spell is valid
|
||||
SpellInfo spellInfo = Global.SpellMgr.GetSpellInfo(spellId);
|
||||
if (spellInfo == null || !Global.SpellMgr.IsSpellValid(spellInfo))
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.CommandSpellBroken, spellId);
|
||||
return false;
|
||||
}
|
||||
|
||||
pet.learnSpell(spellId);
|
||||
|
||||
handler.SendSysMessage("Pet has learned spell {0}", spellId);
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("unlearn", RBACPermissions.CommandPetUnlearn)]
|
||||
static bool HandlePetUnlearnCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
if (args.Empty())
|
||||
return false;
|
||||
|
||||
Pet pet = GetSelectedPlayerPetOrOwn(handler);
|
||||
if (!pet)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.SelectPlayerOrPet);
|
||||
return false;
|
||||
}
|
||||
|
||||
uint spellId = handler.extractSpellIdFromLink(args);
|
||||
|
||||
if (pet.HasSpell(spellId))
|
||||
pet.removeSpell(spellId, false);
|
||||
else
|
||||
handler.SendSysMessage("Pet doesn't have that spell");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("level", RBACPermissions.CommandPetLevel)]
|
||||
static bool HandlePetLevelCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
Pet pet = GetSelectedPlayerPetOrOwn(handler);
|
||||
Player owner = pet ? pet.GetOwner() : null;
|
||||
if (!pet || !owner)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.SelectPlayerOrPet);
|
||||
return false;
|
||||
}
|
||||
|
||||
int level = args.NextInt32();
|
||||
if (level == 0)
|
||||
level = (int)(owner.getLevel() - pet.getLevel());
|
||||
if (level == 0 || level < -SharedConst.StrongMaxLevel || level > SharedConst.StrongMaxLevel)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.BadValue);
|
||||
return false;
|
||||
}
|
||||
|
||||
int newLevel = (int)pet.getLevel() + level;
|
||||
if (newLevel < 1)
|
||||
newLevel = 1;
|
||||
else if (newLevel > owner.getLevel())
|
||||
newLevel = (int)owner.getLevel();
|
||||
|
||||
pet.GivePetLevel(newLevel);
|
||||
return true;
|
||||
}
|
||||
|
||||
static Pet GetSelectedPlayerPetOrOwn(CommandHandler handler)
|
||||
{
|
||||
Unit target = handler.getSelectedUnit();
|
||||
if (target)
|
||||
{
|
||||
if (target.IsTypeId(TypeId.Player))
|
||||
return target.ToPlayer().GetPet();
|
||||
if (target.IsPet())
|
||||
return target.ToPet();
|
||||
return null;
|
||||
}
|
||||
|
||||
Player player = handler.GetSession().GetPlayer();
|
||||
return player ? player.GetPet() : null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,250 @@
|
||||
/*
|
||||
* Copyright (C) 2012-2017 CypherCore <http://github.com/CypherCore>
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using Framework.Constants;
|
||||
using Framework.IO;
|
||||
using Game.DataStorage;
|
||||
using Game.Entities;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace Game.Chat
|
||||
{
|
||||
[CommandGroup("quest", RBACPermissions.CommandQuest)]
|
||||
class QuestCommands
|
||||
{
|
||||
[Command("add", RBACPermissions.CommandQuestAdd)]
|
||||
static bool Add(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
Player player = handler.getSelectedPlayer();
|
||||
if (!player)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.NoCharSelected);
|
||||
return false;
|
||||
}
|
||||
|
||||
// .addquest #entry'
|
||||
// number or [name] Shift-click form |color|Hquest:quest_id:quest_level|h[name]|h|r
|
||||
string cId = handler.extractKeyFromLink(args, "Hquest");
|
||||
if (string.IsNullOrEmpty(cId))
|
||||
return false;
|
||||
|
||||
uint entry = uint.Parse(cId);
|
||||
|
||||
Quest quest = Global.ObjectMgr.GetQuestTemplate(entry);
|
||||
if (quest == null)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.CommandQuestNotfound, entry);
|
||||
return false;
|
||||
}
|
||||
|
||||
// check item starting quest (it can work incorrectly if added without item in inventory)
|
||||
var itc = Global.ObjectMgr.GetItemTemplates();
|
||||
var result = itc.Values.FirstOrDefault(p => p.GetStartQuest() == entry);
|
||||
|
||||
if (result != null)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.CommandQuestStartfromitem, entry, result.GetId());
|
||||
return false;
|
||||
}
|
||||
|
||||
// ok, normal (creature/GO starting) quest
|
||||
if (player.CanAddQuest(quest, true))
|
||||
player.AddQuestAndCheckCompletion(quest, null);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("complete", RBACPermissions.CommandQuestComplete)]
|
||||
static bool Complete(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
Player player = handler.getSelectedPlayer();
|
||||
if (!player)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.NoCharSelected);
|
||||
return false;
|
||||
}
|
||||
|
||||
// .quest complete #entry
|
||||
// number or [name] Shift-click form |color|Hquest:quest_id:quest_level|h[name]|h|r
|
||||
string cId = handler.extractKeyFromLink(args, "Hquest");
|
||||
if (string.IsNullOrEmpty(cId))
|
||||
return false;
|
||||
|
||||
uint entry = uint.Parse(cId);
|
||||
|
||||
Quest quest = Global.ObjectMgr.GetQuestTemplate(entry);
|
||||
|
||||
// If player doesn't have the quest
|
||||
if (quest == null || player.GetQuestStatus(entry) == QuestStatus.None)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.CommandQuestNotfound, entry);
|
||||
return false;
|
||||
}
|
||||
|
||||
for (int i = 0; i < quest.Objectives.Count; ++i)
|
||||
{
|
||||
QuestObjective obj = quest.Objectives[i];
|
||||
|
||||
switch (obj.Type)
|
||||
{
|
||||
case QuestObjectiveType.Item:
|
||||
{
|
||||
uint curItemCount = player.GetItemCount((uint)obj.ObjectID, true);
|
||||
List<ItemPosCount> dest = new List<ItemPosCount>();
|
||||
InventoryResult msg = player.CanStoreNewItem(ItemConst.NullBag, ItemConst.NullSlot, dest, (uint)obj.ObjectID, (uint)(obj.Amount - curItemCount));
|
||||
if (msg == InventoryResult.Ok)
|
||||
{
|
||||
Item item = player.StoreNewItem(dest, (uint)obj.ObjectID, true);
|
||||
player.SendNewItem(item, (uint)(obj.Amount - curItemCount), true, false);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case QuestObjectiveType.Monster:
|
||||
{
|
||||
CreatureTemplate creatureInfo = Global.ObjectMgr.GetCreatureTemplate((uint)obj.ObjectID);
|
||||
if (creatureInfo != null)
|
||||
for (int z = 0; z < obj.Amount; ++z)
|
||||
player.KilledMonster(creatureInfo, ObjectGuid.Empty);
|
||||
break;
|
||||
}
|
||||
case QuestObjectiveType.GameObject:
|
||||
{
|
||||
for (int z = 0; z < obj.Amount; ++z)
|
||||
player.KillCreditGO((uint)obj.ObjectID);
|
||||
break;
|
||||
}
|
||||
case QuestObjectiveType.MinReputation:
|
||||
{
|
||||
int curRep = player.GetReputationMgr().GetReputation((uint)obj.ObjectID);
|
||||
if (curRep < obj.Amount)
|
||||
{
|
||||
FactionRecord factionEntry = CliDB.FactionStorage.LookupByKey(obj.ObjectID);
|
||||
if (factionEntry != null)
|
||||
player.GetReputationMgr().SetReputation(factionEntry, obj.Amount);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case QuestObjectiveType.MaxReputation:
|
||||
{
|
||||
int curRep = player.GetReputationMgr().GetReputation((uint)obj.ObjectID);
|
||||
if (curRep > obj.Amount)
|
||||
{
|
||||
FactionRecord factionEntry = CliDB.FactionStorage.LookupByKey(obj.ObjectID);
|
||||
if (factionEntry != null)
|
||||
player.GetReputationMgr().SetReputation(factionEntry, obj.Amount);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case QuestObjectiveType.Money:
|
||||
{
|
||||
player.ModifyMoney(obj.Amount);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
player.CompleteQuest(entry);
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("remove", RBACPermissions.CommandQuestRemove)]
|
||||
static bool Remove(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
Player player = handler.getSelectedPlayer();
|
||||
if (!player)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.NoCharSelected);
|
||||
return false;
|
||||
}
|
||||
|
||||
// .removequest #entry'
|
||||
// number or [name] Shift-click form |color|Hquest:quest_id:quest_level|h[name]|h|r
|
||||
string cId = handler.extractKeyFromLink(args, "Hquest");
|
||||
if (string.IsNullOrEmpty(cId))
|
||||
return false;
|
||||
|
||||
uint entry = uint.Parse(cId);
|
||||
|
||||
Quest quest = Global.ObjectMgr.GetQuestTemplate(entry);
|
||||
if (quest == null)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.CommandQuestNotfound, entry);
|
||||
return false;
|
||||
}
|
||||
|
||||
// remove all quest entries for 'entry' from quest log
|
||||
for (byte slot = 0; slot < SharedConst.MaxQuestLogSize; ++slot)
|
||||
{
|
||||
uint logQuest = player.GetQuestSlotQuestId(slot);
|
||||
if (logQuest == entry)
|
||||
{
|
||||
player.SetQuestSlot(slot, 0);
|
||||
|
||||
// we ignore unequippable quest items in this case, its' still be equipped
|
||||
player.TakeQuestSourceItem(logQuest, false);
|
||||
|
||||
if (quest.HasFlag(QuestFlags.Pvp))
|
||||
{
|
||||
player.pvpInfo.IsHostile = player.pvpInfo.IsInHostileArea || player.HasPvPForcingQuest();
|
||||
player.UpdatePvPState();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
player.RemoveActiveQuest(entry, false);
|
||||
player.RemoveRewardedQuest(entry);
|
||||
|
||||
Global.ScriptMgr.OnQuestStatusChange(player, entry);
|
||||
|
||||
handler.SendSysMessage(CypherStrings.CommandQuestRemoved);
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("reward", RBACPermissions.CommandQuestReward)]
|
||||
static bool Reward(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
Player player = handler.getSelectedPlayer();
|
||||
if (!player)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.NoCharSelected);
|
||||
return false;
|
||||
}
|
||||
|
||||
// .quest reward #entry
|
||||
// number or [name] Shift-click form |color|Hquest:quest_id:quest_level|h[name]|h|r
|
||||
string cId = handler.extractKeyFromLink(args, "Hquest");
|
||||
if (string.IsNullOrEmpty(cId))
|
||||
return false;
|
||||
|
||||
uint entry = uint.Parse(cId);
|
||||
|
||||
Quest quest = Global.ObjectMgr.GetQuestTemplate(entry);
|
||||
|
||||
// If player doesn't have the quest
|
||||
if (quest == null || player.GetQuestStatus(entry) != QuestStatus.Complete)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.CommandQuestNotfound, entry);
|
||||
return false;
|
||||
}
|
||||
|
||||
player.RewardQuest(quest, 0, player);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,317 @@
|
||||
/*
|
||||
* Copyright (C) 2012-2017 CypherCore <http://github.com/CypherCore>
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using Framework.Constants;
|
||||
using Framework.IO;
|
||||
using Game.Accounts;
|
||||
using Game.Entities;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Game.Chat.Commands
|
||||
{
|
||||
[CommandGroup("rbac", RBACPermissions.CommandRbac, true)]
|
||||
class RbacComands
|
||||
{
|
||||
[Command("list", RBACPermissions.CommandRbacList, true)]
|
||||
static bool HandleRBACListPermissionsCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
uint id = args.NextUInt32();
|
||||
|
||||
if (id == 0)
|
||||
{
|
||||
var permissions = Global.AccountMgr.GetRBACPermissionList();
|
||||
handler.SendSysMessage(CypherStrings.RbacListPermissionsHeader);
|
||||
foreach (var permission in permissions.Values)
|
||||
handler.SendSysMessage(CypherStrings.RbacListElement, permission.GetId(), permission.GetName());
|
||||
}
|
||||
else
|
||||
{
|
||||
RBACPermission permission = Global.AccountMgr.GetRBACPermission(id);
|
||||
if (permission == null)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.RbacWrongParameterId, id);
|
||||
return false;
|
||||
}
|
||||
|
||||
handler.SendSysMessage(CypherStrings.RbacListPermissionsHeader);
|
||||
handler.SendSysMessage(CypherStrings.RbacListElement, permission.GetId(), permission.GetName());
|
||||
handler.SendSysMessage(CypherStrings.RbacListPermsLinkedHeader);
|
||||
var permissions = permission.GetLinkedPermissions();
|
||||
foreach (var permissionId in permissions)
|
||||
{
|
||||
RBACPermission rbacPermission = Global.AccountMgr.GetRBACPermission(permissionId);
|
||||
if (rbacPermission != null)
|
||||
handler.SendSysMessage(CypherStrings.RbacListElement, rbacPermission.GetId(), rbacPermission.GetName());
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
[CommandGroup("account", RBACPermissions.CommandRbacAcc, true)]
|
||||
class RbacAccountCommands
|
||||
{
|
||||
[Command("grant", RBACPermissions.CommandRbacAccPermGrant, true)]
|
||||
static bool HandleRBACPermGrantCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
RBACCommandData command = ReadParams(args, handler);
|
||||
if (command == null)
|
||||
return false;
|
||||
|
||||
RBACCommandResult result = command.rbac.GrantPermission(command.id, command.realmId);
|
||||
RBACPermission permission = Global.AccountMgr.GetRBACPermission(command.id);
|
||||
|
||||
switch (result)
|
||||
{
|
||||
case RBACCommandResult.CantAddAlreadyAdded:
|
||||
handler.SendSysMessage(CypherStrings.RbacPermGrantedInList, command.id, permission.GetName(),
|
||||
command.realmId, command.rbac.GetId(), command.rbac.GetName());
|
||||
break;
|
||||
case RBACCommandResult.InDeniedList:
|
||||
handler.SendSysMessage(CypherStrings.RbacPermGrantedInDeniedList, command.id, permission.GetName(),
|
||||
command.realmId, command.rbac.GetId(), command.rbac.GetName());
|
||||
break;
|
||||
case RBACCommandResult.OK:
|
||||
handler.SendSysMessage(CypherStrings.RbacPermGranted, command.id, permission.GetName(),
|
||||
command.realmId, command.rbac.GetId(), command.rbac.GetName());
|
||||
break;
|
||||
case RBACCommandResult.IdDoesNotExists:
|
||||
handler.SendSysMessage(CypherStrings.RbacWrongParameterId, command.id);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("deny", RBACPermissions.CommandRbacAccPermDeny, true)]
|
||||
static bool HandleRBACPermDenyCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
RBACCommandData command = ReadParams(args, handler);
|
||||
|
||||
if (command == null)
|
||||
return false;
|
||||
|
||||
RBACCommandResult result = command.rbac.DenyPermission(command.id, command.realmId);
|
||||
RBACPermission permission = Global.AccountMgr.GetRBACPermission(command.id);
|
||||
|
||||
switch (result)
|
||||
{
|
||||
case RBACCommandResult.CantAddAlreadyAdded:
|
||||
handler.SendSysMessage(CypherStrings.RbacPermDeniedInList, command.id, permission.GetName(),
|
||||
command.realmId, command.rbac.GetId(), command.rbac.GetName());
|
||||
break;
|
||||
case RBACCommandResult.InGrantedList:
|
||||
handler.SendSysMessage(CypherStrings.RbacPermDeniedInGrantedList, command.id, permission.GetName(),
|
||||
command.realmId, command.rbac.GetId(), command.rbac.GetName());
|
||||
break;
|
||||
case RBACCommandResult.OK:
|
||||
handler.SendSysMessage(CypherStrings.RbacPermDenied, command.id, permission.GetName(),
|
||||
command.realmId, command.rbac.GetId(), command.rbac.GetName());
|
||||
break;
|
||||
case RBACCommandResult.IdDoesNotExists:
|
||||
handler.SendSysMessage(CypherStrings.RbacWrongParameterId, command.id);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("revoke", RBACPermissions.CommandRbacAccPermRevoke, true)]
|
||||
static bool HandleRBACPermRevokeCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
RBACCommandData command = ReadParams(args, handler);
|
||||
|
||||
if (command == null)
|
||||
return false;
|
||||
|
||||
RBACCommandResult result = command.rbac.RevokePermission(command.id, command.realmId);
|
||||
RBACPermission permission = Global.AccountMgr.GetRBACPermission(command.id);
|
||||
|
||||
switch (result)
|
||||
{
|
||||
case RBACCommandResult.CantRevokeNotInList:
|
||||
handler.SendSysMessage(CypherStrings.RbacPermRevokedNotInList, command.id, permission.GetName(),
|
||||
command.realmId, command.rbac.GetId(), command.rbac.GetName());
|
||||
break;
|
||||
case RBACCommandResult.OK:
|
||||
handler.SendSysMessage(CypherStrings.RbacPermRevoked, command.id, permission.GetName(),
|
||||
command.realmId, command.rbac.GetId(), command.rbac.GetName());
|
||||
break;
|
||||
case RBACCommandResult.IdDoesNotExists:
|
||||
handler.SendSysMessage(CypherStrings.RbacWrongParameterId, command.id);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("list", RBACPermissions.CommandRbacAccPermList, true)]
|
||||
static bool HandleRBACPermListCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
RBACCommandData command = ReadParams(args, handler, false);
|
||||
|
||||
if (command == null)
|
||||
return false;
|
||||
|
||||
handler.SendSysMessage(CypherStrings.RbacListHeaderGranted, command.rbac.GetId(), command.rbac.GetName());
|
||||
var granted = command.rbac.GetGrantedPermissions();
|
||||
if (granted.Empty())
|
||||
handler.SendSysMessage(CypherStrings.RbacListEmpty);
|
||||
else
|
||||
{
|
||||
foreach (var id in granted)
|
||||
{
|
||||
RBACPermission permission = Global.AccountMgr.GetRBACPermission(id);
|
||||
handler.SendSysMessage(CypherStrings.RbacListElement, permission.GetId(), permission.GetName());
|
||||
}
|
||||
}
|
||||
|
||||
handler.SendSysMessage(CypherStrings.RbacListHeaderDenied, command.rbac.GetId(), command.rbac.GetName());
|
||||
var denied = command.rbac.GetDeniedPermissions();
|
||||
if (denied.Empty())
|
||||
handler.SendSysMessage(CypherStrings.RbacListEmpty);
|
||||
else
|
||||
{
|
||||
foreach (var id in denied)
|
||||
{
|
||||
RBACPermission permission = Global.AccountMgr.GetRBACPermission(id);
|
||||
handler.SendSysMessage(CypherStrings.RbacListElement, permission.GetId(), permission.GetName());
|
||||
}
|
||||
}
|
||||
handler.SendSysMessage(CypherStrings.RbacListHeaderBySecLevel, command.rbac.GetId(), command.rbac.GetName(), command.rbac.GetSecurityLevel());
|
||||
var defaultPermissions = Global.AccountMgr.GetRBACDefaultPermissions(command.rbac.GetSecurityLevel());
|
||||
if (defaultPermissions.Empty())
|
||||
handler.SendSysMessage(CypherStrings.RbacListEmpty);
|
||||
else
|
||||
{
|
||||
foreach (var id in defaultPermissions)
|
||||
{
|
||||
RBACPermission permission = Global.AccountMgr.GetRBACPermission(id);
|
||||
handler.SendSysMessage(CypherStrings.RbacListElement, permission.GetId(), permission.GetName());
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
static RBACCommandData ReadParams(StringArguments args, CommandHandler handler, bool checkParams = true)
|
||||
{
|
||||
if (args.Empty())
|
||||
return null;
|
||||
|
||||
string param1 = args.NextString();
|
||||
string param2 = args.NextString();
|
||||
string param3 = args.NextString();
|
||||
|
||||
int realmId = -1;
|
||||
uint accountId = 0;
|
||||
string accountName;
|
||||
uint id = 0;
|
||||
RBACCommandData data;
|
||||
RBACData rdata = null;
|
||||
bool useSelectedPlayer = false;
|
||||
|
||||
if (checkParams)
|
||||
{
|
||||
if (string.IsNullOrEmpty(param3))
|
||||
{
|
||||
if (!string.IsNullOrEmpty(param2))
|
||||
realmId = int.Parse(param2);
|
||||
|
||||
if (!string.IsNullOrEmpty(param1))
|
||||
id = uint.Parse(param1);
|
||||
|
||||
useSelectedPlayer = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
id = uint.Parse(param2);
|
||||
realmId = int.Parse(param3);
|
||||
}
|
||||
|
||||
if (id == 0)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.RbacWrongParameterId, id);
|
||||
return null;
|
||||
}
|
||||
|
||||
if (realmId < -1 || realmId == 0)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.RbacWrongParameterRealm, realmId);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else if (string.IsNullOrEmpty(param1))
|
||||
useSelectedPlayer = true;
|
||||
|
||||
if (useSelectedPlayer)
|
||||
{
|
||||
Player player = handler.getSelectedPlayer();
|
||||
if (!player)
|
||||
return null;
|
||||
|
||||
rdata = player.GetSession().GetRBACData();
|
||||
accountId = rdata.GetId();
|
||||
Global.AccountMgr.GetName(accountId, out accountName);
|
||||
}
|
||||
else
|
||||
{
|
||||
accountName = param1;
|
||||
accountId = Global.AccountMgr.GetId(accountName);
|
||||
|
||||
if (accountId == 0)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.AccountNotExist, accountName);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
if (checkParams && handler.HasLowerSecurityAccount(null, accountId, true))
|
||||
return null;
|
||||
|
||||
data = new RBACCommandData();
|
||||
|
||||
if (rdata == null)
|
||||
{
|
||||
data.rbac = new RBACData(accountId, accountName, (int)Global.WorldMgr.GetRealm().Id.Realm, (byte)Global.AccountMgr.GetSecurity(accountId, (int)Global.WorldMgr.GetRealm().Id.Realm));
|
||||
data.rbac.LoadFromDB();
|
||||
data.needDelete = true;
|
||||
}
|
||||
else
|
||||
data.rbac = rdata;
|
||||
|
||||
data.id = id;
|
||||
data.realmId = realmId;
|
||||
return data;
|
||||
}
|
||||
|
||||
class RBACCommandData
|
||||
{
|
||||
public uint id;
|
||||
public int realmId;
|
||||
public RBACData rbac;
|
||||
public bool needDelete;
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,282 @@
|
||||
/*
|
||||
* Copyright (C) 2012-2017 CypherCore <http://github.com/CypherCore>
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using Framework.Constants;
|
||||
using Framework.Database;
|
||||
using Framework.IO;
|
||||
using Game.Achievements;
|
||||
using Game.DataStorage;
|
||||
using Game.Entities;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Game.Chat
|
||||
{
|
||||
[CommandGroup("reset", RBACPermissions.CommandReset, true)]
|
||||
class ResetCommands
|
||||
{
|
||||
[Command("achievements", RBACPermissions.CommandResetAchievements, true)]
|
||||
static bool HandleResetAchievementsCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
Player target;
|
||||
ObjectGuid targetGuid;
|
||||
if (!handler.extractPlayerTarget(args, out target, out targetGuid))
|
||||
return false;
|
||||
|
||||
if (target)
|
||||
target.ResetAchievements();
|
||||
else
|
||||
PlayerAchievementMgr.DeleteFromDB(targetGuid);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("honor", RBACPermissions.CommandResetHonor, true)]
|
||||
static bool HandleResetHonorCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
Player target;
|
||||
if (!handler.extractPlayerTarget(args, out target))
|
||||
return false;
|
||||
|
||||
target.SetUInt32Value(PlayerFields.Kills, 0);
|
||||
target.SetUInt32Value(PlayerFields.LifetimeHonorableKills, 0);
|
||||
target.UpdateCriteria(CriteriaTypes.EarnHonorableKill);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool HandleResetStatsOrLevelHelper(Player player)
|
||||
{
|
||||
ChrClassesRecord classEntry = CliDB.ChrClassesStorage.LookupByKey(player.GetClass());
|
||||
if (classEntry == null)
|
||||
{
|
||||
Log.outError(LogFilter.Server, "Class {0} not found in DBC (Wrong DBC files?)", player.GetClass());
|
||||
return false;
|
||||
}
|
||||
|
||||
PowerType powerType = classEntry.PowerType;
|
||||
|
||||
// reset m_form if no aura
|
||||
if (!player.HasAuraType(AuraType.ModShapeshift))
|
||||
player.SetShapeshiftForm(ShapeShiftForm.None);
|
||||
|
||||
player.setFactionForRace(player.GetRace());
|
||||
player.SetUInt32Value(UnitFields.DisplayPower, (uint)powerType);
|
||||
|
||||
// reset only if player not in some form;
|
||||
if (player.GetShapeshiftForm() == ShapeShiftForm.None)
|
||||
player.InitDisplayIds();
|
||||
|
||||
player.SetByteValue(UnitFields.Bytes2, UnitBytes2Offsets.PvpFlag, (byte)UnitBytes2Flags.PvP);
|
||||
|
||||
player.SetUInt32Value(UnitFields.Flags, (uint)UnitFlags.PvpAttackable);
|
||||
|
||||
//-1 is default value
|
||||
player.SetUInt32Value(PlayerFields.WatchedFactionIndex, 0xFFFFFFFF);
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("level", RBACPermissions.CommandResetLevel, true)]
|
||||
static bool HandleResetLevelCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
Player target;
|
||||
if (!handler.extractPlayerTarget(args, out target))
|
||||
return false;
|
||||
|
||||
if (!HandleResetStatsOrLevelHelper(target))
|
||||
return false;
|
||||
|
||||
byte oldLevel = (byte)target.getLevel();
|
||||
|
||||
// set starting level
|
||||
uint startLevel = (uint)(target.GetClass() != Class.Deathknight ? WorldConfig.GetIntValue(WorldCfg.StartPlayerLevel) : WorldConfig.GetIntValue(WorldCfg.StartDeathKnightPlayerLevel));
|
||||
|
||||
target._ApplyAllLevelScaleItemMods(false);
|
||||
target.SetLevel(startLevel);
|
||||
target.InitRunes();
|
||||
target.InitStatsForLevel(true);
|
||||
target.InitTaxiNodesForLevel();
|
||||
target.InitTalentForLevel();
|
||||
target.SetUInt32Value(PlayerFields.Xp, 0);
|
||||
|
||||
target._ApplyAllLevelScaleItemMods(true);
|
||||
|
||||
// reset level for pet
|
||||
Pet pet = target.GetPet();
|
||||
if (pet)
|
||||
pet.SynchronizeLevelWithOwner();
|
||||
|
||||
Global.ScriptMgr.OnPlayerLevelChanged(target, oldLevel);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("spells", RBACPermissions.CommandResetSpells, true)]
|
||||
static bool HandleResetSpellsCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
Player target;
|
||||
ObjectGuid targetGuid;
|
||||
string targetName;
|
||||
if (!handler.extractPlayerTarget(args, out target, out targetGuid, out targetName))
|
||||
return false;
|
||||
|
||||
if (target)
|
||||
{
|
||||
target.ResetSpells();
|
||||
|
||||
target.SendSysMessage(CypherStrings.ResetSpells);
|
||||
if (handler.GetSession() == null || handler.GetSession().GetPlayer() != target)
|
||||
handler.SendSysMessage(CypherStrings.ResetSpellsOnline, handler.GetNameLink(target));
|
||||
}
|
||||
else
|
||||
{
|
||||
PreparedStatement stmt = DB.Characters.GetPreparedStatement(CharStatements.UPD_ADD_AT_LOGIN_FLAG);
|
||||
stmt.AddValue(0, (ushort)AtLoginFlags.ResetSpells);
|
||||
stmt.AddValue(1, targetGuid.GetCounter());
|
||||
DB.Characters.Execute(stmt);
|
||||
|
||||
handler.SendSysMessage(CypherStrings.ResetSpellsOffline, targetName);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("stats", RBACPermissions.CommandResetStats, true)]
|
||||
static bool HandleResetStatsCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
Player target;
|
||||
if (!handler.extractPlayerTarget(args, out target))
|
||||
return false;
|
||||
|
||||
if (!HandleResetStatsOrLevelHelper(target))
|
||||
return false;
|
||||
|
||||
target.InitRunes();
|
||||
target.InitStatsForLevel(true);
|
||||
target.InitTaxiNodesForLevel();
|
||||
target.InitTalentForLevel();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("talents", RBACPermissions.CommandResetTalents, true)]
|
||||
static bool HandleResetTalentsCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
Player target;
|
||||
ObjectGuid targetGuid;
|
||||
string targetName;
|
||||
|
||||
if (!handler.extractPlayerTarget(args, out target, out targetGuid, out targetName))
|
||||
{
|
||||
/* TODO: 6.x remove/update pet talents
|
||||
// Try reset talents as Hunter Pet
|
||||
Creature* creature = handler.getSelectedCreature();
|
||||
if (!*args && creature && creature.IsPet())
|
||||
{
|
||||
Unit* owner = creature.GetOwner();
|
||||
if (owner && owner.GetTypeId() == TYPEID_PLAYER && creature.ToPet().IsPermanentPetFor(owner.ToPlayer()))
|
||||
{
|
||||
creature.ToPet().resetTalents();
|
||||
owner.ToPlayer().SendTalentsInfoData(true);
|
||||
|
||||
ChatHandler(owner.ToPlayer().GetSession()).SendSysMessage(LANG_RESET_PET_TALENTS);
|
||||
if (!handler.GetSession() || handler.GetSession().GetPlayer() != owner.ToPlayer())
|
||||
handler.PSendSysMessage(LANG_RESET_PET_TALENTS_ONLINE, handler.GetNameLink(owner.ToPlayer()).c_str());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
*/
|
||||
|
||||
handler.SendSysMessage(CypherStrings.NoCharSelected);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (target)
|
||||
{
|
||||
target.ResetTalents(true);
|
||||
target.ResetTalentSpecialization();
|
||||
target.SendTalentsInfoData();
|
||||
target.SendSysMessage(CypherStrings.ResetTalents);
|
||||
if (handler.GetSession() == null || handler.GetSession().GetPlayer() != target)
|
||||
handler.SendSysMessage(CypherStrings.ResetTalentsOnline, handler.GetNameLink(target));
|
||||
|
||||
/* TODO: 6.x remove/update pet talents
|
||||
Pet* pet = target.GetPet();
|
||||
Pet.resetTalentsForAllPetsOf(target, pet);
|
||||
if (pet)
|
||||
target.SendTalentsInfoData(true);
|
||||
*/
|
||||
return true;
|
||||
}
|
||||
else if (!targetGuid.IsEmpty())
|
||||
{
|
||||
PreparedStatement stmt = DB.Characters.GetPreparedStatement(CharStatements.UPD_ADD_AT_LOGIN_FLAG);
|
||||
stmt.AddValue(0, (ushort)(AtLoginFlags.None | AtLoginFlags.ResetPetTalents));
|
||||
stmt.AddValue(1, targetGuid.GetCounter());
|
||||
DB.Characters.Execute(stmt);
|
||||
|
||||
string nameLink = handler.playerLink(targetName);
|
||||
handler.SendSysMessage(CypherStrings.ResetTalentsOffline, nameLink);
|
||||
return true;
|
||||
}
|
||||
|
||||
handler.SendSysMessage(CypherStrings.NoCharSelected);
|
||||
return false;
|
||||
}
|
||||
|
||||
[Command("all", RBACPermissions.CommandResetAll, true)]
|
||||
static bool HandleResetAllCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
if (args.Empty())
|
||||
return false;
|
||||
|
||||
string caseName = args.NextString();
|
||||
|
||||
AtLoginFlags atLogin;
|
||||
|
||||
// Command specially created as single command to prevent using short case names
|
||||
if (caseName == "spells")
|
||||
{
|
||||
atLogin = AtLoginFlags.ResetSpells;
|
||||
Global.WorldMgr.SendWorldText(CypherStrings.ResetallSpells);
|
||||
if (handler.GetSession() == null)
|
||||
handler.SendSysMessage(CypherStrings.ResetallSpells);
|
||||
}
|
||||
else if (caseName == "talents")
|
||||
{
|
||||
atLogin = AtLoginFlags.ResetTalents | AtLoginFlags.ResetPetTalents;
|
||||
Global.WorldMgr.SendWorldText(CypherStrings.ResetallTalents);
|
||||
if (handler.GetSession() == null)
|
||||
handler.SendSysMessage(CypherStrings.ResetallTalents);
|
||||
}
|
||||
else
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.ResetallUnknownCase, args);
|
||||
return false;
|
||||
}
|
||||
|
||||
PreparedStatement stmt = DB.Characters.GetPreparedStatement(CharStatements.UPD_ALL_AT_LOGIN_FLAGS);
|
||||
stmt.AddValue(0, (ushort)atLogin);
|
||||
DB.Characters.Execute(stmt);
|
||||
|
||||
var plist = Global.ObjAccessor.GetPlayers();
|
||||
foreach (var player in plist)
|
||||
player.SetAtLoginFlag(atLogin);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
/*
|
||||
* Copyright (C) 2012-2017 CypherCore <http://github.com/CypherCore>
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using Framework.Constants;
|
||||
using Framework.IO;
|
||||
using Game.DataStorage;
|
||||
using Game.Entities;
|
||||
using System;
|
||||
|
||||
namespace Game.Chat
|
||||
{
|
||||
[CommandGroup("scene", RBACPermissions.CommandScene)]
|
||||
class SceneCommands
|
||||
{
|
||||
[Command("cancel", RBACPermissions.CommandSceneCancel)]
|
||||
static bool HandleCancelSceneCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
if (args.Empty())
|
||||
return false;
|
||||
|
||||
Player target = handler.getSelectedPlayerOrSelf();
|
||||
if (!target)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.PlayerNotFound);
|
||||
return false;
|
||||
}
|
||||
|
||||
uint id = args.NextUInt32();
|
||||
|
||||
if (!CliDB.SceneScriptPackageStorage.HasRecord(id))
|
||||
return false;
|
||||
|
||||
target.GetSceneMgr().CancelSceneByPackageId(id);
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("debug", RBACPermissions.CommandSceneDedug)]
|
||||
static bool HandleDebugSceneCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
Player player = handler.GetSession().GetPlayer();
|
||||
if (player)
|
||||
{
|
||||
player.GetSceneMgr().ToggleDebugSceneMode();
|
||||
handler.SendSysMessage(player.GetSceneMgr().IsInDebugSceneMode() ? CypherStrings.CommandSceneDebugOn : CypherStrings.CommandSceneDebugOff);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("play", RBACPermissions.CommandScenePlay)]
|
||||
static bool HandlePlaySceneCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
if (args.Empty())
|
||||
return false;
|
||||
|
||||
string sceneIdStr = args.NextString();
|
||||
if (sceneIdStr.IsEmpty())
|
||||
return false;
|
||||
|
||||
uint sceneId = uint.Parse(sceneIdStr);
|
||||
Player target = handler.getSelectedPlayerOrSelf();
|
||||
if (!target)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.PlayerNotFound);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (Global.ObjectMgr.GetSceneTemplate(sceneId) == null)
|
||||
return false;
|
||||
|
||||
target.GetSceneMgr().PlayScene(sceneId);
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("playpackage", RBACPermissions.CommandScenePlayPackage)]
|
||||
static bool HandlePlayScenePackageCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
if (args.Empty())
|
||||
return false;
|
||||
|
||||
string scenePackageIdStr = args.NextString();
|
||||
string flagsStr = args.NextString("");
|
||||
|
||||
if (scenePackageIdStr.IsEmpty())
|
||||
return false;
|
||||
|
||||
uint scenePackageId = uint.Parse(scenePackageIdStr);
|
||||
uint flags = !flagsStr.IsEmpty() ? uint.Parse(flagsStr) : (uint)SceneFlags.Unk16;
|
||||
Player target = handler.getSelectedPlayerOrSelf();
|
||||
|
||||
if (!target)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.PlayerNotFound);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!CliDB.SceneScriptPackageStorage.HasRecord(scenePackageId))
|
||||
return false;
|
||||
|
||||
target.GetSceneMgr().PlaySceneByPackageId(scenePackageId, (SceneFlags)flags);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,248 @@
|
||||
/*
|
||||
* Copyright (C) 2012-2017 CypherCore <http://github.com/CypherCore>
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using Framework.Constants;
|
||||
using Framework.Database;
|
||||
using Framework.IO;
|
||||
using Game.Entities;
|
||||
using Game.Mails;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Game.Chat.Commands
|
||||
{
|
||||
[CommandGroup("send", RBACPermissions.CommandSend, false)]
|
||||
class SendCommands
|
||||
{
|
||||
[Command("mail", RBACPermissions.CommandSendMail, true)]
|
||||
static bool HandleSendMailCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
// format: name "subject text" "mail text"
|
||||
Player target;
|
||||
ObjectGuid targetGuid;
|
||||
string targetName;
|
||||
if (!handler.extractPlayerTarget(args, out target, out targetGuid, out targetName))
|
||||
return false;
|
||||
|
||||
string tail1 = args.NextString("");
|
||||
if (string.IsNullOrEmpty(tail1))
|
||||
return false;
|
||||
|
||||
string subject = handler.extractQuotedArg(tail1);
|
||||
if (string.IsNullOrEmpty(subject))
|
||||
return false;
|
||||
|
||||
string tail2 = args.NextString("");
|
||||
if (string.IsNullOrEmpty(tail2))
|
||||
return false;
|
||||
|
||||
string text = handler.extractQuotedArg(tail2);
|
||||
if (string.IsNullOrEmpty(text))
|
||||
return false;
|
||||
|
||||
// from console show not existed sender
|
||||
MailSender sender = new MailSender(MailMessageType.Normal, handler.GetSession() ? handler.GetSession().GetPlayer().GetGUID().GetCounter() : 0, MailStationery.Gm);
|
||||
|
||||
/// @todo Fix poor design
|
||||
SQLTransaction trans = new SQLTransaction();
|
||||
new MailDraft(subject, text)
|
||||
.SendMailTo(trans, new MailReceiver(target, targetGuid.GetCounter()), sender);
|
||||
|
||||
DB.Characters.CommitTransaction(trans);
|
||||
|
||||
string nameLink = handler.playerLink(targetName);
|
||||
handler.SendSysMessage(CypherStrings.MailSent, nameLink);
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("items", RBACPermissions.CommandSendItems, true)]
|
||||
static bool HandleSendItemsCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
// format: name "subject text" "mail text" item1[:count1] item2[:count2] ... item12[:count12]
|
||||
Player receiver;
|
||||
ObjectGuid receiverGuid;
|
||||
string receiverName;
|
||||
if (!handler.extractPlayerTarget(args, out receiver, out receiverGuid, out receiverName))
|
||||
return false;
|
||||
|
||||
string tail1 = args.NextString("");
|
||||
if (string.IsNullOrEmpty(tail1))
|
||||
return false;
|
||||
|
||||
string subject = handler.extractQuotedArg(tail1);
|
||||
if (string.IsNullOrEmpty(subject))
|
||||
return false;
|
||||
|
||||
string tail2 = args.NextString("");
|
||||
if (string.IsNullOrEmpty(tail2))
|
||||
return false;
|
||||
|
||||
string text = handler.extractQuotedArg(tail2);
|
||||
if (string.IsNullOrEmpty(text))
|
||||
return false;
|
||||
|
||||
// extract items
|
||||
List<KeyValuePair<uint, uint>> items = new List<KeyValuePair<uint, uint>>();
|
||||
|
||||
// get all tail string
|
||||
StringArguments tail = new StringArguments(args.NextString(""));
|
||||
|
||||
// get from tail next item str
|
||||
StringArguments itemStr;
|
||||
while ((itemStr = new StringArguments(tail.NextString(" "))) != null)
|
||||
{
|
||||
// parse item str
|
||||
string itemIdStr = itemStr.NextString(":");
|
||||
string itemCountStr = itemStr.NextString(" ");
|
||||
|
||||
uint itemId = uint.Parse(itemIdStr);
|
||||
if (itemId == 0)
|
||||
return false;
|
||||
|
||||
ItemTemplate item_proto = Global.ObjectMgr.GetItemTemplate(itemId);
|
||||
if (item_proto == null)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.CommandItemidinvalid, itemId);
|
||||
return false;
|
||||
}
|
||||
|
||||
uint itemCount = !string.IsNullOrEmpty(itemCountStr) ? uint.Parse(itemCountStr) : 1;
|
||||
if (itemCount < 1 || (item_proto.GetMaxCount() > 0 && itemCount > item_proto.GetMaxCount()))
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.CommandInvalidItemCount, itemCount, itemId);
|
||||
return false;
|
||||
}
|
||||
|
||||
while (itemCount > item_proto.GetMaxStackSize())
|
||||
{
|
||||
items.Add(new KeyValuePair<uint, uint>(itemId, item_proto.GetMaxStackSize()));
|
||||
itemCount -= item_proto.GetMaxStackSize();
|
||||
}
|
||||
|
||||
items.Add(new KeyValuePair<uint, uint>(itemId, itemCount));
|
||||
|
||||
if (items.Count > SharedConst.MaxMailItems)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.CommandMailItemsLimit, SharedConst.MaxMailItems);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// from console show not existed sender
|
||||
MailSender sender = new MailSender(MailMessageType.Normal, handler.GetSession() ? handler.GetSession().GetPlayer().GetGUID().GetCounter() : 0, MailStationery.Gm);
|
||||
|
||||
// fill mail
|
||||
MailDraft draft = new MailDraft(subject, text);
|
||||
|
||||
SQLTransaction trans = new SQLTransaction();
|
||||
|
||||
foreach (var pair in items)
|
||||
{
|
||||
Item item = Item.CreateItem(pair.Key, pair.Value, handler.GetSession() ? handler.GetSession().GetPlayer() : null);
|
||||
if (item)
|
||||
{
|
||||
item.SaveToDB(trans); // save for prevent lost at next mail load, if send fail then item will deleted
|
||||
draft.AddItem(item);
|
||||
}
|
||||
}
|
||||
|
||||
draft.SendMailTo(trans, new MailReceiver(receiver, receiverGuid.GetCounter()), sender);
|
||||
DB.Characters.CommitTransaction(trans);
|
||||
|
||||
string nameLink = handler.playerLink(receiverName);
|
||||
handler.SendSysMessage(CypherStrings.MailSent, nameLink);
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("money", RBACPermissions.CommandSendMoney, true)]
|
||||
static bool HandleSendMoneyCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
/// format: name "subject text" "mail text" money
|
||||
|
||||
Player receiver;
|
||||
ObjectGuid receiverGuid;
|
||||
string receiverName;
|
||||
if (!handler.extractPlayerTarget(args, out receiver, out receiverGuid, out receiverName))
|
||||
return false;
|
||||
|
||||
string tail1 = args.NextString("");
|
||||
if (string.IsNullOrEmpty(tail1))
|
||||
return false;
|
||||
|
||||
string subject = handler.extractQuotedArg(tail1);
|
||||
if (string.IsNullOrEmpty(subject))
|
||||
return false;
|
||||
|
||||
string tail2 = args.NextString("");
|
||||
if (string.IsNullOrEmpty(tail2))
|
||||
return false;
|
||||
|
||||
string text = handler.extractQuotedArg(tail2);
|
||||
if (string.IsNullOrEmpty(text))
|
||||
return false;
|
||||
|
||||
string moneyStr = args.NextString("");
|
||||
long money = !string.IsNullOrEmpty(moneyStr) ? long.Parse(moneyStr) : 0;
|
||||
if (money <= 0)
|
||||
return false;
|
||||
|
||||
// from console show not existed sender
|
||||
MailSender sender = new MailSender(MailMessageType.Normal, handler.GetSession() ? handler.GetSession().GetPlayer().GetGUID().GetCounter() : 0, MailStationery.Gm);
|
||||
|
||||
SQLTransaction trans = new SQLTransaction();
|
||||
|
||||
new MailDraft(subject, text)
|
||||
.AddMoney((uint)money)
|
||||
.SendMailTo(trans, new MailReceiver(receiver, receiverGuid.GetCounter()), sender);
|
||||
|
||||
DB.Characters.CommitTransaction(trans);
|
||||
|
||||
string nameLink = handler.playerLink(receiverName);
|
||||
handler.SendSysMessage(CypherStrings.MailSent, nameLink);
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("message", RBACPermissions.CommandSendMessage, true)]
|
||||
static bool HandleSendMessageCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
/// - Find the player
|
||||
Player player;
|
||||
if (!handler.extractPlayerTarget(args, out player))
|
||||
return false;
|
||||
|
||||
string msgStr = args.NextString("");
|
||||
if (string.IsNullOrEmpty(msgStr))
|
||||
return false;
|
||||
|
||||
// Check that he is not logging out.
|
||||
if (player.GetSession().isLogingOut())
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.PlayerNotFound);
|
||||
return false;
|
||||
}
|
||||
|
||||
/// - Send the message
|
||||
player.GetSession().SendNotification("{0}", msgStr);
|
||||
player.GetSession().SendNotification("|cffff0000[Message from administrator]:|r");
|
||||
|
||||
// Confirmation message
|
||||
string nameLink = handler.GetNameLink(player);
|
||||
handler.SendSysMessage(CypherStrings.Sendmessage, nameLink, msgStr);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,376 @@
|
||||
/*
|
||||
* Copyright (C) 2012-2017 CypherCore <http://github.com/CypherCore>
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using Framework.Configuration;
|
||||
using Framework.Constants;
|
||||
using Framework.IO;
|
||||
using System;
|
||||
|
||||
namespace Game.Chat
|
||||
{
|
||||
[CommandGroup("server", RBACPermissions.CommandServer, true)]
|
||||
class ServerCommands
|
||||
{
|
||||
[Command("corpses", RBACPermissions.CommandServerCorpses, true)]
|
||||
static bool Corpses(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
Global.WorldMgr.RemoveOldCorpses();
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("exit", RBACPermissions.CommandServerExit, true)]
|
||||
static bool Exit(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.CommandExit);
|
||||
Global.WorldMgr.StopNow(ShutdownExitCode.Shutdown);
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("info", RBACPermissions.CommandServerInfo, true)]
|
||||
static bool Info(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
uint playersNum = Global.WorldMgr.GetPlayerCount();
|
||||
uint maxPlayersNum = Global.WorldMgr.GetMaxPlayerCount();
|
||||
int activeClientsNum = Global.WorldMgr.GetActiveSessionCount();
|
||||
int queuedClientsNum = Global.WorldMgr.GetQueuedSessionCount();
|
||||
uint maxActiveClientsNum = Global.WorldMgr.GetMaxActiveSessionCount();
|
||||
uint maxQueuedClientsNum = Global.WorldMgr.GetMaxQueuedSessionCount();
|
||||
string uptime = Time.secsToTimeString(Global.WorldMgr.GetUptime());
|
||||
uint updateTime = Global.WorldMgr.GetUpdateTime();
|
||||
|
||||
handler.SendSysMessage(CypherStrings.ConnectedPlayers, playersNum, maxPlayersNum);
|
||||
handler.SendSysMessage(CypherStrings.ConnectedUsers, activeClientsNum, maxActiveClientsNum, queuedClientsNum, maxQueuedClientsNum);
|
||||
handler.SendSysMessage(CypherStrings.Uptime, uptime);
|
||||
handler.SendSysMessage(CypherStrings.UpdateDiff, updateTime);
|
||||
// Can't use Global.WorldMgr.ShutdownMsg here in case of console command
|
||||
if (Global.WorldMgr.IsShuttingDown())
|
||||
handler.SendSysMessage(CypherStrings.ShutdownTimeleft, Time.secsToTimeString(Global.WorldMgr.GetShutDownTimeLeft()));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("motd", RBACPermissions.CommandServerMotd, true)]
|
||||
static bool Motd(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.MotdCurrent, Global.WorldMgr.GetMotd());
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("plimit", RBACPermissions.CommandServerPlimit, true)]
|
||||
static bool PLimit(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
if (!args.Empty())
|
||||
{
|
||||
string paramStr = args.NextString();
|
||||
if (string.IsNullOrEmpty(paramStr))
|
||||
return false;
|
||||
|
||||
int limit = paramStr.Length;
|
||||
|
||||
switch (paramStr.ToLower())
|
||||
{
|
||||
case "player":
|
||||
Global.WorldMgr.SetPlayerSecurityLimit(AccountTypes.Player);
|
||||
break;
|
||||
case "moderator":
|
||||
Global.WorldMgr.SetPlayerSecurityLimit(AccountTypes.Moderator);
|
||||
break;
|
||||
case "gamemaster":
|
||||
Global.WorldMgr.SetPlayerSecurityLimit(AccountTypes.GameMaster);
|
||||
break;
|
||||
case "administrator":
|
||||
Global.WorldMgr.SetPlayerSecurityLimit(AccountTypes.Administrator);
|
||||
break;
|
||||
case "reset":
|
||||
Global.WorldMgr.SetPlayerAmountLimit(ConfigMgr.GetDefaultValue<uint>("PlayerLimit", 100));
|
||||
Global.WorldMgr.LoadDBAllowedSecurityLevel();
|
||||
break;
|
||||
default:
|
||||
int value = int.Parse(paramStr);
|
||||
if (value < 0)
|
||||
Global.WorldMgr.SetPlayerSecurityLimit((AccountTypes)(-value));
|
||||
else
|
||||
Global.WorldMgr.SetPlayerAmountLimit((uint)value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
uint playerAmountLimit = Global.WorldMgr.GetPlayerAmountLimit();
|
||||
AccountTypes allowedAccountType = Global.WorldMgr.GetPlayerSecurityLimit();
|
||||
string secName = "";
|
||||
switch (allowedAccountType)
|
||||
{
|
||||
case AccountTypes.Player:
|
||||
secName = "Player";
|
||||
break;
|
||||
case AccountTypes.Moderator:
|
||||
secName = "Moderator";
|
||||
break;
|
||||
case AccountTypes.GameMaster:
|
||||
secName = "Gamemaster";
|
||||
break;
|
||||
case AccountTypes.Administrator:
|
||||
secName = "Administrator";
|
||||
break;
|
||||
default:
|
||||
secName = "<unknown>";
|
||||
break;
|
||||
}
|
||||
handler.SendSysMessage("Player limits: amount {0}, min. security level {1}.", playerAmountLimit, secName);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool IsOnlyUser(WorldSession mySession)
|
||||
{
|
||||
// check if there is any session connected from a different address
|
||||
string myAddr = mySession ? mySession.GetRemoteAddress() : "";
|
||||
var sessions = Global.WorldMgr.GetAllSessions();
|
||||
foreach (var session in sessions)
|
||||
if (session && myAddr != session.GetRemoteAddress())
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool ParseExitCode(string exitCodeStr, out int exitCode)
|
||||
{
|
||||
exitCode = int.Parse(exitCodeStr);
|
||||
|
||||
// Handle atoi() errors
|
||||
if (exitCode == 0 && (exitCodeStr[0] != '0' || (exitCodeStr.Length > 1 && exitCodeStr[1] != '\0')))
|
||||
return false;
|
||||
|
||||
// Exit code should be in range of 0-125, 126-255 is used
|
||||
// in many shells for their own return codes and code > 255
|
||||
// is not supported in many others
|
||||
if (exitCode < 0 || exitCode > 125)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool ShutdownServer(StringArguments args,CommandHandler handler, ShutdownMask shutdownMask, ShutdownExitCode defaultExitCode)
|
||||
{
|
||||
if (args.Empty())
|
||||
return false;
|
||||
|
||||
string delayStr = args.NextString();
|
||||
if (delayStr.IsEmpty())
|
||||
return false;
|
||||
|
||||
int delay;
|
||||
if (int.TryParse(delayStr, out delay))
|
||||
{
|
||||
// Prevent interpret wrong arg value as 0 secs shutdown time
|
||||
if ((delay == 0 && (delayStr[0] != '0' || delayStr.Length > 1 && delayStr[1] != '\0')) || delay < 0)
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
delay = (int)Time.TimeStringToSecs(delayStr);
|
||||
|
||||
if (delay == 0)
|
||||
return false;
|
||||
}
|
||||
|
||||
string reason = "";
|
||||
string exitCodeStr = "";
|
||||
string nextToken;
|
||||
while (!(nextToken = args.NextString()).IsEmpty())
|
||||
{
|
||||
if (nextToken.IsNumber())
|
||||
exitCodeStr = nextToken;
|
||||
else
|
||||
{
|
||||
reason = nextToken;
|
||||
reason += args.NextString("\0");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int exitCode = (int)defaultExitCode;
|
||||
if (!exitCodeStr.IsEmpty())
|
||||
if (!ParseExitCode(exitCodeStr, out exitCode))
|
||||
return false;
|
||||
|
||||
// Override parameter "delay" with the configuration value if there are still players connected and "force" parameter was not specified
|
||||
if (delay < WorldConfig.GetIntValue(WorldCfg.ForceShutdownThreshold) && !shutdownMask.HasAnyFlag(ShutdownMask.Force) && !IsOnlyUser(handler.GetSession()))
|
||||
{
|
||||
delay = WorldConfig.GetIntValue(WorldCfg.ForceShutdownThreshold);
|
||||
handler.SendSysMessage(CypherStrings.ShutdownDelayed, delay);
|
||||
}
|
||||
|
||||
Global.WorldMgr.ShutdownServ((uint)delay, shutdownMask, (ShutdownExitCode)exitCode, reason);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
[CommandGroup("idleRestart", RBACPermissions.CommandServerIdlerestart, true)]
|
||||
class IdleRestartCommands
|
||||
{
|
||||
[Command("", RBACPermissions.CommandServerIdlerestart, true)]
|
||||
static bool HandleServerIdleRestartCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
return ShutdownServer(args, handler, ShutdownMask.Restart | ShutdownMask.Idle, ShutdownExitCode.Restart);
|
||||
}
|
||||
|
||||
[Command("cancel", RBACPermissions.CommandServerIdlerestartCancel, true)]
|
||||
static bool Cancel(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
Global.WorldMgr.ShutdownCancel();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
[CommandGroup("idleshutdown", RBACPermissions.CommandServerIdleshutdown, true)]
|
||||
class IdleshutdownCommands
|
||||
{
|
||||
[Command("", RBACPermissions.CommandServerIdleshutdown, true)]
|
||||
static bool HandleServerIdleShutDownCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
return ShutdownServer(args, handler, ShutdownMask.Idle, ShutdownExitCode.Shutdown);
|
||||
}
|
||||
|
||||
[Command("cancel", RBACPermissions.CommandServerIdleshutdownCancel, true)]
|
||||
static bool Cancel(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
Global.WorldMgr.ShutdownCancel();
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
[CommandGroup("restart", RBACPermissions.CommandServerInfo, true)]
|
||||
class RestartCommands
|
||||
{
|
||||
[Command("", RBACPermissions.CommandServerRestart, true)]
|
||||
static bool HandleServerRestartCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
return ShutdownServer(args, handler, ShutdownMask.Restart, ShutdownExitCode.Restart);
|
||||
}
|
||||
|
||||
[Command("cancel", RBACPermissions.CommandServerRestartCancel, true)]
|
||||
static bool HandleServerRestartCancelCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
Global.WorldMgr.ShutdownCancel();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("force", RBACPermissions.CommandServerRestartCancel, true)]
|
||||
static bool HandleServerForceRestartCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
return ShutdownServer(args, handler, ShutdownMask.Force | ShutdownMask.Restart, ShutdownExitCode.Restart);
|
||||
}
|
||||
}
|
||||
|
||||
[CommandGroup("shutdown", RBACPermissions.CommandServerMotd, true)]
|
||||
class ShutdownCommands
|
||||
{
|
||||
[Command("", RBACPermissions.CommandServerShutdown, true)]
|
||||
static bool HandleServerShutDownCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
return ShutdownServer(args, handler, 0, ShutdownExitCode.Shutdown);
|
||||
}
|
||||
|
||||
[Command("cancel", RBACPermissions.CommandServerShutdownCancel, true)]
|
||||
static bool HandleServerShutDownCancelCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
uint timer = Global.WorldMgr.ShutdownCancel();
|
||||
if (timer != 0)
|
||||
handler.SendSysMessage(CypherStrings.ShutdownCancelled, timer);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("force", RBACPermissions.CommandServerShutdownCancel, true)]
|
||||
static bool HandleServerForceShutDownCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
return ShutdownServer(args, handler, ShutdownMask.Force, ShutdownExitCode.Shutdown);
|
||||
}
|
||||
}
|
||||
|
||||
[CommandGroup("set", RBACPermissions.CommandServerSet, true)]
|
||||
class SetCommands
|
||||
{
|
||||
[Command("difftime", RBACPermissions.CommandServerSetDifftime, true)]
|
||||
static bool HandleServerSetDiffTimeCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
if (args.Empty())
|
||||
return false;
|
||||
|
||||
string newTimeStr = args.NextString();
|
||||
if (newTimeStr.IsEmpty())
|
||||
return false;
|
||||
|
||||
int newTime = int.Parse(newTimeStr);
|
||||
if (newTime < 0)
|
||||
return false;
|
||||
|
||||
//Global.WorldMgr.SetRecordDiffInterval(newTime);
|
||||
//printf("Record diff every %i ms\n", newTime);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("loglevel", RBACPermissions.CommandServerSetLoglevel, true)]
|
||||
static bool HandleServerSetLogLevelCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
if (args.Empty())
|
||||
return false;
|
||||
|
||||
string type = args.NextString();
|
||||
string name = args.NextString();
|
||||
string level = args.NextString();
|
||||
|
||||
if (string.IsNullOrEmpty(type) || string.IsNullOrEmpty(name) || string.IsNullOrEmpty(level) || name.IsEmpty() || level.IsEmpty() || (type[0] != 'a' && type[0] != 'l'))
|
||||
return false;
|
||||
|
||||
return Log.SetLogLevel(name, level, type[0] == 'l');
|
||||
}
|
||||
|
||||
[Command("motd", RBACPermissions.CommandServerSetMotd, true)]
|
||||
static bool SetMotd(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
Global.WorldMgr.SetMotd(args.NextString(""));
|
||||
handler.SendSysMessage(CypherStrings.MotdNew, args);
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("closed", RBACPermissions.CommandServerSetClosed, true)]
|
||||
static bool SetClosed(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
string arg1 = args.NextString();
|
||||
if (arg1.Equals("on"))
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.WorldClosed);
|
||||
Global.WorldMgr.SetClosed(true);
|
||||
return true;
|
||||
}
|
||||
else if (arg1.Equals("off"))
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.WorldOpened);
|
||||
Global.WorldMgr.SetClosed(false);
|
||||
return true;
|
||||
}
|
||||
|
||||
handler.SendSysMessage(CypherStrings.UseBol);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,194 @@
|
||||
/*
|
||||
* Copyright (C) 2012-2017 CypherCore <http://github.com/CypherCore>
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using Framework.Constants;
|
||||
using Framework.IO;
|
||||
using Game.DataStorage;
|
||||
using Game.Entities;
|
||||
using Game.Spells;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Game.Chat
|
||||
{
|
||||
class SpellCommands
|
||||
{
|
||||
[CommandNonGroup("cooldown", RBACPermissions.CommandCooldown)]
|
||||
static bool HandleCooldownCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
Unit target = handler.getSelectedUnit();
|
||||
if (!target)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.PlayerNotFound);
|
||||
return false;
|
||||
}
|
||||
|
||||
Player owner = target.GetCharmerOrOwnerPlayerOrPlayerItself();
|
||||
if (!owner)
|
||||
{
|
||||
owner = handler.GetSession().GetPlayer();
|
||||
target = owner;
|
||||
}
|
||||
|
||||
string nameLink = handler.GetNameLink(owner);
|
||||
if (args.Empty())
|
||||
{
|
||||
target.GetSpellHistory().ResetAllCooldowns();
|
||||
target.GetSpellHistory().ResetAllCharges();
|
||||
handler.SendSysMessage(CypherStrings.RemoveallCooldown, nameLink);
|
||||
}
|
||||
else
|
||||
{
|
||||
// number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
|
||||
uint spellIid = handler.extractSpellIdFromLink(args);
|
||||
if (spellIid == 0)
|
||||
return false;
|
||||
|
||||
SpellInfo spellInfo = Global.SpellMgr.GetSpellInfo(spellIid);
|
||||
if (spellInfo == null)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.UnknownSpell, owner == handler.GetSession().GetPlayer() ? handler.GetCypherString(CypherStrings.You) : nameLink);
|
||||
return false;
|
||||
}
|
||||
|
||||
target.GetSpellHistory().ResetCooldown(spellIid, true);
|
||||
target.GetSpellHistory().ResetCharges(spellInfo.ChargeCategoryId);
|
||||
handler.SendSysMessage(CypherStrings.RemoveallCooldown, spellIid, owner == handler.GetSession().GetPlayer() ? handler.GetCypherString(CypherStrings.You) : nameLink);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
[CommandNonGroup("aura", RBACPermissions.CommandAura)]
|
||||
static bool Auracommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
Unit target = handler.getSelectedUnit();
|
||||
if (!target)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.SelectCharOrCreature);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
|
||||
uint spellId = handler.extractSpellIdFromLink(args);
|
||||
|
||||
SpellInfo spellInfo = Global.SpellMgr.GetSpellInfo(spellId);
|
||||
if (spellInfo != null)
|
||||
{
|
||||
ObjectGuid castId = ObjectGuid.Create(HighGuid.Cast, SpellCastSource.Normal, target.GetMapId(), spellId, target.GetMap().GenerateLowGuid(HighGuid.Cast));
|
||||
Aura.TryRefreshStackOrCreate(spellInfo, castId, SpellConst.MaxEffectMask, target, target);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
[CommandNonGroup("unaura", RBACPermissions.CommandUnaura)]
|
||||
static bool UnAura(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
Unit target = handler.getSelectedUnit();
|
||||
if (!target)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.SelectCharOrCreature);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
string argstr = args.NextString();
|
||||
if (argstr == "all")
|
||||
{
|
||||
target.RemoveAllAuras();
|
||||
return true;
|
||||
}
|
||||
|
||||
// number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
|
||||
uint spellId = handler.extractSpellIdFromLink(args);
|
||||
if (spellId == 0)
|
||||
return false;
|
||||
|
||||
target.RemoveAurasDueToSpell(spellId);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
[CommandNonGroup("maxskill", RBACPermissions.CommandMaxskill)]
|
||||
static bool HandleMaxSkillCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
Player player = handler.getSelectedPlayerOrSelf();
|
||||
if (!player)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.NoCharSelected);
|
||||
return false;
|
||||
}
|
||||
|
||||
// each skills that have max skill value dependent from level seted to current level max skill value
|
||||
player.UpdateSkillsToMaxSkillsForLevel();
|
||||
return true;
|
||||
}
|
||||
|
||||
[CommandNonGroup("setskill", RBACPermissions.CommandSetskill)]
|
||||
static bool SetSkill(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
// number or [name] Shift-click form |color|Hskill:skill_id|h[name]|h|r
|
||||
string skillStr = handler.extractKeyFromLink(args, "Hskill");
|
||||
if (string.IsNullOrEmpty(skillStr))
|
||||
return false;
|
||||
|
||||
string levelStr = args.NextString();
|
||||
if (string.IsNullOrEmpty(levelStr))
|
||||
return false;
|
||||
|
||||
string maxPureSkill = args.NextString();
|
||||
|
||||
uint skill = uint.Parse(skillStr);
|
||||
if (skill == 0)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.InvalidSkillId, skill);
|
||||
return false;
|
||||
}
|
||||
|
||||
uint level = uint.Parse(levelStr);
|
||||
Player target = handler.getSelectedPlayerOrSelf();
|
||||
if (!target)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.NoCharSelected);
|
||||
return false;
|
||||
}
|
||||
|
||||
SkillLineRecord skillLine = CliDB.SkillLineStorage.LookupByKey(skill);
|
||||
if (skillLine == null)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.InvalidSkillId, skill);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool targetHasSkill = target.GetSkillValue((SkillType)skill) != 0;
|
||||
|
||||
// If our target does not yet have the skill they are trying to add to them, the chosen level also becomes
|
||||
// the max level of the new profession.
|
||||
ushort max = !string.IsNullOrEmpty(maxPureSkill) ? ushort.Parse(maxPureSkill) : targetHasSkill ? target.GetPureMaxSkillValue((SkillType)skill) : (ushort)level;
|
||||
|
||||
if (level == 0 || level > max || max <= 0)
|
||||
return false;
|
||||
|
||||
// If the player has the skill, we get the current skill step. If they don't have the skill, we
|
||||
// add the skill to the player's book with step 1 (which is the first rank, in most cases something
|
||||
// like 'Apprentice <skill>'.
|
||||
target.SetSkill((SkillType)skill, (uint)(targetHasSkill ? target.GetSkillStep((SkillType)skill) : 1), level, max);
|
||||
handler.SendSysMessage(CypherStrings.SetSkill, skill, skillLine.DisplayName[handler.GetSessionDbcLocale()], handler.GetNameLink(target), level, max);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,170 @@
|
||||
/*
|
||||
* Copyright (C) 2012-2017 CypherCore <http://github.com/CypherCore>
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using Framework.Constants;
|
||||
using Framework.IO;
|
||||
using Game.DataStorage;
|
||||
using Game.Entities;
|
||||
using Game.Groups;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Game.Chat
|
||||
{
|
||||
[CommandGroup("tele", RBACPermissions.CommandTele)]
|
||||
class TeleCommands
|
||||
{
|
||||
[Command("", RBACPermissions.CommandTele)]
|
||||
static bool HandleTeleCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
if (args.Empty())
|
||||
return false;
|
||||
|
||||
Player me = handler.GetPlayer();
|
||||
|
||||
GameTele tele = handler.extractGameTeleFromLink(args);
|
||||
|
||||
if (tele == null)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.CommandTeleNotfound);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (me.IsInCombat())
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.YouInCombat);
|
||||
return false;
|
||||
}
|
||||
|
||||
var map = CliDB.MapStorage.LookupByKey(tele.mapId);
|
||||
if (map == null || (map.IsBattlegroundOrArena() && (me.GetMapId() != tele.mapId || !me.IsGameMaster())))
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.CannotTeleToBg);
|
||||
return false;
|
||||
}
|
||||
|
||||
// stop flight if need
|
||||
if (me.IsInFlight())
|
||||
{
|
||||
me.GetMotionMaster().MovementExpired();
|
||||
me.CleanupAfterTaxiFlight();
|
||||
}
|
||||
// save only in non-flight case
|
||||
else
|
||||
me.SaveRecallPosition();
|
||||
|
||||
me.TeleportTo(tele.mapId, tele.posX, tele.posY, tele.posZ, tele.orientation);
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("add", RBACPermissions.CommandTeleAdd)]
|
||||
static bool HandleTeleAddCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
[Command("del", RBACPermissions.CommandTeleDel, true)]
|
||||
static bool HandleTeleDelCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
[Command("group", RBACPermissions.CommandTeleGroup)]
|
||||
static bool HandleTeleGroupCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
if (args.Empty())
|
||||
return false;
|
||||
|
||||
Player target = handler.getSelectedPlayer();
|
||||
if (!target)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.NoCharSelected);
|
||||
return false;
|
||||
}
|
||||
|
||||
// check online security
|
||||
if (handler.HasLowerSecurity(target, ObjectGuid.Empty))
|
||||
return false;
|
||||
|
||||
// id, or string, or [name] Shift-click form |color|Htele:id|h[name]|h|r
|
||||
GameTele tele = handler.extractGameTeleFromLink(args);
|
||||
if (tele == null)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.CommandTeleNotfound);
|
||||
return false;
|
||||
}
|
||||
|
||||
MapRecord map = CliDB.MapStorage.LookupByKey(tele.mapId);
|
||||
if (map == null || map.IsBattlegroundOrArena())
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.CannotTeleToBg);
|
||||
return false;
|
||||
}
|
||||
|
||||
string nameLink = handler.GetNameLink(target);
|
||||
|
||||
Group grp = target.GetGroup();
|
||||
if (!grp)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.NotInGroup, nameLink);
|
||||
return false;
|
||||
}
|
||||
|
||||
for (GroupReference refe = grp.GetFirstMember(); refe != null; refe = refe.next())
|
||||
{
|
||||
Player player = refe.GetSource();
|
||||
if (!player || !player.GetSession())
|
||||
continue;
|
||||
|
||||
// check online security
|
||||
if (handler.HasLowerSecurity(player, ObjectGuid.Empty))
|
||||
return false;
|
||||
|
||||
string plNameLink = handler.GetNameLink(player);
|
||||
|
||||
if (player.IsBeingTeleported())
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.IsTeleported, plNameLink);
|
||||
continue;
|
||||
}
|
||||
|
||||
handler.SendSysMessage(CypherStrings.TeleportingTo, plNameLink, "", tele.name);
|
||||
if (handler.needReportToTarget(player))
|
||||
player.SendSysMessage(CypherStrings.TeleportedToBy, nameLink);
|
||||
|
||||
// stop flight if need
|
||||
if (player.IsInFlight())
|
||||
{
|
||||
player.GetMotionMaster().MovementExpired();
|
||||
player.CleanupAfterTaxiFlight();
|
||||
}
|
||||
// save only in non-flight case
|
||||
else
|
||||
player.SaveRecallPosition();
|
||||
|
||||
player.TeleportTo(tele.mapId, tele.posX, tele.posY, tele.posZ, tele.orientation);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("name", RBACPermissions.CommandTeleName, true)]
|
||||
static bool HandleTeleNameCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,490 @@
|
||||
/*
|
||||
* Copyright (C) 2012-2017 CypherCore <http://github.com/CypherCore>
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using Framework.Constants;
|
||||
using Framework.IO;
|
||||
using Game.Entities;
|
||||
using Game.SupportSystem;
|
||||
|
||||
namespace Game.Chat.Commands
|
||||
{
|
||||
[CommandGroup("ticket", RBACPermissions.CommandTicket, true)]
|
||||
class TicketCommands
|
||||
{
|
||||
[Command("togglesystem", RBACPermissions.CommandTicketTogglesystem, true)]
|
||||
static bool HandleTicketToggleSystem(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
if (!WorldConfig.GetBoolValue(WorldCfg.SupportTicketsEnabled))
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.DisallowTicketsConfig);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool status = !Global.SupportMgr.GetSupportSystemStatus();
|
||||
Global.SupportMgr.SetSupportSystemStatus(status);
|
||||
handler.SendSysMessage(status ? CypherStrings.AllowTickets : CypherStrings.DisallowTickets);
|
||||
return true;
|
||||
}
|
||||
|
||||
[CommandGroup("bug", RBACPermissions.CommandTicketBug, true)]
|
||||
class TicketBugCommands
|
||||
{
|
||||
[Command("assign", RBACPermissions.CommandTicketBugAssign, true)]
|
||||
static bool HandleTicketBugAssignCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
return HandleTicketAssignToCommand<BugTicket>(args, handler);
|
||||
}
|
||||
|
||||
[Command("close", RBACPermissions.CommandTicketBugClose, true)]
|
||||
static bool HandleTicketBugCloseCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
return HandleCloseByIdCommand<BugTicket>(args, handler);
|
||||
}
|
||||
|
||||
[Command("closedlist", RBACPermissions.CommandTicketBugClosedlist, true)]
|
||||
static bool HandleTicketBugClosedListCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
return HandleClosedListCommand<BugTicket>(args, handler);
|
||||
}
|
||||
|
||||
[Command("comment", RBACPermissions.CommandTicketBugComment, true)]
|
||||
static bool HandleTicketBugCommentCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
return HandleCommentCommand<BugTicket>(args, handler);
|
||||
}
|
||||
|
||||
[Command("delete", RBACPermissions.CommandTicketBugDelete, true)]
|
||||
static bool HandleTicketBugDeleteCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
return HandleDeleteByIdCommand<BugTicket>(args, handler);
|
||||
}
|
||||
|
||||
[Command("list", RBACPermissions.CommandTicketBugList, true)]
|
||||
static bool HandleTicketBugListCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
return HandleListCommand<BugTicket>(args, handler);
|
||||
}
|
||||
|
||||
[Command("unassign", RBACPermissions.CommandTicketBugUnassign, true)]
|
||||
static bool HandleTicketBugUnAssignCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
return HandleUnAssignCommand<BugTicket>(args, handler);
|
||||
}
|
||||
|
||||
[Command("view", RBACPermissions.CommandTicketBugView, true)]
|
||||
static bool HandleTicketBugViewCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
return HandleGetByIdCommand<BugTicket>(args, handler);
|
||||
}
|
||||
}
|
||||
|
||||
[CommandGroup("complaint", RBACPermissions.CommandTicketComplaint, true)]
|
||||
class TicketComplaintCommands
|
||||
{
|
||||
[Command("assign", RBACPermissions.CommandTicketComplaintAssign, true)]
|
||||
static bool HandleTicketComplaintAssignCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
return HandleTicketAssignToCommand<ComplaintTicket>(args, handler);
|
||||
}
|
||||
|
||||
[Command("close", RBACPermissions.CommandTicketComplaintClose, true)]
|
||||
static bool HandleTicketComplaintCloseCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
return HandleCloseByIdCommand<ComplaintTicket>(args, handler);
|
||||
}
|
||||
|
||||
[Command("closedlist", RBACPermissions.CommandTicketComplaintClosedlist, true)]
|
||||
static bool HandleTicketComplaintClosedListCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
return HandleClosedListCommand<ComplaintTicket>(args, handler);
|
||||
}
|
||||
|
||||
[Command("comment", RBACPermissions.CommandTicketComplaintComment, true)]
|
||||
static bool HandleTicketComplaintCommentCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
return HandleCommentCommand<ComplaintTicket>(args, handler);
|
||||
}
|
||||
|
||||
[Command("delete", RBACPermissions.CommandTicketComplaintDelete, true)]
|
||||
static bool HandleTicketComplaintDeleteCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
return HandleDeleteByIdCommand<ComplaintTicket>(args, handler);
|
||||
}
|
||||
|
||||
[Command("list", RBACPermissions.CommandTicketComplaintList, true)]
|
||||
static bool HandleTicketComplaintListCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
return HandleListCommand<ComplaintTicket>(args, handler);
|
||||
}
|
||||
|
||||
[Command("unassign", RBACPermissions.CommandTicketComplaintUnassign, true)]
|
||||
static bool HandleTicketComplaintUnAssignCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
return HandleUnAssignCommand<ComplaintTicket>(args, handler);
|
||||
}
|
||||
|
||||
[Command("view", RBACPermissions.CommandTicketComplaintView, true)]
|
||||
static bool HandleTicketComplaintViewCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
return HandleGetByIdCommand<ComplaintTicket>(args, handler);
|
||||
}
|
||||
}
|
||||
|
||||
[CommandGroup("suggestion", RBACPermissions.CommandTicketSuggestion, true)]
|
||||
class TicketSuggestionCommands
|
||||
{
|
||||
[Command("assign", RBACPermissions.CommandTicketSuggestionAssign, true)]
|
||||
static bool HandleTicketSuggestionAssignCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
return HandleTicketAssignToCommand<SuggestionTicket>(args, handler);
|
||||
}
|
||||
|
||||
[Command("close", RBACPermissions.CommandTicketSuggestionClose, true)]
|
||||
static bool HandleTicketSuggestionCloseCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
return HandleCloseByIdCommand<SuggestionTicket>(args, handler);
|
||||
}
|
||||
|
||||
[Command("closedlist", RBACPermissions.CommandTicketSuggestionClosedlist, true)]
|
||||
static bool HandleTicketSuggestionClosedListCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
return HandleClosedListCommand<SuggestionTicket>(args, handler);
|
||||
}
|
||||
|
||||
[Command("comment", RBACPermissions.CommandTicketSuggestionComment, true)]
|
||||
static bool HandleTicketSuggestionCommentCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
return HandleCommentCommand<SuggestionTicket>(args, handler);
|
||||
}
|
||||
|
||||
[Command("delete", RBACPermissions.CommandTicketSuggestionDelete, true)]
|
||||
static bool HandleTicketSuggestionDeleteCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
return HandleDeleteByIdCommand<SuggestionTicket>(args, handler);
|
||||
}
|
||||
|
||||
[Command("list", RBACPermissions.CommandTicketSuggestionList, true)]
|
||||
static bool HandleTicketSuggestionListCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
return HandleListCommand<SuggestionTicket>(args, handler);
|
||||
}
|
||||
|
||||
[Command("unassign", RBACPermissions.CommandTicketSuggestionUnassign, true)]
|
||||
static bool HandleTicketSuggestionUnAssignCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
return HandleUnAssignCommand<SuggestionTicket>(args, handler);
|
||||
}
|
||||
|
||||
[Command("view", RBACPermissions.CommandTicketSuggestionView, true)]
|
||||
static bool HandleTicketSuggestionViewCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
return HandleGetByIdCommand<SuggestionTicket>(args, handler);
|
||||
}
|
||||
}
|
||||
|
||||
[CommandGroup("reset", RBACPermissions.CommandTicketReset, true)]
|
||||
class TicketResetCommands
|
||||
{
|
||||
[Command("all", RBACPermissions.CommandTicketResetAll, true)]
|
||||
static bool HandleTicketResetAllCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
if (Global.SupportMgr.GetOpenTicketCount<BugTicket>() != 0 || Global.SupportMgr.GetOpenTicketCount<ComplaintTicket>() != 0 || Global.SupportMgr.GetOpenTicketCount<SuggestionTicket>() != 0)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.CommandTicketpending);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
Global.SupportMgr.ResetTickets<BugTicket>();
|
||||
Global.SupportMgr.ResetTickets<ComplaintTicket>();
|
||||
Global.SupportMgr.ResetTickets<SuggestionTicket>();
|
||||
handler.SendSysMessage(CypherStrings.CommandTicketreset);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("bug", RBACPermissions.CommandTicketResetBug, true)]
|
||||
static bool HandleTicketResetBugCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
return HandleResetCommand<BugTicket>(args, handler);
|
||||
}
|
||||
|
||||
[Command("complaint", RBACPermissions.CommandTicketResetComplaint, true)]
|
||||
static bool HandleTicketResetComplaintCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
return HandleResetCommand<ComplaintTicket>(args, handler);
|
||||
}
|
||||
|
||||
[Command("suggestion", RBACPermissions.CommandTicketResetSuggestion, true)]
|
||||
static bool HandleTicketResetSuggestionCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
return HandleResetCommand<SuggestionTicket>(args, handler);
|
||||
}
|
||||
}
|
||||
|
||||
static bool HandleTicketAssignToCommand<T>(StringArguments args, CommandHandler handler) where T : Ticket
|
||||
{
|
||||
if (args.Empty())
|
||||
return false;
|
||||
|
||||
uint ticketId = args.NextUInt32();
|
||||
|
||||
string target = args.NextString();
|
||||
if (string.IsNullOrEmpty(target))
|
||||
return false;
|
||||
|
||||
if (!ObjectManager.NormalizePlayerName(ref target))
|
||||
return false;
|
||||
|
||||
T ticket = Global.SupportMgr.GetTicket<T>(ticketId);
|
||||
if (ticket == null || ticket.IsClosed())
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.CommandTicketnotexist);
|
||||
return true;
|
||||
}
|
||||
|
||||
ObjectGuid targetGuid = ObjectManager.GetPlayerGUIDByName(target);
|
||||
uint accountId = ObjectManager.GetPlayerAccountIdByGUID(targetGuid);
|
||||
// Target must exist and have administrative rights
|
||||
if (!Global.AccountMgr.HasPermission(accountId, RBACPermissions.CommandsBeAssignedTicket, Global.WorldMgr.GetRealm().Id.Realm))
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.CommandTicketassignerrorA);
|
||||
return true;
|
||||
}
|
||||
|
||||
// If already assigned, leave
|
||||
if (ticket.IsAssignedTo(targetGuid))
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.CommandTicketassignerrorB, ticket.GetId());
|
||||
return true;
|
||||
}
|
||||
|
||||
// If assigned to different player other than current, leave
|
||||
//! Console can override though
|
||||
Player player = handler.GetSession() != null ? handler.GetSession().GetPlayer() : null;
|
||||
if (player && ticket.IsAssignedNotTo(player.GetGUID()))
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.CommandTicketalreadyassigned, ticket.GetId());
|
||||
return true;
|
||||
}
|
||||
|
||||
// Assign ticket
|
||||
ticket.SetAssignedTo(targetGuid, Global.AccountMgr.IsAdminAccount(Global.AccountMgr.GetSecurity(accountId, (int)Global.WorldMgr.GetRealm().Id.Realm)));
|
||||
ticket.SaveToDB();
|
||||
|
||||
string msg = ticket.FormatViewMessageString(handler, null, target, null, null);
|
||||
handler.SendGlobalGMSysMessage(msg);
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool HandleCloseByIdCommand<T>(StringArguments args, CommandHandler handler) where T : Ticket
|
||||
{
|
||||
if (args.Empty())
|
||||
return false;
|
||||
|
||||
uint ticketId = args.NextUInt32();
|
||||
T ticket = Global.SupportMgr.GetTicket<T>(ticketId);
|
||||
if (ticket == null || ticket.IsClosed())
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.CommandTicketnotexist);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Ticket should be assigned to the player who tries to close it.
|
||||
// Console can override though
|
||||
Player player = handler.GetSession() != null ? handler.GetSession().GetPlayer() : null;
|
||||
if (player && ticket.IsAssignedNotTo(player.GetGUID()))
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.CommandTicketcannotclose, ticket.GetId());
|
||||
return true;
|
||||
}
|
||||
|
||||
ObjectGuid closedByGuid = ObjectGuid.Empty;
|
||||
if (player)
|
||||
closedByGuid = player.GetGUID();
|
||||
else
|
||||
closedByGuid.SetRawValue(0, ulong.MaxValue);
|
||||
|
||||
Global.SupportMgr.CloseTicket<T>(ticket.GetId(), closedByGuid);
|
||||
|
||||
string msg = ticket.FormatViewMessageString(handler, player ? player.GetName() : "Console", null, null, null);
|
||||
handler.SendGlobalGMSysMessage(msg);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool HandleClosedListCommand<T>(StringArguments args, CommandHandler handler) where T : Ticket
|
||||
{
|
||||
Global.SupportMgr.ShowClosedList<T>(handler);
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool HandleCommentCommand<T>(StringArguments args, CommandHandler handler) where T : Ticket
|
||||
{
|
||||
if (args.Empty())
|
||||
return false;
|
||||
|
||||
uint ticketId = args.NextUInt32();
|
||||
|
||||
string comment = args.NextString("\n");
|
||||
if (string.IsNullOrEmpty(comment))
|
||||
return false;
|
||||
|
||||
T ticket = Global.SupportMgr.GetTicket<T>(ticketId);
|
||||
if (ticket == null || ticket.IsClosed())
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.CommandTicketnotexist);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Cannot comment ticket assigned to someone else
|
||||
//! Console excluded
|
||||
Player player = handler.GetSession() != null ? handler.GetSession().GetPlayer() : null;
|
||||
if (player && ticket.IsAssignedNotTo(player.GetGUID()))
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.CommandTicketalreadyassigned, ticket.GetId());
|
||||
return true;
|
||||
}
|
||||
|
||||
ticket.SetComment(comment);
|
||||
ticket.SaveToDB();
|
||||
Global.SupportMgr.UpdateLastChange();
|
||||
|
||||
string msg = ticket.FormatViewMessageString(handler, null, ticket.GetAssignedToName(), null, null);
|
||||
msg += string.Format(handler.GetCypherString(CypherStrings.CommandTicketlistaddcomment), player ? player.GetName() : "Console", comment);
|
||||
handler.SendGlobalGMSysMessage(msg);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool HandleDeleteByIdCommand<T>(StringArguments args, CommandHandler handler) where T : Ticket
|
||||
{
|
||||
if (args.Empty())
|
||||
return false;
|
||||
|
||||
uint ticketId = args.NextUInt32();
|
||||
T ticket = Global.SupportMgr.GetTicket<T>(ticketId);
|
||||
if (ticket == null)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.CommandTicketnotexist);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!ticket.IsClosed())
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.CommandTicketclosefirst);
|
||||
return true;
|
||||
}
|
||||
|
||||
string msg = ticket.FormatViewMessageString(handler, null, null, null, handler.GetSession() != null ? handler.GetSession().GetPlayer().GetName() : "Console");
|
||||
handler.SendGlobalGMSysMessage(msg);
|
||||
|
||||
Global.SupportMgr.RemoveTicket<T>(ticket.GetId());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool HandleListCommand<T>(StringArguments args, CommandHandler handler) where T : Ticket
|
||||
{
|
||||
Global.SupportMgr.ShowList<T>(handler);
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool HandleResetCommand<T>(StringArguments args, CommandHandler handler) where T : Ticket
|
||||
{
|
||||
if (Global.SupportMgr.GetOpenTicketCount<T>() != 0)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.CommandTicketpending);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
Global.SupportMgr.ResetTickets<T>();
|
||||
handler.SendSysMessage(CypherStrings.CommandTicketreset);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool HandleUnAssignCommand<T>(StringArguments args, CommandHandler handler) where T : Ticket
|
||||
{
|
||||
if (args.Empty())
|
||||
return false;
|
||||
|
||||
uint ticketId = args.NextUInt32();
|
||||
T ticket = Global.SupportMgr.GetTicket<T>(ticketId);
|
||||
if (ticket == null || ticket.IsClosed())
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.CommandTicketnotexist);
|
||||
return true;
|
||||
}
|
||||
// Ticket must be assigned
|
||||
if (!ticket.IsAssigned())
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.CommandTicketnotassigned, ticket.GetId());
|
||||
return true;
|
||||
}
|
||||
|
||||
// Get security level of player, whom this ticket is assigned to
|
||||
AccountTypes security = AccountTypes.Player;
|
||||
Player assignedPlayer = ticket.GetAssignedPlayer();
|
||||
if (assignedPlayer && assignedPlayer.IsInWorld)
|
||||
security = assignedPlayer.GetSession().GetSecurity();
|
||||
else
|
||||
{
|
||||
ObjectGuid guid = ticket.GetAssignedToGUID();
|
||||
uint accountId = ObjectManager.GetPlayerAccountIdByGUID(guid);
|
||||
security = Global.AccountMgr.GetSecurity(accountId, (int)Global.WorldMgr.GetRealm().Id.Realm);
|
||||
}
|
||||
|
||||
// Check security
|
||||
//! If no m_session present it means we're issuing this command from the console
|
||||
AccountTypes mySecurity = handler.GetSession() != null ? handler.GetSession().GetSecurity() : AccountTypes.Console;
|
||||
if (security > mySecurity)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.CommandTicketunassignsecurity);
|
||||
return true;
|
||||
}
|
||||
|
||||
string assignedTo = ticket.GetAssignedToName(); // copy assignedto name because we need it after the ticket has been unnassigned
|
||||
|
||||
ticket.SetUnassigned();
|
||||
ticket.SaveToDB();
|
||||
string msg = ticket.FormatViewMessageString(handler, null, assignedTo, handler.GetSession() != null ? handler.GetSession().GetPlayer().GetName() : "Console", null);
|
||||
handler.SendGlobalGMSysMessage(msg);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool HandleGetByIdCommand<T>(StringArguments args, CommandHandler handler) where T : Ticket
|
||||
{
|
||||
if (args.Empty())
|
||||
return false;
|
||||
|
||||
uint ticketId = args.NextUInt32();
|
||||
T ticket = Global.SupportMgr.GetTicket<T>(ticketId);
|
||||
if (ticket == null || ticket.IsClosed())
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.CommandTicketnotexist);
|
||||
return true;
|
||||
}
|
||||
|
||||
handler.SendSysMessage(ticket.FormatViewMessageString(handler, true));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,208 @@
|
||||
/*
|
||||
* Copyright (C) 2012-2017 CypherCore <http://github.com/CypherCore>
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using Framework.Constants;
|
||||
using Framework.IO;
|
||||
using Game.DataStorage;
|
||||
using Game.Entities;
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
|
||||
namespace Game.Chat.Commands
|
||||
{
|
||||
[CommandGroup("titles", RBACPermissions.CommandTitles)]
|
||||
class TitleCommands
|
||||
{
|
||||
[Command("current", RBACPermissions.CommandTitlesCurrent)]
|
||||
static bool HandleTitlesCurrentCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
// number or [name] Shift-click form |color|Htitle:title_id|h[name]|h|r
|
||||
string id_p = handler.extractKeyFromLink(args, "Htitle");
|
||||
if (string.IsNullOrEmpty(id_p))
|
||||
return false;
|
||||
|
||||
uint id = uint.Parse(id_p);
|
||||
if (id == 0)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.InvalidTitleId, id);
|
||||
return false;
|
||||
}
|
||||
|
||||
Player target = handler.getSelectedPlayer();
|
||||
if (!target)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.NoCharSelected);
|
||||
return false;
|
||||
}
|
||||
|
||||
// check online security
|
||||
if (handler.HasLowerSecurity(target, ObjectGuid.Empty))
|
||||
return false;
|
||||
|
||||
CharTitlesRecord titleInfo = CliDB.CharTitlesStorage.LookupByKey(id);
|
||||
if (titleInfo == null)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.InvalidTitleId, id);
|
||||
return false;
|
||||
}
|
||||
|
||||
string tNameLink = handler.GetNameLink(target);
|
||||
|
||||
target.SetTitle(titleInfo); // to be sure that title now known
|
||||
target.SetUInt32Value(PlayerFields.ChosenTitle, titleInfo.MaskID);
|
||||
|
||||
handler.SendSysMessage(CypherStrings.TitleCurrentRes, id, (target.GetGender() == Gender.Male ? titleInfo.NameMale : titleInfo.NameFemale)[handler.GetSessionDbcLocale()], tNameLink);
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("add", RBACPermissions.CommandTitlesAdd)]
|
||||
static bool HandleTitlesAddCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
// number or [name] Shift-click form |color|Htitle:title_id|h[name]|h|r
|
||||
string id_p = handler.extractKeyFromLink(args, "Htitle");
|
||||
if (string.IsNullOrEmpty(id_p))
|
||||
return false;
|
||||
|
||||
uint id = uint.Parse(id_p);
|
||||
if (id == 0)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.InvalidTitleId, id);
|
||||
return false;
|
||||
}
|
||||
|
||||
Player target = handler.getSelectedPlayer();
|
||||
if (!target)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.NoCharSelected);
|
||||
return false;
|
||||
}
|
||||
|
||||
// check online security
|
||||
if (handler.HasLowerSecurity(target, ObjectGuid.Empty))
|
||||
return false;
|
||||
|
||||
CharTitlesRecord titleInfo = CliDB.CharTitlesStorage.LookupByKey(id);
|
||||
if (titleInfo == null)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.InvalidTitleId, id);
|
||||
return false;
|
||||
}
|
||||
|
||||
string tNameLink = handler.GetNameLink(target);
|
||||
|
||||
string titleNameStr = string.Format((target.GetGender() == Gender.Male ? titleInfo.NameMale : titleInfo.NameFemale)[handler.GetSessionDbcLocale()].ConvertFormatSyntax(), target.GetName());
|
||||
|
||||
target.SetTitle(titleInfo);
|
||||
handler.SendSysMessage(CypherStrings.TitleAddRes, id, titleNameStr, tNameLink);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("remove", RBACPermissions.CommandTitlesRemove)]
|
||||
static bool HandleTitlesRemoveCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
// number or [name] Shift-click form |color|Htitle:title_id|h[name]|h|r
|
||||
string id_p = handler.extractKeyFromLink(args, "Htitle");
|
||||
if (string.IsNullOrEmpty(id_p))
|
||||
return false;
|
||||
|
||||
uint id = uint.Parse(id_p);
|
||||
if (id == 0)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.InvalidTitleId, id);
|
||||
return false;
|
||||
}
|
||||
|
||||
Player target = handler.getSelectedPlayer();
|
||||
if (!target)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.NoCharSelected);
|
||||
return false;
|
||||
}
|
||||
|
||||
// check online security
|
||||
if (handler.HasLowerSecurity(target, ObjectGuid.Empty))
|
||||
return false;
|
||||
|
||||
CharTitlesRecord titleInfo = CliDB.CharTitlesStorage.LookupByKey(id);
|
||||
if (titleInfo == null)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.InvalidTitleId, id);
|
||||
return false;
|
||||
}
|
||||
|
||||
target.SetTitle(titleInfo, true);
|
||||
|
||||
string tNameLink = handler.GetNameLink(target);
|
||||
|
||||
string titleNameStr = string.Format((target.GetGender() == Gender.Male ? titleInfo.NameMale : titleInfo.NameFemale)[handler.GetSessionDbcLocale()].ConvertFormatSyntax(), target.GetName());
|
||||
|
||||
handler.SendSysMessage(CypherStrings.TitleRemoveRes, id, titleNameStr, tNameLink);
|
||||
|
||||
if (!target.HasTitle(target.GetUInt32Value(PlayerFields.ChosenTitle)))
|
||||
{
|
||||
target.SetUInt32Value(PlayerFields.ChosenTitle, 0);
|
||||
handler.SendSysMessage(CypherStrings.CurrentTitleReset, tNameLink);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
[CommandGroup("set", RBACPermissions.CommandTitlesSet)]
|
||||
class TitleSetCommands
|
||||
{
|
||||
//Edit Player KnownTitles
|
||||
[Command("mask", RBACPermissions.CommandTitlesSetMask)]
|
||||
static bool HandleTitlesSetMaskCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
if (args.Empty())
|
||||
return false;
|
||||
|
||||
ulong titles = args.NextUInt64();
|
||||
|
||||
Player target = handler.getSelectedPlayer();
|
||||
if (!target)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.NoCharSelected);
|
||||
return false;
|
||||
}
|
||||
|
||||
// check online security
|
||||
if (handler.HasLowerSecurity(target, ObjectGuid.Empty))
|
||||
return false;
|
||||
|
||||
ulong titles2 = titles;
|
||||
|
||||
foreach (CharTitlesRecord tEntry in CliDB.CharTitlesStorage.Values)
|
||||
titles2 &= ~(1ul << (int)tEntry.MaskID);
|
||||
|
||||
titles &= ~titles2; // remove not existed titles
|
||||
|
||||
target.SetUInt64Value(PlayerFields.KnownTitles, titles);
|
||||
handler.SendSysMessage(CypherStrings.Done);
|
||||
|
||||
if (!target.HasTitle(target.GetUInt32Value(PlayerFields.ChosenTitle)))
|
||||
{
|
||||
target.SetUInt32Value(PlayerFields.ChosenTitle, 0);
|
||||
handler.SendSysMessage(CypherStrings.CurrentTitleReset, handler.GetNameLink(target));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,969 @@
|
||||
/*
|
||||
* Copyright (C) 2012-2017 CypherCore <http://github.com/CypherCore>
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using Framework.Constants;
|
||||
using Framework.Database;
|
||||
using Framework.IO;
|
||||
using Game.Entities;
|
||||
using Game.Maps;
|
||||
using System;
|
||||
|
||||
namespace Game.Chat.Commands
|
||||
{
|
||||
[CommandGroup("wp", RBACPermissions.CommandWp)]
|
||||
class WPCommands
|
||||
{
|
||||
[Command("add", RBACPermissions.CommandWpAdd)]
|
||||
static bool HandleWpAddCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
// optional
|
||||
string path_number = null;
|
||||
uint pathid = 0;
|
||||
|
||||
if (!args.Empty())
|
||||
path_number = args.NextString();
|
||||
|
||||
uint point = 0;
|
||||
Creature target = handler.getSelectedCreature();
|
||||
|
||||
PreparedStatement stmt;
|
||||
|
||||
if (string.IsNullOrEmpty(path_number))
|
||||
{
|
||||
if (target)
|
||||
pathid = target.GetWaypointPath();
|
||||
else
|
||||
{
|
||||
stmt = DB.World.GetPreparedStatement(WorldStatements.SEL_WAYPOINT_DATA_MAX_ID);
|
||||
SQLResult result1 = DB.World.Query(stmt);
|
||||
|
||||
uint maxpathid = result1.Read<uint>(0);
|
||||
pathid = maxpathid + 1;
|
||||
handler.SendSysMessage("|cff00ff00New path started.|r");
|
||||
}
|
||||
}
|
||||
else
|
||||
pathid = uint.Parse(path_number);
|
||||
|
||||
// path_id . ID of the Path
|
||||
// point . number of the waypoint (if not 0)
|
||||
|
||||
if (pathid == 0)
|
||||
{
|
||||
handler.SendSysMessage("|cffff33ffCurrent creature haven't loaded path.|r");
|
||||
return true;
|
||||
}
|
||||
|
||||
stmt = DB.World.GetPreparedStatement(WorldStatements.SEL_WAYPOINT_DATA_MAX_POINT);
|
||||
stmt.AddValue(0, pathid);
|
||||
SQLResult result = DB.World.Query(stmt);
|
||||
|
||||
if (result.IsEmpty())
|
||||
point = result.Read<uint>(0);
|
||||
|
||||
Player player = handler.GetSession().GetPlayer();
|
||||
|
||||
stmt = DB.World.GetPreparedStatement(WorldStatements.INS_WAYPOINT_DATA);
|
||||
stmt.AddValue(0, pathid);
|
||||
stmt.AddValue(1, point + 1);
|
||||
stmt.AddValue(2, player.GetPositionX());
|
||||
stmt.AddValue(3, player.GetPositionY());
|
||||
stmt.AddValue(4, player.GetPositionZ());
|
||||
|
||||
DB.World.Execute(stmt);
|
||||
|
||||
handler.SendSysMessage("|cff00ff00PathID: |r|cff00ffff{0} |r|cff00ff00: Waypoint |r|cff00ffff{1}|r|cff00ff00 created.|r", pathid, point + 1);
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("event", RBACPermissions.CommandWpEvent)]
|
||||
static bool HandleWpEventCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
if (args.Empty())
|
||||
return false;
|
||||
|
||||
string show = args.NextString();
|
||||
PreparedStatement stmt;
|
||||
|
||||
// Check
|
||||
if ((show != "add") && (show != "mod") && (show != "del") && (show != "listid"))
|
||||
return false;
|
||||
|
||||
string arg_id = args.NextString();
|
||||
uint id = 0;
|
||||
if (show == "add")
|
||||
{
|
||||
if (!string.IsNullOrEmpty(arg_id))
|
||||
id = uint.Parse(arg_id);
|
||||
|
||||
if (id != 0)
|
||||
{
|
||||
stmt = DB.World.GetPreparedStatement(WorldStatements.SEL_WAYPOINT_SCRIPT_ID_BY_GUID);
|
||||
stmt.AddValue(0, id);
|
||||
SQLResult result = DB.World.Query(stmt);
|
||||
|
||||
if (result.IsEmpty())
|
||||
{
|
||||
stmt = DB.World.GetPreparedStatement(WorldStatements.INS_WAYPOINT_SCRIPT);
|
||||
stmt.AddValue(0, id);
|
||||
DB.World.Execute(stmt);
|
||||
|
||||
handler.SendSysMessage("|cff00ff00Wp Event: New waypoint event added: {0}|r", "", id);
|
||||
}
|
||||
else
|
||||
handler.SendSysMessage("|cff00ff00Wp Event: You have choosed an existing waypoint script guid: {0}|r", id);
|
||||
}
|
||||
else
|
||||
{
|
||||
stmt = DB.World.GetPreparedStatement(WorldStatements.SEL_WAYPOINT_SCRIPTS_MAX_ID);
|
||||
SQLResult result = DB.World.Query(stmt);
|
||||
id = result.Read<uint>(0);
|
||||
|
||||
stmt = DB.World.GetPreparedStatement(WorldStatements.INS_WAYPOINT_SCRIPT);
|
||||
stmt.AddValue(0, id + 1);
|
||||
DB.World.Execute(stmt);
|
||||
|
||||
handler.SendSysMessage("|cff00ff00Wp Event: New waypoint event added: |r|cff00ffff{0}|r", id + 1);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
if (show == "listid")
|
||||
{
|
||||
if (string.IsNullOrEmpty(arg_id))
|
||||
{
|
||||
handler.SendSysMessage("|cff33ffffWp Event: You must provide waypoint script id.|r");
|
||||
return true;
|
||||
}
|
||||
|
||||
id = uint.Parse(arg_id);
|
||||
|
||||
uint a2, a3, a4, a5, a6;
|
||||
float a8, a9, a10, a11;
|
||||
string a7;
|
||||
|
||||
stmt = DB.World.GetPreparedStatement(WorldStatements.SEL_WAYPOINT_SCRIPT_BY_ID);
|
||||
stmt.AddValue(0, id);
|
||||
SQLResult result = DB.World.Query(stmt);
|
||||
|
||||
if (result.IsEmpty())
|
||||
{
|
||||
handler.SendSysMessage("|cff33ffffWp Event: No waypoint scripts found on id: {0}|r", id);
|
||||
return true;
|
||||
}
|
||||
|
||||
do
|
||||
{
|
||||
a2 = result.Read<uint>(0);
|
||||
a3 = result.Read<uint>(1);
|
||||
a4 = result.Read<uint>(2);
|
||||
a5 = result.Read<uint>(3);
|
||||
a6 = result.Read<uint>(4);
|
||||
a7 = result.Read<string>(5);
|
||||
a8 = result.Read<float>(6);
|
||||
a9 = result.Read<float>(7);
|
||||
a10 = result.Read<float>(8);
|
||||
a11 = result.Read<float>(9);
|
||||
|
||||
handler.SendSysMessage("|cffff33ffid:|r|cff00ffff {0}|r|cff00ff00, guid: |r|cff00ffff{1}|r|cff00ff00, delay: |r|cff00ffff{2}|r|cff00ff00, command: |r|cff00ffff{3}|r|cff00ff00," +
|
||||
"datalong: |r|cff00ffff{4}|r|cff00ff00, datalong2: |r|cff00ffff{5}|r|cff00ff00, datatext: |r|cff00ffff{6}|r|cff00ff00, posx: |r|cff00ffff{7}|r|cff00ff00, " +
|
||||
"posy: |r|cff00ffff{8}|r|cff00ff00, posz: |r|cff00ffff{9}|r|cff00ff00, orientation: |r|cff00ffff{10}|r", id, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11);
|
||||
}
|
||||
while (result.NextRow());
|
||||
}
|
||||
|
||||
if (show == "del")
|
||||
{
|
||||
if (arg_id.IsEmpty())
|
||||
{
|
||||
handler.SendSysMessage("|cffff33ffERROR: Waypoint script guid not present.|r");
|
||||
return true;
|
||||
}
|
||||
|
||||
id = uint.Parse(arg_id);
|
||||
|
||||
stmt = DB.World.GetPreparedStatement(WorldStatements.SEL_WAYPOINT_SCRIPT_ID_BY_GUID);
|
||||
stmt.AddValue(0, id);
|
||||
SQLResult result = DB.World.Query(stmt);
|
||||
|
||||
if (!result.IsEmpty())
|
||||
{
|
||||
stmt = DB.World.GetPreparedStatement(WorldStatements.DEL_WAYPOINT_SCRIPT);
|
||||
stmt.AddValue(0, id);
|
||||
DB.World.Execute(stmt);
|
||||
|
||||
handler.SendSysMessage("|cff00ff00{0}{1}|r", "Wp Event: Waypoint script removed: ", id);
|
||||
}
|
||||
else
|
||||
handler.SendSysMessage("|cffff33ffWp Event: ERROR: you have selected a non existing script: {0}|r", id);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
if (show == "mod")
|
||||
{
|
||||
if (string.IsNullOrEmpty(arg_id))
|
||||
{
|
||||
handler.SendSysMessage("|cffff33ffERROR: Waypoint script guid not present.|r");
|
||||
return true;
|
||||
}
|
||||
|
||||
id = uint.Parse(arg_id);
|
||||
|
||||
if (id == 0)
|
||||
{
|
||||
handler.SendSysMessage("|cffff33ffERROR: No valid waypoint script id not present.|r");
|
||||
return true;
|
||||
}
|
||||
|
||||
string arg_string = args.NextString();
|
||||
if (string.IsNullOrEmpty(arg_string))
|
||||
{
|
||||
handler.SendSysMessage("|cffff33ffERROR: No argument present.|r");
|
||||
return true;
|
||||
}
|
||||
|
||||
if ((arg_string != "setid") && (arg_string != "delay") && (arg_string != "command")
|
||||
&& (arg_string != "datalong") && (arg_string != "datalong2") && (arg_string != "dataint") && (arg_string != "posx")
|
||||
&& (arg_string != "posy") && (arg_string != "posz") && (arg_string != "orientation"))
|
||||
{
|
||||
handler.SendSysMessage("|cffff33ffERROR: No valid argument present.|r");
|
||||
return true;
|
||||
}
|
||||
|
||||
string arg_3 = args.NextString();
|
||||
if (string.IsNullOrEmpty(arg_3))
|
||||
{
|
||||
handler.SendSysMessage("|cffff33ffERROR: No additional argument present.|r");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (arg_string == "setid")
|
||||
{
|
||||
uint newid = uint.Parse(arg_3);
|
||||
handler.SendSysMessage("|cff00ff00Wp Event: Waypoint script guid: {0}|r|cff00ffff id changed: |r|cff00ff00{1}|r", newid, id);
|
||||
|
||||
stmt = DB.World.GetPreparedStatement(WorldStatements.UPD_WAYPOINT_SCRIPT_ID);
|
||||
stmt.AddValue(0, newid);
|
||||
stmt.AddValue(1, id);
|
||||
|
||||
DB.World.Execute(stmt);
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
stmt = DB.World.GetPreparedStatement(WorldStatements.SEL_WAYPOINT_SCRIPT_ID_BY_GUID);
|
||||
stmt.AddValue(0, id);
|
||||
SQLResult result = DB.World.Query(stmt);
|
||||
|
||||
if (result.IsEmpty())
|
||||
{
|
||||
handler.SendSysMessage("|cffff33ffERROR: You have selected an non existing waypoint script guid.|r");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (arg_string == "posx")
|
||||
{
|
||||
stmt = DB.World.GetPreparedStatement(WorldStatements.UPD_WAYPOINT_SCRIPT_X);
|
||||
stmt.AddValue(0, float.Parse(arg_3));
|
||||
stmt.AddValue(1, id);
|
||||
DB.World.Execute(stmt);
|
||||
|
||||
handler.SendSysMessage("|cff00ff00Waypoint script:|r|cff00ffff {0}|r|cff00ff00 position_x updated.|r", id);
|
||||
return true;
|
||||
}
|
||||
else if (arg_string == "posy")
|
||||
{
|
||||
stmt = DB.World.GetPreparedStatement(WorldStatements.UPD_WAYPOINT_SCRIPT_Y);
|
||||
stmt.AddValue(0, float.Parse(arg_3));
|
||||
stmt.AddValue(1, id);
|
||||
DB.World.Execute(stmt);
|
||||
|
||||
handler.SendSysMessage("|cff00ff00Waypoint script: {0} position_y updated.|r", id);
|
||||
return true;
|
||||
}
|
||||
else if (arg_string == "posz")
|
||||
{
|
||||
stmt = DB.World.GetPreparedStatement(WorldStatements.UPD_WAYPOINT_SCRIPT_Z);
|
||||
stmt.AddValue(0, float.Parse(arg_3));
|
||||
stmt.AddValue(1, id);
|
||||
DB.World.Execute(stmt);
|
||||
|
||||
handler.SendSysMessage("|cff00ff00Waypoint script: |r|cff00ffff{0}|r|cff00ff00 position_z updated.|r", id);
|
||||
return true;
|
||||
}
|
||||
else if (arg_string == "orientation")
|
||||
{
|
||||
stmt = DB.World.GetPreparedStatement(WorldStatements.UPD_WAYPOINT_SCRIPT_O);
|
||||
stmt.AddValue(0, float.Parse(arg_3));
|
||||
stmt.AddValue(1, id);
|
||||
DB.World.Execute(stmt);
|
||||
|
||||
handler.SendSysMessage("|cff00ff00Waypoint script: |r|cff00ffff{0}|r|cff00ff00 orientation updated.|r", id);
|
||||
return true;
|
||||
}
|
||||
else if (arg_string == "dataint")
|
||||
{
|
||||
DB.World.Execute("UPDATE waypoint_scripts SET {0}='{1}' WHERE guid='{2}'", arg_string, uint.Parse(arg_3), id); // Query can't be a prepared statement
|
||||
|
||||
handler.SendSysMessage("|cff00ff00Waypoint script: |r|cff00ffff{0}|r|cff00ff00 dataint updated.|r", id);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
DB.World.Execute("UPDATE waypoint_scripts SET {0}='{1}' WHERE guid='{2}'", arg_string, arg_string, id); // Query can't be a prepared statement
|
||||
}
|
||||
}
|
||||
handler.SendSysMessage("|cff00ff00Waypoint script:|r|cff00ffff{0}:|r|cff00ff00 {1} updated.|r", id, arg_string);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("load", RBACPermissions.CommandWpLoad)]
|
||||
static bool HandleWpLoadCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
if (args.Empty())
|
||||
return false;
|
||||
|
||||
// optional
|
||||
string path_number = args.NextString();
|
||||
|
||||
uint pathid;
|
||||
ulong guidLow;
|
||||
Creature target = handler.getSelectedCreature();
|
||||
|
||||
// Did player provide a path_id?
|
||||
if (string.IsNullOrEmpty(path_number))
|
||||
return false;
|
||||
|
||||
if (!target)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.SelectCreature);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (target.GetEntry() == 1)
|
||||
{
|
||||
handler.SendSysMessage("|cffff33ffYou want to load path to a waypoint? Aren't you?|r");
|
||||
return false;
|
||||
}
|
||||
|
||||
pathid = uint.Parse(path_number);
|
||||
if (pathid == 0)
|
||||
{
|
||||
handler.SendSysMessage("|cffff33ffNo valid path number provided.|r");
|
||||
return true;
|
||||
}
|
||||
|
||||
guidLow = target.GetSpawnId();
|
||||
|
||||
PreparedStatement stmt = DB.World.GetPreparedStatement(WorldStatements.SEL_CREATURE_ADDON_BY_GUID);
|
||||
stmt.AddValue(0, guidLow);
|
||||
SQLResult result = DB.World.Query(stmt);
|
||||
|
||||
if (!result.IsEmpty())
|
||||
{
|
||||
stmt = DB.World.GetPreparedStatement(WorldStatements.UPD_CREATURE_ADDON_PATH);
|
||||
stmt.AddValue(0, pathid);
|
||||
stmt.AddValue(1, guidLow);
|
||||
}
|
||||
else
|
||||
{
|
||||
stmt = DB.World.GetPreparedStatement(WorldStatements.INS_CREATURE_ADDON);
|
||||
stmt.AddValue(0, guidLow);
|
||||
stmt.AddValue(1, pathid);
|
||||
}
|
||||
|
||||
DB.World.Execute(stmt);
|
||||
|
||||
stmt = DB.World.GetPreparedStatement(WorldStatements.UPD_CREATURE_MOVEMENT_TYPE);
|
||||
stmt.AddValue(0, (byte)MovementGeneratorType.Waypoint);
|
||||
stmt.AddValue(1, guidLow);
|
||||
|
||||
DB.World.Execute(stmt);
|
||||
|
||||
target.LoadPath(pathid);
|
||||
target.SetDefaultMovementType(MovementGeneratorType.Waypoint);
|
||||
target.GetMotionMaster().Initialize();
|
||||
target.Say("Path loaded.", Language.Universal);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("modify", RBACPermissions.CommandWpModify)]
|
||||
static bool HandleWpModifyCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
if (args.Empty())
|
||||
return false;
|
||||
|
||||
// first arg: add del text emote spell waittime move
|
||||
string show = args.NextString();
|
||||
if (string.IsNullOrEmpty(show))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check
|
||||
// Remember: "show" must also be the name of a column!
|
||||
if ((show != "delay") && (show != "action") && (show != "action_chance")
|
||||
&& (show != "move_flag") && (show != "del") && (show != "move"))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Next arg is: <PATHID> <WPNUM> <ARGUMENT>
|
||||
string arg_str;
|
||||
|
||||
// Did user provide a GUID
|
||||
// or did the user select a creature?
|
||||
// . variable lowguid is filled with the GUID of the NPC
|
||||
uint pathid;
|
||||
uint point;
|
||||
Creature target = handler.getSelectedCreature();
|
||||
|
||||
// User did select a visual waypoint?
|
||||
if (!target || target.GetEntry() != 1)
|
||||
{
|
||||
handler.SendSysMessage("|cffff33ffERROR: You must select a waypoint.|r");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check the creature
|
||||
PreparedStatement stmt = DB.World.GetPreparedStatement(WorldStatements.SEL_WAYPOINT_DATA_BY_WPGUID);
|
||||
stmt.AddValue(0, target.GetSpawnId());
|
||||
SQLResult result = DB.World.Query(stmt);
|
||||
|
||||
if (result.IsEmpty())
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.WaypointNotfoundsearch, target.GetGUID().ToString());
|
||||
// Select waypoint number from database
|
||||
// Since we compare float values, we have to deal with
|
||||
// some difficulties.
|
||||
// Here we search for all waypoints that only differ in one from 1 thousand
|
||||
// See also: http://dev.mysql.com/doc/refman/5.0/en/problems-with-float.html
|
||||
string maxDiff = "0.01";
|
||||
|
||||
stmt = DB.World.GetPreparedStatement(WorldStatements.SEL_WAYPOINT_DATA_BY_POS);
|
||||
stmt.AddValue(0, target.GetPositionX());
|
||||
stmt.AddValue(1, maxDiff);
|
||||
stmt.AddValue(2, target.GetPositionY());
|
||||
stmt.AddValue(3, maxDiff);
|
||||
stmt.AddValue(4, target.GetPositionZ());
|
||||
stmt.AddValue(5, maxDiff);
|
||||
result = DB.World.Query(stmt);
|
||||
|
||||
if (result.IsEmpty())
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.WaypointNotfounddbproblem, target.GetGUID().ToString());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
do
|
||||
{
|
||||
pathid = result.Read<uint>(0);
|
||||
point = result.Read<uint>(1);
|
||||
}
|
||||
while (result.NextRow());
|
||||
|
||||
// We have the waypoint number and the GUID of the "master npc"
|
||||
// Text is enclosed in "<>", all other arguments not
|
||||
arg_str = args.NextString();
|
||||
|
||||
// Check for argument
|
||||
if (show != "del" && show != "move" && arg_str == null)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.WaypointArgumentreq, show);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (show == "del")
|
||||
{
|
||||
handler.SendSysMessage("|cff00ff00DEBUG: wp modify del, PathID: |r|cff00ffff{0}|r", pathid);
|
||||
|
||||
target.DeleteFromDB();
|
||||
target.AddObjectToRemoveList();
|
||||
|
||||
stmt = DB.World.GetPreparedStatement(WorldStatements.DEL_WAYPOINT_DATA);
|
||||
stmt.AddValue(0, pathid);
|
||||
stmt.AddValue(1, point);
|
||||
DB.World.Execute(stmt);
|
||||
|
||||
stmt = DB.World.GetPreparedStatement(WorldStatements.UPD_WAYPOINT_DATA_POINT);
|
||||
stmt.AddValue(0, pathid);
|
||||
stmt.AddValue(1, point);
|
||||
DB.World.Execute(stmt);
|
||||
|
||||
handler.SendSysMessage(CypherStrings.WaypointRemoved);
|
||||
return true;
|
||||
} // del
|
||||
|
||||
if (show == "move")
|
||||
{
|
||||
handler.SendSysMessage("|cff00ff00DEBUG: wp move, PathID: |r|cff00ffff{0}|r", pathid);
|
||||
|
||||
Player chr = handler.GetSession().GetPlayer();
|
||||
Map map = chr.GetMap();
|
||||
// What to do:
|
||||
// Move the visual spawnpoint
|
||||
// Respawn the owner of the waypoints
|
||||
target.DeleteFromDB();
|
||||
target.AddObjectToRemoveList();
|
||||
|
||||
// re-create
|
||||
Creature wpCreature = new Creature();
|
||||
if (!wpCreature.Create(map.GenerateLowGuid(HighGuid.Creature), map, chr.GetPhaseMask(), 1, chr.GetPositionX(), chr.GetPositionY(), chr.GetPositionZ(), chr.GetOrientation()))
|
||||
{
|
||||
wpCreature.CopyPhaseFrom(chr);
|
||||
wpCreature.SaveToDB(map.GetId(), (1u << (int)map.GetSpawnMode()), chr.GetPhaseMask());
|
||||
// To call _LoadGoods(); _LoadQuests(); CreateTrainerSpells();
|
||||
/// @todo Should we first use "Create" then use "LoadFromDB"?
|
||||
if (!wpCreature.LoadCreatureFromDB(wpCreature.GetSpawnId(), map))
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.WaypointVpNotcreated, 1);
|
||||
return false;
|
||||
}
|
||||
|
||||
stmt = DB.World.GetPreparedStatement(WorldStatements.UPD_WAYPOINT_DATA_POSITION);
|
||||
stmt.AddValue(0, chr.GetPositionX());
|
||||
stmt.AddValue(1, chr.GetPositionY());
|
||||
stmt.AddValue(2, chr.GetPositionZ());
|
||||
stmt.AddValue(3, pathid);
|
||||
stmt.AddValue(4, point);
|
||||
DB.World.Execute(stmt);
|
||||
|
||||
handler.SendSysMessage(CypherStrings.WaypointChanged);
|
||||
}
|
||||
return true;
|
||||
} // move
|
||||
|
||||
if (string.IsNullOrEmpty(arg_str))
|
||||
{
|
||||
// show_str check for present in list of correct values, no sql injection possible
|
||||
DB.World.Execute("UPDATE waypoint_data SET {0}=null WHERE id='{1}' AND point='{2}'", show, pathid, point); // Query can't be a prepared statement
|
||||
}
|
||||
else
|
||||
{
|
||||
// show_str check for present in list of correct values, no sql injection possible
|
||||
DB.World.Execute("UPDATE waypoint_data SET {0}='{1}' WHERE id='{2}' AND point='{3}'", show, arg_str, pathid, point); // Query can't be a prepared statement
|
||||
}
|
||||
|
||||
handler.SendSysMessage(CypherStrings.WaypointChangedNo, show);
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("reload", RBACPermissions.CommandWpReload)]
|
||||
static bool HandleWpReloadCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
if (args.Empty())
|
||||
return false;
|
||||
|
||||
uint id = args.NextUInt32();
|
||||
|
||||
if (id == 0)
|
||||
return false;
|
||||
|
||||
handler.SendSysMessage("|cff00ff00Loading Path: |r|cff00ffff{0}|r", id);
|
||||
Global.WaypointMgr.ReloadPath(id);
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("show", RBACPermissions.CommandWpShow)]
|
||||
static bool HandleWpShowCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
if (args.Empty())
|
||||
return false;
|
||||
|
||||
// first arg: on, off, first, last
|
||||
string show = args.NextString();
|
||||
if (string.IsNullOrEmpty(show))
|
||||
return false;
|
||||
|
||||
// second arg: GUID (optional, if a creature is selected)
|
||||
string guid_str = args.NextString();
|
||||
|
||||
uint pathid = 0;
|
||||
Creature target = handler.getSelectedCreature();
|
||||
|
||||
// Did player provide a PathID?
|
||||
|
||||
if (string.IsNullOrEmpty(guid_str))
|
||||
{
|
||||
// No PathID provided
|
||||
// . Player must have selected a creature
|
||||
|
||||
if (!target)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.SelectCreature);
|
||||
return false;
|
||||
}
|
||||
|
||||
pathid = target.GetWaypointPath();
|
||||
}
|
||||
else
|
||||
{
|
||||
// PathID provided
|
||||
// Warn if player also selected a creature
|
||||
// . Creature selection is ignored <-
|
||||
if (target)
|
||||
handler.SendSysMessage(CypherStrings.WaypointCreatselected);
|
||||
|
||||
pathid = uint.Parse(guid_str);
|
||||
}
|
||||
|
||||
// Show info for the selected waypoint
|
||||
if (show == "info")
|
||||
{
|
||||
// Check if the user did specify a visual waypoint
|
||||
if (!target || target.GetEntry() != 1)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.WaypointVpSelect);
|
||||
return false;
|
||||
}
|
||||
|
||||
PreparedStatement stmt = DB.World.GetPreparedStatement(WorldStatements.SEL_WAYPOINT_DATA_ALL_BY_WPGUID);
|
||||
stmt.AddValue(0, target.GetSpawnId());
|
||||
SQLResult result = DB.World.Query(stmt);
|
||||
|
||||
if (result.IsEmpty())
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.WaypointNotfounddbproblem, target.GetSpawnId());
|
||||
return true;
|
||||
}
|
||||
|
||||
handler.SendSysMessage("|cff00ffffDEBUG: wp show info:|r");
|
||||
do
|
||||
{
|
||||
pathid = result.Read<uint>(0);
|
||||
uint point = result.Read<uint>(1);
|
||||
uint delay = result.Read<uint>(2);
|
||||
uint flag = result.Read<uint>(3);
|
||||
uint ev_id = result.Read<uint>(4);
|
||||
uint ev_chance = result.Read<uint>(5);
|
||||
|
||||
handler.SendSysMessage("|cff00ff00Show info: for current point: |r|cff00ffff{0}|r|cff00ff00, Path ID: |r|cff00ffff{1}|r", point, pathid);
|
||||
handler.SendSysMessage("|cff00ff00Show info: delay: |r|cff00ffff{0}|r", delay);
|
||||
handler.SendSysMessage("|cff00ff00Show info: Move flag: |r|cff00ffff{0}|r", flag);
|
||||
handler.SendSysMessage("|cff00ff00Show info: Waypoint event: |r|cff00ffff{0}|r", ev_id);
|
||||
handler.SendSysMessage("|cff00ff00Show info: Event chance: |r|cff00ffff{0}|r", ev_chance);
|
||||
}
|
||||
while (result.NextRow());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
if (show == "on")
|
||||
{
|
||||
PreparedStatement stmt = DB.World.GetPreparedStatement(WorldStatements.SEL_WAYPOINT_DATA_POS_BY_ID);
|
||||
stmt.AddValue(0, pathid);
|
||||
SQLResult result = DB.World.Query(stmt);
|
||||
|
||||
if (result.IsEmpty())
|
||||
{
|
||||
handler.SendSysMessage("|cffff33ffPath no found.|r");
|
||||
return false;
|
||||
}
|
||||
|
||||
handler.SendSysMessage("|cff00ff00DEBUG: wp on, PathID: |cff00ffff{0}|r", pathid);
|
||||
|
||||
// Delete all visuals for this NPC
|
||||
stmt = DB.World.GetPreparedStatement(WorldStatements.SEL_WAYPOINT_DATA_WPGUID_BY_ID);
|
||||
stmt.AddValue(0, pathid);
|
||||
SQLResult result2 = DB.World.Query(stmt);
|
||||
|
||||
if (!result2.IsEmpty())
|
||||
{
|
||||
bool hasError = false;
|
||||
do
|
||||
{
|
||||
ulong wpguid = result2.Read<ulong>(0);
|
||||
|
||||
Creature creature = handler.GetCreatureFromPlayerMapByDbGuid(wpguid);
|
||||
if (!creature)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.WaypointNotremoved, wpguid);
|
||||
hasError = true;
|
||||
|
||||
stmt = DB.World.GetPreparedStatement(WorldStatements.DEL_CREATURE);
|
||||
stmt.AddValue(0, wpguid);
|
||||
DB.World.Execute(stmt);
|
||||
}
|
||||
else
|
||||
{
|
||||
creature.CombatStop();
|
||||
creature.DeleteFromDB();
|
||||
creature.AddObjectToRemoveList();
|
||||
}
|
||||
|
||||
}
|
||||
while (result2.NextRow());
|
||||
|
||||
if (hasError)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.WaypointToofar1);
|
||||
handler.SendSysMessage(CypherStrings.WaypointToofar2);
|
||||
handler.SendSysMessage(CypherStrings.WaypointToofar3);
|
||||
}
|
||||
}
|
||||
|
||||
do
|
||||
{
|
||||
uint point = result.Read<uint>(0);
|
||||
float x = result.Read<float>(1);
|
||||
float y = result.Read<float>(2);
|
||||
float z = result.Read<float>(3);
|
||||
|
||||
uint id = 1;
|
||||
|
||||
Player chr = handler.GetSession().GetPlayer();
|
||||
Map map = chr.GetMap();
|
||||
float o = chr.GetOrientation();
|
||||
|
||||
Creature wpCreature = new Creature();
|
||||
if (!wpCreature.Create(map.GenerateLowGuid(HighGuid.Creature), map, chr.GetPhaseMask(), id, x, y, z, o))
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.WaypointVpNotcreated, id);
|
||||
return false;
|
||||
}
|
||||
|
||||
wpCreature.CopyPhaseFrom(chr);
|
||||
wpCreature.SaveToDB(map.GetId(), (1u << (int)map.GetSpawnMode()), chr.GetPhaseMask());
|
||||
|
||||
// Set "wpguid" column to the visual waypoint
|
||||
stmt = DB.World.GetPreparedStatement(WorldStatements.UPD_WAYPOINT_DATA_WPGUID);
|
||||
stmt.AddValue(0, wpCreature.GetSpawnId());
|
||||
stmt.AddValue(1, pathid);
|
||||
stmt.AddValue(2, point);
|
||||
DB.World.Execute(stmt);
|
||||
|
||||
// To call _LoadGoods(); _LoadQuests(); CreateTrainerSpells();
|
||||
if (!wpCreature.LoadCreatureFromDB(wpCreature.GetSpawnId(), map))
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.WaypointVpNotcreated, id);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (target)
|
||||
{
|
||||
wpCreature.SetDisplayId(target.GetDisplayId());
|
||||
wpCreature.SetObjectScale(0.5f);
|
||||
wpCreature.SetLevel(Math.Min(point, SharedConst.StrongMaxLevel));
|
||||
}
|
||||
}
|
||||
while (result.NextRow());
|
||||
|
||||
handler.SendSysMessage("|cff00ff00Showing the current creature's path.|r");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (show == "first")
|
||||
{
|
||||
handler.SendSysMessage("|cff00ff00DEBUG: wp first, pathid: {0}|r", pathid);
|
||||
|
||||
PreparedStatement stmt = DB.World.GetPreparedStatement(WorldStatements.SEL_WAYPOINT_DATA_POS_FIRST_BY_ID);
|
||||
stmt.AddValue(0, pathid);
|
||||
SQLResult result = DB.World.Query(stmt);
|
||||
|
||||
if (result.IsEmpty())
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.WaypointNotfound, pathid);
|
||||
return false;
|
||||
}
|
||||
|
||||
float x = result.Read<float>(0);
|
||||
float y = result.Read<float>(1);
|
||||
float z = result.Read<float>(2);
|
||||
uint id = 1;
|
||||
|
||||
Player chr = handler.GetSession().GetPlayer();
|
||||
float o = chr.GetOrientation();
|
||||
Map map = chr.GetMap();
|
||||
|
||||
Creature creature = new Creature();
|
||||
if (!creature.Create(map.GenerateLowGuid(HighGuid.Creature), map, chr.GetPhaseMask(), id, x, y, z, o))
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.WaypointVpNotcreated, id);
|
||||
return false;
|
||||
}
|
||||
|
||||
creature.CopyPhaseFrom(chr);
|
||||
|
||||
creature.SaveToDB(map.GetId(), (uint)(1 << (int)map.GetSpawnMode()), chr.GetPhaseMask());
|
||||
if (!creature.LoadCreatureFromDB(creature.GetSpawnId(), map))
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.WaypointVpNotcreated, id);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (target)
|
||||
{
|
||||
creature.SetDisplayId(target.GetDisplayId());
|
||||
creature.SetObjectScale(0.5f);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
if (show == "last")
|
||||
{
|
||||
handler.SendSysMessage("|cff00ff00DEBUG: wp last, PathID: |r|cff00ffff{0}|r", pathid);
|
||||
|
||||
PreparedStatement stmt = DB.World.GetPreparedStatement(WorldStatements.SEL_WAYPOINT_DATA_POS_LAST_BY_ID);
|
||||
stmt.AddValue(0, pathid);
|
||||
SQLResult result = DB.World.Query(stmt);
|
||||
|
||||
if (result.IsEmpty())
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.WaypointNotfoundlast, pathid);
|
||||
return false;
|
||||
}
|
||||
|
||||
float x = result.Read<float>(0);
|
||||
float y = result.Read<float>(1);
|
||||
float z = result.Read<float>(2);
|
||||
float o = result.Read<float>(3);
|
||||
uint id = 1;
|
||||
|
||||
Player chr = handler.GetSession().GetPlayer();
|
||||
Map map = chr.GetMap();
|
||||
|
||||
Creature creature = new Creature();
|
||||
if (!creature.Create(map.GenerateLowGuid(HighGuid.Creature), map, chr.GetPhaseMask(), id, x, y, z, o))
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.WaypointNotcreated, id);
|
||||
return false;
|
||||
}
|
||||
|
||||
creature.CopyPhaseFrom(chr);
|
||||
|
||||
creature.SaveToDB(map.GetId(), (uint)(1 << (int)map.GetSpawnMode()), chr.GetPhaseMask());
|
||||
if (!creature.LoadCreatureFromDB(creature.GetSpawnId(), map))
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.WaypointNotcreated, id);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (target)
|
||||
{
|
||||
creature.SetDisplayId(target.GetDisplayId());
|
||||
creature.SetObjectScale(0.5f);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
if (show == "off")
|
||||
{
|
||||
PreparedStatement stmt = DB.World.GetPreparedStatement(WorldStatements.SEL_CREATURE_BY_ID);
|
||||
stmt.AddValue(0, 1);
|
||||
SQLResult result = DB.World.Query(stmt);
|
||||
|
||||
if (result.IsEmpty())
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.WaypointVpNotfound);
|
||||
return false;
|
||||
}
|
||||
bool hasError = false;
|
||||
do
|
||||
{
|
||||
ulong lowguid = result.Read<ulong>(0);
|
||||
|
||||
Creature creature = handler.GetCreatureFromPlayerMapByDbGuid(lowguid);
|
||||
if (!creature)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.WaypointNotremoved, lowguid);
|
||||
hasError = true;
|
||||
|
||||
stmt = DB.World.GetPreparedStatement(WorldStatements.DEL_CREATURE);
|
||||
stmt.AddValue(0, lowguid);
|
||||
DB.World.Execute(stmt);
|
||||
}
|
||||
else
|
||||
{
|
||||
creature.CombatStop();
|
||||
creature.DeleteFromDB();
|
||||
creature.AddObjectToRemoveList();
|
||||
}
|
||||
}
|
||||
while (result.NextRow());
|
||||
// set "wpguid" column to "empty" - no visual waypoint spawned
|
||||
stmt = DB.World.GetPreparedStatement(WorldStatements.UPD_WAYPOINT_DATA_ALL_WPGUID);
|
||||
|
||||
DB.World.Execute(stmt);
|
||||
//DB.World.PExecute("UPDATE creature_movement SET wpguid = '0' WHERE wpguid <> '0'");
|
||||
|
||||
if (hasError)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.WaypointToofar1);
|
||||
handler.SendSysMessage(CypherStrings.WaypointToofar2);
|
||||
handler.SendSysMessage(CypherStrings.WaypointToofar3);
|
||||
}
|
||||
|
||||
handler.SendSysMessage(CypherStrings.WaypointVpAllremoved);
|
||||
return true;
|
||||
}
|
||||
|
||||
handler.SendSysMessage("|cffff33ffDEBUG: wpshow - no valid command found|r");
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("unload", RBACPermissions.CommandWpUnload)]
|
||||
static bool HandleWpUnLoadCommand(StringArguments args, CommandHandler handler)
|
||||
{
|
||||
Creature target = handler.getSelectedCreature();
|
||||
if (!target)
|
||||
{
|
||||
handler.SendSysMessage("|cff33ffffYou must select a target.|r");
|
||||
return true;
|
||||
}
|
||||
|
||||
ulong guidLow = target.GetSpawnId();
|
||||
if (guidLow == 0)
|
||||
{
|
||||
handler.SendSysMessage("|cffff33ffTarget is not saved to DB.|r");
|
||||
return true;
|
||||
}
|
||||
|
||||
CreatureAddon addon = Global.ObjectMgr.GetCreatureAddon(guidLow);
|
||||
if (addon == null || addon.path_id == 0)
|
||||
{
|
||||
handler.SendSysMessage("|cffff33ffTarget does not have a loaded path.|r");
|
||||
return true;
|
||||
}
|
||||
|
||||
PreparedStatement stmt = DB.World.GetPreparedStatement(WorldStatements.DEL_CREATURE_ADDON);
|
||||
stmt.AddValue(0, guidLow);
|
||||
DB.World.Execute(stmt);
|
||||
|
||||
target.UpdateWaypointID(0);
|
||||
|
||||
stmt = DB.World.GetPreparedStatement(WorldStatements.UPD_CREATURE_MOVEMENT_TYPE);
|
||||
stmt.AddValue(0, (byte)MovementGeneratorType.Idle);
|
||||
stmt.AddValue(1, guidLow);
|
||||
DB.World.Execute(stmt);
|
||||
|
||||
target.LoadPath(0);
|
||||
target.SetDefaultMovementType(MovementGeneratorType.Idle);
|
||||
target.GetMotionMaster().MoveTargetedHome();
|
||||
target.GetMotionMaster().Initialize();
|
||||
target.Say("Path unloaded.", Language.Universal);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user