Global chat work

This commit is contained in:
ceikry 2023-02-21 12:46:17 -06:00
parent aa0632d274
commit 840f4a86f8
5 changed files with 41 additions and 9 deletions

View file

@ -264,5 +264,8 @@ class ServerConstants {
@JvmField
var DRAGON_AXE_USE_OSRS_SPEC = false
@JvmField
var ENABLE_GLOBALCHAT = false
}
}

View file

@ -0,0 +1,19 @@
package core.game.system.communication
import core.api.getAttribute
import core.api.sendMessage
import core.game.world.repository.Repository
import core.tools.colorize
object GlobalChat {
private val ATTR_GLOBAL_MUTE = "/save:globalmute"
fun process(sender: String, message: String) {
val msg = prepare(sender, message)
for (player in Repository.players.filter { !getAttribute(it, ATTR_GLOBAL_MUTE, false) })
sendMessage(player, msg)
}
private fun prepare(sender: String, message: String) : String {
return colorize("%44e3e0[%GG%44e3e0] %ffffff$sender: $message")
}
}

View file

@ -133,6 +133,7 @@ object ServerConfigParser {
ServerConstants.DISCORD_MOD_WEBHOOK = data.getString("server.moderation_webhook", "")
ServerConstants.NOAUTH_DEFAULT_ADMIN = data.getBoolean("server.noauth_default_admin", false)
ServerConstants.DRAGON_AXE_USE_OSRS_SPEC = data.getBoolean("world.dragon_axe_use_osrs_spec", false)
ServerConstants.ENABLE_GLOBALCHAT = data.getBoolean("world.enable_globalchat", true)
}

View file

@ -55,6 +55,7 @@ import core.game.node.entity.player.info.LogType
import core.game.node.entity.player.info.PlayerMonitor
import core.tools.SystemLogger
import core.game.system.command.CommandSystem
import core.game.system.communication.GlobalChat
import core.game.world.GameWorld
import core.game.world.repository.Repository
import core.net.packet.`in`.Packet
@ -202,7 +203,11 @@ object PacketProcessor {
if (pkt.player.details.isMuted)
pkt.player.sendMessage("You have been muted due to breaking a rule.")
else {
if (pkt.message.startsWith("/") && pkt.player.communication.clan != null) {
if (ServerConstants.ENABLE_GLOBALCHAT && pkt.message.startsWith("//")) {
GlobalChat.process(pkt.player.username, pkt.message.substring(2))
return
}
else if (pkt.message.startsWith("/") && pkt.player.communication.clan != null) {
val builder = ClanMessage.newBuilder()
builder.sender = pkt.player.name
builder.clanName = pkt.player.communication.clan.owner.lowercase().replace(" ", "_")

View file

@ -7,14 +7,18 @@ const val GREEN = "<col=66ff33>"
const val BLUE = "<col=3366ff>"
const val PURPLE = "<col=cc00ff>"
fun colorize(line: String): String{
val new = line.replace("%R", RED)
.replace("%O", ORANGE)
.replace("%Y", YELLOW)
.replace("%G", GREEN)
.replace("%B", BLUE)
.replace("%P", PURPLE).append("</col>") + " "
return new
private val pattern = Regex("%[0-9a-fA-F]{6}")
private val testData = arrayOf("This is a string with no colors.", "This %R is a string with one color.", "This %R %G %B is a string with multiple colors.", "This %ffffff is an arbitrary hex string.")
fun colorize(line: String): String {
return line.replace("%R", RED)
.replace("%O", ORANGE)
.replace("%Y", YELLOW)
.replace("%G", GREEN)
.replace("%B", BLUE)
.replace("%P", PURPLE)
.replace(pattern) { matchResult -> "<col=${matchResult.value.substring(1)}>" }
.append("</col>") + " "
}
fun colorize(line: String, hexColor: String): String{