parent
260117bf31
commit
57f2e21061
@ -11,6 +11,7 @@ import (
|
|||||||
proto "server/msg"
|
proto "server/msg"
|
||||||
"server/pkg/github.com/name5566/leaf/log"
|
"server/pkg/github.com/name5566/leaf/log"
|
||||||
"sort"
|
"sort"
|
||||||
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -23,6 +24,7 @@ type ChampshipMgr struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type ChampshipData struct {
|
type ChampshipData struct {
|
||||||
|
mu sync.RWMutex
|
||||||
AutoId int
|
AutoId int
|
||||||
RobotId int
|
RobotId int
|
||||||
Rank map[int][]*ChampshipRank // 锦标赛排行榜
|
Rank map[int][]*ChampshipRank // 锦标赛排行榜
|
||||||
@ -115,7 +117,7 @@ func (c *ChampshipMgr) NotifyAll() (interface{}, error) {
|
|||||||
func (c *ChampshipMgr) ZeroUpdate() (interface{}, error) {
|
func (c *ChampshipMgr) ZeroUpdate() (interface{}, error) {
|
||||||
log.Debug("ChampshipMgr ZeroUpdate")
|
log.Debug("ChampshipMgr ZeroUpdate")
|
||||||
data := c.getData()
|
data := c.getData()
|
||||||
c.lock.Lock()
|
data.mu.Lock()
|
||||||
data.ZeroTime = GoUtil.ZeroTimestamp()
|
data.ZeroTime = GoUtil.ZeroTimestamp()
|
||||||
// 深拷贝 map,避免多个协程持有同一个 map 引用导致并发读写
|
// 深拷贝 map,避免多个协程持有同一个 map 引用导致并发读写
|
||||||
oldRank := make(map[int][]*ChampshipRank, len(data.Rank))
|
oldRank := make(map[int][]*ChampshipRank, len(data.Rank))
|
||||||
@ -144,7 +146,7 @@ func (c *ChampshipMgr) ZeroUpdate() (interface{}, error) {
|
|||||||
for k := range data.PreGroupInfo {
|
for k := range data.PreGroupInfo {
|
||||||
c.SetRankCache(k)
|
c.SetRankCache(k)
|
||||||
}
|
}
|
||||||
c.lock.Unlock()
|
data.mu.Unlock()
|
||||||
|
|
||||||
c.mDispatr.AfterFunc(time.Duration(GoUtil.NextZeroTimestampDuration())*time.Second, func() {
|
c.mDispatr.AfterFunc(time.Duration(GoUtil.NextZeroTimestampDuration())*time.Second, func() {
|
||||||
c.ZeroUpdate()
|
c.ZeroUpdate()
|
||||||
@ -159,7 +161,7 @@ func (c *ChampshipMgr) ZeroUpdate() (interface{}, error) {
|
|||||||
|
|
||||||
func (c *ChampshipMgr) NotifyPlayer() {
|
func (c *ChampshipMgr) NotifyPlayer() {
|
||||||
data := c.getData()
|
data := c.getData()
|
||||||
c.lock.Lock()
|
data.mu.RLock()
|
||||||
// 深拷贝需要通知的数据,避免在锁外访问 map
|
// 深拷贝需要通知的数据,避免在锁外访问 map
|
||||||
notifyList := make([]struct {
|
notifyList := make([]struct {
|
||||||
Uid int
|
Uid int
|
||||||
@ -176,7 +178,7 @@ func (c *ChampshipMgr) NotifyPlayer() {
|
|||||||
}{Uid: v[i].Uid, Rank: i + 1})
|
}{Uid: v[i].Uid, Rank: i + 1})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
c.lock.Unlock()
|
data.mu.RUnlock()
|
||||||
|
|
||||||
// 在锁外通知,避免持锁时间过长
|
// 在锁外通知,避免持锁时间过长
|
||||||
for _, item := range notifyList {
|
for _, item := range notifyList {
|
||||||
@ -186,8 +188,8 @@ func (c *ChampshipMgr) NotifyPlayer() {
|
|||||||
|
|
||||||
func (c *ChampshipMgr) ai() (interface{}, error) {
|
func (c *ChampshipMgr) ai() (interface{}, error) {
|
||||||
ChampshipData := c.getData()
|
ChampshipData := c.getData()
|
||||||
c.lock.Lock()
|
ChampshipData.mu.Lock()
|
||||||
defer c.lock.Unlock()
|
defer ChampshipData.mu.Unlock()
|
||||||
Now := GoUtil.Now()
|
Now := GoUtil.Now()
|
||||||
uids := make(map[int]struct{})
|
uids := make(map[int]struct{})
|
||||||
for k, v := range ChampshipData.Rank {
|
for k, v := range ChampshipData.Rank {
|
||||||
@ -248,8 +250,8 @@ func (c *ChampshipMgr) ai() (interface{}, error) {
|
|||||||
|
|
||||||
func (c *ChampshipMgr) GetPreRankMsg(Uid int) *proto.ResChampshipPreRank {
|
func (c *ChampshipMgr) GetPreRankMsg(Uid int) *proto.ResChampshipPreRank {
|
||||||
ChampshipData := c.getData()
|
ChampshipData := c.getData()
|
||||||
c.lock.Lock()
|
ChampshipData.mu.RLock()
|
||||||
defer c.lock.Unlock()
|
defer ChampshipData.mu.RUnlock()
|
||||||
GroupId := ChampshipData.PreGroupInfo[Uid]
|
GroupId := ChampshipData.PreGroupInfo[Uid]
|
||||||
if GroupId == 0 {
|
if GroupId == 0 {
|
||||||
return &proto.ResChampshipPreRank{}
|
return &proto.ResChampshipPreRank{}
|
||||||
@ -306,8 +308,8 @@ func (c *ChampshipMgr) GetPreRankMsg(Uid int) *proto.ResChampshipPreRank {
|
|||||||
// TODO 待优化
|
// TODO 待优化
|
||||||
func (c *ChampshipMgr) GetRankMsg(Uid int) *proto.ResChampshipRank {
|
func (c *ChampshipMgr) GetRankMsg(Uid int) *proto.ResChampshipRank {
|
||||||
ChampshipData := c.getData()
|
ChampshipData := c.getData()
|
||||||
c.lock.Lock()
|
ChampshipData.mu.RLock()
|
||||||
defer c.lock.Unlock()
|
defer ChampshipData.mu.RUnlock()
|
||||||
GroupId := ChampshipData.GroupInfo[Uid]
|
GroupId := ChampshipData.GroupInfo[Uid]
|
||||||
if GroupId == 0 {
|
if GroupId == 0 {
|
||||||
return &proto.ResChampshipRank{}
|
return &proto.ResChampshipRank{}
|
||||||
@ -371,8 +373,8 @@ func (c *ChampshipMgr) group() (interface{}, error) {
|
|||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
ChampshipData := c.getData()
|
ChampshipData := c.getData()
|
||||||
c.lock.Lock()
|
ChampshipData.mu.Lock()
|
||||||
defer c.lock.Unlock()
|
defer ChampshipData.mu.Unlock()
|
||||||
if len(ChampshipData.Pool) == 0 { // 未分配玩家池为空
|
if len(ChampshipData.Pool) == 0 { // 未分配玩家池为空
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
@ -468,8 +470,8 @@ func (c *ChampshipMgr) group() (interface{}, error) {
|
|||||||
|
|
||||||
func (c *ChampshipMgr) getGroupId(Uid int) int {
|
func (c *ChampshipMgr) getGroupId(Uid int) int {
|
||||||
ChampshipData := c.getData()
|
ChampshipData := c.getData()
|
||||||
c.lock.Lock()
|
ChampshipData.mu.RLock()
|
||||||
defer c.lock.Unlock()
|
defer ChampshipData.mu.RUnlock()
|
||||||
GroupId, ok := ChampshipData.GroupInfo[Uid]
|
GroupId, ok := ChampshipData.GroupInfo[Uid]
|
||||||
if ok {
|
if ok {
|
||||||
return GroupId
|
return GroupId
|
||||||
@ -484,8 +486,8 @@ func (c *ChampshipMgr) inRank(m *msg.Msg) (interface{}, error) {
|
|||||||
GroupId := c.getGroupId(data.Uid)
|
GroupId := c.getGroupId(data.Uid)
|
||||||
|
|
||||||
ChampshipData := c.getData()
|
ChampshipData := c.getData()
|
||||||
c.lock.Lock()
|
ChampshipData.mu.Lock()
|
||||||
defer c.lock.Unlock()
|
defer ChampshipData.mu.Unlock()
|
||||||
|
|
||||||
// 再次检查 GroupId,因为可能在等待锁期间被其他协程修改
|
// 再次检查 GroupId,因为可能在等待锁期间被其他协程修改
|
||||||
if currentGroupId, ok := ChampshipData.GroupInfo[data.Uid]; ok {
|
if currentGroupId, ok := ChampshipData.GroupInfo[data.Uid]; ok {
|
||||||
@ -557,8 +559,8 @@ func (c *ChampshipMgr) inRank(m *msg.Msg) (interface{}, error) {
|
|||||||
|
|
||||||
func (c *ChampshipMgr) getMyRank(Uid int) int {
|
func (c *ChampshipMgr) getMyRank(Uid int) int {
|
||||||
ChampshipData := c.getData()
|
ChampshipData := c.getData()
|
||||||
c.lock.Lock()
|
ChampshipData.mu.RLock()
|
||||||
defer c.lock.Unlock()
|
defer ChampshipData.mu.RUnlock()
|
||||||
GroupId := ChampshipData.GroupInfo[Uid]
|
GroupId := ChampshipData.GroupInfo[Uid]
|
||||||
if GroupId == 0 {
|
if GroupId == 0 {
|
||||||
return 0
|
return 0
|
||||||
@ -595,8 +597,8 @@ func (c *ChampshipMgr) unsafe_getMyRank(Uid int) int {
|
|||||||
|
|
||||||
func (c *ChampshipMgr) getLastMyRank(Uid int) int {
|
func (c *ChampshipMgr) getLastMyRank(Uid int) int {
|
||||||
ChampshipData := c.getData()
|
ChampshipData := c.getData()
|
||||||
c.lock.Lock()
|
ChampshipData.mu.RLock()
|
||||||
defer c.lock.Unlock()
|
defer ChampshipData.mu.RUnlock()
|
||||||
GroupId := ChampshipData.PreGroupInfo[Uid]
|
GroupId := ChampshipData.PreGroupInfo[Uid]
|
||||||
if GroupId == 0 {
|
if GroupId == 0 {
|
||||||
return 0
|
return 0
|
||||||
|
|||||||
@ -49,6 +49,7 @@ type MessageMgr struct {
|
|||||||
type MessageData struct {
|
type MessageData struct {
|
||||||
MessageList map[int64]*MessageList
|
MessageList map[int64]*MessageList
|
||||||
PlayerList map[int64]int
|
PlayerList map[int64]int
|
||||||
|
mu sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
type MessageList struct {
|
type MessageList struct {
|
||||||
@ -129,8 +130,8 @@ func (m *MessageMgr) MessageMgrInit() {
|
|||||||
func FixBug() {
|
func FixBug() {
|
||||||
messageMgrData := getMessageData()
|
messageMgrData := getMessageData()
|
||||||
// 先更新 PlayerList(需要加锁)
|
// 先更新 PlayerList(需要加锁)
|
||||||
G_GameLogicPtr.MessageMgr.lock.Lock()
|
messageMgrData.mu.Lock()
|
||||||
defer G_GameLogicPtr.MessageMgr.lock.Unlock()
|
defer messageMgrData.mu.Unlock()
|
||||||
now := GoUtil.Now()
|
now := GoUtil.Now()
|
||||||
for k, v := range messageMgrData.MessageList {
|
for k, v := range messageMgrData.MessageList {
|
||||||
if k < 100000 {
|
if k < 100000 {
|
||||||
@ -212,12 +213,12 @@ func ChampshipRankInfoHandler(data *msg.Msg) (interface{}, error) {
|
|||||||
func NotifyAllPlayerMsg(m *msg.Msg) {
|
func NotifyAllPlayerMsg(m *msg.Msg) {
|
||||||
messageMgrData := getMessageData()
|
messageMgrData := getMessageData()
|
||||||
// 先复制 PlayerList,避免长时间持有锁
|
// 先复制 PlayerList,避免长时间持有锁
|
||||||
G_GameLogicPtr.MessageMgr.lock.Lock()
|
messageMgrData.mu.Lock()
|
||||||
playerListCopy := make(map[int64]int, len(messageMgrData.PlayerList))
|
playerListCopy := make(map[int64]int, len(messageMgrData.PlayerList))
|
||||||
for k, v := range messageMgrData.PlayerList {
|
for k, v := range messageMgrData.PlayerList {
|
||||||
playerListCopy[k] = v
|
playerListCopy[k] = v
|
||||||
}
|
}
|
||||||
G_GameLogicPtr.MessageMgr.lock.Unlock()
|
messageMgrData.mu.Unlock()
|
||||||
|
|
||||||
// 在锁外发送消息
|
// 在锁外发送消息
|
||||||
for PlayerId, node := range playerListCopy {
|
for PlayerId, node := range playerListCopy {
|
||||||
@ -247,9 +248,9 @@ func CatnipPartnerHandler(data *msg.Msg) (interface{}, error) {
|
|||||||
func ReplyPlayerMsgASync(m *msg.Msg, reply interface{}) (interface{}, error) {
|
func ReplyPlayerMsgASync(m *msg.Msg, reply interface{}) (interface{}, error) {
|
||||||
clone := m.Reply(reply)
|
clone := m.Reply(reply)
|
||||||
messageMgrData := getMessageData()
|
messageMgrData := getMessageData()
|
||||||
G_GameLogicPtr.MessageMgr.lock.Lock()
|
messageMgrData.mu.Lock()
|
||||||
node, ok := messageMgrData.PlayerList[int64(m.From)]
|
node, ok := messageMgrData.PlayerList[int64(m.From)]
|
||||||
G_GameLogicPtr.MessageMgr.lock.Unlock()
|
messageMgrData.mu.Unlock()
|
||||||
|
|
||||||
if ok {
|
if ok {
|
||||||
SendMsgToNodeAsync(clone, node)
|
SendMsgToNodeAsync(clone, node)
|
||||||
@ -270,10 +271,10 @@ func ClusterSyncHandler(data *msg.Msg) (interface{}, error) {
|
|||||||
})
|
})
|
||||||
// 发送暂存区消息(先复制再释放锁,避免长时间持有锁)
|
// 发送暂存区消息(先复制再释放锁,避免长时间持有锁)
|
||||||
messageMgrData := getMessageData()
|
messageMgrData := getMessageData()
|
||||||
G_GameLogicPtr.MessageMgr.lock.Lock()
|
messageMgrData.mu.Lock()
|
||||||
TempMessageList := messageMgrData.MessageList
|
TempMessageList := messageMgrData.MessageList
|
||||||
messageMgrData.MessageList = make(map[int64]*MessageList)
|
messageMgrData.MessageList = make(map[int64]*MessageList)
|
||||||
G_GameLogicPtr.MessageMgr.lock.Unlock() // 立即释放锁,在锁外发送消息
|
messageMgrData.mu.Unlock() // 立即释放锁,在锁外发送消息
|
||||||
|
|
||||||
log.Debug("[Middleware] Cluster sync send temp message len: %d", len(TempMessageList))
|
log.Debug("[Middleware] Cluster sync send temp message len: %d", len(TempMessageList))
|
||||||
for _, Message := range TempMessageList {
|
for _, Message := range TempMessageList {
|
||||||
@ -289,9 +290,9 @@ func PlayerLoginHandler(data *msg.Msg) (interface{}, error) {
|
|||||||
node := data.Extra.(int)
|
node := data.Extra.(int)
|
||||||
messageMgrData := getMessageData()
|
messageMgrData := getMessageData()
|
||||||
// 先更新 PlayerList(需要加锁)
|
// 先更新 PlayerList(需要加锁)
|
||||||
G_GameLogicPtr.MessageMgr.lock.Lock()
|
messageMgrData.mu.Lock()
|
||||||
messageMgrData.PlayerList[int64(data.From)] = node
|
messageMgrData.PlayerList[int64(data.From)] = node
|
||||||
G_GameLogicPtr.MessageMgr.lock.Unlock()
|
messageMgrData.mu.Unlock()
|
||||||
|
|
||||||
log.Debug("[Middleware] Player login success player id: %v, node: %v", data.From, data.Extra.(int))
|
log.Debug("[Middleware] Player login success player id: %v, node: %v", data.From, data.Extra.(int))
|
||||||
// 对玩家消息列表加锁
|
// 对玩家消息列表加锁
|
||||||
@ -329,9 +330,9 @@ func PlayerLoginHandler(data *msg.Msg) (interface{}, error) {
|
|||||||
|
|
||||||
func PlayerLogoutHandler(data *msg.Msg) (interface{}, error) {
|
func PlayerLogoutHandler(data *msg.Msg) (interface{}, error) {
|
||||||
messageMgrData := getMessageData()
|
messageMgrData := getMessageData()
|
||||||
G_GameLogicPtr.MessageMgr.lock.Lock()
|
messageMgrData.mu.Lock()
|
||||||
delete(messageMgrData.PlayerList, int64(data.From))
|
delete(messageMgrData.PlayerList, int64(data.From))
|
||||||
G_GameLogicPtr.MessageMgr.lock.Unlock()
|
messageMgrData.mu.Unlock()
|
||||||
log.Debug("[Middleware] Player logout success player id: %v", data.From)
|
log.Debug("[Middleware] Player logout success player id: %v", data.From)
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
@ -357,9 +358,9 @@ func ComsumerMsgHandler(data *msg.Msg) (interface{}, error) {
|
|||||||
func NotifyPlayerMsgAsync(m *msg.Msg) {
|
func NotifyPlayerMsgAsync(m *msg.Msg) {
|
||||||
messageMgrData := getMessageData()
|
messageMgrData := getMessageData()
|
||||||
// 检查玩家是否在线(需要加锁)
|
// 检查玩家是否在线(需要加锁)
|
||||||
G_GameLogicPtr.MessageMgr.lock.Lock()
|
messageMgrData.mu.Lock()
|
||||||
node, ok := messageMgrData.PlayerList[int64(m.To)]
|
node, ok := messageMgrData.PlayerList[int64(m.To)]
|
||||||
G_GameLogicPtr.MessageMgr.lock.Unlock()
|
messageMgrData.mu.Unlock()
|
||||||
// 在线则直接发送消息
|
// 在线则直接发送消息
|
||||||
if ok {
|
if ok {
|
||||||
SendMsgToNodeAsync(m, node)
|
SendMsgToNodeAsync(m, node)
|
||||||
@ -373,9 +374,9 @@ func CenterPlayerMsgHandler(data *msg.Msg) (interface{}, error) {
|
|||||||
// 遍历消息列表,发送消息给在线玩家
|
// 遍历消息列表,发送消息给在线玩家
|
||||||
|
|
||||||
// 检查玩家是否在线(需要加锁)
|
// 检查玩家是否在线(需要加锁)
|
||||||
G_GameLogicPtr.MessageMgr.lock.Lock()
|
messageMgrData.mu.Lock()
|
||||||
node, ok := messageMgrData.PlayerList[int64(PlayerId)]
|
node, ok := messageMgrData.PlayerList[int64(PlayerId)]
|
||||||
G_GameLogicPtr.MessageMgr.lock.Unlock()
|
messageMgrData.mu.Unlock()
|
||||||
// 在线则直接发送消息
|
// 在线则直接发送消息
|
||||||
if ok {
|
if ok {
|
||||||
SendMsgToNodeAsync(data, node)
|
SendMsgToNodeAsync(data, node)
|
||||||
@ -883,8 +884,9 @@ func sendMessageSync(m *msg.Msg, node int) (*msg.Msg, error) {
|
|||||||
|
|
||||||
// 保存消息到本地
|
// 保存消息到本地
|
||||||
func saveMessage(m *msg.Msg) error {
|
func saveMessage(m *msg.Msg) error {
|
||||||
G_GameLogicPtr.MessageMgr.lock.Lock()
|
data := getMessageData()
|
||||||
defer G_GameLogicPtr.MessageMgr.lock.Unlock()
|
data.mu.Lock()
|
||||||
|
defer data.mu.Unlock()
|
||||||
// 使用不加锁的内部方法,避免死锁
|
// 使用不加锁的内部方法,避免死锁
|
||||||
messages := getMessgeUnsafe(int64(m.To))
|
messages := getMessgeUnsafe(int64(m.To))
|
||||||
messages.mu.Lock()
|
messages.mu.Lock()
|
||||||
@ -931,8 +933,9 @@ func getMessgeUnsafe(PlayerId int64) *MessageList {
|
|||||||
|
|
||||||
// getMessge 获取消息列表(加锁版本)
|
// getMessge 获取消息列表(加锁版本)
|
||||||
func getMessge(PlayerId int64) *MessageList {
|
func getMessge(PlayerId int64) *MessageList {
|
||||||
G_GameLogicPtr.MessageMgr.lock.Lock()
|
messageMgrData := getMessageData()
|
||||||
defer G_GameLogicPtr.MessageMgr.lock.Unlock()
|
messageMgrData.mu.Lock()
|
||||||
|
defer messageMgrData.mu.Unlock()
|
||||||
return getMessgeUnsafe(PlayerId)
|
return getMessgeUnsafe(PlayerId)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -966,8 +969,8 @@ func deleteMessage(m *msg.Msg) error {
|
|||||||
if len(messages.Messages) == 0 {
|
if len(messages.Messages) == 0 {
|
||||||
// 如果消息列表为空,则删除该玩家的消息列表
|
// 如果消息列表为空,则删除该玩家的消息列表
|
||||||
messageMgrData := getMessageData()
|
messageMgrData := getMessageData()
|
||||||
G_GameLogicPtr.MessageMgr.lock.Lock()
|
messageMgrData.mu.Lock()
|
||||||
defer G_GameLogicPtr.MessageMgr.lock.Unlock()
|
defer messageMgrData.mu.Unlock()
|
||||||
delete(messageMgrData.MessageList, int64(m.To))
|
delete(messageMgrData.MessageList, int64(m.To))
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@ -139,9 +139,7 @@ func (s *ServerMod) SaveData() {
|
|||||||
DbData.Key = s.key
|
DbData.Key = s.key
|
||||||
DbData.UpdataTime = GoUtil.Now()
|
DbData.UpdataTime = GoUtil.Now()
|
||||||
var err error
|
var err error
|
||||||
s.lock.Lock()
|
|
||||||
DbData.ModData, err = GoUtil.GobMarshal(s.data)
|
DbData.ModData, err = GoUtil.GobMarshal(s.data)
|
||||||
s.lock.Unlock()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("SaveData Marshal failed,Mod Key: %s err:%v", s.key, err)
|
log.Error("SaveData Marshal failed,Mod Key: %s err:%v", s.key, err)
|
||||||
return
|
return
|
||||||
|
|||||||
@ -7,6 +7,7 @@ import (
|
|||||||
"server/game/mod/msg"
|
"server/game/mod/msg"
|
||||||
GoUtil "server/game_util"
|
GoUtil "server/game_util"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -23,6 +24,7 @@ type VarData struct {
|
|||||||
NewUseVar map[int]map[string]*VarExpireData
|
NewUseVar map[int]map[string]*VarExpireData
|
||||||
ZeroTime int64
|
ZeroTime int64
|
||||||
Version int64
|
Version int64
|
||||||
|
mu sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -64,8 +66,8 @@ func (f *VarMgr) Init() {
|
|||||||
|
|
||||||
func (f *VarMgr) fixbug() {
|
func (f *VarMgr) fixbug() {
|
||||||
data := f.getData()
|
data := f.getData()
|
||||||
f.lock.Lock()
|
data.mu.Lock()
|
||||||
defer f.lock.Unlock()
|
defer data.mu.Unlock()
|
||||||
for k, v := range data.NewUseVar {
|
for k, v := range data.NewUseVar {
|
||||||
if v != nil {
|
if v != nil {
|
||||||
del := true
|
del := true
|
||||||
@ -87,8 +89,8 @@ func (f *VarMgr) version() {
|
|||||||
case 0:
|
case 0:
|
||||||
// future version update
|
// future version update
|
||||||
data := f.getData()
|
data := f.getData()
|
||||||
f.lock.Lock()
|
data.mu.Lock()
|
||||||
defer f.lock.Unlock()
|
defer data.mu.Unlock()
|
||||||
// set to next version
|
// set to next version
|
||||||
for k, v := range data.UserVar {
|
for k, v := range data.UserVar {
|
||||||
if v != nil {
|
if v != nil {
|
||||||
@ -127,8 +129,9 @@ func (f *VarMgr) ZeroUpdate() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (f *VarMgr) HandleCatnipPartner(Uid, Partner, GameId int, EndTime int64) (interface{}, error) {
|
func (f *VarMgr) HandleCatnipPartner(Uid, Partner, GameId int, EndTime int64) (interface{}, error) {
|
||||||
f.lock.Lock()
|
data := f.getData()
|
||||||
defer f.lock.Unlock()
|
data.mu.Lock()
|
||||||
|
defer data.mu.Unlock()
|
||||||
|
|
||||||
OtherPartnerInfo := f.GetUserVar(Uid, VAR_CATNIP_PARTNER)
|
OtherPartnerInfo := f.GetUserVar(Uid, VAR_CATNIP_PARTNER)
|
||||||
MyPartnerInfo := f.GetUserVar(Partner, VAR_CATNIP_PARTNER)
|
MyPartnerInfo := f.GetUserVar(Partner, VAR_CATNIP_PARTNER)
|
||||||
@ -149,8 +152,6 @@ func (f *VarMgr) HandleCatnipPartner(Uid, Partner, GameId int, EndTime int64) (i
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (f *VarMgr) SetUserVar(uid int, key string, value interface{}) {
|
func (f *VarMgr) SetUserVar(uid int, key string, value interface{}) {
|
||||||
f.lock.Lock()
|
|
||||||
defer f.lock.Unlock()
|
|
||||||
varData := f.getData().NewUseVar[uid]
|
varData := f.getData().NewUseVar[uid]
|
||||||
if varData == nil {
|
if varData == nil {
|
||||||
varData = make(map[string]*VarExpireData)
|
varData = make(map[string]*VarExpireData)
|
||||||
@ -167,8 +168,6 @@ func (f *VarMgr) SetUserVar(uid int, key string, value interface{}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (f *VarMgr) GetUserVar(uid int, key string) *VarExpireData {
|
func (f *VarMgr) GetUserVar(uid int, key string) *VarExpireData {
|
||||||
f.lock.Lock()
|
|
||||||
defer f.lock.Unlock()
|
|
||||||
varData := f.getData().NewUseVar[uid]
|
varData := f.getData().NewUseVar[uid]
|
||||||
if varData == nil {
|
if varData == nil {
|
||||||
varData = make(map[string]*VarExpireData)
|
varData = make(map[string]*VarExpireData)
|
||||||
@ -183,8 +182,6 @@ func (f *VarMgr) GetUserVar(uid int, key string) *VarExpireData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (f *VarMgr) SetVar(key string, value interface{}) {
|
func (f *VarMgr) SetVar(key string, value interface{}) {
|
||||||
f.lock.Lock()
|
|
||||||
defer f.lock.Unlock()
|
|
||||||
f.getData().NewVar[key] = &VarExpireData{
|
f.getData().NewVar[key] = &VarExpireData{
|
||||||
D: value,
|
D: value,
|
||||||
}
|
}
|
||||||
@ -201,8 +198,8 @@ func getVarData() *VarData {
|
|||||||
|
|
||||||
func SetVarDataHandler(m *msg.Msg) (interface{}, error) {
|
func SetVarDataHandler(m *msg.Msg) (interface{}, error) {
|
||||||
data := getVarData()
|
data := getVarData()
|
||||||
G_GameLogicPtr.VarMgr.lock.Lock()
|
data.mu.Lock()
|
||||||
defer G_GameLogicPtr.VarMgr.lock.Unlock()
|
defer data.mu.Unlock()
|
||||||
if v, ok := m.Extra.(msg.VarData); ok {
|
if v, ok := m.Extra.(msg.VarData); ok {
|
||||||
ved, ok := data.NewVar[v.Key]
|
ved, ok := data.NewVar[v.Key]
|
||||||
if !ok {
|
if !ok {
|
||||||
@ -240,8 +237,8 @@ func SetVarDataHandler(m *msg.Msg) (interface{}, error) {
|
|||||||
|
|
||||||
func GetUserVarDataHandler(m *msg.Msg) (interface{}, error) {
|
func GetUserVarDataHandler(m *msg.Msg) (interface{}, error) {
|
||||||
data := getVarData()
|
data := getVarData()
|
||||||
G_GameLogicPtr.VarMgr.lock.Lock()
|
data.mu.Lock()
|
||||||
defer G_GameLogicPtr.VarMgr.lock.Unlock()
|
defer data.mu.Unlock()
|
||||||
userVar := &VarExpireData{}
|
userVar := &VarExpireData{}
|
||||||
if v, ok := m.Extra.(msg.VarData); ok {
|
if v, ok := m.Extra.(msg.VarData); ok {
|
||||||
if varData, ok := data.NewUseVar[m.From]; ok {
|
if varData, ok := data.NewUseVar[m.From]; ok {
|
||||||
@ -258,8 +255,8 @@ func GetUserVarDataHandler(m *msg.Msg) (interface{}, error) {
|
|||||||
|
|
||||||
func SetUserVarDataHandler(m *msg.Msg) (interface{}, error) {
|
func SetUserVarDataHandler(m *msg.Msg) (interface{}, error) {
|
||||||
data := getVarData()
|
data := getVarData()
|
||||||
G_GameLogicPtr.VarMgr.lock.Lock()
|
data.mu.Lock()
|
||||||
defer G_GameLogicPtr.VarMgr.lock.Unlock()
|
defer data.mu.Unlock()
|
||||||
if v, ok := m.Extra.(msg.VarData); ok {
|
if v, ok := m.Extra.(msg.VarData); ok {
|
||||||
varData := data.NewUseVar[m.To]
|
varData := data.NewUseVar[m.To]
|
||||||
if varData == nil {
|
if varData == nil {
|
||||||
@ -304,8 +301,6 @@ func SetUserVarDataHandler(m *msg.Msg) (interface{}, error) {
|
|||||||
|
|
||||||
func GetVarDataHandler(m *msg.Msg) (interface{}, error) {
|
func GetVarDataHandler(m *msg.Msg) (interface{}, error) {
|
||||||
data := getVarData()
|
data := getVarData()
|
||||||
G_GameLogicPtr.VarMgr.lock.Lock()
|
|
||||||
defer G_GameLogicPtr.VarMgr.lock.Unlock()
|
|
||||||
varData := &VarExpireData{}
|
varData := &VarExpireData{}
|
||||||
if v, ok := m.Extra.(msg.VarData); ok {
|
if v, ok := m.Extra.(msg.VarData); ok {
|
||||||
varData, _ = data.NewVar[v.Key]
|
varData, _ = data.NewVar[v.Key]
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user