diff --git a/src/d_clisrv.c b/src/d_clisrv.c index b6a46a8fd..e40d9d7d6 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -5241,10 +5241,16 @@ static void HandlePacketFromPlayer(SINT8 node) textcmd[0] += (UINT8)netbuffer->u.textcmd[0]; } break; - case PT_LOGIN: + case PT_SAY: if (client) break; + say_pak say = netbuffer->u.say; + DoSayCommand(say.message, say.target, say.flags, say.source); + break; + case PT_LOGIN: + if (client) + break; #ifndef NOMD5 if (doomcom->datalength < 16)/* ignore partial sends */ break; @@ -6944,3 +6950,41 @@ void D_MD5PasswordPass(const UINT8 *buffer, size_t len, const char *salt, void * md5_buffer(tmpbuf, 256, dest); #endif } + +// Want to say something? XD_SAY is server only, gotta request that they send one on our behalf +void DoSayPacket(SINT8 target, UINT8 flags, UINT8 source, char *message) +{ + say_pak *packet = (void*)&netbuffer->u.say; + netbuffer->packettype = PT_SAY; + + memset(packet->message, 0, sizeof(packet->message)); + strcpy(packet->message, message); + + packet->source = source; + packet->flags = flags; + packet->target = target; + + HSendPacket(servernode, false, 0, sizeof(say_pak)); +} + +void DoSayPacketFromCommand(SINT8 target, size_t usedargs, UINT8 flags) +{ + char buf[2 + HU_MAXMSGLEN + 1]; + size_t numwords, ix; + char *msg = &buf[3]; + const size_t msgspace = sizeof buf - 2; + + numwords = COM_Argc() - usedargs; + I_Assert(numwords > 0); + + msg[0] = '\0'; + + for (ix = 0; ix < numwords; ix++) + { + if (ix > 0) + strlcat(msg, " ", msgspace); + strlcat(msg, COM_Argv(ix + usedargs), msgspace); + } + + DoSayPacket(target, flags, consoleplayer, msg); +} \ No newline at end of file diff --git a/src/d_clisrv.h b/src/d_clisrv.h index fee63b0ec..5f194498f 100644 --- a/src/d_clisrv.h +++ b/src/d_clisrv.h @@ -41,6 +41,8 @@ applications may follow different packet versions. // one that defines the actual packets to // be transmitted. +#define HU_MAXMSGLEN 223 + // Networking and tick handling related. #define BACKUPTICS 512 // more than enough for most timeouts.... #define CLIENTBACKUPTICS 32 @@ -127,6 +129,8 @@ typedef enum PT_RESPONSEALL, // OK, here is my signature on that random bullshit PT_RESULTSALL, // Here's what everyone responded to PT_CHALLENGEALL with, if this is wrong or you don't receive it disconnect + PT_SAY, // "Hey server, please send this chat message to everyone via XD_SAY" + NUMPACKETTYPE } packettype_t; @@ -385,6 +389,14 @@ struct resultsall_pak uint8_t signature[MAXPLAYERS][SIGNATURELENGTH]; } ATTRPACK; +struct say_pak +{ + char message[HU_MAXMSGLEN + 1]; + UINT8 target; + UINT8 flags; + UINT8 source; +} ATTRPACK; + // // Network packet data // @@ -427,6 +439,7 @@ struct doomdata_t challengeall_pak challengeall; // 256 bytes responseall_pak responseall; // 256 bytes resultsall_pak resultsall; // 1024 bytes. Also, you really shouldn't trust anything here. + say_pak say; // I don't care anymore. } u; // This is needed to pack diff packet types data together } ATTRPACK; @@ -630,6 +643,9 @@ rewind_t *CL_RewindToTime(tic_t time); void HandleSigfail(const char *string); +void DoSayPacket(SINT8 target, UINT8 flags, UINT8 source, char *message); +void DoSayPacketFromCommand(SINT8 target, size_t usedargs, UINT8 flags); + #ifdef __cplusplus } // extern "C" #endif diff --git a/src/d_net.c b/src/d_net.c index 917b181fe..c04ec400b 100644 --- a/src/d_net.c +++ b/src/d_net.c @@ -1023,6 +1023,7 @@ static boolean ShouldDropPacket(void) case PT_LOGIN: case PT_ASKLUAFILE: case PT_SENDINGLUAFILE: + case PT_SAY: return true; default: return false; diff --git a/src/hu_stuff.c b/src/hu_stuff.c index 5b028662d..a64c5548b 100644 --- a/src/hu_stuff.c +++ b/src/hu_stuff.c @@ -60,6 +60,7 @@ #include "k_color.h" #include "k_hud.h" #include "r_fps.h" +#include "d_clisrv.h" // coords are scaled #define HU_INPUTX 0 @@ -478,7 +479,6 @@ void HU_AddChatText(const char *text, boolean playsound) CON_LogMessage(va("%s\n", text)); } - /** Runs a say command, sending an ::XD_SAY message. * A say command consists of a signed 8-bit integer for the target, an * unsigned 8-bit flag variable, and then the message itself. @@ -498,27 +498,10 @@ void HU_AddChatText(const char *text, boolean playsound) * \author Graue */ -static void DoSayCommand(SINT8 target, size_t usedargs, UINT8 flags) +void DoSayCommand(char *message, SINT8 target, UINT8 flags, UINT8 source) { char buf[2 + HU_MAXMSGLEN + 1]; - size_t numwords, ix; - char *msg = &buf[2]; - const size_t msgspace = sizeof buf - 2; - - numwords = COM_Argc() - usedargs; - I_Assert(numwords > 0); - - if (CHAT_MUTE) // TODO: Per Player mute. - { - HU_AddChatText(va("%s>ERROR: The chat is muted. You can't say anything.", "\x85"), false); - return; - } - - // Only servers/admins can shout or CSAY. - if (!server && !IsPlayerAdmin(consoleplayer)) - { - flags &= ~(HU_SHOUT|HU_CSAY); - } + char *msg = &buf[3]; // Enforce shout for the dedicated server. if (dedicated && !(flags & HU_CSAY)) @@ -528,66 +511,16 @@ static void DoSayCommand(SINT8 target, size_t usedargs, UINT8 flags) buf[0] = target; buf[1] = flags; + buf[2] = source; msg[0] = '\0'; - for (ix = 0; ix < numwords; ix++) - { - if (ix > 0) - strlcat(msg, " ", msgspace); - strlcat(msg, COM_Argv(ix + usedargs), msgspace); - } - - if (strlen(msg) > 4 && strnicmp(msg, "/pm", 3) == 0) // used /pm - { - // what we're gonna do now is check if the player exists - // with that logic, characters 4 and 5 are our numbers: - const char *newmsg; - char playernum[3]; - INT32 spc = 1; // used if playernum[1] is a space. - - strncpy(playernum, msg+3, 3); - - // check for undesirable characters in our "number" - if (((playernum[0] < '0') || (playernum[0] > '9')) || ((playernum[1] < '0') || (playernum[1] > '9'))) - { - // check if playernum[1] is a space - if (playernum[1] == ' ') - spc = 0; - // let it slide - else - { - HU_AddChatText("\x82NOTICE: \x80Invalid command format. Correct format is \'/pm \'.", false); - return; - } - } - // I'm very bad at C, I swear I am, additional checks eww! - if (spc != 0 && msg[5] != ' ') - { - HU_AddChatText("\x82NOTICE: \x80Invalid command format. Correct format is \'/pm \'.", false); - return; - } - - target = atoi(playernum); // turn that into a number - //CONS_Printf("%d\n", target); - - // check for target player, if it doesn't exist then we can't send the message! - if (target < MAXPLAYERS && playeringame[target]) // player exists - target++; // even though playernums are from 0 to 31, target is 1 to 32, so up that by 1 to have it work! - else - { - HU_AddChatText(va("\x82NOTICE: \x80Player %d does not exist.", target), false); // same - return; - } - buf[0] = target; - newmsg = msg+5+spc; - strlcpy(msg, newmsg, HU_MAXMSGLEN + 1); - } + strcpy(msg, message); SendNetXCmd(XD_SAY, buf, strlen(msg) + 1 + msg-buf); } /** Send a message to everyone. - * \sa DoSayCommand, Command_Sayteam_f, Command_Sayto_f + * \sa DoSayPacket, Command_Sayteam_f, Command_Sayto_f * \author Graue */ static void Command_Say_f(void) @@ -600,11 +533,11 @@ static void Command_Say_f(void) // Autoshout is handled by HU_queueChatChar. // If you're using the say command, you can use the shout command, lol. - DoSayCommand(0, 1, 0); + DoSayPacketFromCommand(0, 1, 0); } /** Send a message to a particular person. - * \sa DoSayCommand, Command_Sayteam_f, Command_Say_f + * \sa DoSayPacket, Command_Sayteam_f, Command_Say_f * \author Graue */ static void Command_Sayto_f(void) @@ -625,11 +558,11 @@ static void Command_Sayto_f(void) } target++; // Internally we use 0 to 31, but say command uses 1 to 32. - DoSayCommand((SINT8)target, 2, 0); + DoSayPacketFromCommand((SINT8)target, 2, 0); } /** Send a message to members of the player's team. - * \sa DoSayCommand, Command_Say_f, Command_Sayto_f + * \sa DoSayPacket, Command_Say_f, Command_Sayto_f * \author Graue */ static void Command_Sayteam_f(void) @@ -647,9 +580,9 @@ static void Command_Sayteam_f(void) } if (G_GametypeHasTeams()) // revert to normal say if we don't have teams in this gametype. - DoSayCommand(-1, 1, 0); + DoSayPacketFromCommand(-1, 1, 0); else - DoSayCommand(0, 1, 0); + DoSayPacketFromCommand(0, 1, 0); } /** Send a message to everyone, to be displayed by CECHO. Only @@ -669,7 +602,7 @@ static void Command_CSay_f(void) return; } - DoSayCommand(0, 1, HU_CSAY); + DoSayPacketFromCommand(0, 1, HU_CSAY); } static void Command_Shout(void) @@ -686,13 +619,13 @@ static void Command_Shout(void) return; } - DoSayCommand(0, 1, HU_SHOUT); + DoSayPacketFromCommand(0, 1, HU_SHOUT); } static tic_t stop_spamming[MAXPLAYERS]; /** Receives a message, processing an ::XD_SAY command. - * \sa DoSayCommand + * \sa DoSayPacket * \author Graue */ static void Got_Saycmd(UINT8 **p, INT32 playernum) @@ -707,21 +640,16 @@ static void Got_Saycmd(UINT8 **p, INT32 playernum) CONS_Debug(DBG_NETPLAY,"Received SAY cmd from Player %d (%s)\n", playernum+1, player_names[playernum]); + // Only server can ever legitimately send this + if (playernum != serverplayer) + return; + target = READSINT8(*p); flags = READUINT8(*p); + playernum = READUINT8(*p); msg = (char *)*p; SKIPSTRINGL(*p, HU_MAXMSGLEN + 1); - if ((cv_mute.value || flags & (HU_CSAY|HU_SHOUT)) && playernum != serverplayer && !(IsPlayerAdmin(playernum))) - { - CONS_Alert(CONS_WARNING, cv_mute.value ? - M_GetText("Illegal say command received from %s while muted\n") : M_GetText("Illegal csay command received from non-admin %s\n"), - player_names[playernum]); - if (server) - SendKick(playernum, KICK_MSG_CON_FAIL); - return; - } - //check for invalid characters (0x80 or above) { size_t i; @@ -738,25 +666,8 @@ static void Got_Saycmd(UINT8 **p, INT32 playernum) } } - // before we do anything, let's verify the guy isn't spamming, get this easier on us. - - //if (stop_spamming[playernum] != 0 && cv_chatspamprotection.value && !(flags & HU_CSAY)) - if (stop_spamming[playernum] != 0 && consoleplayer != playernum && cv_chatspamprotection.value && !(flags & (HU_CSAY|HU_SHOUT))) - { - CONS_Debug(DBG_NETPLAY,"Received SAY cmd too quickly from Player %d (%s), assuming as spam and blocking message.\n", playernum+1, player_names[playernum]); - stop_spamming[playernum] = 4; - spam_eatmsg = 1; - } - else - stop_spamming[playernum] = 4; // you can hold off for 4 tics, can you? - - // run the lua hook even if we were supposed to eat the msg, netgame consistency goes first. - - if (LUA_HookPlayerMsg(playernum, target, flags, msg, spam_eatmsg)) - return; - if (spam_eatmsg) - return; // don't proceed if we were supposed to eat the message. + return; // If it's a CSAY, just CECHO and be done with it. if (flags & HU_CSAY) @@ -1094,29 +1005,12 @@ static void HU_sendChatMessage(void) memset(w_chat, '\0', sizeof(w_chat)); c_input = 0; - // last minute mute check - if (CHAT_MUTE) - { - HU_AddChatText(va("%s>ERROR: The chat is muted. You can't say anything.", "\x85"), false); - return; - } - if (strlen(msg) > 4 && strnicmp(msg, "/pm", 3) == 0) // used /pm { INT32 spc = 1; // used if playernum[1] is a space. char playernum[3]; const char *newmsg; - // what we're gonna do now is check if the player exists - // with that logic, characters 4 and 5 are our numbers: - - // teamtalk can't send PMs, just don't send it, else everyone would be able to see it, and no one wants to see your sex RP sicko. - if (teamtalk) - { - HU_AddChatText(va("%sCannot send sayto in Say-Team.", "\x85"), false); - return; - } - strncpy(playernum, msg+3, 3); // check for undesirable characters in our "number" if (!(isdigit(playernum[0]) && isdigit(playernum[1]))) @@ -1161,7 +1055,8 @@ static void HU_sendChatMessage(void) buf[0] = target; buf[1] = ((server || IsPlayerAdmin(consoleplayer)) && cv_autoshout.value) ? HU_SHOUT : 0; // flags - SendNetXCmd(XD_SAY, buf, 2 + strlen(&buf[2]) + 1); + + DoSayPacket(target, buf[1], consoleplayer, msg); } } diff --git a/src/hu_stuff.h b/src/hu_stuff.h index 08b997bdc..ff8dedf49 100644 --- a/src/hu_stuff.h +++ b/src/hu_stuff.h @@ -95,7 +95,6 @@ struct playersort_t //------------------------------------ // chat stuff //------------------------------------ -#define HU_MAXMSGLEN 223 #define CHAT_BUFSIZE 64 // that's enough messages, right? We'll delete the older ones when that gets out of hand. #define NETSPLITSCREEN // why the hell WOULDN'T we want this? #ifdef NETSPLITSCREEN @@ -158,6 +157,8 @@ void HU_DoCEcho(const char *msg); void HU_DoTitlecardCEcho(const char *msg); void HU_ClearTitlecardCEcho(void); +void DoSayCommand(char *message, SINT8 target, UINT8 flags, UINT8 source); + // Demo playback info extern UINT32 hu_demotime; extern UINT32 hu_demolap; diff --git a/src/typedef.h b/src/typedef.h index 47d5fcf45..62f87cb79 100644 --- a/src/typedef.h +++ b/src/typedef.h @@ -76,6 +76,7 @@ TYPEDEF (serverchallenge_pak); TYPEDEF (challengeall_pak); TYPEDEF (responseall_pak); TYPEDEF (resultsall_pak); +TYPEDEF (say_pak); // d_event.h TYPEDEF (event_t);