1 /* 2 * This file is part of OpenTTD. 3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2. 4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>. 6 */ 7 8 /** @file script_client.cpp Implementation of ScriptClient. */ 9 10 #include "../../stdafx.h" 11 #include "script_client.hpp" 12 #include "../../network/network.h" 13 #include "../../network/network_base.h" 14 15 #include "../../safeguards.h" 16 17 /** 18 * Finds NetworkClientInfo given client-identifier, 19 * is used by other methods to resolve client-identifier. 20 * @param client The client to get info structure for 21 * @return A pointer to corresponding CI struct or nullptr when not found. 22 */ FindClientInfo(ScriptClient::ClientID client)23static NetworkClientInfo *FindClientInfo(ScriptClient::ClientID client) 24 { 25 if (client == ScriptClient::CLIENT_INVALID) return nullptr; 26 if (!_networking) return nullptr; 27 return NetworkClientInfo::GetByClientID((::ClientID)client); 28 } 29 ResolveClientID(ScriptClient::ClientID client)30/* static */ ScriptClient::ClientID ScriptClient::ResolveClientID(ScriptClient::ClientID client) 31 { 32 return (FindClientInfo(client) == nullptr ? ScriptClient::CLIENT_INVALID : client); 33 } 34 GetName(ScriptClient::ClientID client)35/* static */ char *ScriptClient::GetName(ScriptClient::ClientID client) 36 { 37 NetworkClientInfo *ci = FindClientInfo(client); 38 if (ci == nullptr) return nullptr; 39 return stredup(ci->client_name.c_str()); 40 } 41 GetCompany(ScriptClient::ClientID client)42/* static */ ScriptCompany::CompanyID ScriptClient::GetCompany(ScriptClient::ClientID client) 43 { 44 NetworkClientInfo *ci = FindClientInfo(client); 45 if (ci == nullptr) return ScriptCompany::COMPANY_INVALID; 46 return (ScriptCompany::CompanyID)ci->client_playas; 47 } 48 GetJoinDate(ScriptClient::ClientID client)49/* static */ ScriptDate::Date ScriptClient::GetJoinDate(ScriptClient::ClientID client) 50 { 51 NetworkClientInfo *ci = FindClientInfo(client); 52 if (ci == nullptr) return ScriptDate::DATE_INVALID; 53 return (ScriptDate::Date)ci->join_date; 54 } 55