Skip to content

Commit

Permalink
Merged pull request "Sync with Q2PRO: Client console input (cmds & cv…
Browse files Browse the repository at this point in the history
…ars)": NVIDIA#374
  • Loading branch information
apanteleev committed Feb 17, 2024
2 parents 3da27f8 + 53c3034 commit 8b88559
Show file tree
Hide file tree
Showing 11 changed files with 153 additions and 86 deletions.
16 changes: 13 additions & 3 deletions doc/client.md
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,12 @@ variable is a bitmask. Default value is 0.
- 1 — when new command is entered
- 2 — when new lines are printed

#### `con_auto_chat`
Specifies how console commands not starting with a slash or backslash
are handled while in game. Default value is 0.
- 0 — handle as regular commands
- 1 — forward as chat
- 2 — forward as team chat

### Game Screen

Expand Down Expand Up @@ -1792,10 +1798,11 @@ flag. _Value_ may be composed from multiple tokens.
Sets the specified _cvar_ to _value_, and marks the cvar with `archive`
flag. _Value_ may be composed from multiple tokens.

#### `cvarlist [-achlmnrstuvw:]`
#### `cvarlist [-achlmnrstuvw:] [wildcard]`
Display the list of registered cvars and their current values with
filtering by cvar name or by cvar flags. If no options are given,
all cvars are listed. Supported options are reproduced below.
all cvars are listed. Optional _wildcard_ argument filters cvars by name.
Supported options are reproduced below.

* `-a` or `--archive`: list archived cvars
* `-c` or `--cheat`: list cheat protected cvars
Expand All @@ -1808,7 +1815,6 @@ all cvars are listed. Supported options are reproduced below.
* `-t` or `--custom`: list user-created cvars
* `-u` or `--userinfo`: list userinfo cvars
* `-v` or `--verbose`: display flags of each cvar
* `-w` or `--wildcard=<string>`: list cvars matching wildcard `string`

#### `macrolist`
Display the list of registered macros and their current values.
Expand Down Expand Up @@ -1966,6 +1972,10 @@ Optional `count` argument specifies how far to go back in message history
(it should be positive integer). If `count` is omitted, then the most
recent IP address is used.

#### `remotemode <address> <password>`
Put client console into rcon mode. All commands entered will be forwarded
to remove server. Press Ctrl+D or close console to exit this mode.

#### `ogg <info|play|stop>`
Execute OGG subcommand. Available subcommands:
- `info`:
Expand Down
5 changes: 4 additions & 1 deletion inc/common/cmd.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ void Cbuf_Execute(cmdbuf_t *buf);
// Normally called once per frame, but may be explicitly invoked.
// Do not call inside a command function!

void Cbuf_Frame(cmdbuf_t *buf);
// Called once per frame. Decrements waitCount, resets aliasCount.

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

/*
Expand All @@ -96,7 +99,6 @@ typedef struct genctx_s {
} genctx_t;

typedef void (*xcommand_t)(void);
typedef void (*xcommandex_t)(cmdbuf_t *);
typedef size_t (*xmacro_t)(char *, size_t);
typedef void (*xcompleter_t)(struct genctx_s *, int);

Expand Down Expand Up @@ -192,6 +194,7 @@ void Cmd_WriteAliases(qhandle_t f);
do { \
if ((var)->string[0]) { \
Cbuf_AddText(&cmd_buffer, (var)->string); \
Cbuf_AddText(&cmd_buffer, "\n"); \
} \
} while(0)

Expand Down
1 change: 1 addition & 0 deletions inc/shared/shared.h
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,7 @@ int SortStricmp(const void *p1, const void *p2);

size_t COM_strclr(char *s);
char *COM_StripQuotes(char *s);
char *COM_TrimSpace(char *s);

// buffer safe operations
size_t Q_strlcpy(char *dst, const char *src, size_t size);
Expand Down
57 changes: 18 additions & 39 deletions src/client/console.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ typedef enum {
typedef enum {
CON_POPUP,
CON_DEFAULT,
CON_CHAT,
CON_REMOTE
} consoleMode_t;

Expand Down Expand Up @@ -98,6 +97,7 @@ static cvar_t *con_history;
static cvar_t *con_timestamps;
static cvar_t *con_timestampsformat;
static cvar_t *con_timestampscolor;
static cvar_t *con_auto_chat;

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

Expand Down Expand Up @@ -190,11 +190,6 @@ static void toggle_console(consoleMode_t mode, chatMode_t chat)
return;
}

if (mode == CON_CHAT && (cls.state != ca_active || cls.demo.playback)) {
Com_Printf("You must be in a level to chat.\n");
return;
}

// toggling console discards chat message
Key_SetDest((cls.key_dest | KEY_CONSOLE) & ~KEY_MESSAGE);
con.mode = mode;
Expand All @@ -206,16 +201,6 @@ void Con_ToggleConsole_f(void)
toggle_console(CON_DEFAULT, CHAT_NONE);
}

static void Con_ToggleChat_f(void)
{
toggle_console(CON_CHAT, CHAT_DEFAULT);
}

static void Con_ToggleChat2_f(void)
{
toggle_console(CON_CHAT, CHAT_TEAM);
}

/*
================
Con_Clear_f
Expand Down Expand Up @@ -446,8 +431,6 @@ static void con_timestampscolor_changed(cvar_t *self)

static const cmdreg_t c_console[] = {
{ "toggleconsole", Con_ToggleConsole_f },
{ "togglechat", Con_ToggleChat_f },
{ "togglechat2", Con_ToggleChat2_f },
{ "messagemode", Con_MessageMode_f },
{ "messagemode2", Con_MessageMode2_f },
{ "remotemode", Con_RemoteMode_f, CL_RemoteMode_c },
Expand Down Expand Up @@ -495,6 +478,7 @@ void Con_Init(void)
con_timestampscolor = Cvar_Get("con_timestampscolor", "#aaa", 0);
con_timestampscolor->changed = con_timestampscolor_changed;
con_timestampscolor_changed(con_timestampscolor);
con_auto_chat = Cvar_Get("con_auto_chat", "0", 0);

IF_Init(&con.prompt.inputLine, 0, MAX_FIELD_TEXT - 1);
IF_Init(&con.chatPrompt.inputLine, 0, MAX_FIELD_TEXT - 1);
Expand Down Expand Up @@ -961,17 +945,7 @@ static void Con_DrawSolidConsole(void)
y = vislines - CON_PRESTEP + CHAR_HEIGHT;

// draw command prompt
switch (con.mode) {
case CON_CHAT:
i = '&';
break;
case CON_REMOTE:
i = '#';
break;
default:
i = 17;
break;
}
i = con.mode == CON_REMOTE ? '#' : 17;
R_SetColor(U32_YELLOW);
R_DrawChar(CHAR_WIDTH, y, 0, i, con.charsetImage);
R_ClearColor();
Expand Down Expand Up @@ -1114,18 +1088,23 @@ static void Con_Action(void)
}

// backslash text are commands, else chat
if (cmd[0] == '\\' || cmd[0] == '/') {
Cbuf_AddText(&cmd_buffer, cmd + 1); // skip slash
Cbuf_AddText(&cmd_buffer, "\n");
int backslash = cmd[0] == '\\' || cmd[0] == '/';

if (con.mode == CON_REMOTE) {
CL_SendRcon(&con.remoteAddress, con.remotePassword, cmd + backslash);
} else {
if (con.mode == CON_REMOTE) {
CL_SendRcon(&con.remoteAddress, con.remotePassword, cmd);
} else if (cls.state == ca_active && con.mode == CON_CHAT) {
Con_Say(cmd);
} else {
Cbuf_AddText(&cmd_buffer, cmd);
Cbuf_AddText(&cmd_buffer, "\n");
if (!backslash && cls.state == ca_active) {
switch (con_auto_chat->integer) {
case CHAT_DEFAULT:
Cbuf_AddText(&cmd_buffer, "cmd say ");
break;
case CHAT_TEAM:
Cbuf_AddText(&cmd_buffer, "cmd say_team ");
break;
}
}
Cbuf_AddText(&cmd_buffer, cmd + backslash);
Cbuf_AddText(&cmd_buffer, "\n");
}

Con_Printf("]%s\n", cmd);
Expand Down
8 changes: 2 additions & 6 deletions src/client/input.c
Original file line number Diff line number Diff line change
Expand Up @@ -739,12 +739,8 @@ void CL_FinalizeCmd(void)
vec3_t move;

// command buffer ticks in sync with cl_maxfps
if (cmd_buffer.waitCount > 0) {
cmd_buffer.waitCount--;
}
if (cl_cmdbuf.waitCount > 0) {
cl_cmdbuf.waitCount--;
}
Cbuf_Frame(&cmd_buffer);
Cbuf_Frame(&cl_cmdbuf);

if (cls.state != ca_active) {
goto clear; // not talking to a server
Expand Down
3 changes: 0 additions & 3 deletions src/client/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -2597,14 +2597,12 @@ static const cmdreg_t c_client[] = {
{ "userinfo", CL_Userinfo_f },
{ "snd_restart", CL_RestartSound_f },
{ "play", CL_PlaySound_f, CL_PlaySound_c },
//{ "changing", CL_Changing_f },
{ "disconnect", CL_Disconnect_f },
{ "connect", CL_Connect_f, CL_Connect_c },
{ "followip", CL_FollowIP_f },
{ "passive", CL_PassiveConnect_f },
{ "reconnect", CL_Reconnect_f },
{ "rcon", CL_Rcon_f, CL_Rcon_c },
//{ "precache", CL_Precache_f },
{ "serverstatus", CL_ServerStatus_f, CL_ServerStatus_c },
{ "ignoretext", CL_IgnoreText_f },
{ "unignoretext", CL_UnIgnoreText_f },
Expand All @@ -2614,7 +2612,6 @@ static const cmdreg_t c_client[] = {
{ "dumpstatusbar", CL_DumpStatusbar_f },
{ "dumplayout", CL_DumpLayout_f },
{ "writeconfig", CL_WriteConfig_f, CL_WriteConfig_c },
// { "msgtab", CL_Msgtab_f, CL_Msgtab_g },
{ "vid_restart", CL_RestartRefresh_f },
{ "r_reload", CL_ReloadRefresh_f },

Expand Down
Loading

0 comments on commit 8b88559

Please sign in to comment.