MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / NetworkServerSendChat

Function NetworkServerSendChat

src/network/network_server.cpp:1252–1360  ·  view source on GitHub ↗

* Send an actual chat message. * @param action The action that's performed. * @param desttype The type of destination. * @param dest The actual destination index. * @param msg The actual message. * @param from_id The origin of the message. * @param data Arbitrary data. * @param from_admin Whether the origin is an admin or not. */

Source from the content-addressed store, hash-verified

1250 * @param from_admin Whether the origin is an admin or not.
1251 */
1252void NetworkServerSendChat(NetworkAction action, DestType desttype, int dest, std::string_view msg, ClientID from_id, int64_t data, bool from_admin)
1253{
1254 const NetworkClientInfo *ci, *ci_own, *ci_to;
1255
1256 switch (desttype) {
1257 case DESTTYPE_CLIENT:
1258 /* Are we sending to the server? */
1259 if ((ClientID)dest == CLIENT_ID_SERVER) {
1260 ci = NetworkClientInfo::GetByClientID(from_id);
1261 /* Display the text locally, and that is it */
1262 if (ci != nullptr) {
1263 NetworkTextMessage(action, GetDrawStringCompanyColour(ci->client_playas), false, ci->client_name, msg, data);
1264
1265 if (_settings_client.network.server_admin_chat) {
1266 NetworkAdminChat(action, desttype, from_id, msg, data, from_admin);
1267 }
1268 }
1269 } else {
1270 /* Else find the client to send the message to */
1271 for (NetworkClientSocket *cs : NetworkClientSocket::Iterate()) {
1272 if (cs->client_id == (ClientID)dest && cs->status >= ServerNetworkGameSocketHandler::STATUS_AUTHORIZED) {
1273 cs->SendChat(action, from_id, false, msg, data);
1274 break;
1275 }
1276 }
1277 }
1278
1279 /* Display the message locally (so you know you have sent it) */
1280 if (from_id != (ClientID)dest) {
1281 if (from_id == CLIENT_ID_SERVER) {
1282 ci = NetworkClientInfo::GetByClientID(from_id);
1283 ci_to = NetworkClientInfo::GetByClientID((ClientID)dest);
1284 if (ci != nullptr && ci_to != nullptr) {
1285 NetworkTextMessage(action, GetDrawStringCompanyColour(ci->client_playas), true, ci_to->client_name, msg, data);
1286 }
1287 } else {
1288 for (NetworkClientSocket *cs : NetworkClientSocket::Iterate()) {
1289 if (cs->client_id == from_id && cs->status >= ServerNetworkGameSocketHandler::STATUS_AUTHORIZED) {
1290 cs->SendChat(action, (ClientID)dest, true, msg, data);
1291 break;
1292 }
1293 }
1294 }
1295 }
1296 break;
1297 case DESTTYPE_TEAM: {
1298 /* If this is false, the message is already displayed on the client who sent it. */
1299 bool show_local = true;
1300 /* Find all clients that belong to this company */
1301 ci_to = nullptr;
1302 for (NetworkClientSocket *cs : NetworkClientSocket::Iterate()) {
1303 ci = cs->GetInfo();
1304 if (ci != nullptr && ci->client_playas == (CompanyID)dest && cs->status >= ServerNetworkGameSocketHandler::STATUS_AUTHORIZED) {
1305 cs->SendChat(action, from_id, false, msg, data);
1306 if (cs->client_id == from_id) show_local = false;
1307 ci_to = ci; // Remember a client that is in the company for company-name
1308 }
1309 }

Callers 9

ConSayFunction · 0.85
ConSayCompanyFunction · 0.85
ConSayClientFunction · 0.85
Receive_ADMIN_CHATMethod · 0.85
SendChatFunction · 0.85
Receive_CLIENT_CHATMethod · 0.85
NetworkServerDoMoveFunction · 0.85
NetworkServerNewCompanyFunction · 0.85

Calls 6

NetworkTextMessageFunction · 0.85
NetworkAdminChatFunction · 0.85
GetStringFunction · 0.50
SendChatMethod · 0.45
GetInfoMethod · 0.45

Tested by

no test coverage detected