This repository has been archived on 2022-06-27. You can view files and clone it, but cannot push or open issues or pull requests.
Xash3DArchive/engine/common/sys_con.c

540 lines
14 KiB
C
Raw Normal View History

2011-05-09 22:00:00 +02:00
/*
sys_con.c - win32 dedicated and developer console
Copyright (C) 2007 Uncle Mike
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 3 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.
*/
2007-11-10 22:00:00 +01:00
2011-03-12 22:00:00 +01:00
#include "common.h"
2007-11-10 22:00:00 +01:00
/*
===============================================================================
WIN32 CONSOLE
===============================================================================
*/
2009-01-13 22:00:00 +01:00
// console defines
2007-11-10 22:00:00 +01:00
#define SUBMIT_ID 1 // "submit" button
2009-01-13 22:00:00 +01:00
#define QUIT_ON_ESCAPE_ID 2 // escape event
2007-11-11 22:00:00 +01:00
#define EDIT_ID 110
#define INPUT_ID 109
2007-11-10 22:00:00 +01:00
#define IDI_ICON1 101
2010-02-18 22:00:00 +01:00
2011-04-08 22:00:00 +02:00
#define SYSCONSOLE "XashConsole"
2010-02-18 22:00:00 +01:00
#define COMMAND_HISTORY 64 // system console keep more commands than game console
2007-11-10 22:00:00 +01:00
typedef struct
{
2011-03-12 22:00:00 +01:00
char title[64];
2007-11-10 22:00:00 +01:00
HWND hWnd;
HWND hwndBuffer;
HWND hwndButtonSubmit;
HBRUSH hbrEditBackground;
HFONT hfBufferFont;
HWND hwndInputLine;
2010-02-18 22:00:00 +01:00
string consoleText;
string returnedText;
string historyLines[COMMAND_HISTORY];
int nextHistoryLine;
int historyLine;
2007-11-10 22:00:00 +01:00
int status;
int windowWidth, windowHeight;
WNDPROC SysInputLineWndProc;
2009-09-10 22:00:00 +02:00
size_t outLen;
2011-03-12 22:00:00 +01:00
// log stuff
qboolean log_active;
char log_path[MAX_SYSPATH];
FILE *logfile;
2007-11-10 22:00:00 +01:00
} WinConData;
2011-03-12 22:00:00 +01:00
static WinConData s_wcd;
2007-11-10 22:00:00 +01:00
2010-10-26 22:00:00 +02:00
void Con_ShowConsole( qboolean show )
2007-11-10 22:00:00 +01:00
{
2011-02-11 22:00:00 +01:00
if( !s_wcd.hWnd || show == s_wcd.status )
2007-11-10 22:00:00 +01:00
return;
s_wcd.status = show;
if( show )
{
ShowWindow( s_wcd.hWnd, SW_SHOWNORMAL );
SendMessage( s_wcd.hwndBuffer, EM_LINESCROLL, 0, 0xffff );
}
else ShowWindow( s_wcd.hWnd, SW_HIDE );
}
2010-02-18 22:00:00 +01:00
void Con_DisableInput( void )
{
2011-03-12 22:00:00 +01:00
if( host.type != HOST_DEDICATED ) return;
2010-02-18 22:00:00 +01:00
SendMessage( s_wcd.hwndButtonSubmit, WM_ENABLE, 0, 0 );
SendMessage( s_wcd.hwndInputLine, WM_ENABLE, 0, 0 );
}
void Con_SetInputText( const char *inputText )
2007-11-10 22:00:00 +01:00
{
2011-03-12 22:00:00 +01:00
if( host.type != HOST_DEDICATED ) return;
2010-02-18 22:00:00 +01:00
SetWindowText( s_wcd.hwndInputLine, inputText );
2011-03-12 22:00:00 +01:00
SendMessage( s_wcd.hwndInputLine, EM_SETSEL, Q_strlen( inputText ), -1 );
2010-02-18 22:00:00 +01:00
}
2007-11-10 22:00:00 +01:00
2012-04-06 22:00:00 +02:00
static void Con_Clear_f( void )
{
if( host.type != HOST_DEDICATED ) return;
SendMessage( s_wcd.hwndBuffer, EM_SETSEL, 0, -1 );
SendMessage( s_wcd.hwndBuffer, EM_REPLACESEL, FALSE, (LPARAM)"" );
UpdateWindow( s_wcd.hwndBuffer );
}
2010-10-26 22:00:00 +02:00
static int Con_KeyEvent( int key, qboolean down )
2010-07-24 22:00:00 +02:00
{
char inputBuffer[1024];
if( !down )
return 0;
switch( key )
{
case VK_TAB:
GetWindowText( s_wcd.hwndInputLine, inputBuffer, sizeof( inputBuffer ));
2011-03-12 22:00:00 +01:00
Cmd_AutoComplete( inputBuffer );
2010-07-24 22:00:00 +02:00
Con_SetInputText( inputBuffer );
return 1;
case VK_DOWN:
if( s_wcd.historyLine == s_wcd.nextHistoryLine )
return 0;
s_wcd.historyLine++;
Con_SetInputText( s_wcd.historyLines[s_wcd.historyLine % COMMAND_HISTORY] );
return 1;
case VK_UP:
if( s_wcd.nextHistoryLine - s_wcd.historyLine < COMMAND_HISTORY && s_wcd.historyLine > 0 )
s_wcd.historyLine--;
Con_SetInputText( s_wcd.historyLines[s_wcd.historyLine % COMMAND_HISTORY] );
return 1;
}
return 0;
}
2010-02-18 22:00:00 +01:00
static long _stdcall Con_WndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch( uMsg )
2007-11-10 22:00:00 +01:00
{
case WM_ACTIVATE:
2010-02-18 22:00:00 +01:00
if( LOWORD( wParam ) != WA_INACTIVE )
SetFocus( s_wcd.hwndInputLine );
2007-11-10 22:00:00 +01:00
break;
case WM_CLOSE:
2018-02-25 22:00:00 +01:00
if( host.status == HOST_ERR_FATAL )
2007-11-10 22:00:00 +01:00
{
// send windows message
PostQuitMessage( 0 );
}
2011-03-12 22:00:00 +01:00
else Sys_Quit(); // otherwise
2007-11-10 22:00:00 +01:00
return 0;
case WM_CTLCOLORSTATIC:
2011-03-12 22:00:00 +01:00
if((HWND)lParam == s_wcd.hwndBuffer )
2007-11-10 22:00:00 +01:00
{
2011-03-12 22:00:00 +01:00
SetBkColor((HDC)wParam, RGB( 0x90, 0x90, 0x90 ));
SetTextColor((HDC)wParam, RGB( 0xff, 0xff, 0xff ));
2010-02-18 22:00:00 +01:00
return (long)s_wcd.hbrEditBackground;
2007-11-10 22:00:00 +01:00
}
break;
case WM_COMMAND:
2010-02-18 22:00:00 +01:00
if( wParam == SUBMIT_ID )
2007-11-10 22:00:00 +01:00
{
2010-02-18 22:00:00 +01:00
SendMessage( s_wcd.hwndInputLine, WM_CHAR, 13, 0L );
2007-11-10 22:00:00 +01:00
SetFocus( s_wcd.hwndInputLine );
}
break;
case WM_HOTKEY:
2010-02-18 22:00:00 +01:00
switch( LOWORD( wParam ))
2007-11-10 22:00:00 +01:00
{
2009-01-13 22:00:00 +01:00
case QUIT_ON_ESCAPE_ID:
2007-11-10 22:00:00 +01:00
PostQuitMessage( 0 );
break;
}
break;
case WM_CREATE:
2010-02-18 22:00:00 +01:00
s_wcd.hbrEditBackground = CreateSolidBrush( RGB( 0x90, 0x90, 0x90 ));
2007-11-10 22:00:00 +01:00
break;
}
return DefWindowProc( hWnd, uMsg, wParam, lParam );
}
2010-02-18 22:00:00 +01:00
long _stdcall Con_InputLineProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
2007-11-10 22:00:00 +01:00
{
2010-02-18 22:00:00 +01:00
char inputBuffer[1024];
2007-11-10 22:00:00 +01:00
2010-02-18 22:00:00 +01:00
switch( uMsg )
2007-11-10 22:00:00 +01:00
{
case WM_KILLFOCUS:
2010-02-18 22:00:00 +01:00
if(( HWND )wParam == s_wcd.hWnd )
2007-11-10 22:00:00 +01:00
{
SetFocus( hWnd );
return 0;
}
break;
2010-07-24 22:00:00 +02:00
case WM_SYSKEYDOWN:
case WM_KEYDOWN:
if( Con_KeyEvent( LOWORD( wParam ), true ))
2010-02-18 22:00:00 +01:00
return 0;
2010-07-24 22:00:00 +02:00
break;
case WM_SYSKEYUP:
case WM_KEYUP:
if( Con_KeyEvent( LOWORD( wParam ), false ))
2010-02-18 22:00:00 +01:00
return 0;
break;
2007-11-10 22:00:00 +01:00
case WM_CHAR:
2010-07-24 22:00:00 +02:00
if( Con_KeyEvent( wParam, true ))
return 0;
2018-02-25 22:00:00 +01:00
if( wParam == 13 && host.status != HOST_ERR_FATAL )
2007-11-10 22:00:00 +01:00
{
2010-02-18 22:00:00 +01:00
GetWindowText( s_wcd.hwndInputLine, inputBuffer, sizeof( inputBuffer ));
2011-03-12 22:00:00 +01:00
Q_strncat( s_wcd.consoleText, inputBuffer, sizeof( s_wcd.consoleText ) - Q_strlen( s_wcd.consoleText ) - 5 );
Q_strcat( s_wcd.consoleText, "\n" );
2007-11-10 22:00:00 +01:00
SetWindowText( s_wcd.hwndInputLine, "" );
2018-03-03 22:00:00 +01:00
Con_Printf( ">%s\n", inputBuffer );
2010-02-18 22:00:00 +01:00
// copy line to history buffer
2011-03-12 22:00:00 +01:00
Q_strncpy( s_wcd.historyLines[s_wcd.nextHistoryLine % COMMAND_HISTORY], inputBuffer, MAX_STRING );
2010-02-18 22:00:00 +01:00
s_wcd.nextHistoryLine++;
s_wcd.historyLine = s_wcd.nextHistoryLine;
2007-11-10 22:00:00 +01:00
return 0;
}
2010-07-24 22:00:00 +02:00
break;
2007-11-10 22:00:00 +01:00
}
return CallWindowProc( s_wcd.SysInputLineWndProc, hWnd, uMsg, wParam, lParam );
}
/*
===============================================================================
WIN32 IO
===============================================================================
*/
/*
================
2011-03-12 22:00:00 +01:00
Con_WinPrint
2007-11-10 22:00:00 +01:00
print into window console
================
*/
2011-03-12 22:00:00 +01:00
void Con_WinPrint( const char *pMsg )
2007-11-10 22:00:00 +01:00
{
2011-03-12 22:00:00 +01:00
size_t len = Q_strlen( pMsg );
2009-09-10 22:00:00 +02:00
2007-11-10 22:00:00 +01:00
// replace selection instead of appending if we're overflowing
2009-09-10 22:00:00 +02:00
s_wcd.outLen += len;
if( s_wcd.outLen >= 0x7fff )
2007-11-10 22:00:00 +01:00
{
SendMessage( s_wcd.hwndBuffer, EM_SETSEL, 0, -1 );
2009-09-10 22:00:00 +02:00
s_wcd.outLen = len;
2007-11-10 22:00:00 +01:00
}
2009-09-10 22:00:00 +02:00
SendMessage( s_wcd.hwndBuffer, EM_REPLACESEL, 0, (LPARAM)pMsg );
2007-11-10 22:00:00 +01:00
// put this text into the windows console
SendMessage( s_wcd.hwndBuffer, EM_LINESCROLL, 0, 0xffff );
SendMessage( s_wcd.hwndBuffer, EM_SCROLLCARET, 0, 0 );
}
/*
================
Con_CreateConsole
create win32 console
================
*/
void Con_CreateConsole( void )
{
2010-02-18 22:00:00 +01:00
HDC hDC;
WNDCLASS wc;
RECT rect;
2008-10-27 22:00:00 +01:00
int nHeight;
int swidth, sheight, fontsize;
int DEDSTYLE = WS_POPUPWINDOW | WS_CAPTION;
int CONSTYLE = WS_CHILD|WS_VISIBLE|WS_VSCROLL|WS_BORDER|WS_EX_CLIENTEDGE|ES_LEFT|ES_MULTILINE|ES_AUTOVSCROLL|ES_READONLY;
2011-03-12 22:00:00 +01:00
string FontName;
2007-11-10 22:00:00 +01:00
wc.style = 0;
wc.lpfnWndProc = (WNDPROC)Con_WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
2011-03-12 22:00:00 +01:00
wc.hInstance = host.hInst;
wc.hIcon = LoadIcon( host.hInst, MAKEINTRESOURCE( IDI_ICON1 ));
2008-08-04 22:00:00 +02:00
wc.hCursor = LoadCursor( NULL, IDC_ARROW );
2007-11-10 22:00:00 +01:00
wc.hbrBackground = (void *)COLOR_3DSHADOW;
wc.lpszClassName = SYSCONSOLE;
2010-07-21 22:00:00 +02:00
wc.lpszMenuName = 0;
2007-11-10 22:00:00 +01:00
2018-03-03 22:00:00 +01:00
if( Sys_CheckParm( "-log" ))
2011-03-12 22:00:00 +01:00
s_wcd.log_active = true;
2007-11-14 22:00:00 +01:00
2012-12-22 21:00:00 +01:00
if( host.type == HOST_NORMAL )
2007-11-10 22:00:00 +01:00
{
rect.left = 0;
rect.right = 536;
rect.top = 0;
rect.bottom = 364;
2011-03-12 22:00:00 +01:00
Q_strncpy( FontName, "Fixedsys", sizeof( FontName ));
2018-08-23 23:00:00 +02:00
Q_strncpy( s_wcd.title, va( "Xash3D %s", XASH_VERSION ), sizeof( s_wcd.title ));
2011-03-12 22:00:00 +01:00
Q_strncpy( s_wcd.log_path, "engine.log", sizeof( s_wcd.log_path ));
2007-11-10 22:00:00 +01:00
fontsize = 8;
}
else // dedicated console
{
rect.left = 0;
2010-02-18 22:00:00 +01:00
rect.right = 640;
2007-11-10 22:00:00 +01:00
rect.top = 0;
rect.bottom = 392;
2011-03-12 22:00:00 +01:00
Q_strncpy( FontName, "System", sizeof( FontName ));
Q_strncpy( s_wcd.title, "Xash Dedicated Server", sizeof( s_wcd.title ));
Q_strncpy( s_wcd.log_path, "dedicated.log", sizeof( s_wcd.log_path ));
2012-12-22 21:00:00 +01:00
s_wcd.log_active = true; // always make log
2007-11-10 22:00:00 +01:00
fontsize = 14;
}
2011-03-12 22:00:00 +01:00
Sys_InitLog();
if( !RegisterClass( &wc ))
{
// print into log
2018-09-10 23:00:00 +02:00
Con_DPrintf( S_ERROR "Can't register window class '%s'\n", SYSCONSOLE );
2011-03-12 22:00:00 +01:00
return;
}
2007-11-10 22:00:00 +01:00
AdjustWindowRect( &rect, DEDSTYLE, FALSE );
hDC = GetDC( GetDesktopWindow() );
swidth = GetDeviceCaps( hDC, HORZRES );
sheight = GetDeviceCaps( hDC, VERTRES );
ReleaseDC( GetDesktopWindow(), hDC );
s_wcd.windowWidth = rect.right - rect.left;
s_wcd.windowHeight = rect.bottom - rect.top;
2011-03-12 22:00:00 +01:00
s_wcd.hWnd = CreateWindowEx( WS_EX_DLGMODALFRAME, SYSCONSOLE, s_wcd.title, DEDSTYLE, ( swidth - 600 ) / 2, ( sheight - 450 ) / 2 , rect.right - rect.left + 1, rect.bottom - rect.top + 1, NULL, NULL, host.hInst, NULL );
2010-02-18 22:00:00 +01:00
if( s_wcd.hWnd == NULL )
2007-11-14 22:00:00 +01:00
{
2018-09-10 23:00:00 +02:00
Con_DPrintf( S_ERROR "Can't create window '%s'\n", s_wcd.title );
2007-11-14 22:00:00 +01:00
return;
}
2007-11-10 22:00:00 +01:00
// create fonts
hDC = GetDC( s_wcd.hWnd );
2010-07-24 22:00:00 +02:00
nHeight = -MulDiv( fontsize, GetDeviceCaps( hDC, LOGPIXELSY ), 72 );
2011-03-12 22:00:00 +01:00
s_wcd.hfBufferFont = CreateFont( nHeight, 0, 0, 0, FW_LIGHT, 0, 0, 0, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, FF_MODERN|FIXED_PITCH, FontName );
2007-11-10 22:00:00 +01:00
ReleaseDC( s_wcd.hWnd, hDC );
2011-03-12 22:00:00 +01:00
if( host.type == HOST_DEDICATED )
2007-11-10 22:00:00 +01:00
{
// create the input line
2011-03-12 22:00:00 +01:00
s_wcd.hwndInputLine = CreateWindowEx( WS_EX_CLIENTEDGE, "edit", NULL, WS_CHILD|WS_VISIBLE|WS_BORDER|ES_LEFT|ES_AUTOHSCROLL, 0, 366, 550, 25, s_wcd.hWnd, (HMENU)INPUT_ID, host.hInst, NULL );
2007-11-10 22:00:00 +01:00
2011-03-12 22:00:00 +01:00
s_wcd.hwndButtonSubmit = CreateWindow( "button", NULL, BS_PUSHBUTTON|WS_VISIBLE|WS_CHILD|BS_DEFPUSHBUTTON, 552, 367, 87, 25, s_wcd.hWnd, (HMENU)SUBMIT_ID, host.hInst, NULL );
2007-11-10 22:00:00 +01:00
SendMessage( s_wcd.hwndButtonSubmit, WM_SETTEXT, 0, ( LPARAM ) "submit" );
}
// create the scrollbuffer
2008-08-04 22:00:00 +02:00
GetClientRect( s_wcd.hWnd, &rect );
2007-11-10 22:00:00 +01:00
2011-03-12 22:00:00 +01:00
s_wcd.hwndBuffer = CreateWindowEx( WS_EX_DLGMODALFRAME|WS_EX_CLIENTEDGE, "edit", NULL, CONSTYLE, 0, 0, rect.right - rect.left, min(365, rect.bottom), s_wcd.hWnd, (HMENU)EDIT_ID, host.hInst, NULL );
SendMessage( s_wcd.hwndBuffer, WM_SETFONT, (WPARAM)s_wcd.hfBufferFont, 0 );
2007-11-10 22:00:00 +01:00
2011-03-12 22:00:00 +01:00
if( host.type == HOST_DEDICATED )
2007-11-10 22:00:00 +01:00
{
2011-03-12 22:00:00 +01:00
s_wcd.SysInputLineWndProc = (WNDPROC)SetWindowLong( s_wcd.hwndInputLine, GWL_WNDPROC, (long)Con_InputLineProc );
2010-02-18 22:00:00 +01:00
SendMessage( s_wcd.hwndInputLine, WM_SETFONT, ( WPARAM )s_wcd.hfBufferFont, 0 );
2007-11-10 22:00:00 +01:00
}
// show console if needed
2011-03-12 22:00:00 +01:00
if( host.con_showalways )
2007-11-10 22:00:00 +01:00
{
// make console visible
2011-03-12 22:00:00 +01:00
ShowWindow( s_wcd.hWnd, SW_SHOWDEFAULT );
2007-11-10 22:00:00 +01:00
UpdateWindow( s_wcd.hWnd );
SetForegroundWindow( s_wcd.hWnd );
2011-03-12 22:00:00 +01:00
if( host.type != HOST_DEDICATED )
SetFocus( s_wcd.hWnd );
2007-11-10 22:00:00 +01:00
else SetFocus( s_wcd.hwndInputLine );
s_wcd.status = true;
}
else s_wcd.status = false;
}
2012-04-06 22:00:00 +02:00
/*
================
Con_InitConsoleCommands
register console commands (dedicated only)
================
*/
void Con_InitConsoleCommands( void )
{
if( host.type != HOST_DEDICATED ) return;
Cmd_AddCommand( "clear", Con_Clear_f, "clear console history" );
}
2007-11-10 22:00:00 +01:00
/*
================
Con_DestroyConsole
destroy win32 console
================
*/
void Con_DestroyConsole( void )
{
// last text message into console or log
2018-09-10 23:00:00 +02:00
Con_Reportf( "Sys_FreeLibrary: Unloading xash.dll\n" );
2007-11-10 22:00:00 +01:00
2007-12-11 22:00:00 +01:00
Sys_CloseLog();
2007-11-10 22:00:00 +01:00
2010-02-18 22:00:00 +01:00
if( s_wcd.hWnd )
2007-11-10 22:00:00 +01:00
{
2010-02-18 22:00:00 +01:00
DeleteObject( s_wcd.hbrEditBackground );
2007-11-10 22:00:00 +01:00
DeleteObject( s_wcd.hfBufferFont );
2012-12-22 21:00:00 +01:00
if( host.type == HOST_DEDICATED )
{
ShowWindow( s_wcd.hwndButtonSubmit, SW_HIDE );
DestroyWindow( s_wcd.hwndButtonSubmit );
s_wcd.hwndButtonSubmit = 0;
ShowWindow( s_wcd.hwndInputLine, SW_HIDE );
DestroyWindow( s_wcd.hwndInputLine );
s_wcd.hwndInputLine = 0;
}
ShowWindow( s_wcd.hwndBuffer, SW_HIDE );
DestroyWindow( s_wcd.hwndBuffer );
s_wcd.hwndBuffer = 0;
2007-11-10 22:00:00 +01:00
ShowWindow( s_wcd.hWnd, SW_HIDE );
DestroyWindow( s_wcd.hWnd );
s_wcd.hWnd = 0;
}
2011-02-11 22:00:00 +01:00
2011-03-12 22:00:00 +01:00
UnregisterClass( SYSCONSOLE, host.hInst );
2010-02-18 22:00:00 +01:00
// place it here in case Sys_Crash working properly
2011-03-12 22:00:00 +01:00
if( host.hMutex ) CloseHandle( host.hMutex );
2007-11-10 22:00:00 +01:00
}
/*
================
2011-03-10 22:00:00 +01:00
Con_Input
2007-11-10 22:00:00 +01:00
returned input text
================
*/
2011-03-10 22:00:00 +01:00
char *Con_Input( void )
2007-11-10 22:00:00 +01:00
{
2010-02-18 22:00:00 +01:00
if( s_wcd.consoleText[0] == 0 )
return NULL;
2007-11-10 22:00:00 +01:00
2011-03-12 22:00:00 +01:00
Q_strncpy( s_wcd.returnedText, s_wcd.consoleText, sizeof( s_wcd.returnedText ));
2007-11-10 22:00:00 +01:00
s_wcd.consoleText[0] = 0;
return s_wcd.returnedText;
}
/*
================
Con_SetFocus
change focus to console hwnd
================
*/
void Con_RegisterHotkeys( void )
{
SetFocus( s_wcd.hWnd );
2007-11-25 22:00:00 +01:00
// user can hit escape for quit
2009-01-13 22:00:00 +01:00
RegisterHotKey( s_wcd.hWnd, QUIT_ON_ESCAPE_ID, 0, VK_ESCAPE );
2008-08-04 22:00:00 +02:00
}
/*
===============================================================================
SYSTEM LOG
===============================================================================
*/
void Sys_InitLog( void )
{
const char *mode;
2017-03-14 22:00:00 +01:00
if( host.change_game && host.type != HOST_DEDICATED )
2008-08-04 22:00:00 +02:00
mode = "a";
else mode = "w";
// create log if needed
2011-03-12 22:00:00 +01:00
if( s_wcd.log_active )
2008-08-04 22:00:00 +02:00
{
2011-03-12 22:00:00 +01:00
s_wcd.logfile = fopen( s_wcd.log_path, mode );
2018-09-10 23:00:00 +02:00
if( !s_wcd.logfile )
{
2018-09-29 23:00:00 +02:00
MSGBOX( va( "can't create log file %s\n", s_wcd.log_path ));
2018-09-10 23:00:00 +02:00
return;
}
2008-08-04 22:00:00 +02:00
2014-04-23 22:00:00 +02:00
fprintf( s_wcd.logfile, "=================================================================================\n" );
fprintf( s_wcd.logfile, "\t%s (build %i) started at %s\n", s_wcd.title, Q_buildnum(), Q_timestamp( TIME_FULL ));
fprintf( s_wcd.logfile, "=================================================================================\n" );
2008-08-04 22:00:00 +02:00
}
}
void Sys_CloseLog( void )
{
2011-03-12 22:00:00 +01:00
char event_name[64];
2008-08-04 22:00:00 +02:00
// continue logged
2018-02-25 22:00:00 +01:00
switch( host.status )
2008-08-04 22:00:00 +02:00
{
2011-03-12 22:00:00 +01:00
case HOST_CRASHED:
Q_strncpy( event_name, "crashed", sizeof( event_name ));
break;
case HOST_ERR_FATAL:
Q_strncpy( event_name, "stopped with error", sizeof( event_name ));
break;
default:
if( !host.change_game ) Q_strncpy( event_name, "stopped", sizeof( event_name ));
else Q_strncpy( event_name, host.finalmsg, sizeof( event_name ));
break;
2008-08-04 22:00:00 +02:00
}
2011-03-12 22:00:00 +01:00
if( s_wcd.logfile )
2008-08-04 22:00:00 +02:00
{
2011-03-12 22:00:00 +01:00
fprintf( s_wcd.logfile, "\n");
2014-04-23 22:00:00 +02:00
fprintf( s_wcd.logfile, "=================================================================================");
2017-02-12 22:00:00 +01:00
if( host.change_game ) fprintf( s_wcd.logfile, "\n\t%s (build %i) %s\n", s_wcd.title, Q_buildnum(), event_name );
else fprintf( s_wcd.logfile, "\n\t%s (build %i) %s at %s\n", s_wcd.title, Q_buildnum(), event_name, Q_timestamp( TIME_FULL ));
2014-04-23 22:00:00 +02:00
fprintf( s_wcd.logfile, "=================================================================================");
2011-03-12 22:00:00 +01:00
if( host.change_game ) fprintf( s_wcd.logfile, "\n" ); // just for tabulate
fclose( s_wcd.logfile );
s_wcd.logfile = NULL;
2008-08-04 22:00:00 +02:00
}
}
void Sys_PrintLog( const char *pMsg )
{
2011-03-12 22:00:00 +01:00
if( !s_wcd.logfile ) return;
fprintf( s_wcd.logfile, pMsg );
fflush( s_wcd.logfile );
2007-11-10 22:00:00 +01:00
}