(svn r1547) -Feature: windows dedicated (if anyone would run that, but ok), is now functioning correctly. There is no other way but to create a new thread, but that's only MS braindeadness

-Fix: [1103113] font size changing. Dedicated server did not have code filtering, 'tab' could result in bigger fonts
-Fix: [1103069] console backspace key with ded server; fixed due to normal console handling
-Fix: [1101963] console in dedicated server; see above
-Fix: dedicated server also writes to log file if active
This commit is contained in:
darkvater 2005-01-16 18:19:33 +00:00
parent 8521367373
commit a1e94b67d5
3 changed files with 109 additions and 52 deletions

View File

@ -192,9 +192,8 @@ static void IConsoleWndProc(Window* w, WindowEvent* e)
IConsolePrintF(_iconsole_color_commands, "] %s", _iconsole_cmdline); IConsolePrintF(_iconsole_color_commands, "] %s", _iconsole_cmdline);
_iconsole_cmdbufferpos = 19; _iconsole_cmdbufferpos = 19;
IConsoleCmdBufferAdd(_iconsole_cmdline); IConsoleCmdBufferAdd(_iconsole_cmdline);
if (strlen(_iconsole_cmdline) != 0) // only execute if there is something typed obviously
IConsoleCmdExec(_iconsole_cmdline);
IConsoleCmdExec(_iconsole_cmdline);
IConsoleClearCommand(); IConsoleClearCommand();
break; break;
case WKC_CTRL | WKC_RETURN: case WKC_CTRL | WKC_RETURN:
@ -271,11 +270,31 @@ void IConsoleClear(void)
free(_iconsole_buffer[i]); free(_iconsole_buffer[i]);
} }
static void IConsoleWriteToLogFile(const char* string)
{
if (_iconsole_output_file != NULL) {
// if there is an console output file ... also print it there
fwrite(string, strlen(string), 1, _iconsole_output_file);
fwrite("\n", 1, 1, _iconsole_output_file);
}
}
bool CloseConsoleLogIfActive(void)
{
if (_iconsole_output_file != NULL) {
IConsolePrintF(_iconsole_color_default, "file output complete");
fclose(_iconsole_output_file);
return true;
}
return false;
}
void IConsoleFree(void) void IConsoleFree(void)
{ {
_iconsole_inited = false; _iconsole_inited = false;
IConsoleClear(); IConsoleClear();
if (_iconsole_output_file != NULL) fclose(_iconsole_output_file); CloseConsoleLogIfActive();
} }
void IConsoleResize(void) void IConsoleResize(void)
@ -382,6 +401,7 @@ void IConsolePrint(uint16 color_code, const char* string)
if (_network_dedicated) { if (_network_dedicated) {
printf("%s\n", string); printf("%s\n", string);
IConsoleWriteToLogFile(string);
return; return;
} }
@ -403,11 +423,7 @@ void IConsolePrint(uint16 color_code, const char* string)
} }
free(_ex); free(_ex);
if (_iconsole_output_file != NULL) { IConsoleWriteToLogFile(string);
// if there is an console output file ... also print it there
fwrite(string, strlen(string), 1, _iconsole_output_file);
fwrite("\n", 1, 1, _iconsole_output_file);
}
if (_iconsole_win != NULL) SetWindowDirty(_iconsole_win); if (_iconsole_win != NULL) SetWindowDirty(_iconsole_win);
} }
@ -1072,6 +1088,9 @@ void IConsoleCmdExec(const char* cmdstr)
uint c; uint c;
uint i; uint i;
uint l; uint l;
if (strlen(cmdstr) == 0) // only execute if there is something typed obviously
return;
if (_stdlib_con_developer) if (_stdlib_con_developer)
IConsolePrintF(_iconsole_color_debug, "CONDEBUG: execution_cmdline: %s", cmdstr); IConsolePrintF(_iconsole_color_debug, "CONDEBUG: execution_cmdline: %s", cmdstr);

View File

@ -607,17 +607,7 @@ DEF_CONSOLE_CMD(ConReturn)
/* **************************** */ /* **************************** */
/* default console commands */ /* default console commands */
/* **************************** */ /* **************************** */
bool CloseConsoleLogIfActive() extern bool CloseConsoleLogIfActive(void);
{
extern FILE* _iconsole_output_file;
if (_iconsole_output_file != NULL) {
IConsolePrintF(_iconsole_color_default, "file output complete");
fclose(_iconsole_output_file);
return true;
}
return false;
}
DEF_CONSOLE_CMD(ConScript) DEF_CONSOLE_CMD(ConScript)
{ {

View File

@ -88,6 +88,40 @@ static void DedicatedSignalHandler(int sig)
} }
#endif #endif
#ifdef WIN32
HANDLE hEvent;
static HANDLE hThread; // Thread to close
static char _win_console_thread_buffer[200];
/* Windows Console thread. Just loop and signal when input has been received */
void WINAPI CheckForConsoleInput(void)
{
while (true) {
fgets(_win_console_thread_buffer, lengthof(_win_console_thread_buffer), stdin);
SetEvent(hEvent); // signal input waiting that the line is ready
}
}
void CreateWindowsConsoleThread(void)
{
/* Create event to signal when console input is ready */
hEvent = CreateEvent(NULL, false, false, "keyboard input");
hThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)CheckForConsoleInput, 0, 0, NULL);
if (hThread == NULL)
error("Cannot create console thread!");
DEBUG(misc, 0) ("Windows console thread started...");
}
void CloseWindowsConsoleThread(void)
{
CloseHandle(hThread);
DEBUG(misc, 0) ("Windows console thread shut down...");
}
#endif
static const char *DedicatedVideoStart(char **parm) { static const char *DedicatedVideoStart(char **parm) {
_screen.width = _screen.pitch = _cur_resolution[0]; _screen.width = _screen.pitch = _cur_resolution[0];
_screen.height = _cur_resolution[1]; _screen.height = _cur_resolution[1];
@ -99,6 +133,7 @@ static const char *DedicatedVideoStart(char **parm) {
#ifdef WIN32 #ifdef WIN32
// For win32 we need to allocate an console (debug mode does the same) // For win32 we need to allocate an console (debug mode does the same)
CreateConsole(); CreateConsole();
CreateWindowsConsoleThread();
SetConsoleTitle("OpenTTD Dedicated Server"); SetConsoleTitle("OpenTTD Dedicated Server");
#endif #endif
@ -110,13 +145,20 @@ static const char *DedicatedVideoStart(char **parm) {
DEBUG(misc,0)("Loading dedicated server..."); DEBUG(misc,0)("Loading dedicated server...");
return NULL; return NULL;
} }
static void DedicatedVideoStop() { free(_dedicated_video_mem); }
static void DedicatedVideoStop(void)
{
#ifdef WIN32
CloseWindowsConsoleThread();
#endif
free(_dedicated_video_mem);
}
static void DedicatedVideoMakeDirty(int left, int top, int width, int height) {} static void DedicatedVideoMakeDirty(int left, int top, int width, int height) {}
static bool DedicatedVideoChangeRes(int w, int h) { return false; } static bool DedicatedVideoChangeRes(int w, int h) { return false; }
#ifdef UNIX #ifdef UNIX
static bool InputWaiting(void)
static bool InputWaiting()
{ {
struct timeval tv; struct timeval tv;
fd_set readfds; fd_set readfds;
@ -133,49 +175,55 @@ static bool InputWaiting()
if (ret > 0) if (ret > 0)
return true; return true;
else
return false; return false;
} }
#else #else
static bool InputWaiting() static bool InputWaiting(void)
{ {
return kbhit(); if (WaitForSingleObject(hEvent, 1) == WAIT_OBJECT_0)
return true;
return false;
} }
#endif #endif
static void DedicatedHandleKeyInput() static void DedicatedHandleKeyInput(void)
{ {
#ifdef WIN32
char input;
#endif
static char input_line[200] = ""; static char input_line[200] = "";
#if defined(UNIX) || defined(__OS2__) if (!InputWaiting())
if (InputWaiting()) { return;
if (_exit_game)
return;
fgets(input_line, 200, stdin); if (_exit_game)
// Forget about the final \n (or \r) return;
strtok(input_line, "\r\n");
IConsoleCmdExec(input_line); #if defined(UNIX) || defined(__OS2__)
} fgets(input_line, lengthof(input_line), stdin);
#else #else
if (InputWaiting()) { strncpy(input_line, _win_console_thread_buffer, lengthof(input_line));
input = getch(); #endif
printf("%c", input);
if (input != '\r') /* XXX - strtok() does not 'forget' \n\r if it is the first character! */
snprintf(input_line, 200, "%s%c", input_line, input); strtok(input_line, "\r\n"); // Forget about the final \n (or \r)
else { { /* Remove any special control characters */
printf("\n"); uint i;
IConsoleCmdExec(input_line); for (i = 0; i < lengthof(input_line); i++) {
input_line[0] = '\0'; if (input_line[i] == '\n' || input_line[i] == '\r') // cut missed beginning '\0'
input_line[i] = '\0';
if (input_line[i] == '\0')
break;
if (!IS_INT_INSIDE(input_line[i], ' ', 256))
input_line[i] = ' ';
} }
} }
#endif
IConsoleCmdExec(input_line); // execute command
} }
static int DedicatedVideoMainLoop() static int DedicatedVideoMainLoop(void)
{ {
#ifndef WIN32 #ifndef WIN32
struct timeval tim; struct timeval tim;
@ -259,10 +307,10 @@ static const char *DedicatedVideoStart(char **parm) {
} }
void DedicatedFork(void) {} void DedicatedFork(void) {}
static void DedicatedVideoStop() { free(_dedicated_video_mem); } static void DedicatedVideoStop(void) { free(_dedicated_video_mem); }
static void DedicatedVideoMakeDirty(int left, int top, int width, int height) {} static void DedicatedVideoMakeDirty(int left, int top, int width, int height) {}
static bool DedicatedVideoChangeRes(int w, int h) { return false; } static bool DedicatedVideoChangeRes(int w, int h) { return false; }
static int DedicatedVideoMainLoop() { return ML_QUIT; } static int DedicatedVideoMainLoop(void) { return ML_QUIT; }
const HalVideoDriver _dedicated_video_driver = { const HalVideoDriver _dedicated_video_driver = {
DedicatedVideoStart, DedicatedVideoStart,