Stole a proper version comparison function from dpkg. Version strings

(for sv_minqfversion) are no longer compared as floats, so a server admin
can require client versions with a lot more granularity. (e.g. 0.2.99beta5
is greater than 0.2.99beta4, but lower than 0.3.0)
This commit is contained in:
Jeff Teunissen 2000-11-26 09:48:01 +00:00
parent c8fcb1cf22
commit 8465917ed1
5 changed files with 174 additions and 25 deletions

View File

@ -11,8 +11,8 @@ EXTRA_DIST = adivtab.h anorm_dots.h anorms.h asm_draw.h asm_i386.h block16.h \
qdefs.h qendian.h qstructs.h qtypes.h quakeasm.h quakedef.h \ qdefs.h qendian.h qstructs.h qtypes.h quakeasm.h quakedef.h \
quakefs.h quakeio.h r_dynamic.h r_local.h r_shared.h render.h \ quakefs.h quakeio.h r_dynamic.h r_local.h r_shared.h render.h \
sbar.h screen.h server.h sizebuf.h skin.h sound.h spritegn.h sys.h \ sbar.h screen.h server.h sizebuf.h skin.h sound.h spritegn.h sys.h \
tga.h teamplay.h uint32.h va.h vid.h view.h wad.h winquake.h \ tga.h teamplay.h uint32.h va.h ver_check.h vid.h view.h wad.h \
world.h zone.h \ winquake.h world.h zone.h \
\ \
win32/fnmatch.h win32/version.h win32/version.h.in \ win32/fnmatch.h win32/version.h win32/version.h.in \
win32/resources/icon1.ico win32/resources/resource.h \ win32/resources/icon1.ico win32/resources/resource.h \

45
include/ver_check.h Normal file
View File

@ -0,0 +1,45 @@
/*
ver_check.h
Version number comparison prototype
Copyright (C) 2000 Jeff Teunissen <deek@dusknet.dhs.org>
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 2
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.
You should have received a copy of the GNU General Public License
along with this program; if not, write to:
Free Software Foundation, Inc.
59 Temple Place - Suite 330
Boston, MA 02111-1307, USA
$Id$
*/
#ifndef __ver_check_h_
#define __ver_check_h_
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
/*
ver_compare
Compare two ASCII version strings. If the first is greater than the second,
return a positive number. If the second is greater, return a negative. If
they are equal, return zero.
*/
int ver_compare (const char *, const char *);
#endif // __ver_check_h_

View File

@ -69,8 +69,8 @@ endif
server_SOURCES= pr_cmds.c pr_edict.c pr_exec.c pr_offs.c sv_ccmds.c sv_cvar.c \ server_SOURCES= pr_cmds.c pr_edict.c pr_exec.c pr_offs.c sv_ccmds.c sv_cvar.c \
sv_ents.c sv_init.c sv_main.c sv_misc.c sv_model.c \ sv_ents.c sv_init.c sv_main.c sv_misc.c sv_model.c \
sv_move.c sv_nchan.c sv_phys.c sv_send.c sv_user.c world.c \ sv_move.c sv_nchan.c sv_phys.c sv_send.c sv_user.c \
$(world_ASM) ver_check.c world.c $(world_ASM)
qf_server_SOURCES= $(common_SOURCES) $(server_SOURCES) qf_server_SOURCES= $(common_SOURCES) $(server_SOURCES)
qf_server_LDADD= -L. -lqfsys_sv $(NET_LIBS) $(Z_LIBS) $(DL_LIBS) qf_server_LDADD= -L. -lqfsys_sv $(NET_LIBS) $(Z_LIBS) $(DL_LIBS)

View File

@ -29,27 +29,30 @@
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
# include <config.h> # include <config.h>
#endif #endif
#include "server.h"
#include "va.h"
#include "crc.h"
#include "msg.h"
#include "world.h"
#include "commdef.h"
#include "cmd.h"
#include "sys.h"
#include "pmove.h"
#include "quakefs.h"
#include "qargs.h"
#include "bothdefs.h"
#include "buildnum.h"
#include <stdarg.h> #include <stdarg.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#ifdef HAVE_STRINGS_H #ifdef HAVE_STRINGS_H
#include <strings.h> # include <strings.h>
#endif #endif
#include "bothdefs.h"
#include "buildnum.h"
#include "cmd.h"
#include "commdef.h"
#include "crc.h"
#include "msg.h"
#include "pmove.h"
#include "qargs.h"
#include "quakefs.h"
#include "server.h"
#include "sys.h"
#include "va.h"
#include "ver_check.h"
#include "world.h"
quakeparms_t host_parms; quakeparms_t host_parms;
qboolean host_initialized; // true if into command execution qboolean host_initialized; // true if into command execution
@ -671,14 +674,13 @@ SVC_DirectConnect (void)
s = Info_ValueForKey (userinfo, "*qf_version"); s = Info_ValueForKey (userinfo, "*qf_version");
if ((!s[0]) || sv_minqfversion->value) { // kick old clients? if ((!s[0]) || sv_minqfversion->value) { // kick old clients?
if ((atof (s) + 0.005) < sv_minqfversion->value) { if (ver_compare (s, sv_minqfversion->string) < 0) {
Con_Printf ("%s: QF version %g is less than minimum version %g.\n", Con_Printf ("%s: Version %s is less than minimum version %s.\n",
NET_AdrToString (net_from), NET_AdrToString (net_from), s, sv_minqfversion->string);
atof (s),
sv_minqfversion->value);
Netchan_OutOfBandPrint (net_from, Netchan_OutOfBandPrint (net_from,
"%c\nserver requires QuakeForge v%g or greater. Get it from http://www.quakeforge.net/\n", "%c\nserver requires QuakeForge v%s or greater. Get it from http://www.quakeforge.net/\n",
A2C_PRINT, sv_minqfversion->value); A2C_PRINT, sv_minqfversion->string);
return; return;
} }
} }

102
source/ver_check.c Normal file
View File

@ -0,0 +1,102 @@
/*
ver_check.c
Version number comparisons
Copyright (C) 1995 Ian Jackson <iwj10@cus.cam.ac.uk>
Copyright (C) 2000 Jeff Teunissen <deek@dusknet.dhs.org>
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 2
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.
You should have received a copy of the GNU General Public License
along with this program; if not, write to:
Free Software Foundation, Inc.
59 Temple Place - Suite 330
Boston, MA 02111-1307, USA
$Id$
*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <stdlib.h>
#include <ctype.h>
/*
ver_compare
Compare two ASCII version strings. If the first is greater than the second,
return a positive number. If the second is greater, return a negative. If
they are equal, return zero.
*/
int
ver_compare (const char *value, const char *reference)
{
const char *valptr, *refptr;
int vc, rc;
long vl, rl;
if (!value)
value = "";
if (!reference)
reference = "";
for (;;) {
valptr = value;
while (*valptr && !isdigit(*valptr)) // Scan past any non-digit chars
valptr++;
refptr = reference;
while (*refptr && !isdigit(*refptr)) // get past non-digits here too
refptr++;
for (;;) {
vc = (value == valptr) ? 0 : *value++;
rc = (reference == refptr) ? 0 : *reference++;
if ((!vc) && (!rc))
break;
if (vc && !isalpha (vc)) vc += 256; // ASCII charset
if (rc && !isalpha (rc)) rc += 256;
if (vc != rc)
return (vc - rc);
}
value = valptr;
reference = refptr;
vl = rl = 0;
if (isdigit (*valptr))
vl = strtol (value, (char **) &value, 10);
if (isdigit (*refptr))
rl = strtol (reference, (char **) &reference, 10);
if (vl != rl)
return (vl - rl);
if ((!*value) && (!*reference))
return 0;
if (!*value)
return -1;
if (!*reference)
return 1;
}
}