aboutsummaryrefslogtreecommitdiff
path: root/games/openttd
diff options
context:
space:
mode:
authorAlexey Dokuchaev <danfe@FreeBSD.org>2014-11-16 12:35:54 +0000
committerAlexey Dokuchaev <danfe@FreeBSD.org>2014-11-16 12:35:54 +0000
commitb22bca432ad7945b95c6e77d72e4614c252de522 (patch)
tree1fbf72fcad4caef9ad00fb8b43fac9c957077fb1 /games/openttd
parent309eda097829f10ade0823ffa228036ff2f2dff5 (diff)
Notes
Diffstat (limited to 'games/openttd')
-rw-r--r--games/openttd/Makefile7
-rw-r--r--games/openttd/files/extra-patch-save-passwords137
2 files changed, 144 insertions, 0 deletions
diff --git a/games/openttd/Makefile b/games/openttd/Makefile
index 2ea8bb2e724a..eb3cee2acc18 100644
--- a/games/openttd/Makefile
+++ b/games/openttd/Makefile
@@ -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
diff --git a/games/openttd/files/extra-patch-save-passwords b/games/openttd/files/extra-patch-save-passwords
new file mode 100644
index 000000000000..d4801c2288c4
--- /dev/null
+++ b/games/openttd/files/extra-patch-save-passwords
@@ -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