From f7c8f08b66dc4f855a330026e5a3b1346f37a541 Mon Sep 17 00:00:00 2001 From: Hexagon Date: Fri, 11 Aug 2023 20:04:16 -0300 Subject: [PATCH] persistence: promote pang/cookie balance to long --- database/migrations/V0001__base-schema.sql | 10 +++--- .../packet/outbound/CookieBalancePacket.kt | 4 +-- .../game/packet/outbound/MatchReplies.kt | 4 +-- .../game/packet/outbound/PangBalancePacket.kt | 4 +-- .../game/persistence/PlayerRepository.kt | 4 +-- .../game/persistence/jooq/tables/Account.kt | 10 +++--- .../jooq/tables/records/AccountRecord.kt | 34 +++++++++---------- .../fking/pangya/game/player/PlayerWallet.kt | 4 +-- .../work/fking/pangya/game/room/RoomPlayer.kt | 4 +-- .../game/room/match/PracticeMatchDirector.kt | 4 +-- .../pangya/game/task/ChangeClubSetStatTask.kt | 4 +-- 11 files changed, 43 insertions(+), 43 deletions(-) diff --git a/database/migrations/V0001__base-schema.sql b/database/migrations/V0001__base-schema.sql index 4a521bc..67cbd6b 100644 --- a/database/migrations/V0001__base-schema.sql +++ b/database/migrations/V0001__base-schema.sql @@ -1,11 +1,11 @@ CREATE TABLE account ( uid serial PRIMARY KEY, - uuid uuid NOT NULL, - username text NOT NULL, + uuid uuid NOT NULL, + username text NOT NULL, nickname text, - password bytea NOT NULL, - pang_balance int NOT NULL, - cookie_balance int NOT NULL, + password bytea NOT NULL, + pang_balance bigint NOT NULL, + cookie_balance bigint NOT NULL, created_at timestamptz DEFAULT NOW() ); diff --git a/game-server/src/main/kotlin/work/fking/pangya/game/packet/outbound/CookieBalancePacket.kt b/game-server/src/main/kotlin/work/fking/pangya/game/packet/outbound/CookieBalancePacket.kt index 59df46b..0f16ba2 100644 --- a/game-server/src/main/kotlin/work/fking/pangya/game/packet/outbound/CookieBalancePacket.kt +++ b/game-server/src/main/kotlin/work/fking/pangya/game/packet/outbound/CookieBalancePacket.kt @@ -5,13 +5,13 @@ import work.fking.pangya.game.player.Player import work.fking.pangya.networking.protocol.OutboundPacket class CookieBalancePacket( - private val balance: Int + private val balance: Long ) : OutboundPacket { constructor(player: Player) : this(player.wallet.cookieBalance) override fun encode(buffer: ByteBuf) { buffer.writeShortLE(0x96) - buffer.writeLongLE(balance.toLong()) + buffer.writeLongLE(balance) } } diff --git a/game-server/src/main/kotlin/work/fking/pangya/game/packet/outbound/MatchReplies.kt b/game-server/src/main/kotlin/work/fking/pangya/game/packet/outbound/MatchReplies.kt index ecc283f..a599e61 100644 --- a/game-server/src/main/kotlin/work/fking/pangya/game/packet/outbound/MatchReplies.kt +++ b/game-server/src/main/kotlin/work/fking/pangya/game/packet/outbound/MatchReplies.kt @@ -218,8 +218,8 @@ object MatchReplies { buffer.writeByte(player.currentHole) // hole buffer.writeByte(3) // total strokes? buffer.writeIntLE(-1) // score - buffer.writeLongLE(player.pang.toLong()) // pang - buffer.writeLongLE(player.bonusPang.toLong()) // bonus pang + buffer.writeLongLE(player.pang) // pang + buffer.writeLongLE(player.bonusPang) // bonus pang buffer.writeByte(1) // finished the hole, 1 or 0 not } } diff --git a/game-server/src/main/kotlin/work/fking/pangya/game/packet/outbound/PangBalancePacket.kt b/game-server/src/main/kotlin/work/fking/pangya/game/packet/outbound/PangBalancePacket.kt index 7d03497..7a0d0af 100644 --- a/game-server/src/main/kotlin/work/fking/pangya/game/packet/outbound/PangBalancePacket.kt +++ b/game-server/src/main/kotlin/work/fking/pangya/game/packet/outbound/PangBalancePacket.kt @@ -5,13 +5,13 @@ import work.fking.pangya.game.player.Player import work.fking.pangya.networking.protocol.OutboundPacket class PangBalancePacket( - private val balance: Int + private val balance: Long ) : OutboundPacket { constructor(player: Player) : this(player.wallet.pangBalance) override fun encode(buffer: ByteBuf) { buffer.writeShortLE(0xc8) - buffer.writeLongLE(balance.toLong()) + buffer.writeLongLE(balance) } } diff --git a/game-server/src/main/kotlin/work/fking/pangya/game/persistence/PlayerRepository.kt b/game-server/src/main/kotlin/work/fking/pangya/game/persistence/PlayerRepository.kt index f72aa16..e6eff30 100644 --- a/game-server/src/main/kotlin/work/fking/pangya/game/persistence/PlayerRepository.kt +++ b/game-server/src/main/kotlin/work/fking/pangya/game/persistence/PlayerRepository.kt @@ -28,8 +28,8 @@ class JooqPlayerRepository : PlayerRepository { .where(ACCOUNT.UID.eq(playerUid)) .fetchOne { PlayerWallet( - pangBalance = it[ACCOUNT.PANG_BALANCE] as Int, - cookieBalance = it[ACCOUNT.COOKIE_BALANCE] as Int + pangBalance = it[ACCOUNT.PANG_BALANCE] as Long, + cookieBalance = it[ACCOUNT.COOKIE_BALANCE] as Long ) } return wallet ?: throw IllegalStateException("could not load player wallet for playerUid=$playerUid") diff --git a/game-server/src/main/kotlin/work/fking/pangya/game/persistence/jooq/tables/Account.kt b/game-server/src/main/kotlin/work/fking/pangya/game/persistence/jooq/tables/Account.kt index d9aeab5..2b97ed3 100644 --- a/game-server/src/main/kotlin/work/fking/pangya/game/persistence/jooq/tables/Account.kt +++ b/game-server/src/main/kotlin/work/fking/pangya/game/persistence/jooq/tables/Account.kt @@ -95,12 +95,12 @@ open class Account( /** * The column public.account.pang_balance. */ - val PANG_BALANCE: TableField = createField(DSL.name("pang_balance"), SQLDataType.INTEGER.nullable(false), this, "") + val PANG_BALANCE: TableField = createField(DSL.name("pang_balance"), SQLDataType.BIGINT.nullable(false), this, "") /** * The column public.account.cookie_balance. */ - val COOKIE_BALANCE: TableField = createField(DSL.name("cookie_balance"), SQLDataType.INTEGER.nullable(false), this, "") + val COOKIE_BALANCE: TableField = createField(DSL.name("cookie_balance"), SQLDataType.BIGINT.nullable(false), this, "") /** * The column public.account.created_at. @@ -152,16 +152,16 @@ open class Account( // ------------------------------------------------------------------------- // Row8 type methods // ------------------------------------------------------------------------- - override fun fieldsRow(): Row8 = super.fieldsRow() as Row8 + override fun fieldsRow(): Row8 = super.fieldsRow() as Row8 /** * Convenience mapping calling {@link SelectField#convertFrom(Function)}. */ - fun mapping(from: (Int?, java.util.UUID?, String?, String?, ByteArray?, Int?, Int?, OffsetDateTime?) -> U): SelectField = convertFrom(Records.mapping(from)) + fun mapping(from: (Int?, java.util.UUID?, String?, String?, ByteArray?, Long?, Long?, OffsetDateTime?) -> U): SelectField = convertFrom(Records.mapping(from)) /** * Convenience mapping calling {@link SelectField#convertFrom(Class, * Function)}. */ - fun mapping(toType: Class, from: (Int?, java.util.UUID?, String?, String?, ByteArray?, Int?, Int?, OffsetDateTime?) -> U): SelectField = convertFrom(toType, Records.mapping(from)) + fun mapping(toType: Class, from: (Int?, java.util.UUID?, String?, String?, ByteArray?, Long?, Long?, OffsetDateTime?) -> U): SelectField = convertFrom(toType, Records.mapping(from)) } diff --git a/game-server/src/main/kotlin/work/fking/pangya/game/persistence/jooq/tables/records/AccountRecord.kt b/game-server/src/main/kotlin/work/fking/pangya/game/persistence/jooq/tables/records/AccountRecord.kt index 8947cac..13fb91a 100644 --- a/game-server/src/main/kotlin/work/fking/pangya/game/persistence/jooq/tables/records/AccountRecord.kt +++ b/game-server/src/main/kotlin/work/fking/pangya/game/persistence/jooq/tables/records/AccountRecord.kt @@ -20,7 +20,7 @@ import work.fking.pangya.game.persistence.jooq.tables.Account * This class is generated by jOOQ. */ @Suppress("UNCHECKED_CAST") -open class AccountRecord private constructor() : UpdatableRecordImpl(Account.ACCOUNT), Record8 { +open class AccountRecord private constructor() : UpdatableRecordImpl(Account.ACCOUNT), Record8 { open var uid: Int? set(value): Unit = set(0, value) @@ -42,13 +42,13 @@ open class AccountRecord private constructor() : UpdatableRecordImpl = super.fieldsRow() as Row8 - override fun valuesRow(): Row8 = super.valuesRow() as Row8 + override fun fieldsRow(): Row8 = super.fieldsRow() as Row8 + override fun valuesRow(): Row8 = super.valuesRow() as Row8 override fun field1(): Field = Account.ACCOUNT.UID override fun field2(): Field = Account.ACCOUNT.UUID override fun field3(): Field = Account.ACCOUNT.USERNAME override fun field4(): Field = Account.ACCOUNT.NICKNAME override fun field5(): Field = Account.ACCOUNT.PASSWORD - override fun field6(): Field = Account.ACCOUNT.PANG_BALANCE - override fun field7(): Field = Account.ACCOUNT.COOKIE_BALANCE + override fun field6(): Field = Account.ACCOUNT.PANG_BALANCE + override fun field7(): Field = Account.ACCOUNT.COOKIE_BALANCE override fun field8(): Field = Account.ACCOUNT.CREATED_AT override fun component1(): Int? = uid override fun component2(): UUID = uuid override fun component3(): String = username override fun component4(): String? = nickname override fun component5(): ByteArray = password - override fun component6(): Int = pangBalance - override fun component7(): Int = cookieBalance + override fun component6(): Long = pangBalance + override fun component7(): Long = cookieBalance override fun component8(): OffsetDateTime? = createdAt override fun value1(): Int? = uid override fun value2(): UUID = uuid override fun value3(): String = username override fun value4(): String? = nickname override fun value5(): ByteArray = password - override fun value6(): Int = pangBalance - override fun value7(): Int = cookieBalance + override fun value6(): Long = pangBalance + override fun value7(): Long = cookieBalance override fun value8(): OffsetDateTime? = createdAt override fun value1(value: Int?): AccountRecord { @@ -116,12 +116,12 @@ open class AccountRecord private constructor() : UpdatableRecordImpl 2100 CONTROL -> 1700 ACCURACY -> 2400 @@ -54,7 +54,7 @@ class ChangeClubSetStatTask( persistenceCtx.playerRepository.saveWallet(tx, player.uid, wallet) persistenceCtx.inventoryRepository.saveItem(tx, player.uid, clubSet) } - player.writeAndFlush(ClubSetReplies.upgradeAck(type, stat.ordinal, itemUid, cost.toLong())) + player.writeAndFlush(ClubSetReplies.upgradeAck(type, stat.ordinal, itemUid, cost)) } private fun downgrade(clubSet: Item) {