mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2025-12-22 07:13:07 +01:00
Decouple network version from OpenRCT2 version
This allows to present a different version of network stream than just OpenRCT2 version, as we can possibly have breaking changes to network in one release cycle. This commit also adds easy way of identification which hosts are running which versions, by showing a tooltip when hovering mouse cursor over the network compatibility icon. Client's own version is displayed as well.
This commit is contained in:
@@ -4018,6 +4018,9 @@ STR_5713 :Kick Player
|
||||
STR_5714 :Show options window
|
||||
STR_5715 :New Game
|
||||
STR_5716 :Not allowed in multiplayer mode
|
||||
# For identifying client network version in server list window
|
||||
STR_5717 :Network version: {STRING}
|
||||
STR_5718 :{SMALLFONT}{BLACK}Network version: {STRING}
|
||||
|
||||
#############
|
||||
# Scenarios #
|
||||
|
||||
@@ -2310,6 +2310,9 @@ enum {
|
||||
|
||||
STR_NOT_ALLOWED_IN_MULTIPLAYER = 5716,
|
||||
|
||||
STR_NETWORK_VERSION = 5717,
|
||||
STR_NETWORK_VERSION_TIP = 5718,
|
||||
|
||||
// Have to include resource strings (from scenarios and objects) for the time being now that language is partially working
|
||||
STR_COUNT = 32768
|
||||
};
|
||||
|
||||
@@ -1253,7 +1253,7 @@ void Network::Client_Send_AUTH(const char* name, const char* password)
|
||||
{
|
||||
std::unique_ptr<NetworkPacket> packet = std::move(NetworkPacket::Allocate());
|
||||
*packet << (uint32)NETWORK_COMMAND_AUTH;
|
||||
packet->WriteString(OPENRCT2_VERSION);
|
||||
packet->WriteString(NETWORK_STREAM_ID);
|
||||
packet->WriteString(name);
|
||||
packet->WriteString(password);
|
||||
server_connection.authstatus = NETWORK_AUTH_REQUESTED;
|
||||
@@ -1411,7 +1411,7 @@ void Network::Server_Send_GAMEINFO(NetworkConnection& connection)
|
||||
json_t* obj = json_object();
|
||||
json_object_set_new(obj, "name", json_string(gConfigNetwork.server_name));
|
||||
json_object_set_new(obj, "requiresPassword", json_boolean(password.size() > 0));
|
||||
json_object_set_new(obj, "version", json_string(OPENRCT2_VERSION));
|
||||
json_object_set_new(obj, "version", json_string(NETWORK_STREAM_ID));
|
||||
json_object_set_new(obj, "players", json_integer(player_list.size()));
|
||||
json_object_set_new(obj, "maxPlayers", json_integer(gConfigNetwork.maxplayers));
|
||||
json_object_set_new(obj, "description", json_string(gConfigNetwork.server_description));
|
||||
@@ -1629,7 +1629,7 @@ void Network::Server_Handle_AUTH(NetworkConnection& connection, NetworkPacket& p
|
||||
const char* gameversion = packet.ReadString();
|
||||
const char* name = packet.ReadString();
|
||||
const char* password = packet.ReadString();
|
||||
if (!gameversion || strcmp(gameversion, OPENRCT2_VERSION) != 0) {
|
||||
if (!gameversion || strcmp(gameversion, NETWORK_STREAM_ID) != 0) {
|
||||
connection.authstatus = NETWORK_AUTH_BADVERSION;
|
||||
} else
|
||||
if (!name) {
|
||||
|
||||
@@ -65,6 +65,12 @@ extern "C" {
|
||||
|
||||
#ifndef DISABLE_NETWORK
|
||||
|
||||
// This define specifies which version of network stream current build uses.
|
||||
// It is used for making sure only compatible builds get connected, even within
|
||||
// single OpenRCT2 version.
|
||||
#define NETWORK_STREAM_VERSION "0"
|
||||
#define NETWORK_STREAM_ID OPENRCT2_VERSION "-" NETWORK_STREAM_VERSION
|
||||
|
||||
#ifdef __WINDOWS__
|
||||
#include <winsock2.h>
|
||||
#include <ws2tcpip.h>
|
||||
@@ -402,6 +408,8 @@ private:
|
||||
};
|
||||
|
||||
#endif // __cplusplus
|
||||
#else /* DISABLE_NETWORK */
|
||||
#define NETWORK_STREAM_ID "Multiplayer disabled"
|
||||
#endif /* DISABLE_NETWORK */
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
#include "../network/network.h"
|
||||
#include "../sprites.h"
|
||||
#include "../windows/dropdown.h"
|
||||
#include "../windows/tooltip.h"
|
||||
#include "../util/util.h"
|
||||
#include "error.h"
|
||||
|
||||
@@ -289,6 +290,8 @@ static void window_server_list_scroll_mousedown(rct_window *w, int scrollIndex,
|
||||
window_dropdown_show_text(ddx, ddy, 0, COLOUR_GREY, 0, 2);
|
||||
}
|
||||
|
||||
char *gVersion = NULL;
|
||||
|
||||
static void window_server_list_scroll_mouseover(rct_window *w, int scrollIndex, int x, int y)
|
||||
{
|
||||
// Item
|
||||
@@ -312,9 +315,18 @@ static void window_server_list_scroll_mouseover(rct_window *w, int scrollIndex,
|
||||
}
|
||||
}
|
||||
|
||||
int width = w->widgets[WIDX_LIST].right - w->widgets[WIDX_LIST].left;
|
||||
int right = width - 3 - 14 - 10;
|
||||
if (x < right)
|
||||
{
|
||||
w->widgets[WIDX_LIST].tooltip = STR_NONE;
|
||||
window_tooltip_close();
|
||||
}
|
||||
|
||||
if (w->selected_list_item != index || _hoverButtonIndex != hoverButtonIndex) {
|
||||
w->selected_list_item = index;
|
||||
_hoverButtonIndex = hoverButtonIndex;
|
||||
window_tooltip_close();
|
||||
window_invalidate(w);
|
||||
}
|
||||
}
|
||||
@@ -354,6 +366,7 @@ static void window_server_list_textinput(rct_window *w, int widgetIndex, char *t
|
||||
|
||||
static void window_server_list_invalidate(rct_window *w)
|
||||
{
|
||||
RCT2_GLOBAL(RCT2_ADDRESS_COMMON_FORMAT_ARGS, char *) = gVersion;
|
||||
window_server_list_widgets[WIDX_BACKGROUND].right = w->width - 1;
|
||||
window_server_list_widgets[WIDX_BACKGROUND].bottom = w->height - 1;
|
||||
window_server_list_widgets[WIDX_TITLE].right = w->width - 2;
|
||||
@@ -379,6 +392,8 @@ static void window_server_list_paint(rct_window *w, rct_drawpixelinfo *dpi)
|
||||
window_draw_widgets(w, dpi);
|
||||
|
||||
gfx_draw_string_left(dpi, STR_PLAYER_NAME, NULL, COLOUR_WHITE, w->x + 6, w->y + w->widgets[WIDX_PLAYER_NAME_INPUT].top);
|
||||
char *version = NETWORK_STREAM_ID;
|
||||
gfx_draw_string_left(dpi, STR_NETWORK_VERSION, (void*)&version, COLOUR_WHITE, w->x + 324, w->y + w->widgets[WIDX_START_SERVER].top);
|
||||
}
|
||||
|
||||
static void window_server_list_scrollpaint(rct_window *w, rct_drawpixelinfo *dpi, int scrollIndex)
|
||||
@@ -392,6 +407,7 @@ static void window_server_list_scrollpaint(rct_window *w, rct_drawpixelinfo *dpi
|
||||
int width = w->widgets[WIDX_LIST].right - w->widgets[WIDX_LIST].left;
|
||||
|
||||
int y = 0;
|
||||
w->widgets[WIDX_LIST].tooltip = STR_NONE;
|
||||
for (int i = 0; i < w->no_list_items; i++) {
|
||||
if (y >= dpi->y + dpi->height) continue;
|
||||
// if (y + ITEM_HEIGHT < dpi->y) continue;
|
||||
@@ -402,6 +418,8 @@ static void window_server_list_scrollpaint(rct_window *w, rct_drawpixelinfo *dpi
|
||||
// Draw hover highlight
|
||||
if (highlighted) {
|
||||
gfx_fill_rect(dpi, 0, y, width, y + ITEM_HEIGHT, 0x02000031);
|
||||
gVersion = serverDetails->version;
|
||||
w->widgets[WIDX_LIST].tooltip = STR_NETWORK_VERSION_TIP;
|
||||
}
|
||||
|
||||
int colour = w->colours[1];
|
||||
@@ -426,7 +444,7 @@ static void window_server_list_scrollpaint(rct_window *w, rct_drawpixelinfo *dpi
|
||||
compatibilitySpriteId = SPR_G2_RCT1_CLOSE_BUTTON_0;
|
||||
} else {
|
||||
// Server online... check version
|
||||
bool correctVersion = strcmp(serverDetails->version, OPENRCT2_VERSION) == 0;
|
||||
bool correctVersion = strcmp(serverDetails->version, NETWORK_STREAM_ID) == 0;
|
||||
compatibilitySpriteId = correctVersion ? SPR_G2_RCT1_OPEN_BUTTON_2 : SPR_G2_RCT1_CLOSE_BUTTON_2;
|
||||
}
|
||||
gfx_draw_sprite(dpi, compatibilitySpriteId, right, y + 1, 0);
|
||||
|
||||
Reference in New Issue
Block a user