mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2025-12-24 00:03:11 +01:00
password prompt for client
This commit is contained in:
@@ -3906,6 +3906,8 @@ STR_5564 :Insert Corrupt Element
|
|||||||
STR_5565 :{SMALLFONT}{BLACK}Inserts a corrupt map element at top of tile. This will hide any element above the corrupt element.
|
STR_5565 :{SMALLFONT}{BLACK}Inserts a corrupt map element at top of tile. This will hide any element above the corrupt element.
|
||||||
STR_5566 :Password:
|
STR_5566 :Password:
|
||||||
STR_5567 :Advertise
|
STR_5567 :Advertise
|
||||||
|
STR_5568 :Password Required
|
||||||
|
STR_5569 :This server requires a password
|
||||||
|
|
||||||
#####################
|
#####################
|
||||||
# Rides/attractions #
|
# Rides/attractions #
|
||||||
|
|||||||
@@ -629,6 +629,7 @@ void window_cheats_open();
|
|||||||
void window_player_list_open();
|
void window_player_list_open();
|
||||||
void window_network_status_open(const char* text);
|
void window_network_status_open(const char* text);
|
||||||
void window_network_status_close();
|
void window_network_status_close();
|
||||||
|
void window_network_status_open_password();
|
||||||
void window_server_list_open();
|
void window_server_list_open();
|
||||||
void window_server_start_open();
|
void window_server_start_open();
|
||||||
|
|
||||||
|
|||||||
@@ -2156,6 +2156,8 @@ enum {
|
|||||||
|
|
||||||
STR_PASSWORD = 5566,
|
STR_PASSWORD = 5566,
|
||||||
STR_ADVERTISE = 5567,
|
STR_ADVERTISE = 5567,
|
||||||
|
STR_PASSWORD_REQUIRED = 5568,
|
||||||
|
STR_PASSWORD_REQUIRED_DESC = 5569,
|
||||||
|
|
||||||
// Have to include resource strings (from scenarios and objects) for the time being now that language is partially working
|
// Have to include resource strings (from scenarios and objects) for the time being now that language is partially working
|
||||||
STR_COUNT = 32768
|
STR_COUNT = 32768
|
||||||
|
|||||||
@@ -779,6 +779,21 @@ void Network::Client_Send_AUTH(const char* gameversion, const char* name, const
|
|||||||
server_connection.QueuePacket(std::move(packet));
|
server_connection.QueuePacket(std::move(packet));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Network::Server_Send_AUTH(NetworkConnection& connection)
|
||||||
|
{
|
||||||
|
uint8 new_playerid = 0;
|
||||||
|
if (connection.player) {
|
||||||
|
new_playerid = connection.player->id;
|
||||||
|
}
|
||||||
|
std::unique_ptr<NetworkPacket> packet = std::move(NetworkPacket::Allocate());
|
||||||
|
*packet << (uint32)NETWORK_COMMAND_AUTH << (uint32)connection.authstatus << (uint8)new_playerid;
|
||||||
|
connection.QueuePacket(std::move(packet));
|
||||||
|
if (connection.authstatus != NETWORK_AUTH_OK && connection.authstatus != NETWORK_AUTH_REQUIREPASSWORD) {
|
||||||
|
shutdown(connection.socket, SHUT_RD);
|
||||||
|
connection.SendQueuedPackets();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Network::Server_Send_MAP(NetworkConnection* connection)
|
void Network::Server_Send_MAP(NetworkConnection* connection)
|
||||||
{
|
{
|
||||||
int buffersize = 0x600000;
|
int buffersize = 0x600000;
|
||||||
@@ -1042,6 +1057,9 @@ int Network::Client_Handle_AUTH(NetworkConnection& connection, NetworkPacket& pa
|
|||||||
connection.last_disconnect_reason = "Bad Password";
|
connection.last_disconnect_reason = "Bad Password";
|
||||||
shutdown(connection.socket, SHUT_RDWR);
|
shutdown(connection.socket, SHUT_RDWR);
|
||||||
break;
|
break;
|
||||||
|
case NETWORK_AUTH_REQUIREPASSWORD:
|
||||||
|
window_network_status_open_password();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@@ -1052,21 +1070,22 @@ int Network::Server_Handle_AUTH(NetworkConnection& connection, NetworkPacket& pa
|
|||||||
const char* gameversion = packet.ReadString();
|
const char* gameversion = packet.ReadString();
|
||||||
const char* name = packet.ReadString();
|
const char* name = packet.ReadString();
|
||||||
const char* password = packet.ReadString();
|
const char* password = packet.ReadString();
|
||||||
uint8 playerid = 0;
|
|
||||||
if (!gameversion || strcmp(gameversion, OPENRCT2_VERSION) != 0) {
|
if (!gameversion || strcmp(gameversion, OPENRCT2_VERSION) != 0) {
|
||||||
connection.authstatus = NETWORK_AUTH_BADVERSION;
|
connection.authstatus = NETWORK_AUTH_BADVERSION;
|
||||||
} else
|
} else
|
||||||
if (!name) {
|
if (!name) {
|
||||||
connection.authstatus = NETWORK_AUTH_BADNAME;
|
connection.authstatus = NETWORK_AUTH_BADNAME;
|
||||||
} else
|
} else
|
||||||
if (!password || strcmp(password, Network::password) != 0) {
|
if (!password || strlen(password) == 0) {
|
||||||
|
connection.authstatus = NETWORK_AUTH_REQUIREPASSWORD;
|
||||||
|
} else
|
||||||
|
if (strcmp(password, Network::password) != 0) {
|
||||||
connection.authstatus = NETWORK_AUTH_BADPASSWORD;
|
connection.authstatus = NETWORK_AUTH_BADPASSWORD;
|
||||||
} else {
|
} else {
|
||||||
connection.authstatus = NETWORK_AUTH_OK;
|
connection.authstatus = NETWORK_AUTH_OK;
|
||||||
NetworkPlayer* player = AddPlayer(name);
|
NetworkPlayer* player = AddPlayer(name);
|
||||||
connection.player = player;
|
connection.player = player;
|
||||||
if (player) {
|
if (player) {
|
||||||
playerid = player->id;
|
|
||||||
char text[256];
|
char text[256];
|
||||||
char* lineCh = text;
|
char* lineCh = text;
|
||||||
lineCh = utf8_write_codepoint(lineCh, FORMAT_OUTLINE);
|
lineCh = utf8_write_codepoint(lineCh, FORMAT_OUTLINE);
|
||||||
@@ -1077,13 +1096,7 @@ int Network::Server_Handle_AUTH(NetworkConnection& connection, NetworkPacket& pa
|
|||||||
Server_Send_MAP(&connection);
|
Server_Send_MAP(&connection);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
std::unique_ptr<NetworkPacket> responsepacket = std::move(NetworkPacket::Allocate());
|
Server_Send_AUTH(connection);
|
||||||
*responsepacket << (uint32)NETWORK_COMMAND_AUTH << (uint32)connection.authstatus << (uint8)playerid;
|
|
||||||
connection.QueuePacket(std::move(responsepacket));
|
|
||||||
if (connection.authstatus != NETWORK_AUTH_OK) {
|
|
||||||
shutdown(connection.socket, SHUT_RD);
|
|
||||||
connection.SendQueuedPackets();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@@ -1356,6 +1369,11 @@ void network_send_gamecmd(uint32 eax, uint32 ebx, uint32 ecx, uint32 edx, uint32
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void network_send_password(const char* password)
|
||||||
|
{
|
||||||
|
gNetwork.Client_Send_AUTH(OPENRCT2_VERSION, gConfigNetwork.player_name, password);
|
||||||
|
}
|
||||||
|
|
||||||
void network_kick_player(int playerId)
|
void network_kick_player(int playerId)
|
||||||
{
|
{
|
||||||
gNetwork.KickPlayer(playerId);
|
gNetwork.KickPlayer(playerId);
|
||||||
|
|||||||
@@ -37,7 +37,8 @@ enum {
|
|||||||
NETWORK_AUTH_OK,
|
NETWORK_AUTH_OK,
|
||||||
NETWORK_AUTH_BADVERSION,
|
NETWORK_AUTH_BADVERSION,
|
||||||
NETWORK_AUTH_BADNAME,
|
NETWORK_AUTH_BADNAME,
|
||||||
NETWORK_AUTH_BADPASSWORD
|
NETWORK_AUTH_BADPASSWORD,
|
||||||
|
NETWORK_AUTH_REQUIREPASSWORD
|
||||||
};
|
};
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
@@ -217,6 +218,7 @@ public:
|
|||||||
void SetPassword(const char* password);
|
void SetPassword(const char* password);
|
||||||
|
|
||||||
void Client_Send_AUTH(const char* gameversion, const char* name, const char* password);
|
void Client_Send_AUTH(const char* gameversion, const char* name, const char* password);
|
||||||
|
void Server_Send_AUTH(NetworkConnection& connection);
|
||||||
void Server_Send_MAP(NetworkConnection* connection = nullptr);
|
void Server_Send_MAP(NetworkConnection* connection = nullptr);
|
||||||
void Client_Send_CHAT(const char* text);
|
void Client_Send_CHAT(const char* text);
|
||||||
void Server_Send_CHAT(const char* text);
|
void Server_Send_CHAT(const char* text);
|
||||||
@@ -318,6 +320,7 @@ int network_get_player_id(unsigned int index);
|
|||||||
void network_send_map();
|
void network_send_map();
|
||||||
void network_send_chat(const char* text);
|
void network_send_chat(const char* text);
|
||||||
void network_send_gamecmd(uint32 eax, uint32 ebx, uint32 ecx, uint32 edx, uint32 esi, uint32 edi, uint32 ebp, uint8 callback);
|
void network_send_gamecmd(uint32 eax, uint32 ebx, uint32 ecx, uint32 edx, uint32 esi, uint32 edi, uint32 ebp, uint8 callback);
|
||||||
|
void network_send_password(const char* password);
|
||||||
|
|
||||||
void network_kick_player(int playerId);
|
void network_kick_player(int playerId);
|
||||||
void network_set_password(const char* password);
|
void network_set_password(const char* password);
|
||||||
|
|||||||
@@ -25,10 +25,13 @@
|
|||||||
#include "../util/util.h"
|
#include "../util/util.h"
|
||||||
#include "../network/network.h"
|
#include "../network/network.h"
|
||||||
|
|
||||||
|
char _password[33];
|
||||||
|
|
||||||
enum WINDOW_NETWORK_STATUS_WIDGET_IDX {
|
enum WINDOW_NETWORK_STATUS_WIDGET_IDX {
|
||||||
WIDX_BACKGROUND,
|
WIDX_BACKGROUND,
|
||||||
WIDX_TITLE,
|
WIDX_TITLE,
|
||||||
WIDX_CLOSE,
|
WIDX_CLOSE,
|
||||||
|
WIDX_PASSWORD
|
||||||
};
|
};
|
||||||
|
|
||||||
static rct_widget window_network_status_widgets[] = {
|
static rct_widget window_network_status_widgets[] = {
|
||||||
@@ -42,6 +45,7 @@ static char window_network_status_text[1024];
|
|||||||
|
|
||||||
static void window_network_status_mouseup(rct_window *w, int widgetIndex);
|
static void window_network_status_mouseup(rct_window *w, int widgetIndex);
|
||||||
static void window_network_status_update(rct_window *w);
|
static void window_network_status_update(rct_window *w);
|
||||||
|
static void window_network_status_textinput(rct_window *w, int widgetIndex, char *text);
|
||||||
static void window_network_status_invalidate(rct_window *w);
|
static void window_network_status_invalidate(rct_window *w);
|
||||||
static void window_network_status_paint(rct_window *w, rct_drawpixelinfo *dpi);
|
static void window_network_status_paint(rct_window *w, rct_drawpixelinfo *dpi);
|
||||||
|
|
||||||
@@ -65,7 +69,7 @@ static rct_window_event_list window_network_status_events = {
|
|||||||
NULL,
|
NULL,
|
||||||
NULL,
|
NULL,
|
||||||
NULL,
|
NULL,
|
||||||
NULL,
|
window_network_status_textinput,
|
||||||
NULL,
|
NULL,
|
||||||
NULL,
|
NULL,
|
||||||
NULL,
|
NULL,
|
||||||
@@ -112,6 +116,16 @@ void window_network_status_close()
|
|||||||
window_close_by_class(WC_NETWORK_STATUS);
|
window_close_by_class(WC_NETWORK_STATUS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void window_network_status_open_password()
|
||||||
|
{
|
||||||
|
rct_window* window;
|
||||||
|
window = window_bring_to_front_by_class(WC_NETWORK_STATUS);
|
||||||
|
if (window == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
|
window_text_input_raw_open(window, WIDX_PASSWORD, STR_PASSWORD_REQUIRED, STR_PASSWORD_REQUIRED_DESC, _password, 32);
|
||||||
|
}
|
||||||
|
|
||||||
static void window_network_status_mouseup(rct_window *w, int widgetIndex)
|
static void window_network_status_mouseup(rct_window *w, int widgetIndex)
|
||||||
{
|
{
|
||||||
switch (widgetIndex) {
|
switch (widgetIndex) {
|
||||||
@@ -126,6 +140,18 @@ static void window_network_status_update(rct_window *w)
|
|||||||
widget_invalidate(w, WIDX_BACKGROUND);
|
widget_invalidate(w, WIDX_BACKGROUND);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void window_network_status_textinput(rct_window *w, int widgetIndex, char *text)
|
||||||
|
{
|
||||||
|
strcpy(_password, "");
|
||||||
|
switch (widgetIndex) {
|
||||||
|
case WIDX_PASSWORD:
|
||||||
|
if (text != NULL)
|
||||||
|
safe_strncpy(_password, text, sizeof(_password));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
network_send_password(_password);
|
||||||
|
}
|
||||||
|
|
||||||
static void window_network_status_invalidate(rct_window *w)
|
static void window_network_status_invalidate(rct_window *w)
|
||||||
{
|
{
|
||||||
window_network_status_widgets[WIDX_BACKGROUND].right = w->width - 1;
|
window_network_status_widgets[WIDX_BACKGROUND].right = w->width - 1;
|
||||||
|
|||||||
Reference in New Issue
Block a user