remove some obviated const_casts
This commit is contained in:
+1
-1
@@ -36,7 +36,7 @@ bool Client::send(string&& data) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (this->crypt_out.get()) {
|
if (this->crypt_out.get()) {
|
||||||
this->crypt_out->encrypt(const_cast<char*>(data.data()), data.size());
|
this->crypt_out->encrypt(data.data(), data.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
struct evbuffer* buf = bufferevent_get_output(this->bev);
|
struct evbuffer* buf = bufferevent_get_output(this->bev);
|
||||||
|
|||||||
+6
-8
@@ -67,7 +67,7 @@ void ProxyServer::send_to_end(const std::string& data, bool to_server) {
|
|||||||
PSOEncryption* crypt = to_server ? this->server_output_crypt.get() : this->client_output_crypt.get();
|
PSOEncryption* crypt = to_server ? this->server_output_crypt.get() : this->client_output_crypt.get();
|
||||||
if (crypt) {
|
if (crypt) {
|
||||||
string crypted_data = data;
|
string crypted_data = data;
|
||||||
crypt->encrypt(const_cast<char*>(crypted_data.data()), crypted_data.size());
|
crypt->encrypt(crypted_data.data(), crypted_data.size());
|
||||||
evbuffer_add(buf, crypted_data.data(), crypted_data.size());
|
evbuffer_add(buf, crypted_data.data(), crypted_data.size());
|
||||||
} else {
|
} else {
|
||||||
evbuffer_add(buf, data.data(), data.size());
|
evbuffer_add(buf, data.data(), data.size());
|
||||||
@@ -274,21 +274,19 @@ void ProxyServer::receive_and_process_commands(bool from_server) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
string command(command_size, '\0');
|
string command(command_size, '\0');
|
||||||
ssize_t bytes = evbuffer_remove(source_buf,
|
ssize_t bytes = evbuffer_remove(source_buf, command.data(), command_size);
|
||||||
const_cast<char*>(command.data()), command_size);
|
|
||||||
if (bytes < static_cast<ssize_t>(command_size)) {
|
if (bytes < static_cast<ssize_t>(command_size)) {
|
||||||
throw logic_error("enough bytes available, but could not remove them");
|
throw logic_error("enough bytes available, but could not remove them");
|
||||||
}
|
}
|
||||||
//log(INFO, "[ProxyServer-debug] read command (%zX bytes)", bytes);
|
//log(INFO, "[ProxyServer-debug] read command (%zX bytes)", bytes);
|
||||||
// overwrite the header with the already-decrypted header
|
// overwrite the header with the already-decrypted header
|
||||||
memcpy(const_cast<char*>(command.data()), input_header, this->header_size);
|
memcpy(command.data(), input_header, this->header_size);
|
||||||
|
|
||||||
//log(INFO, "[ProxyServer-debug] received encrypted command with pre-decrypted header");
|
//log(INFO, "[ProxyServer-debug] received encrypted command with pre-decrypted header");
|
||||||
//print_data(stderr, command);
|
//print_data(stderr, command);
|
||||||
|
|
||||||
if (source_crypt) {
|
if (source_crypt) {
|
||||||
source_crypt->decrypt(
|
source_crypt->decrypt(command.data() + this->header_size,
|
||||||
const_cast<char*>(command.data() + this->header_size),
|
|
||||||
command_size - this->header_size);
|
command_size - this->header_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -346,7 +344,7 @@ void ProxyServer::receive_and_process_commands(bool from_server) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ReconnectCommandArgs* args = reinterpret_cast<ReconnectCommandArgs*>(
|
ReconnectCommandArgs* args = reinterpret_cast<ReconnectCommandArgs*>(
|
||||||
const_cast<char*>(command.data() + this->header_size));
|
command.data() + this->header_size);
|
||||||
memset(&this->next_destination, 0, sizeof(this->next_destination));
|
memset(&this->next_destination, 0, sizeof(this->next_destination));
|
||||||
struct sockaddr_in* sin = reinterpret_cast<struct sockaddr_in*>(
|
struct sockaddr_in* sin = reinterpret_cast<struct sockaddr_in*>(
|
||||||
&this->next_destination);
|
&this->next_destination);
|
||||||
@@ -378,7 +376,7 @@ void ProxyServer::receive_and_process_commands(bool from_server) {
|
|||||||
// reencrypt and forward the command
|
// reencrypt and forward the command
|
||||||
if (dest_buf) {
|
if (dest_buf) {
|
||||||
if (dest_crypt) {
|
if (dest_crypt) {
|
||||||
dest_crypt->encrypt(const_cast<char*>(command.data()), command.size());
|
dest_crypt->encrypt(command.data(), command.size());
|
||||||
}
|
}
|
||||||
//log(INFO, "[ProxyServer-debug] sending encrypted command");
|
//log(INFO, "[ProxyServer-debug] sending encrypted command");
|
||||||
//print_data(stderr, command);
|
//print_data(stderr, command);
|
||||||
|
|||||||
+2
-2
@@ -54,7 +54,7 @@ commands:\n\
|
|||||||
if (data.size() == 0) {
|
if (data.size() == 0) {
|
||||||
throw invalid_argument("no data given");
|
throw invalid_argument("no data given");
|
||||||
}
|
}
|
||||||
uint16_t* size_field = reinterpret_cast<uint16_t*>(const_cast<char*>(data.data() + 2));
|
uint16_t* size_field = reinterpret_cast<uint16_t*>(data.data() + 2);
|
||||||
*size_field = data.size();
|
*size_field = data.size();
|
||||||
|
|
||||||
log(INFO, "%s (from proxy):", to_client ? "server" : "client");
|
log(INFO, "%s (from proxy):", to_client ? "server" : "client");
|
||||||
@@ -78,7 +78,7 @@ commands:\n\
|
|||||||
}
|
}
|
||||||
data.push_back('\0');
|
data.push_back('\0');
|
||||||
data.resize((data.size() + 3) & (~3));
|
data.resize((data.size() + 3) & (~3));
|
||||||
uint16_t* size_field = reinterpret_cast<uint16_t*>(const_cast<char*>(data.data() + 2));
|
uint16_t* size_field = reinterpret_cast<uint16_t*>(data.data() + 2);
|
||||||
*size_field = data.size();
|
*size_field = data.size();
|
||||||
|
|
||||||
log(INFO, "client (from proxy):");
|
log(INFO, "client (from proxy):");
|
||||||
|
|||||||
+6
-7
@@ -366,7 +366,7 @@ string Quest::decode_gci(const string& filename) {
|
|||||||
"GCI file is truncated before download quest header (have 0x%zX bytes)", data.size()));
|
"GCI file is truncated before download quest header (have 0x%zX bytes)", data.size()));
|
||||||
}
|
}
|
||||||
PSODownloadQuestHeader* h = reinterpret_cast<PSODownloadQuestHeader*>(
|
PSODownloadQuestHeader* h = reinterpret_cast<PSODownloadQuestHeader*>(
|
||||||
const_cast<char*>(data.data() + 0x2080));
|
data.data() + 0x2080);
|
||||||
h->byteswap();
|
h->byteswap();
|
||||||
|
|
||||||
string compressed_data_with_header = data.substr(0x2088, h->size);
|
string compressed_data_with_header = data.substr(0x2088, h->size);
|
||||||
@@ -385,8 +385,8 @@ string Quest::decode_gci(const string& filename) {
|
|||||||
if (compressed_data_with_header.size() < sizeof(DecryptedHeader)) {
|
if (compressed_data_with_header.size() < sizeof(DecryptedHeader)) {
|
||||||
throw runtime_error("GCI file compressed data truncated during header");
|
throw runtime_error("GCI file compressed data truncated during header");
|
||||||
}
|
}
|
||||||
DecryptedHeader* dh = reinterpret_cast<DecryptedHeader*>(const_cast<char*>(
|
DecryptedHeader* dh = reinterpret_cast<DecryptedHeader*>(
|
||||||
compressed_data_with_header.data()));
|
compressed_data_with_header.data());
|
||||||
if (dh->unknown1 || dh->unknown2 || dh->unknown4) {
|
if (dh->unknown1 || dh->unknown2 || dh->unknown4) {
|
||||||
throw runtime_error("GCI file appears to be encrypted");
|
throw runtime_error("GCI file appears to be encrypted");
|
||||||
}
|
}
|
||||||
@@ -476,8 +476,7 @@ vector<shared_ptr<const Quest>> QuestIndex::filter(GameVersion version,
|
|||||||
static string create_download_quest_file(const string& compressed_data,
|
static string create_download_quest_file(const string& compressed_data,
|
||||||
size_t decompressed_size) {
|
size_t decompressed_size) {
|
||||||
string data(8, '\0');
|
string data(8, '\0');
|
||||||
auto* header = reinterpret_cast<PSODownloadQuestHeader*>(const_cast<char*>(
|
auto* header = reinterpret_cast<PSODownloadQuestHeader*>(data.data());
|
||||||
compressed_data.data()));
|
|
||||||
header->size = decompressed_size + sizeof(PSODownloadQuestHeader);
|
header->size = decompressed_size + sizeof(PSODownloadQuestHeader);
|
||||||
header->encryption_seed = random_object<uint32_t>();
|
header->encryption_seed = random_object<uint32_t>();
|
||||||
data += compressed_data;
|
data += compressed_data;
|
||||||
@@ -487,7 +486,7 @@ static string create_download_quest_file(const string& compressed_data,
|
|||||||
|
|
||||||
// TODO: for DC quests, do we use DC encryption?
|
// TODO: for DC quests, do we use DC encryption?
|
||||||
PSOPCEncryption encr(header->encryption_seed);
|
PSOPCEncryption encr(header->encryption_seed);
|
||||||
encr.encrypt(const_cast<char*>(data.data() + sizeof(PSODownloadQuestHeader)),
|
encr.encrypt(data.data() + sizeof(PSODownloadQuestHeader),
|
||||||
data.size() - sizeof(PSODownloadQuestHeader));
|
data.size() - sizeof(PSODownloadQuestHeader));
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
@@ -498,7 +497,7 @@ shared_ptr<Quest> Quest::create_download_quest(const string& file_basename) cons
|
|||||||
}
|
}
|
||||||
|
|
||||||
string decompressed_bin = prs_decompress(*this->bin_contents());
|
string decompressed_bin = prs_decompress(*this->bin_contents());
|
||||||
void* data_ptr = const_cast<char*>(decompressed_bin.data());
|
void* data_ptr = decompressed_bin.data();
|
||||||
switch (this->version) {
|
switch (this->version) {
|
||||||
case GameVersion::DC:
|
case GameVersion::DC:
|
||||||
reinterpret_cast<PSOQuestHeaderDC*>(data_ptr)->is_download = 0x01;
|
reinterpret_cast<PSOQuestHeaderDC*>(data_ptr)->is_download = 0x01;
|
||||||
|
|||||||
@@ -2220,27 +2220,27 @@ void process_command(shared_ptr<ServerState> s, shared_ptr<Client> c,
|
|||||||
if (c->version == GameVersion::BB) {
|
if (c->version == GameVersion::BB) {
|
||||||
data_to_print.resize(size + 8);
|
data_to_print.resize(size + 8);
|
||||||
PSOCommandHeaderBB* header = reinterpret_cast<PSOCommandHeaderBB*>(
|
PSOCommandHeaderBB* header = reinterpret_cast<PSOCommandHeaderBB*>(
|
||||||
const_cast<char*>(data_to_print.data()));
|
data_to_print.data());
|
||||||
header->command = command;
|
header->command = command;
|
||||||
header->flag = flag;
|
header->flag = flag;
|
||||||
header->size = size + 8;
|
header->size = size + 8;
|
||||||
memcpy(const_cast<char*>(data_to_print.data() + 8), data, size);
|
memcpy(data_to_print.data() + 8, data, size);
|
||||||
} else if (c->version == GameVersion::PC) {
|
} else if (c->version == GameVersion::PC) {
|
||||||
data_to_print.resize(size + 4);
|
data_to_print.resize(size + 4);
|
||||||
PSOCommandHeaderPC* header = reinterpret_cast<PSOCommandHeaderPC*>(
|
PSOCommandHeaderPC* header = reinterpret_cast<PSOCommandHeaderPC*>(
|
||||||
const_cast<char*>(data_to_print.data()));
|
data_to_print.data());
|
||||||
header->command = command;
|
header->command = command;
|
||||||
header->flag = flag;
|
header->flag = flag;
|
||||||
header->size = size + 4;
|
header->size = size + 4;
|
||||||
memcpy(const_cast<char*>(data_to_print.data() + 4), data, size);
|
memcpy(data_to_print.data() + 4, data, size);
|
||||||
} else { // DC/GC
|
} else { // DC/GC
|
||||||
data_to_print.resize(size + 4);
|
data_to_print.resize(size + 4);
|
||||||
PSOCommandHeaderDCGC* header = reinterpret_cast<PSOCommandHeaderDCGC*>(
|
PSOCommandHeaderDCGC* header = reinterpret_cast<PSOCommandHeaderDCGC*>(
|
||||||
const_cast<char*>(data_to_print.data()));
|
data_to_print.data());
|
||||||
header->command = command;
|
header->command = command;
|
||||||
header->flag = flag;
|
header->flag = flag;
|
||||||
header->size = size + 4;
|
header->size = size + 4;
|
||||||
memcpy(const_cast<char*>(data_to_print.data() + 4), data, size);
|
memcpy(data_to_print.data() + 4, data, size);
|
||||||
}
|
}
|
||||||
print_data(stderr, data_to_print);
|
print_data(stderr, data_to_print);
|
||||||
}
|
}
|
||||||
|
|||||||
+8
-8
@@ -360,8 +360,8 @@ void send_guild_card_chunk_bb(shared_ptr<Client> c, size_t chunk_index) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
string contents(8, '\0');
|
string contents(8, '\0');
|
||||||
*reinterpret_cast<uint32_t*>(const_cast<char*>(contents.data())) = 0;
|
*reinterpret_cast<uint32_t*>(contents.data()) = 0;
|
||||||
*reinterpret_cast<uint32_t*>(const_cast<char*>(contents.data() + 4)) = chunk_index;
|
*reinterpret_cast<uint32_t*>(contents.data() + 4) = chunk_index;
|
||||||
contents.append(reinterpret_cast<char*>(&c->player.guild_cards + chunk_offset),
|
contents.append(reinterpret_cast<char*>(&c->player.guild_cards + chunk_offset),
|
||||||
data_size);
|
data_size);
|
||||||
|
|
||||||
@@ -469,7 +469,7 @@ static void send_large_message_pc_patch_bb(shared_ptr<Client> c, uint8_t command
|
|||||||
u16string data;
|
u16string data;
|
||||||
if (include_header) {
|
if (include_header) {
|
||||||
data.resize(sizeof(LargeMessageOptionalHeader) / sizeof(char16_t));
|
data.resize(sizeof(LargeMessageOptionalHeader) / sizeof(char16_t));
|
||||||
*reinterpret_cast<LargeMessageOptionalHeader*>(const_cast<char16_t*>(data.data())) =
|
*reinterpret_cast<LargeMessageOptionalHeader*>(data.data()) =
|
||||||
{0, from_serial_number};
|
{0, from_serial_number};
|
||||||
}
|
}
|
||||||
data += text;
|
data += text;
|
||||||
@@ -483,7 +483,7 @@ static void send_large_message_dc_gc(shared_ptr<Client> c, uint8_t command,
|
|||||||
string data;
|
string data;
|
||||||
if (include_header) {
|
if (include_header) {
|
||||||
data.resize(sizeof(LargeMessageOptionalHeader) / sizeof(char));
|
data.resize(sizeof(LargeMessageOptionalHeader) / sizeof(char));
|
||||||
*reinterpret_cast<LargeMessageOptionalHeader*>(const_cast<char*>(data.data())) =
|
*reinterpret_cast<LargeMessageOptionalHeader*>(data.data()) =
|
||||||
{0, from_serial_number};
|
{0, from_serial_number};
|
||||||
}
|
}
|
||||||
data += encode_sjis(text);
|
data += encode_sjis(text);
|
||||||
@@ -2025,7 +2025,7 @@ void send_ep3_card_list_update(shared_ptr<Client> c) {
|
|||||||
auto file_data = file_cache.get("system/ep3/cardupdate.mnr");
|
auto file_data = file_cache.get("system/ep3/cardupdate.mnr");
|
||||||
|
|
||||||
string data("\0\0\0\0", 4);
|
string data("\0\0\0\0", 4);
|
||||||
*reinterpret_cast<uint32_t*>(const_cast<char*>(data.data())) = file_data->size();
|
*reinterpret_cast<uint32_t*>(data.data()) = file_data->size();
|
||||||
data += *file_data;
|
data += *file_data;
|
||||||
data.resize((data.size() + 3) & ~3);
|
data.resize((data.size() + 3) & ~3);
|
||||||
|
|
||||||
@@ -2049,7 +2049,7 @@ void send_ep3_map_list(shared_ptr<Lobby> l) {
|
|||||||
auto file_data = file_cache.get("system/ep3/maplist.mnr");
|
auto file_data = file_cache.get("system/ep3/maplist.mnr");
|
||||||
|
|
||||||
string data(16, '\0');
|
string data(16, '\0');
|
||||||
PSOSubcommand* subs = reinterpret_cast<PSOSubcommand*>(const_cast<char*>(data.data()));
|
PSOSubcommand* subs = reinterpret_cast<PSOSubcommand*>(data.data());
|
||||||
subs[0].dword = 0x000000B6;
|
subs[0].dword = 0x000000B6;
|
||||||
subs[1].dword = (23 + file_data->size()) & 0xFFFFFFFC;
|
subs[1].dword = (23 + file_data->size()) & 0xFFFFFFFC;
|
||||||
subs[2].dword = 0x00000040;
|
subs[2].dword = 0x00000040;
|
||||||
@@ -2065,7 +2065,7 @@ void send_ep3_map_data(shared_ptr<Lobby> l, uint32_t map_id) {
|
|||||||
auto file_data = file_cache.get(filename);
|
auto file_data = file_cache.get(filename);
|
||||||
|
|
||||||
string data(12, '\0');
|
string data(12, '\0');
|
||||||
PSOSubcommand* subs = reinterpret_cast<PSOSubcommand*>(const_cast<char*>(data.data()));
|
PSOSubcommand* subs = reinterpret_cast<PSOSubcommand*>(data.data());
|
||||||
subs[0].dword = 0x000000B6;
|
subs[0].dword = 0x000000B6;
|
||||||
subs[1].dword = (19 + file_data->size()) & 0xFFFFFFFC;
|
subs[1].dword = (19 + file_data->size()) & 0xFFFFFFFC;
|
||||||
subs[2].dword = 0x00000041;
|
subs[2].dword = 0x00000041;
|
||||||
@@ -2168,7 +2168,7 @@ void send_server_time(shared_ptr<Client> c) {
|
|||||||
gmtime_r(&t_secs, &t_parsed);
|
gmtime_r(&t_secs, &t_parsed);
|
||||||
|
|
||||||
string time_str(128, 0);
|
string time_str(128, 0);
|
||||||
size_t len = strftime(const_cast<char*>(time_str.data()), time_str.size(),
|
size_t len = strftime(time_str.data(), time_str.size(),
|
||||||
"%Y:%m:%d: %H:%M:%S.000", &t_parsed);
|
"%Y:%m:%d: %H:%M:%S.000", &t_parsed);
|
||||||
if (len == 0) {
|
if (len == 0) {
|
||||||
throw runtime_error("format_time buffer too short");
|
throw runtime_error("format_time buffer too short");
|
||||||
|
|||||||
+1
-1
@@ -184,7 +184,7 @@ void Server::receive_and_process_commands(shared_ptr<Client> c) {
|
|||||||
size_t new_bytes = evbuffer_get_length(buf);
|
size_t new_bytes = evbuffer_get_length(buf);
|
||||||
new_bytes &= ~(header_size - 1); // only read in multiples of header_size
|
new_bytes &= ~(header_size - 1); // only read in multiples of header_size
|
||||||
c->recv_buffer.resize(existing_bytes + new_bytes);
|
c->recv_buffer.resize(existing_bytes + new_bytes);
|
||||||
void* recv_ptr = const_cast<char*>(c->recv_buffer.data() + existing_bytes);
|
void* recv_ptr = c->recv_buffer.data() + existing_bytes;
|
||||||
if (evbuffer_remove(buf, recv_ptr, new_bytes) != static_cast<ssize_t>(new_bytes)) {
|
if (evbuffer_remove(buf, recv_ptr, new_bytes) != static_cast<ssize_t>(new_bytes)) {
|
||||||
throw runtime_error("some bytes could not be read from the receive buffer");
|
throw runtime_error("some bytes could not be read from the receive buffer");
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -57,7 +57,7 @@ void Shell::read_stdin() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
string command(2048, '\0');
|
string command(2048, '\0');
|
||||||
if (!fgets(const_cast<char*>(command.data()), command.size(), stdin)) {
|
if (!fgets(command.data(), command.size(), stdin)) {
|
||||||
if (!any_command_read) {
|
if (!any_command_read) {
|
||||||
// ctrl+d probably; we should exit
|
// ctrl+d probably; we should exit
|
||||||
fputc('\n', stderr);
|
fputc('\n', stderr);
|
||||||
|
|||||||
+1
-1
@@ -72,6 +72,6 @@ size_t add_color_inplace(T* a) {
|
|||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
void add_color_inplace(std::basic_string<T>& a, size_t header_bytes) {
|
void add_color_inplace(std::basic_string<T>& a, size_t header_bytes) {
|
||||||
size_t count = add_color_inplace(const_cast<T*>(a.data() + header_bytes));
|
size_t count = add_color_inplace(a.data() + header_bytes);
|
||||||
a.resize(count + header_bytes);
|
a.resize(count + header_bytes);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user