Skip to content

Instantly share code, notes, and snippets.

@apathyboy
Forked from Kronos11/gist:1008402
Created June 8, 2011 03:18
Show Gist options
  • Select an option

  • Save apathyboy/1013706 to your computer and use it in GitHub Desktop.

Select an option

Save apathyboy/1013706 to your computer and use it in GitHub Desktop.
LoginClientToken
template<typename T>
struct BaseSwgPacket {
void serialize(anh::ByteBuffer& buffer) const {
buffer.write(T::opcount);
buffer.write(T::opcode);
onSerialize(buffer);
}
void deserialize(anh::ByteBuffer buffer) {
uint16_t opcount = buffer.read<uint16_t>();
uint32_t opcode = buffer.read<uint32_t>();
if (opcount != T::opcount || opcode != T::opcode) {
// @todo throw here perhaps? for now just return;
return;
}
onDeserialize(std::move(buffer));
}
virtual void onSerialize(anh::ByteBuffer& buffer) const = 0;
virtual void onDeserialize(anh::ByteBuffer buffer) = 0;
};
struct LoginClientId : public BaseSwgPacket<LoginClientId> {
static const uint16_t opcount = 4;
static const uint32_t opcode = 0x41131F96;
std::string username;
std::string password;
std::string client_version;
void onDeserialize(anh::ByteBuffer buffer) {
username = buffer.read<std::string>();
password = buffer.read<std::string>();
client_version = buffer.read<std::string>();
}
void onSerialize(anh::ByteBuffer& buffer) const {
buffer.write(username);
buffer.write(password);
buffer.write(client_version);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment