Replace most T.Parse with T.TryParse for all user input.

This commit is contained in:
hondacrx
2017-11-05 15:21:29 -05:00
parent 8c863de8a6
commit 8ed446ae7a
40 changed files with 477 additions and 527 deletions
+2 -2
View File
@@ -884,8 +884,8 @@ namespace Google.Protobuf
if (subseconds != "") if (subseconds != "")
{ {
// This should always work, as we've got 1-9 digits. // This should always work, as we've got 1-9 digits.
int parsedFraction = int.Parse(subseconds.Substring(1)); if (int.TryParse(subseconds.Substring(1), out int parsedFraction))
nanos = parsedFraction * SubsecondScalingFactors[subseconds.Length] * multiplier; nanos = parsedFraction * SubsecondScalingFactors[subseconds.Length] * multiplier;
} }
if (!Duration.IsNormalized(seconds, nanos)) if (!Duration.IsNormalized(seconds, nanos))
{ {
@@ -720,7 +720,10 @@ namespace Game.Achievements
ca.Date = achievementResult.Read<uint>(1); ca.Date = achievementResult.Read<uint>(1);
var guids = new StringArray(achievementResult.Read<string>(2), ' '); var guids = new StringArray(achievementResult.Read<string>(2), ' ');
for (int i = 0; i < guids.Length; ++i) for (int i = 0; i < guids.Length; ++i)
ca.CompletingPlayers.Add(ObjectGuid.Create(HighGuid.Player, ulong.Parse(guids[i]))); {
if (ulong.TryParse(guids[i], out ulong guid))
ca.CompletingPlayers.Add(ObjectGuid.Create(HighGuid.Player, guid));
}
ca.Changed = false; ca.Changed = false;
+4 -1
View File
@@ -39,7 +39,10 @@ namespace Game.BlackMarket
var bonusListIDsTok = new StringArray(fields.Read<string>(7), ' '); var bonusListIDsTok = new StringArray(fields.Read<string>(7), ' ');
List<uint> bonusListIDs = new List<uint>(); List<uint> bonusListIDs = new List<uint>();
foreach (string token in bonusListIDsTok) foreach (string token in bonusListIDsTok)
bonusListIDs.Add(uint.Parse(token)); {
if (uint.TryParse(token, out uint id))
bonusListIDs.Add(id);
}
if (!bonusListIDs.Empty()) if (!bonusListIDs.Empty())
{ {
+3 -1
View File
@@ -80,7 +80,9 @@ namespace Game.Chat
for (var i = 0; i < tokens.Length; ++i) for (var i = 0; i < tokens.Length; ++i)
{ {
ObjectGuid bannedGuid = new ObjectGuid(); ObjectGuid bannedGuid = new ObjectGuid();
bannedGuid.SetRawValue(ulong.Parse(tokens[i].Substring(0, 16)), ulong.Parse(tokens[i].Substring(16))); if (ulong.TryParse(tokens[i].Substring(0, 16), out ulong highguid) && ulong.TryParse(tokens[i].Substring(16), out ulong lowguid))
bannedGuid.SetRawValue(highguid, lowguid);
if (!bannedGuid.IsEmpty()) if (!bannedGuid.IsEmpty())
{ {
Log.outDebug(LogFilter.ChatSystem, "Channel({0}) loaded bannedStore guid:{1}", _channelName, bannedGuid); Log.outDebug(LogFilter.ChatSystem, "Channel({0}) loaded bannedStore guid:{1}", _channelName, bannedGuid);
+17 -12
View File
@@ -73,12 +73,14 @@ namespace Game.Chat
public bool ExecuteCommandInTable(List<ChatCommand> table, string text, string fullcmd) public bool ExecuteCommandInTable(List<ChatCommand> table, string text, string fullcmd)
{ {
string oldtext = text;
StringArguments args = new StringArguments(text); StringArguments args = new StringArguments(text);
string cmd = args.NextString(); string cmd = args.NextString();
foreach (var command in table) foreach (var command in table)
{ {
//if (!command.Name.Equals(cmd))
//continue;
if (!hasStringAbbr(command.Name, cmd)) if (!hasStringAbbr(command.Name, cmd))
continue; continue;
@@ -102,9 +104,9 @@ namespace Game.Chat
if (!command.ChildCommands.Empty()) if (!command.ChildCommands.Empty())
{ {
if (!ExecuteCommandInTable(command.ChildCommands, args.NextString(""), fullcmd)) string arg = args.NextString("");
if (!ExecuteCommandInTable(command.ChildCommands, arg, fullcmd))
{ {
string arg = args.NextString("");
if (!arg.IsEmpty()) if (!arg.IsEmpty())
SendSysMessage(CypherStrings.NoSubcmd); SendSysMessage(CypherStrings.NoSubcmd);
else else
@@ -121,7 +123,7 @@ namespace Game.Chat
continue; continue;
_sentErrorMessage = false; _sentErrorMessage = false;
if (command.Handler(new StringArguments(!command.Name.IsEmpty() ? args.NextString("") : oldtext), this)) if (command.Handler(new StringArguments(!command.Name.IsEmpty() ? args.NextString("") : text), this))
{ {
if (GetSession() == null) // ignore console if (GetSession() == null) // ignore console
return true; return true;
@@ -343,8 +345,7 @@ namespace Game.Chat
if (string.IsNullOrEmpty(cId)) if (string.IsNullOrEmpty(cId))
return null; return null;
uint id; if (!uint.TryParse(cId, out uint id))
if (!uint.TryParse(cId, out id))
return null; return null;
return Global.ObjectMgr.GetGameTele(id); return Global.ObjectMgr.GetGameTele(id);
@@ -460,13 +461,15 @@ namespace Game.Chat
case 1: case 1:
{ {
guidHigh = HighGuid.Creature; guidHigh = HighGuid.Creature;
ulong lowguid = ulong.Parse(idS); if (!ulong.TryParse(idS, out ulong lowguid))
return 0;
return lowguid; return lowguid;
} }
case 2: case 2:
{ {
guidHigh = HighGuid.GameObject; guidHigh = HighGuid.GameObject;
ulong lowguid = ulong.Parse(idS); if (!ulong.TryParse(idS, out ulong lowguid))
return 0;
return lowguid; return lowguid;
} }
} }
@@ -491,12 +494,13 @@ namespace Game.Chat
// number or [name] Shift-click form |color|Htalent:talent_id, rank|h[name]|h|r // number or [name] Shift-click form |color|Htalent:talent_id, rank|h[name]|h|r
// number or [name] Shift-click form |color|Htrade:spell_id, skill_id, max_value, cur_value|h[name]|h|r // number or [name] Shift-click form |color|Htrade:spell_id, skill_id, max_value, cur_value|h[name]|h|r
int type = 0; int type = 0;
string param1_str = null; string param1Str = null;
string idS = extractKeyFromLink(args, spellKeys, out type, out param1_str); string idS = extractKeyFromLink(args, spellKeys, out type, out param1Str);
if (string.IsNullOrEmpty(idS)) if (string.IsNullOrEmpty(idS))
return 0; return 0;
uint id = uint.Parse(idS); if (!uint.TryParse(idS, out uint id))
return 0;
switch (type) switch (type)
{ {
@@ -516,7 +520,8 @@ namespace Game.Chat
return id; return id;
case 4: case 4:
{ {
uint glyph_prop_id = !string.IsNullOrEmpty(param1_str) ? uint.Parse(param1_str) : 0; if (!uint.TryParse(param1Str, out uint glyph_prop_id))
glyph_prop_id = 0;
GlyphPropertiesRecord glyphPropEntry = CliDB.GlyphPropertiesStorage.LookupByKey(glyph_prop_id); GlyphPropertiesRecord glyphPropEntry = CliDB.GlyphPropertiesStorage.LookupByKey(glyph_prop_id);
if (glyphPropEntry == null) if (glyphPropEntry == null)
+9 -3
View File
@@ -494,7 +494,9 @@ namespace Game.Chat
handler.HasLowerSecurityAccount(null, accountId, true)) handler.HasLowerSecurityAccount(null, accountId, true))
return false; return false;
byte expansion = byte.Parse(exp); //get int anyway (0 if error) if (!byte.TryParse(exp, out byte expansion))
return false;
if (expansion > WorldConfig.GetIntValue(WorldCfg.Expansion)) if (expansion > WorldConfig.GetIntValue(WorldCfg.Expansion))
return false; return false;
@@ -548,7 +550,9 @@ namespace Game.Chat
} }
// Check for invalid specified GM level. // Check for invalid specified GM level.
gm = isAccountNameGiven ? uint.Parse(arg2) : uint.Parse(arg1); if (!uint.TryParse(isAccountNameGiven ? arg2 : arg1, out gm))
return false;
if (gm > (uint)AccountTypes.Console) if (gm > (uint)AccountTypes.Console)
{ {
handler.SendSysMessage(CypherStrings.BadValue); handler.SendSysMessage(CypherStrings.BadValue);
@@ -557,7 +561,9 @@ namespace Game.Chat
// command.getSession() == NULL only for console // command.getSession() == NULL only for console
targetAccountId = (isAccountNameGiven) ? Global.AccountMgr.GetId(targetAccountName) : handler.getSelectedPlayer().GetSession().GetAccountId(); targetAccountId = (isAccountNameGiven) ? Global.AccountMgr.GetId(targetAccountName) : handler.getSelectedPlayer().GetSession().GetAccountId();
int gmRealmID = (isAccountNameGiven) ? int.Parse(arg3) : int.Parse(arg2); if (int.TryParse(isAccountNameGiven ? arg3 : arg2, out int gmRealmID))
return false;
AccountTypes playerSecurity; AccountTypes playerSecurity;
if (handler.GetSession() != null) if (handler.GetSession() != null)
playerSecurity = Global.AccountMgr.GetSecurity(handler.GetSession().GetAccountId(), gmRealmID); playerSecurity = Global.AccountMgr.GetSecurity(handler.GetSession().GetAccountId(), gmRealmID);
+1 -2
View File
@@ -180,8 +180,7 @@ namespace Game.Chat
if (string.IsNullOrEmpty(idStr)) if (string.IsNullOrEmpty(idStr))
return false; return false;
uint teamId = uint.Parse(idStr); if (!uint.TryParse(idStr, out uint teamId) || teamId == 0)
if (teamId == 0)
return false; return false;
Player target; Player target;
@@ -44,10 +44,8 @@ namespace Game.Chat.Commands
return false; return false;
} }
string createGameAccountParam = args.NextString(); if (!bool.TryParse(args.NextString(), out bool createGameAccount))
bool createGameAccount = true; createGameAccount = true;
if (!string.IsNullOrEmpty(createGameAccountParam))
createGameAccount = bool.Parse(createGameAccountParam);
string gameAccountName; string gameAccountName;
switch (Global.BNetAccountMgr.CreateBattlenetAccount(accountName, password, createGameAccount, out gameAccountName)) switch (Global.BNetAccountMgr.CreateBattlenetAccount(accountName, password, createGameAccount, out gameAccountName))
+4 -4
View File
@@ -47,7 +47,8 @@ namespace Game.Chat.Commands
if (string.IsNullOrEmpty(durationStr)) if (string.IsNullOrEmpty(durationStr))
return false; return false;
uint duration = uint.Parse(durationStr); if (!uint.TryParse(durationStr, out uint duration))
return false;
string reasonStr = args.NextString(""); string reasonStr = args.NextString("");
if (string.IsNullOrEmpty(reasonStr)) if (string.IsNullOrEmpty(reasonStr))
@@ -115,9 +116,8 @@ namespace Game.Chat.Commands
if (string.IsNullOrEmpty(nameOrIP)) if (string.IsNullOrEmpty(nameOrIP))
return false; return false;
uint duration;
string durationStr = args.NextString(); string durationStr = args.NextString();
if (string.IsNullOrEmpty(durationStr) || !uint.TryParse(durationStr, out duration)) if (!uint.TryParse(durationStr, out uint duration))
return false; return false;
string reasonStr = args.NextString(""); string reasonStr = args.NextString("");
@@ -144,7 +144,7 @@ namespace Game.Chat.Commands
switch (Global.WorldMgr.BanAccount(mode, nameOrIP, durationStr, reasonStr, author)) switch (Global.WorldMgr.BanAccount(mode, nameOrIP, durationStr, reasonStr, author))
{ {
case BanReturn.Success: case BanReturn.Success:
if (uint.Parse(durationStr) > 0) if (!uint.TryParse(durationStr, out uint tempValue) || tempValue > 0)
{ {
if (WorldConfig.GetBoolValue(WorldCfg.ShowBanInWorld)) if (WorldConfig.GetBoolValue(WorldCfg.ShowBanInWorld))
Global.WorldMgr.SendWorldText(CypherStrings.BanAccountYoubannedmessageWorld, author, nameOrIP, Time.secsToTimeString(Time.TimeStringToSecs(durationStr)).ToString(), reasonStr); Global.WorldMgr.SendWorldText(CypherStrings.BanAccountYoubannedmessageWorld, author, nameOrIP, Time.secsToTimeString(Time.TimeStringToSecs(durationStr)).ToString(), reasonStr);
+11 -6
View File
@@ -216,7 +216,9 @@ namespace Game.Chat
return false; return false;
int oldlevel = (int)(target ? target.getLevel() : Player.GetLevelFromDB(targetGuid)); int oldlevel = (int)(target ? target.getLevel() : Player.GetLevelFromDB(targetGuid));
int newlevel = !string.IsNullOrEmpty(levelStr) ? int.Parse(levelStr) : oldlevel;
if (!int.TryParse(levelStr, out int newlevel))
newlevel = oldlevel;
if (newlevel < 1) if (newlevel < 1)
return false; // invalid level return false; // invalid level
@@ -520,8 +522,7 @@ namespace Game.Chat
if (!daysStr.IsNumber()) if (!daysStr.IsNumber())
return false; return false;
keepDays = int.Parse(daysStr); if (!int.TryParse(daysStr, out keepDays) || keepDays < 0)
if (keepDays < 0)
return false; return false;
} }
// config option value 0 -> disabled and can't be used // config option value 0 -> disabled and can't be used
@@ -542,8 +543,11 @@ namespace Game.Chat
// search by GUID // search by GUID
if (searchString.IsNumber()) if (searchString.IsNumber())
{ {
if (!ulong.TryParse(searchString, out ulong guid))
return false;
stmt = DB.Characters.GetPreparedStatement(CharStatements.SEL_CHAR_DEL_INFO_BY_GUID); stmt = DB.Characters.GetPreparedStatement(CharStatements.SEL_CHAR_DEL_INFO_BY_GUID);
stmt.AddValue(0, ulong.Parse(searchString)); stmt.AddValue(0, guid);
result = DB.Characters.Query(stmt); result = DB.Characters.Query(stmt);
} }
// search by name // search by name
@@ -671,9 +675,10 @@ namespace Game.Chat
return false; return false;
int oldlevel = (int)(target ? target.getLevel() : Player.GetLevelFromDB(targetGuid)); int oldlevel = (int)(target ? target.getLevel() : Player.GetLevelFromDB(targetGuid));
int addlevel = !string.IsNullOrEmpty(levelStr) ? int.Parse(levelStr) : 1; if (!int.TryParse(levelStr, out int addlevel))
int newlevel = oldlevel + addlevel; addlevel = 1;
int newlevel = oldlevel + addlevel;
if (newlevel < 1) if (newlevel < 1)
newlevel = 1; newlevel = 1;
+106 -174
View File
@@ -91,7 +91,8 @@ namespace Game.Chat
string fill_str = args.NextString(); string fill_str = args.NextString();
string duration_str = args.NextString(); string duration_str = args.NextString();
int duration = duration_str.IsEmpty() ? int.Parse(duration_str) : -1; if (!int.TryParse(duration_str, out int duration))
duration = -1;
if (duration <= 0 || duration >= 30 * Time.Minute) // arbitary upper limit if (duration <= 0 || duration >= 30 * Time.Minute) // arbitary upper limit
duration = 3 * Time.Minute; duration = 3 * Time.Minute;
@@ -110,14 +111,11 @@ namespace Game.Chat
if (args.Empty()) if (args.Empty())
return false; return false;
string conversationEntryStr = args.NextString(); uint conversationEntry = args.NextUInt32();
if (conversationEntry == 0)
if (conversationEntryStr.IsEmpty())
return false; return false;
uint conversationEntry = uint.Parse(conversationEntryStr);
Player target = handler.getSelectedPlayerOrSelf(); Player target = handler.getSelectedPlayerOrSelf();
if (!target) if (!target)
{ {
handler.SendSysMessage(CypherStrings.PlayerNotFound); handler.SendSysMessage(CypherStrings.PlayerNotFound);
@@ -137,14 +135,9 @@ namespace Game.Chat
if (args.Empty()) if (args.Empty())
return false; return false;
string i = args.NextString(); uint entry = args.NextUInt32();
if (string.IsNullOrEmpty(i)) if (!sbyte.TryParse(args.NextString(), out sbyte seatId))
return false; seatId = -1;
string j = args.NextString();
uint entry = uint.Parse(i);
sbyte seatId = !string.IsNullOrEmpty(j) ? sbyte.Parse(j) : (sbyte)-1;
if (entry == 0) if (entry == 0)
handler.GetSession().GetPlayer().EnterVehicle(target, seatId); handler.GetSession().GetPlayer().EnterVehicle(target, seatId);
@@ -448,24 +441,20 @@ namespace Game.Chat
if (args.Empty()) if (args.Empty())
return false; return false;
string e = args.NextString(); if (!ulong.TryParse(args.NextString(), out ulong guid))
string f = args.NextString();
if (string.IsNullOrEmpty(e) || string.IsNullOrEmpty(f))
return false; return false;
ulong guid = ulong.Parse(e); if (!uint.TryParse(args.NextString(), out uint index))
uint index = uint.Parse(f);
Item i = handler.GetSession().GetPlayer().GetItemByGuid(ObjectGuid.Create(HighGuid.Item, guid));
if (!i)
return false; return false;
if (index >= i.valuesCount) Item item = handler.GetSession().GetPlayer().GetItemByGuid(ObjectGuid.Create(HighGuid.Item, guid));
if (!item)
return false; return false;
uint value = i.GetUInt32Value(index); if (index >= item.valuesCount)
return false;
uint value = item.GetUInt32Value(index);
handler.SendSysMessage("Item {0}: value at {1} is {2}", guid, index, value); handler.SendSysMessage("Item {0}: value at {1} is {2}", guid, index, value);
@@ -478,42 +467,41 @@ namespace Game.Chat
if (args.Empty()) if (args.Empty())
return false; return false;
string x = args.NextString(); string fieldStr = args.NextString();
string z = args.NextString(); string valueStr = args.NextString();
if (string.IsNullOrEmpty(x)) if (string.IsNullOrEmpty(fieldStr))
return false; return false;
Unit target = handler.getSelectedUnit(); Unit target = handler.getSelectedUnit();
if (!target) if (!target)
{ {
handler.SendSysMessage(CypherStrings.SelectCharOrCreature); handler.SendSysMessage(CypherStrings.SelectCharOrCreature);
return false; return false;
} }
if (!uint.TryParse(fieldStr, out uint field))
return false;
ObjectGuid guid = target.GetGUID(); ObjectGuid guid = target.GetGUID();
if (field >= target.valuesCount)
uint opcode = uint.Parse(x);
if (opcode >= target.valuesCount)
{ {
handler.SendSysMessage(CypherStrings.TooBigIndex, opcode, guid.ToString(), target.valuesCount); handler.SendSysMessage(CypherStrings.TooBigIndex, field, guid.ToString(), target.valuesCount);
return false; return false;
} }
bool isInt32 = true; if (!bool.TryParse(valueStr, out bool isInt32))
if (!string.IsNullOrEmpty(z)) isInt32 = true;
isInt32 = bool.Parse(z);
if (isInt32) if (isInt32)
{ {
uint value = target.GetUInt32Value(opcode); uint value = target.GetUInt32Value(field);
handler.SendSysMessage(CypherStrings.GetUintField, guid.ToString(), opcode, value); handler.SendSysMessage(CypherStrings.GetUintField, guid.ToString(), field, value);
} }
else else
{ {
float value = target.GetFloatValue(opcode); float value = target.GetFloatValue(field);
handler.SendSysMessage(CypherStrings.GetFloatField, guid.ToString(), opcode, value); handler.SendSysMessage(CypherStrings.GetFloatField, guid.ToString(), field, value);
} }
return true; return true;
@@ -548,19 +536,15 @@ namespace Game.Chat
if (args.Empty()) if (args.Empty())
return false; return false;
string e = args.NextString(); if (!ulong.TryParse(args.NextString(), out ulong guid))
if (string.IsNullOrEmpty(e))
return false; return false;
ulong guid = ulong.Parse(e); Item item = handler.GetSession().GetPlayer().GetItemByGuid(ObjectGuid.Create(HighGuid.Item, guid));
if (!item)
Item i = handler.GetSession().GetPlayer().GetItemByGuid(ObjectGuid.Create(HighGuid.Item, guid));
if (!i)
return false; return false;
handler.GetSession().GetPlayer().DestroyItem(i.GetBagSlot(), i.GetSlot(), true); handler.GetSession().GetPlayer().DestroyItem(item.GetBagSlot(), item.GetSlot(), true);
Global.ScriptMgr.OnItemExpire(handler.GetSession().GetPlayer(), i.GetTemplate()); Global.ScriptMgr.OnItemExpire(handler.GetSession().GetPlayer(), item.GetTemplate());
return true; return true;
} }
@@ -592,27 +576,21 @@ namespace Game.Chat
if (args.Empty()) if (args.Empty())
return false; return false;
string x = args.NextString(); uint field = args.NextUInt32();
string y = args.NextString(); int value = args.NextInt32();
if (string.IsNullOrEmpty(x) || string.IsNullOrEmpty(y)) if (field >= handler.GetSession().GetPlayer().valuesCount)
return false;
uint opcode = uint.Parse(x);
int value = int.Parse(y);
if (opcode >= handler.GetSession().GetPlayer().valuesCount)
{ {
handler.SendSysMessage(CypherStrings.TooBigIndex, opcode, handler.GetSession().GetPlayer().GetGUID().ToString(), handler.GetSession().GetPlayer().valuesCount); handler.SendSysMessage(CypherStrings.TooBigIndex, field, handler.GetSession().GetPlayer().GetGUID().ToString(), handler.GetSession().GetPlayer().valuesCount);
return false; return false;
} }
uint currentValue = handler.GetSession().GetPlayer().GetUInt32Value(opcode); uint currentValue = handler.GetSession().GetPlayer().GetUInt32Value(field);
currentValue += (uint)value; currentValue += (uint)value;
handler.GetSession().GetPlayer().SetUInt32Value(opcode, currentValue); handler.GetSession().GetPlayer().SetUInt32Value(field, currentValue);
handler.SendSysMessage(CypherStrings.Change32bitField, opcode, currentValue); handler.SendSysMessage(CypherStrings.Change32bitField, field, currentValue);
return true; return true;
} }
@@ -637,14 +615,16 @@ namespace Game.Chat
string mask2 = args.NextString(" \n"); string mask2 = args.NextString(" \n");
uint moveFlags = uint.Parse(mask1); if (!uint.TryParse(mask1, out uint moveFlags))
return false;
target.SetUnitMovementFlags((MovementFlag)moveFlags); target.SetUnitMovementFlags((MovementFlag)moveFlags);
/// @fixme: port master's HandleDebugMoveflagsCommand; flags need different handling /// @fixme: port master's HandleDebugMoveflagsCommand; flags need different handling
if (!string.IsNullOrEmpty(mask2)) if (!string.IsNullOrEmpty(mask2))
{ {
uint moveFlagsExtra = uint.Parse(mask2); if (!uint.TryParse(mask2, out uint moveFlagsExtra))
return false;
target.SetUnitMovementFlags2((MovementFlag2)moveFlagsExtra); target.SetUnitMovementFlags2((MovementFlag2)moveFlagsExtra);
} }
@@ -771,15 +751,15 @@ namespace Game.Chat
string map_str = args.NextString(); string map_str = args.NextString();
string difficulty_str = args.NextString(); string difficulty_str = args.NextString();
int map = !map_str.IsEmpty() ? int.Parse(map_str) : -1; if (!int.TryParse(map_str, out int map) || map <= 0)
if (map <= 0)
return false; return false;
MapRecord mEntry = CliDB.MapStorage.LookupByKey(map); MapRecord mEntry = CliDB.MapStorage.LookupByKey(map);
if (mEntry == null || !mEntry.IsRaid()) if (mEntry == null || !mEntry.IsRaid())
return false; return false;
int difficulty = !difficulty_str.IsEmpty() ? int.Parse(difficulty_str) : -1; if (!int.TryParse(difficulty_str, out int difficulty))
difficulty = -1;
if (difficulty >= (int)Difficulty.Max || difficulty < -1) if (difficulty >= (int)Difficulty.Max || difficulty < -1)
return false; return false;
@@ -838,21 +818,15 @@ namespace Game.Chat
return false; return false;
} }
string x = args.NextString(); uint field = args.NextUInt32();
string y = args.NextString(); uint val = args.NextUInt32();
if (string.IsNullOrEmpty(x) || string.IsNullOrEmpty(y))
return false;
uint opcode = uint.Parse(x);
uint val = uint.Parse(y);
if (val > 32) //uint = 32 bits if (val > 32) //uint = 32 bits
return false; return false;
uint value = (uint)(val != 0 ? 1 << ((int)val - 1) : 0); uint value = (uint)(val != 0 ? 1 << ((int)val - 1) : 0);
target.SetUInt32Value(opcode, value); target.SetUInt32Value(field, value);
handler.SendSysMessage(CypherStrings.Set32bitField, opcode, value); handler.SendSysMessage(CypherStrings.Set32bitField, field, value);
return true; return true;
} }
@@ -862,27 +836,23 @@ namespace Game.Chat
if (args.Empty()) if (args.Empty())
return false; return false;
string e = args.NextString(); if (!ulong.TryParse(args.NextString(), out ulong guid))
string f = args.NextString();
string g = args.NextString();
if (string.IsNullOrEmpty(e) || string.IsNullOrEmpty(f) || string.IsNullOrEmpty(g))
return false; return false;
ulong guid = ulong.Parse(e); if (!uint.TryParse(args.NextString(), out uint index))
uint index = uint.Parse(f);
uint value = uint.Parse(g);
Item i = handler.GetSession().GetPlayer().GetItemByGuid(ObjectGuid.Create(HighGuid.Item, guid));
if (!i)
return false; return false;
if (index >= i.valuesCount) if (!uint.TryParse(args.NextString(), out uint value))
return false;
Item item = handler.GetSession().GetPlayer().GetItemByGuid(ObjectGuid.Create(HighGuid.Item, guid));
if (!item)
return false; return false;
i.SetUInt32Value(index, value); if (index >= item.valuesCount)
return false;
item.SetUInt32Value(index, value);
return true; return true;
} }
@@ -892,13 +862,6 @@ namespace Game.Chat
if (args.Empty()) if (args.Empty())
return false; return false;
string x = args.NextString();
string y = args.NextString();
string z = args.NextString();
if (string.IsNullOrEmpty(x) || string.IsNullOrEmpty(y))
return false;
WorldObject target = handler.GetSelectedObject(); WorldObject target = handler.GetSelectedObject();
if (!target) if (!target)
{ {
@@ -908,28 +871,32 @@ namespace Game.Chat
ObjectGuid guid = target.GetGUID(); ObjectGuid guid = target.GetGUID();
uint opcode = uint.Parse(x); uint field = args.NextUInt32();
if (opcode >= target.valuesCount) if (field >= target.valuesCount)
{ {
handler.SendSysMessage(CypherStrings.TooBigIndex, opcode, guid.ToString(), target.valuesCount); handler.SendSysMessage(CypherStrings.TooBigIndex, field, guid.ToString(), target.valuesCount);
return false; return false;
} }
bool isInt32 = true; string valueStr = args.NextString();
if (!string.IsNullOrEmpty(z)) if (!bool.TryParse(args.NextString(), out bool isInt32))
isInt32 = bool.Parse(z); isInt32 = true;
if (isInt32) if (isInt32)
{ {
uint value = uint.Parse(y); if (!uint.TryParse(valueStr, out uint value))
target.SetUInt32Value(opcode, value); return false;
handler.SendSysMessage(CypherStrings.SetUintField, guid.ToString(), opcode, value);
target.SetUInt32Value(field, value);
handler.SendSysMessage(CypherStrings.SetUintField, guid.ToString(), field, value);
} }
else else
{ {
float value = float.Parse(y); if (!float.TryParse(valueStr, out float value))
target.SetFloatValue(opcode, value); return false;
handler.SendSysMessage(CypherStrings.SetFloatField, guid.ToString(), opcode, value);
target.SetFloatValue(field, value);
handler.SendSysMessage(CypherStrings.SetFloatField, guid.ToString(), field, value);
} }
return true; return true;
@@ -945,11 +912,7 @@ namespace Game.Chat
if (args.Empty()) if (args.Empty())
return false; return false;
string i = args.NextString(); uint id = args.NextUInt32();
if (string.IsNullOrEmpty(i))
return false;
uint id = uint.Parse(i);
handler.SendSysMessage("Vehicle id set to {0}", id); handler.SendSysMessage("Vehicle id set to {0}", id);
return true; return true;
} }
@@ -960,40 +923,32 @@ namespace Game.Chat
if (args.Empty()) if (args.Empty())
return false; return false;
string e = args.NextString(); uint entry = args.NextUInt32();
string i = args.NextString(); if (entry == 0)
if (string.IsNullOrEmpty(e))
return false; return false;
uint entry = uint.Parse(e);
float x, y, z, o = handler.GetSession().GetPlayer().GetOrientation(); float x, y, z, o = handler.GetSession().GetPlayer().GetOrientation();
handler.GetSession().GetPlayer().GetClosePoint(out x, out y, out z, handler.GetSession().GetPlayer().GetObjectSize()); handler.GetSession().GetPlayer().GetClosePoint(out x, out y, out z, handler.GetSession().GetPlayer().GetObjectSize());
if (string.IsNullOrEmpty(i)) uint id = args.NextUInt32();
if (id == 0)
return handler.GetSession().GetPlayer().SummonCreature(entry, x, y, z, o); return handler.GetSession().GetPlayer().SummonCreature(entry, x, y, z, o);
uint id = uint.Parse(i); CreatureTemplate creatureTemplate = Global.ObjectMgr.GetCreatureTemplate(entry);
if (creatureTemplate == null)
CreatureTemplate ci = Global.ObjectMgr.GetCreatureTemplate(entry);
if (ci == null)
return false; return false;
VehicleRecord ve = CliDB.VehicleStorage.LookupByKey(id); VehicleRecord vehicleRecord = CliDB.VehicleStorage.LookupByKey(id);
if (ve == null) if (vehicleRecord == null)
return false; return false;
Creature v = new Creature(); Creature creature = new Creature();
Map map = handler.GetSession().GetPlayer().GetMap(); Map map = handler.GetSession().GetPlayer().GetMap();
if (!creature.Create(map.GenerateLowGuid(HighGuid.Vehicle), map, handler.GetSession().GetPlayer().GetPhaseMask(), entry, x, y, z, o, null, id))
if (!v.Create(map.GenerateLowGuid(HighGuid.Vehicle), map, handler.GetSession().GetPlayer().GetPhaseMask(), entry, x, y, z, o, null, id))
return false; return false;
map.AddToMap(v.ToCreature()); map.AddToMap(creature.ToCreature());
return true; return true;
} }
@@ -1053,11 +1008,6 @@ namespace Game.Chat
if (args.Empty()) if (args.Empty())
return false; return false;
uint updateIndex;
uint value;
string index = args.NextString();
Unit unit = handler.getSelectedUnit(); Unit unit = handler.getSelectedUnit();
if (!unit) if (!unit)
{ {
@@ -1065,10 +1015,8 @@ namespace Game.Chat
return false; return false;
} }
if (string.IsNullOrEmpty(index)) uint updateIndex = args.NextUInt32();
return true;
updateIndex = uint.Parse(index);
//check updateIndex //check updateIndex
if (unit.IsTypeId(TypeId.Player)) if (unit.IsTypeId(TypeId.Player))
{ {
@@ -1078,8 +1026,9 @@ namespace Game.Chat
else if (updateIndex >= (int)UnitFields.End) else if (updateIndex >= (int)UnitFields.End)
return true; return true;
string val = args.NextString(); uint value;
if (string.IsNullOrEmpty(val)) string valueStr = args.NextString();
if (string.IsNullOrEmpty(valueStr))
{ {
value = unit.GetUInt32Value(updateIndex); value = unit.GetUInt32Value(updateIndex);
@@ -1087,10 +1036,10 @@ namespace Game.Chat
return true; return true;
} }
value = uint.Parse(val); if (!uint.TryParse(valueStr, out value))
return false;
handler.SendSysMessage(CypherStrings.UpdateChange, unit.GetGUID().ToString(), updateIndex, value); handler.SendSysMessage(CypherStrings.UpdateChange, unit.GetGUID().ToString(), updateIndex, value);
unit.SetUInt32Value(updateIndex, value); unit.SetUInt32Value(updateIndex, value);
return true; return true;
@@ -1099,15 +1048,11 @@ namespace Game.Chat
[Command("uws", RBACPermissions.CommandDebugUws)] [Command("uws", RBACPermissions.CommandDebugUws)]
static bool HandleDebugUpdateWorldStateCommand(StringArguments args, CommandHandler handler) static bool HandleDebugUpdateWorldStateCommand(StringArguments args, CommandHandler handler)
{ {
string w = args.NextString(); if (!uint.TryParse(args.NextString(), out uint variable) || variable == 0)
string s = args.NextString();
if (string.IsNullOrEmpty(w) || string.IsNullOrEmpty(s))
return false; return false;
uint world = uint.Parse(w); uint state = args.NextUInt32();
uint state = uint.Parse(s); handler.GetSession().GetPlayer().SendUpdateWorldState(variable, state);
handler.GetSession().GetPlayer().SendUpdateWorldState(world, state);
return true; return true;
} }
@@ -1216,20 +1161,15 @@ namespace Game.Chat
if (args.Empty()) if (args.Empty())
return false; return false;
string t = args.NextString();
string p = args.NextString();
if (string.IsNullOrEmpty(t))
return false;
List<uint> terrainswap = new List<uint>(); List<uint> terrainswap = new List<uint>();
List<uint> phaseId = new List<uint>(); List<uint> phaseId = new List<uint>();
List<uint> worldMapSwap = new List<uint>(); List<uint> worldMapSwap = new List<uint>();
terrainswap.Add(uint.Parse(t)); if (uint.TryParse(args.NextString(), out uint terrain))
terrainswap.Add(terrain);
if (!string.IsNullOrEmpty(p)) if (uint.TryParse(args.NextString(), out uint phase))
phaseId.Add(uint.Parse(p)); phaseId.Add(phase);
handler.GetSession().SendSetPhaseShift(phaseId, terrainswap, worldMapSwap); handler.GetSession().SendSetPhaseShift(phaseId, terrainswap, worldMapSwap);
return true; return true;
@@ -1241,19 +1181,11 @@ namespace Game.Chat
if (args.Empty()) if (args.Empty())
return false; return false;
string result = args.NextString(); if (!byte.TryParse(args.NextString(), out byte failNum) ||failNum == 0)
if (string.IsNullOrEmpty(result))
return false; return false;
byte failNum = byte.Parse(result); int failArg1 = args.NextInt32();
if (failNum == 0) int failArg2 = args.NextInt32();
return false;
string fail1 = args.NextString();
int failArg1 = !string.IsNullOrEmpty(fail1) ? int.Parse(fail1) : 0;
string fail2 = args.NextString();
int failArg2 = !string.IsNullOrEmpty(fail2) ? int.Parse(fail2) : 0;
CastFailed castFailed = new CastFailed(); CastFailed castFailed = new CastFailed();
castFailed.CastID = ObjectGuid.Empty; castFailed.CastID = ObjectGuid.Empty;
@@ -74,15 +74,8 @@ namespace Game.Chat.Commands
handler.SendSysMessage(CypherStrings.NoCharSelected); handler.SendSysMessage(CypherStrings.NoCharSelected);
return false; return false;
} }
string timeStr = args.NextString();
if (string.IsNullOrEmpty(timeStr))
{
handler.SendSysMessage(CypherStrings.BadValue);
return false;
}
uint time = uint.Parse(timeStr); if (!uint.TryParse(args.NextString(), out uint time) || time == 0)
if (time == 0)
{ {
handler.SendSysMessage(CypherStrings.BadValue); handler.SendSysMessage(CypherStrings.BadValue);
return false; return false;
+4 -9
View File
@@ -30,19 +30,17 @@ namespace Game.Chat.Commands
{ {
static bool HandleAddDisables(StringArguments args, CommandHandler handler, DisableType disableType) static bool HandleAddDisables(StringArguments args, CommandHandler handler, DisableType disableType)
{ {
string entryStr = args.NextString(); uint entry = args.NextUInt32();
if (string.IsNullOrEmpty(entryStr) || int.Parse(entryStr) == 0) if (entry == 0)
return false; return false;
string flagsStr = args.NextString(); string flagsStr = args.NextString();
uint flags = !string.IsNullOrEmpty(flagsStr) ? byte.Parse(flagsStr) : 0u; uint flags = args.NextUInt32();
string disableComment = args.NextString(""); string disableComment = args.NextString("");
if (string.IsNullOrEmpty(disableComment)) if (string.IsNullOrEmpty(disableComment))
return false; return false;
uint entry = uint.Parse(entryStr);
string disableTypeStr = ""; string disableTypeStr = "";
switch (disableType) switch (disableType)
{ {
@@ -230,12 +228,9 @@ namespace Game.Chat.Commands
{ {
static bool HandleRemoveDisables(StringArguments args, CommandHandler handler, DisableType disableType) static bool HandleRemoveDisables(StringArguments args, CommandHandler handler, DisableType disableType)
{ {
string entryStr = args.NextString(); if (!uint.TryParse(args.NextString(), out uint entry) || entry == 0)
if (string.IsNullOrEmpty(entryStr) || uint.Parse(entryStr) == 0)
return false; return false;
uint entry = uint.Parse(entryStr);
string disableTypeStr = ""; string disableTypeStr = "";
switch (disableType) switch (disableType)
{ {
+6 -6
View File
@@ -34,10 +34,10 @@ namespace Game.Chat
if (string.IsNullOrEmpty(id)) if (string.IsNullOrEmpty(id))
return false; return false;
ushort eventId = ushort.Parse(id); if (!ushort.TryParse(id, out ushort eventId))
return false;
var events = Global.GameEventMgr.GetEventMap(); var events = Global.GameEventMgr.GetEventMap();
if (eventId >= events.Length) if (eventId >= events.Length)
{ {
handler.SendSysMessage(CypherStrings.EventNotExist); handler.SendSysMessage(CypherStrings.EventNotExist);
@@ -109,10 +109,10 @@ namespace Game.Chat
if (string.IsNullOrEmpty(id)) if (string.IsNullOrEmpty(id))
return false; return false;
ushort eventId = ushort.Parse(id); if (!ushort.TryParse(id, out ushort eventId))
return false;
var events = Global.GameEventMgr.GetEventMap(); var events = Global.GameEventMgr.GetEventMap();
if (eventId < 1 || eventId >= events.Length) if (eventId < 1 || eventId >= events.Length)
{ {
handler.SendSysMessage(CypherStrings.EventNotExist); handler.SendSysMessage(CypherStrings.EventNotExist);
@@ -148,10 +148,10 @@ namespace Game.Chat
if (string.IsNullOrEmpty(id)) if (string.IsNullOrEmpty(id))
return false; return false;
ushort eventId = ushort.Parse(id); if (!ushort.TryParse(id, out ushort eventId))
return false;
var events = Global.GameEventMgr.GetEventMap(); var events = Global.GameEventMgr.GetEventMap();
if (eventId < 1 || eventId >= events.Length) if (eventId < 1 || eventId >= events.Length)
{ {
handler.SendSysMessage(CypherStrings.EventNotExist); handler.SendSysMessage(CypherStrings.EventNotExist);
+36 -27
View File
@@ -41,8 +41,7 @@ namespace Game.Chat
if (string.IsNullOrEmpty(id)) if (string.IsNullOrEmpty(id))
return false; return false;
ulong guidLow = ulong.Parse(id); if (!ulong.TryParse(id, out ulong guidLow) || guidLow == 0)
if (guidLow == 0)
return false; return false;
GameObject obj = handler.GetObjectFromPlayerMapByDbGuid(guidLow); GameObject obj = handler.GetObjectFromPlayerMapByDbGuid(guidLow);
@@ -68,8 +67,7 @@ namespace Game.Chat
if (string.IsNullOrEmpty(id)) if (string.IsNullOrEmpty(id))
return false; return false;
ulong guidLow = ulong.Parse(id); if (!ulong.TryParse(id, out ulong guidLow) || guidLow == 0)
if (guidLow == 0)
return false; return false;
GameObject obj = handler.GetObjectFromPlayerMapByDbGuid(guidLow); GameObject obj = handler.GetObjectFromPlayerMapByDbGuid(guidLow);
@@ -109,8 +107,7 @@ namespace Game.Chat
if (string.IsNullOrEmpty(id)) if (string.IsNullOrEmpty(id))
return false; return false;
ulong guidLow = ulong.Parse(id); if (!ulong.TryParse(id, out ulong guidLow) || guidLow == 0)
if (guidLow == 0)
return false; return false;
GameObject obj = handler.GetObjectFromPlayerMapByDbGuid(guidLow); GameObject obj = handler.GetObjectFromPlayerMapByDbGuid(guidLow);
@@ -132,12 +129,14 @@ namespace Game.Chat
} }
else else
{ {
if (string.IsNullOrEmpty(toY) || string.IsNullOrEmpty(toZ)) if (!float.TryParse(toX, out x))
return false; return false;
x = float.Parse(toX); if (!float.TryParse(toY, out y))
y = float.Parse(toY); return false;
z = float.Parse(toZ);
if (!float.TryParse(toZ, out z))
return false;
if (!GridDefines.IsValidMapCoord(obj.GetMapId(), x, y, z)) if (!GridDefines.IsValidMapCoord(obj.GetMapId(), x, y, z))
{ {
@@ -215,8 +214,7 @@ namespace Game.Chat
if (string.IsNullOrEmpty(idStr)) if (string.IsNullOrEmpty(idStr))
return false; return false;
uint objectId = uint.Parse(idStr); if (!uint.TryParse(idStr, out uint objectId) || objectId != 0)
if (objectId != 0)
result = DB.World.Query("SELECT guid, id, position_x, position_y, position_z, orientation, map, PhaseId, PhaseGroup, (POW(position_x - '{0}', 2) + POW(position_y - '{1}', 2) + POW(position_z - '{2}', 2)) AS order_ FROM gameobject WHERE map = '{3}' AND id = '{4}' ORDER BY order_ ASC LIMIT 1", 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); player.GetPositionX(), player.GetPositionY(), player.GetPositionZ(), player.GetMapId(), objectId);
else else
@@ -325,8 +323,7 @@ namespace Game.Chat
if (string.IsNullOrEmpty(id)) if (string.IsNullOrEmpty(id))
return false; return false;
ulong guidLow = ulong.Parse(id); if (!ulong.TryParse(id, out ulong guidLow) || guidLow == 0)
if (guidLow == 0)
return false; return false;
GameObject obj = handler.GetObjectFromPlayerMapByDbGuid(guidLow); GameObject obj = handler.GetObjectFromPlayerMapByDbGuid(guidLow);
@@ -340,15 +337,21 @@ namespace Game.Chat
float oz = 0.0f, oy = 0.0f, ox = 0.0f; float oz = 0.0f, oy = 0.0f, ox = 0.0f;
if (!orientation.IsEmpty()) if (!orientation.IsEmpty())
{ {
oz = float.Parse(orientation); if (!float.TryParse(orientation, out oz))
return false;
orientation = args.NextString(); orientation = args.NextString();
if (!orientation.IsEmpty()) if (!orientation.IsEmpty())
{ {
oy = float.Parse(orientation); if (!float.TryParse(orientation, out oy))
return false;
orientation = args.NextString(); orientation = args.NextString();
if (!orientation.IsEmpty()) if (!orientation.IsEmpty())
ox = float.Parse(orientation); {
if (!float.TryParse(orientation, out ox))
return false;
}
} }
} }
else else
@@ -392,14 +395,19 @@ namespace Game.Chat
if (cValue.IsEmpty()) if (cValue.IsEmpty())
return false; return false;
ulong guidLow = ulong.Parse(cValue); if (!ulong.TryParse(cValue, out ulong guidLow))
return false;
GameObjectData data = Global.ObjectMgr.GetGOData(guidLow); GameObjectData data = Global.ObjectMgr.GetGOData(guidLow);
if (data == null) if (data == null)
return false; return false;
entry = data.id; entry = data.id;
} }
else else
entry = uint.Parse(param1); {
if (!uint.TryParse(param1, out entry))
return false;
}
GameObjectTemplate gameObjectInfo = Global.ObjectMgr.GetGameObjectTemplate(entry); GameObjectTemplate gameObjectInfo = Global.ObjectMgr.GetGameObjectTemplate(entry);
if (gameObjectInfo == null) if (gameObjectInfo == null)
@@ -438,12 +446,11 @@ namespace Game.Chat
return false; return false;
// number or [name] Shift-click form |color|Hgameobject_entry:go_id|h[name]|h|r // number or [name] Shift-click form |color|Hgameobject_entry:go_id|h[name]|h|r
string id = handler.extractKeyFromLink(args, "Hgameobject_entry"); string idStr = handler.extractKeyFromLink(args, "Hgameobject_entry");
if (string.IsNullOrEmpty(id)) if (string.IsNullOrEmpty(idStr))
return false; return false;
uint objectId = uint.Parse(id); if (!uint.TryParse(idStr, out uint objectId) || objectId == 0)
if (objectId == 0)
return false; return false;
uint spawntimeSecs = args.NextUInt32(); uint spawntimeSecs = args.NextUInt32();
@@ -573,8 +580,7 @@ namespace Game.Chat
if (string.IsNullOrEmpty(id)) if (string.IsNullOrEmpty(id))
return false; return false;
ulong guidLow = ulong.Parse(id); if (!ulong.TryParse(id, out ulong guidLow) || guidLow == 0)
if (guidLow == 0)
return false; return false;
GameObject obj = handler.GetObjectFromPlayerMapByDbGuid(guidLow); GameObject obj = handler.GetObjectFromPlayerMapByDbGuid(guidLow);
@@ -588,7 +594,9 @@ namespace Game.Chat
if (string.IsNullOrEmpty(type)) if (string.IsNullOrEmpty(type))
return false; return false;
int objectType = int.Parse(type); if (!int.TryParse(type, out int objectType))
return false;
if (objectType < 0) if (objectType < 0)
{ {
if (objectType == -1) if (objectType == -1)
@@ -602,7 +610,8 @@ namespace Game.Chat
if (string.IsNullOrEmpty(state)) if (string.IsNullOrEmpty(state))
return false; return false;
uint objectState = uint.Parse(state); if (!uint.TryParse(state, out uint objectState))
return false;
if (objectType < 4) if (objectType < 4)
obj.SetByteValue(GameObjectFields.Bytes1, (byte)objectType, (byte)objectState); obj.SetByteValue(GameObjectFields.Bytes1, (byte)objectType, (byte)objectState);
+35 -43
View File
@@ -55,18 +55,15 @@ namespace Game.Chat.Commands
if (string.IsNullOrEmpty(idStr)) if (string.IsNullOrEmpty(idStr))
return false; return false;
int entry = int.Parse(idStr); if (!int.TryParse(idStr, out int entry) || entry == 0)
if (entry == 0)
return false; return false;
whereClause += "WHERE id = '" + entry + '\''; whereClause += "WHERE id = '" + entry + '\'';
} }
else else
{ {
ulong guidLow = ulong.Parse(param1);
// Number is invalid - maybe the user specified the mob's name // Number is invalid - maybe the user specified the mob's name
if (guidLow == 0) if (!ulong.TryParse(param1, out ulong guidLow) || guidLow == 0)
{ {
string name = param1; string name = param1;
whereClause += ", creature_template WHERE creature.id = creature_template.entry AND creature_template.name LIKE '" + name + '\''; whereClause += ", creature_template WHERE creature.id = creature_template.entry AND creature_template.name LIKE '" + name + '\'';
@@ -159,18 +156,18 @@ namespace Game.Chat.Commands
Player player = handler.GetSession().GetPlayer(); Player player = handler.GetSession().GetPlayer();
string gridX = args.NextString(); if (!float.TryParse(args.NextString(), out float gridX))
string gridY = args.NextString();
string id = args.NextString();
if (string.IsNullOrEmpty(gridX) || string.IsNullOrEmpty(gridY))
return false; return false;
uint mapId = !string.IsNullOrEmpty(id) ? uint.Parse(id) : player.GetMapId(); if (!float.TryParse(args.NextString(), out float gridY))
return false;
if (!uint.TryParse(args.NextString(), out uint mapId))
mapId = player.GetMapId();
// center of grid // center of grid
float x = (float.Parse(gridX) - MapConst.CenterGridId + 0.5f) * MapConst.SizeofGrids; float x = (gridX - MapConst.CenterGridId + 0.5f) * MapConst.SizeofGrids;
float y = (float.Parse(gridY) - MapConst.CenterGridId + 0.5f) * MapConst.SizeofGrids; float y = (gridY - MapConst.CenterGridId + 0.5f) * MapConst.SizeofGrids;
if (!GridDefines.IsValidMapCoord(mapId, x, y)) if (!GridDefines.IsValidMapCoord(mapId, x, y))
{ {
@@ -209,8 +206,7 @@ namespace Game.Chat.Commands
if (string.IsNullOrEmpty(id)) if (string.IsNullOrEmpty(id))
return false; return false;
ulong guidLow = ulong.Parse(id); if (!ulong.TryParse(id, out ulong guidLow) || guidLow == 0)
if (guidLow == 0)
return false; return false;
float x, y, z, o; float x, y, z, o;
@@ -264,8 +260,7 @@ namespace Game.Chat.Commands
if (string.IsNullOrEmpty(id)) if (string.IsNullOrEmpty(id))
return false; return false;
uint questID = uint.Parse(id); if (!uint.TryParse(id, out uint questID) || questID == 0)
if (questID == 0)
return false; return false;
if (Global.ObjectMgr.GetQuestTemplate(questID) == null) if (Global.ObjectMgr.GetQuestTemplate(questID) == null)
@@ -328,8 +323,7 @@ namespace Game.Chat.Commands
if (string.IsNullOrEmpty(id)) if (string.IsNullOrEmpty(id))
return false; return false;
uint nodeId = uint.Parse(id); if (!uint.TryParse(id, out uint nodeId) || nodeId == 0)
if (nodeId == 0)
return false; return false;
TaxiNodesRecord node = CliDB.TaxiNodesStorage.LookupByKey(nodeId); TaxiNodesRecord node = CliDB.TaxiNodesStorage.LookupByKey(nodeId);
@@ -408,25 +402,21 @@ namespace Game.Chat.Commands
Player player = handler.GetSession().GetPlayer(); Player player = handler.GetSession().GetPlayer();
string zoneX = args.NextString(); if (!float.TryParse(args.NextString(), out float x))
string zoneY = args.NextString();
string id = handler.extractKeyFromLink(args, "Harea"); // string or [name] Shift-click form |color|Harea:area_id|h[name]|h|r
if (string.IsNullOrEmpty(zoneX) || string.IsNullOrEmpty(zoneY))
return false; return false;
float x = float.Parse(zoneX); if (!float.TryParse(args.NextString(),out float y))
float y = float.Parse(zoneY); return false;
// prevent accept wrong numeric args // prevent accept wrong numeric args
if ((x == 0.0f && zoneX[0] != '0') || (y == 0.0f && zoneY[0] != '0')) if (x == 0.0f || y == 0.0f)
return false; return false;
uint areaId = !string.IsNullOrEmpty(id) ? uint.Parse(id) : player.GetZoneId(); string idStr = handler.extractKeyFromLink(args, "Harea"); // string or [name] Shift-click form |color|Harea:area_id|h[name]|h|r
if (!uint.TryParse(idStr, out uint areaId))
areaId = player.GetZoneId();
AreaTableRecord areaEntry = CliDB.AreaTableStorage.LookupByKey(areaId); AreaTableRecord areaEntry = CliDB.AreaTableStorage.LookupByKey(areaId);
if (x < 0 || x > 100 || y < 0 || y > 100 || areaEntry == null) if (x < 0 || x > 100 || y < 0 || y > 100 || areaEntry == null)
{ {
handler.SendSysMessage(CypherStrings.InvalidZoneCoord, x, y, areaId); handler.SendSysMessage(CypherStrings.InvalidZoneCoord, x, y, areaId);
@@ -478,24 +468,26 @@ namespace Game.Chat.Commands
Player player = handler.GetSession().GetPlayer(); Player player = handler.GetSession().GetPlayer();
string goX = args.NextString(); if (!float.TryParse(args.NextString(), out float x))
string goY = args.NextString();
string goZ = args.NextString();
string id = args.NextString();
string port = args.NextString();
if (goX.IsEmpty() || goY.IsEmpty())
return false; return false;
float x = float.Parse(goX); if (!float.TryParse(args.NextString(), out float y))
float y = float.Parse(goY); return false;
float z;
float ort = !port.IsEmpty() ? float.Parse(port) : player.GetOrientation();
uint mapId = !id.IsEmpty() ? uint.Parse(id) : player.GetMapId();
string goZ = args.NextString();
if (!uint.TryParse(args.NextString(), out uint mapId))
mapId = player.GetMapId();
if (!float.TryParse(args.NextString(), out float ort))
ort = player.GetOrientation();
float z;
if (!goZ.IsEmpty()) if (!goZ.IsEmpty())
{ {
z = float.Parse(goZ); if (!float.TryParse(goZ, out z))
return false;
if (!GridDefines.IsValidMapCoord(mapId, x, y, z)) if (!GridDefines.IsValidMapCoord(mapId, x, y, z))
{ {
handler.SendSysMessage(CypherStrings.InvalidTargetCoord, x, y, mapId); handler.SendSysMessage(CypherStrings.InvalidTargetCoord, x, y, mapId);
+3 -1
View File
@@ -138,7 +138,9 @@ namespace Game.Chat
if (!targetGuild) if (!targetGuild)
return false; return false;
byte newRank = byte.Parse(rankStr); if (!byte.TryParse(rankStr, out byte newRank))
return false;
return targetGuild.ChangeMemberRank(targetGuid, newRank); return targetGuild.ChangeMemberRank(targetGuid, newRank);
} }
+12 -11
View File
@@ -81,17 +81,15 @@ namespace Game.Chat
player = handler.GetSession().GetPlayer(); player = handler.GetSession().GetPlayer();
string map = args.NextString(); string map = args.NextString();
string pDiff = args.NextString(); if (!sbyte.TryParse(args.NextString(), out sbyte diff))
sbyte diff = -1; diff = -1;
if (string.IsNullOrEmpty(pDiff))
diff = sbyte.Parse(pDiff);
ushort counter = 0; ushort counter = 0;
ushort MapId = 0; ushort MapId = 0;
if (map != "all") if (map != "all")
{ {
MapId = ushort.Parse(map); if (!ushort.TryParse(map, out MapId) || MapId == 0)
if (MapId == 0)
return false; return false;
} }
@@ -159,8 +157,6 @@ namespace Game.Chat
string param1 = args.NextString(); string param1 = args.NextString();
string param2 = args.NextString(); string param2 = args.NextString();
string param3 = args.NextString(); string param3 = args.NextString();
uint encounterId = 0;
EncounterState state = 0;
Player player = null; Player player = null;
// Character name must be provided when using this from console. // Character name must be provided when using this from console.
@@ -197,8 +193,12 @@ namespace Game.Chat
return false; return false;
} }
encounterId = uint.Parse(param1); if (!uint.TryParse(param1, out uint encounterId))
state = (EncounterState)int.Parse(param2); return false;
EncounterState state = EncounterState.NotStarted;
if (int.TryParse(param2, out int param2Value))
state = (EncounterState)param2Value;
// Reject improper values. // Reject improper values.
if (state > EncounterState.ToBeDecided || encounterId > map.GetInstanceScript().GetEncounterCount()) if (state > EncounterState.ToBeDecided || encounterId > map.GetInstanceScript().GetEncounterCount())
@@ -257,7 +257,8 @@ namespace Game.Chat
return false; return false;
} }
encounterId = uint.Parse(param1); if (!uint.TryParse(param1, out encounterId))
return false;
if (encounterId > map.GetInstanceScript().GetEncounterCount()) if (encounterId > map.GetInstanceScript().GetEncounterCount())
{ {
+3 -4
View File
@@ -95,13 +95,12 @@ namespace Game.Chat
[Command("options", RBACPermissions.CommandLfgOptions, true)] [Command("options", RBACPermissions.CommandLfgOptions, true)]
static bool HandleLfgOptionsCommand(StringArguments args, CommandHandler handler) static bool HandleLfgOptionsCommand(StringArguments args, CommandHandler handler)
{ {
int options = -1;
string str = args.NextString(); string str = args.NextString();
int options = -1;
if (!string.IsNullOrEmpty(str)) if (!string.IsNullOrEmpty(str))
{ {
int tmp = int.Parse(str); if (!int.TryParse(str, out options) || options < -1)
if (tmp > -1) return false;
options = tmp;
} }
if (options != -1) if (options != -1)
+9 -11
View File
@@ -85,8 +85,7 @@ namespace Game.Chat.Commands
if (string.IsNullOrEmpty(id)) if (string.IsNullOrEmpty(id))
return false; return false;
uint creatureId = uint.Parse(id); if (!uint.TryParse(id, out uint creatureId) || creatureId == 0)
if (creatureId == 0)
{ {
handler.SendSysMessage(CypherStrings.CommandInvalidcreatureid, creatureId); handler.SendSysMessage(CypherStrings.CommandInvalidcreatureid, creatureId);
return false; return false;
@@ -100,7 +99,8 @@ namespace Game.Chat.Commands
} }
string countStr = args.NextString(); string countStr = args.NextString();
uint count = !string.IsNullOrEmpty(countStr) ? uint.Parse(countStr) : 10; if (!uint.TryParse(args.NextString(), out uint count))
count = 10;
if (count == 0) if (count == 0)
return false; return false;
@@ -153,8 +153,7 @@ namespace Game.Chat.Commands
if (string.IsNullOrEmpty(id)) if (string.IsNullOrEmpty(id))
return false; return false;
uint itemId = uint.Parse(id); if (!uint.TryParse(id, out uint itemId) || itemId == 0)
if (itemId == 0)
{ {
handler.SendSysMessage(CypherStrings.CommandItemidinvalid, itemId); handler.SendSysMessage(CypherStrings.CommandItemidinvalid, itemId);
return false; return false;
@@ -167,8 +166,8 @@ namespace Game.Chat.Commands
return false; return false;
} }
string countStr = args.NextString(); if (!uint.TryParse(args.NextString(), out uint count))
uint count = !string.IsNullOrEmpty(countStr) ? uint.Parse(countStr) : 10; count = 10;
if (count == 0) if (count == 0)
return false; return false;
@@ -470,8 +469,7 @@ namespace Game.Chat.Commands
if (string.IsNullOrEmpty(id)) if (string.IsNullOrEmpty(id))
return false; return false;
uint gameObjectId = uint.Parse(id); if (!uint.TryParse(id, out uint gameObjectId) || gameObjectId == 0)
if (gameObjectId == 0)
{ {
handler.SendSysMessage(CypherStrings.CommandListobjinvalidid, gameObjectId); handler.SendSysMessage(CypherStrings.CommandListobjinvalidid, gameObjectId);
return false; return false;
@@ -484,8 +482,8 @@ namespace Game.Chat.Commands
return false; return false;
} }
string countStr = args.NextString(); if (!uint.TryParse(args.NextString(), out uint count))
uint count = !string.IsNullOrEmpty(countStr) ? uint.Parse(countStr) : 10; count = 10;
if (count == 0) if (count == 0)
return false; return false;
+6 -3
View File
@@ -949,7 +949,8 @@ namespace Game.Chat
{ {
ip = args.NextString(); ip = args.NextString();
limitStr = args.NextString(); limitStr = args.NextString();
limit = string.IsNullOrEmpty(limitStr) ? -1 : int.Parse(limitStr); if (!int.TryParse(limitStr, out limit))
limit = -1;
} }
PreparedStatement stmt = DB.Login.GetPreparedStatement(LoginStatements.SEL_ACCOUNT_BY_IP); PreparedStatement stmt = DB.Login.GetPreparedStatement(LoginStatements.SEL_ACCOUNT_BY_IP);
@@ -965,7 +966,8 @@ namespace Game.Chat
string account = args.NextString(); string account = args.NextString();
string limitStr = args.NextString(); string limitStr = args.NextString();
int limit = string.IsNullOrEmpty(limitStr) ? -1 : int.Parse(limitStr); if (!int.TryParse(limitStr, out int limit))
limit = -1;
PreparedStatement stmt = DB.Login.GetPreparedStatement(LoginStatements.SEL_ACCOUNT_LIST_BY_NAME); PreparedStatement stmt = DB.Login.GetPreparedStatement(LoginStatements.SEL_ACCOUNT_LIST_BY_NAME);
stmt.AddValue(0, account); stmt.AddValue(0, account);
@@ -980,7 +982,8 @@ namespace Game.Chat
string email = args.NextString(); string email = args.NextString();
string limitStr = args.NextString(); string limitStr = args.NextString();
int limit = string.IsNullOrEmpty(limitStr) ? -1 : int.Parse(limitStr); if (!int.TryParse(limitStr, out int limit))
limit = -1;
PreparedStatement stmt = DB.Login.GetPreparedStatement(LoginStatements.SEL_ACCOUNT_LIST_BY_EMAIL); PreparedStatement stmt = DB.Login.GetPreparedStatement(LoginStatements.SEL_ACCOUNT_LIST_BY_EMAIL);
stmt.AddValue(0, email); stmt.AddValue(0, email);
+34 -27
View File
@@ -294,11 +294,11 @@ namespace Game.Chat
} }
else // item_id or [name] Shift-click form |color|Hitem:item_id:0:0:0|h[name]|h|r else // item_id or [name] Shift-click form |color|Hitem:item_id:0:0:0|h[name]|h|r
{ {
string id = handler.extractKeyFromLink(args, "Hitem"); string idStr = handler.extractKeyFromLink(args, "Hitem");
if (string.IsNullOrEmpty(id)) if (string.IsNullOrEmpty(idStr))
return false; return false;
if (!uint.TryParse(id, out itemId)) if (!uint.TryParse(idStr, out itemId))
return false; return false;
} }
@@ -314,7 +314,11 @@ namespace Game.Chat
{ {
var tokens = new StringArray(bonuses, ';'); var tokens = new StringArray(bonuses, ';');
for (var i = 0; i < tokens.Length; ++i) for (var i = 0; i < tokens.Length; ++i)
bonusListIDs.Add(uint.Parse(tokens[i])); {
if (uint.TryParse(tokens[i], out uint id))
bonusListIDs.Add(id);
}
} }
Player player = handler.GetSession().GetPlayer(); Player player = handler.GetSession().GetPlayer();
@@ -386,14 +390,12 @@ namespace Game.Chat
if (args.Empty()) if (args.Empty())
return false; return false;
string id = handler.extractKeyFromLink(args, "Hitemset"); // number or [name] Shift-click form |color|Hitemset:itemset_id|h[name]|h|r string idStr = handler.extractKeyFromLink(args, "Hitemset"); // number or [name] Shift-click form |color|Hitemset:itemset_id|h[name]|h|r
if (string.IsNullOrEmpty(id)) if (string.IsNullOrEmpty(idStr))
return false; return false;
uint itemSetId = uint.Parse(id);
// prevent generation all items with itemset field value '0' // prevent generation all items with itemset field value '0'
if (itemSetId == 0) if (!uint.TryParse(idStr, out uint itemSetId) || itemSetId == 0)
{ {
handler.SendSysMessage(CypherStrings.NoItemsFromItemsetFound, itemSetId); handler.SendSysMessage(CypherStrings.NoItemsFromItemsetFound, itemSetId);
return false; return false;
@@ -407,7 +409,10 @@ namespace Game.Chat
{ {
var tokens = new StringArray(bonuses, ';'); var tokens = new StringArray(bonuses, ';');
for (var i = 0; i < tokens.Length; ++i) for (var i = 0; i < tokens.Length; ++i)
bonusListIDs.Add(uint.Parse(tokens[i])); {
if (uint.TryParse(tokens[i], out uint id))
bonusListIDs.Add(id);
}
} }
Player player = handler.GetSession().GetPlayer(); Player player = handler.GetSession().GetPlayer();
@@ -1263,15 +1268,14 @@ namespace Game.Chat
return false; return false;
} }
// *Change the weather of a cell // *Change the weather of a cell
string px = args.NextString(); //0 to 3, 0: fine, 1: rain, 2: snow, 3: sand
string py = args.NextString(); if (!uint.TryParse(args.NextString(), out uint type))
return false;
if (string.IsNullOrEmpty(px) || string.IsNullOrEmpty(py))
return false; //0 to 1, sending -1 is instand good weather
if (!float.TryParse(args.NextString(), out float grade))
uint type = uint.Parse(px); //0 to 3, 0: fine, 1: rain, 2: snow, 3: sand return false;
float grade = float.Parse(py); //0 to 1, sending -1 is instand good weather
Player player = handler.GetSession().GetPlayer(); Player player = handler.GetSession().GetPlayer();
uint zoneid = player.GetZoneId(); uint zoneid = player.GetZoneId();
@@ -1694,7 +1698,8 @@ namespace Game.Chat
target = session.GetPlayer(); target = session.GetPlayer();
} }
uint notSpeakTime = uint.Parse(delayStr); if (!uint.TryParse(delayStr, out uint notSpeakTime))
return false;
// must have strong lesser security level // must have strong lesser security level
if (handler.HasLowerSecurity(target, targetGuid, true)) if (handler.HasLowerSecurity(target, targetGuid, true))
@@ -2024,7 +2029,9 @@ namespace Game.Chat
if (!target.IsAlive()) if (!target.IsAlive())
return true; return true;
int damage_int = int.Parse(str); if (!int.TryParse(str, out int damage_int))
return false;
if (damage_int <= 0) if (damage_int <= 0)
return true; return true;
@@ -2041,8 +2048,7 @@ namespace Game.Chat
return true; return true;
} }
int school = int.Parse(schoolStr); if (!int.TryParse(schoolStr, out int school) || school >= (int)SpellSchools.Max)
if (school >= (int)SpellSchools.Max)
return false; return false;
SpellSchoolMask schoolmask = (SpellSchoolMask)(1 << school); SpellSchoolMask schoolmask = (SpellSchoolMask)(1 << school);
@@ -2165,7 +2171,8 @@ namespace Game.Chat
{ {
// case 2: .freeze duration // case 2: .freeze duration
// We have a selected player. We'll check him later // We have a selected player. We'll check him later
freezeDuration = int.Parse(arg1); if (!int.TryParse(arg1, out freezeDuration))
return false;
canApplyFreeze = true; canApplyFreeze = true;
} }
else else
@@ -2178,7 +2185,8 @@ namespace Game.Chat
// Check if we have duration set // Check if we have duration set
if (!arg2.IsEmpty() && arg2.IsNumber()) if (!arg2.IsEmpty() && arg2.IsNumber())
{ {
freezeDuration = int.Parse(arg2); if (!int.TryParse(arg2, out freezeDuration))
return false;
canApplyFreeze = true; canApplyFreeze = true;
} }
else else
@@ -2441,8 +2449,7 @@ namespace Game.Chat
if (string.IsNullOrEmpty(idStr)) if (string.IsNullOrEmpty(idStr))
return false; return false;
uint achievementId = uint.Parse(idStr); if (!uint.TryParse(idStr, out uint achievementId) || achievementId == 0)
if (achievementId == 0)
return false; return false;
Player target = handler.getSelectedPlayer(); Player target = handler.getSelectedPlayer();
+11 -38
View File
@@ -121,7 +121,7 @@ namespace Game.Chat
return false; return false;
} }
if (string.IsNullOrEmpty(pfactionid)) if (!uint.TryParse(pfactionid, out uint factionid))
{ {
uint _factionid = target.getFaction(); uint _factionid = target.getFaction();
uint _flag = target.GetUInt32Value(UnitFields.Flags); uint _flag = target.GetUInt32Value(UnitFields.Flags);
@@ -131,35 +131,18 @@ namespace Game.Chat
return true; return true;
} }
uint factionid = uint.Parse(pfactionid); if (!uint.TryParse(args.NextString(), out uint flag))
uint flag;
string pflag = args.NextString();
if (string.IsNullOrEmpty(pflag))
flag = target.GetUInt32Value(UnitFields.Flags); flag = target.GetUInt32Value(UnitFields.Flags);
else
flag = uint.Parse(pflag);
string pnpcflag = args.NextString(); if (!ulong.TryParse(args.NextString(), out ulong npcflag))
ulong npcflag;
if (string.IsNullOrEmpty(pnpcflag))
npcflag = target.GetUInt64Value(UnitFields.NpcFlags); npcflag = target.GetUInt64Value(UnitFields.NpcFlags);
else
npcflag = ulong.Parse(pnpcflag);
string pdyflag = args.NextString(); if (!uint.TryParse(args.NextString(), out uint dyflag))
uint dyflag;
if (string.IsNullOrEmpty(pdyflag))
dyflag = target.GetUInt32Value(ObjectFields.DynamicFlags); dyflag = target.GetUInt32Value(ObjectFields.DynamicFlags);
else
dyflag = uint.Parse(pdyflag);
if (!CliDB.FactionTemplateStorage.ContainsKey(factionid)) if (!CliDB.FactionTemplateStorage.ContainsKey(factionid))
{ {
handler.SendSysMessage(CypherStrings.WrongFaction, factionid); handler.SendSysMessage(CypherStrings.WrongFaction, factionid);
return false; return false;
} }
@@ -191,13 +174,8 @@ namespace Game.Chat
if (val == 0) if (val == 0)
return false; return false;
ushort mark; if (!ushort.TryParse(args.NextString(), out ushort mark))
string pmark = args.NextString();
if (string.IsNullOrEmpty(pmark))
mark = 65535; mark = 65535;
else
mark = ushort.Parse(pmark);
Player target = handler.getSelectedPlayerOrSelf(); Player target = handler.getSelectedPlayerOrSelf();
if (!target) if (!target)
@@ -250,11 +228,7 @@ namespace Game.Chat
if (args.Empty()) if (args.Empty())
return false; return false;
string mountStr = args.NextString(); if (!uint.TryParse(args.NextString(), out uint mount))
if (mountStr.IsEmpty())
return false;
if (uint.TryParse(mountStr, out uint mount))
return false; return false;
if (!CliDB.CreatureDisplayInfoStorage.HasRecord(mount)) if (!CliDB.CreatureDisplayInfoStorage.HasRecord(mount))
@@ -336,7 +310,7 @@ namespace Game.Chat
if ((ulong)moneyToAdd >= PlayerConst.MaxMoneyAmount) if ((ulong)moneyToAdd >= PlayerConst.MaxMoneyAmount)
moneyToAdd = Convert.ToInt64(PlayerConst.MaxMoneyAmount); moneyToAdd = Convert.ToInt64(PlayerConst.MaxMoneyAmount);
moneyToAdd = Math.Min(moneyToAdd, (long)(PlayerConst.MaxMoneyAmount - targetMoney)); moneyToAdd = (long)Math.Min((ulong)moneyToAdd, (PlayerConst.MaxMoneyAmount - targetMoney));
target.ModifyMoney(moneyToAdd); target.ModifyMoney(moneyToAdd);
} }
@@ -454,14 +428,14 @@ namespace Game.Chat
if (string.IsNullOrEmpty(factionTxt)) if (string.IsNullOrEmpty(factionTxt))
return false; return false;
uint factionId = uint.Parse(factionTxt); if (!uint.TryParse(factionTxt, out uint factionId))
return false;
int amount = 0; int amount = 0;
string rankTxt = args.NextString(); string rankTxt = args.NextString();
if (factionId == 0 || rankTxt.IsEmpty()) if (factionId == 0 || !int.TryParse(rankTxt, out amount))
return false; return false;
amount = int.Parse(rankTxt);
if ((amount == 0) && !(amount < 0) && !rankTxt.IsNumber()) if ((amount == 0) && !(amount < 0) && !rankTxt.IsNumber())
{ {
string rankStr = rankTxt.ToLower(); string rankStr = rankTxt.ToLower();
@@ -479,8 +453,7 @@ namespace Game.Chat
string deltaTxt = args.NextString(); string deltaTxt = args.NextString();
if (!string.IsNullOrEmpty(deltaTxt)) if (!string.IsNullOrEmpty(deltaTxt))
{ {
int delta = int.Parse(deltaTxt); if (!int.TryParse(deltaTxt, out int delta) || delta < 0 || (delta > ReputationMgr.PointsInRank[r] - 1))
if ((delta < 0) || (delta > ReputationMgr.PointsInRank[r] - 1))
{ {
handler.SendSysMessage(CypherStrings.CommandFactionDelta, (ReputationMgr.PointsInRank[r] - 1)); handler.SendSysMessage(CypherStrings.CommandFactionDelta, (ReputationMgr.PointsInRank[r] - 1));
return false; return false;
+23 -30
View File
@@ -133,7 +133,8 @@ namespace Game.Chat
if (string.IsNullOrEmpty(cId)) if (string.IsNullOrEmpty(cId))
return false; return false;
lowguid = uint.Parse(cId); if (!ulong.TryParse(cId, out lowguid))
return false;
// Attempting creature load from DB data // Attempting creature load from DB data
CreatureData data = Global.ObjectMgr.GetCreatureData(lowguid); CreatureData data = Global.ObjectMgr.GetCreatureData(lowguid);
@@ -330,7 +331,10 @@ namespace Game.Chat
return false; return false;
} }
ObjectGuid receiver_guid = ObjectGuid.Create(HighGuid.Player, ulong.Parse(receiver_str)); if (!ulong.TryParse(receiver_str, out ulong guid))
return false;
ObjectGuid receiver_guid = ObjectGuid.Create(HighGuid.Player, guid);
// check online security // check online security
Player receiver = Global.ObjAccessor.FindPlayer(receiver_guid); Player receiver = Global.ObjAccessor.FindPlayer(receiver_guid);
@@ -541,11 +545,10 @@ namespace Game.Chat
if (string.IsNullOrEmpty(cId)) if (string.IsNullOrEmpty(cId))
return false; return false;
ulong lowguid = ulong.Parse(cId); if (!ulong.TryParse(cId, out ulong guidLow) || guidLow == 0)
if (lowguid == 0)
return false; return false;
unit = handler.GetCreatureFromPlayerMapByDbGuid(lowguid); unit = handler.GetCreatureFromPlayerMapByDbGuid(guidLow);
} }
else else
unit = handler.getSelectedCreature(); unit = handler.getSelectedCreature();
@@ -585,7 +588,9 @@ namespace Game.Chat
handler.SendSysMessage(CypherStrings.CommandNeeditemsend); handler.SendSysMessage(CypherStrings.CommandNeeditemsend);
return false; return false;
} }
uint itemId = uint.Parse(pitem);
if (!uint.TryParse(pitem, out uint itemId))
return false;
ItemVendorType type = ItemVendorType.Item; // FIXME: make type (1 item, 2 currency) an argument ItemVendorType type = ItemVendorType.Item; // FIXME: make type (1 item, 2 currency) an argument
@@ -596,7 +601,6 @@ namespace Game.Chat
} }
ItemTemplate itemTemplate = Global.ObjectMgr.GetItemTemplate(itemId); ItemTemplate itemTemplate = Global.ObjectMgr.GetItemTemplate(itemId);
handler.SendSysMessage(CypherStrings.ItemDeletedFromList, itemId, itemTemplate.GetName()); handler.SendSysMessage(CypherStrings.ItemDeletedFromList, itemId, itemTemplate.GetName());
return true; return true;
} }
@@ -752,20 +756,13 @@ namespace Game.Chat
if (args.Empty()) if (args.Empty())
return false; return false;
string arg1 = args.NextString(); uint data_1 = args.NextUInt32();
string arg2 = args.NextString(); uint data_2 = args.NextUInt32();
if (string.IsNullOrEmpty(arg1) || string.IsNullOrEmpty(arg2))
return false;
uint data_1 = uint.Parse(arg1);
uint data_2 = uint.Parse(arg2);
if (data_1 == 0 || data_2 == 0) if (data_1 == 0 || data_2 == 0)
return false; return false;
Creature creature = handler.getSelectedCreature(); Creature creature = handler.getSelectedCreature();
if (!creature) if (!creature)
{ {
handler.SendSysMessage(CypherStrings.SelectCreature); handler.SendSysMessage(CypherStrings.SelectCreature);
@@ -862,9 +859,7 @@ namespace Game.Chat
} }
else // case .setmovetype #creature_guid $move_type (with selected creature) else // case .setmovetype #creature_guid $move_type (with selected creature)
{ {
lowguid = uint.Parse(guid_str); if (!ulong.TryParse(guid_str, out lowguid) || lowguid != 0)
if (lowguid != 0)
creature = handler.GetCreatureFromPlayerMapByDbGuid(lowguid); creature = handler.GetCreatureFromPlayerMapByDbGuid(lowguid);
// attempt check creature existence by DB data // attempt check creature existence by DB data
@@ -1095,8 +1090,7 @@ namespace Game.Chat
if (string.IsNullOrEmpty(charID)) if (string.IsNullOrEmpty(charID))
return false; return false;
uint id = uint.Parse(charID); if (!uint.TryParse(charID, out uint id) || Global.ObjectMgr.GetCreatureTemplate(id) == null)
if (Global.ObjectMgr.GetCreatureTemplate(id) == null)
return false; return false;
Player chr = handler.GetSession().GetPlayer(); Player chr = handler.GetSession().GetPlayer();
@@ -1160,8 +1154,7 @@ namespace Game.Chat
return false; return false;
} }
uint itemId = uint.Parse(pitem); if (!uint.TryParse(pitem, out uint itemId) || itemId == 0)
if (itemId == 0)
return false; return false;
uint maxcount = args.NextUInt32(); uint maxcount = args.NextUInt32();
@@ -1189,7 +1182,10 @@ namespace Game.Chat
{ {
var bonusListIDsTok = new StringArray(fbonuslist, ';'); var bonusListIDsTok = new StringArray(fbonuslist, ';');
foreach (string token in bonusListIDsTok) foreach (string token in bonusListIDsTok)
vItem.BonusListIDs.Add(uint.Parse(token)); {
if (uint.TryParse(token, out uint id))
vItem.BonusListIDs.Add(id);
}
} }
if (!Global.ObjectMgr.IsVendorItemValid(vendor_entry, vItem, handler.GetSession().GetPlayer())) if (!Global.ObjectMgr.IsVendorItemValid(vendor_entry, vItem, handler.GetSession().GetPlayer()))
@@ -1220,8 +1216,7 @@ namespace Game.Chat
return false; return false;
} }
int wait = !string.IsNullOrEmpty(waitStr) ? int.Parse(waitStr) : 0; if (!int.TryParse(waitStr, out int wait) || wait < 0)
if (wait < 0)
wait = 0; wait = 0;
// Update movement type // Update movement type
@@ -1301,15 +1296,13 @@ namespace Game.Chat
if (string.IsNullOrEmpty(charID)) if (string.IsNullOrEmpty(charID))
return false; return false;
Player chr = handler.GetSession().GetPlayer(); if (!uint.TryParse(charID, out uint id) || id == 0)
uint id = uint.Parse(charID);
if (id == 0)
return false; return false;
if (Global.ObjectMgr.GetCreatureTemplate(id) == null) if (Global.ObjectMgr.GetCreatureTemplate(id) == null)
return false; return false;
Player chr = handler.GetSession().GetPlayer();
chr.SummonCreature(id, chr, loot ? TempSummonType.CorpseTimedDespawn : TempSummonType.CorpseDespawn, 30 * Time.InMilliseconds); chr.SummonCreature(id, chr, loot ? TempSummonType.CorpseTimedDespawn : TempSummonType.CorpseDespawn, 30 * Time.InMilliseconds);
return true; return true;
+4 -12
View File
@@ -40,11 +40,9 @@ namespace Game.Chat
// .addquest #entry' // .addquest #entry'
// number or [name] Shift-click form |color|Hquest:quest_id:quest_level|h[name]|h|r // number or [name] Shift-click form |color|Hquest:quest_id:quest_level|h[name]|h|r
string cId = handler.extractKeyFromLink(args, "Hquest"); string cId = handler.extractKeyFromLink(args, "Hquest");
if (string.IsNullOrEmpty(cId)) if (!uint.TryParse(cId, out uint entry))
return false; return false;
uint entry = uint.Parse(cId);
Quest quest = Global.ObjectMgr.GetQuestTemplate(entry); Quest quest = Global.ObjectMgr.GetQuestTemplate(entry);
if (quest == null) if (quest == null)
{ {
@@ -82,11 +80,9 @@ namespace Game.Chat
// .quest complete #entry // .quest complete #entry
// number or [name] Shift-click form |color|Hquest:quest_id:quest_level|h[name]|h|r // number or [name] Shift-click form |color|Hquest:quest_id:quest_level|h[name]|h|r
string cId = handler.extractKeyFromLink(args, "Hquest"); string cId = handler.extractKeyFromLink(args, "Hquest");
if (string.IsNullOrEmpty(cId)) if (!uint.TryParse(cId, out uint entry))
return false; return false;
uint entry = uint.Parse(cId);
Quest quest = Global.ObjectMgr.GetQuestTemplate(entry); Quest quest = Global.ObjectMgr.GetQuestTemplate(entry);
// If player doesn't have the quest // If player doesn't have the quest
@@ -176,11 +172,9 @@ namespace Game.Chat
// .removequest #entry' // .removequest #entry'
// number or [name] Shift-click form |color|Hquest:quest_id:quest_level|h[name]|h|r // number or [name] Shift-click form |color|Hquest:quest_id:quest_level|h[name]|h|r
string cId = handler.extractKeyFromLink(args, "Hquest"); string cId = handler.extractKeyFromLink(args, "Hquest");
if (string.IsNullOrEmpty(cId)) if (!uint.TryParse(cId, out uint entry))
return false; return false;
uint entry = uint.Parse(cId);
Quest quest = Global.ObjectMgr.GetQuestTemplate(entry); Quest quest = Global.ObjectMgr.GetQuestTemplate(entry);
if (quest == null) if (quest == null)
{ {
@@ -229,11 +223,9 @@ namespace Game.Chat
// .quest reward #entry // .quest reward #entry
// number or [name] Shift-click form |color|Hquest:quest_id:quest_level|h[name]|h|r // number or [name] Shift-click form |color|Hquest:quest_id:quest_level|h[name]|h|r
string cId = handler.extractKeyFromLink(args, "Hquest"); string cId = handler.extractKeyFromLink(args, "Hquest");
if (string.IsNullOrEmpty(cId)) if (!uint.TryParse(cId, out uint entry))
return false; return false;
uint entry = uint.Parse(cId);
Quest quest = Global.ObjectMgr.GetQuestTemplate(entry); Quest quest = Global.ObjectMgr.GetQuestTemplate(entry);
// If player doesn't have the quest // If player doesn't have the quest
+9 -6
View File
@@ -236,18 +236,21 @@ namespace Game.Chat.Commands
{ {
if (string.IsNullOrEmpty(param3)) if (string.IsNullOrEmpty(param3))
{ {
if (!string.IsNullOrEmpty(param2)) if (!int.TryParse(param2, out realmId))
realmId = int.Parse(param2); return null;
if (!string.IsNullOrEmpty(param1)) if (!uint.TryParse(param1, out id))
id = uint.Parse(param1); return null;
useSelectedPlayer = true; useSelectedPlayer = true;
} }
else else
{ {
id = uint.Parse(param2); if (!uint.TryParse(param2, out id))
realmId = int.Parse(param3); return null;
if (!int.TryParse(param3, out realmId))
return null;
} }
if (id == 0) if (id == 0)
+4 -13
View File
@@ -67,11 +67,7 @@ namespace Game.Chat
if (args.Empty()) if (args.Empty())
return false; return false;
string sceneIdStr = args.NextString(); uint sceneId = args.NextUInt32();
if (sceneIdStr.IsEmpty())
return false;
uint sceneId = uint.Parse(sceneIdStr);
Player target = handler.getSelectedPlayerOrSelf(); Player target = handler.getSelectedPlayerOrSelf();
if (!target) if (!target)
{ {
@@ -92,16 +88,11 @@ namespace Game.Chat
if (args.Empty()) if (args.Empty())
return false; return false;
string scenePackageIdStr = args.NextString(); uint scenePackageId = args.NextUInt32();
string flagsStr = args.NextString(""); if (!uint.TryParse(args.NextString(""), out uint flags))
flags = (uint)SceneFlags.Unk16;
if (scenePackageIdStr.IsEmpty())
return false;
uint scenePackageId = uint.Parse(scenePackageIdStr);
uint flags = !flagsStr.IsEmpty() ? uint.Parse(flagsStr) : (uint)SceneFlags.Unk16;
Player target = handler.getSelectedPlayerOrSelf(); Player target = handler.getSelectedPlayerOrSelf();
if (!target) if (!target)
{ {
handler.SendSysMessage(CypherStrings.PlayerNotFound); handler.SendSysMessage(CypherStrings.PlayerNotFound);
+8 -5
View File
@@ -108,8 +108,7 @@ namespace Game.Chat.Commands
string itemIdStr = itemStr.NextString(":"); string itemIdStr = itemStr.NextString(":");
string itemCountStr = itemStr.NextString(" "); string itemCountStr = itemStr.NextString(" ");
uint itemId = uint.Parse(itemIdStr); if (!uint.TryParse(itemIdStr, out uint itemId) || itemId == 0)
if (itemId == 0)
return false; return false;
ItemTemplate item_proto = Global.ObjectMgr.GetItemTemplate(itemId); ItemTemplate item_proto = Global.ObjectMgr.GetItemTemplate(itemId);
@@ -119,7 +118,10 @@ namespace Game.Chat.Commands
return false; return false;
} }
uint itemCount = !string.IsNullOrEmpty(itemCountStr) ? uint.Parse(itemCountStr) : 1; uint itemCount = 0;
if (string.IsNullOrEmpty(itemCountStr) || !uint.TryParse(itemCountStr, out itemCount))
itemCount = 1;
if (itemCount < 1 || (item_proto.GetMaxCount() > 0 && itemCount > item_proto.GetMaxCount())) if (itemCount < 1 || (item_proto.GetMaxCount() > 0 && itemCount > item_proto.GetMaxCount()))
{ {
handler.SendSysMessage(CypherStrings.CommandInvalidItemCount, itemCount, itemId); handler.SendSysMessage(CypherStrings.CommandInvalidItemCount, itemCount, itemId);
@@ -194,8 +196,9 @@ namespace Game.Chat.Commands
if (string.IsNullOrEmpty(text)) if (string.IsNullOrEmpty(text))
return false; return false;
string moneyStr = args.NextString(""); if (!long.TryParse(args.NextString(""), out long money))
long money = !string.IsNullOrEmpty(moneyStr) ? long.Parse(moneyStr) : 0; money = 0;
if (money <= 0) if (money <= 0)
return false; return false;
+6 -4
View File
@@ -100,7 +100,9 @@ namespace Game.Chat
Global.WorldMgr.LoadDBAllowedSecurityLevel(); Global.WorldMgr.LoadDBAllowedSecurityLevel();
break; break;
default: default:
int value = int.Parse(paramStr); if (!int.TryParse(paramStr, out int value))
return false;
if (value < 0) if (value < 0)
Global.WorldMgr.SetPlayerSecurityLimit((AccountTypes)(-value)); Global.WorldMgr.SetPlayerSecurityLimit((AccountTypes)(-value));
else else
@@ -148,7 +150,8 @@ namespace Game.Chat
static bool ParseExitCode(string exitCodeStr, out int exitCode) static bool ParseExitCode(string exitCodeStr, out int exitCode)
{ {
exitCode = int.Parse(exitCodeStr); if (!int.TryParse(exitCodeStr, out exitCode))
return false;
// Handle atoi() errors // Handle atoi() errors
if (exitCode == 0 && (exitCodeStr[0] != '0' || (exitCodeStr.Length > 1 && exitCodeStr[1] != '\0'))) if (exitCode == 0 && (exitCodeStr[0] != '0' || (exitCodeStr.Length > 1 && exitCodeStr[1] != '\0')))
@@ -317,8 +320,7 @@ namespace Game.Chat
if (newTimeStr.IsEmpty()) if (newTimeStr.IsEmpty())
return false; return false;
int newTime = int.Parse(newTimeStr); if (!int.TryParse(newTimeStr, out int newTime) || newTime < 0)
if (newTime < 0)
return false; return false;
//Global.WorldMgr.SetRecordDiffInterval(newTime); //Global.WorldMgr.SetRecordDiffInterval(newTime);
+7 -10
View File
@@ -146,20 +146,16 @@ namespace Game.Chat
if (string.IsNullOrEmpty(skillStr)) if (string.IsNullOrEmpty(skillStr))
return false; return false;
string levelStr = args.NextString(); if (!uint.TryParse(skillStr, out uint skill) || skill == 0)
if (string.IsNullOrEmpty(levelStr))
return false;
string maxPureSkill = args.NextString();
uint skill = uint.Parse(skillStr);
if (skill == 0)
{ {
handler.SendSysMessage(CypherStrings.InvalidSkillId, skill); handler.SendSysMessage(CypherStrings.InvalidSkillId, skill);
return false; return false;
} }
uint level = uint.Parse(levelStr); uint level = args.NextUInt32();
if (level == 0)
return false;
Player target = handler.getSelectedPlayerOrSelf(); Player target = handler.getSelectedPlayerOrSelf();
if (!target) if (!target)
{ {
@@ -176,9 +172,10 @@ namespace Game.Chat
bool targetHasSkill = target.GetSkillValue((SkillType)skill) != 0; bool targetHasSkill = target.GetSkillValue((SkillType)skill) != 0;
ushort maxPureSkill = args.NextUInt16();
// If our target does not yet have the skill they are trying to add to them, the chosen level also becomes // If our target does not yet have the skill they are trying to add to them, the chosen level also becomes
// the max level of the new profession. // the max level of the new profession.
ushort max = !string.IsNullOrEmpty(maxPureSkill) ? ushort.Parse(maxPureSkill) : targetHasSkill ? target.GetPureMaxSkillValue((SkillType)skill) : (ushort)level; ushort max = maxPureSkill != 0 ? maxPureSkill : targetHasSkill ? target.GetPureMaxSkillValue((SkillType)skill) : (ushort)level;
if (level == 0 || level > max || max <= 0) if (level == 0 || level > max || max <= 0)
return false; return false;
+3 -6
View File
@@ -35,8 +35,7 @@ namespace Game.Chat.Commands
if (string.IsNullOrEmpty(id_p)) if (string.IsNullOrEmpty(id_p))
return false; return false;
uint id = uint.Parse(id_p); if (!uint.TryParse(id_p, out uint id) || id == 0)
if (id == 0)
{ {
handler.SendSysMessage(CypherStrings.InvalidTitleId, id); handler.SendSysMessage(CypherStrings.InvalidTitleId, id);
return false; return false;
@@ -77,8 +76,7 @@ namespace Game.Chat.Commands
if (string.IsNullOrEmpty(id_p)) if (string.IsNullOrEmpty(id_p))
return false; return false;
uint id = uint.Parse(id_p); if (!uint.TryParse(id_p, out uint id) || id == 0)
if (id == 0)
{ {
handler.SendSysMessage(CypherStrings.InvalidTitleId, id); handler.SendSysMessage(CypherStrings.InvalidTitleId, id);
return false; return false;
@@ -120,8 +118,7 @@ namespace Game.Chat.Commands
if (string.IsNullOrEmpty(id_p)) if (string.IsNullOrEmpty(id_p))
return false; return false;
uint id = uint.Parse(id_p); if (!uint.TryParse(id_p, out uint id) || id == 0)
if (id == 0)
{ {
handler.SendSysMessage(CypherStrings.InvalidTitleId, id); handler.SendSysMessage(CypherStrings.InvalidTitleId, id);
return false; return false;
+36 -17
View File
@@ -57,7 +57,10 @@ namespace Game.Chat.Commands
} }
} }
else else
pathid = uint.Parse(path_number); {
if (!uint.TryParse(path_number, out pathid))
return false;
}
// path_id . ID of the Path // path_id . ID of the Path
// point . number of the waypoint (if not 0) // point . number of the waypoint (if not 0)
@@ -107,8 +110,8 @@ namespace Game.Chat.Commands
uint id = 0; uint id = 0;
if (show == "add") if (show == "add")
{ {
if (!string.IsNullOrEmpty(arg_id)) if (!uint.TryParse(arg_id, out id))
id = uint.Parse(arg_id); id = 0;
if (id != 0) if (id != 0)
{ {
@@ -151,7 +154,8 @@ namespace Game.Chat.Commands
return true; return true;
} }
id = uint.Parse(arg_id); if (!uint.TryParse(arg_id, out id))
return false;
uint a2, a3, a4, a5, a6; uint a2, a3, a4, a5, a6;
float a8, a9, a10, a11; float a8, a9, a10, a11;
@@ -195,7 +199,8 @@ namespace Game.Chat.Commands
return true; return true;
} }
id = uint.Parse(arg_id); if (!uint.TryParse(arg_id, out id))
return false;
stmt = DB.World.GetPreparedStatement(WorldStatements.SEL_WAYPOINT_SCRIPT_ID_BY_GUID); stmt = DB.World.GetPreparedStatement(WorldStatements.SEL_WAYPOINT_SCRIPT_ID_BY_GUID);
stmt.AddValue(0, id); stmt.AddValue(0, id);
@@ -223,9 +228,7 @@ namespace Game.Chat.Commands
return true; return true;
} }
id = uint.Parse(arg_id); if (!uint.TryParse(arg_id, out id) || id == 0)
if (id == 0)
{ {
handler.SendSysMessage("|cffff33ffERROR: No valid waypoint script id not present.|r"); handler.SendSysMessage("|cffff33ffERROR: No valid waypoint script id not present.|r");
return true; return true;
@@ -255,7 +258,8 @@ namespace Game.Chat.Commands
if (arg_string == "setid") if (arg_string == "setid")
{ {
uint newid = uint.Parse(arg_3); if (!uint.TryParse(arg_3, out uint newid))
return false;
handler.SendSysMessage("|cff00ff00Wp Event: Waypoint script guid: {0}|r|cff00ffff id changed: |r|cff00ff00{1}|r", newid, id); handler.SendSysMessage("|cff00ff00Wp Event: Waypoint script guid: {0}|r|cff00ffff id changed: |r|cff00ff00{1}|r", newid, id);
stmt = DB.World.GetPreparedStatement(WorldStatements.UPD_WAYPOINT_SCRIPT_ID); stmt = DB.World.GetPreparedStatement(WorldStatements.UPD_WAYPOINT_SCRIPT_ID);
@@ -280,8 +284,11 @@ namespace Game.Chat.Commands
if (arg_string == "posx") if (arg_string == "posx")
{ {
if (!float.TryParse(arg_3, out float arg3))
return false;
stmt = DB.World.GetPreparedStatement(WorldStatements.UPD_WAYPOINT_SCRIPT_X); stmt = DB.World.GetPreparedStatement(WorldStatements.UPD_WAYPOINT_SCRIPT_X);
stmt.AddValue(0, float.Parse(arg_3)); stmt.AddValue(0, arg3);
stmt.AddValue(1, id); stmt.AddValue(1, id);
DB.World.Execute(stmt); DB.World.Execute(stmt);
@@ -290,8 +297,11 @@ namespace Game.Chat.Commands
} }
else if (arg_string == "posy") else if (arg_string == "posy")
{ {
if (!float.TryParse(arg_3, out float arg3))
return false;
stmt = DB.World.GetPreparedStatement(WorldStatements.UPD_WAYPOINT_SCRIPT_Y); stmt = DB.World.GetPreparedStatement(WorldStatements.UPD_WAYPOINT_SCRIPT_Y);
stmt.AddValue(0, float.Parse(arg_3)); stmt.AddValue(0, arg3);
stmt.AddValue(1, id); stmt.AddValue(1, id);
DB.World.Execute(stmt); DB.World.Execute(stmt);
@@ -300,8 +310,11 @@ namespace Game.Chat.Commands
} }
else if (arg_string == "posz") else if (arg_string == "posz")
{ {
if (!float.TryParse(arg_3, out float arg3))
return false;
stmt = DB.World.GetPreparedStatement(WorldStatements.UPD_WAYPOINT_SCRIPT_Z); stmt = DB.World.GetPreparedStatement(WorldStatements.UPD_WAYPOINT_SCRIPT_Z);
stmt.AddValue(0, float.Parse(arg_3)); stmt.AddValue(0, args);
stmt.AddValue(1, id); stmt.AddValue(1, id);
DB.World.Execute(stmt); DB.World.Execute(stmt);
@@ -310,8 +323,11 @@ namespace Game.Chat.Commands
} }
else if (arg_string == "orientation") else if (arg_string == "orientation")
{ {
if (!float.TryParse(arg_3, out float arg3))
return false;
stmt = DB.World.GetPreparedStatement(WorldStatements.UPD_WAYPOINT_SCRIPT_O); stmt = DB.World.GetPreparedStatement(WorldStatements.UPD_WAYPOINT_SCRIPT_O);
stmt.AddValue(0, float.Parse(arg_3)); stmt.AddValue(0, arg3);
stmt.AddValue(1, id); stmt.AddValue(1, id);
DB.World.Execute(stmt); DB.World.Execute(stmt);
@@ -320,7 +336,10 @@ namespace Game.Chat.Commands
} }
else if (arg_string == "dataint") else if (arg_string == "dataint")
{ {
DB.World.Execute("UPDATE waypoint_scripts SET {0}='{1}' WHERE guid='{2}'", arg_string, uint.Parse(arg_3), id); // Query can't be a prepared statement if (!uint.TryParse(arg_3, out uint arg3))
return false;
DB.World.Execute("UPDATE waypoint_scripts SET {0}='{1}' WHERE guid='{2}'", arg_string, arg3, id); // Query can't be a prepared statement
handler.SendSysMessage("|cff00ff00Waypoint script: |r|cff00ffff{0}|r|cff00ff00 dataint updated.|r", id); handler.SendSysMessage("|cff00ff00Waypoint script: |r|cff00ffff{0}|r|cff00ff00 dataint updated.|r", id);
return true; return true;
@@ -364,8 +383,7 @@ namespace Game.Chat.Commands
return false; return false;
} }
pathid = uint.Parse(path_number); if (!uint.TryParse(path_number, out pathid) || pathid == 0)
if (pathid == 0)
{ {
handler.SendSysMessage("|cffff33ffNo valid path number provided.|r"); handler.SendSysMessage("|cffff33ffNo valid path number provided.|r");
return true; return true;
@@ -624,7 +642,8 @@ namespace Game.Chat.Commands
if (target) if (target)
handler.SendSysMessage(CypherStrings.WaypointCreatselected); handler.SendSysMessage(CypherStrings.WaypointCreatselected);
pathid = uint.Parse(guid_str); if (!uint.TryParse(guid_str, out pathid))
return false;
} }
// Show info for the selected waypoint // Show info for the selected waypoint
+14 -7
View File
@@ -86,18 +86,25 @@ namespace Game
continue; continue;
} }
if (flags.HasAnyFlag<byte>(DisableFlags.SpellMap)) if (flags.HasAnyFlag(DisableFlags.SpellMap))
{ {
var array = new StringArray(params_0, ','); var array = new StringArray(params_0, ',');
for (byte i = 0; i < array.Length;) for (byte i = 0; i < array.Length;)
data.param0.Add(uint.Parse(array[i++])); {
if (uint.TryParse(array[i++], out uint id))
data.param0.Add(id);
}
} }
if (flags.HasAnyFlag<byte>(DisableFlags.SpellArea)) if (flags.HasAnyFlag(DisableFlags.SpellArea))
{ {
var array = new StringArray(params_1, ','); var array = new StringArray(params_1, ',');
for (byte i = 0; i < array.Length;) for (byte i = 0; i < array.Length;)
data.param1.Add(uint.Parse(array[i++])); {
if (uint.TryParse(array[i++], out uint id))
data.param1.Add(id);
}
} }
break; break;
@@ -121,11 +128,11 @@ namespace Game
break; break;
case MapTypes.Instance: case MapTypes.Instance:
case MapTypes.Raid: case MapTypes.Raid:
if (flags.HasAnyFlag<byte>(DisableFlags.DungeonStatusHeroic) && Global.DB2Mgr.GetMapDifficultyData(entry, Difficulty.Heroic) == null) if (flags.HasAnyFlag(DisableFlags.DungeonStatusHeroic) && Global.DB2Mgr.GetMapDifficultyData(entry, Difficulty.Heroic) == null)
flags -= DisableFlags.DungeonStatusHeroic; flags -= DisableFlags.DungeonStatusHeroic;
if (flags.HasAnyFlag<byte>(DisableFlags.DungeonStatusHeroic10Man) && Global.DB2Mgr.GetMapDifficultyData(entry, Difficulty.Raid10HC) == null) if (flags.HasAnyFlag(DisableFlags.DungeonStatusHeroic10Man) && Global.DB2Mgr.GetMapDifficultyData(entry, Difficulty.Raid10HC) == null)
flags -= DisableFlags.DungeonStatusHeroic10Man; flags -= DisableFlags.DungeonStatusHeroic10Man;
if (flags.HasAnyFlag<byte>(DisableFlags.DungeonStatusHeroic25Man) && Global.DB2Mgr.GetMapDifficultyData(entry, Difficulty.Raid25HC) == null) if (flags.HasAnyFlag(DisableFlags.DungeonStatusHeroic25Man) && Global.DB2Mgr.GetMapDifficultyData(entry, Difficulty.Raid25HC) == null)
flags -= DisableFlags.DungeonStatusHeroic25Man; flags -= DisableFlags.DungeonStatusHeroic25Man;
if (flags == 0) if (flags == 0)
isFlagInvalid = true; isFlagInvalid = true;
+9 -6
View File
@@ -422,7 +422,10 @@ namespace Game.Entities
var tokens = new StringArray(fields.Read<string>(6), ' '); var tokens = new StringArray(fields.Read<string>(6), ' ');
if (tokens.Length == ItemConst.MaxProtoSpells) if (tokens.Length == ItemConst.MaxProtoSpells)
for (byte i = 0; i < ItemConst.MaxProtoSpells; ++i) for (byte i = 0; i < ItemConst.MaxProtoSpells; ++i)
SetSpellCharges(i, int.Parse(tokens[i])); {
if (int.TryParse(tokens[i], out int value))
SetSpellCharges(i, value);
}
SetUInt32Value(ItemFields.Flags, itemFlags); SetUInt32Value(ItemFields.Flags, itemFlags);
@@ -477,8 +480,8 @@ namespace Game.Entities
var bonusListIDs = new StringArray(fields.Read<string>(20), ' '); var bonusListIDs = new StringArray(fields.Read<string>(20), ' ');
for (var i = 0; i < bonusListIDs.Length; ++i) for (var i = 0; i < bonusListIDs.Length; ++i)
{ {
uint bonusListID = uint.Parse(tokens[i]); if (uint.TryParse(tokens[i], out uint bonusListID))
AddBonuses(bonusListID); AddBonuses(bonusListID);
} }
SetModifier(ItemModifier.TransmogAppearanceAllSpecs, fields.Read<uint>(21)); SetModifier(ItemModifier.TransmogAppearanceAllSpecs, fields.Read<uint>(21));
@@ -503,8 +506,7 @@ namespace Game.Entities
uint b = 0; uint b = 0;
foreach (string token in gemBonusListIDs) foreach (string token in gemBonusListIDs)
{ {
uint bonusListID = uint.Parse(token); if (uint.TryParse(token, out uint bonusListID) && bonusListID != 0)
if (bonusListID != 0)
gemData[i].BonusListIDs[b++] = (ushort)bonusListID; gemData[i].BonusListIDs[b++] = (ushort)bonusListID;
} }
@@ -1904,7 +1906,8 @@ namespace Game.Entities
StringArray bonusLists = new StringArray(item_result.Read<string>(12), ' '); StringArray bonusLists = new StringArray(item_result.Read<string>(12), ' ');
foreach (string line in bonusLists) foreach (string line in bonusLists)
{ {
loot_item.BonusListIDs.Add(uint.Parse(line)); if (uint.TryParse(line, out uint id))
loot_item.BonusListIDs.Add(id);
} }
// Copy the extra loot conditions from the item in the loot template // Copy the extra loot conditions from the item in the loot template
+5 -2
View File
@@ -1054,8 +1054,11 @@ namespace Game.Entities
for (var index = 0; index < count; ++index) for (var index = 0; index < count; ++index)
{ {
UpdateData[(int)startOffset + index] = uint.Parse(lines[index]); if (uint.TryParse(lines[index], out uint value))
_changesMask.Set((int)(startOffset + index), true); {
UpdateData[(int)startOffset + index] = value;
_changesMask.Set((int)(startOffset + index), true);
}
} }
} }
+8 -3
View File
@@ -284,8 +284,10 @@ namespace Game.Entities
var GUIDlist = new StringArray(strGUID, ' '); var GUIDlist = new StringArray(strGUID, ' ');
List<ObjectGuid> looters = new List<ObjectGuid>(); List<ObjectGuid> looters = new List<ObjectGuid>();
for (var i = 0; i < GUIDlist.Length; ++i) for (var i = 0; i < GUIDlist.Length; ++i)
looters.Add(ObjectGuid.Create(HighGuid.Item, ulong.Parse(GUIDlist[i]))); {
if (ulong.TryParse(GUIDlist[i], out ulong guid))
looters.Add(ObjectGuid.Create(HighGuid.Item, guid));
}
if (looters.Count > 1 && item.GetTemplate().GetMaxStackSize() == 1 && item.IsSoulBound()) if (looters.Count > 1 && item.GetTemplate().GetMaxStackSize() == 1 && item.IsSoulBound())
{ {
@@ -1083,7 +1085,10 @@ namespace Game.Entities
List<uint> bonusListIDs = new List<uint>(); List<uint> bonusListIDs = new List<uint>();
var bonusListIdTokens = new StringArray(result.Read<string>(11), ' '); var bonusListIdTokens = new StringArray(result.Read<string>(11), ' ');
for (var i = 0; i < bonusListIdTokens.Length; ++i) for (var i = 0; i < bonusListIdTokens.Length; ++i)
bonusListIDs.Add(uint.Parse(bonusListIdTokens[i])); {
if (uint.TryParse(bonusListIdTokens[i], out uint id))
bonusListIDs.Add(id);
}
if (itemId == 0) if (itemId == 0)
{ {
+5 -4
View File
@@ -109,7 +109,8 @@ namespace Game.Entities
for (var i = 0; index < PlayerConst.TaxiMaskSize && i != split.Length; ++i, ++index) for (var i = 0; index < PlayerConst.TaxiMaskSize && i != split.Length; ++i, ++index)
{ {
// load and set bits only for existing taxi nodes // load and set bits only for existing taxi nodes
m_taximask[index] = (byte)(CliDB.TaxiNodesMask[index] & uint.Parse(split[i])); if (uint.TryParse(split[i], out uint id))
m_taximask[index] = (byte)(CliDB.TaxiNodesMask[index] & id);
} }
} }
@@ -127,12 +128,12 @@ namespace Game.Entities
var stringArray = new StringArray(values, ' '); var stringArray = new StringArray(values, ' ');
if (stringArray.Length > 0) if (stringArray.Length > 0)
m_flightMasterFactionId = uint.Parse(stringArray[0]); uint.TryParse(stringArray[0], out m_flightMasterFactionId);
for (var i = 1; i < stringArray.Length; ++i) for (var i = 1; i < stringArray.Length; ++i)
{ {
uint node = uint.Parse(stringArray[i]); if (uint.TryParse(stringArray[i], out uint node))
AddTaxiDestination(node); AddTaxiDestination(node);
} }
if (m_TaxiDestinations.Empty()) if (m_TaxiDestinations.Empty())
+1 -1
View File
@@ -252,7 +252,7 @@ namespace Game.Entities
for (byte i = 0; i < tokens.Length && index < SharedConst.ActionBarIndexEnd; ++i, ++index) for (byte i = 0; i < tokens.Length && index < SharedConst.ActionBarIndexEnd; ++i, ++index)
{ {
ActiveStates type = tokens[i++].ToEnum<ActiveStates>(); ActiveStates type = tokens[i++].ToEnum<ActiveStates>();
uint action = uint.Parse(tokens[i]); uint.TryParse(tokens[i], out uint action);
PetActionBar[index].SetActionAndType(action, type); PetActionBar[index].SetActionAndType(action, type);
+8 -2
View File
@@ -3125,7 +3125,10 @@ namespace Game
var bonusListIDsTok = new StringArray(result.Read<string>(6), ' '); var bonusListIDsTok = new StringArray(result.Read<string>(6), ' ');
foreach (string token in bonusListIDsTok) foreach (string token in bonusListIDsTok)
vItem.BonusListIDs.Add(uint.Parse(token)); {
if (uint.TryParse(token, out uint id))
vItem.BonusListIDs.Add(id);
}
if (!IsVendorItemValid(entry, vItem, null, skipvendors)) if (!IsVendorItemValid(entry, vItem, null, skipvendors))
continue; continue;
@@ -3171,7 +3174,10 @@ namespace Game
var bonusListIDsTok = new StringArray(result.Read<string>(5), ' '); var bonusListIDsTok = new StringArray(result.Read<string>(5), ' ');
foreach (string token in bonusListIDsTok) foreach (string token in bonusListIDsTok)
vItem.BonusListIDs.Add(uint.Parse(token)); {
if (uint.TryParse(token, out uint id))
vItem.BonusListIDs.Add(id);
}
if (!IsVendorItemValid((uint)vendor, vItem, null, skip_vendors)) if (!IsVendorItemValid((uint)vendor, vItem, null, skip_vendors))
continue; continue;
+4 -1
View File
@@ -1977,7 +1977,10 @@ namespace Game
} }
for (int index = 0; index < ktcount; ++index) for (int index = 0; index < ktcount; ++index)
knownTitles[index] = uint.Parse(tokens[index]); {
if (uint.TryParse(tokens[index], out uint id))
knownTitles[index] = id;
}
foreach (var it in Global.ObjectMgr.FactionChangeTitles) foreach (var it in Global.ObjectMgr.FactionChangeTitles)
{ {