.:: Bots United ::.

.:: Bots United ::. (http://forums.bots-united.com/index.php)
-   General Bot Coding (http://forums.bots-united.com/forumdisplay.php?f=24)
-   -   Ded servers with hlds (http://forums.bots-united.com/showthread.php?t=220)

Rick 05-01-2004 21:10

Ded servers with hlds
 
I just noticed something for ded servers... In botman's code (and I think I saw it in others to) printf is used to show message's at the screen when a dedicated server runs. But this won't work with hlds.
So instead of printf(msghere) use
Code:

(*g_engfuncs.pfnServerPrint) (msghere)
(Or did I just say something every knew except me :))

Pierre-Marie Baty 05-01-2004 23:34

Re: Ded servers with hlds
 
I wrote my own facilities :)
Code:

int printf (const char *fmt, ...)
{
  // this function prints a message on the screen. If we are running a dedicated server, the
  // text will be printed on the server console, else if we are running a listen server, it
  // will be printed in game on the listen server client's HUD chat area. Since it's basically
  // a redefinition of the standard C libraries printf() function, it has to be the same type,
  // hence the integer return value.
  va_list argptr;
  static char string[1024];
  // concatenate all the arguments in one string
  va_start (argptr, fmt);
  vsprintf (string, fmt, argptr);
  va_end (argptr);
  // are we running a listen server ?
  if (!server.is_dedicated && IsValidPlayer (pListenserverEntity))
  {
          MESSAGE_BEGIN (MSG_ONE, GetUserMsgId ("SayText"), NULL, pListenserverEntity); // then print to HUD
          WRITE_BYTE (ENTINDEX (pListenserverEntity));
          WRITE_STRING (string);
          MESSAGE_END ();
  }
  else
          pfnServerPrint (string); // else print to console
  // if developer mode is on...
  if (server.developer_level > 0)
          LogToFile ("(server HUD): %s", string); // also log this message to the logfile
  return (0); // printf() HAS to return a value
}

int ServerConsole_printf (const char *fmt, ...)
{
  // this function asks the engine to print a message on the server console
  va_list argptr;
  static char string[1024];
  // concatenate all the arguments in one string
  va_start (argptr, fmt);
  vsprintf (string, fmt, argptr);
  va_end (argptr);
  (*g_engfuncs.pfnServerPrint) (string); // print to console
  // if developer mode is on...
  if (server.developer_level > 0)
          if (string[0] == '.')
                LogToFile (string); // also log this message to the logfile (not prefixing dots)
          else
                LogToFile ("(server console): %s", string); // also log this message to the logfile
  return (0); // printf() HAS to return a value
}


Rick 06-01-2004 20:25

Re: Ded servers with hlds
 
looks nice :) ah well guess you already figured it out printf does not work :) But it could be handy to know for beginners :|


All times are GMT +2. The time now is 02:21.

Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.