(svn r6820) -Codechange: Some more const correctness, coding style.
-Codechange: Add FOR_ALL_ACTIVE_CLIENT_INFOS macro that will loop all clients skipping inactive ones.
This commit is contained in:
		@@ -658,10 +658,10 @@ DEF_CONSOLE_CMD(ConKick)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
DEF_CONSOLE_CMD(ConResetCompany)
 | 
					DEF_CONSOLE_CMD(ConResetCompany)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	Player *p;
 | 
						const Player *p;
 | 
				
			||||||
	NetworkClientState *cs;
 | 
						const NetworkClientState *cs;
 | 
				
			||||||
	NetworkClientInfo *ci;
 | 
						const NetworkClientInfo *ci;
 | 
				
			||||||
	byte index;
 | 
						PlayerID index;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (argc == 0) {
 | 
						if (argc == 0) {
 | 
				
			||||||
		IConsoleHelp("Remove an idle company from the game. Usage: 'reset_company <company-id>'");
 | 
							IConsoleHelp("Remove an idle company from the game. Usage: 'reset_company <company-id>'");
 | 
				
			||||||
@@ -721,14 +721,12 @@ DEF_CONSOLE_CMD(ConNetworkClients)
 | 
				
			|||||||
		return true;
 | 
							return true;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for (ci = _network_client_info; ci != &_network_client_info[MAX_CLIENT_INFO]; ci++) {
 | 
						FOR_ALL_ACTIVE_CLIENT_INFOS(ci) {
 | 
				
			||||||
		if (ci->client_index != NETWORK_EMPTY_INDEX) {
 | 
					 | 
				
			||||||
		IConsolePrintF(8, "Client #%1d  name: '%s'  company: %1d  IP: %s",
 | 
							IConsolePrintF(8, "Client #%1d  name: '%s'  company: %1d  IP: %s",
 | 
				
			||||||
		               ci->client_index, ci->client_name,
 | 
							               ci->client_index, ci->client_name,
 | 
				
			||||||
		               ci->client_playas + (IsValidPlayer(ci->client_playas) ? 1 : 0),
 | 
							               ci->client_playas + (IsValidPlayer(ci->client_playas) ? 1 : 0),
 | 
				
			||||||
		               GetPlayerIP(ci));
 | 
							               GetPlayerIP(ci));
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return true;
 | 
						return true;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -748,9 +746,7 @@ DEF_CONSOLE_CMD(ConNetworkConnect)
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (argc < 2) return false;
 | 
						if (argc < 2) return false;
 | 
				
			||||||
 | 
						if (_networking) NetworkDisconnect(); // we are in network-mode, first close it!
 | 
				
			||||||
	if (_networking) // We are in network-mode, first close it!
 | 
					 | 
				
			||||||
		NetworkDisconnect();
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	ip = argv[1];
 | 
						ip = argv[1];
 | 
				
			||||||
	/* Default settings: default port and new company */
 | 
						/* Default settings: default port and new company */
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -55,7 +55,7 @@ NetworkClientInfo *NetworkFindClientInfoFromIndex(uint16 client_index)
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
	NetworkClientInfo *ci;
 | 
						NetworkClientInfo *ci;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for (ci = _network_client_info; ci != &_network_client_info[MAX_CLIENT_INFO]; ci++) {
 | 
						for (ci = _network_client_info; ci != endof(_network_client_info); ci++) {
 | 
				
			||||||
		if (ci->client_index == client_index) return ci;
 | 
							if (ci->client_index == client_index) return ci;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -70,7 +70,7 @@ NetworkClientInfo *NetworkFindClientInfoFromIP(const char *ip)
 | 
				
			|||||||
	NetworkClientInfo *ci;
 | 
						NetworkClientInfo *ci;
 | 
				
			||||||
	uint32 ip_number = inet_addr(ip);
 | 
						uint32 ip_number = inet_addr(ip);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for (ci = _network_client_info; ci != &_network_client_info[MAX_CLIENT_INFO]; ci++) {
 | 
						for (ci = _network_client_info; ci != endof(_network_client_info); ci++) {
 | 
				
			||||||
		if (ci->client_ip == ip_number) return ci;
 | 
							if (ci->client_ip == ip_number) return ci;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -198,7 +198,8 @@ NetworkClientState _clients[MAX_CLIENTS];
 | 
				
			|||||||
#define SEND_COMMAND(type) NetworkPacketSend_ ## type ## _command
 | 
					#define SEND_COMMAND(type) NetworkPacketSend_ ## type ## _command
 | 
				
			||||||
#define RECEIVE_COMMAND(type) NetworkPacketReceive_ ## type ## _command
 | 
					#define RECEIVE_COMMAND(type) NetworkPacketReceive_ ## type ## _command
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define FOR_ALL_CLIENTS(cs) for (cs = _clients; cs != &_clients[MAX_CLIENTS] && cs->socket != INVALID_SOCKET; cs++)
 | 
					#define FOR_ALL_CLIENTS(cs) for (cs = _clients; cs != endof(_clients) && cs->socket != INVALID_SOCKET; cs++)
 | 
				
			||||||
 | 
					#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)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Packet *NetworkSend_Init(PacketType type);
 | 
					Packet *NetworkSend_Init(PacketType type);
 | 
				
			||||||
void NetworkSend_uint8(Packet *packet, uint8 data);
 | 
					void NetworkSend_uint8(Packet *packet, uint8 data);
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1048,9 +1048,7 @@ static const NetworkClientInfo *NetworkFindClientInfo(byte client_no)
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
	const NetworkClientInfo *ci;
 | 
						const NetworkClientInfo *ci;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for (ci = _network_client_info; ci != &_network_client_info[MAX_CLIENT_INFO]; ci++) {
 | 
						FOR_ALL_ACTIVE_CLIENT_INFOS(ci) {
 | 
				
			||||||
		// Skip non-active items
 | 
					 | 
				
			||||||
		if (ci->client_index == NETWORK_EMPTY_INDEX) continue;
 | 
					 | 
				
			||||||
		if (client_no == 0) return ci;
 | 
							if (client_no == 0) return ci;
 | 
				
			||||||
		client_no--;
 | 
							client_no--;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -1123,12 +1121,10 @@ static void HandleClientListPopupClick(byte index, byte clientno) {
 | 
				
			|||||||
static bool CheckClientListHeight(Window *w)
 | 
					static bool CheckClientListHeight(Window *w)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	int num = 0;
 | 
						int num = 0;
 | 
				
			||||||
	NetworkClientInfo *ci;
 | 
						const NetworkClientInfo *ci;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Should be replaced with a loop through all clients
 | 
						// Should be replaced with a loop through all clients
 | 
				
			||||||
	for (ci = _network_client_info; ci != &_network_client_info[MAX_CLIENT_INFO]; ci++) {
 | 
						FOR_ALL_ACTIVE_CLIENT_INFOS(ci) {
 | 
				
			||||||
		// Skip non-active items
 | 
					 | 
				
			||||||
		if (ci->client_index == NETWORK_EMPTY_INDEX) continue;
 | 
					 | 
				
			||||||
		num++;
 | 
							num++;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -1307,10 +1303,7 @@ static void ClientListWndProc(Window *w, WindowEvent *e)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
		y = CLNWND_OFFSET;
 | 
							y = CLNWND_OFFSET;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		for (ci = _network_client_info; ci != &_network_client_info[MAX_CLIENT_INFO]; ci++) {
 | 
							FOR_ALL_ACTIVE_CLIENT_INFOS(ci) {
 | 
				
			||||||
			// Skip non-active items
 | 
					 | 
				
			||||||
			if (ci->client_index == NETWORK_EMPTY_INDEX) continue;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
			if (_selected_clientlist_item == i++) { // Selected item, highlight it
 | 
								if (_selected_clientlist_item == i++) { // Selected item, highlight it
 | 
				
			||||||
				GfxFillRect(1, y, 248, y + CLNWND_ROWSIZE - 1, 0);
 | 
									GfxFillRect(1, y, 248, y + CLNWND_ROWSIZE - 1, 0);
 | 
				
			||||||
				colour = 0xC;
 | 
									colour = 0xC;
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user