Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Used string comparisons ignoring case #226

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion E3Next/Classes/Magician.cs
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ public static void ArmPets()
{
if (e3util.IsShuttingDown() || E3.IsPaused()) return;

if (string.Equals(ownerSpawn.Name, E3.CurrentName)) continue;
if (E3.CurrentName.EqualsIns(ownerSpawn.Name)) continue;
var theirPetId = ownerSpawn.PetID;
if (theirPetId < 0)
{
Expand Down
2 changes: 0 additions & 2 deletions E3Next/E3.cs
Original file line number Diff line number Diff line change
Expand Up @@ -357,8 +357,6 @@ private static void Init()
CurrentId = MQ.Query<int>("${Me.ID}");
//do first to get class information


CurrentName = MQ.Query<string>("${Me.CleanName}");
ServerName = e3util.FormatServerName(MQ.Query<string>("${MacroQuest.Server}"));
//deal with the Shadow Knight class issue.
string classValue =e3util.ClassNameFix(MQ.Query<string>("${Me.Class}"));
Expand Down
18 changes: 9 additions & 9 deletions E3Next/Processors/Alerts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,7 @@ private static void RegisterEvents()
pattern = "roars with fury as it surveys its attackers";
EventProcessor.RegisterEvent("Ture_warning", pattern, (x) => {
{

if (E3.CurrentName == MQ.Query<string>("${Raid.Leader}"))
if (IsRaidLeader())
{
MQ.Cmd($"/rsay AE Rampage INC 5 seconds.");
}
Expand All @@ -128,8 +127,7 @@ private static void RegisterEvents()
pattern = "eyes roll into its head as it goes into a frenzy";
EventProcessor.RegisterEvent("Ture_Ramp_Start", pattern, (x) => {
{

if (E3.CurrentName == MQ.Query<string>("${Raid.Leader}"))
if (IsRaidLeader())
{
MQ.Cmd($"/rsay -+- 10k AE Rampage Started -+-");
}
Expand All @@ -142,8 +140,7 @@ private static void RegisterEvents()
pattern = "calms and regains its focus";
EventProcessor.RegisterEvent("Ture_Ramp_End", pattern, (x) => {
{

if (E3.CurrentName == MQ.Query<string>("${Raid.Leader}"))
if (IsRaidLeader())
{
MQ.Cmd($"/rsay -+- Boss Safe - AE Rampage ended -+-");
}
Expand All @@ -156,8 +153,7 @@ private static void RegisterEvents()
pattern = "Keldovan the Harrier regains his combat stance";
EventProcessor.RegisterEvent("Keldovan_Power", pattern, (x) => {
{

if (E3.CurrentName == MQ.Query<string>("${Raid.Leader}"))
if (IsRaidLeader())
{
MQ.Cmd($"/rsay -+- Keldovan has regained a power - KILL A DOG -+-");
}
Expand Down Expand Up @@ -190,7 +186,7 @@ private static void RegisterEvents()
{
string mobname = x.match.Groups[1].Value;
string personName = x.match.Groups[2].Value;
if(E3.CurrentName==personName)
if(E3.CurrentName.EqualsIns(personName))
{
MQ.Cmd($"/g I have reflected {mobname} spell!");
}
Expand Down Expand Up @@ -223,5 +219,9 @@ private static void RegisterEvents()

});
}

private static Boolean IsRaidLeader() {
return E3.CurrentName.EqualsIns(MQ.Query<string>("${Raid.Leader}"));
}
}
}
2 changes: 1 addition & 1 deletion E3Next/Processors/Basics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ public static void RegisterEvents()

EventProcessor.RegisterCommand("/pizza", (x) =>
{
if (E3.CurrentName == "Reek")
if (E3.CurrentName.EqualsIns("Reek"))
{
System.Diagnostics.Process.Start("https://ordering.orders2.me/menu/pontillos-pizzeria-hudson-ridge");
}
Expand Down
2 changes: 1 addition & 1 deletion E3Next/Processors/Casting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1841,7 +1841,7 @@ public static Int64 TimeLeftOnMySpell(Data.Spell spell)
{
//check if its mine
string casterName = MQ.Query<string>($"${{Target.Buff[{i}].Caster}}");
if (E3.CurrentName == casterName)
if (E3.CurrentName.EqualsIns(casterName))
{
//its my spell!
Int64 millisecondsLeft = MQ.Query<Int64>($"${{Target.BuffDuration[{i}]}}");
Expand Down
4 changes: 2 additions & 2 deletions E3Next/Processors/Loot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ private static void RegisterEvents()
EventProcessor.RegisterCommand("/looton", (x) =>
{

if (x.args.Count >0 && E3.Bots.BotsConnected().Contains(x.args[0], StringComparer.OrdinalIgnoreCase) && !x.args[0].Equals(E3.CurrentName, StringComparison.OrdinalIgnoreCase))
if (x.args.Count >0 && E3.Bots.BotsConnected().Contains(x.args[0], StringComparer.OrdinalIgnoreCase) && !E3.CurrentName.EqualsIns(x.args[0]))
{
if (x.args.Count == 2 && x.args[1] == "force")
{
Expand All @@ -104,7 +104,7 @@ private static void RegisterEvents()
});
EventProcessor.RegisterCommand("/lootoff", (x) =>
{
if (x.args.Count > 0 && !x.args[0].Equals(E3.CurrentName, StringComparison.OrdinalIgnoreCase))
if (x.args.Count > 0 && !E3.CurrentName.EqualsIns(x.args[0]))
{
E3.Bots.BroadcastCommandToPerson(x.args[0], "/lootoff");
}
Expand Down
18 changes: 9 additions & 9 deletions E3Next/Processors/Rez.cs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ public static void RefreshCorpseList(RezType rezType = RezType.AE)
continue;

}
if(spawn.DisplayName == E3.CurrentName)
if(E3.CurrentName.EqualsIns(spawn.DisplayName))
{
//rez ourself last
rezOurself = true;
Expand All @@ -231,7 +231,7 @@ public static void RefreshCorpseList(RezType rezType = RezType.AE)
continue;

}
if (spawn.DisplayName == E3.CurrentName)
if (E3.CurrentName.EqualsIns(spawn.DisplayName))
{
//rez ourself last
rezOurself = true;
Expand Down Expand Up @@ -262,7 +262,7 @@ public static void RefreshCorpseList(RezType rezType = RezType.AE)
continue;

}
if(spawn.DisplayName == E3.CurrentName)
if(E3.CurrentName.EqualsIns(spawn.DisplayName))
{
//rez ourself last
rezOurself = true;
Expand All @@ -281,7 +281,7 @@ public static void RefreshCorpseList(RezType rezType = RezType.AE)
//lists are super small so contains is fine
if (!_corpseList.Contains(spawn.ID))
{
if (spawn.DisplayName == E3.CurrentName)
if (E3.CurrentName.EqualsIns(spawn.DisplayName))
{
_corpseList.Add(spawn.ID);
}
Expand Down Expand Up @@ -653,7 +653,7 @@ private static void RegisterEvents()
{
string user = x.args[0];

if (user == E3.CurrentName)
if (E3.CurrentName.EqualsIns(user))
{
//its a me!
MultiRez();
Expand All @@ -676,7 +676,7 @@ private static void RegisterEvents()
{
string user = x.args[0];

if (user == E3.CurrentName)
if (E3.CurrentName.EqualsIns(user))
{
//its a me!
MultiRez(RezType.Group);
Expand All @@ -701,7 +701,7 @@ private static void RegisterEvents()
{
string user = x.args[0];

if (user == E3.CurrentName)
Copy link
Owner

Choose a reason for hiding this comment

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

forgot to do the spawn.DisplayName == E3.CurrentName types

Copy link
Owner

Choose a reason for hiding this comment

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

i just found all occurances of E3.CurrentName

Copy link
Owner

Choose a reason for hiding this comment

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

Also, have to remove the places where the first character is now upper cased as we are allowing anything to be in the config file and making it non case sensitive, so casting target will also have to use the new compairson i think

Copy link
Owner

Choose a reason for hiding this comment

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

thankfully TryByName in the spawns class is case insensitive already

Copy link
Contributor Author

@Lyricalpanda Lyricalpanda Feb 28, 2024

Choose a reason for hiding this comment

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

I left spawn.DisplayName == CurrentName, since I wasn't sure if we wanted to keep those case comparisons and that seemed intentional. It sounds like everything can be case insensitive then? Or are there cases we do care about case?

Copy link
Owner

Choose a reason for hiding this comment

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

other than using the containskey in said if staement

Copy link
Contributor Author

@Lyricalpanda Lyricalpanda Mar 19, 2024

Choose a reason for hiding this comment

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

I was just tracing usage of target for so casting target will also have to use the new compairson i think.

string target = E3.CurrentName
if (!_spawns.TryByName(target, out var spawn)) { }

So target should be fine, as getting/setting should be non case sensitive? At least in buffCheck

And

if (_spawns.TryByName(spell.CastTarget, out var spawn))

Copy link
Owner

Choose a reason for hiding this comment

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

if you read up in the comments, i already said trybyname was fine as it wasn't case sensitive :) its the other stuff tho

Copy link
Owner

Choose a reason for hiding this comment

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

basically anything with a == marks :P

Copy link
Contributor Author

@Lyricalpanda Lyricalpanda Mar 19, 2024

Choose a reason for hiding this comment

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

Oh, well then trybyname is fine :p. I was just trying to be exhaustive around other usages. Only things I saw was the target = E3.CurrentName, Spell.CastTarget = CharacterName, and e3.firstCharToUpper. But my traces seemed like they'd be okay?

Screenshot 2024-03-19 095138
Screenshot 2024-03-19 095149

if (E3.CurrentName.EqualsIns(user))
{
//its a me!
MultiRez(RezType.GroupOrRaid);
Expand Down Expand Up @@ -817,7 +817,7 @@ private static void RegisterEvents()
if(x.args.Count>0)
{
//is it us?
if(x.args[0].Equals(E3.CurrentName, StringComparison.OrdinalIgnoreCase))
if(E3.CurrentName.EqualsIns(x.args[0]))
{
//its us! lets wait
_waitingOnRez = true;
Expand All @@ -841,7 +841,7 @@ private static void RegisterEvents()
{
var sender = x.match.Groups[1].Value;
// of course i know him. he's me
if (string.Equals(sender, E3.CurrentName)) return;
if (E3.CurrentName.EqualsIns(sender)) return;

MQ.Cmd($"/consent {sender}");
}
Expand Down
5 changes: 3 additions & 2 deletions E3Next/Server/SharedDataClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using E3Core.Data;
using E3Core.Processors;
using E3Core.Settings;
using E3Core.Utility;
using MonoCore;
using NetMQ;
using NetMQ.Sockets;
Expand Down Expand Up @@ -181,7 +182,7 @@ public void ProcessCommands()
if (typeInfo == OnCommandData.CommandType.OnCommandGroup || typeInfo == OnCommandData.CommandType.OnCommandGroupZone)
{
//check to see if we are part of their group
if (user == E3.CurrentName)
if (E3.CurrentName.EqualsIns(user))
{
//not for us only group members
continue;
Expand Down Expand Up @@ -218,7 +219,7 @@ public void ProcessCommands()
}

//check to see if we are part of their group
if (user == E3.CurrentName && (!(typeInfo == OnCommandData.CommandType.OnCommandName||typeInfo== OnCommandData.CommandType.OnCommandGroupAll || typeInfo == OnCommandData.CommandType.OnCommandAll || typeInfo== OnCommandData.CommandType.OnCommandGroupAllZone|| typeInfo==OnCommandData.CommandType.OnCommandAllZone)))
if (E3.CurrentName.EqualsIns(user) && (!(typeInfo == OnCommandData.CommandType.OnCommandName||typeInfo== OnCommandData.CommandType.OnCommandGroupAll || typeInfo == OnCommandData.CommandType.OnCommandAll || typeInfo== OnCommandData.CommandType.OnCommandGroupAllZone|| typeInfo==OnCommandData.CommandType.OnCommandAllZone)))
{
//if not an all type command and not us, kick out.
//not for us only group members
Expand Down
6 changes: 6 additions & 0 deletions E3Next/Utility/e3util.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ public static void PutOriginalTargetBackIfNeeded(Int32 targetid)
}
}
}

public static Boolean EqualsIns(this string str, string compareStr)
{
return str.Equals(compareStr, StringComparison.OrdinalIgnoreCase);
}

public static string ReplaceInsensitive(this string str,
string oldValue, string newValue)
{
Expand Down