Merge pull request #6 from openmmo-org/feat/friendlist

feat(game): add friendlist
This commit is contained in:
Fiereu authored and GitHub committed 2026-06-22 17:13:30 +02:00
commit df862c71b7
56 files changed
+473 -182

No files matched your search

@@ -271,11 +271,11 @@ object GameProtocol : Protocol() {
c2s<UnblockPlayerPacket>(0x61u, UnblockPlayerPacketCodec)
s2c<EntityCoordSyncPacket>(0x61u, EntityCoordSyncPacketCodec)
c2s<RemoveFriendPacket>(0x62u, RemoveFriendPacketCodec)
c2s<AddFriendPacket>(0x62u, AddFriendPacketCodec)
s2c<SocialActionOutcomePacket>(0x62u, SocialActionOutcomePacketCodec)
c2s<SetPlayerTitlePacket>(0x63u, SetPlayerTitlePacketCodec)
s2c<ContactRosterPacket>(0x63u, ContactRosterPacketCodec)
c2s<RemoveFriendPacket>(0x63u, RemoveFriendPacketCodec)
s2c<FriendListPacket>(0x63u, FriendListPacketCodec)
c2s<FriendProfileRequestPacket>(0x64u, FriendProfileRequestPacketCodec)
s2c<ContactInsertPacket>(0x64u, ContactInsertPacketCodec)
@@ -594,6 +594,5 @@ object GameProtocol : Protocol() {
s2c<GtlListingsPagePacket>(0xFEu, GtlListingsPagePacketCodec)
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)
}
}
@@ -75,9 +75,7 @@ private val EventsCodec: Codec<List<InputEventSample>> =
shortB = S16LE.read(buf)
}
}
result.add(
InputEventSample(type, timestamp, byteA, byteB, intA, shortA, shortB, intB)
)
result.add(InputEventSample(type, timestamp, byteA, byteB, intA, shortA, shortB, intB))
previous = timestamp
}
return result
@@ -75,9 +75,21 @@ private class BattleParticipantCodec(private val isCapture: Boolean) :
}
}
return BattleActionParticipant(
entityId, kind, intA, intB, intC, shortA, critByte, critShort, capturedShort, capturedByte,
xpShort, xpByteA, xpByteB, pokemon, statStages
)
entityId,
kind,
intA,
intB,
intC,
shortA,
critByte,
critShort,
capturedShort,
capturedByte,
xpShort,
xpByteA,
xpByteB,
pokemon,
statStages)
}
}
@@ -28,7 +28,8 @@ private val BattleActionSelectBody: Codec<BattleActionSelectPacket> =
S8.write(buf, value.extraFlag)
}
2, 3 -> {
2,
3 -> {
S16LE.write(buf, value.moveOrItemId)
}
@@ -157,7 +157,8 @@ internal val BattleSerializedEntryCodec: Codec<BattleSerializedEntry> =
S16LE.write(buf, value.y)
}
is EmptyCreatureDataEntry -> throw MalformedPacketException("cannot encode default battle entry")
is EmptyCreatureDataEntry ->
throw MalformedPacketException("cannot encode default battle entry")
}
}
}
@@ -28,14 +28,18 @@ internal val MessageArgCodec: Codec<MessageArg> =
when (type) {
28 -> {}
30 -> longValue = field(S64LE) { it.longValue!! }
9, 10, 17 -> intValue = field(S32LE) { it.intValue!! }
5, 18 -> stringValue = field(Utf16LeNullTerminated) { it.stringValue!! }
9,
10,
17 -> intValue = field(S32LE) { it.intValue!! }
5,
18 -> stringValue = field(Utf16LeNullTerminated) { it.stringValue!! }
else -> {
val count = field(U8) { it.shortValues!!.size }
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)
}
}
@@ -88,7 +88,8 @@ object BattleEntityDeltaPacketCodec : PacketCodec<BattleEntityDeltaPacket>() {
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 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
return BattleEntityDeltaPacket(
@@ -35,9 +35,18 @@ private val BattleRankingEntryCodec: Codec<BattleRankingEntry> =
val bool2 = field(Bool) { it.bool2 }
field(S8) { 0 }
return BattleRankingEntry(
entityId, flag1, flag2, name, value1, genderId, ribbons, byte1, int1, byte2, bool1,
bool2
)
entityId,
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 boxByte = field(S8) { it.boxByte }
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
if (!active) {
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
var participants = emptyList<BattleRankingEntry>()
@@ -40,9 +40,16 @@ object BattleSendOutActivePacketCodec : PacketCodec<BattleSendOutActivePacket>()
return BattleSendOutActivePacket(
opponent,
BattleSendOutMember(
entityIdA, entityIdB, entityIdC, speciesByte, nickname, ownerName, value, nameA, nameB,
levelByte, flag
)
)
entityIdA,
entityIdB,
entityIdC,
speciesByte,
nickname,
ownerName,
value,
nameA,
nameB,
levelByte,
flag))
}
}
@@ -43,8 +43,7 @@ private val BattleAddPokemonCodec: Codec<BattleAddPokemon> =
BattleAddStatusEffect(durationTurns, effectType, sourceSlot)
} else null
return BattleAddPokemon(
entityId, frontSpriteId, backSpriteId, side, slot, partyIndex, statusEffect
)
entityId, frontSpriteId, backSpriteId, side, slot, partyIndex, statusEffect)
}
}
@@ -45,8 +45,7 @@ private val BattlePartyPokemonCodec: Codec<BattlePartyPokemon> =
BattlePartyStatusEffect(durationTurns, effectType, sourceSlot)
} else null
return BattlePartyPokemon(
entityId, frontSpriteId, backSpriteId, side, slot, partyIndex, statusEffect
)
entityId, frontSpriteId, backSpriteId, side, slot, partyIndex, statusEffect)
}
}
@@ -17,7 +17,8 @@ private val SimulationConfigPayload: Codec<ByteArray> =
data class BattleSimulationRequestPacket(val simulationConfig: ByteArray) {
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()
}
@@ -33,9 +33,17 @@ private class BattlePreviewMemberCodec(
val levelByte = field(S8) { it.levelByte }
val flag = field(Bool) { it.flag }
return BattlePreviewMember(
entityIdA, entityIdB, entityIdC, speciesByte, nickname, ownerName, value, nameA, nameB,
levelByte, flag
)
entityIdA,
entityIdB,
entityIdC,
speciesByte,
nickname,
ownerName,
value,
nameA,
nameB,
levelByte,
flag)
}
}
@@ -34,7 +34,8 @@ object CharacterAppearanceApplyPacketCodec : PacketCodec<CharacterAppearanceAppl
val moves = mutableListOf<AppearanceMoveEntry>()
for (slot in 0 until 15) {
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? =
if (hasPp) field(S8) { v -> v.creatureMoves.moves.first { it.slot == slot }.ppUp ?: 0 }
else null
@@ -15,8 +15,7 @@ object ChatMessageSendPacketCodec : PacketCodec<ChatMessageSendPacket>() {
override fun CodecScope<ChatMessageSendPacket>.body(): ChatMessageSendPacket {
val mode = field(S8) { it.mode }
val target = field(Utf16LeNullTerminated) { it.target }
val message =
if (mode.toInt() == 4) field(Utf16LeNullTerminated) { it.message ?: "" } else null
val message = if (mode.toInt() == 4) field(Utf16LeNullTerminated) { it.message ?: "" } else null
return ChatMessageSendPacket(mode, target, message)
}
}
@@ -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)
}
}
@@ -49,8 +49,7 @@ data class CustomizeCharacterAppearancePacket(
val paletteIndex: Byte,
)
object CustomizeCharacterAppearancePacketCodec :
PacketCodec<CustomizeCharacterAppearancePacket>() {
object CustomizeCharacterAppearancePacketCodec : PacketCodec<CustomizeCharacterAppearancePacket>() {
override fun CodecScope<CustomizeCharacterAppearancePacket>.body():
CustomizeCharacterAppearancePacket {
val entityId = field(S64LE) { it.entityId }
@@ -59,7 +58,6 @@ object CustomizeCharacterAppearancePacketCodec :
val moveSet = field(CreatureMovesetCodec) { it.moveSet }
val paletteIndex = field(S8) { it.paletteIndex }
return CustomizeCharacterAppearancePacket(
entityId, colorCategoryId, colorSlot, moveSet, paletteIndex
)
entityId, colorCategoryId, colorSlot, moveSet, paletteIndex)
}
}
@@ -53,7 +53,8 @@ object EntityAppearancePatchPacketCodec : PacketCodec<EntityAppearancePatchPacke
val flagsInt = flags.toInt()
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 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 =
if (flagsInt and 8 != 0) {
val count = field(S8) { it.cosmetics!!.size.toByte() }.toInt()
@@ -64,7 +65,6 @@ object EntityAppearancePatchPacketCodec : PacketCodec<EntityAppearancePatchPacke
}
} else null
return EntityAppearancePatchPacket(
entityId, spriteId, direction, animation, appearance, cosmetics
)
entityId, spriteId, direction, animation, appearance, cosmetics)
}
}
@@ -112,7 +112,8 @@ private val EventOverlayStateCodec: Codec<EventOverlayStatePacket> =
S16LE.write(buf, r.regionId)
S16LE.write(buf, r.secondary)
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)
for (p in points) {
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)
}
}
@@ -15,7 +15,9 @@ data class ReconnectHelloAuth(val entityId: Long, val sessionToken: ByteArray) :
data class NewHelloAuth(val userId: Int, val sessionToken: ByteArray) : HelloAuthData() {
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()
}
@@ -88,10 +88,36 @@ private val GmCharacterSessionCodec: Codec<GmCharacterSession> =
val statusCount = field(U8) { it.statusList.size }
val statusList = (0 until statusCount).map { i -> field(S8) { it.statusList[i] } }
return GmCharacterSession(
entityId, name, 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
)
entityId,
name,
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 stringC = field(Utf16LeNullTerminated) { it.account!!.stringC }
GmAccountInfo(
rankExtraA, rankExtraB, rankExtraC, ipAddress, playtime, accountId, stringA, stringB,
stringC
)
rankExtraA,
rankExtraB,
rankExtraC,
ipAddress,
playtime,
accountId,
stringA,
stringB,
stringC)
} else null
val extraByte = field(U8) { if (it.extra != null) 1 else 0 }
val extra =
@@ -169,7 +201,8 @@ object GmPlayerLookupPacketCodec : PacketCodec<GmPlayerLookupPacket>() {
GmExtraDetail(value, text)
} else null
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)
}
}
@@ -47,8 +47,6 @@ object GtlCreateListingPacketCodec : PacketCodec<GtlCreateListingPacket>() {
val itemKind = field(S8) { it.itemKind }
val priceShort = field(S16LE) { it.priceShort }
val filterCriteria = field(FilterCriteriaBytes) { it.filterCriteria }
return GtlCreateListingPacket(
categoryIndex, listingCount, itemKind, priceShort, filterCriteria
)
return GtlCreateListingPacket(categoryIndex, listingCount, itemKind, priceShort, filterCriteria)
}
}
@@ -39,7 +39,6 @@ object GtlSellPokemonListingPacketCodec : PacketCodec<GtlSellPokemonListingPacke
val criteriaCount = field(U8) { it.criteriaCount }
val criteriaData = field(RemainingBytes) { it.criteriaData }
return GtlSellPokemonListingPacket(
listingType, entryKindId, listingCategory, itemTypeId, criteriaCount, criteriaData
)
listingType, entryKindId, listingCategory, itemTypeId, criteriaCount, criteriaData)
}
}
@@ -38,7 +38,8 @@ private object GuildProfileDataCodec : PacketCodec<GuildProfileData>() {
val value5 = field(S16LE, GuildProfileData::value5)
val value6 = field(S32LE, GuildProfileData::value6)
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(
guildId,
name,
@@ -33,7 +33,8 @@ object GuildProfileSyncPacketCodec : PacketCodec<GuildProfileSyncPacket>() {
val value5 = field(S16LE, GuildProfileSyncPacket::value5)
val value6 = field(S32LE, GuildProfileSyncPacket::value6)
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(
guildId,
name,
@@ -43,7 +43,8 @@ private val HighScoreEntryCodec: Codec<HighScoreEntry> =
val rank = field(S32LE) { it.rank }
val score = field(S32LE) { it.score }
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)
}
}
@@ -47,8 +47,6 @@ object ListWindowPagePacketCodec : PacketCodec<ListWindowPagePacket>() {
val headerB = field(S8) { it.headerB }
val headerC = field(S8) { it.headerC }
val rows = field(ListWindowRowCodec.listPrefixed(U16LE)) { it.rows }
return ListWindowPagePacket(
windowId, firstPage, lastPage, headerA, headerB, headerC, rows
)
return ListWindowPagePacket(windowId, firstPage, lastPage, headerA, headerB, headerC, rows)
}
}
@@ -52,7 +52,8 @@ object LocalCharacterDeltaPacketCodec : PacketCodec<LocalCharacterDeltaPacket>()
value64a = 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
return LocalCharacterDeltaPacket(
mask = mask,
@@ -26,7 +26,6 @@ object MapTileObjectSlotSetPacketCodec : PacketCodec<MapTileObjectSlotSetPacket>
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
return MapTileObjectSlotSetPacket(
blockX, blockY, blockZ, slot, present, objectX, objectY, objectZ, relative
)
blockX, blockY, blockZ, slot, present, objectX, objectY, objectZ, relative)
}
}
@@ -42,7 +42,6 @@ object MarketBoardPagePacketCodec : PacketCodec<MarketBoardPagePacket>() {
entries.add(MarketBoardEntry(itemId, valueA, valueB, rank))
}
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 unk6 = field(U16LE) { it.unk6 }
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)
}
}
@@ -16,7 +16,6 @@ object RequestConfirmationPromptPacketCodec : PacketCodec<RequestConfirmationPro
val requestTimeoutSeconds = if (visible) field(U16LE) { it.requestTimeoutSeconds!! } else null
val responseTimeoutSeconds = if (visible) field(U16LE) { it.responseTimeoutSeconds!! } else null
return RequestConfirmationPromptPacket(
visible, entityId, requestTimeoutSeconds, responseTimeoutSeconds
)
visible, entityId, requestTimeoutSeconds, responseTimeoutSeconds)
}
}
@@ -40,8 +40,7 @@ private val ServerMessageArgCodec: Codec<ServerMessageArg> =
else -> shortValues = field(S16LE.listPrefixed(U8)) { it.shortValues!! }
}
return ServerMessageArg(
argId, type, hasExtra, extra, longValue, intValue, stringValue, shortValues
)
argId, type, hasExtra, extra, longValue, intValue, stringValue, shortValues)
}
}
@@ -24,16 +24,13 @@ private val ColorPaletteCodec: Codec<List<Short>> =
}
}
object SetBattleMonsterAppearancePacketCodec :
PacketCodec<SetBattleMonsterAppearancePacket>() {
object SetBattleMonsterAppearancePacketCodec : PacketCodec<SetBattleMonsterAppearancePacket>() {
override fun CodecScope<SetBattleMonsterAppearancePacket>.body():
SetBattleMonsterAppearancePacket {
val partySlot = field(S16LE) { it.partySlot }
val pokemonEntityId = field(S64LE) { it.pokemonEntityId }
val shininessType = field(S8) { it.shininessType }
val colorPalette = field(ColorPaletteCodec) { it.colorPalette }
return SetBattleMonsterAppearancePacket(
partySlot, pokemonEntityId, shininessType, colorPalette
)
return SetBattleMonsterAppearancePacket(partySlot, pokemonEntityId, shininessType, colorPalette)
}
}
@@ -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)
}
}
@@ -11,10 +11,8 @@ data class SocialActionOutcomePacket(
object SocialActionOutcomePacketCodec : PacketCodec<SocialActionOutcomePacket>() {
override fun CodecScope<SocialActionOutcomePacket>.body(): SocialActionOutcomePacket {
val action = field(U8) { it.action }
val entityId: Long? =
if (resolveKind(action) == 1) field(S64LE) { it.entityId!! } else null
val value: Short? =
if (resolveKind(action) == 2) field(S16LE) { it.value!! } else null
val entityId: Long? = if (resolveKind(action) == 1) field(S64LE) { it.entityId!! } else null
val value: Short? = if (resolveKind(action) == 2) field(S16LE) { it.value!! } else null
return SocialActionOutcomePacket(action, entityId, value)
}
@@ -16,8 +16,7 @@ object SpatialGroupInsertPacketCodec : PacketCodec<SpatialGroupInsertPacket>() {
val entityId = field(S64LE) { it.entityId }
val value = field(S16LE) { it.value }
val extraCoordPresent = false
val extraValue: Short? =
if (extraCoordPresent) field(S16LE) { it.extraValue ?: 0 } else null
val extraValue: Short? = if (extraCoordPresent) field(S16LE) { it.extraValue ?: 0 } else null
return SpatialGroupInsertPacket(group, entityId, value, extraCoordPresent, extraValue)
}
}
@@ -11,7 +11,8 @@ data class StorageBoxFilterPacket(
other is StorageBoxFilterPacket &&
listTypeIndex == other.listTypeIndex &&
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 {
var r = listTypeIndex?.hashCode() ?: 0
@@ -26,9 +27,7 @@ private val CookieBytes = bytesPrefixed(U8)
object StorageBoxFilterPacketCodec : PacketCodec<StorageBoxFilterPacket>() {
override fun CodecScope<StorageBoxFilterPacket>.body(): StorageBoxFilterPacket {
val typeFlags =
field(U8) {
(if (it.boxName != null) 1 else 0) or (if (it.cookieData != null) 2 else 0)
}
field(U8) { (if (it.boxName != null) 1 else 0) or (if (it.cookieData != null) 2 else 0) }
val listTypeIndex: Byte? =
if (typeFlags and 1 != 0) field(S8) { it.listTypeIndex ?: 0 } else null
val boxName: String? =
@@ -35,9 +35,7 @@ object StorageContextWindowPacketCodec : PacketCodec<StorageContextWindowPacket>
val quantity = field(S8) { it.items[i].quantity }
val ball = field(S8) { it.items[i].ball }
val location = field(S8) { it.items[i].location }
items.add(
StorageBoxItem(slot, valueA, valueB, valueC, valueD, quantity, ball, location)
)
items.add(StorageBoxItem(slot, valueA, valueB, valueC, valueD, quantity, ball, location))
}
return StorageContextWindowPacket(kind, items)
}
@@ -50,7 +50,6 @@ object StorageInventoryPacketCodec : PacketCodec<StorageInventoryPacket>() {
val listC = field(StorageQuantityCodec.listPrefixed(U8)) { it.listC }
val listD = field(StorageQuantityCodec.listPrefixed(U8)) { it.listD }
return StorageInventoryPacket(
header, totalA, totalB, valueC, usedA, usedB, listA, listB, listC, listD
)
header, totalA, totalB, valueC, usedA, usedB, listA, listB, listC, listD)
}
}
@@ -56,8 +56,7 @@ object TeamPreviewLeadSubmitPacketCodec : PacketCodec<TeamPreviewLeadSubmitPacke
val pokemonEntityId = field(S64LE) { it.pokemonEntityId }
val battleSlot = field(S8) { it.battleSlot }
val present = field(U8) { if (it.appearance != null) 1 else 0 }
val appearance =
if (present != 0) field(AppearanceCodec) { it.appearance!! } else null
val appearance = if (present != 0) field(AppearanceCodec) { it.appearance!! } else null
val teamSide = field(S16LE) { it.teamSide }
val reserved = field(S8) { it.reserved }
return TeamPreviewLeadSubmitPacket(
@@ -7,9 +7,7 @@ data class TypedBinaryDataPacket(
val data: ByteArray,
) {
override fun equals(other: Any?): Boolean =
other is TypedBinaryDataPacket &&
dataType == other.dataType &&
data.contentEquals(other.data)
other is TypedBinaryDataPacket && dataType == other.dataType && data.contentEquals(other.data)
override fun hashCode(): Int = dataType * 31 + data.contentHashCode()
}
@@ -28,16 +28,18 @@ private val WorldNoticeArgCodec: Codec<WorldNoticeArg> =
when (type) {
28 -> {}
30 -> longValue = field(S64LE) { it.longValue!! }
9, 10, 17 -> intValue = field(S32LE) { it.intValue!! }
5, 18 -> stringValue = field(Utf16LeNullTerminated) { it.stringValue!! }
9,
10,
17 -> intValue = field(S32LE) { it.intValue!! }
5,
18 -> stringValue = field(Utf16LeNullTerminated) { it.stringValue!! }
else -> {
val count = field(U8) { it.shortValues!!.size }
shortValues = (0 until count).map { i -> field(S16LE) { it.shortValues!![i] } }
}
}
return WorldNoticeArg(
argId, type, hasExtra, extra, longValue, intValue, stringValue, shortValues
)
argId, type, hasExtra, extra, longValue, intValue, stringValue, shortValues)
}
}
@@ -9,7 +9,8 @@ data class WorldObjectInstanceDespawnPacket(
)
object WorldObjectInstanceDespawnPacketCodec : PacketCodec<WorldObjectInstanceDespawnPacket>() {
override fun CodecScope<WorldObjectInstanceDespawnPacket>.body(): WorldObjectInstanceDespawnPacket {
override fun CodecScope<WorldObjectInstanceDespawnPacket>.body():
WorldObjectInstanceDespawnPacket {
val entityId = field(S64LE) { it.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.TokenPayloadPacket
import io.kotest.core.spec.style.FunSpec
import io.kotest.matchers.collections.shouldContainAll
import io.kotest.matchers.shouldBe
class GameProtocolTest :
FunSpec({
test("at least one registration per known opcode") {
val opcodes = GameProtocol.registrations.map { it.opcode }.toSet()
opcodes shouldBe
opcodes shouldContainAll
setOf(
0x01u.toUByte(),
0x02u.toUByte(),
@@ -30,8 +30,8 @@ class GameServer
@Inject
constructor(
private val config: GameServerConfig,
@Named("boss") private val bossGroup: EventLoopGroup,
@Named("worker") private val workerGroup: EventLoopGroup,
@param:Named("boss") private val bossGroup: EventLoopGroup,
@param:Named("worker") private val workerGroup: EventLoopGroup,
private val rootKey: ECPrivateKey,
private val handlerProvider: Provider<GameAppHandler>,
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.Language
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.CreateCharacterPacket
import de.fiereu.openmmo.net.game.packets.DialogChoicePacket
import de.fiereu.openmmo.net.game.packets.EntityInteractPacket
import de.fiereu.openmmo.net.game.packets.EntityLeavePacket
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.JoinPacket
import de.fiereu.openmmo.net.game.packets.KeepAlivePacket
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.RequestPlayerPacket
import de.fiereu.openmmo.net.game.packets.RequestSocialProfilePacket
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.InteractionService
import de.fiereu.openmmo.server.game.services.LoginService
import de.fiereu.openmmo.server.game.services.MovementService
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.SessionRegistry
import de.fiereu.openmmo.server.game.storage.CharacterStore
@@ -41,6 +49,7 @@ constructor(
private val dialogService: DialogService,
private val interactionService: InteractionService,
private val multiplayerService: MultiplayerService,
private val socialService: SocialService,
private val sessionRegistry: SessionRegistry,
private val characterStore: CharacterStore,
scope: CoroutineScope,
@@ -60,6 +69,14 @@ constructor(
onSuspend<InteractiveResponsePacket> { event -> dialogService.onInteractive(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<ChatMessagePacket> { event -> onChatMessage(event) }
}
@@ -42,6 +42,7 @@ constructor(
private val mapLoadService: MapLoadService,
private val npcService: NpcService,
private val multiplayerService: MultiplayerService,
private val socialService: SocialService,
private val sessionRegistry: SessionRegistry,
private val mapManager: MapManager,
private val characterStore: CharacterStore,
@@ -283,6 +284,9 @@ constructor(
}
ctx.send(RenderScreenPacket(true))
socialService.sendFriendList(ctx)
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")
}
@@ -1,9 +1,12 @@
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.JoinPacket
import de.fiereu.openmmo.net.game.packets.KeepAlivePacket
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.di.DaggerGameServerComponent
import io.kotest.core.spec.style.FunSpec
@@ -26,5 +29,8 @@ class GameAppHandlerTest :
handler.isRegistered(MovementPacket::class) shouldBe true
handler.isRegistered(ChatMessagePacket::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
constructor(
private val config: LoginServerConfig,
@Named("boss") private val bossGroup: EventLoopGroup,
@Named("worker") private val workerGroup: EventLoopGroup,
@param:Named("boss") private val bossGroup: EventLoopGroup,
@param:Named("worker") private val workerGroup: EventLoopGroup,
private val rootKey: ECPrivateKey,
private val handlerProvider: Provider<LoginAppHandler>,
) {