From a2996042bdb9494e4f028f79e450b7745cc5d642 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E9=9C=B2=28=E5=A4=A7=E6=9F=8F=29?= Date: Thu, 11 Mar 2021 14:17:30 +0800 Subject: [PATCH] =?UTF-8?q?[fix]=20=E4=BF=AE=E6=94=B9=E4=B8=80=E4=BA=9B?= =?UTF-8?q?=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 4 +- example/api/html.go | 4 +- example/api/web.go | 30 +- example/main.go | 33 +- go.mod | 3 +- go.sum | 60 ++ pb/build_proto.sh | 36 +- pb/message.pb.go | 1223 ++++++++++++++++++++++++++---------- pb/message.proto | 1 + room/manager.go | 62 +- {room => router}/router.go | 31 +- 11 files changed, 1064 insertions(+), 423 deletions(-) rename {room => router}/router.go (82%) diff --git a/README.md b/README.md index a7752c3..cde08ee 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ _**用golang写的帧同步服务器**_ --- -`帧同步服务器目标是作为一个可以在运行时扩展,完全脱离玩法逻辑的帧同步服务器。` +`帧同步服务器目标是作为一个可以横向扩展,完全脱离玩法逻辑的帧同步服务器。` * 采用KCP(可根据需求改成其他协议)作为网络底层 * 帧同步作为同步方式 * protobuf作为传输协议 @@ -30,7 +30,7 @@ go build ### example的创建房间 1. http方式 - 1. ./example -web=10002 + 1. go run example/main.go -web=10002 1. 浏览器打开 http://127.0.0.1:10002 1. Room是房间ID,Member填参战者ID(用,隔开) diff --git a/example/api/html.go b/example/api/html.go index 4c67981..0a5a949 100644 --- a/example/api/html.go +++ b/example/api/html.go @@ -1,4 +1,4 @@ -package web +package api const htmlStr = ` @@ -44,7 +44,7 @@ const htmlStr = `

- +

diff --git a/example/api/web.go b/example/api/web.go index 3c6520a..72dac7b 100644 --- a/example/api/web.go +++ b/example/api/web.go @@ -1,4 +1,4 @@ -package web +package api import ( "fmt" @@ -10,11 +10,21 @@ import ( "github.com/byebyebruce/lockstepserver/room" ) -func init() { - http.HandleFunc("/create", HTTPHandleFuncCreate) - http.HandleFunc("/", HTTPHandleFunc) +type HttpApi struct { + m *room.RoomManager } -func HTTPHandleFunc(w http.ResponseWriter, r *http.Request) { + +func NewHttpApi(m *room.RoomManager) *HttpApi { + r := &HttpApi{ + m: m, + } + + http.HandleFunc("/create", r.HTTPHandleFuncCreate) + http.HandleFunc("/", r.HTTPHandleFunc) + return r +} + +func (h *HttpApi) HTTPHandleFunc(w http.ResponseWriter, r *http.Request) { query := r.URL.Query() if 0 == len(query) { @@ -28,7 +38,7 @@ func HTTPHandleFunc(w http.ResponseWriter, r *http.Request) { } } -func HTTPHandleFuncCreate(w http.ResponseWriter, r *http.Request) { +func (h *HttpApi) HTTPHandleFuncCreate(w http.ResponseWriter, r *http.Request) { ret := "error" @@ -55,11 +65,11 @@ func HTTPHandleFuncCreate(w http.ResponseWriter, r *http.Request) { } - room, ok := room.CreateRoom(roomID, 0, ps, 0, "test") - if ok { - ret = fmt.Sprintf("room.ID=[%d] room.Secret=[%s] room.Time=[%d]", room.ID(), room.SecretKey(), room.TimeStamp()) + room, err := h.m.CreateRoom(roomID, 0, ps, 0, "test") + if nil != err { + ret = err.Error() } else { - ret = "failed!" + ret = fmt.Sprintf("room.ID=[%d] room.Secret=[%s] room.Time=[%d]", room.ID(), room.SecretKey(), room.TimeStamp()) } } diff --git a/example/main.go b/example/main.go index 52c57fe..54918b5 100644 --- a/example/main.go +++ b/example/main.go @@ -17,17 +17,20 @@ import ( "syscall" "time" + l4g "github.com/alecthomas/log4go" + "github.com/byebyebruce/lockstepserver/example/api" "github.com/byebyebruce/lockstepserver/kcp_server" "github.com/byebyebruce/lockstepserver/protocol" "github.com/byebyebruce/lockstepserver/room" + "github.com/byebyebruce/lockstepserver/router" "github.com/byebyebruce/lockstepserver/util" - l4g "github.com/alecthomas/log4go" ) var ( nodeId = flag.Uint64("id", 0, "id") gWeb = flag.String("web", ":10002", "web listen address") outAddress = flag.String("out", ":10086", "out listen address(':10086' means localhost:10086)") + m *room.RoomManager ) //Init 初始化 @@ -37,16 +40,13 @@ func LoadConfig() bool { //Init 初始化 func Init() bool { - if len(*gWeb) > 0 { - - go func() { - e := http.ListenAndServe(*gWeb, nil) - if nil != e { - panic(e) - } - }() - l4g.Info("[main] http.ListenAndServe port=[%s]", *gWeb) - } + go func() { + e := http.ListenAndServe(*gWeb, nil) + if nil != e { + panic(e) + } + }() + l4g.Info("[main] http.ListenAndServe port=[%s]", *gWeb) return true } @@ -61,17 +61,20 @@ func Run() { l4g.Global.Close() }() - defer room.Stop() - //address := util.GetLocalIP() //udp server - networkServer, err := kcp_server.ListenAndServe(*outAddress, &room.Router{}, &protocol.MsgProtocol{}) + networkServer, err := kcp_server.ListenAndServe(*outAddress, router.New(m), &protocol.MsgProtocol{}) if nil != err { panic(err) } - l4g.Info("[main] kcp.Listen addr=[%s]", outAddress) + l4g.Info("[main] kcp.Listen addr=[%s]", *outAddress) defer networkServer.Stop() + m = room.NewRoomManager() + defer m.Stop() + + _ = api.NewHttpApi(m) + //主循环定时器 ticker := time.NewTimer(time.Second) defer ticker.Stop() diff --git a/go.mod b/go.mod index 0516500..9266c15 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.13 require ( github.com/alecthomas/log4go v0.0.0-20180109082532-d146e6b86faa - github.com/golang/protobuf v1.3.4 + github.com/golang/protobuf v1.4.1 github.com/klauspost/cpuid v1.2.3 // indirect github.com/klauspost/reedsolomon v1.9.3 // indirect github.com/pkg/errors v0.9.1 // indirect @@ -15,4 +15,5 @@ require ( github.com/xtaci/lossyconn v0.0.0-20200209145036-adba10fffc37 // indirect golang.org/x/crypto v0.0.0-20200302210943-78000ba7a073 // indirect golang.org/x/net v0.0.0-20200301022130-244492dfa37a // indirect + google.golang.org/protobuf v1.25.0 ) diff --git a/go.sum b/go.sum index 1a13c37..f193655 100644 --- a/go.sum +++ b/go.sum @@ -1,13 +1,36 @@ +cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/alecthomas/log4go v0.0.0-20180109082532-d146e6b86faa h1:0zdYOLyuQ3TWIgWNgEH+LnmZNMmkO1ze3wriQt093Mk= github.com/alecthomas/log4go v0.0.0-20180109082532-d146e6b86faa/go.mod h1:iCVmQ9g4TfaRX5m5jq5sXY7RXYWPv9/PynM/GocbG3w= +github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= +github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= +github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= +github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= +github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= +github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= +github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.4 h1:87PNWwrRvUSnqS4dlcBU/ftvOIBep4sYuBLlh6rX2wk= github.com/golang/protobuf v1.3.4/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= +github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= +github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= +github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= +github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= +github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= +github.com/golang/protobuf v1.4.1 h1:ZFgWrT+bLgsYPirOnRfKLYJLvssAegOj/hgyMFdJZe0= +github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8= +github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= +github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/klauspost/cpuid v1.2.3 h1:CCtW0xUnWGVINKvE/WWOYKdsPV6mawAtvQuSl8guwQs= github.com/klauspost/cpuid v1.2.3/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek= github.com/klauspost/reedsolomon v1.9.3 h1:N/VzgeMfHmLc+KHMD1UL/tNkfXAt8FnUqlgXGIduwAY= github.com/klauspost/reedsolomon v1.9.3/go.mod h1:CwCi+NUr9pqSVktrkN+Ondf06rkhYZ/pcNv7fu+8Un4= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= github.com/templexxx/cpufeat v0.0.0-20180724012125-cef66df7f161 h1:89CEmDvlq/F7SJEOqkIdNDGJXrQIhuIx9D2DBXjavSU= github.com/templexxx/cpufeat v0.0.0-20180724012125-cef66df7f161/go.mod h1:wM7WEvslTq+iOEAMDLSzhVuOt5BRZ05WirO+b09GHQU= github.com/templexxx/xor v0.0.0-20191217153810-f85b25db303b h1:fj5tQ8acgNUr6O8LEplsxDhUIe2573iLkJc+PqnzZTI= @@ -22,10 +45,47 @@ golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACk golang.org/x/crypto v0.0.0-20191219195013-becbf705a915/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20200302210943-78000ba7a073 h1:xMPOj6Pz6UipU1wXLkrtqpHbR0AVFnyPEQq/wRWz9lM= golang.org/x/crypto v0.0.0-20200302210943-78000ba7a073/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= +golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= +golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= +golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20200301022130-244492dfa37a h1:GuSPYbZzB5/dcLNCwLQLsg3obCJtX9IJhpXkvY7kzk0= golang.org/x/net v0.0.0-20200301022130-244492dfa37a/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= +golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d h1:+R4KGOnez64A81RvjARKc4UT5/tI9ujCIVX+P5KiHuI= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= +golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= +google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= +google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= +google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= +google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo= +google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= +google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= +google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= +google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= +google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= +google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= +google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= +google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= +google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +google.golang.org/protobuf v1.25.0 h1:Ejskq+SyPohKW+1uil0JJMtmHCgJPJ/qWTxr8qp+R4c= +google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= +honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= diff --git a/pb/build_proto.sh b/pb/build_proto.sh index 5fa24f6..a63f507 100644 --- a/pb/build_proto.sh +++ b/pb/build_proto.sh @@ -1,36 +1,4 @@ #!/bin/bash -DIR="$( cd "$( dirname "$0" )" && pwd )" -echo pwd=$DIR +set -ex -function xrsh_get_osname() -{ - uname -s -} - -xrsh_get_osname - -get_char() -{ - SAVEDSTTY=`stty -g` - stty -echo - stty raw - dd if=/dev/tty bs=1 count=1 2> /dev/null - stty -raw - stty echo - stty $SAVEDSTTY -} - -if [ $(uname -s) = 'Linux' ]; then - PROTOC=$DIR/../../../deps/protobuf/bin/protoc -else - PROTOC=$DIR/../../../tools/protoc_win/protoc.exe -fi - -if $PROTOC --go_out=. *.proto -then - echo build success - sleep 1 -else - echo build failed - get_char -fi +protoc --go_out=. *.proto \ No newline at end of file diff --git a/pb/message.pb.go b/pb/message.pb.go index d4372bf..27e9183 100644 --- a/pb/message.pb.go +++ b/pb/message.pb.go @@ -1,516 +1,1093 @@ // Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.25.0 +// protoc v3.14.0 // source: message.proto -/* -Package pb is a generated protocol buffer package. - -It is generated from these files: - message.proto - -It has these top-level messages: - C2S_ConnectMsg - S2C_ConnectMsg - S2C_JoinRoomMsg - S2C_StartMsg - C2S_ProgressMsg - S2C_ProgressMsg - C2S_InputMsg - InputData - FrameData - S2C_FrameMsg - C2S_ResultMsg -*/ package pb -import proto "github.com/golang/protobuf/proto" -import fmt "fmt" -import math "math" +import ( + proto "github.com/golang/protobuf/proto" + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + sync "sync" +) -// Reference imports to suppress errors if they are not otherwise used. -var _ = proto.Marshal -var _ = fmt.Errorf -var _ = math.Inf +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) -// This is a compile-time assertion to ensure that this generated file -// is compatible with the proto package it is being compiled against. -// A compilation error at this line likely means your copy of the -// proto package needs to be updated. -const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package +// This is a compile-time assertion that a sufficiently up-to-date version +// of the legacy proto package is being used. +const _ = proto.ProtoPackageIsVersion4 -// 消息ID +//消息ID type ID int32 const ( ID_MSG_BEGIN ID = 0 - ID_MSG_Connect ID = 1 - ID_MSG_Heartbeat ID = 2 - ID_MSG_JoinRoom ID = 10 - ID_MSG_Progress ID = 20 - ID_MSG_Ready ID = 30 - ID_MSG_Start ID = 40 - ID_MSG_Frame ID = 50 - ID_MSG_Input ID = 60 - ID_MSG_Result ID = 70 - ID_MSG_Close ID = 100 + ID_MSG_Connect ID = 1 //连接(客户端发来第一个消息) + ID_MSG_Heartbeat ID = 2 //心跳(服务端返回Connect成功之后每隔1秒发送一个心跳包) + ID_MSG_JoinRoom ID = 10 //进入 + ID_MSG_Progress ID = 20 //进度 + ID_MSG_Ready ID = 30 //准备 + ID_MSG_Start ID = 40 //开始 + ID_MSG_Frame ID = 50 //帧数据 + ID_MSG_Input ID = 60 //输入 + ID_MSG_Result ID = 70 //结果 + ID_MSG_Close ID = 100 //房间关闭 ID_MSG_END ID = 255 ) -var ID_name = map[int32]string{ - 0: "MSG_BEGIN", - 1: "MSG_Connect", - 2: "MSG_Heartbeat", - 10: "MSG_JoinRoom", - 20: "MSG_Progress", - 30: "MSG_Ready", - 40: "MSG_Start", - 50: "MSG_Frame", - 60: "MSG_Input", - 70: "MSG_Result", - 100: "MSG_Close", - 255: "MSG_END", -} -var ID_value = map[string]int32{ - "MSG_BEGIN": 0, - "MSG_Connect": 1, - "MSG_Heartbeat": 2, - "MSG_JoinRoom": 10, - "MSG_Progress": 20, - "MSG_Ready": 30, - "MSG_Start": 40, - "MSG_Frame": 50, - "MSG_Input": 60, - "MSG_Result": 70, - "MSG_Close": 100, - "MSG_END": 255, -} +// Enum value maps for ID. +var ( + ID_name = map[int32]string{ + 0: "MSG_BEGIN", + 1: "MSG_Connect", + 2: "MSG_Heartbeat", + 10: "MSG_JoinRoom", + 20: "MSG_Progress", + 30: "MSG_Ready", + 40: "MSG_Start", + 50: "MSG_Frame", + 60: "MSG_Input", + 70: "MSG_Result", + 100: "MSG_Close", + 255: "MSG_END", + } + ID_value = map[string]int32{ + "MSG_BEGIN": 0, + "MSG_Connect": 1, + "MSG_Heartbeat": 2, + "MSG_JoinRoom": 10, + "MSG_Progress": 20, + "MSG_Ready": 30, + "MSG_Start": 40, + "MSG_Frame": 50, + "MSG_Input": 60, + "MSG_Result": 70, + "MSG_Close": 100, + "MSG_END": 255, + } +) func (x ID) Enum() *ID { p := new(ID) *p = x return p } + func (x ID) String() string { - return proto.EnumName(ID_name, int32(x)) + return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x)) } -func (x *ID) UnmarshalJSON(data []byte) error { - value, err := proto.UnmarshalJSONEnum(ID_value, data, "ID") + +func (ID) Descriptor() protoreflect.EnumDescriptor { + return file_message_proto_enumTypes[0].Descriptor() +} + +func (ID) Type() protoreflect.EnumType { + return &file_message_proto_enumTypes[0] +} + +func (x ID) Number() protoreflect.EnumNumber { + return protoreflect.EnumNumber(x) +} + +// Deprecated: Do not use. +func (x *ID) UnmarshalJSON(b []byte) error { + num, err := protoimpl.X.UnmarshalJSONEnum(x.Descriptor(), b) if err != nil { return err } - *x = ID(value) + *x = ID(num) return nil } -func (ID) EnumDescriptor() ([]byte, []int) { return fileDescriptor0, []int{0} } -// 错误码 +// Deprecated: Use ID.Descriptor instead. +func (ID) EnumDescriptor() ([]byte, []int) { + return file_message_proto_rawDescGZIP(), []int{0} +} + +//错误码 type ERRORCODE int32 const ( - ERRORCODE_ERR_Ok ERRORCODE = 0 - ERRORCODE_ERR_NoPlayer ERRORCODE = 1 - ERRORCODE_ERR_NoRoom ERRORCODE = 2 - ERRORCODE_ERR_RoomState ERRORCODE = 3 - ERRORCODE_ERR_Token ERRORCODE = 4 + ERRORCODE_ERR_Ok ERRORCODE = 0 //OK + ERRORCODE_ERR_NoPlayer ERRORCODE = 1 //没有这个玩家 + ERRORCODE_ERR_NoRoom ERRORCODE = 2 //没有房间 + ERRORCODE_ERR_RoomState ERRORCODE = 3 //房间状态不正确 + ERRORCODE_ERR_Token ERRORCODE = 4 //Token验证失败 ) -var ERRORCODE_name = map[int32]string{ - 0: "ERR_Ok", - 1: "ERR_NoPlayer", - 2: "ERR_NoRoom", - 3: "ERR_RoomState", - 4: "ERR_Token", -} -var ERRORCODE_value = map[string]int32{ - "ERR_Ok": 0, - "ERR_NoPlayer": 1, - "ERR_NoRoom": 2, - "ERR_RoomState": 3, - "ERR_Token": 4, -} +// Enum value maps for ERRORCODE. +var ( + ERRORCODE_name = map[int32]string{ + 0: "ERR_Ok", + 1: "ERR_NoPlayer", + 2: "ERR_NoRoom", + 3: "ERR_RoomState", + 4: "ERR_Token", + } + ERRORCODE_value = map[string]int32{ + "ERR_Ok": 0, + "ERR_NoPlayer": 1, + "ERR_NoRoom": 2, + "ERR_RoomState": 3, + "ERR_Token": 4, + } +) func (x ERRORCODE) Enum() *ERRORCODE { p := new(ERRORCODE) *p = x return p } + func (x ERRORCODE) String() string { - return proto.EnumName(ERRORCODE_name, int32(x)) + return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x)) +} + +func (ERRORCODE) Descriptor() protoreflect.EnumDescriptor { + return file_message_proto_enumTypes[1].Descriptor() +} + +func (ERRORCODE) Type() protoreflect.EnumType { + return &file_message_proto_enumTypes[1] +} + +func (x ERRORCODE) Number() protoreflect.EnumNumber { + return protoreflect.EnumNumber(x) } -func (x *ERRORCODE) UnmarshalJSON(data []byte) error { - value, err := proto.UnmarshalJSONEnum(ERRORCODE_value, data, "ERRORCODE") + +// Deprecated: Do not use. +func (x *ERRORCODE) UnmarshalJSON(b []byte) error { + num, err := protoimpl.X.UnmarshalJSONEnum(x.Descriptor(), b) if err != nil { return err } - *x = ERRORCODE(value) + *x = ERRORCODE(num) return nil } -func (ERRORCODE) EnumDescriptor() ([]byte, []int) { return fileDescriptor0, []int{1} } -// 客户端发来的第一个消息 +// Deprecated: Use ERRORCODE.Descriptor instead. +func (ERRORCODE) EnumDescriptor() ([]byte, []int) { + return file_message_proto_rawDescGZIP(), []int{1} +} + +//客户端发来的第一个消息 type C2S_ConnectMsg struct { - PlayerID *uint64 `protobuf:"varint,1,opt,name=playerID" json:"playerID,omitempty"` - BattleID *uint64 `protobuf:"varint,2,opt,name=battleID" json:"battleID,omitempty"` - Token *string `protobuf:"bytes,10,opt,name=token" json:"token,omitempty"` - XXX_unrecognized []byte `json:"-"` + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + PlayerID *uint64 `protobuf:"varint,1,opt,name=playerID" json:"playerID,omitempty"` //唯一ID + BattleID *uint64 `protobuf:"varint,2,opt,name=battleID" json:"battleID,omitempty"` //战斗ID + Token *string `protobuf:"bytes,10,opt,name=token" json:"token,omitempty"` //令牌 +} + +func (x *C2S_ConnectMsg) Reset() { + *x = C2S_ConnectMsg{} + if protoimpl.UnsafeEnabled { + mi := &file_message_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } } -func (m *C2S_ConnectMsg) Reset() { *m = C2S_ConnectMsg{} } -func (m *C2S_ConnectMsg) String() string { return proto.CompactTextString(m) } -func (*C2S_ConnectMsg) ProtoMessage() {} -func (*C2S_ConnectMsg) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{0} } +func (x *C2S_ConnectMsg) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*C2S_ConnectMsg) ProtoMessage() {} -func (m *C2S_ConnectMsg) GetPlayerID() uint64 { - if m != nil && m.PlayerID != nil { - return *m.PlayerID +func (x *C2S_ConnectMsg) ProtoReflect() protoreflect.Message { + mi := &file_message_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use C2S_ConnectMsg.ProtoReflect.Descriptor instead. +func (*C2S_ConnectMsg) Descriptor() ([]byte, []int) { + return file_message_proto_rawDescGZIP(), []int{0} +} + +func (x *C2S_ConnectMsg) GetPlayerID() uint64 { + if x != nil && x.PlayerID != nil { + return *x.PlayerID } return 0 } -func (m *C2S_ConnectMsg) GetBattleID() uint64 { - if m != nil && m.BattleID != nil { - return *m.BattleID +func (x *C2S_ConnectMsg) GetBattleID() uint64 { + if x != nil && x.BattleID != nil { + return *x.BattleID } return 0 } -func (m *C2S_ConnectMsg) GetToken() string { - if m != nil && m.Token != nil { - return *m.Token +func (x *C2S_ConnectMsg) GetToken() string { + if x != nil && x.Token != nil { + return *x.Token } return "" } -// 服务端返回连接结果 +//服务端返回连接结果 type S2C_ConnectMsg struct { - ErrorCode *ERRORCODE `protobuf:"varint,1,opt,name=errorCode,enum=pb.ERRORCODE" json:"errorCode,omitempty"` - XXX_unrecognized []byte `json:"-"` + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + ErrorCode *ERRORCODE `protobuf:"varint,1,opt,name=errorCode,enum=pb.ERRORCODE" json:"errorCode,omitempty"` //错误码 +} + +func (x *S2C_ConnectMsg) Reset() { + *x = S2C_ConnectMsg{} + if protoimpl.UnsafeEnabled { + mi := &file_message_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *S2C_ConnectMsg) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*S2C_ConnectMsg) ProtoMessage() {} + +func (x *S2C_ConnectMsg) ProtoReflect() protoreflect.Message { + mi := &file_message_proto_msgTypes[1] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) } -func (m *S2C_ConnectMsg) Reset() { *m = S2C_ConnectMsg{} } -func (m *S2C_ConnectMsg) String() string { return proto.CompactTextString(m) } -func (*S2C_ConnectMsg) ProtoMessage() {} -func (*S2C_ConnectMsg) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{1} } +// Deprecated: Use S2C_ConnectMsg.ProtoReflect.Descriptor instead. +func (*S2C_ConnectMsg) Descriptor() ([]byte, []int) { + return file_message_proto_rawDescGZIP(), []int{1} +} -func (m *S2C_ConnectMsg) GetErrorCode() ERRORCODE { - if m != nil && m.ErrorCode != nil { - return *m.ErrorCode +func (x *S2C_ConnectMsg) GetErrorCode() ERRORCODE { + if x != nil && x.ErrorCode != nil { + return *x.ErrorCode } return ERRORCODE_ERR_Ok } -// 服务端返回进入房间消息 +//服务端返回进入房间消息 type S2C_JoinRoomMsg struct { - Roomseatid *int32 `protobuf:"varint,1,opt,name=roomseatid" json:"roomseatid,omitempty"` - Others []uint64 `protobuf:"varint,2,rep,name=others" json:"others,omitempty"` - Pros []int32 `protobuf:"varint,3,rep,name=pros" json:"pros,omitempty"` - RandomSeed *int32 `protobuf:"varint,4,opt,name=randomSeed" json:"randomSeed,omitempty"` - XXX_unrecognized []byte `json:"-"` + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Roomseatid *int32 `protobuf:"varint,1,opt,name=roomseatid" json:"roomseatid,omitempty"` //自己的位置索引id(1~N) + Others []uint64 `protobuf:"varint,2,rep,name=others" json:"others,omitempty"` //其他人的id + Pros []int32 `protobuf:"varint,3,rep,name=pros" json:"pros,omitempty"` //其他人的进度 + RandomSeed *int32 `protobuf:"varint,4,opt,name=randomSeed" json:"randomSeed,omitempty"` //随机种子 +} + +func (x *S2C_JoinRoomMsg) Reset() { + *x = S2C_JoinRoomMsg{} + if protoimpl.UnsafeEnabled { + mi := &file_message_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *S2C_JoinRoomMsg) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*S2C_JoinRoomMsg) ProtoMessage() {} + +func (x *S2C_JoinRoomMsg) ProtoReflect() protoreflect.Message { + mi := &file_message_proto_msgTypes[2] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) } -func (m *S2C_JoinRoomMsg) Reset() { *m = S2C_JoinRoomMsg{} } -func (m *S2C_JoinRoomMsg) String() string { return proto.CompactTextString(m) } -func (*S2C_JoinRoomMsg) ProtoMessage() {} -func (*S2C_JoinRoomMsg) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{2} } +// Deprecated: Use S2C_JoinRoomMsg.ProtoReflect.Descriptor instead. +func (*S2C_JoinRoomMsg) Descriptor() ([]byte, []int) { + return file_message_proto_rawDescGZIP(), []int{2} +} -func (m *S2C_JoinRoomMsg) GetRoomseatid() int32 { - if m != nil && m.Roomseatid != nil { - return *m.Roomseatid +func (x *S2C_JoinRoomMsg) GetRoomseatid() int32 { + if x != nil && x.Roomseatid != nil { + return *x.Roomseatid } return 0 } -func (m *S2C_JoinRoomMsg) GetOthers() []uint64 { - if m != nil { - return m.Others +func (x *S2C_JoinRoomMsg) GetOthers() []uint64 { + if x != nil { + return x.Others } return nil } -func (m *S2C_JoinRoomMsg) GetPros() []int32 { - if m != nil { - return m.Pros +func (x *S2C_JoinRoomMsg) GetPros() []int32 { + if x != nil { + return x.Pros } return nil } -func (m *S2C_JoinRoomMsg) GetRandomSeed() int32 { - if m != nil && m.RandomSeed != nil { - return *m.RandomSeed +func (x *S2C_JoinRoomMsg) GetRandomSeed() int32 { + if x != nil && x.RandomSeed != nil { + return *x.RandomSeed } return 0 } -// 服务端广播开始游戏消息 +//服务端广播开始游戏消息 type S2C_StartMsg struct { - TimeStamp *int64 `protobuf:"varint,1,opt,name=timeStamp" json:"timeStamp,omitempty"` - XXX_unrecognized []byte `json:"-"` + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + TimeStamp *int64 `protobuf:"varint,1,opt,name=timeStamp" json:"timeStamp,omitempty"` //同步时间戳 +} + +func (x *S2C_StartMsg) Reset() { + *x = S2C_StartMsg{} + if protoimpl.UnsafeEnabled { + mi := &file_message_proto_msgTypes[3] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *S2C_StartMsg) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*S2C_StartMsg) ProtoMessage() {} + +func (x *S2C_StartMsg) ProtoReflect() protoreflect.Message { + mi := &file_message_proto_msgTypes[3] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) } -func (m *S2C_StartMsg) Reset() { *m = S2C_StartMsg{} } -func (m *S2C_StartMsg) String() string { return proto.CompactTextString(m) } -func (*S2C_StartMsg) ProtoMessage() {} -func (*S2C_StartMsg) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{3} } +// Deprecated: Use S2C_StartMsg.ProtoReflect.Descriptor instead. +func (*S2C_StartMsg) Descriptor() ([]byte, []int) { + return file_message_proto_rawDescGZIP(), []int{3} +} -func (m *S2C_StartMsg) GetTimeStamp() int64 { - if m != nil && m.TimeStamp != nil { - return *m.TimeStamp +func (x *S2C_StartMsg) GetTimeStamp() int64 { + if x != nil && x.TimeStamp != nil { + return *x.TimeStamp } return 0 } -// 读条进度 +//读条进度 type C2S_ProgressMsg struct { - Pro *int32 `protobuf:"varint,1,opt,name=pro" json:"pro,omitempty"` - XXX_unrecognized []byte `json:"-"` + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Pro *int32 `protobuf:"varint,1,opt,name=pro" json:"pro,omitempty"` //进度值0~100 +} + +func (x *C2S_ProgressMsg) Reset() { + *x = C2S_ProgressMsg{} + if protoimpl.UnsafeEnabled { + mi := &file_message_proto_msgTypes[4] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *C2S_ProgressMsg) String() string { + return protoimpl.X.MessageStringOf(x) } -func (m *C2S_ProgressMsg) Reset() { *m = C2S_ProgressMsg{} } -func (m *C2S_ProgressMsg) String() string { return proto.CompactTextString(m) } -func (*C2S_ProgressMsg) ProtoMessage() {} -func (*C2S_ProgressMsg) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{4} } +func (*C2S_ProgressMsg) ProtoMessage() {} -func (m *C2S_ProgressMsg) GetPro() int32 { - if m != nil && m.Pro != nil { - return *m.Pro +func (x *C2S_ProgressMsg) ProtoReflect() protoreflect.Message { + mi := &file_message_proto_msgTypes[4] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use C2S_ProgressMsg.ProtoReflect.Descriptor instead. +func (*C2S_ProgressMsg) Descriptor() ([]byte, []int) { + return file_message_proto_rawDescGZIP(), []int{4} +} + +func (x *C2S_ProgressMsg) GetPro() int32 { + if x != nil && x.Pro != nil { + return *x.Pro } return 0 } -// 读条进度 +//读条进度 type S2C_ProgressMsg struct { - Id *uint64 `protobuf:"varint,1,opt,name=id" json:"id,omitempty"` - Pro *int32 `protobuf:"varint,2,opt,name=pro" json:"pro,omitempty"` - XXX_unrecognized []byte `json:"-"` + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Id *uint64 `protobuf:"varint,1,opt,name=id" json:"id,omitempty"` //id + Pro *int32 `protobuf:"varint,2,opt,name=pro" json:"pro,omitempty"` //进度值0~100 +} + +func (x *S2C_ProgressMsg) Reset() { + *x = S2C_ProgressMsg{} + if protoimpl.UnsafeEnabled { + mi := &file_message_proto_msgTypes[5] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *S2C_ProgressMsg) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*S2C_ProgressMsg) ProtoMessage() {} + +func (x *S2C_ProgressMsg) ProtoReflect() protoreflect.Message { + mi := &file_message_proto_msgTypes[5] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) } -func (m *S2C_ProgressMsg) Reset() { *m = S2C_ProgressMsg{} } -func (m *S2C_ProgressMsg) String() string { return proto.CompactTextString(m) } -func (*S2C_ProgressMsg) ProtoMessage() {} -func (*S2C_ProgressMsg) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{5} } +// Deprecated: Use S2C_ProgressMsg.ProtoReflect.Descriptor instead. +func (*S2C_ProgressMsg) Descriptor() ([]byte, []int) { + return file_message_proto_rawDescGZIP(), []int{5} +} -func (m *S2C_ProgressMsg) GetId() uint64 { - if m != nil && m.Id != nil { - return *m.Id +func (x *S2C_ProgressMsg) GetId() uint64 { + if x != nil && x.Id != nil { + return *x.Id } return 0 } -func (m *S2C_ProgressMsg) GetPro() int32 { - if m != nil && m.Pro != nil { - return *m.Pro +func (x *S2C_ProgressMsg) GetPro() int32 { + if x != nil && x.Pro != nil { + return *x.Pro } return 0 } -// 操作输入消息 +//操作输入消息 type C2S_InputMsg struct { - Sid *int32 `protobuf:"varint,1,opt,name=sid" json:"sid,omitempty"` - X *int32 `protobuf:"varint,2,opt,name=x" json:"x,omitempty"` - Y *int32 `protobuf:"varint,3,opt,name=y" json:"y,omitempty"` - FrameID *uint32 `protobuf:"varint,4,opt,name=frameID" json:"frameID,omitempty"` - XXX_unrecognized []byte `json:"-"` + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Sid *int32 `protobuf:"varint,1,opt,name=sid" json:"sid,omitempty"` //操作id + X *int32 `protobuf:"varint,2,opt,name=x" json:"x,omitempty"` //操作位置x + Y *int32 `protobuf:"varint,3,opt,name=y" json:"y,omitempty"` //操作位置y + FrameID *uint32 `protobuf:"varint,4,opt,name=frameID" json:"frameID,omitempty"` //帧ID +} + +func (x *C2S_InputMsg) Reset() { + *x = C2S_InputMsg{} + if protoimpl.UnsafeEnabled { + mi := &file_message_proto_msgTypes[6] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *C2S_InputMsg) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*C2S_InputMsg) ProtoMessage() {} + +func (x *C2S_InputMsg) ProtoReflect() protoreflect.Message { + mi := &file_message_proto_msgTypes[6] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) } -func (m *C2S_InputMsg) Reset() { *m = C2S_InputMsg{} } -func (m *C2S_InputMsg) String() string { return proto.CompactTextString(m) } -func (*C2S_InputMsg) ProtoMessage() {} -func (*C2S_InputMsg) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{6} } +// Deprecated: Use C2S_InputMsg.ProtoReflect.Descriptor instead. +func (*C2S_InputMsg) Descriptor() ([]byte, []int) { + return file_message_proto_rawDescGZIP(), []int{6} +} -func (m *C2S_InputMsg) GetSid() int32 { - if m != nil && m.Sid != nil { - return *m.Sid +func (x *C2S_InputMsg) GetSid() int32 { + if x != nil && x.Sid != nil { + return *x.Sid } return 0 } -func (m *C2S_InputMsg) GetX() int32 { - if m != nil && m.X != nil { - return *m.X +func (x *C2S_InputMsg) GetX() int32 { + if x != nil && x.X != nil { + return *x.X } return 0 } -func (m *C2S_InputMsg) GetY() int32 { - if m != nil && m.Y != nil { - return *m.Y +func (x *C2S_InputMsg) GetY() int32 { + if x != nil && x.Y != nil { + return *x.Y } return 0 } -func (m *C2S_InputMsg) GetFrameID() uint32 { - if m != nil && m.FrameID != nil { - return *m.FrameID +func (x *C2S_InputMsg) GetFrameID() uint32 { + if x != nil && x.FrameID != nil { + return *x.FrameID } return 0 } -// 帧存储操作输入 +//帧存储操作输入 type InputData struct { - Id *uint64 `protobuf:"varint,1,opt,name=id" json:"id,omitempty"` - Sid *int32 `protobuf:"varint,2,opt,name=sid" json:"sid,omitempty"` - X *int32 `protobuf:"varint,3,opt,name=x" json:"x,omitempty"` - Y *int32 `protobuf:"varint,4,opt,name=y" json:"y,omitempty"` - Roomseatid *int32 `protobuf:"varint,5,opt,name=roomseatid" json:"roomseatid,omitempty"` - XXX_unrecognized []byte `json:"-"` + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Id *uint64 `protobuf:"varint,1,opt,name=id" json:"id,omitempty"` //id + Sid *int32 `protobuf:"varint,2,opt,name=sid" json:"sid,omitempty"` //操作id + X *int32 `protobuf:"varint,3,opt,name=x" json:"x,omitempty"` //操作位置x + Y *int32 `protobuf:"varint,4,opt,name=y" json:"y,omitempty"` //操作位置y + Roomseatid *int32 `protobuf:"varint,5,opt,name=roomseatid" json:"roomseatid,omitempty"` //操作者的位置索引id(1~N) +} + +func (x *InputData) Reset() { + *x = InputData{} + if protoimpl.UnsafeEnabled { + mi := &file_message_proto_msgTypes[7] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *InputData) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*InputData) ProtoMessage() {} + +func (x *InputData) ProtoReflect() protoreflect.Message { + mi := &file_message_proto_msgTypes[7] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) } -func (m *InputData) Reset() { *m = InputData{} } -func (m *InputData) String() string { return proto.CompactTextString(m) } -func (*InputData) ProtoMessage() {} -func (*InputData) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{7} } +// Deprecated: Use InputData.ProtoReflect.Descriptor instead. +func (*InputData) Descriptor() ([]byte, []int) { + return file_message_proto_rawDescGZIP(), []int{7} +} -func (m *InputData) GetId() uint64 { - if m != nil && m.Id != nil { - return *m.Id +func (x *InputData) GetId() uint64 { + if x != nil && x.Id != nil { + return *x.Id } return 0 } -func (m *InputData) GetSid() int32 { - if m != nil && m.Sid != nil { - return *m.Sid +func (x *InputData) GetSid() int32 { + if x != nil && x.Sid != nil { + return *x.Sid } return 0 } -func (m *InputData) GetX() int32 { - if m != nil && m.X != nil { - return *m.X +func (x *InputData) GetX() int32 { + if x != nil && x.X != nil { + return *x.X } return 0 } -func (m *InputData) GetY() int32 { - if m != nil && m.Y != nil { - return *m.Y +func (x *InputData) GetY() int32 { + if x != nil && x.Y != nil { + return *x.Y } return 0 } -func (m *InputData) GetRoomseatid() int32 { - if m != nil && m.Roomseatid != nil { - return *m.Roomseatid +func (x *InputData) GetRoomseatid() int32 { + if x != nil && x.Roomseatid != nil { + return *x.Roomseatid } return 0 } -// 帧数据 +//帧数据 type FrameData struct { - FrameID *uint32 `protobuf:"varint,1,opt,name=frameID" json:"frameID,omitempty"` - Input []*InputData `protobuf:"bytes,2,rep,name=input" json:"input,omitempty"` - XXX_unrecognized []byte `json:"-"` + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + FrameID *uint32 `protobuf:"varint,1,opt,name=frameID" json:"frameID,omitempty"` //帧ID + Input []*InputData `protobuf:"bytes,2,rep,name=input" json:"input,omitempty"` //操作输入 +} + +func (x *FrameData) Reset() { + *x = FrameData{} + if protoimpl.UnsafeEnabled { + mi := &file_message_proto_msgTypes[8] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } } -func (m *FrameData) Reset() { *m = FrameData{} } -func (m *FrameData) String() string { return proto.CompactTextString(m) } -func (*FrameData) ProtoMessage() {} -func (*FrameData) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{8} } +func (x *FrameData) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*FrameData) ProtoMessage() {} + +func (x *FrameData) ProtoReflect() protoreflect.Message { + mi := &file_message_proto_msgTypes[8] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} -func (m *FrameData) GetFrameID() uint32 { - if m != nil && m.FrameID != nil { - return *m.FrameID +// Deprecated: Use FrameData.ProtoReflect.Descriptor instead. +func (*FrameData) Descriptor() ([]byte, []int) { + return file_message_proto_rawDescGZIP(), []int{8} +} + +func (x *FrameData) GetFrameID() uint32 { + if x != nil && x.FrameID != nil { + return *x.FrameID } return 0 } -func (m *FrameData) GetInput() []*InputData { - if m != nil { - return m.Input +func (x *FrameData) GetInput() []*InputData { + if x != nil { + return x.Input } return nil } -// 广播帧消息 +//广播帧消息 type S2C_FrameMsg struct { - Frames []*FrameData `protobuf:"bytes,1,rep,name=frames" json:"frames,omitempty"` - XXX_unrecognized []byte `json:"-"` + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Frames []*FrameData `protobuf:"bytes,1,rep,name=frames" json:"frames,omitempty"` //帧数据 +} + +func (x *S2C_FrameMsg) Reset() { + *x = S2C_FrameMsg{} + if protoimpl.UnsafeEnabled { + mi := &file_message_proto_msgTypes[9] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *S2C_FrameMsg) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*S2C_FrameMsg) ProtoMessage() {} + +func (x *S2C_FrameMsg) ProtoReflect() protoreflect.Message { + mi := &file_message_proto_msgTypes[9] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) } -func (m *S2C_FrameMsg) Reset() { *m = S2C_FrameMsg{} } -func (m *S2C_FrameMsg) String() string { return proto.CompactTextString(m) } -func (*S2C_FrameMsg) ProtoMessage() {} -func (*S2C_FrameMsg) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{9} } +// Deprecated: Use S2C_FrameMsg.ProtoReflect.Descriptor instead. +func (*S2C_FrameMsg) Descriptor() ([]byte, []int) { + return file_message_proto_rawDescGZIP(), []int{9} +} -func (m *S2C_FrameMsg) GetFrames() []*FrameData { - if m != nil { - return m.Frames +func (x *S2C_FrameMsg) GetFrames() []*FrameData { + if x != nil { + return x.Frames } return nil } -// 结果消息 +//结果消息 type C2S_ResultMsg struct { - WinnerID *uint64 `protobuf:"varint,1,opt,name=winnerID" json:"winnerID,omitempty"` - XXX_unrecognized []byte `json:"-"` + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + WinnerID *uint64 `protobuf:"varint,1,opt,name=winnerID" json:"winnerID,omitempty"` //胜利者ID +} + +func (x *C2S_ResultMsg) Reset() { + *x = C2S_ResultMsg{} + if protoimpl.UnsafeEnabled { + mi := &file_message_proto_msgTypes[10] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *C2S_ResultMsg) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*C2S_ResultMsg) ProtoMessage() {} + +func (x *C2S_ResultMsg) ProtoReflect() protoreflect.Message { + mi := &file_message_proto_msgTypes[10] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) } -func (m *C2S_ResultMsg) Reset() { *m = C2S_ResultMsg{} } -func (m *C2S_ResultMsg) String() string { return proto.CompactTextString(m) } -func (*C2S_ResultMsg) ProtoMessage() {} -func (*C2S_ResultMsg) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{10} } +// Deprecated: Use C2S_ResultMsg.ProtoReflect.Descriptor instead. +func (*C2S_ResultMsg) Descriptor() ([]byte, []int) { + return file_message_proto_rawDescGZIP(), []int{10} +} -func (m *C2S_ResultMsg) GetWinnerID() uint64 { - if m != nil && m.WinnerID != nil { - return *m.WinnerID +func (x *C2S_ResultMsg) GetWinnerID() uint64 { + if x != nil && x.WinnerID != nil { + return *x.WinnerID } return 0 } -func init() { - proto.RegisterType((*C2S_ConnectMsg)(nil), "pb.C2S_ConnectMsg") - proto.RegisterType((*S2C_ConnectMsg)(nil), "pb.S2C_ConnectMsg") - proto.RegisterType((*S2C_JoinRoomMsg)(nil), "pb.S2C_JoinRoomMsg") - proto.RegisterType((*S2C_StartMsg)(nil), "pb.S2C_StartMsg") - proto.RegisterType((*C2S_ProgressMsg)(nil), "pb.C2S_ProgressMsg") - proto.RegisterType((*S2C_ProgressMsg)(nil), "pb.S2C_ProgressMsg") - proto.RegisterType((*C2S_InputMsg)(nil), "pb.C2S_InputMsg") - proto.RegisterType((*InputData)(nil), "pb.InputData") - proto.RegisterType((*FrameData)(nil), "pb.FrameData") - proto.RegisterType((*S2C_FrameMsg)(nil), "pb.S2C_FrameMsg") - proto.RegisterType((*C2S_ResultMsg)(nil), "pb.C2S_ResultMsg") - proto.RegisterEnum("pb.ID", ID_name, ID_value) - proto.RegisterEnum("pb.ERRORCODE", ERRORCODE_name, ERRORCODE_value) -} - -func init() { proto.RegisterFile("message.proto", fileDescriptor0) } - -var fileDescriptor0 = []byte{ - // 588 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x6c, 0x53, 0x5d, 0x6f, 0xd3, 0x30, - 0x14, 0x5d, 0x3e, 0xba, 0x91, 0xbb, 0xb6, 0x33, 0xd6, 0x84, 0x22, 0x84, 0xa6, 0x2a, 0x13, 0x52, - 0xb5, 0xa1, 0x3d, 0x14, 0xf1, 0x06, 0x2f, 0x34, 0xdd, 0xe8, 0xa4, 0x7d, 0xc8, 0x41, 0xbc, 0x20, - 0x31, 0xb9, 0xc4, 0x8c, 0x68, 0x4d, 0x1c, 0xd9, 0x9e, 0x58, 0x1f, 0xf8, 0x77, 0xfc, 0x2f, 0xd0, - 0x75, 0xe2, 0xb4, 0x9b, 0x78, 0xf3, 0xb9, 0x37, 0xf7, 0x9c, 0x73, 0x3f, 0x02, 0x83, 0x52, 0x68, - 0xcd, 0x6f, 0xc5, 0x49, 0xad, 0xa4, 0x91, 0xd4, 0xaf, 0x17, 0xc9, 0x37, 0x18, 0x4e, 0x27, 0xd9, - 0xcd, 0x54, 0x56, 0x95, 0xf8, 0x6e, 0x2e, 0xf4, 0x2d, 0x7d, 0x09, 0xcf, 0xea, 0x25, 0x5f, 0x09, - 0x35, 0x4f, 0x63, 0x6f, 0xe4, 0x8d, 0x43, 0xd6, 0x61, 0xcc, 0x2d, 0xb8, 0x31, 0x4b, 0x31, 0x4f, - 0x63, 0xbf, 0xc9, 0x39, 0x4c, 0xf7, 0xa1, 0x67, 0xe4, 0x9d, 0xa8, 0x62, 0x18, 0x79, 0xe3, 0x88, - 0x35, 0x20, 0xf9, 0x00, 0xc3, 0x6c, 0x32, 0xdd, 0xe4, 0x3f, 0x86, 0x48, 0x28, 0x25, 0xd5, 0x54, - 0xe6, 0xc2, 0x0a, 0x0c, 0x27, 0x83, 0x93, 0x7a, 0x71, 0x32, 0x63, 0xec, 0x8a, 0x4d, 0xaf, 0xd2, - 0x19, 0x5b, 0xe7, 0x93, 0xdf, 0xb0, 0x87, 0xe5, 0xe7, 0xb2, 0xa8, 0x98, 0x94, 0x25, 0xd6, 0x1f, - 0x00, 0x28, 0x29, 0x4b, 0x2d, 0xb8, 0x29, 0x72, 0x4b, 0xd0, 0x63, 0x1b, 0x11, 0xfa, 0x02, 0xb6, - 0xa5, 0xf9, 0x29, 0x94, 0x8e, 0xfd, 0x51, 0x30, 0x0e, 0x59, 0x8b, 0x28, 0x85, 0xb0, 0x56, 0x52, - 0xc7, 0xc1, 0x28, 0x18, 0xf7, 0x98, 0x7d, 0x5b, 0x2e, 0x5e, 0xe5, 0xb2, 0xcc, 0x84, 0xc8, 0xe3, - 0xb0, 0xe5, 0xea, 0x22, 0xc9, 0x1b, 0xe8, 0xa3, 0x7c, 0x66, 0xb8, 0xb2, 0xde, 0x5f, 0x41, 0x64, - 0x8a, 0x52, 0x64, 0x86, 0x97, 0xb5, 0x95, 0x0e, 0xd8, 0x3a, 0x90, 0x1c, 0xc2, 0x1e, 0xce, 0xf2, - 0x5a, 0xc9, 0x5b, 0x25, 0xb4, 0xc6, 0x02, 0x02, 0x41, 0xad, 0x64, 0xeb, 0x12, 0x9f, 0xc9, 0xdb, - 0xa6, 0xa3, 0xcd, 0x8f, 0x86, 0xe0, 0xb7, 0x9d, 0x84, 0xcc, 0x2f, 0x72, 0x57, 0xe4, 0xaf, 0x8b, - 0xbe, 0x40, 0x1f, 0x99, 0xe7, 0x55, 0x7d, 0x6f, 0x5a, 0x5a, 0xdd, 0x35, 0x8f, 0x4f, 0xda, 0x07, - 0xef, 0xa1, 0xad, 0xf0, 0x1e, 0x10, 0xad, 0xe2, 0xa0, 0x41, 0x2b, 0x1a, 0xc3, 0xce, 0x0f, 0xc5, - 0x4b, 0x5c, 0x1a, 0xb6, 0x38, 0x60, 0x0e, 0x26, 0x05, 0x44, 0x96, 0x33, 0xe5, 0x86, 0xff, 0xcf, - 0x06, 0x8a, 0xf8, 0x4f, 0x44, 0x82, 0x47, 0x22, 0xa1, 0x13, 0x79, 0xbc, 0x96, 0xde, 0xd3, 0xb5, - 0x24, 0xe7, 0x10, 0x9d, 0xa2, 0xaa, 0x95, 0xda, 0x70, 0xe4, 0x3d, 0x72, 0x44, 0x0f, 0xa1, 0x57, - 0xa0, 0x23, 0xbb, 0xbc, 0xdd, 0xe6, 0x32, 0x3a, 0x8b, 0xac, 0xc9, 0x25, 0xef, 0x9a, 0xb5, 0x58, - 0x3e, 0x1c, 0xc7, 0x6b, 0xd8, 0xb6, 0xf5, 0x3a, 0xf6, 0xd6, 0x55, 0x9d, 0x1a, 0x6b, 0x93, 0xc9, - 0x31, 0x0c, 0x70, 0x8a, 0x4c, 0xe8, 0xfb, 0xa5, 0x3b, 0xf5, 0x5f, 0x45, 0x55, 0x6d, 0x9e, 0xba, - 0xc3, 0x47, 0x7f, 0x3c, 0xf0, 0xe7, 0x29, 0x1d, 0x40, 0x74, 0x91, 0x9d, 0xdd, 0x7c, 0x9c, 0x9d, - 0xcd, 0x2f, 0xc9, 0x16, 0xdd, 0x83, 0x5d, 0x84, 0xed, 0x39, 0x13, 0x8f, 0x3e, 0x87, 0x01, 0x06, - 0x3e, 0x09, 0xae, 0xcc, 0x42, 0x70, 0x43, 0x7c, 0x4a, 0xa0, 0x8f, 0x21, 0x77, 0xb3, 0x04, 0x5c, - 0xc4, 0xed, 0x9c, 0xec, 0x3b, 0x5a, 0x26, 0x78, 0xbe, 0x22, 0x07, 0x0e, 0xda, 0x3b, 0x23, 0x63, - 0x07, 0x6d, 0x07, 0x64, 0xe2, 0xa0, 0x1d, 0x03, 0x79, 0x4f, 0x87, 0x00, 0x4d, 0x2d, 0xb6, 0x41, - 0x4e, 0x5d, 0x7a, 0xba, 0x94, 0x5a, 0x10, 0x5c, 0xd2, 0x0e, 0xc2, 0xd9, 0x65, 0x4a, 0xfe, 0x7a, - 0x47, 0x5f, 0x21, 0xea, 0x7e, 0x2c, 0x0a, 0xb0, 0x3d, 0x63, 0xec, 0xe6, 0xea, 0x8e, 0x6c, 0xa1, - 0x27, 0x7c, 0x5f, 0xca, 0x6b, 0xfb, 0x73, 0x13, 0x0f, 0x79, 0x9b, 0x88, 0x75, 0xed, 0x63, 0x6b, - 0x88, 0x11, 0x65, 0x86, 0x1b, 0x41, 0x02, 0x94, 0xc2, 0xd0, 0x67, 0xfc, 0xb5, 0x49, 0xf8, 0x2f, - 0x00, 0x00, 0xff, 0xff, 0x75, 0xbf, 0xd7, 0x5d, 0x50, 0x04, 0x00, 0x00, +var File_message_proto protoreflect.FileDescriptor + +var file_message_proto_rawDesc = []byte{ + 0x0a, 0x0d, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, + 0x02, 0x70, 0x62, 0x22, 0x5e, 0x0a, 0x0e, 0x43, 0x32, 0x53, 0x5f, 0x43, 0x6f, 0x6e, 0x6e, 0x65, + 0x63, 0x74, 0x4d, 0x73, 0x67, 0x12, 0x1a, 0x0a, 0x08, 0x70, 0x6c, 0x61, 0x79, 0x65, 0x72, 0x49, + 0x44, 0x18, 0x01, 0x20, 0x01, 0x28, 0x04, 0x52, 0x08, 0x70, 0x6c, 0x61, 0x79, 0x65, 0x72, 0x49, + 0x44, 0x12, 0x1a, 0x0a, 0x08, 0x62, 0x61, 0x74, 0x74, 0x6c, 0x65, 0x49, 0x44, 0x18, 0x02, 0x20, + 0x01, 0x28, 0x04, 0x52, 0x08, 0x62, 0x61, 0x74, 0x74, 0x6c, 0x65, 0x49, 0x44, 0x12, 0x14, 0x0a, + 0x05, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x74, 0x6f, + 0x6b, 0x65, 0x6e, 0x22, 0x3d, 0x0a, 0x0e, 0x53, 0x32, 0x43, 0x5f, 0x43, 0x6f, 0x6e, 0x6e, 0x65, + 0x63, 0x74, 0x4d, 0x73, 0x67, 0x12, 0x2b, 0x0a, 0x09, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x43, 0x6f, + 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x0d, 0x2e, 0x70, 0x62, 0x2e, 0x45, 0x52, + 0x52, 0x4f, 0x52, 0x43, 0x4f, 0x44, 0x45, 0x52, 0x09, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x43, 0x6f, + 0x64, 0x65, 0x22, 0x7d, 0x0a, 0x0f, 0x53, 0x32, 0x43, 0x5f, 0x4a, 0x6f, 0x69, 0x6e, 0x52, 0x6f, + 0x6f, 0x6d, 0x4d, 0x73, 0x67, 0x12, 0x1e, 0x0a, 0x0a, 0x72, 0x6f, 0x6f, 0x6d, 0x73, 0x65, 0x61, + 0x74, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x0a, 0x72, 0x6f, 0x6f, 0x6d, 0x73, + 0x65, 0x61, 0x74, 0x69, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x6f, 0x74, 0x68, 0x65, 0x72, 0x73, 0x18, + 0x02, 0x20, 0x03, 0x28, 0x04, 0x52, 0x06, 0x6f, 0x74, 0x68, 0x65, 0x72, 0x73, 0x12, 0x12, 0x0a, + 0x04, 0x70, 0x72, 0x6f, 0x73, 0x18, 0x03, 0x20, 0x03, 0x28, 0x05, 0x52, 0x04, 0x70, 0x72, 0x6f, + 0x73, 0x12, 0x1e, 0x0a, 0x0a, 0x72, 0x61, 0x6e, 0x64, 0x6f, 0x6d, 0x53, 0x65, 0x65, 0x64, 0x18, + 0x04, 0x20, 0x01, 0x28, 0x05, 0x52, 0x0a, 0x72, 0x61, 0x6e, 0x64, 0x6f, 0x6d, 0x53, 0x65, 0x65, + 0x64, 0x22, 0x2c, 0x0a, 0x0c, 0x53, 0x32, 0x43, 0x5f, 0x53, 0x74, 0x61, 0x72, 0x74, 0x4d, 0x73, + 0x67, 0x12, 0x1c, 0x0a, 0x09, 0x74, 0x69, 0x6d, 0x65, 0x53, 0x74, 0x61, 0x6d, 0x70, 0x18, 0x01, + 0x20, 0x01, 0x28, 0x03, 0x52, 0x09, 0x74, 0x69, 0x6d, 0x65, 0x53, 0x74, 0x61, 0x6d, 0x70, 0x22, + 0x23, 0x0a, 0x0f, 0x43, 0x32, 0x53, 0x5f, 0x50, 0x72, 0x6f, 0x67, 0x72, 0x65, 0x73, 0x73, 0x4d, + 0x73, 0x67, 0x12, 0x10, 0x0a, 0x03, 0x70, 0x72, 0x6f, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, + 0x03, 0x70, 0x72, 0x6f, 0x22, 0x33, 0x0a, 0x0f, 0x53, 0x32, 0x43, 0x5f, 0x50, 0x72, 0x6f, 0x67, + 0x72, 0x65, 0x73, 0x73, 0x4d, 0x73, 0x67, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, + 0x01, 0x28, 0x04, 0x52, 0x02, 0x69, 0x64, 0x12, 0x10, 0x0a, 0x03, 0x70, 0x72, 0x6f, 0x18, 0x02, + 0x20, 0x01, 0x28, 0x05, 0x52, 0x03, 0x70, 0x72, 0x6f, 0x22, 0x56, 0x0a, 0x0c, 0x43, 0x32, 0x53, + 0x5f, 0x49, 0x6e, 0x70, 0x75, 0x74, 0x4d, 0x73, 0x67, 0x12, 0x10, 0x0a, 0x03, 0x73, 0x69, 0x64, + 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x03, 0x73, 0x69, 0x64, 0x12, 0x0c, 0x0a, 0x01, 0x78, + 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x01, 0x78, 0x12, 0x0c, 0x0a, 0x01, 0x79, 0x18, 0x03, + 0x20, 0x01, 0x28, 0x05, 0x52, 0x01, 0x79, 0x12, 0x18, 0x0a, 0x07, 0x66, 0x72, 0x61, 0x6d, 0x65, + 0x49, 0x44, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x07, 0x66, 0x72, 0x61, 0x6d, 0x65, 0x49, + 0x44, 0x22, 0x69, 0x0a, 0x09, 0x49, 0x6e, 0x70, 0x75, 0x74, 0x44, 0x61, 0x74, 0x61, 0x12, 0x0e, + 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x04, 0x52, 0x02, 0x69, 0x64, 0x12, 0x10, + 0x0a, 0x03, 0x73, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x03, 0x73, 0x69, 0x64, + 0x12, 0x0c, 0x0a, 0x01, 0x78, 0x18, 0x03, 0x20, 0x01, 0x28, 0x05, 0x52, 0x01, 0x78, 0x12, 0x0c, + 0x0a, 0x01, 0x79, 0x18, 0x04, 0x20, 0x01, 0x28, 0x05, 0x52, 0x01, 0x79, 0x12, 0x1e, 0x0a, 0x0a, + 0x72, 0x6f, 0x6f, 0x6d, 0x73, 0x65, 0x61, 0x74, 0x69, 0x64, 0x18, 0x05, 0x20, 0x01, 0x28, 0x05, + 0x52, 0x0a, 0x72, 0x6f, 0x6f, 0x6d, 0x73, 0x65, 0x61, 0x74, 0x69, 0x64, 0x22, 0x4a, 0x0a, 0x09, + 0x46, 0x72, 0x61, 0x6d, 0x65, 0x44, 0x61, 0x74, 0x61, 0x12, 0x18, 0x0a, 0x07, 0x66, 0x72, 0x61, + 0x6d, 0x65, 0x49, 0x44, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x07, 0x66, 0x72, 0x61, 0x6d, + 0x65, 0x49, 0x44, 0x12, 0x23, 0x0a, 0x05, 0x69, 0x6e, 0x70, 0x75, 0x74, 0x18, 0x02, 0x20, 0x03, + 0x28, 0x0b, 0x32, 0x0d, 0x2e, 0x70, 0x62, 0x2e, 0x49, 0x6e, 0x70, 0x75, 0x74, 0x44, 0x61, 0x74, + 0x61, 0x52, 0x05, 0x69, 0x6e, 0x70, 0x75, 0x74, 0x22, 0x35, 0x0a, 0x0c, 0x53, 0x32, 0x43, 0x5f, + 0x46, 0x72, 0x61, 0x6d, 0x65, 0x4d, 0x73, 0x67, 0x12, 0x25, 0x0a, 0x06, 0x66, 0x72, 0x61, 0x6d, + 0x65, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0d, 0x2e, 0x70, 0x62, 0x2e, 0x46, 0x72, + 0x61, 0x6d, 0x65, 0x44, 0x61, 0x74, 0x61, 0x52, 0x06, 0x66, 0x72, 0x61, 0x6d, 0x65, 0x73, 0x22, + 0x2b, 0x0a, 0x0d, 0x43, 0x32, 0x53, 0x5f, 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x4d, 0x73, 0x67, + 0x12, 0x1a, 0x0a, 0x08, 0x77, 0x69, 0x6e, 0x6e, 0x65, 0x72, 0x49, 0x44, 0x18, 0x01, 0x20, 0x01, + 0x28, 0x04, 0x52, 0x08, 0x77, 0x69, 0x6e, 0x6e, 0x65, 0x72, 0x49, 0x44, 0x2a, 0xc4, 0x01, 0x0a, + 0x02, 0x49, 0x44, 0x12, 0x0d, 0x0a, 0x09, 0x4d, 0x53, 0x47, 0x5f, 0x42, 0x45, 0x47, 0x49, 0x4e, + 0x10, 0x00, 0x12, 0x0f, 0x0a, 0x0b, 0x4d, 0x53, 0x47, 0x5f, 0x43, 0x6f, 0x6e, 0x6e, 0x65, 0x63, + 0x74, 0x10, 0x01, 0x12, 0x11, 0x0a, 0x0d, 0x4d, 0x53, 0x47, 0x5f, 0x48, 0x65, 0x61, 0x72, 0x74, + 0x62, 0x65, 0x61, 0x74, 0x10, 0x02, 0x12, 0x10, 0x0a, 0x0c, 0x4d, 0x53, 0x47, 0x5f, 0x4a, 0x6f, + 0x69, 0x6e, 0x52, 0x6f, 0x6f, 0x6d, 0x10, 0x0a, 0x12, 0x10, 0x0a, 0x0c, 0x4d, 0x53, 0x47, 0x5f, + 0x50, 0x72, 0x6f, 0x67, 0x72, 0x65, 0x73, 0x73, 0x10, 0x14, 0x12, 0x0d, 0x0a, 0x09, 0x4d, 0x53, + 0x47, 0x5f, 0x52, 0x65, 0x61, 0x64, 0x79, 0x10, 0x1e, 0x12, 0x0d, 0x0a, 0x09, 0x4d, 0x53, 0x47, + 0x5f, 0x53, 0x74, 0x61, 0x72, 0x74, 0x10, 0x28, 0x12, 0x0d, 0x0a, 0x09, 0x4d, 0x53, 0x47, 0x5f, + 0x46, 0x72, 0x61, 0x6d, 0x65, 0x10, 0x32, 0x12, 0x0d, 0x0a, 0x09, 0x4d, 0x53, 0x47, 0x5f, 0x49, + 0x6e, 0x70, 0x75, 0x74, 0x10, 0x3c, 0x12, 0x0e, 0x0a, 0x0a, 0x4d, 0x53, 0x47, 0x5f, 0x52, 0x65, + 0x73, 0x75, 0x6c, 0x74, 0x10, 0x46, 0x12, 0x0d, 0x0a, 0x09, 0x4d, 0x53, 0x47, 0x5f, 0x43, 0x6c, + 0x6f, 0x73, 0x65, 0x10, 0x64, 0x12, 0x0c, 0x0a, 0x07, 0x4d, 0x53, 0x47, 0x5f, 0x45, 0x4e, 0x44, + 0x10, 0xff, 0x01, 0x2a, 0x5b, 0x0a, 0x09, 0x45, 0x52, 0x52, 0x4f, 0x52, 0x43, 0x4f, 0x44, 0x45, + 0x12, 0x0a, 0x0a, 0x06, 0x45, 0x52, 0x52, 0x5f, 0x4f, 0x6b, 0x10, 0x00, 0x12, 0x10, 0x0a, 0x0c, + 0x45, 0x52, 0x52, 0x5f, 0x4e, 0x6f, 0x50, 0x6c, 0x61, 0x79, 0x65, 0x72, 0x10, 0x01, 0x12, 0x0e, + 0x0a, 0x0a, 0x45, 0x52, 0x52, 0x5f, 0x4e, 0x6f, 0x52, 0x6f, 0x6f, 0x6d, 0x10, 0x02, 0x12, 0x11, + 0x0a, 0x0d, 0x45, 0x52, 0x52, 0x5f, 0x52, 0x6f, 0x6f, 0x6d, 0x53, 0x74, 0x61, 0x74, 0x65, 0x10, + 0x03, 0x12, 0x0d, 0x0a, 0x09, 0x45, 0x52, 0x52, 0x5f, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x10, 0x04, +} + +var ( + file_message_proto_rawDescOnce sync.Once + file_message_proto_rawDescData = file_message_proto_rawDesc +) + +func file_message_proto_rawDescGZIP() []byte { + file_message_proto_rawDescOnce.Do(func() { + file_message_proto_rawDescData = protoimpl.X.CompressGZIP(file_message_proto_rawDescData) + }) + return file_message_proto_rawDescData +} + +var file_message_proto_enumTypes = make([]protoimpl.EnumInfo, 2) +var file_message_proto_msgTypes = make([]protoimpl.MessageInfo, 11) +var file_message_proto_goTypes = []interface{}{ + (ID)(0), // 0: pb.ID + (ERRORCODE)(0), // 1: pb.ERRORCODE + (*C2S_ConnectMsg)(nil), // 2: pb.C2S_ConnectMsg + (*S2C_ConnectMsg)(nil), // 3: pb.S2C_ConnectMsg + (*S2C_JoinRoomMsg)(nil), // 4: pb.S2C_JoinRoomMsg + (*S2C_StartMsg)(nil), // 5: pb.S2C_StartMsg + (*C2S_ProgressMsg)(nil), // 6: pb.C2S_ProgressMsg + (*S2C_ProgressMsg)(nil), // 7: pb.S2C_ProgressMsg + (*C2S_InputMsg)(nil), // 8: pb.C2S_InputMsg + (*InputData)(nil), // 9: pb.InputData + (*FrameData)(nil), // 10: pb.FrameData + (*S2C_FrameMsg)(nil), // 11: pb.S2C_FrameMsg + (*C2S_ResultMsg)(nil), // 12: pb.C2S_ResultMsg +} +var file_message_proto_depIdxs = []int32{ + 1, // 0: pb.S2C_ConnectMsg.errorCode:type_name -> pb.ERRORCODE + 9, // 1: pb.FrameData.input:type_name -> pb.InputData + 10, // 2: pb.S2C_FrameMsg.frames:type_name -> pb.FrameData + 3, // [3:3] is the sub-list for method output_type + 3, // [3:3] is the sub-list for method input_type + 3, // [3:3] is the sub-list for extension type_name + 3, // [3:3] is the sub-list for extension extendee + 0, // [0:3] is the sub-list for field type_name +} + +func init() { file_message_proto_init() } +func file_message_proto_init() { + if File_message_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_message_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*C2S_ConnectMsg); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_message_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*S2C_ConnectMsg); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_message_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*S2C_JoinRoomMsg); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_message_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*S2C_StartMsg); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_message_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*C2S_ProgressMsg); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_message_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*S2C_ProgressMsg); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_message_proto_msgTypes[6].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*C2S_InputMsg); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_message_proto_msgTypes[7].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*InputData); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_message_proto_msgTypes[8].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*FrameData); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_message_proto_msgTypes[9].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*S2C_FrameMsg); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_message_proto_msgTypes[10].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*C2S_ResultMsg); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_message_proto_rawDesc, + NumEnums: 2, + NumMessages: 11, + NumExtensions: 0, + NumServices: 0, + }, + GoTypes: file_message_proto_goTypes, + DependencyIndexes: file_message_proto_depIdxs, + EnumInfos: file_message_proto_enumTypes, + MessageInfos: file_message_proto_msgTypes, + }.Build() + File_message_proto = out.File + file_message_proto_rawDesc = nil + file_message_proto_goTypes = nil + file_message_proto_depIdxs = nil } diff --git a/pb/message.proto b/pb/message.proto index ffdd3cb..4ad3e4d 100644 --- a/pb/message.proto +++ b/pb/message.proto @@ -1,3 +1,4 @@ +syntax = "proto2"; package pb; diff --git a/room/manager.go b/room/manager.go index 1a95a62..00466ce 100644 --- a/room/manager.go +++ b/room/manager.go @@ -1,63 +1,73 @@ package room import ( + "fmt" "sync" ) -var ( +// RoomManager 房间管理器 +type RoomManager struct { room map[uint64]*Room wg sync.WaitGroup rw sync.RWMutex -) +} -func init() { - room = make(map[uint64]*Room) +// NewRoomManager 构造 +func NewRoomManager() *RoomManager { + m := &RoomManager{ + room: make(map[uint64]*Room), + } + return m } -func CreateRoom(id uint64, typeID int32, playerID []uint64, randomSeed int32, logicServer string) (*Room, bool) { - rw.Lock() - defer rw.Unlock() +// CreateRoom 创建房间 +func (m *RoomManager) CreateRoom(id uint64, typeID int32, playerID []uint64, randomSeed int32, logicServer string) (*Room, error) { + m.rw.Lock() + defer m.rw.Unlock() - r, ok := room[id] + r, ok := m.room[id] if ok { - return nil, false + return nil, fmt.Errorf("room id[%d] exists", id) } r = NewRoom(id, typeID, playerID, randomSeed, logicServer) - room[id] = r + m.room[id] = r go func() { - wg.Add(1) + m.wg.Add(1) defer func() { - rw.Lock() - delete(room, id) - rw.Unlock() + m.rw.Lock() + delete(m.room, id) + m.rw.Unlock() - wg.Done() + m.wg.Done() }() r.Run() }() - return r, true + return r, nil } -func GetRoom(id uint64) *Room { +// GetRoom 获得房间 +func (m *RoomManager) GetRoom(id uint64) *Room { - rw.RLock() - defer rw.RUnlock() + m.rw.RLock() + defer m.rw.RUnlock() - r, _ := room[id] + r, _ := m.room[id] return r } -func Stop() { - rw.Lock() - for _, v := range room { +// Stop 停止 +func (m *RoomManager) Stop() { + + m.rw.Lock() + for _, v := range m.room { v.Stop() } - room = make(map[uint64]*Room) - rw.Unlock() + m.room = make(map[uint64]*Room) + m.rw.Unlock() - wg.Wait() + m.wg.Wait() } diff --git a/room/router.go b/router/router.go similarity index 82% rename from room/router.go rename to router/router.go index 1819b2a..7458683 100644 --- a/room/router.go +++ b/router/router.go @@ -1,4 +1,4 @@ -package room +package router import ( "sync/atomic" @@ -7,6 +7,7 @@ import ( "github.com/byebyebruce/lockstepserver/network" "github.com/byebyebruce/lockstepserver/pb" "github.com/byebyebruce/lockstepserver/protocol" + "github.com/byebyebruce/lockstepserver/room" l4g "github.com/alecthomas/log4go" ) @@ -16,18 +17,29 @@ func verifyToken(secret string) string { return secret } +// Router 消息路由器 type Router struct { + m *room.RoomManager totalConn uint64 } -func (m *Router) OnConnect(conn *network.Conn) bool { +// New 构造 +func New(m *room.RoomManager) *Router { + return &Router{ + m: m, + } +} + +// OnConnect 链接进来 +func (r *Router) OnConnect(conn *network.Conn) bool { - id := atomic.AddUint64(&m.totalConn, 1) + id := atomic.AddUint64(&r.totalConn, 1) l4g.Debug("[router] OnConnect [%s] totalConn=%d", conn.GetRawConn().RemoteAddr().String(), id) return true } -func (m *Router) OnMessage(conn *network.Conn, p network.Packet) bool { +// OnMessage 消息处理 +func (r *Router) OnMessage(conn *network.Conn, p network.Packet) bool { msg := p.(*protocol.Packet) @@ -53,7 +65,7 @@ func (m *Router) OnMessage(conn *network.Conn, p network.Packet) bool { ErrorCode: pb.ERRORCODE_ERR_Ok.Enum(), } - room := GetRoom(roomID) + room := r.m.GetRoom(roomID) if nil == room { ret.ErrorCode = pb.ERRORCODE_ERR_NoRoom.Enum() conn.AsyncWritePacket(protocol.NewPacket(uint8(pb.ID_MSG_Connect), ret), time.Millisecond) @@ -97,17 +109,16 @@ func (m *Router) OnMessage(conn *network.Conn, p network.Packet) bool { // 正式版不会提供这个消息 conn.AsyncWritePacket(protocol.NewPacket(uint8(pb.ID_MSG_END), msg.GetData()), time.Millisecond) return true - default: - return false } return false } -func (m *Router) OnClose(conn *network.Conn) { - id := atomic.LoadUint64(&m.totalConn) - 1 - atomic.StoreUint64(&m.totalConn, id) +// OnClose 链接断开 +func (r *Router) OnClose(conn *network.Conn) { + id := atomic.LoadUint64(&r.totalConn) - 1 + atomic.StoreUint64(&r.totalConn, id) l4g.Info("[router] OnClose: total=%d", id) }