- update: schema now sets the skills column to prevent a crash
- update: frontend to only pass the session id - update: launcher to pass the session correctly - update: validate session response now returns the session id and user id to the requester - update: auth client based on session id instead of a jwt token
This commit is contained in:
@@ -20,6 +20,6 @@ RUN apk add --no-cache libssl3 libgcc
|
||||
|
||||
COPY --from=builder /usr/src/packet-service/target/release/packet-service /usr/local/bin/packet-service
|
||||
|
||||
EXPOSE 4000
|
||||
EXPOSE 29000
|
||||
|
||||
CMD ["packet-service"]
|
||||
@@ -119,6 +119,29 @@ pub(crate) enum ItemType {
|
||||
Zuly = 0x1F,
|
||||
}
|
||||
|
||||
impl ItemType {
|
||||
pub(crate) fn from_i32(value: i32) -> Option<ItemType> {
|
||||
match value {
|
||||
1 => Some(ItemType::ItemGoggles),
|
||||
2 => Some(ItemType::ItemHelmet),
|
||||
3 => Some(ItemType::ItemArmor),
|
||||
4 => Some(ItemType::ItemGauntlet),
|
||||
5 => Some(ItemType::ItemBoots),
|
||||
6 => Some(ItemType::ItemBackpack),
|
||||
7 => Some(ItemType::ItemRing),
|
||||
8 => Some(ItemType::ItemWeaponR),
|
||||
9 => Some(ItemType::ItemWeaponL),
|
||||
10 => Some(ItemType::ItemConsumable),
|
||||
11 => Some(ItemType::ItemEtcGem),
|
||||
12 => Some(ItemType::ItemEtc),
|
||||
13 => Some(ItemType::ItemEtc2),
|
||||
14 => Some(ItemType::ItemRiding),
|
||||
0x1F => Some(ItemType::Zuly),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mod party_req {
|
||||
#[repr(u8)]
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
|
||||
@@ -140,7 +140,7 @@ pub(crate) async fn handle_login_req(
|
||||
debug!("{:?}", data);
|
||||
|
||||
let mut auth_client = auth_client.lock().await;
|
||||
match auth_client.login_token(&data.token.0).await {
|
||||
match auth_client.validate_session(&data.token.0).await {
|
||||
Ok(response) => {
|
||||
if response.valid == false {
|
||||
info!("Login failed: Invalid credentials");
|
||||
@@ -158,7 +158,7 @@ pub(crate) async fn handle_login_req(
|
||||
|
||||
if let Some(mut state) = connection_service.get_connection_mut(&connection_id) {
|
||||
state.user_id = Some(response.user_id.parse().unwrap());
|
||||
state.session_id = Some(response.session_id);
|
||||
state.session_id = Some(response.session_id.parse().unwrap());
|
||||
}
|
||||
|
||||
let consul_url =
|
||||
|
||||
@@ -3,6 +3,7 @@ use crate::character_client::CharacterClient;
|
||||
use crate::connection_service::ConnectionService;
|
||||
use crate::dataconsts::*;
|
||||
use crate::enums;
|
||||
use crate::enums::ItemType;
|
||||
use crate::packet::{send_packet, Packet, PacketPayload};
|
||||
use crate::packet_type::PacketType;
|
||||
use crate::packets::*;
|
||||
@@ -16,7 +17,7 @@ use tonic::{Code, Status};
|
||||
use tracing::{debug, error, info, warn};
|
||||
use utils::null_string::NullTerminatedString;
|
||||
|
||||
pub(crate) fn convert_slot(slot: i32) -> srv_char_list_reply::EquippedPosition {
|
||||
pub(crate) fn convert_slot_to_equip_slot(slot: i32) -> srv_char_list_reply::EquippedPosition {
|
||||
match enums::EquippedPosition::from_i32(slot) {
|
||||
Some(enums::EquippedPosition::Goggles) => srv_char_list_reply::EquippedPosition::Googles,
|
||||
Some(enums::EquippedPosition::Helmet) => srv_char_list_reply::EquippedPosition::Helmet,
|
||||
@@ -30,6 +31,34 @@ pub(crate) fn convert_slot(slot: i32) -> srv_char_list_reply::EquippedPosition {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn convert_slot_to_body_part(slot: i32) -> usize {
|
||||
match enums::EquippedPosition::from_i32(slot) {
|
||||
Some(enums::EquippedPosition::Goggles) => 6,
|
||||
Some(enums::EquippedPosition::Helmet) => 2,
|
||||
Some(enums::EquippedPosition::Armor) => 3,
|
||||
Some(enums::EquippedPosition::Backpack) => 7,
|
||||
Some(enums::EquippedPosition::Gauntlet) => 4,
|
||||
Some(enums::EquippedPosition::Boots) => 5,
|
||||
Some(enums::EquippedPosition::WeaponR) => 8,
|
||||
Some(enums::EquippedPosition::WeaponL) => 9,
|
||||
_ => 12,
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn convert_type_to_body_part(slot: i32) -> ItemType {
|
||||
match enums::EquippedPosition::from_i32(slot) {
|
||||
Some(enums::EquippedPosition::Goggles) => ItemType::ItemGoggles,
|
||||
Some(enums::EquippedPosition::Helmet) => ItemType::ItemHelmet,
|
||||
Some(enums::EquippedPosition::Armor) => ItemType::ItemArmor,
|
||||
Some(enums::EquippedPosition::Backpack) => ItemType::ItemBackpack,
|
||||
Some(enums::EquippedPosition::Gauntlet) => ItemType::ItemGauntlet,
|
||||
Some(enums::EquippedPosition::Boots) => ItemType::ItemBoots,
|
||||
Some(enums::EquippedPosition::WeaponR) => ItemType::ItemWeaponR,
|
||||
Some(enums::EquippedPosition::WeaponL) => ItemType::ItemWeaponL,
|
||||
_ => ItemType::None,
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) async fn handle_char_list_req(
|
||||
stream: &mut TcpStream,
|
||||
packet: Packet,
|
||||
@@ -64,7 +93,7 @@ pub(crate) async fn handle_char_list_req(
|
||||
|
||||
for item in character.items {
|
||||
if item.slot < MAX_VISIBLE_ITEMS as i32 {
|
||||
let slot = convert_slot(item.slot) as usize;
|
||||
let slot = convert_slot_to_equip_slot(item.slot) as usize;
|
||||
item_list[slot] = EquippedItem {
|
||||
id: item.item_id as u16,
|
||||
gem_opt: item.gem_option as u16,
|
||||
@@ -244,6 +273,7 @@ pub(crate) async fn handle_select_char_req(
|
||||
|
||||
let character = character_data.character.unwrap_or_default();
|
||||
|
||||
let name = NullTerminatedString(character.name.clone());
|
||||
let looks = character.looks.unwrap();
|
||||
let position = character.position.unwrap();
|
||||
let stats = character.stats.unwrap();
|
||||
@@ -253,22 +283,23 @@ pub(crate) async fn handle_select_char_req(
|
||||
core::array::from_fn(|i| EquippedItem::default());
|
||||
let mut inventory: [srv_inventory_data::Item; (MAX_ITEMS as usize)] =
|
||||
core::array::from_fn(|i| srv_inventory_data::Item::default());
|
||||
let mut skill_list: [u16; (MAX_SKILL_COUNT as usize)] = core::array::from_fn(|i| {
|
||||
if i < skills.len() {
|
||||
return skills[i] as u16;
|
||||
}
|
||||
0
|
||||
});
|
||||
let mut skill_list: [u16; (MAX_SKILL_COUNT as usize)] = [0u16; MAX_SKILL_COUNT as usize];
|
||||
|
||||
for index in 0..skills.len() {
|
||||
skill_list[index] = skills[index].id as u16;
|
||||
}
|
||||
|
||||
for item in items {
|
||||
if item.slot < MAX_VISIBLE_ITEMS as i32 {
|
||||
let slot = convert_slot(item.slot) as usize;
|
||||
equipped_item_list[slot] = EquippedItem {
|
||||
id: item.item_id as u16,
|
||||
gem_opt: item.gem_option as u16,
|
||||
socket: item.socket as i8,
|
||||
grade: item.grade as u8,
|
||||
};
|
||||
let slot = convert_type_to_body_part(item.slot) as usize - 2;
|
||||
if slot >= 0 {
|
||||
equipped_item_list[slot] = EquippedItem {
|
||||
id: item.item_id as u16,
|
||||
gem_opt: item.gem_option as u16,
|
||||
socket: item.socket as i8,
|
||||
grade: item.grade as u8,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
inventory[item.slot as usize] = srv_inventory_data::Item {
|
||||
@@ -337,8 +368,9 @@ pub(crate) async fn handle_select_char_req(
|
||||
skills: skill_list,
|
||||
hotbar: hotbar_list,
|
||||
tag: user_id as u32,
|
||||
name: request.name,
|
||||
name,
|
||||
};
|
||||
debug!("{:?}", data);
|
||||
let response_packet = Packet::new(PacketType::PakwcSelectCharReply, &data)?;
|
||||
send_packet(stream, &response_packet).await?;
|
||||
|
||||
|
||||
@@ -14,14 +14,18 @@ pub struct Packet {
|
||||
}
|
||||
|
||||
pub trait PacketPayload {
|
||||
fn encode(&self) -> Result<Vec<u8>, Box<dyn std::error::Error + Send + Sync>> where Self: Encode {
|
||||
fn encode(&self) -> Result<Vec<u8>, Box<dyn std::error::Error + Send + Sync>>
|
||||
where
|
||||
Self: Encode,
|
||||
{
|
||||
let config = bincode::config::standard().with_fixed_int_encoding();
|
||||
Ok(bincode::encode_to_vec(self, config)?)
|
||||
}
|
||||
|
||||
fn decode(data: &[u8]) -> Result<Self, Box<dyn std::error::Error + Send + Sync>>
|
||||
where
|
||||
Self: Sized, Self: Decode<()>
|
||||
Self: Sized,
|
||||
Self: Decode<()>,
|
||||
{
|
||||
let config = bincode::config::standard().with_fixed_int_encoding();
|
||||
Ok(bincode::decode_from_slice(data, config)?.0)
|
||||
@@ -107,7 +111,7 @@ impl Packet {
|
||||
|
||||
pub async fn send_packet(stream: &mut TcpStream, packet: &Packet) -> Result<(), std::io::Error> {
|
||||
let data = packet.to_raw();
|
||||
debug!("Sending data: {:?}", data);
|
||||
debug!("Sending '{:#X}' bytes of data. {:?}", data.len(), data);
|
||||
stream.write_all(&data).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
use bincode::{Decode, Encode};
|
||||
use std::time::Duration;
|
||||
|
||||
// `HotbarItem` structure converted to Rust.
|
||||
#[derive(Debug, Clone, Copy, Encode, Decode, Default)]
|
||||
@@ -18,8 +17,7 @@ pub(crate) struct Skill {
|
||||
// `StatusEffect` structure converted to Rust.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Encode, Decode, Default)]
|
||||
pub(crate) struct StatusEffect {
|
||||
expired: Duration,
|
||||
expired: u32,
|
||||
value: u16,
|
||||
unknown: u16,
|
||||
dt: Duration,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user