完善机器人

This commit is contained in:
flswld
2023-05-13 20:40:40 +08:00
parent 9f10142c47
commit 0bc54baf12
9 changed files with 163 additions and 62 deletions

View File

@@ -150,6 +150,7 @@ func (k *KcpConnectManager) acceptHandle(listener *kcp.Listener) {
}
conn.SetACKNoDelay(true)
conn.SetWriteDelay(false)
conn.SetWindowSize(255, 255)
atomic.AddInt32(&CLIENT_CONN_NUM, 1)
logger.Info("client connect, convId: %v", convId)
kcpRawSendChan := make(chan *ProtoMsg, 1000)

View File

@@ -94,7 +94,13 @@ func EncodePayloadToBin(kcpMsg *KcpMsg, xorKey []byte) (bin []byte) {
if kcpMsg.ProtoData == nil {
kcpMsg.ProtoData = make([]byte, 0)
}
bin = make([]byte, len(kcpMsg.HeadData)+len(kcpMsg.ProtoData)+12)
// 检查长度
packetLen := len(kcpMsg.HeadData) + len(kcpMsg.ProtoData) + 12
if packetLen > PacketMaxLen {
logger.Error("packet len too long")
return make([]byte, 0)
}
bin = make([]byte, packetLen)
// 头部幻数
bin[0] = 0x45
bin[1] = 0x67