You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
107 lines
2.9 KiB
107 lines
2.9 KiB
/* $Id: netsrvlist.c,v 1.1 2003/12/24 02:42:06 stpohle Exp $
|
|
* netsrvlist.c - shows a list of possible servers.*/
|
|
|
|
#include "basic.h"
|
|
#include "bomberclone.h"
|
|
#include "basic.h"
|
|
#include "bomberclone.h"
|
|
#include "network.h"
|
|
#include "menu.h"
|
|
#include "ogcache-client.h"
|
|
|
|
_charlist srvlst_text[MAX_SRVLIST];
|
|
struct __srvlst_entry {
|
|
char host[LEN_SERVERNAME];
|
|
char port[LEN_PORT];
|
|
char gamename[LEN_GAMENAME];
|
|
int maxplayers;
|
|
int curplayers;
|
|
int ai_family;
|
|
} srvlst_dat[MAX_SRVLIST];
|
|
int srvlst_cnt = 0;
|
|
|
|
|
|
|
|
/* will build up our srvlst list with
|
|
* all servers we have in there */
|
|
void srvlist_rebuildlist () {
|
|
int ogclst, i;
|
|
char text[255];
|
|
|
|
d_printf ("srvlist_rebuildlist\n");
|
|
|
|
/* delete the whole list */
|
|
srvlst_cnt = 0;
|
|
srvlst_text[0].text[0] = 0;
|
|
srvlst_text[0].next = NULL;
|
|
|
|
/* add the OpenGameCache Entrys */
|
|
if (bman.notifygamemaster) {
|
|
for (ogclst = 0; ogclst < MAX_OGC_ENTRYS; ogclst++)
|
|
if (ogc_array[ogclst].serial != -1) {
|
|
srvlst_dat[srvlst_cnt].host[0] = 0;
|
|
srvlst_dat[srvlst_cnt].port[0] = 0;
|
|
srvlst_dat[srvlst_cnt].gamename[0] = 0;
|
|
|
|
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);
|
|
srvlst_cnt++;
|
|
}
|
|
}
|
|
|
|
/* add local server list
|
|
* - this will have to be finished later -*/
|
|
|
|
|
|
/* add broadcasted list
|
|
* - this will have to be finished later -*/
|
|
|
|
/* make the list viewable */
|
|
for (i = 0; i < srvlst_cnt; i++) {
|
|
if (srvlst_dat[i].gamename[0] != 0) /* gamename is present */
|
|
sprintf (text, "%s", srvlst_dat[i].gamename);
|
|
else
|
|
sprintf (text, "%s:%s", srvlst_dat[i].host, srvlst_dat[i].port);
|
|
strncpy (srvlst_text[i].text, text, LEN_CHARENTRY);
|
|
}
|
|
charlist_fillarraypointer (srvlst_text, srvlst_cnt);
|
|
};
|
|
|
|
|
|
|
|
/* show a list of servers you can select */
|
|
void net_getserver () {
|
|
int menuselect = 0, entry = 0;
|
|
_charlist *sel_entry = &srvlst_text[0];
|
|
|
|
d_printf ("net_getserver\n");
|
|
|
|
bman.servername[0] = 0;
|
|
ogc_browsestart ();
|
|
|
|
menu_new ("Join a Game", 500, 400);
|
|
menu_create_list ("Host a Game", -1, 50, 475, 250, srvlst_text, &sel_entry, 1);
|
|
menu_create_button ("OK", -1, 325, 150, 0);
|
|
|
|
while (menuselect != -1 && bman.state != GS_quit) {
|
|
srvlist_rebuildlist ();
|
|
menuselect = menu_loop ();
|
|
|
|
switch (menuselect) {
|
|
case (0):
|
|
// Ok Join Selected Game
|
|
case (1): // Join a Game
|
|
entry = &srvlst_text[0] - sel_entry;
|
|
d_printf ("Selected Entry %s:%s Game:%s\n", srvlst_dat[entry].host, srvlst_dat[entry].port, srvlst_dat[entry].gamename);
|
|
bman.net_ai_family = srvlst_dat[entry].ai_family;
|
|
sprintf (bman.servername, "%s:%s", srvlst_dat[entry].host, srvlst_dat[entry].port);
|
|
menuselect = -1;
|
|
break;
|
|
}
|
|
}
|
|
|
|
ogc_browsestop ();
|
|
menu_delete ();
|
|
};
|