1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248
|
/*
*
* $Id: nUserl.c,v 1.7 2004/09/12 20:01:06 jon Exp $
*
* Copyright 1999-2004 Jon Trulson under the ARTISTIC LICENSE. (See LICENSE).
*/
#include "c_defs.h"
#include "context.h"
#include "global.h"
#include "datatypes.h"
#include "color.h"
#include "conf.h"
#include "conqcom.h"
#include "conqlb.h"
#include "gldisplay.h"
#include "node.h"
#include "client.h"
#include "packet.h"
#include "nCP.h"
#include "nMenu.h"
#include "nDead.h"
#include "nUserl.h"
#include "cqkeys.h"
/* from conquestgl */
extern Unsgn8 clientFlags;
extern int lastServerError;
static int snum, godlike;
static int uvec[MAXUSERS];
static int nu;
static int fuser;
static int offset;
static int extrast; /* normal, or extra stats? */
static int nUserlDisplay(dspConfig_t *);
static int nUserlIdle(void);
static int nUserlInput(int ch);
static scrNode_t nUserlNode = {
nUserlDisplay, /* display */
nUserlIdle, /* idle */
nUserlInput, /* input */
NULL /* next */
};
static int retnode; /* the node to return to */
scrNode_t *nUserlInit(int nodeid, int setnode, int sn, int gl, int extra)
{
int i, unum;
retnode = nodeid;
snum = sn;
godlike = gl;
extrast = extra;
/* init the user vector */
for (i=0; i<MAXUSERS; i++)
uvec[i] = i;
/* sort the (living) user list */
nu = 0;
for ( unum = 0; unum < MAXUSERS; unum++)
if ( Users[unum].live)
{
uvec[nu++] = unum;
}
clbSortUsers(uvec, nu);
fuser = 0;
if (setnode)
setNode(&nUserlNode);
return(&nUserlNode);
}
static int nUserlDisplay(dspConfig_t *dsp)
{
int j, fline, lline, lin;
static char *hd1="U S E R L I S T";
static char *ehd1="M O R E U S E R S T A T S";
static char *ehd2="name cpu conq coup geno taken bombed/shot shots fired last entry";
static char *ehd3="planets armies phaser torps";
static char cbuf[BUFFER_SIZE];
int color;
/* Do some screen setup. */
lin = 0;
if (extrast)
{
cprintf(lin, 0, ALIGN_CENTER, "#%d#%s", LabelColor, ehd1);
lin = lin + 2;
cprintf(lin, 34, ALIGN_NONE, "#%d#%s", LabelColor, ehd3);
c_strcpy( ehd2, cbuf );
lin = lin + 1;
cprintf(lin, 0, ALIGN_NONE, "#%d#%s", LabelColor, cbuf);
}
else
{
cprintf(lin, 0, ALIGN_CENTER, "#%d#%s", LabelColor, hd1);
lin = lin + 3; /* FIXME - hardcoded??? - dwp */
clbUserline( -1, -1, cbuf, FALSE, FALSE );
cprintf(lin, 0, ALIGN_NONE, "#%d#%s", LabelColor, cbuf);
}
for ( j = 0; cbuf[j] != EOS; j = j + 1 )
if ( cbuf[j] != ' ' )
cbuf[j] = '-';
lin++;
cprintf(lin, 0, ALIGN_NONE, "#%d#%s", LabelColor, cbuf);
fline = lin + 1; /* first line to use */
lline = MSG_LIN1; /* last line to use */
offset = fuser;
lin = fline;
while ( offset < nu && lin <= lline )
{
if (extrast)
clbStatline( uvec[offset], cbuf );
else
clbUserline( uvec[offset], -1, cbuf, godlike, FALSE );
/* determine color */
if ( snum > 0 && snum <= MAXSHIPS ) /* we're a valid ship */
{
if ( strcmp(Users[uvec[offset]].username,
Users[Ships[snum].unum].username) == 0 &&
Users[uvec[offset]].type == Users[Ships[snum].unum].type)
color = NoColor | CQC_A_BOLD; /* it's ours */
else if (Ships[snum].war[Users[uvec[offset]].team])
color = RedLevelColor; /* we're at war with it */
else if (Ships[snum].team == Users[uvec[offset]].team && !selfwar(snum))
color = GreenLevelColor; /* it's a team ship */
else
color = YellowLevelColor;
}
else if (godlike)/* we are running conqoper */
color = YellowLevelColor; /* bland view */
else /* we don't have a ship yet */
{
if ( strcmp(Users[uvec[offset]].username,
Users[Context.unum].username) == 0 &&
Users[uvec[offset]].type == Users[Context.unum].type)
color = NoColor | CQC_A_BOLD; /* it's ours */
else if (Users[Context.unum].war[Users[uvec[offset]].team])
color = RedLevelColor; /* we're war with them (might be selfwar) */
else if (Users[Context.unum].team == Users[uvec[offset]].team)
color = GreenLevelColor; /* team ship */
else
color = YellowLevelColor;
}
cprintf(lin, 0, ALIGN_CENTER, "#%d#%s", color, cbuf);
offset = offset + 1;
lin = lin + 1;
}
if ( offset >= nu ) /* last page */
cprintf(MSG_LIN2, 0, ALIGN_CENTER, "#%d#%s", NoColor, MTXT_DONE);
else
cprintf(MSG_LIN2, 0, ALIGN_CENTER, "#%d#%s", NoColor, MTXT_MORE);
return NODE_OK;
}
static int nUserlIdle(void)
{
int pkttype;
Unsgn8 buf[PKT_MAXSIZE];
int sockl[2] = {cInfo.sock, cInfo.usock};
while ((pkttype = waitForPacket(PKT_FROMSERVER, sockl, PKT_ANYPKT,
buf, PKT_MAXSIZE, 0, NULL)) > 0)
processPacket(buf);
if (pkttype < 0) /* some error */
{
clog("nUserlIdle: waiForPacket returned %d", pkttype);
Ships[Context.snum].status = SS_OFF;
return NODE_EXIT;
}
if (clientFlags & SPCLNTSTAT_FLAG_KILLED && retnode == DSP_NODE_CP)
{
/* time to die properly. */
setONode(NULL);
nDeadInit();
return NODE_OK;
}
return NODE_OK;
}
static int nUserlInput(int ch)
{
ch = CQ_CHAR(ch);
if (ch == TERM_EXTRA)
{
fuser = 0; /* move to first page */
return NODE_OK;
}
if (offset < nu)
{
if (ch == ' ')
{
fuser = offset;
return NODE_OK;
}
}
/* go back */
switch (retnode)
{
case DSP_NODE_CP:
setONode(NULL);
nCPInit();
break;
case DSP_NODE_MENU:
setONode(NULL);
nMenuInit();
break;
default:
clog("nUserlInput: invalid return node: %d, going to DSP_NODE_MENU",
retnode);
setONode(NULL);
nMenuInit();
break;
}
/* NOTREACHED */
return NODE_OK;
}
|