Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 16 Nov 2014 12:35:55 +0000 (UTC)
From:      Alexey Dokuchaev <danfe@FreeBSD.org>
To:        ports-committers@freebsd.org, svn-ports-all@freebsd.org, svn-ports-head@freebsd.org
Subject:   svn commit: r372636 - in head/games/openttd: . files
Message-ID:  <201411161235.sAGCZt48065053@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: danfe
Date: Sun Nov 16 12:35:54 2014
New Revision: 372636
URL: https://svnweb.freebsd.org/changeset/ports/372636
QAT: https://qat.redports.org/buildarchive/r372636/

Log:
  Add an optional patch to enable saving of passwords between server restarts.
  
  Submitted by:	Alex Kushnaryov

Added:
  head/games/openttd/files/extra-patch-save-passwords   (contents, props changed)
Modified:
  head/games/openttd/Makefile

Modified: head/games/openttd/Makefile
==============================================================================
--- head/games/openttd/Makefile	Sun Nov 16 12:25:30 2014	(r372635)
+++ head/games/openttd/Makefile	Sun Nov 16 12:35:54 2014	(r372636)
@@ -66,6 +66,10 @@ RUN_DEPENDS+=	${LOCALBASE}/share/${PORTN
 		${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

Added: head/games/openttd/files/extra-patch-save-passwords
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/games/openttd/files/extra-patch-save-passwords	Sun Nov 16 12:35:54 2014	(r372636)
@@ -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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201411161235.sAGCZt48065053>