Changeset - r17588:0297fca9cfa3
[Not reviewed]
master
0 11 0
rubidium - 14 years ago 2011-04-22 15:54:16
rubidium@openttd.org
(svn r22362) -Codechange: NetworkFindClientInfoFromClientID -> NetworkClientInfo::GetByClientID
11 files changed with 39 insertions and 38 deletions:
0 comments (0 inline, 0 general)
src/company_cmd.cpp
Show inline comments
 
@@ -812,7 +812,7 @@ CommandCost CmdCompanyCtrl(TileIndex til
 
#ifdef ENABLE_NETWORK
 
			/* Has the network client a correct ClientIndex? */
 
			if (!(flags & DC_EXEC)) return CommandCost();
 
			NetworkClientInfo *ci = NetworkFindClientInfoFromClientID(client_id);
 
			NetworkClientInfo *ci = NetworkClientInfo::GetByClientID(client_id);
 
			if (ci == NULL) return CommandCost();
 

	
 
			/* Delete multiplayer progress bar */
src/console_cmds.cpp
Show inline comments
 
@@ -500,7 +500,7 @@ static bool ConKickOrBan(const char *arg
 
			return true;
 
		}
 

	
 
		NetworkClientInfo *ci = NetworkFindClientInfoFromClientID(client_id);
 
		NetworkClientInfo *ci = NetworkClientInfo::GetByClientID(client_id);
 
		if (ci == NULL) {
 
			IConsoleError("Invalid client");
 
			return true;
 
@@ -695,7 +695,7 @@ DEF_CONSOLE_CMD(ConClientNickChange)
 
		return true;
 
	}
 

	
 
	if (NetworkFindClientInfoFromClientID(client_id) == NULL) {
 
	if (NetworkClientInfo::GetByClientID(client_id) == NULL) {
 
		IConsoleError("Invalid client");
 
		return true;
 
	}
 
@@ -723,7 +723,7 @@ DEF_CONSOLE_CMD(ConJoinCompany)
 
		return true;
 
	}
 

	
 
	if (NetworkFindClientInfoFromClientID(_network_own_client_id)->client_playas == company_id) {
 
	if (NetworkClientInfo::GetByClientID(_network_own_client_id)->client_playas == company_id) {
 
		IConsoleError("You are already there!");
 
		return true;
 
	}
 
@@ -762,7 +762,7 @@ DEF_CONSOLE_CMD(ConMoveClient)
 
		return true;
 
	}
 

	
 
	const NetworkClientInfo *ci = NetworkFindClientInfoFromClientID((ClientID)atoi(argv[1]));
 
	const NetworkClientInfo *ci = NetworkClientInfo::GetByClientID((ClientID)atoi(argv[1]));
 
	CompanyID company_id = (CompanyID)(atoi(argv[2]) <= MAX_COMPANIES ? atoi(argv[2]) - 1 : atoi(argv[2]));
 

	
 
	/* check the client exists */
 
@@ -824,7 +824,7 @@ DEF_CONSOLE_CMD(ConResetCompany)
 
		IConsoleError("Cannot remove company: a client is connected to that company.");
 
		return false;
 
	}
 
	const NetworkClientInfo *ci = NetworkFindClientInfoFromClientID(CLIENT_ID_SERVER);
 
	const NetworkClientInfo *ci = NetworkClientInfo::GetByClientID(CLIENT_ID_SERVER);
 
	if (ci->client_playas == index) {
 
		IConsoleError("Cannot remove company: the server is connected to that company.");
 
		return true;
src/main_gui.cpp
Show inline comments
 
@@ -377,7 +377,7 @@ struct MainWindow : Window
 
#ifdef ENABLE_NETWORK
 
			case GHK_CHAT: // smart chat; send to team if any, otherwise to all
 
				if (_networking) {
 
					const NetworkClientInfo *cio = NetworkFindClientInfoFromClientID(_network_own_client_id);
 
					const NetworkClientInfo *cio = NetworkClientInfo::GetByClientID(_network_own_client_id);
 
					if (cio == NULL) break;
 

	
 
					ShowNetworkChatQueryWindow(NetworkClientPreferTeamChat(cio) ? DESTTYPE_TEAM : DESTTYPE_BROADCAST, cio->client_playas);
 
@@ -390,7 +390,7 @@ struct MainWindow : Window
 

	
 
			case GHK_CHAT_COMPANY: // send text to all team mates
 
				if (_networking) {
 
					const NetworkClientInfo *cio = NetworkFindClientInfoFromClientID(_network_own_client_id);
 
					const NetworkClientInfo *cio = NetworkClientInfo::GetByClientID(_network_own_client_id);
 
					if (cio == NULL) break;
 

	
 
					ShowNetworkChatQueryWindow(DESTTYPE_TEAM, cio->client_playas);
src/network/network.cpp
Show inline comments
 
@@ -108,7 +108,7 @@ NetworkClientInfo::~NetworkClientInfo()
 
 * @param client_id the ClientID to search for
 
 * @return return a pointer to the corresponding NetworkClientInfo struct or NULL when not found
 
 */
 
NetworkClientInfo *NetworkFindClientInfoFromClientID(ClientID client_id)
 
/* static */ NetworkClientInfo *NetworkClientInfo::GetByClientID(ClientID client_id)
 
{
 
	NetworkClientInfo *ci;
 

	
src/network/network_admin.cpp
Show inline comments
 
@@ -576,7 +576,7 @@ DEF_ADMIN_RECEIVE_COMMAND(Server, ADMIN_
 
					this->SendClientInfo(ci);
 
				}
 
			} else {
 
				ci = NetworkFindClientInfoFromClientID((ClientID)d1);
 
				ci = NetworkClientInfo::GetByClientID((ClientID)d1);
 
				if (ci != NULL) this->SendClientInfo(ci);
 
			}
 
			break;
src/network/network_base.h
Show inline comments
 
@@ -32,6 +32,8 @@ struct NetworkClientInfo : NetworkClient
 

	
 
	NetworkClientInfo(ClientID client_id = INVALID_CLIENT_ID) : client_id(client_id) {}
 
	~NetworkClientInfo();
 

	
 
	static NetworkClientInfo *GetByClientID(ClientID client_id);
 
};
 

	
 
#define FOR_ALL_CLIENT_INFOS_FROM(var, start) FOR_ALL_ITEMS_FROM(NetworkClientInfo, clientinfo_index, var, start)
src/network/network_chat_gui.cpp
Show inline comments
 
@@ -468,7 +468,7 @@ struct NetworkChatWindow : public QueryS
 
		if (widget != NWCW_DESTINATION) return;
 

	
 
		if (this->dtype == DESTTYPE_CLIENT) {
 
			SetDParamStr(0, NetworkFindClientInfoFromClientID((ClientID)this->dest)->client_name);
 
			SetDParamStr(0, NetworkClientInfo::GetByClientID((ClientID)this->dest)->client_name);
 
		}
 
		Dimension d = GetStringBoundingBox(this->dest_string);
 
		d.width  += WD_FRAMERECT_LEFT + WD_FRAMERECT_RIGHT;
 
@@ -481,7 +481,7 @@ struct NetworkChatWindow : public QueryS
 
		if (widget != NWCW_DESTINATION) return;
 

	
 
		if (this->dtype == DESTTYPE_CLIENT) {
 
			SetDParamStr(0, NetworkFindClientInfoFromClientID((ClientID)this->dest)->client_name);
 
			SetDParamStr(0, NetworkClientInfo::GetByClientID((ClientID)this->dest)->client_name);
 
		}
 
		DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, r.top + WD_FRAMERECT_TOP, this->dest_string, TC_BLACK, SA_RIGHT);
 
	}
src/network/network_client.cpp
Show inline comments
 
@@ -556,7 +556,7 @@ DEF_GAME_RECEIVE_COMMAND(Client, PACKET_
 
	if (this->status < STATUS_AUTHORIZED) return NETWORK_RECV_STATUS_MALFORMED_PACKET;
 
	if (this->HasClientQuit()) return NETWORK_RECV_STATUS_CONN_LOST;
 

	
 
	ci = NetworkFindClientInfoFromClientID(client_id);
 
	ci = NetworkClientInfo::GetByClientID(client_id);
 
	if (ci != NULL) {
 
		if (playas == ci->client_playas && strcmp(name, ci->client_name) != 0) {
 
			/* Client name changed, display the change */
 
@@ -909,7 +909,7 @@ DEF_GAME_RECEIVE_COMMAND(Client, PACKET_
 
	p->Recv_string(msg, NETWORK_CHAT_LENGTH);
 
	int64 data = p->Recv_uint64();
 

	
 
	ci_to = NetworkFindClientInfoFromClientID(client_id);
 
	ci_to = NetworkClientInfo::GetByClientID(client_id);
 
	if (ci_to == NULL) return NETWORK_RECV_STATUS_OKAY;
 

	
 
	/* Did we initiate the action locally? */
 
@@ -918,7 +918,7 @@ DEF_GAME_RECEIVE_COMMAND(Client, PACKET_
 
			case NETWORK_ACTION_CHAT_CLIENT:
 
				/* For speaking to client we need the client-name */
 
				snprintf(name, sizeof(name), "%s", ci_to->client_name);
 
				ci = NetworkFindClientInfoFromClientID(_network_own_client_id);
 
				ci = NetworkClientInfo::GetByClientID(_network_own_client_id);
 
				break;
 

	
 
			/* For speaking to company or giving money, we need the company-name */
 
@@ -930,7 +930,7 @@ DEF_GAME_RECEIVE_COMMAND(Client, PACKET_
 
				SetDParam(0, ci_to->client_playas);
 

	
 
				GetString(name, str, lastof(name));
 
				ci = NetworkFindClientInfoFromClientID(_network_own_client_id);
 
				ci = NetworkClientInfo::GetByClientID(_network_own_client_id);
 
				break;
 
			}
 

	
 
@@ -954,7 +954,7 @@ DEF_GAME_RECEIVE_COMMAND(Client, PACKET_
 

	
 
	ClientID client_id = (ClientID)p->Recv_uint32();
 

	
 
	NetworkClientInfo *ci = NetworkFindClientInfoFromClientID(client_id);
 
	NetworkClientInfo *ci = NetworkClientInfo::GetByClientID(client_id);
 
	if (ci != NULL) {
 
		NetworkTextMessage(NETWORK_ACTION_LEAVE, CC_DEFAULT, false, ci->client_name, NULL, GetNetworkErrorMsg((NetworkErrorCode)p->Recv_uint8()));
 
		delete ci;
 
@@ -971,7 +971,7 @@ DEF_GAME_RECEIVE_COMMAND(Client, PACKET_
 

	
 
	ClientID client_id = (ClientID)p->Recv_uint32();
 

	
 
	NetworkClientInfo *ci = NetworkFindClientInfoFromClientID(client_id);
 
	NetworkClientInfo *ci = NetworkClientInfo::GetByClientID(client_id);
 
	if (ci != NULL) {
 
		NetworkTextMessage(NETWORK_ACTION_LEAVE, CC_DEFAULT, false, ci->client_name, NULL, STR_NETWORK_MESSAGE_CLIENT_LEAVING);
 
		delete ci;
 
@@ -991,7 +991,7 @@ DEF_GAME_RECEIVE_COMMAND(Client, PACKET_
 

	
 
	ClientID client_id = (ClientID)p->Recv_uint32();
 

	
 
	NetworkClientInfo *ci = NetworkFindClientInfoFromClientID(client_id);
 
	NetworkClientInfo *ci = NetworkClientInfo::GetByClientID(client_id);
 
	if (ci != NULL) {
 
		NetworkTextMessage(NETWORK_ACTION_JOIN, CC_DEFAULT, false, ci->client_name);
 
	}
 
@@ -1056,7 +1056,7 @@ DEF_GAME_RECEIVE_COMMAND(Client, PACKET_
 
		return NETWORK_RECV_STATUS_MALFORMED_PACKET;
 
	}
 

	
 
	const NetworkClientInfo *ci = NetworkFindClientInfoFromClientID(client_id);
 
	const NetworkClientInfo *ci = NetworkClientInfo::GetByClientID(client_id);
 
	/* Just make sure we do not try to use a client_index that does not exist */
 
	if (ci == NULL) return NETWORK_RECV_STATUS_OKAY;
 

	
 
@@ -1169,7 +1169,7 @@ void NetworkClientsToSpectators(CompanyI
 

	
 
void NetworkUpdateClientName()
 
{
 
	NetworkClientInfo *ci = NetworkFindClientInfoFromClientID(_network_own_client_id);
 
	NetworkClientInfo *ci = NetworkClientInfo::GetByClientID(_network_own_client_id);
 

	
 
	if (ci == NULL) return;
 

	
src/network/network_func.h
Show inline comments
 
@@ -68,7 +68,6 @@ bool NetworkServerStart();
 
void NetworkServerUpdateCompanyPassworded(CompanyID company_id, bool passworded);
 
bool NetworkServerChangeClientName(ClientID client_id, const char *new_name);
 

	
 
NetworkClientInfo *NetworkFindClientInfoFromClientID(ClientID client_id);
 
const char *GetClientIP(NetworkClientInfo *ci);
 

	
 
void NetworkServerDoMove(ClientID client_id, CompanyID company_id);
src/network/network_gui.cpp
Show inline comments
 
@@ -1772,7 +1772,7 @@ struct NetworkClientListPopupWindow : Wi
 
		this->desired_location.x = x;
 
		this->desired_location.y = y;
 

	
 
		const NetworkClientInfo *ci = NetworkFindClientInfoFromClientID(client_id);
 
		const NetworkClientInfo *ci = NetworkClientInfo::GetByClientID(client_id);
 

	
 
		if (_network_own_client_id != ci->client_id) {
 
			this->AddAction(STR_NETWORK_CLIENTLIST_SPEAK_TO_CLIENT, &ClientList_SpeakToClient);
 
@@ -1848,7 +1848,7 @@ struct NetworkClientListPopupWindow : Wi
 
			this->SetDirty();
 
		} else {
 
			if (index < this->actions.Length() && _cursor.pos.y >= this->top) {
 
				const NetworkClientInfo *ci = NetworkFindClientInfoFromClientID(this->client_id);
 
				const NetworkClientInfo *ci = NetworkClientInfo::GetByClientID(this->client_id);
 
				if (ci != NULL) this->actions[index].proc(ci);
 
			}
 

	
 
@@ -1864,7 +1864,7 @@ static void PopupClientList(ClientID cli
 
{
 
	DeleteWindowByClass(WC_CLIENT_LIST_POPUP);
 

	
 
	if (NetworkFindClientInfoFromClientID(client_id) == NULL) return;
 
	if (NetworkClientInfo::GetByClientID(client_id) == NULL) return;
 

	
 
	new NetworkClientListPopupWindow(&_client_list_popup_desc, x, y, client_id);
 
}
src/network/network_server.cpp
Show inline comments
 
@@ -326,7 +326,7 @@ NetworkRecvStatus ServerNetworkGameSocke
 
	memset(clients, 0, sizeof(clients));
 

	
 
	/* Add the local player (if not dedicated) */
 
	const NetworkClientInfo *ci = NetworkFindClientInfoFromClientID(CLIENT_ID_SERVER);
 
	const NetworkClientInfo *ci = NetworkClientInfo::GetByClientID(CLIENT_ID_SERVER);
 
	if (ci != NULL && Company::IsValidID(ci->client_playas)) {
 
		strecpy(clients[ci->client_playas], ci->client_name, lastof(clients[ci->client_playas]));
 
	}
 
@@ -487,7 +487,7 @@ NetworkRecvStatus ServerNetworkGameSocke
 
		}
 
	}
 
	/* Also send the info of the server */
 
	return this->SendClientInfo(NetworkFindClientInfoFromClientID(CLIENT_ID_SERVER));
 
	return this->SendClientInfo(NetworkClientInfo::GetByClientID(CLIENT_ID_SERVER));
 
}
 

	
 
NetworkRecvStatus ServerNetworkGameSocketHandler::SendWait()
 
@@ -1177,7 +1177,7 @@ void NetworkServerSendChat(NetworkAction
 
		case DESTTYPE_CLIENT:
 
			/* Are we sending to the server? */
 
			if ((ClientID)dest == CLIENT_ID_SERVER) {
 
				ci = NetworkFindClientInfoFromClientID(from_id);
 
				ci = NetworkClientInfo::GetByClientID(from_id);
 
				/* Display the text locally, and that is it */
 
				if (ci != NULL) {
 
					NetworkTextMessage(action, GetDrawStringCompanyColour(ci->client_playas), false, ci->client_name, msg, data);
 
@@ -1199,8 +1199,8 @@ void NetworkServerSendChat(NetworkAction
 
			/* Display the message locally (so you know you have sent it) */
 
			if (from_id != (ClientID)dest) {
 
				if (from_id == CLIENT_ID_SERVER) {
 
					ci = NetworkFindClientInfoFromClientID(from_id);
 
					ci_to = NetworkFindClientInfoFromClientID((ClientID)dest);
 
					ci = NetworkClientInfo::GetByClientID(from_id);
 
					ci_to = NetworkClientInfo::GetByClientID((ClientID)dest);
 
					if (ci != NULL && ci_to != NULL) {
 
						NetworkTextMessage(action, GetDrawStringCompanyColour(ci->client_playas), true, ci_to->client_name, msg, data);
 
					}
 
@@ -1233,8 +1233,8 @@ void NetworkServerSendChat(NetworkAction
 
				NetworkAdminChat(action, desttype, from_id, msg, data, from_admin);
 
			}
 

	
 
			ci = NetworkFindClientInfoFromClientID(from_id);
 
			ci_own = NetworkFindClientInfoFromClientID(CLIENT_ID_SERVER);
 
			ci = NetworkClientInfo::GetByClientID(from_id);
 
			ci_own = NetworkClientInfo::GetByClientID(CLIENT_ID_SERVER);
 
			if (ci != NULL && ci_own != NULL && ci_own->client_playas == dest) {
 
				NetworkTextMessage(action, GetDrawStringCompanyColour(ci->client_playas), false, ci->client_name, msg, data);
 
				if (from_id == CLIENT_ID_SERVER) show_local = false;
 
@@ -1272,7 +1272,7 @@ void NetworkServerSendChat(NetworkAction
 

	
 
			NetworkAdminChat(action, desttype, from_id, msg, data, from_admin);
 

	
 
			ci = NetworkFindClientInfoFromClientID(from_id);
 
			ci = NetworkClientInfo::GetByClientID(from_id);
 
			if (ci != NULL) {
 
				NetworkTextMessage(action, GetDrawStringCompanyColour(ci->client_playas), false, ci->client_name, msg, data);
 
			}
 
@@ -1502,7 +1502,7 @@ void NetworkPopulateCompanyStats(Network
 
void NetworkUpdateClientInfo(ClientID client_id)
 
{
 
	NetworkClientSocket *cs;
 
	NetworkClientInfo *ci = NetworkFindClientInfoFromClientID(client_id);
 
	NetworkClientInfo *ci = NetworkClientInfo::GetByClientID(client_id);
 

	
 
	if (ci == NULL) return;
 

	
 
@@ -1547,7 +1547,7 @@ static void NetworkAutoCleanCompanies()
 
	}
 

	
 
	if (!_network_dedicated) {
 
		ci = NetworkFindClientInfoFromClientID(CLIENT_ID_SERVER);
 
		ci = NetworkClientInfo::GetByClientID(CLIENT_ID_SERVER);
 
		if (Company::IsValidID(ci->client_playas)) clients_in_company[ci->client_playas] = true;
 
	}
 

	
 
@@ -1622,7 +1622,7 @@ bool NetworkFindName(char new_name[NETWO
 
			}
 
		}
 
		/* Check if it is the same as the server-name */
 
		ci = NetworkFindClientInfoFromClientID(CLIENT_ID_SERVER);
 
		ci = NetworkClientInfo::GetByClientID(CLIENT_ID_SERVER);
 
		if (ci != NULL) {
 
			if (strcmp(ci->client_name, new_name) == 0) found_name = false; // name already in use
 
		}
 
@@ -1653,7 +1653,7 @@ bool NetworkServerChangeClientName(Clien
 
		if (strcmp(ci->client_name, new_name) == 0) return false;
 
	}
 

	
 
	ci = NetworkFindClientInfoFromClientID(client_id);
 
	ci = NetworkClientInfo::GetByClientID(client_id);
 
	if (ci == NULL) return false;
 

	
 
	NetworkTextMessage(NETWORK_ACTION_NAME_CHANGE, CC_DEFAULT, true, ci->client_name, new_name);
 
@@ -1880,7 +1880,7 @@ void NetworkServerDoMove(ClientID client
 
	/* Only allow non-dedicated servers and normal clients to be moved */
 
	if (client_id == CLIENT_ID_SERVER && _network_dedicated) return;
 

	
 
	NetworkClientInfo *ci = NetworkFindClientInfoFromClientID(client_id);
 
	NetworkClientInfo *ci = NetworkClientInfo::GetByClientID(client_id);
 

	
 
	/* No need to waste network resources if the client is in the company already! */
 
	if (ci->client_playas == company_id) return;
0 comments (0 inline, 0 general)