Merge pull request #6 from openmmo-org/feat/friendlist
feat(game): add friendlist
This commit is contained in:
commit
df862c71b7
56 files changed
+473
-182
No files matched your search
@@ -271,11 +271,11 @@ object GameProtocol : Protocol() {
|
|||||||
c2s<UnblockPlayerPacket>(0x61u, UnblockPlayerPacketCodec)
|
c2s<UnblockPlayerPacket>(0x61u, UnblockPlayerPacketCodec)
|
||||||
s2c<EntityCoordSyncPacket>(0x61u, EntityCoordSyncPacketCodec)
|
s2c<EntityCoordSyncPacket>(0x61u, EntityCoordSyncPacketCodec)
|
||||||
|
|
||||||
c2s<RemoveFriendPacket>(0x62u, RemoveFriendPacketCodec)
|
c2s<AddFriendPacket>(0x62u, AddFriendPacketCodec)
|
||||||
s2c<SocialActionOutcomePacket>(0x62u, SocialActionOutcomePacketCodec)
|
s2c<SocialActionOutcomePacket>(0x62u, SocialActionOutcomePacketCodec)
|
||||||
|
|
||||||
c2s<SetPlayerTitlePacket>(0x63u, SetPlayerTitlePacketCodec)
|
c2s<RemoveFriendPacket>(0x63u, RemoveFriendPacketCodec)
|
||||||
s2c<ContactRosterPacket>(0x63u, ContactRosterPacketCodec)
|
s2c<FriendListPacket>(0x63u, FriendListPacketCodec)
|
||||||
|
|
||||||
c2s<FriendProfileRequestPacket>(0x64u, FriendProfileRequestPacketCodec)
|
c2s<FriendProfileRequestPacket>(0x64u, FriendProfileRequestPacketCodec)
|
||||||
s2c<ContactInsertPacket>(0x64u, ContactInsertPacketCodec)
|
s2c<ContactInsertPacket>(0x64u, ContactInsertPacketCodec)
|
||||||
@@ -594,6 +594,5 @@ object GameProtocol : Protocol() {
|
|||||||
s2c<GtlListingsPagePacket>(0xFEu, GtlListingsPagePacketCodec)
|
s2c<GtlListingsPagePacket>(0xFEu, GtlListingsPagePacketCodec)
|
||||||
|
|
||||||
s2c<WorldSessionStatePacket>(0xFFu, WorldSessionStatePacketCodec)
|
s2c<WorldSessionStatePacket>(0xFFu, WorldSessionStatePacketCodec)
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
package de.fiereu.openmmo.net.game.packets
|
||||||
|
|
||||||
|
import de.fiereu.bytecodec.CodecScope
|
||||||
|
import de.fiereu.bytecodec.PacketCodec
|
||||||
|
import de.fiereu.bytecodec.Utf16LeNullTerminated
|
||||||
|
|
||||||
|
data class AddFriendPacket(val username: String)
|
||||||
|
|
||||||
|
object AddFriendPacketCodec : PacketCodec<AddFriendPacket>() {
|
||||||
|
override fun CodecScope<AddFriendPacket>.body(): AddFriendPacket {
|
||||||
|
val username = field(Utf16LeNullTerminated) { it.username }
|
||||||
|
return AddFriendPacket(username)
|
||||||
|
}
|
||||||
|
}
|
||||||
+1
-3
@@ -75,9 +75,7 @@ private val EventsCodec: Codec<List<InputEventSample>> =
|
|||||||
shortB = S16LE.read(buf)
|
shortB = S16LE.read(buf)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
result.add(
|
result.add(InputEventSample(type, timestamp, byteA, byteB, intA, shortA, shortB, intB))
|
||||||
InputEventSample(type, timestamp, byteA, byteB, intA, shortA, shortB, intB)
|
|
||||||
)
|
|
||||||
previous = timestamp
|
previous = timestamp
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
|
|||||||
+15
-3
@@ -75,9 +75,21 @@ private class BattleParticipantCodec(private val isCapture: Boolean) :
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return BattleActionParticipant(
|
return BattleActionParticipant(
|
||||||
entityId, kind, intA, intB, intC, shortA, critByte, critShort, capturedShort, capturedByte,
|
entityId,
|
||||||
xpShort, xpByteA, xpByteB, pokemon, statStages
|
kind,
|
||||||
)
|
intA,
|
||||||
|
intB,
|
||||||
|
intC,
|
||||||
|
shortA,
|
||||||
|
critByte,
|
||||||
|
critShort,
|
||||||
|
capturedShort,
|
||||||
|
capturedByte,
|
||||||
|
xpShort,
|
||||||
|
xpByteA,
|
||||||
|
xpByteB,
|
||||||
|
pokemon,
|
||||||
|
statStages)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-1
@@ -28,7 +28,8 @@ private val BattleActionSelectBody: Codec<BattleActionSelectPacket> =
|
|||||||
S8.write(buf, value.extraFlag)
|
S8.write(buf, value.extraFlag)
|
||||||
}
|
}
|
||||||
|
|
||||||
2, 3 -> {
|
2,
|
||||||
|
3 -> {
|
||||||
S16LE.write(buf, value.moveOrItemId)
|
S16LE.write(buf, value.moveOrItemId)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-1
@@ -157,7 +157,8 @@ internal val BattleSerializedEntryCodec: Codec<BattleSerializedEntry> =
|
|||||||
S16LE.write(buf, value.y)
|
S16LE.write(buf, value.y)
|
||||||
}
|
}
|
||||||
|
|
||||||
is EmptyCreatureDataEntry -> throw MalformedPacketException("cannot encode default battle entry")
|
is EmptyCreatureDataEntry ->
|
||||||
|
throw MalformedPacketException("cannot encode default battle entry")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+7
-3
@@ -28,14 +28,18 @@ internal val MessageArgCodec: Codec<MessageArg> =
|
|||||||
when (type) {
|
when (type) {
|
||||||
28 -> {}
|
28 -> {}
|
||||||
30 -> longValue = field(S64LE) { it.longValue!! }
|
30 -> longValue = field(S64LE) { it.longValue!! }
|
||||||
9, 10, 17 -> intValue = field(S32LE) { it.intValue!! }
|
9,
|
||||||
5, 18 -> stringValue = field(Utf16LeNullTerminated) { it.stringValue!! }
|
10,
|
||||||
|
17 -> intValue = field(S32LE) { it.intValue!! }
|
||||||
|
5,
|
||||||
|
18 -> stringValue = field(Utf16LeNullTerminated) { it.stringValue!! }
|
||||||
else -> {
|
else -> {
|
||||||
val count = field(U8) { it.shortValues!!.size }
|
val count = field(U8) { it.shortValues!!.size }
|
||||||
shortValues = (0 until count).map { i -> field(S16LE) { it.shortValues!![i] } }
|
shortValues = (0 until count).map { i -> field(S16LE) { it.shortValues!![i] } }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return MessageArg(argId, type, hasExtra, extra, longValue, intValue, stringValue, shortValues)
|
return MessageArg(
|
||||||
|
argId, type, hasExtra, extra, longValue, intValue, stringValue, shortValues)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-1
@@ -88,7 +88,8 @@ object BattleEntityDeltaPacketCodec : PacketCodec<BattleEntityDeltaPacket>() {
|
|||||||
val ivs = if (m and 262144 != 0) field(S16LE.repeat(5)) { it.ivs!! } else null
|
val ivs = if (m and 262144 != 0) field(S16LE.repeat(5)) { it.ivs!! } else null
|
||||||
val caughtBall = if (m and 524288 != 0) field(S8) { it.caughtBall!! } else null
|
val caughtBall = if (m and 524288 != 0) field(S8) { it.caughtBall!! } else null
|
||||||
val statusFlags2 = if (m and 1048576 != 0) field(S16LE) { it.statusFlags2!! } else null
|
val statusFlags2 = if (m and 1048576 != 0) field(S16LE) { it.statusFlags2!! } else null
|
||||||
val statusList = if (m and 4194304 != 0) field(S8.listPrefixed(U8)) { it.statusList!! } else null
|
val statusList =
|
||||||
|
if (m and 4194304 != 0) field(S8.listPrefixed(U8)) { it.statusList!! } else null
|
||||||
val status = if (m and 8388608 != 0) field(S8) { it.status!! } else null
|
val status = if (m and 8388608 != 0) field(S8) { it.status!! } else null
|
||||||
|
|
||||||
return BattleEntityDeltaPacket(
|
return BattleEntityDeltaPacket(
|
||||||
|
|||||||
+14
-7
@@ -35,9 +35,18 @@ private val BattleRankingEntryCodec: Codec<BattleRankingEntry> =
|
|||||||
val bool2 = field(Bool) { it.bool2 }
|
val bool2 = field(Bool) { it.bool2 }
|
||||||
field(S8) { 0 }
|
field(S8) { 0 }
|
||||||
return BattleRankingEntry(
|
return BattleRankingEntry(
|
||||||
entityId, flag1, flag2, name, value1, genderId, ribbons, byte1, int1, byte2, bool1,
|
entityId,
|
||||||
bool2
|
flag1,
|
||||||
)
|
flag2,
|
||||||
|
name,
|
||||||
|
value1,
|
||||||
|
genderId,
|
||||||
|
ribbons,
|
||||||
|
byte1,
|
||||||
|
int1,
|
||||||
|
byte2,
|
||||||
|
bool1,
|
||||||
|
bool2)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -148,8 +157,7 @@ private val BattleStorageItemCodec: Codec<BattleStorageItem> =
|
|||||||
val pokemonByte = field(S8) { it.pokemonByte }
|
val pokemonByte = field(S8) { it.pokemonByte }
|
||||||
val boxByte = field(S8) { it.boxByte }
|
val boxByte = field(S8) { it.boxByte }
|
||||||
return BattleStorageItem(
|
return BattleStorageItem(
|
||||||
typeByte, short1, short2, short3, short4, byte1, pokemonByte, boxByte
|
typeByte, short1, short2, short3, short4, byte1, pokemonByte, boxByte)
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -167,8 +175,7 @@ object BattleScreenOpenPacketCodec : PacketCodec<BattleScreenOpenPacket>() {
|
|||||||
val active = field(U8) { if (it.active) 1 else 0 } == 1
|
val active = field(U8) { if (it.active) 1 else 0 } == 1
|
||||||
if (!active) {
|
if (!active) {
|
||||||
return BattleScreenOpenPacket(
|
return BattleScreenOpenPacket(
|
||||||
false, false, emptyList(), emptyList(), emptyList(), emptyList()
|
false, false, emptyList(), emptyList(), emptyList(), emptyList())
|
||||||
)
|
|
||||||
}
|
}
|
||||||
val wild = field(U8) { if (it.wild) 1 else 0 } == 1
|
val wild = field(U8) { if (it.wild) 1 else 0 } == 1
|
||||||
var participants = emptyList<BattleRankingEntry>()
|
var participants = emptyList<BattleRankingEntry>()
|
||||||
|
|||||||
+11
-4
@@ -40,9 +40,16 @@ object BattleSendOutActivePacketCodec : PacketCodec<BattleSendOutActivePacket>()
|
|||||||
return BattleSendOutActivePacket(
|
return BattleSendOutActivePacket(
|
||||||
opponent,
|
opponent,
|
||||||
BattleSendOutMember(
|
BattleSendOutMember(
|
||||||
entityIdA, entityIdB, entityIdC, speciesByte, nickname, ownerName, value, nameA, nameB,
|
entityIdA,
|
||||||
levelByte, flag
|
entityIdB,
|
||||||
)
|
entityIdC,
|
||||||
)
|
speciesByte,
|
||||||
|
nickname,
|
||||||
|
ownerName,
|
||||||
|
value,
|
||||||
|
nameA,
|
||||||
|
nameB,
|
||||||
|
levelByte,
|
||||||
|
flag))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+1
-2
@@ -43,8 +43,7 @@ private val BattleAddPokemonCodec: Codec<BattleAddPokemon> =
|
|||||||
BattleAddStatusEffect(durationTurns, effectType, sourceSlot)
|
BattleAddStatusEffect(durationTurns, effectType, sourceSlot)
|
||||||
} else null
|
} else null
|
||||||
return BattleAddPokemon(
|
return BattleAddPokemon(
|
||||||
entityId, frontSpriteId, backSpriteId, side, slot, partyIndex, statusEffect
|
entityId, frontSpriteId, backSpriteId, side, slot, partyIndex, statusEffect)
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-2
@@ -45,8 +45,7 @@ private val BattlePartyPokemonCodec: Codec<BattlePartyPokemon> =
|
|||||||
BattlePartyStatusEffect(durationTurns, effectType, sourceSlot)
|
BattlePartyStatusEffect(durationTurns, effectType, sourceSlot)
|
||||||
} else null
|
} else null
|
||||||
return BattlePartyPokemon(
|
return BattlePartyPokemon(
|
||||||
entityId, frontSpriteId, backSpriteId, side, slot, partyIndex, statusEffect
|
entityId, frontSpriteId, backSpriteId, side, slot, partyIndex, statusEffect)
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-1
@@ -17,7 +17,8 @@ private val SimulationConfigPayload: Codec<ByteArray> =
|
|||||||
|
|
||||||
data class BattleSimulationRequestPacket(val simulationConfig: ByteArray) {
|
data class BattleSimulationRequestPacket(val simulationConfig: ByteArray) {
|
||||||
override fun equals(other: Any?): Boolean =
|
override fun equals(other: Any?): Boolean =
|
||||||
other is BattleSimulationRequestPacket && simulationConfig.contentEquals(other.simulationConfig)
|
other is BattleSimulationRequestPacket &&
|
||||||
|
simulationConfig.contentEquals(other.simulationConfig)
|
||||||
|
|
||||||
override fun hashCode(): Int = simulationConfig.contentHashCode()
|
override fun hashCode(): Int = simulationConfig.contentHashCode()
|
||||||
}
|
}
|
||||||
|
|||||||
+11
-3
@@ -33,9 +33,17 @@ private class BattlePreviewMemberCodec(
|
|||||||
val levelByte = field(S8) { it.levelByte }
|
val levelByte = field(S8) { it.levelByte }
|
||||||
val flag = field(Bool) { it.flag }
|
val flag = field(Bool) { it.flag }
|
||||||
return BattlePreviewMember(
|
return BattlePreviewMember(
|
||||||
entityIdA, entityIdB, entityIdC, speciesByte, nickname, ownerName, value, nameA, nameB,
|
entityIdA,
|
||||||
levelByte, flag
|
entityIdB,
|
||||||
)
|
entityIdC,
|
||||||
|
speciesByte,
|
||||||
|
nickname,
|
||||||
|
ownerName,
|
||||||
|
value,
|
||||||
|
nameA,
|
||||||
|
nameB,
|
||||||
|
levelByte,
|
||||||
|
flag)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-1
@@ -34,7 +34,8 @@ object CharacterAppearanceApplyPacketCodec : PacketCodec<CharacterAppearanceAppl
|
|||||||
val moves = mutableListOf<AppearanceMoveEntry>()
|
val moves = mutableListOf<AppearanceMoveEntry>()
|
||||||
for (slot in 0 until 15) {
|
for (slot in 0 until 15) {
|
||||||
if (mask and (1 shl slot) != 0) {
|
if (mask and (1 shl slot) != 0) {
|
||||||
val packed = field(S16LE) { v -> v.creatureMoves.moves.first { it.slot == slot }.packedMove }
|
val packed =
|
||||||
|
field(S16LE) { v -> v.creatureMoves.moves.first { it.slot == slot }.packedMove }
|
||||||
val pp: Byte? =
|
val pp: Byte? =
|
||||||
if (hasPp) field(S8) { v -> v.creatureMoves.moves.first { it.slot == slot }.ppUp ?: 0 }
|
if (hasPp) field(S8) { v -> v.creatureMoves.moves.first { it.slot == slot }.ppUp ?: 0 }
|
||||||
else null
|
else null
|
||||||
|
|||||||
+1
-2
@@ -15,8 +15,7 @@ object ChatMessageSendPacketCodec : PacketCodec<ChatMessageSendPacket>() {
|
|||||||
override fun CodecScope<ChatMessageSendPacket>.body(): ChatMessageSendPacket {
|
override fun CodecScope<ChatMessageSendPacket>.body(): ChatMessageSendPacket {
|
||||||
val mode = field(S8) { it.mode }
|
val mode = field(S8) { it.mode }
|
||||||
val target = field(Utf16LeNullTerminated) { it.target }
|
val target = field(Utf16LeNullTerminated) { it.target }
|
||||||
val message =
|
val message = if (mode.toInt() == 4) field(Utf16LeNullTerminated) { it.message ?: "" } else null
|
||||||
if (mode.toInt() == 4) field(Utf16LeNullTerminated) { it.message ?: "" } else null
|
|
||||||
return ChatMessageSendPacket(mode, target, message)
|
return ChatMessageSendPacket(mode, target, message)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
-56
@@ -1,56 +0,0 @@
|
|||||||
package de.fiereu.openmmo.net.game.packets
|
|
||||||
|
|
||||||
import de.fiereu.bytecodec.*
|
|
||||||
|
|
||||||
data class ContactAppearance(
|
|
||||||
val name: String,
|
|
||||||
val valueA: Byte,
|
|
||||||
val valueB: Int,
|
|
||||||
val kind: Byte,
|
|
||||||
val packedSlots: Byte,
|
|
||||||
val spriteData: List<Short>,
|
|
||||||
)
|
|
||||||
|
|
||||||
data class ContactRosterEntry(
|
|
||||||
val player: Long,
|
|
||||||
val value: Int,
|
|
||||||
val online: Boolean,
|
|
||||||
val appearance: ContactAppearance,
|
|
||||||
)
|
|
||||||
|
|
||||||
data class ContactRosterPacket(
|
|
||||||
val mode: Int,
|
|
||||||
val entries: List<ContactRosterEntry>,
|
|
||||||
)
|
|
||||||
|
|
||||||
private val ContactAppearanceCodec: Codec<ContactAppearance> =
|
|
||||||
object : PacketCodec<ContactAppearance>() {
|
|
||||||
override fun CodecScope<ContactAppearance>.body(): ContactAppearance {
|
|
||||||
val name = field(Utf16LeNullTerminated) { it.name }
|
|
||||||
val valueA = field(S8) { it.valueA }
|
|
||||||
val valueB = field(S32LE) { it.valueB }
|
|
||||||
val kind = field(S8) { it.kind }
|
|
||||||
val packedSlots = field(S8) { it.packedSlots }
|
|
||||||
val spriteData = field(S16LE.repeat(12)) { it.spriteData }
|
|
||||||
return ContactAppearance(name, valueA, valueB, kind, packedSlots, spriteData)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private val ContactRosterEntryCodec: Codec<ContactRosterEntry> =
|
|
||||||
object : PacketCodec<ContactRosterEntry>() {
|
|
||||||
override fun CodecScope<ContactRosterEntry>.body(): ContactRosterEntry {
|
|
||||||
val player = field(S64LE) { it.player }
|
|
||||||
val value = field(S32LE) { it.value }
|
|
||||||
val online = field(U8) { if (it.online) 1 else 0 } == 1
|
|
||||||
val appearance = field(ContactAppearanceCodec) { it.appearance }
|
|
||||||
return ContactRosterEntry(player, value, online, appearance)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
object ContactRosterPacketCodec : PacketCodec<ContactRosterPacket>() {
|
|
||||||
override fun CodecScope<ContactRosterPacket>.body(): ContactRosterPacket {
|
|
||||||
val mode = field(U8) { it.mode }
|
|
||||||
val entries = field(ContactRosterEntryCodec.listPrefixed(U8)) { it.entries }
|
|
||||||
return ContactRosterPacket(mode, entries)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+2
-4
@@ -49,8 +49,7 @@ data class CustomizeCharacterAppearancePacket(
|
|||||||
val paletteIndex: Byte,
|
val paletteIndex: Byte,
|
||||||
)
|
)
|
||||||
|
|
||||||
object CustomizeCharacterAppearancePacketCodec :
|
object CustomizeCharacterAppearancePacketCodec : PacketCodec<CustomizeCharacterAppearancePacket>() {
|
||||||
PacketCodec<CustomizeCharacterAppearancePacket>() {
|
|
||||||
override fun CodecScope<CustomizeCharacterAppearancePacket>.body():
|
override fun CodecScope<CustomizeCharacterAppearancePacket>.body():
|
||||||
CustomizeCharacterAppearancePacket {
|
CustomizeCharacterAppearancePacket {
|
||||||
val entityId = field(S64LE) { it.entityId }
|
val entityId = field(S64LE) { it.entityId }
|
||||||
@@ -59,7 +58,6 @@ object CustomizeCharacterAppearancePacketCodec :
|
|||||||
val moveSet = field(CreatureMovesetCodec) { it.moveSet }
|
val moveSet = field(CreatureMovesetCodec) { it.moveSet }
|
||||||
val paletteIndex = field(S8) { it.paletteIndex }
|
val paletteIndex = field(S8) { it.paletteIndex }
|
||||||
return CustomizeCharacterAppearancePacket(
|
return CustomizeCharacterAppearancePacket(
|
||||||
entityId, colorCategoryId, colorSlot, moveSet, paletteIndex
|
entityId, colorCategoryId, colorSlot, moveSet, paletteIndex)
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+3
-3
@@ -53,7 +53,8 @@ object EntityAppearancePatchPacketCodec : PacketCodec<EntityAppearancePatchPacke
|
|||||||
val flagsInt = flags.toInt()
|
val flagsInt = flags.toInt()
|
||||||
val direction = if (flagsInt and 1 != 0) field(S8) { it.direction!! } else null
|
val direction = if (flagsInt and 1 != 0) field(S8) { it.direction!! } else null
|
||||||
val animation = if (flagsInt and 2 != 0) field(S16LE) { it.animation!! } else null
|
val animation = if (flagsInt and 2 != 0) field(S16LE) { it.animation!! } else null
|
||||||
val appearance = if (flagsInt and 4 != 0) field(EntityAppearanceCodec) { it.appearance!! } else null
|
val appearance =
|
||||||
|
if (flagsInt and 4 != 0) field(EntityAppearanceCodec) { it.appearance!! } else null
|
||||||
val cosmetics =
|
val cosmetics =
|
||||||
if (flagsInt and 8 != 0) {
|
if (flagsInt and 8 != 0) {
|
||||||
val count = field(S8) { it.cosmetics!!.size.toByte() }.toInt()
|
val count = field(S8) { it.cosmetics!!.size.toByte() }.toInt()
|
||||||
@@ -64,7 +65,6 @@ object EntityAppearancePatchPacketCodec : PacketCodec<EntityAppearancePatchPacke
|
|||||||
}
|
}
|
||||||
} else null
|
} else null
|
||||||
return EntityAppearancePatchPacket(
|
return EntityAppearancePatchPacket(
|
||||||
entityId, spriteId, direction, animation, appearance, cosmetics
|
entityId, spriteId, direction, animation, appearance, cosmetics)
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+2
-1
@@ -112,7 +112,8 @@ private val EventOverlayStateCodec: Codec<EventOverlayStatePacket> =
|
|||||||
S16LE.write(buf, r.regionId)
|
S16LE.write(buf, r.regionId)
|
||||||
S16LE.write(buf, r.secondary)
|
S16LE.write(buf, r.secondary)
|
||||||
if (grid) {
|
if (grid) {
|
||||||
val points = r.gridPoints ?: throw MalformedPacketException("grid overlay region missing points")
|
val points =
|
||||||
|
r.gridPoints ?: throw MalformedPacketException("grid overlay region missing points")
|
||||||
U8.write(buf, points.size)
|
U8.write(buf, points.size)
|
||||||
for (p in points) {
|
for (p in points) {
|
||||||
S16LE.write(buf, p.x)
|
S16LE.write(buf, p.x)
|
||||||
|
|||||||
@@ -0,0 +1,40 @@
|
|||||||
|
package de.fiereu.openmmo.net.game.packets
|
||||||
|
|
||||||
|
import de.fiereu.bytecodec.*
|
||||||
|
|
||||||
|
data class FriendListEntry(
|
||||||
|
val player: Long,
|
||||||
|
val friendsSince: Int,
|
||||||
|
val online: Boolean,
|
||||||
|
val name: String,
|
||||||
|
val unk: Byte,
|
||||||
|
val lastSeen: Int,
|
||||||
|
val appearance: List<Short>,
|
||||||
|
)
|
||||||
|
|
||||||
|
data class FriendListPacket(
|
||||||
|
val mode: Int,
|
||||||
|
val entries: List<FriendListEntry>,
|
||||||
|
)
|
||||||
|
|
||||||
|
private val FriendListEntryCodec: Codec<FriendListEntry> =
|
||||||
|
object : PacketCodec<FriendListEntry>() {
|
||||||
|
override fun CodecScope<FriendListEntry>.body(): FriendListEntry {
|
||||||
|
val player = field(S64LE) { it.player }
|
||||||
|
val friendsSince = field(S32LE) { it.friendsSince }
|
||||||
|
val online = field(Bool) { it.online }
|
||||||
|
val name = field(Utf16LeNullTerminated) { it.name }
|
||||||
|
val unk = field(S8) { it.unk }
|
||||||
|
val lastSeen = field(S32LE) { it.lastSeen }
|
||||||
|
val appearance = field(S16LE.repeat(5)) { it.appearance }
|
||||||
|
return FriendListEntry(player, friendsSince, online, name, unk, lastSeen, appearance)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
object FriendListPacketCodec : PacketCodec<FriendListPacket>() {
|
||||||
|
override fun CodecScope<FriendListPacket>.body(): FriendListPacket {
|
||||||
|
val mode = field(U8) { it.mode }
|
||||||
|
val entries = field(FriendListEntryCodec.listPrefixed(U8)) { it.entries }
|
||||||
|
return FriendListPacket(mode, entries)
|
||||||
|
}
|
||||||
|
}
|
||||||
+3
-1
@@ -15,7 +15,9 @@ data class ReconnectHelloAuth(val entityId: Long, val sessionToken: ByteArray) :
|
|||||||
|
|
||||||
data class NewHelloAuth(val userId: Int, val sessionToken: ByteArray) : HelloAuthData() {
|
data class NewHelloAuth(val userId: Int, val sessionToken: ByteArray) : HelloAuthData() {
|
||||||
override fun equals(other: Any?): Boolean =
|
override fun equals(other: Any?): Boolean =
|
||||||
other is NewHelloAuth && userId == other.userId && sessionToken.contentEquals(other.sessionToken)
|
other is NewHelloAuth &&
|
||||||
|
userId == other.userId &&
|
||||||
|
sessionToken.contentEquals(other.sessionToken)
|
||||||
|
|
||||||
override fun hashCode(): Int = userId * 31 + sessionToken.contentHashCode()
|
override fun hashCode(): Int = userId * 31 + sessionToken.contentHashCode()
|
||||||
}
|
}
|
||||||
|
|||||||
+41
-8
@@ -88,10 +88,36 @@ private val GmCharacterSessionCodec: Codec<GmCharacterSession> =
|
|||||||
val statusCount = field(U8) { it.statusList.size }
|
val statusCount = field(U8) { it.statusList.size }
|
||||||
val statusList = (0 until statusCount).map { i -> field(S8) { it.statusList[i] } }
|
val statusList = (0 until statusCount).map { i -> field(S8) { it.statusList[i] } }
|
||||||
return GmCharacterSession(
|
return GmCharacterSession(
|
||||||
entityId, name, secondaryName, intA, byteA, intB, longA, intC, intD, intE, shortA, intF,
|
entityId,
|
||||||
byteB, byteC, byteD, shortB, byteE, intG, byteF, byteG, byteH, byteI, byteJ, shortC,
|
name,
|
||||||
shortD, shortE, statusByte, shortF, shortG, statusList
|
secondaryName,
|
||||||
)
|
intA,
|
||||||
|
byteA,
|
||||||
|
intB,
|
||||||
|
longA,
|
||||||
|
intC,
|
||||||
|
intD,
|
||||||
|
intE,
|
||||||
|
shortA,
|
||||||
|
intF,
|
||||||
|
byteB,
|
||||||
|
byteC,
|
||||||
|
byteD,
|
||||||
|
shortB,
|
||||||
|
byteE,
|
||||||
|
intG,
|
||||||
|
byteF,
|
||||||
|
byteG,
|
||||||
|
byteH,
|
||||||
|
byteI,
|
||||||
|
byteJ,
|
||||||
|
shortC,
|
||||||
|
shortD,
|
||||||
|
shortE,
|
||||||
|
statusByte,
|
||||||
|
shortF,
|
||||||
|
shortG,
|
||||||
|
statusList)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -157,9 +183,15 @@ object GmPlayerLookupPacketCodec : PacketCodec<GmPlayerLookupPacket>() {
|
|||||||
val stringB = field(Utf16LeNullTerminated) { it.account!!.stringB }
|
val stringB = field(Utf16LeNullTerminated) { it.account!!.stringB }
|
||||||
val stringC = field(Utf16LeNullTerminated) { it.account!!.stringC }
|
val stringC = field(Utf16LeNullTerminated) { it.account!!.stringC }
|
||||||
GmAccountInfo(
|
GmAccountInfo(
|
||||||
rankExtraA, rankExtraB, rankExtraC, ipAddress, playtime, accountId, stringA, stringB,
|
rankExtraA,
|
||||||
stringC
|
rankExtraB,
|
||||||
)
|
rankExtraC,
|
||||||
|
ipAddress,
|
||||||
|
playtime,
|
||||||
|
accountId,
|
||||||
|
stringA,
|
||||||
|
stringB,
|
||||||
|
stringC)
|
||||||
} else null
|
} else null
|
||||||
val extraByte = field(U8) { if (it.extra != null) 1 else 0 }
|
val extraByte = field(U8) { if (it.extra != null) 1 else 0 }
|
||||||
val extra =
|
val extra =
|
||||||
@@ -169,7 +201,8 @@ object GmPlayerLookupPacketCodec : PacketCodec<GmPlayerLookupPacket>() {
|
|||||||
GmExtraDetail(value, text)
|
GmExtraDetail(value, text)
|
||||||
} else null
|
} else null
|
||||||
val charCount = field(U16LE) { it.characters.size }
|
val charCount = field(U16LE) { it.characters.size }
|
||||||
val characters = (0 until charCount).map { i -> field(GmCharacterListingCodec) { it.characters[i] } }
|
val characters =
|
||||||
|
(0 until charCount).map { i -> field(GmCharacterListingCodec) { it.characters[i] } }
|
||||||
return GmPlayerLookupPacket(true, session, rank, account, extra, characters)
|
return GmPlayerLookupPacket(true, session, rank, account, extra, characters)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+1
-3
@@ -47,8 +47,6 @@ object GtlCreateListingPacketCodec : PacketCodec<GtlCreateListingPacket>() {
|
|||||||
val itemKind = field(S8) { it.itemKind }
|
val itemKind = field(S8) { it.itemKind }
|
||||||
val priceShort = field(S16LE) { it.priceShort }
|
val priceShort = field(S16LE) { it.priceShort }
|
||||||
val filterCriteria = field(FilterCriteriaBytes) { it.filterCriteria }
|
val filterCriteria = field(FilterCriteriaBytes) { it.filterCriteria }
|
||||||
return GtlCreateListingPacket(
|
return GtlCreateListingPacket(categoryIndex, listingCount, itemKind, priceShort, filterCriteria)
|
||||||
categoryIndex, listingCount, itemKind, priceShort, filterCriteria
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+1
-2
@@ -39,7 +39,6 @@ object GtlSellPokemonListingPacketCodec : PacketCodec<GtlSellPokemonListingPacke
|
|||||||
val criteriaCount = field(U8) { it.criteriaCount }
|
val criteriaCount = field(U8) { it.criteriaCount }
|
||||||
val criteriaData = field(RemainingBytes) { it.criteriaData }
|
val criteriaData = field(RemainingBytes) { it.criteriaData }
|
||||||
return GtlSellPokemonListingPacket(
|
return GtlSellPokemonListingPacket(
|
||||||
listingType, entryKindId, listingCategory, itemTypeId, criteriaCount, criteriaData
|
listingType, entryKindId, listingCategory, itemTypeId, criteriaCount, criteriaData)
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+2
-1
@@ -38,7 +38,8 @@ private object GuildProfileDataCodec : PacketCodec<GuildProfileData>() {
|
|||||||
val value5 = field(S16LE, GuildProfileData::value5)
|
val value5 = field(S16LE, GuildProfileData::value5)
|
||||||
val value6 = field(S32LE, GuildProfileData::value6)
|
val value6 = field(S32LE, GuildProfileData::value6)
|
||||||
val rankCount = field(S8) { it.rankNames.size.toByte() }
|
val rankCount = field(S8) { it.rankNames.size.toByte() }
|
||||||
val rankNames = List(rankCount.toInt()) { i -> field(Utf16LeNullTerminated) { it.rankNames[i] } }
|
val rankNames =
|
||||||
|
List(rankCount.toInt()) { i -> field(Utf16LeNullTerminated) { it.rankNames[i] } }
|
||||||
return GuildProfileData(
|
return GuildProfileData(
|
||||||
guildId,
|
guildId,
|
||||||
name,
|
name,
|
||||||
|
|||||||
+2
-1
@@ -33,7 +33,8 @@ object GuildProfileSyncPacketCodec : PacketCodec<GuildProfileSyncPacket>() {
|
|||||||
val value5 = field(S16LE, GuildProfileSyncPacket::value5)
|
val value5 = field(S16LE, GuildProfileSyncPacket::value5)
|
||||||
val value6 = field(S32LE, GuildProfileSyncPacket::value6)
|
val value6 = field(S32LE, GuildProfileSyncPacket::value6)
|
||||||
val rankCount = field(S8) { it.rankNames.size.toByte() }
|
val rankCount = field(S8) { it.rankNames.size.toByte() }
|
||||||
val rankNames = List(rankCount.toInt()) { i -> field(Utf16LeNullTerminated) { it.rankNames[i] } }
|
val rankNames =
|
||||||
|
List(rankCount.toInt()) { i -> field(Utf16LeNullTerminated) { it.rankNames[i] } }
|
||||||
return GuildProfileSyncPacket(
|
return GuildProfileSyncPacket(
|
||||||
guildId,
|
guildId,
|
||||||
name,
|
name,
|
||||||
|
|||||||
+2
-1
@@ -43,7 +43,8 @@ private val HighScoreEntryCodec: Codec<HighScoreEntry> =
|
|||||||
val rank = field(S32LE) { it.rank }
|
val rank = field(S32LE) { it.rank }
|
||||||
val score = field(S32LE) { it.score }
|
val score = field(S32LE) { it.score }
|
||||||
val count = field(U8) { it.appearances.size }
|
val count = field(U8) { it.appearances.size }
|
||||||
val appearances = (0 until count).map { i -> field(HighScoreAppearanceCodec) { it.appearances[i] } }
|
val appearances =
|
||||||
|
(0 until count).map { i -> field(HighScoreAppearanceCodec) { it.appearances[i] } }
|
||||||
return HighScoreEntry(entityId, rank, score, appearances)
|
return HighScoreEntry(entityId, rank, score, appearances)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-3
@@ -47,8 +47,6 @@ object ListWindowPagePacketCodec : PacketCodec<ListWindowPagePacket>() {
|
|||||||
val headerB = field(S8) { it.headerB }
|
val headerB = field(S8) { it.headerB }
|
||||||
val headerC = field(S8) { it.headerC }
|
val headerC = field(S8) { it.headerC }
|
||||||
val rows = field(ListWindowRowCodec.listPrefixed(U16LE)) { it.rows }
|
val rows = field(ListWindowRowCodec.listPrefixed(U16LE)) { it.rows }
|
||||||
return ListWindowPagePacket(
|
return ListWindowPagePacket(windowId, firstPage, lastPage, headerA, headerB, headerC, rows)
|
||||||
windowId, firstPage, lastPage, headerA, headerB, headerC, rows
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+2
-1
@@ -52,7 +52,8 @@ object LocalCharacterDeltaPacketCodec : PacketCodec<LocalCharacterDeltaPacket>()
|
|||||||
value64a = null
|
value64a = null
|
||||||
value64b = null
|
value64b = null
|
||||||
}
|
}
|
||||||
val statusConditions = if (m and 128 != 0) field(S8.listPrefixed(U8)) { it.statusConditions!! } else null
|
val statusConditions =
|
||||||
|
if (m and 128 != 0) field(S8.listPrefixed(U8)) { it.statusConditions!! } else null
|
||||||
val value256 = if (m and 256 != 0) field(S8) { it.value256!! } else null
|
val value256 = if (m and 256 != 0) field(S8) { it.value256!! } else null
|
||||||
return LocalCharacterDeltaPacket(
|
return LocalCharacterDeltaPacket(
|
||||||
mask = mask,
|
mask = mask,
|
||||||
|
|||||||
+1
-2
@@ -26,7 +26,6 @@ object MapTileObjectSlotSetPacketCodec : PacketCodec<MapTileObjectSlotSetPacket>
|
|||||||
val objectZ = if (present) field(S8) { it.objectZ!! } else null
|
val objectZ = if (present) field(S8) { it.objectZ!! } else null
|
||||||
val relative = if (present) field(U8) { if (it.relative == true) 1 else 0 } == 1 else null
|
val relative = if (present) field(U8) { if (it.relative == true) 1 else 0 } == 1 else null
|
||||||
return MapTileObjectSlotSetPacket(
|
return MapTileObjectSlotSetPacket(
|
||||||
blockX, blockY, blockZ, slot, present, objectX, objectY, objectZ, relative
|
blockX, blockY, blockZ, slot, present, objectX, objectY, objectZ, relative)
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+1
-2
@@ -42,7 +42,6 @@ object MarketBoardPagePacketCodec : PacketCodec<MarketBoardPagePacket>() {
|
|||||||
entries.add(MarketBoardEntry(itemId, valueA, valueB, rank))
|
entries.add(MarketBoardEntry(itemId, valueA, valueB, rank))
|
||||||
}
|
}
|
||||||
return MarketBoardPagePacket(
|
return MarketBoardPagePacket(
|
||||||
hasData, page, category, total, expiryOffsetMillis, count, categoryRanked, entries
|
hasData, page, category, total, expiryOffsetMillis, count, categoryRanked, entries)
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -34,7 +34,6 @@ object NpcSpawnPacketCodec : PacketCodec<NpcSpawnPacket>() {
|
|||||||
val facing = field(U8) { it.facing }
|
val facing = field(U8) { it.facing }
|
||||||
val unk6 = field(U16LE) { it.unk6 }
|
val unk6 = field(U16LE) { it.unk6 }
|
||||||
return NpcSpawnPacket(
|
return NpcSpawnPacket(
|
||||||
entityId, unk1, unk2, unk3, unk4, regionId, bankId, mapId, x, y, facing, unk5, unk6
|
entityId, unk1, unk2, unk3, unk4, regionId, bankId, mapId, x, y, facing, unk5, unk6)
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+1
-2
@@ -16,7 +16,6 @@ object RequestConfirmationPromptPacketCodec : PacketCodec<RequestConfirmationPro
|
|||||||
val requestTimeoutSeconds = if (visible) field(U16LE) { it.requestTimeoutSeconds!! } else null
|
val requestTimeoutSeconds = if (visible) field(U16LE) { it.requestTimeoutSeconds!! } else null
|
||||||
val responseTimeoutSeconds = if (visible) field(U16LE) { it.responseTimeoutSeconds!! } else null
|
val responseTimeoutSeconds = if (visible) field(U16LE) { it.responseTimeoutSeconds!! } else null
|
||||||
return RequestConfirmationPromptPacket(
|
return RequestConfirmationPromptPacket(
|
||||||
visible, entityId, requestTimeoutSeconds, responseTimeoutSeconds
|
visible, entityId, requestTimeoutSeconds, responseTimeoutSeconds)
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+1
-2
@@ -40,8 +40,7 @@ private val ServerMessageArgCodec: Codec<ServerMessageArg> =
|
|||||||
else -> shortValues = field(S16LE.listPrefixed(U8)) { it.shortValues!! }
|
else -> shortValues = field(S16LE.listPrefixed(U8)) { it.shortValues!! }
|
||||||
}
|
}
|
||||||
return ServerMessageArg(
|
return ServerMessageArg(
|
||||||
argId, type, hasExtra, extra, longValue, intValue, stringValue, shortValues
|
argId, type, hasExtra, extra, longValue, intValue, stringValue, shortValues)
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-5
@@ -24,16 +24,13 @@ private val ColorPaletteCodec: Codec<List<Short>> =
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
object SetBattleMonsterAppearancePacketCodec :
|
object SetBattleMonsterAppearancePacketCodec : PacketCodec<SetBattleMonsterAppearancePacket>() {
|
||||||
PacketCodec<SetBattleMonsterAppearancePacket>() {
|
|
||||||
override fun CodecScope<SetBattleMonsterAppearancePacket>.body():
|
override fun CodecScope<SetBattleMonsterAppearancePacket>.body():
|
||||||
SetBattleMonsterAppearancePacket {
|
SetBattleMonsterAppearancePacket {
|
||||||
val partySlot = field(S16LE) { it.partySlot }
|
val partySlot = field(S16LE) { it.partySlot }
|
||||||
val pokemonEntityId = field(S64LE) { it.pokemonEntityId }
|
val pokemonEntityId = field(S64LE) { it.pokemonEntityId }
|
||||||
val shininessType = field(S8) { it.shininessType }
|
val shininessType = field(S8) { it.shininessType }
|
||||||
val colorPalette = field(ColorPaletteCodec) { it.colorPalette }
|
val colorPalette = field(ColorPaletteCodec) { it.colorPalette }
|
||||||
return SetBattleMonsterAppearancePacket(
|
return SetBattleMonsterAppearancePacket(partySlot, pokemonEntityId, shininessType, colorPalette)
|
||||||
partySlot, pokemonEntityId, shininessType, colorPalette
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
-14
@@ -1,14 +0,0 @@
|
|||||||
package de.fiereu.openmmo.net.game.packets
|
|
||||||
|
|
||||||
import de.fiereu.bytecodec.CodecScope
|
|
||||||
import de.fiereu.bytecodec.PacketCodec
|
|
||||||
import de.fiereu.bytecodec.Utf16LeNullTerminated
|
|
||||||
|
|
||||||
data class SetPlayerTitlePacket(val titleText: String)
|
|
||||||
|
|
||||||
object SetPlayerTitlePacketCodec : PacketCodec<SetPlayerTitlePacket>() {
|
|
||||||
override fun CodecScope<SetPlayerTitlePacket>.body(): SetPlayerTitlePacket {
|
|
||||||
val titleText = field(Utf16LeNullTerminated) { it.titleText }
|
|
||||||
return SetPlayerTitlePacket(titleText)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+2
-4
@@ -11,10 +11,8 @@ data class SocialActionOutcomePacket(
|
|||||||
object SocialActionOutcomePacketCodec : PacketCodec<SocialActionOutcomePacket>() {
|
object SocialActionOutcomePacketCodec : PacketCodec<SocialActionOutcomePacket>() {
|
||||||
override fun CodecScope<SocialActionOutcomePacket>.body(): SocialActionOutcomePacket {
|
override fun CodecScope<SocialActionOutcomePacket>.body(): SocialActionOutcomePacket {
|
||||||
val action = field(U8) { it.action }
|
val action = field(U8) { it.action }
|
||||||
val entityId: Long? =
|
val entityId: Long? = if (resolveKind(action) == 1) field(S64LE) { it.entityId!! } else null
|
||||||
if (resolveKind(action) == 1) field(S64LE) { it.entityId!! } else null
|
val value: Short? = if (resolveKind(action) == 2) field(S16LE) { it.value!! } else null
|
||||||
val value: Short? =
|
|
||||||
if (resolveKind(action) == 2) field(S16LE) { it.value!! } else null
|
|
||||||
return SocialActionOutcomePacket(action, entityId, value)
|
return SocialActionOutcomePacket(action, entityId, value)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-2
@@ -16,8 +16,7 @@ object SpatialGroupInsertPacketCodec : PacketCodec<SpatialGroupInsertPacket>() {
|
|||||||
val entityId = field(S64LE) { it.entityId }
|
val entityId = field(S64LE) { it.entityId }
|
||||||
val value = field(S16LE) { it.value }
|
val value = field(S16LE) { it.value }
|
||||||
val extraCoordPresent = false
|
val extraCoordPresent = false
|
||||||
val extraValue: Short? =
|
val extraValue: Short? = if (extraCoordPresent) field(S16LE) { it.extraValue ?: 0 } else null
|
||||||
if (extraCoordPresent) field(S16LE) { it.extraValue ?: 0 } else null
|
|
||||||
return SpatialGroupInsertPacket(group, entityId, value, extraCoordPresent, extraValue)
|
return SpatialGroupInsertPacket(group, entityId, value, extraCoordPresent, extraValue)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+3
-4
@@ -11,7 +11,8 @@ data class StorageBoxFilterPacket(
|
|||||||
other is StorageBoxFilterPacket &&
|
other is StorageBoxFilterPacket &&
|
||||||
listTypeIndex == other.listTypeIndex &&
|
listTypeIndex == other.listTypeIndex &&
|
||||||
boxName == other.boxName &&
|
boxName == other.boxName &&
|
||||||
(cookieData?.contentEquals(other.cookieData ?: ByteArray(0)) ?: (other.cookieData == null))
|
(cookieData?.contentEquals(other.cookieData ?: ByteArray(0))
|
||||||
|
?: (other.cookieData == null))
|
||||||
|
|
||||||
override fun hashCode(): Int {
|
override fun hashCode(): Int {
|
||||||
var r = listTypeIndex?.hashCode() ?: 0
|
var r = listTypeIndex?.hashCode() ?: 0
|
||||||
@@ -26,9 +27,7 @@ private val CookieBytes = bytesPrefixed(U8)
|
|||||||
object StorageBoxFilterPacketCodec : PacketCodec<StorageBoxFilterPacket>() {
|
object StorageBoxFilterPacketCodec : PacketCodec<StorageBoxFilterPacket>() {
|
||||||
override fun CodecScope<StorageBoxFilterPacket>.body(): StorageBoxFilterPacket {
|
override fun CodecScope<StorageBoxFilterPacket>.body(): StorageBoxFilterPacket {
|
||||||
val typeFlags =
|
val typeFlags =
|
||||||
field(U8) {
|
field(U8) { (if (it.boxName != null) 1 else 0) or (if (it.cookieData != null) 2 else 0) }
|
||||||
(if (it.boxName != null) 1 else 0) or (if (it.cookieData != null) 2 else 0)
|
|
||||||
}
|
|
||||||
val listTypeIndex: Byte? =
|
val listTypeIndex: Byte? =
|
||||||
if (typeFlags and 1 != 0) field(S8) { it.listTypeIndex ?: 0 } else null
|
if (typeFlags and 1 != 0) field(S8) { it.listTypeIndex ?: 0 } else null
|
||||||
val boxName: String? =
|
val boxName: String? =
|
||||||
|
|||||||
+1
-3
@@ -35,9 +35,7 @@ object StorageContextWindowPacketCodec : PacketCodec<StorageContextWindowPacket>
|
|||||||
val quantity = field(S8) { it.items[i].quantity }
|
val quantity = field(S8) { it.items[i].quantity }
|
||||||
val ball = field(S8) { it.items[i].ball }
|
val ball = field(S8) { it.items[i].ball }
|
||||||
val location = field(S8) { it.items[i].location }
|
val location = field(S8) { it.items[i].location }
|
||||||
items.add(
|
items.add(StorageBoxItem(slot, valueA, valueB, valueC, valueD, quantity, ball, location))
|
||||||
StorageBoxItem(slot, valueA, valueB, valueC, valueD, quantity, ball, location)
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
return StorageContextWindowPacket(kind, items)
|
return StorageContextWindowPacket(kind, items)
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-2
@@ -50,7 +50,6 @@ object StorageInventoryPacketCodec : PacketCodec<StorageInventoryPacket>() {
|
|||||||
val listC = field(StorageQuantityCodec.listPrefixed(U8)) { it.listC }
|
val listC = field(StorageQuantityCodec.listPrefixed(U8)) { it.listC }
|
||||||
val listD = field(StorageQuantityCodec.listPrefixed(U8)) { it.listD }
|
val listD = field(StorageQuantityCodec.listPrefixed(U8)) { it.listD }
|
||||||
return StorageInventoryPacket(
|
return StorageInventoryPacket(
|
||||||
header, totalA, totalB, valueC, usedA, usedB, listA, listB, listC, listD
|
header, totalA, totalB, valueC, usedA, usedB, listA, listB, listC, listD)
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+1
-2
@@ -56,8 +56,7 @@ object TeamPreviewLeadSubmitPacketCodec : PacketCodec<TeamPreviewLeadSubmitPacke
|
|||||||
val pokemonEntityId = field(S64LE) { it.pokemonEntityId }
|
val pokemonEntityId = field(S64LE) { it.pokemonEntityId }
|
||||||
val battleSlot = field(S8) { it.battleSlot }
|
val battleSlot = field(S8) { it.battleSlot }
|
||||||
val present = field(U8) { if (it.appearance != null) 1 else 0 }
|
val present = field(U8) { if (it.appearance != null) 1 else 0 }
|
||||||
val appearance =
|
val appearance = if (present != 0) field(AppearanceCodec) { it.appearance!! } else null
|
||||||
if (present != 0) field(AppearanceCodec) { it.appearance!! } else null
|
|
||||||
val teamSide = field(S16LE) { it.teamSide }
|
val teamSide = field(S16LE) { it.teamSide }
|
||||||
val reserved = field(S8) { it.reserved }
|
val reserved = field(S8) { it.reserved }
|
||||||
return TeamPreviewLeadSubmitPacket(
|
return TeamPreviewLeadSubmitPacket(
|
||||||
|
|||||||
+1
-3
@@ -7,9 +7,7 @@ data class TypedBinaryDataPacket(
|
|||||||
val data: ByteArray,
|
val data: ByteArray,
|
||||||
) {
|
) {
|
||||||
override fun equals(other: Any?): Boolean =
|
override fun equals(other: Any?): Boolean =
|
||||||
other is TypedBinaryDataPacket &&
|
other is TypedBinaryDataPacket && dataType == other.dataType && data.contentEquals(other.data)
|
||||||
dataType == other.dataType &&
|
|
||||||
data.contentEquals(other.data)
|
|
||||||
|
|
||||||
override fun hashCode(): Int = dataType * 31 + data.contentHashCode()
|
override fun hashCode(): Int = dataType * 31 + data.contentHashCode()
|
||||||
}
|
}
|
||||||
|
|||||||
+6
-4
@@ -28,16 +28,18 @@ private val WorldNoticeArgCodec: Codec<WorldNoticeArg> =
|
|||||||
when (type) {
|
when (type) {
|
||||||
28 -> {}
|
28 -> {}
|
||||||
30 -> longValue = field(S64LE) { it.longValue!! }
|
30 -> longValue = field(S64LE) { it.longValue!! }
|
||||||
9, 10, 17 -> intValue = field(S32LE) { it.intValue!! }
|
9,
|
||||||
5, 18 -> stringValue = field(Utf16LeNullTerminated) { it.stringValue!! }
|
10,
|
||||||
|
17 -> intValue = field(S32LE) { it.intValue!! }
|
||||||
|
5,
|
||||||
|
18 -> stringValue = field(Utf16LeNullTerminated) { it.stringValue!! }
|
||||||
else -> {
|
else -> {
|
||||||
val count = field(U8) { it.shortValues!!.size }
|
val count = field(U8) { it.shortValues!!.size }
|
||||||
shortValues = (0 until count).map { i -> field(S16LE) { it.shortValues!![i] } }
|
shortValues = (0 until count).map { i -> field(S16LE) { it.shortValues!![i] } }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return WorldNoticeArg(
|
return WorldNoticeArg(
|
||||||
argId, type, hasExtra, extra, longValue, intValue, stringValue, shortValues
|
argId, type, hasExtra, extra, longValue, intValue, stringValue, shortValues)
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-1
@@ -9,7 +9,8 @@ data class WorldObjectInstanceDespawnPacket(
|
|||||||
)
|
)
|
||||||
|
|
||||||
object WorldObjectInstanceDespawnPacketCodec : PacketCodec<WorldObjectInstanceDespawnPacket>() {
|
object WorldObjectInstanceDespawnPacketCodec : PacketCodec<WorldObjectInstanceDespawnPacket>() {
|
||||||
override fun CodecScope<WorldObjectInstanceDespawnPacket>.body(): WorldObjectInstanceDespawnPacket {
|
override fun CodecScope<WorldObjectInstanceDespawnPacket>.body():
|
||||||
|
WorldObjectInstanceDespawnPacket {
|
||||||
val entityId = field(S64LE) { it.entityId }
|
val entityId = field(S64LE) { it.entityId }
|
||||||
return WorldObjectInstanceDespawnPacket(entityId)
|
return WorldObjectInstanceDespawnPacket(entityId)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,44 @@
|
|||||||
|
package de.fiereu.openmmo.net.game
|
||||||
|
|
||||||
|
import de.fiereu.bytecodec.test.decodeBytes
|
||||||
|
import de.fiereu.bytecodec.test.encodeToBytes
|
||||||
|
import de.fiereu.openmmo.net.game.packets.FriendListEntry
|
||||||
|
import de.fiereu.openmmo.net.game.packets.FriendListPacket
|
||||||
|
import de.fiereu.openmmo.net.game.packets.FriendListPacketCodec
|
||||||
|
import io.kotest.core.spec.style.FunSpec
|
||||||
|
import io.kotest.matchers.shouldBe
|
||||||
|
|
||||||
|
class FriendListPacketTest :
|
||||||
|
FunSpec({
|
||||||
|
test("roundtrips entries with mixed online state and variable-length names") {
|
||||||
|
val pkt =
|
||||||
|
FriendListPacket(
|
||||||
|
mode = 0,
|
||||||
|
entries =
|
||||||
|
listOf(
|
||||||
|
FriendListEntry(
|
||||||
|
player = 0x0102030405069000L,
|
||||||
|
friendsSince = 1_600_000_000,
|
||||||
|
online = false,
|
||||||
|
name = "Alpha",
|
||||||
|
unk = 0,
|
||||||
|
lastSeen = 1_700_000_000,
|
||||||
|
appearance = listOf(1, 2, 3, 4, 5),
|
||||||
|
),
|
||||||
|
FriendListEntry(
|
||||||
|
player = 0xA7L,
|
||||||
|
friendsSince = 1_650_000_000,
|
||||||
|
online = true,
|
||||||
|
name = "BravoBravoBravo",
|
||||||
|
unk = 0,
|
||||||
|
lastSeen = 1_710_000_000,
|
||||||
|
appearance = listOf(0, 0, 0, 0, 0),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
val decoded = FriendListPacketCodec.decodeBytes(FriendListPacketCodec.encodeToBytes(pkt))
|
||||||
|
decoded shouldBe pkt
|
||||||
|
decoded.entries.map { it.name } shouldBe listOf("Alpha", "BravoBravoBravo")
|
||||||
|
decoded.entries.map { it.online } shouldBe listOf(false, true)
|
||||||
|
}
|
||||||
|
})
|
||||||
@@ -11,13 +11,14 @@ import de.fiereu.openmmo.net.game.packets.LoadMapPacket
|
|||||||
import de.fiereu.openmmo.net.game.packets.NullPacket
|
import de.fiereu.openmmo.net.game.packets.NullPacket
|
||||||
import de.fiereu.openmmo.net.game.packets.TokenPayloadPacket
|
import de.fiereu.openmmo.net.game.packets.TokenPayloadPacket
|
||||||
import io.kotest.core.spec.style.FunSpec
|
import io.kotest.core.spec.style.FunSpec
|
||||||
|
import io.kotest.matchers.collections.shouldContainAll
|
||||||
import io.kotest.matchers.shouldBe
|
import io.kotest.matchers.shouldBe
|
||||||
|
|
||||||
class GameProtocolTest :
|
class GameProtocolTest :
|
||||||
FunSpec({
|
FunSpec({
|
||||||
test("at least one registration per known opcode") {
|
test("at least one registration per known opcode") {
|
||||||
val opcodes = GameProtocol.registrations.map { it.opcode }.toSet()
|
val opcodes = GameProtocol.registrations.map { it.opcode }.toSet()
|
||||||
opcodes shouldBe
|
opcodes shouldContainAll
|
||||||
setOf(
|
setOf(
|
||||||
0x01u.toUByte(),
|
0x01u.toUByte(),
|
||||||
0x02u.toUByte(),
|
0x02u.toUByte(),
|
||||||
|
|||||||
@@ -30,8 +30,8 @@ class GameServer
|
|||||||
@Inject
|
@Inject
|
||||||
constructor(
|
constructor(
|
||||||
private val config: GameServerConfig,
|
private val config: GameServerConfig,
|
||||||
@Named("boss") private val bossGroup: EventLoopGroup,
|
@param:Named("boss") private val bossGroup: EventLoopGroup,
|
||||||
@Named("worker") private val workerGroup: EventLoopGroup,
|
@param:Named("worker") private val workerGroup: EventLoopGroup,
|
||||||
private val rootKey: ECPrivateKey,
|
private val rootKey: ECPrivateKey,
|
||||||
private val handlerProvider: Provider<GameAppHandler>,
|
private val handlerProvider: Provider<GameAppHandler>,
|
||||||
private val sessionRegistry: SessionRegistry,
|
private val sessionRegistry: SessionRegistry,
|
||||||
|
|||||||
@@ -6,24 +6,32 @@ import de.fiereu.network.coroutines.CoroutineProtocolHandler
|
|||||||
import de.fiereu.openmmo.common.enums.ChatType
|
import de.fiereu.openmmo.common.enums.ChatType
|
||||||
import de.fiereu.openmmo.common.enums.Language
|
import de.fiereu.openmmo.common.enums.Language
|
||||||
import de.fiereu.openmmo.net.game.GameProtocol
|
import de.fiereu.openmmo.net.game.GameProtocol
|
||||||
|
import de.fiereu.openmmo.net.game.packets.AddFriendPacket
|
||||||
|
import de.fiereu.openmmo.net.game.packets.BlockPlayerPacket
|
||||||
|
import de.fiereu.openmmo.net.game.packets.CancelSocialInteractionPacket
|
||||||
import de.fiereu.openmmo.net.game.packets.ChatMessagePacket
|
import de.fiereu.openmmo.net.game.packets.ChatMessagePacket
|
||||||
import de.fiereu.openmmo.net.game.packets.CreateCharacterPacket
|
import de.fiereu.openmmo.net.game.packets.CreateCharacterPacket
|
||||||
import de.fiereu.openmmo.net.game.packets.DialogChoicePacket
|
import de.fiereu.openmmo.net.game.packets.DialogChoicePacket
|
||||||
import de.fiereu.openmmo.net.game.packets.EntityInteractPacket
|
import de.fiereu.openmmo.net.game.packets.EntityInteractPacket
|
||||||
import de.fiereu.openmmo.net.game.packets.EntityLeavePacket
|
import de.fiereu.openmmo.net.game.packets.EntityLeavePacket
|
||||||
import de.fiereu.openmmo.net.game.packets.FaceDirectionPacket
|
import de.fiereu.openmmo.net.game.packets.FaceDirectionPacket
|
||||||
|
import de.fiereu.openmmo.net.game.packets.FriendProfileRequestPacket
|
||||||
import de.fiereu.openmmo.net.game.packets.InteractiveResponsePacket
|
import de.fiereu.openmmo.net.game.packets.InteractiveResponsePacket
|
||||||
import de.fiereu.openmmo.net.game.packets.JoinPacket
|
import de.fiereu.openmmo.net.game.packets.JoinPacket
|
||||||
import de.fiereu.openmmo.net.game.packets.KeepAlivePacket
|
import de.fiereu.openmmo.net.game.packets.KeepAlivePacket
|
||||||
import de.fiereu.openmmo.net.game.packets.MovementPacket
|
import de.fiereu.openmmo.net.game.packets.MovementPacket
|
||||||
|
import de.fiereu.openmmo.net.game.packets.RemoveFriendPacket
|
||||||
import de.fiereu.openmmo.net.game.packets.RequestCharactersPacket
|
import de.fiereu.openmmo.net.game.packets.RequestCharactersPacket
|
||||||
import de.fiereu.openmmo.net.game.packets.RequestPlayerPacket
|
import de.fiereu.openmmo.net.game.packets.RequestPlayerPacket
|
||||||
|
import de.fiereu.openmmo.net.game.packets.RequestSocialProfilePacket
|
||||||
import de.fiereu.openmmo.net.game.packets.SelectCharacterPacket
|
import de.fiereu.openmmo.net.game.packets.SelectCharacterPacket
|
||||||
|
import de.fiereu.openmmo.net.game.packets.UnblockPlayerPacket
|
||||||
import de.fiereu.openmmo.server.game.services.DialogService
|
import de.fiereu.openmmo.server.game.services.DialogService
|
||||||
import de.fiereu.openmmo.server.game.services.InteractionService
|
import de.fiereu.openmmo.server.game.services.InteractionService
|
||||||
import de.fiereu.openmmo.server.game.services.LoginService
|
import de.fiereu.openmmo.server.game.services.LoginService
|
||||||
import de.fiereu.openmmo.server.game.services.MovementService
|
import de.fiereu.openmmo.server.game.services.MovementService
|
||||||
import de.fiereu.openmmo.server.game.services.MultiplayerService
|
import de.fiereu.openmmo.server.game.services.MultiplayerService
|
||||||
|
import de.fiereu.openmmo.server.game.services.SocialService
|
||||||
import de.fiereu.openmmo.server.game.session.PLAYER_STATE
|
import de.fiereu.openmmo.server.game.session.PLAYER_STATE
|
||||||
import de.fiereu.openmmo.server.game.session.SessionRegistry
|
import de.fiereu.openmmo.server.game.session.SessionRegistry
|
||||||
import de.fiereu.openmmo.server.game.storage.CharacterStore
|
import de.fiereu.openmmo.server.game.storage.CharacterStore
|
||||||
@@ -41,6 +49,7 @@ constructor(
|
|||||||
private val dialogService: DialogService,
|
private val dialogService: DialogService,
|
||||||
private val interactionService: InteractionService,
|
private val interactionService: InteractionService,
|
||||||
private val multiplayerService: MultiplayerService,
|
private val multiplayerService: MultiplayerService,
|
||||||
|
private val socialService: SocialService,
|
||||||
private val sessionRegistry: SessionRegistry,
|
private val sessionRegistry: SessionRegistry,
|
||||||
private val characterStore: CharacterStore,
|
private val characterStore: CharacterStore,
|
||||||
scope: CoroutineScope,
|
scope: CoroutineScope,
|
||||||
@@ -60,6 +69,14 @@ constructor(
|
|||||||
onSuspend<InteractiveResponsePacket> { event -> dialogService.onInteractive(event) }
|
onSuspend<InteractiveResponsePacket> { event -> dialogService.onInteractive(event) }
|
||||||
onSuspend<DialogChoicePacket> { event -> dialogService.onDialogChoice(event) }
|
onSuspend<DialogChoicePacket> { event -> dialogService.onDialogChoice(event) }
|
||||||
|
|
||||||
|
on<AddFriendPacket> { event -> socialService.onAddFriend(event) }
|
||||||
|
on<RemoveFriendPacket> { event -> socialService.onRemoveFriend(event) }
|
||||||
|
on<BlockPlayerPacket> { event -> socialService.onBlockPlayer(event) }
|
||||||
|
on<UnblockPlayerPacket> { event -> socialService.onUnblockPlayer(event) }
|
||||||
|
on<FriendProfileRequestPacket> { event -> socialService.onFriendProfileRequest(event) }
|
||||||
|
on<RequestSocialProfilePacket> { event -> socialService.onRequestSocialProfile(event) }
|
||||||
|
on<CancelSocialInteractionPacket> { event -> socialService.onCancelSocialInteraction(event) }
|
||||||
|
|
||||||
on<KeepAlivePacket> { event -> event.session.send(event.packet) }
|
on<KeepAlivePacket> { event -> event.session.send(event.packet) }
|
||||||
on<ChatMessagePacket> { event -> onChatMessage(event) }
|
on<ChatMessagePacket> { event -> onChatMessage(event) }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ constructor(
|
|||||||
private val mapLoadService: MapLoadService,
|
private val mapLoadService: MapLoadService,
|
||||||
private val npcService: NpcService,
|
private val npcService: NpcService,
|
||||||
private val multiplayerService: MultiplayerService,
|
private val multiplayerService: MultiplayerService,
|
||||||
|
private val socialService: SocialService,
|
||||||
private val sessionRegistry: SessionRegistry,
|
private val sessionRegistry: SessionRegistry,
|
||||||
private val mapManager: MapManager,
|
private val mapManager: MapManager,
|
||||||
private val characterStore: CharacterStore,
|
private val characterStore: CharacterStore,
|
||||||
@@ -283,6 +284,9 @@ constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
ctx.send(RenderScreenPacket(true))
|
ctx.send(RenderScreenPacket(true))
|
||||||
|
|
||||||
|
socialService.sendFriendList(ctx)
|
||||||
|
|
||||||
log.info { "Player $charId spawned in bank=$bankId map=$mapId; ${others.size} others present" }
|
log.info { "Player $charId spawned in bank=$bankId map=$mapId; ${others.size} others present" }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,118 @@
|
|||||||
|
package de.fiereu.openmmo.server.game.services
|
||||||
|
|
||||||
|
import de.fiereu.network.PacketEvent
|
||||||
|
import de.fiereu.network.SessionContext
|
||||||
|
import de.fiereu.openmmo.net.game.packets.AddFriendPacket
|
||||||
|
import de.fiereu.openmmo.net.game.packets.BlockPlayerPacket
|
||||||
|
import de.fiereu.openmmo.net.game.packets.CancelSocialInteractionPacket
|
||||||
|
import de.fiereu.openmmo.net.game.packets.FriendListEntry
|
||||||
|
import de.fiereu.openmmo.net.game.packets.FriendListPacket
|
||||||
|
import de.fiereu.openmmo.net.game.packets.FriendProfileRequestPacket
|
||||||
|
import de.fiereu.openmmo.net.game.packets.PartyMemberJoinPacket
|
||||||
|
import de.fiereu.openmmo.net.game.packets.PartyMemberLeavePacket
|
||||||
|
import de.fiereu.openmmo.net.game.packets.RemoveFriendPacket
|
||||||
|
import de.fiereu.openmmo.net.game.packets.RequestSocialProfilePacket
|
||||||
|
import de.fiereu.openmmo.net.game.packets.UnblockPlayerPacket
|
||||||
|
import de.fiereu.openmmo.server.game.session.PLAYER_STATE
|
||||||
|
import de.fiereu.openmmo.server.game.session.SessionRegistry
|
||||||
|
import de.fiereu.openmmo.server.game.storage.CharacterStore
|
||||||
|
import de.fiereu.openmmo.server.game.storage.SocialStore
|
||||||
|
import io.github.oshai.kotlinlogging.KotlinLogging
|
||||||
|
import javax.inject.Inject
|
||||||
|
import javax.inject.Singleton
|
||||||
|
|
||||||
|
private val log = KotlinLogging.logger {}
|
||||||
|
|
||||||
|
@Singleton
|
||||||
|
class SocialService
|
||||||
|
@Inject
|
||||||
|
constructor(
|
||||||
|
private val socialStore: SocialStore,
|
||||||
|
private val sessionRegistry: SessionRegistry,
|
||||||
|
private val characterStore: CharacterStore,
|
||||||
|
) {
|
||||||
|
|
||||||
|
fun sendFriendList(ctx: SessionContext) {
|
||||||
|
val state = ctx.attributes[PLAYER_STATE] ?: return
|
||||||
|
ctx.send(buildFriendList(state.userId))
|
||||||
|
}
|
||||||
|
|
||||||
|
fun onAddFriend(event: PacketEvent<AddFriendPacket>) {
|
||||||
|
val ctx = event.session
|
||||||
|
val state = ctx.attributes[PLAYER_STATE] ?: return
|
||||||
|
val name = event.packet.username
|
||||||
|
socialStore.addFriend(state.userId, name)
|
||||||
|
log.info { "AddFriend user=${state.userId} name='$name'" }
|
||||||
|
ctx.send(buildFriendList(state.userId))
|
||||||
|
}
|
||||||
|
|
||||||
|
fun onRemoveFriend(event: PacketEvent<RemoveFriendPacket>) {
|
||||||
|
val ctx = event.session
|
||||||
|
val state = ctx.attributes[PLAYER_STATE] ?: return
|
||||||
|
val name = event.packet.username
|
||||||
|
val removed = socialStore.removeFriend(state.userId, name)
|
||||||
|
log.info { "RemoveFriend user=${state.userId} name='$name' removed=$removed" }
|
||||||
|
ctx.send(buildFriendList(state.userId))
|
||||||
|
}
|
||||||
|
|
||||||
|
fun onBlockPlayer(event: PacketEvent<BlockPlayerPacket>) {
|
||||||
|
val ctx = event.session
|
||||||
|
val state = ctx.attributes[PLAYER_STATE] ?: return
|
||||||
|
val packet = event.packet
|
||||||
|
socialStore.block(state.userId, packet.username)
|
||||||
|
log.info {
|
||||||
|
"BlockPlayer user=${state.userId} name='${packet.username}' reason='${packet.reason}'"
|
||||||
|
}
|
||||||
|
ctx.send(
|
||||||
|
PartyMemberJoinPacket(
|
||||||
|
player = syntheticId(packet.username),
|
||||||
|
name = packet.username,
|
||||||
|
secondaryName = packet.reason,
|
||||||
|
value = 0,
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
|
fun onUnblockPlayer(event: PacketEvent<UnblockPlayerPacket>) {
|
||||||
|
val ctx = event.session
|
||||||
|
val state = ctx.attributes[PLAYER_STATE] ?: return
|
||||||
|
val name = event.packet.username
|
||||||
|
val removed = socialStore.unblock(state.userId, name)
|
||||||
|
log.info { "UnblockPlayer user=${state.userId} name='$name' removed=$removed" }
|
||||||
|
ctx.send(PartyMemberLeavePacket(memberId = syntheticId(name)))
|
||||||
|
}
|
||||||
|
|
||||||
|
fun onFriendProfileRequest(event: PacketEvent<FriendProfileRequestPacket>) {
|
||||||
|
log.info { "FriendProfileRequest targetEntityId=${event.packet.targetEntityId}" }
|
||||||
|
}
|
||||||
|
|
||||||
|
fun onRequestSocialProfile(event: PacketEvent<RequestSocialProfilePacket>) {
|
||||||
|
log.info { "RequestSocialProfile targetId=${event.packet.targetId}" }
|
||||||
|
}
|
||||||
|
|
||||||
|
fun onCancelSocialInteraction(event: PacketEvent<CancelSocialInteractionPacket>) {
|
||||||
|
log.info { "CancelSocialInteraction from ${event.session.remoteAddress}" }
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun buildFriendList(userId: Int): FriendListPacket {
|
||||||
|
val entries =
|
||||||
|
socialStore.getFriends(userId).map { name ->
|
||||||
|
FriendListEntry(
|
||||||
|
player = syntheticId(name),
|
||||||
|
friendsSince = 0,
|
||||||
|
online = isOnlineByName(name),
|
||||||
|
name = name,
|
||||||
|
unk = 0,
|
||||||
|
lastSeen = 0,
|
||||||
|
appearance = List(5) { 0 },
|
||||||
|
)
|
||||||
|
}
|
||||||
|
return FriendListPacket(mode = 0, entries = entries)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun isOnlineByName(name: String): Boolean =
|
||||||
|
sessionRegistry.onlineCharacterIds().any { id ->
|
||||||
|
characterStore.getCharacter(id)?.info?.name == name
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun syntheticId(name: String): Long = (name.hashCode().toLong() shl 16) or 0x9000L
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
package de.fiereu.openmmo.server.game.storage
|
||||||
|
|
||||||
|
import java.util.concurrent.ConcurrentHashMap
|
||||||
|
import javax.inject.Inject
|
||||||
|
import javax.inject.Singleton
|
||||||
|
|
||||||
|
@Singleton
|
||||||
|
class SocialStore @Inject constructor() {
|
||||||
|
private val friendsByUser = ConcurrentHashMap<Int, MutableSet<String>>()
|
||||||
|
private val blockedByUser = ConcurrentHashMap<Int, MutableSet<String>>()
|
||||||
|
|
||||||
|
fun getFriends(userId: Int): Set<String> = friendsByUser.getOrPut(userId) { seedFriends() }
|
||||||
|
|
||||||
|
fun addFriend(userId: Int, name: String) {
|
||||||
|
friendsByUser.getOrPut(userId) { seedFriends() }.add(name)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun removeFriend(userId: Int, name: String): Boolean =
|
||||||
|
friendsByUser.getOrPut(userId) { seedFriends() }.remove(name)
|
||||||
|
|
||||||
|
fun getBlocked(userId: Int): Set<String> = blockedByUser.getOrPut(userId) { mutableSetOf() }
|
||||||
|
|
||||||
|
fun block(userId: Int, name: String) {
|
||||||
|
blockedByUser.getOrPut(userId) { mutableSetOf() }.add(name)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun unblock(userId: Int, name: String): Boolean =
|
||||||
|
blockedByUser.getOrPut(userId) { mutableSetOf() }.remove(name)
|
||||||
|
|
||||||
|
private fun seedFriends(): MutableSet<String> = linkedSetOf("Red", "Blue", "Green")
|
||||||
|
}
|
||||||
+6
@@ -1,9 +1,12 @@
|
|||||||
package de.fiereu.openmmo.server.game.handler
|
package de.fiereu.openmmo.server.game.handler
|
||||||
|
|
||||||
|
import de.fiereu.openmmo.net.game.packets.AddFriendPacket
|
||||||
|
import de.fiereu.openmmo.net.game.packets.BlockPlayerPacket
|
||||||
import de.fiereu.openmmo.net.game.packets.ChatMessagePacket
|
import de.fiereu.openmmo.net.game.packets.ChatMessagePacket
|
||||||
import de.fiereu.openmmo.net.game.packets.JoinPacket
|
import de.fiereu.openmmo.net.game.packets.JoinPacket
|
||||||
import de.fiereu.openmmo.net.game.packets.KeepAlivePacket
|
import de.fiereu.openmmo.net.game.packets.KeepAlivePacket
|
||||||
import de.fiereu.openmmo.net.game.packets.MovementPacket
|
import de.fiereu.openmmo.net.game.packets.MovementPacket
|
||||||
|
import de.fiereu.openmmo.net.game.packets.RemoveFriendPacket
|
||||||
import de.fiereu.openmmo.server.game.config.GameServerConfig
|
import de.fiereu.openmmo.server.game.config.GameServerConfig
|
||||||
import de.fiereu.openmmo.server.game.di.DaggerGameServerComponent
|
import de.fiereu.openmmo.server.game.di.DaggerGameServerComponent
|
||||||
import io.kotest.core.spec.style.FunSpec
|
import io.kotest.core.spec.style.FunSpec
|
||||||
@@ -26,5 +29,8 @@ class GameAppHandlerTest :
|
|||||||
handler.isRegistered(MovementPacket::class) shouldBe true
|
handler.isRegistered(MovementPacket::class) shouldBe true
|
||||||
handler.isRegistered(ChatMessagePacket::class) shouldBe true
|
handler.isRegistered(ChatMessagePacket::class) shouldBe true
|
||||||
handler.isRegistered(KeepAlivePacket::class) shouldBe true
|
handler.isRegistered(KeepAlivePacket::class) shouldBe true
|
||||||
|
handler.isRegistered(AddFriendPacket::class) shouldBe true
|
||||||
|
handler.isRegistered(RemoveFriendPacket::class) shouldBe true
|
||||||
|
handler.isRegistered(BlockPlayerPacket::class) shouldBe true
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
package de.fiereu.openmmo.server.game.storage
|
||||||
|
|
||||||
|
import io.kotest.core.spec.style.FunSpec
|
||||||
|
import io.kotest.matchers.shouldBe
|
||||||
|
|
||||||
|
class SocialStoreTest :
|
||||||
|
FunSpec({
|
||||||
|
test("friends are seeded per user and survive add/remove") {
|
||||||
|
val store = SocialStore()
|
||||||
|
store.getFriends(1) shouldBe linkedSetOf("Red", "Blue", "Green")
|
||||||
|
|
||||||
|
store.addFriend(1, "Yellow")
|
||||||
|
store.getFriends(1).contains("Yellow") shouldBe true
|
||||||
|
|
||||||
|
store.removeFriend(1, "Red") shouldBe true
|
||||||
|
store.getFriends(1).contains("Red") shouldBe false
|
||||||
|
store.removeFriend(1, "Red") shouldBe false
|
||||||
|
}
|
||||||
|
|
||||||
|
test("block list is independent per user") {
|
||||||
|
val store = SocialStore()
|
||||||
|
store.getBlocked(1) shouldBe emptySet()
|
||||||
|
|
||||||
|
store.block(1, "Troll")
|
||||||
|
store.getBlocked(1) shouldBe setOf("Troll")
|
||||||
|
store.getBlocked(2) shouldBe emptySet()
|
||||||
|
|
||||||
|
store.unblock(1, "Troll") shouldBe true
|
||||||
|
store.getBlocked(1) shouldBe emptySet()
|
||||||
|
}
|
||||||
|
})
|
||||||
@@ -24,8 +24,8 @@ class LoginServer
|
|||||||
@Inject
|
@Inject
|
||||||
constructor(
|
constructor(
|
||||||
private val config: LoginServerConfig,
|
private val config: LoginServerConfig,
|
||||||
@Named("boss") private val bossGroup: EventLoopGroup,
|
@param:Named("boss") private val bossGroup: EventLoopGroup,
|
||||||
@Named("worker") private val workerGroup: EventLoopGroup,
|
@param:Named("worker") private val workerGroup: EventLoopGroup,
|
||||||
private val rootKey: ECPrivateKey,
|
private val rootKey: ECPrivateKey,
|
||||||
private val handlerProvider: Provider<LoginAppHandler>,
|
private val handlerProvider: Provider<LoginAppHandler>,
|
||||||
) {
|
) {
|
||||||
|
|||||||
Reference in new issue
Block a user