notification功能开发
This commit is contained in:
parent
5b7812c469
commit
d310ce93f6
43
src/server/conf/notification/notification_cfg.go
Normal file
43
src/server/conf/notification/notification_cfg.go
Normal file
@ -0,0 +1,43 @@
|
||||
package notification_cfg
|
||||
|
||||
import "server/gamedata"
|
||||
|
||||
const (
|
||||
CFG_NOTIFICATION = "Notification"
|
||||
)
|
||||
|
||||
func init() {
|
||||
gamedata.InitCfg(CFG_NOTIFICATION)
|
||||
}
|
||||
|
||||
func GetFriendApplyNotificationColdown() int {
|
||||
data, err := gamedata.GetDataByIntKey(CFG_NOTIFICATION, 2)
|
||||
if err != nil {
|
||||
return 0
|
||||
}
|
||||
return gamedata.GetIntValue(data, "Coldown")
|
||||
}
|
||||
|
||||
func GetPetroomGameNotificationColdown() (int, int) {
|
||||
data, err := gamedata.GetDataByIntKey(CFG_NOTIFICATION, 1)
|
||||
if err != nil {
|
||||
return 0, 0
|
||||
}
|
||||
return gamedata.GetIntValue(data, "Coldown"), gamedata.GetIntValue(data, "DailyLimit")
|
||||
}
|
||||
|
||||
func GetPetroomGameNotificationMsg() (string, string) {
|
||||
data, err := gamedata.GetDataByIntKey(CFG_NOTIFICATION, 1)
|
||||
if err != nil {
|
||||
return "", ""
|
||||
}
|
||||
return gamedata.GetStringValue(data, "TitleKey"), gamedata.GetStringValue(data, "InfoKey")
|
||||
}
|
||||
|
||||
func GetFriendApplyNotificationMsg() (string, string) {
|
||||
data, err := gamedata.GetDataByIntKey(CFG_NOTIFICATION, 2)
|
||||
if err != nil {
|
||||
return "", ""
|
||||
}
|
||||
return gamedata.GetStringValue(data, "TitleKey"), gamedata.GetStringValue(data, "InfoKey")
|
||||
}
|
||||
@ -36,6 +36,7 @@ type PlayerSimpleData struct {
|
||||
ActLog *friend.ActLogInfo
|
||||
Physiology map[int]int
|
||||
Lang int
|
||||
Account string
|
||||
}
|
||||
|
||||
type VarGoldCard struct {
|
||||
|
||||
@ -899,6 +899,7 @@ func saveMessage(m *msg.Msg) error {
|
||||
messages.mu.Lock()
|
||||
defer messages.mu.Unlock()
|
||||
now := GoUtil.Now()
|
||||
applycount := 0
|
||||
for _, msgItem := range messages.Messages {
|
||||
if msgItem == nil {
|
||||
continue
|
||||
@ -911,6 +912,12 @@ func saveMessage(m *msg.Msg) error {
|
||||
// 删除过期消息
|
||||
messages.Messages = append(messages.Messages[:0], messages.Messages[1:]...)
|
||||
}
|
||||
if msgItem.Type == msg.HANDLE_TYPE_APPLY {
|
||||
applycount++
|
||||
}
|
||||
}
|
||||
if applycount > 1 && m.Type == msg.HANDLE_TYPE_APPLY {
|
||||
NotifyFriendApply(m.To, m.From)
|
||||
}
|
||||
// 添加消息
|
||||
messages.Messages = append(messages.Messages, m)
|
||||
|
||||
@ -53,6 +53,8 @@ const (
|
||||
HANDLE_MOD_CHAMPSHIP_RANK_LIST = 20015 // 锦标赛排行榜
|
||||
HANDLE_MOD_CHAMPSHIP_PRE_RANK = 20016 // 锦标赛上期排名
|
||||
HANDLE_MOD_CHAMPSHIP_GROUP = 20017 // 锦标赛分组
|
||||
HANDLE_MOD_DAILY_VAR_GET = 20018 // 获取变量
|
||||
HANDLE_MOD_DAILY_VAR_SET = 20019 // 设置变量
|
||||
)
|
||||
|
||||
const (
|
||||
|
||||
54
src/server/game/notification.go
Normal file
54
src/server/game/notification.go
Normal file
@ -0,0 +1,54 @@
|
||||
package game
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
languageCfg "server/conf/language"
|
||||
notification_cfg "server/conf/notification"
|
||||
GoUtil "server/game_util"
|
||||
"server/msg"
|
||||
)
|
||||
|
||||
const (
|
||||
NOTIFY_TYPE_FRIEND_APPLY = 1
|
||||
NOTIFY_TYPE_PETROOM_GAME = 2
|
||||
)
|
||||
|
||||
func NotifyPetroomGame(PlayerId int) {
|
||||
PlayerSimpleData := G_GameLogicPtr.GetSimplePlayerByUid(PlayerId)
|
||||
if PlayerSimpleData == nil {
|
||||
return
|
||||
}
|
||||
count, last := GetPetroomGameNotification(PlayerId)
|
||||
coldown, dailyLimit := notification_cfg.GetPetroomGameNotificationColdown()
|
||||
if count >= dailyLimit {
|
||||
return
|
||||
}
|
||||
if GoUtil.Now()-last < int64(coldown) {
|
||||
return
|
||||
}
|
||||
titlekey, infokey := notification_cfg.GetPetroomGameNotificationMsg()
|
||||
title := languageCfg.GetLanguage(msg.LANG_TYPE(PlayerSimpleData.Lang), titlekey)
|
||||
info := languageCfg.GetLanguage(msg.LANG_TYPE(PlayerSimpleData.Lang), infokey)
|
||||
GoUtil.NotifyPlayer(GoUtil.Int(PlayerSimpleData.Account), NOTIFY_TYPE_PETROOM_GAME, title, fmt.Sprintf(info, PlayerSimpleData.PetName))
|
||||
SetPetroomGameNotification(PlayerId, count+1)
|
||||
}
|
||||
|
||||
func NotifyFriendApply(PlayerId, FriendId int) {
|
||||
PlayerSimpleData := G_GameLogicPtr.GetSimplePlayerByUid(PlayerId)
|
||||
if PlayerSimpleData == nil {
|
||||
return
|
||||
}
|
||||
FriendSimpleData := G_GameLogicPtr.GetSimplePlayerByUid(FriendId)
|
||||
if FriendSimpleData == nil {
|
||||
return
|
||||
}
|
||||
count := GetFriendApplyNotification(PlayerId)
|
||||
if count > 0 {
|
||||
return
|
||||
}
|
||||
titlekey, infokey := notification_cfg.GetFriendApplyNotificationMsg()
|
||||
title := languageCfg.GetLanguage(msg.LANG_TYPE(PlayerSimpleData.Lang), titlekey)
|
||||
info := languageCfg.GetLanguage(msg.LANG_TYPE(PlayerSimpleData.Lang), infokey)
|
||||
GoUtil.NotifyPlayer(GoUtil.Int(PlayerSimpleData.Account), NOTIFY_TYPE_FRIEND_APPLY, title, fmt.Sprintf(info, FriendSimpleData.Name))
|
||||
SetFriendApplyNotification(PlayerId, count+1)
|
||||
}
|
||||
@ -1002,6 +1002,7 @@ func (p *Player) UpdateUserInfo() {
|
||||
simple.ActLog = p.PlayMod.getFriendMod().GetActLogLast()
|
||||
simple.Physiology = p.PlayMod.getPlayroomMod().GetPhysiologyList()
|
||||
simple.Lang = int(p.PlayMod.getBaseMod().Lang)
|
||||
simple.Account = p.PlayMod.getBaseMod().Account
|
||||
//TODO 存储到redis 在新版本中将优化成gob进行压缩
|
||||
value, _ := json.Marshal(simple)
|
||||
IdStr := GoUtil.String(p.M_DwUin)
|
||||
|
||||
@ -3985,6 +3985,7 @@ func ReqPlayroomSelectReward(player *Player, buf []byte) error {
|
||||
PlayroomMod.ResetGame()
|
||||
player.PlayerDecoSetLog("emoji", int(req.EmojiId), "playroom_select_reward")
|
||||
player.PlayroomBackData()
|
||||
NotifyPetroomGame(Target)
|
||||
player.PlayMod.save()
|
||||
player.PushClientRes(&msg.ResPlayroomSelectReward{
|
||||
Code: msg.RES_CODE_SUCCESS,
|
||||
|
||||
@ -28,7 +28,16 @@ func (p *Player) GetVarData(key string) interface{} {
|
||||
return cache.D
|
||||
}
|
||||
|
||||
func (p *Player) GetUserVarData(key string, PlayerId int) interface{} {
|
||||
func GetDailyVarData(key string) interface{} {
|
||||
cache := &VarExpireData{}
|
||||
err := LoadCacheVarData(key, cache)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
return cache.D
|
||||
}
|
||||
|
||||
func GetUserVarData(key string, PlayerId int) interface{} {
|
||||
cache := map[string]*VarExpireData{}
|
||||
err := LoadCacheVarData(GoUtil.GetVarKey(int(PlayerId)), &cache)
|
||||
if err != nil {
|
||||
@ -39,24 +48,18 @@ func (p *Player) GetUserVarData(key string, PlayerId int) interface{} {
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
if data.T > 0 && data.T < GoUtil.Now() {
|
||||
return nil
|
||||
}
|
||||
return data.D
|
||||
}
|
||||
|
||||
// func GetServerVarData(key string) interface{} {
|
||||
// data, err := GetServerData(key)
|
||||
// if err != nil {
|
||||
// log.Error("GetServerVarData err : %s", err)
|
||||
// return nil
|
||||
// }
|
||||
// return data.Extra
|
||||
// }
|
||||
|
||||
func (p *Player) OpVarDataAsync(PlayerId int, key string, value interface{}, opType int) {
|
||||
func OpDailyVarDataAsync(PlayerId int, key string, value interface{}, opType int) {
|
||||
SendMsgToCenterAsync(&msg.Msg{
|
||||
From: int(p.M_DwUin),
|
||||
From: 0,
|
||||
To: PlayerId,
|
||||
SendT: GoUtil.Now(),
|
||||
HandleType: msg.HANDLE_MOD_USER_VAR_SET,
|
||||
HandleType: msg.HANDLE_MOD_DAILY_VAR_SET,
|
||||
Extra: msg.VarData{
|
||||
Key: key,
|
||||
Value: value,
|
||||
@ -65,12 +68,28 @@ func (p *Player) OpVarDataAsync(PlayerId int, key string, value interface{}, opT
|
||||
})
|
||||
}
|
||||
|
||||
func (p *Player) OpVarDataSync(PlayerId int, key string, value interface{}, opType int) (*msg.Msg, error) {
|
||||
func (p *Player) OpVarDataAsync(PlayerId int, key string, value interface{}, opType int, end int64) {
|
||||
SendMsgToCenterAsync(&msg.Msg{
|
||||
From: int(p.M_DwUin),
|
||||
To: PlayerId,
|
||||
SendT: GoUtil.Now(),
|
||||
HandleType: msg.HANDLE_MOD_USER_VAR_SET,
|
||||
End: end,
|
||||
Extra: msg.VarData{
|
||||
Key: key,
|
||||
Value: value,
|
||||
SetType: opType,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func (p *Player) OpVarDataSync(PlayerId int, key string, value interface{}, opType int, end int64) (*msg.Msg, error) {
|
||||
return SendMsgToCenterSync(&msg.Msg{
|
||||
From: int(p.M_DwUin),
|
||||
To: PlayerId,
|
||||
SendT: GoUtil.Now(),
|
||||
HandleType: msg.HANDLE_MOD_USER_VAR_SET,
|
||||
End: end,
|
||||
Extra: msg.VarData{
|
||||
Key: key,
|
||||
Value: value,
|
||||
@ -93,56 +112,56 @@ func (p *Player) OpServerVarDataSync(key string, Value interface{}, opType int)
|
||||
})
|
||||
}
|
||||
|
||||
func (p *Player) SetVarDataAsync(key string, value interface{}, PlayerId int) {
|
||||
p.OpVarDataAsync(PlayerId, key, value, msg.VAR_OP_SET)
|
||||
func (p *Player) SetVarDataAsync(key string, value interface{}, PlayerId int, end int64) {
|
||||
p.OpVarDataAsync(PlayerId, key, value, msg.VAR_OP_SET, end)
|
||||
}
|
||||
|
||||
func (p *Player) AddVarDataAsync(key string, PlayerId int) {
|
||||
p.OpVarDataAsync(PlayerId, key, nil, msg.VAR_OP_ADD)
|
||||
func (p *Player) AddVarDataAsync(key string, PlayerId int, end int64) {
|
||||
p.OpVarDataAsync(PlayerId, key, nil, msg.VAR_OP_ADD, end)
|
||||
}
|
||||
|
||||
func (p *Player) SubVarDataAsync(key string, PlayerId int) {
|
||||
p.OpVarDataAsync(PlayerId, key, nil, msg.VAR_OP_SUB)
|
||||
func (p *Player) SubVarDataAsync(key string, PlayerId int, end int64) {
|
||||
p.OpVarDataAsync(PlayerId, key, nil, msg.VAR_OP_SUB, end)
|
||||
}
|
||||
|
||||
func (p *Player) AddPlayroomUpvote(PlayerId int) {
|
||||
p.AddVarDataAsync(VAR_PLAYROOM_UPVOTE, PlayerId)
|
||||
p.AddVarDataAsync(VAR_PLAYROOM_UPVOTE, PlayerId, 0)
|
||||
}
|
||||
|
||||
func (p *Player) AddPlayroomChip(PlayerId int) {
|
||||
p.AddVarDataAsync(VAR_PLAYROOM_CHIP, PlayerId)
|
||||
p.AddVarDataAsync(VAR_PLAYROOM_CHIP, PlayerId, 0)
|
||||
}
|
||||
|
||||
func (p *Player) SubPlayroomChip(PlayerId int) {
|
||||
p.SubVarDataAsync(VAR_PLAYROOM_CHIP, PlayerId)
|
||||
p.SubVarDataAsync(VAR_PLAYROOM_CHIP, PlayerId, 0)
|
||||
}
|
||||
|
||||
func (p *Player) GetPlayroomUpvote(PlayerId int) int {
|
||||
data := p.GetUserVarData(VAR_PLAYROOM_UPVOTE, PlayerId)
|
||||
data := GetUserVarData(VAR_PLAYROOM_UPVOTE, PlayerId)
|
||||
if data == nil {
|
||||
return 0
|
||||
}
|
||||
return data.(int)
|
||||
return GoUtil.Int(data)
|
||||
}
|
||||
|
||||
func (p *Player) GetPlayroomChip(PlayerId int) int {
|
||||
data := p.GetUserVarData(VAR_PLAYROOM_CHIP, PlayerId)
|
||||
data := GetUserVarData(VAR_PLAYROOM_CHIP, PlayerId)
|
||||
if data == nil {
|
||||
return 0
|
||||
}
|
||||
return data.(int)
|
||||
return GoUtil.Int(data)
|
||||
}
|
||||
|
||||
func (p *Player) SetPlayroomKiss(Kiss int, PlayerId int) {
|
||||
p.SetVarDataAsync(VAR_PLAYROOM_KISS, Kiss, PlayerId)
|
||||
p.SetVarDataAsync(VAR_PLAYROOM_KISS, Kiss, PlayerId, 0)
|
||||
}
|
||||
|
||||
func (p *Player) GetPlayroomKiss(PlayerId int) int {
|
||||
data := p.GetUserVarData(VAR_PLAYROOM_KISS, PlayerId)
|
||||
data := GetUserVarData(VAR_PLAYROOM_KISS, PlayerId)
|
||||
if data == nil {
|
||||
return 0
|
||||
}
|
||||
return data.(int)
|
||||
return GoUtil.Int(data)
|
||||
}
|
||||
|
||||
func (p *Player) GetGoldCard() *VarGoldCard {
|
||||
@ -150,7 +169,11 @@ func (p *Player) GetGoldCard() *VarGoldCard {
|
||||
if data == nil {
|
||||
return &VarGoldCard{}
|
||||
}
|
||||
return data.(*VarGoldCard)
|
||||
i, ok := data.(*VarGoldCard)
|
||||
if !ok {
|
||||
return &VarGoldCard{}
|
||||
}
|
||||
return i
|
||||
}
|
||||
|
||||
func (p *Player) GetCatnipPartner(Uid int) []int {
|
||||
@ -184,3 +207,47 @@ func LoadCacheVarData(key string, value interface{}) error {
|
||||
}
|
||||
return GoUtil.GobUnmarshal(data, value)
|
||||
}
|
||||
|
||||
const (
|
||||
notifyKeyFriendApply = "friend_apply_n"
|
||||
notifyKeyPetroomGame = "petroom_game_n"
|
||||
)
|
||||
|
||||
func GetFriendApplyNotification(PlayerId int) int {
|
||||
data := GetUserVarData(notifyKeyFriendApply, PlayerId)
|
||||
if data == nil {
|
||||
return 0
|
||||
}
|
||||
return GoUtil.Int(data)
|
||||
}
|
||||
|
||||
func SetFriendApplyNotification(PlayerId int, Count int) {
|
||||
p := new(Player)
|
||||
p.SetVarDataAsync(notifyKeyFriendApply, Count, PlayerId, 0)
|
||||
}
|
||||
|
||||
func GetPetroomGameNotification(PlayerId int) (int, int64) {
|
||||
data := GetUserVarData(notifyKeyPetroomGame, PlayerId)
|
||||
if data == nil {
|
||||
return 0, 0
|
||||
}
|
||||
info, ok := data.(*VarExpireData)
|
||||
if !ok {
|
||||
return 0, 0
|
||||
}
|
||||
if info.T > 0 && info.T < GoUtil.Now() {
|
||||
return 0, 0
|
||||
}
|
||||
v, ok := info.D.(map[string]interface{})
|
||||
return GoUtil.Int(v["count"]), GoUtil.Int64(v["send"])
|
||||
}
|
||||
|
||||
func SetPetroomGameNotification(PlayerId int, Count int) {
|
||||
p := new(Player)
|
||||
end := GoUtil.ZeroTimestamp() + oneday
|
||||
value := map[string]interface{}{
|
||||
"count": Count,
|
||||
"send": GoUtil.Now(),
|
||||
}
|
||||
p.SetVarDataAsync(notifyKeyPetroomGame, value, PlayerId, end)
|
||||
}
|
||||
|
||||
@ -22,6 +22,7 @@ type VarData struct {
|
||||
|
||||
NewVar map[string]*VarExpireData
|
||||
NewUseVar map[int]map[string]*VarExpireData
|
||||
DailyVar map[string]*VarExpireData
|
||||
ZeroTime int64
|
||||
Version int64
|
||||
mu sync.Mutex
|
||||
@ -47,14 +48,17 @@ func (f *VarMgr) Init() {
|
||||
f.init()
|
||||
// 版本更新 重构
|
||||
f.version()
|
||||
if f.data.(*VarData).NewVar == nil {
|
||||
f.data.(*VarData).NewVar = make(map[string]*VarExpireData)
|
||||
if f.getData().NewVar == nil {
|
||||
f.getData().NewVar = make(map[string]*VarExpireData)
|
||||
}
|
||||
if f.data.(*VarData).UserVar == nil {
|
||||
f.data.(*VarData).UserVar = make(map[string]*VarUserData)
|
||||
if f.getData().UserVar == nil {
|
||||
f.getData().UserVar = make(map[string]*VarUserData)
|
||||
}
|
||||
if f.data.(*VarData).VarExpire == nil {
|
||||
f.data.(*VarData).VarExpire = make(map[string]*VarExpireData)
|
||||
if f.getData().VarExpire == nil {
|
||||
f.getData().VarExpire = make(map[string]*VarExpireData)
|
||||
}
|
||||
if f.getData().DailyVar == nil {
|
||||
f.getData().DailyVar = make(map[string]*VarExpireData)
|
||||
}
|
||||
if f.getData().ZeroTime == GoUtil.ZeroTimestamp() {
|
||||
f.ZeroUpdate()
|
||||
@ -72,7 +76,7 @@ func (f *VarMgr) fixbug() {
|
||||
if v != nil {
|
||||
del := true
|
||||
for _, ved := range v {
|
||||
if ved.D.(int) != 0 {
|
||||
if n, ok := ved.D.(int); ok && n != 0 {
|
||||
del = false
|
||||
}
|
||||
}
|
||||
@ -92,13 +96,13 @@ func (f *VarMgr) version() {
|
||||
data.mu.Lock()
|
||||
defer data.mu.Unlock()
|
||||
// set to next version
|
||||
for k, v := range data.UserVar {
|
||||
if v != nil {
|
||||
for k, userData := range data.UserVar {
|
||||
if userData != nil {
|
||||
uidStr := strings.Split(k, "_")[2]
|
||||
uid := GoUtil.Int(uidStr)
|
||||
f.SetUserVar(uid, VAR_PLAYROOM_UPVOTE, v.Upvote)
|
||||
f.SetUserVar(uid, VAR_PLAYROOM_CHIP, v.Chip)
|
||||
f.SetUserVar(uid, VAR_PLAYROOM_KISS, v.Kiss)
|
||||
f.SetUserVar(uid, VAR_PLAYROOM_UPVOTE, userData.Upvote)
|
||||
f.SetUserVar(uid, VAR_PLAYROOM_CHIP, userData.Chip)
|
||||
f.SetUserVar(uid, VAR_PLAYROOM_KISS, userData.Kiss)
|
||||
delete(data.UserVar, k)
|
||||
}
|
||||
}
|
||||
@ -111,18 +115,23 @@ func (f *VarMgr) version() {
|
||||
}
|
||||
|
||||
func (f *VarMgr) ZeroUpdate() {
|
||||
f.getData().ZeroTime = GoUtil.ZeroTimestamp()
|
||||
data := f.getData()
|
||||
data.mu.Lock()
|
||||
defer data.mu.Unlock()
|
||||
data.ZeroTime = GoUtil.ZeroTimestamp()
|
||||
// 随机生成两个金卡
|
||||
Card1, Card2 := card.RankGoldCard()
|
||||
f.SetVar(VAR_GOLD_CARD, &VarGoldCard{
|
||||
Four: Card1,
|
||||
Five: Card2,
|
||||
})
|
||||
for k, v := range f.getData().NewVar {
|
||||
for k, v := range data.NewVar {
|
||||
if v.T < GoUtil.ZeroTimestamp() {
|
||||
delete(f.getData().Var, k)
|
||||
delete(data.NewVar, k)
|
||||
}
|
||||
}
|
||||
// 清空每日变量
|
||||
data.DailyVar = make(map[string]*VarExpireData)
|
||||
f.mDispatr.AfterFunc(time.Duration(GoUtil.NextZeroTimestampDuration())*time.Second, func() {
|
||||
f.ZeroUpdate()
|
||||
})
|
||||
@ -163,7 +172,6 @@ func (f *VarMgr) SetUserVar(uid int, key string, value interface{}) {
|
||||
}
|
||||
ved.D = value
|
||||
varData[key] = ved
|
||||
f.getData().NewUseVar[uid] = varData
|
||||
SaveCacheVarData(GoUtil.GetVarKey(uid), varData)
|
||||
}
|
||||
|
||||
@ -171,7 +179,6 @@ func (f *VarMgr) GetUserVar(uid int, key string) *VarExpireData {
|
||||
varData := f.getData().NewUseVar[uid]
|
||||
if varData == nil {
|
||||
varData = make(map[string]*VarExpireData)
|
||||
//f.getData().NewUseVar[uid] = varData
|
||||
}
|
||||
ved, ok := varData[key]
|
||||
if !ok {
|
||||
@ -189,7 +196,7 @@ func (f *VarMgr) SetVar(key string, value interface{}) {
|
||||
}
|
||||
|
||||
func (f *VarMgr) getData() *VarData {
|
||||
return f.data.(*VarData)
|
||||
return f.getData()
|
||||
}
|
||||
|
||||
func getVarData() *VarData {
|
||||
@ -200,38 +207,20 @@ func SetVarDataHandler(m *msg.Msg) (interface{}, error) {
|
||||
data := getVarData()
|
||||
data.mu.Lock()
|
||||
defer data.mu.Unlock()
|
||||
if v, ok := m.Extra.(msg.VarData); ok {
|
||||
ved, ok := data.NewVar[v.Key]
|
||||
if !ok {
|
||||
ved = &VarExpireData{}
|
||||
}
|
||||
switch v.SetType {
|
||||
case msg.VAR_OP_SET:
|
||||
ved.D = v.Value
|
||||
case msg.VAR_OP_ADD:
|
||||
if num, ok := ved.D.(int); ok {
|
||||
ved.D = num + 1
|
||||
} else {
|
||||
ved.D = 1
|
||||
}
|
||||
case msg.VAR_OP_SUB:
|
||||
if num, ok := ved.D.(int); ok {
|
||||
if num > 0 {
|
||||
ved.D = num - 1
|
||||
} else {
|
||||
ved.D = 0
|
||||
}
|
||||
} else {
|
||||
ved.D = 0
|
||||
}
|
||||
}
|
||||
ved.U = time.Now().Unix()
|
||||
if m.End > 0 {
|
||||
ved.T = m.End
|
||||
}
|
||||
data.NewVar[v.Key] = ved
|
||||
SaveCacheVarData(v.Key, ved)
|
||||
v, ok := m.Extra.(msg.VarData)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("invalid parameters for setting var data")
|
||||
}
|
||||
ved, ok := data.NewVar[v.Key]
|
||||
if !ok {
|
||||
ved = &VarExpireData{}
|
||||
}
|
||||
varDataOperation(ved, v.SetType, v.Value)
|
||||
if m.End > 0 {
|
||||
ved.T = m.End
|
||||
}
|
||||
data.NewVar[v.Key] = ved
|
||||
SaveCacheVarData(v.Key, ved)
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
@ -257,53 +246,69 @@ func SetUserVarDataHandler(m *msg.Msg) (interface{}, error) {
|
||||
data := getVarData()
|
||||
data.mu.Lock()
|
||||
defer data.mu.Unlock()
|
||||
if v, ok := m.Extra.(msg.VarData); ok {
|
||||
varData := data.NewUseVar[m.To]
|
||||
if varData == nil {
|
||||
varData = make(map[string]*VarExpireData)
|
||||
data.NewUseVar[m.To] = varData
|
||||
}
|
||||
ved, ok := varData[v.Key]
|
||||
if !ok {
|
||||
ved = &VarExpireData{}
|
||||
}
|
||||
switch v.SetType {
|
||||
case msg.VAR_OP_SET:
|
||||
ved.D = v.Value
|
||||
case msg.VAR_OP_ADD:
|
||||
if num, ok := ved.D.(int); ok {
|
||||
ved.D = num + 1
|
||||
} else {
|
||||
ved.D = 1
|
||||
}
|
||||
case msg.VAR_OP_SUB:
|
||||
if num, ok := ved.D.(int); ok {
|
||||
if num > 0 {
|
||||
ved.D = num - 1
|
||||
} else {
|
||||
ved.D = 0
|
||||
}
|
||||
} else {
|
||||
ved.D = 0
|
||||
}
|
||||
}
|
||||
ved.U = time.Now().Unix()
|
||||
if m.End > 0 {
|
||||
ved.T = m.End
|
||||
}
|
||||
varData[v.Key] = ved
|
||||
data.NewUseVar[m.To] = varData
|
||||
SaveCacheVarData(GoUtil.GetVarKey(m.To), data.NewUseVar[m.To])
|
||||
v, ok := m.Extra.(msg.VarData)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("invalid parameters for setting var data")
|
||||
}
|
||||
// 保存到缓存中
|
||||
varData := data.NewUseVar[m.To]
|
||||
if varData == nil {
|
||||
varData = make(map[string]*VarExpireData)
|
||||
data.NewUseVar[m.To] = varData
|
||||
}
|
||||
ved := varData[v.Key]
|
||||
if ved == nil {
|
||||
ved = &VarExpireData{}
|
||||
}
|
||||
varDataOperation(ved, v.SetType, v.Value)
|
||||
if m.End > 0 {
|
||||
ved.T = m.End
|
||||
}
|
||||
varData[v.Key] = ved
|
||||
SaveCacheVarData(GoUtil.GetVarKey(m.To), varData)
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func GetVarDataHandler(m *msg.Msg) (interface{}, error) {
|
||||
data := getVarData()
|
||||
varData := &VarExpireData{}
|
||||
info, ok := m.Extra.(msg.VarData)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("invalid parameters for getting var data")
|
||||
}
|
||||
varData, _ = data.NewVar[info.Key]
|
||||
if varData == nil {
|
||||
varData = &VarExpireData{}
|
||||
}
|
||||
ReplyPlayerMsgASync(m, varData.D)
|
||||
return varData, nil
|
||||
}
|
||||
|
||||
func SetDailyVarDataHandler(m *msg.Msg) (interface{}, error) {
|
||||
data := getVarData()
|
||||
data.mu.Lock()
|
||||
defer data.mu.Unlock()
|
||||
info, ok := m.Extra.(msg.VarData)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("invalid parameters for getting daily var data")
|
||||
}
|
||||
varData := data.DailyVar[info.Key]
|
||||
if varData == nil {
|
||||
varData = &VarExpireData{}
|
||||
}
|
||||
varDataOperation(varData, info.SetType, info.Value)
|
||||
if m.End > 0 {
|
||||
varData.T = m.End
|
||||
}
|
||||
data.DailyVar[info.Key] = varData
|
||||
SaveCacheVarData(GoUtil.GetVarKey(m.To), varData)
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func GetDailyVarDataHandler(m *msg.Msg) (interface{}, error) {
|
||||
data := getVarData()
|
||||
varData := &VarExpireData{}
|
||||
if v, ok := m.Extra.(msg.VarData); ok {
|
||||
varData, _ = data.NewVar[v.Key]
|
||||
varData, _ = data.DailyVar[v.Key]
|
||||
if varData == nil {
|
||||
varData = &VarExpireData{}
|
||||
}
|
||||
@ -312,3 +317,28 @@ func GetVarDataHandler(m *msg.Msg) (interface{}, error) {
|
||||
}
|
||||
return nil, fmt.Errorf("invalid parameters for getting var data")
|
||||
}
|
||||
|
||||
func varDataOperation(varData *VarExpireData, setType int, value interface{}) *VarExpireData {
|
||||
switch setType {
|
||||
case msg.VAR_OP_SET:
|
||||
varData.D = value
|
||||
case msg.VAR_OP_ADD:
|
||||
if num, ok := varData.D.(int); ok {
|
||||
varData.D = num + 1
|
||||
} else {
|
||||
varData.D = 1
|
||||
}
|
||||
case msg.VAR_OP_SUB:
|
||||
if num, ok := varData.D.(int); ok {
|
||||
if num > 0 {
|
||||
varData.D = num - 1
|
||||
} else {
|
||||
varData.D = 0
|
||||
}
|
||||
} else {
|
||||
varData.D = 0
|
||||
}
|
||||
}
|
||||
varData.U = GoUtil.Now()
|
||||
return varData
|
||||
}
|
||||
|
||||
@ -15,6 +15,7 @@ import (
|
||||
"math/rand"
|
||||
"net/http"
|
||||
"reflect"
|
||||
"server/pkg/github.com/name5566/leaf/log"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
@ -568,7 +569,7 @@ func NotifyPlayer(uid, pushid int, title, content string) {
|
||||
payload := strings.NewReader(`[
|
||||
{
|
||||
"projectId": "` + PROJECT_ID + `",
|
||||
"platform": "auto",
|
||||
"platform": "firebasepush",
|
||||
"pushId": "` + PROJECT_ID + `_` + fmt.Sprintf("%08d", pushid) + `",
|
||||
"executeId": "` + executeId + `",
|
||||
"environment": "production",
|
||||
@ -606,7 +607,7 @@ func NotifyPlayer(uid, pushid int, title, content string) {
|
||||
req.Header.Add("Timestamp", strconv.Itoa(int(timestamp)))
|
||||
req.Header.Add("Signature", signature)
|
||||
req.Header.Add("Content-Type", "application/json")
|
||||
fmt.Print(req)
|
||||
fmt.Println(payload)
|
||||
res, err := client.Do(req)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
@ -619,5 +620,5 @@ func NotifyPlayer(uid, pushid int, title, content string) {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
fmt.Println(string(body))
|
||||
log.Debug("notification send uid %d, type %d , res %v", uid, pushid, body)
|
||||
}
|
||||
|
||||
@ -96,5 +96,5 @@ func TestEndless(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestNotify(t *testing.T) {
|
||||
GoUtil.NotifyPlayer(3625212, 1, "Test Notification", "This is a test notification from the server.")
|
||||
GoUtil.NotifyPlayer(19246, 1, "Test Notification", "This is a test notification from the server.")
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user