Skip to content
This repository has been archived by the owner on Apr 10, 2021. It is now read-only.

Commit

Permalink
stop crashing from invalid characters
Browse files Browse the repository at this point in the history
  • Loading branch information
1fbff5f83b23d39d38b1dfcb4cac8d9b committed Jan 11, 2020
1 parent c576003 commit 731b6a9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
12 changes: 6 additions & 6 deletions byond-extools/src/core/socket/socket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ bool Socket::create(int family, int socktype, int protocol)
return raw_socket != INVALID_SOCKET;
}

bool connect_socket(Socket& socket, const char* port, const char* remote)
bool connect_socket(Socket& socket, const char* port, const char* remote, bool yell = false)
{

struct addrinfo* result = NULL;
Expand All @@ -75,14 +75,14 @@ bool connect_socket(Socket& socket, const char* port, const char* remote)
iResult = getaddrinfo(remote, port, &hints, &result);
if (iResult != 0)
{
Core::Alert("getaddrinfo failed with error: " + std::to_string(iResult));
if(yell) Core::Alert("getaddrinfo failed with error: " + std::to_string(iResult));
return false;
}

// Create a SOCKET for connecting to server
if (!socket.create(result->ai_family, result->ai_socktype, result->ai_protocol))
{
Core::Alert("socket failed with error: " + std::to_string(WSAGetLastError()));
if(yell) Core::Alert("socket failed with error: " + std::to_string(WSAGetLastError()));
freeaddrinfo(result);
return false;
}
Expand All @@ -91,7 +91,7 @@ bool connect_socket(Socket& socket, const char* port, const char* remote)
iResult = ::connect(socket.raw(), result->ai_addr, (int)result->ai_addrlen);
if (iResult == SOCKET_ERROR)
{
Core::Alert("connect failed with error: " + std::to_string(WSAGetLastError()));
if(yell) Core::Alert("connect failed with error: " + std::to_string(WSAGetLastError()));
freeaddrinfo(result);
socket.close();
return false;
Expand Down Expand Up @@ -176,7 +176,7 @@ bool JsonStream::connect(const char* port, const char* remote)
return false;
}

return connect_socket(socket, port, remote);
return connect_socket(socket, port, remote, true);
}

bool JsonStream::send(const char* type, nlohmann::json content)
Expand All @@ -190,7 +190,7 @@ bool JsonStream::send(const char* type, nlohmann::json content)

bool JsonStream::send(nlohmann::json j)
{
std::string data = j.dump();
std::string data = j.dump(-1, ' ', false, nlohmann::json::error_handler_t::replace);
data.push_back(0);
while (!data.empty())
{
Expand Down
2 changes: 1 addition & 1 deletion byond-extools/src/extended_profiling/normal_profiling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ trvh dump_all_profiles(unsigned int args_len, Value* args, Value src)
interresult.push_back(j);
}
nlohmann::json jresult = interresult;
std::string result = jresult.dump();
std::string result = jresult.dump(-1, ' ', false, nlohmann::json::error_handler_t::replace);
auto end = std::chrono::high_resolution_clock::now();
unsigned long long milis = std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count();
//Core::Alert(std::to_string(milis));
Expand Down

0 comments on commit 731b6a9

Please sign in to comment.