fix login issue*
This commit is contained in:
@@ -59,7 +59,7 @@ defmodule Odinsea.Channel.Handler.Alliance do
|
||||
|
||||
# Handle deny separately
|
||||
if op == 22 do
|
||||
handle_deny_invite(client_pid, character_id, char_state, guild_id)
|
||||
handle_deny_invite(client_pid, char_state)
|
||||
else
|
||||
handle_alliance_op(op, packet, client_pid, character_id, char_state, guild_id)
|
||||
end
|
||||
@@ -255,8 +255,15 @@ defmodule Odinsea.Channel.Handler.Alliance do
|
||||
Also called when op == 22 in alliance operation.
|
||||
|
||||
Reference: AllianceHandler.DenyInvite()
|
||||
|
||||
## Parameters
|
||||
- client_pid: The client process ID
|
||||
- character_state: The character's current state (includes guild_id)
|
||||
"""
|
||||
def handle_deny_invite(client_pid, character_id, char_state, guild_id) do
|
||||
def handle_deny_invite(client_pid, character_state) do
|
||||
character_id = character_state.id
|
||||
guild_id = character_state.guild_id
|
||||
|
||||
# Get invited alliance ID
|
||||
# invited_alliance_id = World.Guild.get_invited_id(guild_id)
|
||||
|
||||
|
||||
@@ -2016,6 +2016,221 @@ defmodule Odinsea.Channel.Packets do
|
||||
|> Out.to_data()
|
||||
end
|
||||
|
||||
# =============================================================================
|
||||
# Buddy List Packets
|
||||
# =============================================================================
|
||||
|
||||
@doc """
|
||||
Updates the buddy list for a character.
|
||||
Ported from MaplePacketCreator.updateBuddylist()
|
||||
|
||||
## Parameters
|
||||
- buddy_list: List of buddy entries
|
||||
- deleted: Operation type (7 = update, or other values for different operations)
|
||||
"""
|
||||
def update_buddylist(buddy_list, deleted \\ 7) do
|
||||
packet = Out.new(Opcodes.lp_buddylist())
|
||||
|> Out.encode_byte(deleted)
|
||||
|> Out.encode_byte(length(buddy_list))
|
||||
|
||||
# Encode each buddy entry
|
||||
packet = Enum.reduce(buddy_list, packet, fn buddy, p ->
|
||||
p
|
||||
|> Out.encode_int(buddy.character_id)
|
||||
|> Out.encode_string(buddy.name, 13)
|
||||
|> Out.encode_byte(if buddy.visible, do: 0, else: 1)
|
||||
|> Out.encode_int(if buddy.channel == -1, do: -1, else: buddy.channel - 1)
|
||||
|> Out.encode_string(buddy.group || "ETC", 17)
|
||||
end)
|
||||
|
||||
# Padding ints for each buddy (always 0)
|
||||
packet = Enum.reduce(buddy_list, packet, fn _, p ->
|
||||
Out.encode_int(p, 0)
|
||||
end)
|
||||
|
||||
Out.to_data(packet)
|
||||
end
|
||||
|
||||
@doc """
|
||||
Sends a buddy request to a character.
|
||||
Ported from MaplePacketCreator.requestBuddylistAdd()
|
||||
|
||||
## Parameters
|
||||
- cid_from: Character ID sending the request
|
||||
- name_from: Name of character sending the request
|
||||
- level_from: Level of character sending the request
|
||||
- job_from: Job ID of character sending the request
|
||||
"""
|
||||
def request_buddylist_add(cid_from, name_from, level_from, job_from) do
|
||||
Out.new(Opcodes.lp_buddylist())
|
||||
|> Out.encode_byte(9)
|
||||
|> Out.encode_int(cid_from)
|
||||
|> Out.encode_string(name_from)
|
||||
|> Out.encode_int(level_from)
|
||||
|> Out.encode_int(job_from)
|
||||
|> Out.encode_int(cid_from)
|
||||
|> Out.encode_string(name_from, 13)
|
||||
|> Out.encode_byte(1)
|
||||
|> Out.encode_int(0)
|
||||
|> Out.encode_string("ETC", 16)
|
||||
|> Out.encode_short(1)
|
||||
|> Out.to_data()
|
||||
end
|
||||
|
||||
@doc """
|
||||
Sends a buddy list message/status code.
|
||||
Ported from MaplePacketCreator.buddylistMessage()
|
||||
|
||||
## Message codes:
|
||||
- 11: Buddy list full
|
||||
- 12: Target buddy list full
|
||||
- 13: Already registered as buddy
|
||||
- 14: Character not found
|
||||
- 15: Request sent
|
||||
- 17: You cannot add yourself as a buddy
|
||||
- 19: Already requested
|
||||
- 21: Cannot add GM to buddy list
|
||||
"""
|
||||
def buddylist_message(message_code) do
|
||||
Out.new(Opcodes.lp_buddylist())
|
||||
|> Out.encode_byte(message_code)
|
||||
|> Out.to_data()
|
||||
end
|
||||
|
||||
# =============================================================================
|
||||
# Party Packets
|
||||
# =============================================================================
|
||||
|
||||
@doc """
|
||||
Party creation confirmation packet.
|
||||
Ported from MaplePacketCreator.partyCreated()
|
||||
|
||||
## Parameters
|
||||
- party_id: The newly created party ID
|
||||
"""
|
||||
def party_created(party_id) do
|
||||
opcode_byte = if Odinsea.Constants.Game.gms?(), do: 10, else: 8
|
||||
|
||||
Out.new(Opcodes.lp_party_operation())
|
||||
|> Out.encode_byte(opcode_byte)
|
||||
|> Out.encode_int(party_id)
|
||||
|> Out.encode_int(999_999_999)
|
||||
|> Out.encode_int(999_999_999)
|
||||
|> Out.encode_long(0)
|
||||
|> Out.encode_byte(0)
|
||||
|> Out.encode_byte(1)
|
||||
|> Out.to_data()
|
||||
end
|
||||
|
||||
@doc """
|
||||
Party invitation packet (sent to invited player).
|
||||
Ported from MaplePacketCreator.partyInvite()
|
||||
|
||||
## Parameters
|
||||
- from_character: Character struct of the inviter (needs :party_id, :name, :level, :job)
|
||||
"""
|
||||
def party_invite(from_character) do
|
||||
party_id = from_character.party_id || 0
|
||||
|
||||
Out.new(Opcodes.lp_party_operation())
|
||||
|> Out.encode_byte(4)
|
||||
|> Out.encode_int(party_id)
|
||||
|> Out.encode_string(from_character.name)
|
||||
|> Out.encode_int(from_character.level)
|
||||
|> Out.encode_int(from_character.job)
|
||||
|> Out.encode_byte(0)
|
||||
|> Out.to_data()
|
||||
end
|
||||
|
||||
@doc """
|
||||
Party request packet (for request-to-join scenarios).
|
||||
Ported from MaplePacketCreator.partyRequestInvite()
|
||||
|
||||
## Parameters
|
||||
- from_character: Character struct of the requester (needs :id, :name, :level, :job)
|
||||
"""
|
||||
def party_request(from_character) do
|
||||
Out.new(Opcodes.lp_party_operation())
|
||||
|> Out.encode_byte(7)
|
||||
|> Out.encode_int(from_character.id)
|
||||
|> Out.encode_string(from_character.name)
|
||||
|> Out.encode_int(from_character.level)
|
||||
|> Out.encode_int(from_character.job)
|
||||
|> Out.to_data()
|
||||
end
|
||||
|
||||
@doc """
|
||||
Party status/error message packet.
|
||||
Ported from MaplePacketCreator.partyStatusMessage()
|
||||
|
||||
## Message codes:
|
||||
- 10: A beginner can't create a party
|
||||
- 11: Your request for a party didn't work due to an unexpected error
|
||||
- 13: You have yet to join a party
|
||||
- 16: Already have joined a party
|
||||
- 17: The party you're trying to join is already in full capacity
|
||||
- 19: Unable to find the requested character in this channel
|
||||
- 23: 'Char' have denied request to the party (with charname)
|
||||
|
||||
## Parameters
|
||||
- message_code: The status/error code
|
||||
- charname: Optional character name for personalized messages
|
||||
"""
|
||||
def party_status_message(message_code, charname \\ nil) do
|
||||
opcode_byte = if Odinsea.Constants.Game.gms?() and message_code >= 7,
|
||||
do: message_code + 2,
|
||||
else: message_code
|
||||
|
||||
packet = Out.new(Opcodes.lp_party_operation())
|
||||
|> Out.encode_byte(opcode_byte)
|
||||
|
||||
packet = if charname do
|
||||
Out.encode_string(packet, charname)
|
||||
else
|
||||
packet
|
||||
end
|
||||
|
||||
Out.to_data(packet)
|
||||
end
|
||||
|
||||
# =============================================================================
|
||||
# Guild Packets
|
||||
# =============================================================================
|
||||
|
||||
@doc """
|
||||
Guild invitation packet (sent to invited player).
|
||||
Ported from MaplePacketCreator.guildInvite()
|
||||
|
||||
## Parameters
|
||||
- guild_id: ID of the guild
|
||||
- from_name: Name of the character sending the invite
|
||||
- from_level: Level of the character sending the invite
|
||||
- from_job: Job ID of the character sending the invite
|
||||
"""
|
||||
def guild_invite(guild_id, from_name, from_level, from_job) do
|
||||
Out.new(Opcodes.lp_guild_operation())
|
||||
|> Out.encode_byte(0x05)
|
||||
|> Out.encode_int(guild_id)
|
||||
|> Out.encode_string(from_name)
|
||||
|> Out.encode_int(from_level)
|
||||
|> Out.encode_int(from_job)
|
||||
|> Out.to_data()
|
||||
end
|
||||
|
||||
@doc """
|
||||
Guild invitation denial packet.
|
||||
Ported from MaplePacketCreator.denyGuildInvitation()
|
||||
|
||||
## Parameters
|
||||
- charname: Name of the character who denied the invitation
|
||||
"""
|
||||
def deny_guild_invitation(charname) do
|
||||
Out.new(Opcodes.lp_guild_operation())
|
||||
|> Out.encode_byte(0x3D)
|
||||
|> Out.encode_string(charname)
|
||||
|> Out.to_data()
|
||||
end
|
||||
|
||||
# =============================================================================
|
||||
# Utility Functions
|
||||
# =============================================================================
|
||||
|
||||
@@ -108,6 +108,16 @@ defmodule Odinsea.Channel.Players do
|
||||
end
|
||||
end
|
||||
|
||||
@doc """
|
||||
Finds a player by name in the channel.
|
||||
Returns the player data or nil if not found.
|
||||
|
||||
This is the public API for player lookup by name.
|
||||
"""
|
||||
def find_by_name(name, _channel_id \\ nil) do
|
||||
get_player_by_name(name)
|
||||
end
|
||||
|
||||
@doc """
|
||||
Updates player data.
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user