Add command support.

This commit is contained in:
SilicaAndPina 2020-12-23 04:13:38 +13:00
parent da205c3cd3
commit b6dd899372
7 changed files with 129 additions and 18 deletions

View file

@ -53,8 +53,9 @@
"for_others":"<B>TAG!!</B> %USERNAME% is now it! (tagged by %TAGGER%)" "for_others":"<B>TAG!!</B> %USERNAME% is now it! (tagged by %TAGGER%)"
}, },
"commands":{ "commands":{
"mute_help":"<FONT COLOR='#FF0000'><B>PLAYER COMMAND [%COMMAND%] COMPLETED</B></FONT> Mute Channel Not Recognized. (ALL/ADS/GLOBAL/ISLAND/NEAR/HERE/BUDDY/PM/BR/SOCIALS/LOGINS)", "mute_help":"Mute Channel Not Recognized. (ALL/ADS/GLOBAL/ISLAND/NEAR/HERE/BUDDY/PM/BR/SOCIALS/LOGINS)",
"command_completed":"<FONT COLOR='#FF0000'><B>PLAYER COMMAND [%COMMAND%] COMPLETED</B></FONT>" "player_command_completed":"<FONT COLOR='#FF0000'><B>PLAYER COMMAND [%COMMAND%] COMPLETED</B></FONT>",
"admin_command_completed":"<FONT COLOR='#FF0000'><B>COMMAND [%COMMAND%]:</B></FONT>"
}, },
"disconnect":{ "disconnect":{
"banned":"Your account has been BANNED. You will no longer be able to login", "banned":"Your account has been BANNED. You will no longer be able to login",

View file

@ -53,13 +53,43 @@ namespace HISP.Game.Chat
if (user.Administrator || user.Moderator) if (user.Administrator || user.Moderator)
if (message[0] == '%') if (message[0] == '%')
{
if(message.StartsWith("%STICKBUG"))
{
return Command.Stickbug(message, args, user);
}
return false; return false;
}
if (message[0] == '!') if (message[0] == '!')
{ {
if (message.StartsWith("!MUTE")) // Alias for !MUTE
{ if (message.StartsWith("!MUTEALL"))
return Command.Mute(message, new string[] { "ALL" }, user);
else if (message.StartsWith("!MUTEADS"))
return Command.Mute(message, new string[] { "ADS" }, user);
else if (message.StartsWith("!MUTEGLOBAL"))
return Command.Mute(message, new string[] { "GLOBAL" }, user);
else if (message.StartsWith("!MUTEISLAND"))
return Command.Mute(message, new string[] { "ISLAND" }, user);
else if (message.StartsWith("!MUTENEAR"))
return Command.Mute(message, new string[] { "NEAR" }, user);
else if (message.StartsWith("!MUTEHERE"))
return Command.Mute(message, new string[] { "HERE" }, user);
else if (message.StartsWith("!MUTEBUDDY"))
return Command.Mute(message, new string[] { "BUDDY" }, user);
else if (message.StartsWith("!MUTEPM"))
return Command.Mute(message, new string[] { "PM" }, user);
else if (message.StartsWith("!MUTEPM"))
return Command.Mute(message, new string[] { "PM" }, user);
else if (message.StartsWith("!MUTEBR"))
return Command.Mute(message, new string[] { "BR" }, user);
else if (message.StartsWith("!MUTESOCIALS"))
return Command.Mute(message, new string[] { "SOCIALS" }, user);
else if (message.StartsWith("!MUTELOGINS"))
return Command.Mute(message, new string[] { "LOGINS" }, user);
else if (message.StartsWith("!MUTE"))
return Command.Mute(message, args, user); return Command.Mute(message, args, user);
}
} }
return false; return false;
} }

View file

@ -1,18 +1,60 @@
using HISP.Player; using HISP.Player;
using HISP.Server; using HISP.Server;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HISP.Game.Chat namespace HISP.Game.Chat
{ {
class Command class Command
{ {
public static bool Stickbug(string message, string[] args, User user)
{
if (args.Length <= 0)
return false;
if (!user.Administrator)
return false;
if(args[0] == "ALL")
{
foreach(GameClient client in GameServer.ConnectedClients)
{
if(client.LoggedIn)
{
byte[] swfModulePacket = PacketBuilder.CreateSwfModulePacket("fun/stickbug.swf", PacketBuilder.PACKET_SWF_MODULE_GENTLE);
client.SendPacket(swfModulePacket);
}
}
}
else
{
try
{
User victimUser = GameServer.GetUserByName(args[0]);
byte[] swfModulePacket = PacketBuilder.CreateSwfModulePacket("fun/stickbug.swf", PacketBuilder.PACKET_SWF_MODULE_GENTLE);
victimUser.LoggedinClient.SendPacket(swfModulePacket);
}
catch(KeyNotFoundException)
{
return false;
}
}
byte[] chatPacket = PacketBuilder.CreateChat(Messages.FormatAdminCommandCompleteMessage(message.Substring(1)), PacketBuilder.CHAT_BOTTOM_LEFT);
user.LoggedinClient.SendPacket(chatPacket);
return true;
}
public static bool Mute(string message, string[] args, User user) public static bool Mute(string message, string[] args, User user)
{ {
string mesasge = Messages.FormatPlayerCommandCompleteMessage(message.Substring(1));
if (args.Length <= 0)
{
message += Messages.MuteHelp;
goto leave;
}
string muteType = args[0]; string muteType = args[0];
if (muteType == "GLOBAL") if (muteType == "GLOBAL")
@ -33,19 +75,33 @@ namespace HISP.Game.Chat
} else if (muteType == "SOCIALS") } else if (muteType == "SOCIALS")
{ {
user.MuteSocials = true; user.MuteSocials = true;
} else if (muteType == "ALL") }
else if (muteType == "PM")
{
user.MutePrivateMessage = true;
}
else if (muteType == "BR")
{
user.MuteBuddyRequests = true;
}
else if (muteType == "LOGINS")
{
user.MuteLogins = true;
}
else if (muteType == "ALL")
{ {
user.MuteAll = true; user.MuteAll = true;
} else } else
{ {
return false; message += Messages.MuteHelp;
goto leave;
} }
byte[] chatPacket = PacketBuilder.CreateChat(Messages.FormatCommandComplete(message.Substring(1)), PacketBuilder.CHAT_BOTTOM_LEFT); leave:;
byte[] chatPacket = PacketBuilder.CreateChat(message, PacketBuilder.CHAT_BOTTOM_LEFT);
user.LoggedinClient.SendPacket(chatPacket); user.LoggedinClient.SendPacket(chatPacket);
return true; return true;
} }
} }

View file

@ -69,7 +69,9 @@ namespace HISP.Game
public static string ModChatFormat; public static string ModChatFormat;
public static string AdminChatFormat; public static string AdminChatFormat;
public static string CommandFormat; public static string AdminCommandFormat;
public static string PlayerCommandFormat;
public static string MuteHelp;
public static string GlobalChatFormatForModerators; public static string GlobalChatFormatForModerators;
public static string DirectChatFormatForModerators; public static string DirectChatFormatForModerators;
@ -261,9 +263,14 @@ namespace HISP.Game
{ {
return StatsCompetitionGearFormat.Replace("%GEARFORMAT%", competitonGearFormat); return StatsCompetitionGearFormat.Replace("%GEARFORMAT%", competitonGearFormat);
} }
public static string FormatCommandComplete(string command) public static string FormatAdminCommandCompleteMessage(string command)
{ {
return CommandFormat.Replace("%COMMAND%", command); return AdminCommandFormat.Replace("%COMMAND%", command);
}
public static string FormatPlayerCommandCompleteMessage(string command)
{
return PlayerCommandFormat.Replace("%COMMAND%", command);
} }
public static string FormatEquipItemMessage(string name) public static string FormatEquipItemMessage(string name)

View file

@ -455,7 +455,10 @@ namespace HISP.Server
Messages.ModChatFormatForSender = gameData.messages.chat.for_sender.mod_format; Messages.ModChatFormatForSender = gameData.messages.chat.for_sender.mod_format;
Messages.AdminChatFormatForSender = gameData.messages.chat.for_sender.admin_format; Messages.AdminChatFormatForSender = gameData.messages.chat.for_sender.admin_format;
Messages.CommandFormat = gameData.messages.commands.command_completed; Messages.AdminCommandFormat = gameData.messages.commands.admin_command_completed;
Messages.PlayerCommandFormat = gameData.messages.commands.player_command_completed;
Messages.MuteHelp = gameData.messages.commands.mute_help;
Messages.PasswordNotice = gameData.messages.chat.password_included; Messages.PasswordNotice = gameData.messages.chat.password_included;
Messages.CapsNotice = gameData.messages.chat.caps_notice; Messages.CapsNotice = gameData.messages.chat.caps_notice;

View file

@ -1437,6 +1437,20 @@ namespace HISP.Server
} }
return usersHere.ToArray(); return usersHere.ToArray();
} }
public static User GetUserByName(string username)
{
foreach(GameClient client in ConnectedClients)
{
if(client.LoggedIn)
{
if (client.LoggedinUser.Username == username)
return client.LoggedinUser;
}
}
throw new KeyNotFoundException("User was not found.");
}
public static User[] GetNearbyUsers(int x, int y, bool includeStealth=false, bool includeMuted=false) public static User[] GetNearbyUsers(int x, int y, bool includeStealth=false, bool includeMuted=false)
{ {
int startX = x - 15; int startX = x - 15;