(SPOILERS AHEAD!)
apophis wrote:
Another problem is that some engine commands use Con_Print for only part of their output, so when you run the command though RCon half of it goes through RCon and half of it is printed to the server console. I think an example of this is the find command.
Humm... this remind me a related or unrelated function, Sys_ConsoleInput.
The actual halflife version may looks similar. Notice that this stuff dont use the standard librarys but need windows api calls... ..to print chars to console.
char *Sys_ConsoleInput (void) //Carmack version { static char text[256]; static int len; INPUT_RECORD recs[1024]; int dummy; int ch, numread, numevents;
if (!isDedicated) return NULL;
//DEDICATED CONSOLE INPUT
for ( ;; ) {
if (!GetNumberOfConsoleInputEvents (hinput, (unsigned long *) &numevents)) Sys_Error ("Error getting # of console events");
if (numevents <= 0) break;
if (!ReadConsoleInput(hinput, recs, 1, (unsigned long *) &numread)) Sys_Error ("Error reading console input");
if (numread != 1) Sys_Error ("Couldn't read console input");
if (recs[0].EventType == KEY_EVENT) { if (!recs[0].Event.KeyEvent.bKeyDown) { ch = recs[0].Event.KeyEvent.uChar.AsciiChar;
switch (ch) { case '\r': WriteFile(houtput, "\r\n", 2, (unsigned long *) &dummy, NULL); if (len) { text[len] = 0; len = 0; return text; } else if (sc_return_on_enter) { // special case to allow exiting from the error handler on Enter text[0] = '\r'; len = 0; return text; }
break;
case '\b': WriteFile(houtput, "\b \b", 3, (unsigned long *) &dummy, NULL); if (len) { len--; } break;
default: if (ch >= ' ') { WriteFile(houtput, &ch, 1, (unsigned long *) &dummy, NULL); text[len] = ch; len = (len + 1) & 0xff; }
break;
} } } }
return NULL; }
Here, the glorious Linux version (from ZQuake), a bit hacky but use the standard c libs:
// these are referenced by net_udp.c qbool do_stdin = true, stdin_ready;
char *Sys_ConsoleInput(void) //Tonik version { static char text[256]; char dummy[256]; int len;
if (!dedicated || noconinput) return NULL;
len = read (0, text, sizeof(text)); if (len < 1) return NULL;
// Tonik: if the line was longer than 256 chars, // through away the remainder (FIXME) while (read (0, dummy, sizeof(dummy)) > 0) {};
text[len-1] = 0; // rip off the /n and terminate
return text; }
And here its my actuall crappy version:
char *Sys_ConsoleInput(void) //Tei version { static char text[1024]; static int index; int len; char c;
//cin.rdbuf()->setbuf(NULL, 0);//me vomit over a C++ book
if (!isDedicated) return NULL;
if (!kbhit()) return NULL;
c = getche();
text[index]=c;
index ++;
if (c!=13) return NULL;
printf("\n");
text[index]=0; index = 0;
return text; }
And here its the final cut. How Con_Printf has fallen in the Dark Side of windows:
void Sys_Printf (char *fmt, ...) { va_list argptr; char text[1024]; DWORD dummy;
va_start (argptr,fmt); vsprintf (text, fmt, argptr); va_end (argptr); #if DARKSIDE WriteFile(houtput, text, strlen (text), &dummy, NULL); #else printf(text); #endif }
void Con_Printf (char *fmt, ...) { va_list argptr; char msg[MAXPRINTMSG]; static qboolean inupdate;
va_start (argptr,fmt); vsprintf (msg,fmt,argptr); va_end (argptr);
// also echo to debugging console Sys_Printf ("%s", msg); // also echo to debugging console
// log all messages to file if (con_debuglog) Con_DebugLog(va("%s/qconsole.log",com_gamedir), "%s", msg);
}
_______________________________________________ To unsubscribe, edit your list preferences, or view the list archives, please visit: http://list.valvesoftware.com/mailman/listinfo/hlcoders