|
|
|
@ -1,4 +1,4 @@
|
|
|
|
|
/* $Id: netsrvlist.c,v 1.11 2005/03/27 01:31:50 stpohle Exp $
|
|
|
|
|
/* $Id: netsrvlist.c,v 1.12 2005/03/28 02:48:34 stpohle Exp $
|
|
|
|
|
* netsrvlist.c - shows a list of possible servers.*/
|
|
|
|
|
|
|
|
|
|
#include "basic.h"
|
|
|
|
@ -21,6 +21,7 @@ struct __srvlst_entry {
|
|
|
|
|
int maxplayers;
|
|
|
|
|
int curplayers;
|
|
|
|
|
int ai_family;
|
|
|
|
|
char comment[32];
|
|
|
|
|
} srvlst_dat[MAX_SRVLIST];
|
|
|
|
|
int srvlst_cnt = 0;
|
|
|
|
|
|
|
|
|
@ -28,7 +29,8 @@ int srvlst_cnt = 0;
|
|
|
|
|
* all servers we have in there */
|
|
|
|
|
void srvlist_rebuildlist () {
|
|
|
|
|
int ogclst, i;
|
|
|
|
|
char text[255];
|
|
|
|
|
char txt1[255];
|
|
|
|
|
char txt2[255];
|
|
|
|
|
|
|
|
|
|
/* delete the whole list */
|
|
|
|
|
for (i = 0; i < MAX_SRVLIST; i++) {
|
|
|
|
@ -38,6 +40,7 @@ void srvlist_rebuildlist () {
|
|
|
|
|
srvlst_dat[i].port[0] = 0;
|
|
|
|
|
srvlst_dat[i].version[0] = 0;
|
|
|
|
|
srvlst_dat[i].gamename[0] = 0;
|
|
|
|
|
srvlst_dat[i].comment[0] = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
srvlst_cnt = 0;
|
|
|
|
@ -50,7 +53,7 @@ void srvlist_rebuildlist () {
|
|
|
|
|
strncpy (srvlst_dat[srvlst_cnt].version, broadcast_list[i].version, LEN_VERSION);
|
|
|
|
|
strncpy (srvlst_dat[srvlst_cnt].gamename, broadcast_list[i].gamename, LEN_GAMENAME);
|
|
|
|
|
srvlst_dat[srvlst_cnt].ai_family = bman.net_ai_family;
|
|
|
|
|
|
|
|
|
|
sprintf (srvlst_dat[srvlst_cnt].comment, "LAN");
|
|
|
|
|
srvlst_cnt++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -68,6 +71,8 @@ void srvlist_rebuildlist () {
|
|
|
|
|
strncpy (srvlst_dat[srvlst_cnt].host,ogc_array[ogclst].host, LEN_SERVERNAME);
|
|
|
|
|
strncpy (srvlst_dat[srvlst_cnt].port,ogc_array[ogclst].port, LEN_PORT);
|
|
|
|
|
strncpy (srvlst_dat[srvlst_cnt].gamename,ogc_array[ogclst].gamename, LEN_GAMENAME);
|
|
|
|
|
strncpy (srvlst_dat[srvlst_cnt].version,ogc_array[ogclst].version, LEN_VERSION);
|
|
|
|
|
sprintf (srvlst_dat[srvlst_cnt].comment, "INet");
|
|
|
|
|
srvlst_cnt++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -77,10 +82,12 @@ void srvlist_rebuildlist () {
|
|
|
|
|
/* make the list viewable */
|
|
|
|
|
for (i = 0; i < srvlst_cnt; i++) {
|
|
|
|
|
if (srvlst_dat[i].gamename[0] != 0) /* gamename is present */
|
|
|
|
|
sprintf (text, "%s(%s)", srvlst_dat[i].gamename, srvlst_dat[i].version);
|
|
|
|
|
else
|
|
|
|
|
sprintf (text, "%s:%s(%s)", srvlst_dat[i].host, srvlst_dat[i].port, srvlst_dat[i].version);
|
|
|
|
|
strncpy (srvlst_text[i].text, text, LEN_CHARENTRY);
|
|
|
|
|
sprintf (txt1, "%-28s %-11s %-4s", srvlst_dat[i].gamename, srvlst_dat[i].version, srvlst_dat[i].comment);
|
|
|
|
|
else {
|
|
|
|
|
sprintf (txt2, "%s:%s", srvlst_dat[i].host, srvlst_dat[i].port);
|
|
|
|
|
sprintf (txt1, "%-28s %-11s %-4s", txt2, srvlst_dat[i].version, srvlst_dat[i].comment);
|
|
|
|
|
}
|
|
|
|
|
strncpy (srvlst_text[i].text, txt1, LEN_CHARENTRY);
|
|
|
|
|
}
|
|
|
|
|
if (srvlst_cnt == 0)
|
|
|
|
|
strcpy (srvlst_text[0].text, "No Servers Found");
|
|
|
|
@ -91,10 +98,11 @@ void srvlist_rebuildlist () {
|
|
|
|
|
|
|
|
|
|
/* show a list of servers you can select */
|
|
|
|
|
void net_getserver () {
|
|
|
|
|
int menuselect = 0, entry = 0, eventstate, done, srvlst_lastrebuild = 0;
|
|
|
|
|
int menuselect = 0, entry = 0, newentry = 0, eventstate, done, srvlst_lastrebuild = 0;
|
|
|
|
|
_charlist *sel_entry = &srvlst_text[0];
|
|
|
|
|
_menu *menu;
|
|
|
|
|
_menuitem *srvlst_listmenu;
|
|
|
|
|
_menuitem *srvlst_entry;
|
|
|
|
|
SDL_Event event;
|
|
|
|
|
|
|
|
|
|
d_printf ("net_getserver\n");
|
|
|
|
@ -107,7 +115,7 @@ void net_getserver () {
|
|
|
|
|
|
|
|
|
|
menu = menu_new ("Join a Game", 500, 400);
|
|
|
|
|
srvlst_listmenu = menu_create_list (menu, "Host a Game", -1, 50, 475, 250, srvlst_text, &sel_entry, 1);
|
|
|
|
|
menu_create_entry (menu, "IP :", -1, 320, 475, bman.servername, LEN_SERVERNAME+LEN_PORT + 2, MENU_entrytext, 2);
|
|
|
|
|
srvlst_entry = menu_create_entry (menu, "IP :", -1, 320, 475, bman.servername, LEN_SERVERNAME+LEN_PORT + 2, MENU_entrytext, 2);
|
|
|
|
|
menu_create_button (menu, "OK", -1, 350, 150, 0);
|
|
|
|
|
menu_focus_id (menu, 1);
|
|
|
|
|
|
|
|
|
@ -133,21 +141,29 @@ void net_getserver () {
|
|
|
|
|
|
|
|
|
|
done = menu_event_loop (menu, &event, eventstate);
|
|
|
|
|
menuselect = menu->focus->id;
|
|
|
|
|
newentry = sel_entry - &srvlst_text[0];
|
|
|
|
|
|
|
|
|
|
if (newentry != entry) {
|
|
|
|
|
entry = newentry;
|
|
|
|
|
d_printf ("Selected Entry (%d) %s:%s Game:%s\n", entry, srvlst_dat[entry].host, srvlst_dat[entry].port, srvlst_dat[entry].gamename);
|
|
|
|
|
if (srvlst_dat[entry].host[0] != 0
|
|
|
|
|
&& srvlst_dat[entry].port[0] != 0
|
|
|
|
|
&& srvlst_dat[entry].gamename[0] != 0) { /* test if there was a selection */
|
|
|
|
|
bman.net_ai_family = srvlst_dat[entry].ai_family;
|
|
|
|
|
sprintf (bman.servername, "%s:%s", srvlst_dat[entry].host, srvlst_dat[entry].port);
|
|
|
|
|
}
|
|
|
|
|
srvlst_listmenu->changed = 1;
|
|
|
|
|
menu_reload (menu);
|
|
|
|
|
menu_draw (menu);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (done) {
|
|
|
|
|
switch (menuselect) {
|
|
|
|
|
case (0): // Ok Join Selected Game
|
|
|
|
|
menuselect = -1;
|
|
|
|
|
break;
|
|
|
|
|
case (1): // Join a Game
|
|
|
|
|
entry = sel_entry - &srvlst_text[0];
|
|
|
|
|
d_printf ("Selected Entry (%d) %s:%s Game:%s\n", entry, srvlst_dat[entry].host, srvlst_dat[entry].port, srvlst_dat[entry].gamename);
|
|
|
|
|
if (srvlst_dat[entry].host[0] != 0
|
|
|
|
|
&& srvlst_dat[entry].port[0] != 0
|
|
|
|
|
&& srvlst_dat[entry].gamename[0] != 0) { /* test if there was a selection */
|
|
|
|
|
bman.net_ai_family = srvlst_dat[entry].ai_family;
|
|
|
|
|
sprintf (bman.servername, "%s:%s", srvlst_dat[entry].host, srvlst_dat[entry].port);
|
|
|
|
|
menu_focus_id (menu, 0);
|
|
|
|
|
}
|
|
|
|
|
menu_focus_id (menu, 0);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|