-
Notifications
You must be signed in to change notification settings - Fork 0
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
117 additions
and
3 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
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,51 @@ | ||
use crate::client_thread::ClientHandler; | ||
use crate::packets::to_client::CharSelectionInfo; | ||
use crate::packets::HandleablePacket; | ||
use async_trait::async_trait; | ||
use tracing::info; | ||
use l2_core::shared_packets::common::ReadablePacket; | ||
use l2_core::shared_packets::read::ReadablePacketBuffer; | ||
use l2_core::traits::handlers::{PacketHandler, PacketSender}; | ||
|
||
#[derive(Debug, Clone)] | ||
pub struct RestoreChar { | ||
char_slot: i32, | ||
} | ||
|
||
impl ReadablePacket for RestoreChar { | ||
const PACKET_ID: u8 = 0x7B; | ||
const EX_PACKET_ID: Option<u16> = None; | ||
fn read(data: &[u8]) -> anyhow::Result<Self> { | ||
let mut buffer = ReadablePacketBuffer::new(data.to_vec()); | ||
Ok(Self { | ||
char_slot: buffer.read_i32(), | ||
}) | ||
} | ||
} | ||
|
||
#[async_trait] | ||
impl HandleablePacket for RestoreChar { | ||
type HandlerType = ClientHandler; | ||
async fn handle(&self, handler: &mut Self::HandlerType) -> anyhow::Result<()> { | ||
//todo flood protection | ||
info!("Restore slot: {}", self.char_slot); | ||
handler.restore_char_by_slot_id(self.char_slot).await?; | ||
let sk = handler.get_session_key().ok_or(anyhow::anyhow!( | ||
"Error after char restoration, Session is missing" | ||
))?; | ||
let chars = handler.get_account_chars().ok_or(anyhow::anyhow!( | ||
"Programming error, seems like all chars dropped from the list during restoration" | ||
))?; | ||
let controller = handler.get_controller(); | ||
let user_name = &handler | ||
.user | ||
.as_ref() | ||
.ok_or(anyhow::anyhow!( | ||
"Programming error, or possible cheating: missing user in handler for char restoration" | ||
))? | ||
.username; | ||
let p = CharSelectionInfo::new(user_name, sk.get_play_session_id(), controller, chars)?; | ||
handler.send_packet(Box::new(p)).await?; | ||
Ok(()) | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
use l2_core::enums::CharDeletionFailReasons; | ||
use l2_core::shared_packets::write::SendablePacketBuffer; | ||
use macro_common::SendablePacketImpl; | ||
|
||
#[allow(unused)] | ||
#[derive(Debug, Clone, SendablePacketImpl)] | ||
pub struct CharDeleteFail { | ||
buffer: SendablePacketBuffer, | ||
} | ||
|
||
#[allow(unused)] | ||
impl CharDeleteFail { | ||
const PACKET_ID: u8 = 0x1E; | ||
const EX_PACKET_ID: Option<u16> = None; | ||
|
||
pub fn new(reason: CharDeletionFailReasons) -> anyhow::Result<Self> { | ||
let mut inst = Self { | ||
buffer: SendablePacketBuffer::new(), | ||
}; | ||
inst.buffer.write(Self::PACKET_ID)?; | ||
inst.buffer.write_i32(reason as i32)?; | ||
Ok(inst) | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#[repr(i32)] | ||
#[derive(Clone, Debug)] | ||
pub enum CharDeletionFailReasons { | ||
None, | ||
Unknown, | ||
PledgeMember, | ||
PledgeMaster, | ||
ProhibitCharDeletion, | ||
Commission, | ||
Mentor, | ||
Mentee, | ||
Mail, | ||
} |
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