summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorM. Kristall <mkpdev@gmail.com>2010-12-10 02:35:57 +0000
committerTim Angus <tim@ngus.net>2013-01-03 00:17:48 +0000
commit367880a7cc9dc865184e1c6d3e4825c1880c68af (patch)
treea6822f8527c0d28f81d4ff433d046f99e966e043
parent4b05a8fcb7f873e41e777d6f77f80656ac1f44cc (diff)
* Sort admins and levels by descending level on readconfig
-rw-r--r--src/game/g_admin.c51
-rw-r--r--src/game/g_admin.h2
2 files changed, 52 insertions, 1 deletions
diff --git a/src/game/g_admin.c b/src/game/g_admin.c
index 5c4af687..adf840d1 100644
--- a/src/game/g_admin.c
+++ b/src/game/g_admin.c
@@ -923,6 +923,52 @@ qboolean G_admin_cmd_check( gentity_t *ent )
return qfalse;
}
+struct llist
+{
+ struct llist *next;
+};
+static void llsort( struct llist **head, int compar( const void *, const void * ) )
+{
+ struct llist *a, *b, *t, *l;
+ int i, c = 1, ns, as, bs;
+
+ if( !*head )
+ return;
+
+ do
+ {
+ a = *head, l = *head = NULL;
+ for( ns = 0; a; ns++, a = b )
+ {
+ b = a;
+ for( i = as = 0; i < c; i++ )
+ {
+ as++;
+ if( !( b = b->next ) )
+ break;
+ }
+ for( bs = c; ( b && bs ) || as; l = t )
+ {
+ if( as && ( !bs || !b || compar( a, b ) < 0 ) )
+ t = a, a = a->next, as--;
+ else
+ t = b, b = b->next, bs--;
+ if( l )
+ l->next = t;
+ else
+ *head = t;
+ }
+ }
+ l->next = NULL;
+ c *= 2;
+ } while( ns > 1 );
+}
+
+static int cmplevel( const void *a, const void *b )
+{
+ return ((g_admin_level_t *)b)->level - ((g_admin_level_t *)a)->level;
+}
+
qboolean G_admin_readconfig( gentity_t *ent )
{
g_admin_level_t *l = NULL;
@@ -1127,6 +1173,11 @@ qboolean G_admin_readconfig( gentity_t *ent )
lc, ac, bc, cc ) );
if( lc == 0 )
admin_default_levels();
+ else
+ {
+ llsort( (struct llist **)&g_admin_levels, cmplevel );
+ llsort( (struct llist **)&g_admin_admins, cmplevel );
+ }
// restore admin mapping
for( i = 0; i < level.maxclients; i++ )
diff --git a/src/game/g_admin.h b/src/game/g_admin.h
index 0ff45796..3de278af 100644
--- a/src/game/g_admin.h
+++ b/src/game/g_admin.h
@@ -92,9 +92,9 @@ g_admin_level_t;
typedef struct g_admin_admin
{
struct g_admin_admin *next;
+ int level;
char guid[ 33 ];
char name[ MAX_NAME_LENGTH ];
- int level;
char flags[ MAX_ADMIN_FLAGS ];
}
g_admin_admin_t;