Changeset - r10315:480d8227cc53
[Not reviewed]
master
0 2 0
smatz - 16 years ago 2008-11-03 12:03:00
smatz@openttd.org
(svn r14560) -Fix [FS#2396](r14555): lengthof() can't be simply replaced by lastof() in some cases (part by Aali)
2 files changed with 4 insertions and 4 deletions:
0 comments (0 inline, 0 general)
src/network/network_server.cpp
Show inline comments
 
@@ -1327,110 +1327,110 @@ void NetworkPopulateCompanyInfo()
 
		if (_cur_year - 1 == c->inaugurated_year) {
 
			// The company is here just 1 year, so display [2], else display[1]
 
			for (i = 0; i < lengthof(c->yearly_expenses[2]); i++) {
 
				_network_company_info[c->index].income -= c->yearly_expenses[2][i];
 
			}
 
		} else {
 
			for (i = 0; i < lengthof(c->yearly_expenses[1]); i++) {
 
				_network_company_info[c->index].income -= c->yearly_expenses[1][i];
 
			}
 
		}
 

	
 
		// Set some general stuff
 
		_network_company_info[c->index].inaugurated_year = c->inaugurated_year;
 
		_network_company_info[c->index].company_value = c->old_economy[0].company_value;
 
		_network_company_info[c->index].money = c->money;
 
		_network_company_info[c->index].performance = c->old_economy[0].performance_history;
 
	}
 

	
 
	// Go through all vehicles and count the type of vehicles
 
	FOR_ALL_VEHICLES(v) {
 
		if (!IsValidCompanyID(v->owner) || !v->IsPrimaryVehicle()) continue;
 
		byte type = 0;
 
		switch (v->type) {
 
			case VEH_TRAIN: type = 0; break;
 
			case VEH_ROAD: type = (v->cargo_type != CT_PASSENGERS) ? 1 : 2; break;
 
			case VEH_AIRCRAFT: type = 3; break;
 
			case VEH_SHIP: type = 4; break;
 
			default: continue;
 
		}
 
		_network_company_info[v->owner].num_vehicle[type]++;
 
	}
 

	
 
	// Go through all stations and count the types of stations
 
	FOR_ALL_STATIONS(s) {
 
		if (IsValidCompanyID(s->owner)) {
 
			NetworkCompanyInfo *npi = &_network_company_info[s->owner];
 

	
 
			if (s->facilities & FACIL_TRAIN)      npi->num_station[0]++;
 
			if (s->facilities & FACIL_TRUCK_STOP) npi->num_station[1]++;
 
			if (s->facilities & FACIL_BUS_STOP)   npi->num_station[2]++;
 
			if (s->facilities & FACIL_AIRPORT)    npi->num_station[3]++;
 
			if (s->facilities & FACIL_DOCK)       npi->num_station[4]++;
 
		}
 
	}
 

	
 
	ci = NetworkFindClientInfoFromIndex(NETWORK_SERVER_INDEX);
 
	// Register local company (if not dedicated)
 
	if (ci != NULL && IsValidCompanyID(ci->client_playas))
 
		strecpy(_network_company_info[ci->client_playas].clients, ci->client_name, lastof(_network_company_info[0].clients));
 
		strecpy(_network_company_info[ci->client_playas].clients, ci->client_name, lastof(_network_company_info[ci->client_playas].clients));
 

	
 
	FOR_ALL_CLIENTS(cs) {
 
		char client_name[NETWORK_CLIENT_NAME_LENGTH];
 

	
 
		NetworkGetClientName(client_name, sizeof(client_name), cs);
 

	
 
		ci = DEREF_CLIENT_INFO(cs);
 
		if (ci != NULL && IsValidCompanyID(ci->client_playas)) {
 
			if (!StrEmpty(_network_company_info[ci->client_playas].clients)) {
 
				strecat(_network_company_info[ci->client_playas].clients, ", ", lastof(_network_company_info[0].clients));
 
				strecat(_network_company_info[ci->client_playas].clients, ", ", lastof(_network_company_info[ci->client_playas].clients));
 
			}
 

	
 
			strecat(_network_company_info[ci->client_playas].clients, client_name, lastof(_network_company_info[0].clients));
 
			strecat(_network_company_info[ci->client_playas].clients, client_name, lastof(_network_company_info[ci->client_playas].clients));
 
		}
 
	}
 
}
 

	
 
// Send a packet to all clients with updated info about this client_index
 
void NetworkUpdateClientInfo(uint16 client_index)
 
{
 
	NetworkTCPSocketHandler *cs;
 
	NetworkClientInfo *ci = NetworkFindClientInfoFromIndex(client_index);
 

	
 
	if (ci == NULL) return;
 

	
 
	FOR_ALL_CLIENTS(cs) {
 
		SEND_COMMAND(PACKET_SERVER_CLIENT_INFO)(cs, ci);
 
	}
 
}
 

	
 
/* Check if we want to restart the map */
 
static void NetworkCheckRestartMap()
 
{
 
	if (_settings_client.network.restart_game_year != 0 && _cur_year >= _settings_client.network.restart_game_year) {
 
		DEBUG(net, 0, "Auto-restarting map. Year %d reached", _cur_year);
 

	
 
		StartNewGameWithoutGUI(GENERATE_NEW_SEED);
 
	}
 
}
 

	
 
/* Check if the server has autoclean_companies activated
 
    Two things happen:
 
      1) If a company is not protected, it is closed after 1 year (for example)
 
      2) If a company is protected, protection is disabled after 3 years (for example)
 
           (and item 1. happens a year later) */
 
static void NetworkAutoCleanCompanies()
 
{
 
	NetworkTCPSocketHandler *cs;
 
	const NetworkClientInfo *ci;
 
	const Company *c;
 
	bool clients_in_company[MAX_COMPANIES];
 

	
 
	if (!_settings_client.network.autoclean_companies) return;
 

	
 
	memset(clients_in_company, 0, sizeof(clients_in_company));
 

	
 
	/* Detect the active companies */
 
	FOR_ALL_CLIENTS(cs) {
 
		ci = DEREF_CLIENT_INFO(cs);
 
		if (IsValidCompanyID(ci->client_playas)) clients_in_company[ci->client_playas] = true;
 
	}
src/unix.cpp
Show inline comments
 
@@ -109,97 +109,97 @@ bool FiosIsHiddenFile(const struct diren
 
#ifdef WITH_ICONV
 

	
 
#include <iconv.h>
 
#include <errno.h>
 
#include "debug.h"
 
#include "string_func.h"
 

	
 
const char *GetCurrentLocale(const char *param);
 

	
 
#define INTERNALCODE "UTF-8"
 

	
 
/** Try and try to decipher the current locale from environmental
 
 * variables. MacOSX is hardcoded, other OS's are dynamic. If no suitable
 
 * locale can be found, don't do any conversion "" */
 
static const char *GetLocalCode()
 
{
 
#if defined(__APPLE__)
 
	return "UTF-8-MAC";
 
#else
 
	/* Strip locale (eg en_US.UTF-8) to only have UTF-8 */
 
	const char *locale = GetCurrentLocale("LC_CTYPE");
 
	if (locale != NULL) locale = strchr(locale, '.');
 

	
 
	return (locale == NULL) ? "" : locale + 1;
 
#endif
 
}
 

	
 
/** FYI: This is not thread-safe.
 
 * convert between locales, which from and which to is set in the calling
 
 * functions OTTD2FS() and FS2OTTD(). You should NOT use this function directly
 
 * NOTE: iconv was added in OSX 10.3. 10.2.x will still have the invalid char
 
 * issues. There aren't any easy fix for this */
 
static const char *convert_tofrom_fs(iconv_t convd, const char *name)
 
{
 
	static char buf[1024];
 
	/* Work around buggy iconv implementation where inbuf is wrongly typed as
 
	 * non-const. Correct implementation is at
 
	 * http://www.opengroup.org/onlinepubs/007908799/xsh/iconv.html */
 
#ifdef HAVE_BROKEN_ICONV
 
	char *inbuf = (char*)name;
 
#else
 
	const char *inbuf = name;
 
#endif
 

	
 
	char *outbuf  = buf;
 
	size_t outlen = sizeof(buf) - 1;
 
	size_t inlen  = strlen(name);
 

	
 
	strecpy(outbuf, name, lastof(buf));
 
	strecpy(outbuf, name, outbuf + outlen);
 

	
 
	iconv(convd, NULL, NULL, NULL, NULL);
 
	if (iconv(convd, &inbuf, &inlen, &outbuf, &outlen) == (size_t)(-1)) {
 
		DEBUG(misc, 0, "[iconv] error converting '%s'. Errno %d", name, errno);
 
	}
 

	
 
	*outbuf = '\0';
 
	/* FIX: invalid characters will abort conversion, but they shouldn't occur? */
 
	return buf;
 
}
 

	
 
/** Convert from OpenTTD's encoding to that of the local environment
 
 * @param name pointer to a valid string that will be converted
 
 * @return pointer to a new stringbuffer that contains the converted string */
 
const char *OTTD2FS(const char *name)
 
{
 
	static iconv_t convd = (iconv_t)(-1);
 

	
 
	if (convd == (iconv_t)(-1)) {
 
		const char *env = GetLocalCode();
 
		convd = iconv_open(env, INTERNALCODE);
 
		if (convd == (iconv_t)(-1)) {
 
			DEBUG(misc, 0, "[iconv] conversion from codeset '%s' to '%s' unsupported", INTERNALCODE, env);
 
			return name;
 
		}
 
	}
 

	
 
	return convert_tofrom_fs(convd, name);
 
}
 

	
 
/** Convert to OpenTTD's encoding from that of the local environment
 
 * @param name pointer to a valid string that will be converted
 
 * @return pointer to a new stringbuffer that contains the converted string */
 
const char *FS2OTTD(const char *name)
 
{
 
	static iconv_t convd = (iconv_t)(-1);
 

	
 
	if (convd == (iconv_t)(-1)) {
 
		const char *env = GetLocalCode();
 
		convd = iconv_open(INTERNALCODE, env);
 
		if (convd == (iconv_t)(-1)) {
 
			DEBUG(misc, 0, "[iconv] conversion from codeset '%s' to '%s' unsupported", env, INTERNALCODE);
 
			return name;
 
		}
 
	}
 

	
 
	return convert_tofrom_fs(convd, name);
 
}
0 comments (0 inline, 0 general)