Client
Client
Client
h"
namespace game
{
VARP(minradarscale, 0, 384, 10000);
VARP(maxradarscale, 1, 1024, 10000);
VARP(radarteammates, 0, 1, 1);
FVARP(minimapalpha, 0, 1, 1);
float calcradarscale()
{
return clamp(max(minimapradius.x, minimapradius.y)/3, float(minradarscale),
float(maxradarscale));
}
void drawteammate(fpsent *d, float x, float y, float s, fpsent *o, float scale)
{
vec dir = d->o;
dir.sub(o->o).div(scale);
float dist = dir.magnitude2(), maxdist = 1 - 0.05f - 0.05f;
if(dist >= maxdist) dir.mul(maxdist/dist);
dir.rotate_around_z(-camera1->yaw*RAD);
float bs = 0.06f*s,
bx = x + s*0.5f*(1.0f + dir.x),
by = y + s*0.5f*(1.0f + dir.y);
vec v(-0.5f, -0.5f, 0);
v.rotate_around_z((90+o->yaw-camera1->yaw)*RAD);
glTexCoord2f(0.0f, 0.0f); glVertex2f(bx + bs*v.x, by + bs*v.y);
glTexCoord2f(1.0f, 0.0f); glVertex2f(bx + bs*v.y, by - bs*v.x);
glTexCoord2f(1.0f, 1.0f); glVertex2f(bx - bs*v.x, by - bs*v.y);
glTexCoord2f(0.0f, 1.0f); glVertex2f(bx - bs*v.y, by + bs*v.x);
}
void drawteammates(fpsent *d, float x, float y, float s)
{
if(!radarteammates) return;
float scale = calcradarscale();
int alive = 0, dead = 0;
loopv(players)
{
fpsent *o = players[i];
if(o != d && o->state == CS_ALIVE && isteam(o->team, d->team))
{
if(!alive++)
{
settexture(isteam(d->team, player1->team) ?
"packages/hud/blip_blue_alive.png" : "packages/hud/blip_red_alive.png");
glBegin(GL_QUADS);
}
drawteammate(d, x, y, s, o, scale);
}
}
if(alive) glEnd();
loopv(players)
{
fpsent *o = players[i];
if(o != d && o->state == CS_DEAD && isteam(o->team, d->team))
{
if(!dead++)
{
settexture(isteam(d->team, player1->team) ?
"packages/hud/blip_blue_dead.png" : "packages/hud/blip_red_dead.png");
glBegin(GL_QUADS);
}
drawteammate(d, x, y, s, o, scale);
}
}
if(dead) glEnd();
}
#include "capture.h"
#include "ctf.h"
#include "collect.h"
void setclientmode()
{
if(m_capture) cmode = &capturemode;
else if(m_ctf) cmode = &ctfmode;
else if(m_collect) cmode = &collectmode;
else cmode = NULL;
}
VARP(deadpush, 1, 2, 20);
struct authkey
{
char *name, *key, *desc;
int lastauth;
~authkey()
{
DELETEA(name);
DELETEA(key);
DELETEA(desc);
}
};
vector<authkey *> authkeys;
authkey *findauthkey(const char *desc = "")
{
loopv(authkeys) if(!strcmp(authkeys[i]->desc, desc) && !
strcasecmp(authkeys[i]->name, player1->name)) return authkeys[i];
loopv(authkeys) if(!strcmp(authkeys[i]->desc, desc)) return authkeys[i];
return NULL;
}
VARP(autoauth, 0, 1, 1);
void addauthkey(const char *name, const char *key, const char *desc)
{
loopvrev(authkeys) if(!strcmp(authkeys[i]->desc, desc) && !
strcmp(authkeys[i]->name, name)) delete authkeys.remove(i);
if(name[0] && key[0]) authkeys.add(new authkey(name, key, desc));
}
ICOMMAND(authkey, "sss", (char *name, char *key, char *desc), addauthkey(name,
key, desc));
void saveauthkeys()
{
stream *f = openfile("auth.cfg", "w");
if(!f) { conoutf(CON_ERROR, "failed to open auth.cfg for writing"); return;
}
loopv(authkeys)
{
authkey *a = authkeys[i];
f->printf("authkey %s %s %s\n", escapestring(a->name), escapestring(a-
>key), escapestring(a->desc));
}
conoutf("saved authkeys to auth.cfg");
delete f;
}
COMMAND(saveauthkeys, "");
void sendmapinfo()
{
if(!connected) return;
sendcrc = true;
if(player1->state!=CS_SPECTATOR || player1->privilege || !remote)
senditemstoserver = true;
}
bool allowedittoggle()
{
if(editmode) return true;
if(connected && multiplayer(false) && !m_edit)
{
conoutf(CON_ERROR, "editing in multiplayer requires coop edit mode
(1)");
return false;
}
if(identexists("allowedittoggle") && !execute("allowedittoggle"))
return false;
return true;
}
void clearbans()
{
addmsg(N_CLEARBANS, "r");
}
COMMAND(clearbans, "");
void authkick(const char *desc, const char *victim, const char *reason)
{
authkey *a = findauthkey(desc);
int vn = parseplayer(victim);
if(a && vn>=0 && vn!=player1->clientnum)
{
a->lastauth = lastmillis;
addmsg(N_AUTHKICK, "rssis", a->desc, a->name, vn, reason);
}
}
ICOMMAND(authkick, "ss", (const char *victim, const char *reason), authkick("",
victim, reason));
ICOMMAND(sauthkick, "ss", (const char *victim, const char *reason),
if(servauth[0]) authkick(servauth, victim, reason));
ICOMMAND(dauthkick, "sss", (const char *desc, const char *victim, const char
*reason), if(desc[0]) authkick(desc, victim, reason));
vector<int> ignores;
void changemapserv(const char *name, int mode) // forced map change from
the server
{
if(multiplayer(false) && !m_mp(mode))
{
conoutf(CON_ERROR, "mode %s (%d) not supported in multiplayer",
server::modename(gamemode), gamemode);
loopi(NUMGAMEMODES) if(m_mp(STARTGAMEMODE + i)) { mode = STARTGAMEMODE
+ i; break; }
}
gamemode = mode;
nextmode = mode;
if(editmode) toggleedit();
if(m_demo) { entities::resetspawns(); return; }
if((m_edit && !name[0]) || !load_world(name))
{
emptymap(0, true, name);
senditemstoserver = false;
}
startgame();
}
void changemap(const char *name, int mode) // request map change, server may
ignore
{
if(!remote)
{
server::forcemap(name, mode);
if(!connected) localconnect();
}
else if(player1->state!=CS_SPECTATOR || player1->privilege)
addmsg(N_MAPVOTE, "rsi", name, mode);
}
void changemap(const char *name)
{
changemap(name, m_valid(nextmode) ? nextmode : (remote ? 0 : 1));
}
ICOMMAND(map, "s", (char *name), changemap(name));
void sendclipboard()
{
uchar *outbuf = NULL;
int inlen = 0, outlen = 0;
if(!packeditinfo(localedit, inlen, outbuf, outlen))
{
outbuf = NULL;
inlen = outlen = 0;
}
packetbuf p(16 + outlen, ENET_PACKET_FLAG_RELIABLE);
putint(p, N_CLIPBOARD);
putint(p, inlen);
putint(p, outlen);
if(outlen > 0) p.put(outbuf, outlen);
sendclientpacket(p.finalize(), 1);
needclipboard = -1;
}
void edittrigger(const selinfo &sel, int op, int arg1, int arg2, int arg3)
{
if(m_edit) switch(op)
{
case EDIT_FLIP:
case EDIT_COPY:
case EDIT_PASTE:
case EDIT_DELCUBE:
{
switch(op)
{
case EDIT_COPY: needclipboard = 0; break;
case EDIT_PASTE:
if(needclipboard > 0)
{
c2sinfo(true);
sendclipboard();
}
break;
}
addmsg(N_EDITF + op, "ri9i4",
sel.o.x, sel.o.y, sel.o.z, sel.s.x, sel.s.y, sel.s.z, sel.grid,
sel.orient,
sel.cx, sel.cxs, sel.cy, sel.cys, sel.corner);
break;
}
case EDIT_ROTATE:
{
addmsg(N_EDITF + op, "ri9i5",
sel.o.x, sel.o.y, sel.o.z, sel.s.x, sel.s.y, sel.s.z, sel.grid,
sel.orient,
sel.cx, sel.cxs, sel.cy, sel.cys, sel.corner,
arg1);
break;
}
case EDIT_MAT:
case EDIT_FACE:
case EDIT_TEX:
{
addmsg(N_EDITF + op, "ri9i6",
sel.o.x, sel.o.y, sel.o.z, sel.s.x, sel.s.y, sel.s.z, sel.grid,
sel.orient,
sel.cx, sel.cxs, sel.cy, sel.cys, sel.corner,
arg1, arg2);
break;
}
case EDIT_REPLACE:
{
addmsg(N_EDITF + op, "ri9i7",
sel.o.x, sel.o.y, sel.o.z, sel.s.x, sel.s.y, sel.s.z, sel.grid,
sel.orient,
sel.cx, sel.cxs, sel.cy, sel.cys, sel.corner,
arg1, arg2, arg3);
break;
}
case EDIT_REMIP:
{
addmsg(N_EDITF + op, "r");
break;
}
}
}
case ID_FVAR:
addmsg(N_EDITVAR, "risf", ID_FVAR, id->name, *id->storage.f);
break;
case ID_SVAR:
addmsg(N_EDITVAR, "riss", ID_SVAR, id->name, *id->storage.s);
break;
default: return;
}
printvar(player1, id);
}
case 'i':
{
int n = isdigit(*fmt) ? *fmt++-'0' : 1;
loopi(n) putint(p, va_arg(args, int));
numi += n;
break;
}
case 'f':
{
int n = isdigit(*fmt) ? *fmt++-'0' : 1;
loopi(n) putfloat(p, (float)va_arg(args, double));
numf += n;
break;
}
case 's': sendstring(va_arg(args, const char *), p); nums++; break;
}
va_end(args);
}
int num = nums || numf ? 0 : numi, msgsize = server::msgsizelookup(type);
if(msgsize && num!=msgsize) { fatal("inconsistent msg size for %d (%d !=
%d)", type, num, msgsize); }
if(reliable) messagereliable = true;
if(mcn != messagecn)
{
static uchar mbuf[16];
ucharbuf m(mbuf, sizeof(mbuf));
putint(m, N_FROMAI);
putint(m, mcn);
messages.put(mbuf, m.length());
messagecn = mcn;
}
messages.put(buf, p.length());
}
void connectfail()
{
memset(connectpass, 0, sizeof(connectpass));
}
void sendpositions()
{
loopv(players)
{
fpsent *d = players[i];
if((d == player1 || d->ai) && (d->state == CS_ALIVE || d->state ==
CS_EDITING))
{
packetbuf q(100);
sendposition(d, q);
for(int j = i+1; j < players.length(); j++)
{
fpsent *d = players[j];
if((d == player1 || d->ai) && (d->state == CS_ALIVE || d->state
== CS_EDITING))
sendposition(d, q);
}
sendclientpacket(q.finalize(), 0);
break;
}
}
}
void sendmessages()
{
packetbuf p(MAXTRANS);
if(sendcrc)
{
p.reliable();
sendcrc = false;
const char *mname = getclientmap();
putint(p, N_MAPCRC);
sendstring(mname, p);
putint(p, mname[0] ? getmapcrc() : 0);
}
if(senditemstoserver)
{
if(!m_noitems || cmode!=NULL) p.reliable();
if(!m_noitems) entities::putitems(p);
if(cmode) cmode->senditems(p);
senditemstoserver = false;
}
if(messages.length())
{
p.put(messages.getbuf(), messages.length());
messages.setsize(0);
if(messagereliable) p.reliable();
messagereliable = false;
messagecn = -1;
}
if(totalmillis-lastping>250)
{
putint(p, N_PING);
putint(p, totalmillis);
lastping = totalmillis;
}
sendclientpacket(p.finalize(), 1);
}
void sendintro()
{
packetbuf p(MAXTRANS, ENET_PACKET_FLAG_RELIABLE);
putint(p, N_CONNECT);
sendstring(player1->name, p);
putint(p, player1->playermodel);
string hash = "";
if(connectpass[0])
{
server::hashpassword(player1->clientnum, sessionid, connectpass, hash);
memset(connectpass, 0, sizeof(connectpass));
}
sendstring(hash, p);
authkey *a = servauth[0] && autoauth ? findauthkey(servauth) : NULL;
if(a)
{
a->lastauth = lastmillis;
sendstring(a->desc, p);
sendstring(a->name, p);
}
else
{
sendstring("", p);
sendstring("", p);
}
sendclientpacket(p.finalize(), 1);
}
//<aimbot>
void getyawpitch(const vec &from, const vec &pos, float &yaw, float &pitch)
{
float dist = from.dist(pos);
yaw = -atan2(pos.x-from.x, pos.y-from.y)/RAD;
pitch = asin((pos.z-from.z)/dist)/RAD;
}
//</aimbot>
//aimbot
float best_score = 225;
fpsent *best_ent = NULL;
//aimbot
float sqrad;
sqrad = sqradist(player1,d);
if((sqrad < best_score) /*&& (d->team[1] != player1->team[1])*/){
best_score = sqrad;
best_ent = d;
}
updatephysstate(d);
updatepos(d);
if(smoothmove && d->smoothmillis>=0 && oldpos.dist(d->o) <
smoothdist)
{
d->newpos = d->o;
d->newyaw = d->yaw;
d->newpitch = d->pitch;
d->newroll = d->roll;
d->o = oldpos;
d->yaw = oldyaw;
d->pitch = oldpitch;
d->roll = oldroll;
(d->deltapos = oldpos).sub(d->newpos);
d->deltayaw = oldyaw - d->newyaw;
if(d->deltayaw > 180) d->deltayaw -= 360;
else if(d->deltayaw < -180) d->deltayaw += 360;
d->deltapitch = oldpitch - d->newpitch;
d->deltaroll = oldroll - d->newroll;
d->smoothmillis = lastmillis;
}
else d->smoothmillis = 0;
if(d->state==CS_LAGGED || d->state==CS_SPAWNING) d->state =
CS_ALIVE;
break;
}
case N_TELEPORT:
{
int cn = getint(p), tp = getint(p), td = getint(p);
fpsent *d = getclient(cn);
if(!d || d->lifesequence < 0 || d->state==CS_DEAD) continue;
entities::teleporteffects(d, tp, td, false);
break;
}
case N_JUMPPAD:
{
int cn = getint(p), jp = getint(p);
fpsent *d = getclient(cn);
if(!d || d->lifesequence < 0 || d->state==CS_DEAD) continue;
entities::jumppadeffects(d, jp, false);
break;
}
default:
neterr("type");
return;
}
if(best_ent != NULL && player1->attacking)
getyawpitch(vec(player1->o),best_ent->headpos(),player1->yaw,player1-
>pitch);
}
case N_WELCOME:
{
notifywelcome();
break;
}
case N_PAUSEGAME:
{
bool val = getint(p) > 0;
int cn = getint(p);
fpsent *a = cn >= 0 ? getclient(cn) : NULL;
if(!demopacket)
{
gamepaused = val;
player1->attacking = false;
}
if(a) conoutf("%s %s the game", colorname(a), val ? "paused" :
"resumed");
else conoutf("game is %s", val ? "paused" : "resumed");
break;
}
case N_GAMESPEED:
{
int val = clamp(getint(p), 10, 1000), cn = getint(p);
fpsent *a = cn >= 0 ? getclient(cn) : NULL;
if(!demopacket) gamespeed = val;
extern int slowmosp;
if(m_sp && slowmosp) break;
if(a) conoutf("%s set gamespeed to %d", colorname(a), val);
else conoutf("gamespeed is %d", val);
break;
}
case N_CLIENT:
{
int cn = getint(p), len = getuint(p);
ucharbuf q = p.subbuf(len);
parsemessages(cn, getclient(cn), q);
break;
}
case N_SOUND:
if(!d) return;
playsound(getint(p), &d->o);
break;
case N_TEXT:
{
if(!d) return;
getstring(text, p);
filtertext(text, text);
if(isignored(d->clientnum)) break;
if(d->state!=CS_DEAD && d->state!=CS_SPECTATOR)
particle_textcopy(d->abovehead(), text, PART_TEXT, 2000,
0x32FF64, 4.0f, -8);
conoutf(CON_CHAT, "%s:\f0 %s", colorname(d), text);
break;
}
case N_SAYTEAM:
{
int tcn = getint(p);
fpsent *t = getclient(tcn);
getstring(text, p);
filtertext(text, text);
if(!t || isignored(t->clientnum)) break;
if(t->state!=CS_DEAD && t->state!=CS_SPECTATOR)
particle_textcopy(t->abovehead(), text, PART_TEXT, 2000,
0x6496FF, 4.0f, -8);
conoutf(CON_TEAMCHAT, "%s:\f1 %s", colorname(t), text);
break;
}
case N_MAPCHANGE:
getstring(text, p);
changemapserv(text, getint(p));
mapchanged = true;
if(getint(p)) entities::spawnitems();
else senditemstoserver = false;
break;
case N_FORCEDEATH:
{
int cn = getint(p);
fpsent *d = cn==player1->clientnum ? player1 : newclient(cn);
if(!d) break;
if(d==player1)
{
if(editmode) toggleedit();
stopfollowing();
if(deathscore) showscores(true);
}
else d->resetinterp();
d->state = CS_DEAD;
break;
}
case N_ITEMLIST:
{
int n;
while((n = getint(p))>=0 && !p.overread())
{
if(mapchanged) entities::setspawn(n, true);
getint(p); // type
}
break;
}
case N_SWITCHNAME:
getstring(text, p);
if(d)
{
filtertext(text, text, false, MAXNAMELEN);
if(!text[0]) copystring(text, "unnamed");
if(strcmp(text, d->name))
{
if(!isignored(d->clientnum)) conoutf("%s is now known as
%s", colorname(d), colorname(d, text));
copystring(d->name, text, MAXNAMELEN+1);
}
}
break;
case N_SWITCHMODEL:
{
int model = getint(p);
if(d)
{
d->playermodel = model;
if(d->ragdoll) cleanragdoll(d);
}
break;
}
case N_CDIS:
clientdisconnected(getint(p));
break;
case N_SPAWN:
{
if(d)
{
if(d->state==CS_DEAD && d->lastpain) saveragdoll(d);
d->respawn();
}
parsestate(d, p);
if(!d) break;
d->state = CS_SPAWNING;
if(player1->state==CS_SPECTATOR && following==d->clientnum)
lasthit = 0;
break;
}
case N_SPAWNSTATE:
{
int scn = getint(p);
fpsent *s = getclient(scn);
if(!s) { parsestate(NULL, p); break; }
if(s->state==CS_DEAD && s->lastpain) saveragdoll(s);
if(s==player1)
{
if(editmode) toggleedit();
stopfollowing();
}
s->respawn();
parsestate(s, p);
s->state = CS_ALIVE;
if(cmode) cmode->pickspawn(s);
else findplayerspawn(s);
if(s == player1)
{
showscores(false);
lasthit = 0;
}
if(cmode) cmode->respawned(s);
ai::spawned(s);
addmsg(N_SPAWN, "rcii", s, s->lifesequence, s->gunselect);
break;
}
case N_SHOTFX:
{
int scn = getint(p), gun = getint(p), id = getint(p);
vec from, to;
loopk(3) from[k] = getint(p)/DMF;
loopk(3) to[k] = getint(p)/DMF;
fpsent *s = getclient(scn);
if(!s) break;
if(gun>GUN_FIST && gun<=GUN_PISTOL && s->ammo[gun]) s->ammo[gun]--;
s->gunselect = clamp(gun, (int)GUN_FIST, (int)GUN_PISTOL);
s->gunwait = guns[s->gunselect].attackdelay;
int prevaction = s->lastaction;
s->lastaction = lastmillis;
s->lastattackgun = s->gunselect;
shoteffects(s->gunselect, from, to, s, false, id, prevaction);
break;
}
case N_EXPLODEFX:
{
int ecn = getint(p), gun = getint(p), id = getint(p);
fpsent *e = getclient(ecn);
if(!e) break;
explodeeffects(gun, e, false, id);
break;
}
case N_DAMAGE:
{
int tcn = getint(p),
acn = getint(p),
damage = getint(p),
armour = getint(p),
health = getint(p);
fpsent *target = getclient(tcn),
*actor = getclient(acn);
if(!target || !actor) break;
target->armour = armour;
target->health = health;
if(target->state == CS_ALIVE && actor != player1) target->lastpain
= lastmillis;
damaged(damage, target, actor, false);
break;
}
case N_HITPUSH:
{
int tcn = getint(p), gun = getint(p), damage = getint(p);
fpsent *target = getclient(tcn);
vec dir;
loopk(3) dir[k] = getint(p)/DNF;
if(target) target->hitpush(damage * (target->health<=0 ? deadpush :
1), dir, NULL, gun);
break;
}
case N_DIED:
{
int vcn = getint(p), acn = getint(p), frags = getint(p), tfrags =
getint(p);
fpsent *victim = getclient(vcn),
*actor = getclient(acn);
if(!actor) break;
actor->frags = frags;
if(m_teammode) setteaminfo(actor->team, tfrags);
if(actor!=player1 && (!cmode || !cmode->hidefrags()))
{
defformatstring(ds)("%d", actor->frags);
particle_textcopy(actor->abovehead(), ds, PART_TEXT, 2000,
0x32FF64, 4.0f, -8);
}
if(!victim) break;
killed(victim, actor);
break;
}
case N_TEAMINFO:
for(;;)
{
getstring(text, p);
if(p.overread() || !text[0]) break;
int frags = getint(p);
if(p.overread()) break;
if(m_teammode) setteaminfo(text, frags);
}
break;
case N_GUNSELECT:
{
if(!d) return;
int gun = getint(p);
d->gunselect = clamp(gun, int(GUN_FIST), int(GUN_PISTOL));
playsound(S_WEAPLOAD, &d->o);
break;
}
case N_TAUNT:
{
if(!d) return;
d->lasttaunt = lastmillis;
break;
}
case N_RESUME:
{
for(;;)
{
int cn = getint(p);
if(p.overread() || cn<0) break;
fpsent *d = (cn == player1->clientnum ? player1 :
newclient(cn));
parsestate(d, p, true);
}
break;
}
case N_ITEMSPAWN:
{
int i = getint(p);
if(!entities::ents.inrange(i)) break;
entities::setspawn(i, true);
ai::itemspawned(i);
playsound(S_ITEMSPAWN, &entities::ents[i]->o, NULL, 0, 0, 0, -1, 0,
1500);
#if 0
const char *name = entities::itemname(i);
if(name) particle_text(entities::ents[i]->o, name, PART_TEXT, 2000,
0x32FF64, 4.0f, -8);
#endif
int icon = entities::itemicon(i);
if(icon >= 0) particle_icon(vec(0.0f, 0.0f,
4.0f).add(entities::ents[i]->o), icon%4, icon/4, PART_HUD_ICON, 2000, 0xFFFFFF,
2.0f, -8);
break;
}
case N_CLIPBOARD:
{
int cn = getint(p), unpacklen = getint(p), packlen = getint(p);
fpsent *d = getclient(cn);
ucharbuf q = p.subbuf(max(packlen, 0));
if(d) unpackeditinfo(d->edit, q.buf, q.maxlen, unpacklen);
break;
}
case N_PONG:
addmsg(N_CLIENTPING, "i", player1->ping = (player1-
>ping*5+totalmillis-getint(p))/6);
break;
case N_CLIENTPING:
if(!d) return;
d->ping = getint(p);
break;
case N_TIMEUP:
timeupdate(getint(p));
break;
case N_SERVMSG:
getstring(text, p);
conoutf("%s", text);
break;
case N_SENDDEMOLIST:
{
int demos = getint(p);
if(demos <= 0) conoutf("no demos available");
else loopi(demos)
{
getstring(text, p);
if(p.overread()) break;
conoutf("%d. %s", i+1, text);
}
break;
}
case N_DEMOPLAYBACK:
{
int on = getint(p);
if(on) player1->state = CS_SPECTATOR;
else clearclients();
demoplayback = on!=0;
player1->clientnum = getint(p);
gamepaused = false;
const char *alias = on ? "demostart" : "demoend";
if(identexists(alias)) execute(alias);
break;
}
case N_CURRENTMASTER:
{
int mm = getint(p), mn;
loopv(players) players[i]->privilege = PRIV_NONE;
while((mn = getint(p))>=0 && !p.overread())
{
fpsent *m = mn==player1->clientnum ? player1 : newclient(mn);
int priv = getint(p);
if(m) m->privilege = priv;
}
if(mm != mastermode)
{
mastermode = mm;
conoutf("mastermode is %s (%d)",
server::mastermodename(mastermode), mastermode);
}
break;
}
case N_MASTERMODE:
{
mastermode = getint(p);
conoutf("mastermode is %s (%d)",
server::mastermodename(mastermode), mastermode);
break;
}
case N_EDITMODE:
{
int val = getint(p);
if(!d) break;
if(val)
{
d->editstate = d->state;
d->state = CS_EDITING;
}
else
{
d->state = d->editstate;
if(d->state==CS_DEAD) deathstate(d, true);
}
break;
}
case N_SPECTATOR:
{
int sn = getint(p), val = getint(p);
fpsent *s;
if(sn==player1->clientnum)
{
s = player1;
if(val && remote && !player1->privilege) senditemstoserver =
false;
}
else s = newclient(sn);
if(!s) return;
if(val)
{
if(s==player1)
{
if(editmode) toggleedit();
if(s->state==CS_DEAD) showscores(false);
disablezoom();
}
s->state = CS_SPECTATOR;
}
else if(s->state==CS_SPECTATOR)
{
if(s==player1) stopfollowing();
deathstate(s, true);
}
break;
}
case N_SETTEAM:
{
int wn = getint(p);
getstring(text, p);
int reason = getint(p);
fpsent *w = getclient(wn);
if(!w) return;
filtertext(w->team, text, false, MAXTEAMLEN);
static const char *fmt[2] = { "%s switched to team %s", "%s forced
to team %s"};
if(reason >= 0 && size_t(reason) < sizeof(fmt)/sizeof(fmt[0]))
conoutf(fmt[reason], colorname(w), w->team);
break;
}
#define PARSEMESSAGES 1
#include "capture.h"
#include "ctf.h"
#include "collect.h"
#undef PARSEMESSAGES
case N_ANNOUNCE:
{
int t = getint(p);
if (t==I_QUAD) { playsound(S_V_QUAD10, NULL, NULL, 0, 0, 0, -
1, 0, 3000); conoutf(CON_GAMEINFO, "\f2quad damage will spawn in 10 seconds!"); }
else if(t==I_BOOST) { playsound(S_V_BOOST10, NULL, NULL, 0, 0, 0, -
1, 0, 3000); conoutf(CON_GAMEINFO, "\f2+10 health will spawn in 10 seconds!"); }
break;
}
case N_NEWMAP:
{
int size = getint(p);
if(size>=0) emptymap(size, true, NULL);
else enlargemap(true);
if(d && d!=player1)
{
int newsize = 0;
while(1<<newsize < getworldsize()) newsize++;
conoutf(size>=0 ? "%s started a new map of size %d" : "%s
enlarged the map to size %d", colorname(d), newsize);
}
break;
}
case N_REQAUTH:
{
getstring(text, p);
if(autoauth && text[0] && tryauth(text)) conoutf("server requested
authkey \"%s\"", text);
break;
}
case N_AUTHCHAL:
{
getstring(text, p);
authkey *a = findauthkey(text);
uint id = (uint)getint(p);
getstring(text, p);
if(a && a->lastauth && lastmillis - a->lastauth < 60*1000)
{
vector<char> buf;
answerchallenge(a->key, text, buf);
//conoutf(CON_DEBUG, "answering %u, challenge %s with %s", id,
text, buf.getbuf());
addmsg(N_AUTHANS, "rsis", a->desc, id, buf.getbuf());
}
break;
}
case N_INITAI:
{
int bn = getint(p), on = getint(p), at = getint(p), sk =
clamp(getint(p), 1, 101), pm = getint(p);
string name, team;
getstring(text, p);
filtertext(name, text, false, MAXNAMELEN);
getstring(text, p);
filtertext(team, text, false, MAXTEAMLEN);
fpsent *b = newclient(bn);
if(!b) break;
ai::init(b, at, on, sk, bn, pm, name, team);
break;
}
case N_SERVCMD:
getstring(text, p);
break;
default:
neterr("type", cn < 0);
return;
}
}
case N_SENDMAP:
{
if(!m_edit) return;
string oldname;
copystring(oldname, getclientmap());
defformatstring(mname)("getmap_%d", lastmillis);
defformatstring(fname)("packages/base/%s.ogz", mname);
stream *map = openrawfile(path(fname), "wb");
if(!map) return;
conoutf("received map");
ucharbuf b = p.subbuf(p.remaining());
map->write(b.buf, b.maxlen);
delete map;
if(load_world(mname, oldname[0] ? oldname : NULL))
entities::spawnitems(true);
remove(findfile(fname, "rb"));
break;
}
}
}
case 1:
parsemessages(-1, NULL, p);
break;
case 2:
receivefile(p);
break;
}
}
void getmap()
{
if(!m_edit) { conoutf(CON_ERROR, "\"getmap\" only works in coop edit
mode"); return; }
conoutf("getting map...");
addmsg(N_GETMAP, "r");
}
COMMAND(getmap, "");
void stopdemo()
{
if(remote)
{
if(player1->privilege<PRIV_MASTER) return;
addmsg(N_STOPDEMO, "r");
}
else server::stopdemo();
}
COMMAND(stopdemo, "");
void getdemo(int i)
{
if(i<=0) conoutf("getting demo...");
else conoutf("getting demo %d...", i);
addmsg(N_GETDEMO, "ri", i);
}
ICOMMAND(getdemo, "i", (int *val), getdemo(*val));
void listdemos()
{
conoutf("listing demos...");
addmsg(N_LISTDEMOS, "r");
}
COMMAND(listdemos, "");
void sendmap()
{
if(!m_edit || (player1->state==CS_SPECTATOR && remote && !player1-
>privilege)) { conoutf(CON_ERROR, "\"sendmap\" only works in coop edit mode");
return; }
conoutf("sending map...");
defformatstring(mname)("sendmap_%d", lastmillis);
save_world(mname, true);
defformatstring(fname)("packages/base/%s.ogz", mname);
stream *map = openrawfile(path(fname), "rb");
if(map)
{
stream::offset len = map->size();
if(len > 4*1024*1024) conoutf(CON_ERROR, "map is too large");
else if(len <= 0) conoutf(CON_ERROR, "could not read map");
else
{
sendfile(-1, 2, map);
if(needclipboard >= 0) needclipboard++;
}
delete map;
}
else conoutf(CON_ERROR, "could not read map");
remove(findfile(fname, "rb"));
}
COMMAND(sendmap, "");
void gotosel()
{
if(player1->state!=CS_EDITING) return;
player1->o = getselpos();
vec dir;
vecfromyawpitch(player1->yaw, player1->pitch, 1, 0, dir);
player1->o.add(dir.mul(-32));
player1->resetinterp();
}
COMMAND(gotosel, "");
}