From 5fc313657de0fb37e58bb2319fe91015222687d7 Mon Sep 17 00:00:00 2001 From: SilicaAndPina Date: Mon, 5 Apr 2021 11:51:08 +1200 Subject: [PATCH] Add various chat related checks --- DataCollection/gamedata.json | 5 ++ .../HorseIsleServer/Game/Chat/Command.cs | 6 +- .../HorseIsleServer/Game/Messages.cs | 5 ++ .../HorseIsleServer/Player/Dance.cs | 2 + .../HorseIsleServer/Player/User.cs | 3 + .../HorseIsleServer/Server/GameClient.cs | 8 ++ .../HorseIsleServer/Server/GameDataJson.cs | 5 ++ .../HorseIsleServer/Server/GameServer.cs | 83 ++++++++++++++++++- 8 files changed, 114 insertions(+), 3 deletions(-) diff --git a/DataCollection/gamedata.json b/DataCollection/gamedata.json index a2dcfdf..a9fccea 100755 --- a/DataCollection/gamedata.json +++ b/DataCollection/gamedata.json @@ -61,6 +61,11 @@ "no_telescope":"You do not have a telescope to use! You try making circles with your hands and placing them in front of one eye, but it is of minimal aid...", "starved_horse":"You have been sent to Prison Isle for starving one of your horses! They have been fed for you.", "message_queue":"OFFLINE MESSAGE:", + "chat_errors":{ + "cant_find_player":"Could not find player to Private chat!", + "ads_once_per_minute":"Ads may only be posted once per minute.", + "global_chats_limited":"CHAT NOT SENT: Global chats are limited (+1 earned per 2 minutes). Please chat using CHAT NEAR/ISLAND/BUDDIES when possible." + }, "events":{ "real_time_riddle":{ "event_start":"CHAT RIDDLE: %RIDDLETEXT% (answer first via any chat method)", diff --git a/Horse Isle Server/HorseIsleServer/Game/Chat/Command.cs b/Horse Isle Server/HorseIsleServer/Game/Chat/Command.cs index 54b4efe..708fba7 100755 --- a/Horse Isle Server/HorseIsleServer/Game/Chat/Command.cs +++ b/Horse Isle Server/HorseIsleServer/Game/Chat/Command.cs @@ -124,6 +124,7 @@ namespace HISP.Game.Chat try{ User bannedUser = GameServer.GetUserByName(args[0]); bannedUser.LoggedinClient.Kick(Messages.KickReasonBanned); + } catch(KeyNotFoundException){}; @@ -357,7 +358,10 @@ namespace HISP.Game.Chat string moves = string.Join(" ", args).ToLower(); string formattedmessage = Messages.FormatPlayerCommandCompleteMessage(message.Substring(1)); - new Dance(user, moves); + if (user.ActiveDance != null) + user.ActiveDance.Dispose(); + + user.ActiveDance = new Dance(user, moves); byte[] chatPacket = PacketBuilder.CreateChat(formattedmessage, PacketBuilder.CHAT_BOTTOM_LEFT); user.LoggedinClient.SendPacket(chatPacket); diff --git a/Horse Isle Server/HorseIsleServer/Game/Messages.cs b/Horse Isle Server/HorseIsleServer/Game/Messages.cs index 5a87f42..a4a8ab3 100755 --- a/Horse Isle Server/HorseIsleServer/Game/Messages.cs +++ b/Horse Isle Server/HorseIsleServer/Game/Messages.cs @@ -40,6 +40,11 @@ namespace HISP.Game public static string CantSendPrivateMessagePlayerMutedFormat; + // Chat Errors + public static string CantFindPlayerToPrivateMessage; + public static string AdsOnlyOncePerMinute; + public static string GlobalChatLimited; + // Auto Sell public static string AutoSellNotStandingInSamePlace; public static string AutoSellSuccessFormat; diff --git a/Horse Isle Server/HorseIsleServer/Player/Dance.cs b/Horse Isle Server/HorseIsleServer/Player/Dance.cs index 59960c6..9ce152c 100644 --- a/Horse Isle Server/HorseIsleServer/Player/Dance.cs +++ b/Horse Isle Server/HorseIsleServer/Player/Dance.cs @@ -15,6 +15,7 @@ namespace HISP.Player public Dance(User BaseUser, string DanceMoves) { baseUser = BaseUser; + baseUser.ActiveDance = this; Moves = DanceMoves.ToLower(); MoveIndex = -1; danceTimer = new Timer(new TimerCallback(onDanceTick), null, DanceSpeed, DanceSpeed); @@ -79,6 +80,7 @@ namespace HISP.Player public void Dispose() { + baseUser.ActiveDance = null; baseUser = null; Moves = null; danceTimer.Dispose(); diff --git a/Horse Isle Server/HorseIsleServer/Player/User.cs b/Horse Isle Server/HorseIsleServer/Player/User.cs index af7e973..7a6d988 100755 --- a/Horse Isle Server/HorseIsleServer/Player/User.cs +++ b/Horse Isle Server/HorseIsleServer/Player/User.cs @@ -101,11 +101,14 @@ namespace HISP.Player public User SocializingWith; public List BeingSocializedBy = new List(); public User PendingBuddyRequestTo; + public Dance ActiveDance; + public bool CanUseAdsChat = true; public int CapturingHorseId; public DateTime LoginTime; public string LastSeenWeather; public int LastClickedRanchBuilding = 0; public bool ListingAuction = false; + public int TotalGlobalChatMessages = 1; public string GetWeatherSeen() { diff --git a/Horse Isle Server/HorseIsleServer/Server/GameClient.cs b/Horse Isle Server/HorseIsleServer/Server/GameClient.cs index a9f19af..aa25036 100755 --- a/Horse Isle Server/HorseIsleServer/Server/GameClient.cs +++ b/Horse Isle Server/HorseIsleServer/Server/GameClient.cs @@ -47,6 +47,7 @@ namespace HISP.Server private int warnInterval = GameServer.IdleWarning * 60 * 1000; private int kickInterval = GameServer.IdleTimeout * 60 * 1000; + private bool dcLock = false; private void minuteTimerTick(object state) @@ -55,7 +56,14 @@ namespace HISP.Server totalMinutesElapsed++; if (LoggedIn) { + LoggedinUser.CanUseAdsChat = true; LoggedinUser.FreeMinutes -= 1; + + if(totalMinutesElapsed % 2 == 0) + { + LoggedinUser.TotalGlobalChatMessages++; + } + if (LoggedinUser.FreeMinutes <= 0) { LoggedinUser.FreeMinutes = 0; diff --git a/Horse Isle Server/HorseIsleServer/Server/GameDataJson.cs b/Horse Isle Server/HorseIsleServer/Server/GameDataJson.cs index 3bda7f3..f25f7ec 100755 --- a/Horse Isle Server/HorseIsleServer/Server/GameDataJson.cs +++ b/Horse Isle Server/HorseIsleServer/Server/GameDataJson.cs @@ -882,6 +882,11 @@ namespace HISP.Server Messages.CantSendPrivateMessagePlayerMutedFormat = gameData.messages.meta.mute_command.cant_send_pm_player_muted; + // Chat Errors + Messages.CantFindPlayerToPrivateMessage = gameData.messages.chat_errors.cant_find_player; + Messages.AdsOnlyOncePerMinute = gameData.messages.chat_errors.ads_once_per_minute; + Messages.GlobalChatLimited = gameData.messages.chat_errors.global_chats_limited; + // Warp Command Messages.SuccessfullyWarpedToPlayer = gameData.messages.commands.warp.player; diff --git a/Horse Isle Server/HorseIsleServer/Server/GameServer.cs b/Horse Isle Server/HorseIsleServer/Server/GameServer.cs index 848f3e4..45a359b 100755 --- a/Horse Isle Server/HorseIsleServer/Server/GameServer.cs +++ b/Horse Isle Server/HorseIsleServer/Server/GameServer.cs @@ -204,7 +204,7 @@ namespace HISP.Server Database.IncPlayerTirednessForOfflineUsers(); - // Offline player handling w sql magic... + // Offline player handling w sql black magic... Database.DecrementHorseLeaseTimeForOfflinePlayers(); Database.TpOfflinePlayersBackToUniterForOfflinePlayers(); @@ -5391,7 +5391,51 @@ namespace HISP.Server if (message == "") return; - + + if(message.StartsWith("/")) + { + string channelString = message.Split(' ')[0].ToLower(); + string newMessage = string.Join(' ', message.Split(' ').Skip(1)); + message = newMessage; + switch(channelString) + { + case "/$": + case "/ads": + channel = Chat.ChatChannel.Ads; + break; + case "/all": + channel = Chat.ChatChannel.All; + break; + case "/here": + channel = Chat.ChatChannel.Here; + break; + case "/near": + channel = Chat.ChatChannel.Near; + break; + case "/buddy": + channel = Chat.ChatChannel.Buddies; + break; + case "/island": + channel = Chat.ChatChannel.Isle; + break; + case "/admin": + if (sender.LoggedinUser.Administrator) + channel = Chat.ChatChannel.Admin; + else + return; + break; + case "/mod": + if (sender.LoggedinUser.Moderator) + channel = Chat.ChatChannel.Mod; + else + return; + break; + default: + channel = Chat.ChatChannel.Dm; + nameTo = channelString.Substring(1); + break; + } + } if (Chat.ProcessCommand(sender.LoggedinUser, message)) { @@ -5446,6 +5490,41 @@ namespace HISP.Server GameClient[] recipiants = Chat.GetRecipiants(sender.LoggedinUser, channel, nameTo); + // Spam Protection + + if(channel == Chat.ChatChannel.Dm) + { + if(recipiants.Length <= 0) + { + byte[] cantFindPlayer = PacketBuilder.CreateChat(Messages.CantFindPlayerToPrivateMessage, PacketBuilder.CHAT_BOTTOM_RIGHT); + sender.SendPacket(cantFindPlayer); + + return; + } + } + else if(channel == Chat.ChatChannel.Ads) + { + if(!sender.LoggedinUser.CanUseAdsChat) + { + byte[] cantSendInAds = PacketBuilder.CreateChat(Messages.AdsOnlyOncePerMinute, PacketBuilder.CHAT_BOTTOM_RIGHT); + sender.SendPacket(cantSendInAds); + + return; + } + sender.LoggedinUser.CanUseAdsChat = false; + } + else if(channel == Chat.ChatChannel.All) + { + if(sender.LoggedinUser.TotalGlobalChatMessages <= 0) + { + byte[] globalLimited = PacketBuilder.CreateChat(Messages.GlobalChatLimited, PacketBuilder.CHAT_BOTTOM_RIGHT); + sender.SendPacket(globalLimited); + + return; + } + sender.LoggedinUser.TotalGlobalChatMessages--; + } + // Muted user checks if(channel == Chat.ChatChannel.Dm) {