[CF-Devel] bugs/problems with windows server

crossfire-devel at archives.real-time.com crossfire-devel at archives.real-time.com
Wed Mar 24 12:01:19 CST 2004


I noticed a few bugs/problems, when running a crossfire server 
under WindowsXP on my machine at home

1.) The server sometimes did hang. After building a full-debug
version, i found out, that the problem was the windows
emulation of the gettimeofday function in "win32.c", which simply set 
  "time_Info->tv_usec = timeGetTime() *1000;",
which is wrong, since timeGetTime() returns the system
time in milliseconds and somewhere else in the code
there are code fragments like: "last_time->tv_usec = 0;",
so that sleep_delta() in "time.c" sometimes tried to
Sleep enormously long (> 4800 seconds:).
The patch at the end of this mail fixes the problem.

2.) The variable "skill" is sometimes used uninitialized in
"int kill_object(object *op,int dam, object *hitter, int type)"
in "attack.c" (change_exp() is sometimes called there with 
skill=0xcccccccc, when doing a full debug build with VisualC++).

Maybe this isn't a real bug, because in the cases where
changeExp() is called with an uninitialized skill parameter,
skill may probably not be used in changeExp(); but this "bug"
makes it impossible to run the debug version of the server, 
because everytime skill is used uninitialized, the
runtime check system of VisualC++ throws an exception.

I simply changed:
  char buf[MAX_BUF], *skill;
to:
  char buf[MAX_BUF], *skill = NULL;

3.) The VisualC++ runtime uses another type prefix in printf 
format strings for 64-bit integers than the GNU C/C++ compiler. 
Could you please change all occurrencs (about 20-30) of code like

  sprintf( buf, "%lld", ... );

to something like:

  #ifdef WIN32
    sprintf( buf, "%I64d", ... );
  #else
    sprintf( buf, "%lld", ... );

I saw you already started doing this, but there are still a lot
of places where this hasn't been changed yet.


---------------------
"gettimeofday"-Patch:
---------------------


Old version (in "win32.c"):
===========================

int gettimeofday(struct timeval *time_Info, struct timezone *timezone_Info)
{
  /* Get the time, if they want it */
  if (time_Info != NULL) {
    time_Info->tv_sec = time(NULL);
    time_Info->tv_usec = timeGetTime() *1000;
  }

  /* Get the timezone, if they want it */
  if (timezone_Info != NULL) {
    _tzset();
    timezone_Info->tz_minuteswest = _timezone;
    timezone_Info->tz_dsttime = _daylight;
  }

  /* And return */
  return 0;
}


New version:
============

int gettimeofday(struct timeval *time_Info, struct timezone *timezone_Info)
{
  // remarks: a DWORD is an unsigned long
  static DWORD time_t0, time_delta, mm_t0;
  static int t_initialized = 0;
  DWORD mm_t, delta_t;

  if( !t_initialized )
  {
    time_t0 = time(NULL);
    time_delta = 0;
    mm_t0 = timeGetTime();
    t_initialized = 1;
  }
  /* Get the time, if they want it */
  if (time_Info != NULL) 
  {
    // timeGetTime() returns the system time in milliseconds
    mm_t = timeGetTime();
  
    // handle wrap around of system time (happens every 
    // 2^32 milliseconds = 49.71 days)
    if( mm_t < mm_t0 )
      delta_t = (0xffffffff - mm_t0) + mm_t + 1; 
    else
      delta_t = mm_t - mm_t0;
    mm_t0 = mm_t;

    time_delta += delta_t;
    if( time_delta >= 1000 )
    {
      time_t0 += time_delta / 1000;
      time_delta = time_delta % 1000;
    }
    time_Info->tv_sec = time_t0;
    time_Info->tv_usec = time_delta * 1000;
  }

  /* Get the timezone, if they want it */
  if (timezone_Info != NULL) {
    _tzset();
    timezone_Info->tz_minuteswest = _timezone;
    timezone_Info->tz_dsttime = _daylight;
  }
  /* And return */
  return 0;
}
  

_______________________________________________
crossfire-devel mailing list
     
     crossfire-devel at lists.real-time.com
     
     
     https://mailman.real-time.com/mailman/listinfo/crossfire-devel
     
     
    


More information about the crossfire mailing list