├── .gitignore ├── Cargo.lock ├── Cargo.toml ├── readme.md ├── src ├── app.rs ├── context.rs ├── handle.rs ├── lib.rs ├── logger.rs ├── main.rs ├── middleware.rs ├── request.rs ├── response.rs ├── route.rs └── server.rs └── wiki ├── begin.md ├── design.md ├── readme.md ├── requirement_zh.md └── some.md /.gitignore: -------------------------------------------------------------------------------- 1 | target 2 | .idea/ 3 | -------------------------------------------------------------------------------- /Cargo.lock: -------------------------------------------------------------------------------- 1 | [[package]] 2 | name = "leaf" 3 | version = "0.0.1" 4 | 5 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | edition = "2018" 3 | name = "leaf" 4 | version = "0.0.1" 5 | authors = ["wsc "] 6 | 7 | [dependencies] 8 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # A fast,safety,distributed game server framework for Rust 2 | Server is a fast, scalable game server framework for Rust. It provides the basic development framework and many related components, including libraries and tools. Server is also suitable for real-time web applications; its distributed architecture makes server scale better than other real-time web frameworks. 3 | 4 | # status (develop) 5 | ** don't use production ,it's experiment ** 6 | 7 | # Features 8 | * fast 9 | * safety 10 | * distributed 11 | 12 | # License 13 | (The MIT License) 14 | 15 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 16 | 17 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /src/app.rs: -------------------------------------------------------------------------------- 1 | use middleware::Middleware; 2 | 3 | pub struct App { 4 | data: Data, 5 | // router: Router, 6 | middleware: Vec + Send + Sync>>, 7 | } 8 | 9 | impl App{ 10 | fn new(){ 11 | App{ 12 | data:AppData::new(), 13 | middleware: Vec::new() 14 | } 15 | } 16 | } 17 | 18 | pub struct AppData { 19 | 20 | } 21 | 22 | 23 | -------------------------------------------------------------------------------- /src/context.rs: -------------------------------------------------------------------------------- 1 | use app::AppData; 2 | // 上下文 3 | pub struct Context{ 4 | data:Data, 5 | appData:AppData, 6 | } 7 | -------------------------------------------------------------------------------- /src/handle.rs: -------------------------------------------------------------------------------- 1 | 2 | // 处理器 3 | pub trait Handle: 'static { 4 | fn handle() {} 5 | } 6 | -------------------------------------------------------------------------------- /src/lib.rs: -------------------------------------------------------------------------------- 1 | mod app; 2 | mod context; 3 | mod middleware; 4 | mod request; 5 | mod response; 6 | mod route; 7 | mod handle; 8 | mod server; 9 | mod logger; 10 | -------------------------------------------------------------------------------- /src/logger.rs: -------------------------------------------------------------------------------- 1 | use middleware::Middleware; 2 | use request::Request; 3 | use context::Context; 4 | 5 | pub struct Logger{ 6 | 7 | } 8 | 9 | impl Logger{ 10 | fn new() -> Self { 11 | Logger{} 12 | } 13 | } 14 | 15 | impl Middleware for Logger{ 16 | fn handle(&self, req: &Request>) { 17 | println!(" Logger "); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/main.rs: -------------------------------------------------------------------------------- 1 | fn index(){ 2 | 3 | } 4 | 5 | 6 | fn main(){ 7 | 8 | 9 | 10 | 11 | } 12 | -------------------------------------------------------------------------------- /src/middleware.rs: -------------------------------------------------------------------------------- 1 | use response::Response; 2 | use request::Request; 3 | use context::Context; 4 | use std::result::Result; 5 | 6 | pub trait Middleware: 'static { 7 | fn handle(&self, req: &Request>) { 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/request.rs: -------------------------------------------------------------------------------- 1 | pub struct Request{ 2 | 3 | } 4 | -------------------------------------------------------------------------------- /src/response.rs: -------------------------------------------------------------------------------- 1 | pub struct Response{ 2 | body:Body 3 | } 4 | 5 | impl Response{ 6 | fn new() ->Self{ 7 | Response{ 8 | body:Body 9 | } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/route.rs: -------------------------------------------------------------------------------- 1 | use std::collections::HashMap; 2 | use std::hash::Hash; 3 | use handle::Handle; 4 | 5 | /// route 6 | pub trait Route where K: Hash, V: Handle { 7 | fn set(&mut self, K, V) {} 8 | fn get(&self, K) -> Option { 9 | Ok(V) 10 | } 11 | } 12 | 13 | /// default impl 14 | pub struct Router where V: Handle { 15 | inner: HashMap, 16 | } 17 | 18 | impl Router { 19 | fn new() { 20 | Router { 21 | inner: HashMap::new() 22 | } 23 | } 24 | } 25 | 26 | 27 | impl Route for Router { 28 | fn set(&mut self, k: K, v: V) { 29 | self.inner.insert(k, v) 30 | } 31 | 32 | fn get(&self, k: K) { 33 | self.inner.get(&k) 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/server.rs: -------------------------------------------------------------------------------- 1 | 2 | pub struct Server{ 3 | 4 | } 5 | 6 | impl Server{ 7 | 8 | fn start(){ 9 | 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /wiki/begin.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rust-game/gamesvr-rs/f0ed3951bc3c0de197093d5a8fc4ac5cc6100dfa/wiki/begin.md -------------------------------------------------------------------------------- /wiki/design.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rust-game/gamesvr-rs/f0ed3951bc3c0de197093d5a8fc4ac5cc6100dfa/wiki/design.md -------------------------------------------------------------------------------- /wiki/readme.md: -------------------------------------------------------------------------------- 1 | #this is wiki 2 | 3 | #中文 4 | ** url ** 5 | 6 | #english 7 | 8 | ** url ** -------------------------------------------------------------------------------- /wiki/requirement_zh.md: -------------------------------------------------------------------------------- 1 | 2 | # 传输协议支持 3 | * TCP 4 | * UDP 5 | * HTTP 6 | * HTTP2.0 7 | * WebSocket (仅用于 页游) 8 | 9 | # 传输数据格式支持 10 | * Json (仅用于 页游) 11 | * protobuf 12 | * 13 | 14 | # 数据库支持 15 | * mysql 16 | * redis 17 | * mongodb 18 | * postgresql(最后实现) 19 | 20 | # 传输数据处理 21 | * 加密 解密 22 | * 压缩 解压 23 | 24 | -------------------------------------------------------------------------------- /wiki/some.md: -------------------------------------------------------------------------------- 1 | #关于设计的理论 2 | 3 | # Context (Session+Request+Response+errInfo) 4 | 贯穿一次请求的的上下文 5 | 每次请求过来都会初始化一个全新的 6 | 一个全局的错误信息载体 7 | #Session 8 | 贯穿一次用户登录后的数据 -- 9 | 这个数据不能直接保存在内存中 10 | 考虑速度 感觉也不能写文件 这个是否需要有待确认 11 | 设计出来 写端实现redis方式 确保速度 12 | 13 | #Request 14 | 贯穿一次请求的的请求端的数据 15 | 实现从传输层读出数据 16 | 17 | #Response 18 | 贯穿一次请求的响应存储的内容 19 | 实现一个写数据到传输层 20 | 21 | #Transfer 22 | 传输层 23 | 24 | #Route 25 | 路由规则 对外只有唯一的接入口 ip:port 结构 26 | 通常是hash [int]Action这种高效结构 客户端和服务端功能 27 | 一一对应的所以不需要复杂的路由保证速度 28 | 参数由内容携带 29 | 30 | #Action 31 | 是一个请求的最小单位 通常处理一个请求的码 32 | 33 | #Module 模块 34 | 是一堆Action的集合 通常一类功能 比如登录模块的方法集合 35 | 单个服务(线程)的最小单位 36 | 同一个Module可以运行到很多服务器 同一action转发需要Gate 37 | 38 | #Server 39 | 服务的最小单位 40 | 包含一个或者多个Module 41 | 唯一ip:port 需要向Gate注册 提供那些Action的服务 42 | 43 | #Gate 44 | 记录Action 分散到那些Server上面 45 | (怎么实现分布式互相发现,并做负载均衡这个问题还有待参考学习) 46 | --------------------------------------------------------------------------------