You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

262 lines
9.3 KiB

using System.Collections.Generic;
using Sog;
using ProtoCSStruct;
namespace Game
{
public static class MailSvc
{
public static int AddMailGoods(ref DBMail mail, int type, string id, int value)
{
if (! UnifyOp.IsValidGoodsId(type, id) || value <= 0)
{
TraceLog.Error("MailSvc.AddMailGoods invalid goods type {0} or id {1} or value {2}", type, id, value);
return -1;
}
for (int i = 0; i < mail.AddGoods.Count; i++)
{
if (mail.AddGoods[i].Type == type && mail.AddGoods[i].Id.ToString() == id)
{
mail.AddGoods[i].Value += value;
return 0;
}
}
if (mail.AddGoods.Count < mail.AddGoods.GetMaxCount())
{
var goods = new TypeIDValueString { Type = type, Id = new FixedStructString64(id), Value = value };
mail.AddGoods.Add(ref goods);
}
else
{
TraceLog.Error("MailSvc.AddMailGoods add type {0} id {1} value {2} failed, mail goods is full"
, (GoodsType)type, id, value);
return -2;
}
return 0;
}
internal static void QueryRoleMail(PlayerOnGame player)
{
//已经查询过了
if(player.DBMailDataLoadedTime != 0)
{
return;
}
player.Trace("MailSvc.OnPlayerOnline uid {0}, query role mail from db", player.UserID);
SSQueryMailReq req = new SSQueryMailReq();
req.Uid = player.UserID;
GameServerUtils.GetPacketSender().SendToMailServer((int)SSGameMsgID.QueryMailReq, ref req, player.UserID);
}
public static void OnPlayerOnline(PlayerOnGame player)
{
QueryRoleMail(player);
//第一次Facebook登录, 发送一封奖励邮件
if(player.RoleData.MailOp.FacebookLoginFirstMailTime == 0
&& player.AccountInfo.AccountType == 1)
{
player.Trace("MailSvc.OnPlayerOnline uid {0} login with facebook account,send award mail"
, player.UserID);
player.RoleData.MailOp.FacebookLoginFirstMailTime = GameServerUtils.GetTimeSecond();
player.MakeDirty();
DBMail awardMail = new DBMail();
awardMail.Uid = player.UserID;
//var currency = new IDValue64() { Id = (long)CurrencyType.Chip, Value =0 };
//awardMail.AddCurrency.Add(ref currency);
awardMail.MailType = (int)MailType.FacebookLoginFirst;
awardMail.Title.SetString("#Mail23");
awardMail.Content.SetString("#Mail24");
MailSender.SendNewMailToPlayer(player.UserID, ref awardMail);
}
////老玩家补偿
//var targetReamId = PresetSvc.GetOldPlayerReamId();
//PlayerSession playerSession = GameServerUtils.GetPlayerTableOp().GetPlayerSession(player.SessionID);
//if (!player.RoleData.ExtData.IsSendCompensation && playerSession.AccountInfo.Compensation > 1 &&
// player.RealmID == targetReamId)
//{
// DBMail mail = new DBMail();
// mail.Uid = player.UserID;
// mail.MailType = (int)MailType.Compensation;
// mail.SendTime = GameServerUtils.GetTimeSecond();
// mail.Title.SetString("#OldPlayerReward_MailName");
// mail.Content.SetString("#OldPlayerReward_MailDesc");
// MailSvc.AddMailGoods(ref mail, (int)GoodsType.Items, ItemId.Token,
// playerSession.AccountInfo.Compensation);
// player.RoleData.ExtData.IsSendCompensation = true;
// MailSender.SendNewMailToPlayer(player.UserID, ref mail);
//}
}
public static void DeleteMailMemory(PlayerOnGame player,long mailID)
{
//没数据
if (player.DBMailDataLoadedTime == 0)
{
return;
}
for(int i=0; i<player.MailInfo.Count; i++)
{
ref var mail = ref player.MailInfo[i];
if(mail.MailID == mailID)
{
player.MailInfo.RemoveAt(i);
player.Trace("MailSvc.DeleteMailMemory uid {0} mailID {1} success"
, player.UserID, mailID);
//删除成功后返回
return;
}
}
player.Error("MailSvc.DeleteMailMemory uid {0} mailID {1} not in memory"
, player.UserID, mailID);
}
public static void DeleteAllMailMemory(PlayerOnGame player, List<long> list)
{
//没数据
if (player.DBMailDataLoadedTime == 0)
{
return;
}
if (list == null)
{
return;
}
foreach (long mailId in list)
{
for (int i = player.MailInfo.Count - 1; i >= 0; i--)
{
ref var mail = ref player.MailInfo[i];
if (mail.MailID == mailId)
{
player.MailInfo.RemoveAt(i);
player.Trace("MailSvc.DeleteAllMailMemory uid {0} mailID {1} success"
, player.UserID, mail.MailID);
break;
}
}
}
}
public static void InsertMailMemory(PlayerOnGame player, ref DBMail newMail)
{
//没数据
if (player.DBMailDataLoadedTime == 0)
{
return;
}
for (int i = 0; i < player.MailInfo.Count; i++)
{
ref var mail = ref player.MailInfo[i];
if (mail.MailID == newMail.MailID)
{
player.Error("MailSvc.InsertMailMemory uid {0} mailID {1} already in memory"
, player.UserID, newMail.MailID);
break;
}
}
if (player.MailInfo.Count < player.MailInfo.GetMaxCount())
{
player.MailInfo.Add(ref newMail);
}
else
{
TraceLog.Error("MailSvc.InsertMailMemory error,player {0} not enough space to insert Mail {1}",
player.UserID, newMail.MailID);
}
player.Trace("MailSvc.InsertMailMemory uid {0} mailID {1} success in memory"
, player.UserID, newMail.MailID);
}
public static int GetMailIndexFromPlayer(PlayerOnGame player, long mailID)
{
//没数据
if (player.DBMailDataLoadedTime == 0)
{
return -1;
}
for (int i = 0; i < player.MailInfo.Count; i++)
{
ref var mail = ref player.MailInfo[i];
if (mail.MailID == mailID)
{
player.Trace("MailSvc.GetMailIndexFromPlayer uid {0} mailID {1} success", player.UserID, mailID);
return i;
}
}
player.Error("MailSvc.GetMailIndexFromPlayer uid {0} mailID {1} not in memory", player.UserID, mailID);
return -1;
}
public static ref DBMail GetMailByIndex(PlayerOnGame player, int index)
{
return ref player.MailInfo[index];
}
//某些特殊邮件的特殊逻辑
public static void ProcessSpecialMailOnQueryRes(PlayerOnGame player)
{
//List<uint> delMailList = new List<uint>();
////先从内存中删除
//foreach(var mailID in delMailList)
//{
// DeleteMailMemory(player, mailID);
//}
for(int i = 0; i < player.MailInfo.Count;i++)
{
ref var mail = ref player.MailInfo[i];
if(mail.AddReward.IsEmpty() == false)
{
//处理奖励
List<RewardItemRW> res = RewardSvc.Reward(player, mail.AddReward.GetString(), false);
foreach (var r in res)
{
TypeIDValueString typeIDValueString = new TypeIDValueString();
typeIDValueString.Type = r.type;
typeIDValueString.Id.SetString(r.code);
typeIDValueString.Value = (int)r.amount;
mail.AddGoods.Add(ref typeIDValueString);
}
mail.AddReward.SetString("");
//通知mailsvr
SSMailOpReq mailOpReq = new SSMailOpReq();
mailOpReq.OpType = (int)MailOpType.Update;
mailOpReq.ClientOpUid = player.UserID;
mailOpReq.AckGameServerID = GameServerUtils.GetApp().ServerID;
mailOpReq.UniqueID = WaitAckStructRequestSender.Instance.GeneratorUniqueID();
mailOpReq.Mail = mail;
GameServerUtils.GetPacketSender().SendToMailServer((int)SSGameMsgID.MailOpReq, ref mailOpReq, player.UserID);
}
}
}
}
}