this is NOT recommended for the PSP
For the psp use the tutorial located here:
http://forums.inside3d.com/viewtopic.php?t=2175
Hello.
Today you will learn (hopefully) how to add an in game server list to the Quake Engine.
This tutorial is very simple and easy to do.
Step one
Create a new file called slist.c
Step Two
In that file add this code:
Code: Select all
/*
Copyright (C) 1999-2000, contributors of the QuakeForge project
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
// slist.c -- serverlist addressbook
#include "quakedef.h"
server_entry_t slist[MAX_SERVER_LIST];
void SList_Init (void)
{
memset (&slist, 0, sizeof(slist));
}
void SList_Shutdown (void)
{
FILE *f;
if (!(f = fopen (va("%s/servers.lst", com_gamedir), "wt")))
{
Con_DPrintf ("Couldn't open servers.lst\n");
return;
}
SList_Save (f);
fclose (f);
}
void SList_Set (int i, char *addr, char *desc)
{
if (i >= MAX_SERVER_LIST || i < 0)
Sys_Error ("SList_Set: Bad index %d", i);
if (slist[i].server)
Z_Free (slist[i].server);
if (slist[i].description)
Z_Free (slist[i].description);
slist[i].server = CopyString (addr);
slist[i].description = CopyString (desc);
}
void SList_Reset_NoFree (int i)
{
if (i >= MAX_SERVER_LIST || i < 0)
Sys_Error ("SList_Reset_NoFree: Bad index %d", i);
slist[i].description = slist[i].server = NULL;
}
void SList_Reset (int i)
{
if (i >= MAX_SERVER_LIST || i < 0)
Sys_Error ("SList_Reset: Bad index %d", i);
if (slist[i].server)
{
Z_Free (slist[i].server);
slist[i].server = NULL;
}
if (slist[i].description)
{
Z_Free (slist[i].description);
slist[i].description = NULL;
}
}
void SList_Switch (int a, int b)
{
server_entry_t temp;
if (a >= MAX_SERVER_LIST || a < 0)
Sys_Error ("SList_Switch: Bad index %d", a);
if (b >= MAX_SERVER_LIST || b < 0)
Sys_Error ("SList_Switch: Bad index %d", b);
memcpy (&temp, &slist[a], sizeof(temp));
memcpy (&slist[a], &slist[b], sizeof(temp));
memcpy (&slist[b], &temp, sizeof(temp));
}
int SList_Length (void)
{
int count;
for (count = 0 ; count < MAX_SERVER_LIST && slist[count].server ; count++)
;
return count;
}
void SList_Load (void)
{
int c, len, argc, count;
char line[128], *desc, *addr;
FILE *f;
if (!(f = fopen (va("%s/servers.lst", com_gamedir), "rt")))
return;
count = len = 0;
while ((c = getc(f)))
{
if (c == '\n' || c == '\r' || c == EOF)
{
if (c == '\r' && (c = getc(f)) != '\n' && c != EOF)
ungetc (c, f);
line[len] = 0;
len = 0;
Cmd_TokenizeString (line);
if ((argc = Cmd_Argc()) >= 1)
{
addr = Cmd_Argv(0);
desc = (argc >= 2) ? Cmd_Args() : "Unknown";
SList_Set (count, addr, desc);
if (++count == MAX_SERVER_LIST)
break;
}
if (c == EOF)
break; //just in case an EOF follows a '\r'
}
else
{
if (len + 1 < sizeof(line))
line[len++] = c;
}
}
fclose (f);
}
void SList_Save (FILE *f)
{
int i;
for (i=0 ; i<MAX_SERVER_LIST ; i++)
{
if (!slist[i].server)
break;
fprintf (f, "%s\t%s\n", slist[i].server, slist[i].description);
}
}
Create another new file called slist.h
Step Four
In that file add this code:
Code: Select all
/*
Copyright (C) 1999-2000, contributors of the QuakeForge project
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
// slist.h
#define MAX_SERVER_LIST 256
#define MAX_PLAYERS 16
typedef struct
{
int id;
int frags;
int time;
char *name;
int top;
int bottom;
} playerinfo_t;
typedef struct
{
char *server;
char *description;
} server_entry_t;
extern server_entry_t slist[MAX_SERVER_LIST];
void SList_Init (void);
void SList_Shutdown (void);
void SList_Set (int i,char *addr,char *desc);
void SList_Reset_NoFree (int i);
void SList_Reset (int i);
void SList_Switch (int a,int b);
int SList_Length (void);
void SList_Load (void);
void SList_Save (FILE *f);
Open up Quakedef.h and at the bottom of the include list add this line of code:
#include "slist.h"
Step Six
Open up menu.c and replace the sever list menu with this:
Code: Select all
///=============================================================================
/* SERVER LIST MENU */
#define MENU_X 50
#define MENU_Y 21
#define TITLE_Y 4
#define STAT_Y 166
extern qboolean keydown[256];
int slist_cursor = 0, slist_mins = 0, slist_maxs = 15, slist_state;
#define SLIST_BUFSIZE 128
playerinfo_t plist[16]; int numPlayers;
void M_Menu_ServerList_f (void)
{
SList_Load ();
key_dest = key_menu;
m_state = m_slist;
m_entersound = true;
slist_state = 0;
}
void M_ServerList_Draw (void)
{
int serv, line;
M_DrawTextBox (MENU_X, TITLE_Y, 23, 1);
M_PrintWhite (MENU_X + 60, TITLE_Y + 8, "Server List");
if (!slist[0].server)
{
M_PrintWhite (84, MENU_Y + 32, "Empty server list");
M_Print (60, MENU_Y + 48, "By Team Xlink");
return;
}
M_DrawTextBox (MENU_X, STAT_Y, 23, 1);
M_DrawTextBox (MENU_X, MENU_Y, 23, slist_maxs - slist_mins + 1);
for (serv = slist_mins, line = 1 ; serv <= slist_maxs && serv < MAX_SERVER_LIST && slist[serv].server ; serv++, line++)
M_Print (MENU_X + 18, line * 8 + MENU_Y, va("%1.21s", slist[serv].description));
M_Print (MENU_X - 36, STAT_Y - 4, "By Team Xlink");
M_PrintWhite (MENU_X + 18, STAT_Y + 8, va("%1.22s", slist[slist_cursor].server));
M_DrawCharacter (MENU_X + 8, (slist_cursor - slist_mins + 1) * 8 + MENU_Y, 12+((int)(realtime*4)&1));
}
void M_ServerList_Key (key)
{
if (!slist[0].server && key != K_ESCAPE && key != K_INS)
return;
switch (key)
{
case K_ESCAPE:
M_Menu_MultiPlayer_f ();
break;
case K_UPARROW:
S_LocalSound ("misc/menu1.wav");
if (slist_cursor > 0)
{
if (keydown[K_CTRL])
SList_Switch (slist_cursor, slist_cursor - 1);
slist_cursor--;
}
break;
case K_DOWNARROW:
S_LocalSound ("misc/menu1.wav");
if (keydown[K_CTRL])
{
if (slist_cursor != SList_Length() - 1)
{
SList_Switch (slist_cursor, slist_cursor + 1);
slist_cursor++;
}
}
else if (slist_cursor < MAX_SERVER_LIST - 1 && slist[slist_cursor+1].server)
slist_cursor++;
break;
case K_HOME:
S_LocalSound ("misc/menu1.wav");
slist_cursor = 0;
break;
case K_END:
S_LocalSound ("misc/menu1.wav");
slist_cursor = SList_Length() - 1;
break;
case K_AUX1:
S_LocalSound ("misc/menu1.wav");
slist_cursor -= (slist_maxs - slist_mins);
if (slist_cursor < 0)
slist_cursor = 0;
break;
case K_AUX2:
S_LocalSound ("misc/menu1.wav");
slist_cursor += (slist_maxs - slist_mins);
if (slist_cursor >= MAX_SERVER_LIST)
slist_cursor = MAX_SERVER_LIST - 1;
while (!slist[slist_cursor].server)
slist_cursor--;
break;
case K_ENTER:
m_state = m_main;
M_ToggleMenu_f ();
Cbuf_AddText ( va ("connect \"%s\"\n", slist[slist_cursor].server) );
break;
}
if (slist_cursor < slist_mins)
{
slist_maxs -= (slist_mins - slist_cursor);
slist_mins = slist_cursor;
}
if (slist_cursor > slist_maxs)
{
slist_mins += (slist_cursor - slist_maxs);
slist_maxs = slist_cursor;
}
}
Scroll down to:
Code: Select all
void M_Init (void)
Code: Select all
Cmd_AddCommand ("menu_quit", M_Menu_Quit_f);
Code: Select all
Cmd_AddCommand ("menu_serverlist", M_Menu_ServerList_f);
Code: Select all
menu_serverlist
Code: Select all
Cbuf_AddText ("menu_serverlist");
PSP
Step 8
Well, since more people are interested in PSP Quake then I thought, I will throw in the steps for the psp.
Go to your subdirectory called psp and open up the file called makefile
*It will most likely make a confirmation pop up that talks about which program to use to open it. You can use any text editor (As long as it doesn't have automatic formatting) *cough* Microsoft Word, if you have no idea what to use, just use notepad
Find this:
Code: Select all
$(OBJ_DIR)/world.o \
$(OBJ_DIR)/zone.o
Code: Select all
$(OBJ_DIR)/world.o \
$(OBJ_DIR)/zone.o \
$(OBJ_DIR)/slist.o
**PSP TIP START**
Whenever you need to add a file to your engine at the end of the file, your last line of the $(OBJ_DIR) has to NOT have a frontslash \.
Every other &(OBG_DIR) line MUST have a front slash \.
**PSP TIP END**
There you go.
If you have any comments or questions, improvements or anything just replay away!
Additional Credit:
Quake Forge Project
Team Xlink