烫

烫烫烫烫烫

×

  • 分类

  • 归档

  • 标签

  • 关于

一个轻量级的游戏服务器引擎

发表于 2018-05-02 | 分类于 GitHub

一个轻量级的游戏服务器引擎

要点

  • 业务层基于ECS框架来做开发, 继承实体基类与组件基类即可
  • 基于etcd的 服务注册 / TTL / 服务发现 / 负载均衡 / 上报负载 / Watch机制 一体化
  • 基于msgpack的RPC框架, 支持 ip地址直接call以及配合ECS的remote虚拟实体/组件直接call
  • 基于asyncio异步IO的协程业务层支持, 可实现类似 result = await rpc_call() 的直接调RPC拿返回的效果
    • 实现了协程池, 封装成了简洁的装饰器便于业务层调用
  • 支持TCP与RUDP
  • 基于sanic开发的异步HTTP微服务框架供方便开发各类公共服务
    • 基于jwt的auth模块
    • 基于redis的数据落地模块
    • 基于umongo的ODM模块
  • 热更新reload模块
    • 全量式, 安全保障
    • 增量式, 速度更快, 方便平时开发
  • 支持异步的TimedRotating日志模块
    • 根据日期时间自动滚动切换日志文件
    • 支持协程对象的callback
    • 根据日志level改变颜色, 方便查询
    • 报trace可打印堆栈与locals
    • 对于 warning 以上的日志级别直接对Pycharm提供文件跳转支持
  • 支持1:N模型的定时器模块, 避免覆盖同一个key的易错点
    • 可以重复使用一个key, 并不会冲掉之前key的timer, 但是当调用cancel_timer的时候, 会一次性全部cancel掉所有
  • 制作了增强型json解析器, 支持注释/自动去除逗号/变量宏
  • 基于MongoDB的数据落地模块
  • client端的模拟与自动化测试配套
  • 大厅服务器的前置网关gate服务器, 负责压缩/解压, 加密/解密数据以及鉴权

架构图

本架构图根据 PlantUML 自动生成

一个自动生成网站目录大纲的油猴脚本

发表于 2022-08-25 | 分类于 GitHub

auto-toc

auto-toc

Displays a table of contents for any website, making it easier to read and navigate long articles, documentations, and online books.

Generate TOC(table of contents) for any website. 可以为任何网站生成TOC网站目录大纲.

Switch black/white themes automatically according to your compupter’s light/dark mode. 会根据你的电脑的黑夜白天模式自动切换黑白主题.

light

dark

Features

  • Work properly on any website that conforms to the HTML standard and uses HTML heading tags properly (e.g. Wikipedia.com).
  • Accurate article and heading detection
  • A clean user interface
  • Highlight current heading
  • Click to jump to headings
  • Drag the panel to your preferred position
  • Only runs when you actually use it
  • Dark mode, automatically
  • 6 heading levels
  • Expand all headings to a specific level
  • Support HTML label:
    • H1, H2, H3, H4, H5, H6
    • <strong>
    • <b>

Installation & Usage

  • English: https://greasyfork.org/en/scripts/458022-auto-toc?locale_override=1
  • 中文: https://greasyfork.org/zh-CN/scripts/458022-auto-toc?locale_override=1

By default, it is not open. You need to go to the plug-in menu to open the switch for the website that wants to open the toc. The plug-in will remember this switch, and the toc will be generated automatically according to the switch when you open the website the next time.

可以为任何网站生成TOC网站目录大纲, 默认是不打开的, 需要去插件菜单里为想要打开 toc 的网站开启开关, 插件会记住这个开关, 下回再打开这个网站会自动根据开关来生成 toc 与否.

Inspired by

  • https://github.com/FallenMax/smart-toc
  • https://chrome.google.com/webstore/detail/lifgeihcfpkmmlfjbailfpfhbahhibba
  • https://greasyfork.org/en/scripts/415856-bc-smarttoc

Tab一下交互式搜一切文件且动态补全任何路径的shell插件

发表于 2022-08-22 | 分类于 GitHub

tab-to-find

tab-to-find

一个tab就能交互式动态搜一切 !!

并且支持命令对于任何目录和文件的路径的 tab 动态补全

对于经常要找文件和烦恼输入非常长的路径的人来说极为好用, 不用一个路径一个路径慢慢敲了, 可以一步搜索到位, 即使有几百万的文件, 也非常丝滑, 丝毫不卡

简称: T T F

Demo

tab-to-find-demo.gif

功能

跟平时一样按tab就完事

  • 不输入任何东西, tab 也可直接动态搜索当前目录以及子目录的所有目录和文件, 只是当做一个搜索工具也很好用
  • tab来补全
    • 可以不一定是头部完全匹配, 比如 输入 doc 然后 tab , 可以匹配 test_doc 也可以匹配 doc_test 也可以匹配 test_doc_test
    • 可以递归匹配当前目录的子目录的所有 doc 的文件/目录, 也就是说你可以在 home 目录输入 cd doc 然后从 home 目录一步直接 cd 到 ~/github/test-proj/documents 里 !
      • 如果只有一个匹配项, 则自动补全
        • 比如匹配到了 Documents/ , 但如果这不是你想要的, 你想要的是 ~/github/test-proj/documents , 那你可以再按一次tab
      • 如果不只是有一个匹配项, 则会递归搜索子目录下的所有含有 doc 的文件夹
    • 如果 cd 后面跟的不是目录, 则自动进入到那个文件所在的目录, 比如输入 cd ~/github/test.txt 则可以直接进入到 ~/github 这个文件夹里
    • 如果输入以 // 结尾, 则可以只搜索一层目录的文件夹, 而不是递归搜索所有子目录的
    • 如果输入以 .. 结尾, 则可以只搜索一层目录的文件, 而不是递归搜索所有子目录的
    • 同理 vi, ln, mv, cp 等等其他命令也是如此

Usage

  • Press tab to search everything
  • Press tab for completion as usual

安装方法

  1. 先安装fd, 按照 fd的安装方法 安装一下就行(一般来说就是一行命令就搞定), 不用额外配置
  2. 再安装fzf, 按照 fzf的安装方法 安装一下就行(一般来说就是一行命令就搞定), 不用额外配置
  3. 然后再按照下方的手动方式 或者 走Oh-My-Zsh方式的方式来安装 tab-to-find 就可以了

手动方式

先克隆一波这个项目

1
git clone https://github.com/no5ix/tab-to-find ~/somewhere

然后把下面这行加到你的 ~/.zshrc.

1
source ~/somewhere/tab-to-find.plugin.zsh

OhMyZsh方式

执行下面这行命令

1
git clone https://github.com/no5ix/tab-to-find ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/tab-to-find
  1. 然后vim ~/.zshrc, 找到七八十行左右 plugins=(git) 的位置 比如原来是 plugins=(git) 则改为 plugins=(git tab-to-find)
  2. source ~/.zshrc 或者重启 zsh

Installation

  1. Install fd by following its installation instruction.
  2. Install fzf by following its installation instruction.
  3. then install tab-to-find by following Manual or Oh-My-Zsh below

Manual

clone this repository.

1
git clone https://github.com/no5ix/tab-to-find ~/somewhere

Then add the following line to your ~/.zshrc.

1
source ~/somewhere/tab-to-find.plugin.zsh

OhMyZsh

Clone this repository to your custom directory and then add tab-to-find to your plugin list.

1
git clone https://github.com/no5ix/tab-to-find ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/tab-to-find

一个只有2M+大小的强大效率工具sux

发表于 2020-01-09 | 分类于 GitHub

sux

sux

  • 知乎链接
  • 下载链接

sux 是一个只有2M+大小的强大效率工具同时拥有

  • 翻译
  • 历史剪切板
  • Everything搜索工具栏
  • 截图 & 贴图
  • 类似listary/alfred/wox的快捷搜索: shift+空格
  • 类似macos的触发角
  • 屏幕边缘触发器
  • 全局自定义快捷键实现各种操作
  • 文本替换器
  • 文本变换器
  • 托盘菜单
  • 快捷指令
  • 可自定义的json配置
  • 自定义主题
  • blabla…

An alternative to Alfred/Wox/Listary/Capslock+/OneQuick .

Inspired by Alfred/Wox/Listary/Capslock+/utools/OneQuick, thank u.

. . .

一个轻量级的kcp会话实现

发表于 2018-08-09 | 分类于 NP

kcpp

轻量级的kcp会话实现-kcpp

kcpp真正实现了只需要包含一个头文件再随意写几行代码就可以用上kcp, 而无需烦心如何组织代码来适配kcp

  • 只需包含 kcpp.h 这一个头文件即可
  • 只需调用 KcpSession::Send 和 KcpSession::Recv 和 KcpSession::Update 即可完成UDP的链接状态管理、会话控制、 RUDP协议调度

Features

  • single-header-only
  • session implementation
  • dynamic redundancy
  • two-channel
    • reliable
    • unreliable

kcpp Examples

  • realtime-server : A realtime dedicated game server ( FPS / MOBA ). 一个实时的专用游戏服务器.
  • realtime-server-ue4-demo : A UE4 State Synchronization demo for realtime-server. 为realtime-server而写的一个UE4状态同步demo, Video Preview 视频演示
  • TestKcppServer.cpp
  • TestKcppClient.cpp

kcpp Usage

the main loop was supposed as:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
Game.Init()

// kcpp init
kcpp::KcpSession myKcpSess(
KcpSession::RoleTypeE,
std::bind(udp_output, _1, _2),
std::bind(udp_input),
std::bind(timer));

while (!isGameOver)
myKcpSess.Update()

while (myKcpSess.Recv(data, len))
if (len > 0)
Game.HandleRecvData(data, len)
else if (len < 0)
Game.HandleRecvError(len);

if (myKcpSess.CheckCanSend())
myKcpSess.Send(data, len)
else
Game.HandleCanNotSendForNow()

Game.Logic()
Game.Render()

The Recv/Send/Update functions of kcpp are guaranteed to be non-blocking.
Please read TestKcppClient.cpp and TestKcppServer.cpp for some basic usage.

kcp源码注释

本项目还附了一个注释版的kcp源码 ikcp.h 和 ikcp.c, 算是另一种的 kcp详解, 方便自己学习也为大家更快的上手, 原始代码来自: https://github.com/skywind3000/kcp , 感谢 skywind3000 带来

这么短小精悍的好项目

注 : 项目中使用 tab 缩进且设置了tab = 2 space

几乎每个段落都有注释, 且关键数据结构还带有图解, 比如 :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
...
//
// kcp发送的数据包设计了自己的包结构,包头一共24bytes,包含了一些必要的信息,具体内容和大小如下:
//
// |<------------ 4 bytes ------------>|
// +--------+--------+--------+--------+
// | conv | conv:Conversation, 会话序号,用于标识收发数据包是否一致
// +--------+--------+--------+--------+ cmd: Command, 指令类型,代表这个Segment的类型
// | cmd | frg | wnd | frg: Fragment, 分段序号,分段从大到小,0代表数据包接收完毕
// +--------+--------+--------+--------+ wnd: Window, 窗口大小
// | ts | ts: Timestamp, 发送的时间戳
// +--------+--------+--------+--------+
// | sn | sn: Sequence Number, Segment序号
// +--------+--------+--------+--------+
// | una | una: Unacknowledged, 当前未收到的序号,
// +--------+--------+--------+--------+ 即代表这个序号之前的包均收到
// | len | len: Length, 后续数据的长度
// +--------+--------+--------+--------+
//
...

//---------------------------------------------------------------------
// ...
// rcv_queue 接收消息的队列, rcv_queue的数据是连续的,rcv_buf可能是间隔的
// nrcv_que // 接收队列rcv_queue中的Segment数量, 需要小于 rcv_wnd
// rcv_queue 如下图所示
// +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
// ... | 2 | 3 | 4 | ...............................................
// +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
// ^ ^ ^
// | | |
// rcv_nxt rcv_nxt + nrcv_que rcv_nxt + rcv_wnd
//
// snd_buf 发送消息的缓存
// snd_buf 如下图所示
// +---+---+---+---+---+---+---+---+---+---+---+---+---+
// ... | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | ...........
// +---+---+---+---+---+---+---+---+---+---+---+---+---+
// ^ ^ ^
// | | |
// snd_una snd_nxt snd_una + snd_wnd
//
//
// rcv_buf 接收消息的缓存
// rcv_buf 如下图所示, rcv_queue的数据是连续的,rcv_buf可能是间隔的
// +---+---+---+---+---+---+---+---+---+---+---+---+---+
// ... | 2 | 4 | 6 | 7 | 8 | 9 | ...........
// +---+---+---+---+---+---+---+---+---+---+---+---+---+
//
...

在注释的过程中, 除了少量空格和换行以及一处有无符号比较的调整(为保证高警告级别可编译过)外 :
if ((IUINT32)count >= IKCP_WND_RCV) return -2;
没有对原始代码进行任何其他改动, 最大程度地保证了代码的“原汁原味”。

QQ群

因为 KCP 官方群已经满了, 可以加群 496687140

12…50
no5ix

no5ix

推荐使用Chrome/Firefox/Safari阅读本博客. 以前的老笔记将会一篇一篇慢慢整理为博客, 这既启发了他人, 也锻炼了自己的描述交流能力.

13 分类
248 日志
93 标签
关于
友情链接
  • ksun的博客
  • 你有图么我有故事
© 2013 - 2023 no5ix