From 7739d49d4a46178dc5419ff6f588505c197a8f39 Mon Sep 17 00:00:00 2001 From: Ceikry Date: Mon, 28 Mar 2022 13:47:57 +0000 Subject: [PATCH] Added ingame rules confirmation screen --- .../java/core/game/component/Component.java | 6 +- .../player/info/login/LoginConfiguration.java | 4 ++ .../src/main/kotlin/rs09/ServerConstants.kt | 5 +- .../gnomecooking/GnomeCookingConstants.kt | 4 +- .../tutorial/TutorialMagicTutorDialogue.kt | 4 +- .../game/interaction/InterfaceListeners.kt | 2 +- .../game/interaction/inter/RulesAndInfo.kt | 58 +++++++++++++++++++ .../system/command/sets/MiscCommandSet.kt | 20 +++++++ .../game/system/config/ServerConfigParser.kt | 3 +- 9 files changed, 94 insertions(+), 12 deletions(-) create mode 100644 Server/src/main/kotlin/rs09/game/interaction/inter/RulesAndInfo.kt diff --git a/Server/src/main/java/core/game/component/Component.java b/Server/src/main/java/core/game/component/Component.java index 9ce427f4c..83dd11bff 100644 --- a/Server/src/main/java/core/game/component/Component.java +++ b/Server/src/main/java/core/game/component/Component.java @@ -84,11 +84,7 @@ public class Component { * @return {@code True} if the component can be closed. */ public boolean close(Player player) { - InterfaceListeners.runClose(player,this); - if (closeEvent != null && !closeEvent.close(player, this)) { - return false; - } - return true; + return (closeEvent == null || closeEvent.close(player, this)) && InterfaceListeners.runClose(player, this); } /** diff --git a/Server/src/main/java/core/game/node/entity/player/info/login/LoginConfiguration.java b/Server/src/main/java/core/game/node/entity/player/info/login/LoginConfiguration.java index f0fd51197..fd0ec114f 100644 --- a/Server/src/main/java/core/game/node/entity/player/info/login/LoginConfiguration.java +++ b/Server/src/main/java/core/game/node/entity/player/info/login/LoginConfiguration.java @@ -12,6 +12,8 @@ import core.net.packet.PacketRepository; import core.net.packet.context.InterfaceContext; import core.net.packet.out.Interface; import core.plugin.Plugin; +import rs09.ServerConstants; +import rs09.game.interaction.inter.RulesAndInfo; import rs09.game.system.SystemLogger; import rs09.game.world.GameWorld; import rs09.game.world.repository.Repository; @@ -144,6 +146,8 @@ public final class LoginConfiguration { player.getEmoteManager().unlock(Emotes.SAFETY_FIRST); } player.varpManager.sendAllVarps(); + if(ServerConstants.RULES_AND_INFO_ENABLED) + RulesAndInfo.openFor(player); /*if (GameWorld.getSettings().isPvp()) { player.getPacketDispatch().sendString("", 226, 1); }*/ diff --git a/Server/src/main/kotlin/rs09/ServerConstants.kt b/Server/src/main/kotlin/rs09/ServerConstants.kt index 5843419ca..16fc727f9 100644 --- a/Server/src/main/kotlin/rs09/ServerConstants.kt +++ b/Server/src/main/kotlin/rs09/ServerConstants.kt @@ -116,6 +116,9 @@ class ServerConstants { @JvmField var LOG_CUTSCENE = true + @JvmField + var RULES_AND_INFO_ENABLED = true + //location names for the ::to command. val TELEPORT_DESTINATIONS = arrayOf( arrayOf(Location.create(2974, 4383, 2), "corp", "corporal", "corporeal"), @@ -203,4 +206,4 @@ class ServerConstants { @JvmField var DAILY_RESTART = false } -} \ No newline at end of file +} diff --git a/Server/src/main/kotlin/rs09/game/content/activity/gnomecooking/GnomeCookingConstants.kt b/Server/src/main/kotlin/rs09/game/content/activity/gnomecooking/GnomeCookingConstants.kt index b974b25ae..4f0979fe1 100644 --- a/Server/src/main/kotlin/rs09/game/content/activity/gnomecooking/GnomeCookingConstants.kt +++ b/Server/src/main/kotlin/rs09/game/content/activity/gnomecooking/GnomeCookingConstants.kt @@ -1,8 +1,8 @@ package rs09.game.content.activity.gnomecooking const val GC_BASE_ATTRIBUTE = "gnome_cooking" -const val GC_TUT_PROG = "tutorial:stage" -const val GC_TUT_FIN = "tutorial:complete" +const val GC_TUT_PROG = "gnome-cooking:tutorial:stage" +const val GC_TUT_FIN = "gnome-cooking:tutorial:complete" const val GC_JOB_ORDINAL = "job:job_ordinal" const val GC_JOB_COMPLETE = "job:job_complete" const val GC_HARD_JOB = "job:hard_job" diff --git a/Server/src/main/kotlin/rs09/game/content/tutorial/TutorialMagicTutorDialogue.kt b/Server/src/main/kotlin/rs09/game/content/tutorial/TutorialMagicTutorDialogue.kt index dac6fd5de..b4cefaa61 100644 --- a/Server/src/main/kotlin/rs09/game/content/tutorial/TutorialMagicTutorDialogue.kt +++ b/Server/src/main/kotlin/rs09/game/content/tutorial/TutorialMagicTutorDialogue.kt @@ -16,6 +16,7 @@ import core.net.amsc.WorldCommunicator import core.plugin.Initializable import org.rs09.consts.Items import org.rs09.consts.NPCs +import rs09.game.interaction.inter.RulesAndInfo import rs09.game.world.GameWorld import rs09.tools.END_DIALOGUE @@ -147,7 +148,6 @@ class TutorialMagicTutorDialogue(player: Player? = null) : DialoguePlugin(player "at any time, look for a signpost or use the Lumbridge Home Port Spell." ) stage = 12 - player.unlock() if(WorldCommunicator.isEnabled()) MSPacketRepository.sendInfoUpdate(player) TutorialStage.removeHintIcon(player) @@ -158,12 +158,12 @@ class TutorialMagicTutorDialogue(player: Player? = null) : DialoguePlugin(player player.unhook(TutorialUseWithReceiver) player.unhook(TutorialInteractionReceiver) player.unhook(TutorialButtonReceiver) + RulesAndInfo.openFor(player) } 12 -> { player.setAttribute("close_c_", true) end() - sendMessage(player, "Welcome to ${GameWorld.settings!!.name}.") } } } diff --git a/Server/src/main/kotlin/rs09/game/interaction/InterfaceListeners.kt b/Server/src/main/kotlin/rs09/game/interaction/InterfaceListeners.kt index 7145a3fa9..ab626abac 100644 --- a/Server/src/main/kotlin/rs09/game/interaction/InterfaceListeners.kt +++ b/Server/src/main/kotlin/rs09/game/interaction/InterfaceListeners.kt @@ -55,7 +55,7 @@ object InterfaceListeners { @JvmStatic fun runClose(player: Player,component: Component): Boolean{ - val method = getCloseListener(component.id) ?: return false + val method = getCloseListener(component.id) ?: return true return method.invoke(player,component) } diff --git a/Server/src/main/kotlin/rs09/game/interaction/inter/RulesAndInfo.kt b/Server/src/main/kotlin/rs09/game/interaction/inter/RulesAndInfo.kt new file mode 100644 index 000000000..7eeac8bdf --- /dev/null +++ b/Server/src/main/kotlin/rs09/game/interaction/inter/RulesAndInfo.kt @@ -0,0 +1,58 @@ +package rs09.game.interaction.inter + +import api.* +import core.game.node.entity.player.Player +import core.tools.RandomFunction +import rs09.game.interaction.InterfaceListener +import rs09.game.system.SystemLogger + +object RulesAndInfo { + val RULES = arrayOf( + "1. Be respectful to your fellow players.", + " -No harassment, etc.", + " -Keep arguments private.", + "2. Do not exploit bugs.", + " -Zero tolerance. Can result in account deletion.", + " -If you discover a bug, report it on our Gitlab.", + "3. Do not discuss or advertise other servers.", + " -Discussion of the live jagex games is fine.", + " -Discussion of open source projects is fine.", + "4. No use of any kind of automation tool.", + " -This includes autoclickers, autohotkey, etc.", + " -Exception: 1-to-1 inputs, such as mousekeys." + ) + val SEPARATOR = " " + val INFO = arrayOf( + "To join our Discord, type ::discord" + ) + + @JvmStatic + fun openFor(player: Player) + { + if(getAttribute(player, "rules:confirmed", false) || !getAttribute(player, "tutorial:complete", false)) + return + var ln = 1 + val pin = getAttribute(player, "rules:pin", RandomFunction.random(1000,9999)) + setAttribute(player, "/save:rules:pin", pin) + for(line in INFO) setInterfaceText(player, INFO[ln - 1], 384, ln++) + setInterfaceText(player, SEPARATOR, 384, ln++) + val newIndex = ln + for(line in RULES) setInterfaceText(player, RULES[ln - newIndex], 384, ln++) + setInterfaceText(player, "If you agree to the above, type ::confirmrules $pin", 384, ln++) + setInterfaceText(player, "", 384, ln) + player.packetDispatch.sendInterfaceConfig(384, 17, true) + openInterface(player, 384) + player.lock() + } +} + +class RulesListener : InterfaceListener() +{ + override fun defineListeners() { + onClose(384){player, _ -> + if(!getAttribute(player, "rules:confirmed", false)) + runTask(player, 1) { RulesAndInfo.openFor(player); sendDialogue(player, "Please read the rules.") } + return@onClose true + } + } +} \ No newline at end of file diff --git a/Server/src/main/kotlin/rs09/game/system/command/sets/MiscCommandSet.kt b/Server/src/main/kotlin/rs09/game/system/command/sets/MiscCommandSet.kt index 7a08708ff..03d40bbe9 100644 --- a/Server/src/main/kotlin/rs09/game/system/command/sets/MiscCommandSet.kt +++ b/Server/src/main/kotlin/rs09/game/system/command/sets/MiscCommandSet.kt @@ -526,6 +526,26 @@ class MiscCommandSet : CommandSet(Command.Privilege.ADMIN){ } } + + define("confirmrules", Command.Privilege.STANDARD) { player, args -> + if(getAttribute(player,"rules:confirmed", false)) + reject(player, "You have already confirmed the rules.") + if(args.size < 2) + reject(player, "Usage: ::confirmrules PIN") + val pin = args[1].toIntOrNull() ?: (-1).also{ reject(player, "Please enter a valid number.") } + if(pin == getAttribute(player, "rules:pin", -1)) + { + player.setAttribute("/save:rules:confirmed", true) + player.interfaceManager.close() + sendDialogue(player, "Thank you!") + player.unlock() + player.removeAttribute("rules:pin") + } + else + { + sendDialogue(player, "Wrong pin. Try again.") + } + } } fun showGeBotsearch(player: Player, searchTerm: String) diff --git a/Server/src/main/kotlin/rs09/game/system/config/ServerConfigParser.kt b/Server/src/main/kotlin/rs09/game/system/config/ServerConfigParser.kt index d55443dd3..d1bed5335 100644 --- a/Server/src/main/kotlin/rs09/game/system/config/ServerConfigParser.kt +++ b/Server/src/main/kotlin/rs09/game/system/config/ServerConfigParser.kt @@ -102,6 +102,7 @@ object ServerConfigParser { ServerConstants.GRAND_EXCHANGE_DATA_PATH = data.getPath("paths.eco_data") ServerConstants.CELEDT_DATA_PATH = data.getPath("paths.cele_drop_table_path") ServerConstants.SERVER_GE_NAME = data.getString("world.name_ge") ?: ServerConstants.SERVER_NAME + ServerConstants.RULES_AND_INFO_ENABLED = data.getBoolean("world.show_rules", true) } @@ -147,4 +148,4 @@ object ServerConfigParser { return pathProduct } -} \ No newline at end of file +}