252 lines
7.3 KiB
Go
252 lines
7.3 KiB
Go
package handler
|
|
|
|
import (
|
|
"ecs/proto"
|
|
"ecs/proto/pb"
|
|
"ecs/servers/game/logic"
|
|
"github.com/oylshe1314/framework/net"
|
|
)
|
|
|
|
func (this *PlayerHandler) MailSend(player *logic.Player, msg *net.Message) {
|
|
var req = new(pb.MailSendReq)
|
|
var err = msg.Read(req)
|
|
if err != nil {
|
|
this.Logger().Error("Read message failed, ", err)
|
|
_ = player.TipNotice(proto.TipMessageError)
|
|
return
|
|
}
|
|
|
|
if req.UserId == 0 {
|
|
this.Logger().Error("Parameter error, req.UserId == 0")
|
|
_ = player.TipNotice(proto.TipParameterError)
|
|
return
|
|
}
|
|
|
|
if req.AreaId == 0 {
|
|
this.Logger().Error("Parameter error, req.AreaId == 0")
|
|
_ = player.TipNotice(proto.TipParameterError)
|
|
return
|
|
}
|
|
|
|
if req.RoleId == 0 {
|
|
this.Logger().Error("Parameter error, req.RoleId == 0")
|
|
_ = player.TipNotice(proto.TipParameterError)
|
|
return
|
|
}
|
|
|
|
if req.Mail == nil {
|
|
this.Logger().Error("Parameter error, req.Mail == nil")
|
|
_ = player.TipNotice(proto.TipParameterError)
|
|
return
|
|
}
|
|
|
|
_ = player.TipNotice(proto.TipServerError)
|
|
}
|
|
|
|
func (this *PlayerHandler) MailRead(player *logic.Player, msg *net.Message) {
|
|
var req = new(pb.MailReadReq)
|
|
var err = msg.Read(req)
|
|
if err != nil {
|
|
this.Logger().Error("Read message failed, ", err)
|
|
_ = player.TipNotice(proto.TipMessageError)
|
|
return
|
|
}
|
|
|
|
if req.Uid == 0 {
|
|
this.Logger().Error("Parameter error, req.Uid == 0")
|
|
_ = player.TipNotice(proto.TipParameterError)
|
|
return
|
|
}
|
|
|
|
var mail = player.Mail[req.Uid]
|
|
if mail == nil {
|
|
this.Logger().Error("Parameter error, player 'Mail' was not found, req.Uid: ", req.Uid)
|
|
_ = player.TipNotice(proto.TipMailNotFound)
|
|
return
|
|
}
|
|
|
|
if pb.MailStatus(mail.Status) >= pb.MailStatus_HasRead {
|
|
return
|
|
}
|
|
|
|
mail.Status = uint32(pb.MailStatus_HasRead)
|
|
|
|
player.SaveModel(mail)
|
|
|
|
_ = player.Send(pb.ModId_ModuleMail, pb.MsgId_ModMailRead, &pb.MailChangeListAck{
|
|
ChangeList: []*pb.MailChange{{Uid: mail.Uid, Status: pb.MailStatus(mail.Status)}},
|
|
})
|
|
|
|
this.eventManager.PlayerMailLog(player, logic.LogTypeMailRead, mail.Uid, mail.Type, mail.SentUserId, mail.SentServerId, mail.SentRoleId, mail.Title, mail.Content, mail.CreateTime, mail.Expiration, mail.Args, mail.Items)
|
|
}
|
|
|
|
func (this *PlayerHandler) MailItemGet(player *logic.Player, msg *net.Message) {
|
|
var req = new(pb.MailItemGetReq)
|
|
var err = msg.Read(req)
|
|
if err != nil {
|
|
this.Logger().Error("Read message failed, ", err)
|
|
_ = player.TipNotice(proto.TipMessageError)
|
|
return
|
|
}
|
|
|
|
if req.Uid == 0 {
|
|
this.Logger().Error("Parameter error, req.Uid == 0")
|
|
_ = player.TipNotice(proto.TipParameterError)
|
|
return
|
|
}
|
|
|
|
var mail = player.Mail[req.Uid]
|
|
if mail == nil {
|
|
this.Logger().Error("Parameter error, player 'Mail' was not found, req.Uid: ", req.Uid)
|
|
_ = player.TipNotice(proto.TipMailNotFound)
|
|
return
|
|
}
|
|
|
|
if len(mail.Items) == 0 {
|
|
this.Logger().Error("Parameter error, len(mail.Items) == 0, req.Uid: ", req.Uid)
|
|
_ = player.TipNotice(proto.TipMailNoItems)
|
|
return
|
|
}
|
|
|
|
if pb.MailStatus(mail.Status) >= pb.MailStatus_HasGot {
|
|
return
|
|
}
|
|
|
|
var itemList []*pb.Item
|
|
for i := range mail.Items {
|
|
_ = player.AddItem(mail.Items[i][0], mail.Items[i][1], logic.LogTypeItemObtainByMail)
|
|
itemList = append(itemList, &pb.Item{ItemId: mail.Items[i][0], ItemNum: mail.Items[i][1]})
|
|
}
|
|
|
|
mail.Status = uint32(pb.MailStatus_HasGot)
|
|
|
|
player.SaveModel(mail)
|
|
|
|
_ = player.Send(pb.ModId_ModuleMail, pb.MsgId_ModMailItemGet, &pb.MailItemGetAck{
|
|
ItemList: itemList,
|
|
})
|
|
|
|
_ = player.Send(pb.ModId_ModuleMail, pb.MsgId_ModMailChange, &pb.MailChangeListAck{
|
|
ChangeList: []*pb.MailChange{{Uid: mail.Uid, Status: pb.MailStatus(mail.Status)}},
|
|
})
|
|
|
|
this.eventManager.PlayerMailLog(player, logic.LogTypeMailReward, mail.Uid, mail.Type, mail.SentUserId, mail.SentServerId, mail.SentRoleId, mail.Title, mail.Content, mail.CreateTime, mail.Expiration, mail.Args, mail.Items)
|
|
}
|
|
|
|
func (this *PlayerHandler) MailItemGetAll(player *logic.Player, _ *net.Message) {
|
|
var changeList []*pb.MailChange
|
|
var mailItems = map[uint32]uint32{}
|
|
for uid, mail := range player.Mail {
|
|
if pb.MailStatus(mail.Status) >= pb.MailStatus_HasGot {
|
|
continue
|
|
}
|
|
|
|
if len(mail.Items) == 0 {
|
|
continue
|
|
}
|
|
|
|
for i := range mail.Items {
|
|
mailItems[mail.Items[i][0]] += mail.Items[i][1]
|
|
}
|
|
|
|
mail.Status = uint32(pb.MailStatus_HasGot)
|
|
player.SaveModel(mail)
|
|
|
|
changeList = append(changeList, &pb.MailChange{Uid: uid, Status: pb.MailStatus(mail.Status)})
|
|
|
|
this.eventManager.PlayerMailLog(player, logic.LogTypeMailReward, mail.Uid, mail.Type, mail.SentUserId, mail.SentServerId, mail.SentRoleId, mail.Title, mail.Content, mail.CreateTime, mail.Expiration, mail.Args, mail.Items)
|
|
}
|
|
|
|
var itemList []*pb.Item
|
|
for itemId, itemNum := range mailItems {
|
|
_ = player.AddItem(itemId, itemNum, logic.LogTypeItemObtainByMail)
|
|
itemList = append(itemList, &pb.Item{ItemId: itemId, ItemNum: itemNum})
|
|
}
|
|
|
|
if len(itemList) > 0 {
|
|
_ = player.Send(pb.ModId_ModuleMail, pb.MsgId_ModMailItemGetAll, &pb.MailItemGetAck{
|
|
ItemList: itemList,
|
|
})
|
|
}
|
|
|
|
if len(changeList) > 0 {
|
|
_ = player.Send(pb.ModId_ModuleMail, pb.MsgId_ModMailChange, &pb.MailChangeListAck{
|
|
ChangeList: changeList,
|
|
})
|
|
}
|
|
}
|
|
|
|
func (this *PlayerHandler) MailDelete(player *logic.Player, msg *net.Message) {
|
|
var req = new(pb.MailDeleteReq)
|
|
var err = msg.Read(req)
|
|
if err != nil {
|
|
this.Logger().Error("Read message failed, ", err)
|
|
_ = player.TipNotice(proto.TipMessageError)
|
|
return
|
|
}
|
|
|
|
if req.Uid == 0 {
|
|
this.Logger().Error("Parameter error, req.Uid == 0")
|
|
_ = player.TipNotice(proto.TipParameterError)
|
|
return
|
|
}
|
|
|
|
var mail = player.Mail[req.Uid]
|
|
if mail == nil {
|
|
//this.Logger().Error("Parameter error, Player 'Mail' was not found, req.Uid: ", req.Uid)
|
|
//_ = player.TipNotice(proto.TipMailNotFound)
|
|
return
|
|
}
|
|
|
|
if pb.MailType(mail.Type) == pb.MailType_MailAllRegion {
|
|
if pb.MailStatus(mail.Status) >= pb.MailStatus_Deleted {
|
|
return
|
|
}
|
|
mail.Status = uint32(pb.MailStatus_Deleted)
|
|
player.SaveModel(mail)
|
|
} else {
|
|
delete(player.Mail, req.Uid)
|
|
player.WipeModel(mail)
|
|
}
|
|
|
|
_ = player.Send(pb.ModId_ModuleMail, pb.MsgId_ModMailChange, &pb.MailChangeListAck{
|
|
ChangeList: []*pb.MailChange{{Uid: mail.Uid, Status: pb.MailStatus(mail.Status)}},
|
|
})
|
|
|
|
this.eventManager.PlayerMailLog(player, logic.LogTypeMailDelete, mail.Uid, mail.Type, mail.SentUserId, mail.SentServerId, mail.SentRoleId, mail.Title, mail.Content, mail.CreateTime, mail.Expiration, mail.Args, mail.Items)
|
|
}
|
|
|
|
func (this *PlayerHandler) MailDeleteAll(player *logic.Player, _ *net.Message) {
|
|
var changeList []*pb.MailChange
|
|
for id, mail := range player.Mail {
|
|
if pb.MailStatus(mail.Status) < pb.MailStatus_HasRead {
|
|
continue
|
|
}
|
|
|
|
if len(mail.Items) > 0 {
|
|
if pb.MailStatus(mail.Status) < pb.MailStatus_HasGot {
|
|
continue
|
|
}
|
|
}
|
|
|
|
if pb.MailType(mail.Type) == pb.MailType_MailAllRegion {
|
|
if pb.MailStatus(mail.Status) >= pb.MailStatus_Deleted {
|
|
continue
|
|
}
|
|
mail.Status = uint32(pb.MailStatus_Deleted)
|
|
player.SaveModel(mail)
|
|
} else {
|
|
delete(player.Mail, id)
|
|
player.WipeModel(mail)
|
|
}
|
|
|
|
changeList = append(changeList, &pb.MailChange{Uid: id, Status: pb.MailStatus_Deleted})
|
|
|
|
this.eventManager.PlayerMailLog(player, logic.LogTypeMailDelete, mail.Uid, mail.Type, mail.SentUserId, mail.SentServerId, mail.SentRoleId, mail.Title, mail.Content, mail.CreateTime, mail.Expiration, mail.Args, mail.Items)
|
|
}
|
|
|
|
if len(changeList) > 0 {
|
|
_ = player.Send(pb.ModId_ModuleMail, pb.MsgId_ModMailChange, &pb.MailChangeListAck{ChangeList: changeList})
|
|
}
|
|
}
|