//--------------------------------------------------------------------- // 收到邮件的通知 public override void onRecvMailNotify(Mail mail) { }
//--------------------------------------------------------------------- // 系统给单人发送邮件 Task IGrainAppProxyService.SendMailFromSystem(Mail mail) { if (!string.IsNullOrEmpty(mail.RecverGuid)) { string grain_key = string.Format("{0}_{1}", AppId, mail.RecverGuid); var grain_cache_playermailbox = GrainFactory.GetGrain<IGrainMailBoxCache>(grain_key); grain_cache_playermailbox.AddMail(mail); } else { // 接收邮件的PlayerId为空,拒收该邮件 } return TaskDone.Done; }
//--------------------------------------------------------------------- // 收到邮件的通知 public abstract void onRecvMailNotify(Mail mail);
//--------------------------------------------------------------------- // Cell->Cell //async Task IGrainPlayer.S2SAddFriendRequest(string player_from) //{ // Logger.Info("S2SAddFriendRequest() GrainId={0}", GrainKey); // if (!GrainClientKey.Equals(Guid.Empty)) // { // // 读取PlayerInfo // var player_info = await IMContext.Instance.Mongo.ReadAsync<PlayerInfo>( // e => e.Id == player_from, DbCollectName.PlayerInfo); // // 推送给Client // if (player_info != null) // { // PlayerNotify player_notify; // player_notify.id = PlayerNotifyId.AddFriendRequestNotify; // player_notify.data = EbTool.protobufSerialize<PlayerInfo>(MemoryStream, player_info); // ((IGrainPlayer)this).ClientNotify(player_notify); // } // } //} //--------------------------------------------------------------------- // Cell->Cell,对FromPlayer生效 //Task IGrainPlayer.S2SAddFriendResponseNotify(AddFriendResponseNotify addfriend_response_notify) //{ // Logger.Info("S2SAddFriendResponseNotify() GrainId={0}", GrainKey); // // 本地添加好友 // //ListFriend.Add(addfriend_response_notify.player_response.Id); // // 更新好友列表缓存 // //var grain_cache_friendlist = GrainFactory.GetGrain<IGrainCacheFriendList>(this.GetPrimaryKey()); // //grain_cache_friendlist.AddFriend(addfriend_response_notify.player_response.Id); // if (!GrainClientKey.Equals(Guid.Empty)) // { // // 推送给Client // PlayerNotify player_notify; // player_notify.id = PlayerNotifyId.AddFriendResponseNotify; // player_notify.data = EbTool.protobufSerialize<AddFriendResponseNotify>(MemoryStream, addfriend_response_notify); // ((IGrainPlayer)this).ClientNotify(player_notify); // } // return TaskDone.Done; //} //--------------------------------------------------------------------- // Cell->Cell,FromPlayer->ToPlayer //Task IGrainPlayer.S2SDeleteFriendResponseNotify(string player_guid) //{ // Logger.Info("S2SDeleteFriendResponseNotify() GrainId={0}", GrainKey); // // 直接从本地列表删除好友 // //ListFriend.RemoveAll(item => // //{ // // if (item == player_guid) return true; // // else return false; // //}); // // 更新好友列表缓存 // //var grain_cache_friendlist = GrainFactory.GetGrain<IGrainCacheFriendList>(this.GetPrimaryKey()); // //grain_cache_friendlist.DeleteFriend(player_guid); // if (!GrainClientKey.Equals(Guid.Empty)) // { // // 推送给Client // PlayerNotify player_notify; // player_notify.id = PlayerNotifyId.DeleteFriendNotify; // player_notify.data = EbTool.protobufSerialize<string>(MemoryStream, player_guid); // ((IGrainPlayer)this).ClientNotify(player_notify); // } // return TaskDone.Done; //} //--------------------------------------------------------------------- // Cell->Cell,System->ToPlayer Task IGrainPlayer.S2SRecvMailSystem2Player(Mail mail) { Logger.Info("S2SRecvMailSystem2Player() GrainId={0}", GrainKey); mail.Id = Guid.NewGuid().ToString(); mail.MailState = MailState.New; mail.CreateTime = DateTime.UtcNow; mail.SenderType = MailSenderType.System; // 本地添加邮件 //ListMail.Add(mail); // 更新MailList缓存 //var grain_cache_maillist = GrainFactory.GetGrain<IGrainCacheMailList>(this.GetPrimaryKey()); //grain_cache_maillist.AddMail(mail); // 通知Client收到消息 if (!GrainClientKey.Equals(Guid.Empty)) { PlayerNotify player_notify; player_notify.id = PlayerNotifyId.RecvMailNotify; player_notify.data = EbTool.protobufSerialize<Mail>(MemoryStream, mail); ((IGrainPlayer)this).ClientNotify(player_notify); } return TaskDone.Done; }
//--------------------------------------------------------------------- async Task IGrainMailBoxCache.AddMail(Mail mail) { ListMail.Add(mail); // 告知Client if (HasClient) { PlayerNotify player_notify; player_notify.id = PlayerNotifyId.RecvMailNotify; player_notify.data = EbTool.protobufSerialize<Mail>(MemoryStream, mail); var grain_player = this.GrainFactory.GetGrain<IGrainPlayer>(GrainKey); grain_player.ClientNotify(player_notify); } // Mail写入Db await IMContext.Instance.Mongo.InsertAsync<Mail>( IMContext.DbCollectMailInfo, mail); }