Skip to content

Commit

Permalink
support for userinfo chat status
Browse files Browse the repository at this point in the history
  • Loading branch information
timbergeron committed Aug 26, 2024
1 parent 51fa99f commit d9914c6
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 2 deletions.
10 changes: 10 additions & 0 deletions Quake/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -4626,4 +4626,14 @@ size_t UTF8_WriteCodePoint(char* dst, size_t maxbytes, uint32_t codepoint)
}

return 0;
}

void SetChatInfo (int flags) // woods #chatinfo
{
char command[16];

int chat_value = (flags & CIF_AFK) ? CIF_AFK : (flags & CIF_CHAT) ? CIF_CHAT : 0;

snprintf(command, sizeof(command), "setinfo chat %d\n", chat_value);
Cbuf_AddText(command);
}
5 changes: 5 additions & 0 deletions Quake/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,11 @@ qboolean isSpecialMap (const char* name); // woods for bmodels
// Unicode
size_t UTF8_WriteCodePoint(char* dst, size_t maxbytes, uint32_t codepoint); // woods #serversmenu (ironwail)

#define CIF_CHAT (1<<0) // set this flag if user is in console, mm1, mm2 etc but not in game -- woods #chatinfo
#define CIF_AFK (1<<1) // set this flag if app loses focus, ie alt+tab -- woods #chatinfo

void SetChatInfo (int flags); // woods #chatinfo

//============================================================================

// QUAKEFS
Expand Down
16 changes: 16 additions & 0 deletions Quake/console.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ extern qboolean endscoreprint; // woods -- don't filter end scores pq_confilter+
char lastconnected[3]; // woods -- #identify+
char lc[3]; // woods -- #identify+
int retry_counter = 0; // woods #ms
extern SDL_TimerID chatTimerID; // woods #chatinfo
extern qboolean isChatTimerRunning; // woods #chatinfo

/*
================
Expand Down Expand Up @@ -156,6 +158,18 @@ void Con_ToggleConsole_f (void)
if ((key_linepos == 1) && (cl_say.value == 2 || cl_say.value == 3)) // woods #ezsay add leading space for mode 2
Char_Console2(32);

if (cl_say.value) // woods #chatinfo
{
SetChatInfo (0);

if (isChatTimerRunning) // woods #chatinfo
{
SDL_RemoveTimer(chatTimerID);
isChatTimerRunning = false;
chatTimerID = 0;
}
}

SCR_EndLoadingPlaque ();
memset (con_times, 0, sizeof(con_times));

Expand Down Expand Up @@ -276,6 +290,7 @@ static void Con_MessageMode_f (void)
return;
chat_team = false;
key_dest = key_message;
SetChatInfo (CIF_CHAT); // woods #chatinfo
}

/*
Expand All @@ -289,6 +304,7 @@ static void Con_MessageMode2_f (void)
return;
chat_team = true;
key_dest = key_message;
SetChatInfo (CIF_CHAT); // woods #chatinfo
}

/*
Expand Down
7 changes: 7 additions & 0 deletions Quake/in_sdl.c
Original file line number Diff line number Diff line change
Expand Up @@ -1229,9 +1229,13 @@ void IN_SendKeyEvents (void)
Sound_Toggle_Mute_Off_f();

if ((cl.gametype == GAME_DEATHMATCH) && (cls.state == ca_connected))
{
if (cl.modtype == 1 || cl.modtype == 4)
Cmd_ExecuteString("cmd afkoff", src_command); // afk

SetChatInfo (0); // woods #chatinfo
}

if (cl_afk.value) // woods #smartafk
{
if (strlen(afk_name) > 1) // intiate only if a AFK event has occured
Expand All @@ -1254,9 +1258,12 @@ void IN_SendKeyEvents (void)
Sound_Toggle_Mute_On_f(); // woods #mute -- adapted from Fitzquake Mark V

if ((cl.gametype == GAME_DEATHMATCH) && (cls.state == ca_connected))
{
if (cl.modtype == 1 || cl.modtype == 4) // woods if afk is NO
Cmd_ExecuteString("cmd afkon", src_command); // afk

SetChatInfo (CIF_AFK); // woods #chatinfo
}
if (cl_afk.value) // woods #smartafk
{
if (!strstr(cl_name.string, afktype)) // initiate AFK-in-name if AFK not already in the name
Expand Down
54 changes: 52 additions & 2 deletions Quake/keys.c
Original file line number Diff line number Diff line change
Expand Up @@ -1027,17 +1027,53 @@ void Key_Console (int key)
}
}

void Char_Console (int key)
/*
====================
woods #chatinfo -- deletct chat typing and set userinfo chat key, with a 3 second delay to set it back to 0
====================
*/

SDL_TimerID chatTimerID = 0;
qboolean isChatTimerRunning = false; // Track whether the timer is running
#define CHAT_TIMER_DELAY 3000 // 3000ms = 3 second delay

void ExecuteSetInfoChat()
{
if (cl_say.value)
SetChatInfo (0);
}

Uint32 ChatTimerCallback(Uint32 interval, void* param)
{
ExecuteSetInfoChat(); // function to execute the delayed code
chatTimerID = 0; // the timer has run
isChatTimerRunning = false;
return 0; // stop the timer after it's called once
}

void Char_Console(int key) // woods -- added detection for when typing in console to set chat to 1 for multiplayer games
{
size_t len;
char *workline = key_lines[edit_line];
int max;

if (cl_say.value) // woods #chatinfo
{
char tmp[3];
int chat;

Info_GetKey(cls.userinfo, "chat", tmp, sizeof(tmp));
chat = atoi(tmp);

if (chat == 0)
SetChatInfo(CIF_CHAT);
}

if (cl_say.value && (cls.state == ca_connected && cl.gametype == GAME_DEATHMATCH))
if ((cl.modtype == 1) || (cl.modtype == 4))
max = MAX_CHAT_SIZE_EX;
else
max = MAX_CHAT_SIZE;
max = MAX_CHAT_SIZE;
else
max = MAXCMDLINE;
if (key_linepos < max) // woods limit chat to 45 server limit #chatlimit
Expand Down Expand Up @@ -1068,6 +1104,19 @@ void Char_Console (int key)

Con_TabComplete (TABCOMPLETE_AUTOHINT);
}

if (cl_say.value) // woods #chatinfo --3 second delay to set chat to 0
{
if (isChatTimerRunning) // kill the existing timer if a new char event happens -- woods #chatinfo
{
SDL_RemoveTimer(chatTimerID);
isChatTimerRunning = false;
}

chatTimerID = SDL_AddTimer(CHAT_TIMER_DELAY, ChatTimerCallback, NULL); // woods #chatinfo
if (chatTimerID != 0)
isChatTimerRunning = true;
}
}

//============================================================================
Expand All @@ -1091,6 +1140,7 @@ void Key_EndChat (void)
key_dest = key_game;
chat_bufferlen = 0;
chat_buffer[0] = 0;
SetChatInfo (0); // woods #chatinfo
}

void PasteToMessage (void) // woods zircon (baker)
Expand Down

0 comments on commit d9914c6

Please sign in to comment.