freebsd-ports/games/openttd/files/extra-patch-save-passwords
Alexey Dokuchaev f984e758ff - Update to version 1.5.0, fixup optional persistent password saving patch
- Replace references to PORTVERSION with DISTVERSION throughout Makefile to
  make testing of beta- and RC-versions easier (e.g., just set DISTVERSION=
  1.x.y-RCz and go)
2015-04-07 02:49:01 +00:00

137 lines
5.5 KiB
Text

--- 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
@@ -74,7 +74,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"
#include "../safeguards.h"
@@ -500,6 +500,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;
@@ -1684,6 +1685,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) {
@@ -1782,6 +1786,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( );
+ }
}
/**
@@ -2206,4 +2213,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
@@ -1111,6 +1111,10 @@
#ifdef ENABLE_NETWORK
if (_network_server) {
seprintf(_network_game_info.map_name, lastof(_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
@@ -3915,6 +3915,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