Revert change

merge-requests/38/head
julien bruel 2021-04-09 21:07:04 +02:00
parent 570d8e43b2
commit 3ee66fb2de
16 changed files with 44 additions and 220 deletions

View File

@ -136,7 +136,7 @@ Steam_Client *get_steam_clientserver_old()
static bool steamclient_has_ipv6_functions_flag;
bool steamclient_has_ipv6_functions()
{
return steamclient_has_ipv6_functions_flag;
return steamclient_has_ipv6_functions_flag || get_steam_client()->gameserver_has_ipv6_functions;
}
static void *create_client_interface(const char *ver)

View File

@ -5843,9 +5843,15 @@ STEAMAPI_API SteamAPICall_t SteamAPI_ISteamGameServer_GetServerReputation( IStea
return self->GetServerReputation();
}
STEAMAPI_API SteamIPAddress_t SteamAPI_ISteamGameServer_GetPublicIP( ISteamGameServer* self )
{
return self->GetPublicIP();
STEAMAPI_API void *SteamAPI_ISteamGameServer_GetPublicIP( intptr_t instancePtr, void *instancePtr_possible )
{
//abuse call convention rules to get this working.
if (steamclient_has_ipv6_functions()) {
get_steam_client()->steam_gameserver->GetPublicIP_fix((SteamIPAddress_t *)instancePtr);
return (void *)instancePtr;
} else {
return (void *)((ISteamGameServer012 *)instancePtr)->GetPublicIP_old();
}
}
STEAMAPI_API bool SteamAPI_ISteamGameServer_HandleIncomingPacket( ISteamGameServer* self, const void * pData, int cbData, uint32 srcIP, uint16 srcPort )

View File

@ -16,7 +16,6 @@
<http://www.gnu.org/licenses/>. */
#include "network.h"
#include "dll.h"
#define MAX_BROADCASTS 16
static int number_broadcasts = -1;
@ -219,26 +218,25 @@ static int set_socket_nonblocking(sock_t sock)
static void kill_socket(sock_t sock)
{
if (is_socket_valid(sock))
{
#if defined(STEAM_WIN32)
closesocket(sock);
#else
close(sock);
#endif
}
#if defined(STEAM_WIN32)
closesocket(sock);
#else
close(sock);
#endif
}
static void kill_tcp_socket(struct TCP_Socket &socket)
{
kill_socket(socket.sock);
if (is_socket_valid(socket.sock)) {
kill_socket(socket.sock);
}
socket = TCP_Socket();
}
static bool initialed;
static void run_at_startup()
{
static bool initialed = false;
if (initialed) {
return;
}
@ -893,22 +891,6 @@ void Networking::Run()
char data[2048];
int len;
if (query_alive && is_socket_valid(query_socket)) {
PRINT_DEBUG("RECV QUERY\n");
Steam_Client* client = get_steam_client();
sockaddr_in addr;
addr.sin_family = AF_INET;
while ((len = receive_packet(query_socket, &ip_port, data, sizeof(data))) >= 0) {
client->steam_gameserver->HandleIncomingPacket(data, len, htonl(ip_port.ip), htons(ip_port.port));
len = client->steam_gameserver->GetNextOutgoingPacket(data, sizeof(data), &ip_port.ip, &ip_port.port);
addr.sin_addr.s_addr = htonl(ip_port.ip);
addr.sin_port = htons(ip_port.port);
sendto(query_socket, data, len, 0, (sockaddr*)&addr, sizeof(addr));
}
}
PRINT_DEBUG("RECV UDP\n");
while((len = receive_packet(udp_socket, &ip_port, data, sizeof(data))) >= 0) {
PRINT_DEBUG("recv %i %hhu.%hhu.%hhu.%hhu:%hu\n", len, ((unsigned char *)&ip_port.ip)[0], ((unsigned char *)&ip_port.ip)[1], ((unsigned char *)&ip_port.ip)[2], ((unsigned char *)&ip_port.ip)[3], htons(ip_port.port));
@ -1270,75 +1252,3 @@ bool Networking::isAlive()
{
return alive;
}
void Networking::startQuery(IP_PORT ip_port)
{
if (ip_port.port <= 1024)
return;
if (!query_alive)
{
if (ip_port.port == MASTERSERVERUPDATERPORT_USEGAMESOCKETSHARE)
{
PRINT_DEBUG("Source Query in Shared Mode\n");
return;
}
int retry = 0;
constexpr auto max_retry = 10;
while (retry++ < max_retry)
{
query_socket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
if (is_socket_valid(query_socket))
break;
if (retry > max_retry)
{
reset_last_error();
return;
}
}
retry = 0;
sockaddr_in addr;
addr.sin_addr.s_addr = htonl(ip_port.ip);
addr.sin_port = htons(ip_port.port);
addr.sin_family = AF_INET;
while (retry++ < max_retry)
{
int res = bind(query_socket, (sockaddr*)&addr, sizeof(sockaddr_in));
if (res == 0)
{
set_socket_nonblocking(query_socket);
break;
}
if (retry >= max_retry)
{
kill_socket(query_socket);
query_socket = -1;
reset_last_error();
return;
}
}
char str_ip[16];
inet_ntop(AF_INET, &(addr.sin_addr), str_ip, 16);
PRINT_DEBUG("Started query server on %s:%d\n", str_ip, htons(addr.sin_port));
}
query_alive = true;
}
void Networking::shutDownQuery()
{
query_alive = false;
kill_socket(query_socket);
}
bool Networking::isQueryAlive()
{
return query_alive;
}

View File

@ -86,10 +86,9 @@ struct Connection {
class Networking {
bool enabled = false;
bool query_alive;
bool alive;
std::chrono::high_resolution_clock::time_point last_run;
sock_t query_socket, udp_socket, tcp_socket;
sock_t udp_socket, tcp_socket;
uint16 udp_port, tcp_port;
uint32 own_ip;
std::vector<struct Connection> connections;
@ -137,11 +136,6 @@ public:
void shutDown();
bool isAlive();
void startQuery(IP_PORT ip_port);
void shutDownQuery();
bool isQueryAlive();
};
#endif

View File

@ -145,9 +145,6 @@ public:
//networking
bool disable_networking = false;
//gameserver source query
bool disable_source_query = false;
//overlay
bool disable_overlay = false;
};

View File

@ -109,6 +109,8 @@ Steam_Client::Steam_Client()
steam_gameserver_game_coordinator = new Steam_Game_Coordinator(settings_server, network, callback_results_server, callbacks_server, run_every_runcb);
steam_masterserver_updater = new Steam_Masterserver_Updater(settings_server, network, callback_results_server, callbacks_server, run_every_runcb);
gameserver_has_ipv6_functions = false;
last_cb_run = 0;
PRINT_DEBUG("client init end\n");
}
@ -303,8 +305,10 @@ ISteamGameServer *Steam_Client::GetISteamGameServer( HSteamUser hSteamUser, HSte
} else if (strcmp(pchVersion, "SteamGameServer012") == 0) {
return (ISteamGameServer *)(void *)(ISteamGameServer012 *)steam_gameserver;
} else if (strcmp(pchVersion, STEAMGAMESERVER_INTERFACE_VERSION) == 0) {
gameserver_has_ipv6_functions = true;
return (ISteamGameServer *)(void *)(ISteamGameServer *)steam_gameserver;
} else {
gameserver_has_ipv6_functions = true;
return (ISteamGameServer *)(void *)(ISteamGameServer *)steam_gameserver;
}

View File

@ -139,6 +139,8 @@ public:
unsigned steam_pipe_counter = 1;
std::map<HSteamPipe, enum Steam_Pipe> steam_pipes;
bool gameserver_has_ipv6_functions;
Steam_Client();
~Steam_Client();
// Creates a communication pipe to the Steam client.

View File

@ -16,7 +16,6 @@
<http://www.gnu.org/licenses/>. */
#include "steam_gameserver.h"
#include "source_query.h"
#define SEND_SERVER_RATE 5.0
@ -34,11 +33,6 @@ Steam_GameServer::~Steam_GameServer()
delete ticket_manager;
}
std::vector<std::pair<CSteamID, Gameserver_Player_Info_t>>* Steam_GameServer::get_players()
{
return &players;
}
//
// Basic server data. These properties, if set, must be set before before calling LogOn. They
// may not be changed after logged in.
@ -60,10 +54,6 @@ bool Steam_GameServer::InitGameServer( uint32 unIP, uint16 usGamePort, uint16 us
server_data.set_port(usGamePort);
server_data.set_query_port(usQueryPort);
server_data.set_offline(false);
if (!settings->disable_source_query)
network->startQuery({ unIP, usQueryPort });
if (!settings->get_local_game_id().AppID()) settings->set_game_id(CGameID(nGameAppId));
//TODO: flags should be k_unServerFlag
flags = unFlags;
@ -354,22 +344,7 @@ bool Steam_GameServer::SendUserConnectAndAuthenticate( uint32 unIPClient, const
PRINT_DEBUG("SendUserConnectAndAuthenticate %u %u\n", unIPClient, cubAuthBlobSize);
std::lock_guard<std::recursive_mutex> lock(global_mutex);
bool res = ticket_manager->SendUserConnectAndAuthenticate(unIPClient, pvAuthBlob, cubAuthBlobSize, pSteamIDUser);
if (res)
{
std::pair<CSteamID, Gameserver_Player_Info_t> infos;
if( pSteamIDUser != nullptr)
infos.first = *pSteamIDUser;
infos.second.join_time = std::chrono::steady_clock::now();
infos.second.score = 0;
infos.second.name = "Player";
players.emplace_back(std::move(infos));
}
return res;
return ticket_manager->SendUserConnectAndAuthenticate(unIPClient, pvAuthBlob, cubAuthBlobSize, pSteamIDUser);
}
@ -382,16 +357,7 @@ CSteamID Steam_GameServer::CreateUnauthenticatedUserConnection()
PRINT_DEBUG("CreateUnauthenticatedUserConnection\n");
std::lock_guard<std::recursive_mutex> lock(global_mutex);
CSteamID bot_id = ticket_manager->fakeUser();
std::pair<CSteamID, Gameserver_Player_Info_t> infos;
infos.first = bot_id;
infos.second.join_time = std::chrono::steady_clock::now();
infos.second.score = 0;
infos.second.name = "Bot";
players.emplace_back(std::move(infos));
return bot_id;
return ticket_manager->fakeUser();
}
@ -402,16 +368,6 @@ void Steam_GameServer::SendUserDisconnect( CSteamID steamIDUser )
{
PRINT_DEBUG("SendUserDisconnect\n");
std::lock_guard<std::recursive_mutex> lock(global_mutex);
auto player_it = std::find_if(players.begin(), players.end(), [&steamIDUser](std::pair<CSteamID, Gameserver_Player_Info_t>& player)
{
return player.first == steamIDUser;
});
if (player_it != players.end())
{
players.erase(player_it);
}
ticket_manager->endAuth(steamIDUser);
}
@ -425,21 +381,7 @@ void Steam_GameServer::SendUserDisconnect( CSteamID steamIDUser )
bool Steam_GameServer::BUpdateUserData( CSteamID steamIDUser, const char *pchPlayerName, uint32 uScore )
{
PRINT_DEBUG("BUpdateUserData\n");
auto player_it = std::find_if(players.begin(), players.end(), [&steamIDUser](std::pair<CSteamID, Gameserver_Player_Info_t>& player)
{
return player.first == steamIDUser;
});
if (player_it != players.end())
{
if( pchPlayerName != nullptr)
player_it->second.name = pchPlayerName;
player_it->second.score = uScore;
return true;
}
return false;
return true;
}
// You shouldn't need to call this as it is called internally by SteamGameServer_Init() and can only be called once.
@ -617,6 +559,12 @@ SteamIPAddress_t Steam_GameServer::GetPublicIP()
return ip;
}
void Steam_GameServer::GetPublicIP_fix(SteamIPAddress_t *out)
{
PRINT_DEBUG("GetPublicIP_fix\n");
if (out) *out = GetPublicIP();
}
// These are in GameSocketShare mode, where instead of ISteamGameServer creating its own
// socket to talk to the master server on, it lets the game use its socket to forward messages
// back and forth. This prevents us from requiring server ops to open up yet another port
@ -636,18 +584,6 @@ bool Steam_GameServer::HandleIncomingPacket( const void *pData, int cbData, uint
{
PRINT_DEBUG("HandleIncomingPacket %i %X %i\n", cbData, srcIP, srcPort);
std::lock_guard<std::recursive_mutex> lock(global_mutex);
if (settings->disable_source_query) return true;
Gameserver_Outgoing_Packet packet;
packet.data = std::move(Source_Query::handle_source_query(pData, cbData, server_data));
if (packet.data.empty())
return false;
packet.ip = srcIP;
packet.port = srcPort;
outgoing_packets.emplace_back(std::move(packet));
return true;
}
@ -660,7 +596,6 @@ int Steam_GameServer::GetNextOutgoingPacket( void *pOut, int cbMaxOut, uint32 *p
{
PRINT_DEBUG("GetNextOutgoingPacket\n");
std::lock_guard<std::recursive_mutex> lock(global_mutex);
if (settings->disable_source_query) return 0;
if (outgoing_packets.size() == 0) return 0;
if (outgoing_packets.back().data.size() < cbMaxOut) cbMaxOut = outgoing_packets.back().data.size();
@ -761,10 +696,6 @@ void Steam_GameServer::RunCallbacks()
msg.set_allocated_gameserver(new Gameserver(server_data));
msg.mutable_gameserver()->set_offline(true);
network->sendToAllIndividuals(&msg, true);
// Shutdown Source Query
network->shutDownQuery();
// And empty the queue if needed
outgoing_packets.clear();
}
}
}

View File

@ -15,9 +15,6 @@
License along with the Goldberg Emulator; if not, see
<http://www.gnu.org/licenses/>. */
#ifndef __INCLUDED_GAMESERVER__
#define __INCLUDED_GAMESERVER__
#include "base.h"
//-----------------------------------------------------------------------------
@ -25,18 +22,12 @@
//-----------------------------------------------------------------------------
struct Gameserver_Outgoing_Packet {
std::vector<uint8_t> data;
std::string data;
uint32 ip;
uint16 port;
};
struct Gameserver_Player_Info_t {
std::chrono::steady_clock::time_point join_time;
std::string name;
uint32 score;
};
class Steam_GameServer :
public ISteamGameServer005,
public ISteamGameServer008,
@ -56,7 +47,6 @@ public ISteamGameServer
bool logged_in = false;
bool call_servers_disconnected = false;
Gameserver server_data;
std::vector<std::pair<CSteamID, Gameserver_Player_Info_t>> players;
uint32 flags;
bool policy_response_called;
@ -69,9 +59,6 @@ public:
Steam_GameServer(class Settings *settings, class Networking *network, class SteamCallBacks *callbacks);
~Steam_GameServer();
std::vector<std::pair<CSteamID, Gameserver_Player_Info_t>>* get_players();
//
// Basic server data. These properties, if set, must be set before before calling LogOn. They
// may not be changed after logged in.
@ -291,6 +278,7 @@ public:
// connect to
uint32 GetPublicIP_old();
SteamIPAddress_t GetPublicIP();
void GetPublicIP_fix(SteamIPAddress_t *out);
// These are in GameSocketShare mode, where instead of ISteamGameServer creating its own
// socket to talk to the master server on, it lets the game use its socket to forward messages
@ -342,5 +330,3 @@ public:
//
void RunCallbacks();
};
#endif

View File

@ -15,9 +15,6 @@
License along with the Goldberg Emulator; if not, see
<http://www.gnu.org/licenses/>. */
#ifndef __INCLUDED_STEAM_MATCHMAKING__
#define __INCLUDED_STEAM_MATCHMAKING__
#include "base.h"
#define SEND_LOBBY_RATE 5.0
@ -1482,5 +1479,3 @@ void Callback(Common_Message *msg)
};
#endif

View File

@ -239,6 +239,7 @@ bool GetAchievement( const char *pchName, bool *pbAchieved )
try {
auto it = defined_achievements_find(pchName);
if (it == defined_achievements.end()) return false;
std::string pch_name = it->value("name", std::string());
auto ach = user_achievements.find(pch_name);
@ -261,6 +262,7 @@ bool SetAchievement( const char *pchName )
try {
auto it = defined_achievements_find(pchName);
if (it == defined_achievements.end()) return false;
std::string pch_name = it->value("name", std::string());
if (it != defined_achievements.end()) {
@ -288,6 +290,7 @@ bool ClearAchievement( const char *pchName )
try {
auto it = defined_achievements_find(pchName);
if (it == defined_achievements.end()) return false;
std::string pch_name = it->value("name", std::string());
if (it != defined_achievements.end()) {
@ -313,6 +316,7 @@ bool GetAchievementAndUnlockTime( const char *pchName, bool *pbAchieved, uint32
try {
auto it = defined_achievements_find(pchName);
if (it == defined_achievements.end()) return false;
std::string pch_name = it->value("name", std::string());
auto ach = user_achievements.find(pch_name);
@ -417,6 +421,8 @@ bool IndicateAchievementProgress( const char *pchName, uint32 nCurProgress, uint
try {
auto it = defined_achievements_find(pchName);
if (it == defined_achievements.end()) return false;
std::string pch_name = it->value("name", std::string());
auto ach = user_achievements.find(pch_name);

View File

@ -15,9 +15,6 @@
License along with the Goldberg Emulator; if not, see
<http://www.gnu.org/licenses/>. */
#ifndef __INCLUDED_STEAM_UTILS__
#define __INCLUDED_STEAM_UTILS__
#include "base.h"
#include "local_storage.h"
#include "../overlay_experimental/steam_overlay.h"
@ -409,5 +406,3 @@ ESteamIPv6ConnectivityState GetIPv6ConnectivityState( ESteamIPv6ConnectivityProt
}
};
#endif

View File

@ -189,8 +189,6 @@ public:
// behind NAT and you want to advertise its IP in a lobby for other clients to directly
// connect to
virtual uint32 GetPublicIP_old() = 0;
virtual SteamIPAddress_t GetPublicIP() = 0;
// These are in GameSocketShare mode, where instead of ISteamGameServer creating its own
// socket to talk to the master server on, it lets the game use its socket to forward messages

View File

@ -1011,7 +1011,7 @@ STEAMAPI_API EUserHasLicenseForAppResult SteamAPI_ISteamGameServer_UserHasLicens
STEAMAPI_API bool SteamAPI_ISteamGameServer_RequestUserGroupStatus( ISteamGameServer* self, uint64_steamid steamIDUser, uint64_steamid steamIDGroup );
STEAMAPI_API void SteamAPI_ISteamGameServer_GetGameplayStats( ISteamGameServer* self );
STEAMAPI_API SteamAPICall_t SteamAPI_ISteamGameServer_GetServerReputation( ISteamGameServer* self );
STEAMAPI_API SteamIPAddress_t SteamAPI_ISteamGameServer_GetPublicIP( ISteamGameServer* self );
//STEAMAPI_API SteamIPAddress_t SteamAPI_ISteamGameServer_GetPublicIP( ISteamGameServer* self );
STEAMAPI_API bool SteamAPI_ISteamGameServer_HandleIncomingPacket( ISteamGameServer* self, const void * pData, int cbData, uint32 srcIP, uint16 srcPort );
STEAMAPI_API int SteamAPI_ISteamGameServer_GetNextOutgoingPacket( ISteamGameServer* self, void * pOut, int cbMaxOut, uint32 * pNetAdr, uint16 * pPort );
STEAMAPI_API void SteamAPI_ISteamGameServer_EnableHeartbeats( ISteamGameServer* self, bool bActive );

BIN
steamclient.dll Normal file

Binary file not shown.

BIN
steamclient64.dll Normal file

Binary file not shown.