26 lines
1.1 KiB
C++
26 lines
1.1 KiB
C++
#pragma once
|
|
#include "gateway/protocol.hpp"
|
|
#include <array>
|
|
#include <set>
|
|
namespace gateway {
|
|
struct ForcedReaction { uint32_t faction=0, reaction=0; };
|
|
using ForcedReactions=std::array<ForcedReaction,32>;
|
|
inline ForcedReactions turtle_forced_reactions(std::span<const uint8_t> body) {
|
|
Reader r(body);const auto count=r.le(4);
|
|
if(count>32)throw Error("forced reaction slot bound");
|
|
ForcedReactions slots{};std::set<uint32_t> seen;
|
|
for(unsigned i=0;i<count;++i){
|
|
auto faction=uint32_t(r.le(4)),reaction=uint32_t(r.le(4));
|
|
if(!faction || faction>INT32_MAX || reaction>7 || !seen.insert(faction).second)
|
|
throw Error("invalid forced reaction");
|
|
slots[i]={faction,reaction};
|
|
}
|
|
r.end();return slots;
|
|
}
|
|
// Version 1, realm, map, self, followed by every slot. Zero pairs clear old overrides.
|
|
inline Bytes forced_reactions_input(uint16_t realm,uint16_t map,uint64_t self,const ForcedReactions& slots){
|
|
Bytes out{1};le(out,realm,2);le(out,map,2);le(out,self,8);
|
|
for(const auto& s:slots){le(out,s.faction,4);le(out,s.reaction,4);}return out;
|
|
}
|
|
}
|