Skip to content

Commit

Permalink
feat: Expand name protection rules to chat messages
Browse files Browse the repository at this point in the history
  • Loading branch information
phinner committed Dec 14, 2023
1 parent a9ace31 commit d4b8cdc
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,7 @@ fun String.toInetAddressOrNull(): InetAddress? =
fun ByteArray.encodeBase64(): String = Base64.getEncoder().encodeToString(this)

fun String.decodeBase64(): ByteArray = Base64.getDecoder().decode(this)

private val LINK_REGEX = Regex("(https?://|discord.gg)")

fun String.containsLink(): Boolean = LINK_REGEX.containsMatchIn(lowercase())
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import com.xpdustry.imperium.common.inject.InstanceManager
import com.xpdustry.imperium.common.inject.get
import com.xpdustry.imperium.common.message.Messenger
import com.xpdustry.imperium.common.misc.MINDUSTRY_ORANGE_COLOR
import com.xpdustry.imperium.common.misc.containsLink
import com.xpdustry.imperium.common.misc.logger
import com.xpdustry.imperium.common.misc.stripMindustryColors
import com.xpdustry.imperium.common.misc.toHexString
Expand Down Expand Up @@ -112,6 +113,18 @@ class ChatMessageListener(instances: InstanceManager) : ImperiumApplication.List
ctx.message
}

chatMessagePipeline.register("anti-links", Priority.NORMAL) { ctx ->
if (ctx.sender == null || !ctx.message.containsLink()) {
return@register ctx.message
} else {
if (ctx.target == ctx.sender) {
ctx.sender.sendMessage(
"[scarlet]You can't send discord invitations or links in the chat.")
}
return@register ""
}
}

val chaoticHourFormat = DecimalFormat("000")
placeholderPipeline.registerCaching("subject_playtime", 10.seconds, ::getContextKey) {
(subject, query) ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import com.xpdustry.imperium.common.config.ServerConfig
import com.xpdustry.imperium.common.inject.InstanceManager
import com.xpdustry.imperium.common.inject.get
import com.xpdustry.imperium.common.misc.LoggerDelegate
import com.xpdustry.imperium.common.misc.containsLink
import com.xpdustry.imperium.common.misc.logger
import com.xpdustry.imperium.common.misc.stripMindustryColors
import com.xpdustry.imperium.common.network.VpnDetection
Expand Down Expand Up @@ -75,8 +76,7 @@ class GatekeeperListener(instances: InstanceManager) : ImperiumApplication.Liste

pipeline.register("cracked-client", Priority.NORMAL, CrackedClientGatekeeper())
pipeline.register("links", Priority.NORMAL) { context ->
val name = context.name.lowercase()
if (name.contains("discord.gg") || context.name.matches(Regex("https?://"))) {
if (context.name.containsLink()) {
GatekeeperResult.Failure("Your name cannot contain a link.")
} else {
GatekeeperResult.Success
Expand Down

0 comments on commit d4b8cdc

Please sign in to comment.