/// <summary> /// 写邮件 /// </summary> public void HandleWriteMail(MailWriteInfo info) { if (info.receiver.IsIdxValid()) { ProcessWrite(info); } else { if (String.IsNullOrEmpty(info.receiver.char_name)) { Log.Debug("错误的收件人name:" + info.receiver.char_name); return; } Player recv_player = UnitManager.Instance.GetPlayerByName(info.receiver.char_name); if (recv_player != null) { info.receiver.char_idx = recv_player.char_idx; ProcessWrite(info); } else {//需要查db Player player = UnitManager.Instance.GetUnitByIdx(m_char_idx) as Player; if (player == null) { return; } SQLCharHandle.QueryCharacterInfoByName(info.receiver.char_name, player.db_id, (ret, data) => {//收件人必须是在同一个数据库 if (ret && m_char_idx > 0) { info.receiver.char_idx = data.char_idx; ProcessWrite(info); } else {//告诉客户端发送失败 ss2c.MailCommand msg_client = PacketPools.Get(ss2c.msg.MAIL_COMMAND) as ss2c.MailCommand; msg_client.mail_idx = 0; msg_client.command_type = eMailCommandType.WRITE_MAIL; msg_client.error_type = eMailCommandError.RECIPIENT_NOT_FOUND; ServerNetManager.Instance.SendProxy(player.client_uid, msg_client); } }); } } }
/// <summary> /// 删除邮件 /// </summary> /// <param name="list">需要删除的列表</param> public void HandleDeleteMail(List <long> list) { Player player = UnitManager.Instance.GetUnitByIdx(m_char_idx) as Player; if (player == null) { return; } foreach (var mail_idx in list) { MailInfo mail_info; if (!m_all_mails.TryGetValue(mail_idx, out mail_info)) { continue; } if (m_del_mails.Contains(mail_idx)) { continue; } if (mail_info.receiver_idx == 0) { continue; } // 告诉客户端 if (mail_info.mail_type != eMailType.SYSTEM_INTERNAL) { ss2c.MailCommand msg_client = PacketPools.Get(ss2c.msg.MAIL_COMMAND) as ss2c.MailCommand; msg_client.mail_idx = mail_idx; msg_client.command_type = eMailCommandType.DELETE_MAIL; msg_client.error_type = eMailCommandError.NONE; ServerNetManager.Instance.SendProxy(player.client_uid, msg_client); } // 修改邮件集合 m_del_mails.Add(mail_idx); m_new_mails.Remove(mail_idx); m_save_mails.Remove(mail_idx); m_all_mails.Remove(mail_idx); CommonObjectPools.Despawn(mail_info); } }
private void ProcessWrite(MailWriteInfo info) { Player player = UnitManager.Instance.GetUnitByIdx(m_char_idx) as Player; if (player == null) { return; } if (info.receiver.char_idx == 0) { Log.Debug("错误的收件人id:" + info.receiver.char_idx); return; } //存db MailInfo mail_info = CommonObjectPools.Spawn <MailInfo>(); mail_info.mail_idx = IdSharedManager.Instance.GetNextMailIdx(); mail_info.mail_type = eMailType.NORMAL; mail_info.spid = 0;//普通邮件,不区分渠道id mail_info.receiver_idx = info.receiver.char_idx; mail_info.sender_idx = m_char_idx; mail_info.sender_name = player.char_name; mail_info.send_time = Time.second_time; mail_info.expire_time = 0; mail_info.delivery_time = 0; mail_info.flags = (uint)eMailFlags.NONE; mail_info.subject = info.subject; mail_info.bin_mail_content.content_type = eMailContentType.NORMAL; mail_info.bin_mail_content.bin_normal_content.content = info.content; SQLMailHandle.CreateMail(mail_info, player.db_id); CommonObjectPools.Despawn(mail_info); //告诉客户端发送成功 ss2c.MailCommand msg_client = PacketPools.Get(ss2c.msg.MAIL_COMMAND) as ss2c.MailCommand; msg_client.mail_idx = 0; msg_client.command_type = eMailCommandType.WRITE_MAIL; msg_client.error_type = eMailCommandError.NONE; ServerNetManager.Instance.SendProxy(player.client_uid, msg_client); }
/// <summary> /// 邮件操作结果 /// </summary> private void OnMailCommand(PacketBase packet) { ss2c.MailCommand msg = packet as ss2c.MailCommand; }