Compare commits
4 Commits
d2ef266f81
...
3dab666dd8
Author | SHA1 | Date |
---|---|---|
Mr_Goldberg | 3dab666dd8 | |
Mr_Goldberg | bfe8e156f0 | |
Mr_Goldberg | 9c7499aa27 | |
Mr_Goldberg | 03426b217d |
10
dll/base.cpp
10
dll/base.cpp
|
@ -41,6 +41,11 @@ std::string get_env_variable(std::string name)
|
||||||
return utf8_encode(env_variable);
|
return utf8_encode(env_variable);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool set_env_variable(std::string name, std::string value)
|
||||||
|
{
|
||||||
|
return SetEnvironmentVariableW(utf8_decode(name).c_str(), utf8_decode(value).c_str());
|
||||||
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
static int fd = -1;
|
static int fd = -1;
|
||||||
|
@ -81,6 +86,11 @@ std::string get_env_variable(std::string name)
|
||||||
return std::string(env);
|
return std::string(env);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool set_env_variable(std::string name, std::string value)
|
||||||
|
{
|
||||||
|
return setenv(name.c_str(), value.c_str(), 1) == 0;
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
std::recursive_mutex global_mutex;
|
std::recursive_mutex global_mutex;
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
extern std::recursive_mutex global_mutex;
|
extern std::recursive_mutex global_mutex;
|
||||||
|
|
||||||
std::string get_env_variable(std::string name);
|
std::string get_env_variable(std::string name);
|
||||||
|
bool set_env_variable(std::string name, std::string value);
|
||||||
bool check_timedout(std::chrono::high_resolution_clock::time_point old, double timeout);
|
bool check_timedout(std::chrono::high_resolution_clock::time_point old, double timeout);
|
||||||
|
|
||||||
class CCallbackMgr
|
class CCallbackMgr
|
||||||
|
|
|
@ -125,6 +125,7 @@ message Networking_Sockets {
|
||||||
uint64 connection_id = 3;
|
uint64 connection_id = 3;
|
||||||
uint64 connection_id_from = 4;
|
uint64 connection_id_from = 4;
|
||||||
bytes data = 5;
|
bytes data = 5;
|
||||||
|
uint64 message_number = 7;
|
||||||
}
|
}
|
||||||
|
|
||||||
message Networking_Messages {
|
message Networking_Messages {
|
||||||
|
|
|
@ -1126,9 +1126,12 @@ void Networking::setAppID(uint32 appid)
|
||||||
|
|
||||||
bool Networking::sendToIPPort(Common_Message *msg, uint32 ip, uint16 port, bool reliable)
|
bool Networking::sendToIPPort(Common_Message *msg, uint32 ip, uint16 port, bool reliable)
|
||||||
{
|
{
|
||||||
|
bool is_local_ip = ((ip >> 24) == 0x7F);
|
||||||
|
uint32_t local_ip = getIP(ids.front());
|
||||||
|
PRINT_DEBUG("sendToIPPort %X %u %X\n", ip, is_local_ip, local_ip);
|
||||||
//TODO: actually send to ip/port
|
//TODO: actually send to ip/port
|
||||||
for (auto &conn: connections) {
|
for (auto &conn: connections) {
|
||||||
if (ntohl(conn.tcp_ip_port.ip) == ip) {
|
if (ntohl(conn.tcp_ip_port.ip) == ip || (is_local_ip && ntohl(conn.tcp_ip_port.ip) == local_ip)) {
|
||||||
for (auto &steam_id : conn.ids) {
|
for (auto &steam_id : conn.ids) {
|
||||||
msg->set_dest_id(steam_id.ConvertToUint64());
|
msg->set_dest_id(steam_id.ConvertToUint64());
|
||||||
sendTo(msg, reliable, &conn);
|
sendTo(msg, reliable, &conn);
|
||||||
|
|
|
@ -60,6 +60,11 @@ Steam_Client::Steam_Client()
|
||||||
|
|
||||||
PRINT_DEBUG("steam client init: id: %llu server id: %llu appid: %u port: %u \n", settings_client->get_local_steam_id().ConvertToUint64(), settings_server->get_local_steam_id().ConvertToUint64(), appid, settings_server->get_port());
|
PRINT_DEBUG("steam client init: id: %llu server id: %llu appid: %u port: %u \n", settings_client->get_local_steam_id().ConvertToUint64(), settings_server->get_local_steam_id().ConvertToUint64(), appid, settings_server->get_port());
|
||||||
|
|
||||||
|
if (appid) {
|
||||||
|
set_env_variable("SteamAppId", std::to_string(appid));
|
||||||
|
set_env_variable("SteamGameId", std::to_string(appid));
|
||||||
|
}
|
||||||
|
|
||||||
steam_overlay = new Steam_Overlay(settings_client, callback_results_client, callbacks_client, run_every_runcb, network);
|
steam_overlay = new Steam_Overlay(settings_client, callback_results_client, callbacks_client, run_every_runcb, network);
|
||||||
|
|
||||||
steam_user = new Steam_User(settings_client, local_storage, network, callback_results_client, callbacks_client);
|
steam_user = new Steam_User(settings_client, local_storage, network, callback_results_client, callbacks_client);
|
||||||
|
@ -159,6 +164,8 @@ void Steam_Client::setAppID(uint32 appid)
|
||||||
settings_server->set_game_id(CGameID(appid));
|
settings_server->set_game_id(CGameID(appid));
|
||||||
local_storage->setAppId(appid);
|
local_storage->setAppId(appid);
|
||||||
network->setAppID(appid);
|
network->setAppID(appid);
|
||||||
|
set_env_variable("SteamAppId", std::to_string(appid));
|
||||||
|
set_env_variable("SteamGameId", std::to_string(appid));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -35,6 +35,12 @@ enum connect_socket_status {
|
||||||
CONNECT_SOCKET_TIMEDOUT
|
CONNECT_SOCKET_TIMEDOUT
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct compare_snm_for_queue {
|
||||||
|
bool operator()(Networking_Sockets &left, Networking_Sockets &right) {
|
||||||
|
return left.message_number() > right.message_number();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
struct Connect_Socket {
|
struct Connect_Socket {
|
||||||
int virtual_port;
|
int virtual_port;
|
||||||
int real_port;
|
int real_port;
|
||||||
|
@ -47,10 +53,10 @@ struct Connect_Socket {
|
||||||
enum connect_socket_status status;
|
enum connect_socket_status status;
|
||||||
int64 user_data;
|
int64 user_data;
|
||||||
|
|
||||||
std::queue<std::string> data;
|
std::priority_queue<Networking_Sockets, std::vector<Networking_Sockets>, compare_snm_for_queue> data;
|
||||||
HSteamNetPollGroup poll_group;
|
HSteamNetPollGroup poll_group;
|
||||||
|
|
||||||
unsigned long long packet_receive_counter;
|
unsigned long long packet_send_counter;
|
||||||
CSteamID created_by;
|
CSteamID created_by;
|
||||||
|
|
||||||
std::chrono::steady_clock::time_point connect_request_last_sent;
|
std::chrono::steady_clock::time_point connect_request_last_sent;
|
||||||
|
@ -222,6 +228,7 @@ HSteamNetConnection new_connect_socket(SteamNetworkingIdentity remote_identity,
|
||||||
socket.created_by = settings->get_local_steam_id();
|
socket.created_by = settings->get_local_steam_id();
|
||||||
socket.connect_request_last_sent = std::chrono::steady_clock::now();
|
socket.connect_request_last_sent = std::chrono::steady_clock::now();
|
||||||
socket.connect_requests_sent = 0;
|
socket.connect_requests_sent = 0;
|
||||||
|
socket.packet_send_counter = 1;
|
||||||
|
|
||||||
HSteamNetConnection socket_id = get_socket_id();
|
HSteamNetConnection socket_id = get_socket_id();
|
||||||
if (socket_id == k_HSteamNetConnection_Invalid) ++socket_id;
|
if (socket_id == k_HSteamNetConnection_Invalid) ++socket_id;
|
||||||
|
@ -385,7 +392,7 @@ HSteamNetConnection ConnectByIPAddress( const SteamNetworkingIPAddr *address )
|
||||||
|
|
||||||
HSteamNetConnection ConnectByIPAddress( const SteamNetworkingIPAddr &address, int nOptions, const SteamNetworkingConfigValue_t *pOptions )
|
HSteamNetConnection ConnectByIPAddress( const SteamNetworkingIPAddr &address, int nOptions, const SteamNetworkingConfigValue_t *pOptions )
|
||||||
{
|
{
|
||||||
PRINT_DEBUG("Steam_Networking_Sockets::ConnectByIPAddress\n");
|
PRINT_DEBUG("Steam_Networking_Sockets::ConnectByIPAddress %X\n", address.GetIPv4());
|
||||||
std::lock_guard<std::recursive_mutex> lock(global_mutex);
|
std::lock_guard<std::recursive_mutex> lock(global_mutex);
|
||||||
SteamNetworkingIdentity ip_id;
|
SteamNetworkingIdentity ip_id;
|
||||||
ip_id.SetIPAddr(address);
|
ip_id.SetIPAddr(address);
|
||||||
|
@ -757,11 +764,17 @@ EResult SendMessageToConnection( HSteamNetConnection hConn, const void *pData, u
|
||||||
msg.mutable_networking_sockets()->set_connection_id_from(connect_socket->first);
|
msg.mutable_networking_sockets()->set_connection_id_from(connect_socket->first);
|
||||||
msg.mutable_networking_sockets()->set_connection_id(connect_socket->second.remote_id);
|
msg.mutable_networking_sockets()->set_connection_id(connect_socket->second.remote_id);
|
||||||
msg.mutable_networking_sockets()->set_data(pData, cbData);
|
msg.mutable_networking_sockets()->set_data(pData, cbData);
|
||||||
|
uint64 message_number = connect_socket->second.packet_send_counter;
|
||||||
|
msg.mutable_networking_sockets()->set_message_number(message_number);
|
||||||
|
connect_socket->second.packet_send_counter += 1;
|
||||||
|
|
||||||
bool reliable = false;
|
bool reliable = false;
|
||||||
if (nSendFlags & k_nSteamNetworkingSend_Reliable) reliable = true;
|
if (nSendFlags & k_nSteamNetworkingSend_Reliable) reliable = true;
|
||||||
|
if (network->sendTo(&msg, reliable)) {
|
||||||
|
if (pOutMessageNumber) *pOutMessageNumber = message_number;
|
||||||
|
return k_EResultOK;
|
||||||
|
}
|
||||||
|
|
||||||
if (pOutMessageNumber) *pOutMessageNumber = 1; //TODO
|
|
||||||
if (network->sendTo(&msg, reliable)) return k_EResultOK;
|
|
||||||
return k_EResultFail;
|
return k_EResultFail;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -853,17 +866,16 @@ SteamNetworkingMessage_t *get_steam_message_connection(HSteamNetConnection hConn
|
||||||
if (connect_socket == s->connect_sockets.end()) return NULL;
|
if (connect_socket == s->connect_sockets.end()) return NULL;
|
||||||
if (connect_socket->second.data.empty()) return NULL;
|
if (connect_socket->second.data.empty()) return NULL;
|
||||||
SteamNetworkingMessage_t *pMsg = new SteamNetworkingMessage_t();
|
SteamNetworkingMessage_t *pMsg = new SteamNetworkingMessage_t();
|
||||||
unsigned long size = connect_socket->second.data.front().size();
|
unsigned long size = connect_socket->second.data.top().data().size();
|
||||||
pMsg->m_pData = malloc(size);
|
pMsg->m_pData = malloc(size);
|
||||||
pMsg->m_cbSize = size;
|
pMsg->m_cbSize = size;
|
||||||
memcpy(pMsg->m_pData, connect_socket->second.data.front().data(), size);
|
memcpy(pMsg->m_pData, connect_socket->second.data.top().data().data(), size);
|
||||||
pMsg->m_conn = hConn;
|
pMsg->m_conn = hConn;
|
||||||
pMsg->m_identityPeer = connect_socket->second.remote_identity;
|
pMsg->m_identityPeer = connect_socket->second.remote_identity;
|
||||||
pMsg->m_nConnUserData = connect_socket->second.user_data;
|
pMsg->m_nConnUserData = connect_socket->second.user_data;
|
||||||
pMsg->m_usecTimeReceived = std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::steady_clock::now() - created).count();
|
pMsg->m_usecTimeReceived = std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::steady_clock::now() - created).count();
|
||||||
//TODO: check where messagenumber starts
|
//TODO: check where messagenumber starts
|
||||||
pMsg->m_nMessageNumber = connect_socket->second.packet_receive_counter;
|
pMsg->m_nMessageNumber = connect_socket->second.data.top().message_number();
|
||||||
++connect_socket->second.packet_receive_counter;
|
|
||||||
|
|
||||||
pMsg->m_pfnFreeData = &free_steam_message_data;
|
pMsg->m_pfnFreeData = &free_steam_message_data;
|
||||||
pMsg->m_pfnRelease = &delete_steam_message;
|
pMsg->m_pfnRelease = &delete_steam_message;
|
||||||
|
@ -2074,7 +2086,7 @@ void Callback(Common_Message *msg)
|
||||||
if (connect_socket != s->connect_sockets.end()) {
|
if (connect_socket != s->connect_sockets.end()) {
|
||||||
if (connect_socket->second.remote_identity.GetSteamID64() == msg->source_id() && connect_socket->second.status == CONNECT_SOCKET_CONNECTED) {
|
if (connect_socket->second.remote_identity.GetSteamID64() == msg->source_id() && connect_socket->second.status == CONNECT_SOCKET_CONNECTED) {
|
||||||
PRINT_DEBUG("Steam_Networking_Sockets: got data len %u on connection %u\n", msg->networking_sockets().data().size(), connect_socket->first);
|
PRINT_DEBUG("Steam_Networking_Sockets: got data len %u on connection %u\n", msg->networking_sockets().data().size(), connect_socket->first);
|
||||||
connect_socket->second.data.push(msg->networking_sockets().data());
|
connect_socket->second.data.push(msg->networking_sockets());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (msg->networking_sockets().type() == Networking_Sockets::CONNECTION_END) {
|
} else if (msg->networking_sockets().type() == Networking_Sockets::CONNECTION_END) {
|
||||||
|
|
|
@ -380,7 +380,7 @@ bool InitFilterText( uint32 unFilterOptions )
|
||||||
int FilterText( char* pchOutFilteredText, uint32 nByteSizeOutFilteredText, const char * pchInputMessage, bool bLegalOnly )
|
int FilterText( char* pchOutFilteredText, uint32 nByteSizeOutFilteredText, const char * pchInputMessage, bool bLegalOnly )
|
||||||
{
|
{
|
||||||
PRINT_DEBUG("FilterText old\n");
|
PRINT_DEBUG("FilterText old\n");
|
||||||
return 0;
|
return FilterText(k_ETextFilteringContextUnknown, CSteamID(), pchInputMessage, pchOutFilteredText, nByteSizeOutFilteredText );
|
||||||
}
|
}
|
||||||
|
|
||||||
// Filters the provided input message and places the filtered result into pchOutFilteredText, using legally required filtering and additional filtering based on the context and user settings
|
// Filters the provided input message and places the filtered result into pchOutFilteredText, using legally required filtering and additional filtering based on the context and user settings
|
||||||
|
@ -393,7 +393,16 @@ int FilterText( char* pchOutFilteredText, uint32 nByteSizeOutFilteredText, const
|
||||||
int FilterText( ETextFilteringContext eContext, CSteamID sourceSteamID, const char *pchInputMessage, char *pchOutFilteredText, uint32 nByteSizeOutFilteredText )
|
int FilterText( ETextFilteringContext eContext, CSteamID sourceSteamID, const char *pchInputMessage, char *pchOutFilteredText, uint32 nByteSizeOutFilteredText )
|
||||||
{
|
{
|
||||||
PRINT_DEBUG("FilterText\n");
|
PRINT_DEBUG("FilterText\n");
|
||||||
return 0;
|
if (!nByteSizeOutFilteredText) return 0;
|
||||||
|
unsigned len = strlen(pchInputMessage);
|
||||||
|
if (!len) return 0;
|
||||||
|
len += 1;
|
||||||
|
if (len > nByteSizeOutFilteredText) len = nByteSizeOutFilteredText;
|
||||||
|
len -= 1;
|
||||||
|
|
||||||
|
memcpy(pchOutFilteredText, pchInputMessage, len);
|
||||||
|
pchOutFilteredText[len] = 0;
|
||||||
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue