邮件协议
This commit is contained in:
1 parent
605b4dbed2
commit
6e9e2458e3
11 files changed
+271
-23
No files matched your search
@@ -49,7 +49,7 @@ type ScenePoint struct {
|
||||
type PointData struct {
|
||||
Id int32 `json:"-"`
|
||||
PointType int `json:"-"`
|
||||
PointTypeStr string `json:"$type"` // 传送点类型
|
||||
PointTypeStr string `json:"pointType"` // 传送点类型
|
||||
TranPos *Position `json:"tranPos"` // 传送后位置
|
||||
TranRot *Position `json:"tranRot"` // 传送后朝向
|
||||
DungeonIds []int32 `json:"dungeonIds"` // 地牢id列表
|
||||
@@ -115,7 +115,7 @@ func (g *GameDataConfig) loadScenePoint() {
|
||||
case PointTypeStrOther:
|
||||
pointData.PointType = PointTypeOther
|
||||
default:
|
||||
logger.Error("unknown scene point type: %v", pointData.PointTypeStr)
|
||||
logger.Info("unknown scene point type: %v", pointData.PointTypeStr)
|
||||
pointData.PointType = PointTypeOther
|
||||
}
|
||||
scenePoint.PointMap[int32(pointId)] = pointData
|
||||
|
||||
@@ -53,6 +53,7 @@ type Game struct {
|
||||
isStop bool // 停服标志
|
||||
dispatchCancel bool // 取消调度标志
|
||||
endlessLoopCounter map[int]uint64 // 死循环保护计数器
|
||||
transactionSeq uint32 // 事务序列号
|
||||
ai *model.Player // 本服的Ai玩家对象
|
||||
}
|
||||
|
||||
@@ -68,6 +69,7 @@ func NewGameCore(discoveryClient *rpc.DiscoveryClient, db *dao.Dao, messageQueue
|
||||
r.isStop = false
|
||||
r.dispatchCancel = false
|
||||
r.endlessLoopCounter = make(map[int]uint64)
|
||||
r.transactionSeq = 0
|
||||
GAME = r
|
||||
LOCAL_EVENT_MANAGER = NewLocalEventManager()
|
||||
ROUTE_MANAGER = NewRouteManager()
|
||||
@@ -300,6 +302,11 @@ func (g *Game) EndlessLoopCheck(checkType int) {
|
||||
}
|
||||
}
|
||||
|
||||
func (g *Game) NewTransaction(uid uint32) string {
|
||||
g.transactionSeq++
|
||||
return strconv.Itoa(int(uid)) + "-" + strconv.Itoa(int(time.Now().Unix())) + "-" + strconv.Itoa(int(g.transactionSeq))
|
||||
}
|
||||
|
||||
var EXIT_SAVE_FIN_CHAN chan bool
|
||||
|
||||
func (g *Game) ServerStopNotify() {
|
||||
|
||||
@@ -501,7 +501,6 @@ func (g *GMCmd) GMClearQuest(userId uint32) {
|
||||
return
|
||||
}
|
||||
player.DbQuest = nil
|
||||
GAME.AcceptQuest(player, false)
|
||||
GAME.LogoutPlayer(userId)
|
||||
}
|
||||
|
||||
@@ -853,3 +852,12 @@ func (g *GMCmd) GetPlayerPos(userId uint32) (*model.Vector, *model.Vector) {
|
||||
}
|
||||
return GAME.GetPlayerPos(player), player.GetPos()
|
||||
}
|
||||
|
||||
func (g *GMCmd) SendMail(userId uint32, title string, content string) {
|
||||
player := USER_MANAGER.GetOnlineUser(userId)
|
||||
if player == nil {
|
||||
logger.Error("player is nil, uid: %v", userId)
|
||||
return
|
||||
}
|
||||
GAME.AddPlayerMail(userId, title, content)
|
||||
}
|
||||
@@ -137,6 +137,12 @@ func (r *RouteManager) initRoute() {
|
||||
cmd.UnlockAvatarTalentReq: GAME.UnlockAvatarTalentReq,
|
||||
cmd.ReliquaryUpgradeReq: GAME.ReliquaryUpgradeReq,
|
||||
cmd.ReliquaryPromoteReq: GAME.ReliquaryPromoteReq,
|
||||
cmd.GetAllMailReq: GAME.GetAllMailReq,
|
||||
cmd.GetAllMailNotify: GAME.GetAllMailNotify,
|
||||
cmd.DelMailReq: GAME.DelMailReq,
|
||||
cmd.GetMailItemReq: GAME.GetMailItemReq,
|
||||
cmd.ReadMailNotify: GAME.ReadMailNotify,
|
||||
cmd.ChangeMailStarNotify: GAME.ChangeMailStarNotify,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -66,6 +66,12 @@ func (t *TickManager) CreateUserGlobalTick(userId uint32) {
|
||||
|
||||
// DestroyUserGlobalTick 销毁玩家tick对象
|
||||
func (t *TickManager) DestroyUserGlobalTick(userId uint32) {
|
||||
userTick, exist := t.userTickMap[userId]
|
||||
if !exist {
|
||||
logger.Error("user not exist, uid: %v", userId)
|
||||
return
|
||||
}
|
||||
userTick.globalTick.Stop()
|
||||
delete(t.userTickMap, userId)
|
||||
}
|
||||
|
||||
|
||||
@@ -104,12 +104,11 @@ func (g *Game) OnLogin(userId uint32, clientSeq uint32, gateAppId string, player
|
||||
player.MpPos = new(model.Vector)
|
||||
player.MpRot = new(model.Vector)
|
||||
|
||||
dbQuest := player.GetDbQuest()
|
||||
for _, quest := range dbQuest.GetQuestMap() {
|
||||
if quest.State == constant.QUEST_STATE_UNFINISHED {
|
||||
quest.State = constant.QUEST_STATE_UNSTARTED
|
||||
g.StartQuest(player, quest.QuestId, false)
|
||||
}
|
||||
if player.DbQuest == nil {
|
||||
player.SceneId = 3
|
||||
player.Pos = &model.Vector{X: 2747, Y: 194, Z: -1719}
|
||||
player.Rot = &model.Vector{X: 0, Y: 307, Z: 0}
|
||||
g.AcceptQuest(player, false)
|
||||
}
|
||||
|
||||
g.TriggerOpenState(userId)
|
||||
|
||||
@@ -0,0 +1,199 @@
|
||||
package game
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"hk4e/gs/model"
|
||||
"hk4e/pkg/logger"
|
||||
"hk4e/pkg/object"
|
||||
"hk4e/protocol/cmd"
|
||||
"hk4e/protocol/proto"
|
||||
|
||||
pb "google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
/************************************************** 接口请求 **************************************************/
|
||||
|
||||
func (g *Game) GetAllMailReq(player *model.Player, payloadMsg pb.Message) {
|
||||
req := payloadMsg.(*proto.GetAllMailReq)
|
||||
|
||||
rsp := &proto.GetAllMailRsp{
|
||||
MailList: g.PacketMailList(player.PlayerId),
|
||||
IsCollected: req.IsCollected,
|
||||
IsTruncated: false,
|
||||
}
|
||||
g.SendMsg(cmd.GetAllMailRsp, player.PlayerId, player.ClientSeq, rsp)
|
||||
}
|
||||
|
||||
func (g *Game) GetAllMailNotify(player *model.Player, payloadMsg pb.Message) {
|
||||
ntf := payloadMsg.(*proto.GetAllMailNotify)
|
||||
|
||||
pbMailList := make([]*proto.MailData, 0)
|
||||
if player.ClientVersion >= 400 {
|
||||
pbMailList = g.PacketMailList(player.PlayerId)
|
||||
}
|
||||
|
||||
g.SendMsg(cmd.GetAllMailResultNotify, player.PlayerId, player.ClientSeq, &proto.GetAllMailResultNotify{
|
||||
Transaction: g.NewTransaction(player.PlayerId),
|
||||
MailList: pbMailList,
|
||||
PageIndex: 1,
|
||||
TotalPageCount: 1,
|
||||
IsCollected: ntf.IsCollected,
|
||||
})
|
||||
}
|
||||
|
||||
func (g *Game) DelMailReq(player *model.Player, payloadMsg pb.Message) {
|
||||
req := payloadMsg.(*proto.DelMailReq)
|
||||
|
||||
g.DelPlayerMail(player.PlayerId, req.MailIdList)
|
||||
|
||||
rsp := &proto.DelMailRsp{
|
||||
MailIdList: req.MailIdList,
|
||||
}
|
||||
g.SendMsg(cmd.DelMailRsp, player.PlayerId, player.ClientSeq, rsp)
|
||||
}
|
||||
|
||||
func (g *Game) GetMailItemReq(player *model.Player, payloadMsg pb.Message) {
|
||||
req := payloadMsg.(*proto.GetMailItemReq)
|
||||
|
||||
rsp := &proto.GetMailItemRsp{
|
||||
MailIdList: req.MailIdList,
|
||||
ItemList: nil,
|
||||
}
|
||||
g.SendMsg(cmd.GetMailItemRsp, player.PlayerId, player.ClientSeq, rsp)
|
||||
}
|
||||
|
||||
func (g *Game) ReadMailNotify(player *model.Player, payloadMsg pb.Message) {
|
||||
ntf := payloadMsg.(*proto.ReadMailNotify)
|
||||
g.ReadPlayerMail(player.PlayerId, ntf.MailIdList)
|
||||
}
|
||||
|
||||
func (g *Game) ChangeMailStarNotify(player *model.Player, payloadMsg pb.Message) {
|
||||
ntf := payloadMsg.(*proto.ChangeMailStarNotify)
|
||||
g.StarPlayerMail(player.PlayerId, ntf.MailIdList, ntf.IsStar)
|
||||
}
|
||||
|
||||
/************************************************** 游戏功能 **************************************************/
|
||||
|
||||
var MailIdSeq uint32 = 0
|
||||
|
||||
func (g *Game) AddPlayerMail(userId uint32, title string, content string) {
|
||||
player := USER_MANAGER.GetOnlineUser(userId)
|
||||
if player == nil {
|
||||
logger.Error("player is nil, uid: %v", userId)
|
||||
return
|
||||
}
|
||||
MailIdSeq++
|
||||
mail := &model.Mail{
|
||||
MailId: MailIdSeq,
|
||||
Title: title,
|
||||
Content: content,
|
||||
Sender: "flswld",
|
||||
SendTime: uint32(time.Now().Unix()),
|
||||
ExpireTime: uint32(time.Now().Add(time.Hour * 24).Unix()),
|
||||
IsRead: false,
|
||||
IsStar: false,
|
||||
}
|
||||
player.MailMap[mail.MailId] = mail
|
||||
ntf := &proto.MailChangeNotify{
|
||||
MailList: []*proto.MailData{g.PacketMail(mail)},
|
||||
DelMailIdList: nil,
|
||||
}
|
||||
g.SendMsg(cmd.MailChangeNotify, player.PlayerId, player.ClientSeq, ntf)
|
||||
}
|
||||
|
||||
func (g *Game) DelPlayerMail(userId uint32, mailIdList []uint32) {
|
||||
player := USER_MANAGER.GetOnlineUser(userId)
|
||||
if player == nil {
|
||||
logger.Error("player is nil, uid: %v", userId)
|
||||
return
|
||||
}
|
||||
for _, mailId := range mailIdList {
|
||||
delete(player.MailMap, mailId)
|
||||
}
|
||||
ntf := &proto.MailChangeNotify{
|
||||
MailList: nil,
|
||||
DelMailIdList: mailIdList,
|
||||
}
|
||||
g.SendMsg(cmd.MailChangeNotify, player.PlayerId, player.ClientSeq, ntf)
|
||||
}
|
||||
|
||||
func (g *Game) ReadPlayerMail(userId uint32, mailIdList []uint32) {
|
||||
player := USER_MANAGER.GetOnlineUser(userId)
|
||||
if player == nil {
|
||||
logger.Error("player is nil, uid: %v", userId)
|
||||
return
|
||||
}
|
||||
for _, mailId := range mailIdList {
|
||||
mail, exist := player.MailMap[mailId]
|
||||
if !exist {
|
||||
return
|
||||
}
|
||||
mail.IsRead = true
|
||||
}
|
||||
}
|
||||
|
||||
func (g *Game) StarPlayerMail(userId uint32, mailIdList []uint32, isStar bool) {
|
||||
player := USER_MANAGER.GetOnlineUser(userId)
|
||||
if player == nil {
|
||||
logger.Error("player is nil, uid: %v", userId)
|
||||
return
|
||||
}
|
||||
pbMailList := make([]*proto.MailData, 0)
|
||||
for _, mailId := range mailIdList {
|
||||
mail, exist := player.MailMap[mailId]
|
||||
if !exist {
|
||||
return
|
||||
}
|
||||
mail.IsStar = isStar
|
||||
pbMail := g.PacketMail(mail)
|
||||
if pbMail == nil {
|
||||
return
|
||||
}
|
||||
pbMailList = append(pbMailList, pbMail)
|
||||
}
|
||||
ntf := &proto.MailChangeNotify{
|
||||
MailList: pbMailList,
|
||||
DelMailIdList: nil,
|
||||
}
|
||||
g.SendMsg(cmd.MailChangeNotify, player.PlayerId, player.ClientSeq, ntf)
|
||||
}
|
||||
|
||||
/************************************************** 打包封装 **************************************************/
|
||||
|
||||
func (g *Game) PacketMail(mail *model.Mail) *proto.MailData {
|
||||
return &proto.MailData{
|
||||
MailId: mail.MailId,
|
||||
MailTextContent: &proto.MailTextContent{
|
||||
Title: mail.Title,
|
||||
Content: mail.Content,
|
||||
Sender: mail.Sender,
|
||||
},
|
||||
ItemList: nil,
|
||||
SendTime: mail.SendTime,
|
||||
ExpireTime: mail.ExpireTime,
|
||||
Importance: uint32(object.ConvBoolToInt64(mail.IsStar)),
|
||||
IsRead: mail.IsRead,
|
||||
IsAttachmentGot: false,
|
||||
ConfigId: 0,
|
||||
ArgumentList: nil,
|
||||
CollectState: proto.MailCollectState_MAIL_NOT_COLLECTIBLE,
|
||||
}
|
||||
}
|
||||
|
||||
func (g *Game) PacketMailList(userId uint32) []*proto.MailData {
|
||||
player := USER_MANAGER.GetOnlineUser(userId)
|
||||
if player == nil {
|
||||
logger.Error("player is nil, uid: %v", userId)
|
||||
return nil
|
||||
}
|
||||
pbMailList := make([]*proto.MailData, 0)
|
||||
for _, mail := range player.MailMap {
|
||||
pbMail := g.PacketMail(mail)
|
||||
if pbMail == nil {
|
||||
return nil
|
||||
}
|
||||
pbMailList = append(pbMailList, pbMail)
|
||||
}
|
||||
return pbMailList
|
||||
}
|
||||
+2
-12
@@ -1427,8 +1427,6 @@ func (g *Game) SetPlayerWeather(player *model.Player, weatherAreaId uint32, clim
|
||||
|
||||
/************************************************** 打包封装 **************************************************/
|
||||
|
||||
var SceneTransactionSeq uint32 = 0
|
||||
|
||||
func (g *Game) PacketPlayerEnterSceneNotifyLogin(player *model.Player) *proto.PlayerEnterSceneNotify {
|
||||
world := WORLD_MANAGER.GetWorldById(player.WorldId)
|
||||
if world == nil {
|
||||
@@ -1454,11 +1452,7 @@ func (g *Game) PacketPlayerEnterSceneNotifyLogin(player *model.Player) *proto.Pl
|
||||
WorldType: 1,
|
||||
SceneTagIdList: make([]uint32, 0),
|
||||
}
|
||||
SceneTransactionSeq++
|
||||
playerEnterSceneNotify.SceneTransaction = strconv.Itoa(int(player.GetSceneId())) + "-" +
|
||||
strconv.Itoa(int(player.PlayerId)) + "-" +
|
||||
strconv.Itoa(int(time.Now().Unix())) + "-" +
|
||||
strconv.Itoa(int(SceneTransactionSeq))
|
||||
playerEnterSceneNotify.SceneTransaction = strconv.Itoa(int(player.GetSceneId())) + "-" + g.NewTransaction(player.PlayerId)
|
||||
// TODO 暂时先解锁全部场景标签 看着喜庆
|
||||
for _, sceneTagDataConfig := range gdconf.GetSceneTagDataMap() {
|
||||
if uint32(sceneTagDataConfig.SceneId) == player.GetSceneId() {
|
||||
@@ -1520,11 +1514,7 @@ func (g *Game) PacketPlayerEnterSceneNotifyCore(
|
||||
DungeonId: dungeonId,
|
||||
SceneTagIdList: make([]uint32, 0),
|
||||
}
|
||||
SceneTransactionSeq++
|
||||
playerEnterSceneNotify.SceneTransaction = strconv.Itoa(int(sceneId)) + "-" +
|
||||
strconv.Itoa(int(player.PlayerId)) + "-" +
|
||||
strconv.Itoa(int(time.Now().Unix())) + "-" +
|
||||
strconv.Itoa(int(SceneTransactionSeq))
|
||||
playerEnterSceneNotify.SceneTransaction = strconv.Itoa(int(sceneId)) + "-" + g.NewTransaction(player.PlayerId)
|
||||
// TODO 暂时先解锁全部场景标签 看着喜庆
|
||||
for _, sceneTagDataConfig := range gdconf.GetSceneTagDataMap() {
|
||||
if uint32(sceneTagDataConfig.SceneId) == sceneId {
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
)
|
||||
|
||||
type Mail struct {
|
||||
ID primitive.ObjectID `bson:"_id,omitempty"`
|
||||
MailId uint32 `bson:"mail_id"`
|
||||
Title string `bson:"title"`
|
||||
Content string `bson:"content"`
|
||||
Sender string `bson:"sender"`
|
||||
SendTime uint32 `bson:"send_time"`
|
||||
ExpireTime uint32 `bson:"expire_time"`
|
||||
IsRead bool `bson:"is_read"`
|
||||
IsStar bool `bson:"is_star"`
|
||||
}
|
||||
+5
-2
@@ -89,8 +89,9 @@ type Player struct {
|
||||
MpPos *Vector `bson:"-" msgpack:"-"` // 多人世界坐标
|
||||
MpRot *Vector `bson:"-" msgpack:"-"` // 多人世界朝向
|
||||
// 特殊数据
|
||||
ChatMsgMap map[uint32][]*ChatMsg `bson:"-" msgpack:"-"` // 聊天信息 数据量偏大 只从db读写 不保存到redis
|
||||
RemoteWorldPlayerNum uint32 `bson:"-"` // 远程展示世界内人数 在线同步到redis 不保存到db
|
||||
ChatMsgMap map[uint32][]*ChatMsg `bson:"-" msgpack:"-"` // 聊天信息 只从db读写 不保存到redis
|
||||
RemoteWorldPlayerNum uint32 `bson:"-"` // 远程展示世界内人数 不保存到db 在线同步到redis
|
||||
MailMap map[uint32]*Mail `bson:"-" msgpack:"-"` // 邮件信息 只从db读写 不保存到redis
|
||||
}
|
||||
|
||||
// 存档场景
|
||||
@@ -179,6 +180,8 @@ func (p *Player) InitOnlineData() {
|
||||
dbWeapon.InitDbWeapon(p)
|
||||
dbItem := p.GetDbItem()
|
||||
dbItem.InitDbItem(p)
|
||||
|
||||
p.MailMap = make(map[uint32]*Mail)
|
||||
}
|
||||
|
||||
type Vector struct {
|
||||
|
||||
@@ -446,6 +446,19 @@ func (c *CmdProtoMap) registerMessage() {
|
||||
c.regMsg(ServerLogNotify, func() any { return new(proto.ServerLogNotify) })
|
||||
c.regMsg(MarkEntityInMinMapNotify, func() any { return new(proto.MarkEntityInMinMapNotify) })
|
||||
c.regMsg(UnmarkEntityInMinMapNotify, func() any { return new(proto.UnmarkEntityInMinMapNotify) })
|
||||
|
||||
// 邮件
|
||||
c.regMsg(GetAllMailReq, func() any { return new(proto.GetAllMailReq) }) // 获取邮件列表请求
|
||||
c.regMsg(GetAllMailRsp, func() any { return new(proto.GetAllMailRsp) }) // 获取邮件列表响应
|
||||
c.regMsg(GetAllMailNotify, func() any { return new(proto.GetAllMailNotify) }) // 获取邮件列表通知
|
||||
c.regMsg(GetAllMailResultNotify, func() any { return new(proto.GetAllMailResultNotify) }) // 获取邮件列表结果通知
|
||||
c.regMsg(MailChangeNotify, func() any { return new(proto.MailChangeNotify) }) // 新邮件通知
|
||||
c.regMsg(DelMailReq, func() any { return new(proto.DelMailReq) }) // 删除邮件请求
|
||||
c.regMsg(DelMailRsp, func() any { return new(proto.DelMailRsp) }) // 删除邮件响应
|
||||
c.regMsg(GetMailItemReq, func() any { return new(proto.GetMailItemReq) }) // 邮件领奖请求
|
||||
c.regMsg(GetMailItemRsp, func() any { return new(proto.GetMailItemRsp) }) // 邮件领奖响应
|
||||
c.regMsg(ReadMailNotify, func() any { return new(proto.ReadMailNotify) }) // 邮件阅读通知
|
||||
c.regMsg(ChangeMailStarNotify, func() any { return new(proto.ChangeMailStarNotify) }) // 邮件收藏通知
|
||||
}
|
||||
|
||||
func (c *CmdProtoMap) regMsg(cmdId uint16, protoObjNewFunc func() any) {
|
||||
|
||||
Reference in new issue
Block a user