Esempio n. 1
0
            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);
                }

                if (!ulong.TryParse(id, out ulong guidLow) || 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);
                }

                if (!int.TryParse(type, out int objectType))
                {
                    return(false);
                }

                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);
                }

                if (!uint.TryParse(state, out uint objectState))
                {
                    return(false);
                }

                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);
            }
Esempio n. 2
0
        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);
            }

            if (!uint.TryParse(factionTxt, out uint factionId))
            {
                return(false);
            }

            int    amount  = 0;
            string rankTxt = args.NextString();

            if (factionId == 0 || !int.TryParse(rankTxt, out amount))
            {
                return(false);
            }

            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))
                        {
                            if (!int.TryParse(deltaTxt, out int delta) || 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);
        }
Esempio n. 3
0
        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);

            float x, y, z;

            player.GetPosition(out x, out y, out z);

            handler.SendSysMessage("{0:D4}{1:D2}{2:D2}.mmtile", player.GetMapId(), gy, gx);
            handler.SendSysMessage("gridloc [{0}, {1}]", gx, gy);

            // calculate navmesh tile location
            uint terrainMapId = PhasingHandler.GetTerrainMapId(player.GetPhaseShift(), player.GetMap(), x, y);

            Detour.dtNavMesh      navmesh      = Global.MMapMgr.GetNavMesh(terrainMapId);
            Detour.dtNavMeshQuery navmeshquery = Global.MMapMgr.GetNavMeshQuery(terrainMapId, player.GetInstanceId());
            if (navmesh == null || navmeshquery == null)
            {
                handler.SendSysMessage("NavMesh not loaded for current map.");
                return(true);
            }

            float[] min      = navmesh.getParams().orig;
            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);
        }
Esempio n. 4
0
        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);
        }
Esempio n. 5
0
        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);
            }

            if (!ushort.TryParse(args.NextString(), out ushort mark))
            {
                mark = 65535;
            }

            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);
        }
Esempio n. 6
0
            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);
                }

                if (!ulong.TryParse(id, out ulong guidLow) || 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);
                }

                if (!int.TryParse(type, out int objectType))
                {
                    return(false);
                }

                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);
                }

                if (!uint.TryParse(state, out uint objectState))
                {
                    return(false);
                }

                switch (objectType)
                {
                case 0:
                    obj.SetGoState((GameObjectState)objectState);
                    break;

                case 1:
                    obj.SetGoType((GameObjectTypes)objectState);
                    break;

                case 2:
                    obj.SetGoArtKit((byte)objectState);
                    break;

                case 3:
                    obj.SetGoAnimProgress(objectState);
                    break;

                case 4:
                    obj.SendCustomAnim(objectState);
                    break;

                case 5:
                    if (objectState < 0 || objectState > (uint)GameObjectDestructibleState.Rebuilding)
                    {
                        return(false);
                    }

                    obj.SetDestructibleState((GameObjectDestructibleState)objectState);
                    break;

                default:
                    break;
                }

                handler.SendSysMessage("Set gobject type {0} state {1}", objectType, objectState);
                return(true);
            }
Esempio n. 7
0
        static bool HandleGroupListCommand(StringArguments args, CommandHandler handler)
        {
            // Get ALL the variables!
            Player     playerTarget;
            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 (Global.CharacterCacheStorage.GetCharacterNameByGuid(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 f**k, 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);
                string phases = "";
                if (p && p.IsInWorld)
                {
                    // ... than, it prints information like "is online", where he is, etc...
                    onlineState = "online";
                    phases      = PhasingHandler.FormatPhases(p.GetPhaseShift());

                    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";
                }

                // Now we can print those informations for every single member of each group!
                handler.SendSysMessage(CypherStrings.GroupPlayerNameGuid, slot.name, onlineState,
                                       zoneName, phases, slot.guid.ToString(), flags, LFGQueue.GetRolesString(slot.roles));
            }

            // And finish after every iterator is done.
            return(true);
        }
Esempio n. 8
0
        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);
        }
Esempio n. 9
0
        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);
        }
Esempio n. 10
0
        static bool HandleGameObjectInfoCommand(StringArguments args, CommandHandler handler)
        {
            if (args.Empty())
            {
                return(false);
            }

            string param1 = handler.ExtractKeyFromLink(args, "Hgameobject_entry");

            if (param1.IsEmpty())
            {
                return(false);
            }

            uint entry;

            if (param1.Equals("guid"))
            {
                string cValue = handler.ExtractKeyFromLink(args, "Hgameobject");
                if (cValue.IsEmpty())
                {
                    return(false);
                }

                if (!ulong.TryParse(cValue, out ulong guidLow))
                {
                    return(false);
                }

                GameObjectData data = Global.ObjectMgr.GetGameObjectData(guidLow);
                if (data == null)
                {
                    return(false);
                }
                entry = data.Id;
            }
            else
            {
                if (!uint.TryParse(param1, out entry))
                {
                    return(false);
                }
            }

            GameObjectTemplate gameObjectInfo = Global.ObjectMgr.GetGameObjectTemplate(entry);

            if (gameObjectInfo == null)
            {
                return(false);
            }

            GameObject thisGO = null;

            if (handler.GetSession().GetPlayer())
            {
                thisGO = handler.GetSession().GetPlayer().FindNearestGameObject(entry, 30);
            }
            else if (handler.GetSelectedObject() != null && handler.GetSelectedObject().IsTypeId(TypeId.GameObject))
            {
                thisGO = handler.GetSelectedObject().ToGameObject();
            }

            GameObjectTypes type      = gameObjectInfo.type;
            uint            displayId = gameObjectInfo.displayId;
            string          name      = gameObjectInfo.name;
            uint            lootId    = gameObjectInfo.GetLootId();

            // If we have a real object, send some info about it
            if (thisGO != null)
            {
                handler.SendSysMessage(CypherStrings.SpawninfoGuidinfo, thisGO.GetGUID().ToString());
                handler.SendSysMessage(CypherStrings.SpawninfoSpawnidLocation, thisGO.GetSpawnId(), thisGO.GetPositionX(), thisGO.GetPositionY(), thisGO.GetPositionZ());
                Player player = handler.GetSession().GetPlayer();
                if (player != null)
                {
                    Position playerPos = player.GetPosition();
                    float    dist      = thisGO.GetExactDist(playerPos);
                    handler.SendSysMessage(CypherStrings.SpawninfoDistancefromplayer, dist);
                }
            }
            handler.SendSysMessage(CypherStrings.GoinfoEntry, entry);
            handler.SendSysMessage(CypherStrings.GoinfoType, type);
            handler.SendSysMessage(CypherStrings.GoinfoLootid, lootId);
            handler.SendSysMessage(CypherStrings.GoinfoDisplayid, displayId);
            WorldObject obj = handler.GetSelectedObject();

            if (obj != null)
            {
                if (obj.IsGameObject() && obj.ToGameObject().GetGameObjectData() != null && obj.ToGameObject().GetGameObjectData().spawnGroupData.groupId != 0)
                {
                    SpawnGroupTemplateData groupData = obj.ToGameObject().GetGameObjectData().spawnGroupData;
                    handler.SendSysMessage(CypherStrings.SpawninfoGroupId, groupData.name, groupData.groupId, groupData.flags, obj.GetMap().IsSpawnGroupActive(groupData.groupId));
                }
                if (obj.IsGameObject())
                {
                    handler.SendSysMessage(CypherStrings.SpawninfoCompatibilityMode, obj.ToGameObject().GetRespawnCompatibilityMode());
                }
            }
            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);
        }
Esempio n. 11
0
        static bool HandleGroupSummonCommand(CommandHandler handler, StringArguments args)
        {
            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();
            Map    gmMap           = gmPlayer.GetMap();
            bool   toInstance      = gmMap.Instanceable();
            bool   onlyLocalSummon = false;

            // make sure people end up on our instance of the map, disallow far summon if intended destination is different from actual destination
            // note: we could probably relax this further by checking permanent saves and the like, but eh
            // :close enough:
            if (toInstance)
            {
                Player groupLeader = Global.ObjAccessor.GetPlayer(gmMap, group.GetLeaderGUID());
                if (!groupLeader || (groupLeader.GetMapId() != gmMap.GetId()) || (groupLeader.GetInstanceId() != gmMap.GetInstanceId()))
                {
                    handler.SendSysMessage(CypherStrings.PartialGroupSummon);
                    onlyLocalSummon = true;
                }
            }

            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))
                {
                    continue;
                }

                string plNameLink = handler.GetNameLink(player);

                if (player.IsBeingTeleported())
                {
                    handler.SendSysMessage(CypherStrings.IsTeleported, plNameLink);
                    continue;
                }

                if (toInstance)
                {
                    Map playerMap = player.GetMap();

                    if ((onlyLocalSummon || (playerMap.Instanceable() && playerMap.GetId() == gmMap.GetId())) &&        // either no far summon allowed or we're in the same map as player (no map switch)
                        ((playerMap.GetId() != gmMap.GetId()) || (playerMap.GetInstanceId() != gmMap.GetInstanceId()))) // so we need to be in the same map and instance of the map, otherwise skip
                    {
                        // cannot summon from instance to instance
                        handler.SendSysMessage(CypherStrings.CannotSummonInstInst, plNameLink);
                        continue;
                    }
                }

                handler.SendSysMessage(CypherStrings.Summoning, plNameLink, "");
                if (handler.NeedReportToTarget(player))
                {
                    player.SendSysMessage(CypherStrings.SummonedBy, handler.GetNameLink());
                }

                // stop flight if need
                if (player.IsInFlight())
                {
                    player.FinishTaxiFlight();
                }
                else
                {
                    player.SaveRecallPosition(); // save only in non-flight case
                }
                // before GM
                float x, y, z;
                gmPlayer.GetClosePoint(out x, out y, out z, player.GetCombatReach());
                player.TeleportTo(gmPlayer.GetMapId(), x, y, z, player.GetOrientation());
            }

            return(true);
        }
Esempio n. 12
0
            static bool HandleAccountSetSecLevelCommand(CommandHandler handler, string accountName, byte securityLevel, int?realmId)
            {
                uint accountId;

                if (!accountName.IsEmpty())
                {
                    accountId = Global.AccountMgr.GetId(accountName);
                    if (accountId == 0)
                    {
                        handler.SendSysMessage(CypherStrings.AccountNotExist, accountName);
                        return(false);
                    }
                }
                else
                {
                    Player player = handler.GetSelectedPlayer();
                    if (!player)
                    {
                        return(false);
                    }

                    accountId = player.GetSession().GetAccountId();
                    Global.AccountMgr.GetName(accountId, out accountName);
                }

                if (securityLevel > (uint)AccountTypes.Console)
                {
                    handler.SendSysMessage(CypherStrings.BadValue);
                    return(false);
                }

                int realmID = -1;

                if (realmId.HasValue)
                {
                    realmID = realmId.Value;
                }

                AccountTypes playerSecurity;

                if (handler.GetSession() != null)
                {
                    playerSecurity = Global.AccountMgr.GetSecurity(handler.GetSession().GetAccountId(), realmID);
                }
                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
                AccountTypes targetSecurity = Global.AccountMgr.GetSecurity(accountId, realmID);

                if (targetSecurity >= playerSecurity || (AccountTypes)securityLevel >= 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 (realmID == -1 && !Global.AccountMgr.IsConsoleAccount(playerSecurity))
                {
                    stmt = DB.Login.GetPreparedStatement(LoginStatements.SEL_ACCOUNT_ACCESS_SECLEVEL_TEST);
                    stmt.AddValue(0, accountId);
                    stmt.AddValue(1, securityLevel);

                    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 (realmID < -1)
                {
                    handler.SendSysMessage(CypherStrings.InvalidRealmid);
                    return(false);
                }

                Global.AccountMgr.UpdateAccountAccess(null, accountId, (byte)securityLevel, realmID);

                handler.SendSysMessage(CypherStrings.YouChangeSecurity, accountName, securityLevel);
                return(true);
            }
Esempio n. 13
0
        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);
            }

            if (!uint.TryParse(param1, out encounterId))
            {
                return(false);
            }

            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);
        }
Esempio n. 14
0
        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);
        }
Esempio n. 15
0
        static bool HandleGameObjectInfoCommand(StringArguments args, CommandHandler handler)
        {
            uint            entry     = 0;
            GameObjectTypes type      = 0;
            uint            displayId = 0;
            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);
                }

                if (!ulong.TryParse(cValue, out ulong guidLow))
                {
                    return(false);
                }

                GameObjectData data = Global.ObjectMgr.GetGOData(guidLow);
                if (data == null)
                {
                    return(false);
                }
                entry = data.id;
            }
            else
            {
                if (!uint.TryParse(param1, out entry))
                {
                    return(false);
                }
            }

            GameObjectTemplate gameObjectInfo = Global.ObjectMgr.GetGameObjectTemplate(entry);

            if (gameObjectInfo == null)
            {
                return(false);
            }

            type      = gameObjectInfo.type;
            displayId = gameObjectInfo.displayId;
            string 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);
        }
Esempio n. 16
0
            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);
            }
Esempio n. 17
0
            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 idStr = handler.ExtractKeyFromLink(args, "Hgameobject_entry");

                if (string.IsNullOrEmpty(idStr))
                {
                    return(false);
                }

                if (!uint.TryParse(idStr, out uint objectId) || 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 = GameObject.CreateGameObject(objectInfo.entry, map, player, Quaternion.fromEulerAnglesZYX(player.GetOrientation(), 0.0f, 0.0f), 255, GameObjectState.Ready);

                if (!obj)
                {
                    return(false);
                }

                PhasingHandler.InheritPhaseShift(obj, player);

                if (spawntimeSecs != 0)
                {
                    obj.SetRespawnTime((int)spawntimeSecs);
                }

                // fill the gameobject data and save to the db
                obj.SaveToDB(map.GetId(), new List <Difficulty>()
                {
                    map.GetDifficultyID()
                });
                ulong spawnId = obj.GetSpawnId();

                // this will generate a new guid if the object is in an instance
                obj = GameObject.CreateGameObjectFromDB(spawnId, map);
                if (!obj)
                {
                    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);
            }
Esempio n. 18
0
            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);
                }

                if (!byte.TryParse(exp, out byte expansion))
                {
                    return(false);
                }

                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);
            }
Esempio n. 19
0
        static bool HandleCharacterChangeAccountCommand(StringArguments args, CommandHandler handler)
        {
            string playerNameStr;
            string accountName;

            handler.ExtractOptFirstArg(args, out playerNameStr, out accountName);
            if (accountName.IsEmpty())
            {
                return(false);
            }

            ObjectGuid targetGuid;
            string     targetName;

            if (!handler.ExtractPlayerTarget(new StringArguments(playerNameStr), out _, out targetGuid, out targetName))
            {
                return(false);
            }

            CharacterCacheEntry characterInfo = Global.CharacterCacheStorage.GetCharacterCacheByGuid(targetGuid);

            if (characterInfo == null)
            {
                handler.SendSysMessage(CypherStrings.PlayerNotFound);
                return(false);
            }

            uint oldAccountId = characterInfo.AccountId;
            uint newAccountId = oldAccountId;

            PreparedStatement stmt = DB.Login.GetPreparedStatement(LoginStatements.SEL_ACCOUNT_ID_BY_NAME);

            stmt.AddValue(0, accountName);
            SQLResult result = DB.Login.Query(stmt);

            if (!result.IsEmpty())
            {
                newAccountId = result.Read <uint>(0);
            }
            else
            {
                handler.SendSysMessage(CypherStrings.AccountNotExist, accountName);
                return(false);
            }

            // nothing to do :)
            if (newAccountId == oldAccountId)
            {
                return(true);
            }

            uint charCount = Global.AccountMgr.GetCharactersCount(newAccountId);

            if (charCount != 0)
            {
                if (charCount >= WorldConfig.GetIntValue(WorldCfg.CharactersPerRealm))
                {
                    handler.SendSysMessage(CypherStrings.AccountCharacterListFull, accountName, newAccountId);
                    return(false);
                }
            }

            stmt = DB.Characters.GetPreparedStatement(CharStatements.UPD_ACCOUNT_BY_GUID);
            stmt.AddValue(0, newAccountId);
            stmt.AddValue(1, targetGuid.GetCounter());
            DB.Characters.DirectExecute(stmt);

            Global.WorldMgr.UpdateRealmCharCount(oldAccountId);
            Global.WorldMgr.UpdateRealmCharCount(newAccountId);

            Global.CharacterCacheStorage.UpdateCharacterAccountId(targetGuid, newAccountId);

            handler.SendSysMessage(CypherStrings.ChangeAccountSuccess, targetName, accountName);

            string       logString = $"changed ownership of player {targetName} ({targetGuid.ToString()}) from account {oldAccountId} to account {newAccountId}";
            WorldSession session   = handler.GetSession();

            if (session != null)
            {
                Player player = session.GetPlayer();
                if (player != null)
                {
                    Log.outCommand(session.GetAccountId(), $"GM {player.GetName()} (Account: {session.GetAccountId()}) {logString}");
                }
            }
            else
            {
                Log.outCommand(0, $"{handler.GetCypherString(CypherStrings.Console)} {logString}");
            }
            return(true);
        }
Esempio n. 20
0
            static bool HandleSetGmLevelCommand(StringArguments args, CommandHandler handler)
            {
                if (args.Empty())
                {
                    handler.SendSysMessage(CypherStrings.CmdSyntax);
                    return(false);
                }

                string       targetAccountName = "";
                uint         targetAccountId;
                AccountTypes targetSecurity;
                uint         gm;

                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.
                if (!uint.TryParse(isAccountNameGiven ? arg2 : arg1, out gm))
                {
                    return(false);
                }

                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();
                if (!int.TryParse(isAccountNameGiven ? arg3 : arg2, out int gmRealmID))
                {
                    return(false);
                }

                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);
            }
Esempio n. 21
0
        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);
        }
Esempio n. 22
0
                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);
                }
Esempio n. 23
0
        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);
        }
Esempio n. 24
0
        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);
            }

            if (!ulong.TryParse(id, out ulong guidLow) || 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 (!float.TryParse(toX, out x))
                {
                    return(false);
                }

                if (!float.TryParse(toY, out y))
                {
                    return(false);
                }

                if (!float.TryParse(toZ, out z))
                {
                    return(false);
                }

                if (!GridDefines.IsValidMapCoord(obj.GetMapId(), x, y, z))
                {
                    handler.SendSysMessage(CypherStrings.InvalidTargetCoord, x, y, obj.GetMapId());
                    return(false);
                }
            }

            Map map = obj.GetMap();

            obj.Relocate(x, y, z, obj.GetOrientation());
            obj.SaveToDB();

            // Generate a completely new spawn with new guid
            // client caches recently deleted objects and brings them back to life
            // when CreateObject block for this guid is received again
            // however it entirely skips parsing that block and only uses already known location
            obj.Delete();

            obj = GameObject.CreateGameObjectFromDB(guidLow, map);
            if (!obj)
            {
                return(false);
            }

            handler.SendSysMessage(CypherStrings.CommandMoveobjmessage, obj.GetSpawnId(), obj.GetGoInfo().name, obj.GetGUID().ToString());

            return(true);
        }
Esempio n. 25
0
        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)
            {
                long newmoney = (long)targetMoney + 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 > (long)PlayerConst.MaxMoneyAmount)
                    {
                        newmoney = (long)PlayerConst.MaxMoneyAmount;
                    }

                    handler.SendSysMessage(CypherStrings.YouTakeMoney, moneyToAddMsg, handler.GetNameLink(target));
                    if (handler.needReportToTarget(target))
                    {
                        target.SendSysMessage(CypherStrings.YoursMoneyTaken, handler.GetNameLink(), moneyToAddMsg);
                    }
                    target.SetMoney((ulong)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 = (long)Math.Min((ulong)moneyToAdd, (PlayerConst.MaxMoneyAmount - targetMoney));

                target.ModifyMoney(moneyToAdd);
            }

            Log.outDebug(LogFilter.ChatSystem, Global.ObjectMgr.GetCypherString(CypherStrings.NewMoney), targetMoney, moneyToAdd, target.GetMoney());
            return(true);
        }
Esempio n. 26
0
        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);
                }

                if (!uint.TryParse(idStr, out uint objectId) || 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);
        }
Esempio n. 27
0
        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);
        }
Esempio n. 28
0
        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);
            }

            if (!ulong.TryParse(id, out ulong guidLow) || 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())
            {
                if (!float.TryParse(orientation, out oz))
                {
                    return(false);
                }

                orientation = args.NextString();
                if (!orientation.IsEmpty())
                {
                    if (!float.TryParse(orientation, out oy))
                    {
                        return(false);
                    }

                    orientation = args.NextString();
                    if (!orientation.IsEmpty())
                    {
                        if (!float.TryParse(orientation, out ox))
                        {
                            return(false);
                        }
                    }
                }
            }
            else
            {
                Player player = handler.GetPlayer();
                oz = player.GetOrientation();
            }

            Map map = obj.GetMap();

            obj.Relocate(obj.GetPositionX(), obj.GetPositionY(), obj.GetPositionZ());
            obj.SetWorldRotationAngles(oz, oy, ox);
            obj.SaveToDB();

            // Generate a completely new spawn with new guid
            // client caches recently deleted objects and brings them back to life
            // when CreateObject block for this guid is received again
            // however it entirely skips parsing that block and only uses already known location
            obj.Delete();

            obj = GameObject.CreateGameObjectFromDB(guidLow, map);
            if (!obj)
            {
                return(false);
            }

            handler.SendSysMessage(CypherStrings.CommandTurnobjmessage, obj.GetSpawnId(), obj.GetGoInfo().name, obj.GetGUID().ToString(), obj.GetOrientation());

            return(true);
        }
Esempio n. 29
0
        static bool PathCommand(StringArguments args, CommandHandler handler)
        {
            if (Global.MMapMgr.GetNavMesh(handler.GetPlayer().GetMapId()) == 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);
        }
Esempio n. 30
0
        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);
            }

            if (!ulong.TryParse(id, out ulong guidLow) || 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())
            {
                if (!float.TryParse(orientation, out oz))
                {
                    return(false);
                }

                orientation = args.NextString();
                if (!orientation.IsEmpty())
                {
                    if (!float.TryParse(orientation, out oy))
                    {
                        return(false);
                    }

                    orientation = args.NextString();
                    if (!orientation.IsEmpty())
                    {
                        if (!float.TryParse(orientation, out ox))
                        {
                            return(false);
                        }
                    }
                }
            }
            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);
        }