This commit is contained in:
@@ -27,8 +27,14 @@ func (s *Server) Boot(serverid, port uint16) error {
|
||||
gnet.WithMulticore(true),
|
||||
gnet.WithTicker(true),
|
||||
|
||||
// gnet.WithReusePort(true),
|
||||
// gnet.WithReuseAddr(true),
|
||||
// 其他调优配置↓
|
||||
gnet.WithTCPNoDelay(gnet.TCPNoDelay), // 禁用Nagle算法(降低延迟,适合小数据包场景)
|
||||
gnet.WithReusePort(true), // 开启SO_REUSEPORT(多核下提升并发)
|
||||
gnet.WithReadBufferCap(1024*64), // 读缓冲区64KB(根据业务调整,默认太小)
|
||||
gnet.WithWriteBufferCap(1024*64), // 写缓冲区64KB
|
||||
|
||||
gnet.WithLockOSThread(true), // 绑定goroutine到OS线程(减少上下文切换)
|
||||
|
||||
gnet.WithSocketRecvBuffer(s.bufferSize))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
|
||||
@@ -24,9 +24,9 @@ type Server struct {
|
||||
handler Handler
|
||||
discorse bool
|
||||
quit bool
|
||||
batchRead int
|
||||
serverid uint16
|
||||
port uint16
|
||||
// batchRead int
|
||||
serverid uint16
|
||||
port uint16
|
||||
}
|
||||
|
||||
type Option func(*Server)
|
||||
@@ -38,9 +38,9 @@ func NewServer(options ...Option) *Server {
|
||||
// handler: handler.NewTomeeHandler(), //请求返回
|
||||
codec: codec.NewTomeeSocketCodec(), //默认解码器 len+pack
|
||||
workerPool: goroutine.Default(),
|
||||
bufferSize: 4096, //默认缓冲区大小
|
||||
bufferSize: 40960, //默认缓冲区大小
|
||||
multicore: true,
|
||||
batchRead: 8,
|
||||
//batchRead: 8,
|
||||
//discorse: true,
|
||||
}
|
||||
for _, option := range options {
|
||||
|
||||
@@ -31,7 +31,6 @@ func (h Controller) Login(data *user.MAIN_LOGIN_IN, c gnet.Conn) (result *user.L
|
||||
return
|
||||
}
|
||||
|
||||
share.ShareManager.SetUserOnline(data.Head.UserID, h.Port) //设置用户登录服务器
|
||||
currentPlayer := player.GetPlayer(c, data.Head.UserID)
|
||||
if currentPlayer == nil {
|
||||
cool.Logger.Error(context.Background(), "获取玩家失败", data.Head.UserID)
|
||||
@@ -40,9 +39,10 @@ func (h Controller) Login(data *user.MAIN_LOGIN_IN, c gnet.Conn) (result *user.L
|
||||
return
|
||||
}
|
||||
currentPlayer.Service = service.NewUserService(data.Head.UserID)
|
||||
currentPlayer.Service.Info.Kick(data.Head.UserID)
|
||||
|
||||
currentPlayer.Info = currentPlayer.Service.Info.GetCache()
|
||||
|
||||
currentPlayer.Info = currentPlayer.Service.Info.SetLogin()
|
||||
share.ShareManager.SetUserOnline(data.Head.UserID, h.Port) //设置用户登录服务器
|
||||
if currentPlayer.Info == nil {
|
||||
defer c.Close()
|
||||
return
|
||||
|
||||
@@ -4,7 +4,6 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"blazing/cool"
|
||||
|
||||
@@ -71,24 +70,10 @@ func (c *BaseSysUserController) GetSession(ctx context.Context, req *SessionReq)
|
||||
res.PetID = dict.NewDictInfoService().GetShiny()
|
||||
res.Server = config.NewServerService().GetPort(int(t1.Debug))
|
||||
// share.ShareManager.DeleteSession(t1)
|
||||
ser := playerservice.NewUserService(uint32(t1.ID))
|
||||
|
||||
res.Session = blazing.NewInfoService(uint32(t.UserId)).Gensession()
|
||||
defer func() {
|
||||
kickErr := ser.Info.Kick(uint32(t1.ID))
|
||||
if kickErr != nil {
|
||||
fmt.Println("踢人失败", kickErr)
|
||||
|
||||
}
|
||||
logininfo := ser.Info.SetLogin()
|
||||
if logininfo != nil {
|
||||
|
||||
cool.CacheManager.Set(context.Background(), fmt.Sprintf("session:%d", uint32(t1.ID)), res.Session, 0)
|
||||
cool.CacheManager.Set(context.TODO(), fmt.Sprintf("player:%d", uint32(t1.ID)), logininfo, 10*time.Minute)
|
||||
|
||||
}
|
||||
}()
|
||||
|
||||
cool.CacheManager.Set(context.Background(), fmt.Sprintf("session:%d", uint32(t1.ID)), res.Session, 0)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,6 @@ import (
|
||||
"blazing/modules/player/model"
|
||||
"context"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
|
||||
"strings"
|
||||
|
||||
@@ -59,17 +58,7 @@ func (s *InfoService) Person(userid uint32) (out *model.Player) {
|
||||
return
|
||||
|
||||
}
|
||||
func (s *InfoService) GetCache() *model.PlayerInfo {
|
||||
|
||||
ret, _ := cool.CacheManager.Get(context.TODO(), fmt.Sprintf("player:%d", s.userid))
|
||||
if ret == nil {
|
||||
return nil
|
||||
}
|
||||
var rets *model.PlayerInfo
|
||||
ret.Struct(&rets)
|
||||
return rets
|
||||
|
||||
}
|
||||
func (s *InfoService) SetLogin() *model.PlayerInfo {
|
||||
|
||||
m := cool.DBM(s.Model).Where("player_id", s.userid)
|
||||
|
||||
Reference in New Issue
Block a user