This commit is contained in:
aozhiwei 2023-08-10 19:30:44 +08:00
parent 0253d530ee
commit b7b090b625
3 changed files with 18 additions and 21 deletions

View File

@ -9,24 +9,15 @@ import (
"cs" "cs"
) )
type MsgHdr struct {
conn net.Conn
msgId int
seqId int
data []byte
msg interface{}
entry q5.ListHead
}
type WSPListener_ struct { type WSPListener_ struct {
listener net.Listener listener net.Listener
ch <-chan *MsgHdr ch <-chan *q5.MsgHdr
} }
var WSPListener = new (WSPListener_) var WSPListener = new (WSPListener_)
func (this *WSPListener_) Init() { func (this *WSPListener_) Init() {
this.ch = make(chan *MsgHdr) this.ch = make(chan *q5.MsgHdr)
listener, err := net.Listen("tcp", "0.0.0.0:8888") listener, err := net.Listen("tcp", "0.0.0.0:8888")
if err != nil { if err != nil {
@ -75,9 +66,9 @@ func (this *WSPListener_) socketRead(conn net.Conn) {
if bufLen - offset < 12 + packLen { if bufLen - offset < 12 + packLen {
continue continue
} }
hdr := new(MsgHdr) hdr := new(q5.MsgHdr)
hdr.msgId = int(buf[0]) >> 16 + int(buf[1]) hdr.MsgId = int(buf[0]) >> 16 + int(buf[1])
hdr.seqId = int(buf[0]) >> 16 + int(buf[1]) hdr.SeqId = int(buf[0]) >> 16 + int(buf[1])
offset += 12 + packLen offset += 12 + packLen
} else { } else {
warning = true warning = true
@ -95,8 +86,8 @@ func (this *WSPListener_) socketRead(conn net.Conn) {
func (this *WSPListener_) parseNetPkt() { func (this *WSPListener_) parseNetPkt() {
for { for {
if hdr, ok := <-this.ch; ok { if hdr, ok := <-this.ch; ok {
hdr.msg = cs.ParsePb(hdr.msgId, hdr.data) hdr.Msg = cs.ParsePb(hdr.MsgId, hdr.Data)
if hdr.msg != nil { if hdr.Msg != nil {
} }
} }

View File

@ -44,11 +44,11 @@ func (this *App_) Update() {
} }
for !this.workList.Empty() { for !this.workList.Empty() {
next := this.workList.Next() next := this.workList.Next()
hdr, ok := next.GetData().(*MsgHdr) hdr, ok := next.GetData().(*q5.MsgHdr)
if ok { if ok {
handlerId := cs.GetMsgHandlerId(hdr.msgId) handlerId := cs.GetMsgHandlerId(hdr.MsgId)
if handlerId == PLAYER_MGR_HANDLER_ID { if handlerId == PLAYER_MGR_HANDLER_ID {
cs.DispatchMsg(hdr.msgId, PlayerMgr) cs.DispatchMsg(hdr.MsgId, PlayerMgr)
} }
} }
next.Del() next.Del()
@ -76,11 +76,11 @@ func (this *App_) goReportServerState() {
} }
func (this *App_) addNetMsg(hdr *MsgHdr) { func (this *App_) addNetMsg(hdr *q5.MsgHdr) {
{ {
this.msgMutex.Lock() this.msgMutex.Lock()
defer this.msgMutex.Unlock() defer this.msgMutex.Unlock()
this.msgList.AddTail(&hdr.entry); this.msgList.AddTail(&hdr.Entry);
} }
this.NotifyLoopCond() this.NotifyLoopCond()
} }

View File

@ -13,6 +13,12 @@ type MsgHandler interface {
type MsgHandlerImpl struct { type MsgHandlerImpl struct {
} }
type NetMsgHandler struct {
MsgId int
HandlerId int
cb func(MsgHandler)
}
func (this *MsgHandlerImpl) CMPing(msg *CMPing) { func (this *MsgHandlerImpl) CMPing(msg *CMPing) {
} }