diff --git a/source/src/bot/ac_bot.h b/source/src/bot/ac_bot.h index 858874f5..16d88f23 100644 --- a/source/src/bot/ac_bot.h +++ b/source/src/bot/ac_bot.h @@ -36,8 +36,8 @@ public: virtual void Spawn(void); }; -inline void AddScreenText(char *t, ...) {}; // UNDONE -inline void AddDebugText(char *t, ...) {}; // UNDONE +inline void AddScreenText(const char *t, ...) {}; // UNDONE +inline void AddDebugText(const char *t, ...) {}; // UNDONE #endif diff --git a/source/src/bot/bot.h b/source/src/bot/bot.h index 01ecce78..033d87c3 100644 --- a/source/src/bot/bot.h +++ b/source/src/bot/bot.h @@ -348,9 +348,9 @@ class CBotManager float m_fReAddBotDelay; void LoadBotNamesFile(void); - char *GetBotName(void); + const char *GetBotName(void); void LoadBotTeamsFile(void); - char *GetBotTeam(void); + const char *GetBotTeam(void); void CreateSkillData(void); void InitSkillData(void); void InitBotItems(void); @@ -376,7 +376,7 @@ public: void ClearStoredBots(void) { while(!m_StoredBots.Empty()) delete m_StoredBots.Pop(); } void ReAddBot(CStoredBot *bot) { CreateBot(bot->m_szTeam, SkillNrToSkillName(bot->m_sSkillNr), bot->m_szName); }; void EndMap(void); - void BeginMap(char *szMapName); + void BeginMap(const char *szMapName); int GetBotIndex(botent *m); void LetBotsUpdateStats(void); void LetBotsHear(int n, vec *loc); diff --git a/source/src/bot/bot_util.cpp b/source/src/bot/bot_util.cpp index 5f86759e..bc1facb9 100644 --- a/source/src/bot/bot_util.cpp +++ b/source/src/bot/bot_util.cpp @@ -449,7 +449,7 @@ float GetCubeHeight(int x, int y) return ceil; } -char *SkillNrToSkillName(short skillnr) +const char *SkillNrToSkillName(short skillnr) { if (skillnr == 0) return "best"; else if (skillnr == 1) return "good"; diff --git a/source/src/bot/bot_util.h b/source/src/bot/bot_util.h index fe1a41a8..2f4b5d42 100644 --- a/source/src/bot/bot_util.h +++ b/source/src/bot/bot_util.h @@ -32,7 +32,7 @@ vec CrossProduct(const vec &a, const vec &b); int GetDirection(const vec &angles, const vec &v1, const vec &v2); float GetCubeFloor(int x, int y); float GetCubeHeight(int x, int y); -char *SkillNrToSkillName(short skillnr); +const char *SkillNrToSkillName(short skillnr); bool IsInGame(dynent *d); // ================================================================== diff --git a/source/src/bot/bot_waypoint.h b/source/src/bot/bot_waypoint.h index ce447878..d96f80de 100644 --- a/source/src/bot/bot_waypoint.h +++ b/source/src/bot/bot_waypoint.h @@ -123,7 +123,7 @@ public: void SaveWaypoints(void); bool LoadWPExpFile(void); void SaveWPExpFile(void); - void SetMapName(char *map) { strcpy(m_szMapName, map); }; + void SetMapName(const char *map) { strcpy(m_szMapName, map); }; void SetWaypointsVisible(bool Visible) { m_bDrawWaypoints = Visible; }; void SetPathsVisible(bool Visible) { m_bDrawWPPaths = Visible; }; diff --git a/source/src/bot/botmanager.cpp b/source/src/bot/botmanager.cpp index c0fabb06..39ab890a 100644 --- a/source/src/bot/botmanager.cpp +++ b/source/src/bot/botmanager.cpp @@ -175,10 +175,10 @@ void CBotManager::LoadBotNamesFile() fclose(fp); } -char *CBotManager::GetBotName() +const char *CBotManager::GetBotName() { - char *szOutput = NULL; - TMultiChoice BotNameChoices; + const char *szOutput = NULL; + TMultiChoice BotNameChoices; short ChoiceVal; for(int j=0;j BotTeamChoices; + const char *szOutput = NULL; + TMultiChoice BotTeamChoices; short ChoiceVal; for(int j=0;jpBot) { diff --git a/source/src/clientgame.cpp b/source/src/clientgame.cpp index 39665efd..02f76aa2 100644 --- a/source/src/clientgame.cpp +++ b/source/src/clientgame.cpp @@ -48,7 +48,7 @@ bool duplicatename(playerent *d, char *name = NULL) return false; } -char *colorname(playerent *d, int num, char *name, char *prefix) +char *colorname(playerent *d, int num, char *name, const char *prefix) { if(!name) name = d->name; if(name[0] && !duplicatename(d, name)) return name; @@ -65,7 +65,7 @@ char *colorping(int ping) return cping; } -void newname(char *name) +void newname(const char *name) { if(name[0]) { @@ -507,7 +507,7 @@ void preparectf(bool cleanonly=false) int suicided = -1; -void startmap(char *name) // called just after a map load +void startmap(const char *name) // called just after a map load { clearminimap(); senditemstoserver = true; @@ -612,8 +612,8 @@ votedisplayinfo *newvotedisplayinfo(playerent *owner, int type, char *arg1, char v->owner = owner; v->type = type; v->millis = lastmillis + (30+10)*1000; - 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 master to player %s", "load map %s in mode %s", "%s demo recording for the next match", "stop demo recording", "clear all demos"}; - char *msg = msgs[type]; + 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 master to player %s", "load map %s in mode %s", "%s demo recording for the next match", "stop demo recording", "clear all demos"}; + const char *msg = msgs[type]; switch(v->type) { case SA_KICK: @@ -712,7 +712,7 @@ void callvotesuc() void callvoteerr(int e) { if(e < 0 || e >= VOTEE_NUM) return; - char *verr[VOTEE_NUM] = { "voting is currently disabled", "there is already a vote pending", "you have already voted", "you can't vote that often", "this vote is only available in multiplayer" }; + const char *verr[VOTEE_NUM] = { "voting is currently disabled", "there is already a vote pending", "you have already voted", "you can't vote that often", "this vote is only available in multiplayer" }; conoutf("\f3could not vote: %s", verr[e]); DELETEP(calledvote); } @@ -756,7 +756,7 @@ void setadmin(char *claim, char *password) COMMAND(setmaster, ARG_1INT); COMMAND(setadmin, ARG_2STR); -void changemap(char *name) // silently request map change, server may ignore +void changemap(const char *name) // silently request map change, server may ignore { ENetPacket *packet = enet_packet_create(NULL, MAXTRANS, ENET_PACKET_FLAG_RELIABLE); ucharbuf p(packet->data, packet->dataLength); diff --git a/source/src/clients2c.cpp b/source/src/clients2c.cpp index b2934b58..e721bc0c 100644 --- a/source/src/clients2c.cpp +++ b/source/src/clients2c.cpp @@ -7,7 +7,7 @@ extern bool c2sinit, senditemstoserver; extern string clientpassword; -void neterr(char *s) +void neterr(const char *s) { conoutf("\f3illegal network message (%s)", s); disconnect(); @@ -187,7 +187,7 @@ void parsemessages(int cn, playerent *d, ucharbuf &p) { getint(p); s_sprintfd(nextmapalias)("nextmap_%s", getclientmap()); - char *map = getalias(nextmapalias); // look up map in the cycle + const char *map = getalias(nextmapalias); // look up map in the cycle changemap(map ? map : getclientmap()); break; } diff --git a/source/src/command.cpp b/source/src/command.cpp index e8ad58a9..6f944323 100644 --- a/source/src/command.cpp +++ b/source/src/command.cpp @@ -8,18 +8,17 @@ char *exchangestr(char *o, char *n) { delete[] o; return newstring(n); } int execcontext = IEXC_CORE; -hashtable *idents = NULL; // contains ALL vars/commands/aliases +hashtable *idents = NULL; // contains ALL vars/commands/aliases bool persistidents = true; -void alias(char *name, char *action) +void alias(const char *name, const char *action) { ident *b = idents->access(name); if(!b) { - name = newstring(name); - ident b = { ID_ALIAS, name, 0, 0, 0, 0, 0, newstring(action), 0, persistidents, execcontext }; - idents->access(name, &b); + ident b = { ID_ALIAS, newstring(name), 0, 0, 0, 0, 0, newstring(action), 0, persistidents, execcontext }; + idents->access(b.name, &b); } else if(b->type==ID_ALIAS) { @@ -34,36 +33,36 @@ COMMAND(alias, ARG_2STR); // variable's and commands are registered through globals, see cube.h -int variable(char *name, int min, int cur, int max, int *storage, void (*fun)(), bool persist) +int variable(const char *name, int min, int cur, int max, int *storage, void (*fun)(), bool persist) { - if(!idents) idents = new hashtable; + if(!idents) idents = new hashtable; ident v = { ID_VAR, name, min, max, storage, fun, 0, 0, 0, persist, IEXC_CORE }; idents->access(name, &v); return cur; } -void setvar(char *name, int i) { *idents->access(name)->storage = i; } -int getvar(char *name) { return *idents->access(name)->storage; } -bool identexists(char *name) { return idents->access(name)!=NULL; } +void setvar(const char *name, int i) { *idents->access(name)->storage = i; } +int getvar(const char *name) { return *idents->access(name)->storage; } +bool identexists(const char *name) { return idents->access(name)!=NULL; } -char *getalias(char *name) +const char *getalias(const char *name) { ident *i = idents->access(name); return i && i->type==ID_ALIAS ? i->action : NULL; } -bool addcommand(char *name, void (*fun)(), int narg) +bool addcommand(const char *name, void (*fun)(), int narg) { - if(!idents) idents = new hashtable; + if(!idents) idents = new hashtable; ident c = { ID_COMMAND, name, 0, 0, 0, fun, narg, 0, 0, false, IEXC_CORE }; idents->access(name, &c); return false; } -char *parseexp(char *&p, int right) // parse any nested set of () or [] +char *parseexp(const char *&p, int right) // parse any nested set of () or [] { int left = *p++; - char *word = p; + const char *word = p; for(int brak = 1; brak; ) { int c = *p++; @@ -81,14 +80,14 @@ char *parseexp(char *&p, int right) // parse any nested set of () or return s; } -char *parseword(char *&p) // parse single argument, including expressions +char *parseword(const char *&p) // parse single argument, including expressions { p += strspn(p, " \t\r"); if(p[0]=='/' && p[1]=='/') p += strcspn(p, "\n\0"); if(*p=='\"') { p++; - char *word = p; + const char *word = p; p += strcspn(p, "\"\r\n\0"); char *s = newstring(word, p-word); if(*p=='\"') p++; @@ -96,7 +95,7 @@ char *parseword(char *&p) // parse single argument, includ } if(*p=='(') return parseexp(p, ')'); if(*p=='[') return parseexp(p, ']'); - char *word = p; + const char *word = p; p += strcspn(p, "; \t\r\n\0"); if(p-word==0) return NULL; return newstring(word, p-word); @@ -114,7 +113,7 @@ char *lookup(char *n) // find value of ident reference return n; } -int execute(char *p) // all evaluation happens here, recursively +int execute(const char *p) // all evaluation happens here, recursively { const int MAXWORDS = 25; // limit, remove char *w[MAXWORDS]; @@ -124,10 +123,10 @@ int execute(char *p) // all evaluation happens here, int numargs = MAXWORDS; loopi(MAXWORDS) // collect all argument values { - w[i] = ""; + w[i] = (char *)""; if(i>numargs) continue; char *s = parseword(p); // parse and evaluate exps - if(!s) { numargs = i; s = ""; } + if(!s) { numargs = i; s = (char *)""; } if(*s=='$') s = lookup(s); // substitute variables w[i] = s; } @@ -257,7 +256,7 @@ void complete(char *s) if(completeidx>=idx) completeidx = 0; } -bool execfile(char *cfgfile) +bool execfile(const char *cfgfile) { string s; s_strcpy(s, cfgfile); @@ -268,7 +267,7 @@ bool execfile(char *cfgfile) return true; } -void exec(char *cfgfile) +void exec(const char *cfgfile) { if(!execfile(cfgfile)) conoutf("could not read \"%s\"", cfgfile); } @@ -276,7 +275,7 @@ void exec(char *cfgfile) // below the commands that implement a small imperative language. thanks to the semantics of // () and [] expressions, any control construct can be defined trivially. -void intset(char *name, int v) { string b; itoa(b, v); alias(name, b); } +void intset(const char *name, int v) { string b; itoa(b, v); alias(name, b); } void ifthen(char *cond, char *thenp, char *elsep) { execute(cond[0]!='0' ? thenp : elsep); } void loopa(char *times, char *body) { int t = atoi(times); loopi(t) { intset("i", i); execute(body); } } @@ -365,7 +364,7 @@ void writecfg() COMMAND(writecfg, ARG_NONE); -void identnames(vector &names, bool builtinonly) +void identnames(vector &names, bool builtinonly) { enumerateht(*idents) if(!builtinonly || idents->enumc->data.type != ID_ALIAS) names.add(idents->enumc->key); } diff --git a/source/src/command.h b/source/src/command.h index 41a7bdb6..ada872a2 100644 --- a/source/src/command.h +++ b/source/src/command.h @@ -3,7 +3,7 @@ enum { ID_VAR, ID_COMMAND, ID_ALIAS }; struct ident { int type; // one of ID_* above - char *name; + const char *name; int min, max; // ID_VAR int *storage; // ID_VAR void (*fun)(); // ID_VAR, ID_COMMAND diff --git a/source/src/console.cpp b/source/src/console.cpp index 871ff663..af9497f0 100644 --- a/source/src/console.cpp +++ b/source/src/console.cpp @@ -131,7 +131,7 @@ struct releaseaction }; vector releaseactions; -char *addreleaseaction(char *s) +char *addreleaseaction(const char *s) { if(!keypressed) return NULL; releaseaction &ra = releaseactions.add(); @@ -152,8 +152,7 @@ void saycommand(char *init) // turns input to the comman SDL_EnableUNICODE(saycommandon = (init!=NULL)); setscope(false); if(!editmode) keyrepeat(saycommandon); - if(!init) init = ""; - s_strcpy(commandbuf, init); + s_strcpy(commandbuf, init ? init : ""); commandpos = -1; player1->stopmoving(); // prevent situations where player presses direction key, open command line, then releases key } diff --git a/source/src/docs.cpp b/source/src/docs.cpp index c8a35fa2..4f5983fc 100644 --- a/source/src/docs.cpp +++ b/source/src/docs.cpp @@ -46,7 +46,7 @@ struct docsection }; vector sections; -hashtable docidents; // manage globally instead of a section tree to ensure uniqueness +hashtable docidents; // manage globally instead of a section tree to ensure uniqueness docsection *lastsection = NULL; docident *lastident = NULL; @@ -123,7 +123,7 @@ COMMANDN(dockey, adddockey, ARG_3STR); int stringsort(const char **a, const char **b) { return strcmp(*a, *b); } -char *cvecstr(vector &cvec, char *substr, int *rline = NULL) +char *cvecstr(vector &cvec, const char *substr, int *rline = NULL) { char *r = NULL; loopv(cvec) if(cvec[i]) if((r = strstr(cvec[i], substr)) != NULL) @@ -136,7 +136,7 @@ char *cvecstr(vector &cvec, char *substr, int *rline = NULL) void docundone(int allidents) { - cvector inames; + vector inames; identnames(inames, !(allidents > 0)); inames.sort(stringsort); loopv(inames) @@ -168,7 +168,7 @@ void docundone(int allidents) void docinvalid() { - cvector inames; + vector inames; identnames(inames, true); inames.sort(stringsort); enumerateht(docidents) if(!strchr(docidents.enumc->data.name, ' ') && !identexists(docidents.enumc->data.name)) diff --git a/source/src/entities.cpp b/source/src/entities.cpp index c4fcacbd..e0676632 100644 --- a/source/src/entities.cpp +++ b/source/src/entities.cpp @@ -5,7 +5,7 @@ vector ents; -char *entnames[] = +const char *entnames[] = { "none?", "light", "playerstart", "clips", "ammobox","grenades", @@ -14,13 +14,13 @@ char *entnames[] = "ladder", "ctf-flag", "sound", "?", "?", }; -char *entmdlnames[] = +const char *entmdlnames[] = { //FIXME : fix the "pickups" infront "pickups/pistolclips", "pickups/ammobox", "pickups/nades", "pickups/health", "pickups/kevlar", "pickups/akimbo", }; -void renderent(entity &e, char *mdlname, float z, float yaw, int anim = ANIM_MAPMODEL|ANIM_LOOP, int basetime = 0, float speed = 0) +void renderent(entity &e, const char *mdlname, float z, float yaw, int anim = ANIM_MAPMODEL|ANIM_LOOP, int basetime = 0, float speed = 0) { rendermodel(mdlname, anim, 0, 1.1f, vec(e.x, e.y, z+S(e.x, e.y)->floor), yaw, 0, speed, basetime); } diff --git a/source/src/main.cpp b/source/src/main.cpp index 14719c3a..024e7f23 100644 --- a/source/src/main.cpp +++ b/source/src/main.cpp @@ -35,10 +35,11 @@ void quit() // normal exit exit(EXIT_SUCCESS); } -void fatal(char *s, char *o) // failure exit +void fatal(const char *s, ...) // failure exit { - s_sprintfd(msg)("%s%s (%s)\n", s, o, SDL_GetError()); - cleanup(msg); + s_sprintfdlv(msg,s,s); + s_sprintfd(msgerr)("%s (%s)\n", msg, SDL_GetError()); + cleanup(msgerr); exit(EXIT_FAILURE); } @@ -219,7 +220,7 @@ int main(int argc, char **argv) { bool dedicated = false; int fs = SDL_FULLSCREEN, par = 0, uprate = 0, maxcl = DEFAULTCLIENTS, scthreshold = -5, port = 0; - char *sdesc = "", *ip = "", *master = NULL, *passwd = "", *maprot = NULL, *adminpwd = NULL, *srvmsg = NULL; + const char *sdesc = "", *ip = "", *master = NULL, *passwd = "", *maprot = NULL, *adminpwd = NULL, *srvmsg = NULL; #define initlog(s) puts("init: " s) initlog("sdl"); @@ -332,7 +333,7 @@ int main(int argc, char **argv) screen = SDL_SetVideoMode(scr_w, scr_h, hasbpp ? colorbits : 0, SDL_OPENGL|resize|fs); if(screen) break; } - if(!screen) fatal("Unable to create OpenGL screen: ", SDL_GetError()); + if(!screen) fatal("Unable to create OpenGL screen"); else { if(!hasbpp) conoutf("%d bit color buffer not supported - disabling", colorbits); diff --git a/source/src/menus.cpp b/source/src/menus.cpp index b3e47361..9a714cd2 100644 --- a/source/src/menus.cpp +++ b/source/src/menus.cpp @@ -3,7 +3,7 @@ #include "pch.h" #include "cube.h" -hashtable menus; +hashtable menus; gmenu *curmenu = NULL, *lastmenu = NULL; vector menustack; @@ -79,7 +79,7 @@ void rendermenu() m.inited = true; if(m.menusel>=m.items.length()) m.menusel = max(m.items.length()-1, 0); } - char *title = m.title; + const char *title = m.title; if(!title) { static string buf; s_sprintf(buf)("[ %s menu ]", m.name); title = buf; } int hitems = (m.header ? 2 : 0) + (m.footer ? 2 : 0), pagesize = MAXMENU - hitems, @@ -167,7 +167,7 @@ void rendermenumdl() glPopMatrix(); } -void *addmenu(char *name, char *title, bool allowinput, void (__cdecl *refreshfunc)(void *, bool)) +void *addmenu(const char *name, const char *title, bool allowinput, void (__cdecl *refreshfunc)(void *, bool)) { name = newstring(name); gmenu &menu = menus[name]; diff --git a/source/src/protos.h b/source/src/protos.h index 541c7d05..0d101ae8 100644 --- a/source/src/protos.h +++ b/source/src/protos.h @@ -21,20 +21,20 @@ struct color // command extern bool persistidents; -extern int variable(char *name, int min, int cur, int max, int *storage, void (*fun)(), bool persist); -extern void setvar(char *name, int i); -extern int getvar(char *name); -extern bool identexists(char *name); -extern bool addcommand(char *name, void (*fun)(), int narg); -extern int execute(char *p); -extern void exec(char *cfgfile); -extern bool execfile(char *cfgfile); +extern int variable(const char *name, int min, int cur, int max, int *storage, void (*fun)(), bool persist); +extern void setvar(const char *name, int i); +extern int getvar(const char *name); +extern bool identexists(const char *name); +extern bool addcommand(const char *name, void (*fun)(), int narg); +extern int execute(const char *p); +extern void exec(const char *cfgfile); +extern bool execfile(const char *cfgfile); extern void resetcomplete(); extern void complete(char *s); -extern void alias(char *name, char *action); -extern char *getalias(char *name); +extern void alias(const char *name, const char *action); +extern const char *getalias(const char *name); extern void writecfg(); -extern void identnames(vector &names, bool builtinonly); +extern void identnames(vector &names, bool builtinonly); extern void changescriptcontext(int newcontext); // console @@ -42,7 +42,7 @@ extern void keypress(int code, bool isdown, int cooked); extern void rendercommand(int x, int y); extern void renderconsole(); extern char *getcurcommand(); -extern char *addreleaseaction(char *s); +extern char *addreleaseaction(const char *s); extern void writebinds(FILE *f); extern void conoutf(const char *s, ...); @@ -52,7 +52,7 @@ extern bool menuvisible(); extern void menumanual(void *menu, int n, char *text, char *action = NULL, color *bgcolor = NULL); extern void menuheader(void *menu, char *header = NULL, char *footer = NULL); extern bool menukey(int code, bool isdown); -extern void *addmenu(char *name, char *title = NULL, bool allowinput = true, void (__cdecl *refreshfunc)(void *, bool) = NULL); +extern void *addmenu(const char *name, const char *title = NULL, bool allowinput = true, void (__cdecl *refreshfunc)(void *, bool) = NULL); extern void rendermenumdl(); extern void menuset(void *m); extern void menuselect(void *menu, int sel); @@ -66,11 +66,11 @@ struct mitem struct gmenu { - char *name, *title, *header, *footer; + const char *name, *title, *header, *footer; vector items; int mwidth; int menusel; - char *mdl; // (optional) md2 mdl + const char *mdl; // (optional) md2 mdl int anim, rotspeed, scale; bool allowinput, inited; void (__cdecl *refreshfunc)(void *, bool); @@ -80,7 +80,7 @@ struct gmenu extern void addserver(char *servername, char *serverport); extern char *getservername(int n); extern bool resolverwait(const char *name, ENetAddress *address); -extern int connectwithtimeout(ENetSocket sock, char *hostname, ENetAddress &remoteaddress); +extern int connectwithtimeout(ENetSocket sock, const char *hostname, ENetAddress &remoteaddress); extern void writeservercfg(); extern void refreshservers(void *menu, bool init); @@ -138,7 +138,7 @@ extern void render_flat(int tex, int x, int y, int size, int h, sqr *l1, sqr *l2 extern void render_flatdelta(int wtex, int x, int y, int size, float h1, float h2, float h3, float h4, sqr *l1, sqr *l2, sqr *l3, sqr *l4, bool isceil); extern void render_square(int wtex, float floor1, float floor2, float ceil1, float ceil2, int x1, int y1, int x2, int y2, int size, sqr *l1, sqr *l2, bool topleft); extern void render_tris(int x, int y, int size, bool topleft, sqr *h1, sqr *h2, sqr *s, sqr *t, sqr *u, sqr *v); -extern void setwatercolor(char *r = "", char *g = "", char *b = "", char *a = ""); +extern void setwatercolor(const char *r = "", const char *g = "", const char *b = "", const char *a = ""); extern void addwaterquad(int x, int y, int size); extern int renderwater(float hf, GLuint reflecttex, GLuint refracttex); extern void resetcubes(); @@ -158,7 +158,7 @@ extern void sendpackettoserv(int chan, ENetPacket *packet); extern void gets2c(); extern void c2sinfo(playerent *d); extern void c2skeepalive(); -extern void neterr(char *s); +extern void neterr(const char *s); extern int getclientnum(); extern void changemapserv(char *name, int mode); extern void changeteam(int team, bool respawn = true); @@ -172,8 +172,8 @@ extern void listdemos(); extern flaginfo flaginfos[2]; extern bool autoteambalance; extern void updateworld(int curtime, int lastmillis); -extern void startmap(char *name); -extern void changemap(char *name); +extern void startmap(const char *name); +extern void changemap(const char *name); extern void initclient(); extern void deathstate(playerent *pl); extern void spawnplayer(playerent *d); @@ -204,7 +204,7 @@ extern bool tryrespawn(); extern void findplayerstart(playerent *d); extern void serveropcommand(int cmd, int arg1); extern void refreshsopmenu(void *menu, bool init); -extern char *colorname(playerent *d, int num = 0, char *name = NULL, char *prefix = ""); +extern char *colorname(playerent *d, int num = 0, char *name = NULL, const char *prefix = ""); extern char *colorping(int ping); extern void toggledeathcam(); extern void followplayer(int i = 1); @@ -282,7 +282,7 @@ struct font extern int VIRTW; // virtual screen size for text & HUD extern font *curfont; -extern bool setfont(char *name); +extern bool setfont(const char *name); extern void draw_text(const char *str, int left, int top); extern void draw_textf(const char *fstr, int left, int top, ...); extern int char_width(int c, int x = 0); @@ -355,7 +355,7 @@ extern void music(char *name, char *cmd); extern void clearmapsounds(); // rendermodel -extern void rendermodel(char *mdl, int anim, int tex, float rad, const vec &o, float yaw, float pitch, float speed = 0, int basetime = 0, playerent *d = NULL, char *vwepmdl = NULL, float scale = 1.0f); +extern void rendermodel(const char *mdl, int anim, int tex, float rad, const vec &o, float yaw, float pitch, float speed = 0, int basetime = 0, playerent *d = NULL, const char *vwepmdl = NULL, float scale = 1.0f); extern void startmodelbatches(); extern void endmodelbatches(); extern mapmodelinfo &getmminfo(int i); @@ -368,7 +368,7 @@ extern void preload_hudguns(); extern void preload_mapmodels(); extern void renderclients(); extern void renderclient(playerent *d); -extern void renderclient(playerent *d, char *mdlname, char *vwepname, int tex = 0); +extern void renderclient(playerent *d, const char *mdlname, const char *vwepname, int tex = 0); // weapon extern bool scoped; @@ -394,7 +394,7 @@ extern void tryreload(playerent *p); extern void checkakimbo(); // entities -extern char *entnames[]; +extern const char *entnames[]; extern void putitems(ucharbuf &p); extern void pickupeffects(int n, playerent *d); @@ -416,8 +416,8 @@ extern void scrolldoc(int i); // server extern void localservertoclient(int chan, uchar *buf, int len); extern const char *modestr(int n); -extern void fatal(char *s, char *o = ""); -extern void initserver(bool dedicated, int uprate, char *sdesc, char *ip, int port, char *master, char *passwd, int maxcl, char *maprot, char *adminpwd, char *srvmsg, int scthreshold); +extern void fatal(const char *s, ...); +extern void initserver(bool dedicated, int uprate, const char *sdesc, const char *ip, int port, const char *master, const char *passwd, int maxcl, const char *maprot, const char *adminpwd, const char *srvmsg, int scthreshold); extern void cleanupserver(); extern void localconnect(); extern void localdisconnect(); @@ -435,7 +435,7 @@ extern void restoreserverstate(vector &ents); extern uchar *retrieveservers(uchar *buf, int buflen); extern char msgsizelookup(int msg); extern void serverms(int mode, int numplayers, int minremain, char *smapname, int millis, int serverport); -extern void servermsinit(const char *master, char *ip, int serverport, char *sdesc, bool listen); +extern void servermsinit(const char *master, const char *ip, int serverport, const char *sdesc, bool listen); extern bool serverpickup(int i, int sender); extern bool valid_client(int cn); extern void extinfo_cnbuf(ucharbuf &p, int cn); diff --git a/source/src/rendercubes.cpp b/source/src/rendercubes.cpp index 4131e86b..1a07b36b 100644 --- a/source/src/rendercubes.cpp +++ b/source/src/rendercubes.cpp @@ -343,7 +343,7 @@ int wx1, wy1, wx2, wy2; VARP(watersubdiv, 1, 4, 64); VARF(waterlevel, -128, -128, 127, if(!noteditmode()) hdr.waterlevel = waterlevel); -void setwatercolor(char *r, char *g, char *b, char *a) +void setwatercolor(const char *r, const char *g, const char *b, const char *a) { if(r[0]) { diff --git a/source/src/rendermodel.cpp b/source/src/rendermodel.cpp index 954a18af..d5810256 100644 --- a/source/src/rendermodel.cpp +++ b/source/src/rendermodel.cpp @@ -197,7 +197,7 @@ void endmodelbatches() numbatches = -1; } -void rendermodel(char *mdl, int anim, int tex, float rad, const vec &o, float yaw, float pitch, float speed, int basetime, playerent *d, char *vwepmdl, float scale) +void rendermodel(const char *mdl, int anim, int tex, float rad, const vec &o, float yaw, float pitch, float speed, int basetime, playerent *d, const char *vwepmdl, float scale) { model *m = loadmodel(mdl); if(!m) return; @@ -309,7 +309,7 @@ void preload_entmodels() model *mdl = loadmodel(entmdlnames[i]); if(dynshadow && mdl) mdl->genshadows(8.0f, 2.0f); } - static char *bouncemdlnames[] = { "misc/gib01", "misc/gib02", "misc/gib03", "weapons/grenade/static" }; + static const char *bouncemdlnames[] = { "misc/gib01", "misc/gib02", "misc/gib03", "weapons/grenade/static" }; loopi(sizeof(bouncemdlnames)/sizeof(bouncemdlnames[0])) { model *mdl = loadmodel(bouncemdlnames[i]); @@ -328,7 +328,7 @@ void preload_mapmodels() } } -void renderclient(playerent *d, char *mdlname, char *vwepname, int tex) +void renderclient(playerent *d, const char *mdlname, const char *vwepname, int tex) { int varseed = (int)(size_t)d; int anim = ANIM_IDLE|ANIM_LOOP; diff --git a/source/src/rendertext.cpp b/source/src/rendertext.cpp index 99f9e44d..b8a712c3 100644 --- a/source/src/rendertext.cpp +++ b/source/src/rendertext.cpp @@ -5,7 +5,7 @@ int VIRTW; -static hashtable fonts; +static hashtable fonts; static font *fontdef = NULL; font *curfont = NULL; @@ -46,7 +46,7 @@ void fontchar(int x, int y, int w, int h) COMMANDN(font, newfont, ARG_8STR); COMMANDN(fontchar, fontchar, ARG_4INT); -bool setfont(char *name) +bool setfont(const char *name) { font *f = fonts.access(name); if(!f) return false; diff --git a/source/src/server.cpp b/source/src/server.cpp index 95a94896..3d80e4d3 100644 --- a/source/src/server.cpp +++ b/source/src/server.cpp @@ -375,7 +375,7 @@ bool buildworldstate() int maxclients = DEFAULTCLIENTS, scorethreshold = -5; string smapname; -char *adminpasswd = NULL, *motd = NULL; +const char *adminpasswd = NULL, *motd = NULL; int countclients(int type, bool exclude = false) { @@ -504,7 +504,7 @@ void sendf(int cn, int chan, const char *format, ...) if(packet->referenceCount==0) enet_packet_destroy(packet); } -void sendservmsg(char *msg, int client=-1) +void sendservmsg(const char *msg, int client=-1) { sendf(client, 1, "ris", SV_SERVMSG, msg); } @@ -938,7 +938,7 @@ void sendteamtext(char *text, int sender) const char *disc_reason(int reason) { - static char *disc_reasons[] = { "normal", "end of packet", "client num", "kicked by server operator", "banned by server operator", "tag type", "connection refused due to ban", "wrong password", "failed admin login", "server FULL - maxclients", "server mastermode is \"private\"", "auto kick - did your score drop below the threshold?" }; + static const char *disc_reasons[] = { "normal", "end of packet", "client num", "kicked by server operator", "banned by server operator", "tag type", "connection refused due to ban", "wrong password", "failed admin login", "server FULL - maxclients", "server mastermode is \"private\"", "auto kick - did your score drop below the threshold?" }; return reason >= 0 && (size_t)reason < sizeof(disc_reasons)/sizeof(disc_reasons[0]) ? disc_reasons[reason] : "unknown"; } @@ -2331,7 +2331,7 @@ void localconnect() } #endif -void initserver(bool dedicated, int uprate, char *sdesc, char *ip, int serverport, char *master, char *passwd, int maxcl, char *maprot, char *adminpwd, char *srvmsg, int scthreshold) +void initserver(bool dedicated, int uprate, const char *sdesc, const char *ip, int serverport, const char *master, const char *passwd, int maxcl, const char *maprot, const char *adminpwd, const char *srvmsg, int scthreshold) { if(passwd) s_strcpy(serverpassword, passwd); maxclients = maxcl > 0 ? min(maxcl, MAXCLIENTS) : DEFAULTCLIENTS; @@ -2345,7 +2345,7 @@ void initserver(bool dedicated, int uprate, char *sdesc, char *ip, int serverpor if(!serverhost) fatal("could not create server host\n"); loopi(maxclients) serverhost->peers[i].data = (void *)-1; if(!maprot || !maprot[0]) maprot = newstring("config/maprot.cfg"); - readscfg(path(maprot)); + readscfg(path(maprot, true)); if(adminpwd && adminpwd[0]) adminpasswd = adminpwd; if(srvmsg && srvmsg[0]) motd = srvmsg; scorethreshold = min(-1, scthreshold); @@ -2368,12 +2368,18 @@ void initserver(bool dedicated, int uprate, char *sdesc, char *ip, int serverpor #ifdef STANDALONE void localservertoclient(int chan, uchar *buf, int len) {} -void fatal(char *s, char *o) { cleanupserver(); printf("fatal: %s\n", s); exit(EXIT_FAILURE); } +void fatal(const char *s, ...) +{ + cleanupserver(); + s_sprintfdlv(msg,s,s); + printf("fatal: %s\n", msg); + exit(EXIT_FAILURE); +} int main(int argc, char **argv) { int uprate = 0, maxcl = DEFAULTCLIENTS, scthreshold = -5, port = 0; - char *sdesc = "", *ip = "", *master = NULL, *passwd = "", *maprot = "", *adminpasswd = NULL, *srvmsg = NULL, *service = NULL; + const char *sdesc = "", *ip = "", *master = NULL, *passwd = "", *maprot = "", *adminpasswd = NULL, *srvmsg = NULL, *service = NULL; for(int i = 1; i= 0; } -int connectwithtimeout(ENetSocket sock, char *hostname, ENetAddress &remoteaddress) +int connectwithtimeout(ENetSocket sock, const char *hostname, ENetAddress &remoteaddress) { int result = enet_socket_connect(sock, &remoteaddress); if(result<0) enet_socket_destroy(sock); @@ -17,7 +17,7 @@ int connectwithtimeout(ENetSocket sock, char *hostname, ENetAddress &remoteaddre } #endif -ENetSocket httpgetsend(ENetAddress &remoteaddress, char *hostname, char *req, char *ref, char *agent, ENetAddress *localaddress = NULL) +ENetSocket httpgetsend(ENetAddress &remoteaddress, const char *hostname, const char *req, const char *ref, const char *agent, ENetAddress *localaddress = NULL) { if(remoteaddress.host==ENET_HOST_ANY) { @@ -233,7 +233,7 @@ void serverms(int mode, int numplayers, int minremain, char *smapname, int milli } } -void servermsinit(const char *master, char *ip, int infoport, char *sdesc, bool listen) +void servermsinit(const char *master, const char *ip, int infoport, const char *sdesc, bool listen) { const char *mid = strstr(master, "/"); if(mid) s_strncpy(masterbase, master, mid-master+1); @@ -250,3 +250,4 @@ void servermsinit(const char *master, char *ip, int infoport, char *sdesc, bool else enet_socket_set_option(pongsock, ENET_SOCKOPT_NONBLOCK, 1); } } + diff --git a/source/src/texture.cpp b/source/src/texture.cpp index b7b8323c..adf7dc9c 100644 --- a/source/src/texture.cpp +++ b/source/src/texture.cpp @@ -143,7 +143,7 @@ Texture *sky[6] = {NULL, NULL, NULL, NULL, NULL, NULL}; void loadsky(char *basename) { - char *side[] = { "ft", "bk", "lf", "rt", "dn", "up" }; + const char *side[] = { "ft", "bk", "lf", "rt", "dn", "up" }; loopi(6) { s_sprintfd(name)("packages/%s_%s.jpg", basename, side[i]); diff --git a/source/src/tools.cpp b/source/src/tools.cpp index fb8369e2..6a88ee28 100644 --- a/source/src/tools.cpp +++ b/source/src/tools.cpp @@ -15,14 +15,8 @@ string homedir = ""; vector packagedirs; -char *path(char *s, bool copy) +char *path(char *s) { - if(copy) - { - static string tmp; - s_strcpy(tmp, s); - s = tmp; - } for(char *t = s; (t = strpbrk(t, "/\\")); *t++ = PATHDIV); for(char *prevdir = NULL, *curdir = s;;) { @@ -44,6 +38,14 @@ char *path(char *s, bool copy) return s; } +char *path(const char *s, bool copy) +{ + static string tmp; + s_strcpy(tmp, s); + path(tmp); + return tmp; +} + const char *parentdir(const char *directory) { const char *p = strrchr(directory, '/'); diff --git a/source/src/tools.h b/source/src/tools.h index 6af5482f..3a24f94f 100644 --- a/source/src/tools.h +++ b/source/src/tools.h @@ -468,7 +468,8 @@ inline char *newstring(const char *s, size_t l) { return s_strncpy(newstring(l), inline char *newstring(const char *s) { return newstring(s, strlen(s)); } inline char *newstringbuf(const char *s) { return newstring(s, _MAXDEFSTR-1); } -extern char *path(char *s, bool copy = false); +extern char *path(char *s); +extern char *path(const char *s, bool copy); extern const char *parentdir(const char *directory); extern bool fileexists(const char *path, const char *mode); extern bool createdir(const char *path);