don't store pointers for serverlist_viewlist, because they become
authorhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Sun, 24 Jan 2010 17:02:53 +0000 (17:02 +0000)
committerhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Sun, 24 Jan 2010 17:02:53 +0000 (17:02 +0000)
invalid after serverlist_cache is reallocated

git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@9844 d7cf8633-e32d-0410-b094-e92efae38249

menu.c
mvm_cmds.c
netconn.c
netconn.h

diff --git a/menu.c b/menu.c
index 754152c..5634d21 100644 (file)
--- a/menu.c
+++ b/menu.c
@@ -4400,9 +4400,10 @@ static void M_ServerList_Draw (void)
        {
                for (n = start;n < end;n++)
                {
+                       serverlist_entry_t *entry = ServerList_GetViewEntry(n);
                        DrawQ_Fill(menu_x, menu_y + y, 640, 16, n == slist_cursor ? (0.5 + 0.2 * sin(realtime * M_PI)) : 0, 0, 0, 0.5, 0);
-                       M_PrintColored(0, y, serverlist_viewlist[n]->line1);y += 8;
-                       M_PrintColored(0, y, serverlist_viewlist[n]->line2);y += 8;
+                       M_PrintColored(0, y, entry->line1);y += 8;
+                       M_PrintColored(0, y, entry->line2);y += 8;
                }
        }
        else if (realtime - masterquerytime > 10)
@@ -4456,7 +4457,7 @@ static void M_ServerList_Key(int k, int ascii)
        case K_ENTER:
                S_LocalSound ("sound/misc/menu2.wav");
                if (serverlist_viewcount)
-                       Cbuf_AddText(va("connect \"%s\"\n", serverlist_viewlist[slist_cursor]->info.cname));
+                       Cbuf_AddText(va("connect \"%s\"\n", ServerList_GetViewEntry(slist_cursor)->info.cname));
                break;
 
        default:
index 208ac89..07424f8 100644 (file)
@@ -436,7 +436,7 @@ void VM_M_getserverliststring(void)
                Con_Print("VM_M_getserverliststring: bad hostnr passed!\n");
                return;
        }
-       cache = serverlist_viewlist[hostnr];
+       cache = ServerList_GetViewEntry(hostnr);
        switch( (int) PRVM_G_FLOAT(OFS_PARM0) ) {
                case SLIF_CNAME:
                        PRVM_G_INT( OFS_RETURN ) = PRVM_SetTempString( cache->info.cname );
@@ -494,7 +494,7 @@ void VM_M_getserverlistnumber(void)
                Con_Print("VM_M_getserverliststring: bad hostnr passed!\n");
                return;
        }
-       cache = serverlist_viewlist[hostnr];
+       cache = ServerList_GetViewEntry(hostnr);
        switch( (int) PRVM_G_FLOAT(OFS_PARM0) ) {
                case SLIF_MAXPLAYERS:
                        PRVM_G_FLOAT( OFS_RETURN ) = cache->info.maxplayers;
index 28c2318..1a70905 100755 (executable)
--- a/netconn.c
+++ b/netconn.c
@@ -148,7 +148,7 @@ serverlist_infofield_t serverlist_sortbyfield;
 int serverlist_sortflags;
 
 int serverlist_viewcount = 0;
-serverlist_entry_t *serverlist_viewlist[SERVERLIST_VIEWLISTSIZE];
+unsigned short serverlist_viewlist[SERVERLIST_VIEWLISTSIZE];
 
 int serverlist_maxcachecount = 0;
 int serverlist_cachecount = 0;
@@ -185,7 +185,7 @@ static void _ServerList_ViewList_Helper_InsertBefore( int index, serverlist_entr
        for( ; i > index ; i-- )
                serverlist_viewlist[ i ] = serverlist_viewlist[ i - 1 ];
 
-       serverlist_viewlist[index] = entry;
+       serverlist_viewlist[index] = (int)(entry - serverlist_cache);
 }
 
 /// we suppose serverlist_viewcount to be valid, ie > 0
@@ -431,11 +431,11 @@ static void ServerList_ViewList_Insert( serverlist_entry_t *entry )
 
        // two special cases
        // check whether to insert it as new first item
-       if( _ServerList_Entry_Compare( entry, serverlist_viewlist[0] ) ) {
+       if( _ServerList_Entry_Compare( entry, ServerList_GetViewEntry(0) ) ) {
                _ServerList_ViewList_Helper_InsertBefore( 0, entry );
                return;
        } // check whether to insert it as new last item
-       else if( !_ServerList_Entry_Compare( entry, serverlist_viewlist[serverlist_viewcount - 1] ) ) {
+       else if( !_ServerList_Entry_Compare( entry, ServerList_GetViewEntry(serverlist_viewcount - 1) ) ) {
                _ServerList_ViewList_Helper_InsertBefore( serverlist_viewcount, entry );
                return;
        }
@@ -445,7 +445,7 @@ static void ServerList_ViewList_Insert( serverlist_entry_t *entry )
        {
                mid = (start + end) / 2;
                // test the item that lies in the middle between start and end
-               if( _ServerList_Entry_Compare( entry, serverlist_viewlist[mid] ) )
+               if( _ServerList_Entry_Compare( entry, ServerList_GetViewEntry(mid) ) )
                        // the item has to be in the upper half
                        end = mid;
                else
@@ -460,7 +460,7 @@ static void ServerList_ViewList_Remove( serverlist_entry_t *entry )
        int i;
        for( i = 0; i < serverlist_viewcount; i++ )
        {
-               if (serverlist_viewlist[i] == entry)
+               if (ServerList_GetViewEntry(i) == entry)
                {
                        _ServerList_ViewList_Helper_Remove(i);
                        break;
index 9d4a912..b0eb6da 100755 (executable)
--- a/netconn.h
+++ b/netconn.h
@@ -348,16 +348,23 @@ typedef struct serverlist_mask_s
        serverlist_info_t info;
 } serverlist_mask_t;
 
+#define ServerList_GetCacheEntry(x) (&serverlist_cache[(x)])
+#define ServerList_GetViewEntry(x) (ServerList_GetCacheEntry(serverlist_viewlist[(x)]))
+
 extern serverlist_mask_t serverlist_andmasks[SERVERLIST_ANDMASKCOUNT];
 extern serverlist_mask_t serverlist_ormasks[SERVERLIST_ORMASKCOUNT];
 
 extern serverlist_infofield_t serverlist_sortbyfield;
 extern int serverlist_sortflags; // not using the enum, as it is a bitmask
 
+#if SERVERLIST_TOTALSIZE > 65536
+#error too many servers, change type of index array
+#endif
 extern int serverlist_viewcount;
-extern serverlist_entry_t *serverlist_viewlist[SERVERLIST_VIEWLISTSIZE];
+extern unsigned short serverlist_viewlist[SERVERLIST_VIEWLISTSIZE];
 
 extern int serverlist_cachecount;
+extern serverlist_entry_t *serverlist_cache;
 
 extern qboolean serverlist_consoleoutput;