Skip to content

Commit

Permalink
practice mode fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
hex-agon committed Jul 7, 2023
1 parent bd58cb0 commit 6cd6755
Show file tree
Hide file tree
Showing 28 changed files with 507 additions and 262 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package work.fking.pangya.game.model

import io.netty.buffer.ByteBuf

data class Coord2D(val x: Float, val z: Float) {

constructor(buffer: ByteBuf) : this(
x = buffer.readFloatLE(),
z = buffer.readFloatLE()
)
}

fun ByteBuf.write(coord: Coord2D) {
this.writeFloatLE(coord.x)
this.writeFloatLE(coord.z)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package work.fking.pangya.game.model

import io.netty.buffer.ByteBuf

data class Coord3D(val x: Float, val y: Float, val z: Float) {
constructor(buffer: ByteBuf) : this(
x = buffer.readFloatLE(),
y = buffer.readFloatLE(),
z = buffer.readFloatLE()
)

}

fun ByteBuf.write(coord: Coord3D) {
this.writeFloatLE(coord.x)
this.writeFloatLE(coord.y)
this.writeFloatLE(coord.z)
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import work.fking.pangya.game.packet.handler.match.MatchPlayerRotateAimPacketHan
import work.fking.pangya.game.packet.handler.match.MatchPlayerShotCommitPacketHandler
import work.fking.pangya.game.packet.handler.match.MatchPlayerTurnEndPacketHandler
import work.fking.pangya.game.packet.handler.match.MatchPlayerShotStartPacketHandler
import work.fking.pangya.game.packet.handler.match.MatchPlayerShotSyncPacketHandler
import work.fking.pangya.game.packet.handler.match.MatchTourneyShotPacketHandler
import work.fking.pangya.game.packet.handler.match.StartGamePacketHandler
import work.fking.pangya.game.packet.handler.room.CreateRoomPacketHandler
import work.fking.pangya.game.packet.handler.room.LeaveRoomPacketHandler
Expand All @@ -43,7 +45,7 @@ enum class ClientPacketType(
MATCH_PLAYER_POWER_TOGGLE(0x15),
MATCH_PLAYER_CHANGE_CLUB(0x16),
MATCH_HOLE_START(0x1a, MatchHoleStartPacketHandler()),
MATCH_PLAYER_SHOT_SYNC(0x1b),
MATCH_PLAYER_SHOT_SYNC(0x1b, MatchPlayerShotSyncPacketHandler()),
MATCH_PLAYER_SHOT_END(0x1c, MatchPlayerTurnEndPacketHandler()),
EQUIPMENT_UPDATE(0x20, EquipmentUpdatePacketHandler()),
MATCH_PLAYER_TURN_START(0x22),
Expand All @@ -64,6 +66,7 @@ enum class ClientPacketType(
LOCKER_INVENTORY_REQUEST(0xd3, LockerInventoryRequestPacketHandler()),
UNKNOWN_140(0x140),
ACHIEVEMENT_STATUS_REQUEST(0x157),
MATCH_PLAYER_TOURNEY_SHOT(0x12f, MatchTourneyShotPacketHandler()),
PAPEL_SHOP_PLAY(0x14b, PapelShopPlayPacketHandler()),
LOGIN_BONUS_INFO(0x16e, LoginBonusStatusPacketHandler()),
LOGIN_BONUS_CLAIM(0x16f, LoginBonusClaimPacketHandler());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class ProtocolDecoder(
PangCrypt.decrypt(buffer, cryptKey)
val packetId = buffer.readShortLE().toInt()
val packetType = protocol.forId(packetId)
LOGGER.trace("Incoming packet {} (0x{})", packetType, Integer.toHexString(packetId))
LOGGER.debug("Incoming packet {} (0x{})", packetType, Integer.toHexString(packetId))

if (packetType == null) {
LOGGER.warn("Unknown packetId=0x{}", Integer.toHexString(packetId))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,5 @@ class UpdateChatMacrosPacketHandler : ClientPacketHandler {
for (i in 0 until MAX_MACROS) {
macros[i] = packet.readFixedSizeString(MACRO_LENGTH)
}
println(macros)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package work.fking.pangya.game.packet.handler.match

import io.netty.buffer.ByteBuf
import work.fking.pangya.game.GameServer
import work.fking.pangya.game.model.Coord
import work.fking.pangya.game.model.Coord2D
import work.fking.pangya.game.net.ClientPacketHandler
import work.fking.pangya.game.player.Player
import work.fking.pangya.game.room.match.PlayerHoleStartEvent
Expand All @@ -16,8 +16,8 @@ class MatchHoleStartPacketHandler : ClientPacketHandler {
val unknown1 = packet.readIntLE()
val unknown2 = packet.readIntLE()
val par = packet.readByte()
val teeCoord = Coord(packet.readFloatLE(), packet.readFloatLE())
val holeCoord = Coord(packet.readFloatLE(), packet.readFloatLE())
val teeCoord = Coord2D(packet.readFloatLE(), packet.readFloatLE())
val holeCoord = Coord2D(packet.readFloatLE(), packet.readFloatLE())


room.handleMatchEvent(PlayerHoleStartEvent(
Expand All @@ -27,13 +27,6 @@ class MatchHoleStartPacketHandler : ClientPacketHandler {
teeCoord = teeCoord,
holeCoord = holeCoord
))
// roomPlayer.finishedHole = false
// println("${player.nickname} hole start")
//
// player.write(MatchReplies.gameHoleWeather())
// player.write(MatchReplies.gameHoleWind())
// player.write(MatchReplies.gamePlayerStartHole(player))
// player.flush()
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import work.fking.pangya.game.GameServer
import work.fking.pangya.game.net.ClientPacketHandler
import work.fking.pangya.game.player.Player
import work.fking.pangya.game.room.match.PlayerShotCommitEvent
import work.fking.pangya.game.room.match.ShotData
import work.fking.pangya.game.room.match.ShotCommitData

class MatchPlayerShotCommitPacketHandler : ClientPacketHandler {
override fun handle(server: GameServer, player: Player, packet: ByteBuf) {
Expand All @@ -17,9 +17,8 @@ class MatchPlayerShotCommitPacketHandler : ClientPacketHandler {
if (shotType == 1) { // ??
val bytes = ByteArray(9)
packet.readBytes(bytes)
println(bytes.contentToString())
}
val shotData = ShotData(
val shotData = ShotCommitData(
maxClick = packet.readFloatLE(),
minClick = packet.readFloatLE(),
curve = packet.readFloatLE(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package work.fking.pangya.game.packet.handler.match

import io.netty.buffer.ByteBuf
import work.fking.pangya.game.GameServer
import work.fking.pangya.game.net.ClientPacketHandler
import work.fking.pangya.game.player.Player
import work.fking.pangya.game.room.match.PlayerShotSyncEvent

class MatchPlayerShotSyncPacketHandler : ClientPacketHandler {

override fun handle(server: GameServer, player: Player, packet: ByteBuf) {
val room = player.currentRoom ?: throw IllegalStateException("Player ${player.nickname} tried to sync shot but is not in a room")
val roomPlayer = room.findSelf(player)

val connectionId = packet.readIntLE()
val x = packet.readFloatLE()
val y = packet.readFloatLE()
val z = packet.readFloatLE()
val state = packet.readByte().toInt()
val bunker = packet.readByte().toInt()
val unknown = packet.readByte().toInt()
val pang = packet.readIntLE()
val bonusPang = packet.readIntLE()
val cameraFlags = packet.readIntLE()
val shotFlags = packet.readIntLE()
val shotFrames = packet.readShortLE().toInt() // i think this is the travel time in frames?
val grandPrixPenalties = packet.readByte().toInt()

room.handleMatchEvent(PlayerShotSyncEvent(
player = roomPlayer,
x = x,
z = z,
shotFlags = shotFlags,
frames = shotFrames
))
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package work.fking.pangya.game.packet.handler.match

import io.netty.buffer.ByteBuf
import work.fking.pangya.game.GameServer
import work.fking.pangya.game.net.ClientPacketHandler
import work.fking.pangya.game.player.Player
import work.fking.pangya.game.room.match.PlayerTourneyShotEvent
import work.fking.pangya.game.room.match.TourneyShotData

class MatchTourneyShotPacketHandler : ClientPacketHandler {

override fun handle(server: GameServer, player: Player, packet: ByteBuf) {
val room = player.currentRoom ?: throw IllegalStateException("Player ${player.nickname} tried to sync tourney shot but is not in a room")
val roomPlayer = room.findSelf(player)

val shotData = TourneyShotData(packet)

room.handleMatchEvent(PlayerTourneyShotEvent(roomPlayer, shotData))
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import work.fking.pangya.game.player.Player
import work.fking.pangya.game.room.Course
import work.fking.pangya.game.room.HoleMode
import work.fking.pangya.game.room.RoomType
import work.fking.pangya.game.room.courseById
import work.fking.pangya.game.room.holeModeById
import work.fking.pangya.networking.protocol.readPString

class CreateRoomPacketHandler : ClientPacketHandler {
Expand All @@ -19,9 +21,9 @@ class CreateRoomPacketHandler : ClientPacketHandler {
val roomTypeId = packet.readByte()
val roomType = RoomType.forId(roomTypeId)
val holeCount = packet.readByte()
val course = Course.forId(packet.readByte())
val course = courseById(packet.readByte())
val holeModeId = packet.readByte()
val holeMode = HoleMode.forId(holeModeId)
val holeMode = holeModeById(holeModeId)
val unknown3 = packet.readIntLE()
val name = packet.readPString()
val password = packet.readPString()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import work.fking.pangya.game.room.RoomShotTimeChange
import work.fking.pangya.game.room.RoomType
import work.fking.pangya.game.room.RoomTypeChange
import work.fking.pangya.game.room.RoomUpdate
import work.fking.pangya.game.room.courseById
import work.fking.pangya.game.room.holeModeById
import work.fking.pangya.networking.protocol.readPString

class RoomSettingsUpdatePacketHandler : ClientPacketHandler {
Expand All @@ -36,9 +38,9 @@ class RoomSettingsUpdatePacketHandler : ClientPacketHandler {
0 -> RoomNameChange(packet.readPString())
1 -> RoomPasswordChange(packet.readPString())
2 -> RoomTypeChange(RoomType.forId(packet.readByte()))
3 -> RoomCourseChange(Course.forId(packet.readByte()))
3 -> RoomCourseChange(courseById(packet.readByte()))
4 -> RoomHoleCountChange(packet.readByte().toInt())
5 -> RoomHoleModeChange(HoleMode.forId(packet.readByte()))
5 -> RoomHoleModeChange(holeModeById(packet.readByte()))
6 -> RoomShotTimeChange(packet.readUnsignedByte().toInt() * 1000) // client sends in seconds, need ms
7 -> RoomPlayerCountChange(packet.readUnsignedByte().toInt())
8 -> RoomGameTimeChange(packet.readUnsignedByte().toInt() * 60 * 1000) // client sends in minutes, need ms
Expand Down
Loading

0 comments on commit 6cd6755

Please sign in to comment.