Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ jobs:

steps:
- uses: actions/checkout@v3
- name: Init submodule
run: git submodule update --init --recursive
- name: Build
run: cargo build --verbose
- name: Run tests
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
target/
Cargo.lock
Cargo.lock
db.polo
db.polo.wal
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "evenio"]
path = evenio
url = https://github.com/jidoc01/evenio.git
30 changes: 25 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,26 @@
[workspace]
[package]
name = "RustyDO"
version = "0.1.0"
edition = "2021"
authors = ["Jung Hyun Kim <jidoc01@gmail.com>"]
readme = "README.md"
repository = "https://github.com/jidoc01/RustyDO"

members = [
"server",
"crypt",
]
[dependencies]
#evenio = { version = "0.3.0", features = ["rayon"] }
evenio = { path = "./evenio", features = ["rayon"] }
tokio = { version = "1.36.0", features = ["full"] }
polodb_core = "4.4.0"
serde = "1.0.196"
pwhash = "1"
anyhow = "1.0.79"
bytes = "1.5.0"
byteorder = "1.5.0"
encoding = "0.2.33"
lazy_static = "1.4.0"
ignore-result = "0.2.0"
ctrlc = "3.4.2"
rayon = "1.9.0"
tracing-subscriber = "0.3.18"
log = "0.4.21"
rand = "0.8.5"
1 change: 1 addition & 0 deletions evenio
Submodule evenio added at 9e7eed
6 changes: 6 additions & 0 deletions old/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[workspace]

members = [
"server",
"crypt",
]
34 changes: 34 additions & 0 deletions old/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[server]
# A password which is used when servers communicate with each other.
# If it is empty, then it is filled with a random string to prevent attack.
password = ""
use_auto_account= true
# TODO
max_users = 1000
# TODO
tick_per_second = 20


[user]
initial_level = 1
initial_money = 999999999


[message]
notice = '''
[디지몬 온라인 v1.5 프리서버 CBT]

안녕하세요, 테이머 여러분.
즐거운 CBT를 위해 몇 가지 안내드릴 사항이 있어, 아래와 같이 공지드립니다.

· 게임머니는 충분히 많이 지급되오니 아이템을 적극 사용해 주세요.
· 일부 기능들은 미구현입니다: 게시판, 랭킹, 사용자 간 DM.
해당 기능들은 인게임과 무관한 관계로, 차후 개발 예정입니다.
· 인게임에서의 일부 구현 (동글몬 및 아이템 드롭)은, 당시의 정보가 부족한 관계로
아직 완전히 재현되지 않았습니다. 충분한 정보가 모이는 대로 재현될 것입니다.
· 10분 간 아무런 행동을 취하지 않으면 접속 종료됩니다.

감사합니다.

지덕.
'''
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
7 changes: 7 additions & 0 deletions src/constants.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@



pub const HEADER_SIZE: usize = 9;
pub const TAIL_SIZE: usize = 3;

pub const BODY_MAGIC_STAMP: u32 = 0x12345678;
73 changes: 73 additions & 0 deletions src/encrypt/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
mod rc4;

use crate::*;

use crate::constants::HEADER_SIZE;

const BODY_CRYPTO_SIZE: usize = 16;

lazy_static::lazy_static! {
static ref BODY_CRYPTO_KEY: Vec<u8> = {
let mut key = b"\xf6\xef\x8b\xa1\x5c".to_vec();
let mut salt = b"\x00".repeat(BODY_CRYPTO_SIZE - key.len());
key.append(&mut salt);
key
};
}

#[inline]
pub fn encrypt_body<T: AsMut<[u8]>>(mut body: T) {
rc4::transfer(&mut body, BODY_CRYPTO_KEY.as_slice());
}

#[inline]
pub fn encrypt_header<T: AsMut<[u8]>>(mut header: T) {
let header = header.as_mut();

let len = header.len();
if len != HEADER_SIZE {
panic!("Invalid header size: {}", len);
}

let key = header[HEADER_SIZE - 1];
assert!(key < 8, "Invalid key: {}", key);

(0 .. len - 1)
.into_par_iter()
.map(|i| {
(header[i] >> key) | (header[(i + 8 - 1) % 8] << (8 - key))
})
.enumerate()
.collect::<Vec<_>>()
.iter()
.for_each(|(i, v)| {
header[*i] = *v;
});
}

#[inline]
pub fn decrypt_header<T: AsMut<[u8]>>(mut header: T) {
let header = header.as_mut();

let len = header.len();
if len != HEADER_SIZE {
panic!("Invalid header size: {}", len);
}

let key = header[HEADER_SIZE - 1];
if key >= 8 {
// TODO: kick the client who is using an invalid key.
return;
}

(0 .. len - 1)
.map(|i| {
(header[i] << key) | (header[(i + 1) % 8] >> (8 - key))
})
.enumerate()
.collect::<Vec<_>>()
.iter()
.for_each(|(i, v)| {
header[*i] = *v;
});
}
34 changes: 34 additions & 0 deletions src/encrypt/rc4.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#[inline]
pub fn transfer<T, U> (mut data: T, key: U) where T: AsMut<[u8]>, U: AsRef<[u8]>{
let mut state = gen_state(key.as_ref());
transfer_aux(data.as_mut(), &mut state);
}

#[inline]
fn gen_state(key: &[u8]) -> [u8; 256] {
let mut state = [0u8; 256];
for i in 0..256 {
state[i] = i as u8;
}

let mut j = 0usize;
for i in 0..256 {
j = (j + state[i] as usize + key[i % key.len()] as usize) % 256;
state.swap(i, j);
}

state
}

#[inline]
fn transfer_aux(data: &mut [u8], state: &mut [u8; 256]) {
let mut i = 0usize;
let mut j = 0usize;
for byte in data.iter_mut() {
i = (i + 1) % 256;
j = (j + state[i] as usize) % 256;
state.swap(i, j);
let k = state[(state[i] as usize + state[j] as usize) % 256];
*byte ^= k;
}
}
55 changes: 55 additions & 0 deletions src/login/bulletin/board.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
use crate::login::*;

/*
const BULLETIN_TEXT: &str = "Welcome to the server!";
const TICKER_TEXT: &str = "Welcome to the server!";

#[derive(Resource)]
pub struct ResBulletinBoard {
bulletin_text: String,
ticker_text: String,
bulletin_pkt: Arc<dyn OutPacketBuildable + Send + Sync>,
ticker_pkt: Arc<dyn OutPacketBuildable + Send + Sync>,
}

impl ResBulletinBoard {
pub fn bulletin_pkt(&self) -> Arc<dyn OutPacketBuildable + Send + Sync> {
self.bulletin_pkt.clone()
}

pub fn ticker_pkt(&self) -> Arc<dyn OutPacketBuildable + Send + Sync> {
self.ticker_pkt.clone()
}

pub fn update_bulletin_text(&mut self, text: String) {
self.bulletin_pkt = Arc::new(build_bulletin_info_packet(&text));
self.bulletin_text = text;
}

pub fn update_ticker_text(&mut self, text: String) {
self.ticker_pkt = Arc::new(build_ticker_message_packet(&text));
self.ticker_text = text;
}
}

impl Default for ResBulletinBoard {
fn default() -> Self {
Self {
bulletin_text: BULLETIN_TEXT.to_string(),
ticker_text: TICKER_TEXT.to_string(),
bulletin_pkt: Arc::new(build_bulletin_info_packet(BULLETIN_TEXT)),
ticker_pkt: Arc::new(build_ticker_message_packet(TICKER_TEXT)),
}
}
}

fn build_bulletin_info_packet(text: &str) -> impl OutPacketBuildable {
//todo!();
SetEncData {}
}

fn build_ticker_message_packet(text: &str) -> impl OutPacketBuildable {
//todo!();
SetEncData {}
}
*/
20 changes: 20 additions & 0 deletions src/login/bulletin/greet.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
use crate::login::*;

/*

pub fn system_greet_client_on_bulletin(
q: Query<&ClientSessionJobSender, Added<ClientOnBulletinBoard>>,
board: Res<ResBulletinBoard>
) {
if q.is_empty() { return }
let bulletin_info_pkt = board.bulletin_pkt();
let ticker_pkt = board.ticker_pkt();
q
.par_iter()
.for_each(move |sender| {
sender.send_shared_packet(bulletin_info_pkt.clone());
sender.send_shared_packet(ticker_pkt.clone());
});
}

*/
8 changes: 8 additions & 0 deletions src/login/bulletin/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
mod greet;
mod board;

use crate::login::*;


pub fn init(world_helper: &mut WorldHelper) {
}
56 changes: 56 additions & 0 deletions src/login/component.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
use crate::{login::*, storage::account::Account};

use super::{ClientJob, ClientSessionJob};

#[derive(Component)]
pub struct ClientJobReceiver(pub UnboundedReceiver<ClientJob>);

#[derive(Component)]
pub struct ClientSessionJobSender(pub UnboundedSender<ClientSessionJob>);

#[derive(Component)]
pub struct ClientAddr(pub SocketAddr);

#[derive(Component, Clone, PartialEq, Hash, PartialOrd, Eq, Ord)]
pub struct ClientUid(pub u16);

#[derive(Component, PartialEq, Hash, PartialOrd, Eq, Ord)]
pub struct ClientId(pub String);

#[derive(Component)]
pub struct ClientName(pub String);

#[derive(Component)]
pub struct ClientLevel(pub u32);

#[derive(Component)]
pub struct ClientAccount(pub Account);

#[derive(Component)]
pub struct ClientDisconnecting;

#[derive(Component)]
pub struct ClientOnBulletinBoard;

#[derive(Component)]
pub struct ClientOnLobby;

#[derive(Component)]
pub struct ClientOnRoom;

#[derive(Component)]
pub struct ClientOnGame;

impl ClientSessionJobSender {
pub fn send(&self, msg: ClientSessionJob) {
self.0.send(msg).ignore();
}

pub fn send_packet<T: OutPacketBuildable + 'static>(&self, pkt: T) {
self.send(ClientSessionJob::SendPacket(Arc::new(pkt)));
}

pub fn send_shared_packet(&self, pkt: Arc<dyn OutPacketBuildable + Send + Sync>) {
self.send(ClientSessionJob::SendPacket(pkt));
}
}
Loading