Hey,
i found no sorting algorithm in etpub xpsave source, so i just wrote one. Feel free to give feedback:
void G_xpsave_sort()
{
int i, j, index1, index2;
gentity_t *ent;
g_xpsave_t *temp[MAX_XPSAVES];
qboolean found;
//do this for security
for(i=0; i < MAX_XPSAVES; i++)
temp[i] = NULL;
index1 = 0;
index2 = level.numConnectedClients;
for(i=0; g_xpsaves[i]; i++) {
found = qfalse;
for(j=0; j < level.numConnectedClients; j++) {
ent = &g_entities[level.sortedClients[j]];
if(!Q_stricmp(g_xpsaves[i]->guid, ent->client->sess.guid))
{
found = qtrue;
break;
}
}
//list 1
if (found)
temp[index1++] = g_xpsaves[i];
//list 2
else
temp[index2++] = g_xpsaves[i];
//list1 written ? just complete list2 then
if(index1 == level.numConnectedClients)
{
i++;
while(g_xpsaves[i])
{
temp[index2] = g_xpsaves[i];
index2++;
i++;
//maximum reached ?
if(index2 == MAX_XPSAVES)
{
G_Printf("xpsave_sort: index2 maximum reached
");
return;
}
}
break;
}
//maximum reached ?
if(index2 == MAX_XPSAVES)
{
G_Printf("xpsave_sort: index2 maximum reached
");
return;
}
}
//clear for security
//note: actually you could just overwrite it, no ?
for(i=0; i < MAX_XPSAVES; i++)
g_xpsaves[i] = NULL;
//do this for security
temp[MAX_XPSAVES - 1] = NULL;
for(i=0; temp[i]; i++)
g_xpsaves[i] = temp[i];
G_Printf("xpsave: sorting successful...
");
}
You need to reference this function at the very beginning of G_xpsave_writeconfig in etpub source code. In my mod it works also well. Tested 2 times local.
Advantage is that it fixes potential server lag, so grab it up and give feedback, point out bugs, improvements etc