邮件功能

This commit is contained in:
sk 2025-06-20 15:33:09 +08:00
parent 3aa08943b2
commit f4db5a7d3b
7 changed files with 94 additions and 52 deletions

4
go.mod
View File

@ -4,14 +4,14 @@ go 1.24
require ( require (
github.com/json-iterator/go v1.1.12 github.com/json-iterator/go v1.1.12
github.com/oylshe1314/framework v1.0.19 github.com/oylshe1314/framework v1.0.21
github.com/xuri/excelize/v2 v2.9.1 github.com/xuri/excelize/v2 v2.9.1
go.mongodb.org/mongo-driver v1.17.4 go.mongodb.org/mongo-driver v1.17.4
golang.org/x/crypto v0.39.0 golang.org/x/crypto v0.39.0
google.golang.org/protobuf v1.36.6 google.golang.org/protobuf v1.36.6
) )
replace github.com/oylshe1314/framework v1.0.19 => D:\sk\projects\golang\framework-1.0.19 replace github.com/oylshe1314/framework v1.0.21 => D:\sk\projects\golang\framework-1.0.21
require ( require (
filippo.io/edwards25519 v1.1.0 // indirect filippo.io/edwards25519 v1.1.0 // indirect

View File

@ -279,8 +279,8 @@ const (
// TipMailNotFound 找不到邮件 // TipMailNotFound 找不到邮件
TipMailNotFound StringTipError = "MailNotFound" TipMailNotFound StringTipError = "MailNotFound"
// TipMailNoReward 邮件无奖励 // TipMailNoItems 邮件无奖励
TipMailNoReward StringTipError = "MailNoReward" TipMailNoItems StringTipError = "MailNoItems"
// ----------------------- 任务模块 ----------------------- // ----------------------- 任务模块 -----------------------

View File

@ -178,7 +178,7 @@ enum MsgId {
//-------------------------------------------------------------------------- -------------------------------------------------------------------------- //-------------------------------------------------------------------------- --------------------------------------------------------------------------
ModHeroList = 5001; ModHeroList = 5001;
// //
ModHeroChange = 5002; ModHeroChange = 5002;
// //
@ -208,7 +208,7 @@ enum MsgId {
// //
ModHeroBookActivate = 5011; ModHeroBookActivate = 5011;
// ModItem begin ----------------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------- --------------------------------------------------------------------------
// //
ModItemList = 6001; ModItemList = 6001;
@ -245,10 +245,35 @@ enum MsgId {
// //
ModItemTreasureRefine = 6024; ModItemTreasureRefine = 6024;
//ModCounter begin ----------------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------- --------------------------------------------------------------------------
// //
ModCounterList = 7001; ModCounterList = 7001;
// //
ModCounterChange = 7002; ModCounterChange = 7002;
//-------------------------------------------------------------------------- --------------------------------------------------------------------------
//
ModMailList = 8001;
//
ModMailSend = 8002;
//
ModMailChange = 8003;
//
ModMailRead = 8004;
//
ModMailReceive = 8005;
//
ModMailReceiveAll = 8006;
//
ModMailDelete = 8007;
//
ModMailDeleteAll = 8008;
} }

View File

@ -2,6 +2,7 @@ package logic
import ( import (
"ecs/proto" "ecs/proto"
"ecs/proto/pb"
"ecs/servers/game/data" "ecs/servers/game/data"
"github.com/oylshe1314/framework/client/db" "github.com/oylshe1314/framework/client/db"
"github.com/oylshe1314/framework/errors" "github.com/oylshe1314/framework/errors"
@ -246,7 +247,7 @@ func (this *PlayerManager) NewPlayer() *Player {
Equip: map[uint64]*PlayerEquip{}, Equip: map[uint64]*PlayerEquip{},
//GiftPack: map[uint32]*PlayerGiftPack{}, //GiftPack: map[uint32]*PlayerGiftPack{},
Lineup: map[uint64]*PlayerLineup{}, Lineup: map[uint64]*PlayerLineup{},
//Mail: map[uint64]*PlayerMail{}, Mail: map[uint64]*PlayerMail{},
Money: map[uint32]*PlayerMoney{}, Money: map[uint32]*PlayerMoney{},
//MonthlyCard: map[uint32]*PlayerMonthlyCard{}, //MonthlyCard: map[uint32]*PlayerMonthlyCard{},
//Planet: map[uint32]*PlayerPlanet{}, //Planet: map[uint32]*PlayerPlanet{},
@ -523,8 +524,8 @@ func (this *PlayerManager) Unban(player *Player) {
this.storeChanges(player) this.storeChanges(player)
} }
func (this *PlayerManager) Handler(modId, msgId uint16, handler MessageHandler) { func (this *PlayerManager) Handler(modId pb.ModId, msgId pb.MsgId, handler MessageHandler) {
this.messageHandlers[util.Compose2uint16(modId, msgId)] = handler this.messageHandlers[util.Compose2uint16(uint16(modId), uint16(msgId))] = handler
} }
func (this *PlayerManager) Handle(player *Player, msg *net.Message) { func (this *PlayerManager) Handle(player *Player, msg *net.Message) {

View File

@ -74,7 +74,7 @@ type Player struct {
Equip map[uint64]*PlayerEquip `bson:"equip"` Equip map[uint64]*PlayerEquip `bson:"equip"`
//GiftPack map[uint32]*PlayerGiftPack `bson:"gift_pack"` //GiftPack map[uint32]*PlayerGiftPack `bson:"gift_pack"`
Lineup map[uint64]*PlayerLineup `bson:"lineup"` Lineup map[uint64]*PlayerLineup `bson:"lineup"`
//Mail map[uint64]*PlayerMail `bson:"mail"` Mail map[uint64]*PlayerMail `bson:"mail"`
Money map[uint32]*PlayerMoney `bson:"money"` Money map[uint32]*PlayerMoney `bson:"money"`
//MonthlyCard map[uint32]*PlayerMonthlyCard `bson:"monthly_card"` //MonthlyCard map[uint32]*PlayerMonthlyCard `bson:"monthly_card"`
//Planet map[uint32]*PlayerPlanet `bson:"planet"` //Planet map[uint32]*PlayerPlanet `bson:"planet"`
@ -119,11 +119,11 @@ func (this *Player) Uid() uint64 {
return this.RoleId return this.RoleId
} }
func (this *Player) Send(modId, msgId uint16, msg interface{}) (err error) { func (this *Player) Send(modId pb.ModId, msgId pb.MsgId, msg interface{}) (err error) {
if this.conn == nil { if this.conn == nil {
return nil return nil
} }
return this.conn.Send(modId, msgId, msg) return this.conn.Send(uint16(modId), uint16(msgId), msg)
} }
func (this *Player) TipNotice(err proto.TipError) error { func (this *Player) TipNotice(err proto.TipError) error {
@ -142,12 +142,12 @@ func (this *Player) unlock() {
func (this *Player) sync() { func (this *Player) sync() {
//Role module //Role module
_ = this.Send(uint16(pb.ModId_ModuleRole), uint16(pb.MsgId_ModRoleProperty), this.BuildMsgRolePropertyAck()) _ = this.Send(pb.ModId_ModuleRole, pb.MsgId_ModRoleProperty, this.BuildMsgRolePropertyAck())
_ = this.Send(uint16(pb.ModId_ModuleRole), uint16(pb.MsgId_ModRoleMoneyList), this.BuildMsgMoneyListAck()) _ = this.Send(pb.ModId_ModuleRole, pb.MsgId_ModRoleMoneyList, this.BuildMsgMoneyListAck())
_ = this.Send(uint16(pb.ModId_ModuleRole), uint16(pb.MsgId_ModRoleLineupList), this.BuildMsgLineupListAck()) _ = this.Send(pb.ModId_ModuleRole, pb.MsgId_ModRoleLineupList, this.BuildMsgLineupListAck())
//Level module //Level module
_ = this.Send(uint16(pb.ModId_ModuleLevel), uint16(pb.MsgId_ModLevelCopyStatusList), this.BuildMsgCopyStatusListAck()) _ = this.Send(pb.ModId_ModuleLevel, pb.MsgId_ModLevelCopyStatusList, this.BuildMsgCopyStatusListAck())
//_ = this.Send(proto.ModIdLevel, proto.MsgIdCopySpeedStatusList, this.BuildMsgCopySpeedStatusListAck()) //_ = this.Send(proto.ModIdLevel, proto.MsgIdCopySpeedStatusList, this.BuildMsgCopySpeedStatusListAck())
//_ = this.Send(proto.ModIdLevel, proto.MsgIdPlanetList, this.BuildMsgPlanetListAck()) //_ = this.Send(proto.ModIdLevel, proto.MsgIdPlanetList, this.BuildMsgPlanetListAck())
//_ = this.Send(proto.ModIdLevel, proto.MsgIdPlanetRawStoneStatus, this.BuildMsgPlanetRawStoneStatusListAck()) //_ = this.Send(proto.ModIdLevel, proto.MsgIdPlanetRawStoneStatus, this.BuildMsgPlanetRawStoneStatusListAck())
@ -157,8 +157,8 @@ func (this *Player) sync() {
//_ = this.Send(proto.ModIdBattle, proto.MsgIdIdleBattleStatus, this.BuildMsgIdleBattleStatusAck()) //_ = this.Send(proto.ModIdBattle, proto.MsgIdIdleBattleStatus, this.BuildMsgIdleBattleStatusAck())
//Hero module //Hero module
_ = this.Send(uint16(pb.ModId_ModuleHero), uint16(pb.MsgId_ModHeroList), this.BuildMsgHeroListAck()) _ = this.Send(pb.ModId_ModuleHero, pb.MsgId_ModHeroList, this.BuildMsgHeroListAck())
_ = this.Send(uint16(pb.ModId_ModuleHero), uint16(pb.MsgId_ModHeroBookList), this.BuildMsgHeroBookListAck()) _ = this.Send(pb.ModId_ModuleHero, pb.MsgId_ModHeroBookList, this.BuildMsgHeroBookListAck())
//_ = this.Send(proto.ModIdRig, proto.MsgIdRigComponentList, this.BuildMsgRigComponentListAck()) //_ = this.Send(proto.ModIdRig, proto.MsgIdRigComponentList, this.BuildMsgRigComponentListAck())
//_ = this.Send(proto.ModIdRig, proto.MsgIdRigEquipList, this.BuildMsgRigEquipListAck()) //_ = this.Send(proto.ModIdRig, proto.MsgIdRigEquipList, this.BuildMsgRigEquipListAck())
//_ = this.Send(proto.ModIdRig, proto.MsgIdRigRemainsList, this.BuildMsgRigRemainsListAck()) //_ = this.Send(proto.ModIdRig, proto.MsgIdRigRemainsList, this.BuildMsgRigRemainsListAck())
@ -171,12 +171,12 @@ func (this *Player) sync() {
//_ = this.Send(proto.ModIdRig, proto.MsgIdRigWarshipList, this.BuildMsgWarshipListAck()) //_ = this.Send(proto.ModIdRig, proto.MsgIdRigWarshipList, this.BuildMsgWarshipListAck())
//Item module //Item module
_ = this.Send(uint16(pb.ModId_ModuleItem), uint16(pb.MsgId_ModItemList), this.BuildMsgItemListAck()) _ = this.Send(pb.ModId_ModuleItem, pb.MsgId_ModItemList, this.BuildMsgItemListAck())
_ = this.Send(uint16(pb.ModId_ModuleItem), uint16(pb.MsgId_ModItemEquipList), this.BuildMsgEquipListAck()) _ = this.Send(pb.ModId_ModuleItem, pb.MsgId_ModItemEquipList, this.BuildMsgEquipListAck())
_ = this.Send(uint16(pb.ModId_ModuleItem), uint16(pb.MsgId_ModItemTreasureList), this.BuildMsgTreasureListAck()) _ = this.Send(pb.ModId_ModuleItem, pb.MsgId_ModItemTreasureList, this.BuildMsgTreasureListAck())
//Counter module //Counter module
_ = this.Send(uint16(pb.ModId_ModuleCounter), uint16(pb.MsgId_ModCounterList), this.BuildMsgCounterListAck()) _ = this.Send(pb.ModId_ModuleCounter, pb.MsgId_ModCounterList, this.BuildMsgCounterListAck())
////Mail module ////Mail module
//_ = this.Send(proto.ModIdMail, proto.MsgIdMailList, this.BuildMsgMailListAck()) //_ = this.Send(proto.ModIdMail, proto.MsgIdMailList, this.BuildMsgMailListAck())
@ -297,7 +297,7 @@ func (this *Player) exit() {
} }
func (this *Player) kick(message string) { func (this *Player) kick(message string) {
_ = this.Send(uint16(pb.ModId_ModuleLogin), uint16(pb.MsgId_ModLoginKickOut), &pb.KickOutAck{Message: message}) _ = this.Send(pb.ModId_ModuleLogin, pb.MsgId_ModLoginKickOut, &pb.KickOutAck{Message: message})
this.exit() this.exit()
} }
@ -377,7 +377,7 @@ func (this *Player) SaveArray(field string, index int, value interface{}) {
this.SaveField(fmt.Sprint(field, ".", index), value) this.SaveField(fmt.Sprint(field, ".", index), value)
} }
func (this *Player) SaveModel(model interface{}, fields ...string) { func (this *Player) SaveModel(model interface{}) {
key, err := this.modelKey(model) key, err := this.modelKey(model)
if err != nil { if err != nil {
this.manager.logger.Error("Failed to get the key of the model that will be saved, ", err) this.manager.logger.Error("Failed to get the key of the model that will be saved, ", err)
@ -387,12 +387,21 @@ func (this *Player) SaveModel(model interface{}, fields ...string) {
this.SaveField(key, model) this.SaveField(key, model)
} }
func (this *Player) WipeField(field string, value interface{}) { func (this *Player) SaveModelField(model interface{}, field string, value interface{}) {
this.wipe[field] = value key, err := this.modelKey(model)
if err != nil {
this.manager.logger.Error("Failed to get the key of the model that will be saved, ", err)
return
}
this.SaveField(fmt.Sprint(key, ".", field), value)
} }
func (this *Player) WipeArray(field string, index int, value interface{}) { func (this *Player) WipeField(field string) {
this.WipeField(fmt.Sprint(field, ".", index), value) this.wipe[field] = 1
}
func (this *Player) WipeArray(field string, index int) {
this.WipeField(fmt.Sprint(field, ".", index))
} }
func (this *Player) WipeModel(model interface{}) { func (this *Player) WipeModel(model interface{}) {
@ -402,5 +411,5 @@ func (this *Player) WipeModel(model interface{}) {
return return
} }
this.WipeField(key, model) this.WipeField(key)
} }

View File

@ -76,10 +76,10 @@ func (this *Player) checkCorrectModules(cur *GameTime) {
this.Lineup = make(map[uint64]*PlayerLineup) this.Lineup = make(map[uint64]*PlayerLineup)
this.SaveField("money", this.Lineup) this.SaveField("money", this.Lineup)
} }
//if this.Mail == nil { if this.Mail == nil {
// this.Mail = make(map[uint64]*PlayerMail) this.Mail = make(map[uint64]*PlayerMail)
// this.SaveField("mail", this.Mail) this.SaveField("mail", this.Mail)
//} }
if this.Money == nil { if this.Money == nil {
this.Money = make(map[uint32]*PlayerMoney) this.Money = make(map[uint32]*PlayerMoney)
this.SaveField("money", this.Money) this.SaveField("money", this.Money)
@ -222,20 +222,27 @@ func (this *Player) initLineup(cur *GameTime) {
this.SaveModel(lineup) this.SaveModel(lineup)
} }
// func (this *Player) initMails(cur *GameTime) { func (this *Player) initMails(cur *GameTime) {
// var cfgTable = this.manager.tables.ServerCfg.Get("init_mails") var mails = this.manager.tables.ServerConfig.GetInitMails()
// if cfgTable == nil { for i := range mails {
// return var titleId, contentId, itemIds, itemNums = this.manager.tables.ServerConfig.GetInitMail(i)
// } var items = make([][2]uint32, len(itemIds))
// for ii := range itemIds {
// itemIds, itemNums, err := util.SplitItemNums(cfgTable.Value1, cfgTable.Value2, 1) items[ii][0] = uint32(itemIds[ii])
// if err != nil { items[ii][1] = uint32(itemNums[ii])
// return }
// } this.AddMail(util.RandomUid(),
// pb.MailType_MailNormal,
// this.AddMail(proto.MailTypeNormal, proto.MailTitleSystem, proto.MailContentSystem, nil, itemIds, itemNums, cur.Timestamp) util.IntegerToString(titleId),
// } util.IntegerToString(contentId),
// util.Unix(),
0,
nil,
items,
)
}
}
// func (this *Player) initTasks(cur *GameTime) { // func (this *Player) initTasks(cur *GameTime) {
// var cfgTable = this.manager.tables.ServerCfg.Get("init_tasks") // var cfgTable = this.manager.tables.ServerCfg.Get("init_tasks")
// if cfgTable == nil { // if cfgTable == nil {
@ -267,7 +274,7 @@ func (this *Player) checkCorrectFirstLogin(cur *GameTime) {
this.initHeroes(cur) this.initHeroes(cur)
this.initItems(cur) this.initItems(cur)
this.initLineup(cur) this.initLineup(cur)
//this.initMails(cur) this.initMails(cur)
//this.initTasks(cur) //this.initTasks(cur)
this.initPower(cur) this.initPower(cur)
} }

View File

@ -32,7 +32,7 @@ func (this *Player) checkRecoveryPower(login bool, pre, cur *GameTime) {
this.ChangeProperty(util.NewPair(pb.RolePropertyType_PowerNextTime, cur.Timestamp+int64(RolePowerCycle))) this.ChangeProperty(util.NewPair(pb.RolePropertyType_PowerNextTime, cur.Timestamp+int64(RolePowerCycle)))
} }
_ = this.Send(uint16(pb.ModId_ModuleRole), uint16(pb.MsgId_ModRoleMoneyChange), &pb.MoneyListAck{MoneyList: []*pb.Money{money.BuildMsgMoney()}}) _ = this.Send(pb.ModId_ModuleRole, pb.MsgId_ModRoleMoneyChange, &pb.MoneyListAck{MoneyList: []*pb.Money{money.BuildMsgMoney()}})
} }
func (this *Player) checkAcrossTime(login bool, pre, cur *GameTime, handles ...func(login bool, pre, cur *GameTime) bool) bool { func (this *Player) checkAcrossTime(login bool, pre, cur *GameTime, handles ...func(login bool, pre, cur *GameTime) bool) bool {