Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion data/client/scripts.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,12 @@ id = 101
[int_entry]
id = 108

[string_entry]
[name_entry]
id = 109

[string_entry]
id = 110

[dialogue_item_zoom]
id = 3449

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class InstructionHandlers(
var examineNPC: ExamineNpc.(Player) -> Unit = empty()
var examineObject: ExamineObject.(Player) -> Unit = empty()
var enterString: EnterString.(Player) -> Unit = empty()
var enterName: EnterName.(Player) -> Unit = empty()
var enterInt: EnterInt.(Player) -> Unit = empty()
var friendAddHandler: FriendAdd.(Player) -> Unit = empty()
var friendDeleteHandler: FriendDelete.(Player) -> Unit = empty()
Expand Down Expand Up @@ -94,6 +95,7 @@ class InstructionHandlers(
is FinishRegionLoad -> finishRegionLoad.invoke(instruction, player)
is ExecuteCommand -> executeCommand.validate(player, instruction)
is EnterString -> enterString.invoke(instruction, player)
is EnterName -> enterName.invoke(instruction, player)
is EnterInt -> enterInt.invoke(instruction, player)
is FriendAdd -> friendAddHandler.invoke(instruction, player)
is FriendDelete -> friendDeleteHandler.invoke(instruction, player)
Expand Down Expand Up @@ -124,6 +126,7 @@ inline fun <reified I : Instruction> instruction(noinline handler: I.(Player) ->
ExamineNpc::class -> get<InstructionHandlers>().examineNPC = handler as ExamineNpc.(Player) -> Unit
ExamineObject::class -> get<InstructionHandlers>().examineObject = handler as ExamineObject.(Player) -> Unit
EnterString::class -> get<InstructionHandlers>().enterString = handler as EnterString.(Player) -> Unit
EnterName::class -> get<InstructionHandlers>().enterName = handler as EnterName.(Player) -> Unit
EnterInt::class -> get<InstructionHandlers>().enterInt = handler as EnterInt.(Player) -> Unit
FriendAdd::class -> get<InstructionHandlers>().friendAddHandler = handler as FriendAdd.(Player) -> Unit
FriendDelete::class -> get<InstructionHandlers>().friendDeleteHandler = handler as FriendDelete.(Player) -> Unit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ class ContinueSuspension : DialogueSuspension<Unit>() {
}
}

class NameSuspension : DialogueSuspension<String>() {
companion object {
suspend fun get(player: Player) = NameSuspension().get(player)
}
}

class StringSuspension : DialogueSuspension<String>() {
companion object {
suspend fun get(player: Player) = StringSuspension().get(player)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ package content.entity.player.dialogue
import world.gregs.voidps.engine.client.ui.dialogue.continueDialogue
import world.gregs.voidps.engine.client.instruction.instruction
import world.gregs.voidps.engine.suspend.IntSuspension
import world.gregs.voidps.engine.suspend.NameSuspension
import world.gregs.voidps.engine.suspend.StringSuspension
import world.gregs.voidps.network.client.instruction.EnterInt
import world.gregs.voidps.network.client.instruction.EnterName
import world.gregs.voidps.network.client.instruction.EnterString

continueDialogue("dialogue_npc_chat*", "continue") { player ->
Expand Down Expand Up @@ -44,6 +46,10 @@ instruction<EnterString> { player ->
(player.dialogueSuspension as? StringSuspension)?.resume(value)
}

instruction<EnterName> { player ->
(player.dialogueSuspension as? NameSuspension)?.resume(value)
}

continueDialogue("dialogue_confirm_destroy") { player ->
(player.dialogueSuspension as? StringSuspension)?.resume(component)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package content.entity.player.dialogue.type

import world.gregs.voidps.engine.client.sendScript
import world.gregs.voidps.engine.entity.character.player.Player
import world.gregs.voidps.engine.event.Context
import world.gregs.voidps.engine.suspend.NameSuspension

suspend fun Context<Player>.nameEntry(text: String): String {
player.sendScript("name_entry", text)
return NameSuspension.get(player)
}
4 changes: 2 additions & 2 deletions game/src/main/kotlin/content/social/friend/NameChange.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import world.gregs.voidps.engine.inject
import world.gregs.voidps.engine.timer.epochSeconds
import world.gregs.voidps.network.login.protocol.encode.Friend
import content.entity.player.dialogue.type.choice
import content.entity.player.dialogue.type.stringEntry
import content.entity.player.dialogue.type.nameEntry
import java.util.concurrent.TimeUnit

val players: Players by inject()
Expand All @@ -28,7 +28,7 @@ modCommand("rename", "rename your accounts display name (login stays the same)")
player.message("You can change your name again in $days ${"day".plural(days)} and $hours ${"hour".plural(hours)}.")
return@modCommand
}
val toName = stringEntry("Enter a new name")
val toName = nameEntry("Enter a new name")
if (toName.length !in 1..12) {
player.message("Name too long, a username must be less than 12 characters.")
return@modCommand
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package world.gregs.voidps.network.client.instruction

import world.gregs.voidps.network.client.Instruction

data class EnterName(val value: String) : Instruction
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ fun decoders(huffman: Huffman): Array<Decoder?> {
array[4] = RegionLoadedDecoder()
array[47] = RegionLoadingDecoder()
array[7] = ScreenChangeDecoder()
array[43] = StringEntryDecoder()
array[43] = NameEntryDecoder()
array[35] = WalkMapDecoder()
array[82] = WalkMiniMapDecoder()
array[49] = WindowClickDecoder()
Expand All @@ -82,7 +82,7 @@ fun decoders(huffman: Huffman): Array<Decoder?> {
array[74] = ClanChatRankDecoder()
array[77] = ReflectionResponseDecoder()
array[76] = SecondaryTeleportDecoder()
array[1] = ClanChatNameDecoder()
array[1] = StringEntryDecoder()
array[34] = InterfaceOnFloorItemDecoder()
array[40] = APCoordinateDecoder()
array[28] = ResumeObjDialogueDecoder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@ package world.gregs.voidps.network.login.protocol.decode

import io.ktor.utils.io.core.*
import world.gregs.voidps.network.client.Instruction
import world.gregs.voidps.network.client.instruction.EnterName
import world.gregs.voidps.network.login.protocol.Decoder
import world.gregs.voidps.network.login.protocol.readString

class ClanChatNameDecoder : Decoder(BYTE) {
class NameEntryDecoder : Decoder(BYTE) {

override suspend fun decode(packet: ByteReadPacket): Instruction? {
val index = packet.readInt()
val name = packet.readString()
return null
override suspend fun decode(packet: ByteReadPacket): Instruction {
return EnterName(packet.readString())
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class DecoderTest {
ChatTypeChange(123), // 31
ClanChatJoin("clan chat"), // 50
ClanChatKick("clan chat"), // 64
null, // 1
EnterString("a string"), // 1
ClanChatRank("friend name", 123), // 74
ExecuteCommand("item", "abyssal_whip 1"), // 53
FriendDelete("friends_name"), // 6
Expand Down Expand Up @@ -103,7 +103,7 @@ class DecoderTest {
null, // 28
ChangeDisplayMode(12, 345, 678, 9), // 7
null, // 76
EnterString("a string"), // 43
EnterName("a string"), // 43
null, // 84
null, // 71
Walk(1234, 4321), // 35
Expand Down
2 changes: 1 addition & 1 deletion network/src/test/resources/decoder-packets.csv
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
31, 123
50, 99, 108, 97, 110, 32, 99, 104, 97, 116, 0
64, 99, 108, 97, 110, 32, 99, 104, 97, 116, 0
1, 0, 0, 4, -46, 99, 108, 97, 110, 32, 99, 104, 97, 116, 0
1, 97, 32, 115, 116, 114, 105, 110, 103, 0
74, 5, 102, 114, 105, 101, 110, 100, 32, 110, 97, 109, 101, 0
53, 1, 2, 105, 116, 101, 109, 32, 97, 98, 121, 115, 115, 97, 108, 95, 119, 104, 105, 112, 32, 49, 0
6, 102, 114, 105, 101, 110, 100, 115, 95, 110, 97, 109, 101, 0
Expand Down
Loading