2001-07-16 21:39:50 +00:00
|
|
|
/*
|
|
|
|
sv_console.c
|
|
|
|
|
|
|
|
ncurses console for the server
|
|
|
|
|
|
|
|
Copyright (C) 2001 Bill Currie <bill@taniwha.org>
|
|
|
|
|
|
|
|
Author: Bill Currie <bill@taniwha.org>
|
|
|
|
Date: 2001/7/10
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
|
|
|
See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to:
|
|
|
|
|
|
|
|
Free Software Foundation, Inc.
|
|
|
|
59 Temple Place - Suite 330
|
|
|
|
Boston, MA 02111-1307, USA
|
|
|
|
|
|
|
|
*/
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
2003-01-15 15:31:36 +00:00
|
|
|
|
2005-08-04 15:27:09 +00:00
|
|
|
static __attribute__ ((used)) const char rcsid[] =
|
2003-01-15 15:31:36 +00:00
|
|
|
"$Id$";
|
|
|
|
|
2001-07-16 21:39:50 +00:00
|
|
|
#ifdef HAVE_CURSES_H
|
|
|
|
# include <curses.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_STRING_H
|
|
|
|
# include <string.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_STRINGS_H
|
|
|
|
# include <strings.h>
|
|
|
|
#endif
|
2001-09-10 12:56:23 +00:00
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
# include <unistd.h>
|
|
|
|
#endif
|
|
|
|
|
2001-09-28 16:03:45 +00:00
|
|
|
#ifdef HAVE_SYS_IOCTL_H
|
|
|
|
# include <sys/ioctl.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_TERMIOS_H
|
|
|
|
# include <termios.h>
|
|
|
|
#endif
|
2001-09-25 20:16:24 +00:00
|
|
|
#include <signal.h>
|
2001-09-10 12:56:23 +00:00
|
|
|
#include <stdlib.h>
|
2001-07-16 21:39:50 +00:00
|
|
|
|
2002-07-31 05:19:03 +00:00
|
|
|
#include "QF/cbuf.h"
|
2001-07-16 21:39:50 +00:00
|
|
|
#include "QF/cmd.h"
|
|
|
|
#include "QF/console.h"
|
|
|
|
#include "QF/cvar.h"
|
2002-03-18 16:47:04 +00:00
|
|
|
#include "QF/dstring.h"
|
2001-09-16 05:41:28 +00:00
|
|
|
#include "QF/keys.h"
|
2001-07-16 23:15:27 +00:00
|
|
|
#include "QF/plugin.h"
|
2001-07-16 21:39:50 +00:00
|
|
|
#include "QF/qtypes.h"
|
2002-08-27 07:16:28 +00:00
|
|
|
#include "QF/quakefs.h"
|
2001-07-16 21:39:50 +00:00
|
|
|
#include "QF/sys.h"
|
2002-08-07 18:46:53 +00:00
|
|
|
#include "QF/va.h"
|
2005-06-14 11:30:33 +00:00
|
|
|
#include "QF/view.h"
|
2001-07-16 21:39:50 +00:00
|
|
|
|
2001-08-02 23:00:39 +00:00
|
|
|
#include "compat.h"
|
|
|
|
|
2005-06-08 10:07:48 +00:00
|
|
|
static console_data_t sv_con_data;
|
2001-09-16 05:41:28 +00:00
|
|
|
|
2002-08-27 07:16:28 +00:00
|
|
|
static QFile *log_file;
|
2002-08-07 18:46:53 +00:00
|
|
|
static cvar_t *sv_logfile;
|
|
|
|
|
2005-06-13 09:41:48 +00:00
|
|
|
static void C_ExecLine (const char *line);
|
|
|
|
static void C_KeyEvent (knum_t key, short unicode, qboolean down);
|
|
|
|
|
2001-07-18 18:22:13 +00:00
|
|
|
#ifdef HAVE_CURSES_H
|
2005-06-14 11:30:33 +00:00
|
|
|
|
|
|
|
typedef struct sv_view_s {
|
|
|
|
WINDOW *win;
|
|
|
|
void *obj;
|
|
|
|
void (*draw) (view_t *view);
|
|
|
|
void (*setgeometry) (view_t *view);
|
|
|
|
} sv_view_t;
|
|
|
|
|
|
|
|
enum {
|
|
|
|
sv_resize_x = 1,
|
|
|
|
sv_resize_y = 2,
|
|
|
|
sv_scroll = 4,
|
|
|
|
sv_cursor = 8,
|
|
|
|
};
|
|
|
|
|
2001-07-16 23:15:27 +00:00
|
|
|
static int use_curses = 1;
|
2001-07-16 21:39:50 +00:00
|
|
|
|
2005-06-14 11:30:33 +00:00
|
|
|
static view_t *output;
|
|
|
|
static view_t *status;
|
|
|
|
static view_t *input;
|
2001-07-16 23:15:27 +00:00
|
|
|
static int screen_x, screen_y;
|
2001-09-25 20:35:37 +00:00
|
|
|
static int interrupted;
|
2001-07-16 23:15:27 +00:00
|
|
|
|
2001-09-16 05:41:28 +00:00
|
|
|
#define MAXCMDLINE 256
|
|
|
|
|
2001-09-30 05:59:33 +00:00
|
|
|
#define BUFFER_SIZE 32768
|
|
|
|
#define MAX_LINES 1024
|
2004-01-22 04:07:39 +00:00
|
|
|
static int view_offset;
|
2001-09-30 05:59:33 +00:00
|
|
|
|
2001-07-16 21:39:50 +00:00
|
|
|
static chtype attr_table[4] = {
|
|
|
|
A_NORMAL,
|
|
|
|
COLOR_PAIR(1),
|
|
|
|
COLOR_PAIR(2),
|
|
|
|
COLOR_PAIR(3),
|
|
|
|
};
|
|
|
|
|
|
|
|
static const byte attr_map[256] = {
|
|
|
|
3, 3, 3, 3, 3, 3, 3, 3, 3, 0, 0, 3, 3, 0, 3, 3,
|
|
|
|
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
3, 3, 3, 3, 3, 3, 3, 3, 3, 0, 0, 3, 3, 0, 3, 3,
|
|
|
|
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
|
|
|
|
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
|
|
|
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
|
|
|
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
|
|
|
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
|
|
|
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
|
|
|
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
|
|
|
};
|
|
|
|
|
2001-09-10 12:56:23 +00:00
|
|
|
|
2001-10-01 16:09:06 +00:00
|
|
|
static inline void
|
|
|
|
draw_fun_char (WINDOW *win, byte c)
|
|
|
|
{
|
|
|
|
chtype ch = c;
|
|
|
|
ch = sys_char_map[ch] | attr_table[attr_map[ch]];
|
|
|
|
waddch (win, ch);
|
|
|
|
}
|
|
|
|
|
2005-06-14 11:30:33 +00:00
|
|
|
static inline void
|
|
|
|
sv_refresh (view_t *view)
|
|
|
|
{
|
|
|
|
sv_view_t *sv_view = view->data;
|
|
|
|
wnoutrefresh (sv_view->win);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
sv_getch (view_t *view)
|
|
|
|
{
|
|
|
|
sv_view_t *sv_view = view->data;
|
|
|
|
return wgetch (sv_view->win);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
sv_draw (view_t *view)
|
|
|
|
{
|
|
|
|
sv_view_t *sv_view = view->data;
|
|
|
|
if (sv_view->draw)
|
|
|
|
sv_view->draw (view);
|
|
|
|
wnoutrefresh (sv_view->win);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
sv_setgeometry (view_t *view)
|
|
|
|
{
|
|
|
|
sv_view_t *sv_view = view->data;
|
|
|
|
WINDOW *win = sv_view->win;
|
|
|
|
wresize (win, view->ylen, view->xlen);
|
|
|
|
mvwin (win, view->yabs, view->xabs);
|
|
|
|
if (sv_view->setgeometry)
|
|
|
|
sv_view->setgeometry (view);
|
|
|
|
}
|
|
|
|
|
2001-09-26 16:31:36 +00:00
|
|
|
static void
|
2005-06-14 11:30:33 +00:00
|
|
|
draw_output (view_t *view)
|
2001-09-28 23:10:15 +00:00
|
|
|
{
|
2005-06-14 11:30:33 +00:00
|
|
|
sv_view_t *sv_view = view->data;
|
|
|
|
WINDOW *win = sv_view->win;
|
|
|
|
con_buffer_t *output_buffer = sv_view->obj;
|
|
|
|
|
2001-09-30 05:59:33 +00:00
|
|
|
// this is not the most efficient way to update the screen, but oh well
|
2005-06-14 11:30:33 +00:00
|
|
|
int lines = view->ylen - 1; // leave a blank line
|
|
|
|
int width = view->xlen;
|
2004-01-22 04:07:39 +00:00
|
|
|
int cur_line = output_buffer->cur_line + view_offset;
|
2001-10-01 06:49:59 +00:00
|
|
|
int i, y;
|
2001-09-30 05:59:33 +00:00
|
|
|
|
|
|
|
if (lines < 1)
|
|
|
|
return;
|
|
|
|
|
2001-10-01 06:49:59 +00:00
|
|
|
for (y = i = 0; y < lines; i++, y++) {
|
2001-09-30 05:59:33 +00:00
|
|
|
con_line_t *l = Con_BufferLine (output_buffer, cur_line - i);
|
|
|
|
if (!l->text) {
|
|
|
|
i--;
|
|
|
|
break;
|
|
|
|
}
|
2001-10-01 06:49:59 +00:00
|
|
|
y += l->len / width; // really dumb line wrap algo :)
|
2001-09-30 05:59:33 +00:00
|
|
|
}
|
2001-10-01 06:49:59 +00:00
|
|
|
cur_line -= i;
|
|
|
|
y -= lines;
|
2005-06-14 11:30:33 +00:00
|
|
|
wclear (win);
|
|
|
|
wmove (win, 0, 0);
|
2001-09-30 05:59:33 +00:00
|
|
|
do {
|
|
|
|
con_line_t *l = Con_BufferLine (output_buffer, cur_line++);
|
|
|
|
byte *text = l->text;
|
|
|
|
int len = l->len;
|
|
|
|
|
2001-10-01 06:49:59 +00:00
|
|
|
if (y > 0) {
|
|
|
|
text += y * width;
|
|
|
|
len -= y * width;
|
|
|
|
y = 0;
|
|
|
|
if (len < 1) {
|
|
|
|
len = 1;
|
|
|
|
text = l->text + l->len - 1;
|
|
|
|
}
|
2001-09-30 05:59:33 +00:00
|
|
|
}
|
2001-10-01 16:09:06 +00:00
|
|
|
while (len--)
|
2005-06-14 11:30:33 +00:00
|
|
|
draw_fun_char (win, *text++);
|
2004-01-22 04:07:39 +00:00
|
|
|
} while (cur_line < output_buffer->cur_line + view_offset);
|
2001-09-28 23:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2005-06-14 11:30:33 +00:00
|
|
|
draw_status (view_t *view)
|
2001-09-28 23:10:15 +00:00
|
|
|
{
|
2005-06-14 11:30:33 +00:00
|
|
|
sv_view_t *sv_view = view->data;
|
|
|
|
wbkgdset (sv_view->win, COLOR_PAIR(4));
|
|
|
|
wclear (sv_view->win);
|
2001-09-28 23:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2005-06-14 11:30:33 +00:00
|
|
|
draw_input_line (inputline_t *il)
|
2001-09-26 16:31:36 +00:00
|
|
|
{
|
2005-06-14 11:30:33 +00:00
|
|
|
view_t *view = il->user_data;
|
|
|
|
sv_view_t *sv_view = view->data;
|
|
|
|
WINDOW *win = sv_view->win;
|
2003-04-17 00:01:48 +00:00
|
|
|
size_t i;
|
2001-09-26 16:31:36 +00:00
|
|
|
const char *text;
|
|
|
|
|
|
|
|
text = il->lines[il->edit_line] + il->scroll;
|
|
|
|
wmove (win, 0, 0);
|
|
|
|
if (il->scroll) {
|
|
|
|
waddch (win, '<' | COLOR_PAIR (5));
|
|
|
|
text++;
|
|
|
|
} else {
|
|
|
|
waddch (win, *text++);
|
|
|
|
}
|
|
|
|
for (i = 0; i < il->width - 2 && *text; i++) {
|
|
|
|
chtype ch = (byte)*text++;
|
|
|
|
ch = sys_char_map[ch] | attr_table[attr_map[ch]];
|
|
|
|
waddch (win, ch);
|
|
|
|
}
|
|
|
|
while (i++ < il->width - 2) {
|
|
|
|
waddch (win, ' ');
|
|
|
|
}
|
|
|
|
if (*text) {
|
|
|
|
waddch (win, '>' | COLOR_PAIR (5));
|
|
|
|
} else {
|
|
|
|
waddch (win, ' ');
|
|
|
|
}
|
|
|
|
wmove (win, 0, il->linepos - il->scroll);
|
2005-06-14 11:30:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
draw_input (view_t *view)
|
|
|
|
{
|
|
|
|
sv_view_t *sv_view = view->data;
|
|
|
|
draw_input_line (sv_view->obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
setgeometry_input (view_t *view)
|
|
|
|
{
|
|
|
|
sv_view_t *sv_view = view->data;
|
|
|
|
inputline_t *il = sv_view->obj;
|
|
|
|
il->width = view->xlen;
|
2001-09-26 16:31:36 +00:00
|
|
|
}
|
|
|
|
|
2001-09-25 20:16:24 +00:00
|
|
|
static void
|
|
|
|
sigwinch (int sig)
|
|
|
|
{
|
2001-09-25 20:35:37 +00:00
|
|
|
interrupted = 1;
|
2001-09-25 20:16:24 +00:00
|
|
|
signal (SIGWINCH, sigwinch);
|
|
|
|
}
|
2005-06-13 09:41:48 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
process_input (void)
|
|
|
|
{
|
|
|
|
int ch;
|
|
|
|
int escape = 0;
|
|
|
|
|
|
|
|
if (interrupted) {
|
|
|
|
struct winsize size;
|
|
|
|
|
|
|
|
interrupted = 0;
|
|
|
|
if (ioctl (fileno (stdout), TIOCGWINSZ, &size) == 0) {
|
|
|
|
resizeterm (size.ws_row, size.ws_col);
|
|
|
|
getmaxyx (stdscr, screen_y, screen_x);
|
|
|
|
con_linewidth = screen_x;
|
2005-06-14 11:30:33 +00:00
|
|
|
view_resize (sv_con_data.view, screen_x, screen_y);
|
|
|
|
view_draw (sv_con_data.view);
|
2005-06-13 09:41:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (ch = 1; ch; ) {
|
2005-06-14 11:30:33 +00:00
|
|
|
ch = sv_getch (input);
|
2005-06-13 09:41:48 +00:00
|
|
|
if (ch == ERR)
|
|
|
|
escape = 0;
|
|
|
|
if (escape) {
|
|
|
|
switch (escape) {
|
|
|
|
case 1:
|
|
|
|
if (ch == '[') {
|
|
|
|
escape = 2;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
switch (ch) {
|
|
|
|
case '1':
|
|
|
|
escape = 3;
|
|
|
|
continue;
|
|
|
|
case '4':
|
|
|
|
escape = 4;
|
|
|
|
continue;
|
|
|
|
default:
|
|
|
|
escape = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
if (ch == '~')
|
|
|
|
ch = KEY_HOME;
|
|
|
|
escape = 0;
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
if (ch == '~')
|
|
|
|
ch = KEY_END;
|
|
|
|
escape = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
switch (ch) {
|
|
|
|
case '\033':
|
|
|
|
escape = 1;
|
|
|
|
continue;
|
|
|
|
case KEY_ENTER:
|
|
|
|
case '\n':
|
|
|
|
case '\r':
|
|
|
|
ch = QFK_RETURN;
|
|
|
|
break;
|
|
|
|
case '\t':
|
|
|
|
ch = QFK_TAB;
|
|
|
|
break;
|
|
|
|
case KEY_BACKSPACE:
|
|
|
|
case '\b':
|
|
|
|
ch = QFK_BACKSPACE;
|
|
|
|
break;
|
|
|
|
case KEY_DC:
|
|
|
|
ch = QFK_DELETE;
|
|
|
|
break;
|
|
|
|
case KEY_RIGHT:
|
|
|
|
ch = QFK_RIGHT;
|
|
|
|
break;
|
|
|
|
case KEY_LEFT:
|
|
|
|
ch = QFK_LEFT;
|
|
|
|
break;
|
|
|
|
case KEY_UP:
|
|
|
|
ch = QFK_UP;
|
|
|
|
break;
|
|
|
|
case KEY_DOWN:
|
|
|
|
ch = QFK_DOWN;
|
|
|
|
break;
|
|
|
|
case KEY_HOME:
|
|
|
|
ch = QFK_HOME;
|
|
|
|
break;
|
|
|
|
case KEY_END:
|
|
|
|
ch = QFK_END;
|
|
|
|
break;
|
|
|
|
case KEY_NPAGE:
|
|
|
|
ch = QFK_PAGEDOWN;
|
|
|
|
break;
|
|
|
|
case KEY_PPAGE:
|
|
|
|
ch = QFK_PAGEUP;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (ch < 0 || ch >= 256)
|
|
|
|
ch = 0;
|
|
|
|
}
|
|
|
|
C_KeyEvent (ch, 0, 1);
|
|
|
|
}
|
|
|
|
doupdate ();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
key_event (knum_t key, short unicode, qboolean down)
|
|
|
|
{
|
|
|
|
int ovf = view_offset;
|
2005-06-14 11:30:33 +00:00
|
|
|
sv_view_t *sv_view;
|
|
|
|
con_buffer_t *buffer;
|
2005-06-13 09:41:48 +00:00
|
|
|
|
|
|
|
switch (key) {
|
|
|
|
case QFK_PAGEUP:
|
|
|
|
view_offset -= 10;
|
2005-06-14 11:30:33 +00:00
|
|
|
sv_view = output->data;
|
|
|
|
buffer = sv_view->obj;
|
|
|
|
if (view_offset <= -(buffer->num_lines - (screen_y - 3)))
|
|
|
|
view_offset = -(buffer->num_lines - (screen_y - 3)) + 1;
|
2005-06-13 09:41:48 +00:00
|
|
|
if (ovf != view_offset)
|
2005-06-14 11:30:33 +00:00
|
|
|
sv_draw (output);
|
2005-06-13 09:41:48 +00:00
|
|
|
break;
|
|
|
|
case QFK_PAGEDOWN:
|
|
|
|
view_offset += 10;
|
|
|
|
if (view_offset > 0)
|
|
|
|
view_offset = 0;
|
|
|
|
if (ovf != view_offset)
|
2005-06-14 11:30:33 +00:00
|
|
|
sv_draw (output);
|
2005-06-13 09:41:48 +00:00
|
|
|
break;
|
|
|
|
case '\f':
|
2005-06-14 11:30:33 +00:00
|
|
|
sv_draw (output);
|
2005-06-13 09:41:48 +00:00
|
|
|
break;
|
|
|
|
default:
|
2005-06-14 11:30:33 +00:00
|
|
|
sv_view = input->data;
|
|
|
|
Con_ProcessInputLine (sv_view->obj, key);
|
2005-06-13 09:41:48 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
print (char *txt)
|
|
|
|
{
|
2005-06-14 11:30:33 +00:00
|
|
|
sv_view_t *sv_view = output->data;
|
|
|
|
Con_BufferAddText (sv_view->obj, txt);
|
2005-06-13 09:41:48 +00:00
|
|
|
if (!view_offset) {
|
|
|
|
while (*txt)
|
2005-06-14 11:30:33 +00:00
|
|
|
draw_fun_char (sv_view->win, (byte) *txt++);
|
|
|
|
sv_refresh (output);
|
|
|
|
// move the cursor back to the input line
|
|
|
|
sv_refresh (input);
|
2005-06-13 09:41:48 +00:00
|
|
|
doupdate ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-06-14 11:30:33 +00:00
|
|
|
static view_t *
|
|
|
|
create_window (view_t *parent, int xpos, int ypos, int xlen, int ylen,
|
|
|
|
grav_t grav, void *obj, int opts, void (*draw) (view_t *),
|
|
|
|
void (*setgeometry) (view_t *))
|
|
|
|
{
|
|
|
|
view_t *view;
|
|
|
|
sv_view_t *sv_view;
|
|
|
|
|
|
|
|
sv_view = calloc (1, sizeof (sv_view_t));
|
|
|
|
sv_view->obj = obj;
|
|
|
|
sv_view->win = newwin (ylen, xlen, 0, 0); // will get moved when added
|
|
|
|
scrollok (sv_view->win, (opts & sv_scroll) ? TRUE : FALSE);
|
|
|
|
leaveok (sv_view->win, (opts & sv_cursor) ? FALSE : TRUE);
|
|
|
|
nodelay (sv_view->win, TRUE);
|
|
|
|
keypad (sv_view->win, TRUE);
|
|
|
|
sv_view->draw = draw;
|
|
|
|
sv_view->setgeometry = setgeometry;
|
|
|
|
|
|
|
|
view = view_new (xpos, ypos, xlen, ylen, grav);
|
|
|
|
view->data = sv_view;
|
|
|
|
view->draw = sv_draw;
|
|
|
|
view->setgeometry = sv_setgeometry;
|
|
|
|
view->resize_x = (opts & sv_resize_x) != 0;
|
|
|
|
view->resize_y = (opts & sv_resize_y) != 0;
|
|
|
|
view_add (parent, view);
|
|
|
|
|
|
|
|
return view;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inputline_t *
|
|
|
|
create_input_line (int width)
|
|
|
|
{
|
|
|
|
inputline_t *input_line;
|
|
|
|
|
|
|
|
input_line = Con_CreateInputLine (16, MAXCMDLINE, ']');
|
|
|
|
input_line->complete = Con_BasicCompleteCommandLine;
|
|
|
|
input_line->enter = C_ExecLine;
|
|
|
|
input_line->user_data = input;
|
|
|
|
input_line->draw = draw_input_line;
|
|
|
|
input_line->width = width;
|
|
|
|
|
|
|
|
return input_line;
|
|
|
|
}
|
|
|
|
|
2005-06-13 09:41:48 +00:00
|
|
|
static void
|
|
|
|
init (void)
|
|
|
|
{
|
|
|
|
signal (SIGWINCH, sigwinch);
|
|
|
|
|
|
|
|
initscr ();
|
|
|
|
start_color ();
|
|
|
|
cbreak ();
|
|
|
|
noecho ();
|
|
|
|
|
|
|
|
nonl ();
|
|
|
|
intrflush (stdscr, FALSE);
|
|
|
|
|
|
|
|
getmaxyx (stdscr, screen_y, screen_x);
|
2005-06-14 11:30:33 +00:00
|
|
|
sv_con_data.view = view_new (0, 0, screen_x, screen_y, grav_northwest);
|
|
|
|
|
|
|
|
output = create_window (sv_con_data.view,
|
|
|
|
0, 0, screen_x, screen_y - 2, grav_northwest,
|
|
|
|
Con_CreateBuffer (BUFFER_SIZE, MAX_LINES),
|
|
|
|
sv_resize_x | sv_resize_y | sv_scroll,
|
|
|
|
draw_output, 0);
|
|
|
|
|
|
|
|
status = create_window (sv_con_data.view,
|
|
|
|
0, 1, screen_x, 1, grav_southwest,
|
|
|
|
0,
|
|
|
|
sv_resize_x | sv_scroll,
|
|
|
|
draw_status, 0);
|
|
|
|
|
|
|
|
input = create_window (sv_con_data.view,
|
|
|
|
0, 0, screen_x, 1, grav_southwest,
|
|
|
|
create_input_line (screen_x),
|
|
|
|
sv_resize_x | sv_cursor,
|
|
|
|
draw_input, setgeometry_input);
|
|
|
|
((inputline_t *) ((sv_view_t *) input->data)->obj)->user_data = input;
|
2005-06-13 09:41:48 +00:00
|
|
|
|
|
|
|
init_pair (1, COLOR_YELLOW, COLOR_BLACK);
|
|
|
|
init_pair (2, COLOR_GREEN, COLOR_BLACK);
|
|
|
|
init_pair (3, COLOR_RED, COLOR_BLACK);
|
|
|
|
init_pair (4, COLOR_YELLOW, COLOR_BLUE);
|
|
|
|
init_pair (5, COLOR_CYAN, COLOR_BLACK);
|
|
|
|
|
|
|
|
con_linewidth = screen_x;
|
|
|
|
|
2005-06-14 11:30:33 +00:00
|
|
|
view_draw (sv_con_data.view);
|
2005-06-13 09:41:48 +00:00
|
|
|
doupdate ();
|
|
|
|
}
|
2001-09-21 17:28:35 +00:00
|
|
|
#endif
|
2001-09-16 05:41:28 +00:00
|
|
|
|
2003-06-04 18:07:12 +00:00
|
|
|
static void
|
|
|
|
C_ExecLine (const char *line)
|
|
|
|
{
|
|
|
|
if (line[0] == '/')
|
|
|
|
line++;
|
2005-06-08 10:07:48 +00:00
|
|
|
Cbuf_AddText (sv_con_data.cbuf, line);
|
2003-06-04 18:07:12 +00:00
|
|
|
}
|
|
|
|
|
2002-08-07 18:46:53 +00:00
|
|
|
static void
|
|
|
|
sv_logfile_f (cvar_t *var)
|
|
|
|
{
|
2005-06-13 09:41:48 +00:00
|
|
|
if (!var->string[0] || strequal (var->string, "none")) {
|
2002-08-07 18:46:53 +00:00
|
|
|
if (log_file)
|
|
|
|
Qclose (log_file);
|
|
|
|
log_file = 0;
|
|
|
|
} else {
|
|
|
|
char *fname = strdup (var->string);
|
|
|
|
char *flags = strrchr (fname, ':');
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
if (flags) {
|
2002-08-07 18:46:53 +00:00
|
|
|
*flags++ = 0;
|
2003-01-06 18:28:13 +00:00
|
|
|
flags = nva ("a%s", flags);
|
|
|
|
} else {
|
|
|
|
flags = nva ("a");
|
|
|
|
}
|
2003-05-23 17:17:01 +00:00
|
|
|
log_file = QFS_Open (fname, flags);
|
2002-08-07 18:46:53 +00:00
|
|
|
free (flags);
|
|
|
|
free (fname);
|
|
|
|
}
|
|
|
|
}
|
2001-09-16 05:41:28 +00:00
|
|
|
|
2001-07-16 23:15:27 +00:00
|
|
|
static void
|
|
|
|
C_Init (void)
|
2001-07-16 21:39:50 +00:00
|
|
|
{
|
2001-09-20 19:34:02 +00:00
|
|
|
#ifdef HAVE_CURSES_H
|
2002-12-02 20:03:12 +00:00
|
|
|
cvar_t *curses = Cvar_Get ("sv_use_curses", "0", CVAR_ROM, NULL,
|
|
|
|
"Set to 1 to enable curses server console.");
|
2001-09-20 06:51:25 +00:00
|
|
|
use_curses = curses->int_val;
|
2001-07-16 23:15:27 +00:00
|
|
|
if (use_curses) {
|
2005-06-13 09:41:48 +00:00
|
|
|
init ();
|
2001-08-09 15:33:44 +00:00
|
|
|
} else
|
2001-07-16 23:15:27 +00:00
|
|
|
#endif
|
2001-08-09 15:33:44 +00:00
|
|
|
setvbuf (stdout, 0, _IOLBF, BUFSIZ);
|
2002-08-07 18:46:53 +00:00
|
|
|
sv_logfile = Cvar_Get ("sv_logfile", "none", CVAR_NONE, sv_logfile_f,
|
|
|
|
"Control server console logging. \"none\" for off, "
|
|
|
|
"or \"filename:gzflags\"");
|
2001-07-16 21:39:50 +00:00
|
|
|
}
|
|
|
|
|
2001-07-16 23:15:27 +00:00
|
|
|
static void
|
|
|
|
C_Shutdown (void)
|
2001-07-16 21:39:50 +00:00
|
|
|
{
|
2002-08-07 18:46:53 +00:00
|
|
|
if (log_file) {
|
|
|
|
Qclose (log_file);
|
|
|
|
log_file = 0;
|
|
|
|
}
|
2001-07-16 23:15:27 +00:00
|
|
|
#ifdef HAVE_CURSES_H
|
|
|
|
if (use_curses)
|
|
|
|
endwin ();
|
|
|
|
#endif
|
2001-07-16 21:39:50 +00:00
|
|
|
}
|
|
|
|
|
2001-07-16 23:15:27 +00:00
|
|
|
static void
|
|
|
|
C_Print (const char *fmt, va_list args)
|
2001-07-16 21:39:50 +00:00
|
|
|
{
|
2002-03-08 23:11:42 +00:00
|
|
|
static dstring_t *buffer;
|
2001-09-25 16:19:26 +00:00
|
|
|
|
2002-03-08 23:11:42 +00:00
|
|
|
if (!buffer)
|
|
|
|
buffer = dstring_new ();
|
|
|
|
|
|
|
|
dvsprintf (buffer, fmt, args);
|
|
|
|
|
2003-10-22 09:04:18 +00:00
|
|
|
if (log_file) {
|
2002-08-07 18:46:53 +00:00
|
|
|
Qputs (log_file, buffer->str);
|
2003-10-22 09:04:18 +00:00
|
|
|
Qflush (log_file);
|
|
|
|
}
|
2001-07-16 23:15:27 +00:00
|
|
|
#ifdef HAVE_CURSES_H
|
|
|
|
if (use_curses) {
|
2005-06-13 09:41:48 +00:00
|
|
|
print (buffer->str);
|
2001-07-16 23:15:27 +00:00
|
|
|
} else
|
|
|
|
#endif
|
2001-09-25 16:13:41 +00:00
|
|
|
{
|
2005-06-13 09:41:48 +00:00
|
|
|
unsigned char *txt = (unsigned char *) buffer->str;
|
2001-09-25 16:19:26 +00:00
|
|
|
while (*txt)
|
|
|
|
putc (sys_char_map[*txt++], stdout);
|
2001-09-25 16:13:41 +00:00
|
|
|
fflush (stdout);
|
|
|
|
}
|
2001-07-16 21:39:50 +00:00
|
|
|
}
|
|
|
|
|
2001-09-16 05:41:28 +00:00
|
|
|
static void
|
|
|
|
C_ProcessInput (void)
|
|
|
|
{
|
|
|
|
#ifdef HAVE_CURSES_H
|
|
|
|
if (use_curses) {
|
2005-06-13 09:41:48 +00:00
|
|
|
process_input ();
|
2001-09-16 05:41:28 +00:00
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
while (1) {
|
|
|
|
const char *cmd = Sys_ConsoleInput ();
|
|
|
|
if (!cmd)
|
2001-09-16 06:08:09 +00:00
|
|
|
break;
|
2003-04-26 05:12:16 +00:00
|
|
|
C_ExecLine (cmd);
|
2001-09-16 05:41:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2002-01-19 04:37:47 +00:00
|
|
|
C_KeyEvent (knum_t key, short unicode, qboolean down)
|
|
|
|
{
|
2004-01-27 05:23:36 +00:00
|
|
|
#ifdef HAVE_CURSES_H
|
2005-06-13 09:41:48 +00:00
|
|
|
key_event (key, unicode, down);
|
2004-01-22 04:42:06 +00:00
|
|
|
#endif
|
2002-01-19 04:37:47 +00:00
|
|
|
}
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2003-07-25 22:21:47 +00:00
|
|
|
C_DrawConsole (void)
|
2002-01-19 04:37:47 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2002-01-19 04:37:47 +00:00
|
|
|
C_CheckResize (void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2002-01-19 04:37:47 +00:00
|
|
|
C_NewMap (void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2001-07-16 23:15:27 +00:00
|
|
|
static general_funcs_t plugin_info_general_funcs = {
|
|
|
|
C_Init,
|
|
|
|
C_Shutdown,
|
|
|
|
};
|
|
|
|
static general_data_t plugin_info_general_data;
|
2001-07-16 21:39:50 +00:00
|
|
|
|
2001-07-16 23:15:27 +00:00
|
|
|
static console_funcs_t plugin_info_console_funcs = {
|
|
|
|
C_Print,
|
2001-09-16 05:41:28 +00:00
|
|
|
C_ProcessInput,
|
2002-01-19 04:37:47 +00:00
|
|
|
C_KeyEvent,
|
|
|
|
C_DrawConsole,
|
|
|
|
C_CheckResize,
|
|
|
|
C_NewMap,
|
2001-07-16 23:15:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static plugin_funcs_t plugin_info_funcs = {
|
|
|
|
&plugin_info_general_funcs,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
&plugin_info_console_funcs,
|
|
|
|
};
|
2001-07-16 21:39:50 +00:00
|
|
|
|
2001-07-16 23:15:27 +00:00
|
|
|
static plugin_data_t plugin_info_data = {
|
|
|
|
&plugin_info_general_data,
|
|
|
|
0,
|
|
|
|
0,
|
2005-06-08 10:07:48 +00:00
|
|
|
&sv_con_data,
|
2001-07-16 23:15:27 +00:00
|
|
|
};
|
2001-07-16 21:39:50 +00:00
|
|
|
|
2001-07-16 23:15:27 +00:00
|
|
|
static plugin_t plugin_info = {
|
|
|
|
qfp_console,
|
|
|
|
0,
|
|
|
|
QFPLUGIN_VERSION,
|
|
|
|
"0.1",
|
|
|
|
"server console driver",
|
|
|
|
"Copyright (C) 1996-1997 id Software, Inc.\n"
|
|
|
|
"Copyright (C) 1999,2000,2001 contributors of the QuakeForge"
|
|
|
|
" project\n"
|
|
|
|
"Please see the file \"AUTHORS\" for a list of contributors",
|
|
|
|
&plugin_info_funcs,
|
|
|
|
&plugin_info_data,
|
|
|
|
};
|
|
|
|
|
2003-08-01 19:53:46 +00:00
|
|
|
PLUGIN_INFO(console, server)
|
2001-07-16 23:15:27 +00:00
|
|
|
{
|
|
|
|
return &plugin_info;
|
2001-07-16 21:39:50 +00:00
|
|
|
}
|