Changeset - r9428:6800206a6c0d
[Not reviewed]
projects/openttd_vs80.vcproj
Show inline comments
 
@@ -1137,13 +1137,13 @@
 
			</File>
 
			<File
 
				RelativePath=".\..\src\network\network_client.h"
 
				>
 
			</File>
 
			<File
 
				RelativePath=".\..\src\network\network_data.h"
 
				RelativePath=".\..\src\network\network_func.h"
 
				>
 
			</File>
 
			<File
 
				RelativePath=".\..\src\network\network_gamelist.h"
 
				>
 
			</File>
 
@@ -1157,12 +1157,16 @@
 
			</File>
 
			<File
 
				RelativePath=".\..\src\network\network_server.h"
 
				>
 
			</File>
 
			<File
 
				RelativePath=".\..\src\network\network_type.h"
 
				>
 
			</File>
 
			<File
 
				RelativePath=".\..\src\network\network_udp.h"
 
				>
 
			</File>
 
			<File
 
				RelativePath=".\..\src\newgrf.h"
 
				>
projects/openttd_vs90.vcproj
Show inline comments
 
@@ -1134,13 +1134,13 @@
 
			</File>
 
			<File
 
				RelativePath=".\..\src\network\network_client.h"
 
				>
 
			</File>
 
			<File
 
				RelativePath=".\..\src\network\network_data.h"
 
				RelativePath=".\..\src\network\network_func.h"
 
				>
 
			</File>
 
			<File
 
				RelativePath=".\..\src\network\network_gamelist.h"
 
				>
 
			</File>
 
@@ -1154,12 +1154,16 @@
 
			</File>
 
			<File
 
				RelativePath=".\..\src\network\network_server.h"
 
				>
 
			</File>
 
			<File
 
				RelativePath=".\..\src\network\network_type.h"
 
				>
 
			</File>
 
			<File
 
				RelativePath=".\..\src\network\network_udp.h"
 
				>
 
			</File>
 
			<File
 
				RelativePath=".\..\src\newgrf.h"
 
				>
source.list
Show inline comments
 
@@ -207,17 +207,18 @@ md5.h
 
minilzo.h
 
mixer.h
 
music.h
 
namegen_func.h
 
network/network.h
 
network/network_client.h
 
network/network_data.h
 
network/network_func.h
 
network/network_gamelist.h
 
network/network_gui.h
 
network/network_internal.h
 
network/network_server.h
 
network/network_type.h
 
network/network_udp.h
 
newgrf.h
 
newgrf_callbacks.h
 
newgrf_canal.h
 
newgrf_cargo.h
 
newgrf_commons.h
src/console.cpp
Show inline comments
 
/* $Id$ */
 

	
 
/** @file console.cpp Handling of the in-game console. */
 

	
 
#include "stdafx.h"
 
#include "console_internal.h"
 
#include "network/network_data.h"
 
#include "network/network_server.h"
 
#include "core/alloc_func.hpp"
 
#include "string_func.h"
 
#include "strings_type.h"
 
#include "core/math_func.hpp"
 
#include "console_internal.h"
 
#include "network/network.h"
 
#include "network/network_func.h"
 
#include "rev.h"
 

	
 
#include <stdarg.h>
 

	
 
#include "table/strings.h"
 

	
 
@@ -89,13 +89,13 @@ void IConsoleFree()
 
void IConsolePrint(ConsoleColour color_code, const char *string)
 
{
 
	char *str;
 
#ifdef ENABLE_NETWORK
 
	if (_redirect_console_to_client != 0) {
 
		/* Redirect the string to the client */
 
		SEND_COMMAND(PACKET_SERVER_RCON)(NetworkFindClientStateFromIndex(_redirect_console_to_client), color_code, string);
 
		NetworkServerSendRcon(_redirect_console_to_client, color_code, string);
 
		return;
 
	}
 
#endif
 

	
 
	/* Create a copy of the string, strip if of colours and invalid
 
	 * characters and (when applicable) assign it to the console buffer */
src/console_cmds.cpp
Show inline comments
 
@@ -7,23 +7,20 @@
 
#include "console_internal.h"
 
#include "debug.h"
 
#include "engine_func.h"
 
#include "landscape.h"
 
#include "saveload.h"
 
#include "variables.h"
 
#include "network/network_data.h"
 
#include "network/network_client.h"
 
#include "network/network_server.h"
 
#include "network/network_udp.h"
 
#include "network/network.h"
 
#include "network/network_func.h"
 
#include "command_func.h"
 
#include "settings_func.h"
 
#include "fios.h"
 
#include "fileio.h"
 
#include "screenshot.h"
 
#include "genworld.h"
 
#include "network/network.h"
 
#include "strings_func.h"
 
#include "viewport_func.h"
 
#include "window_func.h"
 
#include "functions.h"
 
#include "map_func.h"
 
#include "date_func.h"
 
@@ -422,14 +419,14 @@ DEF_CONSOLE_CMD(ConBan)
 
	if (index == 0 || (ci == NULL && index != (uint32)-1)) {
 
		IConsoleError("Invalid client");
 
		return true;
 
	}
 

	
 
	if (ci != NULL) {
 
		banip = inet_ntoa(*(struct in_addr *)&ci->client_ip);
 
		SEND_COMMAND(PACKET_SERVER_ERROR)(NetworkFindClientStateFromIndex(index), NETWORK_ERROR_KICKED);
 
		banip = GetPlayerIP(ci);
 
		NetworkServerSendError(index, NETWORK_ERROR_KICKED);
 
		IConsolePrint(CC_DEFAULT, "Client banned");
 
	} else {
 
		IConsolePrint(CC_DEFAULT, "Client not online, banned IP");
 
	}
 

	
 
	/* Add user to ban-list */
 
@@ -536,49 +533,25 @@ DEF_CONSOLE_CMD(ConRcon)
 

	
 
	if (argc < 3) return false;
 

	
 
	if (_network_server) {
 
		IConsoleCmdExec(argv[2]);
 
	} else {
 
		SEND_COMMAND(PACKET_CLIENT_RCON)(argv[1], argv[2]);
 
		NetworkClientSendRcon(argv[1], argv[2]);
 
	}
 
	return true;
 
}
 

	
 
DEF_CONSOLE_CMD(ConStatus)
 
{
 
	static const char* const stat_str[] = {
 
		"inactive",
 
		"authorizing",
 
		"authorized",
 
		"waiting",
 
		"loading map",
 
		"map done",
 
		"ready",
 
		"active"
 
	};
 

	
 
	NetworkTCPSocketHandler *cs;
 

	
 
	if (argc == 0) {
 
		IConsoleHelp("List the status of all clients connected to the server. Usage 'status'");
 
		return true;
 
	}
 

	
 
	FOR_ALL_CLIENTS(cs) {
 
		int lag = NetworkCalculateLag(cs);
 
		const NetworkClientInfo *ci = DEREF_CLIENT_INFO(cs);
 
		const char* status;
 

	
 
		status = (cs->status < (ptrdiff_t)lengthof(stat_str) ? stat_str[cs->status] : "unknown");
 
		IConsolePrintF(CC_INFO, "Client #%1d  name: '%s'  status: '%s'  frame-lag: %3d  company: %1d  IP: %s  unique-id: '%s'",
 
			cs->index, ci->client_name, status, lag,
 
			ci->client_playas + (IsValidPlayer(ci->client_playas) ? 1 : 0),
 
			GetPlayerIP(ci), ci->unique_id);
 
	}
 

	
 
	NetworkServerShowStatusToConsole();
 
	return true;
 
}
 

	
 
DEF_CONSOLE_CMD(ConServerInfo)
 
{
 
	const NetworkGameInfo *gi;
 
@@ -626,25 +599,23 @@ DEF_CONSOLE_CMD(ConKick)
 
	if (index == 0) {
 
		IConsoleError("Invalid client");
 
		return true;
 
	}
 

	
 
	if (ci != NULL) {
 
		SEND_COMMAND(PACKET_SERVER_ERROR)(NetworkFindClientStateFromIndex(index), NETWORK_ERROR_KICKED);
 
		NetworkServerSendError(index, NETWORK_ERROR_KICKED);
 
	} else {
 
		IConsoleError("Client not found");
 
	}
 

	
 
	return true;
 
}
 

	
 
DEF_CONSOLE_CMD(ConResetCompany)
 
{
 
	const Player *p;
 
	NetworkTCPSocketHandler *cs;
 
	const NetworkClientInfo *ci;
 
	PlayerID index;
 

	
 
	if (argc == 0) {
 
		IConsoleHelp("Remove an idle company from the game. Usage: 'reset_company <company-id>'");
 
		IConsoleHelp("For company-id's, see the list of companies from the dropdown menu. Player 1 is 1, etc.");
 
		return true;
 
@@ -669,21 +640,17 @@ DEF_CONSOLE_CMD(ConResetCompany)
 

	
 
	if (p->is_ai) {
 
		IConsoleError("Company is owned by an AI.");
 
		return true;
 
	}
 

	
 
	/* Check if the company has active players */
 
	FOR_ALL_CLIENTS(cs) {
 
		ci = DEREF_CLIENT_INFO(cs);
 
		if (ci->client_playas == index) {
 
			IConsoleError("Cannot remove company: a client is connected to that company.");
 
			return true;
 
		}
 
	if (NetworkCompanyHasPlayers(index)) {
 
		IConsoleError("Cannot remove company: a client is connected to that company.");
 
		return false;
 
	}
 
	ci = NetworkFindClientInfoFromIndex(NETWORK_SERVER_INDEX);
 
	const NetworkClientInfo *ci = NetworkFindClientInfoFromIndex(NETWORK_SERVER_INDEX);
 
	if (ci->client_playas == index) {
 
		IConsoleError("Cannot remove company: the server is connected to that company.");
 
		return true;
 
	}
 

	
 
	/* It is safe to remove this company */
 
@@ -1184,15 +1151,15 @@ DEF_CONSOLE_CMD(ConSay)
 
		return true;
 
	}
 

	
 
	if (argc != 2) return false;
 

	
 
	if (!_network_server) {
 
		SEND_COMMAND(PACKET_CLIENT_CHAT)(NETWORK_ACTION_CHAT, DESTTYPE_BROADCAST, 0 /* param does not matter */, argv[1]);
 
		NetworkClientSendChat(NETWORK_ACTION_CHAT, DESTTYPE_BROADCAST, 0 /* param does not matter */, argv[1]);
 
	} else {
 
		NetworkServer_HandleChat(NETWORK_ACTION_CHAT, DESTTYPE_BROADCAST, 0, argv[1], NETWORK_SERVER_INDEX);
 
		NetworkServerSendChat(NETWORK_ACTION_CHAT, DESTTYPE_BROADCAST, 0, argv[1], NETWORK_SERVER_INDEX);
 
	}
 

	
 
	return true;
 
}
 

	
 
DEF_CONSOLE_CMD(ConPlayers)
 
@@ -1238,15 +1205,15 @@ DEF_CONSOLE_CMD(ConSayPlayer)
 
	if (atoi(argv[1]) < 1 || atoi(argv[1]) > MAX_PLAYERS) {
 
		IConsolePrintF(CC_DEFAULT, "Unknown player. Player range is between 1 and %d.", MAX_PLAYERS);
 
		return true;
 
	}
 

	
 
	if (!_network_server) {
 
		SEND_COMMAND(PACKET_CLIENT_CHAT)(NETWORK_ACTION_CHAT_COMPANY, DESTTYPE_TEAM, atoi(argv[1]), argv[2]);
 
		NetworkClientSendChat(NETWORK_ACTION_CHAT_COMPANY, DESTTYPE_TEAM, atoi(argv[1]), argv[2]);
 
	} else {
 
		NetworkServer_HandleChat(NETWORK_ACTION_CHAT_COMPANY, DESTTYPE_TEAM, atoi(argv[1]), argv[2], NETWORK_SERVER_INDEX);
 
		NetworkServerSendChat(NETWORK_ACTION_CHAT_COMPANY, DESTTYPE_TEAM, atoi(argv[1]), argv[2], NETWORK_SERVER_INDEX);
 
	}
 

	
 
	return true;
 
}
 

	
 
DEF_CONSOLE_CMD(ConSayClient)
 
@@ -1257,15 +1224,15 @@ DEF_CONSOLE_CMD(ConSayClient)
 
		return true;
 
	}
 

	
 
	if (argc != 3) return false;
 

	
 
	if (!_network_server) {
 
		SEND_COMMAND(PACKET_CLIENT_CHAT)(NETWORK_ACTION_CHAT_CLIENT, DESTTYPE_CLIENT, atoi(argv[1]), argv[2]);
 
		NetworkClientSendChat(NETWORK_ACTION_CHAT_CLIENT, DESTTYPE_CLIENT, atoi(argv[1]), argv[2]);
 
	} else {
 
		NetworkServer_HandleChat(NETWORK_ACTION_CHAT_CLIENT, DESTTYPE_CLIENT, atoi(argv[1]), argv[2], NETWORK_SERVER_INDEX);
 
		NetworkServerSendChat(NETWORK_ACTION_CHAT_CLIENT, DESTTYPE_CLIENT, atoi(argv[1]), argv[2], NETWORK_SERVER_INDEX);
 
	}
 

	
 
	return true;
 
}
 

	
 
extern void HashCurrentCompanyPassword();
 
@@ -1288,13 +1255,13 @@ bool NetworkChangeCompanyPassword(byte a
 

	
 
	if (strcmp(argv[0], "*") == 0) argv[0][0] = '\0';
 

	
 
	ttd_strlcpy(_network_player_info[_local_player].password, argv[0], sizeof(_network_player_info[_local_player].password));
 

	
 
	if (!_network_server) {
 
		SEND_COMMAND(PACKET_CLIENT_SET_PASSWORD)(_network_player_info[_local_player].password);
 
		NetworkClientSetPassword();
 
	} else {
 
		HashCurrentCompanyPassword();
 
	}
 

	
 
	IConsolePrintF(CC_WARNING, "'company_pw' changed to:  %s", _network_player_info[_local_player].password);
 

	
src/date.cpp
Show inline comments
 
@@ -4,14 +4,13 @@
 

	
 
#include "stdafx.h"
 
#include "openttd.h"
 
#include "variables.h"
 
#include "settings_type.h"
 
#include "network/network.h"
 
#include "network/network_data.h"
 
#include "network/network_server.h"
 
#include "network/network_func.h"
 
#include "currency.h"
 
#include "window_func.h"
 
#include "functions.h"
 
#include "date_func.h"
 
#include "vehicle_base.h"
 
#include "debug.h"
 
@@ -265,26 +264,30 @@ void IncreaseDate()
 
		InvalidateWindowClasses(WC_CHEATS);
 
		PlayersMonthlyLoop();
 
		EnginesMonthlyLoop();
 
		TownsMonthlyLoop();
 
		IndustryMonthlyLoop();
 
		StationMonthlyLoop();
 
#ifdef ENABLE_NETWORK
 
		if (_network_server) NetworkServerMonthlyLoop();
 
#endif /* ENABLE_NETWORK */
 
	}
 

	
 
	/* check if we entered a new year? */
 
	if (ymd.year == _cur_year) return;
 
	_cur_year = ymd.year;
 

	
 
	/* yes, call various yearly loops */
 
	PlayersYearlyLoop();
 
	TrainsYearlyLoop();
 
	RoadVehiclesYearlyLoop();
 
	AircraftYearlyLoop();
 
	ShipsYearlyLoop();
 
#ifdef ENABLE_NETWORK
 
	if (_network_server) NetworkServerYearlyLoop();
 
#endif /* ENABLE_NETWORK */
 

	
 
	if (_cur_year == _settings_client.gui.semaphore_build_before) ResetSignalVariant();
 

	
 
	/* check if we reached end of the game */
 
	if (_cur_year == _settings_client.gui.ending_year) {
 
			ShowEndGameChart();
src/economy.cpp
Show inline comments
 
@@ -11,13 +11,13 @@
 
#include "command_func.h"
 
#include "saveload.h"
 
#include "industry.h"
 
#include "town.h"
 
#include "news_func.h"
 
#include "network/network.h"
 
#include "network/network_data.h"
 
#include "network/network_func.h"
 
#include "variables.h"
 
#include "vehicle_gui.h"
 
#include "ai/ai.h"
 
#include "train.h"
 
#include "roadveh.h"
 
#include "aircraft.h"
 
@@ -485,31 +485,13 @@ static void ChangeNetworkOwner(PlayerID 
 
		_network_playas = new_player;
 
		SetLocalPlayer(new_player);
 
	}
 

	
 
	if (!_network_server) return;
 

	
 
	/* The server has to handle all administrative issues, for example
 
	* updating and notifying all clients of what has happened */
 
	NetworkTCPSocketHandler *cs;
 
	NetworkClientInfo *ci = NetworkFindClientInfoFromIndex(NETWORK_SERVER_INDEX);
 

	
 
	/* The server has just changed from player */
 
	if (current_player == ci->client_playas) {
 
		ci->client_playas = new_player;
 
		NetworkUpdateClientInfo(NETWORK_SERVER_INDEX);
 
	}
 

	
 
	/* Find all clients that were in control of this company, and mark them as new_player */
 
	FOR_ALL_CLIENTS(cs) {
 
		ci = DEREF_CLIENT_INFO(cs);
 
		if (current_player == ci->client_playas) {
 
			ci->client_playas = new_player;
 
			NetworkUpdateClientInfo(ci->client_index);
 
		}
 
	}
 
	NetworkServerChangeOwner(current_player, new_player);
 
#endif /* ENABLE_NETWORK */
 
}
 

	
 
static void PlayersCheckBankrupt(Player *p)
 
{
 
	PlayerID owner;
src/effectvehicle.cpp
Show inline comments
 
@@ -22,13 +22,12 @@
 
#include "rail_type.h"
 
#include "train.h"
 
#include "aircraft.h"
 
#include "industry_map.h"
 
#include "station_map.h"
 
#include "water_map.h"
 
#include "network/network.h"
 
#include "yapf/yapf.h"
 
#include "newgrf_callbacks.h"
 
#include "newgrf_engine.h"
 
#include "newgrf_sound.h"
 
#include "group.h"
 
#include "order_func.h"
src/main_gui.cpp
Show inline comments
 
@@ -31,15 +31,13 @@
 
#include "toolbar_gui.h"
 
#include "statusbar_gui.h"
 
#include "variables.h"
 
#include "tilehighlight_func.h"
 

	
 
#include "network/network.h"
 
#include "network/network_data.h"
 
#include "network/network_client.h"
 
#include "network/network_server.h"
 
#include "network/network_func.h"
 
#include "network/network_gui.h"
 

	
 
#include "table/sprites.h"
 
#include "table/strings.h"
 

	
 
static int _rename_id = 1;
 
@@ -52,15 +50,15 @@ void CcGiveMoney(bool success, TileIndex
 

	
 
	char msg[20];
 
	/* Inform the player of this action */
 
	snprintf(msg, sizeof(msg), "%d", p1);
 

	
 
	if (!_network_server) {
 
		SEND_COMMAND(PACKET_CLIENT_CHAT)(NETWORK_ACTION_GIVE_MONEY, DESTTYPE_TEAM, p2, msg);
 
		NetworkClientSendChat(NETWORK_ACTION_GIVE_MONEY, DESTTYPE_TEAM, p2, msg);
 
	} else {
 
		NetworkServer_HandleChat(NETWORK_ACTION_GIVE_MONEY, DESTTYPE_TEAM, p2, msg, NETWORK_SERVER_INDEX);
 
		NetworkServerSendChat(NETWORK_ACTION_GIVE_MONEY, DESTTYPE_TEAM, p2, msg, NETWORK_SERVER_INDEX);
 
	}
 
#endif /* ENABLE_NETWORK */
 
}
 

	
 
void HandleOnEditText(const char *str)
 
{
src/network/core/core.h
Show inline comments
 
@@ -59,21 +59,21 @@ public:
 
	virtual NetworkRecvStatus CloseConnection() { this->has_quit = true; return NETWORK_RECV_STATUS_OKAY; }
 

	
 
	/**
 
	 * Whether this socket is currently bound to a socket.
 
	 * @return true when the socket is bound, false otherwise
 
	 */
 
	bool IsConnected() { return this->sock != INVALID_SOCKET; }
 
	bool IsConnected() const { return this->sock != INVALID_SOCKET; }
 

	
 
	/**
 
	 * Whether the current client connected to the socket has quit.
 
	 * In the case of UDP, for example, once a client quits (send bad
 
	 * data), the socket in not closed; only the packet is dropped.
 
	 * @return true when the current client has quit, false otherwise
 
	 */
 
	bool HasClientQuit() { return this->has_quit; }
 
	bool HasClientQuit() const { return this->has_quit; }
 

	
 
	void Send_GRFIdentifier(Packet *p, const GRFIdentifier *grf);
 
	void Recv_GRFIdentifier(Packet *p, GRFIdentifier *grf);
 
};
 

	
 
#endif /* ENABLE_NETWORK */
src/network/core/tcp.cpp
Show inline comments
 
@@ -8,13 +8,13 @@
 

	
 
#include "../../stdafx.h"
 
#include "../../debug.h"
 
#include "../../openttd.h"
 
#include "../../variables.h"
 

	
 
#include "../network_data.h"
 
#include "../network_internal.h"
 
#include "packet.h"
 
#include "tcp.h"
 

	
 
#include "table/strings.h"
 

	
 
/** Very ugly temporary hack !!! */
src/network/network.cpp
Show inline comments
 
/* $Id$ */
 

	
 
/** @file network.cpp Base functions for networking support. */
 

	
 
#include "../stdafx.h"
 
#include "network_data.h"
 
#include "../player_type.h"
 

	
 
#ifdef ENABLE_NETWORK
 

	
 
#include "../openttd.h"
 
#include "../debug.h"
 
#include "../strings_func.h"
 
#include "../map_func.h"
 
#include "../command_func.h"
 
#include "../variables.h"
 
#include "../date_func.h"
 
#include "../newgrf_config.h"
 
#include "network_internal.h"
 
#include "network_client.h"
 
#include "network_server.h"
 
#include "network_udp.h"
 
#include "network_gamelist.h"
 
#include "core/udp.h"
 
#include "core/tcp.h"
 
@@ -35,20 +36,42 @@
 
#include "../settings_type.h"
 
#include "../landscape_type.h"
 
#include "../rev.h"
 
#ifdef DEBUG_DUMP_COMMANDS
 
	#include "../core/alloc_func.hpp"
 
#endif /* DEBUG_DUMP_COMMANDS */
 

	
 
#include "table/strings.h"
 

	
 
bool _network_reload_cfg;
 
bool _network_server;     ///< network-server is active
 
bool _network_available;  ///< is network mode available?
 
bool _network_dedicated;  ///< are we a dedicated server?
 
bool _network_advertise;  ///< is the server advertising to the master server?
 
bool _is_network_server;  ///< Does this client wants to be a network-server?
 
NetworkGameInfo _network_game_info;
 
NetworkPlayerInfo _network_player_info[MAX_PLAYERS];
 
NetworkClientInfo _network_client_info[MAX_CLIENT_INFO];
 
uint16 _network_own_client_index;
 
uint16 _redirect_console_to_client;
 
bool _network_need_advertise;
 
uint32 _network_last_advertise_frame;
 
uint8 _network_reconnect;
 
char *_network_host_list[10];
 
char *_network_ban_list[25];
 
uint32 _frame_counter_server; // The frame_counter of the server, if in network-mode
 
uint32 _frame_counter_max; // To where we may go with our clients
 
uint32 _last_sync_frame; // Used in the server to store the last time a sync packet was sent to clients.
 
uint32 _broadcast_list[MAX_INTERFACES + 1];
 
uint32 _network_server_bind_ip;
 
uint32 _sync_seed_1, _sync_seed_2;
 
uint32 _sync_frame;
 
bool _network_first_time;
 
uint32 _network_last_host_ip;
 
bool _network_udp_server;
 
uint16 _network_udp_broadcast;
 
uint8 _network_advertise_retries;
 

	
 
/* Check whether NETWORK_NUM_LANDSCAPES is still in sync with NUM_LANDSCAPE */
 
assert_compile((int)NETWORK_NUM_LANDSCAPES == (int)NUM_LANDSCAPE);
 

	
 
// global variables (declared in network_data.h)
 
CommandPacket *_local_command_queue;
 
@@ -334,19 +357,19 @@ void CheckMinPlayers()
 

	
 
	if (NetworkCountPlayers() < _settings_client.network.min_players) {
 
		if (_min_players_paused) return;
 

	
 
		_min_players_paused = true;
 
		DoCommandP(0, 1, 0, NULL, CMD_PAUSE);
 
		NetworkServer_HandleChat(NETWORK_ACTION_SERVER_MESSAGE, DESTTYPE_BROADCAST, 0, "Game paused (not enough players)", NETWORK_SERVER_INDEX);
 
		NetworkServerSendChat(NETWORK_ACTION_SERVER_MESSAGE, DESTTYPE_BROADCAST, 0, "Game paused (not enough players)", NETWORK_SERVER_INDEX);
 
	} else {
 
		if (!_min_players_paused) return;
 

	
 
		_min_players_paused = false;
 
		DoCommandP(0, 0, 0, NULL, CMD_PAUSE);
 
		NetworkServer_HandleChat(NETWORK_ACTION_SERVER_MESSAGE, DESTTYPE_BROADCAST, 0, "Game unpaused (enough players)", NETWORK_SERVER_INDEX);
 
		NetworkServerSendChat(NETWORK_ACTION_SERVER_MESSAGE, DESTTYPE_BROADCAST, 0, "Game unpaused (enough players)", NETWORK_SERVER_INDEX);
 
	}
 
}
 

	
 
// Find all IP-aliases for this host
 
static void NetworkFindIPs()
 
{
 
@@ -661,13 +684,13 @@ void NetworkCloseClient(NetworkTCPSocket
 
		}
 
	}
 

	
 
	/* When the client was PRE_ACTIVE, the server was in pause mode, so unpause */
 
	if (cs->status == STATUS_PRE_ACTIVE && _settings_client.network.pause_on_join) {
 
		DoCommandP(0, 0, 0, NULL, CMD_PAUSE);
 
		NetworkServer_HandleChat(NETWORK_ACTION_SERVER_MESSAGE, DESTTYPE_BROADCAST, 0, "Game unpaused", NETWORK_SERVER_INDEX);
 
		NetworkServerSendChat(NETWORK_ACTION_SERVER_MESSAGE, DESTTYPE_BROADCAST, 0, "Game unpaused", NETWORK_SERVER_INDEX);
 
	}
 

	
 
	cs->Destroy();
 

	
 
	// Close the gap in the client-list
 
	ci = DEREF_CLIENT_INFO(cs);
src/network/network.h
Show inline comments
 
@@ -14,24 +14,26 @@ void NetworkShutDown();
 

	
 
extern bool _networking;         ///< are we in networking mode?
 
extern bool _network_server;     ///< network-server is active
 
extern bool _network_available;  ///< is network mode available?
 
extern bool _network_dedicated;  ///< are we a dedicated server?
 
extern bool _network_advertise;  ///< is the server advertising to the master server?
 
extern bool _is_network_server;  ///< Does this client wants to be a network-server?
 

	
 
#else /* ENABLE_NETWORK */
 
/* Network function stubs when networking is disabled */
 

	
 
static inline void NetworkStartUp() {}
 
static inline void NetworkShutDown() {}
 

	
 
#define _networking 0
 
#define _network_server 0
 
#define _network_available 0
 
#define _network_dedicated 0
 
#define _network_advertise 0
 
#define _is_network_server 0
 

	
 
#endif /* ENABLE_NETWORK */
 

	
 
/** As which player do we play? */
 
extern PlayerID _network_playas;
 

	
src/network/network_client.cpp
Show inline comments
 
@@ -4,13 +4,13 @@
 

	
 
#ifdef ENABLE_NETWORK
 

	
 
#include "../stdafx.h"
 
#include "../debug.h"
 
#include "../openttd.h"
 
#include "network_data.h"
 
#include "network_internal.h"
 
#include "core/tcp.h"
 
#include "network_client.h"
 
#include "network_gamelist.h"
 
#include "network_gui.h"
 
#include "../saveload.h"
 
#include "../command_func.h"
 
@@ -935,7 +935,42 @@ NetworkRecvStatus NetworkClient_ReadPack
 
		delete p;
 
	}
 

	
 
	return res;
 
}
 

	
 
void NetworkClientSendRcon(const char *password, const char *command)
 
{
 
	SEND_COMMAND(PACKET_CLIENT_RCON)(password, command);
 
}
 

	
 
void NetworkUpdatePlayerName()
 
{
 
	NetworkClientInfo *ci = NetworkFindClientInfoFromIndex(_network_own_client_index);
 

	
 
	if (ci == NULL) return;
 

	
 
	/* Don't change the name if it is the same as the old name */
 
	if (strcmp(ci->client_name, _settings_client.network.player_name) != 0) {
 
		if (!_network_server) {
 
			SEND_COMMAND(PACKET_CLIENT_SET_NAME)(_settings_client.network.player_name);
 
		} else {
 
			if (NetworkFindName(_settings_client.network.player_name)) {
 
				NetworkTextMessage(NETWORK_ACTION_NAME_CHANGE, CC_DEFAULT, false, ci->client_name, "%s", _settings_client.network.player_name);
 
				ttd_strlcpy(ci->client_name, _settings_client.network.player_name, sizeof(ci->client_name));
 
				NetworkUpdateClientInfo(NETWORK_SERVER_INDEX);
 
			}
 
		}
 
	}
 
}
 

	
 
void NetworkClientSendChat(NetworkAction action, DestType type, int dest, const char *msg)
 
{
 
	SEND_COMMAND(PACKET_CLIENT_CHAT)(action, type, dest, msg);
 
}
 

	
 
void NetworkClientSetPassword()
 
{
 
	SEND_COMMAND(PACKET_CLIENT_SET_PASSWORD)(_network_player_info[_local_player].password);
 
}
 

	
 
#endif /* ENABLE_NETWORK */
src/network/network_data.cpp
Show inline comments
 
@@ -3,13 +3,13 @@
 
/** @file network_data.cpp Command handling over network connections. */
 

	
 
#ifdef ENABLE_NETWORK
 

	
 
#include "../stdafx.h"
 
#include "../debug.h"
 
#include "network_data.h"
 
#include "network_internal.h"
 
#include "network_client.h"
 
#include "../command_func.h"
 
#include "../callback_table.h"
 
#include "../core/alloc_func.hpp"
 
#include "../string_func.h"
 
#include "../date_func.h"
src/network/network_data.h
Show inline comments
 
deleted file
src/network/network_func.h
Show inline comments
 
new file 100644
 
/* $Id$ */
 

	
 
/** @file network_internal.h Variables and function used internally. */
 

	
 
#ifndef NETWORK_FUNC_H
 
#define NETWORK_FUNC_H
 

	
 
#ifdef ENABLE_NETWORK
 

	
 
#include "network_type.h"
 
#include "../console_type.h"
 

	
 
extern NetworkGameInfo _network_game_info;
 
extern NetworkPlayerInfo _network_player_info[MAX_PLAYERS];
 
extern NetworkClientInfo _network_client_info[MAX_CLIENT_INFO];
 

	
 
extern uint16 _network_own_client_index;
 
extern uint16 _redirect_console_to_client;
 
extern bool _network_need_advertise;
 
extern uint32 _network_last_advertise_frame;
 
extern uint8 _network_reconnect;
 
extern char *_network_host_list[10];
 
extern char *_network_ban_list[25];
 

	
 
byte NetworkSpectatorCount();
 
void CheckMinPlayers();
 
void NetworkUpdatePlayerName();
 
bool NetworkCompanyHasPlayers(PlayerID company);
 
bool NetworkChangeCompanyPassword(byte argc, char *argv[]);
 
void NetworkReboot();
 
void NetworkDisconnect();
 
void NetworkGameLoop();
 
void NetworkUDPGameLoop();
 
void NetworkUDPCloseAll();
 
void ParseConnectionString(const char **player, const char **port, char *connection_string);
 
void NetworkStartDebugLog(const char *hostname, uint16 port);
 
void NetworkPopulateCompanyInfo();
 

	
 
void NetworkUpdateClientInfo(uint16 client_index);
 
bool NetworkClientConnectGame(const char *host, uint16 port);
 
void NetworkClientSendRcon(const char *password, const char *command);
 
void NetworkClientSendChat(NetworkAction action, DestType type, int dest, const char *msg);
 
void NetworkClientSetPassword();
 

	
 
/*** Commands ran by the server ***/
 
void NetworkServerMonthlyLoop();
 
void NetworkServerYearlyLoop();
 
void NetworkServerChangeOwner(PlayerID current_player, PlayerID new_player);
 
void NetworkServerShowStatusToConsole();
 
bool NetworkServerStart();
 

	
 
NetworkClientInfo *NetworkFindClientInfoFromIndex(uint16 client_index);
 
NetworkClientInfo *NetworkFindClientInfoFromIP(const char *ip);
 
const char* GetPlayerIP(const NetworkClientInfo *ci);
 

	
 
void NetworkServerSendRcon(uint16 client_index, ConsoleColour colour_code, const char *string);
 
void NetworkServerSendError(uint16 client_index, NetworkErrorCode error);
 
void NetworkServerSendChat(NetworkAction action, DestType type, int dest, const char *msg, uint16 from_index);
 

	
 
#define FOR_ALL_ACTIVE_CLIENT_INFOS(ci) for (ci = _network_client_info; ci != endof(_network_client_info); ci++) if (ci->client_index != NETWORK_EMPTY_INDEX)
 

	
 
#endif /* ENABLE_NETWORK */
 
#endif /* NETWORK_FUNC_H */
src/network/network_gamelist.cpp
Show inline comments
 
@@ -8,12 +8,13 @@
 
#ifdef ENABLE_NETWORK
 

	
 
#include "../stdafx.h"
 
#include "../debug.h"
 
#include "../newgrf_config.h"
 
#include "../core/alloc_func.hpp"
 
#include "network_internal.h"
 
#include "core/game.h"
 
#include "network_udp.h"
 
#include "network_gamelist.h"
 
#include "network_gui.h"
 

	
 
NetworkGameList *_network_game_list = NULL;
src/network/network_gamelist.h
Show inline comments
 
@@ -2,12 +2,14 @@
 

	
 
/** @file network_gamelist.h Handling of the list of games. */
 

	
 
#ifndef NETWORK_GAMELIST_H
 
#define NETWORK_GAMELIST_H
 

	
 
#include "network_type.h"
 

	
 
/** Structure with information shown in the game list (GUI) */
 
struct NetworkGameList {
 
	NetworkGameInfo info;  ///< The game information of this server
 
	uint32 ip;             ///< The IP of the game server
 
	uint16 port;           ///< The port of the game server
 
	bool online;           ///< False if the server did not respond (default status)
src/network/network_gui.cpp
Show inline comments
 
@@ -6,13 +6,13 @@
 
#include "../stdafx.h"
 
#include "../openttd.h"
 
#include "../strings_func.h"
 
#include "network.h"
 
#include "../date_func.h"
 
#include "../fios.h"
 
#include "network_data.h"
 
#include "network_internal.h"
 
#include "network_client.h"
 
#include "network_gui.h"
 
#include "network_gamelist.h"
 
#include "../gui.h"
 
#include "../window_gui.h"
 
#include "../textbuf_gui.h"
 
@@ -1556,12 +1556,18 @@ void ShowNetworkNeedPassword(NetworkPass
 
		case NETWORK_GAME_PASSWORD:    caption = STR_NETWORK_NEED_GAME_PASSWORD_CAPTION; break;
 
		case NETWORK_COMPANY_PASSWORD: caption = STR_NETWORK_NEED_COMPANY_PASSWORD_CAPTION; break;
 
	}
 
	ShowQueryString(STR_EMPTY, caption, 20, 180, FindWindowById(WC_NETWORK_STATUS_WINDOW, 0), CS_ALPHANUMERAL);
 
}
 

	
 
// Vars needed for the join-GUI
 
NetworkJoinStatus _network_join_status;
 
uint8 _network_join_waiting;
 
uint16 _network_join_kbytes;
 
uint16 _network_join_kbytes_total;
 

	
 
struct NetworkJoinStatusWindow : Window {
 
	NetworkJoinStatusWindow(const WindowDesc *desc) : Window(desc)
 
	{
 
		this->parent = FindWindowById(WC_NETWORK_WINDOW, 0);
 
	}
 

	
 
@@ -1637,13 +1643,13 @@ void ShowJoinStatusWindow()
 
static void SendChat(const char *buf, DestType type, int dest)
 
{
 
	if (StrEmpty(buf)) return;
 
	if (!_network_server) {
 
		SEND_COMMAND(PACKET_CLIENT_CHAT)((NetworkAction)(NETWORK_ACTION_CHAT + type), type, dest, buf);
 
	} else {
 
		NetworkServer_HandleChat((NetworkAction)(NETWORK_ACTION_CHAT + type), type, dest, buf, NETWORK_SERVER_INDEX);
 
		NetworkServerSendChat((NetworkAction)(NETWORK_ACTION_CHAT + type), type, dest, buf, NETWORK_SERVER_INDEX);
 
	}
 
}
 

	
 

	
 
struct NetworkChatWindow : public QueryStringBaseWindow {
 
	DestType dtype;
src/network/network_gui.h
Show inline comments
 
@@ -2,17 +2,16 @@
 

	
 
/** @file network_gui.h GUIs related to networking. */
 

	
 
#ifndef NETWORK_GUI_H
 
#define NETWORK_GUI_H
 

	
 
#include "../window_type.h"
 

	
 
#ifdef ENABLE_NETWORK
 

	
 
#include "network_data.h"
 
#include "../window_type.h"
 
#include "network_type.h"
 

	
 
void ShowNetworkNeedPassword(NetworkPasswordType npt);
 
void ShowNetworkGiveMoneyWindow(PlayerID player); // PlayerID
 
void ShowNetworkChatQueryWindow(DestType type, int dest);
 
void ShowJoinStatusWindow();
 
void ShowNetworkGameWindow();
src/network/network_internal.h
Show inline comments
 
@@ -4,16 +4,19 @@
 

	
 
#ifndef NETWORK_INTERNAL_H
 
#define NETWORK_INTERNAL_H
 

	
 
#ifdef ENABLE_NETWORK
 

	
 
#include "../player_type.h"
 
#include "../economy_type.h"
 
#include "network.h"
 
#include "network_func.h"
 
#include "core/os_abstraction.h"
 
#include "core/core.h"
 
#include "core/config.h"
 
#include "core/game.h"
 
#include "core/packet.h"
 
#include "core/tcp.h"
 

	
 
/**
 
 * If this line is enable, every frame will have a sync test
 
 *  this is not needed in normal games. Normal is like 1 sync in 100
 
 *  frames. You can enable this if you have a lot of desyncs on a certain
 
 *  game.
 
@@ -26,56 +29,20 @@
 
/**
 
 * In theory sending 1 of the 2 seeds is enough to check for desyncs
 
 *   so in theory, this next define can be left off.
 
 */
 
//#define NETWORK_SEND_DOUBLE_SEED
 

	
 

	
 
enum {
 
	/**
 
	 * How many clients can we have? Like.. MAX_PLAYERS - 1 is the amount of
 
	 *  players that can really play.. so.. a max of 4 spectators.. gives us..
 
	 *  MAX_PLAYERS + 3
 
	 */
 
	MAX_CLIENTS = MAX_PLAYERS + 3,
 
#define MAX_TEXT_MSG_LEN 1024 /* long long long long sentences :-) */
 

	
 
	/** Do not change this next line. It should _ALWAYS_ be MAX_CLIENTS + 1 */
 
	MAX_CLIENT_INFO = MAX_CLIENTS + 1,
 

	
 
	/** Maximum number of internet interfaces supported. */
 
	MAX_INTERFACES = 9,
 

	
 
	/** How many vehicle/station types we put over the network */
 
	NETWORK_VEHICLE_TYPES = 5,
 
	NETWORK_STATION_TYPES = 5,
 
enum MapPacket {
 
	MAP_PACKET_START,
 
	MAP_PACKET_NORMAL,
 
	MAP_PACKET_END,
 
};
 

	
 
struct NetworkPlayerInfo {
 
	char company_name[NETWORK_NAME_LENGTH];         ///< Company name
 
	char password[NETWORK_PASSWORD_LENGTH];         ///< The password for the player
 
	Year inaugurated_year;                          ///< What year the company started in
 
	Money company_value;                            ///< The company value
 
	Money money;                                    ///< The amount of money the company has
 
	Money income;                                   ///< How much did the company earned last year
 
	uint16 performance;                             ///< What was his performance last month?
 
	bool use_password;                              ///< Is there a password
 
	uint16 num_vehicle[NETWORK_VEHICLE_TYPES];      ///< How many vehicles are there of this type?
 
	uint16 num_station[NETWORK_STATION_TYPES];      ///< How many stations are there of this type?
 
	char players[NETWORK_PLAYERS_LENGTH];           ///< The players that control this company (Name1, name2, ..)
 
	uint16 months_empty;                            ///< How many months the company is empty
 
};
 

	
 
struct NetworkClientInfo {
 
	uint16 client_index;                            ///< Index of the client (same as ClientState->index)
 
	char client_name[NETWORK_CLIENT_NAME_LENGTH];   ///< Name of the client
 
	byte client_lang;                               ///< The language of the client
 
	PlayerID client_playas;                         ///< As which player is this client playing (PlayerID)
 
	uint32 client_ip;                               ///< IP-address of the client (so he can be banned)
 
	Date join_date;                                 ///< Gamedate the player has joined
 
	char unique_id[NETWORK_UNIQUE_ID_LENGTH];       ///< Every play sends an unique id so we can indentify him
 
};
 

	
 
enum NetworkJoinStatus {
 
	NETWORK_JOIN_STATUS_CONNECTING,
 
	NETWORK_JOIN_STATUS_AUTHORIZING,
 
	NETWORK_JOIN_STATUS_WAITING,
 
	NETWORK_JOIN_STATUS_DOWNLOADING,
 
@@ -123,73 +90,86 @@ enum NetworkLanguage {
 
	NETLANG_GALICIAN,
 
	NETLANG_GREEK,
 
	NETLANG_LATVIAN,
 
	NETLANG_COUNT
 
};
 

	
 
VARDEF NetworkGameInfo _network_game_info;
 
VARDEF NetworkPlayerInfo _network_player_info[MAX_PLAYERS];
 
VARDEF NetworkClientInfo _network_client_info[MAX_CLIENT_INFO];
 
#define VARDEF extern
 

	
 
extern NetworkGameInfo _network_game_info;
 
extern NetworkPlayerInfo _network_player_info[MAX_PLAYERS];
 

	
 
VARDEF uint16 _network_own_client_index;
 
extern uint32 _frame_counter_server; // The frame_counter of the server, if in network-mode
 
extern uint32 _frame_counter_max; // To where we may go with our clients
 

	
 
VARDEF uint32 _frame_counter_server; // The frame_counter of the server, if in network-mode
 
VARDEF uint32 _frame_counter_max; // To where we may go with our clients
 

	
 
VARDEF uint32 _last_sync_frame; // Used in the server to store the last time a sync packet was sent to clients.
 
extern uint32 _last_sync_frame; // Used in the server to store the last time a sync packet was sent to clients.
 

	
 
// networking settings
 
VARDEF uint32 _broadcast_list[MAX_INTERFACES + 1];
 
extern uint32 _broadcast_list[MAX_INTERFACES + 1];
 

	
 
VARDEF uint32 _network_server_bind_ip;
 
VARDEF bool _is_network_server; // Does this client wants to be a network-server?
 
extern uint32 _network_server_bind_ip;
 

	
 
VARDEF uint16 _redirect_console_to_client;
 

	
 
VARDEF uint32 _sync_seed_1, _sync_seed_2;
 
VARDEF uint32 _sync_frame;
 
VARDEF bool _network_first_time;
 
extern uint32 _sync_seed_1, _sync_seed_2;
 
extern uint32 _sync_frame;
 
extern bool _network_first_time;
 
// Vars needed for the join-GUI
 
VARDEF NetworkJoinStatus _network_join_status;
 
VARDEF uint8 _network_join_waiting;
 
VARDEF uint16 _network_join_kbytes;
 
VARDEF uint16 _network_join_kbytes_total;
 
extern NetworkJoinStatus _network_join_status;
 
extern uint8 _network_join_waiting;
 
extern uint16 _network_join_kbytes;
 
extern uint16 _network_join_kbytes_total;
 

	
 
extern uint32 _network_last_host_ip;
 
extern uint8 _network_reconnect;
 

	
 
VARDEF uint32 _network_last_host_ip;
 
VARDEF uint8 _network_reconnect;
 
extern bool _network_udp_server;
 
extern uint16 _network_udp_broadcast;
 

	
 
extern uint8 _network_advertise_retries;
 

	
 
VARDEF bool _network_udp_server;
 
VARDEF uint16 _network_udp_broadcast;
 
// following externs are instantiated at network.cpp
 
extern CommandPacket *_local_command_queue;
 

	
 
VARDEF bool _network_need_advertise;
 
VARDEF uint32 _network_last_advertise_frame;
 
VARDEF uint8 _network_advertise_retries;
 
// Here we keep track of the clients
 
//  (and the client uses [0] for his own communication)
 
extern NetworkTCPSocketHandler _clients[MAX_CLIENTS];
 

	
 
void NetworkTCPQueryServer(const char* host, unsigned short port);
 

	
 
byte NetworkSpectatorCount();
 

	
 
VARDEF char *_network_host_list[10];
 
VARDEF char *_network_ban_list[25];
 

	
 
void ParseConnectionString(const char **player, const char **port, char *connection_string);
 
void NetworkUpdateClientInfo(uint16 client_index);
 
void NetworkAddServer(const char *b);
 
void NetworkRebuildHostList();
 
bool NetworkChangeCompanyPassword(byte argc, char *argv[]);
 
void NetworkPopulateCompanyInfo();
 
void UpdateNetworkGameWindow(bool unselect);
 
void CheckMinPlayers();
 
void NetworkStartDebugLog(const char *hostname, uint16 port);
 

	
 
void NetworkUDPCloseAll();
 
void NetworkGameLoop();
 
void NetworkUDPGameLoop();
 
bool NetworkServerStart();
 
bool NetworkClientConnectGame(const char *host, uint16 port);
 
void NetworkReboot();
 
void NetworkDisconnect();
 

	
 
bool IsNetworkCompatibleVersion(const char *version);
 

	
 
void NetworkExecuteCommand(CommandPacket *cp);
 
void NetworkAddCommandQueue(NetworkTCPSocketHandler *cs, CommandPacket *cp);
 

	
 
// from network.c
 
void NetworkCloseClient(NetworkTCPSocketHandler *cs);
 
void CDECL NetworkTextMessage(NetworkAction action, ConsoleColour color, bool self_send, const char *name, const char *str, ...);
 
void NetworkGetClientName(char *clientname, size_t size, const NetworkTCPSocketHandler *cs);
 
uint NetworkCalculateLag(const NetworkTCPSocketHandler *cs);
 
byte NetworkGetCurrentLanguageIndex();
 
NetworkTCPSocketHandler *NetworkFindClientStateFromIndex(uint16 client_index);
 
unsigned long NetworkResolveHost(const char *hostname);
 
char* GetNetworkErrorMsg(char* buf, NetworkErrorCode err, const char* last);
 
bool NetworkFindName(char new_name[NETWORK_CLIENT_NAME_LENGTH]);
 

	
 
#define DEREF_CLIENT(i) (&_clients[i])
 
// This returns the NetworkClientInfo from a NetworkClientState
 
#define DEREF_CLIENT_INFO(cs) (&_network_client_info[cs - _clients])
 

	
 
// Macros to make life a bit more easier
 
#define DEF_CLIENT_RECEIVE_COMMAND(type) NetworkRecvStatus NetworkPacketReceive_ ## type ## _command(Packet *p)
 
#define DEF_CLIENT_SEND_COMMAND(type) void NetworkPacketSend_ ## type ## _command()
 
#define DEF_CLIENT_SEND_COMMAND_PARAM(type) void NetworkPacketSend_ ## type ## _command
 
#define DEF_SERVER_RECEIVE_COMMAND(type) void NetworkPacketReceive_ ## type ## _command(NetworkTCPSocketHandler *cs, Packet *p)
 
#define DEF_SERVER_SEND_COMMAND(type) void NetworkPacketSend_ ## type ## _command(NetworkTCPSocketHandler *cs)
 
#define DEF_SERVER_SEND_COMMAND_PARAM(type) void NetworkPacketSend_ ## type ## _command
 

	
 
#define SEND_COMMAND(type) NetworkPacketSend_ ## type ## _command
 
#define RECEIVE_COMMAND(type) NetworkPacketReceive_ ## type ## _command
 

	
 
#define FOR_ALL_CLIENTS(cs) for (cs = _clients; cs != endof(_clients) && cs->IsConnected(); cs++)
 

	
 
#endif /* ENABLE_NETWORK */
 
#endif /* NETWORK_INTERNAL_H */
src/network/network_server.cpp
Show inline comments
 
@@ -5,13 +5,13 @@
 
#ifdef ENABLE_NETWORK
 

	
 
#include "../stdafx.h"
 
#include "../openttd.h" // XXX StringID
 
#include "../debug.h"
 
#include "../strings_func.h"
 
#include "network_data.h"
 
#include "network_internal.h"
 
#include "core/tcp.h"
 
#include "../vehicle_base.h"
 
#include "../vehicle_func.h"
 
#include "../date_func.h"
 
#include "network_server.h"
 
#include "network_udp.h"
 
@@ -801,13 +801,13 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT
 
		}
 

	
 
		if (_settings_client.network.pause_on_join) {
 
			/* Now pause the game till the client is in sync */
 
			DoCommandP(0, 1, 0, NULL, CMD_PAUSE);
 

	
 
			NetworkServer_HandleChat(NETWORK_ACTION_SERVER_MESSAGE, DESTTYPE_BROADCAST, 0, "Game paused (incoming client)", NETWORK_SERVER_INDEX);
 
			NetworkServerSendChat(NETWORK_ACTION_SERVER_MESSAGE, DESTTYPE_BROADCAST, 0, "Game paused (incoming client)", NETWORK_SERVER_INDEX);
 
		}
 
	} else {
 
		// Wrong status for this packet, give a warning to client, and close connection
 
		SEND_COMMAND(PACKET_SERVER_ERROR)(cs, NETWORK_ERROR_NOT_EXPECTED);
 
	}
 
}
 
@@ -1020,13 +1020,13 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT
 

	
 
		/* Now he is! Unpause the game */
 
		cs->status = STATUS_ACTIVE;
 

	
 
		if (_settings_client.network.pause_on_join) {
 
			DoCommandP(0, 0, 0, NULL, CMD_PAUSE);
 
			NetworkServer_HandleChat(NETWORK_ACTION_SERVER_MESSAGE, DESTTYPE_BROADCAST, 0, "Game unpaused (client connected)", NETWORK_SERVER_INDEX);
 
			NetworkServerSendChat(NETWORK_ACTION_SERVER_MESSAGE, DESTTYPE_BROADCAST, 0, "Game unpaused (client connected)", NETWORK_SERVER_INDEX);
 
		}
 

	
 
		CheckMinPlayers();
 

	
 
		/* Execute script for, e.g. MOTD */
 
		IConsoleCmdExec("exec scripts/on_server_connect.scr 0");
 
@@ -1037,13 +1037,13 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT
 
	// With those 2 values we can calculate the lag realtime
 
	cs->last_frame_server = _frame_counter;
 
}
 

	
 

	
 

	
 
void NetworkServer_HandleChat(NetworkAction action, DestType desttype, int dest, const char *msg, uint16 from_index)
 
void NetworkServerSendChat(NetworkAction action, DestType desttype, int dest, const char *msg, uint16 from_index)
 
{
 
	NetworkTCPSocketHandler *cs;
 
	const NetworkClientInfo *ci, *ci_own, *ci_to;
 

	
 
	switch (desttype) {
 
	case DESTTYPE_CLIENT:
 
@@ -1143,13 +1143,13 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT
 
	DestType desttype = (DestType)p->Recv_uint8();
 
	int dest = p->Recv_uint16();
 
	char msg[MAX_TEXT_MSG_LEN];
 

	
 
	p->Recv_string(msg, MAX_TEXT_MSG_LEN);
 

	
 
	NetworkServer_HandleChat(action, desttype, dest, msg, cs->index);
 
	NetworkServerSendChat(action, desttype, dest, msg, cs->index);
 
}
 

	
 
DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_SET_PASSWORD)
 
{
 
	char password[NETWORK_PASSWORD_LENGTH];
 
	const NetworkClientInfo *ci;
 
@@ -1579,7 +1579,85 @@ void NetworkServerYearlyLoop()
 

	
 
void NetworkServerMonthlyLoop()
 
{
 
	NetworkAutoCleanCompanies();
 
}
 

	
 
void NetworkServerChangeOwner(PlayerID current_player, PlayerID new_player)
 
{
 
	/* The server has to handle all administrative issues, for example
 
	 * updating and notifying all clients of what has happened */
 
	NetworkTCPSocketHandler *cs;
 
	NetworkClientInfo *ci = NetworkFindClientInfoFromIndex(NETWORK_SERVER_INDEX);
 

	
 
	/* The server has just changed from player */
 
	if (current_player == ci->client_playas) {
 
		ci->client_playas = new_player;
 
		NetworkUpdateClientInfo(NETWORK_SERVER_INDEX);
 
	}
 

	
 
	/* Find all clients that were in control of this company, and mark them as new_player */
 
	FOR_ALL_CLIENTS(cs) {
 
		ci = DEREF_CLIENT_INFO(cs);
 
		if (current_player == ci->client_playas) {
 
			ci->client_playas = new_player;
 
			NetworkUpdateClientInfo(ci->client_index);
 
		}
 
	}
 
}
 

	
 
const char* GetPlayerIP(const NetworkClientInfo* ci)
 
{
 
	struct in_addr addr;
 

	
 
	addr.s_addr = ci->client_ip;
 
	return inet_ntoa(addr);
 
}
 

	
 
void NetworkServerShowStatusToConsole()
 
{
 
	static const char* const stat_str[] = {
 
		"inactive",
 
		"authorizing",
 
		"authorized",
 
		"waiting",
 
		"loading map",
 
		"map done",
 
		"ready",
 
		"active"
 
	};
 

	
 
	NetworkTCPSocketHandler *cs;
 
	FOR_ALL_CLIENTS(cs) {
 
		int lag = NetworkCalculateLag(cs);
 
		const NetworkClientInfo *ci = DEREF_CLIENT_INFO(cs);
 
		const char* status;
 

	
 
		status = (cs->status < (ptrdiff_t)lengthof(stat_str) ? stat_str[cs->status] : "unknown");
 
		IConsolePrintF(CC_INFO, "Client #%1d  name: '%s'  status: '%s'  frame-lag: %3d  company: %1d  IP: %s  unique-id: '%s'",
 
			cs->index, ci->client_name, status, lag,
 
			ci->client_playas + (IsValidPlayer(ci->client_playas) ? 1 : 0),
 
			GetPlayerIP(ci), ci->unique_id);
 
	}
 
}
 

	
 
void NetworkServerSendRcon(uint16 client_index, ConsoleColour colour_code, const char *string)
 
{
 
	SEND_COMMAND(PACKET_SERVER_RCON)(NetworkFindClientStateFromIndex(client_index), colour_code, string);
 
}
 

	
 
void NetworkServerSendError(uint16 client_index, NetworkErrorCode error)
 
{
 
	SEND_COMMAND(PACKET_SERVER_ERROR)(NetworkFindClientStateFromIndex(client_index), error);
 
}
 

	
 
bool NetworkCompanyHasPlayers(PlayerID company)
 
{
 
	const NetworkTCPSocketHandler *cs;
 
	const NetworkClientInfo *ci;
 
	FOR_ALL_CLIENTS(cs) {
 
		ci = DEREF_CLIENT_INFO(cs);
 
		if (ci->client_playas == company) return true;
 
	}
 
	return false;
 
}
 
#endif /* ENABLE_NETWORK */
src/network/network_server.h
Show inline comments
 
@@ -11,27 +11,14 @@ DEF_SERVER_SEND_COMMAND(PACKET_SERVER_MA
 
DEF_SERVER_SEND_COMMAND_PARAM(PACKET_SERVER_ERROR_QUIT)(NetworkTCPSocketHandler *cs, uint16 client_index, NetworkErrorCode errorno);
 
DEF_SERVER_SEND_COMMAND_PARAM(PACKET_SERVER_ERROR)(NetworkTCPSocketHandler *cs, NetworkErrorCode error);
 
DEF_SERVER_SEND_COMMAND(PACKET_SERVER_SHUTDOWN);
 
DEF_SERVER_SEND_COMMAND(PACKET_SERVER_NEWGAME);
 
DEF_SERVER_SEND_COMMAND_PARAM(PACKET_SERVER_RCON)(NetworkTCPSocketHandler *cs, uint16 color, const char *command);
 

	
 
bool NetworkFindName(char new_name[NETWORK_CLIENT_NAME_LENGTH]);
 
void NetworkServer_HandleChat(NetworkAction action, DestType type, int dest, const char *msg, uint16 from_index);
 

	
 
bool NetworkServer_ReadPackets(NetworkTCPSocketHandler *cs);
 
void NetworkServer_Tick(bool send_frame);
 
void NetworkServerMonthlyLoop();
 
void NetworkServerYearlyLoop();
 

	
 
static inline const char* GetPlayerIP(const NetworkClientInfo* ci)
 
{
 
	struct in_addr addr;
 

	
 
	addr.s_addr = ci->client_ip;
 
	return inet_ntoa(addr);
 
}
 

	
 
#else /* ENABLE_NETWORK */
 
/* Network function stubs when networking is disabled */
 

	
 
static inline void NetworkServerMonthlyLoop() {}
 
static inline void NetworkServerYearlyLoop() {}
src/network/network_type.h
Show inline comments
 
new file 100644
 
/* $Id$ */
 

	
 
/** @file network_internal.h Variables and function used internally. */
 

	
 
#ifndef NETWORK_TYPE_H
 
#define NETWORK_TYPE_H
 

	
 
#ifdef ENABLE_NETWORK
 

	
 
#include "../player_type.h"
 
#include "../economy_type.h"
 
#include "core/config.h"
 
#include "core/game.h"
 

	
 
enum {
 
	/**
 
	 * How many clients can we have? Like.. MAX_PLAYERS - 1 is the amount of
 
	 *  players that can really play.. so.. a max of 4 spectators.. gives us..
 
	 *  MAX_PLAYERS + 3
 
	 */
 
	MAX_CLIENTS = MAX_PLAYERS + 3,
 

	
 
	/** Do not change this next line. It should _ALWAYS_ be MAX_CLIENTS + 1 */
 
	MAX_CLIENT_INFO = MAX_CLIENTS + 1,
 

	
 
	/** Maximum number of internet interfaces supported. */
 
	MAX_INTERFACES = 9,
 

	
 
	/** How many vehicle/station types we put over the network */
 
	NETWORK_VEHICLE_TYPES = 5,
 
	NETWORK_STATION_TYPES = 5,
 

	
 
	NETWORK_SERVER_INDEX = 1,
 
	NETWORK_EMPTY_INDEX  = 0,
 
};
 

	
 
struct NetworkPlayerInfo {
 
	char company_name[NETWORK_NAME_LENGTH];         ///< Company name
 
	char password[NETWORK_PASSWORD_LENGTH];         ///< The password for the player
 
	Year inaugurated_year;                          ///< What year the company started in
 
	Money company_value;                            ///< The company value
 
	Money money;                                    ///< The amount of money the company has
 
	Money income;                                   ///< How much did the company earned last year
 
	uint16 performance;                             ///< What was his performance last month?
 
	bool use_password;                              ///< Is there a password
 
	uint16 num_vehicle[NETWORK_VEHICLE_TYPES];      ///< How many vehicles are there of this type?
 
	uint16 num_station[NETWORK_STATION_TYPES];      ///< How many stations are there of this type?
 
	char players[NETWORK_PLAYERS_LENGTH];           ///< The players that control this company (Name1, name2, ..)
 
	uint16 months_empty;                            ///< How many months the company is empty
 
};
 

	
 
struct NetworkClientInfo {
 
	uint16 client_index;                            ///< Index of the client (same as ClientState->index)
 
	char client_name[NETWORK_CLIENT_NAME_LENGTH];   ///< Name of the client
 
	byte client_lang;                               ///< The language of the client
 
	PlayerID client_playas;                         ///< As which player is this client playing (PlayerID)
 
	uint32 client_ip;                               ///< IP-address of the client (so he can be banned)
 
	Date join_date;                                 ///< Gamedate the player has joined
 
	char unique_id[NETWORK_UNIQUE_ID_LENGTH];       ///< Every play sends an unique id so we can indentify him
 
};
 

	
 
enum NetworkPasswordType {
 
	NETWORK_GAME_PASSWORD,
 
	NETWORK_COMPANY_PASSWORD,
 
};
 

	
 
enum DestType {
 
	DESTTYPE_BROADCAST, ///< Send message/notice to all players (All)
 
	DESTTYPE_TEAM,      ///< Send message/notice to everyone playing the same company (Team)
 
	DESTTYPE_CLIENT,    ///< Send message/notice to only a certain player (Private)
 
};
 

	
 
/** Actions that can be used for NetworkTextMessage */
 
enum NetworkAction {
 
	NETWORK_ACTION_JOIN,
 
	NETWORK_ACTION_LEAVE,
 
	NETWORK_ACTION_SERVER_MESSAGE,
 
	NETWORK_ACTION_CHAT,
 
	NETWORK_ACTION_CHAT_COMPANY,
 
	NETWORK_ACTION_CHAT_CLIENT,
 
	NETWORK_ACTION_GIVE_MONEY,
 
	NETWORK_ACTION_NAME_CHANGE,
 
};
 

	
 
enum NetworkErrorCode {
 
	NETWORK_ERROR_GENERAL, // Try to use this one like never
 

	
 
	/* Signals from clients */
 
	NETWORK_ERROR_DESYNC,
 
	NETWORK_ERROR_SAVEGAME_FAILED,
 
	NETWORK_ERROR_CONNECTION_LOST,
 
	NETWORK_ERROR_ILLEGAL_PACKET,
 
	NETWORK_ERROR_NEWGRF_MISMATCH,
 

	
 
	/* Signals from servers */
 
	NETWORK_ERROR_NOT_AUTHORIZED,
 
	NETWORK_ERROR_NOT_EXPECTED,
 
	NETWORK_ERROR_WRONG_REVISION,
 
	NETWORK_ERROR_NAME_IN_USE,
 
	NETWORK_ERROR_WRONG_PASSWORD,
 
	NETWORK_ERROR_PLAYER_MISMATCH, // Happens in CLIENT_COMMAND
 
	NETWORK_ERROR_KICKED,
 
	NETWORK_ERROR_CHEATER,
 
	NETWORK_ERROR_FULL,
 
};
 

	
 
#endif /* ENABLE_NETWORK */
 
#endif /* NETWORK_TYPE_H */
src/network/network_udp.cpp
Show inline comments
 
@@ -8,17 +8,17 @@
 
 */
 

	
 
#ifdef ENABLE_NETWORK
 

	
 
#include "../stdafx.h"
 
#include "../debug.h"
 
#include "network_data.h"
 
#include "../date_func.h"
 
#include "../map_func.h"
 
#include "network_gamelist.h"
 
#include "network_udp.h"
 
#include "network_internal.h"
 
#include "../variables.h"
 
#include "../newgrf_config.h"
 
#include "../core/endian_func.hpp"
 
#include "../string_func.h"
 
#include "../player_base.h"
 
#include "../player_func.h"
src/newgrf_config.cpp
Show inline comments
 
@@ -5,17 +5,17 @@
 
#include "stdafx.h"
 
#include "openttd.h"
 
#include "debug.h"
 
#include "variables.h"
 
#include "saveload.h"
 
#include "md5.h"
 
#include "network/network_data.h"
 
#include "newgrf.h"
 
#include "newgrf_config.h"
 
#include "core/alloc_func.hpp"
 
#include "string_func.h"
 
#include "network/network_type.h"
 

	
 
#include "fileio.h"
 
#include "fios.h"
 
#include <sys/stat.h>
 

	
 

	
src/openttd.cpp
Show inline comments
 
@@ -3,13 +3,12 @@
 
/** @file openttd.cpp Functions related to starting OpenTTD. */
 

	
 
#include "stdafx.h"
 

	
 
#define VARDEF
 
#include "variables.h"
 
#include "network/network_internal.h"
 
#undef VARDEF
 

	
 
#include "openttd.h"
 

	
 
#include "driver.h"
 
#include "blitter/factory.hpp"
 
@@ -38,12 +37,13 @@
 
#include "fios.h"
 
#include "airport.h"
 
#include "aircraft.h"
 
#include "console_func.h"
 
#include "screenshot.h"
 
#include "network/network.h"
 
#include "network/network_func.h"
 
#include "signs_base.h"
 
#include "signs_func.h"
 
#include "waypoint.h"
 
#include "ai/ai.h"
 
#include "train.h"
 
#include "yapf/yapf.h"
src/player_gui.cpp
Show inline comments
 
@@ -10,20 +10,18 @@
 
#include "viewport_func.h"
 
#include "gfx_func.h"
 
#include "player_func.h"
 
#include "player_base.h"
 
#include "command_func.h"
 
#include "network/network.h"
 
#include "network/network_gui.h"
 
#include "variables.h"
 
#include "roadveh.h"
 
#include "train.h"
 
#include "aircraft.h"
 
#include "newgrf.h"
 
#include "network/network_data.h"
 
#include "network/network_client.h"
 
#include "network/network_gui.h"
 
#include "player_face.h"
 
#include "strings_func.h"
 
#include "functions.h"
 
#include "window_func.h"
 
#include "date_func.h"
 
#include "string_func.h"
src/players.cpp
Show inline comments
 
@@ -10,13 +10,13 @@
 
#include "player_gui.h"
 
#include "town.h"
 
#include "news_func.h"
 
#include "saveload.h"
 
#include "command_func.h"
 
#include "network/network.h"
 
#include "network/network_internal.h"
 
#include "network/network_func.h"
 
#include "variables.h"
 
#include "cheat_func.h"
 
#include "ai/ai.h"
 
#include "player_face.h"
 
#include "group.h"
 
#include "window_func.h"
src/settings.cpp
Show inline comments
 
@@ -22,16 +22,13 @@
 
#include "stdafx.h"
 
#include "openttd.h"
 
#include "currency.h"
 
#include "screenshot.h"
 
#include "variables.h"
 
#include "network/network.h"
 
#include "network/network_data.h"
 
#include "network/network_client.h"
 
#include "network/network_server.h"
 
#include "network/network_udp.h"
 
#include "network/network_func.h"
 
#include "settings_internal.h"
 
#include "command_func.h"
 
#include "console_func.h"
 
#include "saveload.h"
 
#include "npf.h"
 
#include "yapf/yapf.h"
 
@@ -1443,29 +1440,13 @@ static int32 UpdateMinPlayers(int32 p1)
 
	CheckMinPlayers();
 
	return 0;
 
}
 

	
 
static int32 UpdatePlayerName(int32 p1)
 
{
 
	NetworkClientInfo *ci = NetworkFindClientInfoFromIndex(_network_own_client_index);
 

	
 
	if (ci == NULL) return 0;
 

	
 
	/* Don't change the name if it is the same as the old name */
 
	if (strcmp(ci->client_name, _settings_client.network.player_name) != 0) {
 
		if (!_network_server) {
 
			SEND_COMMAND(PACKET_CLIENT_SET_NAME)(_settings_client.network.player_name);
 
		} else {
 
			if (NetworkFindName(_settings_client.network.player_name)) {
 
				NetworkTextMessage(NETWORK_ACTION_NAME_CHANGE, CC_DEFAULT, false, ci->client_name, "%s", _settings_client.network.player_name);
 
				ttd_strlcpy(ci->client_name, _settings_client.network.player_name, sizeof(ci->client_name));
 
				NetworkUpdateClientInfo(NETWORK_SERVER_INDEX);
 
			}
 
		}
 
	}
 

	
 
	NetworkUpdatePlayerName();
 
	return 0;
 
}
 

	
 
static int32 UpdateServerName(int32 p1)
 
{
 
	ttd_strlcpy(_network_game_info.server_name, _settings_client.network.server_name, sizeof(_network_game_info.server_name));
src/vehicle.cpp
Show inline comments
 
@@ -22,13 +22,12 @@
 
#include "rail_type.h"
 
#include "train.h"
 
#include "aircraft.h"
 
#include "industry_map.h"
 
#include "station_map.h"
 
#include "water_map.h"
 
#include "network/network.h"
 
#include "yapf/yapf.h"
 
#include "newgrf_callbacks.h"
 
#include "newgrf_engine.h"
 
#include "newgrf_sound.h"
 
#include "newgrf_station.h"
 
#include "group.h"
0 comments (0 inline, 0 general)