diff --git a/source/src/audiomanager.cpp b/source/src/audiomanager.cpp index 0662356b..72d1d031 100644 --- a/source/src/audiomanager.cpp +++ b/source/src/audiomanager.cpp @@ -39,13 +39,13 @@ void audiomanager::initsound() if(devices) { string d; - s_strcpy(d, "Audio devices: "); + copystring(d, "Audio devices: "); // null separated device string for(const ALchar *c = devices; c[strlen(c)+1]; c += strlen(c)+1) { - if(c!=devices) s_strcat(d, ", "); - s_strcat(d, c); + if(c!=devices) concatstring(d, ", "); + concatstring(d, c); } conoutf("%s", d); } @@ -373,7 +373,7 @@ void voicecom(char *sound, char *text) static int last = 0; if(!last || lastmillis-last > 2000) { - s_sprintfd(soundpath)("voicecom/%s", sound); + defformatstring(soundpath)("voicecom/%s", sound); int s = audiomgr.findsound(soundpath, 0, gamesounds); if(s < 0 || s < S_AFFIRMATIVE || s > S_NICESHOT) return; audiomgr.playsound(s, SP_HIGH); @@ -385,7 +385,7 @@ void voicecom(char *sound, char *text) else // team { addmsg(SV_VOICECOMTEAM, "ri", s); - s_sprintfd(teamtext)("%c%s", '%', text); + defformatstring(teamtext)("%c%s", '%', text); toserver(teamtext); } last = lastmillis; diff --git a/source/src/bot/botmanager.cpp b/source/src/bot/botmanager.cpp index 5b607c64..1b83f931 100644 --- a/source/src/bot/botmanager.cpp +++ b/source/src/bot/botmanager.cpp @@ -164,7 +164,7 @@ void CBotManager::LoadBotNamesFile() { conoutf("Warning: bot name \"%s\" has to many characters(16 is max)", szNameBuffer); } - s_strncpy(m_szBotNames[m_sBotNameCount], szNameBuffer, 16); + copystring(m_szBotNames[m_sBotNameCount], szNameBuffer, 16); m_sBotNameCount++; } } @@ -256,7 +256,7 @@ void CBotManager::LoadBotTeamsFile() if (szNameBuffer[0] != 0) { - s_strncpy(m_szBotTeams[m_sBotTeamCount], szNameBuffer, 5); + copystring(m_szBotTeams[m_sBotTeamCount], szNameBuffer, 5); m_sBotTeamCount++; } } @@ -919,9 +919,9 @@ botent *CBotManager::CreateBot(const char *team, const char *skill, const char * m->pBot->m_bSendC2SInit = false; if (name && *name) - s_strncpy(m->name, name, 16); + copystring(m->name, name, 16); else - s_strncpy(m->name, BotManager.GetBotName(), 16); + copystring(m->name, BotManager.GetBotName(), 16); const char *tempteam = team && *team && strcmp(team, "random") ? team : BotManager.GetBotTeam(); m->team = TEAM_SPECT; diff --git a/source/src/client.cpp b/source/src/client.cpp index 0195b958..abee6a4c 100644 --- a/source/src/client.cpp +++ b/source/src/client.cpp @@ -71,7 +71,7 @@ void connectserv_(const char *servername, const char *serverport = NULL, const c } connectrole = role; - s_strcpy(clientpassword, password ? password : ""); + copystring(clientpassword, password ? password : ""); ENetAddress address; int p = 0; diff --git a/source/src/clientgame.cpp b/source/src/clientgame.cpp index 193b611a..12bce3c7 100644 --- a/source/src/clientgame.cpp +++ b/source/src/clientgame.cpp @@ -58,23 +58,23 @@ char *colorname(playerent *d, char *name, const char *prefix) static string cname[4]; static int num = 0; num = (num + 1) % 4; - s_sprintf(cname[num])("%s%s \fs\f6(%d)\fr", prefix, name, d->clientnum); + formatstring(cname[num])("%s%s \fs\f6(%d)\fr", prefix, name, d->clientnum); return cname[num]; } char *colorping(int ping) { static string cping; - if(multiplayer(false)) s_sprintf(cping)("\fs\f%d%d\fr", ping <= 500 ? 0 : ping <= 1000 ? 2 : 3, ping); - else s_sprintf(cping)("%d", ping); + if(multiplayer(false)) formatstring(cping)("\fs\f%d%d\fr", ping <= 500 ? 0 : ping <= 1000 ? 2 : 3, ping); + else formatstring(cping)("%d", ping); return cping; } char *colorpj(int pj) { static string cpj; - if(multiplayer(false)) s_sprintf(cpj)("\fs\f%d%d\fr", pj <= 90 ? 0 : pj <= 170 ? 2 : 3, pj); - else s_sprintf(cpj)("%d", pj); + if(multiplayer(false)) formatstring(cpj)("\fs\f%d%d\fr", pj <= 90 ? 0 : pj <= 170 ? 2 : 3, pj); + else formatstring(cpj)("%d", pj); return cpj; } @@ -84,7 +84,7 @@ const char *highlight(const char *text) const char *marker = getalias("HIGHLIGHT"), *sep = " ,;:!\"'"; if(!marker || !strstr(text, player1->name)) return text; filterrichtext(result, marker); - s_sprintfd(subst)("\fs%s%s\fr", result, player1->name); + defformatstring(subst)("\fs%s%s\fr", result, player1->name); char *temp = newstring(text); char *s = strtok(temp, sep), *l = temp, *c, *r = result; result[0] = '\0'; @@ -117,7 +117,7 @@ void listignored() { string pl; pl[0] = '\0'; - loopv(players) if(players[i] && players[i]->ignored) s_strcatf(pl, ", %s", colorname(players[i])); + loopv(players) if(players[i] && players[i]->ignored) concatformatstring(pl, ", %s", colorname(players[i])); if(*pl) conoutf(_("ignored players: %s"), pl + 2); else conoutf(_("no players ignored.")); } @@ -138,7 +138,7 @@ void listmuted() { string pl; pl[0] = '\0'; - loopv(players) if(players[i] && players[i]->muted) s_strcatf(pl, ", %s", colorname(players[i])); + loopv(players) if(players[i] && players[i]->muted) concatformatstring(pl, ", %s", colorname(players[i])); if(*pl) conoutf(_("muted players: %s"), pl + 2); else conoutf(_("no players muted.")); } @@ -162,7 +162,7 @@ void newname(const char *name) { c2sinit = false; filtertext(player1->name, name, 0, MAXNAMELEN); - if(!player1->name[0]) s_strcpy(player1->name, "unarmed"); + if(!player1->name[0]) copystring(player1->name, "unarmed"); updateclientname(player1); } else conoutf(_("your name is: %s"), player1->name); @@ -388,17 +388,17 @@ bool showhudtimer(int maxsecs, int startmillis, const char *msg, bool flash) tickstart = startmillis; maxticks = 5*maxsecs; curticks = -1; - s_strcpy(str, "\f3"); + copystring(str, "\f3"); } if(curticks >= maxticks) return false; nextticks = min(nextticks, maxticks); while(curticks < nextticks) { - if(++curticks%5) s_strcat(str, "."); + if(++curticks%5) concatstring(str, "."); else { - s_sprintfd(sec)("%d", maxsecs - (curticks/5)); - s_strcat(str, sec); + defformatstring(sec)("%d", maxsecs - (curticks/5)); + concatstring(str, sec); } } if(nextticks < maxticks) hudeditf(HUDMSG_TIMER|HUDMSG_OVERWRITE, flash ? str : str+2); @@ -642,9 +642,9 @@ void dokill(playerent *pl, playerent *act, bool gib) if(pl->state!=CS_ALIVE || intermission) return; string pname, aname, death; - s_strcpy(pname, pl==player1 ? "you" : colorname(pl)); - s_strcpy(aname, act==player1 ? "you" : colorname(act)); - s_strcpy(death, gib ? "gibbed" : "fragged"); + copystring(pname, pl==player1 ? "you" : colorname(pl)); + copystring(aname, act==player1 ? "you" : colorname(act)); + copystring(death, gib ? "gibbed" : "fragged"); void (*outf)(const char *s, ...) = (pl == player1 || act == player1) ? hudoutf : conoutf; if(pl==act) @@ -813,7 +813,7 @@ int suicided = -1; void startmap(const char *name, bool reset) // called just after a map load { - s_strcpy(clientmap, name); + copystring(clientmap, name); sendmapidenttoserver = true; // Added by Rick if(m_botmode) BotManager.BeginMap(name); @@ -964,8 +964,8 @@ char *votestring(int type, char *arg1, char *arg2) { const char *msgs[] = { "kick player %s", "ban player %s", "remove all bans", "set mastermode to %s", "%s autoteam", "force player %s to the enemy team", "give admin to player %s", "load map %s in mode %s", "%s demo recording for the next match", "stop demo recording", "clear all demos", "set server description to '%s'", "shuffle teams"}; const char *msg = msgs[type]; - char *out = newstring(_MAXDEFSTR); - out[_MAXDEFSTR] = '\0'; + char *out = newstring(MAXSTRLEN); + out[MAXSTRLEN] = '\0'; switch(type) { case SA_KICK: @@ -976,24 +976,24 @@ char *votestring(int type, char *arg1, char *arg2) int cn = atoi(arg1); playerent *p = (cn == getclientnum() ? player1 : getclient(cn)); if(!p) break; - s_sprintf(out)(msg, colorname(p)); + formatstring(out)(msg, colorname(p)); break; } case SA_MASTERMODE: - s_sprintf(out)(msg, mmfullname(atoi(arg1))); + formatstring(out)(msg, mmfullname(atoi(arg1))); break; case SA_AUTOTEAM: case SA_RECORDDEMO: - s_sprintf(out)(msg, atoi(arg1) == 0 ? "disable" : "enable"); + formatstring(out)(msg, atoi(arg1) == 0 ? "disable" : "enable"); break; case SA_MAP: - s_sprintf(out)(msg, arg1, modestr(atoi(arg2), modeacronyms > 0)); + formatstring(out)(msg, arg1, modestr(atoi(arg2), modeacronyms > 0)); break; case SA_SERVERDESC: - s_sprintf(out)(msg, arg1); + formatstring(out)(msg, arg1); break; default: - s_sprintf(out)(msg, arg1, arg2); + formatstring(out)(msg, arg1, arg2); break; } return out; @@ -1007,7 +1007,7 @@ votedisplayinfo *newvotedisplayinfo(playerent *owner, int type, char *arg1, char v->type = type; v->millis = totalmillis + (30+10)*1000; char *votedesc = votestring(type, arg1, arg2); - s_strcpy(v->desc, votedesc); + copystring(v->desc, votedesc); DELETEA(votedesc); return v; } @@ -1158,8 +1158,8 @@ void refreshsopmenu(void *menu, bool init) loopv(players) if(players[i]) { mline &m = mlines.add(); - s_strcpy(m.name, colorname(players[i])); - s_sprintf(m.cmd)("%s %d", menu==kickmenu ? "kick" : (menu==banmenu ? "ban" : (menu==forceteammenu ? "forceteam" : "giveadmin")), i); + copystring(m.name, colorname(players[i])); + formatstring(m.cmd)("%s %d", menu==kickmenu ? "kick" : (menu==banmenu ? "ban" : (menu==forceteammenu ? "forceteam" : "giveadmin")), i); menumanual(menu, m.name, m.cmd); } } diff --git a/source/src/clients2c.cpp b/source/src/clients2c.cpp index 993a8e3a..71eb16b6 100644 --- a/source/src/clients2c.cpp +++ b/source/src/clients2c.cpp @@ -50,7 +50,7 @@ bool changemapserv(char *name, int mode, int download, int revision) // f if(!loaded || getnewrev) getmap(); // no need to ask else { - s_sprintfd(msg)("map '%s' revision: local %d, provided by server %d", name, hdr.maprevision, revision); + defformatstring(msg)("map '%s' revision: local %d, provided by server %d", name, hdr.maprevision, revision); alias("__getmaprevisions", msg); showmenu("getmap"); } @@ -350,7 +350,7 @@ void parsemessages(int cn, playerent *d, ucharbuf &p) d = newclient(cn); getstring(text, p); filtertext(text, text, 0, MAXNAMELEN); - if(!text[0]) s_strcpy(text, "unarmed"); + if(!text[0]) copystring(text, "unarmed"); if(d->name[0]) // already connected { if(strcmp(d->name, text)) @@ -361,7 +361,7 @@ void parsemessages(int cn, playerent *d, ucharbuf &p) c2sinit = false; // send new players my info again conoutf(_("connected: %s"), colorname(d, text)); } - s_strncpy(d->name, text, MAXNAMELEN+1); + copystring(d->name, text, MAXNAMELEN+1); d->setskin(TEAM_CLA, getint(p)); d->setskin(TEAM_RVSF, getint(p)); if(m_flags) loopi(2) @@ -994,7 +994,7 @@ void receivefile(uchar *data, int len) case SV_SENDDEMO: { getstring(text, p); - s_sprintfd(fname)("demos/%s.dmo", text); + defformatstring(fname)("demos/%s.dmo", text); data += strlen(text); int demosize = getint(p); if(p.remaining() < demosize) diff --git a/source/src/command.cpp b/source/src/command.cpp index 9053b0f6..ec91d21b 100644 --- a/source/src/command.cpp +++ b/source/src/command.cpp @@ -434,7 +434,7 @@ char *executeret(const char *p) // all evaluation hap { if(i > argids.length()) { - s_sprintfd(argname)("arg%d", i); + defformatstring(argname)("arg%d", i); argids.add(newident(argname, IEXC_CORE)); } pushident(*argids[i-1], w[i]); // set any arguments as (global) arg values so functions can access them @@ -495,7 +495,7 @@ bool nickcomplete(char *s) if(p && !strncasecmp(p->name, cp, completesize)) { *cp = '\0'; - s_strcat(s, p->name); + concatstring(s, p->name); completeplayer = p; return true; } @@ -600,9 +600,9 @@ void commandcomplete(char *s) if(*s!='/') { string t; - s_strcpy(t, s); - s_strcpy(s, "/"); - s_strcat(s, t); + copystring(t, s); + copystring(s, "/"); + concatstring(s, t); } if(!s[1]) return; char *cp = s; @@ -621,7 +621,7 @@ void commandcomplete(char *s) if(end && end <= cp) { string command; - s_strncpy(command, s+1, min(size_t(end-s), sizeof(command))); + copystring(command, s+1, min(size_t(end-s), sizeof(command))); completeval **hascomplete = completions.access(command); if(hascomplete) cdata = *hascomplete; } @@ -638,7 +638,7 @@ void commandcomplete(char *s) if(!strncasecmp(id.name, cp+1, completesize) && idx++==completeidx) { cp[1] = '\0'; - s_strcat(s, id.name); + concatstring(s, id.name); } ); completeidx++; @@ -654,7 +654,7 @@ void commandcomplete(char *s) if(!strncasecmp(cdata->list[j], cp + 1, completesize)) { cp[1] = '\0'; - s_strcat(s, cdata->list[j]); + concatstring(s, cdata->list[j]); completeidx = j; break; } @@ -676,7 +676,7 @@ void complete(char *s) bool execfile(const char *cfgfile) { string s; - s_strcpy(s, cfgfile); + copystring(s, cfgfile); char *buf = loadfile(path(s), NULL); if(!buf) return false; execute(buf); @@ -1038,18 +1038,18 @@ void currentserver(int i) case 1: // IP { uchar *ip = (uchar *)&curpeer->address.host; - s_sprintf(r)("%d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3]); + formatstring(r)("%d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3]); break; } case 2: // HOST { char hn[1024]; - s_sprintf(r)("%s", (enet_address_get_host(&curpeer->address, hn, sizeof(hn))==0) ? hn : "unknown"); + formatstring(r)("%s", (enet_address_get_host(&curpeer->address, hn, sizeof(hn))==0) ? hn : "unknown"); break; } case 3: // PORT { - s_sprintf(r)("%d", curpeer->address.port); + formatstring(r)("%d", curpeer->address.port); break; } case 4: // STATE @@ -1068,13 +1068,13 @@ void currentserver(int i) "zombie" }; if(curpeer->state>=0 && curpeer->statestate]); + copystring(r, statenames[curpeer->state]); break; // 5 == Connected (compare ../enet/include/enet/enet.h +165) } default: // was HOST:PORT & IP - but as speed-up just IP & PORT { uchar *ip = (uchar *)&curpeer->address.host; - s_sprintf(r)("%d.%d.%d.%d %d", ip[0], ip[1], ip[2], ip[3], curpeer->address.port); + formatstring(r)("%d.%d.%d.%d %d", ip[0], ip[1], ip[2], ip[3], curpeer->address.port); break; } } diff --git a/source/src/console.cpp b/source/src/console.cpp index c0db1071..e76247b7 100644 --- a/source/src/console.cpp +++ b/source/src/console.cpp @@ -91,7 +91,7 @@ void renderconsole() { con.render(); } void clientlogf(const char *s, ...) { - s_sprintfdv(sp, s); + defvformatstring(sp, s, s); filtertext(sp, sp, 2); extern struct servercommandline scl; const char *ts = scl.logtimestamp ? timestring(true, "%b %d %H:%M:%S ") : ""; @@ -107,14 +107,14 @@ void clientlogf(const char *s, ...) void conoutf(const char *s, ...) { - s_sprintfdv(sf, s); + defvformatstring(sf, s, s); clientlogf("%s", sf); con.addline(sf); } int rendercommand(int x, int y, int w) { - s_sprintfd(s)("> %s", cmdline.buf); + defformatstring(s)("> %s", cmdline.buf); int width, height; text_bounds(s, width, height, w); y -= height - FONTH; @@ -209,7 +209,7 @@ void saycommand(char *init) // turns input to the comman SDL_EnableUNICODE(saycommandon = (init!=NULL)); setscope(false); if(!editmode) keyrepeat(saycommandon); - s_strcpy(cmdline.buf, init ? init : ""); + copystring(cmdline.buf, init ? init : ""); DELETEA(cmdaction); DELETEA(cmdprompt); cmdline.pos = -1; @@ -227,13 +227,13 @@ void mapmsg(char *s) string text; filterrichtext(text, s); filterservdesc(text, text); - s_strncpy(hdr.maptitle, text, 128); + copystring(hdr.maptitle, text, 128); } void getmapmsg(void) { string text; - s_strncpy(text, hdr.maptitle, 128); + copystring(text, hdr.maptitle, 128); result(text); } @@ -253,7 +253,7 @@ void pasteconsole(char *dst) if(!IsClipboardFormatAvailable(CF_TEXT)) return; if(!OpenClipboard(NULL)) return; char *cb = (char *)GlobalLock(GetClipboardData(CF_TEXT)); - s_strcat(dst, cb); + concatstring(dst, cb); GlobalUnlock(cb); CloseClipboard(); #elif defined(__APPLE__) @@ -269,15 +269,15 @@ void pasteconsole(char *dst) char *cb = XFetchBytes(wminfo.info.x11.display, &cbsize); if(!cb || !cbsize) return; int commandlen = strlen(dst); - for(char *cbline = cb, *cbend; commandlen + 1 < _MAXDEFSTR && cbline < &cb[cbsize]; cbline = cbend + 1) + for(char *cbline = cb, *cbend; commandlen + 1 < MAXSTRLEN && cbline < &cb[cbsize]; cbline = cbend + 1) { cbend = (char *)memchr(cbline, '\0', &cb[cbsize] - cbline); if(!cbend) cbend = &cb[cbsize]; - if(commandlen + cbend - cbline + 1 > _MAXDEFSTR) cbend = cbline + _MAXDEFSTR - commandlen - 1; + if(commandlen + cbend - cbline + 1 > MAXSTRLEN) cbend = cbline + MAXSTRLEN - commandlen - 1; memcpy(&dst[commandlen], cbline, cbend - cbline); commandlen += cbend - cbline; dst[commandlen] = '\n'; - if(commandlen + 1 < _MAXDEFSTR && cbend < &cb[cbsize]) ++commandlen; + if(commandlen + 1 < MAXSTRLEN && cbend < &cb[cbsize]) ++commandlen; dst[commandlen] = '\0'; } XFree(cb); @@ -298,7 +298,7 @@ struct hline void restore() { - s_strcpy(cmdline.buf, buf); + copystring(cmdline.buf, buf); if(cmdline.pos >= (int)strlen(cmdline.buf)) cmdline.pos = -1; DELETEA(cmdaction); DELETEA(cmdprompt); diff --git a/source/src/console.h b/source/src/console.h index f25acfb4..f238acd7 100644 --- a/source/src/console.h +++ b/source/src/console.h @@ -12,7 +12,7 @@ template struct consolebuffer LINE cl; cl.line = conlines.length()>maxlines ? conlines.pop().line : newstringbuf(""); // constrain the buffer size cl.millis = millis; // for how long to keep line on screen - s_strcpy(cl.line, sf); + copystring(cl.line, sf); return conlines.insert(0, cl); } diff --git a/source/src/docs.cpp b/source/src/docs.cpp index e090245e..fd63c391 100644 --- a/source/src/docs.cpp +++ b/source/src/docs.cpp @@ -246,7 +246,7 @@ void docfind(char *search) { const int matchchars = 200; string match; - s_strncpy(match, r-srch[rline] > matchchars/2 ? r-matchchars/2 : srch[rline], matchchars/2); + copystring(match, r-srch[rline] > matchchars/2 ? r-matchchars/2 : srch[rline], matchchars/2); conoutf("%-20s%s", i.name, match); } }); @@ -310,7 +310,7 @@ void docwriteref(int allidents, const char *ref, const char *schemalocation, con { ident *id = idents->access(inames[i]); if(!id || id->type != ID_COMMAND) continue; - fprintf(f, "\t\t\t\t\n", xmlstringenc(name, id->name, _MAXDEFSTR)); + fprintf(f, "\t\t\t\t\n", xmlstringenc(name, id->name, MAXSTRLEN)); fprintf(f, "\t\t\t\t\t%s\n", desc); if(id->narg != ARG_NONE && id->narg != ARG_DOWN && id->narg != ARG_IVAL && id->narg != ARG_FVAL && id->narg != ARG_SVAL) { @@ -333,7 +333,7 @@ void docwriteref(int allidents, const char *ref, const char *schemalocation, con { ident *id = idents->access(inames[i]); if(!id || (id->type != ID_VAR && id->type != ID_FVAR)) continue; - fprintf(f, "\t\t\t\t\n", xmlstringenc(name, id->name, _MAXDEFSTR)); + fprintf(f, "\t\t\t\t\n", xmlstringenc(name, id->name, MAXSTRLEN)); fprintf(f, "\t\t\t\t\tTODO\n"); switch(id->type) { @@ -352,7 +352,7 @@ void docwriteref(int allidents, const char *ref, const char *schemalocation, con { ident *id = idents->access(inames[i]); if(!id || id->type != ID_ALIAS) continue; - fprintf(f, "\t\t\t\t\n", xmlstringenc(name, id->name, _MAXDEFSTR)); + fprintf(f, "\t\t\t\t\n", xmlstringenc(name, id->name, MAXSTRLEN)); fprintf(f, "\t\t\t\t\t%s\n", desc); fprintf(f, "\t\t\t\t\n"); } @@ -421,7 +421,7 @@ void renderdoc(int x, int y, int doch) if(!*end || *end == ' ') { string cmd; - s_strncpy(cmd, c, clen-i+1); + copystring(cmd, c, clen-i+1); docident *ident = docidents.access(cmd); if(ident) { @@ -429,11 +429,11 @@ void renderdoc(int x, int y, int doch) char *label = newstringbuf(); // label doclines.add(label); - s_sprintf(label)("~%s", ident->name); + formatstring(label)("~%s", ident->name); loopvj(ident->arguments) { - s_strcat(label, " "); - s_strcat(label, ident->arguments[j].token); + concatstring(label, " "); + concatstring(label, ident->arguments[j].token); } doclines.add(NULL); @@ -454,7 +454,7 @@ void renderdoc(int x, int y, int doch) if(cmdline.pos >= args-c) { string a; - s_strncpy(a, args, cmdline.pos-(args-c)+1); + copystring(a, args, cmdline.pos-(args-c)+1); args = a; arg = numargs(args); } @@ -475,7 +475,7 @@ void renderdoc(int x, int y, int doch) { docargument *a = &ident->arguments[j]; if(!a) continue; - s_sprintf(doclines.add(newstringbuf()))("~\f%d%-8s%s %s%s%s", j == arg ? 4 : 5, a->token, a->desc, + formatstring(doclines.add(newstringbuf()))("~\f%d%-8s%s %s%s%s", j == arg ? 4 : 5, a->token, a->desc, a->values ? "(" : "", a->values ? a->values : "", a->values ? ")" : ""); } @@ -505,7 +505,7 @@ void renderdoc(int x, int y, int doch) loopvj(ident->keys) { dockey &k = ident->keys[j]; - s_sprintfd(line)("~%-10s %s", k.name ? k.name : k.alias, k.desc ? k.desc : ""); + defformatstring(line)("~%-10s %s", k.name ? k.name : k.alias, k.desc ? k.desc : ""); doclines.add(newstring(line)); } doclines.add(NULL); @@ -519,13 +519,13 @@ void renderdoc(int x, int y, int doch) { docref &r = ident->references[j]; char *ref = r.ident ? categories[0].refs : (r.url ? categories[1].refs : (r.article ? categories[2].refs : categories[3].refs)); - s_strcat(ref, r.name); - if(j < ident->references.length()-1) s_strcat(ref, ", "); + concatstring(ref, r.name); + if(j < ident->references.length()-1) concatstring(ref, ", "); } loopj(sizeof(categories)/sizeof(category)) { if(!strlen(categories[j].refs)) continue; - s_sprintf(doclines.add(newstringbuf()))("~%s: %s", categories[j].label, categories[j].refs); + formatstring(doclines.add(newstringbuf()))("~%s: %s", categories[j].label, categories[j].refs); } } @@ -604,7 +604,7 @@ void renderdocsection(void *menu, bool init) docident &id = *sections[i].idents[j]; msection &s = msections.add(); s.name = id.name; - s_sprintf(s.cmd)("saycommand [/%s ]", id.name); + formatstring(s.cmd)("saycommand [/%s ]", id.name); } msections.sort(msectionsort); menureset(menu); @@ -623,7 +623,7 @@ void renderdocmenu(void *menu, bool init) loopv(sections) { maction &a = actions.add(); - s_sprintf(a.cmd)("showmenu [%s]", sections[i].name); + formatstring(a.cmd)("showmenu [%s]", sections[i].name); menumanual(menu, sections[i].name, a.cmd); } } diff --git a/source/src/editing.cpp b/source/src/editing.cpp index 8712b47c..b047914a 100644 --- a/source/src/editing.cpp +++ b/source/src/editing.cpp @@ -65,7 +65,7 @@ char *editinfo() int e = closestent(); if(e<0) return NULL; entity &c = ents[e]; - s_sprintf(info)("closest entity = %s (%d, %d, %d, %d), selection = (%d, %d)", entnames[c.type], c.attr1, c.attr2, c.attr3, c.attr4, sel.xs, sel.ys); + formatstring(info)("closest entity = %s (%d, %d, %d, %d), selection = (%d, %d)", entnames[c.type], c.attr1, c.attr2, c.attr3, c.attr4, sel.xs, sel.ys); return info; } diff --git a/source/src/entities.cpp b/source/src/entities.cpp index 0d7917b9..8ccec5e6 100644 --- a/source/src/entities.cpp +++ b/source/src/entities.cpp @@ -99,7 +99,7 @@ void renderentities() { if(e.type==CTF_FLAG) { - s_sprintfd(path)("pickups/flags/%s", team_basestring(e.attr2)); + defformatstring(path)("pickups/flags/%s", team_basestring(e.attr2)); rendermodel(path, ANIM_FLAG|ANIM_LOOP, 0, 0, vec(e.x, e.y, (float)S(e.x, e.y)->floor), (float)((e.attr1+7)-(e.attr1+7)%15), 0, 120.0f); } else if((e.type == CLIP || e.type == PLCLIP) && !stenciling) renderclip(e); @@ -127,7 +127,7 @@ void renderentities() if(f.actor && f.actor != player1) { if(OUTBORD(f.actor->o.x, f.actor->o.y)) break; - s_sprintfd(path)("pickups/flags/small_%s%s", m_ktf ? "" : team_basestring(i), m_htf ? "_htf" : m_ktf ? "ktf" : ""); + defformatstring(path)("pickups/flags/small_%s%s", m_ktf ? "" : team_basestring(i), m_htf ? "_htf" : m_ktf ? "ktf" : ""); rendermodel(path, ANIM_FLAG|ANIM_START|ANIM_DYNALLOC, 0, 0, vec(f.actor->o).add(vec(0, 0, 0.3f+(sinf(lastmillis/100.0f)+1)/10)), lastmillis/2.5f, 0, 120.0f); } break; @@ -137,7 +137,7 @@ void renderentities() { if(OUTBORD(f.pos.x, f.pos.y)) break; entity &e = *f.flagent; - s_sprintfd(path)("pickups/flags/%s%s", m_ktf ? "" : team_basestring(i), m_htf ? "_htf" : m_ktf ? "ktf" : ""); + defformatstring(path)("pickups/flags/%s%s", m_ktf ? "" : team_basestring(i), m_htf ? "_htf" : m_ktf ? "ktf" : ""); if(f.flagent->spawned) rendermodel(path, ANIM_FLAG|ANIM_LOOP, 0, 0, vec(f.pos.x, f.pos.y, f.state==CTFF_INBASE ? (float)S(int(f.pos.x), int(f.pos.y))->floor : f.pos.z), (float)((e.attr1+7)-(e.attr1+7)%15), 0, 120.0f); break; } diff --git a/source/src/hudgun.h b/source/src/hudgun.h index af39c3d7..a8269d47 100644 --- a/source/src/hudgun.h +++ b/source/src/hudgun.h @@ -115,7 +115,7 @@ void preload_hudguns() { loopi(NUMGUNS) { - s_sprintfd(path)("weapons/%s", guns[i].modelname); + defformatstring(path)("weapons/%s", guns[i].modelname); loadmodel(path); } } diff --git a/source/src/log.cpp b/source/src/log.cpp index 7d467147..14e0f217 100644 --- a/source/src/log.cpp +++ b/source/src/log.cpp @@ -40,7 +40,7 @@ bool initlogging(const char *identity, int facility_, int consolethres, int file if(filethres >= 0) filethreshold = min(filethres, (int)ACLOG_NUM); if(syslogthres >= 0) syslogthreshold = min(syslogthres, (int)ACLOG_NUM); facility &= 7; - s_sprintf(ident)("AssaultCube[%s]", identity); + formatstring(ident)("AssaultCube[%s]", identity); if(syslogthreshold < ACLOG_NUM) { #ifdef AC_USE_SYSLOG @@ -49,18 +49,18 @@ bool initlogging(const char *identity, int facility_, int consolethres, int file if((logsock = enet_socket_create(ENET_SOCKET_TYPE_DATAGRAM)) == ENET_SOCKET_NULL || enet_address_set_host(&logdest, "localhost") < 0) syslogthreshold = ACLOG_NUM; #endif } - s_sprintf(filepath)("serverlog_%s_%s.txt", timestring(true), identity); + formatstring(filepath)("serverlog_%s_%s.txt", timestring(true), identity); if(fp) { fclose(fp); fp = NULL; } if(filethreshold < ACLOG_NUM) { fp = fopen(filepath, "w"); if(!fp) printf("failed to open \"%s\" for writing\n", filepath); } - s_sprintfd(msg)("logging started: console(%s), file(%s", levelname[consolethreshold], levelname[fp ? filethreshold : ACLOG_NUM]); - if(fp) s_strcatf(msg, ", \"%s\"", filepath); - s_strcatf(msg, "), syslog(%s", levelname[syslogthreshold]); - if(syslogthreshold < ACLOG_NUM) s_strcatf(msg, ", \"%s\", local%d", ident, facility); - s_strcatf(msg, "), timestamp(%s)", timestamp ? "ENABLED" : "DISABLED"); + defformatstring(msg)("logging started: console(%s), file(%s", levelname[consolethreshold], levelname[fp ? filethreshold : ACLOG_NUM]); + if(fp) concatformatstring(msg, ", \"%s\"", filepath); + concatformatstring(msg, "), syslog(%s", levelname[syslogthreshold]); + if(syslogthreshold < ACLOG_NUM) concatformatstring(msg, ", \"%s\", local%d", ident, facility); + concatformatstring(msg, "), timestamp(%s)", timestamp ? "ENABLED" : "DISABLED"); enabled = consolethreshold < ACLOG_NUM || fp || syslogthreshold < ACLOG_NUM; if(enabled) printf("%s\n", msg); return enabled; @@ -80,7 +80,7 @@ bool logline(int level, const char *msg, ...) { if(!enabled) return false; if(level < 0 || level >= ACLOG_NUM) return false; - s_sprintfdv(sf, msg); + defvformatstring(sf, msg, msg); filtertext(sf, sf, 2); const char *ts = timestamp ? timestring(true, "%b %d %H:%M:%S ") : "", *ld = levelprefix[level]; char *p, *l = sf; @@ -94,7 +94,7 @@ bool logline(int level, const char *msg, ...) syslog(levels[level], "%s", l); #else { - s_sprintfd(text)("<%d>%s: %s", (16 + facility) * 8 + levels[level], ident, l); // no TIMESTAMP, no hostname: syslog will add this + defformatstring(text)("<%d>%s: %s", (16 + facility) * 8 + levels[level], ident, l); // no TIMESTAMP, no hostname: syslog will add this ENetBuffer buf; buf.data = text; buf.dataLength = strlen(text); diff --git a/source/src/main.cpp b/source/src/main.cpp index aa06b76c..77b6e8ae 100644 --- a/source/src/main.cpp +++ b/source/src/main.cpp @@ -43,11 +43,11 @@ void fatal(const char *s, ...) // failure exit if(errors <= 2) { - s_sprintfdlv(msg,s,s); + defvformatstring(msg,s,s); if(errors <= 1) { - s_sprintfdlv(msg,s,s); - s_sprintfd(msgerr)("%s (%s)\n", msg, SDL_GetError()); + defvformatstring(msg,s,s); + defformatstring(msgerr)("%s (%s)\n", msg, SDL_GetError()); cleanup(msgerr); } else puts(msg); @@ -148,13 +148,13 @@ VARP(jpegquality, 10, 70, 100); const char *screenshotpath(const char *imagepath, const char *suffix) { static string buf; - if(imagepath && imagepath[0]) s_strcpy(buf, imagepath); + if(imagepath && imagepath[0]) copystring(buf, imagepath); else { if(getclientmap()[0]) - s_sprintf(buf)("screenshots/%s_%s_%s.%s", timestring(), behindpath(getclientmap()), modestr(gamemode, true), suffix); + formatstring(buf)("screenshots/%s_%s_%s.%s", timestring(), behindpath(getclientmap()), modestr(gamemode, true), suffix); else - s_sprintf(buf)("screenshots/%s.%s", timestring(), suffix); + formatstring(buf)("screenshots/%s.%s", timestring(), suffix); } path(buf); return buf; @@ -739,7 +739,7 @@ int main(int argc, char **argv) initlog("localconnect"); extern string clientmap; - s_strcpy(clientmap, "ac_complex"); + copystring(clientmap, "ac_complex"); localconnect(); if(initscript) execute(initscript); diff --git a/source/src/md2.h b/source/src/md2.h index af456fa7..035ed351 100644 --- a/source/src/md2.h +++ b/source/src/md2.h @@ -246,10 +246,10 @@ struct md2 : vertmodel mdl.model = this; mdl.index = 0; const char *pname = parentdir(loadname); - s_sprintfd(name1)("packages/models/%s/tris.md2", loadname); + defformatstring(name1)("packages/models/%s/tris.md2", loadname); if(!mdl.load(path(name1))) { - s_sprintf(name1)("packages/models/%s/tris.md2", pname); // try md2 in parent folder (vert sharing) + formatstring(name1)("packages/models/%s/tris.md2", pname); // try md2 in parent folder (vert sharing) if(!mdl.load(path(name1))) return false; } Texture *skin; @@ -257,11 +257,11 @@ struct md2 : vertmodel loopv(mdl.meshes) mdl.meshes[i]->skin = skin; if(skin==notexture) conoutf(_("could not load model skin for %s"), name1); loadingmd2 = this; - s_sprintfd(name2)("packages/models/%s/md2.cfg", loadname); + defformatstring(name2)("packages/models/%s/md2.cfg", loadname); persistidents = false; if(!execfile(name2)) { - s_sprintf(name2)("packages/models/%s/md2.cfg", pname); + formatstring(name2)("packages/models/%s/md2.cfg", pname); execfile(name2); } persistidents = true; diff --git a/source/src/md3.h b/source/src/md3.h index 179be4e9..8e648c27 100644 --- a/source/src/md3.h +++ b/source/src/md3.h @@ -209,10 +209,10 @@ struct md3 : vertmodel bool load() { if(loaded) return true; - s_sprintf(md3dir)("packages/models/%s", loadname); + formatstring(md3dir)("packages/models/%s", loadname); const char *pname = parentdir(loadname); - s_sprintfd(cfgname)("packages/models/%s/md3.cfg", loadname); + defformatstring(cfgname)("packages/models/%s/md3.cfg", loadname); loadingmd3 = this; persistidents = false; @@ -231,10 +231,10 @@ struct md3 : vertmodel parts.add(&mdl); mdl.model = this; mdl.index = 0; - s_sprintfd(name1)("packages/models/%s/tris.md3", loadname); + defformatstring(name1)("packages/models/%s/tris.md3", loadname); if(!mdl.load(path(name1))) { - s_sprintf(name1)("packages/models/%s/tris.md3", pname); // try md3 in parent folder (vert sharing) + formatstring(name1)("packages/models/%s/tris.md3", pname); // try md3 in parent folder (vert sharing) if(!mdl.load(path(name1))) return false; }; Texture *skin; @@ -253,7 +253,7 @@ struct md3 : vertmodel void md3load(char *model) { if(!loadingmd3) { conoutf("not loading an md3"); return; }; - s_sprintfd(filename)("%s/%s", md3dir, model); + defformatstring(filename)("%s/%s", md3dir, model); md3::md3part &mdl = *new md3::md3part; loadingmd3->parts.add(&mdl); mdl.model = loadingmd3; @@ -271,7 +271,7 @@ void md3skin(char *objname, char *skin) md3::mesh &m = *mdl.meshes[i]; if(!strcmp(objname, "*") || !strcmp(m.name, objname)) { - s_sprintfd(spath)("%s/%s", md3dir, skin); + defformatstring(spath)("%s/%s", md3dir, skin); m.skin = textureload(spath); } } diff --git a/source/src/menus.cpp b/source/src/menus.cpp index 15ad2707..1f82f170 100644 --- a/source/src/menus.cpp +++ b/source/src/menus.cpp @@ -213,7 +213,7 @@ struct mitemtextvar : mitemmanual virtual void init() { char *r = executeret(textexp); - s_strcpy(dtext, r ? r : ""); + copystring(dtext, r ? r : ""); if(r) delete[] r; } }; @@ -317,7 +317,7 @@ struct mitemtextinput : mitemtext mitemtextinput(gmenu *parent, char *text, char *value, char *action, char *hoveraction, color *bgcolor, int maxchars) : mitemtext(parent, text, action, hoveraction, bgcolor), defaultvalueexp(value), modified(false) { - s_strcpy(input.buf, value); + copystring(input.buf, value); input.max = maxchars>0 ? maxchars : 15; } @@ -339,17 +339,17 @@ struct mitemtextinput : mitemtext string showinput; int sc = 14; while(iboff > 0) { - s_strncpy(showinput, input.buf + iboff - 1, sc + 2); + copystring(showinput, input.buf + iboff - 1, sc + 2); if(text_width(showinput) > 15 * text_width("w")) break; iboff--; sc++; } while(iboff + sc < cibl) { - s_strncpy(showinput, input.buf + iboff, sc + 2); + copystring(showinput, input.buf + iboff, sc + 2); if(text_width(showinput) > 15 * text_width("w")) break; sc++; } - s_strncpy(showinput, input.buf + iboff, sc + 1); + copystring(showinput, input.buf + iboff, sc + 1); draw_text(showinput, x+w-tw, y, 255, 255, 255, 255, selection ? (input.pos>=0 ? (input.pos > sc ? sc : input.pos) : cibl) : -1); } @@ -383,7 +383,7 @@ struct mitemtextinput : mitemtext { const char *p = defaultvalueexp; char *r = executeret(p); - s_strcpy(input.buf, r ? r : ""); + copystring(input.buf, r ? r : ""); if(r) delete[] r; } }; @@ -467,7 +467,7 @@ struct mitemslider : mitem if(display) // extract display name from list { char *val = indexlist(display, value-min_); - s_strcpy(curval, val); + copystring(curval, val); delete[] val; } else itoa(curval, value); // display number only @@ -919,7 +919,7 @@ void rendermenumdl() int tex = 0; if(isplayermodel) { - s_sprintfd(skin)("packages/models/%s.jpg", m.mdl); + defformatstring(skin)("packages/models/%s.jpg", m.mdl); tex = -(int)textureload(skin)->id; } modelattach a[2]; @@ -961,7 +961,7 @@ VARP(browsefiledesc, 0, 1, 1); char *getfiledesc(const char *dir, const char *name, const char *ext) { if(!browsefiledesc || !dir || !name || !ext) return NULL; - s_sprintfd(fn)("%s/%s.%s", dir, name, ext); + defformatstring(fn)("%s/%s.%s", dir, name, ext); path(fn); string text; if(!strcmp(ext, "dmo")) @@ -979,7 +979,7 @@ char *getfiledesc(const char *dir, const char *name, const char *ext) if(hdr.protocol == PROTOCOL_VERSION) tag = ""; else if(hdr.protocol == -PROTOCOL_VERSION) tag = "(recorded on modded server) "; } - s_sprintf(text)("%s%s", tag, hdr.desc); + formatstring(text)("%s%s", tag, hdr.desc); text[DHDR_DESCCHARS - 1] = '\0'; return newstring(text); } @@ -991,7 +991,7 @@ char *getfiledesc(const char *dir, const char *name, const char *ext) if(gzread(f, &hdr, sizeof(header))!=sizeof(header) || (strncmp(hdr.head, "CUBE", 4) && strncmp(hdr.head, "ACMP",4))) { gzclose(f); return NULL; } gzclose(f); endianswap(&hdr.version, sizeof(int), 4); - s_sprintf(text)("%s%s", (hdr.version>MAPVERSION) ? "(incompatible file) " : "", hdr.maptitle); + formatstring(text)("%s%s", (hdr.version>MAPVERSION) ? "(incompatible file) " : "", hdr.maptitle); text[DHDR_DESCCHARS - 1] = '\0'; return newstring(text); } @@ -1011,16 +1011,16 @@ void gmenu::init() char *f = files[i]; if(!f || !f[0]) continue; char *d = getfiledesc(dirlist->dir, f, dirlist->ext); - s_sprintfd(jpgname)("%s/preview/%s.jpg", dirlist->dir, f); + defformatstring(jpgname)("%s/preview/%s.jpg", dirlist->dir, f); if(dirlist->image) { string fullname = ""; - if(dirlist->dir[0]) s_sprintf(fullname)("%s/%s", dirlist->dir, f); - else s_strcpy(fullname, f); + if(dirlist->dir[0]) formatstring(fullname)("%s/%s", dirlist->dir, f); + else copystring(fullname, f); if(dirlist->ext) { - s_strcat(fullname, "."); - s_strcat(fullname, dirlist->ext); + concatstring(fullname, "."); + concatstring(fullname, dirlist->ext); } items.add(new mitemimage(this, newstring(fullname), f, newstring(dirlist->action), NULL, NULL, d)); } @@ -1040,8 +1040,8 @@ void gmenu::render() if(!t) { static string buf; - if(hotkeys) s_sprintf(buf)("%s hotkeys", name); - else s_sprintf(buf)("[ %s menu ]", name); + if(hotkeys) formatstring(buf)("%s hotkeys", name); + else formatstring(buf)("[ %s menu ]", name); t = buf; } bool hasdesc = false; diff --git a/source/src/oggstream.cpp b/source/src/oggstream.cpp index 8bd5890e..71683674 100644 --- a/source/src/oggstream.cpp +++ b/source/src/oggstream.cpp @@ -100,7 +100,7 @@ bool oggstream::open(const char *f) loopi(sizeof(exts)/sizeof(exts[0])) { - s_sprintf(filepath)("packages/audio/songs/%s%s", f, exts[i]); + formatstring(filepath)("packages/audio/songs/%s%s", f, exts[i]); FILE *file = fopen(findfile(path(filepath), "rb"), "rb"); if(!file) continue; @@ -114,7 +114,7 @@ bool oggstream::open(const char *f) info = ov_info(&oggfile, -1); format = info->channels == 2 ? AL_FORMAT_STEREO16 : AL_FORMAT_MONO16; totalseconds = ov_time_total(&oggfile, -1); - s_strcpy(name, f); + copystring(name, f); return true; } diff --git a/source/src/openal.cpp b/source/src/openal.cpp index 5867544e..0ae99fb4 100644 --- a/source/src/openal.cpp +++ b/source/src/openal.cpp @@ -266,7 +266,7 @@ bool sbuffer::load() string filepath; loopi(sizeof(exts)/sizeof(exts[0])) { - s_sprintf(filepath)("packages/audio/sounds/%s%s", name, exts[i]); + formatstring(filepath)("packages/audio/sounds/%s%s", name, exts[i]); const char *file = findfile(path(filepath), "rb"); size_t len = strlen(filepath); diff --git a/source/src/protocol.cpp b/source/src/protocol.cpp index 9f9e2c3a..2ee6aff0 100644 --- a/source/src/protocol.cpp +++ b/source/src/protocol.cpp @@ -322,10 +322,10 @@ char msgsizelookup(int msg) const char *genpwdhash(const char *name, const char *pwd, int salt) { static string temp; - s_sprintf(temp)("%s %d %s %s %d", pwd, salt, name, pwd, abs(PROTOCOL_VERSION)); + formatstring(temp)("%s %d %s %s %d", pwd, salt, name, pwd, abs(PROTOCOL_VERSION)); tiger::hashval hash; tiger::hash((uchar *)temp, (int)strlen(temp), hash); - s_sprintf(temp)("%llx %llx %llx", hash.chunks[0], hash.chunks[1], hash.chunks[2]); + formatstring(temp)("%llx %llx %llx", hash.chunks[0], hash.chunks[1], hash.chunks[2]); return temp; } diff --git a/source/src/protos.h b/source/src/protos.h index e337dee4..b13f936b 100644 --- a/source/src/protos.h +++ b/source/src/protos.h @@ -825,8 +825,8 @@ struct servercommandline filterservdesc(t, t); break; } - case 'P': s_strcat(voteperm, a); break; - case 'M': s_strcat(mapperm, a); break; + case 'P': concatstring(voteperm, a); break; + case 'M': concatstring(mapperm, a); break; case 'V': verbose++; break; case 'C': if(*a && clfilenesting < 3) { diff --git a/source/src/renderhud.cpp b/source/src/renderhud.cpp index 9fc4f4de..d2ec9569 100644 --- a/source/src/renderhud.cpp +++ b/source/src/renderhud.cpp @@ -125,7 +125,7 @@ Texture *crosshairs[CROSSHAIR_NUM] = { NULL }; // weapon specific crosshairs Texture *loadcrosshairtexture(const char *c) { - s_sprintfd(p)("packages/misc/crosshairs/%s", c); + defformatstring(p)("packages/misc/crosshairs/%s", c); Texture *crosshair = textureload(p, 3); if(crosshair==notexture) crosshair = textureload("packages/misc/crosshairs/default.png", 3); return crosshair; @@ -269,7 +269,7 @@ void drawradarent(float x, float y, float yaw, int col, int row, float iconsize, glEnable(GL_BLEND); glTranslatef(iconsize/2, iconsize/2, 0); glScalef(1/2.0f, 1/2.0f, 1/2.0f); - s_sprintfdv(lbl, label); + defvformatstring(lbl, label, label); draw_text(lbl, (int)(x*2), (int)(y*2)); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glDisable(GL_BLEND); @@ -294,7 +294,7 @@ struct hudmessages : consolebuffer { conlines[0].millis = totalmillis; conlines[0].type = HUDMSG_INFO; - s_strcpy(conlines[0].line, sf); + copystring(conlines[0].line, sf); } else consolebuffer::addline(sf, totalmillis); } @@ -304,7 +304,7 @@ struct hudmessages : consolebuffer { conlines[0].millis = totalmillis; conlines[0].type = type; - s_strcpy(conlines[0].line, sf); + copystring(conlines[0].line, sf); } else consolebuffer::addline(sf, totalmillis).type = type; } @@ -327,20 +327,20 @@ hudmessages hudmsgs; void hudoutf(const char *s, ...) { - s_sprintfdv(sf, s); + defvformatstring(sf, s, s); hudmsgs.addline(sf); conoutf("%s", sf); } void hudonlyf(const char *s, ...) { - s_sprintfdv(sf, s); + defvformatstring(sf, s, s); hudmsgs.addline(sf); } void hudeditf(int type, const char *s, ...) { - s_sprintfdv(sf, s); + defvformatstring(sf, s, s); hudmsgs.editline(type, sf); } @@ -652,7 +652,7 @@ void gl_drawhud(int w, int h, int curfps, int nquads, int curvert, bool underwat { if(players.inrange(player1->followplayercn) && players[player1->followplayercn]) { - s_sprintfd(name)("Player %s", players[player1->followplayercn]->name); + defformatstring(name)("Player %s", players[player1->followplayercn]->name); draw_text(name, VIRTW/40, VIRTH/10*8); } } @@ -735,7 +735,7 @@ void loadingscreen(const char *fmt, ...) if(fmt) { glEnable(GL_BLEND); - s_sprintfdlv(str, fmt, fmt); + defvformatstring(str, fmt, fmt); int w = text_width(str); draw_text(str, w>=VIRTW ? 0 : (VIRTW-w)/2, VIRTH*3/4); glDisable(GL_BLEND); diff --git a/source/src/rendermodel.cpp b/source/src/rendermodel.cpp index 4b40a2cc..2afb55ca 100644 --- a/source/src/rendermodel.cpp +++ b/source/src/rendermodel.cpp @@ -87,7 +87,7 @@ void mapmodel(char *rad, char *h, char *zoff, char *snap, char *name) mmi.rad = atoi(rad); mmi.h = atoi(h); mmi.zoff = atoi(zoff); - s_sprintf(mmi.name)("mapmodels/%s", name); + formatstring(mmi.name)("mapmodels/%s", name); } void mapmodelreset() @@ -461,13 +461,13 @@ int findanim(const char *name) void loadskin(const char *dir, const char *altdir, Texture *&skin) // model skin sharing { #define ifnoload if((skin = textureload(path))==notexture) - s_sprintfd(path)("packages/models/%s/skin.jpg", dir); + defformatstring(path)("packages/models/%s/skin.jpg", dir); ifnoload { strcpy(path+strlen(path)-3, "png"); ifnoload { - s_sprintf(path)("packages/models/%s/skin.jpg", altdir); + formatstring(path)("packages/models/%s/skin.jpg", altdir); ifnoload { strcpy(path+strlen(path)-3, "png"); @@ -483,7 +483,7 @@ void preload_playermodels() if(dynshadow && playermdl) playermdl->genshadows(8.0f, 4.0f); loopi(NUMGUNS) { - s_sprintfd(vwep)("weapons/%s/world", guns[i].modelname); + defformatstring(vwep)("weapons/%s/world", guns[i].modelname); model *vwepmdl = loadmodel(vwep); if(dynshadow && vwepmdl) vwepmdl->genshadows(8.0f, 4.0f); } @@ -668,7 +668,7 @@ const char *getclientskin(const char *name, const char *suf) if(namelen == sl && !strncmp(name, s, namelen)) return s; // exact match if(s[sl - 1] == '_') { - s_strcpy(tmp, s); + copystring(tmp, s); tmp[sl - 1] = '\0'; if(strstr(name, tmp)) r = s; // partial match } @@ -701,18 +701,18 @@ void renderclient(playerent *d) if(!m_teammode && d->skin_noteam) cs = d->skin_noteam; } if(cs) - s_sprintf(skin)("%s/custom/%s.jpg", skinbase, cs); + formatstring(skin)("%s/custom/%s.jpg", skinbase, cs); else { - if(!m_teammode || !teamdisplaymode) s_sprintf(skin)("%s/%s/%02i.jpg", skinbase, teamname, skinid); + if(!m_teammode || !teamdisplaymode) formatstring(skin)("%s/%s/%02i.jpg", skinbase, teamname, skinid); else switch(teamdisplaymode) { - case 1: s_sprintf(skin)("%s/%s/%02i_%svest.jpg", skinbase, teamname, skinid, team ? "blue" : "red"); break; - case 2: default: s_sprintf(skin)("%s/%s/%s.jpg", skinbase, teamname, team ? "blue" : "red"); break; + case 1: formatstring(skin)("%s/%s/%02i_%svest.jpg", skinbase, teamname, skinid, team ? "blue" : "red"); break; + case 2: default: formatstring(skin)("%s/%s/%s.jpg", skinbase, teamname, team ? "blue" : "red"); break; } } string vwep; - if(d->weaponsel) s_sprintf(vwep)("weapons/%s/world", d->weaponsel->info.modelname); + if(d->weaponsel) formatstring(vwep)("weapons/%s/world", d->weaponsel->info.modelname); else vwep[0] = 0; renderclient(d, "playermodels", vwep[0] ? vwep : NULL, -(int)textureload(skin)->id); } diff --git a/source/src/rendertext.cpp b/source/src/rendertext.cpp index faa6b9d7..fa050051 100644 --- a/source/src/rendertext.cpp +++ b/source/src/rendertext.cpp @@ -89,7 +89,7 @@ int text_width(const char *str) void draw_textf(const char *fstr, int left, int top, ...) { - s_sprintfdlv(str, top, fstr); + defvformatstring(str, top, fstr); draw_text(str, left, top); } diff --git a/source/src/scoreboard.cpp b/source/src/scoreboard.cpp index 5827ee33..5d3522ef 100644 --- a/source/src/scoreboard.cpp +++ b/source/src/scoreboard.cpp @@ -93,7 +93,7 @@ const char *scoreratio(int frags, int deaths) int precision = 0; if(ratio<10.0f) precision = 2; else if(ratio>=10.0f && ratio<100.0f) precision = 1; - s_sprintf(res)("%.*f", precision, ratio); + formatstring(res)("%.*f", precision, ratio); return res; } @@ -106,8 +106,8 @@ void renderdiscscores(int team) const char *spect = team_isspect(d.team) ? "\f4" : ""; const char *sr = scoreratio(d.frags, d.deaths); const char *clag = team_isspect(d.team) ? "SPECT" : ""; - if(m_flags) s_sprintf(line.s)("%s%d\t%d\t%d\t%s\t%s\tDISC\t\t%s", spect, d.flags, d.frags, d.deaths, sr, clag, d.name); - else s_sprintf(line.s)("%s%d\t%d\t%s\t%s\tDISC\t\t%s", spect, d.frags, d.deaths, sr, clag, d.name); + if(m_flags) formatstring(line.s)("%s%d\t%d\t%d\t%s\t%s\tDISC\t\t%s", spect, d.flags, d.frags, d.deaths, sr, clag, d.name); + else formatstring(line.s)("%s%d\t%d\t%s\t%s\tDISC\t\t%s", spect, d.frags, d.deaths, sr, clag, d.name); } } @@ -125,8 +125,8 @@ void renderscore(playerent *d) sline &line = scorelines.add(); line.bgcolor = d==player1 ? &localplayerc : NULL; string &s = line.s; - if(m_flags) s_sprintf(s)("%s%d\t%d\t%d\t%s\t%s\t%s\t%d\t%s%s%s", spect, d->flagscore, d->frags, d->deaths, sr, clag, cping, d->clientnum, status, colorname(d), ign); - else s_sprintf(s)("%s%d\t%d\t%s\t%s\t%s\t%d\t%s%s%s", spect, d->frags, d->deaths, sr, clag, cping, d->clientnum, status, colorname(d), ign); + if(m_flags) formatstring(s)("%s%d\t%d\t%d\t%s\t%s\t%s\t%d\t%s%s%s", spect, d->flagscore, d->frags, d->deaths, sr, clag, cping, d->clientnum, status, colorname(d), ign); + else formatstring(s)("%s%d\t%d\t%s\t%s\t%s\t%d\t%s%s%s", spect, d->frags, d->deaths, sr, clag, cping, d->clientnum, status, colorname(d), ign); } void renderteamscore(teamscore *t) @@ -137,10 +137,10 @@ void renderteamscore(teamscore *t) space.s[0] = 0; } sline &line = scorelines.add(); - s_sprintfd(plrs)("(%d %s)", t->teammembers.length(), t->teammembers.length() == 1 ? "player" : "players"); + defformatstring(plrs)("(%d %s)", t->teammembers.length(), t->teammembers.length() == 1 ? "player" : "players"); const char *sr = scoreratio(t->frags, t->deaths); - if(m_flags) s_sprintf(line.s)("%d\t%d\t%d\t%s\t\t\t\t%s\t\t%s", t->flagscore, t->frags, t->deaths, sr, team_string(t->team), plrs); - else s_sprintf(line.s)("%d\t%d\t%s\t\t\t\t%s\t\t%s", t->frags, t->deaths, sr, team_string(t->team), plrs); + if(m_flags) formatstring(line.s)("%d\t%d\t%d\t%s\t\t\t\t%s\t\t%s", t->flagscore, t->frags, t->deaths, sr, team_string(t->team), plrs); + else formatstring(line.s)("%d\t%d\t%s\t\t\t\t%s\t\t%s", t->frags, t->deaths, sr, team_string(t->team), plrs); static color teamcolors[2] = { color(1.0f, 0, 0, 0.2f), color(0, 0, 1.0f, 0.2f) }; line.bgcolor = &teamcolors[team_base(t->team)]; loopv(t->teammembers) renderscore(t->teammembers[i]); @@ -169,17 +169,17 @@ void renderscores(void *menu, bool init) if(getclientmap()[0]) { bool fldrprefix = !strncmp(getclientmap(), "maps/", strlen("maps/")); - s_sprintf(modeline)("\"%s\" on map %s", modestr(gamemode, modeacronyms > 0), fldrprefix ? getclientmap()+strlen("maps/") : getclientmap()); + formatstring(modeline)("\"%s\" on map %s", modestr(gamemode, modeacronyms > 0), fldrprefix ? getclientmap()+strlen("maps/") : getclientmap()); } extern int minutesremaining; if((gamemode>1 || (gamemode==0 && (multiplayer(false) || watchingdemo))) && minutesremaining >= 0) { - if(!minutesremaining) s_strcat(modeline, ", intermission"); + if(!minutesremaining) concatstring(modeline, ", intermission"); else { - s_sprintfd(timestr)(", %d %s remaining", minutesremaining, minutesremaining==1 ? "minute" : "minutes"); - s_strcat(modeline, timestr); + defformatstring(timestr)(", %d %s remaining", minutesremaining, minutesremaining==1 ? "minute" : "minutes"); + concatstring(modeline, timestr); } } @@ -188,8 +188,8 @@ void renderscores(void *menu, bool init) serverinfo *s = getconnectedserverinfo(); if(s) { - if(servstate.mastermode > MM_OPEN) s_strcatf(serverline, servstate.mastermode == MM_MATCH ? "M%d " : "P ", servstate.matchteamsize); - s_strcatf(serverline, "%s:%d %s", s->name, s->port, s->sdesc); + if(servstate.mastermode > MM_OPEN) concatformatstring(serverline, servstate.mastermode == MM_MATCH ? "M%d " : "P ", servstate.matchteamsize); + concatformatstring(serverline, "%s:%d %s", s->name, s->port, s->sdesc); } } @@ -264,12 +264,12 @@ const char *asciiscores(bool destjpg) buf[0] = '\0'; if(destjpg) { - s_sprintf(text)("AssaultCube Screenshot (%s)\n", asctime()); + formatstring(text)("AssaultCube Screenshot (%s)\n", asctime()); addstr(buf, text); } if(getclientmap()[0]) { - s_sprintf(text)("\n\"%s\" on map %s", modestr(gamemode, 0), getclientmap(), asctime()); + formatstring(text)("\n\"%s\" on map %s", modestr(gamemode, 0), getclientmap(), asctime()); addstr(buf, text); } if(multiplayer(false)) @@ -279,7 +279,7 @@ const char *asciiscores(bool destjpg) { string sdesc; filtertext(sdesc, s->sdesc, 1); - s_sprintf(text)(", %s:%d %s", s->name, s->port, sdesc); + formatstring(text)(", %s:%d %s", s->name, s->port, sdesc); addstr(buf, text); } } @@ -287,19 +287,19 @@ const char *asciiscores(bool destjpg) addstr(buf, "\n"); else { - s_sprintf(text)("\n%sfrags deaths ratio cn%s name\n", m_flags ? "flags " : "", m_teammode ? " team" : ""); + formatstring(text)("\n%sfrags deaths ratio cn%s name\n", m_flags ? "flags " : "", m_teammode ? " team" : ""); addstr(buf, text); } loopv(scores) { d = scores[i]; const char *sr = scoreratio(d->frags, d->deaths); - s_sprintf(team)(destjpg ? ", %s" : " %-4s", team_string(d->team, true)); - s_sprintf(flags)(destjpg ? "%d/" : " %4d ", d->flagscore); + formatstring(team)(destjpg ? ", %s" : " %-4s", team_string(d->team, true)); + formatstring(flags)(destjpg ? "%d/" : " %4d ", d->flagscore); if(destjpg) - s_sprintf(text)("%s%s (%s%d/%d)\n", d->name, m_teammode ? team : "", m_flags ? flags : "", d->frags, d->deaths); + formatstring(text)("%s%s (%s%d/%d)\n", d->name, m_teammode ? team : "", m_flags ? flags : "", d->frags, d->deaths); else - s_sprintf(text)("%s %4d %4d %5s %2d%s %s%s\n", m_flags ? flags : "", d->frags, d->deaths, sr, d->clientnum, + formatstring(text)("%s %4d %4d %5s %2d%s %s%s\n", m_flags ? flags : "", d->frags, d->deaths, sr, d->clientnum, m_teammode ? team : "", d->name, d->clientrole==CR_ADMIN ? " (admin)" : d==player1 ? " (you)" : ""); addstr(buf, text); } @@ -308,18 +308,18 @@ const char *asciiscores(bool destjpg) { discscore &d = discscores[i]; const char *sr = scoreratio(d.frags, d.deaths); - s_sprintf(team)(destjpg ? ", %s" : " %-4s", team_string(d.team, true)); - s_sprintf(flags)(destjpg ? "%d/" : " %4d ", d.flags); + formatstring(team)(destjpg ? ", %s" : " %-4s", team_string(d.team, true)); + formatstring(flags)(destjpg ? "%d/" : " %4d ", d.flags); if(destjpg) - s_sprintf(text)("%s(disconnected)%s (%s%d/%d)\n", d.name, m_teammode ? team : "", m_flags ? flags : "", d.frags, d.deaths); + formatstring(text)("%s(disconnected)%s (%s%d/%d)\n", d.name, m_teammode ? team : "", m_flags ? flags : "", d.frags, d.deaths); else - s_sprintf(text)("%s %4d %4d %5s --%s %s(disconnected)\n", m_flags ? flags : "", d.frags, d.deaths, sr, m_teammode ? team : "", d.name); + formatstring(text)("%s %4d %4d %5s --%s %s(disconnected)\n", m_flags ? flags : "", d.frags, d.deaths, sr, m_teammode ? team : "", d.name); addstr(buf, text); } if(destjpg) { extern int minutesremaining; - s_sprintf(text)("(%sfrags/deaths), %d minute%s remaining\n", m_flags ? "flags/" : "", minutesremaining, minutesremaining == 1 ? "" : "s"); + formatstring(text)("(%sfrags/deaths), %d minute%s remaining\n", m_flags ? "flags/" : "", minutesremaining, minutesremaining == 1 ? "" : "s"); addstr(buf, text); } return buf; diff --git a/source/src/server.cpp b/source/src/server.cpp index 658e9b45..a3958962 100644 --- a/source/src/server.cpp +++ b/source/src/server.cpp @@ -302,7 +302,7 @@ savedscore *findscore(client &c, bool insert) } if(!insert) return NULL; savedscore &sc = savedscores.add(); - s_strcpy(sc.name, c.name); + copystring(sc.name, c.name); sc.ip = c.peer->address.host; return ≻ } @@ -437,10 +437,10 @@ void enddemorecord() } int mr = gamemillis >= gamelimit ? 0 : (gamelimit - gamemillis + 60000 - 1)/60000; demofile &d = demofiles.add(); - s_sprintf(d.info)("%s: %s, %s, %.2f%s", asctime(), modestr(gamemode), smapname, len > 1024*1024 ? len/(1024*1024.f) : len/1024.0f, len > 1024*1024 ? "MB" : "kB"); - s_sprintf(d.file)("%s_%s_%s", timestring(), behindpath(smapname), modestr(gamemode, true)); - if(mr) { s_strcatf(d.info, ", %d mr", mr); s_strcatf(d.file, "_%dmr", mr); } - s_sprintfd(msg)("Demo \"%s\" recorded\nPress F10 to download it from the server..", d.info); + formatstring(d.info)("%s: %s, %s, %.2f%s", asctime(), modestr(gamemode), smapname, len > 1024*1024 ? len/(1024*1024.f) : len/1024.0f, len > 1024*1024 ? "MB" : "kB"); + formatstring(d.file)("%s_%s_%s", timestring(), behindpath(smapname), modestr(gamemode, true)); + if(mr) { concatformatstring(d.info, ", %d mr", mr); concatformatstring(d.file, "_%dmr", mr); } + defformatstring(msg)("Demo \"%s\" recorded\nPress F10 to download it from the server..", d.info); sendservmsg(msg); logline(ACLOG_INFO, "Demo \"%s\" recorded.", d.info); d.data = new uchar[len]; @@ -450,7 +450,7 @@ void enddemorecord() demotmp = NULL; if(scl.demopath[0]) { - s_sprintf(msg)("%s%s.dmo", scl.demopath, d.file); + formatstring(msg)("%s%s.dmo", scl.demopath, d.file); path(msg); FILE *demo = openfile(msg, "wb"); if(demo) @@ -500,9 +500,9 @@ void setupdemorecord() endianswap(&hdr.version, sizeof(int), 1); endianswap(&hdr.protocol, sizeof(int), 1); memset(hdr.desc, 0, DHDR_DESCCHARS); - s_sprintfd(desc)("%s, %s, %s %s", modestr(gamemode, false), behindpath(smapname), asctime(), servdesc_current); + defformatstring(desc)("%s, %s, %s %s", modestr(gamemode, false), behindpath(smapname), asctime(), servdesc_current); if(strlen(desc) > DHDR_DESCCHARS) - s_sprintf(desc)("%s, %s, %s %s", modestr(gamemode, true), behindpath(smapname), asctime(), servdesc_current); + formatstring(desc)("%s, %s, %s %s", modestr(gamemode, true), behindpath(smapname), asctime(), servdesc_current); desc[DHDR_DESCCHARS - 1] = '\0'; strcpy(hdr.desc, desc); memset(hdr.plist, 0, DHDR_PLISTCHARS); @@ -574,7 +574,7 @@ static void cleardemos(int n) { delete[] demofiles[n-1].data; demofiles.remove(n-1); - s_sprintfd(msg)("cleared demo %d", n); + defformatstring(msg)("cleared demo %d", n); sendservmsg(msg); } } @@ -587,7 +587,7 @@ void senddemo(int cn, int num) if(demofiles.empty()) sendservmsg("no demos available", cn); else { - s_sprintfd(msg)("no demo %d available", num); + defformatstring(msg)("no demo %d available", num); sendservmsg(msg, cn); } return; @@ -622,18 +622,18 @@ void setupdemoplayback() demoheader hdr; string msg; msg[0] = '\0'; - s_sprintfd(file)("demos/%s.dmo", smapname); + defformatstring(file)("demos/%s.dmo", smapname); path(file); demoplayback = opengzfile(file, "rb9"); - if(!demoplayback) s_sprintf(msg)("could not read demo \"%s\"", file); + if(!demoplayback) formatstring(msg)("could not read demo \"%s\"", file); else if(gzread(demoplayback, &hdr, sizeof(demoheader))!=sizeof(demoheader) || memcmp(hdr.magic, DEMO_MAGIC, sizeof(hdr.magic))) - s_sprintf(msg)("\"%s\" is not a demo file", file); + formatstring(msg)("\"%s\" is not a demo file", file); else { endianswap(&hdr.version, sizeof(int), 1); endianswap(&hdr.protocol, sizeof(int), 1); - if(hdr.version!=DEMO_VERSION) s_sprintf(msg)("demo \"%s\" requires an %s version of AssaultCube", file, hdr.versionlastsaytext, text); + copystring(cl->lastsaytext, text); cl->spamcount = 0; } cl->lastsay = servmillis; @@ -1423,12 +1423,12 @@ void updatesdesc(const char *newdesc, ENetAddress *caller = NULL) { if(!newdesc || !newdesc[0] || !updatedescallowed()) { - s_strcpy(servdesc_current, scl.servdesc_full); + copystring(servdesc_current, scl.servdesc_full); custom_servdesc = false; } else { - s_sprintf(servdesc_current)("%s%s%s", scl.servdesc_pre, newdesc, scl.servdesc_suf); + formatstring(servdesc_current)("%s%s%s", scl.servdesc_pre, newdesc, scl.servdesc_suf); custom_servdesc = true; if(caller) servdesc_caller = *caller; } @@ -1656,7 +1656,7 @@ void resetserver(const char *newname, int newmode, int newtime) else enddemorecord(); smode = newmode; - s_strcpy(smapname, newname); + copystring(smapname, newname); minremain = newtime >= 0 ? newtime : (m_teammode ? 15 : 10); gamemillis = 0; @@ -1739,10 +1739,10 @@ void startgame(const char *newname, int newmode, int newtime, bool notify) sendf(-1, 1, "risiii", SV_MAPCHANGE, smapname, smode, mapbuffer.available(), mapbuffer.revision); if(smode>1 || (smode==0 && numnonlocalclients()>0)) sendf(-1, 1, "ri2", SV_TIMEUP, minremain); } - s_sprintfd(gsmsg)("Game start: %s on %s, %d players, %d minutes, mastermode %d, ", modestr(smode), smapname, numclients(), minremain, mastermode); - if(mastermode == MM_MATCH) s_strcatf(gsmsg, "teamsize %d, ", matchteamsize); - if(ms) s_strcatf(gsmsg, "(map rev %d/%d, %s, 'getmap' %sprepared)", smapstats.hdr.maprevision, smapstats.cgzsize, maplocstr[maploc], mapbuffer.available() ? "" : "not "); - else s_strcatf(gsmsg, "error: failed to preload map (map: %s)", maplocstr[maploc]); + defformatstring(gsmsg)("Game start: %s on %s, %d players, %d minutes, mastermode %d, ", modestr(smode), smapname, numclients(), minremain, mastermode); + if(mastermode == MM_MATCH) concatformatstring(gsmsg, "teamsize %d, ", matchteamsize); + if(ms) concatformatstring(gsmsg, "(map rev %d/%d, %s, 'getmap' %sprepared)", smapstats.hdr.maprevision, smapstats.cgzsize, maplocstr[maploc], mapbuffer.available() ? "" : "not "); + else concatformatstring(gsmsg, "error: failed to preload map (map: %s)", maplocstr[maploc]); logline(ACLOG_INFO, "\n%s", gsmsg); if(m_arena) distributespawns(); if(notify) @@ -2206,14 +2206,14 @@ void process(ENetPacket *packet, int sender, int chan) { cl->acversion = getint(p); cl->acbuildtype = getint(p); - s_sprintfd(tags)(", AC: %d|%x", cl->acversion, cl->acbuildtype); + defformatstring(tags)(", AC: %d|%x", cl->acversion, cl->acbuildtype); getstring(text, p); filtertext(text, text, 0, MAXNAMELEN); - if(!text[0]) s_strcpy(text, "unarmed"); - s_strncpy(cl->name, text, MAXNAMELEN+1); + if(!text[0]) copystring(text, "unarmed"); + copystring(cl->name, text, MAXNAMELEN+1); getstring(text, p); - s_strcpy(cl->pwd, text); + copystring(cl->pwd, text); getstring(text, p); filterlang(cl->lang, text); int wantrole = getint(p); @@ -2223,7 +2223,7 @@ void process(ENetPacket *packet, int sender, int chan) bool srvprivate = mastermode == MM_PRIVATE || mastermode == MM_MATCH; bool matchreconnect = mastermode == MM_MATCH && findscore(*cl, false); int bl = 0, wl = nickblacklist.checkwhitelist(*cl); - if(wl == NWL_PASS) s_strcat(tags, ", nickname whitelist match"); + if(wl == NWL_PASS) concatstring(tags, ", nickname whitelist match"); if(wl == NWL_UNLISTED) bl = nickblacklist.checkblacklist(cl->name); if(matchreconnect && !banned) { // former player reconnecting to a server in match mode @@ -2246,7 +2246,7 @@ void process(ENetPacket *packet, int sender, int chan) if(!pd.denyadmin && wantrole == CR_ADMIN) clientrole = CR_ADMIN; if(banned) { - loopv(bans) if(bans[i].address.host == cl->peer->address.host) { bans.remove(i); s_strcat(tags, ", ban removed"); break; } // remove admin bans + loopv(bans) if(bans[i].address.host == cl->peer->address.host) { bans.remove(i); concatstring(tags, ", ban removed"); break; } // remove admin bans } if(srvfull) { @@ -2404,11 +2404,11 @@ void process(ENetPacket *packet, int sender, int chan) QUEUE_MSG; getstring(text, p); filtertext(text, text, 0, MAXNAMELEN); - if(!text[0]) s_strcpy(text, "unarmed"); + if(!text[0]) copystring(text, "unarmed"); QUEUE_STR(text); bool namechanged = strcmp(cl->name, text) != 0; if(namechanged) logline(ACLOG_INFO,"[%s] %s changed name to %s", cl->hostname, cl->name, text); - s_strncpy(cl->name, text, MAXNAMELEN+1); + copystring(cl->name, text, MAXNAMELEN+1); cl->skin[TEAM_CLA] = getint(p); cl->skin[TEAM_RVSF] = getint(p); QUEUE_MSG; @@ -2730,7 +2730,7 @@ void process(ENetPacket *packet, int sender, int chan) if(readonlymap(mp)) { reject = "map is ro"; - s_sprintfd(msg)("\f3map upload rejected: map %s is readonly", sentmap); + defformatstring(msg)("\f3map upload rejected: map %s is readonly", sentmap); sendservmsg(msg, sender); } else if(mp == MAP_NOTFOUND && !strchr(scl.mapperm, 'c') && cl->role < CR_ADMIN) // default: only admins can create maps @@ -2754,7 +2754,7 @@ void process(ENetPacket *packet, int sender, int chan) { logline(ACLOG_INFO,"[%s] %s sent map %s, rev %d, %d + %d(%d) bytes written", clients[sender]->hostname, clients[sender]->name, sentmap, revision, mapsize, cfgsize, cfgsizegz); - s_sprintfd(msg)("%s (%d) up%sed map %s, rev %d%s", clients[sender]->name, sender, mp == MAP_NOTFOUND ? "load": "dat", sentmap, revision, + defformatstring(msg)("%s (%d) up%sed map %s, rev %d%s", clients[sender]->name, sender, mp == MAP_NOTFOUND ? "load": "dat", sentmap, revision, strcmp(sentmap, behindpath(smapname)) || smode == GMODE_COOPEDIT ? "" : " (restart game to use new map version)"); sendservmsg(msg); } @@ -2802,18 +2802,18 @@ void process(ENetPacket *packet, int sender, int chan) else if(mp == MAP_NOTFOUND) reject = "map not found"; else { - s_sprintf(filename)(SERVERMAP_PATH_INCOMING "%s.cgz", rmmap); + formatstring(filename)(SERVERMAP_PATH_INCOMING "%s.cgz", rmmap); remove(filename); - s_sprintf(filename)(SERVERMAP_PATH_INCOMING "%s.cfg", rmmap); + formatstring(filename)(SERVERMAP_PATH_INCOMING "%s.cfg", rmmap); remove(filename); - s_sprintfd(msg)("map '%s' deleted", rmmap); + defformatstring(msg)("map '%s' deleted", rmmap); sendservmsg(msg, sender); logline(ACLOG_INFO,"[%s] deleted map %s", clients[sender]->hostname, rmmap); } if (reject) { logline(ACLOG_INFO,"[%s] deleting map %s failed: %s", clients[sender]->hostname, rmmap, reject); - s_sprintfd(msg)("\f3can't delete map '%s', %s", rmmap, reject); + defformatstring(msg)("\f3can't delete map '%s', %s", rmmap, reject); sendservmsg(msg, sender); } break; @@ -2959,7 +2959,7 @@ void process(ENetPacket *packet, int sender, int chan) if(valid_client(sender) && clients[sender]->role==CR_ADMIN && mastermode == MM_MATCH) { changematchteamsize(atoi(text)); - s_sprintfd(msg)("match team size set to %d", matchteamsize); + defformatstring(msg)("match team size set to %d", matchteamsize); sendservmsg(msg, -1); } } @@ -3054,7 +3054,7 @@ void loggamestatus(const char *reason) { int fragscore[2] = {0, 0}, flagscore[2] = {0, 0}, pnum[2] = {0, 0}; string text; - s_sprintf(text)("%d minutes remaining", minremain); + formatstring(text)("%d minutes remaining", minremain); logline(ACLOG_INFO, ""); logline(ACLOG_INFO, "Game status: %s on %s, %s, %s%c %s", modestr(gamemode), smapname, reason ? reason : text, mmfullname(mastermode), custom_servdesc ? ',' : '\0', servdesc_current); @@ -3063,11 +3063,11 @@ void loggamestatus(const char *reason) { client &c = *clients[i]; if(c.type == ST_EMPTY || !c.name[0]) continue; - s_sprintf(text)("%2d %-16s ", c.clientnum, c.name); // cn name - if(m_teammode) s_strcatf(text, "%-4s ", team_string(c.team, true)); // teamname (abbreviated) - if(m_flags) s_strcatf(text, "%4d ", c.state.flagscore); // flag - s_strcatf(text, "%4d %5d", c.state.frags, c.state.deaths); // frag death - if(m_teammode) s_strcatf(text, " %2d", c.state.teamkills); // tk + formatstring(text)("%2d %-16s ", c.clientnum, c.name); // cn name + if(m_teammode) concatformatstring(text, "%-4s ", team_string(c.team, true)); // teamname (abbreviated) + if(m_flags) concatformatstring(text, "%4d ", c.state.flagscore); // flag + concatformatstring(text, "%4d %5d", c.state.frags, c.state.deaths); // frag death + if(m_teammode) concatformatstring(text, " %2d", c.state.teamkills); // tk logline(ACLOG_INFO, "%s%5d %s %s", text, c.ping, c.role == CR_ADMIN ? "admin " : "normal", c.hostname); if(c.team != TEAM_SPECT) { @@ -3084,8 +3084,8 @@ void loggamestatus(const char *reason) savedscore &sc = savedscores[i]; if(sc.valid) { - s_sprintf(text)(m_teammode ? "%-4s " : "", team_string(sc.team, true)); - if(m_flags) s_strcatf(text, "%4d ", sc.flagscore); + formatstring(text)(m_teammode ? "%-4s " : "", team_string(sc.team, true)); + if(m_flags) concatformatstring(text, "%4d ", sc.flagscore); logline(ACLOG_INFO, " %-16s %s%4d %5d%s - disconnected", sc.name, text, sc.frags, sc.deaths, m_teammode ? " -" : ""); if(sc.team != TEAM_SPECT) { @@ -3135,7 +3135,7 @@ void linequalitystats(int elapsed) } else { // calculate compressed statistics - s_sprintfd(msg)("Uplink quality [ "); + defformatstring(msg)("Uplink quality [ "); int ncs = 0; loopj(scl.maxclients) { @@ -3160,7 +3160,7 @@ void linequalitystats(int elapsed) } } chokelog[i] = (s << 4) + c; - s_strcatf(msg, "%02X ", chokelog[i]); + concatformatstring(msg, "%02X ", chokelog[i]); } logline(ACLOG_DEBUG, "%s] +%d", msg, ncs); } @@ -3280,7 +3280,7 @@ void serverslice(uint timeout) // main server update, called from cube main lo c.connectmillis = servmillis; c.salt = rand()*((servmillis%1000)+1); char hn[1024]; - s_strcpy(c.hostname, (enet_address_get_host_ip(&c.peer->address, hn, sizeof(hn))==0) ? hn : "unknown"); + copystring(c.hostname, (enet_address_get_host_ip(&c.peer->address, hn, sizeof(hn))==0) ? hn : "unknown"); logline(ACLOG_INFO,"[%s] client connected", c.hostname); sendinits2c(c); break; @@ -3463,7 +3463,7 @@ void localconnect() client &c = addclient(); c.type = ST_LOCAL; c.role = CR_ADMIN; - s_strcpy(c.hostname, "local"); + copystring(c.hostname, "local"); sendinits2c(c); } #endif @@ -3475,13 +3475,13 @@ void initserver(bool dedicated) string identity; if(scl.logident[0]) filtertext(identity, scl.logident, 0); - else s_sprintf(identity)("%s#%d", scl.ip[0] ? scl.ip : "local", scl.serverport); + else formatstring(identity)("%s#%d", scl.ip[0] ? scl.ip : "local", scl.serverport); int conthres = scl.verbose > 1 ? ACLOG_DEBUG : (scl.verbose ? ACLOG_VERBOSE : ACLOG_INFO); if(dedicated && !initlogging(identity, scl.syslogfacility, conthres, scl.filethres, scl.syslogthres, scl.logtimestamp)) printf("WARNING: logging not started!\n"); logline(ACLOG_INFO, "logging local AssaultCube server (version %d, protocol %d/%d) now..", AC_VERSION, SERVER_PROTOCOL_VERSION, EXT_VERSION); - s_strcpy(servdesc_current, scl.servdesc_full); + copystring(servdesc_current, scl.servdesc_full); servermsinit(scl.master ? scl.master : AC_MASTER_URI, scl.ip, CUBE_SERVINFO_PORT(scl.serverport), dedicated); if((isdedicated = dedicated)) @@ -3531,8 +3531,8 @@ void initserver(bool dedicated) void localservertoclient(int chan, uchar *buf, int len) {} void fatal(const char *s, ...) { - s_sprintfdlv(msg,s,s); - s_sprintfd(out)("AssaultCube fatal error: %s", msg); + defvformatstring(msg,s,s); + defformatstring(out)("AssaultCube fatal error: %s", msg); if (logline(ACLOG_ERROR, "%s", out)); else puts(out); cleanupserver(); diff --git a/source/src/serveractions.h b/source/src/serveractions.h index dd82cdfe..09a5b1db 100644 --- a/source/src/serveractions.h +++ b/source/src/serveractions.h @@ -33,7 +33,7 @@ struct mapaction : serveraction { forceintermission = true; nextgamemode = mode; - s_strcpy(nextmapname, map); + copystring(nextmapname, map); } else { @@ -65,14 +65,14 @@ struct mapaction : serveraction { // unsupported mode if(strchr(scl.voteperm, 'P')) role = CR_ADMIN; else if(!strchr(scl.voteperm, 'p')) mapok = false; // default: no one can vote for unsupported mode/map combinations - s_sprintfd(msg)("\f3map \"%s\" does not support \"%s\": ", behindpath(map), modestr(mode, false)); - if(romap) s_strcat(msg, "map is readonly"); + defformatstring(msg)("\f3map \"%s\" does not support \"%s\": ", behindpath(map), modestr(mode, false)); + if(romap) concatstring(msg, "map is readonly"); else { - if(!spawns) s_strcat(msg, "player spawns"); - if(!spawns && !flags) s_strcat(msg, " and "); - if(!flags) s_strcat(msg, "flag bases"); - s_strcat(msg, " missing"); + if(!spawns) concatstring(msg, "player spawns"); + if(!spawns && !flags) concatstring(msg, " and "); + if(!flags) concatstring(msg, "flag bases"); + concatstring(msg, " missing"); } if(notify) sendservmsg(msg, caller); logline(ACLOG_INFO, "%s", msg); @@ -92,7 +92,7 @@ struct mapaction : serveraction } else mapok = true; area |= EE_LOCAL_SERV; // local too - s_sprintf(desc)("load map '%s' in mode '%s'", map, modestr(mode)); + formatstring(desc)("load map '%s' in mode '%s'", map, modestr(mode)); } ~mapaction() { DELETEA(map); } }; @@ -132,7 +132,7 @@ struct forceteamaction : playeraction forceteamaction(int cn, int caller) : playeraction(cn) { if(cn != caller) role = roleconf('f'); - if(isvalid()) s_sprintf(desc)("force player %s to the enemy team", clients[cn]->name); + if(isvalid()) formatstring(desc)("force player %s to the enemy team", clients[cn]->name); } }; @@ -158,7 +158,7 @@ struct kickaction : playeraction if(isvalid()) { wasvalid = true; - s_sprintf(desc)("kick player %s", clients[cn]->name); + formatstring(desc)("kick player %s", clients[cn]->name); } } }; @@ -180,7 +180,7 @@ struct banaction : playeraction if(isvalid()) { wasvalid = true; - s_sprintf(desc)("ban player %s", clients[cn]->name); + formatstring(desc)("ban player %s", clients[cn]->name); } } }; @@ -191,7 +191,7 @@ struct removebansaction : serveraction removebansaction() { role = roleconf('B'); - s_strcpy(desc, "remove all bans"); + copystring(desc, "remove all bans"); } }; @@ -203,7 +203,7 @@ struct mastermodeaction : serveraction mastermodeaction(int mode) : mode(mode) { role = roleconf('M'); - if(isvalid()) s_sprintf(desc)("change mastermode to '%s'", mmfullname(mode)); + if(isvalid()) formatstring(desc)("change mastermode to '%s'", mmfullname(mode)); } }; @@ -224,7 +224,7 @@ struct autoteamaction : enableaction autoteamaction(bool enable) : enableaction(enable) { role = roleconf('a'); - if(isvalid()) s_sprintf(desc)("%s autoteam", enable ? "enable" : "disable"); + if(isvalid()) formatstring(desc)("%s autoteam", enable ? "enable" : "disable"); } }; @@ -239,7 +239,7 @@ struct shuffleteamaction : serveraction shuffleteamaction() { role = roleconf('s'); - if(isvalid()) s_strcpy(desc, "shuffle teams"); + if(isvalid()) copystring(desc, "shuffle teams"); } }; @@ -250,7 +250,7 @@ struct recorddemoaction : enableaction // TODO: remove completely recorddemoaction(bool enable) : enableaction(enable) { role = roleconf('R'); - if(isvalid()) s_sprintf(desc)("%s demorecord", enable ? "enable" : "disable"); + if(isvalid()) formatstring(desc)("%s demorecord", enable ? "enable" : "disable"); } }; @@ -265,7 +265,7 @@ struct stopdemoaction : serveraction { role = CR_ADMIN; area |= EE_LOCAL_SERV; - s_strcpy(desc, "stop demo playback"); + copystring(desc, "stop demo playback"); } }; @@ -276,7 +276,7 @@ struct cleardemosaction : serveraction cleardemosaction(int demo) : demo(demo) { role = roleconf('C'); - if(isvalid()) s_sprintf(desc)("clear demo %d", demo); + if(isvalid()) formatstring(desc)("clear demo %d", demo); } }; @@ -290,7 +290,7 @@ struct serverdescaction : serveraction serverdescaction(char *sdesc, int cn) : sdesc(sdesc), cn(cn) { role = roleconf('D'); - s_sprintf(desc)("set server description to '%s'", sdesc); + formatstring(desc)("set server description to '%s'", sdesc); if(isvalid()) address = clients[cn]->peer->address; } ~serverdescaction() { DELETEA(sdesc); } diff --git a/source/src/serverbrowser.cpp b/source/src/serverbrowser.cpp index 6e6929f8..67f09520 100644 --- a/source/src/serverbrowser.cpp +++ b/source/src/serverbrowser.cpp @@ -154,7 +154,7 @@ bool resolverwait(const char *name, ENetAddress *address) if(resolverthreads.empty()) resolverinit(); - s_sprintfd(text)("resolving %s... (esc to abort)", name); + defformatstring(text)("resolving %s... (esc to abort)", name); show_out_of_renderloop_progress(0, text); SDL_LockMutex(resolvermutex); @@ -247,7 +247,7 @@ int connectwithtimeout(ENetSocket sock, const char *hostname, ENetAddress &addre return result; } - s_sprintfd(text)("connecting to %s... (esc to abort)", hostname); + defformatstring(text)("connecting to %s... (esc to abort)", hostname); show_out_of_renderloop_progress(0, text); if(!connmutex) connmutex = SDL_CreateMutex(); @@ -310,7 +310,7 @@ static serverinfo *newserver(const char *name, uint ip = ENET_HOST_ANY, int port si->msweight = weight; if(ip!=ENET_HOST_ANY) si->resolved = serverinfo::RESOLVED; - if(name) s_strcpy(si->name, name); + if(name) copystring(si->name, name); else if(ip==ENET_HOST_ANY || enet_address_get_host_ip(&si->address, si->name, sizeof(si->name)) < 0) { delete si; @@ -492,7 +492,7 @@ void checkpings() filtertext(si->map, text, 1); getstring(text, p); filterservdesc(si->sdesc, text); - s_strcpy(si->description, si->sdesc); + copystring(si->description, si->sdesc); si->maxclients = getint(p); if(p.remaining()) { @@ -558,7 +558,7 @@ void checkpings() if(*text && !p.overread()) { text[MAXINFOLINELEN] = '\0'; - loopi(n) s_strcatf(text, ", %d", getint(p)); + loopi(n) concatformatstring(text, ", %d", getint(p)); ADDINFOLINE(text ); } else break; @@ -603,9 +603,9 @@ void checkpings() ADDINFOLINE("players:\terrors/time"); for(int i = 4; i <= si->maxclients; i++) { - s_sprintfd(msg)(" %d\t", i); - loopj(15) s_strcatf(msg, "\a%c ", '0' + ((si->uplinkstats[i] & 0x0F) > j) + 2 * ((si->uplinkstats[i] & 0xF0) > (j << 4))); - s_strcatf(msg, "\t\t [%02X]", si->uplinkstats[i]); + defformatstring(msg)(" %d\t", i); + loopj(15) concatformatstring(msg, "\a%c ", '0' + ((si->uplinkstats[i] & 0x0F) > j) + 2 * ((si->uplinkstats[i] & 0xF0) > (j << 4))); + concatformatstring(msg, "\t\t [%02X]", si->uplinkstats[i]); ADDINFOLINE(msg); } ADDINFOLINE(""); @@ -635,7 +635,7 @@ void checkpings() else if(si->pongflags & (1 << PONGFLAG_PASSWORD)) sp = "this server is password-protected"; else if(mm) sp = mmfullname(mm); - s_sprintf(si->description)("%s \f1(%s)", si->sdesc, sp); + formatstring(si->description)("%s \f1(%s)", si->sdesc, sp); } } } @@ -734,8 +734,8 @@ string cursearch, cursearchuc; void searchnickname(const char *name) { if(!name || !name[0]) return; - s_strcpy(cursearch, name); - s_strcpy(cursearchuc, name); + copystring(cursearch, name); + copystring(cursearchuc, name); strtoupper(cursearchuc); showmenu("search"); } @@ -746,7 +746,7 @@ VAR(showallservers, 0, 1, 1); bool matchplayername(const char *name) { static string nameuc; - s_strcpy(nameuc, name); + copystring(nameuc, name); strtoupper(nameuc); return strstr(nameuc, cursearchuc) != NULL; } @@ -775,7 +775,7 @@ const char *favcatargname(const char *refdes, int par) static int i = 0; if(par < 0 || par >= FC_NUM) return NULL; i = (i + 1) % 3; - s_sprintf(text[i])("sbfavourite_%s_%s", refdes, fc_als[par]); + formatstring(text[i])("sbfavourite_%s_%s", refdes, fc_als[par]); return text[i]; } @@ -793,10 +793,10 @@ void addfavcategory(const char *refdes) loopi(FC_NUM) alx[i] = getalias(favcatargname(text, i)) ? 1 : 0; loopi(3) { - s_sprintf(val)("%d", *text & (1 << i) ? 90 : 10); + formatstring(val)("%d", *text & (1 << i) ? 90 : 10); if(!alx[i + FC_RED]) alias(favcatargname(text, i + FC_RED), val); } - s_sprintf(val)("favourites %d", favcats.length()); + formatstring(val)("favourites %d", favcats.length()); const int defk[] = { FC_WEIGHT, FC_DESC, FC_TAG, FC_KEYS, FC_IGNORE, FC_ALPHA }; const char *defv[] = { "0", val, refdes, "", "", "20" }; loopi(sizeof(defk)/sizeof(defk[0])) { if(!alx[defk[i]]) alias(favcatargname(text, defk[i]), defv[i]); } @@ -816,7 +816,7 @@ bool favcatcheckkey(serverinfo &si, const char *key) string text, keyuc; if(isdigit(*key)) // IP { - s_sprintf(text)("%s:%d", si.name, si.port); + formatstring(text)("%s:%d", si.name, si.port); return !strncmp(text, key, strlen(key)); } else if(si.address.host != ENET_HOST_ANY && si.ping != 9999) switch(*key) @@ -836,7 +836,7 @@ bool favcatcheckkey(serverinfo &si, const char *key) case '$': if(key[1]) { - s_sprintf(text)("%s \"%s\" %d %d, %d %d %d \"%s\" %d %d", key + 1, si.map, si.mode, si.ping, si.minremain, si.numplayers, si.maxclients, si.name, si.port, si.pongflags); + formatstring(text)("%s \"%s\" %d %d, %d %d %d \"%s\" %d %d", key + 1, si.map, si.mode, si.ping, si.minremain, si.numplayers, si.maxclients, si.name, si.port, si.pongflags); filtertext(text, text, 1); int cnt = 0; for(const char *p = text; (p = strchr(p, '\"')); p++) cnt++; @@ -865,7 +865,7 @@ const char *favcatcheck(serverinfo &si, const char *ckeys, char *autokeys = NULL if(favcatcheckkey(si, k)) { res = true; - if(autokeys && !(isdigit(*k) && strchr(k, ':'))) s_strcatf(autokeys, *autokeys ? " %s" : "%s", k); + if(autokeys && !(isdigit(*k) && strchr(k, ':'))) concatformatstring(autokeys, *autokeys ? " %s" : "%s", k); } else { @@ -969,7 +969,7 @@ void refreshservers(void *menu, bool init) if(lastselectedserver) { serverinfo &si = *lastselectedserver; - s_sprintf(si.full)("%s:%d %s", si.name, si.port, si.sdesc); + formatstring(si.full)("%s:%d %s", si.name, si.port, si.sdesc); menumanual(menu, si.full); menumanual(menu, &dummy); if(si.infotexts.length() && !pinglastselected) @@ -979,14 +979,14 @@ void refreshservers(void *menu, bool init) } else { - s_strcpy(infotext, "-- waiting for server response --"); + copystring(infotext, "-- waiting for server response --"); if(si.getinfo == EXTPING_NOP) si.getinfo = EXTPING_SERVERINFO; if(init || pinglastselected || totalmillis - lastinfo >= servpingrate) pingservers(false, lastselectedserver); pinglastselected = false; } } else - s_strcpy(infotext, " -- no server selected --"); + copystring(infotext, " -- no server selected --"); if(*infotext) menumanual(menu, infotext); return; } @@ -1021,7 +1021,7 @@ void refreshservers(void *menu, bool init) "%sping\tplr\tserver (\fs\f0description\fr)%s%s" // 7: description }; bool showmr = showminremain || serversort == SBS_MINREM; - s_sprintf(title)(titles[serversort], showfavtag ? "fav\t" : "", issearch ? " search results for \f3" : " (F1: Help/Settings)", issearch ? cursearch : ""); + formatstring(title)(titles[serversort], showfavtag ? "fav\t" : "", issearch ? " search results for \f3" : " (F1: Help/Settings)", issearch ? cursearch : ""); menutitle(menu, title); menureset(menu); string text; @@ -1044,29 +1044,29 @@ void refreshservers(void *menu, bool init) { if(si.protocol!=PROTOCOL_VERSION) { - if(!showonlygoodservers) s_sprintf(si.full)("%s:%d [%s]", si.name, si.port, si.protocol<0 ? "modded version" : (si.protocol -1) favimage = getalias(favcatargname(favcats[si.favcat], FC_IMAGE)); filterrichtext(text, si.favcat > -1 && !favimage ? favcattags[si.favcat] : ""); - if(showweights) s_strcatf(text, "(%d)", si.weight); - s_sprintf(si.full)(showfavtag ? (favimage ? "\t" : "\fs%s\fr\t") : "", text); - s_strcatf(si.full, "\fs\f%c%d\t\fs\f%c%d/%d\fr\t\a%c ", basecolor, si.ping, plnumcolor, si.numplayers, si.maxclients, '0' + si.uplinkqual); + if(showweights) concatformatstring(text, "(%d)", si.weight); + formatstring(si.full)(showfavtag ? (favimage ? "\t" : "\fs%s\fr\t") : "", text); + concatformatstring(si.full, "\fs\f%c%d\t\fs\f%c%d/%d\fr\t\a%c ", basecolor, si.ping, plnumcolor, si.numplayers, si.maxclients, '0' + si.uplinkqual); if(si.map[0]) { - s_strcatf(si.full, "%s, %s", si.map, modestr(si.mode, modeacronyms > 0)); - if(showmr) s_strcatf(si.full, ", (%d)", si.minremain); + concatformatstring(si.full, "%s, %s", si.map, modestr(si.mode, modeacronyms > 0)); + if(showmr) concatformatstring(si.full, ", (%d)", si.minremain); } - else s_strcatf(si.full, "empty"); - s_strcatf(si.full, serverbrowserhideip < 2 ? ": \fs%s%s:%d\fr" : ": ", serverbrowserhideip == 1 ? "\f4" : "", si.name, si.port); - s_strcatf(si.full, "\fr %s", si.sdesc); + else concatformatstring(si.full, "empty"); + concatformatstring(si.full, serverbrowserhideip < 2 ? ": \fs%s%s:%d\fr" : ": ", serverbrowserhideip == 1 ? "\f4" : "", si.name, si.port); + concatformatstring(si.full, "\fr %s", si.sdesc); } } else { - if(!showonlygoodservers) s_sprintf(si.full)(si.address.host != ENET_HOST_ANY ? "%s:%d [waiting for server response]" : "%s:%d [unknown host]", si.name, si.port); + if(!showonlygoodservers) formatstring(si.full)(si.address.host != ENET_HOST_ANY ? "%s:%d [waiting for server response]" : "%s:%d [unknown host]", si.name, si.port); else showthisone = false; } if(issearch && showthisone) @@ -1084,9 +1084,9 @@ void refreshservers(void *menu, bool init) filtertext(text, si.sdesc); for(char *p = text; (p = strchr(p, '\"')); *p++ = ' '); text[30] = '\0'; - s_sprintf(si.cmd)("sbconnect %s %d %d %d %d %d \"%s\"", si.name, si.port, serverfull ?1:0, needspasswd ?1:0, mmode, banned, text); + formatstring(si.cmd)("sbconnect %s %d %d %d %d %d \"%s\"", si.name, si.port, serverfull ?1:0, needspasswd ?1:0, mmode, banned, text); } - else s_sprintf(si.cmd)("connect %s %d", si.name, si.port); + else formatstring(si.cmd)("connect %s %d", si.name, si.port); menuimagemanual(menu, favimage, "serverquality", si.full, si.cmd, si.bgcolor, si.description); if(!issearch && servers[i] == oldsel) { @@ -1104,9 +1104,9 @@ void refreshservers(void *menu, bool init) { if(namelists.length() < ++curnl) namelists.add(newstringbuf()); t = namelists[curnl - 1]; - s_strcpy(t, showfavtag ? "\t\t" : "\t"); + copystring(t, showfavtag ? "\t\t" : "\t"); } - s_strcatf(t, " \t\fs%s%s\fr", !issearch || matchplayername(si.playernames[j]) ? "" : "\f4" ,si.playernames[j]); + concatformatstring(t, " \t\fs%s%s\fr", !issearch || matchplayername(si.playernames[j]) ? "" : "\f4" ,si.playernames[j]); cur++; if(cur == 4) { @@ -1124,14 +1124,14 @@ void refreshservers(void *menu, bool init) { if(curnl == 0) { - s_sprintf(notfoundmsg)("\t\tpattern \fs\f3%s\fr not found.", cursearch); + formatstring(notfoundmsg)("\t\tpattern \fs\f3%s\fr not found.", cursearch); menumanual(menu, notfoundmsg, NULL, NULL, NULL); } } else if(!((gmenu *)menu)->items.length() && showonlyfavourites && favcats.inrange(showonlyfavourites - 1)) { const char *desc = getalias(favcatargname(favcats[showonlyfavourites - 1], FC_DESC)); - s_sprintf(notfoundmsg)("no servers in category \f2%s", desc ? desc : favcattags[showonlyfavourites - 1]); + formatstring(notfoundmsg)("no servers in category \f2%s", desc ? desc : favcattags[showonlyfavourites - 1]); menumanual(menu, notfoundmsg, NULL, NULL, NULL); } } @@ -1160,7 +1160,7 @@ bool serverskey(void *menu, int code, bool isdown, int unicode) } else { // add IP:port to group - s_sprintfd(text)("%s:%d", servers[j]->name, servers[j]->port); + defformatstring(text)("%s:%d", servers[j]->name, servers[j]->port); if(key && *key) { char *newkey = newstring(key, strlen(text) + 1 + strlen(key)); @@ -1285,9 +1285,9 @@ void updatefrommaster(int force) string curname, curport, curweight; if(curserver) { - s_strcpy(curname, curserver->name); - s_sprintf(curport)("%d", curserver->port); - s_sprintf(curweight)("%d", curserver->msweight); + copystring(curname, curserver->name); + formatstring(curport)("%d", curserver->port); + formatstring(curweight)("%d", curserver->msweight); } clearservers(); diff --git a/source/src/servercontroller.h b/source/src/servercontroller.h index 31adc79c..27634561 100644 --- a/source/src/servercontroller.h +++ b/source/src/servercontroller.h @@ -93,8 +93,8 @@ struct winservice : servercontroller if(argv && argv[0]) { string procpath; - s_strcpy(procpath, parentdir(argv[0])); - s_strcpy(procpath, parentdir(procpath)); + copystring(procpath, parentdir(argv[0])); + copystring(procpath, parentdir(procpath)); SetCurrentDirectory((LPSTR)procpath); } diff --git a/source/src/serverfiles.h b/source/src/serverfiles.h index 90103845..14e63c00 100644 --- a/source/src/serverfiles.h +++ b/source/src/serverfiles.h @@ -39,17 +39,17 @@ struct servermapbuffer // sending of maps between clients const char *name = behindpath(smapname); // no paths allowed here clear(); - s_sprintf(cgzname)(SERVERMAP_PATH "%s.cgz", name); + formatstring(cgzname)(SERVERMAP_PATH "%s.cgz", name); path(cgzname); if(fileexists(cgzname, "r")) { - s_sprintf(cfgname)(SERVERMAP_PATH "%s.cfg", name); + formatstring(cfgname)(SERVERMAP_PATH "%s.cfg", name); } else { - s_sprintf(cgzname)(SERVERMAP_PATH_INCOMING "%s.cgz", name); + formatstring(cgzname)(SERVERMAP_PATH_INCOMING "%s.cgz", name); path(cgzname); - s_sprintf(cfgname)(SERVERMAP_PATH_INCOMING "%s.cfg", name); + formatstring(cfgname)(SERVERMAP_PATH_INCOMING "%s.cfg", name); } path(cfgname); uchar *cgzdata = (uchar *)loadfile(cgzname, &cgzsize); @@ -65,7 +65,7 @@ struct servermapbuffer // sending of maps between clients cfgsizegz = (int) gzbufsize; if(cgzsize + cfgsizegz < MAXMAPSENDSIZE) { // map is ok, fill buffer - s_strcpy(mapname, name); + copystring(mapname, name); datasize = cgzsize + cfgsizegz; data = new uchar[datasize]; memcpy(data, cgzdata, cgzsize); @@ -85,7 +85,7 @@ struct servermapbuffer // sending of maps between clients if(!nmapname[0] || nmapsize <= 0 || ncfgsizegz < 0 || nmapsize + ncfgsizegz > MAXMAPSENDSIZE || ncfgsize > MAXCFGFILESIZE) return false; // malformed: probably modded client if(smode == GMODE_COOPEDIT && !strcmp(nmapname, behindpath(smapname))) { // update mapbuffer only in coopedit mode (and on same map) - s_strcpy(mapname, nmapname); + copystring(mapname, nmapname); cgzsize = nmapsize; cfgsize = ncfgsize; cfgsizegz = ncfgsizegz; @@ -96,14 +96,14 @@ struct servermapbuffer // sending of maps between clients memcpy(data, ndata, datasize); } - s_sprintfd(name)(SERVERMAP_PATH_INCOMING "%s.cgz", nmapname); + defformatstring(name)(SERVERMAP_PATH_INCOMING "%s.cgz", nmapname); path(name); fp = fopen(name, "wb"); if(fp) { fwrite(ndata, 1, nmapsize, fp); fclose(fp); - s_sprintf(name)(SERVERMAP_PATH_INCOMING "%s.cfg", nmapname); + formatstring(name)(SERVERMAP_PATH_INCOMING "%s.cfg", nmapname); path(name); fp = fopen(name, "wb"); if(fp) @@ -149,24 +149,24 @@ int findmappath(const char *mapname, char *filename) if(!filename) filename = tempname; const char *name = behindpath(mapname); if(!mapname[0]) return MAP_NOTFOUND; - s_sprintf(filename)(SERVERMAP_PATH_BUILTIN "%s.cgz", name); + formatstring(filename)(SERVERMAP_PATH_BUILTIN "%s.cgz", name); path(filename); int loc = MAP_NOTFOUND; if(getfilesize(filename) > 10) loc = MAP_OFFICIAL; else { #ifndef STANDALONE - s_strcpy(filename, setnames(name)); + copystring(filename, setnames(name)); if(!isdedicated && getfilesize(filename) > 10) loc = MAP_LOCAL; else { #endif - s_sprintf(filename)(SERVERMAP_PATH "%s.cgz", name); + formatstring(filename)(SERVERMAP_PATH "%s.cgz", name); path(filename); if(isdedicated && getfilesize(filename) > 10) loc = MAP_CUSTOM; else { - s_sprintf(filename)(SERVERMAP_PATH_INCOMING "%s.cgz", name); + formatstring(filename)(SERVERMAP_PATH_INCOMING "%s.cgz", name); path(filename); if(isdedicated && getfilesize(filename) > 10) loc = MAP_TEMP; } @@ -192,7 +192,7 @@ mapstats *getservermapstats(const char *mapname, bool getlayout, int *maploc) void serverconfigfile::init(const char *name) { - s_strcpy(filename, name); + copystring(filename, name); path(filename); read(); } @@ -259,7 +259,7 @@ struct servermaprot : serverconfigfile l = strtok(l, sep); if(l) { - s_strcpy(c.mapname, behindpath(l)); + copystring(c.mapname, behindpath(l)); for(i = 3; i < CONFIG_MAXPAR; i++) c.par[i] = 0; // default values for(i = 0; i < CONFIG_MAXPAR; i++) { @@ -284,7 +284,7 @@ struct servermaprot : serverconfigfile #ifndef STANDALONE if(!isdedicated) { - s_sprintfd(nextmapalias)("nextmap_%s", getclientmap()); + defformatstring(nextmapalias)("nextmap_%s", getclientmap()); const char *map = getalias(nextmapalias); // look up map in the cycle startgame(map && notify ? map : getclientmap(), getclientmode(), -1, notify); return -1; @@ -495,8 +495,8 @@ struct servernickblacklist : serverconfigfile for(int i = idx; i >= 0; i = whitelistranges[i].next) { iprchain &ic = whitelistranges[i]; - if(ic.pwd) s_strcatf(text, " pwd:\"%s\"", hiddenpwd(ic.pwd)); - else s_strcatf(text, " %s", iprtoa(ic.ipr)); + if(ic.pwd) concatformatstring(text, " pwd:\"%s\"", hiddenpwd(ic.pwd)); + else concatformatstring(text, " %s", iprtoa(ic.ipr)); } logline(ACLOG_VERBOSE, " accept %s%s", key, text); }); @@ -507,7 +507,7 @@ struct servernickblacklist : serverconfigfile loopj(MAXNICKFRAGMENTS) { int k = blacklines[i].frag[j]; - if(k >= 0) { s_strcat(text, " "); s_strcat(text, blfraglist[k]); } + if(k >= 0) { concatstring(text, " "); concatstring(text, blfraglist[k]); } } logline(ACLOG_VERBOSE, " %2d block%s%s", blacklines[i].line, blacklines[i].ignorecase ? "i" : "", text); } @@ -547,7 +547,7 @@ struct servernickblacklist : serverconfigfile { if(blacklines.empty()) return -2; // no nickname blacklist loaded string nameuc; - s_strcpy(nameuc, name); + copystring(nameuc, name); strtoupper(nameuc); loopv(blacklines) { @@ -588,7 +588,7 @@ struct serverpasswords : serverconfigfile if(cmdlinepass[0]) { pwddetail c; - s_strcpy(c.pwd, cmdlinepass); + copystring(c.pwd, cmdlinepass); c.line = 0; // commandline is 'line 0' c.denyadmin = false; adminpwds.add(c); @@ -614,7 +614,7 @@ struct serverpasswords : serverconfigfile l = strtok(l, sep); if(l) { - s_strcpy(c.pwd, l); + copystring(c.pwd, l); par[0] = 0; // default values for(i = 0; i < ADMINPWD_MAXPAR; i++) { @@ -665,7 +665,7 @@ struct serverinfofile char *readinfofile(const char *fnbase, const char *lang) { - s_sprintfd(fname)("%s_%s.txt", fnbase, lang); + defformatstring(fname)("%s_%s.txt", fnbase, lang); path(fname); int len, n; char *c, *s, *t, *buf = loadfile(fname, &len); @@ -712,7 +712,7 @@ struct serverinfofile { char *c = s->info; while(*c) { c += strlen(c); if(c[1]) *c++ = '\n'; } - if(strlen(s->info) > _MAXDEFSTR) s->info[_MAXDEFSTR] = '\0'; // keep MOTD at sane lengths + if(strlen(s->info) > MAXSTRLEN) s->info[MAXSTRLEN] = '\0'; // keep MOTD at sane lengths } return s->info; } diff --git a/source/src/serverms.cpp b/source/src/serverms.cpp index 3072dee8..ada93054 100644 --- a/source/src/serverms.cpp +++ b/source/src/serverms.cpp @@ -35,7 +35,7 @@ ENetSocket httpgetsend(ENetAddress &remoteaddress, const char *hostname, const c return ENET_SOCKET_NULL; } ENetBuffer buf; - s_sprintfd(httpget)("GET %s HTTP/1.0\nHost: %s\nReferer: %s\nUser-Agent: %s\n\n", req, hostname, ref, agent); + defformatstring(httpget)("GET %s HTTP/1.0\nHost: %s\nReferer: %s\nUser-Agent: %s\n\n", req, hostname, ref, agent); buf.data = httpget; buf.dataLength = strlen((char *)buf.data); logline(ACLOG_INFO, "sending request to %s...", hostname); @@ -83,8 +83,8 @@ void updatemasterserver(int millis, const ENetAddress &localaddr) { if(!millis || millis/(60*60*1000)!=lastupdatemaster) { - s_sprintfd(path)("%sregister.do?action=add&port=%d", masterpath, localaddr.port); - s_sprintfd(agent)("AssaultCube Server %d", AC_VERSION); + defformatstring(path)("%sregister.do?action=add&port=%d", masterpath, localaddr.port); + defformatstring(agent)("AssaultCube Server %d", AC_VERSION); mssock = httpgetsend(masterserver, masterbase, path, "assaultcubeserver", agent, &msaddress); masterrep[0] = 0; masterb.data = masterrep; @@ -112,15 +112,15 @@ uchar *retrieveservers(uchar *buf, int buflen) { buf[0] = '\0'; - s_sprintfd(path)("%sretrieve.do?item=list", masterpath); - s_sprintfd(agent)("AssaultCube Client %d", AC_VERSION); + defformatstring(path)("%sretrieve.do?item=list", masterpath); + defformatstring(agent)("AssaultCube Client %d", AC_VERSION); ENetAddress address = masterserver; ENetSocket sock = httpgetsend(address, masterbase, path, "assaultcubeclient", agent); if(sock==ENET_SOCKET_NULL) return buf; /* only cache this if connection succeeds */ masterserver = address; - s_sprintfd(text)("retrieving servers from %s... (esc to abort)", masterbase); + defformatstring(text)("retrieving servers from %s... (esc to abort)", masterbase); show_out_of_renderloop_progress(0, text); ENetBuffer eb; @@ -297,9 +297,9 @@ void serverms(int mode, int numplayers, int minremain, char *smapname, int milli void servermsinit(const char *master, const char *ip, int infoport, bool listen) { const char *mid = strstr(master, "/"); - if(mid) s_strncpy(masterbase, master, mid-master+1); - else s_strcpy(masterbase, (mid = master)); - s_strcpy(masterpath, mid); + if(mid) copystring(masterbase, master, mid-master+1); + else copystring(masterbase, (mid = master)); + copystring(masterpath, mid); if(listen) { diff --git a/source/src/texture.cpp b/source/src/texture.cpp index 2e068f26..8f595ac9 100644 --- a/source/src/texture.cpp +++ b/source/src/texture.cpp @@ -228,7 +228,7 @@ GLuint loadsurface(const char *texname, int &xs, int &ys, int &bpp, int clamp = Texture *textureload(const char *name, int clamp, bool mipmap, bool canreduce) { string pname; - s_strcpy(pname, name); + copystring(pname, name); path(pname); Texture *t = textures.access(pname); if(t) return t; @@ -262,7 +262,7 @@ void texturereset() { slots.setsizenodelete(0); } void texture(char *aframe, char *name) { Slot &s = slots.add(); - s_strcpy(s.name, name); + copystring(s.name, name); path(s.name); s.tex = NULL; s.loaded = false; @@ -279,7 +279,7 @@ Texture *lookuptexture(int tex, Texture *failtex) Slot &s = slots[tex]; if(!s.loaded) { - s_sprintfd(pname)("packages/textures/%s", s.name); + defformatstring(pname)("packages/textures/%s", s.name); s.tex = textureload(pname, 0, true, true); if(s.tex==notexture) s.tex = failtex; s.loaded = true; @@ -326,7 +326,7 @@ void loadsky(char *basename) const char *side[] = { "lf", "rt", "ft", "bk", "dn", "up" }; loopi(6) { - s_sprintfd(name)("packages/%s_%s.jpg", basename, side[i]); + defformatstring(name)("packages/%s_%s.jpg", basename, side[i]); sky[i] = textureload(name, 3); if(!sky[i]) conoutf("could not load sky texture: %s", name); } @@ -339,7 +339,7 @@ void loadnotexture(char *c) noworldtexture = notexture; // reset to default if(c[0]) { - s_sprintfd(p)("packages/textures/%s", c); + defformatstring(p)("packages/textures/%s", c); noworldtexture = textureload(p); if(noworldtexture==notexture) conoutf("could not load alternative texture '%s'.", p); } diff --git a/source/src/tools.cpp b/source/src/tools.cpp index 2f4ebd16..4dbc9efb 100644 --- a/source/src/tools.cpp +++ b/source/src/tools.cpp @@ -57,7 +57,7 @@ const char *asctime() const char *numtime() { static string numt; - s_sprintf(numt)("%ld", (long long) time(NULL)); + formatstring(numt)("%ld", (long long) time(NULL)); return numt; } @@ -87,7 +87,7 @@ char *path(char *s) char *path(const char *s, bool copy) { static string tmp; - s_strcpy(tmp, s); + copystring(tmp, s); path(tmp); return tmp; } @@ -106,7 +106,7 @@ const char *parentdir(const char *directory) if(!p) p = directory; static string parent; size_t len = p-directory+1; - s_strncpy(parent, directory, len); + copystring(parent, directory, len); return parent; } @@ -128,7 +128,7 @@ bool createdir(const char *path) if(path[len-1]==PATHDIV) { static string strip; - path = s_strncpy(strip, path, len); + path = copystring(strip, path, len); } #ifdef WIN32 return CreateDirectory(path, NULL)!=0; @@ -151,7 +151,7 @@ static void fixdir(char *dir) void sethomedir(const char *dir) { string tmpdir; - s_strcpy(tmpdir, dir); + copystring(tmpdir, dir); #ifdef WIN32 const char substitute[] = "?MYDOCUMENTS?"; @@ -161,7 +161,7 @@ void sethomedir(const char *dir) char *mydocuments = getregszvalue(HKEY_CURRENT_USER, regpath, "Personal"); if(mydocuments) { - s_sprintf(tmpdir)("%s%s", mydocuments, dir+strlen(substitute)); + formatstring(tmpdir)("%s%s", mydocuments, dir+strlen(substitute)); delete[] mydocuments; } else @@ -174,7 +174,7 @@ void sethomedir(const char *dir) #ifndef STANDALONE clientlogf("Using home directory: %s", tmpdir); #endif - fixdir(s_strcpy(homedir, tmpdir)); + fixdir(copystring(homedir, tmpdir)); createdir(homedir); } @@ -191,12 +191,12 @@ const char *findfile(const char *filename, const char *mode) static string s; if(homedir[0]) { - s_sprintf(s)("%s%s", homedir, filename); + formatstring(s)("%s%s", homedir, filename); if(fileexists(s, mode)) return s; if(mode[0]=='w' || mode[0]=='a') { string dirs; - s_strcpy(dirs, s); + copystring(dirs, s); char *dir = strchr(dirs[0]==PATHDIV ? dirs+1 : dirs, PATHDIV); while(dir) { @@ -211,7 +211,7 @@ const char *findfile(const char *filename, const char *mode) if(mode[0]=='w' || mode[0]=='a') return filename; loopv(packagedirs) { - s_sprintf(s)("%s%s", packagedirs[i], filename); + formatstring(s)("%s%s", packagedirs[i], filename); if(fileexists(s, mode)) return s; } return filename; @@ -275,7 +275,7 @@ bool listdir(const char *dir, const char *ext, vector &files) { int extsize = ext ? (int)strlen(ext)+1 : 0; #if defined(WIN32) - s_sprintfd(pathname)("%s\\*.%s", dir, ext ? ext : "*"); + defformatstring(pathname)("%s\\*.%s", dir, ext ? ext : "*"); WIN32_FIND_DATA FindFileData; HANDLE Find = FindFirstFile(path(pathname), &FindFileData); if(Find != INVALID_HANDLE_VALUE) @@ -287,7 +287,7 @@ bool listdir(const char *dir, const char *ext, vector &files) } #else string pathname; - s_strcpy(pathname, dir); + copystring(pathname, dir); DIR *d = opendir(path(pathname)); if(d) { @@ -316,12 +316,12 @@ int listfiles(const char *dir, const char *ext, vector &files) string s; if(homedir[0]) { - s_sprintf(s)("%s%s", homedir, dir); + formatstring(s)("%s%s", homedir, dir); if(listdir(s, ext, files)) dirs++; } loopv(packagedirs) { - s_sprintf(s)("%s%s", packagedirs[i], dir); + formatstring(s)("%s%s", packagedirs[i], dir); if(listdir(s, ext, files)) dirs++; } return dirs; @@ -361,7 +361,7 @@ mapstats *loadmapstats(const char *filename, bool getlayout) else s.hdr.waterlevel = -100000; if(s.hdr.version<7) { - s_strncpy(s.hdr.mediareq, "", 128);//s.hdr.mediareq[0] = '\0'; + copystring(s.hdr.mediareq, "", 128);//s.hdr.mediareq[0] = '\0'; } entity e; enttypes = new uchar[s.hdr.numents]; @@ -448,7 +448,7 @@ void stackdumper(unsigned int type, EXCEPTION_POINTERS *ep) EXCEPTION_RECORD *er = ep->ExceptionRecord; CONTEXT *context = ep->ContextRecord; string out, t; - s_sprintf(out)("Win32 Exception: 0x%x [0x%x]\n\n", er->ExceptionCode, er->ExceptionCode==EXCEPTION_ACCESS_VIOLATION ? er->ExceptionInformation[1] : -1); + formatstring(out)("Win32 Exception: 0x%x [0x%x]\n\n", er->ExceptionCode, er->ExceptionCode==EXCEPTION_ACCESS_VIOLATION ? er->ExceptionInformation[1] : -1); STACKFRAME sf = {{context->Eip, 0, AddrModeFlat}, {}, {context->Ebp, 0, AddrModeFlat}, {context->Esp, 0, AddrModeFlat}, 0}; SymInitialize(GetCurrentProcess(), NULL, TRUE); @@ -460,8 +460,8 @@ void stackdumper(unsigned int type, EXCEPTION_POINTERS *ep) if(SymGetSymFromAddr(GetCurrentProcess(), (DWORD)sf.AddrPC.Offset, &off, &si.sym) && SymGetLineFromAddr(GetCurrentProcess(), (DWORD)sf.AddrPC.Offset, &off, &li)) { char *del = strrchr(li.FileName, '\\'); - s_sprintf(t)("%s - %s [%d]\n", si.sym.Name, del ? del + 1 : li.FileName, li.LineNumber); - s_strcat(out, t); + formatstring(t)("%s - %s [%d]\n", si.sym.Name, del ? del + 1 : li.FileName, li.LineNumber); + concatstring(out, t); } } fatal("%s", out); @@ -609,7 +609,7 @@ const char *iptoa(const enet_uint32 ip) static string s[2]; static int buf = 0; buf = (buf + 1) % 2; - s_sprintf(s[buf])("%d.%d.%d.%d", (ip >> 24) & 255, (ip >> 16) & 255, (ip >> 8) & 255, ip & 255); + formatstring(s[buf])("%d.%d.%d.%d", (ip >> 24) & 255, (ip >> 16) & 255, (ip >> 8) & 255, ip & 255); return s[buf]; } @@ -618,8 +618,8 @@ const char *iprtoa(const struct iprange &ipr) static string s[2]; static int buf = 0; buf = (buf + 1) % 2; - if(ipr.lr == ipr.ur) s_strcpy(s[buf], iptoa(ipr.lr)); - else s_sprintf(s[buf])("%s-%s", iptoa(ipr.lr), iptoa(ipr.ur)); + if(ipr.lr == ipr.ur) copystring(s[buf], iptoa(ipr.lr)); + else formatstring(s[buf])("%s-%s", iptoa(ipr.lr), iptoa(ipr.ur)); return s[buf]; } @@ -635,17 +635,17 @@ int cmpipmatch(const struct iprange *a, const struct iprange *b) return - (a->lr < b->lr) + (a->lr > b->ur); } -char *s_strcatf(char *d, const char *s, ...) +char *concatformatstring(char *d, const char *s, ...) { - static s_sprintfdv(temp, s); - return s_strcat(d, temp); + static defvformatstring(temp, s, s); + return concatstring(d, temp); } const char *hiddenpwd(const char *pwd, int showchars) { static int sc = 3; static string text; - s_strcpy(text, pwd); + copystring(text, pwd); if(showchars > 0) sc = showchars; for(int i = (int)strlen(text) - 1; i >= sc; i--) text[i] = '*'; return text; diff --git a/source/src/tools.h b/source/src/tools.h index c2c6f1b1..3b58276d 100644 --- a/source/src/tools.h +++ b/source/src/tools.h @@ -101,32 +101,35 @@ static inline float round(float x) { return floor(x + 0.5f); } // easy safe strings -#define _MAXDEFSTR 260 -typedef char string[_MAXDEFSTR]; +#define MAXSTRLEN 260 +typedef char string[MAXSTRLEN]; -inline void formatstring(char *d, const char *fmt, va_list v) { _vsnprintf(d, _MAXDEFSTR, fmt, v); d[_MAXDEFSTR-1] = 0; } -inline char *s_strncpy(char *d, const char *s, size_t m) { strncpy(d,s,m); d[m-1] = 0; return d; } -inline char *s_strcpy(char *d, const char *s) { return s_strncpy(d,s,_MAXDEFSTR); } -inline char *s_strcat(char *d, const char *s) { size_t n = strlen(d); return s_strncpy(d+n,s,_MAXDEFSTR-n); } -extern char *s_strcatf(char *d, const char *s, ...); +inline void vformatstring(char *d, const char *fmt, va_list v, int len = MAXSTRLEN) { _vsnprintf(d, len, fmt, v); d[len-1] = 0; } +inline char *copystring(char *d, const char *s, size_t len = MAXSTRLEN) { strncpy(d, s, len); d[len-1] = 0; return d; } +inline char *concatstring(char *d, const char *s) { size_t len = strlen(d); return copystring(d+len, s, MAXSTRLEN-len); } +extern char *concatformatstring(char *d, const char *s, ...); -struct s_sprintf_f +struct stringformatter { - char *d; - s_sprintf_f(char *str) : d(str) {} - void operator()(const char* fmt, ...) + char *buf; + stringformatter(char *buf): buf((char *)buf) {} + void operator()(const char *fmt, ...) { va_list v; va_start(v, fmt); - formatstring(d, fmt, v); + vformatstring(buf, fmt, v); va_end(v); - }; + } }; -#define s_sprintf(d) s_sprintf_f((char *)d) -#define s_sprintfd(d) string d; s_sprintf(d) -#define s_sprintfdlv(d,last,fmt) string d; { va_list ap; va_start(ap, last); formatstring(d, fmt, ap); va_end(ap); } -#define s_sprintfdv(d,fmt) s_sprintfdlv(d,fmt,fmt) +#define formatstring(d) stringformatter((char *)d) +#define defformatstring(d) string d; formatstring(d) +#define defvformatstring(d,last,fmt) string d; { va_list ap; va_start(ap, last); vformatstring(d, fmt, ap); va_end(ap); } + +//#define s_sprintf(d) s_sprintf_f((char *)d) +//#define s_sprintfd(d) string d; s_sprintf(d) +//#define s_sprintfdlv(d,last,fmt) string d; { va_list ap; va_start(ap, last); formatstring(d, fmt, ap); va_end(ap); } +//#define s_sprintfdv(d,fmt) s_sprintfdlv(d,fmt,fmt) #define loopv(v) if(false) {} else for(int i = 0; i<(v).length(); i++) #define loopvj(v) if(false) {} else for(int j = 0; j<(v).length(); j++) @@ -635,10 +638,10 @@ struct stopwatch #endif inline char *newstring(size_t l) { return new char[l+1]; } -inline char *newstring(const char *s, size_t l) { return s_strncpy(newstring(l), s, l+1); } +inline char *newstring(const char *s, size_t l) { return copystring(newstring(l), s, l+1); } inline char *newstring(const char *s) { return newstring(s, strlen(s)); } -inline char *newstringbuf() { return newstring(_MAXDEFSTR-1); } -inline char *newstringbuf(const char *s) { return newstring(s, _MAXDEFSTR-1); } +inline char *newstringbuf() { return newstring(MAXSTRLEN-1); } +inline char *newstringbuf(const char *s) { return newstring(s, MAXSTRLEN-1); } inline const char *_gettext(const char *msgid) { diff --git a/source/src/vertmodel.h b/source/src/vertmodel.h index ec7b1d4d..8334f7b3 100644 --- a/source/src/vertmodel.h +++ b/source/src/vertmodel.h @@ -1000,7 +1000,7 @@ struct vertmodel : model #if 0 SDL_Surface *img = SDL_CreateRGBSurface(SDL_SWSURFACE, aasize, aasize, 24, 0x0000FF, 0x00FF00, 0xFF0000, 0); loopi(aasize*aasize) memset((uchar *)img->pixels + 3*i, pixels[i], 3); - s_sprintfd(imgname)("%s_%d.bmp", model->loadname, frame); + defformatstring(imgname)("%s_%d.bmp", model->loadname, frame); for(char *s; (s = strchr(imgname, '/'));) *s = '_'; SDL_SaveBMP(img, imgname); SDL_FreeSurface(img); @@ -1180,8 +1180,8 @@ struct vertmodel : model static string s; char *dir = strrchr(filename, PATHDIV); if(!dir) s[0] = '\0'; - else s_strncpy(s, filename, dir-filename+2); - s_strcat(s, "shadows.dat"); + else copystring(s, filename, dir-filename+2); + concatstring(s, "shadows.dat"); return s; } diff --git a/source/src/weapon.cpp b/source/src/weapon.cpp index 302b8992..dd1b2f93 100644 --- a/source/src/weapon.cpp +++ b/source/src/weapon.cpp @@ -416,13 +416,13 @@ void renderbounceents() switch(p->bouncetype) { case BT_NADE: - s_strcpy(model, "weapons/grenade/static"); + copystring(model, "weapons/grenade/static"); break; case BT_GIB: default: { uint n = (((4*(uint)(size_t)p)+(uint)p->timetolive)%3)+1; - s_sprintf(model)("misc/gib0%u", n); + formatstring(model)("misc/gib0%u", n); int t = lastmillis-p->millis; if(t>p->timetolive-2000) { @@ -646,7 +646,7 @@ void weapon::renderhudmodel(int lastaction, int index) weaponmove wm; if(!intermission) wm.calcmove(unitv, lastaction); - s_sprintfd(path)("weapons/%s", info.modelname); + defformatstring(path)("weapons/%s", info.modelname); bool emit = (wm.anim&ANIM_INDEX)==ANIM_GUN_SHOOT && (lastmillis - lastaction) < flashtime(); int rindex = (righthanded) ? index : (index ? 0 : 1); rendermodel(path, wm.anim|ANIM_DYNALLOC|(rindex ? ANIM_MIRROR : 0)|(emit ? ANIM_PARTICLE : 0), 0, -1, wm.pos, player1->yaw+90, player1->pitch+wm.k_rot, 40.0f, wm.basetime, NULL, NULL, 1.28f); diff --git a/source/src/world.cpp b/source/src/world.cpp index fa508fb9..f84cc866 100644 --- a/source/src/world.cpp +++ b/source/src/world.cpp @@ -457,8 +457,8 @@ bool empty_world(int factor, bool force) // main empty world creation routine } else { - s_strncpy(hdr.maptitle, "Untitled Map by Unknown", 128); - s_strncpy(hdr.mediareq, "", 128); // MediaPack + copystring(hdr.maptitle, "Untitled Map by Unknown", 128); + copystring(hdr.mediareq, "", 128); // MediaPack hdr.waterlevel = -100000; setwatercolor(); loopi(sizeof(hdr.reserved)/sizeof(hdr.reserved[0])) hdr.reserved[i] = 0; diff --git a/source/src/worldio.cpp b/source/src/worldio.cpp index fef09668..062f90f9 100644 --- a/source/src/worldio.cpp +++ b/source/src/worldio.cpp @@ -5,7 +5,7 @@ void backup(char *name, char *backupname) { string backupfile; - s_strcpy(backupfile, findfile(backupname, "wb")); + copystring(backupfile, findfile(backupname, "wb")); remove(backupfile); rename(findfile(name, "wb"), backupfile); } @@ -19,20 +19,20 @@ const char *setnames(const char *name) const char *slash = strpbrk(name, "/\\"); if(slash) { - s_strncpy(pakname, name, slash-name+1); - s_strcpy(mapname, slash+1); + copystring(pakname, name, slash-name+1); + copystring(mapname, slash+1); } else { - s_strcpy(pakname, "maps"); - s_strcpy(mapname, name); + copystring(pakname, "maps"); + copystring(mapname, name); } - s_sprintf(cgzname)("packages/%s/%s.cgz", pakname, mapname); - s_sprintf(ocgzname)("packages/maps/official/%s.cgz", mapname); - s_sprintf(bakname)("packages/%s/%s_%s.BAK", pakname, mapname, numtime()); - s_sprintf(pcfname)("packages/%s/package.cfg", pakname); - s_sprintf(mcfname)("packages/%s/%s.cfg", pakname, mapname); - s_sprintf(omcfname)("packages/maps/official/%s.cfg", mapname); + formatstring(cgzname)("packages/%s/%s.cgz", pakname, mapname); + formatstring(ocgzname)("packages/maps/official/%s.cgz", mapname); + formatstring(bakname)("packages/%s/%s_%s.BAK", pakname, mapname, numtime()); + formatstring(pcfname)("packages/%s/package.cfg", pakname); + formatstring(mcfname)("packages/%s/%s.cfg", pakname, mapname); + formatstring(omcfname)("packages/maps/official/%s.cfg", mapname); path(cgzname); path(bakname); @@ -194,13 +194,13 @@ void checkmapdependencies(bool silent = false) // find required MediaPack (s) fo // well, the "goodname" can still contain the users home-dir #define USEFILENAME(fmtp2f,fname,count) \ { \ - s_sprintfd(basename)(fmtp2f, fname); \ - s_strcpy(goodname, findfile(path(basename), "r")); \ + defformatstring(basename)(fmtp2f, fname); \ + copystring(goodname, findfile(path(basename), "r")); \ int *n = mufpaths.access(goodname); \ if(!n) { n = &mufpaths.access(newstring(goodname), -1); if(fileexists(goodname, "r")) *n = 0; } \ if(*n >= 0) *n += count; \ const char *pt = strstr(goodname, basename); \ - s_strncpy(modname, goodname, pt - goodname + 1); \ + copystring(modname, goodname, pt - goodname + 1); \ if(goodname != pt && !usedmods.access(modname)) usedmods.access(newstring(modname), 0); \ } // skybox textures @@ -271,7 +271,7 @@ void checkmapdependencies(bool silent = false) // find required MediaPack (s) fo // used mods int usedm = 0; allmods[0] = '\0'; - enumeratek(usedmods, const char *, key, s_strcatf(allmods, "%s%s",*allmods ? ", " : "", key); delete key; usedm++); + enumeratek(usedmods, const char *, key, concatformatstring(allmods, "%s%s",*allmods ? ", " : "", key); delete key; usedm++); extern string clientmap; if(!silent) conoutf("used: %s%s %d total packages (%s.cfg)", allmods, usedm ? ", " : "", usedm, clientmap); // mediapacks @@ -279,7 +279,7 @@ void checkmapdependencies(bool silent = false) // find required MediaPack (s) fo int *packn = new int[usedf]; loopi(usedf) packn[i] = -2; // -2: unset, -1: local-only, 0: release, 1..n: i in loopv(mpdefs) int idx; - s_strcpy(reqmpak, ""); + copystring(reqmpak, ""); reqmpak[0] = '\0'; // First check releasefiles int mpfl; @@ -305,7 +305,7 @@ void checkmapdependencies(bool silent = false) // find required MediaPack (s) fo { bool usethis = false; int mpfl; - s_sprintfd(p2mpdf)("packages/mediapack/%s.txt", mpdefs[j]); + defformatstring(p2mpdf)("packages/mediapack/%s.txt", mpdefs[j]); char* mpfc = loadfile(p2mpdf, &mpfl, "r"); if(mpfc) { @@ -324,7 +324,7 @@ void checkmapdependencies(bool silent = false) // find required MediaPack (s) fo packn[idx] = j + 1; if(!usethis) { - s_sprintf(reqmpak)("%s%s%s", reqmpak, reqmpak[0]=='\0'?"":",", mpdefs[j]); + formatstring(reqmpak)("%s%s%s", reqmpak, reqmpak[0]=='\0'?"":",", mpdefs[j]); if(++usedmpaks > 0) usethis = true; if(usedmpaks>25) conoutf("this map requires too many mediapacks."); // even if silent == true } @@ -354,7 +354,7 @@ void save_world(char *mname) backup(cgzname, bakname); // MediaPacks (flowtron) 20091007 checkmapdependencies(true); - s_strncpy(hdr.mediareq, reqmpak, 128); + copystring(hdr.mediareq, reqmpak, 128); gzFile f = opengzfile(cgzname, "wb9"); if(!f) { conoutf("could not write map to %s", cgzname); return; } // TODO (flowtron) : check map dependencies and set the appropriate value (NULL, "-1" or "A,B,C,...") in the header // MediaPack @@ -451,8 +451,8 @@ bool load_world(char *mname) // still supports all map formats that have maploaded = getfilesize(ocgzname); if(maploaded > 0) { - s_strcpy(cgzname, ocgzname); - s_strcpy(mcfname, omcfname); + copystring(cgzname, ocgzname); + copystring(mcfname, omcfname); } else maploaded = getfilesize(cgzname); gzFile f = opengzfile(cgzname, "rb9"); @@ -642,13 +642,13 @@ void listmapdependencies(char *mapname) // print map dependencies to file #define ADDFILENAME(prefix, fname, count) \ { \ - s_sprintfd(basename)(prefix, fname); \ - s_strcpy(fullname, findfile(basename, "r")); \ + defformatstring(basename)(prefix, fname); \ + copystring(fullname, findfile(basename, "r")); \ int *n = sumpaths.access(fullname); \ if(!n) { n = &sumpaths.access(newstring(fullname), -1); if(fileexists(fullname, "r")) *n = 0; } \ if(*n >= 0) *n += count; \ const char *pt = strstr(fullname, basename); \ - s_strncpy(modname, fullname, pt - fullname + 1); \ + copystring(modname, fullname, pt - fullname + 1); \ if(fullname != pt && !usedmods.access(modname)) usedmods.access(newstring(modname), 0); \ } @@ -748,7 +748,7 @@ void listmapdependencies(char *mapname) // print map dependencies to file int usedm = 0; allmods[0] = '\0'; - enumeratek(usedmods, const char *, key, s_strcatf(allmods, "%s%s",*allmods ? ", " : "", key); delete key; usedm++); + enumeratek(usedmods, const char *, key, concatformatstring(allmods, "%s%s",*allmods ? ", " : "", key); delete key; usedm++); pushscontext(IEXC_MAPCFG); // untrusted altogether persistidents = false; execfile(mcfname);