Implement Mute Function.

This commit is contained in:
SilicaAndPina 2021-03-23 19:13:40 +13:00
parent b15e6996fe
commit 5308b53c89
9 changed files with 302 additions and 55 deletions

View file

@ -55,19 +55,19 @@ namespace HISP.Game.Chat
{
if (message[0] == '%')
{
if (message.StartsWith("%GIVE"))
if (message.ToUpper().StartsWith("%GIVE"))
return Command.Give(message, args, user);
if (message.StartsWith("%GOTO"))
if (message.ToUpper().StartsWith("%GOTO"))
return Command.Goto(message, args, user);
if (message.StartsWith("%KICK"))
if (message.ToUpper().StartsWith("%KICK"))
return Command.Kick(message, args, user);
if (message.StartsWith("%NOCLIP"))
if (message.ToUpper().StartsWith("%NOCLIP"))
return Command.NoClip(message, args, user);
if (message.StartsWith("%BAN"))
if (message.ToUpper().StartsWith("%BAN"))
return Command.Ban(message, args, user);
if (message.StartsWith("%UNBAN"))
if (message.ToUpper().StartsWith("%UNBAN"))
return Command.UnBan(message, args, user);
if (message.StartsWith("%ESCAPE"))
if (message.ToUpper().StartsWith("%ESCAPE"))
return Command.Escape(message, args, user);
return false;
}
@ -75,33 +75,90 @@ namespace HISP.Game.Chat
}
if (message[0] == '!')
{
// Alias for !MUTE
if (message.StartsWith("!MUTEALL"))
if (message.ToUpper().StartsWith("!MUTEALL"))
return Command.Mute(message, new string[] { "ALL" }, user);
else if (message.StartsWith("!MUTEADS"))
else if (message.ToUpper().StartsWith("!MUTEADS"))
return Command.Mute(message, new string[] { "ADS" }, user);
else if (message.StartsWith("!MUTEGLOBAL"))
else if (message.ToUpper().StartsWith("!MUTEGLOBAL"))
return Command.Mute(message, new string[] { "GLOBAL" }, user);
else if (message.StartsWith("!MUTEISLAND"))
else if (message.ToUpper().StartsWith("!MUTEISLAND"))
return Command.Mute(message, new string[] { "ISLAND" }, user);
else if (message.StartsWith("!MUTENEAR"))
else if (message.ToUpper().StartsWith("!MUTENEAR"))
return Command.Mute(message, new string[] { "NEAR" }, user);
else if (message.StartsWith("!MUTEHERE"))
else if (message.ToUpper().StartsWith("!MUTEHERE"))
return Command.Mute(message, new string[] { "HERE" }, user);
else if (message.StartsWith("!MUTEBUDDY"))
else if (message.ToUpper().StartsWith("!MUTEBUDDY"))
return Command.Mute(message, new string[] { "BUDDY" }, user);
else if (message.StartsWith("!MUTEPM"))
else if (message.ToUpper().StartsWith("!MUTEPM"))
return Command.Mute(message, new string[] { "PM" }, user);
else if (message.StartsWith("!MUTEBR"))
else if (message.ToUpper().StartsWith("!MUTEBR"))
return Command.Mute(message, new string[] { "BR" }, user);
else if (message.StartsWith("!MUTESOCIALS"))
else if (message.ToUpper().StartsWith("!MUTESOCIALS"))
return Command.Mute(message, new string[] { "SOCIALS" }, user);
else if (message.StartsWith("!MUTELOGINS"))
else if (message.ToUpper().StartsWith("!MUTELOGINS"))
return Command.Mute(message, new string[] { "LOGINS" }, user);
else if (message.StartsWith("!MUTE"))
else if (message.ToUpper().StartsWith("!MUTE"))
return Command.Mute(message, args, user);
else if (message.StartsWith("!WARP"))
// Alias for !UNMUTE
else if (message.ToUpper().StartsWith("!UNMUTEALL"))
return Command.UnMute(message, new string[] { "ALL" }, user);
else if (message.ToUpper().StartsWith("!UNMUTEADS"))
return Command.UnMute(message, new string[] { "ADS" }, user);
else if (message.ToUpper().StartsWith("!UNMUTEGLOBAL"))
return Command.UnMute(message, new string[] { "GLOBAL" }, user);
else if (message.ToUpper().StartsWith("!UNMUTEISLAND"))
return Command.UnMute(message, new string[] { "ISLAND" }, user);
else if (message.ToUpper().StartsWith("!UNMUTENEAR"))
return Command.UnMute(message, new string[] { "NEAR" }, user);
else if (message.ToUpper().StartsWith("!UNMUTEHERE"))
return Command.UnMute(message, new string[] { "HERE" }, user);
else if (message.ToUpper().StartsWith("!UNMUTEBUDDY"))
return Command.UnMute(message, new string[] { "BUDDY" }, user);
else if (message.ToUpper().StartsWith("!UNMUTEPM"))
return Command.UnMute(message, new string[] { "PM" }, user);
else if (message.ToUpper().StartsWith("!UNMUTEBR"))
return Command.UnMute(message, new string[] { "BR" }, user);
else if (message.ToUpper().StartsWith("!UNMUTESOCIALS"))
return Command.UnMute(message, new string[] { "SOCIALS" }, user);
else if (message.ToUpper().StartsWith("!UNMUTELOGINS"))
return Command.UnMute(message, new string[] { "LOGINS" }, user);
else if (message.ToUpper().StartsWith("!UNMUTE"))
return Command.UnMute(message, args, user);
// Alias for !HEAR
else if (message.ToUpper().StartsWith("!HEARALL"))
return Command.UnMute(message, new string[] { "ALL" }, user);
else if (message.ToUpper().StartsWith("!HEARADS"))
return Command.UnMute(message, new string[] { "ADS" }, user);
else if (message.ToUpper().StartsWith("!HEARGLOBAL"))
return Command.UnMute(message, new string[] { "GLOBAL" }, user);
else if (message.ToUpper().StartsWith("!HEARISLAND"))
return Command.UnMute(message, new string[] { "ISLAND" }, user);
else if (message.ToUpper().StartsWith("!HEARNEAR"))
return Command.UnMute(message, new string[] { "NEAR" }, user);
else if (message.ToUpper().StartsWith("!HEARHERE"))
return Command.UnMute(message, new string[] { "HERE" }, user);
else if (message.ToUpper().StartsWith("!HEARBUDDY"))
return Command.UnMute(message, new string[] { "BUDDY" }, user);
else if (message.ToUpper().StartsWith("!HEARPM"))
return Command.UnMute(message, new string[] { "PM" }, user);
else if (message.ToUpper().StartsWith("!HEARBR"))
return Command.UnMute(message, new string[] { "BR" }, user);
else if (message.ToUpper().StartsWith("!HEARSOCIALS"))
return Command.UnMute(message, new string[] { "SOCIALS" }, user);
else if (message.ToUpper().StartsWith("!HEARLOGINS"))
return Command.UnMute(message, new string[] { "LOGINS" }, user);
else if (message.ToUpper().StartsWith("!HEAR"))
return Command.UnMute(message, args, user);
else if (message.ToUpper().StartsWith("!WARP"))
return Command.Warp(message, args, user);
}

View file

@ -15,7 +15,7 @@ namespace HISP.Game.Chat
return false;
if (!user.Administrator)
return false;
if(args[0] == "OBJECT")
if(args[0].ToUpper() == "OBJECT")
{
int itemId = 0;
try
@ -31,7 +31,7 @@ namespace HISP.Game.Chat
return false;
}
}
else if (args[0] == "MONEY")
else if (args[0].ToUpper() == "MONEY")
{
int money = 0;
try
@ -44,7 +44,7 @@ namespace HISP.Game.Chat
return false;
}
}
else if (args[0] == "QUEST")
else if (args[0].ToUpper() == "QUEST")
{
int questId = 0;
try
@ -52,7 +52,7 @@ namespace HISP.Game.Chat
questId = int.Parse(args[1]);
if(args.Length >= 3)
{
if (args[2] == "FORCE")
if (args[0].ToUpper() == "FORCE")
{
Quest.CompleteQuest(user, Quest.GetQuestById(questId));
goto msg;
@ -190,7 +190,7 @@ namespace HISP.Game.Chat
return false;
if (!user.Administrator)
return false;
if(args[0] == "PLAYER")
if(args[0].ToUpper() == "PLAYER")
{
if(args.Length < 2)
return false;
@ -204,7 +204,7 @@ namespace HISP.Game.Chat
return false;
}
}
else if(args[0] == "AREA")
else if(args[0].ToUpper() == "AREA")
{
if (args.Length < 2)
return false;
@ -230,7 +230,7 @@ namespace HISP.Game.Chat
return false;
}
}
else if(args[0] == "NPC")
else if(args[0].ToUpper() == "NPC")
{
if (args.Length < 2)
return false;
@ -362,38 +362,38 @@ namespace HISP.Game.Chat
string muteType = args[0];
if (muteType == "GLOBAL")
if (muteType.ToUpper() == "GLOBAL")
{
user.MuteGlobal = true;
} else if (muteType == "ISLAND")
} else if (muteType.ToUpper() == "ISLAND")
{
user.MuteIsland = true;
} else if (muteType == "NEAR")
} else if (muteType.ToUpper() == "NEAR")
{
user.MuteNear = true;
} else if (muteType == "HERE")
} else if (muteType.ToUpper() == "HERE")
{
user.MuteHere = true;
} else if (muteType == "BUDDY")
} else if (muteType.ToUpper() == "BUDDY")
{
user.MuteBuddy = true;
} else if (muteType == "SOCIALS")
} else if (muteType.ToUpper() == "SOCIALS")
{
user.MuteSocials = true;
}
else if (muteType == "PM")
else if (muteType.ToUpper() == "PM")
{
user.MutePrivateMessage = true;
}
else if (muteType == "BR")
else if (muteType.ToUpper() == "BR")
{
user.MuteBuddyRequests = true;
}
else if (muteType == "LOGINS")
else if (muteType.ToUpper() == "LOGINS")
{
user.MuteLogins = true;
}
else if (muteType == "ALL")
else if (muteType.ToUpper() == "ALL")
{
user.MuteAll = true;
user.MuteGlobal = true;
@ -419,5 +419,80 @@ namespace HISP.Game.Chat
return true;
}
public static bool UnMute(string message, string[] args, User user)
{
string formattedmessage = Messages.FormatPlayerCommandCompleteMessage(message.Substring(1));
if (args.Length <= 0)
{
formattedmessage += Messages.UnMuteHelp;
goto leave;
}
string muteType = args[0];
if (muteType.ToUpper() == "GLOBAL")
{
user.MuteGlobal = false;
}
else if (muteType.ToUpper() == "ISLAND")
{
user.MuteIsland = false;
}
else if (muteType.ToUpper() == "NEAR")
{
user.MuteNear = false;
}
else if (muteType.ToUpper() == "HERE")
{
user.MuteHere = false;
}
else if (muteType.ToUpper() == "BUDDY")
{
user.MuteBuddy = false;
}
else if (muteType.ToUpper() == "SOCIALS")
{
user.MuteSocials = false;
}
else if (muteType.ToUpper() == "PM")
{
user.MutePrivateMessage = false;
}
else if (muteType.ToUpper() == "BR")
{
user.MuteBuddyRequests = false;
}
else if (muteType.ToUpper() == "LOGINS")
{
user.MuteLogins = false;
}
else if (muteType.ToUpper() == "ALL")
{
user.MuteAll = false;
user.MuteGlobal = false;
user.MuteIsland = false;
user.MuteNear = false;
user.MuteHere = false;
user.MuteBuddy = false;
user.MuteSocials = false;
user.MutePrivateMessage = false;
user.MuteBuddyRequests = false;
user.MuteLogins = false;
}
else
{
formattedmessage += Messages.UnMuteHelp;
goto leave;
}
leave:;
byte[] chatPacket = PacketBuilder.CreateChat(formattedmessage, PacketBuilder.CHAT_BOTTOM_LEFT);
user.LoggedinClient.SendPacket(chatPacket);
return true;
}
}
}

View file

@ -23,6 +23,9 @@ namespace HISP.Game
public static string AddBuddyDeleteBuddyFormat;
// Mute Command
public static string NowMutingPlayerFormat;
public static string StoppedMutingPlayerFormat;
public static string PlayerIgnoringYourPrivateMessagesFormat;
public static string PlayerIgnoringYourBuddyRequests;
public static string PlayerIgnoringYourSocials;
@ -550,6 +553,7 @@ namespace HISP.Game
public static string PlayerCommandFormat;
public static string MuteHelp;
public static string UnMuteHelp;
public static string GlobalChatFormatForModerators;
public static string DirectChatFormatForModerators;
@ -967,6 +971,10 @@ namespace HISP.Game
public static string PlayerListMapAllBuddiesForamt;
public static string PlayerListMapAllPlayersFormat;
public static string MuteButton;
public static string HearButton;
public static string PmButton;
public static int ThreeMonthSubscripitionIcon;
public static int YearSubscriptionIcon;
public static int NewUserIcon;
@ -1093,7 +1101,14 @@ namespace HISP.Game
public static string NothingInterestingHere;
// Mute Command
public static string FormatStoppedMutingPlayer(string username)
{
return StoppedMutingPlayerFormat.Replace("%USERNAME%", username);
}
public static string FormatNowMutingPlayer(string username)
{
return NowMutingPlayerFormat.Replace("%USERNAME%", username);
}
public static string FormatCantSendYourIgnoringPlayer(string username)
{
return CantSendPrivateMessagePlayerMutedFormat.Replace("%USERNAME%", username);
@ -2229,10 +2244,30 @@ namespace HISP.Game
return PlayerListIconFormat.Replace("%ICON%", iconId.ToString());
}
public static string FormatPlayerEntry(string iconFormat, string username, int userId, int time, int x, int y, bool idle)
public static string FormatMuteButton(int playerId)
{
return MuteButton.Replace("%PLAYERID%", playerId.ToString());
}
public static string FormatHearButton(int playerId)
{
return HearButton.Replace("%PLAYERID%", playerId.ToString());
}
public static string FormatPmButton(string playerName)
{
return PmButton.Replace("%USERNAME%", playerName);
}
public static string FormatPlayerEntry(string iconFormat, string username, int userId, int time, int x, int y, bool idle, bool muteOrHear, bool isYou)
{
string xy = FormatMapLocation(x, y);
return PlayerListEntryFormat.Replace("%ICONFORMAT%", iconFormat).Replace("%USERNAME%", username).Replace("%PLAYERID%", userId.ToString()).Replace("%TIME%", time.ToString("N0", CultureInfo.InvariantCulture)).Replace("%MAPXY%", xy).Replace("%IDLE%", idle ? PlayerListIdle : "");
string muteButton = FormatMuteButton(userId);
string hearButton = FormatHearButton(userId);
string pmButton = FormatPmButton(username);
string msg = PlayerListEntryFormat.Replace("%ICONFORMAT%", iconFormat).Replace("%USERNAME%", username).Replace("%PLAYERID%", userId.ToString()).Replace("%TIME%", time.ToString("N0", CultureInfo.InvariantCulture)).Replace("%MAPXY%", xy).Replace("%IDLE%", idle ? PlayerListIdle : "");
if (isYou)
msg = msg.Replace("%MUTEORHEAR%", "").Replace("%PMBUTTON%", "");
else
msg = msg.Replace("%MUTEORHEAR%", muteOrHear ? hearButton : muteButton).Replace("%PMBUTTON", pmButton);
return msg;
}
public static string FormatOnlineBuddyEntry(string iconFormat, string username, int userId, int time, int x, int y)
{

View file

@ -1125,26 +1125,28 @@ namespace HISP.Game
public static string BuildNearbyList(User user)
public static string BuildNearbyList(User currentUser)
{
string message = "";
message += Messages.NearbyPlayersListHeader;
User[] nearbyUsers = GameServer.GetNearbyUsers(user.X, user.Y, false, true);
User[] nearbyUsers = GameServer.GetNearbyUsers(currentUser.X, currentUser.Y, false, true);
foreach (User nearbyUser in nearbyUsers)
{
if (nearbyUser.Stealth)
continue;
if (nearbyUser.Id == user.Id)
if (nearbyUser.Id == currentUser.Id)
continue;
bool isYou = (nearbyUser.Id == currentUser.Id);
int icon = nearbyUser.GetPlayerListIcon();
string iconFormat = "";
if (icon != -1)
iconFormat = Messages.FormatIconFormat(icon);
message += Messages.FormatPlayerEntry(iconFormat, nearbyUser.Username, nearbyUser.Id, Convert.ToInt32(Math.Round((DateTime.UtcNow - nearbyUser.LoginTime).TotalMinutes)), nearbyUser.X, nearbyUser.Y, nearbyUser.Idle);
message += Messages.FormatPlayerEntry(iconFormat, nearbyUser.Username, nearbyUser.Id, Convert.ToInt32(Math.Round((DateTime.UtcNow - nearbyUser.LoginTime).TotalMinutes)), nearbyUser.X, nearbyUser.Y, nearbyUser.Idle, currentUser.MutePlayer.IsUserMuted(nearbyUser), isYou);
}
message += Messages.PlayerListIconInformation;
@ -1154,7 +1156,7 @@ namespace HISP.Game
return message;
}
public static string BuildPlayerListAlphabetical()
public static string BuildPlayerListAlphabetical(User currentUser)
{
string message = Messages.PlayerListAllAlphabeticalHeader;
GameClient[] clients = GameServer.ConnectedClients;
@ -1175,12 +1177,13 @@ namespace HISP.Game
foreach (User onlineUser in onlineUsers)
{
bool isYou = (onlineUser.Id == currentUser.Id);
int icon = onlineUser.GetPlayerListIcon();
string iconFormat = "";
if (icon != -1)
iconFormat = Messages.FormatIconFormat(icon);
message += Messages.FormatPlayerEntry(iconFormat, onlineUser.Username, onlineUser.Id, Convert.ToInt32(Math.Round((DateTime.UtcNow - onlineUser.LoginTime).TotalMinutes)), onlineUser.X, onlineUser.Y, onlineUser.Idle);
message += Messages.FormatPlayerEntry(iconFormat, onlineUser.Username, onlineUser.Id, Convert.ToInt32(Math.Round((DateTime.UtcNow - onlineUser.LoginTime).TotalMinutes)), onlineUser.X, onlineUser.Y, onlineUser.Idle, currentUser.MutePlayer.IsUserMuted(onlineUser), isYou);
}
message += Messages.PlayerListIconInformation;
@ -1190,7 +1193,7 @@ namespace HISP.Game
return message;
}
public static string BuildPlayerList()
public static string BuildPlayerList(User currentUser)
{
string message = Messages.PlayerListAllHeader;
GameClient[] clients = GameServer.ConnectedClients;
@ -1201,12 +1204,14 @@ namespace HISP.Game
if (client.LoggedinUser.Stealth)
continue;
bool isYou = (client.LoggedinUser.Id == currentUser.Id);
int icon = client.LoggedinUser.GetPlayerListIcon();
string iconFormat = "";
if (icon != -1)
iconFormat = Messages.FormatIconFormat(icon);
message += Messages.FormatPlayerEntry(iconFormat, client.LoggedinUser.Username, client.LoggedinUser.Id, Convert.ToInt32(Math.Round((DateTime.UtcNow - client.LoggedinUser.LoginTime).TotalMinutes)), client.LoggedinUser.X, client.LoggedinUser.Y, client.LoggedinUser.Idle);
message += Messages.FormatPlayerEntry(iconFormat, client.LoggedinUser.Username, client.LoggedinUser.Id, Convert.ToInt32(Math.Round((DateTime.UtcNow - client.LoggedinUser.LoginTime).TotalMinutes)), client.LoggedinUser.X, client.LoggedinUser.Y, client.LoggedinUser.Idle, currentUser.MutePlayer.IsUserMuted(client.LoggedinUser), isYou);
}
}
@ -2074,7 +2079,7 @@ namespace HISP.Game
message += Messages.MetaTerminator;
return message;
}
public static string BuildPlayerList(User user)
public static string BuildPlayerListMenu(User user)
{
string message = "";