重构
This commit is contained in:
@@ -1,7 +1,6 @@
|
|||||||
package cool
|
package cool
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"blazing/common/data/entity"
|
|
||||||
"blazing/common/utils"
|
"blazing/common/utils"
|
||||||
"context"
|
"context"
|
||||||
"reflect"
|
"reflect"
|
||||||
@@ -14,8 +13,7 @@ import (
|
|||||||
var ctx = context.TODO()
|
var ctx = context.TODO()
|
||||||
|
|
||||||
var (
|
var (
|
||||||
Mainplayer = &utils.SyncMap[uint32, *entity.Player]{} //玩家数据
|
CmdCache = &utils.SyncMap[uint32, reflect.Value]{} //命令缓存
|
||||||
CmdCache = &utils.SyncMap[uint32, reflect.Value]{} //命令缓存
|
|
||||||
|
|
||||||
Loger = glog.New()
|
Loger = glog.New()
|
||||||
)
|
)
|
||||||
@@ -37,12 +35,3 @@ func init() {
|
|||||||
glog.Debug(context.Background(), "初始化雪花算法", newId)
|
glog.Debug(context.Background(), "初始化雪花算法", newId)
|
||||||
|
|
||||||
}
|
}
|
||||||
func ConutPlayer() int {
|
|
||||||
|
|
||||||
count := 0
|
|
||||||
Mainplayer.Range(func(uint32, *entity.Player) bool {
|
|
||||||
count++
|
|
||||||
return true // 继续遍历
|
|
||||||
})
|
|
||||||
return count
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,37 +0,0 @@
|
|||||||
package entity
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/gobwas/ws"
|
|
||||||
"github.com/gobwas/ws/wsutil"
|
|
||||||
"github.com/panjf2000/gnet/v2"
|
|
||||||
"github.com/panjf2000/gnet/v2/pkg/logging"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Conn struct {
|
|
||||||
MainConn gnet.Conn `struc:"[0]pad"` //TODO 不序列化,,序列化下面的作为blob存数据库
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewConn(c gnet.Conn) *Conn {
|
|
||||||
return &Conn{MainConn: c}
|
|
||||||
}
|
|
||||||
func (c *Conn) SendPack(bytes []byte) error {
|
|
||||||
if t, ok := c.MainConn.Context().(*ClientData); ok {
|
|
||||||
if t.Getwsmsg().Upgraded {
|
|
||||||
// This is the echo server
|
|
||||||
err := wsutil.WriteServerMessage(c.MainConn, ws.OpBinary, bytes)
|
|
||||||
if err != nil {
|
|
||||||
logging.Infof("conn[%v] [err=%v]", c.MainConn.RemoteAddr().String(), err.Error())
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
|
|
||||||
_, err := c.MainConn.Write(bytes)
|
|
||||||
if err != nil {
|
|
||||||
logging.Error(err)
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
package entity
|
|
||||||
@@ -1,6 +1,18 @@
|
|||||||
package entity
|
package socket
|
||||||
|
|
||||||
import "sync"
|
import (
|
||||||
|
"sync"
|
||||||
|
)
|
||||||
|
|
||||||
|
func ConutPlayer() int {
|
||||||
|
|
||||||
|
count := 0
|
||||||
|
Mainplayer.Range(func(uint32, *Player) bool {
|
||||||
|
count++
|
||||||
|
return true // 继续遍历
|
||||||
|
})
|
||||||
|
return count
|
||||||
|
}
|
||||||
|
|
||||||
type ClientData struct {
|
type ClientData struct {
|
||||||
isCrossDomain bool //是否跨域过
|
isCrossDomain bool //是否跨域过
|
||||||
@@ -1,24 +1,52 @@
|
|||||||
package entity
|
package socket
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"blazing/common/utils"
|
||||||
|
"blazing/modules/blazing/model"
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/gobwas/ws"
|
||||||
|
"github.com/gobwas/ws/wsutil"
|
||||||
"github.com/gogf/gf/v2/frame/g"
|
"github.com/gogf/gf/v2/frame/g"
|
||||||
|
"github.com/panjf2000/gnet/pkg/logging"
|
||||||
"github.com/tnnmigga/enum"
|
"github.com/tnnmigga/enum"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var Mainplayer = &utils.SyncMap[uint32, *Player]{} //玩家数据
|
||||||
|
|
||||||
|
func (c *Conn) SendPack(bytes []byte) error {
|
||||||
|
if t, ok := c.MainConn.Context().(*ClientData); ok {
|
||||||
|
if t.Getwsmsg().Upgraded {
|
||||||
|
// This is the echo server
|
||||||
|
err := wsutil.WriteServerMessage(c.MainConn, ws.OpBinary, bytes)
|
||||||
|
if err != nil {
|
||||||
|
logging.Infof("conn[%v] [err=%v]", c.MainConn.RemoteAddr().String(), err.Error())
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
|
||||||
|
_, err := c.MainConn.Write(bytes)
|
||||||
|
if err != nil {
|
||||||
|
logging.Error(err)
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
type Player struct {
|
type Player struct {
|
||||||
MainConn Conn
|
MainConn Conn
|
||||||
UserID uint32 //用户ID
|
|
||||||
IsLogin bool //是否登录
|
IsLogin bool //是否登录
|
||||||
mu sync.Mutex
|
mu sync.Mutex
|
||||||
MapId uint32 //当前所在的地图ID
|
|
||||||
|
|
||||||
loginChan chan struct{} // 登录完成通知通道
|
loginChan chan struct{} // 登录完成通知通道
|
||||||
Nick string //昵称
|
Info *model.PlayerInfo
|
||||||
StopChan chan struct{} //停止刷怪协程
|
StopChan chan struct{} //停止刷怪协程
|
||||||
IsFighting bool
|
IsFighting bool
|
||||||
context.Context
|
context.Context
|
||||||
@@ -28,12 +56,6 @@ type Player struct {
|
|||||||
// PlayerOption 定义配置 Player 的函数类型
|
// PlayerOption 定义配置 Player 的函数类型
|
||||||
type PlayerOption func(*Player)
|
type PlayerOption func(*Player)
|
||||||
|
|
||||||
// WithUserID 设置用户ID的选项函数
|
|
||||||
func WithUserID(userID uint32) PlayerOption {
|
|
||||||
return func(p *Player) {
|
|
||||||
p.UserID = userID
|
|
||||||
}
|
|
||||||
}
|
|
||||||
func WithConn(c Conn) PlayerOption {
|
func WithConn(c Conn) PlayerOption {
|
||||||
return func(p *Player) {
|
return func(p *Player) {
|
||||||
p.MainConn = c
|
p.MainConn = c
|
||||||
@@ -51,14 +73,6 @@ func NewPlayer(opts ...PlayerOption) *Player {
|
|||||||
return p
|
return p
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Player) GetUserID() uint32 {
|
|
||||||
return p.UserID
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *Player) SetData(key any) uint32 {
|
|
||||||
|
|
||||||
return p.UserID
|
|
||||||
}
|
|
||||||
func (p *Player) SendPack(b []byte) error {
|
func (p *Player) SendPack(b []byte) error {
|
||||||
fmt.Println("发送数据包", len(b))
|
fmt.Println("发送数据包", len(b))
|
||||||
err := p.MainConn.SendPack(b)
|
err := p.MainConn.SendPack(b)
|
||||||
@@ -66,7 +80,7 @@ func (p *Player) SendPack(b []byte) error {
|
|||||||
}
|
}
|
||||||
func (p *Player) Cheak(b error) {
|
func (p *Player) Cheak(b error) {
|
||||||
if b != nil {
|
if b != nil {
|
||||||
g.Log().Error(context.Background(), "出现错误", p.UserID, b.Error())
|
g.Log().Error(context.Background(), "出现错误", p.Info.UserID, b.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -150,10 +164,10 @@ type Playerinvite struct { //挂载到[]Playerinvite上? 被邀请者->邀请
|
|||||||
func (lw *Player) InvitePlayerToBattle(target int64, mode EnumBattleMode) {
|
func (lw *Player) InvitePlayerToBattle(target int64, mode EnumBattleMode) {
|
||||||
t, ok := Playerinvitemap[uint32(target)] //被邀请者是否被邀请过
|
t, ok := Playerinvitemap[uint32(target)] //被邀请者是否被邀请过
|
||||||
if ok { //说明存在被邀请
|
if ok { //说明存在被邀请
|
||||||
t = append(t, Playerinvite{uint32(lw.UserID), mode})
|
t = append(t, Playerinvite{uint32(lw.Info.UserID), mode})
|
||||||
Playerinvitemap[uint32(target)] = t
|
Playerinvitemap[uint32(target)] = t
|
||||||
} else {
|
} else {
|
||||||
Playerinvitemap[uint32(target)] = []Playerinvite{{uint32(lw.UserID), mode}}
|
Playerinvitemap[uint32(target)] = []Playerinvite{{uint32(lw.Info.UserID), mode}}
|
||||||
}
|
}
|
||||||
|
|
||||||
lw.Playerinvite = uint32(target)
|
lw.Playerinvite = uint32(target)
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package entity
|
package socket
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
@@ -11,6 +11,14 @@ import (
|
|||||||
"github.com/panjf2000/gnet/v2/pkg/logging"
|
"github.com/panjf2000/gnet/v2/pkg/logging"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type Conn struct {
|
||||||
|
MainConn gnet.Conn `struc:"[0]pad"` //TODO 不序列化,,序列化下面的作为blob存数据库
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewConn(c gnet.Conn) *Conn {
|
||||||
|
return &Conn{MainConn: c}
|
||||||
|
}
|
||||||
|
|
||||||
type WsCodec struct {
|
type WsCodec struct {
|
||||||
Upgraded bool // 链接是否升级
|
Upgraded bool // 链接是否升级
|
||||||
Buf bytes.Buffer // 从实际socket中读取到的数据缓存
|
Buf bytes.Buffer // 从实际socket中读取到的数据缓存
|
||||||
@@ -1 +0,0 @@
|
|||||||
package socket
|
|
||||||
@@ -6,9 +6,8 @@ import (
|
|||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"blazing/common/data/entity"
|
|
||||||
"blazing/common/data/share"
|
"blazing/common/data/share"
|
||||||
"blazing/cool"
|
"blazing/common/data/socket"
|
||||||
|
|
||||||
"github.com/gogf/gf/v2/os/glog"
|
"github.com/gogf/gf/v2/os/glog"
|
||||||
"github.com/panjf2000/gnet/v2"
|
"github.com/panjf2000/gnet/v2"
|
||||||
@@ -42,17 +41,17 @@ func (s *Server) Stop() error {
|
|||||||
func (s *Server) OnClose(c gnet.Conn, _ error) (action gnet.Action) {
|
func (s *Server) OnClose(c gnet.Conn, _ error) (action gnet.Action) {
|
||||||
atomic.AddInt64(&s.connected, -1)
|
atomic.AddInt64(&s.connected, -1)
|
||||||
//logging.Infof("conn[%v] disconnected", c.RemoteAddr().String())
|
//logging.Infof("conn[%v] disconnected", c.RemoteAddr().String())
|
||||||
v, ok := c.Context().(*entity.ClientData)
|
v, ok := c.Context().(*socket.ClientData)
|
||||||
if !ok {
|
if !ok {
|
||||||
return
|
return
|
||||||
|
|
||||||
}
|
}
|
||||||
t := v.GetPlayer()
|
t := v.GetPlayer()
|
||||||
if t != nil {
|
if v != nil {
|
||||||
glog.Debug(context.Background(), t.UserID, "断开连接")
|
glog.Debug(context.Background(), t, "断开连接")
|
||||||
t.IsLogin = false
|
t.IsLogin = false
|
||||||
cool.Mainplayer.Delete(t.UserID)
|
socket.Mainplayer.Delete(t.Info.UserID)
|
||||||
share.ShareManager.DeleteUserOnline(t.UserID) //设置用户登录服务器
|
share.ShareManager.DeleteUserOnline(t.Info.UserID) //设置用户登录服务器
|
||||||
}
|
}
|
||||||
|
|
||||||
//}
|
//}
|
||||||
@@ -73,7 +72,7 @@ func (s *Server) OnBoot(eng gnet.Engine) gnet.Action {
|
|||||||
|
|
||||||
func (s *Server) OnOpen(conn gnet.Conn) (out []byte, action gnet.Action) {
|
func (s *Server) OnOpen(conn gnet.Conn) (out []byte, action gnet.Action) {
|
||||||
if conn.Context() == nil {
|
if conn.Context() == nil {
|
||||||
conn.SetContext(entity.NewClientData()) //注入data
|
conn.SetContext(socket.NewClientData()) //注入data
|
||||||
}
|
}
|
||||||
|
|
||||||
atomic.AddInt64(&s.connected, 1)
|
atomic.AddInt64(&s.connected, 1)
|
||||||
@@ -86,7 +85,7 @@ func (s *Server) OnTraffic(c gnet.Conn) (action gnet.Action) {
|
|||||||
return gnet.Close
|
return gnet.Close
|
||||||
}
|
}
|
||||||
|
|
||||||
ws := c.Context().(*entity.ClientData).Getwsmsg()
|
ws := c.Context().(*socket.ClientData).Getwsmsg()
|
||||||
tt, len1 := ws.ReadBufferBytes(c)
|
tt, len1 := ws.ReadBufferBytes(c)
|
||||||
if tt == gnet.Close {
|
if tt == gnet.Close {
|
||||||
|
|
||||||
@@ -165,7 +164,7 @@ const CROSS_DOMAIN = "<?xml version=\"1.0\"?><!DOCTYPE cross-domain-policy><cros
|
|||||||
const TEXT = "<policy-file-request/>\x00"
|
const TEXT = "<policy-file-request/>\x00"
|
||||||
|
|
||||||
func handle(c gnet.Conn) {
|
func handle(c gnet.Conn) {
|
||||||
clientdata := c.Context().(*entity.ClientData)
|
clientdata := c.Context().(*socket.ClientData)
|
||||||
if clientdata.GetIsCrossDomain() {
|
if clientdata.GetIsCrossDomain() {
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package handler
|
package handler
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"blazing/common/data/entity"
|
"blazing/common/data/socket"
|
||||||
"blazing/common/utils/bytearray"
|
"blazing/common/utils/bytearray"
|
||||||
|
|
||||||
"bytes"
|
"bytes"
|
||||||
@@ -37,7 +37,7 @@ func NewTomeeHeader(cmd uint32, userid uint32) *TomeeHeader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type TomeeHandler struct {
|
type TomeeHandler struct {
|
||||||
Callback func(conn *entity.Conn, data TomeeHeader)
|
Callback func(conn *socket.Conn, data TomeeHeader)
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewTomeeHandler() *TomeeHandler {
|
func NewTomeeHandler() *TomeeHandler {
|
||||||
@@ -60,7 +60,7 @@ func (h *TomeeHandler) Handle(c gnet.Conn, data []byte) { //处理接收到的
|
|||||||
header.Result, _ = tempdata.ReadUInt32()
|
header.Result, _ = tempdata.ReadUInt32()
|
||||||
header.Data = tempdata.BytesAvailable()
|
header.Data = tempdata.BytesAvailable()
|
||||||
//fmt.Println("接收封包", header)
|
//fmt.Println("接收封包", header)
|
||||||
h.Callback(entity.NewConn(c), header)
|
h.Callback(socket.NewConn(c), header)
|
||||||
//return header
|
//return header
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
package controller
|
package controller
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"blazing/common/data/entity"
|
"blazing/common/data/socket"
|
||||||
"blazing/common/socket/errorcode"
|
"blazing/common/socket/errorcode"
|
||||||
"blazing/logic/service/login"
|
"blazing/logic/service/login"
|
||||||
"blazing/modules/blazing/service"
|
"blazing/modules/blazing/service"
|
||||||
)
|
)
|
||||||
|
|
||||||
// 处理命令: 1001
|
// 处理命令: 1001
|
||||||
func (h *Controller) CreatePlayer(data *login.CreatePlayerInboundInfo, c *entity.Conn) (result *login.CreatePlayerOutInfo, err errorcode.ErrorCode) {
|
func (h *Controller) CreatePlayer(data *login.CreatePlayerInboundInfo, c *socket.Conn) (result *login.CreatePlayerOutInfo, err errorcode.ErrorCode) {
|
||||||
|
|
||||||
service.NewUserService(data.Head.UserID).Reg(data.Nickname, data.Color)
|
service.NewUserService(data.Head.UserID).Reg(data.Nickname, data.Color)
|
||||||
return result, 0
|
return result, 0
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
package controller
|
package controller
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"blazing/common/data/entity"
|
"blazing/common/data/socket"
|
||||||
"blazing/common/socket/errorcode"
|
"blazing/common/socket/errorcode"
|
||||||
"blazing/logic/service/friend"
|
"blazing/logic/service/friend"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (h Controller) OnSeeOnline(data *friend.SeeOnlineInboundInfo, c *entity.Player) (result *friend.SeeOnlineOutboundInfo, err errorcode.ErrorCode) {
|
func (h Controller) OnSeeOnline(data *friend.SeeOnlineInboundInfo, c *socket.Player) (result *friend.SeeOnlineOutboundInfo, err errorcode.ErrorCode) {
|
||||||
result = &friend.SeeOnlineOutboundInfo{}
|
result = &friend.SeeOnlineOutboundInfo{}
|
||||||
result.Friends = make([]friend.OnlineInfo, 0)
|
result.Friends = make([]friend.OnlineInfo, 0)
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package controller
|
package controller
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"blazing/common/data/entity"
|
"blazing/common/data/socket"
|
||||||
"blazing/common/socket/errorcode"
|
"blazing/common/socket/errorcode"
|
||||||
"blazing/common/socket/handler"
|
"blazing/common/socket/handler"
|
||||||
"blazing/cool"
|
"blazing/cool"
|
||||||
@@ -50,9 +50,9 @@ func (h *LogicClient) QuitSelf(a int) error {
|
|||||||
for {
|
for {
|
||||||
|
|
||||||
//entity.ConutPlayer()
|
//entity.ConutPlayer()
|
||||||
fmt.Println("当前在线人数", cool.ConutPlayer())
|
fmt.Println("当前在线人数", socket.ConutPlayer())
|
||||||
|
|
||||||
if cool.ConutPlayer() <= 0 {
|
if socket.ConutPlayer() <= 0 {
|
||||||
//执行退出逻辑
|
//执行退出逻辑
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
@@ -158,7 +158,7 @@ func getcmd(t reflect.Type) []uint32 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 遍历结构体方法并执行RECV_cmd
|
// 遍历结构体方法并执行RECV_cmd
|
||||||
func Recv(c *entity.Conn, data handler.TomeeHeader) {
|
func Recv(c *socket.Conn, data handler.TomeeHeader) {
|
||||||
|
|
||||||
cmdlister, ok := cool.CmdCache.Load(data.CMD)
|
cmdlister, ok := cool.CmdCache.Load(data.CMD)
|
||||||
if !ok {
|
if !ok {
|
||||||
@@ -189,7 +189,7 @@ func Recv(c *entity.Conn, data handler.TomeeHeader) {
|
|||||||
if nameField.IsValid() && nameField.CanSet() {
|
if nameField.IsValid() && nameField.CanSet() {
|
||||||
nameField.Set(reflect.ValueOf(data))
|
nameField.Set(reflect.ValueOf(data))
|
||||||
}
|
}
|
||||||
if cmdlister.Type().In(1) == reflect.TypeOf(&entity.Player{}) {
|
if cmdlister.Type().In(1) == reflect.TypeOf(&socket.Player{}) {
|
||||||
c1 := service.GetPlayer(c, data.UserID)
|
c1 := service.GetPlayer(c, data.UserID)
|
||||||
err := c1.WaitForLoginWithCtx(context.Background())
|
err := c1.WaitForLoginWithCtx(context.Background())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package controller
|
package controller
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"blazing/common/data/entity"
|
"blazing/common/data/socket"
|
||||||
"blazing/common/socket/errorcode"
|
"blazing/common/socket/errorcode"
|
||||||
"blazing/common/socket/handler"
|
"blazing/common/socket/handler"
|
||||||
"blazing/logic/service/fight"
|
"blazing/logic/service/fight"
|
||||||
@@ -9,14 +9,14 @@ import (
|
|||||||
"blazing/modules/blazing/model"
|
"blazing/modules/blazing/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (h Controller) OnPlayerFightNpcMonster(data *fight.FightNpcMonsterInboundInfo, c *entity.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
|
func (h Controller) OnPlayerFightNpcMonster(data *fight.FightNpcMonsterInboundInfo, c *socket.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
|
||||||
c.IsFighting = true
|
c.IsFighting = true
|
||||||
t1 := handler.NewTomeeHeader(2503, c.UserID)
|
t1 := handler.NewTomeeHeader(2503, c.Info.UserID)
|
||||||
ttt := info.NoteReadyToFightInfo{
|
ttt := info.NoteReadyToFightInfo{
|
||||||
OwnerID: data.Head.UserID,
|
OwnerID: data.Head.UserID,
|
||||||
FightId: 3,
|
FightId: 3,
|
||||||
}
|
}
|
||||||
ttt.OurInfo = info.FightUserInfo{UserID: c.UserID}
|
ttt.OurInfo = info.FightUserInfo{UserID: c.Info.UserID}
|
||||||
|
|
||||||
ttt.OurPetList = []info.ReadyFightPetInfo{{ID: 300,
|
ttt.OurPetList = []info.ReadyFightPetInfo{{ID: 300,
|
||||||
Level: 100,
|
Level: 100,
|
||||||
@@ -41,13 +41,13 @@ func (h Controller) OnPlayerFightNpcMonster(data *fight.FightNpcMonsterInboundIn
|
|||||||
c.SendPack(t1.Pack(&ttt))
|
c.SendPack(t1.Pack(&ttt))
|
||||||
return nil, -1
|
return nil, -1
|
||||||
}
|
}
|
||||||
func (h Controller) OnReadyToFight(data *fight.ReadyToFightInboundInfo, c *entity.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
|
func (h Controller) OnReadyToFight(data *fight.ReadyToFightInboundInfo, c *socket.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
|
||||||
|
|
||||||
t1 := handler.NewTomeeHeader(2504, c.UserID)
|
t1 := handler.NewTomeeHeader(2504, c.Info.UserID)
|
||||||
rett := fight.FightStartOutboundInfo{
|
rett := fight.FightStartOutboundInfo{
|
||||||
IsCanAuto: 0,
|
IsCanAuto: 0,
|
||||||
Info1: fight.FightPetInfo{PetID: 300,
|
Info1: fight.FightPetInfo{PetID: 300,
|
||||||
UserID: c.UserID,
|
UserID: c.Info.UserID,
|
||||||
Hp: 1000,
|
Hp: 1000,
|
||||||
MaxHp: 1000,
|
MaxHp: 1000,
|
||||||
Level: 1,
|
Level: 1,
|
||||||
@@ -72,7 +72,7 @@ func (h Controller) OnReadyToFight(data *fight.ReadyToFightInboundInfo, c *entit
|
|||||||
/**
|
/**
|
||||||
* 接收战斗或者取消战斗的包
|
* 接收战斗或者取消战斗的包
|
||||||
*/
|
*/
|
||||||
func (h Controller) OnPlayerHandleFightInvite(data *fight.HandleFightInviteInboundInfo, c *entity.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
|
func (h Controller) OnPlayerHandleFightInvite(data *fight.HandleFightInviteInboundInfo, c *socket.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
|
||||||
|
|
||||||
return nil, -1
|
return nil, -1
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
package controller
|
package controller
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"blazing/common/data/entity"
|
"blazing/common/data/socket"
|
||||||
"blazing/common/socket/errorcode"
|
"blazing/common/socket/errorcode"
|
||||||
"blazing/logic/service/commendsvr"
|
"blazing/logic/service/commendsvr"
|
||||||
)
|
)
|
||||||
|
|
||||||
// 处理命令: 105
|
// 处理命令: 105
|
||||||
func (h *Controller) GetServer(data *commendsvr.SidInfo, c *entity.Conn) (result *commendsvr.CommendSvrInfo, err errorcode.ErrorCode) { //这个时候player应该是空的
|
func (h *Controller) GetServer(data *commendsvr.SidInfo, c *socket.Conn) (result *commendsvr.CommendSvrInfo, err errorcode.ErrorCode) { //这个时候player应该是空的
|
||||||
result = commendsvr.NewInInfo()
|
result = commendsvr.NewInInfo()
|
||||||
result.ServerList = commendsvr.GetServerInfoList()
|
result.ServerList = commendsvr.GetServerInfoList()
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
package controller
|
package controller
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"blazing/common/data/entity"
|
|
||||||
"blazing/common/data/share"
|
"blazing/common/data/share"
|
||||||
|
"blazing/common/data/socket"
|
||||||
"blazing/common/socket/errorcode"
|
"blazing/common/socket/errorcode"
|
||||||
"blazing/common/socket/handler"
|
"blazing/common/socket/handler"
|
||||||
"blazing/logic/service"
|
"blazing/logic/service"
|
||||||
@@ -11,59 +11,34 @@ import (
|
|||||||
"blazing/logic/service/space"
|
"blazing/logic/service/space"
|
||||||
blservice "blazing/modules/blazing/service"
|
blservice "blazing/modules/blazing/service"
|
||||||
"context"
|
"context"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/gogf/gf/v2/os/glog"
|
"github.com/gogf/gf/v2/os/glog"
|
||||||
|
"github.com/jinzhu/copier"
|
||||||
)
|
)
|
||||||
|
|
||||||
// 处理命令: 1001
|
// 处理命令: 1001
|
||||||
func (h *Controller) Login(data *login.InInfo, c *entity.Conn) (result *login.OutInfo, err errorcode.ErrorCode) { //这个时候player应该是空的
|
func (h *Controller) Login(data *login.InInfo, c *socket.Conn) (result *login.OutInfo, err errorcode.ErrorCode) { //这个时候player应该是空的
|
||||||
|
|
||||||
if tt := data.CheakSession(); tt { //说明sid正确
|
if tt := data.CheakSession(); tt { //说明sid正确
|
||||||
h.RPCClient.Kick(data.Head.UserID) //先踢人
|
h.RPCClient.Kick(data.Head.UserID) //先踢人
|
||||||
|
playerinfo := blservice.NewUserService(data.Head.UserID).Person()
|
||||||
// h.RPCClient.UserLogin(int32(h.Port), int32(data.Head.UserID)) //初始化用户登录
|
t := service.SetPlayer(c, playerinfo)
|
||||||
t := service.SetPlayer(c, data.Head.UserID)
|
copier.Copy(playerinfo, t) //先复制给内存信息
|
||||||
|
|
||||||
share.ShareManager.SetUserOnline(data.Head.UserID, h.Port) //设置用户登录服务器
|
share.ShareManager.SetUserOnline(data.Head.UserID, h.Port) //设置用户登录服务器
|
||||||
t.CompleteLogin() //通知客户端登录成功
|
t.CompleteLogin() //通知客户端登录成功
|
||||||
t.MapId = 1
|
|
||||||
space.GetSpace(t.MapId).Set(t.UserID, t) //添加玩家
|
|
||||||
glog.Debug(context.Background(), "登录成功,初始地图 人数:", space.GetSpace(1).Len())
|
glog.Debug(context.Background(), "登录成功,初始地图 人数:", space.GetSpace(1).Len())
|
||||||
playerinfo := blservice.NewUserService(t.UserID).Person()
|
|
||||||
t.Nick = playerinfo.Nick
|
|
||||||
// blservice.NewPlayerService().ProcessAndSave(t.UserID, func(t *model.PlayerInfo) error {
|
|
||||||
|
|
||||||
// t.Nick = t.Nick + " (在线)"
|
|
||||||
// return nil
|
|
||||||
// })
|
|
||||||
result = login.NewOutInfo() //设置登录消息
|
result = login.NewOutInfo() //设置登录消息
|
||||||
result.UserID = t.UserID
|
copier.Copy(playerinfo, result)
|
||||||
result.RegisterTime = uint32(time.Now().Unix())
|
|
||||||
result.Nick = t.Nick
|
|
||||||
result.Color = playerinfo.Color
|
|
||||||
result.Pos = playerinfo.Pos
|
|
||||||
result.Clothes = playerinfo.Clothes ///append(result.Clothes, model.PeopleItemInfo{ID: 100717, Level: 1})
|
|
||||||
result.MapID = t.MapId
|
|
||||||
result.TimeLimit = playerinfo.TimeLimit //todo 待修复电池不正确问题
|
|
||||||
result.TimeToday = playerinfo.TimeToday
|
|
||||||
//result.PetList = playerinfo.PetList
|
|
||||||
|
|
||||||
defer func() {
|
defer space.GetSpace(t.Info.MapID).Set(t.Info.UserID, t).Range(func(playerID uint32, player *socket.Player) bool {
|
||||||
space.GetSpace(t.MapId).Set(t.UserID, t) //添加玩家
|
|
||||||
tt := maps.NewOutInfo()
|
tt := maps.NewOutInfo()
|
||||||
tt.UserID = t.UserID
|
copier.Copy(playerinfo, tt)
|
||||||
tt.Nick = t.Nick
|
t1 := handler.NewTomeeHeader(2001, t.Info.UserID)
|
||||||
tt.Pos = result.Pos
|
player.SendPack(t1.Pack(&tt))
|
||||||
|
return true
|
||||||
t1 := handler.NewTomeeHeader(2001, t.UserID)
|
})
|
||||||
|
|
||||||
space.GetSpace(t.MapId).Range(func(playerID uint32, player *entity.Player) bool {
|
|
||||||
|
|
||||||
player.SendPack(t1.Pack(&tt))
|
|
||||||
return true
|
|
||||||
})
|
|
||||||
}()
|
|
||||||
|
|
||||||
return result, 0
|
return result, 0
|
||||||
|
|
||||||
|
|||||||
@@ -1,27 +1,29 @@
|
|||||||
package controller
|
package controller
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"blazing/common/data/entity"
|
"blazing/common/data/socket"
|
||||||
"blazing/common/socket/errorcode"
|
"blazing/common/socket/errorcode"
|
||||||
"blazing/logic/service/maphot"
|
"blazing/logic/service/maphot"
|
||||||
"blazing/logic/service/maps"
|
"blazing/logic/service/maps"
|
||||||
"blazing/logic/service/space"
|
"blazing/logic/service/space"
|
||||||
mservice "blazing/modules/blazing/service"
|
mservice "blazing/modules/blazing/service"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/jinzhu/copier"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (h *Controller) MapEnter(data *maps.InInfo, c *entity.Player) (result *maps.OutInfo, err errorcode.ErrorCode) { //这个时候player应该是空的
|
func (h *Controller) MapEnter(data *maps.InInfo, c *socket.Player) (result *maps.OutInfo, err errorcode.ErrorCode) { //这个时候player应该是空的
|
||||||
|
|
||||||
c.MapId = data.MapId //登录地图
|
c.Info.MapID = data.MapId //登录地图
|
||||||
space.GetSpace(c.MapId).Set(c.UserID, c) //添加玩家
|
space.GetSpace(c.Info.MapID).Set(c.Info.UserID, c) //添加玩家
|
||||||
tt := maps.NewOutInfo()
|
result = maps.NewOutInfo()
|
||||||
tt.UserID = c.UserID
|
c.Info.Pos = data.Point
|
||||||
tt.Nick = c.Nick
|
copier.Copy(c.Info, result)
|
||||||
tt.Pos = data.Point
|
|
||||||
data.Broadcast(c.MapId, *tt) //同步广播
|
data.Broadcast(c.Info.MapID, *result) //同步广播
|
||||||
// 如果是无怪地图,直接返回
|
// 如果是无怪地图,直接返回
|
||||||
|
|
||||||
if mservice.NewMonsterService().GetId(c.MapId) == nil {
|
if mservice.NewMonsterService().GetId(c.Info.MapID) == nil {
|
||||||
return nil, -1
|
return nil, -1
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -33,7 +35,7 @@ func (h *Controller) MapEnter(data *maps.InInfo, c *entity.Player) (result *maps
|
|||||||
|
|
||||||
time.After(5 * time.Second)
|
time.After(5 * time.Second)
|
||||||
// 首次刷新
|
// 首次刷新
|
||||||
if !c.IsFighting && c.MapId != 0 {
|
if !c.IsFighting && c.Info.MapID != 0 {
|
||||||
data.SpawnMonsters(c, true)
|
data.SpawnMonsters(c, true)
|
||||||
}
|
}
|
||||||
//循环刷新怪物
|
//循环刷新怪物
|
||||||
@@ -48,16 +50,16 @@ func (h *Controller) MapEnter(data *maps.InInfo, c *entity.Player) (result *maps
|
|||||||
return
|
return
|
||||||
case <-ticker.C:
|
case <-ticker.C:
|
||||||
// 刷新当前地图的怪物
|
// 刷新当前地图的怪物
|
||||||
if !c.IsFighting && c.MapId != 0 {
|
if !c.IsFighting && c.Info.MapID != 0 {
|
||||||
data.SpawnMonsters(c, false)
|
data.SpawnMonsters(c, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}(c.StopChan, int(c.MapId))
|
}(c.StopChan, int(c.Info.MapID))
|
||||||
return nil, -1
|
return nil, -1
|
||||||
}
|
}
|
||||||
func (h Controller) MapHot(data *maphot.InInfo, c *entity.Player) (result *maphot.OutInfo, err errorcode.ErrorCode) {
|
func (h Controller) MapHot(data *maphot.InInfo, c *socket.Player) (result *maphot.OutInfo, err errorcode.ErrorCode) {
|
||||||
|
|
||||||
result = &maphot.OutInfo{
|
result = &maphot.OutInfo{
|
||||||
|
|
||||||
@@ -66,27 +68,29 @@ func (h Controller) MapHot(data *maphot.InInfo, c *entity.Player) (result *mapho
|
|||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
func (h *Controller) MapLeave(data *maps.LeaveMapInboundInfo, c *entity.Player) (result *maps.LeaveMapOutboundInfo, err errorcode.ErrorCode) { //这个时候player应该是空的
|
func (h *Controller) MapLeave(data *maps.LeaveMapInboundInfo, c *socket.Player) (result *maps.LeaveMapOutboundInfo, err errorcode.ErrorCode) { //这个时候player应该是空的
|
||||||
//result = &maps.LeaveMapOutboundInfo{UserID: c.GetUserID()}
|
//result = &maps.LeaveMapOutboundInfo{UserID: c.GetUserID()}
|
||||||
data.Broadcast(c.MapId, maps.LeaveMapOutboundInfo{UserID: c.GetUserID()}) //同步广播
|
data.Broadcast(c.Info.MapID, maps.LeaveMapOutboundInfo{UserID: c.Info.UserID}) //同步广播
|
||||||
space.GetSpace(c.MapId).Delete(c.UserID)
|
space.GetSpace(c.Info.MapID).Delete(c.Info.UserID)
|
||||||
// 如果有正在运行的刷怪协程,发送停止信号
|
// 如果有正在运行的刷怪协程,发送停止信号
|
||||||
if c.StopChan != nil {
|
if c.StopChan != nil {
|
||||||
close(c.StopChan)
|
close(c.StopChan)
|
||||||
c.StopChan = nil
|
c.StopChan = nil
|
||||||
}
|
}
|
||||||
c.MapId = 0 // 重置当前地图
|
//c.MapID = 0 // 重置当前地图
|
||||||
return nil, -1
|
return nil, -1
|
||||||
}
|
}
|
||||||
func (h *Controller) MapList(data *maps.ListMapPlayerInboundInfo, c *entity.Player) (result *maps.ListMapPlayerOutboundInfo, err errorcode.ErrorCode) { //这个时候player应该是空的
|
func (h *Controller) MapList(data *maps.ListMapPlayerInboundInfo, c *socket.Player) (result *maps.ListMapPlayerOutboundInfo, err errorcode.ErrorCode) { //这个时候player应该是空的
|
||||||
|
|
||||||
result = &maps.ListMapPlayerOutboundInfo{}
|
result = &maps.ListMapPlayerOutboundInfo{}
|
||||||
result.Player = make([]maps.OutInfo, 0)
|
result.Player = make([]maps.OutInfo, 0)
|
||||||
result1 := maps.NewOutInfo()
|
|
||||||
|
|
||||||
result1.UserID = c.UserID
|
space.GetSpace(c.Info.MapID).Range(func(userID uint32, player *socket.Player) bool {
|
||||||
//result.Pos = model.Pos{X: 500, Y: 400}
|
result1 := maps.NewOutInfo()
|
||||||
result1.Nick = c.Nick
|
copier.Copy(player.Info, result1)
|
||||||
result.Player = append(result.Player, *result1)
|
result.Player = append(result.Player, *result1)
|
||||||
|
return true
|
||||||
|
})
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
package controller
|
package controller
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"blazing/common/data/entity"
|
"blazing/common/data/socket"
|
||||||
"blazing/common/socket/errorcode"
|
"blazing/common/socket/errorcode"
|
||||||
"blazing/logic/service/pet"
|
"blazing/logic/service/pet"
|
||||||
"blazing/modules/blazing/model"
|
"blazing/modules/blazing/model"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (h *Controller) GetPetInfo(data *pet.InInfo, c *entity.Player) (result *pet.OutInfo, err errorcode.ErrorCode) { //这个时候player应该是空的
|
func (h *Controller) GetPetInfo(data *pet.InInfo, c *socket.Player) (result *pet.OutInfo, err errorcode.ErrorCode) { //这个时候player应该是空的
|
||||||
|
|
||||||
t := model.PetInfo{
|
t := model.PetInfo{
|
||||||
ID: 300,
|
ID: 300,
|
||||||
|
|||||||
@@ -1,15 +1,15 @@
|
|||||||
package controller
|
package controller
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"blazing/common/data/entity"
|
"blazing/common/data/socket"
|
||||||
"blazing/common/socket/errorcode"
|
"blazing/common/socket/errorcode"
|
||||||
"blazing/logic/service/room"
|
"blazing/logic/service/room"
|
||||||
)
|
)
|
||||||
|
|
||||||
// 获取基地物品
|
// 获取基地物品
|
||||||
func (h Controller) OnFitmentUsering(data *room.FitmentUseringInboundInfo, c *entity.Player) (result *room.FitmentUseringOutboundInfo, err errorcode.ErrorCode) {
|
func (h Controller) OnFitmentUsering(data *room.FitmentUseringInboundInfo, c *socket.Player) (result *room.FitmentUseringOutboundInfo, err errorcode.ErrorCode) {
|
||||||
|
|
||||||
result = &room.FitmentUseringOutboundInfo{UserId: c.GetUserID(), RoomId: data.TargetUserID}
|
result = &room.FitmentUseringOutboundInfo{UserId: c.Info.UserID, RoomId: data.TargetUserID}
|
||||||
result.Fitments = make([]room.FitmentShowInfo, 0)
|
result.Fitments = make([]room.FitmentShowInfo, 0)
|
||||||
result.Fitments = append(result.Fitments, room.FitmentShowInfo{Id: 500001, Status: 1, X: 1, Y: 1, Dir: 1})
|
result.Fitments = append(result.Fitments, room.FitmentShowInfo{Id: 500001, Status: 1, X: 1, Y: 1, Dir: 1})
|
||||||
|
|
||||||
@@ -17,14 +17,14 @@ func (h Controller) OnFitmentUsering(data *room.FitmentUseringInboundInfo, c *en
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 获取基地展示精灵
|
// 获取基地展示精灵
|
||||||
func (h Controller) OnGetRoomPetShowInfo(data *room.PetRoomListInboundInfo, c *entity.Player) (result *room.PetRoomListOutboundInfo, err errorcode.ErrorCode) {
|
func (h Controller) OnGetRoomPetShowInfo(data *room.PetRoomListInboundInfo, c *socket.Player) (result *room.PetRoomListOutboundInfo, err errorcode.ErrorCode) {
|
||||||
result = &room.PetRoomListOutboundInfo{}
|
result = &room.PetRoomListOutboundInfo{}
|
||||||
result.Pets = make([]room.PetShowInfo, 0)
|
result.Pets = make([]room.PetShowInfo, 0)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取自己房间的家具
|
// 获取自己房间的家具
|
||||||
func (h Controller) OnGetFitmentAll(data *room.FitmentAllInboundEmpty, c *entity.Player) (result *room.FitmentAllOutboundInfo, err errorcode.ErrorCode) {
|
func (h Controller) OnGetFitmentAll(data *room.FitmentAllInboundEmpty, c *socket.Player) (result *room.FitmentAllOutboundInfo, err errorcode.ErrorCode) {
|
||||||
result = &room.FitmentAllOutboundInfo{}
|
result = &room.FitmentAllOutboundInfo{}
|
||||||
result.Fitments = make([]room.FitmentShowInfo, 0)
|
result.Fitments = make([]room.FitmentShowInfo, 0)
|
||||||
result.Fitments = append(result.Fitments, room.FitmentShowInfo{Id: 500001, Status: 1, X: 1, Y: 1, Dir: 1})
|
result.Fitments = append(result.Fitments, room.FitmentShowInfo{Id: 500001, Status: 1, X: 1, Y: 1, Dir: 1})
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
package controller
|
package controller
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"blazing/common/data/entity"
|
"blazing/common/data/socket"
|
||||||
"blazing/common/socket/errorcode"
|
"blazing/common/socket/errorcode"
|
||||||
"blazing/logic/service/systemtime"
|
"blazing/logic/service/systemtime"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (h Controller) SystemTimeInfo(data *systemtime.InInfo, c *entity.Player) (result *systemtime.OutInfo, err errorcode.ErrorCode) {
|
func (h Controller) SystemTimeInfo(data *systemtime.InInfo, c *socket.Player) (result *systemtime.OutInfo, err errorcode.ErrorCode) {
|
||||||
|
|
||||||
return systemtime.NewOutInfo(), 0
|
return systemtime.NewOutInfo(), 0
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package controller
|
package controller
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"blazing/common/data/entity"
|
"blazing/common/data/socket"
|
||||||
"blazing/common/socket/errorcode"
|
"blazing/common/socket/errorcode"
|
||||||
"blazing/logic/service/task"
|
"blazing/logic/service/task"
|
||||||
"blazing/modules/blazing/model"
|
"blazing/modules/blazing/model"
|
||||||
@@ -11,10 +11,10 @@ import (
|
|||||||
/**
|
/**
|
||||||
* 接受任务
|
* 接受任务
|
||||||
*/
|
*/
|
||||||
func (h Controller) AcceptTask(data *task.AcceptTaskInboundInfo, c *entity.Player) (result *task.AcceptTaskOutboundInfo, err errorcode.ErrorCode) {
|
func (h Controller) AcceptTask(data *task.AcceptTaskInboundInfo, c *socket.Player) (result *task.AcceptTaskOutboundInfo, err errorcode.ErrorCode) {
|
||||||
|
|
||||||
if data.Head.CMD == 2201 { //判断不是每日任务
|
if data.Head.CMD == 2201 { //判断不是每日任务
|
||||||
service.NewUserService(c.UserID).TaskExec(func(ttt map[uint32]model.TaskInfo) bool {
|
service.NewUserService(c.Info.UserID).TaskExec(func(ttt map[uint32]model.TaskInfo) bool {
|
||||||
ft, ok := ttt[data.TaskId]
|
ft, ok := ttt[data.TaskId]
|
||||||
if ok { //如果找到任务
|
if ok { //如果找到任务
|
||||||
if ft.Status == 0 { //可以接受
|
if ft.Status == 0 { //可以接受
|
||||||
@@ -33,7 +33,7 @@ func (h Controller) AcceptTask(data *task.AcceptTaskInboundInfo, c *entity.Playe
|
|||||||
return false
|
return false
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
service.NewUserService(c.UserID).DailyTaskExec(func(ttt map[uint32]model.DailyTaskInfo) bool {
|
service.NewUserService(c.Info.UserID).DailyTaskExec(func(ttt map[uint32]model.DailyTaskInfo) bool {
|
||||||
ft, ok := ttt[data.TaskId]
|
ft, ok := ttt[data.TaskId]
|
||||||
if ok { //如果找到任务
|
if ok { //如果找到任务
|
||||||
if ft.Status == 0 { //可以接受
|
if ft.Status == 0 { //可以接受
|
||||||
@@ -61,10 +61,10 @@ func (h Controller) AcceptTask(data *task.AcceptTaskInboundInfo, c *entity.Playe
|
|||||||
/**
|
/**
|
||||||
* 更新任务步骤
|
* 更新任务步骤
|
||||||
*/
|
*/
|
||||||
func (h Controller) AddTaskBuf(data *task.AddTaskBufInboundInfo, c *entity.Player) (result *task.AddTaskBufOutboundInfo, err errorcode.ErrorCode) {
|
func (h Controller) AddTaskBuf(data *task.AddTaskBufInboundInfo, c *socket.Player) (result *task.AddTaskBufOutboundInfo, err errorcode.ErrorCode) {
|
||||||
|
|
||||||
if data.Head.CMD == 2204 { //判断不是每日任务
|
if data.Head.CMD == 2204 { //判断不是每日任务
|
||||||
service.NewUserService(c.UserID).TaskExec(func(ttt map[uint32]model.TaskInfo) bool {
|
service.NewUserService(c.Info.UserID).TaskExec(func(ttt map[uint32]model.TaskInfo) bool {
|
||||||
if conditions, ok := ttt[data.TaskId]; ok {
|
if conditions, ok := ttt[data.TaskId]; ok {
|
||||||
conditions.TaskInfo = data.TaskList
|
conditions.TaskInfo = data.TaskList
|
||||||
ttt[data.TaskId] = conditions
|
ttt[data.TaskId] = conditions
|
||||||
@@ -74,7 +74,7 @@ func (h Controller) AddTaskBuf(data *task.AddTaskBufInboundInfo, c *entity.Playe
|
|||||||
return false
|
return false
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
service.NewUserService(c.UserID).DailyTaskExec(func(ttt map[uint32]model.DailyTaskInfo) bool {
|
service.NewUserService(c.Info.UserID).DailyTaskExec(func(ttt map[uint32]model.DailyTaskInfo) bool {
|
||||||
if conditions, ok := ttt[data.TaskId]; ok {
|
if conditions, ok := ttt[data.TaskId]; ok {
|
||||||
conditions.DailyTaskInfo = data.TaskList
|
conditions.DailyTaskInfo = data.TaskList
|
||||||
ttt[data.TaskId] = conditions
|
ttt[data.TaskId] = conditions
|
||||||
@@ -92,7 +92,7 @@ func (h Controller) AddTaskBuf(data *task.AddTaskBufInboundInfo, c *entity.Playe
|
|||||||
/**
|
/**
|
||||||
* 完成任务
|
* 完成任务
|
||||||
*/
|
*/
|
||||||
func (h Controller) Complete_Task(data *task.CompleteTaskInboundInfo, c *entity.Player) (result *task.CompleteTaskOutboundInfo, err errorcode.ErrorCode) {
|
func (h Controller) Complete_Task(data *task.CompleteTaskInboundInfo, c *socket.Player) (result *task.CompleteTaskOutboundInfo, err errorcode.ErrorCode) {
|
||||||
|
|
||||||
if data.Head.CMD == 2202 { //判断不是每日任务
|
if data.Head.CMD == 2202 { //判断不是每日任务
|
||||||
|
|
||||||
@@ -106,7 +106,7 @@ func (h Controller) Complete_Task(data *task.CompleteTaskInboundInfo, c *entity.
|
|||||||
/**
|
/**
|
||||||
* 获取任务状态
|
* 获取任务状态
|
||||||
*/
|
*/
|
||||||
func (h Controller) Get_Task_Buf(data *task.GetTaskBufInboundInfo, c *entity.Player) (result *task.GetTaskBufOutboundInfo, err errorcode.ErrorCode) {
|
func (h Controller) Get_Task_Buf(data *task.GetTaskBufInboundInfo, c *socket.Player) (result *task.GetTaskBufOutboundInfo, err errorcode.ErrorCode) {
|
||||||
|
|
||||||
if data.Head.CMD == 2203 { //判断不是每日任务
|
if data.Head.CMD == 2203 { //判断不是每日任务
|
||||||
|
|
||||||
@@ -120,7 +120,7 @@ func (h Controller) Get_Task_Buf(data *task.GetTaskBufInboundInfo, c *entity.Pla
|
|||||||
/**
|
/**
|
||||||
* 删除任务
|
* 删除任务
|
||||||
*/
|
*/
|
||||||
func (h Controller) Delete_Task(data *task.DeleteTaskInboundInfo, c *entity.Player) (result *task.DeleteTaskOutboundInfo, err errorcode.ErrorCode) {
|
func (h Controller) Delete_Task(data *task.DeleteTaskInboundInfo, c *socket.Player) (result *task.DeleteTaskOutboundInfo, err errorcode.ErrorCode) {
|
||||||
|
|
||||||
if data.Head.CMD == 2205 { //判断不是每日任务
|
if data.Head.CMD == 2205 { //判断不是每日任务
|
||||||
|
|
||||||
|
|||||||
@@ -1,15 +1,15 @@
|
|||||||
package controller
|
package controller
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"blazing/common/data/entity"
|
"blazing/common/data/socket"
|
||||||
"blazing/common/socket/errorcode"
|
"blazing/common/socket/errorcode"
|
||||||
"blazing/logic/service/space"
|
"blazing/logic/service/space"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (h Controller) Walk(data *space.InInfo, c *entity.Player) (result *space.OutInfo, err errorcode.ErrorCode) {
|
func (h Controller) Walk(data *space.InInfo, c *socket.Player) (result *space.OutInfo, err errorcode.ErrorCode) {
|
||||||
|
|
||||||
data.Broadcast(c.MapId, space.OutInfo{Flag: data.Flag,
|
data.Broadcast(c.Info.UserID, space.OutInfo{Flag: data.Flag,
|
||||||
UserID: c.GetUserID(),
|
UserID: c.Info.UserID,
|
||||||
Reserve2: data.Reverse2,
|
Reserve2: data.Reverse2,
|
||||||
Point: data.Point}) //走路的广播
|
Point: data.Point}) //走路的广播
|
||||||
|
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ require (
|
|||||||
github.com/go-logr/logr v1.4.2 // indirect
|
github.com/go-logr/logr v1.4.2 // indirect
|
||||||
github.com/go-logr/stdr v1.2.2 // indirect
|
github.com/go-logr/stdr v1.2.2 // indirect
|
||||||
github.com/google/uuid v1.6.0 // indirect
|
github.com/google/uuid v1.6.0 // indirect
|
||||||
|
github.com/jinzhu/copier v0.4.0 // indirect
|
||||||
github.com/mattn/go-colorable v0.1.13 // indirect
|
github.com/mattn/go-colorable v0.1.13 // indirect
|
||||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||||
github.com/mcuadros/go-defaults v1.2.0 // indirect
|
github.com/mcuadros/go-defaults v1.2.0 // indirect
|
||||||
|
|||||||
@@ -28,6 +28,8 @@ github.com/gogf/gf/v2 v2.9.0 h1:semN5Q5qGjDQEv4620VzxcJzJlSD07gmyJ9Sy9zfbHk=
|
|||||||
github.com/gogf/gf/v2 v2.9.0/go.mod h1:sWGQw+pLILtuHmbOxoe0D+0DdaXxbleT57axOLH2vKI=
|
github.com/gogf/gf/v2 v2.9.0/go.mod h1:sWGQw+pLILtuHmbOxoe0D+0DdaXxbleT57axOLH2vKI=
|
||||||
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
||||||
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||||
|
github.com/jinzhu/copier v0.4.0 h1:w3ciUoD19shMCRargcpm0cm91ytaBhDvuRpz1ODO/U8=
|
||||||
|
github.com/jinzhu/copier v0.4.0/go.mod h1:DfbEm0FYsaqBcKcFuvmOZb218JkPGtvSHsKg8S8hyyg=
|
||||||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||||
github.com/lunixbochs/struc v0.0.0-20241101090106-8d528fa2c543 h1:GxMuVb9tJajC1QpbQwYNY1ZAo1EIE8I+UclBjOfjz/M=
|
github.com/lunixbochs/struc v0.0.0-20241101090106-8d528fa2c543 h1:GxMuVb9tJajC1QpbQwYNY1ZAo1EIE8I+UclBjOfjz/M=
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package maps
|
package maps
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"blazing/common/data/entity"
|
"blazing/common/data/socket"
|
||||||
"blazing/common/socket/handler"
|
"blazing/common/socket/handler"
|
||||||
"blazing/logic/service/space"
|
"blazing/logic/service/space"
|
||||||
"blazing/modules/blazing/model"
|
"blazing/modules/blazing/model"
|
||||||
@@ -26,7 +26,7 @@ type InInfo struct {
|
|||||||
|
|
||||||
func (t *InInfo) Broadcast(mapid uint32, o OutInfo) {
|
func (t *InInfo) Broadcast(mapid uint32, o OutInfo) {
|
||||||
|
|
||||||
space.GetSpace(mapid).Range(func(playerID uint32, player *entity.Player) bool {
|
space.GetSpace(mapid).Range(func(playerID uint32, player *socket.Player) bool {
|
||||||
t.Head.Result = 0
|
t.Head.Result = 0
|
||||||
|
|
||||||
player.SendPack(t.Head.Pack(&o))
|
player.SendPack(t.Head.Pack(&o))
|
||||||
@@ -35,7 +35,7 @@ func (t *InInfo) Broadcast(mapid uint32, o OutInfo) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 刷怪具体实现
|
// 刷怪具体实现
|
||||||
func (t *InInfo) SpawnMonsters(c *entity.Player, isfrist bool) {
|
func (t *InInfo) SpawnMonsters(c *socket.Player, isfrist bool) {
|
||||||
// 获取当前地图的怪物配置
|
// 获取当前地图的怪物配置
|
||||||
|
|
||||||
// if c == nil || mservice.NewMonsterService().GetId(c.MapId) == 0 { //用户离线
|
// if c == nil || mservice.NewMonsterService().GetId(c.MapId) == 0 { //用户离线
|
||||||
@@ -52,7 +52,7 @@ func (t *InInfo) SpawnMonsters(c *entity.Player, isfrist bool) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 创建数据包
|
// 创建数据包
|
||||||
tt := handler.NewTomeeHeader(2004, c.UserID)
|
tt := handler.NewTomeeHeader(2004, c.Info.UserID)
|
||||||
|
|
||||||
if isfrist {
|
if isfrist {
|
||||||
t.monsters = generateThreeUniqueNumbers()
|
t.monsters = generateThreeUniqueNumbers()
|
||||||
@@ -60,7 +60,7 @@ func (t *InInfo) SpawnMonsters(c *entity.Player, isfrist bool) {
|
|||||||
|
|
||||||
t.monsters, _, _ = replaceOneNumber(t.monsters)
|
t.monsters, _, _ = replaceOneNumber(t.monsters)
|
||||||
}
|
}
|
||||||
t1 := t.genMonster(c.MapId)
|
t1 := t.genMonster(c.Info.UserID)
|
||||||
|
|
||||||
c.SendPack(tt.Pack(&t1))
|
c.SendPack(tt.Pack(&t1))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package maps
|
package maps
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"blazing/common/data/entity"
|
"blazing/common/data/socket"
|
||||||
"blazing/common/socket/handler"
|
"blazing/common/socket/handler"
|
||||||
"blazing/logic/service/space"
|
"blazing/logic/service/space"
|
||||||
)
|
)
|
||||||
@@ -17,7 +17,7 @@ type LeaveMapInboundInfo struct {
|
|||||||
|
|
||||||
func (t *LeaveMapInboundInfo) Broadcast(mapid uint32, o LeaveMapOutboundInfo) {
|
func (t *LeaveMapInboundInfo) Broadcast(mapid uint32, o LeaveMapOutboundInfo) {
|
||||||
|
|
||||||
space.GetSpace(mapid).Range(func(playerID uint32, player *entity.Player) bool {
|
space.GetSpace(mapid).Range(func(playerID uint32, player *socket.Player) bool {
|
||||||
t.Head.Result = 0
|
t.Head.Result = 0
|
||||||
|
|
||||||
player.SendPack(t.Head.Pack(&o))
|
player.SendPack(t.Head.Pack(&o))
|
||||||
|
|||||||
62
logic/service/nono/nono.go
Normal file
62
logic/service/nono/nono.go
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
package nono
|
||||||
|
|
||||||
|
import "blazing/common/socket/handler"
|
||||||
|
|
||||||
|
// NonoOutboundInfo 用于表示Nono相关的出站信息
|
||||||
|
type NonoOutboundInfo struct {
|
||||||
|
// UserID: 米米号,对应uint32类型,无符号
|
||||||
|
UserID uint32
|
||||||
|
|
||||||
|
// Num: 未知,对应uint32类型,无符号
|
||||||
|
Num uint32
|
||||||
|
|
||||||
|
// Flying: 飞行状态 0为不飞行 大于0为飞行模式,对应uint32类型,无符号
|
||||||
|
Flying uint32
|
||||||
|
|
||||||
|
// Nick: 16字节,固定长度16字节字符串
|
||||||
|
Nick string `struc:"[16]byte"`
|
||||||
|
|
||||||
|
// SuperNono: 是不是超能nono,对应uint32类型,无符号
|
||||||
|
SuperNono uint32
|
||||||
|
|
||||||
|
// Color: nono颜色 00 rgb,对应uint32类型,无符号
|
||||||
|
Color uint32
|
||||||
|
|
||||||
|
// Power: 未知, 返回的实际数值要*1000,对应uint32类型,无符号
|
||||||
|
Power uint32
|
||||||
|
|
||||||
|
// Mate: 未知, 返回的实际数值要*1000,对应uint32类型,无符号
|
||||||
|
Mate uint32
|
||||||
|
|
||||||
|
// IQ: 未知,对应uint32类型,无符号
|
||||||
|
IQ uint32
|
||||||
|
|
||||||
|
// AI: 未知,对应uint16类型,无符号短整数
|
||||||
|
AI uint16
|
||||||
|
|
||||||
|
// Birth: 未知, 返回的实际数值要除以1000,对应uint32类型,无符号
|
||||||
|
Birth uint32
|
||||||
|
|
||||||
|
// ChargeTime: 充电时间,对应uint32类型,无符号
|
||||||
|
ChargeTime uint32
|
||||||
|
|
||||||
|
// Func: 20字节,固定长度20字节数组
|
||||||
|
Func [20]byte
|
||||||
|
|
||||||
|
// SuperEnergy: 超能nono能力,对应uint32类型,无符号
|
||||||
|
SuperEnergy uint32
|
||||||
|
|
||||||
|
// SuperLevel: 超能nono等级,对应uint32类型,无符号
|
||||||
|
SuperLevel uint32
|
||||||
|
|
||||||
|
// SuperStage: 超能nono阶段,对应uint32类型,无符号
|
||||||
|
SuperStage uint32
|
||||||
|
}
|
||||||
|
|
||||||
|
type NonoInboundInfo struct {
|
||||||
|
// 消息头部,命令ID对应MessageCommandIDRegistry.Nono_Info
|
||||||
|
Head handler.TomeeHeader `cmd:"9003" struc:"[0]pad"`
|
||||||
|
|
||||||
|
// 米米号,对应Java的@UInt long类型
|
||||||
|
UserID uint32 `fieldDescription:"米米号" struc:"uint32" uint:"true"`
|
||||||
|
}
|
||||||
@@ -1,22 +1,22 @@
|
|||||||
package service
|
package service
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"blazing/common/data/entity"
|
"blazing/common/data/socket"
|
||||||
"blazing/common/socket/errorcode"
|
"blazing/common/socket/errorcode"
|
||||||
"blazing/common/socket/handler"
|
"blazing/common/socket/handler"
|
||||||
"blazing/cool"
|
"blazing/modules/blazing/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetPlayer(c *entity.Conn, userid uint32) *entity.Player { //TODO 这里待优化,可能存在内存泄漏问题
|
func GetPlayer(c *socket.Conn, userid uint32) *socket.Player { //TODO 这里待优化,可能存在内存泄漏问题
|
||||||
|
|
||||||
//检查player初始化,是否为conn初始后取map,防止二次连接后存在两个player
|
//检查player初始化,是否为conn初始后取map,防止二次连接后存在两个player
|
||||||
|
|
||||||
clientdata := c.MainConn.Context().(*entity.ClientData)
|
clientdata := c.MainConn.Context().(*socket.ClientData)
|
||||||
if clientdata.GetPlayer() != nil {
|
if clientdata.GetPlayer() != nil {
|
||||||
return clientdata.GetPlayer()
|
return clientdata.GetPlayer()
|
||||||
}
|
}
|
||||||
var player *entity.Player
|
var player *socket.Player
|
||||||
if player1, ok := cool.Mainplayer.Load((userid)); ok {
|
if player1, ok := socket.Mainplayer.Load((userid)); ok {
|
||||||
|
|
||||||
clientdata.SetPlayer(player1)
|
clientdata.SetPlayer(player1)
|
||||||
}
|
}
|
||||||
@@ -27,7 +27,7 @@ func GetPlayer(c *entity.Conn, userid uint32) *entity.Player { //TODO 这里待
|
|||||||
func KickPlayer(userid uint32) { //踢出玩家
|
func KickPlayer(userid uint32) { //踢出玩家
|
||||||
//TODO 返回错误码
|
//TODO 返回错误码
|
||||||
//var player *entity.Player
|
//var player *entity.Player
|
||||||
if player1, ok := cool.Mainplayer.Load((userid)); ok {
|
if player1, ok := socket.Mainplayer.Load((userid)); ok {
|
||||||
//取成功,否则创建
|
//取成功,否则创建
|
||||||
head := handler.NewTomeeHeader(1001, userid)
|
head := handler.NewTomeeHeader(1001, userid)
|
||||||
head.Result = uint32(errorcode.ErrorCodes.ErrAccountLoggedInElsewhere)
|
head.Result = uint32(errorcode.ErrorCodes.ErrAccountLoggedInElsewhere)
|
||||||
@@ -40,27 +40,19 @@ func KickPlayer(userid uint32) { //踢出玩家
|
|||||||
//return player
|
//return player
|
||||||
// return nil
|
// return nil
|
||||||
}
|
}
|
||||||
func SetPlayer(c *entity.Conn, userid uint32) *entity.Player { //TODO 这里待优化,
|
func SetPlayer(c *socket.Conn, user *model.PlayerInfo) *socket.Player { //TODO 这里待优化,
|
||||||
|
|
||||||
clientdata := c.MainConn.Context().(*entity.ClientData)
|
clientdata := c.MainConn.Context().(*socket.ClientData)
|
||||||
|
|
||||||
player := entity.NewPlayer(
|
player := socket.NewPlayer(
|
||||||
entity.WithUserID(userid), //注入ID
|
|
||||||
entity.WithConn(*c), //注入conn
|
|
||||||
|
socket.WithConn(*c), //注入conn
|
||||||
)
|
)
|
||||||
cool.Mainplayer.Store(userid, player)
|
socket.Mainplayer.Store(user.UserID, player)
|
||||||
|
|
||||||
clientdata.SetPlayer(player) //= player
|
clientdata.SetPlayer(player) //= player
|
||||||
|
|
||||||
return player
|
return player
|
||||||
// return nil
|
// return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// /**
|
|
||||||
// * @var type OutboundInf
|
|
||||||
// * @global
|
|
||||||
// */
|
|
||||||
// type OutInfo interface {
|
|
||||||
// error //实现错误接口
|
|
||||||
// Code() errorcode.ErrorCode //返回错误码,如果error不等于nil就返回这个实现对前台传错误码
|
|
||||||
// }
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package space
|
package space
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"blazing/common/data/entity"
|
"blazing/common/data/socket"
|
||||||
xml "blazing/common/data/xml/map"
|
xml "blazing/common/data/xml/map"
|
||||||
"blazing/common/utils"
|
"blazing/common/utils"
|
||||||
"blazing/modules/blazing/model"
|
"blazing/modules/blazing/model"
|
||||||
@@ -11,7 +11,7 @@ import (
|
|||||||
// Space 针对Player的并发安全map,键为uint32类型
|
// Space 针对Player的并发安全map,键为uint32类型
|
||||||
type Space struct {
|
type Space struct {
|
||||||
mu sync.RWMutex // 读写锁,读多写少场景更高效
|
mu sync.RWMutex // 读写锁,读多写少场景更高效
|
||||||
data map[uint32]*entity.Player // 存储玩家数据的map,键为玩家ID
|
data map[uint32]*socket.Player // 存储玩家数据的map,键为玩家ID
|
||||||
CanRefresh bool //是否能够刷怪
|
CanRefresh bool //是否能够刷怪
|
||||||
ID uint32 // 地图ID
|
ID uint32 // 地图ID
|
||||||
Name string //地图名称
|
Name string //地图名称
|
||||||
@@ -22,13 +22,13 @@ type Space struct {
|
|||||||
// NewSyncMap 创建一个新的玩家同步map
|
// NewSyncMap 创建一个新的玩家同步map
|
||||||
func NewSpace() *Space {
|
func NewSpace() *Space {
|
||||||
return &Space{
|
return &Space{
|
||||||
data: make(map[uint32]*entity.Player),
|
data: make(map[uint32]*socket.Player),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get 根据玩家ID获取玩家实例
|
// Get 根据玩家ID获取玩家实例
|
||||||
// 读操作使用RLock,允许多个goroutine同时读取
|
// 读操作使用RLock,允许多个goroutine同时读取
|
||||||
func (m *Space) Get(playerID uint32) (*entity.Player, bool) {
|
func (m *Space) Get(playerID uint32) (*socket.Player, bool) {
|
||||||
m.mu.RLock()
|
m.mu.RLock()
|
||||||
defer m.mu.RUnlock()
|
defer m.mu.RUnlock()
|
||||||
val, exists := m.data[playerID]
|
val, exists := m.data[playerID]
|
||||||
@@ -37,10 +37,12 @@ func (m *Space) Get(playerID uint32) (*entity.Player, bool) {
|
|||||||
|
|
||||||
// Set 存储玩家实例(按ID)
|
// Set 存储玩家实例(按ID)
|
||||||
// 写操作使用Lock,独占锁保证数据一致性
|
// 写操作使用Lock,独占锁保证数据一致性
|
||||||
func (m *Space) Set(playerID uint32, player *entity.Player) {
|
func (m *Space) Set(playerID uint32, player *socket.Player)*Space {
|
||||||
m.mu.Lock()
|
m.mu.Lock()
|
||||||
defer m.mu.Unlock()
|
defer m.mu.Unlock()
|
||||||
m.data[playerID] = player
|
m.data[playerID] = player
|
||||||
|
|
||||||
|
return m
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete 根据玩家ID删除玩家实例
|
// Delete 根据玩家ID删除玩家实例
|
||||||
@@ -61,7 +63,7 @@ func (m *Space) Len() int {
|
|||||||
|
|
||||||
// Range 遍历所有玩家并执行回调函数
|
// Range 遍历所有玩家并执行回调函数
|
||||||
// 读操作使用RLock,遍历过程中不会阻塞其他读操作
|
// 读操作使用RLock,遍历过程中不会阻塞其他读操作
|
||||||
func (m *Space) Range(f func(playerID uint32, player *entity.Player) bool) {
|
func (m *Space) Range(f func(playerID uint32, player *socket.Player) bool) {
|
||||||
m.mu.RLock()
|
m.mu.RLock()
|
||||||
defer m.mu.RUnlock()
|
defer m.mu.RUnlock()
|
||||||
for id, player := range m.data {
|
for id, player := range m.data {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package space
|
package space
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"blazing/common/data/entity"
|
"blazing/common/data/socket"
|
||||||
"blazing/common/socket/handler"
|
"blazing/common/socket/handler"
|
||||||
"blazing/modules/blazing/model"
|
"blazing/modules/blazing/model"
|
||||||
)
|
)
|
||||||
@@ -23,7 +23,7 @@ func (t *InInfo) Broadcast(mapid uint32, o OutInfo) {
|
|||||||
//tt := planetmap
|
//tt := planetmap
|
||||||
//g.Dump(GetSpace(mapid).Len())
|
//g.Dump(GetSpace(mapid).Len())
|
||||||
|
|
||||||
GetSpace(mapid).Range(func(playerID uint32, player *entity.Player) bool {
|
GetSpace(mapid).Range(func(playerID uint32, player *socket.Player) bool {
|
||||||
t.Head.Result = 0
|
t.Head.Result = 0
|
||||||
tt := t.Head.Pack(&o)
|
tt := t.Head.Pack(&o)
|
||||||
err := player.SendPack(tt)
|
err := player.SendPack(tt)
|
||||||
|
|||||||
Reference in New Issue
Block a user