whee, finally. stateful console mode :) nukes cl_chatmode.

This commit is contained in:
Bill Currie 2007-04-07 05:50:29 +00:00 committed by Jeff Teunissen
parent f621570dee
commit c6ea999d4d
6 changed files with 103 additions and 53 deletions

2
TODO
View file

@ -27,7 +27,7 @@ o doublesize modes (eg, render in 320x240 but display in 640x480)
o allow qf clients to download .lit files from qf servers.
o better server control of certain cvars
o triggers (f_respawn, f_death, f_took; cl_triggers)
o stateful console (eg, rcon mode, chat mode, normal command mode...)
X stateful console (eg, rcon mode, chat mode, normal command mode...)
o scripted hud
o add a U_PHYSICAL field to entities. it should include a solid bit,
a rotated bbox bit, and mins/maxs for the bbos

View file

@ -116,6 +116,7 @@ void Con_BufferAddText (con_buffer_t *buf, const char *text);
void Con_Init (const char *plugin_name);
void Con_Init_Cvars (void);
void Con_Shutdown (void);
void Con_ExecLine (const char *line);
void Con_ProcessInput (void);
void Con_KeyEvent (knum_t key, short unicode, qboolean down);

View file

@ -61,6 +61,8 @@ typedef struct console_data_s {
struct cbuf_s *cbuf;
struct view_s *view;
float lines;
int (*exec_line)(void *data, const char *line);
void *exec_data;
} console_data_t;
#endif // __QF_plugin_console_h_

View file

@ -86,7 +86,7 @@ static cvar_t *con_notifytime; // seconds
static cvar_t *con_alpha;
static cvar_t *con_size;
static cvar_t *con_speed;
static cvar_t *cl_chatmode;
static cvar_t *cl_conmode;
#define NUM_CON_TIMES 4
static float con_times[NUM_CON_TIMES]; // realtime time the line was generated
@ -284,48 +284,47 @@ Condump_f (void)
Qclose (file);
}
static qboolean
CheckForCommand (const char *line)
static int
cl_exec_line_command (void *data, const char *line)
{
char command[128];
const char *cmd;
int i;
Cbuf_AddText (con_data.cbuf, line);
Cbuf_AddText (con_data.cbuf, "\n");
return 1;
}
for (i = 0; i < 127; i++) {
if (line[i] <= ' ')
break;
else
command[i] = line[i];
}
command[i] = 0;
cmd = Cmd_CompleteCommand (command);
if (!cmd || strcmp (cmd, command))
cmd = Cvar_CompleteVariable (command);
if (!cmd || strcmp (cmd, command))
return false; // just a chat message
return true;
static int
cl_exec_line_chat (void *data, const char *line)
{
Cbuf_AddText (con_data.cbuf, "say ");
Cbuf_AddText (con_data.cbuf, line);
Cbuf_AddText (con_data.cbuf, "\n");
return 0;
}
static int
cl_exec_line_rcon (void *data, const char *line)
{
Cbuf_AddText (con_data.cbuf, "rcon ");
Cbuf_AddText (con_data.cbuf, line);
Cbuf_AddText (con_data.cbuf, "\n");
Con_Printf ("rcon %s\n", line);
return 0;
}
static void
C_ExecLine (const char *line)
cl_conmode_f (cvar_t *var)
{
if (line[0] == '/' && line [1] == '/')
goto no_lf;
else if (line[0] == '|')
Cbuf_AddText (con_data.cbuf, line);
else if (line[0] == '\\' || line[0] == '/')
Cbuf_AddText (con_data.cbuf, line + 1);
else if (cl_chatmode->int_val != 1 && CheckForCommand (line))
Cbuf_AddText (con_data.cbuf, line);
else if (cl_chatmode->int_val) {
Cbuf_AddText (con_data.cbuf, "say ");
Cbuf_AddText (con_data.cbuf, line);
} else
Cbuf_AddText (con_data.cbuf, line);
Cbuf_AddText (con_data.cbuf, "\n");
no_lf:
Con_Printf ("%s\n", line);
if (!strcmp (var->string, "command")) {
con_data.exec_line = cl_exec_line_command;
} else if (!strcmp (var->string, "chat")) {
con_data.exec_line = cl_exec_line_chat;
} else if (!strcmp (var->string, "rcon")) {
con_data.exec_line = cl_exec_line_rcon;
} else {
Con_Printf ("mode must be one of \"command\", \"chat\" or \"rcon\"\n");
Con_Printf (" forcing \"command\"\n");
Cvar_Set (var, "command");
}
}
static void
@ -812,9 +811,6 @@ C_Init (void)
con_notifytime = Cvar_Get ("con_notifytime", "3", CVAR_NONE, NULL,
"How long in seconds messages are displayed "
"on screen");
cl_chatmode = Cvar_Get ("cl_chatmode", "2", CVAR_NONE, NULL,
"Controls when console text will be treated as a "
"chat message: 0 - never, 1 - always, 2 - smart");
con_alpha = Cvar_Get ("con_alpha", "0.6", CVAR_ARCHIVE, NULL,
"alpha value for the console background");
@ -823,6 +819,8 @@ C_Init (void)
"down");
con_speed = Cvar_Get ("con_speed", "300", CVAR_ARCHIVE, NULL,
"How quickly the console scrolls up or down");
cl_conmode = Cvar_Get ("cl_conmode", "command", CVAR_ARCHIVE, cl_conmode_f,
"Set the console input mode (command, chat, rcon)");
con_debuglog = COM_CheckParm ("-condebug");
@ -877,7 +875,7 @@ C_Init (void)
input_line = Con_CreateInputLine (32, MAXCMDLINE, ']');
input_line->complete = Con_BasicCompleteCommandLine;
input_line->enter = C_ExecLine;
input_line->enter = Con_ExecLine;
input_line->width = con_linewidth;
input_line->user_data = 0;
input_line->draw = 0;

View file

@ -92,6 +92,30 @@ Con_Interp_f (cvar_t *var)
}
}
VISIBLE void
Con_ExecLine (const char *line)
{
console_data_t *cd = con_module->data->console;
int echo = 1;
if (line[0] == '/' && line [1] == '/') {
goto no_lf;
} else if (line[0] == '|') {
Cbuf_AddText (cd->cbuf, line);
Cbuf_AddText (cd->cbuf, "\n");
} else if (line[0] == '\\' || line[0] == '/') {
Cbuf_AddText (cd->cbuf, line + 1);
Cbuf_AddText (cd->cbuf, "\n");
} else if (cd->exec_line) {
echo = cd->exec_line (cd->exec_data, line);
} else {
Cbuf_AddText (cd->cbuf, line);
Cbuf_AddText (cd->cbuf, "\n");
}
no_lf:
if (echo)
Con_Printf ("%s\n", line);
}
VISIBLE void
Con_Init_Cvars (void)
{

View file

@ -75,8 +75,8 @@ static console_data_t sv_con_data;
static QFile *log_file;
static cvar_t *sv_logfile;
static cvar_t *sv_conmode;
static void C_ExecLine (const char *line);
static void C_KeyEvent (knum_t key, short unicode, qboolean down);
#ifdef HAVE_CURSES_H
@ -481,7 +481,7 @@ create_input_line (int width)
input_line = Con_CreateInputLine (16, MAXCMDLINE, ']');
input_line->complete = Con_BasicCompleteCommandLine;
input_line->enter = C_ExecLine;
input_line->enter = Con_ExecLine;
input_line->user_data = input;
input_line->draw = draw_input_line;
input_line->width = width;
@ -537,14 +537,6 @@ init (void)
}
#endif
static void
C_ExecLine (const char *line)
{
if (line[0] == '/')
line++;
Cbuf_AddText (sv_con_data.cbuf, line);
}
static void
sv_logfile_f (cvar_t *var)
{
@ -568,6 +560,37 @@ sv_logfile_f (cvar_t *var)
}
}
static int
sv_exec_line_command (void *data, const char *line)
{
Cbuf_AddText (sv_con_data.cbuf, line);
Cbuf_AddText (sv_con_data.cbuf, "\n");
return 1;
}
static int
sv_exec_line_chat (void *data, const char *line)
{
Cbuf_AddText (sv_con_data.cbuf, "say ");
Cbuf_AddText (sv_con_data.cbuf, line);
Cbuf_AddText (sv_con_data.cbuf, "\n");
return 0;
}
static void
sv_conmode_f (cvar_t *var)
{
if (!strcmp (var->string, "command")) {
sv_con_data.exec_line = sv_exec_line_command;
} else if (!strcmp (var->string, "chat")) {
sv_con_data.exec_line = sv_exec_line_chat;
} else {
Con_Printf ("mode must be one of \"command\" or \"chat\"\n");
Con_Printf (" forcing \"command\"\n");
Cvar_Set (var, "command");
}
}
static void
C_Init (void)
{
@ -583,6 +606,8 @@ C_Init (void)
sv_logfile = Cvar_Get ("sv_logfile", "none", CVAR_NONE, sv_logfile_f,
"Control server console logging. \"none\" for off, "
"or \"filename:gzflags\"");
sv_conmode = Cvar_Get ("sv_conmode", "command", CVAR_NONE, sv_conmode_f,
"Set the console input mode (command, chat)");
}
static void
@ -637,7 +662,7 @@ C_ProcessInput (void)
const char *cmd = Sys_ConsoleInput ();
if (!cmd)
break;
C_ExecLine (cmd);
Con_ExecLine (cmd);
}
}