├── .idea
├── $PRODUCT_WORKSPACE_FILE$
├── misc.xml
├── modules.xml
├── server.iml
├── vcs.xml
└── workspace.xml
├── LICENSE
├── README.md
├── ai
├── aiq.go
├── bin
│ ├── ai_server.go
│ └── conf
│ │ └── server.json
├── call.go
├── client.go
├── gameserver.pb.go
├── gameserver.proto
├── logic.go
├── lua
│ ├── json.lua
│ ├── robot_pokers.lua
│ └── root.lua
├── protocal.go
└── vm_play.go
├── base
└── skeleton.go
├── bean
├── cmd.go
├── command.go
├── const.go
├── glog.go
├── gt.go
├── msg.go
├── player.go
├── room.go
├── timer.go
├── timer_test.go
└── union.go
├── bin
├── conf
│ └── server.json
├── gamedata
│ └── .gitignore
└── log
│ └── .gitignore
├── build.sh
├── client
├── base.proto
├── landlord
├── landlord.go
├── protobuf.min.js
├── server
│ └── web.go
└── ws.html
├── conf
├── conf.go
├── json.go
└── server.json
├── db
├── api.go
├── pg.go
├── pg_test.go
└── write.go
├── debug
├── conf
│ ├── conf.go
│ ├── json.go
│ └── server.json
├── run_ai_server.sh
├── run_debug.sh
└── shutdown.sh
├── encrypt
├── cipher.go
├── cipher_test.go
├── password.go
└── password_test.go
├── game
├── external.go
└── internal
│ ├── chanrpc.go
│ ├── handler.go
│ ├── module.go
│ └── queue.go
├── gamedata
└── reader.go
├── gate
├── external.go
├── internal
│ └── module.go
└── router.go
├── global
└── stutas.go
├── hall
├── handler.go
├── login
│ └── login.go
├── mail
│ ├── box.go
│ └── mail.go
├── module.go
└── union
│ ├── info.go
│ ├── logic.go
│ ├── manage.go
│ └── rank.go
├── httpsv
├── handler.go
└── iris.go
├── interface
└── interface.go
├── leaf-server.iml
├── leaf
├── LICENSE
├── README.md
├── TUTORIAL_EN.md
├── TUTORIAL_ZH.md
├── chanrpc
│ ├── chanrpc.go
│ └── example_test.go
├── cluster
│ └── cluster.go
├── conf
│ └── conf.go
├── console
│ ├── command.go
│ └── console.go
├── db
│ └── mongodb
│ │ ├── example_test.go
│ │ └── mongodb.go
├── gate
│ ├── agent.go
│ └── gate.go
├── go
│ ├── example_test.go
│ └── go.go
├── leaf.go
├── log
│ ├── example_test.go
│ └── log.go
├── module
│ ├── module.go
│ └── skeleton.go
├── network
│ ├── agent.go
│ ├── conn.go
│ ├── json
│ │ └── json.go
│ ├── processor.go
│ ├── protobuf
│ │ └── protobuf.go
│ ├── tcp_client.go
│ ├── tcp_conn.go
│ ├── tcp_msg.go
│ ├── tcp_server.go
│ ├── ws_client.go
│ ├── ws_conn.go
│ └── ws_server.go
├── recordfile
│ ├── example_test.go
│ ├── recordfile.go
│ └── test.txt
├── timer
│ ├── cronexpr.go
│ ├── example_test.go
│ └── timer.go
├── util
│ ├── deepcopy.go
│ ├── example_test.go
│ ├── map.go
│ ├── rand.go
│ └── semaphore.go
└── version.go
├── lua
├── game
│ ├── classic_ddz
│ │ ├── auto.lua
│ │ ├── game
│ │ │ ├── game.lua
│ │ │ ├── game.lua.bak
│ │ │ └── root.lua
│ │ ├── place.lua
│ │ ├── pokers.lua
│ │ └── protocol
│ │ │ ├── gameserver.pb
│ │ │ ├── gameserver.proto
│ │ │ ├── makepb.sh
│ │ │ ├── protocol.lua
│ │ │ ├── record_proto.json
│ │ │ └── svn-commit.tmp
│ ├── common
│ │ ├── 17monipdb.dat
│ │ ├── LuaXml.lua
│ │ ├── botname
│ │ ├── game_common.lua
│ │ ├── gauth.lua
│ │ ├── gauth_basexx.lua
│ │ ├── gauth_sha1.lua
│ │ ├── ip2.lua
│ │ ├── ip3.lua
│ │ ├── log_common.lua
│ │ ├── opcode_common.lua
│ │ ├── parser.lua
│ │ ├── protobuf.lua
│ │ ├── test.lua
│ │ ├── util.lua
│ │ ├── utility_common.lua
│ │ └── uuid4.lua
│ ├── debug
│ │ ├── game
│ │ │ ├── game.lua
│ │ │ └── root.lua
│ │ ├── place.lua
│ │ ├── pokers.lua
│ │ └── protocol
│ │ │ ├── gameserver.pb
│ │ │ ├── gameserver.proto
│ │ │ ├── makepb.sh
│ │ │ ├── protocol.lua
│ │ │ └── record_proto.json
│ └── test_game
│ │ ├── game.lua
│ │ ├── game.lua.mine
│ │ ├── game.lua.r125
│ │ ├── game.lua.r128
│ │ ├── root.lua
│ │ └── var.lua
├── lib
│ ├── gauth.lua
│ ├── gauth_basexx.lua
│ ├── gauth_sha1.lua
│ ├── json.lua
│ ├── parser.lua
│ └── uuid4.lua
├── loader.go
├── loader_test.go
└── testing
│ ├── protobuf.lua
│ ├── temp.lua
│ └── testing.lua
├── luajit
├── const.go
├── debug.c
├── debug.go
├── jit
│ ├── Makefile
│ ├── Makefile.dep
│ ├── host
│ │ ├── README
│ │ ├── buildvm
│ │ ├── buildvm.c
│ │ ├── buildvm.exe
│ │ ├── buildvm.h
│ │ ├── buildvm.o
│ │ ├── buildvm_arch.h
│ │ ├── buildvm_asm.c
│ │ ├── buildvm_asm.o
│ │ ├── buildvm_fold.c
│ │ ├── buildvm_fold.o
│ │ ├── buildvm_lib.c
│ │ ├── buildvm_lib.o
│ │ ├── buildvm_peobj.c
│ │ ├── buildvm_peobj.o
│ │ ├── genminilua.lua
│ │ ├── minilua
│ │ ├── minilua.c
│ │ ├── minilua.exe
│ │ └── minilua.o
│ ├── jit
│ │ ├── bc.lua
│ │ ├── bcsave.lua
│ │ ├── dis_arm.lua
│ │ ├── dis_mips.lua
│ │ ├── dis_mipsel.lua
│ │ ├── dis_ppc.lua
│ │ ├── dis_x64.lua
│ │ ├── dis_x86.lua
│ │ ├── dump.lua
│ │ ├── v.lua
│ │ └── vmdef.lua
│ ├── lauxlib.h
│ ├── lib_aux.c
│ ├── lib_aux.o
│ ├── lib_base.c
│ ├── lib_base.o
│ ├── lib_bit.c
│ ├── lib_bit.o
│ ├── lib_debug.c
│ ├── lib_debug.o
│ ├── lib_ffi.c
│ ├── lib_ffi.o
│ ├── lib_init.c
│ ├── lib_init.o
│ ├── lib_io.c
│ ├── lib_io.o
│ ├── lib_jit.c
│ ├── lib_jit.o
│ ├── lib_math.c
│ ├── lib_math.o
│ ├── lib_os.c
│ ├── lib_os.o
│ ├── lib_package.c
│ ├── lib_package.o
│ ├── lib_string.c
│ ├── lib_string.o
│ ├── lib_table.c
│ ├── lib_table.o
│ ├── libluajit.a
│ ├── libluajit_darwin.a
│ ├── lj.supp
│ ├── lj_alloc.c
│ ├── lj_alloc.h
│ ├── lj_alloc.o
│ ├── lj_api.c
│ ├── lj_api.o
│ ├── lj_arch.h
│ ├── lj_asm.c
│ ├── lj_asm.h
│ ├── lj_asm.o
│ ├── lj_asm_arm.h
│ ├── lj_asm_mips.h
│ ├── lj_asm_ppc.h
│ ├── lj_asm_x86.h
│ ├── lj_bc.c
│ ├── lj_bc.h
│ ├── lj_bc.o
│ ├── lj_bcdef.h
│ ├── lj_bcdump.h
│ ├── lj_bcread.c
│ ├── lj_bcread.o
│ ├── lj_bcwrite.c
│ ├── lj_bcwrite.o
│ ├── lj_carith.c
│ ├── lj_carith.h
│ ├── lj_carith.o
│ ├── lj_ccall.c
│ ├── lj_ccall.h
│ ├── lj_ccall.o
│ ├── lj_ccallback.c
│ ├── lj_ccallback.h
│ ├── lj_ccallback.o
│ ├── lj_cconv.c
│ ├── lj_cconv.h
│ ├── lj_cconv.o
│ ├── lj_cdata.c
│ ├── lj_cdata.h
│ ├── lj_cdata.o
│ ├── lj_char.c
│ ├── lj_char.h
│ ├── lj_char.o
│ ├── lj_clib.c
│ ├── lj_clib.h
│ ├── lj_clib.o
│ ├── lj_cparse.c
│ ├── lj_cparse.h
│ ├── lj_cparse.o
│ ├── lj_crecord.c
│ ├── lj_crecord.h
│ ├── lj_crecord.o
│ ├── lj_ctype.c
│ ├── lj_ctype.h
│ ├── lj_ctype.o
│ ├── lj_debug.c
│ ├── lj_debug.h
│ ├── lj_debug.o
│ ├── lj_def.h
│ ├── lj_dispatch.c
│ ├── lj_dispatch.h
│ ├── lj_dispatch.o
│ ├── lj_emit_arm.h
│ ├── lj_emit_mips.h
│ ├── lj_emit_ppc.h
│ ├── lj_emit_x86.h
│ ├── lj_err.c
│ ├── lj_err.h
│ ├── lj_err.o
│ ├── lj_errmsg.h
│ ├── lj_ff.h
│ ├── lj_ffdef.h
│ ├── lj_ffrecord.c
│ ├── lj_ffrecord.h
│ ├── lj_ffrecord.o
│ ├── lj_folddef.h
│ ├── lj_frame.h
│ ├── lj_func.c
│ ├── lj_func.h
│ ├── lj_func.o
│ ├── lj_gc.c
│ ├── lj_gc.h
│ ├── lj_gc.o
│ ├── lj_gdbjit.c
│ ├── lj_gdbjit.h
│ ├── lj_gdbjit.o
│ ├── lj_ir.c
│ ├── lj_ir.h
│ ├── lj_ir.o
│ ├── lj_ircall.h
│ ├── lj_iropt.h
│ ├── lj_jit.h
│ ├── lj_lex.c
│ ├── lj_lex.h
│ ├── lj_lex.o
│ ├── lj_lib.c
│ ├── lj_lib.h
│ ├── lj_lib.o
│ ├── lj_libdef.h
│ ├── lj_load.c
│ ├── lj_load.o
│ ├── lj_mcode.c
│ ├── lj_mcode.h
│ ├── lj_mcode.o
│ ├── lj_meta.c
│ ├── lj_meta.h
│ ├── lj_meta.o
│ ├── lj_obj.c
│ ├── lj_obj.h
│ ├── lj_obj.o
│ ├── lj_opt_dce.c
│ ├── lj_opt_dce.o
│ ├── lj_opt_fold.c
│ ├── lj_opt_fold.o
│ ├── lj_opt_loop.c
│ ├── lj_opt_loop.o
│ ├── lj_opt_mem.c
│ ├── lj_opt_mem.o
│ ├── lj_opt_narrow.c
│ ├── lj_opt_narrow.o
│ ├── lj_opt_sink.c
│ ├── lj_opt_sink.o
│ ├── lj_opt_split.c
│ ├── lj_opt_split.o
│ ├── lj_parse.c
│ ├── lj_parse.h
│ ├── lj_parse.o
│ ├── lj_recdef.h
│ ├── lj_record.c
│ ├── lj_record.h
│ ├── lj_record.o
│ ├── lj_snap.c
│ ├── lj_snap.h
│ ├── lj_snap.o
│ ├── lj_state.c
│ ├── lj_state.h
│ ├── lj_state.o
│ ├── lj_str.c
│ ├── lj_str.h
│ ├── lj_str.o
│ ├── lj_strscan.c
│ ├── lj_strscan.h
│ ├── lj_strscan.o
│ ├── lj_tab.c
│ ├── lj_tab.h
│ ├── lj_tab.o
│ ├── lj_target.h
│ ├── lj_target_arm.h
│ ├── lj_target_mips.h
│ ├── lj_target_ppc.h
│ ├── lj_target_x86.h
│ ├── lj_trace.c
│ ├── lj_trace.h
│ ├── lj_trace.o
│ ├── lj_traceerr.h
│ ├── lj_udata.c
│ ├── lj_udata.h
│ ├── lj_udata.o
│ ├── lj_vm.h
│ ├── lj_vm.o
│ ├── lj_vm.s
│ ├── lj_vmevent.c
│ ├── lj_vmevent.h
│ ├── lj_vmevent.o
│ ├── lj_vmmath.c
│ ├── lj_vmmath.o
│ ├── ljamalg.c
│ ├── lua.h
│ ├── lua.hpp
│ ├── luaconf.h
│ ├── luajit
│ ├── luajit.c
│ ├── luajit.exe
│ ├── luajit.h
│ ├── luajit.o
│ ├── lualib.h
│ ├── msvcbuild.bat
│ ├── ps4build.bat
│ ├── psvitabuild.bat
│ ├── vm_arm.dasc
│ ├── vm_mips.dasc
│ ├── vm_ppc.dasc
│ ├── vm_ppcspe.dasc
│ ├── vm_x86.dasc
│ └── xedkbuild.bat
├── state.c
├── state.go
└── state_test.go
├── main.go
├── msg
├── const.go
└── msg.go
├── props
├── base.go
└── create.go
├── protobuf
├── baseid.lua
├── build.bat
├── example
│ ├── proto.go
│ ├── test.pb.go
│ └── test.proto
├── go_side.pb.go
└── go_side.proto
├── rpc
├── ai_call.go
└── ai_mod.go
├── run_dev.sh
├── server.iml
├── shutdown.sh
├── test.lua
└── vm
├── dat.go
├── vm.go
└── vm_test.go
/.idea/$PRODUCT_WORKSPACE_FILE$:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | 11
8 |
9 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/.idea/server.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/workspace.xml:
--------------------------------------------------------------------------------
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 | 1599381343267
44 |
45 |
46 | 1599381343267
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # 房间类游戏框架
2 | 1.使用protobuf3
3 | 2.模块分离,游戏逻辑,业务可模块化单独部署
4 | 3.golang实现Clua API,封装lua VM。支持解析table
5 | 4.游戏逻辑使用lua编写,支持热更新
6 |
7 | # 性能
8 | 该项目经过斗地主机器人服务器测试,单个VM可稳定运行5000客户端同时游戏,性能强劲,可对单个游戏开N个VM,取决于硬件配置。
9 |
10 | # 备注
11 | 该项目Golang部分95%由我完成,开源也经过了公司的同意。方便棋牌类项目快速开发游戏,只写逻辑。
12 | 最后如果有人使用这个项目,不明白的地方可以提交Issue,尽力解答。
13 |
14 |
--------------------------------------------------------------------------------
/ai/aiq.go:
--------------------------------------------------------------------------------
1 | package ai
2 |
3 | import (
4 | "fmt"
5 | "github.com/astaxie/beego/orm"
6 | "github.com/google/uuid"
7 | "github.com/helloh2o/collections"
8 | "server/bean"
9 | "server/db"
10 | "server/global"
11 | "server/leaf/log"
12 | "server/props"
13 | )
14 |
15 | var (
16 | // 可用的AI 队列
17 | aiQueue = collections.NewQueue()
18 | )
19 |
20 | func Init(max int) {
21 | db.PGRun()
22 | o := orm.NewOrm()
23 | ais := make([]*bean.Player, 0)
24 | n, err := o.QueryTable("player").Filter("Robot", true).Limit(max + 1).Count()
25 | if err != nil {
26 | log.Fatal("%v", err)
27 | } else if n == 0 {
28 | // 初始化AI 数据
29 | for i := 0; i < 4; i++ {
30 | for j := n; j < 3000; j++ {
31 | // create
32 | p := &bean.Player{}
33 | p.Uuid = uuid.New().String()
34 | p.Gold = 10000000
35 | p.RoomCard = 1000000
36 | nx := i*3000 + int(j)
37 | p.Name = fmt.Sprint("编号", nx)
38 | p.NickName = fmt.Sprint("编号", nx)
39 | p.Props = make([]*props.Prop, 0)
40 | p.Robot = true
41 | p.Phone = p.Uuid
42 | p.Email = p.Uuid + "@.robot"
43 | p.Device = p.Uuid + "@device"
44 | ais = append(ais, p)
45 | }
46 | gsv := global.SingleSave{
47 | Data: ais,
48 | Err: make(chan error, 1),
49 | Type: 2,
50 | Length: len(ais),
51 | }
52 | global.OnSingleSave <- gsv
53 | err = <-gsv.Err
54 | if err != nil {
55 | log.Error("Save robots error %v", err)
56 | }
57 | ais = ais[:0]
58 | }
59 | }
60 | _, err = o.QueryTable("player").Filter("robot", true).Limit(max).All(&ais)
61 | if err != nil {
62 | log.Error("query robot error %v", err)
63 | } else {
64 | log.Release("Load AI player %d", len(ais))
65 | }
66 | // 初始化AI 数据
67 | for _, p := range ais {
68 | aiQueue.Put(p)
69 | }
70 | log.Release("AI queue size %d", max)
71 | }
72 |
73 | func getAi() *bean.Player {
74 | if aiQueue.IsEmpty() {
75 | return nil
76 | }
77 | v, _ := aiQueue.Get()
78 | p, ok := v.(*bean.Player)
79 | if !ok {
80 | return nil
81 | }
82 | return p
83 | }
84 |
85 | func putAi(ai interface{}) {
86 | aiQueue.Put(ai)
87 | }
88 |
--------------------------------------------------------------------------------
/ai/bin/ai_server.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "flag"
5 | "github.com/smallnest/rpcx/server"
6 | "log"
7 | "net"
8 | "server/ai"
9 | "server/encrypt"
10 | "time"
11 | )
12 |
13 | var (
14 | max = flag.Int("max", 3, "max ai client")
15 | serverAddr = flag.String("server", "120.26.45.235:3563", "game server addr")
16 | listenAddr = flag.String("listen", ":7080", "open for call AI address.")
17 | autoPlay = flag.Bool("auto", true, "all robot auto play on server started.")
18 | )
19 |
20 | func main() {
21 | flag.Parse()
22 | ai.Init(*max)
23 | ai.InitPlayRule()
24 | // 初始化加密
25 | encrypt.InitCipher("TH27Cco/KLPtga3Z1BLMNwTaEXp/B8GnLQpKbkKk8esx6qCIQ1eYdPdfDizG+WxG04lSpfXXry8c2+OHgqxEOSGqiimMsMCE/1tt/Ku0SLqT5Hj2n949yx7VaQvyNR+5WWjNoVMVg6Ps9BtkeeDPDb1rIvMgjXJ274DfcE1OkPg4JLyuycMyGvvlXkDuhp0CsjTdECNdd9E6HUlab0VznjZnqbEnXP3pjqjQaoXc1lQ7YSqm5mPIPNKUi3szDMecAxf6AVYUvxkrPpVPWAi1msX+Zrh8AC6bSxhR6MThfo/YBSVBBufCJs4wFpJHl2K3ZQ/wdb5gouITUJGWmVW2cQ==")
26 | // 所有机器人自动跑
27 | if *autoPlay {
28 | for i := 1; i <= *max; i++ {
29 | c, err := net.Dial("tcp", *serverAddr)
30 | if err != nil {
31 | log.Printf("can't dial server %s, err %v", *serverAddr, err)
32 | break
33 | }
34 | client := ai.NewClient(c)
35 | go client.Start("", "")
36 | time.Sleep(time.Millisecond * 100)
37 | }
38 | } else {
39 | // RUN RPC CALL server, I need an AI player
40 | s := server.NewServer()
41 | err := s.RegisterName("AI", new(ai.AICall), "")
42 | if err != nil {
43 | log.Fatal(err)
44 | } else {
45 | go func() {
46 | err := s.Serve("tcp", *listenAddr)
47 | if err != nil {
48 | log.Fatal(err)
49 | }
50 | }()
51 | }
52 | }
53 | select {}
54 | }
55 |
--------------------------------------------------------------------------------
/ai/bin/conf/server.json:
--------------------------------------------------------------------------------
1 | {
2 | "LogLevel": "debug",
3 | "LogPath": "",
4 | "TCPAddr": "127.0.0.1:3563",
5 | "WSAddr": "0.0.0.0:3565",
6 | "HTTPAddr": "0.0.0.0:6100",
7 | "MaxConnNum": 20000,
8 | "DBSource": "user=dz_db password=d2SQC4nEeqDF958qLiu2 dbname=dz host=pgm-bp1rx6909s61kx0f9o.pg.rds.aliyuncs.com port=1433 sslmode=disable",
9 | "DBMaxConn": 200,
10 | "DBIdleConn": 10,
11 | "AIRPC": "127.0.0.1:7080",
12 | "Games": [
13 | {
14 | "name": "classic_ddz",
15 | "root": "./lua/game/test_game/root.lua",
16 | "vm_size": 1,
17 | "room": 10,
18 | "des": "性能瓶颈的时候通过命令动态创建新的虚拟机个数,各场次房间个数量由LUA来定"
19 | }
20 | ],
21 | "EncryptStr": "TH27Cco/KLPtga3Z1BLMNwTaEXp/B8GnLQpKbkKk8esx6qCIQ1eYdPdfDizG+WxG04lSpfXXry8c2+OHgqxEOSGqiimMsMCE/1tt/Ku0SLqT5Hj2n949yx7VaQvyNR+5WWjNoVMVg6Ps9BtkeeDPDb1rIvMgjXJ274DfcE1OkPg4JLyuycMyGvvlXkDuhp0CsjTdECNdd9E6HUlab0VznjZnqbEnXP3pjqjQaoXc1lQ7YSqm5mPIPNKUi3szDMecAxf6AVYUvxkrPpVPWAi1msX+Zrh8AC6bSxhR6MThfo/YBSVBBufCJs4wFpJHl2K3ZQ/wdb5gouITUJGWmVW2cQ=="
22 | }
--------------------------------------------------------------------------------
/ai/call.go:
--------------------------------------------------------------------------------
1 | package ai
2 |
3 | import (
4 | "context"
5 | "log"
6 | "net"
7 | "server/rpc"
8 | )
9 |
10 | type AICall struct {
11 | }
12 |
13 | // 远程调用,加入一个机器人到指定服务器对应游戏的场次中
14 | func (ac *AICall) Join(ctx context.Context, args *rpc.AiJoinArs, reply *rpc.AiReply) error {
15 | c, err := net.Dial("tcp", args.Server)
16 | if err != nil {
17 | log.Printf("can't dial server %s, err %v", args.Server, err)
18 | return err
19 | }
20 | client := NewClient(c)
21 | go client.Start(args.GameName, args.GamePlace)
22 | return nil
23 | }
24 |
--------------------------------------------------------------------------------
/ai/client.go:
--------------------------------------------------------------------------------
1 | package ai
2 |
3 | import (
4 | "encoding/binary"
5 | "github.com/golang/protobuf/proto"
6 | "io"
7 | "net"
8 | "server/bean"
9 | "server/encrypt"
10 | "server/leaf/log"
11 | "server/msg"
12 | "server/protobuf"
13 | )
14 |
15 | type Client struct {
16 | Conn net.Conn
17 | Player *bean.Player
18 | OnPackage chan []byte
19 | Done chan struct{}
20 | GameInfo *ScStartGame
21 | Notify *ScGameActionNotify
22 | Dizhu int32
23 | }
24 |
25 | func NewClient(c net.Conn) *Client {
26 | client := new(Client)
27 | client.Conn = c
28 | p := getAi()
29 | if p == nil {
30 | return nil
31 | }
32 | client.Player = p
33 | client.Done = make(chan struct{})
34 | client.OnPackage = make(chan []byte)
35 | return client
36 | }
37 |
38 | func (c *Client) Start(r, p string) {
39 | go c.read()
40 | go c.handle()
41 | // 发送第一个消息
42 | if r == "" && p == "" {
43 | r = "classic_ddz"
44 | p = "custom"
45 | }
46 | enter := protobuf.CsEnterRoom{
47 | Player: c.Player.ToJson(),
48 | Room: r,
49 | Place: p,
50 | }
51 |
52 | bs, err := proto.Marshal(&enter)
53 | if err != nil {
54 | log.Error("Marshal enter error %v", err)
55 | } else {
56 | c.write(msg.CsEnterRoom, bs)
57 | }
58 | }
59 |
60 | func (c *Client) write(id int, data []byte) {
61 | m := make([]byte, 4+len(data))
62 | binary.LittleEndian.PutUint16(m, uint16(len(data)+2))
63 | binary.LittleEndian.PutUint16(m[2:4], uint16(id))
64 | copy(m[4:], data)
65 | encrypt.CipherX.Encode(m[2:])
66 | n, err := c.Conn.Write(m)
67 | if err != nil || n != len(m) {
68 | log.Error("Write package error %s %d", err, n)
69 | }
70 | }
71 |
72 | func (c *Client) read() {
73 | defer func() {
74 | c.Done <- struct{}{}
75 | }()
76 | for {
77 | lenSlice := make([]byte, 2)
78 | _, err := io.ReadFull(c.Conn, lenSlice)
79 | if err != nil {
80 | log.Debug("Client Read msg length error %v", err)
81 | break
82 | }
83 | length := binary.LittleEndian.Uint16(lenSlice)
84 | pk := make([]byte, length)
85 | _, err = io.ReadFull(c.Conn, pk)
86 | if err != nil {
87 | log.Debug("Client Read package error %v", err)
88 | break
89 | }
90 | encrypt.CipherX.Decode(pk)
91 | c.OnPackage <- pk
92 | }
93 | }
94 |
95 | func (c *Client) handle() {
96 | for {
97 | select {
98 | case pk := <-c.OnPackage:
99 | //log.Debug("LittleEndianackage %+v", pk)
100 | id := binary.LittleEndian.Uint16(pk[:2])
101 | data := pk[2:]
102 | // 解包
103 | switch id {
104 | case 0:
105 | var p protobuf.Protocol
106 | err := proto.Unmarshal(data, &p)
107 | if err != nil {
108 | log.Error("unmarshal error %v", err)
109 | } else {
110 | c.doLogic(&p)
111 | }
112 | case 1:
113 |
114 | }
115 | case <-c.Done:
116 | putAi(c.Player)
117 | return
118 | }
119 | }
120 | }
121 |
--------------------------------------------------------------------------------
/ai/lua/root.lua:
--------------------------------------------------------------------------------
1 | --
2 | -- Created by IntelliJ IDEA.
3 | -- User: Administrator
4 | -- Date: 2020/7/30
5 | -- Time: 16:01
6 | -- To change this template use File | Settings | File Templates.
7 | --
8 |
9 | luapath = '/root/golang/src/server/ai/lua'
10 |
11 | --package.path = [[./?.lua;./?/init.lua;/usr/local/share/lua/5.1/?.lua;/usr/local/share/lua/5.1/?/init.lua]]
12 | package.path = [[./?.lua;./?/init.lua;/root/golang/src/server/ai/lua/?.lua]]
13 | package.cpath = [[./?.so;/usr/local/lib/lua/5.1/?.so]]
14 |
15 |
16 | function get_game_path()
17 | return luapath
18 | end
19 |
20 |
--------------------------------------------------------------------------------
/ai/protocal.go:
--------------------------------------------------------------------------------
1 | package ai
2 |
3 | var (
4 | sc_enter_room_failed = 0x1100
5 | sc_enter_room = 0x1101
6 | sc_enter_room_notify = 0x1102
7 |
8 | sc_ready_game_failed = 0x1103
9 | sc_ready_game = 0x1104
10 | sc_ready_game_notify = 0x1105
11 |
12 | sc_leave_room_failed = 0x1106
13 | sc_leave_room = 0x1107
14 | sc_leave_room_notify = 0x1108
15 |
16 | sc_game_action = 0x1109
17 | sc_game_action_notify = 0x110A
18 |
19 | sc_start_game = 0x110B
20 |
21 | sc_game_show_actions = 0x110C
22 |
23 | sc_sure_lack = 0x110D
24 |
25 | sc_game_turn = 0x110E
26 |
27 | sc_game_turn_notify = 0x110F
28 |
29 | sc_continue_game = 0x1110
30 |
31 | sc_inspect_player = 0x1112
32 |
33 | sc_game_action_failed = 0x1113
34 |
35 | sc_end_game = 0x1114
36 |
37 | sc_game_hide_actions = 0x1115
38 |
39 | sc_ready_timer = 0x111A
40 |
41 | sc_lack_infos = 0x111B
42 |
43 | sc_enter_match_room = 0x111C
44 |
45 | sc_broadcast = 0x111D
46 |
47 | sc_sure_exchange = 0x1120
48 | sc_exchange_info = 0x1121
49 |
50 | sc_dismiss_room = 0x1122
51 | sc_dismiss_room_notify = 0x1123
52 | sc_dismiss_room_result = 0x1124
53 |
54 | sc_protocol_pack = 0x11FE
55 | sc_game_debug = 0x11FF
56 |
57 | sc_change_online = 0x1200
58 |
59 | sc_game_refresh_hand_seq = 0x1201
60 |
61 | sc_exchange_tiles_response = 0x1202
62 |
63 | sc_gift_action = 0x1203
64 |
65 | sc_end_game_group = 0x1204
66 |
67 | sc_seat_voiceid = 0x1205
68 |
69 | sc_qian_si_end = 0x1206
70 |
71 | sc_end_group_info = 0x1207
72 |
73 | sc_sure_action = 0x1208
74 |
75 | sc_game_auto_notify = 0x1209
76 | sc_sure_piao = 0x1210
77 | sc_piao_infos = 0x1211
78 |
79 | sc_room_gps_info = 0x1212
80 |
81 | sc_dizhu_info = 0x1213
82 | sc_use_prop = 0x1214
83 | //--------------------------------------------------CS----------------------------------------------------------
84 |
85 | cs_ready_game = 0x2100
86 | cs_leave_room = 0x2101
87 | cs_game_action = 0x2102
88 |
89 | cs_inspect_player = 0x2104
90 |
91 | cs_add_bot = 0x2105
92 | cs_game_auto = 0x2106
93 | cs_game_manual = 0x2107
94 |
95 | cs_resend_action = 0x2108
96 |
97 | cs_chat = 0x2109
98 |
99 | cs_match_game = 0x210A
100 | cs_ready_match_game = 0x210B
101 | cs_change_online = 0x210C
102 |
103 | cs_debug_dismiss_room = 0x210D
104 | cs_debug_run_action = 0x210E
105 |
106 | cs_dismiss_room = 0x2111
107 |
108 | cs_gift_action = 0x2112
109 | cs_submit_voiceid = 0x2113
110 |
111 | cs_game_refresh_seq = 0x2114
112 |
113 | cs_seat_gps = 0x2115
114 |
115 | cs_use_prop = 0x2116
116 |
117 | heartbeat = 0x00FF
118 | )
119 |
--------------------------------------------------------------------------------
/ai/vm_play.go:
--------------------------------------------------------------------------------
1 | package ai
2 |
3 | import (
4 | "flag"
5 | "log"
6 | "server/vm"
7 | )
8 |
9 | var (
10 | _vm *vm.VM
11 | root = flag.String("root", "D:/gohub/src/server/ai/lua/root.lua", "lua root file.")
12 | )
13 |
14 | // 具体的AI打牌算法,交给LUA托管
15 | func InitPlayRule() {
16 | _vm = vm.NewVM("ddz", *root)
17 | if _vm != nil {
18 | log.Printf("create game %s vm %s", "ddz", _vm.Uuid)
19 | } else {
20 | log.Printf("created vm failed for game %s", "ddz")
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/base/skeleton.go:
--------------------------------------------------------------------------------
1 | package base
2 |
3 | import (
4 | "server/conf"
5 | "server/leaf/chanrpc"
6 | "server/leaf/module"
7 | )
8 |
9 | func NewSkeleton() *module.Skeleton {
10 | skeleton := &module.Skeleton{
11 | GoLen: conf.GoLen,
12 | TimerDispatcherLen: conf.TimerDispatcherLen,
13 | AsynCallLen: conf.AsynCallLen,
14 | ChanRPCServer: chanrpc.NewServer(conf.ChanRPCLen),
15 | }
16 | skeleton.Init()
17 | return skeleton
18 | }
19 |
--------------------------------------------------------------------------------
/bean/command.go:
--------------------------------------------------------------------------------
1 | package bean
2 |
3 | // LUA 返回指令
4 | /*type Commands []Command
5 | type Command []string //[0] send [1] detail
6 | type Detail []string //
7 | */
8 |
9 | type Command interface {
10 | cmd()
11 | }
12 |
13 | type SendCommand struct {
14 | Name string
15 | Player string
16 | Packages [][]byte
17 | }
18 |
19 | type TimerCommand struct {
20 | Name string
21 | RoomId int
22 | TimerId int
23 | Duration int
24 | Tag string
25 | }
26 |
27 | type UpdateCommand struct {
28 | Name string
29 | UpdateInfo []map[string]interface{}
30 | }
31 |
32 | type WriteCommand struct {
33 | UuidArr []string
34 | }
35 |
36 | type ClosePCommand struct {
37 | pid string
38 | reason string
39 | }
40 |
41 | type AddBotCommand struct {
42 | game string
43 | }
44 |
45 | type AddLogCommand struct {
46 | glog *GameLog
47 | ulog []*UserLog
48 | }
49 |
50 | func (c *UpdateCommand) cmd() {}
51 | func (c *TimerCommand) cmd() {}
52 | func (c *SendCommand) cmd() {}
53 | func (c *WriteCommand) cmd() {}
54 | func (c *ClosePCommand) cmd() {}
55 | func (c *AddBotCommand) cmd() {}
56 | func (c *AddLogCommand) cmd() {}
57 |
--------------------------------------------------------------------------------
/bean/const.go:
--------------------------------------------------------------------------------
1 | package bean
2 |
3 | const (
4 | NULL = iota
5 | MAIL_MESSAGE // 普通文本消息 0
6 | MAIL_JOIN_UNION // 加入公会邮件 1
7 | )
8 |
9 | const (
10 | CREATE_UNION_FAILED_NAME_EXIST = 1001 // 公会名字存在
11 | CREATE_UNION_FAILED = 1002 // 创建公会失败
12 | NOT_FOUND_UNION = 1003 // 没有找到公会
13 | MASTER_ID_ERR = 1004 // 公会管理员不匹配
14 | NOT_FOUND_PLAYER = 1005 // 没有找到玩家
15 | TRANSTER_UNION_FAILED = 1006 // 转让公会十八
16 | NEED_RE_LOGIN = 1007 // 需要重新登录
17 | )
18 |
--------------------------------------------------------------------------------
/bean/glog.go:
--------------------------------------------------------------------------------
1 | package bean
2 |
3 | type GameLog struct {
4 | Id int64 `json:"id"`
5 | GroupId string `json:"group_id"`
6 | LogUuid string `json:"uuid" orm:"unique;index"`
7 | GameType string `json:"game_type" orm:"index"`
8 | RoomPwd string `json:"room_pwd"`
9 | LogData string `json:"log_data" orm:"type(jsonb)"`
10 | BeginTime int64 `json:"begin_time"`
11 | RoomUuid string `json:"room_uuid"`
12 | }
13 |
14 | type UserLog struct {
15 | Id int64 `json:"id"`
16 | PlayerId int64 `json:"player_id" orm:"index"`
17 | LogUuid string `json:"log_uuid" orm:"index"`
18 | AddTime int64 `json:"add_time"`
19 | }
20 |
21 | // 多字段唯一
22 | func (lg *UserLog) TableUnique() [][]string {
23 | return [][]string{
24 | []string{"PlayerId", "LogUuid"},
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/bean/gt.go:
--------------------------------------------------------------------------------
1 | package bean
2 |
3 | import (
4 | "server/vm"
5 | "time"
6 | )
7 |
8 | type GameTimer struct {
9 | Id int // 计时器ID
10 | RoomId int // 房间号
11 | Tag string // 标签
12 | Duration time.Duration // 持续时间,秒
13 | T *time.Timer
14 | VM *vm.VM
15 | }
16 |
--------------------------------------------------------------------------------
/bean/msg.go:
--------------------------------------------------------------------------------
1 | package bean
2 |
3 | type Msg struct {
4 | Player *Player
5 | Raw []byte // 原始数据
6 | }
7 |
--------------------------------------------------------------------------------
/bean/player.go:
--------------------------------------------------------------------------------
1 | package bean
2 |
3 | import (
4 | "encoding/json"
5 | "server/leaf/gate"
6 | "server/props"
7 | "sync"
8 | )
9 |
10 | type Player struct {
11 | lk sync.RWMutex `json:"-" orm:"-"`
12 | Id int64 `json:"oid"`
13 | Uuid string `json:"uuid" orm:"unique;index"`
14 | NickName string `json:"nick_name"`
15 | Name string `json:"name" orm:"unique;index"`
16 | Password string `json:"-"`
17 | Gold int64 `json:"gold"`
18 | Coin int64 `json:"coin"`
19 | RoomCard int64 `json:"room_card"`
20 | Sex int `json:"sex"`
21 | Ver string `json:"ver"`
22 | Exp int64 `json:"exp"`
23 | Channel string `json:"channel"`
24 | Phone string `json:"phone" orm:"unique;index"`
25 | Device string `json:"device" orm:"unique;index"`
26 | Email string `json:"email" orm:"unique;index"`
27 | LastLogin int64 `json:"last_login"`
28 | Ip string `json:"ip"`
29 | Token string `json:"token"`
30 | Head string `json:"head"`
31 | agent gate.Agent `json:"-" orm:"-"`
32 | Room *Room `json:"-" orm:"-"`
33 | Props []*props.Prop `json:"props" orm:"-"`
34 | Gaming bool `json:"-"`
35 | Robot bool `json:"robot"`
36 | Union int64 `json:"union" orm:"unique;index"` // 区域,公会划分
37 | Level int64 `json:"level"` // 等级
38 | UnionVal int64 `json:"union_val"` // 公会贡献值
39 | Location string `json:"location"` // 位置
40 | }
41 |
42 | func (p *Player) ToJson() string {
43 | data, err := json.Marshal(p)
44 | if err != nil {
45 | return "{'err':'-1'}"
46 | }
47 | return string(data)
48 | }
49 | func (p *Player) SetAgent(a gate.Agent) {
50 | p.lk.Lock()
51 | defer p.lk.Unlock()
52 | p.agent = a
53 | }
54 |
55 | func (p *Player) Agent() gate.Agent {
56 | p.lk.Lock()
57 | defer p.lk.Unlock()
58 | return p.agent
59 | }
60 |
61 | func (p *Player) SetRoom(r *Room) {
62 | p.lk.Lock()
63 | defer p.lk.Unlock()
64 | p.Room = r
65 | }
66 |
67 | func (p *Player) GetRoom() *Room {
68 | p.lk.Lock()
69 | defer p.lk.Unlock()
70 | return p.Room
71 | }
72 |
73 | func (p *Player) SetGaming(in bool) {
74 | p.lk.Lock()
75 | defer p.lk.Unlock()
76 | p.Gaming = in
77 | }
78 |
79 | func (p *Player) GetGaming() bool {
80 | p.lk.Lock()
81 | defer p.lk.Unlock()
82 | return p.Gaming
83 | }
84 |
85 | type WaitPlayer struct {
86 | Player *Player
87 | GameName string
88 | }
89 |
--------------------------------------------------------------------------------
/bean/room.go:
--------------------------------------------------------------------------------
1 | package bean
2 |
3 | import (
4 | "github.com/google/uuid"
5 | "runtime/debug"
6 | "server/global"
7 | "server/leaf/log"
8 | "server/msg"
9 | "server/protobuf"
10 | "server/vm"
11 | "sync"
12 | "sync/atomic"
13 | )
14 |
15 | type Room struct {
16 | Id int
17 | lk sync.RWMutex
18 | Uuid string
19 | Players map[string]*Player // 房间里的用户
20 | VM *vm.VM // 虚拟机
21 | RoomIn chan Msg // 消息进入通道
22 | Close chan struct{} // 关闭房间通道
23 | Gaming bool // 游戏中
24 | }
25 |
26 | var roomid int64
27 |
28 | func NewRoom() *Room {
29 | room := new(Room)
30 | room.Id = int(atomic.AddInt64(&roomid, 1))
31 | room.Uuid = uuid.New().String()
32 | room.Close = make(chan struct{}, 1)
33 | room.Players = make(map[string]*Player)
34 | room.RoomIn = make(chan Msg)
35 | // 保存全局变量
36 | global.Rooms.Store(room.Id, room)
37 | global.Rooms.Store(room.Uuid, room)
38 | // 监听和接受房间消息
39 | go room.run()
40 | return room
41 | }
42 |
43 | func (r *Room) Join(player *Player) {
44 | r.lk.Lock()
45 | defer r.lk.Unlock()
46 | r.Players[player.Uuid] = player
47 | }
48 |
49 | func (r *Room) Leave(player *Player) {
50 | log.Debug("remove player conn, remove player in room status")
51 | r.lk.Lock()
52 | defer r.lk.Unlock()
53 | player.SetRoom(nil)
54 | delete(r.Players, player.Uuid)
55 | }
56 |
57 | func (r *Room) run() {
58 | defer func() {
59 | log.Release(" =========== Room Run End ============")
60 | if r := recover(); r != nil {
61 | log.Error("Crash in Room run() %s\n", debug.Stack())
62 | }
63 | r.kickOut()
64 | }()
65 | // 房间
66 | for {
67 | select {
68 | case m := <-r.RoomIn:
69 | var datap []byte
70 | if m.Raw != nil {
71 | datap = m.Raw
72 | log.Debug("Raw data from client %+v", m.Raw)
73 | // call onmessage
74 | datastr := string(datap)
75 | log.Debug("onmessage data string =(%s) length=%d", datastr, len(datastr))
76 | calldata := vm.NewCallData("onmessage", []interface{}{m.Player.Id, datastr}, 2)
77 | r.VM.CallChan <- calldata
78 | HandleResult(calldata.Result, 0)
79 | } else {
80 | log.Release("No raw data error msg.")
81 | }
82 | case <-r.Close:
83 | return
84 | }
85 | }
86 | }
87 |
88 | func (r *Room) kickOut() {
89 | action := &protobuf.Protocol{Id: msg.G_kickout_room}
90 | // 踢出玩家
91 | for _, p := range r.Players {
92 | r.Leave(p)
93 | // 踢出玩家
94 | p.Agent().WriteMsg(action)
95 | }
96 | }
97 |
98 | func (r *Room) GetVm() *vm.VM {
99 | return r.VM
100 | }
101 |
--------------------------------------------------------------------------------
/bean/timer.go:
--------------------------------------------------------------------------------
1 | package bean
2 |
3 | import (
4 | "fmt"
5 | "server/leaf/log"
6 | "server/vm"
7 | "sync"
8 | "time"
9 | )
10 |
11 | var TB = TimerBucket{}
12 |
13 | func init() {
14 | go TB.Run()
15 | }
16 |
17 | type TimerBucket struct {
18 | timers sync.Map
19 | }
20 |
21 | func (tb *TimerBucket) Add(t *GameTimer) {
22 | key := fmt.Sprint(t.RoomId, "-", t.Id, "-", t.Tag)
23 | log.Debug("Add timer key %s to run %+v", key, *t)
24 | tb.timers.Store(key, t)
25 | }
26 |
27 | func (tb *TimerBucket) Kill(cmd *TimerCommand) {
28 | key := fmt.Sprint(cmd.RoomId, "-", cmd.TimerId, "-", cmd.Tag)
29 | gt, ok := tb.timers.Load(key)
30 | if ok {
31 | gt, ok := gt.(*GameTimer)
32 | if ok {
33 | gt.T.Stop()
34 | tb.remove(key)
35 | }
36 | } else {
37 | log.Release("Not found the game timer %s", key)
38 | }
39 | }
40 |
41 | func (tb *TimerBucket) remove(key string) {
42 | tb.timers.Delete(key)
43 | log.Release("Removed timer %s", key)
44 | }
45 |
46 | func (tb *TimerBucket) Run() {
47 | defer func() {
48 | if r := recover(); r != nil {
49 | log.Debug("TimerBucket Crashed %v", r)
50 | }
51 | }()
52 | for {
53 | tb.timers.Range(func(key, value interface{}) bool {
54 | gt, ok := value.(*GameTimer)
55 | if ok {
56 | select {
57 | // on timer
58 | case <-gt.T.C:
59 | call(gt)
60 | //log.Println("on call")
61 | key := fmt.Sprint(gt.RoomId, "-", gt.Id, "-", gt.Tag)
62 | // remove
63 | tb.remove(key)
64 | default:
65 | return true
66 | }
67 | }
68 | return true
69 | })
70 | time.Sleep(time.Millisecond * 50)
71 | }
72 | }
73 |
74 | func call(gt *GameTimer) {
75 | calldata := vm.NewCallData("on_timer", []interface{}{gt.RoomId, gt.Id, gt.Tag}, 0)
76 | gt.VM.CallChan <- calldata
77 | HandleResult(calldata.Result, 0)
78 | }
79 |
--------------------------------------------------------------------------------
/bean/timer_test.go:
--------------------------------------------------------------------------------
1 | package bean
2 |
3 | import (
4 | "github.com/gogo/protobuf/proto"
5 | "server/leaf/log"
6 | "server/protobuf"
7 | "server/vm"
8 | "testing"
9 | "time"
10 | )
11 |
12 | func TestTimerBucket_Add(t *testing.T) {
13 | v := vm.NewVM("ddz", "D:/gohub/src/server/lua/game/test_game/root.lua")
14 | // 启动
15 | go v.Run()
16 | r := NewRoom()
17 | r.VM = v
18 | // 初始化房间
19 | gameType := "jjddz"
20 | place := "jjddz_custom"
21 | calldata := vm.NewCallData("room_init", []interface{}{r.Uuid, r.Id, gameType, place}, 0)
22 | //calldata := vm.NewCallData("room_init", []interface{}{r.Uuid, r.Id, gameType, place}, []int{vm.VM_string,vm.VM_int,vm.VM_bool})
23 | r.VM.CallChan <- calldata
24 | // 等待同步结果
25 | result := <-calldata.Result
26 | if result.Ok {
27 | log.Release("Game jjddz new room %s register to VM %s", r.Uuid, r.VM.Uuid)
28 | }
29 | for i := 0; i < 10; i++ {
30 | time.Sleep(time.Second * time.Duration(i))
31 | /*go func() {
32 | gt := GameTimer{
33 | Duration: 3,
34 | Id: i,
35 | }
36 | gt.T = time.NewTimer(time.Second * gt.Duration)
37 | bucket.Add(>)
38 | }()*/
39 | p := &protobuf.Protocol{Id: 1001}
40 | data, _ := proto.Marshal(p)
41 | calldata := vm.NewCallData("onmessage", []interface{}{string(data), "xx"}, 5)
42 | v.CallChan <- calldata
43 | // 等待同步结果
44 | // 0 is A Table
45 | HandleResult(calldata.Result, 0)
46 | }
47 | time.Sleep(time.Hour * 10)
48 | }
49 |
--------------------------------------------------------------------------------
/bean/union.go:
--------------------------------------------------------------------------------
1 | package bean
2 |
3 | import (
4 | "encoding/json"
5 | "server/leaf/log"
6 | )
7 |
8 | type Union struct {
9 | Id int64 `json:"id"`
10 | Name string `json:"name" orm:"unique;index"` // 唯一,索引
11 | Level int `json:"level"`
12 | Notice string `json:"notice"` // 公告
13 | Des string `json:"des"` // 描述
14 | Score int64 `json:"score"`
15 | MasterId int64 `json:"master_id"`
16 | MasterUuid string `json:"master_uuid"`
17 | Creater string `json:"creater"`
18 | CreateTime int64 `json:"create_time"`
19 | MaxMember int `json:"max_member"`
20 | Members int32 `json:"members"`
21 | Status int `json:"status"` //0=open// 1= 验证 // 2= 拒绝
22 | Rank int32 `json:"rank"`
23 | }
24 |
25 | // 邮件
26 | type Mail struct {
27 | Id int64 `json:"id"`
28 | Type int `json:"type"`
29 | Sender string `json:"sender"`
30 | Receiver string `json:"receiver" orm:"index"`
31 | Title string `json:"title"`
32 | Content string `json:"content"`
33 | Attach string `json:"attach"`
34 | Read bool `json:"read"`
35 | }
36 |
37 | func (m *Mail) ToJson() []byte {
38 | data, err := json.Marshal(m)
39 | if err != nil {
40 | log.Error("Marshal MAIL ERR, %v", err)
41 | return nil
42 | } else {
43 | return data
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/bin/conf/server.json:
--------------------------------------------------------------------------------
1 | {
2 | "LogLevel": "debug",
3 | "LogPath": "",
4 | "TCPAddr": "127.0.0.1:3563",
5 | "MaxConnNum": 20000
6 | }
7 |
--------------------------------------------------------------------------------
/bin/gamedata/.gitignore:
--------------------------------------------------------------------------------
1 | *
2 | !.gitignore
3 |
--------------------------------------------------------------------------------
/bin/log/.gitignore:
--------------------------------------------------------------------------------
1 | *
2 | !.gitignore
3 |
--------------------------------------------------------------------------------
/build.sh:
--------------------------------------------------------------------------------
1 | go build main.go
2 | killall debug_main
3 | cp main debug/debug_main
4 | echo "ok"
5 |
--------------------------------------------------------------------------------
/client/landlord:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/helloh2o/room_game_server/aecbb085afbf2e797f46d10f1e52b51ea1f0147d/client/landlord
--------------------------------------------------------------------------------
/client/landlord.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "encoding/binary"
5 | "flag"
6 | "fmt"
7 | "github.com/golang/protobuf/proto"
8 | "log"
9 | "net"
10 | "server/protobuf"
11 | "sync"
12 | "time"
13 | )
14 |
15 | var (
16 | max = flag.Int("max", 1, "-max clients")
17 | )
18 |
19 | func main() {
20 | flag.Parse()
21 | log.Printf("max size %d", *max)
22 | done := make(chan struct{})
23 | _ = done
24 | // 测试300个人,100个房间
25 | for i := 0; i < *max; i++ {
26 | time.Sleep(time.Millisecond * 200)
27 | go func(index int) {
28 | conn, err := net.Dial("tcp", "127.0.0.1:3563")
29 | //conn, err := net.Dial("tcp", "120.26.45.235:2563")
30 | if err != nil {
31 | panic(err)
32 | }
33 | // Hello 消息(JSON 格式)
34 | // 对应游戏服务器 Hello 消息结构体
35 | /*data := []byte(`{
36 | "Room": {
37 | "id": 1001,
38 | "token":"1000"
39 | }
40 | }`)*/
41 | enterMsg := protobuf.CsEnterRoom{}
42 | enterMsg.Room = "classic_ddz"
43 | data, err := proto.Marshal(&enterMsg)
44 | //fmt.Printf("%+v\n", data)
45 | if err != nil {
46 | log.Fatal(err)
47 | }
48 | // proto 网络包 = 【包大小2byte + 消息ID2byte + 消息体nbyte】
49 | m := make([]byte, 4+len(data))
50 | // 默认使用大端序
51 | binary.LittleEndian.PutUint16(m, uint16(len(data)+2))
52 | // push id=0 表示0消息进入房间
53 | binary.LittleEndian.PutUint16(m[2:4], uint16(6))
54 | copy(m[4:], data)
55 | // 发送消息
56 | conn.Write(m)
57 | go func() {
58 | time.Sleep(time.Second * 5)
59 | tk := time.Tick(time.Second * 5)
60 | for {
61 | <-tk
62 | t := protobuf.Heartbeat{}
63 | data, err := proto.Marshal(&t)
64 | if err != nil {
65 | log.Fatal(err)
66 | }
67 | // len + data
68 | m := make([]byte, 4+len(data))
69 | // 默认使用大端序
70 | binary.LittleEndian.PutUint16(m, uint16(len(data)+2))
71 | // push id=0 表示游戏消息
72 | binary.LittleEndian.PutUint16(m[2:4], uint16(7))
73 | copy(m[4:], data)
74 | // 发送消息
75 | conn.Write(m)
76 | }
77 | }()
78 | var one sync.Once
79 | for {
80 | buf := make([]byte, 1024)
81 | n, err := conn.Read(buf)
82 | if err == nil {
83 | fmt.Printf("client %v received message %v \n", index, buf[:n])
84 | one.Do(func() {
85 | if n > 2 {
86 | len := binary.LittleEndian.Uint16(buf[:2])
87 | log.Printf("pkg len =%d , read len %d", len, n)
88 | }
89 | var pkg protobuf.Protocol
90 | err := proto.Unmarshal(buf[4:n], &pkg)
91 | if err != nil {
92 | log.Fatal(err)
93 | } else {
94 | }
95 | })
96 | } else {
97 | break
98 | }
99 | }
100 | }(i)
101 | }
102 | //time.Sleep(time.Minute)
103 | <-done
104 | }
105 |
--------------------------------------------------------------------------------
/client/server/web.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "log"
5 | "net/http"
6 | "os"
7 | )
8 |
9 | func main() {
10 | // 修改自己机子上client目录的绝对地址,然后自动web服务器, 浏览器打开http://localhost:8080/ws.html 运行例子
11 | // http.Handle("/", http.FileServer(http.Dir("D:/Dev/go/src/server/client")))
12 | path, err := os.Getwd()
13 | if err != nil {
14 | log.Println(err)
15 | }
16 | http.Handle("/", http.FileServer(http.Dir(path+"/client")))
17 | http.ListenAndServe(":8080", nil)
18 | }
19 |
--------------------------------------------------------------------------------
/conf/conf.go:
--------------------------------------------------------------------------------
1 | package conf
2 |
3 | import (
4 | "log"
5 | "time"
6 | )
7 |
8 | var (
9 | // log conf
10 | LogFlag = log.LstdFlags
11 |
12 | // gate conf
13 | PendingWriteNum = 2000
14 | MaxMsgLen uint32 = 4096
15 | HTTPTimeout = 10 * time.Second
16 | LenMsgLen = 2
17 | LittleEndian = true
18 |
19 | // skeleton conf
20 | GoLen = 10000
21 | TimerDispatcherLen = 10000
22 | AsynCallLen = 10000
23 | ChanRPCLen = 10000
24 | )
25 |
--------------------------------------------------------------------------------
/conf/json.go:
--------------------------------------------------------------------------------
1 | package conf
2 |
3 | import (
4 | "encoding/json"
5 | "io/ioutil"
6 | "server/leaf/log"
7 | )
8 |
9 | var Server struct {
10 | LogLevel string
11 | LogPath string
12 | WSAddr string
13 | CertFile string
14 | KeyFile string
15 | TCPAddr string
16 | HTTPAddr string
17 | MaxConnNum int
18 | ConsolePort int
19 | ProfilePath string
20 | DBSource string
21 | DBMaxConn int
22 | DBIdleConn int
23 | //lua script
24 | Games []Game
25 | //包混淆加密
26 | EncryptStr string
27 | //AI RPC 服务地址
28 | AIRPC string
29 | }
30 |
31 | type Game struct {
32 | Name string `json:"name"`
33 | Root string `json:"root"`
34 | VmSize int `json:"vm_size"` // 虚拟机个数
35 | Room int `json:"room"` // 初始化房间个数
36 | Des string `json:"des"`
37 | }
38 |
39 | func init() {
40 | data, err := ioutil.ReadFile("conf/server.json")
41 | if err != nil {
42 | log.Fatal("%v", err)
43 | }
44 | err = json.Unmarshal(data, &Server)
45 | if err != nil {
46 | log.Fatal("%v", err)
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/conf/server.json:
--------------------------------------------------------------------------------
1 | {
2 | "LogLevel": "debug",
3 | "LogPath": "",
4 | "TCPAddr": "127.0.0.1:2563",
5 | "WSAddr": "0.0.0.0:2565",
6 | "HTTPAddr": "0.0.0.0:6100",
7 | "MaxConnNum": 20000,
8 | "DBSource": "user=dz_db password=d2SQC4nEeqDF958qLiu2 dbname=dz host=pgm-bp1rx6909s61kx0f9o.pg.rds.aliyuncs.com port=1433 sslmode=disable",
9 | "DBMaxConn": 200,
10 | "DBIdleConn": 10,
11 | "AIRPC": "127.0.0.1:7080",
12 | "Games": [
13 | {
14 | "name": "classic_ddz",
15 | "root": "./lua/game/test_game/root.lua",
16 | "vm_size": 1,
17 | "room": 10,
18 | "des": "性能瓶颈的时候通过命令动态创建新的虚拟机个数,各场次房间个数量由LUA来定"
19 | }
20 | ],
21 | "EncryptStr": "TH27Cco/KLPtga3Z1BLMNwTaEXp/B8GnLQpKbkKk8esx6qCIQ1eYdPdfDizG+WxG04lSpfXXry8c2+OHgqxEOSGqiimMsMCE/1tt/Ku0SLqT5Hj2n949yx7VaQvyNR+5WWjNoVMVg6Ps9BtkeeDPDb1rIvMgjXJ274DfcE1OkPg4JLyuycMyGvvlXkDuhp0CsjTdECNdd9E6HUlab0VznjZnqbEnXP3pjqjQaoXc1lQ7YSqm5mPIPNKUi3szDMecAxf6AVYUvxkrPpVPWAi1msX+Zrh8AC6bSxhR6MThfo/YBSVBBufCJs4wFpJHl2K3ZQ/wdb5gouITUJGWmVW2cQ=="
22 | }
23 |
--------------------------------------------------------------------------------
/db/api.go:
--------------------------------------------------------------------------------
1 | package db
2 |
3 | import (
4 | "database/sql"
5 | "errors"
6 | "github.com/astaxie/beego/orm"
7 | "server/bean"
8 | "server/props"
9 | )
10 |
11 | func FindById(id string) (*bean.Player, error) {
12 | var p bean.Player
13 | o := orm.NewOrm()
14 | err := o.QueryTable("player").Filter("id", id).One(&p)
15 | if err == nil {
16 | return &p, nil
17 | }
18 | return nil, err
19 | }
20 |
21 | func QueryProps(player string) (propList []*props.Prop, err error) {
22 | o := orm.NewOrm()
23 | _, err = o.QueryTable("prop").Filter("player", player).Filter("size__gt", 0).All(&propList)
24 | if err == nil {
25 | return propList, nil
26 | }
27 | return nil, err
28 | }
29 | func FindByAuth(name, passwd string) (*bean.Player, error) {
30 | var p bean.Player
31 | var err error
32 | o := orm.NewOrm()
33 | qs := o.QueryTable("player").Filter("name", name).Filter("password", passwd)
34 | if qs.Exist() {
35 | err := qs.One(&p)
36 | if err != nil {
37 | return nil, err
38 | } else {
39 | return &p, nil
40 | }
41 | } else {
42 | err = errors.New("用户名或密码错误")
43 | }
44 | return nil, err
45 | }
46 | func FindByName(name string) (*bean.Player, error) {
47 | var p bean.Player
48 | o := orm.NewOrm()
49 | err := o.QueryTable("player").Filter("name", name).One(&p)
50 | if err == nil {
51 | return &p, nil
52 | }
53 | return nil, err
54 | }
55 | func Save(p interface{}) (err error) {
56 | o := orm.NewOrm()
57 | _, err = o.Insert(p)
58 | return
59 | }
60 |
61 | func InsertMulti(bulk int, data interface{}) (err error) {
62 | //log.Debug("InsertMulti data %+v", data)
63 | if data != nil {
64 | o := orm.NewOrm()
65 | _, err = o.InsertMulti(bulk, data)
66 | } else {
67 | err = errors.New("Unknow Nil data InsertMulti")
68 | }
69 | return
70 | }
71 |
72 | func Exist(username string) bool {
73 | o := orm.NewOrm()
74 | return o.QueryTable("player").Filter("name", username).Exist()
75 | }
76 |
77 | // sql 语句接口
78 | func RawSQL(sql string, args ...interface{}) (ret sql.Result, err error) {
79 | o := orm.NewOrm()
80 | raw := o.Raw(sql, args...)
81 | return raw.Exec()
82 | }
83 |
84 | func Update(p interface{}, cols ...string) (err error) {
85 | o := orm.NewOrm()
86 | err = o.Begin()
87 | if err != nil {
88 | return err
89 | }
90 | _, err = o.Update(p, cols...)
91 | if err != nil {
92 | err = o.Rollback()
93 | if err != nil {
94 | return err
95 | }
96 | }
97 | err = o.Commit()
98 | return
99 | }
100 |
--------------------------------------------------------------------------------
/db/pg.go:
--------------------------------------------------------------------------------
1 | package db
2 |
3 | import (
4 | "github.com/astaxie/beego/orm"
5 | _ "github.com/lib/pq"
6 | "server/bean"
7 | "server/conf"
8 | "server/props"
9 | )
10 |
11 | func PGRun() {
12 | orm.RegisterDriver("postgres", orm.DRPostgres)
13 | orm.RegisterDataBase("default", "postgres", conf.Server.DBSource)
14 | orm.RegisterModel(
15 | new(bean.Player),
16 | new(props.Prop),
17 | new(bean.GameLog),
18 | new(bean.UserLog),
19 | new(bean.Union),
20 | new(bean.Mail),
21 | )
22 | orm.RunSyncdb("default", false, true)
23 | orm.SetMaxIdleConns("default", conf.Server.DBMaxConn)
24 | orm.SetMaxOpenConns("default", conf.Server.DBIdleConn)
25 | }
26 |
--------------------------------------------------------------------------------
/db/write.go:
--------------------------------------------------------------------------------
1 | package db
2 |
3 | import (
4 | "log"
5 | "runtime"
6 | "server/global"
7 | LG "server/leaf/log"
8 | "time"
9 | )
10 |
11 | // 处理写库
12 | var (
13 | // 服务器关闭,最后一次写库
14 | OnFinalSave = make(chan struct{})
15 | // 手动强制存盘
16 | OnForceSave = make(chan struct{})
17 | // 定时存盘需要存储的用户 Timer 30分钟
18 | timerSave = time.NewTicker(time.Minute * 30)
19 | // 结束
20 | Done = make(chan struct{})
21 | )
22 |
23 | func init() {
24 | go func() {
25 | var gss global.SingleSave
26 | var err error
27 | defer func() {
28 | if r := recover(); r != nil {
29 | var buf [4096]byte
30 | n := runtime.Stack(buf[:], false)
31 | log.Printf("Panic Stack, %v", string(buf[:n]))
32 | log.Printf("Panic error %v", err)
33 | if len(gss.Err) == 0 {
34 | gss.Err <- err
35 | }
36 | }
37 | Done <- struct{}{}
38 | }()
39 | for {
40 | select {
41 | case gss = <-global.OnSingleSave:
42 | switch gss.Type {
43 | case 1:
44 | log.Println("DB writer do single save.")
45 | err = Save(gss.Data)
46 | case 2:
47 | log.Println("DB writer do InsertMulti save.")
48 | err = InsertMulti(gss.Length, gss.Data)
49 | default:
50 | log.Println("DB writer do Update save.")
51 | err = Update(gss.Data)
52 | }
53 | if err != nil {
54 | LG.Release("save error %s OnSingleSave", err.Error())
55 | }
56 | // 返回结果
57 | gss.Err <- err
58 | case <-timerSave.C:
59 | log.Printf("DB writer do timer save.")
60 | doUpdate()
61 | case <-OnForceSave:
62 | doUpdate()
63 | case <-OnFinalSave:
64 | log.Printf("DB writer do final save.")
65 | doUpdate()
66 | return
67 | }
68 | }
69 | }()
70 | }
71 |
72 | func doUpdate() {
73 | defer func() {
74 | recover()
75 | }()
76 | global.WaitUpdates.Range(func(key, obj interface{}) bool {
77 | err := Update(obj)
78 | if err != nil {
79 | LG.Release("update error %s Object %+v", err.Error(), obj)
80 | } else {
81 | // delete wait update
82 | global.WaitUpdates.Delete(key)
83 | }
84 | return true
85 | })
86 | }
87 |
--------------------------------------------------------------------------------
/debug/conf/conf.go:
--------------------------------------------------------------------------------
1 | package conf
2 |
3 | import (
4 | "log"
5 | "time"
6 | )
7 |
8 | var (
9 | // log conf
10 | LogFlag = log.LstdFlags
11 |
12 | // gate conf
13 | PendingWriteNum = 2000
14 | MaxMsgLen uint32 = 4096
15 | HTTPTimeout = 10 * time.Second
16 | LenMsgLen = 2
17 | LittleEndian = false
18 |
19 | // skeleton conf
20 | GoLen = 10000
21 | TimerDispatcherLen = 10000
22 | AsynCallLen = 10000
23 | ChanRPCLen = 10000
24 | )
25 |
--------------------------------------------------------------------------------
/debug/conf/json.go:
--------------------------------------------------------------------------------
1 | package conf
2 |
3 | import (
4 | "encoding/json"
5 | "github.com/name5566/leaf/log"
6 | "io/ioutil"
7 | "server/bean"
8 | )
9 |
10 | var Server struct {
11 | LogLevel string
12 | LogPath string
13 | WSAddr string
14 | CertFile string
15 | KeyFile string
16 | TCPAddr string
17 | MaxConnNum int
18 | ConsolePort int
19 | ProfilePath string
20 | //lua script
21 | Games []bean.Game
22 | }
23 |
24 | func init() {
25 | data, err := ioutil.ReadFile("conf/server.json")
26 | if err != nil {
27 | log.Fatal("%v", err)
28 | }
29 | err = json.Unmarshal(data, &Server)
30 | if err != nil {
31 | log.Fatal("%v", err)
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/debug/conf/server.json:
--------------------------------------------------------------------------------
1 | {
2 | "LogLevel": "error",
3 | "LogPath": "",
4 | "TCPAddr": "0.0.0.0:3563",
5 | "HTTPAddr": "0.0.0.0:6100",
6 | "WSAddr": "0.0.0.0:3565",
7 | "MaxConnNum": 20000,
8 | "DBSource": "user=dz_db password=d2SQC4nEeqDF958qLiu2 dbname=dz host=pgm-bp1rx6909s61kx0f9o.pg.rds.aliyuncs.com port=1433 sslmode=disable",
9 | "DBMaxConn": 200,
10 | "DBIdleConn": 10,
11 | "Games": [
12 | {"name":"classic_ddz","root": "./../lua/game/classic_ddz/game/root.lua","vm_size": 1,"room":3000,"des": "性能瓶颈的时候通过命令动态创建新的虚拟机个数,各场次房间个数量由LUA来定"}
13 | ],
14 | "EncryptStr": "TH27Cco/KLPtga3Z1BLMNwTaEXp/B8GnLQpKbkKk8esx6qCIQ1eYdPdfDizG+WxG04lSpfXXry8c2+OHgqxEOSGqiimMsMCE/1tt/Ku0SLqT5Hj2n949yx7VaQvyNR+5WWjNoVMVg6Ps9BtkeeDPDb1rIvMgjXJ274DfcE1OkPg4JLyuycMyGvvlXkDuhp0CsjTdECNdd9E6HUlab0VznjZnqbEnXP3pjqjQaoXc1lQ7YSqm5mPIPNKUi3szDMecAxf6AVYUvxkrPpVPWAi1msX+Zrh8AC6bSxhR6MThfo/YBSVBBufCJs4wFpJHl2K3ZQ/wdb5gouITUJGWmVW2cQ=="
15 | }
16 |
--------------------------------------------------------------------------------
/debug/run_ai_server.sh:
--------------------------------------------------------------------------------
1 | nohup ./ai_server -auto false -max 3000 -root "/root/golang/src/server/ai/lua/root.lua" &
2 |
--------------------------------------------------------------------------------
/debug/run_debug.sh:
--------------------------------------------------------------------------------
1 | nohup ./debug_main &
2 |
--------------------------------------------------------------------------------
/debug/shutdown.sh:
--------------------------------------------------------------------------------
1 | kill 32602
--------------------------------------------------------------------------------
/encrypt/cipher.go:
--------------------------------------------------------------------------------
1 | package encrypt
2 |
3 | import "server/leaf/log"
4 |
5 | type Cipher struct {
6 | // 编码用的密码
7 | encodePassword *password
8 | // 解码用的密码
9 | decodePassword *password
10 | }
11 |
12 | // 加密原数据
13 | func (cipher *Cipher) Encode(bs []byte) {
14 | for i, v := range bs {
15 | bs[i] = cipher.encodePassword[v]
16 | }
17 | }
18 |
19 | // 解码加密后的数据到原数据
20 | func (cipher *Cipher) Decode(bs []byte) {
21 | for i, v := range bs {
22 | bs[i] = cipher.decodePassword[v]
23 | }
24 | }
25 |
26 | var CipherX *Cipher
27 |
28 | // 新建一个编码解码器
29 | func InitCipher(pw string) {
30 | encodePassword, err := ParsePassword(pw)
31 | if err != nil {
32 | log.Fatal("Init cipher password error %v", err)
33 | }
34 | decodePassword := &password{}
35 | for i, v := range encodePassword {
36 | encodePassword[i] = v
37 | decodePassword[v] = byte(i)
38 | }
39 | CipherX = &Cipher{
40 | encodePassword: encodePassword,
41 | decodePassword: decodePassword,
42 | }
43 | }
44 |
45 | // 新建一个编码解码器
46 | func NewCipher(encodePassword *password) *Cipher {
47 | decodePassword := &password{}
48 | for i, v := range encodePassword {
49 | encodePassword[i] = v
50 | decodePassword[v] = byte(i)
51 | }
52 | return &Cipher{
53 | encodePassword: encodePassword,
54 | decodePassword: decodePassword,
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/encrypt/cipher_test.go:
--------------------------------------------------------------------------------
1 | package encrypt
2 |
3 | import (
4 | "crypto/rand"
5 | "reflect"
6 | "testing"
7 | )
8 |
9 | const (
10 | MB = 1024 * 1024
11 | )
12 |
13 | // 测试 Cipher 加密解密
14 | func TestCipher(t *testing.T) {
15 | password := RandPassword()
16 | t.Log(password)
17 | p, _ := ParsePassword(password)
18 | cipher := NewCipher(p)
19 | // 原数据
20 | org := make([]byte, passwordLength)
21 | for i := 0; i < passwordLength; i++ {
22 | org[i] = byte(i)
23 | }
24 | // 复制一份原数据到 tmp
25 | tmp := make([]byte, passwordLength)
26 | copy(tmp, org)
27 | t.Log(tmp)
28 | // 加密 tmp
29 | cipher.Encode(tmp)
30 | t.Log(tmp)
31 | // 解密 tmp
32 | cipher.Decode(tmp)
33 | t.Log(tmp)
34 | if !reflect.DeepEqual(org, tmp) {
35 | t.Error("解码编码数据后无法还原数据,数据不对应")
36 | }
37 | }
38 |
39 | func BenchmarkEncode(b *testing.B) {
40 | password := RandPassword()
41 | p, _ := ParsePassword(password)
42 | cipher := NewCipher(p)
43 | bs := make([]byte, MB)
44 | b.ResetTimer()
45 | rand.Read(bs)
46 | cipher.Encode(bs)
47 | }
48 |
49 | func BenchmarkDecode(b *testing.B) {
50 | password := RandPassword()
51 | p, _ := ParsePassword(password)
52 | cipher := NewCipher(p)
53 | bs := make([]byte, MB)
54 | b.ResetTimer()
55 | rand.Read(bs)
56 | cipher.Decode(bs)
57 | }
58 |
--------------------------------------------------------------------------------
/encrypt/password.go:
--------------------------------------------------------------------------------
1 | package encrypt
2 |
3 | import (
4 | "encoding/base64"
5 | "errors"
6 | "math/rand"
7 | "strings"
8 | "time"
9 | )
10 |
11 | const passwordLength = 256
12 |
13 | type password [passwordLength]byte
14 |
15 | func init() {
16 | // 更新随机种子,防止生成一样的随机密码
17 | rand.Seed(time.Now().Unix())
18 | }
19 |
20 | // 采用base64编码把密码转换为字符串
21 | func (password *password) String() string {
22 | return base64.StdEncoding.EncodeToString(password[:])
23 | }
24 |
25 | // 解析采用base64编码的字符串获取密码
26 | func ParsePassword(passwordString string) (*password, error) {
27 | bs, err := base64.StdEncoding.DecodeString(strings.TrimSpace(passwordString))
28 | if err != nil || len(bs) != passwordLength {
29 | return nil, errors.New("不合法的密码")
30 | }
31 | password := password{}
32 | copy(password[:], bs)
33 | bs = nil
34 | return &password, nil
35 | }
36 |
37 | // 产生 256个byte随机组合的 密码,最后会使用base64编码为字符串存储在配置文件中
38 | // 不能出现任何一个重复的byte位,必须又 0-255 组成,并且都需要包含
39 | func RandPassword() string {
40 | // 随机生成一个由 0~255 组成的 byte 数组
41 | intArr := rand.Perm(passwordLength)
42 | password := &password{}
43 | for i, v := range intArr {
44 | password[i] = byte(v)
45 | if i == v {
46 | // 确保不会出现如何一个byte位出现重复
47 | return RandPassword()
48 | }
49 | }
50 | return password.String()
51 | }
52 |
--------------------------------------------------------------------------------
/encrypt/password_test.go:
--------------------------------------------------------------------------------
1 | package encrypt
2 |
3 | import (
4 | "sort"
5 | "testing"
6 | )
7 |
8 | func (password *password) Len() int {
9 | return passwordLength
10 | }
11 |
12 | func (password *password) Less(i, j int) bool {
13 | return password[i] < password[j]
14 | }
15 |
16 | func (password *password) Swap(i, j int) {
17 | password[i], password[j] = password[j], password[i]
18 | }
19 |
20 | func TestRandPassword(t *testing.T) {
21 | password := RandPassword()
22 | t.Log(password)
23 | bsPassword, err := ParsePassword(password)
24 | if err != nil {
25 | t.Error(err)
26 | }
27 | sort.Sort(bsPassword)
28 | for i := 0; i < passwordLength; i++ {
29 | if bsPassword[i] != byte(i) {
30 | t.Error("不能出现任何一个重复的byte位,必须由 0-255 组成,并且都需要包含")
31 | }
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/game/external.go:
--------------------------------------------------------------------------------
1 | package game
2 |
3 | import (
4 | "server/game/internal"
5 | )
6 |
7 | var (
8 | Module = new(internal.Module)
9 | ChanRPC = internal.ChanRPC
10 | Init = internal.Init
11 | )
12 |
--------------------------------------------------------------------------------
/game/internal/chanrpc.go:
--------------------------------------------------------------------------------
1 | package internal
2 |
3 | import (
4 | "log"
5 | "server/bean"
6 | "server/leaf/gate"
7 | "server/vm"
8 | )
9 |
10 | func init() {
11 | skeleton.RegisterChanRPC("NewAgent", rpcNewAgent)
12 | skeleton.RegisterChanRPC("CloseAgent", rpcCloseAgent)
13 | }
14 |
15 | func rpcNewAgent(args []interface{}) {
16 | a := args[0].(gate.Agent)
17 | _ = a
18 | }
19 |
20 | func rpcCloseAgent(args []interface{}) {
21 | a := args[0].(gate.Agent)
22 | d := a.UserData()
23 | if d != nil {
24 | player, ok := d.(*bean.Player)
25 | defer func() {
26 | recover()
27 | log.Printf("Player %s offline \n ", player.Uuid)
28 | }()
29 | // 玩家断线了发送到LUA
30 | if ok && player.GetRoom() != nil {
31 | calldata := vm.NewCallData("player_disconnect", []interface{}{player.Id}, 0)
32 | player.GetRoom().VM.CallChan <- calldata
33 | bean.HandleResult(calldata.Result, 0)
34 | }
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/game/internal/module.go:
--------------------------------------------------------------------------------
1 | package internal
2 |
3 | import (
4 | "server/base"
5 | "server/leaf/module"
6 | )
7 |
8 | var (
9 | skeleton = base.NewSkeleton()
10 | ChanRPC = skeleton.ChanRPCServer
11 | )
12 |
13 | type Module struct {
14 | *module.Skeleton
15 | }
16 |
17 | func (m *Module) OnInit() {
18 | m.Skeleton = skeleton
19 | }
20 |
21 | func (m *Module) OnDestroy() {
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/gamedata/reader.go:
--------------------------------------------------------------------------------
1 | package gamedata
2 |
3 | import (
4 | "reflect"
5 | "server/leaf/log"
6 | "server/leaf/recordfile"
7 | )
8 |
9 | func readRf(st interface{}) *recordfile.RecordFile {
10 | rf, err := recordfile.New(st)
11 | if err != nil {
12 | log.Fatal("%v", err)
13 | }
14 | fn := reflect.TypeOf(st).Name() + ".txt"
15 | err = rf.Read("gamedata/" + fn)
16 | if err != nil {
17 | log.Fatal("%v: %v", fn, err)
18 | }
19 | return rf
20 | }
21 |
--------------------------------------------------------------------------------
/gate/external.go:
--------------------------------------------------------------------------------
1 | package gate
2 |
3 | import (
4 | "server/gate/internal"
5 | )
6 |
7 | var (
8 | Module = new(internal.Module)
9 | )
10 |
--------------------------------------------------------------------------------
/gate/internal/module.go:
--------------------------------------------------------------------------------
1 | package internal
2 |
3 | import (
4 | "server/conf"
5 | "server/game"
6 | "server/leaf/gate"
7 | "server/msg"
8 | )
9 |
10 | type Module struct {
11 | *gate.Gate
12 | }
13 |
14 | func (m *Module) OnInit() {
15 | m.Gate = &gate.Gate{
16 | MaxConnNum: conf.Server.MaxConnNum,
17 | PendingWriteNum: conf.PendingWriteNum,
18 | MaxMsgLen: conf.MaxMsgLen,
19 | WSAddr: conf.Server.WSAddr,
20 | HTTPTimeout: conf.HTTPTimeout,
21 | CertFile: conf.Server.CertFile,
22 | KeyFile: conf.Server.KeyFile,
23 | TCPAddr: conf.Server.TCPAddr,
24 | LenMsgLen: conf.LenMsgLen,
25 | LittleEndian: conf.LittleEndian,
26 | Processor: msg.Processor,
27 | AgentChanRPC: game.ChanRPC,
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/gate/router.go:
--------------------------------------------------------------------------------
1 | package gate
2 |
3 | import (
4 | "github.com/golang/protobuf/proto"
5 | "server/game"
6 | "server/hall"
7 | "server/leaf/gate"
8 | "server/leaf/log"
9 | "server/msg"
10 | "server/protobuf"
11 | )
12 |
13 | // heartbeat
14 | var hb proto.Message
15 |
16 | func init() {
17 | // game
18 | msg.Processor.SetRouter(&protobuf.Protocol{}, game.ChanRPC)
19 | msg.Processor.SetRouter(&protobuf.CsEnterRoom{}, game.ChanRPC)
20 | // hall
21 | msg.Processor.SetRouter(&protobuf.CsLogin{}, hall.ChanRPC)
22 | msg.Processor.SetRouter(&protobuf.CsRegister{}, hall.ChanRPC)
23 | msg.Processor.SetRouter(&protobuf.CsCreateUnion{}, hall.ChanRPC)
24 | msg.Processor.SetRouter(&protobuf.CsJoinUnion{}, hall.ChanRPC)
25 | msg.Processor.SetRouter(&protobuf.CsQueryUnion{}, hall.ChanRPC)
26 | msg.Processor.SetRouter(&protobuf.CsMailReq{}, hall.ChanRPC)
27 | msg.Processor.SetRouter(&protobuf.CsReadMail{}, hall.ChanRPC)
28 | msg.Processor.SetRouter(&protobuf.CsUnionInfo{}, hall.ChanRPC)
29 | msg.Processor.SetRouter(&protobuf.CsExitUnion{}, hall.ChanRPC)
30 | msg.Processor.SetRouter(&protobuf.CsUnionSettings{}, hall.ChanRPC)
31 | msg.Processor.SetRouter(&protobuf.CsTransferMaster{}, hall.ChanRPC)
32 | msg.Processor.SetRouter(&protobuf.CsTickMember{}, hall.ChanRPC)
33 | msg.Processor.SetRouter(&protobuf.CsLocation{}, hall.ChanRPC)
34 | msg.Processor.SetRouter(&protobuf.CsUnionRank{}, hall.ChanRPC)
35 | // hb
36 | hb = &protobuf.Heartbeat{}
37 | msg.Processor.SetHandler(hb, func(args []interface{}) {
38 | // ping-pong
39 | hb := args[0].(*protobuf.Heartbeat)
40 | agent := args[1].(gate.Agent)
41 | agent.WriteMsg(hb)
42 | log.Debug("Heartbeat Message.")
43 | })
44 | }
45 |
--------------------------------------------------------------------------------
/global/stutas.go:
--------------------------------------------------------------------------------
1 | package global
2 |
3 | import (
4 | "sync"
5 | )
6 |
7 | // 全局状态
8 | var (
9 | // 用户与映射
10 | Players = sync.Map{}
11 | // 房间映射
12 | Rooms = sync.Map{}
13 | // 有数据发生变化的用户
14 | WaitUpdates = sync.Map{}
15 | // 指定存储某对象
16 | OnSingleSave = make(chan SingleSave)
17 | // 等待队列
18 | WaitQueue = make(chan interface{}, 10000)
19 | )
20 |
21 | // 单个保存
22 | type SingleSave struct {
23 | // 数据
24 | Data interface{}
25 | // 错误
26 | Err chan error
27 | // 类型 0 update // 1 insert []interface{} // 2 insert obj
28 | Type int
29 | // 数量
30 | Length int
31 | }
32 |
--------------------------------------------------------------------------------
/hall/handler.go:
--------------------------------------------------------------------------------
1 | package hall
2 |
3 | import (
4 | "reflect"
5 | "server/hall/login"
6 | "server/hall/mail"
7 | "server/hall/union"
8 | "server/protobuf"
9 | )
10 |
11 | func handleMsg(m interface{}, h interface{}) {
12 | skeleton.RegisterChanRPC(reflect.TypeOf(m), h)
13 | }
14 |
15 | func init() {
16 | // login
17 | handleMsg(&protobuf.CsLogin{}, login.Login)
18 | handleMsg(&protobuf.CsRegister{}, login.Register)
19 | handleMsg(&protobuf.CsLocation{}, login.UpdateLocation)
20 | // union
21 | handleMsg(&protobuf.CsCreateUnion{}, union.CreateUnion)
22 | handleMsg(&protobuf.CsQueryUnion{}, union.Query)
23 | handleMsg(&protobuf.CsJoinUnion{}, union.Join)
24 | handleMsg(&protobuf.CsUnionInfo{}, union.GetUnionDetail)
25 | handleMsg(&protobuf.CsExitUnion{}, union.Exit)
26 | handleMsg(&protobuf.CsUnionSettings{}, union.Settings)
27 | handleMsg(&protobuf.CsTransferMaster{}, union.Transfer)
28 | handleMsg(&protobuf.CsTickMember{}, union.TickMember)
29 | handleMsg(&protobuf.CsUnionRank{}, union.RankRoll)
30 | // email
31 | handleMsg(&protobuf.CsMailReq{}, mail.PullMail)
32 | handleMsg(&protobuf.CsReadMail{}, mail.ReadMail)
33 | }
34 |
--------------------------------------------------------------------------------
/hall/mail/box.go:
--------------------------------------------------------------------------------
1 | package mail
2 |
--------------------------------------------------------------------------------
/hall/module.go:
--------------------------------------------------------------------------------
1 | package hall
2 |
3 | import (
4 | "server/base"
5 | "server/leaf/module"
6 | )
7 |
8 | var (
9 | skeleton = base.NewSkeleton()
10 | ChanRPC = skeleton.ChanRPCServer
11 | )
12 |
13 | type Module struct {
14 | *module.Skeleton
15 | }
16 |
17 | func (m *Module) OnInit() {
18 | m.Skeleton = skeleton
19 | }
20 |
21 | func (m *Module) OnDestroy() {
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/hall/union/info.go:
--------------------------------------------------------------------------------
1 | package union
2 |
3 | import (
4 | "github.com/astaxie/beego/orm"
5 | "server/bean"
6 | "server/global"
7 | "server/leaf/gate"
8 | "server/leaf/log"
9 | "server/protobuf"
10 | )
11 |
12 | func GetUnionDetail(args []interface{}) {
13 | m := args[0].(*protobuf.CsUnionInfo)
14 | agent := args[1].(gate.Agent)
15 | p, ok := agent.UserData().(*bean.Player)
16 | if ok {
17 | qUnionId := m.UnionId
18 | if qUnionId == -1 {
19 | cp, ok := global.Players.Load(p.Uuid)
20 | if ok {
21 | cp := cp.(*bean.Player)
22 | qUnionId = cp.Union
23 | }
24 | }
25 | o := orm.NewOrm()
26 | var u bean.Union
27 | err := o.QueryTable("union").Filter("id", qUnionId).One(&u)
28 | if err != nil {
29 | log.Error("Get Union detail error %v", err)
30 | errInfo := protobuf.ScError{
31 | Code: bean.NOT_FOUND_UNION,
32 | Reason: "",
33 | }
34 | agent.WriteMsg(&errInfo)
35 | return
36 | } else {
37 | var members []*bean.Player
38 | _, err = o.QueryTable("player").Filter("union", qUnionId).All(&members)
39 | if err != nil {
40 | log.Error("Get Union detail error %v", err)
41 | errInfo := protobuf.ScError{
42 | Code: bean.NOT_FOUND_UNION,
43 | Reason: "",
44 | }
45 | agent.WriteMsg(&errInfo)
46 | return
47 | } else {
48 | pu := protobuf.ScUnionInfo{
49 | Id: u.Id,
50 | Name: u.Name,
51 | Level: int32(u.Level),
52 | Notice: u.Notice,
53 | Des: u.Des,
54 | Score: u.Score,
55 | MasterId: u.MasterId,
56 | Creator: u.Creater,
57 | CreateTime: u.CreateTime,
58 | MaxMember: int32(u.MaxMember),
59 | Status: int32(u.Status),
60 | }
61 | pu.Members = make([]*protobuf.ScUnionMember, 0)
62 | for _, p := range members {
63 | scum := protobuf.ScUnionMember{
64 | PlayerUuid: p.Uuid,
65 | Name: p.Name,
66 | Level: p.Level,
67 | UnionVal: p.UnionVal,
68 | Head: p.Head,
69 | }
70 | pu.Members = append(pu.Members, &scum)
71 | }
72 | agent.WriteMsg(&pu)
73 | }
74 | }
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/hall/union/manage.go:
--------------------------------------------------------------------------------
1 | package union
2 |
3 | import (
4 | "github.com/astaxie/beego/orm"
5 | "server/bean"
6 | "server/global"
7 | "server/leaf/gate"
8 | "server/leaf/log"
9 | "server/protobuf"
10 | "time"
11 | )
12 |
13 | func CreateUnion(args []interface{}) {
14 | m := args[0].(*protobuf.CsCreateUnion)
15 | agent := args[1].(gate.Agent)
16 | creator, ok := agent.UserData().(*bean.Player)
17 | ret := protobuf.ScCreateUnion{
18 | Ok: false,
19 | Info: nil,
20 | }
21 | if ok {
22 | o := orm.NewOrm()
23 | if o.QueryTable("union").Filter("name", m.Name).Exist() {
24 | errInfo := protobuf.ScError{
25 | Code: bean.CREATE_UNION_FAILED_NAME_EXIST,
26 | Reason: "",
27 | }
28 | agent.WriteMsg(&errInfo)
29 | return
30 | }
31 | un := new(bean.Union)
32 | un.Name = m.Name
33 | un.Creater = creator.Name
34 | un.MasterId = creator.Id
35 | un.MasterUuid = creator.Uuid
36 | un.CreateTime = time.Now().Unix()
37 | un.Level = 1
38 | un.MaxMember = 200
39 | un.Des = m.Des
40 | un.Members++
41 | gs := global.SingleSave{
42 | Data: un,
43 | Err: make(chan error, 1),
44 | Type: 1,
45 | Length: 0,
46 | }
47 | global.OnSingleSave <- gs
48 | err := <-gs.Err
49 | if err != nil {
50 | log.Error("CreateUnion Error %s", err.Error())
51 | errInfo := protobuf.ScError{
52 | Code: bean.CREATE_UNION_FAILED,
53 | Reason: err.Error(),
54 | }
55 | agent.WriteMsg(&errInfo)
56 | return
57 | }
58 | creator.Union = un.Id
59 | global.Players.Store(creator.Uuid, creator)
60 | global.Players.Store(creator.Name, creator)
61 | // update creator
62 | gs.Data = creator
63 | gs.Type = 0
64 | global.OnSingleSave <- gs
65 | err = <-gs.Err
66 | if err != nil {
67 | log.Error("update creator err %v", err)
68 | }
69 | ret.Ok = true
70 | ret.Info = &protobuf.ScUnionInfo{
71 | Id: un.Id,
72 | Name: un.Name,
73 | Level: 1,
74 | Notice: un.Notice,
75 | Des: un.Des,
76 | Score: un.Score,
77 | MasterId: un.MasterId,
78 | Creator: un.Creater,
79 | CreateTime: un.CreateTime,
80 | MaxMember: int32(un.MaxMember),
81 | Status: int32(un.Status),
82 | MasterUuid: un.MasterUuid,
83 | }
84 | mb := protobuf.ScUnionMember{
85 | Name: creator.Name,
86 | Level: creator.Level,
87 | UnionVal: creator.UnionVal,
88 | Head: creator.Head,
89 | PlayerUuid: creator.Uuid,
90 | }
91 | ret.Info.Members = []*protobuf.ScUnionMember{&mb}
92 | } else {
93 | ret.Reason = "无效连接,需要重新登录"
94 | }
95 | agent.WriteMsg(&ret)
96 | }
97 |
98 | func DestroyUnion(un *bean.Union) {
99 |
100 | }
101 |
--------------------------------------------------------------------------------
/hall/union/rank.go:
--------------------------------------------------------------------------------
1 | package union
2 |
--------------------------------------------------------------------------------
/httpsv/handler.go:
--------------------------------------------------------------------------------
1 | package httpsv
2 |
3 | import (
4 | "github.com/astaxie/beego/orm"
5 | "github.com/kataras/iris/context"
6 | "server/bean"
7 | "server/leaf/log"
8 | )
9 |
10 | func init() {
11 | app.Get("/", func(ctx context.Context) {
12 | ctx.StatusCode(403)
13 | })
14 | app.Get("/game/record/{id}/{page}", func(ctx context.Context) {
15 | id := ctx.Params().Get("id")
16 | page, err := ctx.Params().GetInt("page")
17 | if err != nil {
18 | // default page 1
19 | page = 1
20 | }
21 | var ulog []*bean.UserLog
22 | o := orm.NewOrm()
23 | _, err = o.QueryTable("user_log").Filter("player_id", id).Offset(page - 1*20).Limit(20).All(&ulog)
24 | ret := &Resp{}
25 | if err != nil {
26 | log.Error("Query user log error %s", err)
27 | ret.Ret = -1
28 | ret.Error = err.Error()
29 | } else {
30 | if len(ulog) == 0 {
31 | // 没有日志
32 | ret.DATA = make([]*bean.GameLog, 0)
33 | } else {
34 | loguuids := make([]interface{}, 0)
35 | for _, per := range ulog {
36 | loguuids = append(loguuids, per.LogUuid)
37 | }
38 | var gameLogs []*bean.GameLog
39 | _, err = o.QueryTable("game_log").Filter("log_uuid__in", loguuids...).All(&gameLogs)
40 | if err != nil {
41 | log.Error("Query game log error %s", err)
42 | ret.Error = err.Error()
43 | ret.Ret = -1
44 | } else {
45 | ret.DATA = gameLogs
46 | }
47 | }
48 | }
49 | ctx.JSON(ret)
50 | })
51 | }
52 |
--------------------------------------------------------------------------------
/httpsv/iris.go:
--------------------------------------------------------------------------------
1 | package httpsv
2 |
3 | import (
4 | "github.com/kataras/iris"
5 | "github.com/kataras/iris/context"
6 | "github.com/kataras/iris/middleware/logger"
7 | rc "github.com/kataras/iris/middleware/recover"
8 | "github.com/kataras/iris/sessions"
9 | "server/leaf/log"
10 | )
11 |
12 | var (
13 | app = iris.New()
14 | cookieNameForSessionID = "xPLay21cookies3SXLUssionnAXeid"
15 | sess = sessions.New(sessions.Config{Cookie: cookieNameForSessionID, AllowReclaim: true})
16 | )
17 |
18 | func init() {
19 | /*app.RegisterView(iris.HTML("./web", ".html").Reload(true))
20 | app.StaticWeb("/web", "./web")
21 | app.StaticWeb("/fonts", "./web/fonts")
22 | app.StaticWeb("/images", "./web/images")*/
23 | app.Use(rc.New())
24 | app.Use(logger.New())
25 | app.UseGlobal(func(ctx context.Context) {
26 | ctx.Header("Access-Control-Allow-Origin", "*")
27 | //clientIp := GetClientIp(ctx)
28 | //log.Printf("Request from ip ==> %s", clientIp)
29 | ctx.Next()
30 | })
31 | }
32 | func RunHTTP(addr string) {
33 | if err := app.Run(iris.Addr(addr), iris.WithoutServerError(iris.ErrServerClosed)); err != nil {
34 | log.Error("HTTP Server startup error %s", err)
35 | } else {
36 | log.Release("HTTP Server startup at %s", addr)
37 | }
38 | }
39 |
40 | type Resp struct {
41 | Ret int
42 | Error string
43 | DATA interface{}
44 | }
45 |
46 | func GetClientIp(ctx context.Context) string {
47 | clientIp := ctx.Request().Header.Get("CF-Connecting-IP")
48 | if clientIp == "" {
49 | clientIp = ctx.Request().Header.Get("X-Forwarded-For")
50 | if clientIp == "" {
51 | clientIp = ctx.RemoteAddr()
52 | }
53 | }
54 | return clientIp
55 | }
56 |
--------------------------------------------------------------------------------
/interface/interface.go:
--------------------------------------------------------------------------------
1 | package interfaces
2 |
3 | import "server/vm"
4 |
5 | type VRoom interface {
6 | GetVm() *vm.VM
7 | }
8 |
--------------------------------------------------------------------------------
/leaf-server.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/leaf/README.md:
--------------------------------------------------------------------------------
1 | Leaf
2 | ====
3 | A pragmatic game server framework in Go (golang).
4 |
5 | Features
6 | ---------
7 |
8 | * Extremely easy to use
9 | * Reliable
10 | * Multicore support
11 | * Modularity
12 |
13 | Community
14 | ---------
15 |
16 | * QQ 群:376389675
17 |
18 | Documentation
19 | ---------
20 |
21 | * [中文文档](https://server/leaf/blob/master/TUTORIAL_ZH.md)
22 | * [English](https://server/leaf/blob/master/TUTORIAL_EN.md)
23 |
24 | Licensing
25 | ---------
26 |
27 | Leaf is licensed under the Apache License, Version 2.0. See [LICENSE](https://server/leaf/blob/master/LICENSE) for the full license text.
28 |
--------------------------------------------------------------------------------
/leaf/chanrpc/example_test.go:
--------------------------------------------------------------------------------
1 | package chanrpc_test
2 |
3 | import (
4 | "fmt"
5 | "server/leaf/chanrpc"
6 | "sync"
7 | )
8 |
9 | func Example() {
10 | s := chanrpc.NewServer(10)
11 |
12 | var wg sync.WaitGroup
13 | wg.Add(1)
14 |
15 | // goroutine 1
16 | go func() {
17 | s.Register("f0", func(args []interface{}) {
18 |
19 | })
20 |
21 | s.Register("f1", func(args []interface{}) interface{} {
22 | return 1
23 | })
24 |
25 | s.Register("fn", func(args []interface{}) []interface{} {
26 | return []interface{}{1, 2, 3}
27 | })
28 |
29 | s.Register("add", func(args []interface{}) interface{} {
30 | n1 := args[0].(int)
31 | n2 := args[1].(int)
32 | return n1 + n2
33 | })
34 |
35 | wg.Done()
36 |
37 | for {
38 | s.Exec(<-s.ChanCall)
39 | }
40 | }()
41 |
42 | wg.Wait()
43 | wg.Add(1)
44 |
45 | // goroutine 2
46 | go func() {
47 | c := s.Open(10)
48 |
49 | // sync
50 | err := c.Call0("f0")
51 | if err != nil {
52 | fmt.Println(err)
53 | }
54 |
55 | r1, err := c.Call1("f1")
56 | if err != nil {
57 | fmt.Println(err)
58 | } else {
59 | fmt.Println(r1)
60 | }
61 |
62 | rn, err := c.CallN("fn")
63 | if err != nil {
64 | fmt.Println(err)
65 | } else {
66 | fmt.Println(rn[0], rn[1], rn[2])
67 | }
68 |
69 | ra, err := c.Call1("add", 1, 2)
70 | if err != nil {
71 | fmt.Println(err)
72 | } else {
73 | fmt.Println(ra)
74 | }
75 |
76 | // asyn
77 | c.AsynCall("f0", func(err error) {
78 | if err != nil {
79 | fmt.Println(err)
80 | }
81 | })
82 |
83 | c.AsynCall("f1", func(ret interface{}, err error) {
84 | if err != nil {
85 | fmt.Println(err)
86 | } else {
87 | fmt.Println(ret)
88 | }
89 | })
90 |
91 | c.AsynCall("fn", func(ret []interface{}, err error) {
92 | if err != nil {
93 | fmt.Println(err)
94 | } else {
95 | fmt.Println(ret[0], ret[1], ret[2])
96 | }
97 | })
98 |
99 | c.AsynCall("add", 1, 2, func(ret interface{}, err error) {
100 | if err != nil {
101 | fmt.Println(err)
102 | } else {
103 | fmt.Println(ret)
104 | }
105 | })
106 |
107 | c.Cb(<-c.ChanAsynRet)
108 | c.Cb(<-c.ChanAsynRet)
109 | c.Cb(<-c.ChanAsynRet)
110 | c.Cb(<-c.ChanAsynRet)
111 |
112 | // go
113 | s.Go("f0")
114 |
115 | wg.Done()
116 | }()
117 |
118 | wg.Wait()
119 |
120 | // Output:
121 | // 1
122 | // 1 2 3
123 | // 3
124 | // 1
125 | // 1 2 3
126 | // 3
127 | }
128 |
--------------------------------------------------------------------------------
/leaf/cluster/cluster.go:
--------------------------------------------------------------------------------
1 | package cluster
2 |
3 | import (
4 | "math"
5 | "server/leaf/conf"
6 | "server/leaf/network"
7 | "time"
8 | )
9 |
10 | var (
11 | server *network.TCPServer
12 | clients []*network.TCPClient
13 | )
14 |
15 | func Init() {
16 | if conf.ListenAddr != "" {
17 | server = new(network.TCPServer)
18 | server.Addr = conf.ListenAddr
19 | server.MaxConnNum = int(math.MaxInt32)
20 | server.PendingWriteNum = conf.PendingWriteNum
21 | server.LenMsgLen = 4
22 | server.MaxMsgLen = math.MaxUint32
23 | server.NewAgent = newAgent
24 |
25 | server.Start()
26 | }
27 |
28 | for _, addr := range conf.ConnAddrs {
29 | client := new(network.TCPClient)
30 | client.Addr = addr
31 | client.ConnNum = 1
32 | client.ConnectInterval = 3 * time.Second
33 | client.PendingWriteNum = conf.PendingWriteNum
34 | client.LenMsgLen = 4
35 | client.MaxMsgLen = math.MaxUint32
36 | client.NewAgent = newAgent
37 |
38 | client.Start()
39 | clients = append(clients, client)
40 | }
41 | }
42 |
43 | func Destroy() {
44 | if server != nil {
45 | server.Close()
46 | }
47 |
48 | for _, client := range clients {
49 | client.Close()
50 | }
51 | }
52 |
53 | type Agent struct {
54 | conn *network.TCPConn
55 | }
56 |
57 | func newAgent(conn *network.TCPConn) network.Agent {
58 | a := new(Agent)
59 | a.conn = conn
60 | return a
61 | }
62 |
63 | func (a *Agent) Run() {}
64 |
65 | func (a *Agent) OnClose() {}
66 |
--------------------------------------------------------------------------------
/leaf/conf/conf.go:
--------------------------------------------------------------------------------
1 | package conf
2 |
3 | var (
4 | LenStackBuf = 4096
5 |
6 | // log
7 | LogLevel string
8 | LogPath string
9 | LogFlag int
10 |
11 | // console
12 | ConsolePort int
13 | ConsolePrompt string = "Leaf# "
14 | ProfilePath string
15 |
16 | // cluster
17 | ListenAddr string
18 | ConnAddrs []string
19 | PendingWriteNum int
20 | )
21 |
--------------------------------------------------------------------------------
/leaf/console/console.go:
--------------------------------------------------------------------------------
1 | package console
2 |
3 | import (
4 | "bufio"
5 | "math"
6 | "server/leaf/conf"
7 | "server/leaf/network"
8 | "strconv"
9 | "strings"
10 | )
11 |
12 | var server *network.TCPServer
13 |
14 | func Init() {
15 | if conf.ConsolePort == 0 {
16 | return
17 | }
18 |
19 | server = new(network.TCPServer)
20 | server.Addr = "localhost:" + strconv.Itoa(conf.ConsolePort)
21 | server.MaxConnNum = int(math.MaxInt32)
22 | server.PendingWriteNum = 100
23 | server.NewAgent = newAgent
24 |
25 | server.Start()
26 | }
27 |
28 | func Destroy() {
29 | if server != nil {
30 | server.Close()
31 | }
32 | }
33 |
34 | type Agent struct {
35 | conn *network.TCPConn
36 | reader *bufio.Reader
37 | }
38 |
39 | func newAgent(conn *network.TCPConn) network.Agent {
40 | a := new(Agent)
41 | a.conn = conn
42 | a.reader = bufio.NewReader(conn)
43 | return a
44 | }
45 |
46 | func (a *Agent) Run() {
47 | for {
48 | if conf.ConsolePrompt != "" {
49 | a.conn.Write([]byte(conf.ConsolePrompt))
50 | }
51 |
52 | line, err := a.reader.ReadString('\n')
53 | if err != nil {
54 | break
55 | }
56 | line = strings.TrimSuffix(line[:len(line)-1], "\r")
57 |
58 | args := strings.Fields(line)
59 | if len(args) == 0 {
60 | continue
61 | }
62 | if args[0] == "quit" {
63 | break
64 | }
65 | var c Command
66 | for _, _c := range commands {
67 | if _c.name() == args[0] {
68 | c = _c
69 | break
70 | }
71 | }
72 | if c == nil {
73 | a.conn.Write([]byte("command not found, try `help` for help\r\n"))
74 | continue
75 | }
76 | output := c.run(args[1:])
77 | if output != "" {
78 | a.conn.Write([]byte(output + "\r\n"))
79 | }
80 | }
81 | }
82 |
83 | func (a *Agent) OnClose() {}
84 |
--------------------------------------------------------------------------------
/leaf/db/mongodb/example_test.go:
--------------------------------------------------------------------------------
1 | package mongodb_test
2 |
3 | import (
4 | "fmt"
5 | "gopkg.in/mgo.v2"
6 | "server/leaf/db/mongodb"
7 | )
8 |
9 | func Example() {
10 | c, err := mongodb.Dial("localhost", 10)
11 | if err != nil {
12 | fmt.Println(err)
13 | return
14 | }
15 | defer c.Close()
16 |
17 | // session
18 | s := c.Ref()
19 | defer c.UnRef(s)
20 | err = s.DB("test").C("counters").RemoveId("test")
21 | if err != nil && err != mgo.ErrNotFound {
22 | fmt.Println(err)
23 | return
24 | }
25 |
26 | // auto increment
27 | err = c.EnsureCounter("test", "counters", "test")
28 | if err != nil {
29 | fmt.Println(err)
30 | return
31 | }
32 | for i := 0; i < 3; i++ {
33 | id, err := c.NextSeq("test", "counters", "test")
34 | if err != nil {
35 | fmt.Println(err)
36 | return
37 | }
38 | fmt.Println(id)
39 | }
40 |
41 | // index
42 | c.EnsureUniqueIndex("test", "counters", []string{"key1"})
43 |
44 | // Output:
45 | // 1
46 | // 2
47 | // 3
48 | }
49 |
--------------------------------------------------------------------------------
/leaf/gate/agent.go:
--------------------------------------------------------------------------------
1 | package gate
2 |
3 | import (
4 | "net"
5 | )
6 |
7 | type Agent interface {
8 | WriteMsg(msg interface{})
9 | WriteRawMsg(data [][]byte)
10 | LocalAddr() net.Addr
11 | RemoteAddr() net.Addr
12 | Close()
13 | Destroy()
14 | UserData() interface{}
15 | SetUserData(data interface{})
16 | }
17 |
--------------------------------------------------------------------------------
/leaf/go/example_test.go:
--------------------------------------------------------------------------------
1 | package g_test
2 |
3 | import (
4 | "fmt"
5 | "server/leaf/go"
6 | "time"
7 | )
8 |
9 | func Example() {
10 | d := g.New(10)
11 |
12 | // go 1
13 | var res int
14 | d.Go(func() {
15 | fmt.Println("1 + 1 = ?")
16 | res = 1 + 1
17 | }, func() {
18 | fmt.Println(res)
19 | })
20 |
21 | d.Cb(<-d.ChanCb)
22 |
23 | // go 2
24 | d.Go(func() {
25 | fmt.Print("My name is ")
26 | }, func() {
27 | fmt.Println("Leaf")
28 | })
29 |
30 | d.Close()
31 |
32 | // Output:
33 | // 1 + 1 = ?
34 | // 2
35 | // My name is Leaf
36 | }
37 |
38 | func ExampleLinearContext() {
39 | d := g.New(10)
40 |
41 | // parallel
42 | d.Go(func() {
43 | time.Sleep(time.Second / 2)
44 | fmt.Println("1")
45 | }, nil)
46 | d.Go(func() {
47 | fmt.Println("2")
48 | }, nil)
49 |
50 | d.Cb(<-d.ChanCb)
51 | d.Cb(<-d.ChanCb)
52 |
53 | // linear
54 | c := d.NewLinearContext()
55 | c.Go(func() {
56 | time.Sleep(time.Second / 2)
57 | fmt.Println("1")
58 | }, nil)
59 | c.Go(func() {
60 | fmt.Println("2")
61 | }, nil)
62 |
63 | d.Close()
64 |
65 | // Output:
66 | // 2
67 | // 1
68 | // 1
69 | // 2
70 | }
71 |
--------------------------------------------------------------------------------
/leaf/go/go.go:
--------------------------------------------------------------------------------
1 | package g
2 |
3 | import (
4 | "container/list"
5 | "runtime"
6 | "server/leaf/conf"
7 | "server/leaf/log"
8 | "sync"
9 | )
10 |
11 | // one Go per goroutine (goroutine not safe)
12 | type Go struct {
13 | ChanCb chan func()
14 | pendingGo int
15 | }
16 |
17 | type LinearGo struct {
18 | f func()
19 | cb func()
20 | }
21 |
22 | type LinearContext struct {
23 | g *Go
24 | linearGo *list.List
25 | mutexLinearGo sync.Mutex
26 | mutexExecution sync.Mutex
27 | }
28 |
29 | func New(l int) *Go {
30 | g := new(Go)
31 | g.ChanCb = make(chan func(), l)
32 | return g
33 | }
34 |
35 | func (g *Go) Go(f func(), cb func()) {
36 | g.pendingGo++
37 |
38 | go func() {
39 | defer func() {
40 | g.ChanCb <- cb
41 | if r := recover(); r != nil {
42 | if conf.LenStackBuf > 0 {
43 | buf := make([]byte, conf.LenStackBuf)
44 | l := runtime.Stack(buf, false)
45 | log.Error("%v: %s", r, buf[:l])
46 | } else {
47 | log.Error("%v", r)
48 | }
49 | }
50 | }()
51 |
52 | f()
53 | }()
54 | }
55 |
56 | func (g *Go) Cb(cb func()) {
57 | defer func() {
58 | g.pendingGo--
59 | if r := recover(); r != nil {
60 | if conf.LenStackBuf > 0 {
61 | buf := make([]byte, conf.LenStackBuf)
62 | l := runtime.Stack(buf, false)
63 | log.Error("%v: %s", r, buf[:l])
64 | } else {
65 | log.Error("%v", r)
66 | }
67 | }
68 | }()
69 |
70 | if cb != nil {
71 | cb()
72 | }
73 | }
74 |
75 | func (g *Go) Close() {
76 | for g.pendingGo > 0 {
77 | g.Cb(<-g.ChanCb)
78 | }
79 | }
80 |
81 | func (g *Go) Idle() bool {
82 | return g.pendingGo == 0
83 | }
84 |
85 | func (g *Go) NewLinearContext() *LinearContext {
86 | c := new(LinearContext)
87 | c.g = g
88 | c.linearGo = list.New()
89 | return c
90 | }
91 |
92 | func (c *LinearContext) Go(f func(), cb func()) {
93 | c.g.pendingGo++
94 |
95 | c.mutexLinearGo.Lock()
96 | c.linearGo.PushBack(&LinearGo{f: f, cb: cb})
97 | c.mutexLinearGo.Unlock()
98 |
99 | go func() {
100 | c.mutexExecution.Lock()
101 | defer c.mutexExecution.Unlock()
102 |
103 | c.mutexLinearGo.Lock()
104 | e := c.linearGo.Remove(c.linearGo.Front()).(*LinearGo)
105 | c.mutexLinearGo.Unlock()
106 |
107 | defer func() {
108 | c.g.ChanCb <- e.cb
109 | if r := recover(); r != nil {
110 | if conf.LenStackBuf > 0 {
111 | buf := make([]byte, conf.LenStackBuf)
112 | l := runtime.Stack(buf, false)
113 | log.Error("%v: %s", r, buf[:l])
114 | } else {
115 | log.Error("%v", r)
116 | }
117 | }
118 | }()
119 |
120 | e.f()
121 | }()
122 | }
123 |
--------------------------------------------------------------------------------
/leaf/leaf.go:
--------------------------------------------------------------------------------
1 | package leaf
2 |
3 | import (
4 | "os"
5 | "os/signal"
6 | "server/leaf/cluster"
7 | "server/leaf/conf"
8 | "server/leaf/console"
9 | "server/leaf/log"
10 | "server/leaf/module"
11 | "syscall"
12 | )
13 |
14 | func Run(mods ...module.Module) {
15 | // logger
16 | if conf.LogLevel != "" {
17 | logger, err := log.New(conf.LogLevel, conf.LogPath, conf.LogFlag)
18 | if err != nil {
19 | panic(err)
20 | }
21 | log.Export(logger)
22 | defer logger.Close()
23 | }
24 |
25 | log.Release("Leaf %v starting up", version)
26 |
27 | // module
28 | for i := 0; i < len(mods); i++ {
29 | module.Register(mods[i])
30 | }
31 | module.Init()
32 |
33 | // cluster
34 | cluster.Init()
35 |
36 | // console
37 | console.Init()
38 |
39 | // close
40 | c := make(chan os.Signal, 1)
41 | signal.Notify(c, os.Interrupt, os.Kill, syscall.SIGTERM)
42 | sig := <-c
43 | log.Release("Leaf closing down (signal: %v)", sig)
44 | console.Destroy()
45 | cluster.Destroy()
46 | module.Destroy()
47 | }
48 |
--------------------------------------------------------------------------------
/leaf/log/example_test.go:
--------------------------------------------------------------------------------
1 | package log_test
2 |
3 | import (
4 | l "log"
5 | "server/leaf/log"
6 | )
7 |
8 | func Example() {
9 | name := "Leaf"
10 |
11 | log.Debug("My name is %v", name)
12 | log.Release("My name is %v", name)
13 | log.Error("My name is %v", name)
14 | // log.Fatal("My name is %v", name)
15 |
16 | logger, err := log.New("release", "", l.LstdFlags)
17 | if err != nil {
18 | return
19 | }
20 | defer logger.Close()
21 |
22 | logger.Debug("will not print")
23 | logger.Release("My name is %v", name)
24 |
25 | log.Export(logger)
26 |
27 | log.Debug("will not print")
28 | log.Release("My name is %v", name)
29 | }
30 |
--------------------------------------------------------------------------------
/leaf/module/module.go:
--------------------------------------------------------------------------------
1 | package module
2 |
3 | import (
4 | "runtime"
5 | "server/leaf/conf"
6 | "server/leaf/log"
7 | "sync"
8 | )
9 |
10 | type Module interface {
11 | OnInit()
12 | OnDestroy()
13 | Run(closeSig chan bool)
14 | }
15 |
16 | type module struct {
17 | mi Module
18 | closeSig chan bool
19 | wg sync.WaitGroup
20 | }
21 |
22 | var mods []*module
23 |
24 | func Register(mi Module) {
25 | m := new(module)
26 | m.mi = mi
27 | m.closeSig = make(chan bool, 1)
28 |
29 | mods = append(mods, m)
30 | }
31 |
32 | func Init() {
33 | for i := 0; i < len(mods); i++ {
34 | mods[i].mi.OnInit()
35 | }
36 |
37 | for i := 0; i < len(mods); i++ {
38 | m := mods[i]
39 | m.wg.Add(1)
40 | go run(m)
41 | }
42 | }
43 |
44 | func Destroy() {
45 | for i := len(mods) - 1; i >= 0; i-- {
46 | m := mods[i]
47 | m.closeSig <- true
48 | m.wg.Wait()
49 | destroy(m)
50 | }
51 | }
52 |
53 | func run(m *module) {
54 | m.mi.Run(m.closeSig)
55 | m.wg.Done()
56 | }
57 |
58 | func destroy(m *module) {
59 | defer func() {
60 | if r := recover(); r != nil {
61 | if conf.LenStackBuf > 0 {
62 | buf := make([]byte, conf.LenStackBuf)
63 | l := runtime.Stack(buf, false)
64 | log.Error("%v: %s", r, buf[:l])
65 | } else {
66 | log.Error("%v", r)
67 | }
68 | }
69 | }()
70 |
71 | m.mi.OnDestroy()
72 | }
73 |
--------------------------------------------------------------------------------
/leaf/network/agent.go:
--------------------------------------------------------------------------------
1 | package network
2 |
3 | type Agent interface {
4 | Run()
5 | OnClose()
6 | }
7 |
--------------------------------------------------------------------------------
/leaf/network/conn.go:
--------------------------------------------------------------------------------
1 | package network
2 |
3 | import (
4 | "net"
5 | )
6 |
7 | type Conn interface {
8 | ReadMsg() ([]byte, error)
9 | WriteMsg(args ...[]byte) error
10 | LocalAddr() net.Addr
11 | RemoteAddr() net.Addr
12 | Close()
13 | Destroy()
14 | }
15 |
--------------------------------------------------------------------------------
/leaf/network/processor.go:
--------------------------------------------------------------------------------
1 | package network
2 |
3 | type Processor interface {
4 | // must goroutine safe
5 | Route(msg interface{}, userData interface{}, raw []byte) error
6 | // must goroutine safe
7 | Unmarshal(data []byte) (interface{}, error)
8 | // must goroutine safe
9 | Marshal(msg interface{}) ([][]byte, error)
10 | }
11 |
--------------------------------------------------------------------------------
/leaf/network/tcp_conn.go:
--------------------------------------------------------------------------------
1 | package network
2 |
3 | import (
4 | "net"
5 | "server/leaf/log"
6 | "sync"
7 | )
8 |
9 | type ConnSet map[net.Conn]struct{}
10 |
11 | type TCPConn struct {
12 | sync.Mutex
13 | conn net.Conn
14 | writeChan chan []byte
15 | closeFlag bool
16 | msgParser *MsgParser
17 | }
18 |
19 | func newTCPConn(conn net.Conn, pendingWriteNum int, msgParser *MsgParser) *TCPConn {
20 | tcpConn := new(TCPConn)
21 | tcpConn.conn = conn
22 | tcpConn.writeChan = make(chan []byte, pendingWriteNum)
23 | tcpConn.msgParser = msgParser
24 |
25 | go func() {
26 | for b := range tcpConn.writeChan {
27 | if b == nil {
28 | break
29 | }
30 |
31 | _, err := conn.Write(b)
32 | if err != nil {
33 | break
34 | }
35 | }
36 |
37 | conn.Close()
38 | tcpConn.Lock()
39 | tcpConn.closeFlag = true
40 | tcpConn.Unlock()
41 | }()
42 |
43 | return tcpConn
44 | }
45 |
46 | func (tcpConn *TCPConn) doDestroy() {
47 | tcpConn.conn.(*net.TCPConn).SetLinger(0)
48 | tcpConn.conn.Close()
49 |
50 | if !tcpConn.closeFlag {
51 | close(tcpConn.writeChan)
52 | tcpConn.closeFlag = true
53 | }
54 | }
55 |
56 | func (tcpConn *TCPConn) Destroy() {
57 | tcpConn.Lock()
58 | defer tcpConn.Unlock()
59 |
60 | tcpConn.doDestroy()
61 | }
62 |
63 | func (tcpConn *TCPConn) Close() {
64 | tcpConn.Lock()
65 | defer tcpConn.Unlock()
66 | if tcpConn.closeFlag {
67 | return
68 | }
69 |
70 | tcpConn.doWrite(nil)
71 | tcpConn.closeFlag = true
72 | }
73 |
74 | func (tcpConn *TCPConn) doWrite(b []byte) {
75 | if len(tcpConn.writeChan) == cap(tcpConn.writeChan) {
76 | log.Debug("close conn: channel full")
77 | tcpConn.doDestroy()
78 | return
79 | }
80 |
81 | tcpConn.writeChan <- b
82 | }
83 |
84 | // b must not be modified by the others goroutines
85 | func (tcpConn *TCPConn) Write(b []byte) {
86 | tcpConn.Lock()
87 | defer tcpConn.Unlock()
88 | if tcpConn.closeFlag || b == nil {
89 | return
90 | }
91 |
92 | tcpConn.doWrite(b)
93 | }
94 |
95 | func (tcpConn *TCPConn) Read(b []byte) (int, error) {
96 | return tcpConn.conn.Read(b)
97 | }
98 |
99 | func (tcpConn *TCPConn) LocalAddr() net.Addr {
100 | return tcpConn.conn.LocalAddr()
101 | }
102 |
103 | func (tcpConn *TCPConn) RemoteAddr() net.Addr {
104 | return tcpConn.conn.RemoteAddr()
105 | }
106 |
107 | func (tcpConn *TCPConn) ReadMsg() ([]byte, error) {
108 | return tcpConn.msgParser.Read(tcpConn)
109 | }
110 |
111 | func (tcpConn *TCPConn) WriteMsg(args ...[]byte) error {
112 | return tcpConn.msgParser.Write(tcpConn, args...)
113 | }
114 |
--------------------------------------------------------------------------------
/leaf/recordfile/example_test.go:
--------------------------------------------------------------------------------
1 | package recordfile_test
2 |
3 | import (
4 | "fmt"
5 | "server/leaf/recordfile"
6 | )
7 |
8 | func Example() {
9 | type Record struct {
10 | // index 0
11 | IndexInt int "index"
12 | // index 1
13 | IndexStr string "index"
14 | _Number int32
15 | Str string
16 | Arr1 [2]int
17 | Arr2 [3][2]int
18 | Arr3 []int
19 | St struct {
20 | Name string "name"
21 | Num int "num"
22 | }
23 | M map[string]int
24 | }
25 |
26 | rf, err := recordfile.New(Record{})
27 | if err != nil {
28 | return
29 | }
30 |
31 | err = rf.Read("test.txt")
32 | if err != nil {
33 | return
34 | }
35 |
36 | for i := 0; i < rf.NumRecord(); i++ {
37 | r := rf.Record(i).(*Record)
38 | fmt.Println(r.IndexInt)
39 | }
40 |
41 | r := rf.Index(2).(*Record)
42 | fmt.Println(r.Str)
43 |
44 | r = rf.Indexes(0)[2].(*Record)
45 | fmt.Println(r.Str)
46 |
47 | r = rf.Indexes(1)["three"].(*Record)
48 | fmt.Println(r.Str)
49 | fmt.Println(r.Arr1[1])
50 | fmt.Println(r.Arr2[2][0])
51 | fmt.Println(r.Arr3[0])
52 | fmt.Println(r.St.Name)
53 | fmt.Println(r.M["key6"])
54 |
55 | // Output:
56 | // 1
57 | // 2
58 | // 3
59 | // cat
60 | // cat
61 | // book
62 | // 6
63 | // 4
64 | // 6
65 | // name5566
66 | // 6
67 | }
68 |
--------------------------------------------------------------------------------
/leaf/recordfile/test.txt:
--------------------------------------------------------------------------------
1 | 数字索引 字符串索引 数字类型 字符串类型 数组类型 嵌套数组 变长数组 结构体类型 map类型
2 | 1 one 0 knife "[1, 2]" "[[0,1], [1,2], [2,3]]" "[1, 2, 3]" "{""name"": ""name5566"", ""num"": 1}" "{""key1"": 1, ""key2"": 2}"
3 | 2 two 0 cat "[3, 4]" "[[1,2], [2,3], [3,4]]" "[4, 5]" "{""name"": ""name5566"", ""num"": 2}" "{""key3"": 3, ""key4"": 4}"
4 | 3 three 0 book "[5, 6]" "[[2,3], [3,4], [4,5]]" [6] "{""name"": ""name5566"", ""num"": 3}" "{""key5"": 5, ""key6"": 6}"
5 |
--------------------------------------------------------------------------------
/leaf/timer/example_test.go:
--------------------------------------------------------------------------------
1 | package timer_test
2 |
3 | import (
4 | "fmt"
5 | "server/leaf/timer"
6 | "time"
7 | )
8 |
9 | func ExampleTimer() {
10 | d := timer.NewDispatcher(10)
11 |
12 | // timer 1
13 | d.AfterFunc(1, func() {
14 | fmt.Println("My name is Leaf")
15 | })
16 |
17 | // timer 2
18 | t := d.AfterFunc(1, func() {
19 | fmt.Println("will not print")
20 | })
21 | t.Stop()
22 |
23 | // dispatch
24 | (<-d.ChanTimer).Cb()
25 |
26 | // Output:
27 | // My name is Leaf
28 | }
29 |
30 | func ExampleCronExpr() {
31 | cronExpr, err := timer.NewCronExpr("0 * * * *")
32 | if err != nil {
33 | return
34 | }
35 |
36 | fmt.Println(cronExpr.Next(time.Date(
37 | 2000, 1, 1,
38 | 20, 10, 5,
39 | 0, time.UTC,
40 | )))
41 |
42 | // Output:
43 | // 2000-01-01 21:00:00 +0000 UTC
44 | }
45 |
46 | func ExampleCron() {
47 | d := timer.NewDispatcher(10)
48 |
49 | // cron expr
50 | cronExpr, err := timer.NewCronExpr("* * * * * *")
51 | if err != nil {
52 | return
53 | }
54 |
55 | // cron
56 | var c *timer.Cron
57 | c = d.CronFunc(cronExpr, func() {
58 | fmt.Println("My name is Leaf")
59 | c.Stop()
60 | })
61 |
62 | // dispatch
63 | (<-d.ChanTimer).Cb()
64 |
65 | // Output:
66 | // My name is Leaf
67 | }
68 |
--------------------------------------------------------------------------------
/leaf/timer/timer.go:
--------------------------------------------------------------------------------
1 | package timer
2 |
3 | import (
4 | "runtime"
5 | "server/leaf/conf"
6 | "server/leaf/log"
7 | "time"
8 | )
9 |
10 | // one dispatcher per goroutine (goroutine not safe)
11 | type Dispatcher struct {
12 | ChanTimer chan *Timer
13 | }
14 |
15 | func NewDispatcher(l int) *Dispatcher {
16 | disp := new(Dispatcher)
17 | disp.ChanTimer = make(chan *Timer, l)
18 | return disp
19 | }
20 |
21 | // Timer
22 | type Timer struct {
23 | t *time.Timer
24 | cb func()
25 | }
26 |
27 | func (t *Timer) Stop() {
28 | t.t.Stop()
29 | t.cb = nil
30 | }
31 |
32 | func (t *Timer) Cb() {
33 | defer func() {
34 | t.cb = nil
35 | if r := recover(); r != nil {
36 | if conf.LenStackBuf > 0 {
37 | buf := make([]byte, conf.LenStackBuf)
38 | l := runtime.Stack(buf, false)
39 | log.Error("%v: %s", r, buf[:l])
40 | } else {
41 | log.Error("%v", r)
42 | }
43 | }
44 | }()
45 |
46 | if t.cb != nil {
47 | t.cb()
48 | }
49 | }
50 |
51 | func (disp *Dispatcher) AfterFunc(d time.Duration, cb func()) *Timer {
52 | t := new(Timer)
53 | t.cb = cb
54 | t.t = time.AfterFunc(d, func() {
55 | disp.ChanTimer <- t
56 | })
57 | return t
58 | }
59 |
60 | // Cron
61 | type Cron struct {
62 | t *Timer
63 | }
64 |
65 | func (c *Cron) Stop() {
66 | if c.t != nil {
67 | c.t.Stop()
68 | }
69 | }
70 |
71 | func (disp *Dispatcher) CronFunc(cronExpr *CronExpr, _cb func()) *Cron {
72 | c := new(Cron)
73 |
74 | now := time.Now()
75 | nextTime := cronExpr.Next(now)
76 | if nextTime.IsZero() {
77 | return c
78 | }
79 |
80 | // callback
81 | var cb func()
82 | cb = func() {
83 | defer _cb()
84 |
85 | now := time.Now()
86 | nextTime := cronExpr.Next(now)
87 | if nextTime.IsZero() {
88 | return
89 | }
90 | c.t = disp.AfterFunc(nextTime.Sub(now), cb)
91 | }
92 |
93 | c.t = disp.AfterFunc(nextTime.Sub(now), cb)
94 | return c
95 | }
96 |
--------------------------------------------------------------------------------
/leaf/util/deepcopy.go:
--------------------------------------------------------------------------------
1 | package util
2 |
3 | // reference: https://github.com/mohae/deepcopy
4 | import (
5 | "reflect"
6 | )
7 |
8 | func deepCopy(dst, src reflect.Value) {
9 | switch src.Kind() {
10 | case reflect.Interface:
11 | value := src.Elem()
12 | if !value.IsValid() {
13 | return
14 | }
15 | newValue := reflect.New(value.Type()).Elem()
16 | deepCopy(newValue, value)
17 | dst.Set(newValue)
18 | case reflect.Ptr:
19 | value := src.Elem()
20 | if !value.IsValid() {
21 | return
22 | }
23 | dst.Set(reflect.New(value.Type()))
24 | deepCopy(dst.Elem(), value)
25 | case reflect.Map:
26 | dst.Set(reflect.MakeMap(src.Type()))
27 | keys := src.MapKeys()
28 | for _, key := range keys {
29 | value := src.MapIndex(key)
30 | newValue := reflect.New(value.Type()).Elem()
31 | deepCopy(newValue, value)
32 | dst.SetMapIndex(key, newValue)
33 | }
34 | case reflect.Slice:
35 | dst.Set(reflect.MakeSlice(src.Type(), src.Len(), src.Cap()))
36 | for i := 0; i < src.Len(); i++ {
37 | deepCopy(dst.Index(i), src.Index(i))
38 | }
39 | case reflect.Struct:
40 | typeSrc := src.Type()
41 | for i := 0; i < src.NumField(); i++ {
42 | value := src.Field(i)
43 | tag := typeSrc.Field(i).Tag
44 | if value.CanSet() && tag.Get("deepcopy") != "-" {
45 | deepCopy(dst.Field(i), value)
46 | }
47 | }
48 | default:
49 | dst.Set(src)
50 | }
51 | }
52 |
53 | func DeepCopy(dst, src interface{}) {
54 | typeDst := reflect.TypeOf(dst)
55 | typeSrc := reflect.TypeOf(src)
56 | if typeDst != typeSrc {
57 | panic("DeepCopy: " + typeDst.String() + " != " + typeSrc.String())
58 | }
59 | if typeSrc.Kind() != reflect.Ptr {
60 | panic("DeepCopy: pass arguments by address")
61 | }
62 |
63 | valueDst := reflect.ValueOf(dst).Elem()
64 | valueSrc := reflect.ValueOf(src).Elem()
65 | if !valueDst.IsValid() || !valueSrc.IsValid() {
66 | panic("DeepCopy: invalid arguments")
67 | }
68 |
69 | deepCopy(valueDst, valueSrc)
70 | }
71 |
72 | func DeepClone(v interface{}) interface{} {
73 | dst := reflect.New(reflect.TypeOf(v)).Elem()
74 | deepCopy(dst, reflect.ValueOf(v))
75 | return dst.Interface()
76 | }
77 |
--------------------------------------------------------------------------------
/leaf/util/example_test.go:
--------------------------------------------------------------------------------
1 | package util_test
2 |
3 | import (
4 | "fmt"
5 | "server/leaf/util"
6 | )
7 |
8 | func ExampleMap() {
9 | m := new(util.Map)
10 |
11 | fmt.Println(m.Get("key"))
12 | m.Set("key", "value")
13 | fmt.Println(m.Get("key"))
14 | m.Del("key")
15 | fmt.Println(m.Get("key"))
16 |
17 | m.Set(1, "1")
18 | m.Set(2, 2)
19 | m.Set("3", 3)
20 |
21 | fmt.Println(m.Len())
22 |
23 | // Output:
24 | //
25 | // value
26 | //
27 | // 3
28 | }
29 |
30 | func ExampleRandGroup() {
31 | i := util.RandGroup(0, 0, 50, 50)
32 | switch i {
33 | case 2, 3:
34 | fmt.Println("ok")
35 | }
36 |
37 | // Output:
38 | // ok
39 | }
40 |
41 | func ExampleRandInterval() {
42 | v := util.RandInterval(-1, 1)
43 | switch v {
44 | case -1, 0, 1:
45 | fmt.Println("ok")
46 | }
47 |
48 | // Output:
49 | // ok
50 | }
51 |
52 | func ExampleRandIntervalN() {
53 | r := util.RandIntervalN(-1, 0, 2)
54 | if r[0] == -1 && r[1] == 0 ||
55 | r[0] == 0 && r[1] == -1 {
56 | fmt.Println("ok")
57 | }
58 |
59 | // Output:
60 | // ok
61 | }
62 |
63 | func ExampleDeepCopy() {
64 | src := []int{1, 2, 3}
65 |
66 | var dst []int
67 | util.DeepCopy(&dst, &src)
68 |
69 | for _, v := range dst {
70 | fmt.Println(v)
71 | }
72 |
73 | // Output:
74 | // 1
75 | // 2
76 | // 3
77 | }
78 |
79 | func ExampleDeepClone() {
80 | src := []int{1, 2, 3}
81 |
82 | dst := util.DeepClone(src).([]int)
83 |
84 | for _, v := range dst {
85 | fmt.Println(v)
86 | }
87 |
88 | // Output:
89 | // 1
90 | // 2
91 | // 3
92 | }
93 |
--------------------------------------------------------------------------------
/leaf/util/map.go:
--------------------------------------------------------------------------------
1 | package util
2 |
3 | import (
4 | "sync"
5 | )
6 |
7 | type Map struct {
8 | sync.RWMutex
9 | m map[interface{}]interface{}
10 | }
11 |
12 | func (m *Map) init() {
13 | if m.m == nil {
14 | m.m = make(map[interface{}]interface{})
15 | }
16 | }
17 |
18 | func (m *Map) UnsafeGet(key interface{}) interface{} {
19 | if m.m == nil {
20 | return nil
21 | } else {
22 | return m.m[key]
23 | }
24 | }
25 |
26 | func (m *Map) Get(key interface{}) interface{} {
27 | m.RLock()
28 | defer m.RUnlock()
29 | return m.UnsafeGet(key)
30 | }
31 |
32 | func (m *Map) UnsafeSet(key interface{}, value interface{}) {
33 | m.init()
34 | m.m[key] = value
35 | }
36 |
37 | func (m *Map) Set(key interface{}, value interface{}) {
38 | m.Lock()
39 | defer m.Unlock()
40 | m.UnsafeSet(key, value)
41 | }
42 |
43 | func (m *Map) TestAndSet(key interface{}, value interface{}) interface{} {
44 | m.Lock()
45 | defer m.Unlock()
46 |
47 | m.init()
48 |
49 | if v, ok := m.m[key]; ok {
50 | return v
51 | } else {
52 | m.m[key] = value
53 | return nil
54 | }
55 | }
56 |
57 | func (m *Map) UnsafeDel(key interface{}) {
58 | m.init()
59 | delete(m.m, key)
60 | }
61 |
62 | func (m *Map) Del(key interface{}) {
63 | m.Lock()
64 | defer m.Unlock()
65 | m.UnsafeDel(key)
66 | }
67 |
68 | func (m *Map) UnsafeLen() int {
69 | if m.m == nil {
70 | return 0
71 | } else {
72 | return len(m.m)
73 | }
74 | }
75 |
76 | func (m *Map) Len() int {
77 | m.RLock()
78 | defer m.RUnlock()
79 | return m.UnsafeLen()
80 | }
81 |
82 | func (m *Map) UnsafeRange(f func(interface{}, interface{})) {
83 | if m.m == nil {
84 | return
85 | }
86 | for k, v := range m.m {
87 | f(k, v)
88 | }
89 | }
90 |
91 | func (m *Map) RLockRange(f func(interface{}, interface{})) {
92 | m.RLock()
93 | defer m.RUnlock()
94 | m.UnsafeRange(f)
95 | }
96 |
97 | func (m *Map) LockRange(f func(interface{}, interface{})) {
98 | m.Lock()
99 | defer m.Unlock()
100 | m.UnsafeRange(f)
101 | }
102 |
--------------------------------------------------------------------------------
/leaf/util/rand.go:
--------------------------------------------------------------------------------
1 | package util
2 |
3 | import (
4 | "math/rand"
5 | "time"
6 | )
7 |
8 | func init() {
9 | rand.Seed(time.Now().UnixNano())
10 | }
11 |
12 | func RandGroup(p ...uint32) int {
13 | if p == nil {
14 | panic("args not found")
15 | }
16 |
17 | r := make([]uint32, len(p))
18 | for i := 0; i < len(p); i++ {
19 | if i == 0 {
20 | r[0] = p[0]
21 | } else {
22 | r[i] = r[i-1] + p[i]
23 | }
24 | }
25 |
26 | rl := r[len(r)-1]
27 | if rl == 0 {
28 | return 0
29 | }
30 |
31 | rn := uint32(rand.Int63n(int64(rl)))
32 | for i := 0; i < len(r); i++ {
33 | if rn < r[i] {
34 | return i
35 | }
36 | }
37 |
38 | panic("bug")
39 | }
40 |
41 | func RandInterval(b1, b2 int32) int32 {
42 | if b1 == b2 {
43 | return b1
44 | }
45 |
46 | min, max := int64(b1), int64(b2)
47 | if min > max {
48 | min, max = max, min
49 | }
50 | return int32(rand.Int63n(max-min+1) + min)
51 | }
52 |
53 | func RandIntervalN(b1, b2 int32, n uint32) []int32 {
54 | if b1 == b2 {
55 | return []int32{b1}
56 | }
57 |
58 | min, max := int64(b1), int64(b2)
59 | if min > max {
60 | min, max = max, min
61 | }
62 | l := max - min + 1
63 | if int64(n) > l {
64 | n = uint32(l)
65 | }
66 |
67 | r := make([]int32, n)
68 | m := make(map[int32]int32)
69 | for i := uint32(0); i < n; i++ {
70 | v := int32(rand.Int63n(l) + min)
71 |
72 | if mv, ok := m[v]; ok {
73 | r[i] = mv
74 | } else {
75 | r[i] = v
76 | }
77 |
78 | lv := int32(l - 1 + min)
79 | if v != lv {
80 | if mv, ok := m[lv]; ok {
81 | m[v] = mv
82 | } else {
83 | m[v] = lv
84 | }
85 | }
86 |
87 | l--
88 | }
89 |
90 | return r
91 | }
92 |
--------------------------------------------------------------------------------
/leaf/util/semaphore.go:
--------------------------------------------------------------------------------
1 | package util
2 |
3 | type Semaphore chan struct{}
4 |
5 | func MakeSemaphore(n int) Semaphore {
6 | return make(Semaphore, n)
7 | }
8 |
9 | func (s Semaphore) Acquire() {
10 | s <- struct{}{}
11 | }
12 |
13 | func (s Semaphore) Release() {
14 | <-s
15 | }
16 |
--------------------------------------------------------------------------------
/leaf/version.go:
--------------------------------------------------------------------------------
1 | package leaf
2 |
3 | const version = "1.1.3"
4 |
--------------------------------------------------------------------------------
/lua/game/classic_ddz/place.lua:
--------------------------------------------------------------------------------
1 | module('place', package.seeall)
2 |
3 | place_config = {
4 | ['jdddz_custom'] = {
5 | id = 'jdddz_custom',
6 | idtype = 'custom',
7 | name = '自定义',
8 | base_zhu = 1,
9 | req_player_gold = 0,
10 | fuck_gold = 0,
11 | chu_tile_time = 15, --无限制
12 | service_gold = 0,
13 | },
14 | ['jdddz_gold_random1'] = {
15 | id = 'jdddz_gold_random1',
16 | idtype='random',
17 | name = '随机匹配',
18 | base_zhu = 1,
19 | req_player_gold = 0,
20 | chu_tile_time = 15,
21 | },
22 | ['jdddz_gold_random2'] = {
23 | id = 'jdddz_gold_random2',
24 | idtype='random',
25 | name = '随机匹配',
26 | base_zhu = 1,
27 | req_player_gold = 0,
28 | chu_tile_time = 15,
29 |
30 | },
31 | ['jdddz_gold_random3'] = {
32 | id = 'jdddz_gold_random3',
33 | idtype='random',
34 | name = '随机匹配',
35 | base_zhu = 1,
36 | req_player_gold = 0,
37 | chu_tile_time = 15,
38 | }
39 | }
40 |
41 | game_config = {
42 | ['jdddz_gold_random1'] = {
43 | gametype = 'jdddz_gold',
44 |
45 | player_count = 3,
46 | ju_count = 1,
47 | consume_card = 3,
48 | who_pay = 0,
49 | max_fan = 4,
50 | --men_qing_zhong_zhang = true,
51 | --yao_jiu_jiang_dui = true,
52 | --dian_gang_zi_mo = true,
53 | --dian_gang_dian_pao = false,
54 |
55 | allow_stranger = true,
56 | base_gold = 50,
57 | leave_gold = 1000,
58 | join_gold = 2000,
59 |
60 | gps = true,
61 | },
62 | ['jdddz_gold_random2'] = {
63 | gametype = 'jdddz_gold',
64 |
65 | player_count = 3,
66 | ju_count = 1,
67 | consume_card = 3,
68 | who_pay = 0,
69 | max_fan = 4,
70 |
71 | allow_stranger = true,
72 | base_gold = 200,
73 | leave_gold = 4000,
74 | join_gold = 8000,
75 |
76 | gps = true,
77 | },
78 | ['jdddz_gold_random3'] = {
79 | gametype = 'jdddz_gold',
80 |
81 | player_count = 3,
82 | ju_count = 1,
83 | consume_card = 3,
84 | who_pay = 0,
85 | max_fan = 4,
86 |
87 | allow_stranger = true,
88 | base_gold = 500,
89 | leave_gold = 10000,
90 | join_gold = 20000,
91 |
92 | gps = true,
93 | }
94 | }
95 |
--------------------------------------------------------------------------------
/lua/game/classic_ddz/protocol/gameserver.pb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/helloh2o/room_game_server/aecbb085afbf2e797f46d10f1e52b51ea1f0147d/lua/game/classic_ddz/protocol/gameserver.pb
--------------------------------------------------------------------------------
/lua/game/classic_ddz/protocol/makepb.sh:
--------------------------------------------------------------------------------
1 | protoc -o gameserver.pb gameserver.proto
2 |
--------------------------------------------------------------------------------
/lua/game/classic_ddz/protocol/svn-commit.tmp:
--------------------------------------------------------------------------------
1 |
2 | --This line, and those below, will be ignored--
3 |
4 | M gameserver.pb
5 |
--------------------------------------------------------------------------------
/lua/game/common/17monipdb.dat:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/helloh2o/room_game_server/aecbb085afbf2e797f46d10f1e52b51ea1f0147d/lua/game/common/17monipdb.dat
--------------------------------------------------------------------------------
/lua/game/common/gauth.lua:
--------------------------------------------------------------------------------
1 | local basexx = require 'gauth_basexx'
2 | local sha1 = require 'gauth_sha1'
3 |
4 | local band = bit.band
5 |
6 | local GAuth = {}
7 |
8 | function GAuth.GenCode(skey, value)
9 | skey = basexx.from_base32(skey)
10 | value = string.char(
11 | 0, 0, 0, 0,
12 | band(value, 0xFF000000) / 0x1000000,
13 | band(value, 0xFF0000) / 0x10000,
14 | band(value, 0xFF00) / 0x100,
15 | band(value, 0xFF))
16 | local hash = sha1.hmac_binary(skey, value)
17 | local offset = band(hash:sub(-1):byte(1, 1), 0xF)
18 | local function bytesToInt(a,b,c,d)
19 | return a*0x1000000 + b*0x10000 + c*0x100 + d
20 | end
21 | hash = bytesToInt(hash:byte(offset + 1, offset + 4))
22 | hash = band(hash, 0x7FFFFFFF) % 1000000
23 | return ("%06d"):format(hash)
24 | end
25 |
26 | function GAuth.Check(skey, value)
27 | local base = math.floor(os.time() / 30)
28 | if GAuth.GenCode(skey, base) == value then return true end
29 | if GAuth.GenCode(skey, base - 1) == value then return true end
30 | if GAuth.GenCode(skey, base + 1) == value then return true end
31 | if GAuth.GenCode(skey, base + 2) == value then return true end
32 | if GAuth.GenCode(skey, base - 2) == value then return true end
33 | return false
34 | end
35 |
36 | return GAuth
37 |
38 |
--------------------------------------------------------------------------------
/lua/game/common/ip2.lua:
--------------------------------------------------------------------------------
1 | module("ip2", package.seeall)
2 | local bit32 = require('bit')
3 |
4 | function byteToUint32(a,b,c,d)
5 | local _int = 0
6 | if a then
7 | _int = _int + bit32.lshift(a, 24)
8 | end
9 | _int = _int + bit32.lshift(b, 16)
10 | _int = _int + bit32.lshift(c, 8)
11 | _int = _int + d
12 | if _int >= 0 then
13 | return _int
14 | else
15 | return _int + math.pow(2, 32)
16 | end
17 | end
18 |
19 | local ipBinaryFilePath = "/root/golang/src/server/lua/game/common/17monipdb.dat"
20 |
21 | local indexBuffer = ''
22 | local offset_len = 0
23 | local areaList = {}
24 |
25 | function loadAreaList()
26 | local file = io.open(ipBinaryFilePath)
27 | local str = file:read(4)
28 |
29 | offset_len = byteToUint32(string.byte(str, 1), string.byte(str, 2),string.byte(str, 3),string.byte(str, 4))
30 | indexBuffer = file:read(offset_len - 4)
31 |
32 | file:seek("set", 4)
33 | local indexPrefixBuf = file:read(1024);
34 | local indexBuf = file:read(offset_len - 4 - 1024);
35 | local index_offset = -1;
36 | local index_length = -1;
37 | local index = 1;
38 | while index < string.len(indexBuf) do
39 | index_offset = byteToUint32(0, string.byte(indexBuf, index+6),string.byte(indexBuf, index+5),string.byte(indexBuf, index+4))
40 | index_length = string.byte(indexBuf, index+7)
41 | index = index +8
42 | file:seek("set", offset_len - 1024 + index_offset)
43 | areaList[index_offset] = file:read(index_length)
44 | end
45 | end
46 |
47 | loadAreaList()
48 |
49 | function IpOffset(ipstr)
50 | local ip1,ip2,ip3,ip4 = string.match(ipstr, "(%d+).(%d+).(%d+).(%d+)")
51 | local ip_uint32 = byteToUint32(ip1, ip2, ip3, ip4)
52 |
53 | local tmp_offset = ip1 * 4
54 | local start_len = byteToUint32(string.byte(indexBuffer, tmp_offset + 4), string.byte(indexBuffer, tmp_offset + 3), string.byte(indexBuffer, tmp_offset + 2), string.byte(indexBuffer, tmp_offset + 1))
55 |
56 | local max_comp_len = offset_len - 1028
57 | start = start_len * 8 + 1024 + 1
58 | local find_uint32 = 0
59 | local index_offset = -1
60 | local index_length = -1
61 | while start < max_comp_len do
62 | find_uint32 = byteToUint32(string.byte(indexBuffer, start), string.byte(indexBuffer, start+1),string.byte(indexBuffer, start+2),string.byte(indexBuffer, start+3))
63 | if ip_uint32 <= find_uint32 then
64 | index_offset = byteToUint32(0, string.byte(indexBuffer, start+6),string.byte(indexBuffer, start+5),string.byte(indexBuffer, start+4))
65 | index_length = string.byte(indexBuffer, start+7)
66 | break
67 | end
68 | start = start + 8
69 | end
70 |
71 | if index_offset == -1 or index_length == -1 then
72 | return nil
73 | end
74 |
75 | return index_offset
76 | end
77 |
78 |
79 | function IpLocation(ipstr)
80 | return areaList[IpOffset(ipstr)]
81 | end
82 |
--------------------------------------------------------------------------------
/lua/game/common/test.lua:
--------------------------------------------------------------------------------
1 |
2 | local uuid = require("uuid4")
3 |
4 | print(uuid.getUUID())
5 | print(uuid.getUUID())
6 |
--------------------------------------------------------------------------------
/lua/game/common/util.lua:
--------------------------------------------------------------------------------
1 | module("util", package.seeall)
2 |
--------------------------------------------------------------------------------
/lua/game/debug/place.lua:
--------------------------------------------------------------------------------
1 | module('place', package.seeall)
2 |
3 | place_config = {
4 | ['jdddz_custom'] = {
5 | id = 'jdddz_custom',
6 | idtype = 'custom',
7 | name = '自定义',
8 | base_zhu = 1,
9 | req_player_gold = 0,
10 | fuck_gold = 0,
11 | chu_tile_time = 15, --无限制
12 | service_gold = 0,
13 | },
14 | ['jdddz_gold_random1'] = {
15 | id = 'jdddz_gold_random1',
16 | idtype='random',
17 | name = '随机匹配',
18 | base_zhu = 1,
19 | req_player_gold = 0,
20 | chu_tile_time = 15,
21 | },
22 | ['jdddz_gold_random2'] = {
23 | id = 'jdddz_gold_random2',
24 | idtype='random',
25 | name = '随机匹配',
26 | base_zhu = 1,
27 | req_player_gold = 0,
28 | chu_tile_time = 15,
29 |
30 | },
31 | ['jdddz_gold_random3'] = {
32 | id = 'jdddz_gold_random3',
33 | idtype='random',
34 | name = '随机匹配',
35 | base_zhu = 1,
36 | req_player_gold = 0,
37 | chu_tile_time = 15,
38 | }
39 | }
40 |
41 | game_config = {
42 | ['jdddz_gold_random1'] = {
43 | gametype = 'jdddz_gold',
44 |
45 | player_count = 3,
46 | ju_count = 1,
47 | consume_card = 3,
48 | who_pay = 0,
49 | max_fan = 4,
50 | --men_qing_zhong_zhang = true,
51 | --yao_jiu_jiang_dui = true,
52 | --dian_gang_zi_mo = true,
53 | --dian_gang_dian_pao = false,
54 |
55 | allow_stranger = true,
56 | base_gold = 50,
57 | leave_gold = 1000,
58 | join_gold = 2000,
59 |
60 | gps = true,
61 | },
62 | ['jdddz_gold_random2'] = {
63 | gametype = 'jdddz_gold',
64 |
65 | player_count = 3,
66 | ju_count = 1,
67 | consume_card = 3,
68 | who_pay = 0,
69 | max_fan = 4,
70 |
71 | allow_stranger = true,
72 | base_gold = 200,
73 | leave_gold = 4000,
74 | join_gold = 8000,
75 |
76 | gps = true,
77 | },
78 | ['jdddz_gold_random3'] = {
79 | gametype = 'jdddz_gold',
80 |
81 | player_count = 3,
82 | ju_count = 1,
83 | consume_card = 3,
84 | who_pay = 0,
85 | max_fan = 4,
86 |
87 | allow_stranger = true,
88 | base_gold = 500,
89 | leave_gold = 10000,
90 | join_gold = 20000,
91 |
92 | gps = true,
93 | }
94 | }
95 |
--------------------------------------------------------------------------------
/lua/game/debug/protocol/gameserver.pb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/helloh2o/room_game_server/aecbb085afbf2e797f46d10f1e52b51ea1f0147d/lua/game/debug/protocol/gameserver.pb
--------------------------------------------------------------------------------
/lua/game/debug/protocol/makepb.sh:
--------------------------------------------------------------------------------
1 | protoc -o gameserver.pb gameserver.proto
2 |
--------------------------------------------------------------------------------
/lua/game/test_game/game.lua:
--------------------------------------------------------------------------------
1 | ---
2 | --- Generated by EmmyLua(https://github.com/EmmyLua)
3 | --- Created by Administrator.
4 | --- DateTime: 2020/4/22 18:17
5 | ---
6 |
7 | function room_init(pid,rid)
8 | rooms[pid] = rid
9 | for key, value in pairs(rooms) do
10 | print(key,value)
11 | end
12 | print("init room ", pid)
13 | end
14 |
15 | function player_init(pid,playerdata)
16 | print("init player ", pid)
17 | print(playerdata)
18 | return true
19 | end
20 |
21 | function enter_room(pid)
22 | print("player ", pid," enter room")
23 | -- A register room id
24 | <<<<<<< .mine
25 | return "1514ba25-e773-44ec-b916-c4ea4b0ebf9e"
26 | ||||||| .r125
27 | return "4ddb5ffd-0bd4-4ad7-b860-a53d3b321747"
28 | =======
29 | return "0cc94e5f-4bac-459f-8150-5aea66dfe334"
30 | >>>>>>> .r128
31 | end
32 |
33 | function onmessage(m,x)
34 | hotupdate()
35 | print("on::",m,x)
36 | msgs = msgs + 1
37 | for key, value in pairs(rooms) do
38 | print(key,value)
39 | end
40 | return msgs
41 | end
42 |
43 | function hotupdate()
44 | --print(hello)
45 | print("ok hot 888 ...")
46 | end
47 |
--------------------------------------------------------------------------------
/lua/game/test_game/game.lua.mine:
--------------------------------------------------------------------------------
1 | ---
2 | --- Generated by EmmyLua(https://github.com/EmmyLua)
3 | --- Created by Administrator.
4 | --- DateTime: 2020/4/22 18:17
5 | ---
6 |
7 | function room_init(pid,rid)
8 | print("init room ", pid)
9 | end
10 |
11 | function player_init(pid,playerdata)
12 | print("init player ", pid)
13 | print(playerdata)
14 | return true
15 | end
16 |
17 | function enter_room(pid)
18 | print("player ", pid," enter room")
19 | -- A register room id
20 | return "1514ba25-e773-44ec-b916-c4ea4b0ebf9e"
21 | end
22 |
23 | function onmessage(m,x)
24 | hotupdate()
25 | print("on::",m,x)
26 | return m
27 | end
28 |
29 | function hotupdate()
30 | --print(hello)
31 | print("ok hot 888 ...")
32 | end
33 |
--------------------------------------------------------------------------------
/lua/game/test_game/game.lua.r125:
--------------------------------------------------------------------------------
1 | ---
2 | --- Generated by EmmyLua(https://github.com/EmmyLua)
3 | --- Created by Administrator.
4 | --- DateTime: 2020/4/22 18:17
5 | ---
6 |
7 | function room_init(pid,rid)
8 | print("init room ", pid)
9 | end
10 |
11 | function player_init(pid,playerdata)
12 | print("init player ", pid)
13 | print(playerdata)
14 | return true
15 | end
16 |
17 | function enter_room(pid)
18 | print("player ", pid," enter room")
19 | -- A register room id
20 | return "4ddb5ffd-0bd4-4ad7-b860-a53d3b321747"
21 | end
22 |
23 | function onmessage(m,x)
24 | hotupdate()
25 | print("on::",m,x)
26 | return m
27 | end
28 |
29 | function hotupdate()
30 | --print(hello)
31 | print("ok hot 888 ...")
32 | end
--------------------------------------------------------------------------------
/lua/game/test_game/game.lua.r128:
--------------------------------------------------------------------------------
1 | ---
2 | --- Generated by EmmyLua(https://github.com/EmmyLua)
3 | --- Created by Administrator.
4 | --- DateTime: 2020/4/22 18:17
5 | ---
6 |
7 | function room_init(pid,rid)
8 | rooms[pid] = rid
9 | for key, value in pairs(rooms) do
10 | print(key,value)
11 | end
12 | print("init room ", pid)
13 | end
14 |
15 | function player_init(pid,playerdata)
16 | print("init player ", pid)
17 | print(playerdata)
18 | return true
19 | end
20 |
21 | function enter_room(pid)
22 | print("player ", pid," enter room")
23 | -- A register room id
24 | return "0cc94e5f-4bac-459f-8150-5aea66dfe334"
25 | end
26 |
27 | function onmessage(m,x)
28 | hotupdate()
29 | print("on::",m,x)
30 | msgs = msgs + 1
31 | for key, value in pairs(rooms) do
32 | print(key,value)
33 | end
34 | return msgs
35 | end
36 |
37 | function hotupdate()
38 | --print(hello)
39 | print("ok hot 888 ...")
40 | end
--------------------------------------------------------------------------------
/lua/game/test_game/var.lua:
--------------------------------------------------------------------------------
1 | ---
2 | --- Generated by EmmyLua(https://github.com/EmmyLua)
3 | --- Created by Administrator.
4 | --- DateTime: 2020/4/23 17:38
5 | ---
6 |
7 | msgs = 0
8 | rooms = {}
--------------------------------------------------------------------------------
/lua/lib/gauth.lua:
--------------------------------------------------------------------------------
1 | local basexx = require './lua/lib/gauth_basexx'
2 | local sha1 = require './lua/lib/gauth_sha1'
3 |
4 | local band = bit.band
5 |
6 | local GAuth = {}
7 |
8 | function GAuth.GenCode(skey, value)
9 | skey = basexx.from_base32(skey)
10 | value = string.char(
11 | 0, 0, 0, 0,
12 | band(value, 0xFF000000) / 0x1000000,
13 | band(value, 0xFF0000) / 0x10000,
14 | band(value, 0xFF00) / 0x100,
15 | band(value, 0xFF))
16 | local hash = sha1.hmac_binary(skey, value)
17 | local offset = band(hash:sub(-1):byte(1, 1), 0xF)
18 | local function bytesToInt(a,b,c,d)
19 | return a*0x1000000 + b*0x10000 + c*0x100 + d
20 | end
21 | hash = bytesToInt(hash:byte(offset + 1, offset + 4))
22 | hash = band(hash, 0x7FFFFFFF) % 1000000
23 | return ("%06d"):format(hash)
24 | end
25 |
26 | function GAuth.Check(skey, value)
27 | local base = math.floor(os.time() / 30)
28 | if GAuth.GenCode(skey, base) == value then return true end
29 | if GAuth.GenCode(skey, base - 1) == value then return true end
30 | if GAuth.GenCode(skey, base + 1) == value then return true end
31 | if GAuth.GenCode(skey, base + 2) == value then return true end
32 | if GAuth.GenCode(skey, base - 2) == value then return true end
33 | return false
34 | end
35 |
36 | return GAuth
37 |
38 |
--------------------------------------------------------------------------------
/lua/loader_test.go:
--------------------------------------------------------------------------------
1 | package loader
2 |
3 | /*
4 | import (
5 | "fmt"
6 | lua "github.com/yuin/gopher-lua"
7 | "log"
8 | "strconv"
9 | "sync"
10 | "testing"
11 | "time"
12 | )
13 |
14 | func TestLuaBucket_ReLoad(t *testing.T) {
15 | Bucket.SetDir("D:/Dev/go/src/server/lua/game")
16 | Bucket.Load()
17 | go Bucket.Watch()
18 | var wg sync.WaitGroup
19 | wg.Add(100)
20 | for i := 0; i < 100; i++ {
21 | time.Sleep(time.Second)
22 | ch := make(chan lua.LValue)
23 | quit := make(chan lua.LValue)
24 | out := make(chan lua.LValue)
25 | // run lua
26 | go func(ch, quit chan lua.LValue) {
27 | L := lua.NewState()
28 | defer L.Close()
29 | scripts := Bucket.scripts
30 | L.SetGlobal("ch", lua.LChannel(ch))
31 | L.SetGlobal("quit", lua.LChannel(quit))
32 | L.SetGlobal("out", lua.LChannel(out))
33 | for _, luafile := range scripts {
34 | if err := L.DoString(luafile); err != nil {
35 | log.Printf("ERROR:: %s\n", err)
36 | }
37 | //fmt.Printf("Script:: \n%s\n", luafile)
38 | }
39 | }(ch, quit)
40 | // like room
41 | go func(ch, quit, out chan lua.LValue, id int) {
42 | done := make(chan struct{})
43 | go func() {
44 | for {
45 | select {
46 | case data := <-out:
47 | fmt.Println("收到消息")
48 | luastring, ok := data.(lua.LString)
49 | if ok {
50 | fmt.Printf("out message -> %s \n", string(luastring))
51 | }
52 | case <-done:
53 | fmt.Println("done")
54 | return
55 | }
56 | }
57 | }()
58 | for i := 1; i < 10; i++ {
59 | //time.Sleep(time.Second)
60 | ch <- lua.LString(strconv.Itoa(id))
61 | }
62 | quit <- lua.LTrue
63 | done <- struct{}{}
64 | wg.Done()
65 | }(ch, quit, out, i)
66 | }
67 | wg.Wait()
68 | }
69 | */
70 |
--------------------------------------------------------------------------------
/lua/testing/temp.lua:
--------------------------------------------------------------------------------
1 | ---
2 | --- Generated by EmmyLua(https://github.com/EmmyLua)
3 | --- Created by Administrator.
4 | --- DateTime: 2020/4/3 12:30
5 | ---
6 | -- 存放房间中的状态
7 | players = 1
8 | msg = 3
9 | hello = "hello message"
10 |
--------------------------------------------------------------------------------
/luajit/debug.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include "_cgo_export.h"
3 |
4 | static void
5 | bouncehook(lua_State *s, lua_Debug *ar)
6 | {
7 | hookevent(s, ar);
8 | }
9 |
10 | void
11 | sethook(lua_State *s, int mask, int count)
12 | {
13 | lua_sethook(s, bouncehook, mask, count);
14 | }
15 |
--------------------------------------------------------------------------------
/luajit/jit/host/README:
--------------------------------------------------------------------------------
1 | The files in this directory are only used during the build process of LuaJIT.
2 | For cross-compilation, they must be executed on the host, not on the target.
3 |
4 | These files should NOT be installed!
5 |
--------------------------------------------------------------------------------
/luajit/jit/host/buildvm:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/helloh2o/room_game_server/aecbb085afbf2e797f46d10f1e52b51ea1f0147d/luajit/jit/host/buildvm
--------------------------------------------------------------------------------
/luajit/jit/host/buildvm.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/helloh2o/room_game_server/aecbb085afbf2e797f46d10f1e52b51ea1f0147d/luajit/jit/host/buildvm.exe
--------------------------------------------------------------------------------
/luajit/jit/host/buildvm.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/helloh2o/room_game_server/aecbb085afbf2e797f46d10f1e52b51ea1f0147d/luajit/jit/host/buildvm.o
--------------------------------------------------------------------------------
/luajit/jit/host/buildvm_asm.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/helloh2o/room_game_server/aecbb085afbf2e797f46d10f1e52b51ea1f0147d/luajit/jit/host/buildvm_asm.o
--------------------------------------------------------------------------------
/luajit/jit/host/buildvm_fold.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/helloh2o/room_game_server/aecbb085afbf2e797f46d10f1e52b51ea1f0147d/luajit/jit/host/buildvm_fold.o
--------------------------------------------------------------------------------
/luajit/jit/host/buildvm_lib.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/helloh2o/room_game_server/aecbb085afbf2e797f46d10f1e52b51ea1f0147d/luajit/jit/host/buildvm_lib.o
--------------------------------------------------------------------------------
/luajit/jit/host/buildvm_peobj.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/helloh2o/room_game_server/aecbb085afbf2e797f46d10f1e52b51ea1f0147d/luajit/jit/host/buildvm_peobj.o
--------------------------------------------------------------------------------
/luajit/jit/host/minilua:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/helloh2o/room_game_server/aecbb085afbf2e797f46d10f1e52b51ea1f0147d/luajit/jit/host/minilua
--------------------------------------------------------------------------------
/luajit/jit/host/minilua.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/helloh2o/room_game_server/aecbb085afbf2e797f46d10f1e52b51ea1f0147d/luajit/jit/host/minilua.exe
--------------------------------------------------------------------------------
/luajit/jit/host/minilua.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/helloh2o/room_game_server/aecbb085afbf2e797f46d10f1e52b51ea1f0147d/luajit/jit/host/minilua.o
--------------------------------------------------------------------------------
/luajit/jit/jit/dis_mipsel.lua:
--------------------------------------------------------------------------------
1 | ----------------------------------------------------------------------------
2 | -- LuaJIT MIPSEL disassembler wrapper module.
3 | --
4 | -- Copyright (C) 2005-2015 Mike Pall. All rights reserved.
5 | -- Released under the MIT license. See Copyright Notice in luajit.h
6 | ----------------------------------------------------------------------------
7 | -- This module just exports the little-endian functions from the
8 | -- MIPS disassembler module. All the interesting stuff is there.
9 | ------------------------------------------------------------------------------
10 |
11 | local require = require
12 |
13 | module(...)
14 |
15 | local dis_mips = require(_PACKAGE.."dis_mips")
16 |
17 | create = dis_mips.create_el
18 | disass = dis_mips.disass_el
19 | regname = dis_mips.regname
20 |
21 |
--------------------------------------------------------------------------------
/luajit/jit/jit/dis_x64.lua:
--------------------------------------------------------------------------------
1 | ----------------------------------------------------------------------------
2 | -- LuaJIT x64 disassembler wrapper module.
3 | --
4 | -- Copyright (C) 2005-2015 Mike Pall. All rights reserved.
5 | -- Released under the MIT license. See Copyright Notice in luajit.h
6 | ----------------------------------------------------------------------------
7 | -- This module just exports the 64 bit functions from the combined
8 | -- x86/x64 disassembler module. All the interesting stuff is there.
9 | ------------------------------------------------------------------------------
10 |
11 | local require = require
12 |
13 | module(...)
14 |
15 | local dis_x86 = require(_PACKAGE.."dis_x86")
16 |
17 | create = dis_x86.create64
18 | disass = dis_x86.disass64
19 | regname = dis_x86.regname64
20 |
21 |
--------------------------------------------------------------------------------
/luajit/jit/lib_aux.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/helloh2o/room_game_server/aecbb085afbf2e797f46d10f1e52b51ea1f0147d/luajit/jit/lib_aux.o
--------------------------------------------------------------------------------
/luajit/jit/lib_base.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/helloh2o/room_game_server/aecbb085afbf2e797f46d10f1e52b51ea1f0147d/luajit/jit/lib_base.o
--------------------------------------------------------------------------------
/luajit/jit/lib_bit.c:
--------------------------------------------------------------------------------
1 | /*
2 | ** Bit manipulation library.
3 | ** Copyright (C) 2005-2015 Mike Pall. See Copyright Notice in luajit.h
4 | */
5 |
6 | #define lib_bit_c
7 | #define LUA_LIB
8 |
9 | #include "lua.h"
10 | #include "lauxlib.h"
11 | #include "lualib.h"
12 |
13 | #include "lj_obj.h"
14 | #include "lj_err.h"
15 | #include "lj_str.h"
16 | #include "lj_lib.h"
17 |
18 | /* ------------------------------------------------------------------------ */
19 |
20 | #define LJLIB_MODULE_bit
21 |
22 | LJLIB_ASM(bit_tobit) LJLIB_REC(bit_unary IR_TOBIT)
23 | {
24 | lj_lib_checknumber(L, 1);
25 | return FFH_RETRY;
26 | }
27 | LJLIB_ASM_(bit_bnot) LJLIB_REC(bit_unary IR_BNOT)
28 | LJLIB_ASM_(bit_bswap) LJLIB_REC(bit_unary IR_BSWAP)
29 |
30 | LJLIB_ASM(bit_lshift) LJLIB_REC(bit_shift IR_BSHL)
31 | {
32 | lj_lib_checknumber(L, 1);
33 | lj_lib_checkbit(L, 2);
34 | return FFH_RETRY;
35 | }
36 | LJLIB_ASM_(bit_rshift) LJLIB_REC(bit_shift IR_BSHR)
37 | LJLIB_ASM_(bit_arshift) LJLIB_REC(bit_shift IR_BSAR)
38 | LJLIB_ASM_(bit_rol) LJLIB_REC(bit_shift IR_BROL)
39 | LJLIB_ASM_(bit_ror) LJLIB_REC(bit_shift IR_BROR)
40 |
41 | LJLIB_ASM(bit_band) LJLIB_REC(bit_nary IR_BAND)
42 | {
43 | int i = 0;
44 | do { lj_lib_checknumber(L, ++i); } while (L->base+i < L->top);
45 | return FFH_RETRY;
46 | }
47 | LJLIB_ASM_(bit_bor) LJLIB_REC(bit_nary IR_BOR)
48 | LJLIB_ASM_(bit_bxor) LJLIB_REC(bit_nary IR_BXOR)
49 |
50 | /* ------------------------------------------------------------------------ */
51 |
52 | LJLIB_CF(bit_tohex)
53 | {
54 | uint32_t b = (uint32_t)lj_lib_checkbit(L, 1);
55 | int32_t i, n = L->base+1 >= L->top ? 8 : lj_lib_checkbit(L, 2);
56 | const char *hexdigits = "0123456789abcdef";
57 | char buf[8];
58 | if (n < 0) { n = -n; hexdigits = "0123456789ABCDEF"; }
59 | if (n > 8) n = 8;
60 | for (i = n; --i >= 0; ) { buf[i] = hexdigits[b & 15]; b >>= 4; }
61 | lua_pushlstring(L, buf, (size_t)n);
62 | return 1;
63 | }
64 |
65 | /* ------------------------------------------------------------------------ */
66 |
67 | #include "lj_libdef.h"
68 |
69 | LUALIB_API int luaopen_bit(lua_State *L)
70 | {
71 | LJ_LIB_REG(L, LUA_BITLIBNAME, bit);
72 | return 1;
73 | }
74 |
75 |
--------------------------------------------------------------------------------
/luajit/jit/lib_bit.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/helloh2o/room_game_server/aecbb085afbf2e797f46d10f1e52b51ea1f0147d/luajit/jit/lib_bit.o
--------------------------------------------------------------------------------
/luajit/jit/lib_debug.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/helloh2o/room_game_server/aecbb085afbf2e797f46d10f1e52b51ea1f0147d/luajit/jit/lib_debug.o
--------------------------------------------------------------------------------
/luajit/jit/lib_ffi.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/helloh2o/room_game_server/aecbb085afbf2e797f46d10f1e52b51ea1f0147d/luajit/jit/lib_ffi.o
--------------------------------------------------------------------------------
/luajit/jit/lib_init.c:
--------------------------------------------------------------------------------
1 | /*
2 | ** Library initialization.
3 | ** Copyright (C) 2005-2015 Mike Pall. See Copyright Notice in luajit.h
4 | **
5 | ** Major parts taken verbatim from the Lua interpreter.
6 | ** Copyright (C) 1994-2008 Lua.org, PUC-Rio. See Copyright Notice in lua.h
7 | */
8 |
9 | #define lib_init_c
10 | #define LUA_LIB
11 |
12 | #include "lua.h"
13 | #include "lauxlib.h"
14 | #include "lualib.h"
15 |
16 | #include "lj_arch.h"
17 |
18 | static const luaL_Reg lj_lib_load[] = {
19 | { "", luaopen_base },
20 | { LUA_LOADLIBNAME, luaopen_package },
21 | { LUA_TABLIBNAME, luaopen_table },
22 | { LUA_IOLIBNAME, luaopen_io },
23 | { LUA_OSLIBNAME, luaopen_os },
24 | { LUA_STRLIBNAME, luaopen_string },
25 | { LUA_MATHLIBNAME, luaopen_math },
26 | { LUA_DBLIBNAME, luaopen_debug },
27 | { LUA_BITLIBNAME, luaopen_bit },
28 | { LUA_JITLIBNAME, luaopen_jit },
29 | { NULL, NULL }
30 | };
31 |
32 | static const luaL_Reg lj_lib_preload[] = {
33 | #if LJ_HASFFI
34 | { LUA_FFILIBNAME, luaopen_ffi },
35 | #endif
36 | { NULL, NULL }
37 | };
38 |
39 | LUALIB_API void luaL_openlibs(lua_State *L)
40 | {
41 | const luaL_Reg *lib;
42 | for (lib = lj_lib_load; lib->func; lib++) {
43 | lua_pushcfunction(L, lib->func);
44 | lua_pushstring(L, lib->name);
45 | lua_call(L, 1, 0);
46 | }
47 | luaL_findtable(L, LUA_REGISTRYINDEX, "_PRELOAD",
48 | sizeof(lj_lib_preload)/sizeof(lj_lib_preload[0])-1);
49 | for (lib = lj_lib_preload; lib->func; lib++) {
50 | lua_pushcfunction(L, lib->func);
51 | lua_setfield(L, -2, lib->name);
52 | }
53 | lua_pop(L, 1);
54 | }
55 |
56 |
--------------------------------------------------------------------------------
/luajit/jit/lib_init.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/helloh2o/room_game_server/aecbb085afbf2e797f46d10f1e52b51ea1f0147d/luajit/jit/lib_init.o
--------------------------------------------------------------------------------
/luajit/jit/lib_io.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/helloh2o/room_game_server/aecbb085afbf2e797f46d10f1e52b51ea1f0147d/luajit/jit/lib_io.o
--------------------------------------------------------------------------------
/luajit/jit/lib_jit.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/helloh2o/room_game_server/aecbb085afbf2e797f46d10f1e52b51ea1f0147d/luajit/jit/lib_jit.o
--------------------------------------------------------------------------------
/luajit/jit/lib_math.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/helloh2o/room_game_server/aecbb085afbf2e797f46d10f1e52b51ea1f0147d/luajit/jit/lib_math.o
--------------------------------------------------------------------------------
/luajit/jit/lib_os.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/helloh2o/room_game_server/aecbb085afbf2e797f46d10f1e52b51ea1f0147d/luajit/jit/lib_os.o
--------------------------------------------------------------------------------
/luajit/jit/lib_package.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/helloh2o/room_game_server/aecbb085afbf2e797f46d10f1e52b51ea1f0147d/luajit/jit/lib_package.o
--------------------------------------------------------------------------------
/luajit/jit/lib_string.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/helloh2o/room_game_server/aecbb085afbf2e797f46d10f1e52b51ea1f0147d/luajit/jit/lib_string.o
--------------------------------------------------------------------------------
/luajit/jit/lib_table.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/helloh2o/room_game_server/aecbb085afbf2e797f46d10f1e52b51ea1f0147d/luajit/jit/lib_table.o
--------------------------------------------------------------------------------
/luajit/jit/libluajit.a:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/helloh2o/room_game_server/aecbb085afbf2e797f46d10f1e52b51ea1f0147d/luajit/jit/libluajit.a
--------------------------------------------------------------------------------
/luajit/jit/libluajit_darwin.a:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/helloh2o/room_game_server/aecbb085afbf2e797f46d10f1e52b51ea1f0147d/luajit/jit/libluajit_darwin.a
--------------------------------------------------------------------------------
/luajit/jit/lj.supp:
--------------------------------------------------------------------------------
1 | # Valgrind suppression file for LuaJIT 2.0.
2 | {
3 | Optimized string compare
4 | Memcheck:Addr4
5 | fun:lj_str_cmp
6 | }
7 | {
8 | Optimized string compare
9 | Memcheck:Addr1
10 | fun:lj_str_cmp
11 | }
12 | {
13 | Optimized string compare
14 | Memcheck:Addr4
15 | fun:lj_str_new
16 | }
17 | {
18 | Optimized string compare
19 | Memcheck:Addr1
20 | fun:lj_str_new
21 | }
22 | {
23 | Optimized string compare
24 | Memcheck:Cond
25 | fun:lj_str_new
26 | }
27 |
--------------------------------------------------------------------------------
/luajit/jit/lj_alloc.h:
--------------------------------------------------------------------------------
1 | /*
2 | ** Bundled memory allocator.
3 | ** Donated to the public domain.
4 | */
5 |
6 | #ifndef _LJ_ALLOC_H
7 | #define _LJ_ALLOC_H
8 |
9 | #include "lj_def.h"
10 |
11 | #ifndef LUAJIT_USE_SYSMALLOC
12 | LJ_FUNC void *lj_alloc_create(void);
13 | LJ_FUNC void lj_alloc_destroy(void *msp);
14 | LJ_FUNC void *lj_alloc_f(void *msp, void *ptr, size_t osize, size_t nsize);
15 | #endif
16 |
17 | #endif
18 |
--------------------------------------------------------------------------------
/luajit/jit/lj_alloc.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/helloh2o/room_game_server/aecbb085afbf2e797f46d10f1e52b51ea1f0147d/luajit/jit/lj_alloc.o
--------------------------------------------------------------------------------
/luajit/jit/lj_api.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/helloh2o/room_game_server/aecbb085afbf2e797f46d10f1e52b51ea1f0147d/luajit/jit/lj_api.o
--------------------------------------------------------------------------------
/luajit/jit/lj_asm.h:
--------------------------------------------------------------------------------
1 | /*
2 | ** IR assembler (SSA IR -> machine code).
3 | ** Copyright (C) 2005-2015 Mike Pall. See Copyright Notice in luajit.h
4 | */
5 |
6 | #ifndef _LJ_ASM_H
7 | #define _LJ_ASM_H
8 |
9 | #include "lj_jit.h"
10 |
11 | #if LJ_HASJIT
12 | LJ_FUNC void lj_asm_trace(jit_State *J, GCtrace *T);
13 | LJ_FUNC void lj_asm_patchexit(jit_State *J, GCtrace *T, ExitNo exitno,
14 | MCode *target);
15 | #endif
16 |
17 | #endif
18 |
--------------------------------------------------------------------------------
/luajit/jit/lj_asm.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/helloh2o/room_game_server/aecbb085afbf2e797f46d10f1e52b51ea1f0147d/luajit/jit/lj_asm.o
--------------------------------------------------------------------------------
/luajit/jit/lj_bc.c:
--------------------------------------------------------------------------------
1 | /*
2 | ** Bytecode instruction modes.
3 | ** Copyright (C) 2005-2015 Mike Pall. See Copyright Notice in luajit.h
4 | */
5 |
6 | #define lj_bc_c
7 | #define LUA_CORE
8 |
9 | #include "lj_obj.h"
10 | #include "lj_bc.h"
11 |
12 | /* Bytecode offsets and bytecode instruction modes. */
13 | #include "lj_bcdef.h"
14 |
15 |
--------------------------------------------------------------------------------
/luajit/jit/lj_bc.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/helloh2o/room_game_server/aecbb085afbf2e797f46d10f1e52b51ea1f0147d/luajit/jit/lj_bc.o
--------------------------------------------------------------------------------
/luajit/jit/lj_bcdump.h:
--------------------------------------------------------------------------------
1 | /*
2 | ** Bytecode dump definitions.
3 | ** Copyright (C) 2005-2015 Mike Pall. See Copyright Notice in luajit.h
4 | */
5 |
6 | #ifndef _LJ_BCDUMP_H
7 | #define _LJ_BCDUMP_H
8 |
9 | #include "lj_obj.h"
10 | #include "lj_lex.h"
11 |
12 | /* -- Bytecode dump format ------------------------------------------------ */
13 |
14 | /*
15 | ** dump = header proto+ 0U
16 | ** header = ESC 'L' 'J' versionB flagsU [namelenU nameB*]
17 | ** proto = lengthU pdata
18 | ** pdata = phead bcinsW* uvdataH* kgc* knum* [debugB*]
19 | ** phead = flagsB numparamsB framesizeB numuvB numkgcU numknU numbcU
20 | ** [debuglenU [firstlineU numlineU]]
21 | ** kgc = kgctypeU { ktab | (loU hiU) | (rloU rhiU iloU ihiU) | strB* }
22 | ** knum = intU0 | (loU1 hiU)
23 | ** ktab = narrayU nhashU karray* khash*
24 | ** karray = ktabk
25 | ** khash = ktabk ktabk
26 | ** ktabk = ktabtypeU { intU | (loU hiU) | strB* }
27 | **
28 | ** B = 8 bit, H = 16 bit, W = 32 bit, U = ULEB128 of W, U0/U1 = ULEB128 of W+1
29 | */
30 |
31 | /* Bytecode dump header. */
32 | #define BCDUMP_HEAD1 0x1b
33 | #define BCDUMP_HEAD2 0x4c
34 | #define BCDUMP_HEAD3 0x4a
35 |
36 | /* If you perform *any* kind of private modifications to the bytecode itself
37 | ** or to the dump format, you *must* set BCDUMP_VERSION to 0x80 or higher.
38 | */
39 | #define BCDUMP_VERSION 1
40 |
41 | /* Compatibility flags. */
42 | #define BCDUMP_F_BE 0x01
43 | #define BCDUMP_F_STRIP 0x02
44 | #define BCDUMP_F_FFI 0x04
45 |
46 | #define BCDUMP_F_KNOWN (BCDUMP_F_FFI*2-1)
47 |
48 | /* Type codes for the GC constants of a prototype. Plus length for strings. */
49 | enum {
50 | BCDUMP_KGC_CHILD, BCDUMP_KGC_TAB, BCDUMP_KGC_I64, BCDUMP_KGC_U64,
51 | BCDUMP_KGC_COMPLEX, BCDUMP_KGC_STR
52 | };
53 |
54 | /* Type codes for the keys/values of a constant table. */
55 | enum {
56 | BCDUMP_KTAB_NIL, BCDUMP_KTAB_FALSE, BCDUMP_KTAB_TRUE,
57 | BCDUMP_KTAB_INT, BCDUMP_KTAB_NUM, BCDUMP_KTAB_STR
58 | };
59 |
60 | /* -- Bytecode reader/writer ---------------------------------------------- */
61 |
62 | LJ_FUNC int lj_bcwrite(lua_State *L, GCproto *pt, lua_Writer writer,
63 | void *data, int strip);
64 | LJ_FUNC GCproto *lj_bcread(LexState *ls);
65 |
66 | #endif
67 |
--------------------------------------------------------------------------------
/luajit/jit/lj_bcread.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/helloh2o/room_game_server/aecbb085afbf2e797f46d10f1e52b51ea1f0147d/luajit/jit/lj_bcread.o
--------------------------------------------------------------------------------
/luajit/jit/lj_bcwrite.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/helloh2o/room_game_server/aecbb085afbf2e797f46d10f1e52b51ea1f0147d/luajit/jit/lj_bcwrite.o
--------------------------------------------------------------------------------
/luajit/jit/lj_carith.h:
--------------------------------------------------------------------------------
1 | /*
2 | ** C data arithmetic.
3 | ** Copyright (C) 2005-2015 Mike Pall. See Copyright Notice in luajit.h
4 | */
5 |
6 | #ifndef _LJ_CARITH_H
7 | #define _LJ_CARITH_H
8 |
9 | #include "lj_obj.h"
10 |
11 | #if LJ_HASFFI
12 |
13 | LJ_FUNC int lj_carith_op(lua_State *L, MMS mm);
14 |
15 | #if LJ_32 && LJ_HASJIT
16 | LJ_FUNC int64_t lj_carith_mul64(int64_t x, int64_t k);
17 | #endif
18 | LJ_FUNC uint64_t lj_carith_divu64(uint64_t a, uint64_t b);
19 | LJ_FUNC int64_t lj_carith_divi64(int64_t a, int64_t b);
20 | LJ_FUNC uint64_t lj_carith_modu64(uint64_t a, uint64_t b);
21 | LJ_FUNC int64_t lj_carith_modi64(int64_t a, int64_t b);
22 | LJ_FUNC uint64_t lj_carith_powu64(uint64_t x, uint64_t k);
23 | LJ_FUNC int64_t lj_carith_powi64(int64_t x, int64_t k);
24 |
25 | #endif
26 |
27 | #endif
28 |
--------------------------------------------------------------------------------
/luajit/jit/lj_carith.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/helloh2o/room_game_server/aecbb085afbf2e797f46d10f1e52b51ea1f0147d/luajit/jit/lj_carith.o
--------------------------------------------------------------------------------
/luajit/jit/lj_ccall.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/helloh2o/room_game_server/aecbb085afbf2e797f46d10f1e52b51ea1f0147d/luajit/jit/lj_ccall.o
--------------------------------------------------------------------------------
/luajit/jit/lj_ccallback.h:
--------------------------------------------------------------------------------
1 | /*
2 | ** FFI C callback handling.
3 | ** Copyright (C) 2005-2015 Mike Pall. See Copyright Notice in luajit.h
4 | */
5 |
6 | #ifndef _LJ_CCALLBACK_H
7 | #define _LJ_CCALLBACK_H
8 |
9 | #include "lj_obj.h"
10 | #include "lj_ctype.h"
11 |
12 | #if LJ_HASFFI
13 |
14 | /* Really belongs to lj_vm.h. */
15 | LJ_ASMF void lj_vm_ffi_callback(void);
16 |
17 | LJ_FUNC MSize lj_ccallback_ptr2slot(CTState *cts, void *p);
18 | LJ_FUNCA lua_State * LJ_FASTCALL lj_ccallback_enter(CTState *cts, void *cf);
19 | LJ_FUNCA void LJ_FASTCALL lj_ccallback_leave(CTState *cts, TValue *o);
20 | LJ_FUNC void *lj_ccallback_new(CTState *cts, CType *ct, GCfunc *fn);
21 | LJ_FUNC void lj_ccallback_mcode_free(CTState *cts);
22 |
23 | #endif
24 |
25 | #endif
26 |
--------------------------------------------------------------------------------
/luajit/jit/lj_ccallback.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/helloh2o/room_game_server/aecbb085afbf2e797f46d10f1e52b51ea1f0147d/luajit/jit/lj_ccallback.o
--------------------------------------------------------------------------------
/luajit/jit/lj_cconv.h:
--------------------------------------------------------------------------------
1 | /*
2 | ** C type conversions.
3 | ** Copyright (C) 2005-2015 Mike Pall. See Copyright Notice in luajit.h
4 | */
5 |
6 | #ifndef _LJ_CCONV_H
7 | #define _LJ_CCONV_H
8 |
9 | #include "lj_obj.h"
10 | #include "lj_ctype.h"
11 |
12 | #if LJ_HASFFI
13 |
14 | /* Compressed C type index. ORDER CCX. */
15 | enum {
16 | CCX_B, /* Bool. */
17 | CCX_I, /* Integer. */
18 | CCX_F, /* Floating-point number. */
19 | CCX_C, /* Complex. */
20 | CCX_V, /* Vector. */
21 | CCX_P, /* Pointer. */
22 | CCX_A, /* Refarray. */
23 | CCX_S /* Struct/union. */
24 | };
25 |
26 | /* Convert C type info to compressed C type index. ORDER CT. ORDER CCX. */
27 | static LJ_AINLINE uint32_t cconv_idx(CTInfo info)
28 | {
29 | uint32_t idx = ((info >> 26) & 15u); /* Dispatch bits. */
30 | lua_assert(ctype_type(info) <= CT_MAYCONVERT);
31 | #if LJ_64
32 | idx = ((uint32_t)(U64x(f436fff5,fff7f021) >> 4*idx) & 15u);
33 | #else
34 | idx = (((idx < 8 ? 0xfff7f021u : 0xf436fff5) >> 4*(idx & 7u)) & 15u);
35 | #endif
36 | lua_assert(idx < 8);
37 | return idx;
38 | }
39 |
40 | #define cconv_idx2(dinfo, sinfo) \
41 | ((cconv_idx((dinfo)) << 3) + cconv_idx((sinfo)))
42 |
43 | #define CCX(dst, src) ((CCX_##dst << 3) + CCX_##src)
44 |
45 | /* Conversion flags. */
46 | #define CCF_CAST 0x00000001u
47 | #define CCF_FROMTV 0x00000002u
48 | #define CCF_SAME 0x00000004u
49 | #define CCF_IGNQUAL 0x00000008u
50 |
51 | #define CCF_ARG_SHIFT 8
52 | #define CCF_ARG(n) ((n) << CCF_ARG_SHIFT)
53 | #define CCF_GETARG(f) ((f) >> CCF_ARG_SHIFT)
54 |
55 | LJ_FUNC int lj_cconv_compatptr(CTState *cts, CType *d, CType *s, CTInfo flags);
56 | LJ_FUNC void lj_cconv_ct_ct(CTState *cts, CType *d, CType *s,
57 | uint8_t *dp, uint8_t *sp, CTInfo flags);
58 | LJ_FUNC int lj_cconv_tv_ct(CTState *cts, CType *s, CTypeID sid,
59 | TValue *o, uint8_t *sp);
60 | LJ_FUNC int lj_cconv_tv_bf(CTState *cts, CType *s, TValue *o, uint8_t *sp);
61 | LJ_FUNC void lj_cconv_ct_tv(CTState *cts, CType *d,
62 | uint8_t *dp, TValue *o, CTInfo flags);
63 | LJ_FUNC void lj_cconv_bf_tv(CTState *cts, CType *d, uint8_t *dp, TValue *o);
64 | LJ_FUNC int lj_cconv_multi_init(CTState *cts, CType *d, TValue *o);
65 | LJ_FUNC void lj_cconv_ct_init(CTState *cts, CType *d, CTSize sz,
66 | uint8_t *dp, TValue *o, MSize len);
67 |
68 | #endif
69 |
70 | #endif
71 |
--------------------------------------------------------------------------------
/luajit/jit/lj_cconv.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/helloh2o/room_game_server/aecbb085afbf2e797f46d10f1e52b51ea1f0147d/luajit/jit/lj_cconv.o
--------------------------------------------------------------------------------
/luajit/jit/lj_cdata.h:
--------------------------------------------------------------------------------
1 | /*
2 | ** C data management.
3 | ** Copyright (C) 2005-2015 Mike Pall. See Copyright Notice in luajit.h
4 | */
5 |
6 | #ifndef _LJ_CDATA_H
7 | #define _LJ_CDATA_H
8 |
9 | #include "lj_obj.h"
10 | #include "lj_gc.h"
11 | #include "lj_ctype.h"
12 |
13 | #if LJ_HASFFI
14 |
15 | /* Get C data pointer. */
16 | static LJ_AINLINE void *cdata_getptr(void *p, CTSize sz)
17 | {
18 | if (LJ_64 && sz == 4) { /* Support 32 bit pointers on 64 bit targets. */
19 | return ((void *)(uintptr_t)*(uint32_t *)p);
20 | } else {
21 | lua_assert(sz == CTSIZE_PTR);
22 | return *(void **)p;
23 | }
24 | }
25 |
26 | /* Set C data pointer. */
27 | static LJ_AINLINE void cdata_setptr(void *p, CTSize sz, const void *v)
28 | {
29 | if (LJ_64 && sz == 4) { /* Support 32 bit pointers on 64 bit targets. */
30 | *(uint32_t *)p = (uint32_t)(uintptr_t)v;
31 | } else {
32 | lua_assert(sz == CTSIZE_PTR);
33 | *(void **)p = (void *)v;
34 | }
35 | }
36 |
37 | /* Allocate fixed-size C data object. */
38 | static LJ_AINLINE GCcdata *lj_cdata_new(CTState *cts, CTypeID id, CTSize sz)
39 | {
40 | GCcdata *cd;
41 | #ifdef LUA_USE_ASSERT
42 | CType *ct = ctype_raw(cts, id);
43 | lua_assert((ctype_hassize(ct->info) ? ct->size : CTSIZE_PTR) == sz);
44 | #endif
45 | cd = (GCcdata *)lj_mem_newgco(cts->L, sizeof(GCcdata) + sz);
46 | cd->gct = ~LJ_TCDATA;
47 | cd->ctypeid = ctype_check(cts, id);
48 | return cd;
49 | }
50 |
51 | /* Variant which works without a valid CTState. */
52 | static LJ_AINLINE GCcdata *lj_cdata_new_(lua_State *L, CTypeID id, CTSize sz)
53 | {
54 | GCcdata *cd = (GCcdata *)lj_mem_newgco(L, sizeof(GCcdata) + sz);
55 | cd->gct = ~LJ_TCDATA;
56 | cd->ctypeid = id;
57 | return cd;
58 | }
59 |
60 | LJ_FUNC GCcdata *lj_cdata_newref(CTState *cts, const void *pp, CTypeID id);
61 | LJ_FUNC GCcdata *lj_cdata_newv(CTState *cts, CTypeID id, CTSize sz,
62 | CTSize align);
63 |
64 | LJ_FUNC void LJ_FASTCALL lj_cdata_free(global_State *g, GCcdata *cd);
65 | LJ_FUNCA TValue * LJ_FASTCALL lj_cdata_setfin(lua_State *L, GCcdata *cd);
66 |
67 | LJ_FUNC CType *lj_cdata_index(CTState *cts, GCcdata *cd, cTValue *key,
68 | uint8_t **pp, CTInfo *qual);
69 | LJ_FUNC int lj_cdata_get(CTState *cts, CType *s, TValue *o, uint8_t *sp);
70 | LJ_FUNC void lj_cdata_set(CTState *cts, CType *d, uint8_t *dp, TValue *o,
71 | CTInfo qual);
72 |
73 | #endif
74 |
75 | #endif
76 |
--------------------------------------------------------------------------------
/luajit/jit/lj_cdata.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/helloh2o/room_game_server/aecbb085afbf2e797f46d10f1e52b51ea1f0147d/luajit/jit/lj_cdata.o
--------------------------------------------------------------------------------
/luajit/jit/lj_char.c:
--------------------------------------------------------------------------------
1 | /*
2 | ** Character types.
3 | ** Donated to the public domain.
4 | **
5 | ** This is intended to replace the problematic libc single-byte NLS functions.
6 | ** These just don't make sense anymore with UTF-8 locales becoming the norm
7 | ** on POSIX systems. It never worked too well on Windows systems since hardly
8 | ** anyone bothered to call setlocale().
9 | **
10 | ** This table is hardcoded for ASCII. Identifiers include the characters
11 | ** 128-255, too. This allows for the use of all non-ASCII chars as identifiers
12 | ** in the lexer. This is a broad definition, but works well in practice
13 | ** for both UTF-8 locales and most single-byte locales (such as ISO-8859-*).
14 | **
15 | ** If you really need proper character types for UTF-8 strings, please use
16 | ** an add-on library such as slnunicode: http://luaforge.net/projects/sln/
17 | */
18 |
19 | #define lj_char_c
20 | #define LUA_CORE
21 |
22 | #include "lj_char.h"
23 |
24 | LJ_DATADEF const uint8_t lj_char_bits[257] = {
25 | 0,
26 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 3, 3, 3, 3, 1, 1,
27 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
28 | 2, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
29 | 152,152,152,152,152,152,152,152,152,152, 4, 4, 4, 4, 4, 4,
30 | 4,176,176,176,176,176,176,160,160,160,160,160,160,160,160,160,
31 | 160,160,160,160,160,160,160,160,160,160,160, 4, 4, 4, 4,132,
32 | 4,208,208,208,208,208,208,192,192,192,192,192,192,192,192,192,
33 | 192,192,192,192,192,192,192,192,192,192,192, 4, 4, 4, 4, 1,
34 | 128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,
35 | 128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,
36 | 128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,
37 | 128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,
38 | 128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,
39 | 128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,
40 | 128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,
41 | 128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128
42 | };
43 |
44 |
--------------------------------------------------------------------------------
/luajit/jit/lj_char.h:
--------------------------------------------------------------------------------
1 | /*
2 | ** Character types.
3 | ** Donated to the public domain.
4 | */
5 |
6 | #ifndef _LJ_CHAR_H
7 | #define _LJ_CHAR_H
8 |
9 | #include "lj_def.h"
10 |
11 | #define LJ_CHAR_CNTRL 0x01
12 | #define LJ_CHAR_SPACE 0x02
13 | #define LJ_CHAR_PUNCT 0x04
14 | #define LJ_CHAR_DIGIT 0x08
15 | #define LJ_CHAR_XDIGIT 0x10
16 | #define LJ_CHAR_UPPER 0x20
17 | #define LJ_CHAR_LOWER 0x40
18 | #define LJ_CHAR_IDENT 0x80
19 | #define LJ_CHAR_ALPHA (LJ_CHAR_LOWER|LJ_CHAR_UPPER)
20 | #define LJ_CHAR_ALNUM (LJ_CHAR_ALPHA|LJ_CHAR_DIGIT)
21 | #define LJ_CHAR_GRAPH (LJ_CHAR_ALNUM|LJ_CHAR_PUNCT)
22 |
23 | /* Only pass -1 or 0..255 to these macros. Never pass a signed char! */
24 | #define lj_char_isa(c, t) ((lj_char_bits+1)[(c)] & t)
25 | #define lj_char_iscntrl(c) lj_char_isa((c), LJ_CHAR_CNTRL)
26 | #define lj_char_isspace(c) lj_char_isa((c), LJ_CHAR_SPACE)
27 | #define lj_char_ispunct(c) lj_char_isa((c), LJ_CHAR_PUNCT)
28 | #define lj_char_isdigit(c) lj_char_isa((c), LJ_CHAR_DIGIT)
29 | #define lj_char_isxdigit(c) lj_char_isa((c), LJ_CHAR_XDIGIT)
30 | #define lj_char_isupper(c) lj_char_isa((c), LJ_CHAR_UPPER)
31 | #define lj_char_islower(c) lj_char_isa((c), LJ_CHAR_LOWER)
32 | #define lj_char_isident(c) lj_char_isa((c), LJ_CHAR_IDENT)
33 | #define lj_char_isalpha(c) lj_char_isa((c), LJ_CHAR_ALPHA)
34 | #define lj_char_isalnum(c) lj_char_isa((c), LJ_CHAR_ALNUM)
35 | #define lj_char_isgraph(c) lj_char_isa((c), LJ_CHAR_GRAPH)
36 |
37 | #define lj_char_toupper(c) ((c) - (lj_char_islower(c) >> 1))
38 | #define lj_char_tolower(c) ((c) + lj_char_isupper(c))
39 |
40 | LJ_DATA const uint8_t lj_char_bits[257];
41 |
42 | #endif
43 |
--------------------------------------------------------------------------------
/luajit/jit/lj_char.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/helloh2o/room_game_server/aecbb085afbf2e797f46d10f1e52b51ea1f0147d/luajit/jit/lj_char.o
--------------------------------------------------------------------------------
/luajit/jit/lj_clib.h:
--------------------------------------------------------------------------------
1 | /*
2 | ** FFI C library loader.
3 | ** Copyright (C) 2005-2015 Mike Pall. See Copyright Notice in luajit.h
4 | */
5 |
6 | #ifndef _LJ_CLIB_H
7 | #define _LJ_CLIB_H
8 |
9 | #include "lj_obj.h"
10 |
11 | #if LJ_HASFFI
12 |
13 | /* Namespace for C library indexing. */
14 | #define CLNS_INDEX ((1u<env. */
20 | } CLibrary;
21 |
22 | LJ_FUNC TValue *lj_clib_index(lua_State *L, CLibrary *cl, GCstr *name);
23 | LJ_FUNC void lj_clib_load(lua_State *L, GCtab *mt, GCstr *name, int global);
24 | LJ_FUNC void lj_clib_unload(CLibrary *cl);
25 | LJ_FUNC void lj_clib_default(lua_State *L, GCtab *mt);
26 |
27 | #endif
28 |
29 | #endif
30 |
--------------------------------------------------------------------------------
/luajit/jit/lj_clib.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/helloh2o/room_game_server/aecbb085afbf2e797f46d10f1e52b51ea1f0147d/luajit/jit/lj_clib.o
--------------------------------------------------------------------------------
/luajit/jit/lj_cparse.h:
--------------------------------------------------------------------------------
1 | /*
2 | ** C declaration parser.
3 | ** Copyright (C) 2005-2015 Mike Pall. See Copyright Notice in luajit.h
4 | */
5 |
6 | #ifndef _LJ_CPARSE_H
7 | #define _LJ_CPARSE_H
8 |
9 | #include "lj_obj.h"
10 | #include "lj_ctype.h"
11 |
12 | #if LJ_HASFFI
13 |
14 | /* C parser limits. */
15 | #define CPARSE_MAX_BUF 32768 /* Max. token buffer size. */
16 | #define CPARSE_MAX_DECLSTACK 100 /* Max. declaration stack depth. */
17 | #define CPARSE_MAX_DECLDEPTH 20 /* Max. recursive declaration depth. */
18 | #define CPARSE_MAX_PACKSTACK 7 /* Max. pack pragma stack depth. */
19 |
20 | /* Flags for C parser mode. */
21 | #define CPARSE_MODE_MULTI 1 /* Process multiple declarations. */
22 | #define CPARSE_MODE_ABSTRACT 2 /* Accept abstract declarators. */
23 | #define CPARSE_MODE_DIRECT 4 /* Accept direct declarators. */
24 | #define CPARSE_MODE_FIELD 8 /* Accept field width in bits, too. */
25 | #define CPARSE_MODE_NOIMPLICIT 16 /* Reject implicit declarations. */
26 | #define CPARSE_MODE_SKIP 32 /* Skip definitions, ignore errors. */
27 |
28 | typedef int CPChar; /* C parser character. Unsigned ext. from char. */
29 | typedef int CPToken; /* C parser token. */
30 |
31 | /* C parser internal value representation. */
32 | typedef struct CPValue {
33 | union {
34 | int32_t i32; /* Value for CTID_INT32. */
35 | uint32_t u32; /* Value for CTID_UINT32. */
36 | };
37 | CTypeID id; /* C Type ID of the value. */
38 | } CPValue;
39 |
40 | /* C parser state. */
41 | typedef struct CPState {
42 | CPChar c; /* Current character. */
43 | CPToken tok; /* Current token. */
44 | CPValue val; /* Token value. */
45 | GCstr *str; /* Interned string of identifier/keyword. */
46 | CType *ct; /* C type table entry. */
47 | const char *p; /* Current position in input buffer. */
48 | SBuf sb; /* String buffer for tokens. */
49 | lua_State *L; /* Lua state. */
50 | CTState *cts; /* C type state. */
51 | TValue *param; /* C type parameters. */
52 | const char *srcname; /* Current source name. */
53 | BCLine linenumber; /* Input line counter. */
54 | int depth; /* Recursive declaration depth. */
55 | uint32_t tmask; /* Type mask for next identifier. */
56 | uint32_t mode; /* C parser mode. */
57 | uint8_t packstack[CPARSE_MAX_PACKSTACK]; /* Stack for pack pragmas. */
58 | uint8_t curpack; /* Current position in pack pragma stack. */
59 | } CPState;
60 |
61 | LJ_FUNC int lj_cparse(CPState *cp);
62 |
63 | #endif
64 |
65 | #endif
66 |
--------------------------------------------------------------------------------
/luajit/jit/lj_cparse.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/helloh2o/room_game_server/aecbb085afbf2e797f46d10f1e52b51ea1f0147d/luajit/jit/lj_cparse.o
--------------------------------------------------------------------------------
/luajit/jit/lj_crecord.h:
--------------------------------------------------------------------------------
1 | /*
2 | ** Trace recorder for C data operations.
3 | ** Copyright (C) 2005-2015 Mike Pall. See Copyright Notice in luajit.h
4 | */
5 |
6 | #ifndef _LJ_CRECORD_H
7 | #define _LJ_CRECORD_H
8 |
9 | #include "lj_obj.h"
10 | #include "lj_jit.h"
11 | #include "lj_ffrecord.h"
12 |
13 | #if LJ_HASJIT && LJ_HASFFI
14 | LJ_FUNC void LJ_FASTCALL recff_cdata_index(jit_State *J, RecordFFData *rd);
15 | LJ_FUNC void LJ_FASTCALL recff_cdata_call(jit_State *J, RecordFFData *rd);
16 | LJ_FUNC void LJ_FASTCALL recff_cdata_arith(jit_State *J, RecordFFData *rd);
17 | LJ_FUNC void LJ_FASTCALL recff_clib_index(jit_State *J, RecordFFData *rd);
18 | LJ_FUNC void LJ_FASTCALL recff_ffi_new(jit_State *J, RecordFFData *rd);
19 | LJ_FUNC void LJ_FASTCALL recff_ffi_errno(jit_State *J, RecordFFData *rd);
20 | LJ_FUNC void LJ_FASTCALL recff_ffi_string(jit_State *J, RecordFFData *rd);
21 | LJ_FUNC void LJ_FASTCALL recff_ffi_copy(jit_State *J, RecordFFData *rd);
22 | LJ_FUNC void LJ_FASTCALL recff_ffi_fill(jit_State *J, RecordFFData *rd);
23 | LJ_FUNC void LJ_FASTCALL recff_ffi_typeof(jit_State *J, RecordFFData *rd);
24 | LJ_FUNC void LJ_FASTCALL recff_ffi_istype(jit_State *J, RecordFFData *rd);
25 | LJ_FUNC void LJ_FASTCALL recff_ffi_abi(jit_State *J, RecordFFData *rd);
26 | LJ_FUNC void LJ_FASTCALL recff_ffi_xof(jit_State *J, RecordFFData *rd);
27 | LJ_FUNC void LJ_FASTCALL recff_ffi_gc(jit_State *J, RecordFFData *rd);
28 | LJ_FUNC void LJ_FASTCALL lj_crecord_tonumber(jit_State *J, RecordFFData *rd);
29 | #endif
30 |
31 | #endif
32 |
--------------------------------------------------------------------------------
/luajit/jit/lj_crecord.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/helloh2o/room_game_server/aecbb085afbf2e797f46d10f1e52b51ea1f0147d/luajit/jit/lj_crecord.o
--------------------------------------------------------------------------------
/luajit/jit/lj_ctype.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/helloh2o/room_game_server/aecbb085afbf2e797f46d10f1e52b51ea1f0147d/luajit/jit/lj_ctype.o
--------------------------------------------------------------------------------
/luajit/jit/lj_debug.h:
--------------------------------------------------------------------------------
1 | /*
2 | ** Debugging and introspection.
3 | ** Copyright (C) 2005-2015 Mike Pall. See Copyright Notice in luajit.h
4 | */
5 |
6 | #ifndef _LJ_DEBUG_H
7 | #define _LJ_DEBUG_H
8 |
9 | #include "lj_obj.h"
10 |
11 | typedef struct lj_Debug {
12 | /* Common fields. Must be in the same order as in lua.h. */
13 | int event;
14 | const char *name;
15 | const char *namewhat;
16 | const char *what;
17 | const char *source;
18 | int currentline;
19 | int nups;
20 | int linedefined;
21 | int lastlinedefined;
22 | char short_src[LUA_IDSIZE];
23 | int i_ci;
24 | /* Extended fields. Only valid if lj_debug_getinfo() is called with ext = 1.*/
25 | int nparams;
26 | int isvararg;
27 | } lj_Debug;
28 |
29 | LJ_FUNC cTValue *lj_debug_frame(lua_State *L, int level, int *size);
30 | LJ_FUNC BCLine LJ_FASTCALL lj_debug_line(GCproto *pt, BCPos pc);
31 | LJ_FUNC const char *lj_debug_uvname(GCproto *pt, uint32_t idx);
32 | LJ_FUNC const char *lj_debug_uvnamev(cTValue *o, uint32_t idx, TValue **tvp);
33 | LJ_FUNC const char *lj_debug_slotname(GCproto *pt, const BCIns *pc,
34 | BCReg slot, const char **name);
35 | LJ_FUNC const char *lj_debug_funcname(lua_State *L, TValue *frame,
36 | const char **name);
37 | LJ_FUNC void lj_debug_shortname(char *out, GCstr *str);
38 | LJ_FUNC void lj_debug_addloc(lua_State *L, const char *msg,
39 | cTValue *frame, cTValue *nextframe);
40 | LJ_FUNC void lj_debug_pushloc(lua_State *L, GCproto *pt, BCPos pc);
41 | LJ_FUNC int lj_debug_getinfo(lua_State *L, const char *what, lj_Debug *ar,
42 | int ext);
43 |
44 | /* Fixed internal variable names. */
45 | #define VARNAMEDEF(_) \
46 | _(FOR_IDX, "(for index)") \
47 | _(FOR_STOP, "(for limit)") \
48 | _(FOR_STEP, "(for step)") \
49 | _(FOR_GEN, "(for generator)") \
50 | _(FOR_STATE, "(for state)") \
51 | _(FOR_CTL, "(for control)")
52 |
53 | enum {
54 | VARNAME_END,
55 | #define VARNAMEENUM(name, str) VARNAME_##name,
56 | VARNAMEDEF(VARNAMEENUM)
57 | #undef VARNAMEENUM
58 | VARNAME__MAX
59 | };
60 |
61 | #endif
62 |
--------------------------------------------------------------------------------
/luajit/jit/lj_debug.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/helloh2o/room_game_server/aecbb085afbf2e797f46d10f1e52b51ea1f0147d/luajit/jit/lj_debug.o
--------------------------------------------------------------------------------
/luajit/jit/lj_dispatch.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/helloh2o/room_game_server/aecbb085afbf2e797f46d10f1e52b51ea1f0147d/luajit/jit/lj_dispatch.o
--------------------------------------------------------------------------------
/luajit/jit/lj_err.h:
--------------------------------------------------------------------------------
1 | /*
2 | ** Error handling.
3 | ** Copyright (C) 2005-2015 Mike Pall. See Copyright Notice in luajit.h
4 | */
5 |
6 | #ifndef _LJ_ERR_H
7 | #define _LJ_ERR_H
8 |
9 | #include
10 |
11 | #include "lj_obj.h"
12 |
13 | typedef enum {
14 | #define ERRDEF(name, msg) \
15 | LJ_ERR_##name, LJ_ERR_##name##_ = LJ_ERR_##name + sizeof(msg)-1,
16 | #include "lj_errmsg.h"
17 | LJ_ERR__MAX
18 | } ErrMsg;
19 |
20 | LJ_DATA const char *lj_err_allmsg;
21 | #define err2msg(em) (lj_err_allmsg+(int)(em))
22 |
23 | LJ_FUNC GCstr *lj_err_str(lua_State *L, ErrMsg em);
24 | LJ_FUNCA_NORET void LJ_FASTCALL lj_err_throw(lua_State *L, int errcode);
25 | LJ_FUNC_NORET void lj_err_mem(lua_State *L);
26 | LJ_FUNC_NORET void lj_err_run(lua_State *L);
27 | LJ_FUNC_NORET void lj_err_msg(lua_State *L, ErrMsg em);
28 | LJ_FUNC_NORET void lj_err_lex(lua_State *L, GCstr *src, const char *tok,
29 | BCLine line, ErrMsg em, va_list argp);
30 | LJ_FUNC_NORET void lj_err_optype(lua_State *L, cTValue *o, ErrMsg opm);
31 | LJ_FUNC_NORET void lj_err_comp(lua_State *L, cTValue *o1, cTValue *o2);
32 | LJ_FUNC_NORET void lj_err_optype_call(lua_State *L, TValue *o);
33 | LJ_FUNC_NORET void lj_err_callermsg(lua_State *L, const char *msg);
34 | LJ_FUNC_NORET void lj_err_callerv(lua_State *L, ErrMsg em, ...);
35 | LJ_FUNC_NORET void lj_err_caller(lua_State *L, ErrMsg em);
36 | LJ_FUNC_NORET void lj_err_arg(lua_State *L, int narg, ErrMsg em);
37 | LJ_FUNC_NORET void lj_err_argv(lua_State *L, int narg, ErrMsg em, ...);
38 | LJ_FUNC_NORET void lj_err_argtype(lua_State *L, int narg, const char *xname);
39 | LJ_FUNC_NORET void lj_err_argt(lua_State *L, int narg, int tt);
40 |
41 | #endif
42 |
--------------------------------------------------------------------------------
/luajit/jit/lj_err.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/helloh2o/room_game_server/aecbb085afbf2e797f46d10f1e52b51ea1f0147d/luajit/jit/lj_err.o
--------------------------------------------------------------------------------
/luajit/jit/lj_ff.h:
--------------------------------------------------------------------------------
1 | /*
2 | ** Fast function IDs.
3 | ** Copyright (C) 2005-2015 Mike Pall. See Copyright Notice in luajit.h
4 | */
5 |
6 | #ifndef _LJ_FF_H
7 | #define _LJ_FF_H
8 |
9 | /* Fast function ID. */
10 | typedef enum {
11 | FF_LUA_ = FF_LUA, /* Lua function (must be 0). */
12 | FF_C_ = FF_C, /* Regular C function (must be 1). */
13 | #define FFDEF(name) FF_##name,
14 | #include "lj_ffdef.h"
15 | FF__MAX
16 | } FastFunc;
17 |
18 | #endif
19 |
--------------------------------------------------------------------------------
/luajit/jit/lj_ffrecord.h:
--------------------------------------------------------------------------------
1 | /*
2 | ** Fast function call recorder.
3 | ** Copyright (C) 2005-2015 Mike Pall. See Copyright Notice in luajit.h
4 | */
5 |
6 | #ifndef _LJ_FFRECORD_H
7 | #define _LJ_FFRECORD_H
8 |
9 | #include "lj_obj.h"
10 | #include "lj_jit.h"
11 |
12 | #if LJ_HASJIT
13 | /* Data used by handlers to record a fast function. */
14 | typedef struct RecordFFData {
15 | TValue *argv; /* Runtime argument values. */
16 | ptrdiff_t nres; /* Number of returned results (defaults to 1). */
17 | uint32_t data; /* Per-ffid auxiliary data (opcode, literal etc.). */
18 | } RecordFFData;
19 |
20 | LJ_FUNC int32_t lj_ffrecord_select_mode(jit_State *J, TRef tr, TValue *tv);
21 | LJ_FUNC void lj_ffrecord_func(jit_State *J);
22 | #endif
23 |
24 | #endif
25 |
--------------------------------------------------------------------------------
/luajit/jit/lj_ffrecord.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/helloh2o/room_game_server/aecbb085afbf2e797f46d10f1e52b51ea1f0147d/luajit/jit/lj_ffrecord.o
--------------------------------------------------------------------------------
/luajit/jit/lj_func.h:
--------------------------------------------------------------------------------
1 | /*
2 | ** Function handling (prototypes, functions and upvalues).
3 | ** Copyright (C) 2005-2015 Mike Pall. See Copyright Notice in luajit.h
4 | */
5 |
6 | #ifndef _LJ_FUNC_H
7 | #define _LJ_FUNC_H
8 |
9 | #include "lj_obj.h"
10 |
11 | /* Prototypes. */
12 | LJ_FUNC void LJ_FASTCALL lj_func_freeproto(global_State *g, GCproto *pt);
13 |
14 | /* Upvalues. */
15 | LJ_FUNCA void LJ_FASTCALL lj_func_closeuv(lua_State *L, TValue *level);
16 | LJ_FUNC void LJ_FASTCALL lj_func_freeuv(global_State *g, GCupval *uv);
17 |
18 | /* Functions (closures). */
19 | LJ_FUNC GCfunc *lj_func_newC(lua_State *L, MSize nelems, GCtab *env);
20 | LJ_FUNC GCfunc *lj_func_newL_empty(lua_State *L, GCproto *pt, GCtab *env);
21 | LJ_FUNCA GCfunc *lj_func_newL_gc(lua_State *L, GCproto *pt, GCfuncL *parent);
22 | LJ_FUNC void LJ_FASTCALL lj_func_free(global_State *g, GCfunc *c);
23 |
24 | #endif
25 |
--------------------------------------------------------------------------------
/luajit/jit/lj_func.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/helloh2o/room_game_server/aecbb085afbf2e797f46d10f1e52b51ea1f0147d/luajit/jit/lj_func.o
--------------------------------------------------------------------------------
/luajit/jit/lj_gc.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/helloh2o/room_game_server/aecbb085afbf2e797f46d10f1e52b51ea1f0147d/luajit/jit/lj_gc.o
--------------------------------------------------------------------------------
/luajit/jit/lj_gdbjit.h:
--------------------------------------------------------------------------------
1 | /*
2 | ** Client for the GDB JIT API.
3 | ** Copyright (C) 2005-2015 Mike Pall. See Copyright Notice in luajit.h
4 | */
5 |
6 | #ifndef _LJ_GDBJIT_H
7 | #define _LJ_GDBJIT_H
8 |
9 | #include "lj_obj.h"
10 | #include "lj_jit.h"
11 |
12 | #if LJ_HASJIT && defined(LUAJIT_USE_GDBJIT)
13 |
14 | LJ_FUNC void lj_gdbjit_addtrace(jit_State *J, GCtrace *T);
15 | LJ_FUNC void lj_gdbjit_deltrace(jit_State *J, GCtrace *T);
16 |
17 | #else
18 | #define lj_gdbjit_addtrace(J, T) UNUSED(T)
19 | #define lj_gdbjit_deltrace(J, T) UNUSED(T)
20 | #endif
21 |
22 | #endif
23 |
--------------------------------------------------------------------------------
/luajit/jit/lj_gdbjit.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/helloh2o/room_game_server/aecbb085afbf2e797f46d10f1e52b51ea1f0147d/luajit/jit/lj_gdbjit.o
--------------------------------------------------------------------------------
/luajit/jit/lj_ir.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/helloh2o/room_game_server/aecbb085afbf2e797f46d10f1e52b51ea1f0147d/luajit/jit/lj_ir.o
--------------------------------------------------------------------------------
/luajit/jit/lj_lex.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/helloh2o/room_game_server/aecbb085afbf2e797f46d10f1e52b51ea1f0147d/luajit/jit/lj_lex.o
--------------------------------------------------------------------------------
/luajit/jit/lj_lib.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/helloh2o/room_game_server/aecbb085afbf2e797f46d10f1e52b51ea1f0147d/luajit/jit/lj_lib.o
--------------------------------------------------------------------------------
/luajit/jit/lj_load.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/helloh2o/room_game_server/aecbb085afbf2e797f46d10f1e52b51ea1f0147d/luajit/jit/lj_load.o
--------------------------------------------------------------------------------
/luajit/jit/lj_mcode.h:
--------------------------------------------------------------------------------
1 | /*
2 | ** Machine code management.
3 | ** Copyright (C) 2005-2015 Mike Pall. See Copyright Notice in luajit.h
4 | */
5 |
6 | #ifndef _LJ_MCODE_H
7 | #define _LJ_MCODE_H
8 |
9 | #include "lj_obj.h"
10 |
11 | #if LJ_HASJIT || LJ_HASFFI
12 | LJ_FUNC void lj_mcode_sync(void *start, void *end);
13 | #endif
14 |
15 | #if LJ_HASJIT
16 |
17 | #include "lj_jit.h"
18 |
19 | LJ_FUNC void lj_mcode_free(jit_State *J);
20 | LJ_FUNC MCode *lj_mcode_reserve(jit_State *J, MCode **lim);
21 | LJ_FUNC void lj_mcode_commit(jit_State *J, MCode *m);
22 | LJ_FUNC void lj_mcode_abort(jit_State *J);
23 | LJ_FUNC MCode *lj_mcode_patch(jit_State *J, MCode *ptr, int finish);
24 | LJ_FUNC_NORET void lj_mcode_limiterr(jit_State *J, size_t need);
25 |
26 | #define lj_mcode_commitbot(J, m) (J->mcbot = (m))
27 |
28 | #endif
29 |
30 | #endif
31 |
--------------------------------------------------------------------------------
/luajit/jit/lj_mcode.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/helloh2o/room_game_server/aecbb085afbf2e797f46d10f1e52b51ea1f0147d/luajit/jit/lj_mcode.o
--------------------------------------------------------------------------------
/luajit/jit/lj_meta.h:
--------------------------------------------------------------------------------
1 | /*
2 | ** Metamethod handling.
3 | ** Copyright (C) 2005-2015 Mike Pall. See Copyright Notice in luajit.h
4 | */
5 |
6 | #ifndef _LJ_META_H
7 | #define _LJ_META_H
8 |
9 | #include "lj_obj.h"
10 |
11 | /* Metamethod handling */
12 | LJ_FUNC void lj_meta_init(lua_State *L);
13 | LJ_FUNC cTValue *lj_meta_cache(GCtab *mt, MMS mm, GCstr *name);
14 | LJ_FUNC cTValue *lj_meta_lookup(lua_State *L, cTValue *o, MMS mm);
15 | #if LJ_HASFFI
16 | LJ_FUNC int lj_meta_tailcall(lua_State *L, cTValue *tv);
17 | #endif
18 |
19 | #define lj_meta_fastg(g, mt, mm) \
20 | ((mt) == NULL ? NULL : ((mt)->nomm & (1u<<(mm))) ? NULL : \
21 | lj_meta_cache(mt, mm, mmname_str(g, mm)))
22 | #define lj_meta_fast(L, mt, mm) lj_meta_fastg(G(L), mt, mm)
23 |
24 | /* C helpers for some instructions, called from assembler VM. */
25 | LJ_FUNCA cTValue *lj_meta_tget(lua_State *L, cTValue *o, cTValue *k);
26 | LJ_FUNCA TValue *lj_meta_tset(lua_State *L, cTValue *o, cTValue *k);
27 | LJ_FUNCA TValue *lj_meta_arith(lua_State *L, TValue *ra, cTValue *rb,
28 | cTValue *rc, BCReg op);
29 | LJ_FUNCA TValue *lj_meta_cat(lua_State *L, TValue *top, int left);
30 | LJ_FUNCA TValue * LJ_FASTCALL lj_meta_len(lua_State *L, cTValue *o);
31 | LJ_FUNCA TValue *lj_meta_equal(lua_State *L, GCobj *o1, GCobj *o2, int ne);
32 | LJ_FUNCA TValue * LJ_FASTCALL lj_meta_equal_cd(lua_State *L, BCIns ins);
33 | LJ_FUNCA TValue *lj_meta_comp(lua_State *L, cTValue *o1, cTValue *o2, int op);
34 | LJ_FUNCA void lj_meta_call(lua_State *L, TValue *func, TValue *top);
35 | LJ_FUNCA void LJ_FASTCALL lj_meta_for(lua_State *L, TValue *o);
36 |
37 | #endif
38 |
--------------------------------------------------------------------------------
/luajit/jit/lj_meta.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/helloh2o/room_game_server/aecbb085afbf2e797f46d10f1e52b51ea1f0147d/luajit/jit/lj_meta.o
--------------------------------------------------------------------------------
/luajit/jit/lj_obj.c:
--------------------------------------------------------------------------------
1 | /*
2 | ** Miscellaneous object handling.
3 | ** Copyright (C) 2005-2015 Mike Pall. See Copyright Notice in luajit.h
4 | */
5 |
6 | #define lj_obj_c
7 | #define LUA_CORE
8 |
9 | #include "lj_obj.h"
10 |
11 | /* Object type names. */
12 | LJ_DATADEF const char *const lj_obj_typename[] = { /* ORDER LUA_T */
13 | "no value", "nil", "boolean", "userdata", "number", "string",
14 | "table", "function", "userdata", "thread", "proto", "cdata"
15 | };
16 |
17 | LJ_DATADEF const char *const lj_obj_itypename[] = { /* ORDER LJ_T */
18 | "nil", "boolean", "boolean", "userdata", "string", "upval", "thread",
19 | "proto", "function", "trace", "cdata", "table", "userdata", "number"
20 | };
21 |
22 | /* Compare two objects without calling metamethods. */
23 | int lj_obj_equal(cTValue *o1, cTValue *o2)
24 | {
25 | if (itype(o1) == itype(o2)) {
26 | if (tvispri(o1))
27 | return 1;
28 | if (!tvisnum(o1))
29 | return gcrefeq(o1->gcr, o2->gcr);
30 | } else if (!tvisnumber(o1) || !tvisnumber(o2)) {
31 | return 0;
32 | }
33 | return numberVnum(o1) == numberVnum(o2);
34 | }
35 |
36 |
--------------------------------------------------------------------------------
/luajit/jit/lj_obj.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/helloh2o/room_game_server/aecbb085afbf2e797f46d10f1e52b51ea1f0147d/luajit/jit/lj_obj.o
--------------------------------------------------------------------------------
/luajit/jit/lj_opt_dce.c:
--------------------------------------------------------------------------------
1 | /*
2 | ** DCE: Dead Code Elimination. Pre-LOOP only -- ASM already performs DCE.
3 | ** Copyright (C) 2005-2015 Mike Pall. See Copyright Notice in luajit.h
4 | */
5 |
6 | #define lj_opt_dce_c
7 | #define LUA_CORE
8 |
9 | #include "lj_obj.h"
10 |
11 | #if LJ_HASJIT
12 |
13 | #include "lj_ir.h"
14 | #include "lj_jit.h"
15 | #include "lj_iropt.h"
16 |
17 | /* Some local macros to save typing. Undef'd at the end. */
18 | #define IR(ref) (&J->cur.ir[(ref)])
19 |
20 | /* Scan through all snapshots and mark all referenced instructions. */
21 | static void dce_marksnap(jit_State *J)
22 | {
23 | SnapNo i, nsnap = J->cur.nsnap;
24 | for (i = 0; i < nsnap; i++) {
25 | SnapShot *snap = &J->cur.snap[i];
26 | SnapEntry *map = &J->cur.snapmap[snap->mapofs];
27 | MSize n, nent = snap->nent;
28 | for (n = 0; n < nent; n++) {
29 | IRRef ref = snap_ref(map[n]);
30 | if (ref >= REF_FIRST)
31 | irt_setmark(IR(ref)->t);
32 | }
33 | }
34 | }
35 |
36 | /* Backwards propagate marks. Replace unused instructions with NOPs. */
37 | static void dce_propagate(jit_State *J)
38 | {
39 | IRRef1 *pchain[IR__MAX];
40 | IRRef ins;
41 | uint32_t i;
42 | for (i = 0; i < IR__MAX; i++) pchain[i] = &J->chain[i];
43 | for (ins = J->cur.nins-1; ins >= REF_FIRST; ins--) {
44 | IRIns *ir = IR(ins);
45 | if (irt_ismarked(ir->t)) {
46 | irt_clearmark(ir->t);
47 | pchain[ir->o] = &ir->prev;
48 | } else if (!ir_sideeff(ir)) {
49 | *pchain[ir->o] = ir->prev; /* Reroute original instruction chain. */
50 | ir->t.irt = IRT_NIL;
51 | ir->o = IR_NOP; /* Replace instruction with NOP. */
52 | ir->op1 = ir->op2 = 0;
53 | ir->prev = 0;
54 | continue;
55 | }
56 | if (ir->op1 >= REF_FIRST) irt_setmark(IR(ir->op1)->t);
57 | if (ir->op2 >= REF_FIRST) irt_setmark(IR(ir->op2)->t);
58 | }
59 | }
60 |
61 | /* Dead Code Elimination.
62 | **
63 | ** First backpropagate marks for all used instructions. Then replace
64 | ** the unused ones with a NOP. Note that compressing the IR to eliminate
65 | ** the NOPs does not pay off.
66 | */
67 | void lj_opt_dce(jit_State *J)
68 | {
69 | if ((J->flags & JIT_F_OPT_DCE)) {
70 | dce_marksnap(J);
71 | dce_propagate(J);
72 | memset(J->bpropcache, 0, sizeof(J->bpropcache)); /* Invalidate cache. */
73 | }
74 | }
75 |
76 | #undef IR
77 |
78 | #endif
79 |
--------------------------------------------------------------------------------
/luajit/jit/lj_opt_dce.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/helloh2o/room_game_server/aecbb085afbf2e797f46d10f1e52b51ea1f0147d/luajit/jit/lj_opt_dce.o
--------------------------------------------------------------------------------
/luajit/jit/lj_opt_fold.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/helloh2o/room_game_server/aecbb085afbf2e797f46d10f1e52b51ea1f0147d/luajit/jit/lj_opt_fold.o
--------------------------------------------------------------------------------
/luajit/jit/lj_opt_loop.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/helloh2o/room_game_server/aecbb085afbf2e797f46d10f1e52b51ea1f0147d/luajit/jit/lj_opt_loop.o
--------------------------------------------------------------------------------
/luajit/jit/lj_opt_mem.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/helloh2o/room_game_server/aecbb085afbf2e797f46d10f1e52b51ea1f0147d/luajit/jit/lj_opt_mem.o
--------------------------------------------------------------------------------
/luajit/jit/lj_opt_narrow.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/helloh2o/room_game_server/aecbb085afbf2e797f46d10f1e52b51ea1f0147d/luajit/jit/lj_opt_narrow.o
--------------------------------------------------------------------------------
/luajit/jit/lj_opt_sink.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/helloh2o/room_game_server/aecbb085afbf2e797f46d10f1e52b51ea1f0147d/luajit/jit/lj_opt_sink.o
--------------------------------------------------------------------------------
/luajit/jit/lj_opt_split.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/helloh2o/room_game_server/aecbb085afbf2e797f46d10f1e52b51ea1f0147d/luajit/jit/lj_opt_split.o
--------------------------------------------------------------------------------
/luajit/jit/lj_parse.h:
--------------------------------------------------------------------------------
1 | /*
2 | ** Lua parser (source code -> bytecode).
3 | ** Copyright (C) 2005-2015 Mike Pall. See Copyright Notice in luajit.h
4 | */
5 |
6 | #ifndef _LJ_PARSE_H
7 | #define _LJ_PARSE_H
8 |
9 | #include "lj_obj.h"
10 | #include "lj_lex.h"
11 |
12 | LJ_FUNC GCproto *lj_parse(LexState *ls);
13 | LJ_FUNC GCstr *lj_parse_keepstr(LexState *ls, const char *str, size_t l);
14 | #if LJ_HASFFI
15 | LJ_FUNC void lj_parse_keepcdata(LexState *ls, TValue *tv, GCcdata *cd);
16 | #endif
17 |
18 | #endif
19 |
--------------------------------------------------------------------------------
/luajit/jit/lj_parse.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/helloh2o/room_game_server/aecbb085afbf2e797f46d10f1e52b51ea1f0147d/luajit/jit/lj_parse.o
--------------------------------------------------------------------------------
/luajit/jit/lj_record.h:
--------------------------------------------------------------------------------
1 | /*
2 | ** Trace recorder (bytecode -> SSA IR).
3 | ** Copyright (C) 2005-2015 Mike Pall. See Copyright Notice in luajit.h
4 | */
5 |
6 | #ifndef _LJ_RECORD_H
7 | #define _LJ_RECORD_H
8 |
9 | #include "lj_obj.h"
10 | #include "lj_jit.h"
11 |
12 | #if LJ_HASJIT
13 | /* Context for recording an indexed load/store. */
14 | typedef struct RecordIndex {
15 | TValue tabv; /* Runtime value of table (or indexed object). */
16 | TValue keyv; /* Runtime value of key. */
17 | TValue valv; /* Runtime value of stored value. */
18 | TValue mobjv; /* Runtime value of metamethod object. */
19 | GCtab *mtv; /* Runtime value of metatable object. */
20 | cTValue *oldv; /* Runtime value of previously stored value. */
21 | TRef tab; /* Table (or indexed object) reference. */
22 | TRef key; /* Key reference. */
23 | TRef val; /* Value reference for a store or 0 for a load. */
24 | TRef mt; /* Metatable reference. */
25 | TRef mobj; /* Metamethod object reference. */
26 | int idxchain; /* Index indirections left or 0 for raw lookup. */
27 | } RecordIndex;
28 |
29 | LJ_FUNC int lj_record_objcmp(jit_State *J, TRef a, TRef b,
30 | cTValue *av, cTValue *bv);
31 | LJ_FUNC TRef lj_record_constify(jit_State *J, cTValue *o);
32 |
33 | LJ_FUNC void lj_record_call(jit_State *J, BCReg func, ptrdiff_t nargs);
34 | LJ_FUNC void lj_record_tailcall(jit_State *J, BCReg func, ptrdiff_t nargs);
35 | LJ_FUNC void lj_record_ret(jit_State *J, BCReg rbase, ptrdiff_t gotresults);
36 |
37 | LJ_FUNC int lj_record_mm_lookup(jit_State *J, RecordIndex *ix, MMS mm);
38 | LJ_FUNC TRef lj_record_idx(jit_State *J, RecordIndex *ix);
39 |
40 | LJ_FUNC void lj_record_ins(jit_State *J);
41 | LJ_FUNC void lj_record_setup(jit_State *J);
42 | #endif
43 |
44 | #endif
45 |
--------------------------------------------------------------------------------
/luajit/jit/lj_record.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/helloh2o/room_game_server/aecbb085afbf2e797f46d10f1e52b51ea1f0147d/luajit/jit/lj_record.o
--------------------------------------------------------------------------------
/luajit/jit/lj_snap.h:
--------------------------------------------------------------------------------
1 | /*
2 | ** Snapshot handling.
3 | ** Copyright (C) 2005-2015 Mike Pall. See Copyright Notice in luajit.h
4 | */
5 |
6 | #ifndef _LJ_SNAP_H
7 | #define _LJ_SNAP_H
8 |
9 | #include "lj_obj.h"
10 | #include "lj_jit.h"
11 |
12 | #if LJ_HASJIT
13 | LJ_FUNC void lj_snap_add(jit_State *J);
14 | LJ_FUNC void lj_snap_purge(jit_State *J);
15 | LJ_FUNC void lj_snap_shrink(jit_State *J);
16 | LJ_FUNC IRIns *lj_snap_regspmap(GCtrace *T, SnapNo snapno, IRIns *ir);
17 | LJ_FUNC void lj_snap_replay(jit_State *J, GCtrace *T);
18 | LJ_FUNC const BCIns *lj_snap_restore(jit_State *J, void *exptr);
19 | LJ_FUNC void lj_snap_grow_buf_(jit_State *J, MSize need);
20 | LJ_FUNC void lj_snap_grow_map_(jit_State *J, MSize need);
21 |
22 | static LJ_AINLINE void lj_snap_grow_buf(jit_State *J, MSize need)
23 | {
24 | if (LJ_UNLIKELY(need > J->sizesnap)) lj_snap_grow_buf_(J, need);
25 | }
26 |
27 | static LJ_AINLINE void lj_snap_grow_map(jit_State *J, MSize need)
28 | {
29 | if (LJ_UNLIKELY(need > J->sizesnapmap)) lj_snap_grow_map_(J, need);
30 | }
31 |
32 | #endif
33 |
34 | #endif
35 |
--------------------------------------------------------------------------------
/luajit/jit/lj_snap.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/helloh2o/room_game_server/aecbb085afbf2e797f46d10f1e52b51ea1f0147d/luajit/jit/lj_snap.o
--------------------------------------------------------------------------------
/luajit/jit/lj_state.h:
--------------------------------------------------------------------------------
1 | /*
2 | ** State and stack handling.
3 | ** Copyright (C) 2005-2015 Mike Pall. See Copyright Notice in luajit.h
4 | */
5 |
6 | #ifndef _LJ_STATE_H
7 | #define _LJ_STATE_H
8 |
9 | #include "lj_obj.h"
10 |
11 | #define incr_top(L) \
12 | (++L->top >= tvref(L->maxstack) && (lj_state_growstack1(L), 0))
13 |
14 | #define savestack(L, p) ((char *)(p) - mref(L->stack, char))
15 | #define restorestack(L, n) ((TValue *)(mref(L->stack, char) + (n)))
16 |
17 | LJ_FUNC void lj_state_relimitstack(lua_State *L);
18 | LJ_FUNC void lj_state_shrinkstack(lua_State *L, MSize used);
19 | LJ_FUNCA void LJ_FASTCALL lj_state_growstack(lua_State *L, MSize need);
20 | LJ_FUNC void LJ_FASTCALL lj_state_growstack1(lua_State *L);
21 |
22 | static LJ_AINLINE void lj_state_checkstack(lua_State *L, MSize need)
23 | {
24 | if ((mref(L->maxstack, char) - (char *)L->top) <=
25 | (ptrdiff_t)need*(ptrdiff_t)sizeof(TValue))
26 | lj_state_growstack(L, need);
27 | }
28 |
29 | LJ_FUNC lua_State *lj_state_new(lua_State *L);
30 | LJ_FUNC void LJ_FASTCALL lj_state_free(global_State *g, lua_State *L);
31 | #if LJ_64
32 | LJ_FUNC lua_State *lj_state_newstate(lua_Alloc f, void *ud);
33 | #endif
34 |
35 | #endif
36 |
--------------------------------------------------------------------------------
/luajit/jit/lj_state.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/helloh2o/room_game_server/aecbb085afbf2e797f46d10f1e52b51ea1f0147d/luajit/jit/lj_state.o
--------------------------------------------------------------------------------
/luajit/jit/lj_str.h:
--------------------------------------------------------------------------------
1 | /*
2 | ** String handling.
3 | ** Copyright (C) 2005-2015 Mike Pall. See Copyright Notice in luajit.h
4 | */
5 |
6 | #ifndef _LJ_STR_H
7 | #define _LJ_STR_H
8 |
9 | #include
10 |
11 | #include "lj_obj.h"
12 |
13 | /* String interning. */
14 | LJ_FUNC int32_t LJ_FASTCALL lj_str_cmp(GCstr *a, GCstr *b);
15 | LJ_FUNC void lj_str_resize(lua_State *L, MSize newmask);
16 | LJ_FUNCA GCstr *lj_str_new(lua_State *L, const char *str, size_t len);
17 | LJ_FUNC void LJ_FASTCALL lj_str_free(global_State *g, GCstr *s);
18 |
19 | #define lj_str_newz(L, s) (lj_str_new(L, s, strlen(s)))
20 | #define lj_str_newlit(L, s) (lj_str_new(L, "" s, sizeof(s)-1))
21 |
22 | /* Type conversions. */
23 | LJ_FUNC size_t LJ_FASTCALL lj_str_bufnum(char *s, cTValue *o);
24 | LJ_FUNC char * LJ_FASTCALL lj_str_bufint(char *p, int32_t k);
25 | LJ_FUNCA GCstr * LJ_FASTCALL lj_str_fromnum(lua_State *L, const lua_Number *np);
26 | LJ_FUNC GCstr * LJ_FASTCALL lj_str_fromint(lua_State *L, int32_t k);
27 | LJ_FUNCA GCstr * LJ_FASTCALL lj_str_fromnumber(lua_State *L, cTValue *o);
28 |
29 | #define LJ_STR_INTBUF (1+10)
30 | #define LJ_STR_NUMBUF LUAI_MAXNUMBER2STR
31 |
32 | /* String formatting. */
33 | LJ_FUNC const char *lj_str_pushvf(lua_State *L, const char *fmt, va_list argp);
34 | LJ_FUNC const char *lj_str_pushf(lua_State *L, const char *fmt, ...)
35 | #if defined(__GNUC__)
36 | __attribute__ ((format (printf, 2, 3)))
37 | #endif
38 | ;
39 |
40 | /* Resizable string buffers. Struct definition in lj_obj.h. */
41 | LJ_FUNC char *lj_str_needbuf(lua_State *L, SBuf *sb, MSize sz);
42 |
43 | #define lj_str_initbuf(sb) ((sb)->buf = NULL, (sb)->sz = 0)
44 | #define lj_str_resetbuf(sb) ((sb)->n = 0)
45 | #define lj_str_resizebuf(L, sb, size) \
46 | ((sb)->buf = (char *)lj_mem_realloc(L, (sb)->buf, (sb)->sz, (size)), \
47 | (sb)->sz = (size))
48 | #define lj_str_freebuf(g, sb) lj_mem_free(g, (void *)(sb)->buf, (sb)->sz)
49 |
50 | #endif
51 |
--------------------------------------------------------------------------------
/luajit/jit/lj_str.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/helloh2o/room_game_server/aecbb085afbf2e797f46d10f1e52b51ea1f0147d/luajit/jit/lj_str.o
--------------------------------------------------------------------------------
/luajit/jit/lj_strscan.h:
--------------------------------------------------------------------------------
1 | /*
2 | ** String scanning.
3 | ** Copyright (C) 2005-2015 Mike Pall. See Copyright Notice in luajit.h
4 | */
5 |
6 | #ifndef _LJ_STRSCAN_H
7 | #define _LJ_STRSCAN_H
8 |
9 | #include "lj_obj.h"
10 |
11 | /* Options for accepted/returned formats. */
12 | #define STRSCAN_OPT_TOINT 0x01 /* Convert to int32_t, if possible. */
13 | #define STRSCAN_OPT_TONUM 0x02 /* Always convert to double. */
14 | #define STRSCAN_OPT_IMAG 0x04
15 | #define STRSCAN_OPT_LL 0x08
16 | #define STRSCAN_OPT_C 0x10
17 |
18 | /* Returned format. */
19 | typedef enum {
20 | STRSCAN_ERROR,
21 | STRSCAN_NUM, STRSCAN_IMAG,
22 | STRSCAN_INT, STRSCAN_U32, STRSCAN_I64, STRSCAN_U64,
23 | } StrScanFmt;
24 |
25 | LJ_FUNC StrScanFmt lj_strscan_scan(const uint8_t *p, TValue *o, uint32_t opt);
26 | LJ_FUNC int LJ_FASTCALL lj_strscan_num(GCstr *str, TValue *o);
27 | #if LJ_DUALNUM
28 | LJ_FUNC int LJ_FASTCALL lj_strscan_number(GCstr *str, TValue *o);
29 | #else
30 | #define lj_strscan_number(s, o) lj_strscan_num((s), (o))
31 | #endif
32 |
33 | /* Check for number or convert string to number/int in-place (!). */
34 | static LJ_AINLINE int lj_strscan_numberobj(TValue *o)
35 | {
36 | return tvisnumber(o) || (tvisstr(o) && lj_strscan_number(strV(o), o));
37 | }
38 |
39 | #endif
40 |
--------------------------------------------------------------------------------
/luajit/jit/lj_strscan.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/helloh2o/room_game_server/aecbb085afbf2e797f46d10f1e52b51ea1f0147d/luajit/jit/lj_strscan.o
--------------------------------------------------------------------------------
/luajit/jit/lj_tab.h:
--------------------------------------------------------------------------------
1 | /*
2 | ** Table handling.
3 | ** Copyright (C) 2005-2015 Mike Pall. See Copyright Notice in luajit.h
4 | */
5 |
6 | #ifndef _LJ_TAB_H
7 | #define _LJ_TAB_H
8 |
9 | #include "lj_obj.h"
10 |
11 | /* Hash constants. Tuned using a brute force search. */
12 | #define HASH_BIAS (-0x04c11db7)
13 | #define HASH_ROT1 14
14 | #define HASH_ROT2 5
15 | #define HASH_ROT3 13
16 |
17 | /* Scramble the bits of numbers and pointers. */
18 | static LJ_AINLINE uint32_t hashrot(uint32_t lo, uint32_t hi)
19 | {
20 | #if LJ_TARGET_X86ORX64
21 | /* Prefer variant that compiles well for a 2-operand CPU. */
22 | lo ^= hi; hi = lj_rol(hi, HASH_ROT1);
23 | lo -= hi; hi = lj_rol(hi, HASH_ROT2);
24 | hi ^= lo; hi -= lj_rol(lo, HASH_ROT3);
25 | #else
26 | lo ^= hi;
27 | lo = lo - lj_rol(hi, HASH_ROT1);
28 | hi = lo ^ lj_rol(hi, HASH_ROT1 + HASH_ROT2);
29 | hi = hi - lj_rol(lo, HASH_ROT3);
30 | #endif
31 | return hi;
32 | }
33 |
34 | #define hsize2hbits(s) ((s) ? ((s)==1 ? 1 : 1+lj_fls((uint32_t)((s)-1))) : 0)
35 |
36 | LJ_FUNCA GCtab *lj_tab_new(lua_State *L, uint32_t asize, uint32_t hbits);
37 | #if LJ_HASJIT
38 | LJ_FUNC GCtab * LJ_FASTCALL lj_tab_new1(lua_State *L, uint32_t ahsize);
39 | #endif
40 | LJ_FUNCA GCtab * LJ_FASTCALL lj_tab_dup(lua_State *L, const GCtab *kt);
41 | LJ_FUNC void LJ_FASTCALL lj_tab_free(global_State *g, GCtab *t);
42 | #if LJ_HASFFI
43 | LJ_FUNC void lj_tab_rehash(lua_State *L, GCtab *t);
44 | #endif
45 | LJ_FUNCA void lj_tab_reasize(lua_State *L, GCtab *t, uint32_t nasize);
46 |
47 | /* Caveat: all getters except lj_tab_get() can return NULL! */
48 |
49 | LJ_FUNCA cTValue * LJ_FASTCALL lj_tab_getinth(GCtab *t, int32_t key);
50 | LJ_FUNC cTValue *lj_tab_getstr(GCtab *t, GCstr *key);
51 | LJ_FUNCA cTValue *lj_tab_get(lua_State *L, GCtab *t, cTValue *key);
52 |
53 | /* Caveat: all setters require a write barrier for the stored value. */
54 |
55 | LJ_FUNCA TValue *lj_tab_newkey(lua_State *L, GCtab *t, cTValue *key);
56 | LJ_FUNC TValue *lj_tab_setinth(lua_State *L, GCtab *t, int32_t key);
57 | LJ_FUNC TValue *lj_tab_setstr(lua_State *L, GCtab *t, GCstr *key);
58 | LJ_FUNC TValue *lj_tab_set(lua_State *L, GCtab *t, cTValue *key);
59 |
60 | #define inarray(t, key) ((MSize)(key) < (MSize)(t)->asize)
61 | #define arrayslot(t, i) (&tvref((t)->array)[(i)])
62 | #define lj_tab_getint(t, key) \
63 | (inarray((t), (key)) ? arrayslot((t), (key)) : lj_tab_getinth((t), (key)))
64 | #define lj_tab_setint(L, t, key) \
65 | (inarray((t), (key)) ? arrayslot((t), (key)) : lj_tab_setinth(L, (t), (key)))
66 |
67 | LJ_FUNCA int lj_tab_next(lua_State *L, GCtab *t, TValue *key);
68 | LJ_FUNCA MSize LJ_FASTCALL lj_tab_len(GCtab *t);
69 |
70 | #endif
71 |
--------------------------------------------------------------------------------
/luajit/jit/lj_tab.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/helloh2o/room_game_server/aecbb085afbf2e797f46d10f1e52b51ea1f0147d/luajit/jit/lj_tab.o
--------------------------------------------------------------------------------
/luajit/jit/lj_trace.h:
--------------------------------------------------------------------------------
1 | /*
2 | ** Trace management.
3 | ** Copyright (C) 2005-2015 Mike Pall. See Copyright Notice in luajit.h
4 | */
5 |
6 | #ifndef _LJ_TRACE_H
7 | #define _LJ_TRACE_H
8 |
9 | #include "lj_obj.h"
10 |
11 | #if LJ_HASJIT
12 | #include "lj_jit.h"
13 | #include "lj_dispatch.h"
14 |
15 | /* Trace errors. */
16 | typedef enum {
17 | #define TREDEF(name, msg) LJ_TRERR_##name,
18 | #include "lj_traceerr.h"
19 | LJ_TRERR__MAX
20 | } TraceError;
21 |
22 | LJ_FUNC_NORET void lj_trace_err(jit_State *J, TraceError e);
23 | LJ_FUNC_NORET void lj_trace_err_info(jit_State *J, TraceError e);
24 |
25 | /* Trace management. */
26 | LJ_FUNC void LJ_FASTCALL lj_trace_free(global_State *g, GCtrace *T);
27 | LJ_FUNC void lj_trace_reenableproto(GCproto *pt);
28 | LJ_FUNC void lj_trace_flushproto(global_State *g, GCproto *pt);
29 | LJ_FUNC void lj_trace_flush(jit_State *J, TraceNo traceno);
30 | LJ_FUNC int lj_trace_flushall(lua_State *L);
31 | LJ_FUNC void lj_trace_initstate(global_State *g);
32 | LJ_FUNC void lj_trace_freestate(global_State *g);
33 |
34 | /* Event handling. */
35 | LJ_FUNC void lj_trace_ins(jit_State *J, const BCIns *pc);
36 | LJ_FUNCA void LJ_FASTCALL lj_trace_hot(jit_State *J, const BCIns *pc);
37 | LJ_FUNCA int LJ_FASTCALL lj_trace_exit(jit_State *J, void *exptr);
38 |
39 | /* Signal asynchronous abort of trace or end of trace. */
40 | #define lj_trace_abort(g) (G2J(g)->state &= ~LJ_TRACE_ACTIVE)
41 | #define lj_trace_end(J) (J->state = LJ_TRACE_END)
42 |
43 | #else
44 |
45 | #define lj_trace_flushall(L) (UNUSED(L), 0)
46 | #define lj_trace_initstate(g) UNUSED(g)
47 | #define lj_trace_freestate(g) UNUSED(g)
48 | #define lj_trace_abort(g) UNUSED(g)
49 | #define lj_trace_end(J) UNUSED(J)
50 |
51 | #endif
52 |
53 | #endif
54 |
--------------------------------------------------------------------------------
/luajit/jit/lj_trace.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/helloh2o/room_game_server/aecbb085afbf2e797f46d10f1e52b51ea1f0147d/luajit/jit/lj_trace.o
--------------------------------------------------------------------------------
/luajit/jit/lj_traceerr.h:
--------------------------------------------------------------------------------
1 | /*
2 | ** Trace compiler error messages.
3 | ** Copyright (C) 2005-2015 Mike Pall. See Copyright Notice in luajit.h
4 | */
5 |
6 | /* This file may be included multiple times with different TREDEF macros. */
7 |
8 | /* Recording. */
9 | TREDEF(RECERR, "error thrown or hook called during recording")
10 | TREDEF(TRACEOV, "trace too long")
11 | TREDEF(STACKOV, "trace too deep")
12 | TREDEF(SNAPOV, "too many snapshots")
13 | TREDEF(BLACKL, "blacklisted")
14 | TREDEF(NYIBC, "NYI: bytecode %d")
15 |
16 | /* Recording loop ops. */
17 | TREDEF(LLEAVE, "leaving loop in root trace")
18 | TREDEF(LINNER, "inner loop in root trace")
19 | TREDEF(LUNROLL, "loop unroll limit reached")
20 |
21 | /* Recording calls/returns. */
22 | TREDEF(BADTYPE, "bad argument type")
23 | TREDEF(CJITOFF, "JIT compilation disabled for function")
24 | TREDEF(CUNROLL, "call unroll limit reached")
25 | TREDEF(DOWNREC, "down-recursion, restarting")
26 | TREDEF(NYICF, "NYI: C function %p")
27 | TREDEF(NYIFF, "NYI: FastFunc %s")
28 | TREDEF(NYIFFU, "NYI: unsupported variant of FastFunc %s")
29 | TREDEF(NYIRETL, "NYI: return to lower frame")
30 |
31 | /* Recording indexed load/store. */
32 | TREDEF(STORENN, "store with nil or NaN key")
33 | TREDEF(NOMM, "missing metamethod")
34 | TREDEF(IDXLOOP, "looping index lookup")
35 | TREDEF(NYITMIX, "NYI: mixed sparse/dense table")
36 |
37 | /* Recording C data operations. */
38 | TREDEF(NOCACHE, "symbol not in cache")
39 | TREDEF(NYICONV, "NYI: unsupported C type conversion")
40 | TREDEF(NYICALL, "NYI: unsupported C function type")
41 |
42 | /* Optimizations. */
43 | TREDEF(GFAIL, "guard would always fail")
44 | TREDEF(PHIOV, "too many PHIs")
45 | TREDEF(TYPEINS, "persistent type instability")
46 |
47 | /* Assembler. */
48 | TREDEF(MCODEAL, "failed to allocate mcode memory")
49 | TREDEF(MCODEOV, "machine code too long")
50 | TREDEF(MCODELM, "hit mcode limit (retrying)")
51 | TREDEF(SPILLOV, "too many spill slots")
52 | TREDEF(BADRA, "inconsistent register allocation")
53 | TREDEF(NYIIR, "NYI: cannot assemble IR instruction %d")
54 | TREDEF(NYIPHI, "NYI: PHI shuffling too complex")
55 | TREDEF(NYICOAL, "NYI: register coalescing too complex")
56 |
57 | #undef TREDEF
58 |
59 | /* Detecting unused error messages:
60 | awk -F, '/^TREDEF/ { gsub(/TREDEF./, ""); printf "grep -q LJ_TRERR_%s *.[ch] || echo %s\n", $1, $1}' lj_traceerr.h | sh
61 | */
62 |
--------------------------------------------------------------------------------
/luajit/jit/lj_udata.c:
--------------------------------------------------------------------------------
1 | /*
2 | ** Userdata handling.
3 | ** Copyright (C) 2005-2015 Mike Pall. See Copyright Notice in luajit.h
4 | */
5 |
6 | #define lj_udata_c
7 | #define LUA_CORE
8 |
9 | #include "lj_obj.h"
10 | #include "lj_gc.h"
11 | #include "lj_udata.h"
12 |
13 | GCudata *lj_udata_new(lua_State *L, MSize sz, GCtab *env)
14 | {
15 | GCudata *ud = lj_mem_newt(L, sizeof(GCudata) + sz, GCudata);
16 | global_State *g = G(L);
17 | newwhite(g, ud); /* Not finalized. */
18 | ud->gct = ~LJ_TUDATA;
19 | ud->udtype = UDTYPE_USERDATA;
20 | ud->len = sz;
21 | /* NOBARRIER: The GCudata is new (marked white). */
22 | setgcrefnull(ud->metatable);
23 | setgcref(ud->env, obj2gco(env));
24 | /* Chain to userdata list (after main thread). */
25 | setgcrefr(ud->nextgc, mainthread(g)->nextgc);
26 | setgcref(mainthread(g)->nextgc, obj2gco(ud));
27 | return ud;
28 | }
29 |
30 | void LJ_FASTCALL lj_udata_free(global_State *g, GCudata *ud)
31 | {
32 | lj_mem_free(g, ud, sizeudata(ud));
33 | }
34 |
35 |
--------------------------------------------------------------------------------
/luajit/jit/lj_udata.h:
--------------------------------------------------------------------------------
1 | /*
2 | ** Userdata handling.
3 | ** Copyright (C) 2005-2015 Mike Pall. See Copyright Notice in luajit.h
4 | */
5 |
6 | #ifndef _LJ_UDATA_H
7 | #define _LJ_UDATA_H
8 |
9 | #include "lj_obj.h"
10 |
11 | LJ_FUNC GCudata *lj_udata_new(lua_State *L, MSize sz, GCtab *env);
12 | LJ_FUNC void LJ_FASTCALL lj_udata_free(global_State *g, GCudata *ud);
13 |
14 | #endif
15 |
--------------------------------------------------------------------------------
/luajit/jit/lj_udata.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/helloh2o/room_game_server/aecbb085afbf2e797f46d10f1e52b51ea1f0147d/luajit/jit/lj_udata.o
--------------------------------------------------------------------------------
/luajit/jit/lj_vm.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/helloh2o/room_game_server/aecbb085afbf2e797f46d10f1e52b51ea1f0147d/luajit/jit/lj_vm.o
--------------------------------------------------------------------------------
/luajit/jit/lj_vmevent.c:
--------------------------------------------------------------------------------
1 | /*
2 | ** VM event handling.
3 | ** Copyright (C) 2005-2015 Mike Pall. See Copyright Notice in luajit.h
4 | */
5 |
6 | #include
7 |
8 | #define lj_vmevent_c
9 | #define LUA_CORE
10 |
11 | #include "lj_obj.h"
12 | #include "lj_str.h"
13 | #include "lj_tab.h"
14 | #include "lj_state.h"
15 | #include "lj_dispatch.h"
16 | #include "lj_vm.h"
17 | #include "lj_vmevent.h"
18 |
19 | ptrdiff_t lj_vmevent_prepare(lua_State *L, VMEvent ev)
20 | {
21 | global_State *g = G(L);
22 | GCstr *s = lj_str_newlit(L, LJ_VMEVENTS_REGKEY);
23 | cTValue *tv = lj_tab_getstr(tabV(registry(L)), s);
24 | if (tvistab(tv)) {
25 | int hash = VMEVENT_HASH(ev);
26 | tv = lj_tab_getint(tabV(tv), hash);
27 | if (tv && tvisfunc(tv)) {
28 | lj_state_checkstack(L, LUA_MINSTACK);
29 | setfuncV(L, L->top++, funcV(tv));
30 | return savestack(L, L->top);
31 | }
32 | }
33 | g->vmevmask &= ~VMEVENT_MASK(ev); /* No handler: cache this fact. */
34 | return 0;
35 | }
36 |
37 | void lj_vmevent_call(lua_State *L, ptrdiff_t argbase)
38 | {
39 | global_State *g = G(L);
40 | uint8_t oldmask = g->vmevmask;
41 | uint8_t oldh = hook_save(g);
42 | int status;
43 | g->vmevmask = 0; /* Disable all events. */
44 | hook_vmevent(g);
45 | status = lj_vm_pcall(L, restorestack(L, argbase), 0+1, 0);
46 | if (LJ_UNLIKELY(status)) {
47 | /* Really shouldn't use stderr here, but where else to complain? */
48 | L->top--;
49 | fputs("VM handler failed: ", stderr);
50 | fputs(tvisstr(L->top) ? strVdata(L->top) : "?", stderr);
51 | fputc('\n', stderr);
52 | }
53 | hook_restore(g, oldh);
54 | if (g->vmevmask != VMEVENT_NOCACHE)
55 | g->vmevmask = oldmask; /* Restore event mask, but not if not modified. */
56 | }
57 |
58 |
--------------------------------------------------------------------------------
/luajit/jit/lj_vmevent.h:
--------------------------------------------------------------------------------
1 | /*
2 | ** VM event handling.
3 | ** Copyright (C) 2005-2015 Mike Pall. See Copyright Notice in luajit.h
4 | */
5 |
6 | #ifndef _LJ_VMEVENT_H
7 | #define _LJ_VMEVENT_H
8 |
9 | #include "lj_obj.h"
10 |
11 | /* Registry key for VM event handler table. */
12 | #define LJ_VMEVENTS_REGKEY "_VMEVENTS"
13 | #define LJ_VMEVENTS_HSIZE 4
14 |
15 | #define VMEVENT_MASK(ev) ((uint8_t)1 << ((int)(ev) & 7))
16 | #define VMEVENT_HASH(ev) ((int)(ev) & ~7)
17 | #define VMEVENT_HASHIDX(h) ((int)(h) << 3)
18 | #define VMEVENT_NOCACHE 255
19 |
20 | #define VMEVENT_DEF(name, hash) \
21 | LJ_VMEVENT_##name##_, \
22 | LJ_VMEVENT_##name = ((LJ_VMEVENT_##name##_) & 7)|((hash) << 3)
23 |
24 | /* VM event IDs. */
25 | typedef enum {
26 | VMEVENT_DEF(BC, 0x00003883),
27 | VMEVENT_DEF(TRACE, 0xb2d91467),
28 | VMEVENT_DEF(RECORD, 0x9284bf4f),
29 | VMEVENT_DEF(TEXIT, 0xb29df2b0),
30 | LJ_VMEVENT__MAX
31 | } VMEvent;
32 |
33 | #ifdef LUAJIT_DISABLE_VMEVENT
34 | #define lj_vmevent_send(L, ev, args) UNUSED(L)
35 | #define lj_vmevent_send_(L, ev, args, post) UNUSED(L)
36 | #else
37 | #define lj_vmevent_send(L, ev, args) \
38 | if (G(L)->vmevmask & VMEVENT_MASK(LJ_VMEVENT_##ev)) { \
39 | ptrdiff_t argbase = lj_vmevent_prepare(L, LJ_VMEVENT_##ev); \
40 | if (argbase) { \
41 | args \
42 | lj_vmevent_call(L, argbase); \
43 | } \
44 | }
45 | #define lj_vmevent_send_(L, ev, args, post) \
46 | if (G(L)->vmevmask & VMEVENT_MASK(LJ_VMEVENT_##ev)) { \
47 | ptrdiff_t argbase = lj_vmevent_prepare(L, LJ_VMEVENT_##ev); \
48 | if (argbase) { \
49 | args \
50 | lj_vmevent_call(L, argbase); \
51 | post \
52 | } \
53 | }
54 |
55 | LJ_FUNC ptrdiff_t lj_vmevent_prepare(lua_State *L, VMEvent ev);
56 | LJ_FUNC void lj_vmevent_call(lua_State *L, ptrdiff_t argbase);
57 | #endif
58 |
59 | #endif
60 |
--------------------------------------------------------------------------------
/luajit/jit/lj_vmevent.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/helloh2o/room_game_server/aecbb085afbf2e797f46d10f1e52b51ea1f0147d/luajit/jit/lj_vmevent.o
--------------------------------------------------------------------------------
/luajit/jit/lj_vmmath.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/helloh2o/room_game_server/aecbb085afbf2e797f46d10f1e52b51ea1f0147d/luajit/jit/lj_vmmath.o
--------------------------------------------------------------------------------
/luajit/jit/ljamalg.c:
--------------------------------------------------------------------------------
1 | /*
2 | ** LuaJIT core and libraries amalgamation.
3 | ** Copyright (C) 2005-2015 Mike Pall. See Copyright Notice in luajit.h
4 | */
5 |
6 | /*
7 | +--------------------------------------------------------------------------+
8 | | WARNING: Compiling the amalgamation needs a lot of virtual memory |
9 | | (around 300 MB with GCC 4.x)! If you don't have enough physical memory |
10 | | your machine will start swapping to disk and the compile will not finish |
11 | | within a reasonable amount of time. |
12 | | So either compile on a bigger machine or use the non-amalgamated build. |
13 | +--------------------------------------------------------------------------+
14 | */
15 |
16 | #define ljamalg_c
17 | #define LUA_CORE
18 |
19 | /* To get the mremap prototype. Must be defined before any system includes. */
20 | #if defined(__linux__) && !defined(_GNU_SOURCE)
21 | #define _GNU_SOURCE
22 | #endif
23 |
24 | #ifndef WINVER
25 | #define WINVER 0x0501
26 | #endif
27 |
28 | #include "lua.h"
29 | #include "lauxlib.h"
30 |
31 | #include "lj_gc.c"
32 | #include "lj_err.c"
33 | #include "lj_char.c"
34 | #include "lj_bc.c"
35 | #include "lj_obj.c"
36 | #include "lj_str.c"
37 | #include "lj_tab.c"
38 | #include "lj_func.c"
39 | #include "lj_udata.c"
40 | #include "lj_meta.c"
41 | #include "lj_debug.c"
42 | #include "lj_state.c"
43 | #include "lj_dispatch.c"
44 | #include "lj_vmevent.c"
45 | #include "lj_vmmath.c"
46 | #include "lj_strscan.c"
47 | #include "lj_api.c"
48 | #include "lj_lex.c"
49 | #include "lj_parse.c"
50 | #include "lj_bcread.c"
51 | #include "lj_bcwrite.c"
52 | #include "lj_load.c"
53 | #include "lj_ctype.c"
54 | #include "lj_cdata.c"
55 | #include "lj_cconv.c"
56 | #include "lj_ccall.c"
57 | #include "lj_ccallback.c"
58 | #include "lj_carith.c"
59 | #include "lj_clib.c"
60 | #include "lj_cparse.c"
61 | #include "lj_lib.c"
62 | #include "lj_ir.c"
63 | #include "lj_opt_mem.c"
64 | #include "lj_opt_fold.c"
65 | #include "lj_opt_narrow.c"
66 | #include "lj_opt_dce.c"
67 | #include "lj_opt_loop.c"
68 | #include "lj_opt_split.c"
69 | #include "lj_opt_sink.c"
70 | #include "lj_mcode.c"
71 | #include "lj_snap.c"
72 | #include "lj_record.c"
73 | #include "lj_crecord.c"
74 | #include "lj_ffrecord.c"
75 | #include "lj_asm.c"
76 | #include "lj_trace.c"
77 | #include "lj_gdbjit.c"
78 | #include "lj_alloc.c"
79 |
80 | #include "lib_aux.c"
81 | #include "lib_base.c"
82 | #include "lib_math.c"
83 | #include "lib_string.c"
84 | #include "lib_table.c"
85 | #include "lib_io.c"
86 | #include "lib_os.c"
87 | #include "lib_package.c"
88 | #include "lib_debug.c"
89 | #include "lib_bit.c"
90 | #include "lib_jit.c"
91 | #include "lib_ffi.c"
92 | #include "lib_init.c"
93 |
94 |
--------------------------------------------------------------------------------
/luajit/jit/lua.hpp:
--------------------------------------------------------------------------------
1 | // C++ wrapper for LuaJIT header files.
2 |
3 | extern "C" {
4 | #include "lua.h"
5 | #include "lauxlib.h"
6 | #include "lualib.h"
7 | #include "luajit.h"
8 | }
9 |
10 |
--------------------------------------------------------------------------------
/luajit/jit/luajit:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/helloh2o/room_game_server/aecbb085afbf2e797f46d10f1e52b51ea1f0147d/luajit/jit/luajit
--------------------------------------------------------------------------------
/luajit/jit/luajit.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/helloh2o/room_game_server/aecbb085afbf2e797f46d10f1e52b51ea1f0147d/luajit/jit/luajit.exe
--------------------------------------------------------------------------------
/luajit/jit/luajit.h:
--------------------------------------------------------------------------------
1 | /*
2 | ** LuaJIT -- a Just-In-Time Compiler for Lua. http://luajit.org/
3 | **
4 | ** Copyright (C) 2005-2015 Mike Pall. All rights reserved.
5 | **
6 | ** Permission is hereby granted, free of charge, to any person obtaining
7 | ** a copy of this software and associated documentation files (the
8 | ** "Software"), to deal in the Software without restriction, including
9 | ** without limitation the rights to use, copy, modify, merge, publish,
10 | ** distribute, sublicense, and/or sell copies of the Software, and to
11 | ** permit persons to whom the Software is furnished to do so, subject to
12 | ** the following conditions:
13 | **
14 | ** The above copyright notice and this permission notice shall be
15 | ** included in all copies or substantial portions of the Software.
16 | **
17 | ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 | ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 | ** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20 | ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
21 | ** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22 | ** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23 | ** SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 | **
25 | ** [ MIT license: http://www.opensource.org/licenses/mit-license.php ]
26 | */
27 |
28 | #ifndef _LUAJIT_H
29 | #define _LUAJIT_H
30 |
31 | #include "lua.h"
32 |
33 | #define LUAJIT_VERSION "LuaJIT 2.0.4"
34 | #define LUAJIT_VERSION_NUM 20004 /* Version 2.0.4 = 02.00.04. */
35 | #define LUAJIT_VERSION_SYM luaJIT_version_2_0_4
36 | #define LUAJIT_COPYRIGHT "Copyright (C) 2005-2015 Mike Pall"
37 | #define LUAJIT_URL "http://luajit.org/"
38 |
39 | /* Modes for luaJIT_setmode. */
40 | #define LUAJIT_MODE_MASK 0x00ff
41 |
42 | enum {
43 | LUAJIT_MODE_ENGINE, /* Set mode for whole JIT engine. */
44 | LUAJIT_MODE_DEBUG, /* Set debug mode (idx = level). */
45 |
46 | LUAJIT_MODE_FUNC, /* Change mode for a function. */
47 | LUAJIT_MODE_ALLFUNC, /* Recurse into subroutine protos. */
48 | LUAJIT_MODE_ALLSUBFUNC, /* Change only the subroutines. */
49 |
50 | LUAJIT_MODE_TRACE, /* Flush a compiled trace. */
51 |
52 | LUAJIT_MODE_WRAPCFUNC = 0x10, /* Set wrapper mode for C function calls. */
53 |
54 | LUAJIT_MODE_MAX
55 | };
56 |
57 | /* Flags or'ed in to the mode. */
58 | #define LUAJIT_MODE_OFF 0x0000 /* Turn feature off. */
59 | #define LUAJIT_MODE_ON 0x0100 /* Turn feature on. */
60 | #define LUAJIT_MODE_FLUSH 0x0200 /* Flush JIT-compiled code. */
61 |
62 | /* LuaJIT public C API. */
63 |
64 | /* Control the JIT engine. */
65 | LUA_API int luaJIT_setmode(lua_State *L, int idx, int mode);
66 |
67 | /* Enforce (dynamic) linker error for version mismatches. Call from main. */
68 | LUA_API void LUAJIT_VERSION_SYM(void);
69 |
70 | #endif
71 |
--------------------------------------------------------------------------------
/luajit/jit/luajit.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/helloh2o/room_game_server/aecbb085afbf2e797f46d10f1e52b51ea1f0147d/luajit/jit/luajit.o
--------------------------------------------------------------------------------
/luajit/jit/lualib.h:
--------------------------------------------------------------------------------
1 | /*
2 | ** Standard library header.
3 | ** Copyright (C) 2005-2015 Mike Pall. See Copyright Notice in luajit.h
4 | */
5 |
6 | #ifndef _LUALIB_H
7 | #define _LUALIB_H
8 |
9 | #include "lua.h"
10 |
11 | #define LUA_FILEHANDLE "FILE*"
12 |
13 | #define LUA_COLIBNAME "coroutine"
14 | #define LUA_MATHLIBNAME "math"
15 | #define LUA_STRLIBNAME "string"
16 | #define LUA_TABLIBNAME "table"
17 | #define LUA_IOLIBNAME "io"
18 | #define LUA_OSLIBNAME "os"
19 | #define LUA_LOADLIBNAME "package"
20 | #define LUA_DBLIBNAME "debug"
21 | #define LUA_BITLIBNAME "bit"
22 | #define LUA_JITLIBNAME "jit"
23 | #define LUA_FFILIBNAME "ffi"
24 |
25 | LUALIB_API int luaopen_base(lua_State *L);
26 | LUALIB_API int luaopen_math(lua_State *L);
27 | LUALIB_API int luaopen_string(lua_State *L);
28 | LUALIB_API int luaopen_table(lua_State *L);
29 | LUALIB_API int luaopen_io(lua_State *L);
30 | LUALIB_API int luaopen_os(lua_State *L);
31 | LUALIB_API int luaopen_package(lua_State *L);
32 | LUALIB_API int luaopen_debug(lua_State *L);
33 | LUALIB_API int luaopen_bit(lua_State *L);
34 | LUALIB_API int luaopen_jit(lua_State *L);
35 | LUALIB_API int luaopen_ffi(lua_State *L);
36 |
37 | LUALIB_API void luaL_openlibs(lua_State *L);
38 |
39 | #ifndef lua_assert
40 | #define lua_assert(x) ((void)0)
41 | #endif
42 |
43 | #endif
44 |
--------------------------------------------------------------------------------
/luajit/state.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 | #include
6 | #include "_cgo_export.h"
7 |
8 | enum {
9 | Bufsz= 256
10 | };
11 |
12 | typedef struct Readbuf Readbuf;
13 | struct Readbuf {
14 | void* reader;
15 | char* buf;
16 | size_t bufsz;
17 | };
18 |
19 | /* a lua_Reader */
20 | static const char*
21 | readchunk(lua_State *l, void *data, size_t *size)
22 | {
23 | Readbuf *rb;
24 | size_t sz;
25 |
26 | rb = data;
27 | memset(rb->buf, 0, rb->bufsz);
28 | sz = goreadchunk(rb->reader, rb->buf, rb->bufsz);
29 | if(sz < 1){
30 | free(rb->buf);
31 | free(rb);
32 | return NULL;
33 | }
34 | *size = sz;
35 | return rb->buf;
36 | }
37 |
38 | /* a lua_Writer */
39 | static int
40 | writechunk(lua_State *l, const void *p, size_t sz, void *ud)
41 | {
42 | if(gowritechunk(ud, (void*)p, sz) != sz)
43 | return 1;
44 | return 0;
45 | }
46 |
47 | lua_State*
48 | newstate(void)
49 | {
50 | return luaL_newstate();
51 | }
52 |
53 | int
54 | load(lua_State *l, void *reader, const char *chunkname)
55 | {
56 | char *buf;
57 | Readbuf *rb;
58 |
59 | buf = malloc(Bufsz); /* both allocs are freed by readchunk */
60 | if(buf == NULL)
61 | return LUA_ERRMEM;
62 | rb = malloc(sizeof *rb);
63 | if(rb == NULL){
64 | free(buf);
65 | return LUA_ERRMEM;
66 | }
67 | rb->reader = reader;
68 | rb->buf = buf;
69 | rb->bufsz = Bufsz;
70 | return lua_load(l, readchunk, rb, chunkname);
71 | }
72 |
73 | int
74 | dump(lua_State *l, void *ud)
75 | {
76 | return lua_dump(l, writechunk, ud);
77 | }
78 |
79 | /* a lua_CFunction */
80 | static int
81 | bounce(lua_State* s)
82 | {
83 | const char *fn;
84 |
85 | fn = lua_tostring(s, lua_upvalueindex(1));
86 | return docallback((char*)fn, s);
87 | }
88 |
89 | void
90 | pushclosure(lua_State *s, int n)
91 | {
92 | lua_pushcclosure(s, bounce, n + 1);
93 | }
94 |
--------------------------------------------------------------------------------
/main.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "fmt"
5 | "io/ioutil"
6 | LG "log"
7 | "net/http"
8 | _ "net/http/pprof"
9 | "os"
10 | "runtime"
11 | "server/conf"
12 | "server/db"
13 | "server/encrypt"
14 | "server/game"
15 | "server/gate"
16 | "server/hall"
17 | "server/httpsv"
18 | "server/leaf"
19 | lconf "server/leaf/conf"
20 | "server/leaf/log"
21 | )
22 |
23 | func main() {
24 | lconf.LogLevel = conf.Server.LogLevel
25 | lconf.LogPath = conf.Server.LogPath
26 | lconf.LogFlag = conf.LogFlag
27 | lconf.ConsolePort = conf.Server.ConsolePort
28 | lconf.ProfilePath = conf.Server.ProfilePath
29 | // 初始化数据库
30 | db.PGRun()
31 | // 初始化游戏,虚拟机,房间
32 | game.Init()
33 | // 初始化加密暗哨
34 | encrypt.InitCipher(conf.Server.EncryptStr)
35 | // pprof
36 | go func() {
37 | runtime.GOMAXPROCS(2) // 限制 CPU 使用数,避免过载
38 | runtime.SetMutexProfileFraction(1) // 开启对锁调用的跟踪
39 | runtime.SetBlockProfileRate(1) // 开启对阻塞操作的跟踪
40 | http.ListenAndServe("0.0.0.0:6060", nil)
41 | }()
42 | // http server
43 | go httpsv.RunHTTP(conf.Server.HTTPAddr)
44 | log.Release("Websocket on => %s", conf.Server.WSAddr)
45 | log.Release("TCP on => %s", conf.Server.TCPAddr)
46 | pid := os.Getpid()
47 | log.Release("Process ID %d", pid)
48 | err := ioutil.WriteFile("shutdown.sh", []byte(fmt.Sprintf("kill %d", pid)), os.ModePerm)
49 | if err != nil {
50 | log.Error("create shutdown.sh failed.")
51 | }
52 | leaf.Run(
53 | new(hall.Module),
54 | game.Module,
55 | gate.Module,
56 | )
57 | // 写库
58 | db.OnFinalSave <- struct{}{}
59 | <-db.Done
60 | LG.Println("Server is shutdown.")
61 | }
62 |
--------------------------------------------------------------------------------
/msg/const.go:
--------------------------------------------------------------------------------
1 | package msg
2 |
3 | const (
4 | // 房间消息
5 | G_enter_room = uint32(0x101)
6 | G_full_room = uint32(0x102)
7 | G_leave_room = uint32(0x103)
8 | G_kickout_room = uint32(0x104)
9 | Glayer_offline = uint32(0x105)
10 | )
11 |
--------------------------------------------------------------------------------
/msg/msg.go:
--------------------------------------------------------------------------------
1 | package msg
2 |
3 | import (
4 | "server/leaf/network/protobuf"
5 | pp "server/protobuf"
6 | )
7 |
8 | var Processor = protobuf.NewProcessor()
9 |
10 | func init() {
11 | Processor.Register(&pp.Protocol{}) //0
12 | Processor.Register(&pp.CsLogin{}) //1
13 | Processor.Register(&pp.CsRegister{}) //2
14 | Processor.Register(&pp.ScLoginSuccess{}) //3
15 | Processor.Register(&pp.ScRegisterSuccess{}) //4
16 | Processor.Register(&pp.ScError{}) //5
17 | Processor.Register(&pp.CsEnterRoom{}) //6
18 | Processor.Register(&pp.Heartbeat{}) //7
19 | Processor.Register(&pp.ScPropList{}) //8
20 | Processor.Register(&pp.ScServers{}) //9
21 | Processor.Register(&pp.CsCreateUnion{}) //10
22 | Processor.Register(&pp.ScCreateUnion{}) //11
23 | Processor.Register(&pp.CsJoinUnion{}) //12
24 | Processor.Register(&pp.ScJoinUnion{}) //13
25 | Processor.Register(&pp.CsQueryUnion{}) //14
26 | Processor.Register(&pp.ScQueryUnion{}) //15
27 | Processor.Register(&pp.ScMails{}) //16
28 | Processor.Register(&pp.CsMailReq{}) //17
29 | Processor.Register(&pp.CsReadMail{}) //18
30 | Processor.Register(&pp.CsUnionInfo{}) //19
31 | Processor.Register(&pp.ScUnionInfo{}) //20
32 | Processor.Register(&pp.CsExitUnion{}) //21
33 | Processor.Register(&pp.ScExitUnion{}) //22
34 | Processor.Register(&pp.CsUnionSettings{}) //23
35 | Processor.Register(&pp.CsTransferMaster{}) //24
36 | Processor.Register(&pp.ScTransferMaster{}) //25
37 | Processor.Register(&pp.CsTickMember{}) //26
38 | Processor.Register(&pp.ScTickMember{}) //27
39 | Processor.Register(&pp.CsLocation{}) //28
40 | Processor.Register(&pp.ScLocation{}) //29
41 | Processor.Register(&pp.CsUnionRank{}) //30
42 | Processor.Register(&pp.ScUnionRank{}) //31
43 |
44 | }
45 |
46 | const (
47 | Protocol = iota
48 | CsLogin
49 | CsRegister
50 | ScLoginSuccess
51 | ScRegisterSuccess
52 | ScError
53 | CsEnterRoom
54 | Heartbeat
55 | ScPropList
56 | ScServers
57 | CsCreateUnion
58 | ScCreateUnion
59 | CsJoinUnion
60 | ScJoinUnion
61 | CsQueryUnion
62 | ScQueryUnion
63 | ScMails
64 | CsMailReq
65 | CsReadMail
66 | CsUnionInfo
67 | ScUnionInfo
68 | CsExitUnion
69 | ScExitUnion
70 | CsUnionSettings
71 | CsTransferMaster
72 | ScTransferMaster
73 | CsTickMember
74 | ScTickMember
75 | CsLocation
76 | ScLocation
77 | CsUnionRank
78 | ScUnionRank
79 | )
80 |
--------------------------------------------------------------------------------
/props/base.go:
--------------------------------------------------------------------------------
1 | package props
2 |
3 | const (
4 | Unknown = iota
5 | ID_Record
6 | ID_Supper
7 | )
8 |
9 | type Prop struct {
10 | Id int64 `json:"id"` // DB PK
11 | PID int `json:"pid" orm:"unique;index"` // 道具ID
12 | Player string `json:"player"` // 用户UUID
13 | Size int `json:"size"` // 数量
14 | LimitTime int64 `json:"limit_time"` // 期限
15 | Price int32 `json:"price"` // 售价
16 | }
17 |
--------------------------------------------------------------------------------
/props/create.go:
--------------------------------------------------------------------------------
1 | package props
2 |
3 | import "time"
4 |
5 | func NewProp(Pid int, player string, size int, day int64) *Prop {
6 | prop := new(Prop)
7 | prop.PID = Pid
8 | prop.Player = player
9 | prop.Size = size
10 | if day > 0 {
11 | prop.LimitTime = time.Now().Unix() + (day * 24 * 60 * 60)
12 |
13 | }
14 | return prop
15 | }
16 |
--------------------------------------------------------------------------------
/protobuf/baseid.lua:
--------------------------------------------------------------------------------
1 | ---
2 | --- Created by Ayoo.
3 | --- DateTime: 2020/4/27 11:18
4 | ---
5 |
6 | local baseid = {
7 | ---------------------------- LEAF Protocol------------------------
8 | Protocol = 0, -- 游戏通用消息
9 | CsLogin = 1, -- 登录
10 | CsRegister = 2, -- 注册
11 | ScLoginSuccess = 3, -- 登录成功
12 | ScRegisterSuccess = 4, -- 注册成功
13 | ScError = 5, -- 错误消息
14 | CsEnterRoom = 6, -- 进入游戏
15 | Heartbeat = 7, -- 心跳
16 | PropList = 8, -- 道具列表
17 | ScServers = 9, -- 服务器信息
18 | CsCreateUnion = 10, -- 创建公会
19 | ScCreateUnion = 11, -- 创建公会结果
20 | CsJoinUnion = 12, -- 加入公会
21 | ScJoinUnion = 13, -- 加入公会结果
22 | CsQueryUnion = 14, -- 查找公会
23 | ScQueryUnion = 15, -- 查询结果
24 | ScMails = 16, -- 邮件列表
25 | CsMailReq = 17, -- 主动拉去未读邮件
26 | CsReadMail = 18, -- 读取邮件
27 | CsUnionInfo = 19, -- 查询公会信息
28 | ScUnionInfo = 20, -- 公会信息
29 | CsExitUnion = 21, -- 退出公会
30 | ScExitUnion = 22, -- 退出公会返回
31 | CsUnionSettings = 23, --公会设置
32 | CsTransferMaster = 24, -- 公会转让
33 | ScTransferMaster = 25,
34 | CsTickMember = 26, -- 踢出公会
35 | ScTickMember = 27,
36 | CsLocation = 28, -- 更新位置
37 | ScLocation = 29,
38 | }
39 |
40 | return baseid
--------------------------------------------------------------------------------
/protobuf/build.bat:
--------------------------------------------------------------------------------
1 | protoc --go_out=. go_side.proto
--------------------------------------------------------------------------------
/protobuf/example/proto.go:
--------------------------------------------------------------------------------
1 | package example
2 |
3 | import (
4 | "log"
5 | // 辅助库
6 | "github.com/golang/protobuf/proto"
7 | )
8 |
9 | func main() {
10 | // 创建一个消息 Test
11 | test := &Test{
12 | // 使用辅助函数设置域的值
13 | Label: proto.String("hello"),
14 | Type: proto.Int32(17),
15 | Optionalgroup: &Test_OptionalGroup{
16 | RequiredField: proto.String("good bye"),
17 | },
18 | }
19 |
20 | // 进行编码
21 | data, err := proto.Marshal(test)
22 | if err != nil {
23 | log.Fatal("marshaling error: ", err)
24 | }
25 |
26 | // 进行解码
27 | newTest := &Test{}
28 | err = proto.Unmarshal(data, newTest)
29 | if err != nil {
30 | log.Fatal("unmarshaling error: ", err)
31 | }
32 |
33 | // 测试结果
34 | if test.GetLabel() != newTest.GetLabel() {
35 | log.Fatalf("data mismatch %q != %q", test.GetLabel(), newTest.GetLabel())
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/protobuf/example/test.proto:
--------------------------------------------------------------------------------
1 | syntax = "proto2";
2 | option go_package = ".;example";
3 |
4 | enum FOO { X = 17; };
5 |
6 | message Test {
7 | required string label = 1;
8 | optional int32 type = 2 [default=77];
9 | repeated int64 reps = 3;
10 | optional group OptionalGroup = 4 {
11 | required string RequiredField = 5;
12 | }
13 | }
--------------------------------------------------------------------------------
/rpc/ai_call.go:
--------------------------------------------------------------------------------
1 | package rpc
2 |
3 | import (
4 | "context"
5 | "github.com/smallnest/rpcx/client"
6 | "server/leaf/log"
7 | )
8 |
9 | func AddAI(aiserver string, args *AiJoinArs) {
10 | d := client.NewPeer2PeerDiscovery("tcp@"+aiserver, "")
11 | xclient := client.NewXClient("AI", client.Failtry, client.RandomSelect, d, client.DefaultOption)
12 | defer xclient.Close()
13 | reply := &AiReply{}
14 | err := xclient.Call(context.Background(), "Join", args, reply)
15 | if err != nil {
16 | log.Release("failed to call: %v", err)
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/rpc/ai_mod.go:
--------------------------------------------------------------------------------
1 | package rpc
2 |
3 | type AiJoinArs struct {
4 | Server string // 连接的游戏服务器
5 | GameName string // 游戏名字 //classic_ddz
6 | GamePlace string // 游戏场次
7 | }
8 |
9 | type AiReply struct {
10 | OK bool
11 | Reason string
12 | }
13 |
--------------------------------------------------------------------------------
/run_dev.sh:
--------------------------------------------------------------------------------
1 | nohup go run main.go &
2 | #nohup ./debug_main &
3 |
--------------------------------------------------------------------------------
/server.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/shutdown.sh:
--------------------------------------------------------------------------------
1 | kill 7928
--------------------------------------------------------------------------------
/test.lua:
--------------------------------------------------------------------------------
1 | DEBUG = false
2 | print(DEBUG)
3 |
--------------------------------------------------------------------------------
/vm/dat.go:
--------------------------------------------------------------------------------
1 | package vm
2 |
3 | type CallData struct {
4 | Function string
5 | Args []interface{}
6 | Result chan CallResult
7 | Nresult int
8 | }
9 |
10 | func NewCallData(function string, Args []interface{}, nresult int) CallData {
11 | return CallData{Function: function, Result: make(chan CallResult, 1), Args: Args, Nresult: nresult}
12 | }
13 |
14 | type CallResult struct {
15 | Ok bool
16 | Reason string
17 | Data []interface{}
18 | }
19 |
--------------------------------------------------------------------------------
/vm/vm_test.go:
--------------------------------------------------------------------------------
1 | package vm
2 |
3 | import (
4 | "github.com/golang/protobuf/proto"
5 | "log"
6 | "server/protobuf"
7 | "sync"
8 | "testing"
9 | "time"
10 | )
11 |
12 | func TestNewVM(t *testing.T) {
13 | // 模拟客户端N
14 | clients := 5000
15 | // 单个客户端Call VM 次数
16 | clientCallTimes := 30
17 | // VM 数量
18 | vmsize := 1
19 | vms := make([]*VM, 0)
20 | for i := 0; i < vmsize; i++ {
21 | vm := NewVM("ddz", "D:/gohub/src/server/lua/game/test_game/root.lua")
22 | if vm != nil {
23 | vms = append(vms, vm)
24 | }
25 | }
26 | max := clients
27 | var wg sync.WaitGroup
28 | wg.Add(clients)
29 | start := time.Now().Unix()
30 | // 外部调用, 是否同步
31 | for i := 0; i < clients; i++ {
32 | // 多个goroutine 调用
33 | go func(index int) {
34 | defer func() {
35 | wg.Done()
36 | }()
37 | p := &protobuf.Protocol{Id: 1001}
38 | data, _ := proto.Marshal(p)
39 | calltimes := 0
40 | for calltimes < clientCallTimes {
41 | calldata := NewCallData("onmessage", []interface{}{string(data), "xx"}, 1)
42 | vindex := index % len(vms)
43 | log.Printf("vm index %d", vindex)
44 | vm := vms[vindex]
45 | vm.CallChan <- calldata
46 | // 等待同步结果
47 | result := <-calldata.Result
48 | log.Printf("Caller %d Result %v Times %d", index, result, calltimes)
49 | calltimes++
50 | }
51 | }(i)
52 | }
53 | wg.Wait()
54 | end := time.Now().Unix()
55 | log.Printf("%d clients %d call times, costs %d s", max, max*clientCallTimes, end-start)
56 | }
57 |
--------------------------------------------------------------------------------