• This repository has been archived on 08/Nov/2019
  • Stars
    star
    219
  • Rank 175,286 (Top 4 %)
  • Language
    Lua
  • Created almost 8 years ago
  • Updated over 7 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A sample for skynet

这是一个使用 skynet 搭建服务器的简单例子。它很简陋,主要想演示一下 https://github.com/cloudwu/skynet_package 以及 sproto 协议封装的用法。

这个例子可以作为构建游戏服务器的参考,但它并不作为 skynet 推荐的服务器框架使用模式。它还很不完整,可能存在许多疏忽的地方,以及需要针对实际需求做进一步优化。

如何编译

  1. clone 下本仓库。
  2. 更新 submodule ,服务器部分需要用到 skynet ;客户端部分需要用到 lsocket 。
git submodule update --init
  1. 编译 skynet
cd skynet
make linux
  1. 编译 lsocket(如果你需要客户端)
make socket
  1. 编译 skynet package 模块
make

如何运行服务器

以前台模式启动

./run.sh

用 Ctrl-C 可以退出

以后台模式启动

./run.sh -D

用下列指令可以杀掉后台进程

./run.sh -k

后台模式下,log 记录在 run/skynet.log 中。

如何运行客户端

客户端启动脚本为 client/simpleclient.lua ,它依赖 sproto 和 lsocket 两个模块。

ps. sproto 和 lsocket 均可在 mingw 下编译。

客户端需要 Lua 5.3 以上,在 skynet/3rd/lua 下有 lua 5.3.3 解析器。

客户端脚本启动需要传入两个参数,第一个参数是根目录的位置,以方便找到依赖的模块和协议文件 proto/proto.sproto ;第二个参数是服务器地址,默认为 127.0.0.1 。

./client.sh 这个脚本可以简化客户端启动流程。

服务器工作流程

  1. hub 服务监听 5678 端口,当有新连接接入时,启动一个 skynet_package 服务,管理这个链接。

  2. hub 服务把这个新连接交给 auth 服务管理。

  3. auth 服务接受客户端的 signup 和 signin 请求。signup 可以注册一个用户名;signin 可以以一个已注册用户名登录。这里只做简单演示,并没有认证用户的身份。

  4. 当 signin 成功后,hub 服务把链接转交给 manager 服务。

  5. manager 服务将查找是否有 agent 服务对应这个用户;如果没有,则启动一个新的 agent 并记录 agent 服务和用户名之间的关系。

  6. manager 服务通知 agent 接管这个连接,并将此连接关联到特定用户名下。

  7. agent 服务会接收客户端的 login 请求。如果用户已在线(有其它连接已关联)通知客户端 login 失败;否则成功,且可以接收 ping 等其它请求。

  8. 当连接主动断开时,agent 将等待 10 秒,如果这段时间没有重建连接,将在 manager 中注销并自行销毁。

客户端工作流程

客户端以请求回应模式和服务器交流,不能接收服务器的任何主动推送。

  1. 客户端启动时,将尝试连接服务器,并提出 signin 请求。

  2. 如果 signin 失败,将尝试 signup 注册一个用户,如果再失败则退出。成功则重新 singin 。

  3. 如果 signin 成功,将向服务器请求 login ;在 login 之前,会向服务器发起 ping 请求,但一定会失败。

  4. login 成功后,向服务器发起 ping 。

More Repositories

1

skynet

A lightweight online game framework
C
12,707
star
2

coroutine

A asymmetric coroutine library for C.
C
2,381
star
3

pbc

A protocol buffers library for C
C
1,607
star
4

mptun

Multi-path Tunnel
C
1,243
star
5

lua53doc

The Chinese Translation of Lua 5.3 document
HTML
916
star
6

sproto

Yet another protocol library like google protocol buffers , but simple and fast.
C
912
star
7

lua-snapshot

Make a snapshot for lua state to detect memory leaks.
C
497
star
8

rudp

Reliable UDP
C
395
star
9

stellaris_cn

Stellaris 群星 汉化 Mod
Lua
386
star
10

cstring

A simple C string lib
C
351
star
11

buddy

Buddy memory allocation
C
316
star
12

aoi

Area of Interest Library
C
293
star
13

luaecs

C
283
star
14

ltask

C
257
star
15

neuralnet

Toy neural network
C
223
star
16

lua-bgfx

Yet another bgfx lua binding
Lua
215
star
17

socket-server

C
209
star
18

hive

Parallel lua states
C
202
star
19

mread

Multi-Read from one bind port
C
195
star
20

windsoul

An open source 3d engine
C
160
star
21

luareload

reload a lua module
Lua
147
star
22

lua-serialize

Serialize lua objects into a binary block
C
140
star
23

lua-trace

Trace for debug lua
Lua
135
star
24

stable-connection

C
122
star
25

luadebug

A lua debugger in independent lua VM
C
118
star
26

tpp_feedback

《程序员修炼之道》第二版中译反馈
112
star
27

lua-int64

A int64 lib for lua with lightuserdata in 64bit architecture
C
109
star
28

sharplua

Embed lua 5.3 into mono
C
108
star
29

math3d

A lua math lib for linear algebra (matrix and vector)
C
102
star
30

lua-bson

A BSON library for lua
C
102
star
31

ldebug

A Lua Remote Debugger
Lua
94
star
32

battlearena

A experimental project for moba like game server
Lua
87
star
33

luaprofiler

simple lua profiler
C
86
star
34

xlsx2txt

Convert xlsx file to txt for grep text
C
81
star
35

datalist

A simple list data sheet
C
79
star
36

lua-mongo

A simple lua mongo driver
C
76
star
37

remotepvrtool

C
71
star
38

ameba

multithread for lua 5.2
67
star
39

bpa

A bump pointer allocator
C
66
star
40

lua-db

A database shared data among multi-states .
C
62
star
41

lsocket

lsocket from http://tset.de/lsocket/
C
59
star
42

skynet_package

C
58
star
43

luabind

simple and robust lua binding lib
C
56
star
44

lua-stable

Share table among lua states
C
55
star
45

ejoy3d

Just a toy
C
55
star
46

efkbgfx

A bgfx renderer for effekseer runtime
Scala
50
star
47

luawinfile

Replacement lfs and lua original api to support utf-8 filename
C
50
star
48

luacc

LUACC allows you write C code in lua
Lua
47
star
49

lua-conf

Convert a lua table to a C object , and share it among many lua states .
C
46
star
50

xenonauts

xenonauts chinese translation
Lua
45
star
51

rogue

A simple rogue lib for lua
C
44
star
52

dfont

Manage texture for Chinese character rendering.
C
44
star
53

lua-array

lua sparse array
C
43
star
54

handlemap

Map object pointer to an unique id
C
42
star
55

atomdict

A data structure for data exchange between multi lua states.
C
38
star
56

skynet-reload

Reload skynet lua service
C
37
star
57

simplethread

A simple thread library base on pthread and win thread
C
36
star
58

iupmingw

IUP all in one
Lua
36
star
59

vla

Variable length array
C
35
star
60

skynet_group

示范如何让多组游戏服务器运行在同一个 skynet 进程内
Lua
35
star
61

backtrace-mingw

Automatically exported from code.google.com/p/backtrace-mingw
C
33
star
62

syncmodel

一个根据时间戳同步的模型
Lua
31
star
63

tracedoc

Lua
30
star
64

roguestale_cn

A Chinese translation mod of Rogue's Tale
C
30
star
65

bgfxidl

An IDL for bgfx
Lua
28
star
66

attrib

Expression calculate machine
C
28
star
67

luaxlsx

C
27
star
68

pathfinding

A simple A star path-finding module for Lua
C
26
star
69

lalloc

A allocator for lua
C
26
star
70

eaccodec

A simple Ericsson Texture EAC codec
C
25
star
71

lua-crypt

simple crypt lib
C
24
star
72

aura

C
24
star
73

skynet2

单独放一些临时代码, 之后会合并到 skynet 的 2.0 分支中
C
23
star
74

lthread

lua thread (step execute a lua function)
C
21
star
75

skynet_transaction

A example of transaction
Lua
20
star
76

caccessor

Let lua access C types
C
20
star
77

lmonitor

monitor lua calls
C
19
star
78

font16xaa

16xAA font rendering using coverage masks
C
19
star
79

stringid

C
18
star
80

luatypesystem

A simple type system for lua
Lua
17
star
81

manualgc

Automatically exported from code.google.com/p/manualgc
C
17
star
82

ctable

Dump a lua table into a block of memory, and use it as a lua table later.
Lua
17
star
83

syncobj

Lua
15
star
84

tablepointer

Convert lua table to pointer, and iterate it.
C
15
star
85

lua_typecheck

Lua
14
star
86

datatree

C
13
star
87

netout

Redirect stdout to a tcp socket
C
13
star
88

textcell

ImGui style table cell, but for text mode
C
13
star
89

skynet-demo

A demo for skynet (WIP)
Lua
12
star
90

bgfxlshaderc

A lua version of bgfx shaderc
Lua
12
star
91

pdxparser

Paradox Game data file parser
Lua
10
star
92

etccompose

compose ETC2_EAC without encode
C
10
star
93

kdtree

C
9
star
94

freeabc

给自己用的 ABC 输入法
Lua
9
star
95

stylecache

C
9
star
96

luaproto

dump lua prototype constants
C
7
star
97

routemap

C
6
star
98

treeclone

Clone a tree by blueprint
C
5
star
99

extable

Put data into external lua state
C
5
star
100

oni_cn

Oxygen Not Included Chinese Translation mod
4
star