mirror of
https://github.com/KartKrewDev/RingRacers.git
synced 2026-04-26 03:51:50 +00:00
Turn HU_queueChatChar into HU_sendChatMessage
# Conflicts: # src/hu_stuff.c
This commit is contained in:
parent
4fc770aa7b
commit
4c59bb3b2b
1 changed files with 84 additions and 96 deletions
180
src/hu_stuff.c
180
src/hu_stuff.c
|
|
@ -978,104 +978,99 @@ static boolean HU_chatboxContainsOnlySpaces(void)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void HU_queueChatChar(char c)
|
static void HU_sendChatMessage(void)
|
||||||
{
|
{
|
||||||
if (c == KEY_ENTER)
|
char buf[2+256];
|
||||||
|
char *msg = &buf[2];
|
||||||
|
size_t ci;
|
||||||
|
INT32 target = 0;
|
||||||
|
|
||||||
|
// if our message was nothing but spaces, don't send it.
|
||||||
|
if (HU_chatboxContainsOnlySpaces())
|
||||||
|
return;
|
||||||
|
|
||||||
|
// copy printable characters and terminating '\0' only.
|
||||||
|
for (ci = 2; w_chat[ci-2]; ci++)
|
||||||
{
|
{
|
||||||
char buf[2+256];
|
char c = w_chat[ci-2];
|
||||||
char *msg = &buf[2];
|
if (c >= ' ' && !(c & 0x80))
|
||||||
size_t ci;
|
buf[ci] = c;
|
||||||
INT32 target = 0;
|
};
|
||||||
|
buf[ci] = '\0';
|
||||||
|
|
||||||
// if our message was nothing but spaces, don't send it.
|
memset(w_chat, '\0', HU_MAXMSGLEN);
|
||||||
if (HU_chatboxContainsOnlySpaces())
|
c_input = 0;
|
||||||
return;
|
|
||||||
|
|
||||||
// copy printable characters and terminating '\0' only.
|
// last minute mute check
|
||||||
for (ci = 2; w_chat[ci-2]; ci++)
|
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)
|
||||||
{
|
{
|
||||||
c = w_chat[ci-2];
|
HU_AddChatText(va("%sCannot send sayto in Say-Team.", "\x85"), false);
|
||||||
if (c >= ' ' && !(c & 0x80))
|
|
||||||
buf[ci] = c;
|
|
||||||
};
|
|
||||||
buf[ci] = '\0';
|
|
||||||
|
|
||||||
memset(w_chat, '\0', HU_MAXMSGLEN);
|
|
||||||
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strlen(msg) > 4 && strnicmp(msg, "/pm", 3) == 0) // used /pm
|
strncpy(playernum, msg+3, 3);
|
||||||
|
// check for undesirable characters in our "number"
|
||||||
|
if (!(isdigit(playernum[0]) && isdigit(playernum[1])))
|
||||||
{
|
{
|
||||||
INT32 spc = 1; // used if playernum[1] is a space.
|
// check if playernum[1] is a space
|
||||||
char playernum[3];
|
if (playernum[1] == ' ')
|
||||||
const char *newmsg;
|
spc = 0;
|
||||||
|
// let it slide
|
||||||
// what we're gonna do now is check if the player exists
|
else
|
||||||
// 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])))
|
|
||||||
{
|
|
||||||
// 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<player num> \'.", 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<player num> \'.", false);
|
HU_AddChatText("\x82NOTICE: \x80Invalid command format. Correct format is \'/pm<player num> \'.", false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
target = atoi(playernum); // turn that into a number
|
|
||||||
|
|
||||||
// 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
// we need to get rid of the /pm<player num>
|
|
||||||
newmsg = msg+5+spc;
|
|
||||||
strlcpy(msg, newmsg, 255);
|
|
||||||
}
|
}
|
||||||
if (ci > 3) // don't send target+flags+empty message.
|
// I'm very bad at C, I swear I am, additional checks eww!
|
||||||
|
if (spc != 0 && msg[5] != ' ')
|
||||||
{
|
{
|
||||||
buf[0] = teamtalk ? -1 : target; // target
|
HU_AddChatText("\x82NOTICE: \x80Invalid command format. Correct format is \'/pm<player num> \'.", false);
|
||||||
buf[1] = 0; // flags
|
return;
|
||||||
SendNetXCmd(XD_SAY, buf, 2 + strlen(&buf[2]) + 1);
|
|
||||||
}
|
}
|
||||||
return;
|
|
||||||
|
target = atoi(playernum); // turn that into a number
|
||||||
|
|
||||||
|
// 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
// we need to get rid of the /pm<player num>
|
||||||
|
newmsg = msg+5+spc;
|
||||||
|
strlcpy(msg, newmsg, 255);
|
||||||
|
}
|
||||||
|
if (ci > 3) // don't send target+flags+empty message.
|
||||||
|
{
|
||||||
|
buf[0] = teamtalk ? -1 : target; // target
|
||||||
|
buf[1] = 0; // flags
|
||||||
|
SendNetXCmd(XD_SAY, buf, 2 + strlen(&buf[2]) + 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handles key input and string input
|
// Handles key input and string input
|
||||||
//
|
//
|
||||||
static inline boolean HU_keyInChatString(char *s, char ch)
|
static inline void HU_keyInChatString(char *s, char ch)
|
||||||
{
|
{
|
||||||
size_t l;
|
size_t l;
|
||||||
|
|
||||||
|
|
@ -1106,25 +1101,25 @@ static inline boolean HU_keyInChatString(char *s, char ch)
|
||||||
s[c_input] = ch; // and replace this.
|
s[c_input] = ch; // and replace this.
|
||||||
}
|
}
|
||||||
c_input++;
|
c_input++;
|
||||||
return true;
|
return;
|
||||||
}
|
}
|
||||||
return false;
|
return;
|
||||||
}
|
}
|
||||||
else if (ch == KEY_BACKSPACE)
|
else if (ch == KEY_BACKSPACE)
|
||||||
{
|
{
|
||||||
size_t i = c_input;
|
size_t i = c_input;
|
||||||
|
|
||||||
if (c_input <= 0)
|
if (c_input <= 0)
|
||||||
return false;
|
return;
|
||||||
|
|
||||||
if (!s[i-1])
|
if (!s[i-1])
|
||||||
return false;
|
return;
|
||||||
|
|
||||||
if (i >= strlen(s)-1)
|
if (i >= strlen(s)-1)
|
||||||
{
|
{
|
||||||
s[strlen(s)-1] = 0;
|
s[strlen(s)-1] = 0;
|
||||||
c_input--;
|
c_input--;
|
||||||
return false;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (; (i < HU_MAXMSGLEN); i++)
|
for (; (i < HU_MAXMSGLEN); i++)
|
||||||
|
|
@ -1133,10 +1128,6 @@ static inline boolean HU_keyInChatString(char *s, char ch)
|
||||||
}
|
}
|
||||||
c_input--;
|
c_input--;
|
||||||
}
|
}
|
||||||
else if (ch != KEY_ENTER)
|
|
||||||
return false; // did not eat key
|
|
||||||
|
|
||||||
return true; // ate the key
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -1246,14 +1237,9 @@ boolean HU_Responder(event_t *ev)
|
||||||
{
|
{
|
||||||
memcpy(&w_chat[chatlen], paste, pastelen); // copy all of that.
|
memcpy(&w_chat[chatlen], paste, pastelen); // copy all of that.
|
||||||
c_input += pastelen;
|
c_input += pastelen;
|
||||||
/*size_t i = 0;
|
|
||||||
for (;i<pastelen;i++)
|
|
||||||
{
|
|
||||||
HU_queueChatChar(paste[i]); // queue it so that it's actually sent. (this chat write thing is REALLY messy.)
|
|
||||||
}*/
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else // otherwise, we need to shift everything and make space, etc etc
|
else // otherwise, we need to shift everything and make space, etc etc
|
||||||
{
|
{
|
||||||
size_t i = HU_MAXMSGLEN-1;
|
size_t i = HU_MAXMSGLEN-1;
|
||||||
while (i >= c_input)
|
while (i >= c_input)
|
||||||
|
|
@ -1270,12 +1256,11 @@ boolean HU_Responder(event_t *ev)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!CHAT_MUTE && HU_keyInChatString(w_chat,c))
|
|
||||||
{
|
|
||||||
HU_queueChatChar(c);
|
|
||||||
}
|
|
||||||
if (c == KEY_ENTER)
|
if (c == KEY_ENTER)
|
||||||
{
|
{
|
||||||
|
if (!CHAT_MUTE)
|
||||||
|
HU_sendChatMessage();
|
||||||
|
|
||||||
chat_on = false;
|
chat_on = false;
|
||||||
c_input = 0; // reset input cursor
|
c_input = 0; // reset input cursor
|
||||||
chat_scrollmedown = true; // you hit enter, so you might wanna autoscroll to see what you just sent. :)
|
chat_scrollmedown = true; // you hit enter, so you might wanna autoscroll to see what you just sent. :)
|
||||||
|
|
@ -1316,6 +1301,9 @@ boolean HU_Responder(event_t *ev)
|
||||||
else
|
else
|
||||||
c_input++;
|
c_input++;
|
||||||
}
|
}
|
||||||
|
else if (!CHAT_MUTE)
|
||||||
|
HU_keyInChatString(w_chat, c);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue