This commit is contained in:
@@ -27,7 +27,7 @@ func (*ServerHandler) Kick(_ context.Context, userid uint32) error {
|
||||
|
||||
cl, ok := cool.GetClient(useid1)
|
||||
if !ok {
|
||||
return fmt.Errorf("server not found")
|
||||
return nil
|
||||
}
|
||||
cl.KickPerson(userid) //实现指定服务器踢人
|
||||
return nil
|
||||
|
||||
@@ -72,7 +72,7 @@ func (s *Server) OnClose(c gnet.Conn, err error) (action gnet.Action) {
|
||||
|
||||
//logging.Infof("conn[%v] disconnected", c.RemoteAddr().String())
|
||||
v, _ := c.Context().(*player.ClientData)
|
||||
v.LF.Close() //关闭继续接受
|
||||
|
||||
if v.Player != nil {
|
||||
v.Player.Save() //保存玩家数据
|
||||
|
||||
@@ -161,13 +161,9 @@ func (s *Server) OnTraffic(c gnet.Conn) (action gnet.Action) {
|
||||
return
|
||||
}
|
||||
|
||||
t := c.Context().(*player.ClientData)
|
||||
for _, msg := range messages {
|
||||
|
||||
if t.LF.Running() {
|
||||
t.LF.Producer().Write(msg.Payload)
|
||||
}
|
||||
|
||||
s.onevent(c, msg.Payload)
|
||||
//t.OnEvent(msg.Payload)
|
||||
}
|
||||
|
||||
@@ -189,13 +185,7 @@ func (s *Server) handleTCP(conn gnet.Conn) (action gnet.Action) {
|
||||
return gnet.Close
|
||||
|
||||
}
|
||||
|
||||
if t, ok := conn.Context().(*player.ClientData); ok {
|
||||
if t.LF.Running() {
|
||||
t.LF.Producer().Write(data)
|
||||
}
|
||||
|
||||
}
|
||||
s.onevent(conn, data)
|
||||
|
||||
if conn.InboundBuffered() > 0 {
|
||||
if err := conn.Wake(nil); err != nil { // wake up the connection manually to avoid missing the leftover data
|
||||
@@ -233,3 +223,12 @@ func handle(c gnet.Conn) {
|
||||
|
||||
//return
|
||||
}
|
||||
|
||||
func (s *Server) onevent(c gnet.Conn, data []byte) {
|
||||
if t, ok := c.Context().(*player.ClientData); ok {
|
||||
s.workerPool.Submit(func() { //提交任务
|
||||
t.OnEvent(data)
|
||||
})
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,6 @@ import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
|
||||
"github.com/bruceshao/lockfree"
|
||||
"github.com/gobwas/ws"
|
||||
"github.com/gobwas/ws/wsutil"
|
||||
"github.com/gogf/gf/v2/os/glog"
|
||||
@@ -138,7 +137,7 @@ type ClientData struct {
|
||||
Wsmsg *WsCodec
|
||||
Conn gnet.Conn
|
||||
//SaveL sync.Once //保存锁
|
||||
LF *lockfree.Lockfree[[]byte]
|
||||
|
||||
//SaveDone chan struct{}
|
||||
}
|
||||
|
||||
@@ -151,15 +150,7 @@ func NewClientData(c gnet.Conn) *ClientData {
|
||||
Conn: c,
|
||||
Wsmsg: &WsCodec{},
|
||||
}
|
||||
cd.LF = lockfree.NewLockfree[[]byte](
|
||||
8,
|
||||
cd,
|
||||
lockfree.NewConditionBlockStrategy(),
|
||||
)
|
||||
// 启动Lockfree
|
||||
if err := cd.LF.Start(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return cd
|
||||
|
||||
}
|
||||
@@ -217,14 +208,7 @@ func XORDecrypt(encryptedData []byte, keyStr string) []byte {
|
||||
return decrypted
|
||||
}
|
||||
func (h *ClientData) OnEvent(v []byte) {
|
||||
defer func() {
|
||||
if err := recover(); err != nil { // 恢复 panic,err 为 panic 错误值
|
||||
// 1. 打印错误信息
|
||||
|
||||
cool.Logger.Error(context.TODO(), "panic 错误:", err)
|
||||
|
||||
}
|
||||
}()
|
||||
t, ok := h.Conn.Context().(*ClientData)
|
||||
if !ok {
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user