adding custom kill messages support

git-svn-id: svn://svn.code.sf.net/p/actiongame/code/trunk/ac@6215 e016b1c5-ed68-44aa-a2f7-31cac88cffde
This commit is contained in:
Lucas GAUTHERON
2011-04-06 12:21:18 +00:00
parent 7a8bbd462c
commit aee1d4f1f2
9 changed files with 212 additions and 91 deletions
+37 -1
View File
@@ -695,6 +695,41 @@ void dodamage(int damage, playerent *pl, playerent *actor, int gun, bool gib, bo
else audiomgr.playsound(S_PAIN1+rnd(5), pl);
}
void setkillmessage(int gun, bool gib, const char *message)
{
if(gun < 0 || gun >= NUMGUNS)
{
conoutf("invalid gun specified");
return;
}
if(strlen(message)==0)
{
conoutf("invalid message");
return;
}
if(strlen(message)>MAXKILLMSGLEN)
{
conoutf("message is too long (max len is %i)", MAXKILLMSGLEN);
return;
}
if(gib) formatstring(gibmessages[gun])("%s", message);
else formatstring(fragmessages[gun])("%s", message);
}
void fragmessage(const char *gun, const char *message)
{
setkillmessage(atoi(gun), false, message);
}
void gibmessage(const char *gun, const char *message)
{
setkillmessage(atoi(gun), true, message);
}
COMMAND(fragmessage, ARG_2STR);
COMMAND(gibmessage, ARG_2STR);
void dokill(playerent *pl, playerent *act, bool gib, int gun)
{
if(pl->state!=CS_ALIVE || intermission) return;
@@ -702,7 +737,8 @@ void dokill(playerent *pl, playerent *act, bool gib, int gun)
string pname, aname, death;
copystring(pname, pl==player1 ? "you" : colorname(pl));
copystring(aname, act==player1 ? "you" : colorname(act));
copystring(death, gib ? gib_message(gun) : "fragged");
copystring(death, killmessage(gun, gib));
copystring(death, killmessage(gun, gib));
void (*outf)(const char *s, ...) = (pl == player1 || act == player1) ? hudoutf : conoutf;
if(pl==act)
+7 -1
View File
@@ -614,6 +614,12 @@ public:
enum {MD_FRAGS = 0, MD_DEATHS, END_MDS};
struct medalsst {bool assigned; int cn; int item;};
#define MAXKILLMSGLEN 16
extern char fragmessages[NUMGUNS][MAXKILLMSGLEN];
extern char gibmessages[NUMGUNS][MAXKILLMSGLEN];
extern inline char *killmessage(int gun, bool gib);
// deprecated ?!
inline const char * gib_message(int gun)
{
switch (gun)
@@ -624,4 +630,4 @@ inline const char * gib_message(int gun)
case GUN_GRENADE:
default: return "gibbed";
}
}
}
+4 -3
View File
@@ -851,7 +851,7 @@ struct serverconfigfile
struct servercommandline
{
int uprate, serverport, syslogfacility, filethres, syslogthres, maxdemos, maxclients, kickthreshold, banthreshold, verbose, incoming_limit, afk_limit, ban_time, demotimelocal;
const char *ip, *master, *logident, *serverpassword, *adminpasswd, *demopath, *maprot, *pwdfile, *blfile, *nbfile, *infopath, *motdpath, *forbidden, *demofilenameformat, *demotimestampformat;
const char *ip, *master, *logident, *serverpassword, *adminpasswd, *demopath, *maprot, *pwdfile, *blfile, *nbfile, *infopath, *motdpath, *forbidden, *killmessages, *demofilenameformat, *demotimestampformat;
bool logtimestamp, demo_interm;
string motd, servdesc_full, servdesc_pre, servdesc_suf, voteperm, mapperm;
int clfilenesting;
@@ -861,7 +861,7 @@ struct servercommandline
maxclients(DEFAULTCLIENTS), kickthreshold(-5), banthreshold(-6), verbose(0), incoming_limit(10), afk_limit(45000), ban_time(20*60*1000), demotimelocal(0),
ip(""), master(NULL), logident(""), serverpassword(""), adminpasswd(""), demopath(""),
maprot("config/maprot.cfg"), pwdfile("config/serverpwd.cfg"), blfile("config/serverblacklist.cfg"), nbfile("config/nicknameblacklist.cfg"),
infopath("config/serverinfo"), motdpath("config/motd"), forbidden("config/forbidden.cfg"),
infopath("config/serverinfo"), motdpath("config/motd"), forbidden("config/forbidden.cfg"), killmessages("config/killmessages.cfg"),
logtimestamp(false), demo_interm(false),
clfilenesting(0)
{
@@ -878,7 +878,7 @@ struct servercommandline
int ai = atoi(a);
// client: dtwhzbsave
switch(arg[1])
{ // todo: gjlqEGHJQUYZ
{ // todo: gjlqGHJQUYZ
case '-':
if(!strncmp(arg, "--demofilenameformat=", 21))
{
@@ -942,6 +942,7 @@ struct servercommandline
case 'X': pwdfile = a; break;
case 'B': blfile = a; break;
case 'K': nbfile = a; break;
case 'E': killmessages = a; break;
case 'I': infopath = a; break;
case 'o': filterrichtext(motd, a); break;
case 'O': motdpath = a; break;
+4 -1
View File
@@ -19,6 +19,7 @@ servernickblacklist nickblacklist;
serverforbiddenlist forbiddenlist;
serverpasswords passwords;
serverinfofile infofiles;
killmessagesfile killmessages;
// server state
bool isdedicated = false;
@@ -1461,7 +1462,7 @@ void serverdamage(client *target, client *actor, int damage, int gun, bool gib,
target->position.setsize(0);
ts.state = CS_DEAD;
ts.lastdeath = gamemillis;
if(!suic) logline(ACLOG_INFO, "[%s] %s %s%s %s", actor->hostname, actor->name, gib ? gib_message(gun) : "fragged", tk ? " their teammate" : "", target->name);
if(!suic) logline(ACLOG_INFO, "[%s] %s %s%s %s", actor->hostname, actor->name, killmessage(gun), tk ? " their teammate" : "", target->name);
if(m_flags && targethasflag >= 0)
{
if(m_ctf)
@@ -3560,6 +3561,7 @@ void rereadcfgs(void)
nickblacklist.read();
forbiddenlist.read();
passwords.read();
killmessages.read();
}
void loggamestatus(const char *reason)
@@ -4069,6 +4071,7 @@ void initserver(bool dedicated, int argc, char **argv)
ipblacklist.init(scl.blfile);
nickblacklist.init(scl.nbfile);
forbiddenlist.init(scl.forbidden);
killmessages.init(scl.killmessages);
infofiles.init(scl.infopath, scl.motdpath);
infofiles.getinfo("en"); // cache 'en' serverinfo
logline(ACLOG_VERBOSE, "holding up to %d recorded demos in memory", scl.maxdemos);
+10
View File
@@ -495,3 +495,13 @@ guninfo guns[NUMGUNS] =
const char *teamnames[TEAM_NUM+1] = {"CLA", "RVSF", "CLA-SPECT", "RVSF-SPECT", "SPECTATOR", "void"};
const char *teamnames_s[TEAM_NUM+1] = {"CLA", "RVSF", "CSPC", "RSPC", "SPEC", "void"};
// for both client and server
// default messages are hardcoded ! (in case there's a problem with cfgs)
char fragmessages[NUMGUNS][MAXKILLMSGLEN] = { "", "busted", "shredded", "peppered", "sprayed", "punctured", "picked off", "busted", "", "busted" };
char gibmessages[NUMGUNS][MAXKILLMSGLEN] = { "slashed", "", "", "splattered", "", "headshot", "", "", "gibbed", "" };
inline char *killmessage(int gun, bool gib = false)
{
if(gib) return gibmessages[gun];
else return fragmessages[gun];
}
+82
View File
@@ -887,3 +887,85 @@ struct serverinfofile
return getinfocache(motdbase, "en");
}
};
struct killmessagesfile : serverconfigfile
{
void init(const char *name) { serverconfigfile::init(name); }
void read()
{
if(getfilesize(filename) == filelen) return;
if(!load()) return;
char *l, *s, *p = buf;
const char *sep = " \"";
int line = 0;
logline(ACLOG_VERBOSE,"reading kill messages file '%s'", filename);
while(p < buf + filelen)
{
l = p; p += strlen(p) + 1;
l = strtok(l, sep);
char *message = "";
if(l)
{
s = strtok(NULL, sep);
if(s && (!strcmp(l, "fragmessage") || !strcmp(l, "gibmessage")))
{
int errors = 0;
int gun = atoi(s);
s += strlen(s) + 1;
while(s[0] == ' ') s++;
int hasquotes = strspn(s, "\"");
s += hasquotes;
message = s;
// TODO : what's following is too much complicated for nothing.
// it has to remove ending char (space, or quote if there was a first quote)
char endingchar = ' ';
char *end;
if(hasquotes) endingchar = '"';
end = strchr(message, endingchar);
if(end) message[end-message] = '\0';
else
{
if(hasquotes)
{
logline(ACLOG_INFO, " error in line %i, ending quote missing (%s)", line, message);
errors++;
}
}
if(gun < 0 || gun >= NUMGUNS)
{
logline(ACLOG_INFO, " error in line %i, invalid gun : %i", line, gun);
errors++;
}
if(strlen(message)>MAXKILLMSGLEN)
{
logline(ACLOG_INFO, " error in line %i, too long message : string length is %i, max allowed i %i", line, strlen(message), MAXKILLMSGLEN);
errors++;
}
if(!errors)
{
if(!strcmp(l, "fragmessage"))
{
formatstring(fragmessages[gun])("%s", message);
logline(ACLOG_VERBOSE, " added msg '%s' for frags with weapon %i ", message, gun);
}
else
{
formatstring(gibmessages[gun])("%s", message);
logline(ACLOG_VERBOSE, " added msg '%s' for gibs with weapon %i ", message, gun);
}
}
s = NULL;
line++;
}
}
}
}
};