1
0
mirror of https://git.FreeBSD.org/ports.git synced 2025-01-11 07:22:22 +00:00

Add an optional patch to enable saving of passwords between server restarts.

Submitted by:	Alex Kushnaryov
This commit is contained in:
Alexey Dokuchaev 2014-11-16 12:35:54 +00:00
parent 309eda0978
commit b22bca432a
Notes: svn2git 2021-03-31 03:12:20 +00:00
svn path=/head/; revision=372636
2 changed files with 144 additions and 0 deletions

View File

@ -66,6 +66,10 @@ RUN_DEPENDS+= ${LOCALBASE}/share/${PORTNAME}/baseset/opengfx/opengfx.obg:${PORTS
${LOCALBASE}/share/${PORTNAME}/baseset/opensfx/opensfx.obs:${PORTSDIR}/games/opensfx
.endif
.if defined(WITH_SAVE_PASSWORDS)
EXTRA_PATCHES= ${FILESDIR}/extra-patch-save-passwords
.endif
.include <bsd.port.pre.mk>
pre-everything::
@ -81,6 +85,9 @@ pre-everything::
.if !defined(WITH_OPEN_GAME_FILES)
@${ECHO_MSG} "Define WITH_OPEN_GAME_FILES to install with libre graphics, music, and sounds"
.endif
.if !defined(WITH_SAVE_PASSWORDS)
@${ECHO_MSG} "Define WITH_SAVE_PASSWORDS to save passwords between server restarts"
.endif
post-patch:
@${REINPLACE_CMD} -e 's,/usr/local,${LOCALBASE},' ${WRKSRC}/config.lib

View File

@ -0,0 +1,137 @@
--- src/network/network_func.h 2014-10-21 21:36:31.000000000 +0300
+++ src/network/network_func.h 2014-11-09 21:37:49.000000000 +0200
@@ -73,7 +73,8 @@
bool NetworkServerStart();
void NetworkServerNewCompany(const Company *company, NetworkClientInfo *ci);
bool NetworkServerChangeClientName(ClientID client_id, const char *new_name);
-
+void NetworkSavePassword();
+void NetworkLoadPassword();
void NetworkServerDoMove(ClientID client_id, CompanyID company_id);
void NetworkServerSendRcon(ClientID client_id, TextColour colour_code, const char *string);
--- src/network/network_server.cpp 2014-10-21 21:36:31.000000000 +0300
+++ src/network/network_server.cpp 2014-11-09 21:37:49.000000000 +0200
@@ -32,7 +32,7 @@
#include "../core/pool_func.hpp"
#include "../core/random_func.hpp"
#include "../rev.h"
-
+#include "../fileio_func.h"
/* This file handles all the server-commands */
@@ -498,6 +498,7 @@
/* Reset 'lag' counters */
this->last_frame = this->last_frame_server = _frame_counter;
+ DEBUG( net, 1, "requesting GAME password" );
Packet *p = new Packet(PACKET_SERVER_NEED_GAME_PASSWORD);
this->SendPacket(p);
return NETWORK_RECV_STATUS_OKAY;
@@ -1696,6 +1697,9 @@
IConsolePrintF(CC_DEFAULT, "Auto-removed protection from company #%d", c->index + 1);
_network_company_states[c->index].months_empty = 0;
NetworkServerUpdateCompanyPassworded(c->index, false);
+ if (_settings_client.network.save_password) {
+ NetworkSavePassword( );
+ }
}
/* Is the company empty for autoclean_novehicles-months, and has no vehicles? */
if (_settings_client.network.autoclean_novehicles != 0 && _network_company_states[c->index].months_empty > _settings_client.network.autoclean_novehicles && vehicles_in_company[c->index] == 0) {
@@ -1794,6 +1798,9 @@
strecpy(_network_company_states[company_id].password, password, lastof(_network_company_states[company_id].password));
NetworkServerUpdateCompanyPassworded(company_id, !StrEmpty(_network_company_states[company_id].password));
+ if (_settings_client.network.save_password) {
+ NetworkSavePassword( );
+ }
}
/**
@@ -2218,4 +2225,47 @@
}
}
+void NetworkSavePassword( )
+{
+ static FILE *file_pointer;
+ char password_file_name[80];
+
+ seprintf( password_file_name, lastof(password_file_name), "%u.pwd", _settings_game.game_creation.generation_seed );
+ DEBUG( net, 0, "Saving companies password to %s", password_file_name );
+ file_pointer = FioFOpenFile( password_file_name, "wb", SAVE_DIR );
+
+ if (file_pointer != NULL) {
+ for( CompanyID l_company = (CompanyID)0; l_company < MAX_COMPANIES; l_company++ ) {
+ if (NetworkCompanyIsPassworded(l_company)) {
+ fwrite( _network_company_states[l_company].password, strlen(_network_company_states[l_company].password), 1, file_pointer);
+ }
+ fwrite( "\n", 1, 1, file_pointer );
+ }
+ fclose(file_pointer);
+ }
+}
+
+void NetworkLoadPassword( )
+{
+ static FILE *file_pointer;
+ char password[NETWORK_PASSWORD_LENGTH];
+ char password_file_name[80];
+
+ seprintf( password_file_name, lastof(password_file_name), "%u.pwd", _settings_game.game_creation.generation_seed );
+ file_pointer = FioFOpenFile( password_file_name, "rb", SAVE_DIR );
+ if (file_pointer != NULL) {
+ DEBUG( net, 0, "Loading password from %s", password_file_name );
+ for( CompanyID l_company = (CompanyID)0; l_company < MAX_COMPANIES; l_company++ ) {
+ fgets( password, sizeof( password), file_pointer);
+ if (strlen(password)>1) {
+ fseek( file_pointer, 1L, SEEK_CUR );
+ strecpy(_network_company_states[l_company].password, password, lastof(_network_company_states[l_company].password));
+ NetworkServerUpdateCompanyPassworded(l_company, !StrEmpty(_network_company_states[l_company].password));
+ }
+ }
+ } else {
+ DEBUG( net, 0, "Password file %s not found", password_file_name );
+ }
+}
+
#endif /* ENABLE_NETWORK */
--- src/openttd.cpp 2014-10-21 21:36:36.000000000 +0300
+++ src/openttd.cpp 2014-11-09 21:40:39.000000000 +0200
@@ -1101,6 +1101,10 @@
#ifdef ENABLE_NETWORK
if (_network_server) {
snprintf(_network_game_info.map_name, lengthof(_network_game_info.map_name), "%s (Loaded game)", _file_to_saveload.title);
+ // Try to load password
+ if ( _settings_client.network.save_password ) {
+ NetworkLoadPassword( );
+ }
}
#endif /* ENABLE_NETWORK */
}
--- src/settings_type.h 2014-10-21 21:36:35.000000000 +0300
+++ src/settings_type.h 2014-11-09 21:37:49.000000000 +0200
@@ -266,6 +266,7 @@
char last_host[NETWORK_HOSTNAME_LENGTH]; ///< IP address of the last joined server
uint16 last_port; ///< port of the last joined server
bool no_http_content_downloads; ///< do not do content downloads over HTTP
+ bool save_password; ///< If password file is used
#else /* ENABLE_NETWORK */
#endif
};
--- src/table/settings.ini 2014-10-21 21:36:21.000000000 +0300
+++ src/table/settings.ini 2014-11-09 21:37:49.000000000 +0200
@@ -3874,6 +3874,12 @@
def = false
cat = SC_EXPERT
+[SDTC_BOOL]
+ifdef = ENABLE_NETWORK
+var = network.save_password
+flags = SLF_NOT_IN_SAVE | SLF_NO_NETWORK_SYNC
+def = false
+
; Since the network code (CmdChangeSetting and friends) use the index in this array to decide
; which setting the server is talking about all conditional compilation of this array must be at the
; end. This isn't really the best solution, the settings the server can tell the client about should