This commit is contained in:
aozhiwei 2023-08-10 11:01:59 +08:00
parent 1b5450d505
commit a6cca0a465
6 changed files with 77 additions and 23 deletions

View File

@ -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 {
}
}
}
}

View File

@ -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(

View File

@ -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

View File

@ -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"

View File

@ -0,0 +1,7 @@
package mtb
import "fmt"
type Server struct {
Listen_port int
}

View File

@ -31,14 +31,16 @@ class ClientNet {
async init() {
{
this.protoPb = await (new protobuf.Root()).load(this.protoPbFile,
this.protoPb = await (new protobuf.Root()).load
(this.protoPbFile,
{
'keepCase': true
}
);
}
{
this.msgIdPb = await (new protobuf.Root()).load(this.msgIdPbFile,
this.msgIdPb = await (new protobuf.Root()).load
(this.msgIdPbFile,
{
'keepCase': true
}
@ -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);
}