MCPcopy Create free account
hub / github.com/DescentDevelopers/Descent3 / MultiSendMessageFromServer

Function MultiSendMessageFromServer

Descent3/multi.cpp:4956–5019  ·  view source on GitHub ↗

Sends a message from the server to the client

Source from the content-addressed store, hash-verified

4954
4955// Sends a message from the server to the client
4956void MultiSendMessageFromServer(int color, char *message, int to) {
4957 int count = 0;
4958 uint8_t data[MAX_GAME_DATA_SIZE];
4959 int size_offset;
4960
4961 MULTI_ASSERT_NOMESSAGE(Netgame.local_role == LR_SERVER);
4962
4963 size_offset = START_DATA(MP_MESSAGE_FROM_SERVER, data, &count, 1);
4964 MultiAddInt(color, data, &count);
4965
4966 uint8_t len = strlen(message) + 1;
4967
4968 MultiAddByte(len, data, &count);
4969
4970 memcpy(&data[count], message, len);
4971
4972 count += len;
4973
4974 END_DATA(count, data, size_offset);
4975
4976 if (to == MULTI_SEND_MESSAGE_ALL) {
4977 MultiSendReliablyToAllExcept(Player_num, data, count, false);
4978 MultiDoMessageFromServer(data);
4979 } else {
4980 int team = -1;
4981
4982 switch (to) {
4983 case MULTI_SEND_MESSAGE_RED_TEAM:
4984 team = 0;
4985 break;
4986 case MULTI_SEND_MESSAGE_BLUE_TEAM:
4987 team = 1;
4988 break;
4989 case MULTI_SEND_MESSAGE_GREEN_TEAM:
4990 team = 2;
4991 break;
4992 case MULTI_SEND_MESSAGE_YELLOW_TEAM:
4993 team = 3;
4994 break;
4995 }
4996
4997 if (team == -1) {
4998 // send it off to one person
4999 if (to >= 0 && to < MAX_PLAYERS) {
5000 if (NetPlayers[to].flags & NPF_CONNECTED && NetPlayers[to].sequence == NETSEQ_PLAYING && to != Player_num) {
5001 nw_SendReliable(NetPlayers[to].reliable_socket, data, count, false);
5002 }
5003 }
5004 if (to == Player_num)
5005 MultiDoMessageFromServer(data);
5006 } else {
5007 // send it off only to teammates
5008 for (int p = 0; p < MAX_PLAYERS; p++) {
5009 if (NetPlayers[p].flags & NPF_CONNECTED && NetPlayers[p].sequence == NETSEQ_PLAYING &&
5010 Players[p].team == team && p != Player_num) {
5011
5012 nw_SendReliable(NetPlayers[p].reliable_socket, data, count, false);
5013 }

Callers 5

SendCheaterTextFunction · 0.85
MultiDoMessageToServerFunction · 0.85
SendCheaterAttemptTextFunction · 0.85
SetCVarStringFunction · 0.85
SendOffHUDInputMessageFunction · 0.85

Calls 7

START_DATAFunction · 0.85
MultiAddIntFunction · 0.85
MultiAddByteFunction · 0.85
END_DATAFunction · 0.85
MultiDoMessageFromServerFunction · 0.85
nw_SendReliableFunction · 0.85

Tested by

no test coverage detected