Skip to content

Commit b57c106

Browse files
update
1 parent 1e47c88 commit b57c106

File tree

15 files changed

+129
-69
lines changed

15 files changed

+129
-69
lines changed

src/primary/crypto/header_crypt.rs

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ use sha1::Sha1;
44
use super::rc4::RC4;
55

66
const ENCRYPTION_KEY: [u8; 16] = [
7-
0xCC, 0x98, 0xAE, 0x04, 0xE8, 0x97, 0xEA, 0xCA, 0x12, 0xDD, 0xC0, 0x93, 0x42, 0x91, 0x53, 0x57
7+
0xCC, 0x98, 0xAE, 0x04, 0xE8, 0x97, 0xEA, 0xCA, 0x12, 0xDD, 0xC0, 0x93, 0x42, 0x91, 0x53, 0x57,
88
];
99

1010
const DECRYPTION_KEY: [u8; 16] = [
11-
0xC2, 0xB3, 0x72, 0x3C, 0xC6, 0xAE, 0xD9, 0xB5, 0x34, 0x3C, 0x53, 0xEE, 0x2F, 0x43, 0x67, 0xCE
11+
0xC2, 0xB3, 0x72, 0x3C, 0xC6, 0xAE, 0xD9, 0xB5, 0x34, 0x3C, 0x53, 0xEE, 0x2F, 0x43, 0x67, 0xCE,
1212
];
1313

1414
#[derive(Debug)]
@@ -18,18 +18,17 @@ pub struct HeaderEncryptor {
1818

1919
impl HeaderEncryptor {
2020
pub fn new(secret: &[u8]) -> Self {
21-
let mut encryptor = RC4::new(
22-
HmacSha::new(&ENCRYPTION_KEY, secret, Sha1::default()).compute_digest().to_vec()
23-
);
21+
let mut encryptor =
22+
RC4::new(&HmacSha::new(&ENCRYPTION_KEY, secret, Sha1::default()).compute_digest());
2423

25-
let _ = &encryptor.encrypt(&vec![0; 1024]);
24+
encryptor.encrypt(&mut vec![0; 1024]);
2625

2726
Self {
2827
_instance: encryptor,
2928
}
3029
}
3130

32-
pub fn encrypt(&mut self, data: &[u8]) -> Vec<u8> {
31+
pub fn encrypt(&mut self, data: &mut [u8]) {
3332
self._instance.encrypt(data)
3433
}
3534
}
@@ -41,18 +40,17 @@ pub struct HeaderDecryptor {
4140

4241
impl HeaderDecryptor {
4342
pub fn new(secret: &[u8]) -> Self {
44-
let mut decryptor = RC4::new(
45-
HmacSha::new(&DECRYPTION_KEY, secret, Sha1::default()).compute_digest().to_vec()
46-
);
43+
let mut decryptor =
44+
RC4::new(&HmacSha::new(&DECRYPTION_KEY, secret, Sha1::default()).compute_digest());
4745

48-
let _ = &decryptor.encrypt(&vec![0; 1024]);
46+
decryptor.encrypt(&mut vec![0; 1024]);
4947

5048
Self {
5149
_instance: decryptor,
5250
}
5351
}
5452

55-
pub fn decrypt(&mut self, data: &[u8]) -> Vec<u8> {
53+
pub fn decrypt(&mut self, data: &mut [u8]) {
5654
self._instance.encrypt(data)
5755
}
58-
}
56+
}

src/primary/crypto/rc4.rs

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ pub struct RC4 {
66
}
77

88
impl RC4 {
9-
pub fn new(key: Vec<u8>) -> Self {
9+
pub fn new(key: &[u8]) -> Self {
1010
assert!(!key.is_empty() && key.len() <= 256);
1111

1212
let mut state = [0u8; 256];
@@ -20,11 +20,7 @@ impl RC4 {
2020
state.swap(i, j as usize);
2121
}
2222

23-
Self {
24-
i: 0,
25-
j: 0,
26-
state,
27-
}
23+
Self { i: 0, j: 0, state }
2824
}
2925

3026
// prga
@@ -35,12 +31,9 @@ impl RC4 {
3531
self.state[(self.state[self.i as usize].wrapping_add(self.state[self.j as usize])) as usize]
3632
}
3733

38-
pub fn encrypt(&mut self, data: &[u8]) -> Vec<u8> {
39-
let mut encrypted = Vec::new();
40-
for x in data.iter() {
41-
encrypted.push(x ^ self.next());
34+
pub fn encrypt(&mut self, data: &mut [u8]) {
35+
for x in data.iter_mut() {
36+
*x ^= self.next();
4237
}
43-
44-
encrypted
4538
}
46-
}
39+
}

src/primary/server/mock_data.rs

Lines changed: 0 additions & 16 deletions
This file was deleted.

src/primary/server/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ pub use world_server::WorldServer;
44

55
mod auth;
66
mod login_server;
7-
mod mock_data;
87
mod movement;
98
mod player;
109
mod realm;

src/primary/server/player/bind_point_update.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use serde::{Deserialize, Serialize};
33
use tentacli_packet::WorldPacket;
44
use tentacli_traits::types::opcodes::Opcode;
55

6-
use crate::primary::server::mock_data::CurrentPlayer;
6+
use crate::primary::server::player::CurrentPlayer;
77
use crate::primary::traits::PacketHandler;
88
use crate::primary::types::{HandlerInput, HandlerOutput, HandlerResult};
99

src/primary/server/player/char_enum.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use tentacli_packet::WorldPacket;
44
use tentacli_traits::types::opcodes::Opcode;
55
use tentacli_traits::types::player::{Class, Gender, Race};
66

7-
use crate::primary::server::mock_data::CurrentPlayer;
7+
use crate::primary::server::player::CurrentPlayer;
88
use crate::primary::traits::PacketHandler;
99
use crate::primary::types::{HandlerInput, HandlerOutput, HandlerResult};
1010

src/primary/server/player/initial_spells.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,35 @@
11
use async_trait::async_trait;
2-
use serde::{Deserialize, Serialize};
2+
use serde::Serialize;
33
use tentacli_packet::WorldPacket;
44
use tentacli_traits::types::opcodes::Opcode;
5+
use tentacli_traits::types::spell::{CooldownInfo, Spell};
56

67
use crate::primary::traits::PacketHandler;
78
use crate::primary::types::{HandlerInput, HandlerOutput, HandlerResult};
89

9-
#[derive(WorldPacket, Serialize, Deserialize, Debug)]
10+
#[derive(WorldPacket, Serialize, Debug)]
1011
struct Outgoing {
1112
unknown: u8,
1213
spells_count: u16,
13-
spells: Vec<u8>,
14+
spells: Vec<Spell>,
1415
cooldowns_count: u16,
15-
cooldowns: Vec<u8>,
16+
cooldowns: Vec<CooldownInfo>,
1617
}
1718

1819
pub struct Handler;
1920
#[async_trait]
2021
impl PacketHandler for Handler {
2122
async fn handle(&mut self, _: &mut HandlerInput) -> HandlerResult {
23+
let spells = vec![
24+
Spell { spell_id: 6603 }, // auto attack
25+
];
26+
2227
Ok(vec![HandlerOutput::Data(
2328
Opcode::SMSG_INITIAL_SPELLS,
2429
Outgoing {
2530
unknown: 0,
26-
spells_count: 0,
27-
spells: vec![],
31+
spells_count: spells.len() as u16,
32+
spells,
2833
cooldowns_count: 0,
2934
cooldowns: vec![],
3035
}

src/primary/server/player/login_verify_world.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use serde::{Deserialize, Serialize};
33
use tentacli_packet::WorldPacket;
44
use tentacli_traits::types::opcodes::Opcode;
55

6-
use crate::primary::server::mock_data::CurrentPlayer;
6+
use crate::primary::server::player::CurrentPlayer;
77
use crate::primary::traits::PacketHandler;
88
use crate::primary::types::{HandlerInput, HandlerOutput, HandlerResult};
99

src/primary/server/player/mod.rs

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
use tentacli_traits::types::opcodes::Opcode;
22

3+
pub use player_spawn::UpdatePacket;
4+
35
use crate::primary::traits::Processor;
46
use crate::primary::types::{HandlerInput, ProcessorResult};
57

@@ -11,12 +13,33 @@ mod initial_spells;
1113
mod load_equipment_set;
1214
mod login_set_timespeed;
1315
mod login_verify_world;
14-
mod motd;
1516
mod played_time;
1617
mod player_spawn;
1718
mod set_buttons;
1819
mod time_synq_req;
1920

21+
#[non_exhaustive]
22+
pub struct CurrentPlayer;
23+
24+
#[allow(dead_code)]
25+
impl CurrentPlayer {
26+
pub const GUID: u64 = 123;
27+
pub const LEVEL: u8 = 80;
28+
pub const DISPLAY_ID: i32 = 49;
29+
30+
// pub const POS_X: f32 = 10349.6;
31+
pub const POS_X: f32 = 16226.1;
32+
// pub const POS_Y: f32 = -6357.29;
33+
pub const POS_Y: f32 = 16257.8;
34+
// pub const POS_Z: f32 = 33.4026;
35+
pub const POS_Z: f32 = 13.2474;
36+
37+
// pub const ZONE_ID: u32 = 3430;
38+
pub const ZONE_ID: u32 = 876;
39+
// pub const MAP_ID: u32 = 530;
40+
pub const MAP_ID: u32 = 1;
41+
}
42+
2043
pub struct PlayerProcessor;
2144
impl Processor for PlayerProcessor {
2245
fn get_handlers(input: &mut HandlerInput) -> ProcessorResult {
@@ -27,7 +50,6 @@ impl Processor for PlayerProcessor {
2750
Opcode::CMSG_PLAYER_LOGIN => {
2851
vec![
2952
Box::new(login_verify_world::Handler),
30-
Box::new(motd::Handler),
3153
Box::new(bind_point_update::Handler),
3254
Box::new(initial_spells::Handler),
3355
Box::new(set_buttons::Handler),

src/primary/server/player/player_spawn.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use tentacli_traits::types::update_data::{BlockType, ObjectTypeID, UpdateData};
1313
use tentacli_traits::types::update_fields::{FieldValue, ObjectField, PlayerField, UnitField};
1414
use tentacli_traits::types::update_fields::FieldValue::TwoShortsArray;
1515

16-
use crate::primary::server::mock_data::CurrentPlayer;
16+
use crate::primary::server::player::CurrentPlayer;
1717
use crate::primary::traits::PacketHandler;
1818
use crate::primary::types::{HandlerInput, HandlerOutput, HandlerResult};
1919

0 commit comments

Comments
 (0)