Compare commits

...

5 Commits

Author SHA1 Message Date
Mr_Goldberg c231c87312
Allow message sending on not yet connected networking sockets. 2022-09-03 04:29:08 -04:00
Mr_Goldberg 373801b3a4
Fix some UDP packet size issues 2022-09-03 04:21:08 -04:00
Mr_Goldberg 05e2c3bef0
Implement TCP_NODELAY, thanks #209 2022-09-03 04:20:03 -04:00
Mr_Goldberg b1986dfe38
Overlay chat window improvements. 2022-09-03 04:13:58 -04:00
Mr_Goldberg 5d3bbc8529
Fix lobby_connect.exe not building in CI. 2022-09-03 04:13:25 -04:00
5 changed files with 27 additions and 7 deletions

View File

@ -69,6 +69,9 @@ build_windows:
- 7za x protobuf_x86-windows-static.7z -oprotobuf_x86-windows-static - 7za x protobuf_x86-windows-static.7z -oprotobuf_x86-windows-static
- 7za x protobuf_x64-windows-static.7z -oprotobuf_x64-windows-static - 7za x protobuf_x64-windows-static.7z -oprotobuf_x64-windows-static
- 7za x sdk_standalone.7z -osdk_standalone - 7za x sdk_standalone.7z -osdk_standalone
- DLL_FILES="$(ls dll/*.cpp | tr "\n" " ")"; sed "s|dll/\*.cpp|$DLL_FILES|g" -i *.bat
- DLL_FILES="$(ls dll/*.proto | tr "\n" " " | sed "s/.proto/.pb.cc/g")"; sed "s|dll/\*.cc|$DLL_FILES|g" -i *.bat
- sed "s| /MP12 | /MP4 |g" -i *.bat
- python generate_build_win_bat.py - python generate_build_win_bat.py
- export WINEDEBUG=-all - export WINEDEBUG=-all
- wine cmd /c build_win_release_test.bat - wine cmd /c build_win_release_test.bat

View File

@ -117,6 +117,7 @@ inline void reset_LastError()
#include <sys/time.h> #include <sys/time.h>
#include <netinet/in.h> #include <netinet/in.h>
#include <netinet/tcp.h>
#include <linux/netdevice.h> #include <linux/netdevice.h>
#include <fcntl.h> #include <fcntl.h>

View File

@ -27,6 +27,8 @@ static uint32_t upper_range_ips[MAX_BROADCASTS];
#define HEARTBEAT_TIMEOUT 20.0 #define HEARTBEAT_TIMEOUT 20.0
#define USER_TIMEOUT 20.0 #define USER_TIMEOUT 20.0
#define MAX_UDP_SIZE 16384
#if defined(STEAM_WIN32) #if defined(STEAM_WIN32)
//windows xp support //windows xp support
@ -215,6 +217,11 @@ static int set_socket_nonblocking(sock_t sock)
#endif #endif
} }
static bool disable_nagle(sock_t sock)
{
int set = 1;
return (setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, (char *)&set, sizeof(set)) == 0);
}
static void kill_socket(sock_t sock) static void kill_socket(sock_t sock)
{ {
@ -920,7 +927,7 @@ void Networking::Run()
} }
IP_PORT ip_port; IP_PORT ip_port;
char data[2048]; char data[MAX_UDP_SIZE];
int len; int len;
PRINT_DEBUG("RECV UDP\n"); PRINT_DEBUG("RECV UDP\n");
@ -978,6 +985,7 @@ void Networking::Run()
struct TCP_Socket socket; struct TCP_Socket socket;
if (set_socket_nonblocking(sock)) { if (set_socket_nonblocking(sock)) {
PRINT_DEBUG("SET NONBLOCK\n"); PRINT_DEBUG("SET NONBLOCK\n");
disable_nagle(sock);
socket.sock = sock; socket.sock = sock;
socket.received_data = true; socket.received_data = true;
socket.last_heartbeat_received = std::chrono::high_resolution_clock::now(); socket.last_heartbeat_received = std::chrono::high_resolution_clock::now();
@ -1031,6 +1039,7 @@ void Networking::Run()
sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (is_socket_valid(sock) && set_socket_nonblocking(sock)) { if (is_socket_valid(sock) && set_socket_nonblocking(sock)) {
PRINT_DEBUG("NEW SOCKET %u %u\n", sock, conn.tcp_socket_outgoing.sock); PRINT_DEBUG("NEW SOCKET %u %u\n", sock, conn.tcp_socket_outgoing.sock);
disable_nagle(sock);
connect_socket(sock, conn.tcp_ip_port); connect_socket(sock, conn.tcp_ip_port);
conn.tcp_socket_outgoing.sock = sock; conn.tcp_socket_outgoing.sock = sock;
conn.tcp_socket_outgoing.last_heartbeat_received = std::chrono::high_resolution_clock::now(); conn.tcp_socket_outgoing.last_heartbeat_received = std::chrono::high_resolution_clock::now();
@ -1171,7 +1180,7 @@ bool Networking::sendTo(Common_Message *msg, bool reliable, Connection *conn)
if (!enabled) return false; if (!enabled) return false;
size_t size = msg->ByteSizeLong(); size_t size = msg->ByteSizeLong();
if (size >= 65000) reliable = true; //too big for UDP if (size >= MAX_UDP_SIZE) reliable = true; //too big for UDP
bool ret = false; bool ret = false;
CSteamID dest_id((uint64)msg->dest_id()); CSteamID dest_id((uint64)msg->dest_id());

View File

@ -752,7 +752,7 @@ EResult SendMessageToConnection( HSteamNetConnection hConn, const void *pData, u
if (connect_socket == s->connect_sockets.end()) return k_EResultInvalidParam; if (connect_socket == s->connect_sockets.end()) return k_EResultInvalidParam;
if (connect_socket->second.status == CONNECT_SOCKET_CLOSED) return k_EResultNoConnection; if (connect_socket->second.status == CONNECT_SOCKET_CLOSED) return k_EResultNoConnection;
if (connect_socket->second.status == CONNECT_SOCKET_TIMEDOUT) return k_EResultNoConnection; if (connect_socket->second.status == CONNECT_SOCKET_TIMEDOUT) return k_EResultNoConnection;
if (connect_socket->second.status != CONNECT_SOCKET_CONNECTED) return k_EResultInvalidState; if (connect_socket->second.status != CONNECT_SOCKET_CONNECTED && connect_socket->second.status != CONNECT_SOCKET_CONNECTING) return k_EResultInvalidState;
Common_Message msg; Common_Message msg;
msg.set_source_id(connect_socket->second.created_by.ConvertToUint64()); msg.set_source_id(connect_socket->second.created_by.ConvertToUint64());
@ -2084,10 +2084,16 @@ void Callback(Common_Message *msg)
} else if (msg->networking_sockets().type() == Networking_Sockets::DATA) { } else if (msg->networking_sockets().type() == Networking_Sockets::DATA) {
auto connect_socket = s->connect_sockets.find(msg->networking_sockets().connection_id()); auto connect_socket = s->connect_sockets.find(msg->networking_sockets().connection_id());
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()); connect_socket->second.data.push(msg->networking_sockets());
} }
} else {
connect_socket = std::find_if(s->connect_sockets.begin(), s->connect_sockets.end(), [msg](const auto &in) {return in.second.remote_identity.GetSteamID64() == msg->source_id() && (in.second.status == CONNECT_SOCKET_NOT_ACCEPTED || in.second.status == CONNECT_SOCKET_CONNECTED) && in.second.remote_id == msg->networking_sockets().connection_id_from();});
if (connect_socket != s->connect_sockets.end()) {
PRINT_DEBUG("Steam_Networking_Sockets: got data len %u on not accepted connection %u\n", msg->networking_sockets().data().size(), connect_socket->first);
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) {
auto connect_socket = s->connect_sockets.find(msg->networking_sockets().connection_id()); auto connect_socket = s->connect_sockets.find(msg->networking_sockets().connection_id());

View File

@ -568,7 +568,7 @@ void Steam_Overlay::BuildFriendWindow(Friend const& frd, friend_window_state& st
} }
} }
ImGui::InputTextMultiline("##chat_history", &state.chat_history[0], state.chat_history.length(), { -1.0f, 0 }, ImGuiInputTextFlags_ReadOnly); ImGui::InputTextMultiline("##chat_history", &state.chat_history[0], state.chat_history.length(), { -1.0f, -2.0f * ImGui::GetFontSize() }, ImGuiInputTextFlags_ReadOnly);
// TODO: Fix the layout of the chat line + send button. // TODO: Fix the layout of the chat line + send button.
// It should be like this: chat input should fill the window size minus send button size (button size is fixed) // It should be like this: chat input should fill the window size minus send button size (button size is fixed)
// |------------------------------| // |------------------------------|
@ -597,6 +597,7 @@ void Steam_Overlay::BuildFriendWindow(Friend const& frd, friend_window_state& st
if (ImGui::InputText("##chat_line", state.chat_input, max_chat_len, ImGuiInputTextFlags_EnterReturnsTrue)) if (ImGui::InputText("##chat_line", state.chat_input, max_chat_len, ImGuiInputTextFlags_EnterReturnsTrue))
{ {
send_chat_msg = true; send_chat_msg = true;
ImGui::SetKeyboardFocusHere(-1);
} }
ImGui::PopItemWidth(); ImGui::PopItemWidth();
@ -987,7 +988,7 @@ void Steam_Overlay::Callback(Common_Message *msg)
{ {
Steam_Messages const& steam_message = msg->steam_messages(); Steam_Messages const& steam_message = msg->steam_messages();
// Change color to cyan for friend // Change color to cyan for friend
friend_info->second.chat_history.append(steam_message.message()).append("\n", 1); friend_info->second.chat_history.append(friend_info->first.name() + ": " + steam_message.message()).append("\n", 1);
if (!(friend_info->second.window_state & window_state_show)) if (!(friend_info->second.window_state & window_state_show))
{ {
friend_info->second.window_state |= window_state_need_attention; friend_info->second.window_state |= window_state_need_attention;
@ -1113,7 +1114,7 @@ void Steam_Overlay::RunCallbacks()
msg.set_dest_id(friend_id); msg.set_dest_id(friend_id);
network->sendTo(&msg, true); network->sendTo(&msg, true);
friend_info->second.chat_history.append(input).append("\n", 1); friend_info->second.chat_history.append(get_steam_client()->settings_client->get_local_name()).append(": ").append(input).append("\n", 1);
} }
*input = 0; // Reset the input field *input = 0; // Reset the input field
friend_info->second.window_state &= ~window_state_send_message; friend_info->second.window_state &= ~window_state_send_message;