Net: port the select-phase packets
Character create/delete/rename and empire selection now reach the server, and LOGIN_SUCCESS3, PLAYER_CREATE_SUCCESS/FAILURE, PLAYER_DELETE_SUCCESS/WRONG_SOCIAL_ID, POINT_CHANGE and CHANGE_NAME are parsed and forwarded to the select/create windows like Windows. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
40cac5cf52
commit
31c74cec28
@@ -1,5 +1,6 @@
|
||||
#include "protocol.h"
|
||||
#include "eter_net/Packet.h"
|
||||
#include <algorithm>
|
||||
#include <stdexcept>
|
||||
#include <cstring>
|
||||
|
||||
@@ -19,6 +20,38 @@ Bytes select_character(std::uint8_t slot) {
|
||||
return {HEADER_CG_CHARACTER_SELECT, slot};
|
||||
}
|
||||
|
||||
namespace {
|
||||
// strncpy into a zeroed char[width]: at most width-1 bytes keep the terminator (CHARACTER_NAME_MAX_LEN+1 field).
|
||||
void fixed(Bytes& out, const std::string& value, std::size_t width, std::size_t copy) {
|
||||
auto start=out.size(); out.resize(start+width,0);
|
||||
std::copy_n(value.begin(), std::min({value.size(), copy, width}), out.begin()+start);
|
||||
}
|
||||
}
|
||||
|
||||
Bytes create_character(std::uint8_t slot, const std::string& name, std::uint16_t job, std::uint8_t shape,
|
||||
std::uint8_t con, std::uint8_t intelligence, std::uint8_t str, std::uint8_t dex) {
|
||||
Bytes out{HEADER_CG_PLAYER_CREATE, slot};
|
||||
// strncpy(name, name, CHARACTER_NAME_MAX_LEN): the 25th byte stays 0.
|
||||
fixed(out, name, CHARACTER_NAME_MAX_LEN+1, CHARACTER_NAME_MAX_LEN);
|
||||
u16(out, job);
|
||||
out.insert(out.end(), {shape, con, intelligence, str, dex});
|
||||
return out;
|
||||
}
|
||||
|
||||
Bytes destroy_character(std::uint8_t slot, const std::string& private_code) {
|
||||
Bytes out{HEADER_CG_PLAYER_DESTROY, slot};
|
||||
fixed(out, private_code, 8, 8-1); // strncpy(szPrivateCode, code, PRIVATE_CODE_LENGTH-1)
|
||||
return out;
|
||||
}
|
||||
|
||||
Bytes select_empire(std::uint8_t empire) { return {HEADER_CG_EMPIRE, empire}; }
|
||||
|
||||
Bytes change_name(std::uint8_t slot, const std::string& name) {
|
||||
Bytes out{HEADER_CG_CHANGE_NAME, slot};
|
||||
fixed(out, name, CHARACTER_NAME_MAX_LEN+1, CHARACTER_NAME_MAX_LEN);
|
||||
return out;
|
||||
}
|
||||
|
||||
Bytes attack(std::uint8_t type, std::uint32_t victim, std::uint8_t process_crc, std::uint8_t file_crc) {
|
||||
Bytes out{HEADER_CG_ATTACK, type};
|
||||
u32(out, victim);
|
||||
|
||||
Reference in New Issue
Block a user