From bce3a2fed227e8705bf222134515b991a64617f6 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Thu, 10 Aug 2023 19:13:34 +0800 Subject: [PATCH] 1 --- server/imserver/app.go | 21 +++++++++++++++++++++ server/imserver/constant.go | 5 +++++ server/imserver/cs/cs.generate.go | 26 ++++++++++++++++++++++++++ server/imserver/makefile | 2 ++ server/imserver/playermgr.go | 11 +++++++++++ 5 files changed, 65 insertions(+) create mode 100644 server/imserver/constant.go create mode 100644 server/imserver/playermgr.go diff --git a/server/imserver/app.go b/server/imserver/app.go index a5d97141..b6a15254 100644 --- a/server/imserver/app.go +++ b/server/imserver/app.go @@ -7,12 +7,14 @@ import ( "q5" "f5" + "cs" ) type App_ struct { f5.App_ msgMutex sync.Mutex msgList q5.ListHead + workList q5.ListHead } var App = new (App_) @@ -22,6 +24,7 @@ func (this *App_) Init() { f5.App.SetPkgName("imserver") this.App_.Init(this.Update) this.msgList.Init(nil) + this.workList.Init(nil) WSPListener.Init() go this.goReportServerState(); } @@ -32,6 +35,24 @@ func (this *App_) UnInit() { } func (this *App_) Update() { + if this.workList.Empty() { + this.msgMutex.Lock() + defer this.msgMutex.Unlock() + if !this.msgList.Empty() { + this.msgList.ReplaceInit(&this.workList) + } + } + for !this.workList.Empty() { + next := this.workList.Next() + hdr, ok := next.GetData().(*MsgHdr) + if ok { + handlerId := cs.GetMsgHandlerId(hdr.msgId) + if handlerId == PLAYER_MGR_HANDLER_ID { + cs.ProcessNsgMsg(hdr.msgId, PlayerMgr) + } + } + next.Del() + } } func (this *App_) goReportServerState() { diff --git a/server/imserver/constant.go b/server/imserver/constant.go new file mode 100644 index 00000000..ec767481 --- /dev/null +++ b/server/imserver/constant.go @@ -0,0 +1,5 @@ +package main + +const ( + PLAYER_MGR_HANDLER_ID = iota +) diff --git a/server/imserver/cs/cs.generate.go b/server/imserver/cs/cs.generate.go index d5c20244..f932433c 100644 --- a/server/imserver/cs/cs.generate.go +++ b/server/imserver/cs/cs.generate.go @@ -3,3 +3,29 @@ package cs func ParsePb(msgId int, data []byte) interface{} { return nil } + +type MsgHandler interface { + CMPing(*CMPing) + CMLogin(*CMLogin) + CMReconnect(*CMReconnect) +} + +type MsgHandlerImpl struct { +} + +func (this *MsgHandlerImpl) CMPing(msg *CMPing) { +} + +func (this *MsgHandlerImpl) CMLogin(msg *CMLogin) { +} + +func (this *MsgHandlerImpl) CMReconnect(msg *CMReconnect) { +} + +func GetMsgHandlerId(msgId int) (int) { + return 0 +} + +func ProcessNsgMsg(msgId int, msgHandler MsgHandler) { + +} diff --git a/server/imserver/makefile b/server/imserver/makefile index d016953e..a68fd516 100644 --- a/server/imserver/makefile +++ b/server/imserver/makefile @@ -2,6 +2,8 @@ compile: @. /etc/profile protoc --proto_path=proto --go_out=./mtb proto/mt.proto + protoc --proto_path=proto --go_out=./cs proto/cs_msgid.proto + protoc --proto_path=proto --go_out=./cs proto/cs_proto.proto @export GOPROXY=https://goproxy.io @go build -gcflags=all="-N -l" -o ../../bin/imserver/ @echo "compile done" diff --git a/server/imserver/playermgr.go b/server/imserver/playermgr.go new file mode 100644 index 00000000..9f4ee9b3 --- /dev/null +++ b/server/imserver/playermgr.go @@ -0,0 +1,11 @@ +package main + +import ( + "cs" +) + +type PlayerMgr_ struct { + cs.MsgHandlerImpl +} + +var PlayerMgr = new (PlayerMgr_)