Blame view

doc/plugin.md 1.41 KB
29b6d86f   zhangqijia   update plugin doc
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
  
  ## 热更golang有状态服务
  1. golang是有状态的
  2. 数据+逻辑代码分离
  3. 主要热更的是逻辑代码
  
  
  ## 启用插件
  1. 启用插件, 配置文件 conf.yaml, 填入插件.so文件的路径
  ```
  server_game:
    plugin_path: "./bin/plugin.so"
    mongo:
      <<: *default-mongo
      dbname: "game"
  ```
  2. 编译程序 & 插件.
  ```shell
  $ make plugin
  ```
  * 程序和插件需要同一个golang的环境。
  * golang对同一个插件只能加载一次。可以修改.so文件名字 + 软连接的方式来处理
  
  
  ## 写插件代码
  插件中的代码主要是对线上程序 `协议=>逻辑` 的热更.
  
  比如我们要修改游戏服务协议号为`1`的逻辑。 则在`cmd/gameserver/plugin/plugin.go`文件中修改。
  1. 在函数`GetActionMap`中增加一行
  ```
  am[uint32(1)] = HotRpc
  ```
  2. 增加函数`HotRpc`
  ```
  func HotRpc(msg components.IMessage) (int32, interface{}) {
58e37bfe   zhangqijia   add sync.Pool to ...
36
      return 0, nil
29b6d86f   zhangqijia   update plugin doc
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
  }
  ```
  
  3. 编译插件 & 可以参考Makefile:plugin
  ```Makefile
  IMGTIME := $(shell date "+%G%m%d_%H%M%S")
  pname = plugin-$(IMGTIME).so
  plugin:
  	cd bin && rm -rf ./plugin*.so && cd -
  	go build -race --buildmode=plugin -o bin/$(pname) cmd/gameserver/plugin/*.go
  	cd bin && ln -s $(pname) plugin.so && cd -
  ```
  
  4. 把插件放到指定位置, 并给游戏服发送热更指令。可以参考Makefile:regame
  ```Makefile
  regame:plugin
  	lsof -i:8850 | grep "agent" | grep -v grep | awk '{print $$2}'  | xargs -I {} kill -USR1 {}
  ```