100 lines
5.8 KiB
C++
100 lines
5.8 KiB
C++
#pragma once
|
|
#include "gateway/protocol.hpp"
|
|
#include <cstdint>
|
|
#include <cstring>
|
|
#include <optional>
|
|
#include <span>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
// Mailbox — FULLY DROPPED in the gateway (SMSG_MAIL_LIST_RESULT 0x23B,
|
|
// SMSG_SEND_MAIL_RESULT 0x239, SMSG_RECEIVED_MAIL 0x285, MSG_QUERY_NEXT_MAIL_TIME
|
|
// 0x284 have no dispatch; CMSG_* 0x238-0x24A never re-emitted). Source half, both
|
|
// directions. From tortoise MailHandler.cpp. Guids FULL le(8) (operator<<).
|
|
// Verified: SMSG_MAIL_LIST_RESULT is variable-length (u8 count + per-mail variant
|
|
// sender + cstring subject + ALWAYS-written 8-field item block, entry==0 = no item).
|
|
namespace gateway {
|
|
|
|
enum : uint32_t { // MailResponseType (SMSG_SEND_MAIL_RESULT action)
|
|
MAIL_SEND=0, MAIL_MONEY_TAKEN=1, MAIL_ITEM_TAKEN=2, MAIL_RETURNED_TO_SENDER=3,
|
|
MAIL_DELETED=4, MAIL_MADE_PERMANENT=5 };
|
|
enum : uint32_t { // MailResponseResult (error)
|
|
MAIL_OK=0, MAIL_ERR_EQUIP_ERROR=1, MAIL_ERR_CANNOT_SEND_TO_SELF=2,
|
|
MAIL_ERR_NOT_ENOUGH_MONEY=3, MAIL_ERR_RECIPIENT_NOT_FOUND=4, MAIL_ERR_NOT_YOUR_TEAM=5,
|
|
MAIL_ERR_INTERNAL_ERROR=6, MAIL_ERR_DISABLED_FOR_TRIAL_ACC=14, MAIL_ERR_RECIPIENT_CAP_REACHED=15 };
|
|
enum : uint8_t { // MailMessageType (per-mail sender variant)
|
|
MAIL_NORMAL=0, MAIL_AUCTION=2, MAIL_CREATURE=3, MAIL_GAMEOBJECT=4, MAIL_ITEM=5 };
|
|
|
|
// ---- inbound: SMSG_SEND_MAIL_RESULT 0x239 ----
|
|
struct TurtleMailSendResult { uint32_t mailId=0,action=0,error=0,equipError=0,itemGuidLow=0,itemCount=0; };
|
|
inline std::optional<TurtleMailSendResult> turtle_mail_send_result(std::span<const uint8_t> body){
|
|
Reader r(body); TurtleMailSendResult d;
|
|
d.mailId=uint32_t(r.le(4)); d.action=uint32_t(r.le(4)); d.error=uint32_t(r.le(4));
|
|
if(d.error==MAIL_ERR_EQUIP_ERROR) d.equipError=uint32_t(r.le(4));
|
|
else if(d.action==MAIL_ITEM_TAKEN){ d.itemGuidLow=uint32_t(r.le(4)); d.itemCount=uint32_t(r.le(4)); }
|
|
r.end(); return d;
|
|
}
|
|
|
|
// ---- inbound: SMSG_RECEIVED_MAIL 0x285 (new-mail chime) ----
|
|
struct TurtleReceivedMail { uint32_t unk=0; };
|
|
inline std::optional<TurtleReceivedMail> turtle_received_mail(std::span<const uint8_t> body){
|
|
Reader r(body); TurtleReceivedMail d; d.unk=uint32_t(r.le(4)); r.end(); return d;
|
|
}
|
|
|
|
// ---- inbound: MSG_QUERY_NEXT_MAIL_TIME 0x284 (server reply = one float) ----
|
|
struct TurtleNextMailTime { float seconds=0.f; }; // 0 = unread waiting, -86400 = none
|
|
inline std::optional<TurtleNextMailTime> turtle_next_mail_time(std::span<const uint8_t> body){
|
|
Reader r(body); uint32_t bits=uint32_t(r.le(4)); r.end();
|
|
TurtleNextMailTime d; std::memcpy(&d.seconds,&bits,4); return d;
|
|
}
|
|
|
|
// ---- inbound: SMSG_MAIL_LIST_RESULT 0x23B (the inbox) ----
|
|
struct TurtleMailItem { uint32_t entry=0,permEnchant=0,randomPropId=0,suffixFactor=0; uint8_t count=0;
|
|
uint32_t charges=0,maxDurability=0,durability=0; };
|
|
struct TurtleMailEntry {
|
|
uint32_t messageID=0; uint8_t messageType=0;
|
|
uint64_t senderGuid=0; uint32_t senderEntry=0; // NORMAL->guid; CREATURE/GO/AUCTION->entry
|
|
std::string subject; uint32_t itemTextId=0,unk=0,stationery=0;
|
|
bool hasItem=false; TurtleMailItem item;
|
|
uint32_t money=0,cod=0,checked=0; float daysLeft=0.f; uint32_t mailTemplateId=0;
|
|
};
|
|
struct TurtleMailList { std::vector<TurtleMailEntry> mails; };
|
|
inline std::optional<TurtleMailList> turtle_mail_list_result(std::span<const uint8_t> body){
|
|
Reader r(body); TurtleMailList d; uint32_t count=uint32_t(r.le(1));
|
|
for(uint32_t m=0;m<count;++m){
|
|
TurtleMailEntry e; e.messageID=uint32_t(r.le(4)); e.messageType=uint8_t(r.le(1));
|
|
switch(e.messageType){
|
|
case MAIL_NORMAL: e.senderGuid=r.le(8); break;
|
|
case MAIL_CREATURE: case MAIL_GAMEOBJECT: case MAIL_AUCTION: e.senderEntry=uint32_t(r.le(4)); break;
|
|
case MAIL_ITEM: default: break; // no sender field
|
|
}
|
|
e.subject=r.cstring(256); e.itemTextId=uint32_t(r.le(4)); e.unk=uint32_t(r.le(4)); e.stationery=uint32_t(r.le(4));
|
|
e.item.entry=uint32_t(r.le(4)); e.item.permEnchant=uint32_t(r.le(4)); e.item.randomPropId=uint32_t(r.le(4));
|
|
e.item.suffixFactor=uint32_t(r.le(4)); e.item.count=uint8_t(r.le(1)); e.item.charges=uint32_t(r.le(4));
|
|
e.item.maxDurability=uint32_t(r.le(4)); e.item.durability=uint32_t(r.le(4)); e.hasItem=e.item.entry!=0;
|
|
e.money=uint32_t(r.le(4)); e.cod=uint32_t(r.le(4)); e.checked=uint32_t(r.le(4));
|
|
uint32_t fbits=uint32_t(r.le(4)); std::memcpy(&e.daysLeft,&fbits,4);
|
|
e.mailTemplateId=uint32_t(r.le(4));
|
|
d.mails.push_back(std::move(e));
|
|
}
|
|
r.end(); return d;
|
|
}
|
|
|
|
// ---- outbound: native CMSG -> Source CMSG body builders (Source 1.12 opcodes) ----
|
|
// 0x238 SEND_MAIL : u64 mailbox, cstr receiver, cstr subject, cstr body, u32 stationery,
|
|
// u32 0, u64 itemGuid, u32 money, u32 cod, u64 0, u8 0
|
|
// 0x23A GET_MAIL_LIST : u64 mailbox 0x245 TAKE_MONEY : u64 mailbox, u32 mailId
|
|
// 0x246 TAKE_ITEM : u64 mailbox, u32 mailId 0x247 MARK_AS_READ: u64 mailbox, u32 mailId
|
|
// 0x248 RETURN_TO_SENDER : u64 mailbox, u32 mailId 0x249 DELETE: u64 mailbox, u32 mailId
|
|
// 0x24A CREATE_TEXT_ITEM : u64 mailbox, u32 mailId 0x284 QUERY_NEXT_MAIL_TIME: empty
|
|
inline Bytes source_send_mail(uint64_t mailbox,const std::string& receiver,const std::string& subject,
|
|
const std::string& bodyText,uint32_t stationery,uint64_t itemGuid,uint32_t money,uint32_t cod){
|
|
Bytes b; le(b,mailbox,8); cstring(b,receiver); cstring(b,subject); cstring(b,bodyText);
|
|
le(b,stationery,4); le(b,0,4); le(b,itemGuid,8); le(b,money,4); le(b,cod,4); le(b,0,8); le(b,0,1); return b;
|
|
}
|
|
inline Bytes source_mailbox_only(uint64_t mailbox){ Bytes b; le(b,mailbox,8); return b; } // GET_MAIL_LIST
|
|
inline Bytes source_mailbox_mail(uint64_t mailbox,uint32_t mailId){ Bytes b; le(b,mailbox,8); le(b,mailId,4); return b; } // take/mark/return/delete/create-text
|
|
inline Bytes source_query_next_mail_time(){ return Bytes{}; }
|
|
|
|
} // namespace gateway
|