kimi gone wild

This commit is contained in:
ra
2026-02-14 23:12:33 -07:00
parent bbd205ecbe
commit 0222be36c5
98 changed files with 39726 additions and 309 deletions

View File

@@ -1,6 +1,12 @@
defmodule Odinsea.Shop.Client do
@moduledoc """
Client connection handler for the cash shop server.
Handles:
- Cash shop operations (buy, gift, wishlist, etc.)
- MTS (Maple Trading System) operations
- Coupon redemption
- Inventory management
"""
use GenServer, restart: :temporary
@@ -8,8 +14,19 @@ defmodule Odinsea.Shop.Client do
require Logger
alias Odinsea.Net.Packet.In
alias Odinsea.Net.Opcodes
alias Odinsea.Shop.{Operation, MTS, Packets}
alias Odinsea.Database.Context
defstruct [:socket, :ip, :state, :character_id, :account_id]
defstruct [
:socket,
:ip,
:state,
:character_id,
:account_id,
:character,
:account
]
def start_link(socket) do
GenServer.start_link(__MODULE__, socket)
@@ -27,7 +44,9 @@ defmodule Odinsea.Shop.Client do
ip: ip_string,
state: :connected,
character_id: nil,
account_id: nil
account_id: nil,
character: nil,
account: nil
}
send(self(), :receive)
@@ -61,6 +80,10 @@ defmodule Odinsea.Shop.Client do
:ok
end
# ==============================================================================
# Packet Handling
# ==============================================================================
defp handle_packet(data, state) do
packet = In.new(data)
@@ -75,11 +98,98 @@ defmodule Odinsea.Shop.Client do
end
end
defp dispatch_packet(_opcode, _packet, state) do
# TODO: Implement cash shop packet handlers
state
defp dispatch_packet(opcode, packet, state) do
cond do
opcode == Opcodes.cp_player_loggedin() ->
handle_migrate_in(packet, state)
opcode == Opcodes.cp_cash_shop_update() ->
# Cash shop operations
handle_cash_shop_operation(packet, state)
opcode == Opcodes.cp_mts_operation() ->
# MTS operations
handle_mts_operation(packet, state)
opcode == Opcodes.cp_alive_ack() ->
# Ping response - ignore
state
true ->
Logger.debug("Unhandled cash shop opcode: 0x#{Integer.to_string(opcode, 16)}")
state
end
end
# ==============================================================================
# Migrate In Handler
# ==============================================================================
defp handle_migrate_in(packet, state) do
{char_id, packet} = In.decode_int(packet)
{_client_ip, _packet} = In.decode_string(packet) # Skip client IP
Logger.info("Cash shop migrate in for character #{char_id}")
# Load character and account
case Context.get_character(char_id) do
nil ->
Logger.error("Character #{char_id} not found")
:gen_tcp.close(state.socket)
state
character ->
case Context.get_account(character.account_id) do
nil ->
Logger.error("Account #{character.account_id} not found")
:gen_tcp.close(state.socket)
state
account ->
# Load gifts
gifts = Context.load_gifts(character.id)
character = %{character | cash_inventory: gifts ++ (character.cash_inventory || [])}
# Send cash shop setup
setup_packet = Packets.set_cash_shop(character)
:gen_tcp.send(state.socket, setup_packet)
# Send initial update
Operation.cs_update(state.socket, character)
%{state |
state: :in_cash_shop,
character_id: char_id,
account_id: account.id,
character: character,
account: account
}
end
end
end
# ==============================================================================
# Cash Shop Operation Handler
# ==============================================================================
defp handle_cash_shop_operation(packet, state) do
# Delegate to Operation module
Operation.handle(packet, state)
end
# ==============================================================================
# MTS Operation Handler
# ==============================================================================
defp handle_mts_operation(packet, state) do
# Delegate to MTS module
MTS.handle(packet, state)
end
# ==============================================================================
# Utility Functions
# ==============================================================================
defp format_ip({a, b, c, d}) do
"#{a}.#{b}.#{c}.#{d}"
end