diff --git a/server/imserver/WSPListener.go b/server/imserver/WSPListener.go index 8737e243..a1e4232d 100644 --- a/server/imserver/WSPListener.go +++ b/server/imserver/WSPListener.go @@ -2,15 +2,16 @@ package main import ( "net" + "fmt" ) -type GGListener_ struct { +type WSPListener_ struct { listener net.Listener } -var GGListener = new (GGListener_) +var WSPListener = new (WSPListener_) -func (this *GGListener_) Init() { +func (this *WSPListener_) Init() { listener, err := net.Listen("tcp", "0.0.0.0:8888") if err != nil { @@ -20,17 +21,54 @@ func (this *GGListener_) Init() { } } -func (this *GGListener_) UnInit() { +func (this *WSPListener_) UnInit() { } -func (this *GGListener_) accept() { +func (this *WSPListener_) accept() { + fmt.Println("accpet") for { conn, err := this.listener.Accept() if err == nil { + fmt.Println("connected") go this.socketRead(conn) } } } -func (this *GGListener_) socketRead(conn net.Conn) { +/* + struct PackHead + { + unsigned short packlen; + unsigned short msgid; + unsigned int seqid; + unsigned short magic_code; + unsigned short ext_len; + }; +*/ +func (this *WSPListener_) socketRead(conn net.Conn) { + buf := make([]byte, 1024 * 64) + //recvBuf := make([]byte, 1024 * 64) + offset := 0 + for { + bufLen, err := conn.Read(buf) + if err == nil && bufLen > 0 { + warning := false + for bufLen - offset >= 12 { + if buf[8] == 'K' && buf[9] == 'S' { + packLen := int(buf[0]) >> 16 + int(buf[1]) + if bufLen - offset < 12 + packLen { + continue + } + offset += 12 + packLen + } else { + warning = true + offset += 1 + continue + } + } + if warning { + + } + } + } } diff --git a/server/imserver/app.go b/server/imserver/app.go index e793f463..f5f26333 100644 --- a/server/imserver/app.go +++ b/server/imserver/app.go @@ -14,15 +14,16 @@ type App_ struct { var App = new (App_) - func (this *App_) Init() { f5.App = &this.App_ f5.App.SetPkgName("imserver") this.App_.Init() + WSPListener.Init() go this.goReportServerState(); } func (this *App_) UnInit() { + WSPListener.UnInit() this.App_.UnInit() } @@ -35,7 +36,7 @@ func (this *App_) goReportServerState() { params.SetXValue("port", q5.NewXInt32(8888)) params.SetXValue("online_num", q5.NewXInt32(1)) params.SetXValue("room_num", q5.NewXInt32(1)) - params.SetXValue("channel", q5.NewXInt32(1)) + params.SetXValue("channel", q5.NewXInt32(0)) params.SetXValue("alive_count", q5.NewXInt32(1)) params.SetXValue("servicing", q5.NewXInt32(1)) _, err := q5.HttpGet( diff --git a/server/imserver/go.mod b/server/imserver/go.mod index 1af90085..3fce90d4 100644 --- a/server/imserver/go.mod +++ b/server/imserver/go.mod @@ -6,6 +6,8 @@ require q5 v1.0.0 // indirect require f5 v1.0.0 +require mtb v1.0.0 + require ( github.com/go-sql-driver/mysql v1.5.0 // indirect github.com/golang/protobuf v1.4.2 // indirect @@ -16,3 +18,5 @@ require ( replace q5 => ../../third_party/q5 replace f5 => ../../third_party/f5 + +replace mtb => ./mtb \ No newline at end of file diff --git a/server/imserver/makefile b/server/imserver/makefile index 291bc14c..d016953e 100644 --- a/server/imserver/makefile +++ b/server/imserver/makefile @@ -1,6 +1,7 @@ compile: @. /etc/profile + protoc --proto_path=proto --go_out=./mtb proto/mt.proto @export GOPROXY=https://goproxy.io @go build -gcflags=all="-N -l" -o ../../bin/imserver/ @echo "compile done" diff --git a/server/imserver/mtb/mt.go b/server/imserver/mtb/mt.go new file mode 100644 index 00000000..ed0da4f4 --- /dev/null +++ b/server/imserver/mtb/mt.go @@ -0,0 +1,7 @@ +package mtb + +import "fmt" + +type Server struct { + Listen_port int +} diff --git a/tools/robot/clientnet.js b/tools/robot/clientnet.js index f10e2759..6eb3eedb 100644 --- a/tools/robot/clientnet.js +++ b/tools/robot/clientnet.js @@ -31,18 +31,20 @@ class ClientNet { async init() { { - this.protoPb = await (new protobuf.Root()).load(this.protoPbFile, - { - 'keepCase': true - } - ); + this.protoPb = await (new protobuf.Root()).load + (this.protoPbFile, + { + 'keepCase': true + } + ); } { - this.msgIdPb = await (new protobuf.Root()).load(this.msgIdPbFile, - { - 'keepCase': true - } - ); + this.msgIdPb = await (new protobuf.Root()).load + (this.msgIdPbFile, + { + 'keepCase': true + } + ); this.cmMsgId = this.msgIdPb.lookup('CMMessageId_e'); this.smMsgId = this.msgIdPb.lookup('SMMessageId_e'); } @@ -152,11 +154,12 @@ class ClientNet { const msgBuf = msgType.encode(msg).finish(); let buf = Buffer.alloc(12); - buf.writeUInt32LE(msgBuf.length, 0); - buf.writeUInt16LE(msgId, 4); - buf.writeUInt8('K'.charCodeAt(0), 6); - buf.writeUInt8('S'.charCodeAt(0), 7); - buf.writeInt32LE(0, 8); + buf.writeUInt16LE(msgBuf.length, 0); + buf.writeUInt16LE(msgId, 2); + buf.writeUInt32LE(0, 4); + buf.writeUInt8('K'.charCodeAt(0), 8); + buf.writeUInt8('S'.charCodeAt(0), 9); + buf.writeUInt16LE(0, 10); this.conn.sendBinary(Buffer.concat([buf, msgBuf])); console.log(name, msg, (Buffer.concat([buf, msgBuf])).length); }