-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
161 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
...ver/src/main/kotlin/work/fking/pangya/game/packet/handler/shop/ShopEnterUnknownHandler.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package work.fking.pangya.game.packet.handler.shop | ||
|
||
import io.netty.buffer.ByteBuf | ||
import work.fking.pangya.game.GameServer | ||
import work.fking.pangya.game.net.ClientPacketHandler | ||
import work.fking.pangya.game.packet.outbound.ShopReplies | ||
import work.fking.pangya.game.player.Player | ||
|
||
class ShopEnterUnknownHandler: ClientPacketHandler { | ||
override fun handle(server: GameServer, player: Player, packet: ByteBuf) { | ||
player.writeAndFlush(ShopReplies.shopUnknownReply()) | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
...-server/src/main/kotlin/work/fking/pangya/game/packet/handler/shop/ShopPurchaseHandler.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package work.fking.pangya.game.packet.handler.shop | ||
|
||
import io.netty.buffer.ByteBuf | ||
import io.netty.buffer.ByteBufUtil | ||
import org.slf4j.LoggerFactory | ||
import work.fking.pangya.game.GameServer | ||
import work.fking.pangya.game.model.IffType | ||
import work.fking.pangya.game.model.iffTypeFromId | ||
import work.fking.pangya.game.net.ClientPacketHandler | ||
import work.fking.pangya.game.packet.outbound.PurchaseFailedReason.ALREADY_HAVE_THAT_ITEM | ||
import work.fking.pangya.game.packet.outbound.ShopReplies | ||
import work.fking.pangya.game.player.Player | ||
import work.fking.pangya.game.task.ShopUnlockCharacterTask | ||
|
||
private val LOGGER = LoggerFactory.getLogger(ShopPurchaseHandler::class.java) | ||
|
||
class ShopPurchaseHandler : ClientPacketHandler { | ||
|
||
override fun handle(server: GameServer, player: Player, packet: ByteBuf) { | ||
println(ByteBufUtil.prettyHexDump(packet)) | ||
val rental = packet.readByte() | ||
val numOfItems = packet.readUnsignedShortLE() | ||
|
||
repeat(numOfItems) { | ||
val uid = packet.readIntLE() | ||
val iffId = packet.readIntLE() | ||
val rentalTime = packet.readUnsignedShortLE() | ||
val unknown = packet.readUnsignedShortLE() | ||
val quantity = packet.readIntLE() | ||
val pangCost = packet.readIntLE() | ||
val cookieCost = packet.readIntLE() | ||
val couponId = packet.readIntLE() | ||
|
||
when (iffTypeFromId(iffId)) { | ||
IffType.CHARACTER -> handleCharacterPurchase(server, player, iffId) | ||
else -> handleUnknownPurchase(player, iffId) | ||
} | ||
} | ||
} | ||
|
||
private fun handleCharacterPurchase(server: GameServer, player: Player, iffId: Int) { | ||
if (player.characterRoster.findByIffId(iffId) != null) { | ||
player.writeAndFlush(ShopReplies.purchaseFailed(ALREADY_HAVE_THAT_ITEM)) | ||
return | ||
} | ||
|
||
server.runTask( | ||
ShopUnlockCharacterTask( | ||
server.persistenceCtx, | ||
player, | ||
iffId | ||
) | ||
) | ||
} | ||
|
||
private fun handleUnknownPurchase(player: Player, iffId: Int) { | ||
LOGGER.warn("Player tried to purchase iffId={} type={} but we don't know how to handle it", iffId, iffTypeFromId(iffId)) | ||
player.writeAndFlush(ShopReplies.purchaseFailed()) | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
game-server/src/main/kotlin/work/fking/pangya/game/packet/outbound/ShopReplies.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package work.fking.pangya.game.packet.outbound | ||
|
||
import work.fking.pangya.game.packet.outbound.PurchaseFailedReason.GENERIC_ERROR | ||
import work.fking.pangya.game.player.PlayerWallet | ||
import work.fking.pangya.networking.protocol.OutboundPacket | ||
|
||
enum class PurchaseFailedReason(val code: Int) { | ||
GENERIC_ERROR(1), | ||
NOT_ENOUGH_PANG(2), | ||
WRONG_ITEM_CODE(3), | ||
ALREADY_HAVE_THAT_ITEM(4), | ||
CHECK_ITEM_TIME_LIMIT(9), // this is maybe when trying to rent an item that is already rented | ||
CHECK_SALE_TIMES(11) | ||
} | ||
|
||
object ShopReplies { | ||
|
||
fun purchaseFailed(reason: PurchaseFailedReason = GENERIC_ERROR): OutboundPacket { | ||
return OutboundPacket { buffer -> | ||
buffer.writeShortLE(0x68) | ||
buffer.writeIntLE(reason.code) // 1 = purchase failed, 2 = not enough pang, 3 = wrong item code, 4 = already have that item, 9 = check time limit of your item, 11 = please check sale times | ||
} | ||
} | ||
|
||
fun purchaseSuccessful(wallet: PlayerWallet): OutboundPacket { | ||
return OutboundPacket { buffer -> | ||
buffer.writeShortLE(0x68) | ||
buffer.writeIntLE(0) | ||
buffer.writeLongLE(wallet.pangBalance) | ||
buffer.writeLongLE(wallet.cookieBalance) | ||
} | ||
} | ||
|
||
fun shopUnknownReply(): OutboundPacket { | ||
return OutboundPacket { buffer -> | ||
buffer.writeShortLE(0x20e) | ||
buffer.writeIntLE(0) // maybe this is a timestamp to sync sales | ||
buffer.writeIntLE(0) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters