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
3 changes: 3 additions & 0 deletions data/client/client.scripts.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ id = 143
[close_entry]
id = 101

[close_report_abuse]
id = 244

[int_entry]
id = 108

Expand Down
7 changes: 7 additions & 0 deletions game/src/main/kotlin/content/social/report/ReportAbuse.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import content.social.chat.ChatHistory
import world.gregs.voidps.engine.Script
import world.gregs.voidps.engine.client.instruction.instruction
import world.gregs.voidps.engine.client.message
import world.gregs.voidps.engine.client.sendScript
import world.gregs.voidps.engine.client.ui.close
import world.gregs.voidps.engine.client.ui.hasMenuOpen
import world.gregs.voidps.engine.client.ui.open
import world.gregs.voidps.engine.client.variable.hasClock
Expand Down Expand Up @@ -49,7 +51,12 @@ class ReportAbuse(val reports: Reports, val accounts: AccountDefinitions) : Scri
}
}

interfaceClosed("report_abuse") {
sendScript("close_report_abuse")
}

instruction<ReportAbuse> { player ->
player.close("report_abuse")
val rule = Rule.byId(type) ?: return@instruction
val name = name.trim()
if (name.isEmpty()) {
Expand Down
22 changes: 22 additions & 0 deletions game/src/test/kotlin/content/social/report/ReportAbuseTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,22 @@ package content.social.report
import WorldTest
import interfaceOption
import io.mockk.mockkStatic
import io.mockk.unmockkStatic
import io.mockk.verify
import kotlinx.coroutines.test.runTest
import org.junit.jupiter.api.BeforeAll
import org.junit.jupiter.api.Test
import world.gregs.voidps.cache.definition.data.InterfaceDefinition
import world.gregs.voidps.engine.client.ui.hasOpen
import world.gregs.voidps.engine.client.ui.open
import world.gregs.voidps.engine.entity.character.player.PlayerRights
import world.gregs.voidps.engine.entity.character.player.chat.ChatType
import world.gregs.voidps.engine.entity.character.player.rights
import world.gregs.voidps.network.client.instruction.ChatPublic
import world.gregs.voidps.network.client.instruction.ReportAbuse
import world.gregs.voidps.network.login.protocol.encode.interfaceVisibility
import world.gregs.voidps.network.login.protocol.encode.message
import world.gregs.voidps.network.login.protocol.encode.sendScript
import kotlin.test.assertFalse
import kotlin.test.assertTrue

Expand All @@ -40,6 +43,25 @@ internal class ReportAbuseTest : WorldTest() {
}
}

@Test
fun `Submitting a report closes the interface and restores the chat box`() = runTest {
val (player, client) = createClient("snitch")
createPlayer(name = "scammer")
player.open("report_abuse")
assertTrue(player.hasOpen("report_abuse"))

mockkStatic("world.gregs.voidps.network.login.protocol.encode.ScriptEncoderKt")
try {
player.instructions.send(ReportAbuse("scammer", 15, 0, ""))
tick()

assertFalse(player.hasOpen("report_abuse"))
verify { client.sendScript(244, any()) } // close_report_abuse
} finally {
unmockkStatic("world.gregs.voidps.network.login.protocol.encode.ScriptEncoderKt")
}
}

@Test
fun `Can't report yourself`() = runTest {
val (player, client) = createClient("snitch")
Expand Down
Loading