cleanup
* removed convertcase use toupper (concat A B C D ....) instead * moved several COMMAND macros to their function bodies * cleaned up screenshot extension handling * prefix screenshot argument with "screenshot/" and add correct extension
This commit is contained in:
@@ -448,15 +448,6 @@ const highestcn [
|
||||
result $hcn
|
||||
]
|
||||
|
||||
// convertcase - Zap lists of strings to lower/uppercase.
|
||||
const convertcase [
|
||||
if (> $numargs 1) [
|
||||
tempalias tmpCCO []
|
||||
loop ccl $numargs [ if (> $ccl 0) [ tmpCCO = (concatword $tmpCCO [ ] (getalias (format arg%1 (+ $ccl 2)))) ] [ tmpCCO = (concatword $tmpCCO $arg2) ] ]
|
||||
if (!= $arg1 0) [ result (toupper $tmpCCO) ] [ result (tolower $tmpCCO) ]
|
||||
]
|
||||
]
|
||||
|
||||
ingall = 0
|
||||
const ignoreall [ if $connected [ ingall = 1; loop ia (+ (highestcn) 1) [ ignore $ia ]; echo (blue)NOTE: (white)all clients currently on the server were ignored ] ]
|
||||
const unignoreall [ if $connected [ ingall = 0; clearignored -1; echo (blue)NOTE: (white)all clients currently on the server were unignored ] ]
|
||||
|
||||
+37
-75
@@ -88,6 +88,7 @@ void push(const char *name, const char *action)
|
||||
{
|
||||
pusha(name, newstring(action));
|
||||
}
|
||||
COMMAND(push, "ss");
|
||||
|
||||
void pop(const char *name)
|
||||
{
|
||||
@@ -102,7 +103,6 @@ void pop(const char *name)
|
||||
popident(*id);
|
||||
}
|
||||
|
||||
COMMAND(push, "ss");
|
||||
COMMANDF(pop, "v", (char **args, int numargs)
|
||||
{
|
||||
if(numargs > 0)
|
||||
@@ -534,6 +534,7 @@ void floatret(float v, bool neat)
|
||||
}
|
||||
|
||||
void result(const char *s) { commandret = newstring(s); }
|
||||
COMMAND(result, "s");
|
||||
|
||||
#if 0
|
||||
// seer : script evaluation excessive recursion
|
||||
@@ -1059,6 +1060,9 @@ void exec(const char *cfgfile)
|
||||
{
|
||||
if(!execfile(cfgfile)) conoutf("could not read \"%s\"", cfgfile);
|
||||
}
|
||||
COMMAND(exec, "s");
|
||||
|
||||
COMMANDF(execute, "s", (char *s) { intret(execute(s)); });
|
||||
|
||||
void execdir(const char *dir)
|
||||
{
|
||||
@@ -1080,6 +1084,8 @@ COMMAND(execdir, "s");
|
||||
// () and [] expressions, any control construct can be defined trivially.
|
||||
|
||||
void ifthen(char *cond, char *thenp, char *elsep) { commandret = executeret(cond[0]!='0' ? thenp : elsep); }
|
||||
COMMANDN(if, ifthen, "sss");
|
||||
|
||||
void loopa(char *var, int *times, char *body)
|
||||
{
|
||||
int t = *times;
|
||||
@@ -1114,6 +1120,7 @@ void loopa(char *var, int *times, char *body)
|
||||
popident(*id);
|
||||
loop_level--;
|
||||
}
|
||||
COMMANDN(loop, loopa, "sis");
|
||||
|
||||
void whilea(char *cond, char *body)
|
||||
{
|
||||
@@ -1130,12 +1137,13 @@ void whilea(char *cond, char *body)
|
||||
}
|
||||
loop_level--;
|
||||
}
|
||||
COMMANDN(while, whilea, "ss");
|
||||
|
||||
void breaka() { if(loop_level) loop_skip = loop_break = true; }
|
||||
void continuea() { if(loop_level) loop_skip = true; }
|
||||
COMMANDF(break, "", () { if(loop_level) loop_skip = loop_break = true; });
|
||||
COMMANDF(continue, "", () { if(loop_level) loop_skip = true; });
|
||||
|
||||
void concat(char *s) { result(s); }
|
||||
void concatword(char *s) { result(s); }
|
||||
COMMANDF(concat, "c", (const char *s) { result(s); });
|
||||
COMMANDF(concatword, "w", (const char *s) { result(s); });
|
||||
|
||||
void format(char **args, int numargs)
|
||||
{
|
||||
@@ -1166,6 +1174,7 @@ void format(char **args, int numargs)
|
||||
s.add('\0');
|
||||
result(s.getbuf());
|
||||
}
|
||||
COMMAND(format, "v");
|
||||
|
||||
#define whitespaceskip do { s += strspn(s, "\n\t \r"); } while(s[0] == '/' && s[1] == '/' && (s += strcspn(s, "\n\0")))
|
||||
#define elementskip { if(*s=='"') { do { ++s; s += strcspn(s, "\"\n"); } while(*s == '\"' && s[-1] == '\\'); s += *s=='"'; } else s += strcspn(s, "\r\n\t "); }
|
||||
@@ -1254,6 +1263,7 @@ int listlen(const char *s)
|
||||
for(; *s; n++) { elementskip; whitespaceskip; }
|
||||
return n;
|
||||
}
|
||||
COMMANDF(listlen, "s", (char *l) { intret(listlen(l)); });
|
||||
|
||||
int find(char *s, const char *key)
|
||||
{
|
||||
@@ -1294,6 +1304,7 @@ void colora(char *s)
|
||||
commandret = newstring(x);
|
||||
}
|
||||
}
|
||||
COMMANDN(c, colora, "s");
|
||||
|
||||
#ifndef STANDALONE
|
||||
// Easily inject a string into various CubeScript punctuations
|
||||
@@ -1313,8 +1324,10 @@ void addpunct(char *s, char *type)
|
||||
COMMAND(addpunct, "ss");
|
||||
#endif
|
||||
|
||||
void toLower(char *s) { result(strcaps(s, false)); }
|
||||
void toUpper(char *s) { result(strcaps(s, true)); }
|
||||
void toany(char *s, int (*c)(int)) { while(*s) { *s = (*c)(*s); s++; } }
|
||||
|
||||
COMMANDF(tolower, "s", (char *s) { toany(s, tolower); result(s); });
|
||||
COMMANDF(toupper, "s", (char *s) { toany(s, toupper); result(s); });
|
||||
|
||||
void testchar(char *s, int *type)
|
||||
{
|
||||
@@ -1348,11 +1361,9 @@ void testchar(char *s, int *type)
|
||||
if(isdigit(s[0]) != 0) { istrue = true; }
|
||||
break;
|
||||
}
|
||||
if(istrue)
|
||||
intret(1);
|
||||
else
|
||||
intret(0);
|
||||
intret(istrue ? 1 : 0);
|
||||
}
|
||||
COMMAND(testchar, "si");
|
||||
|
||||
char *strreplace(char *dest, const char *source, const char *search, const char *replace)
|
||||
{
|
||||
@@ -1377,6 +1388,7 @@ char *strreplace(char *dest, const char *source, const char *search, const char
|
||||
}
|
||||
}
|
||||
}
|
||||
COMMANDF(strreplace, "sss", (const char *source, const char *search, const char *replace) { string d; result(strreplace(d, source, search, replace)); });
|
||||
|
||||
int stringsort(const char **a, const char **b) { return strcmp(*a, *b); }
|
||||
int stringsortrev(const char **a, const char **b) { return strcmp(*b, *a); }
|
||||
@@ -1421,24 +1433,6 @@ void swapelements(char *list, char *v)
|
||||
}
|
||||
COMMAND(swapelements, "ss");
|
||||
|
||||
COMMANDN(c, colora, "s");
|
||||
COMMANDN(loop, loopa, "sis");
|
||||
COMMANDN(while, whilea, "ss");
|
||||
COMMANDN(break, breaka, "");
|
||||
COMMANDN(continue, continuea, "");
|
||||
COMMANDN(if, ifthen, "sss");
|
||||
COMMAND(exec, "s");
|
||||
COMMAND(concat, "c");
|
||||
COMMAND(concatword, "w");
|
||||
COMMAND(format, "v");
|
||||
COMMAND(result, "s");
|
||||
COMMANDF(execute, "s", (char *s) { intret(execute(s)); });
|
||||
COMMANDF(listlen, "s", (char *l) { intret(listlen(l)); });
|
||||
COMMANDN(tolower, toLower, "s");
|
||||
COMMANDN(toupper, toUpper, "s");
|
||||
COMMAND(testchar, "si");
|
||||
COMMANDF(strreplace, "sss", (const char *source, const char *search, const char *replace) { string d; result(strreplace(d, source, search, replace)); });
|
||||
|
||||
void add(int *a, int *b) { intret(*a + *b); } COMMANDN(+, add, "ii");
|
||||
void mul(int *a, int *b) { intret(*a * *b); } COMMANDN(*, mul, "ii");
|
||||
void sub(int *a, int *b) { intret(*a - *b); } COMMANDN(-, sub, "ii");
|
||||
@@ -1680,13 +1674,15 @@ void scriptcontext(int *context, char *idname)
|
||||
int c = *context;
|
||||
if(c >= 0 && c < IEXC_NUM) id->context = c;
|
||||
}
|
||||
COMMAND(scriptcontext, "is");
|
||||
|
||||
void isolatecontext(int *context)
|
||||
{
|
||||
if(*context >= 0 && *context < IEXC_NUM && !contextsealed) contextisolated[*context] = true;
|
||||
}
|
||||
COMMAND(isolatecontext, "i");
|
||||
|
||||
void sealcontexts() { contextsealed = true; }
|
||||
COMMANDF(sealcontexts, "",() { contextsealed = true; });
|
||||
|
||||
bool allowidentaccess(ident *id) // check if ident is allowed in current context
|
||||
{
|
||||
@@ -1696,36 +1692,21 @@ bool allowidentaccess(ident *id) // check if ident is allowed in current context
|
||||
return execcontext <= id->context;
|
||||
}
|
||||
|
||||
COMMAND(scriptcontext, "is");
|
||||
COMMAND(isolatecontext, "i");
|
||||
COMMAND(sealcontexts, "");
|
||||
|
||||
#ifndef STANDALONE
|
||||
COMMANDF(watchingdemo, "", () { intret(watchingdemo); });
|
||||
|
||||
void systime()
|
||||
{
|
||||
result(numtime());
|
||||
}
|
||||
COMMANDF(systime, "", () { result(numtime()); });
|
||||
COMMANDF(timestamp, "", () { result(timestring(true, "%Y %m %d %H %M %S")); });
|
||||
COMMANDF(datestring, "", () { result(timestring(true, "%c")); });
|
||||
|
||||
void timestamp_()
|
||||
{
|
||||
result(timestring(true, "%Y %m %d %H %M %S"));
|
||||
}
|
||||
|
||||
void datestring()
|
||||
{
|
||||
result(timestring(true, "%c"));
|
||||
}
|
||||
|
||||
void timestring_()
|
||||
COMMANDF(timestring, "", ()
|
||||
{
|
||||
const char *res = timestring(true, "%H:%M:%S");
|
||||
result(res[0] == '0' ? res + 1 : res);
|
||||
}
|
||||
});
|
||||
|
||||
extern int millis_() { extern int totalmillis; return totalmillis; }
|
||||
void strlen_(char *s) { intret(strlen(s)); }
|
||||
COMMANDF(millis, "", () { intret(totalmillis); });
|
||||
COMMANDF(strlen, "s", (char *s) { intret(strlen(s)); });
|
||||
|
||||
void substr_(char *fs, int *pa, int *len)
|
||||
{
|
||||
@@ -1739,6 +1720,7 @@ void substr_(char *fs, int *pa, int *len)
|
||||
if(ilen >= 0 && ilen < int(strlen(fs+ia))) (fs+ia)[ilen] = '\0';
|
||||
result(fs+ia);
|
||||
}
|
||||
COMMANDN(substr, substr_, "sii");
|
||||
|
||||
void strpos_(char *haystack, char *needle, int *occurence)
|
||||
{
|
||||
@@ -1762,31 +1744,11 @@ void strpos_(char *haystack, char *needle, int *occurence)
|
||||
}
|
||||
intret(position);
|
||||
}
|
||||
|
||||
void l0(int *p, int *v) { string f; string r; formatstring(f)("%%0%dd", *p); formatstring(r)(f, *v); result(r); }
|
||||
|
||||
void getscrext()
|
||||
{
|
||||
switch(screenshottype)
|
||||
{
|
||||
case 2: result(".png"); break;
|
||||
case 1: result(".jpg"); break;
|
||||
case 0:
|
||||
default: result(".bmp"); break;
|
||||
}
|
||||
}
|
||||
|
||||
COMMANDF(millis, "", () { intret(millis_()); });
|
||||
COMMANDN(strlen, strlen_, "s");
|
||||
COMMANDN(substr, substr_, "sii");
|
||||
COMMANDN(strpos, strpos_, "ssi");
|
||||
COMMAND(l0, "ii");
|
||||
COMMAND(systime, "");
|
||||
COMMANDN(timestamp, timestamp_, "");
|
||||
COMMAND(datestring, "");
|
||||
COMMANDN(timestring, timestring_, "");
|
||||
|
||||
COMMANDF(l0, "ii", (int *p, int *v) { defformatstring(f)("%%0%dd", *p); defformatstring(r)(f, *v); result(r); });
|
||||
|
||||
COMMANDF(getmode, "i", (int *acr) { result(modestr(gamemode, *acr != 0)); });
|
||||
COMMAND(getscrext, "");
|
||||
|
||||
void listoptions(char *s)
|
||||
{
|
||||
|
||||
+26
-38
@@ -50,6 +50,7 @@ void quit() // normal exit
|
||||
DELETEP(clientlogfile);
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
COMMAND(quit, "");
|
||||
|
||||
void fatal(const char *s, ...) // failure exit
|
||||
{
|
||||
@@ -163,21 +164,6 @@ void setprocesspriority(bool high)
|
||||
}
|
||||
#endif
|
||||
|
||||
const char *screenshotpath(const char *imagepath, const char *suffix)
|
||||
{
|
||||
static string buf;
|
||||
if(imagepath && imagepath[0]) copystring(buf, imagepath);
|
||||
else
|
||||
{
|
||||
if(getclientmap()[0])
|
||||
formatstring(buf)("screenshots/%s_%s_%s.%s", timestring(), behindpath(getclientmap()), modestr(gamemode, true), suffix);
|
||||
else
|
||||
formatstring(buf)("screenshots/%s.%s", timestring(), suffix);
|
||||
}
|
||||
path(buf);
|
||||
return buf;
|
||||
}
|
||||
|
||||
FVARP(screenshotscale, 0.1f, 1.0f, 1.0f);
|
||||
|
||||
void bmp_screenshot(const char *imagepath, bool mapshot = false)
|
||||
@@ -226,9 +212,8 @@ void bmp_screenshot(const char *imagepath, bool mapshot = false)
|
||||
}
|
||||
entropy_add_block(tmp, tmpsize);
|
||||
delete[] tmp;
|
||||
const char *filename = screenshotpath(imagepath, "bmp");
|
||||
stream *file = openfile(filename, "wb");
|
||||
if(!file) conoutf("failed to create: %s", filename);
|
||||
stream *file = openfile(imagepath, "wb");
|
||||
if(!file) conoutf("failed to create: %s", imagepath);
|
||||
else
|
||||
{
|
||||
SDL_SaveBMP_RW(image, file->rwops(), 1);
|
||||
@@ -293,7 +278,7 @@ void jpeg_screenshot(const char *imagepath, bool mapshot = false)
|
||||
free(swapline);
|
||||
}
|
||||
|
||||
const char *filename = findfile(screenshotpath(imagepath, "jpg"), "wb");
|
||||
const char *filename = findfile(imagepath, "wb");
|
||||
conoutf("writing to file: %s", filename);
|
||||
|
||||
jpegenc *jpegencoder = new jpegenc;
|
||||
@@ -456,35 +441,41 @@ void png_screenshot(const char *imagepath, bool mapshot = false)
|
||||
entropy_add_block(tmp, tmpsize);
|
||||
delete[] tmp;
|
||||
|
||||
const char *filename = screenshotpath(imagepath, "png");
|
||||
if(save_png(filename, image) < 0) conoutf("\f3Error saving png file");
|
||||
if(save_png(imagepath, image) < 0) conoutf("\f3Error saving png file");
|
||||
|
||||
SDL_FreeSurface(image);
|
||||
}
|
||||
|
||||
VARP(screenshottype, 0, 1, 2);
|
||||
void screenshot(const char *imagepath)
|
||||
|
||||
const char *getscrext()
|
||||
{
|
||||
const char *screxts[] = { ".bmp", ".jpg", ".png" };
|
||||
return screxts[screenshottype % 3];
|
||||
}
|
||||
COMMANDF(getscrext, "", () { result(getscrext()); });
|
||||
|
||||
void screenshot(const char *filename)
|
||||
{
|
||||
static string buf;
|
||||
if(filename && filename[0]) formatstring(buf)("screenshots/%s%s", filename, getscrext());
|
||||
else if(getclientmap()[0]) formatstring(buf)("screenshots/%s_%s_%s%s", timestring(), behindpath(getclientmap()), modestr(gamemode, true), getscrext());
|
||||
else formatstring(buf)("screenshots/%s%s", timestring(), getscrext());
|
||||
path(buf);
|
||||
|
||||
switch(screenshottype)
|
||||
{
|
||||
case 2: png_screenshot(imagepath,false); break;
|
||||
case 1: jpeg_screenshot(imagepath,false); break;
|
||||
case 2: png_screenshot(buf, false); break;
|
||||
case 1: jpeg_screenshot(buf, false); break;
|
||||
case 0:
|
||||
default: bmp_screenshot(imagepath,false); break;
|
||||
default: bmp_screenshot(buf, false); break;
|
||||
}
|
||||
}
|
||||
COMMAND(screenshot, "s");
|
||||
|
||||
void mapshot()
|
||||
{
|
||||
string suffix;
|
||||
switch(screenshottype)
|
||||
{
|
||||
case 2: copystring(suffix, "png"); break;
|
||||
case 1: copystring(suffix, "jpg"); break;
|
||||
case 0:
|
||||
default: copystring(suffix, "bmp"); break;
|
||||
}
|
||||
defformatstring(buf)("screenshots/mapshot_%s_%s.%s", behindpath(getclientmap()), timestring(), suffix);
|
||||
defformatstring(buf)("screenshots/mapshot_%s_%s%s", behindpath(getclientmap()), timestring(), getscrext());
|
||||
switch(screenshottype)
|
||||
{
|
||||
case 2: png_screenshot(buf,true); break;
|
||||
@@ -493,13 +484,10 @@ void mapshot()
|
||||
default: bmp_screenshot(buf,true); break;
|
||||
}
|
||||
}
|
||||
COMMAND(mapshot, "");
|
||||
|
||||
bool needsautoscreenshot = false;
|
||||
|
||||
COMMAND(screenshot, "s");
|
||||
COMMAND(mapshot, "");
|
||||
COMMAND(quit, "");
|
||||
|
||||
void screenres(int w, int h)
|
||||
{
|
||||
#if !defined(WIN32) && !defined(__APPLE__)
|
||||
|
||||
@@ -1238,7 +1238,7 @@ bool menukey(int code, bool isdown, int unicode, SDLMod mod)
|
||||
case SDLK_F12:
|
||||
if(curmenu->allowinput)
|
||||
{
|
||||
extern void screenshot(const char *imagepath);
|
||||
extern void screenshot(const char *filename);
|
||||
screenshot(NULL);
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -999,7 +999,6 @@ extern void changescriptcontext(int newcontext);
|
||||
extern void explodelist(const char *s, vector<char *> &elems);
|
||||
extern char *indexlist(const char *s, int pos);
|
||||
extern char *parseword(const char *&p);
|
||||
extern char *strreplace(char *dest, const char *source, const char *search, const char *replace);
|
||||
extern void pushscontext(int newcontext);
|
||||
extern int popscontext();
|
||||
extern int curscontext();
|
||||
@@ -1008,8 +1007,6 @@ extern int execcontext;
|
||||
extern const char *currentserver(int i);
|
||||
extern void setcontext(const char *context, const char *info);
|
||||
extern void resetcontext();
|
||||
extern int millis_();
|
||||
extern int screenshottype;
|
||||
|
||||
// server
|
||||
extern int modeacronyms;
|
||||
|
||||
@@ -728,7 +728,7 @@ void newmap(int *i)
|
||||
addmsg(SV_NEWMAP, "ri", max(*i, 0));
|
||||
exechook(HOOK_SP_MP, "onNewMap", "");
|
||||
}
|
||||
defformatstring(startmillis)("%d", millis_());
|
||||
defformatstring(startmillis)("%d", totalmillis);
|
||||
alias("gametimestart", startmillis, true);
|
||||
}
|
||||
|
||||
|
||||
@@ -1014,7 +1014,7 @@ int load_world(char *mname) // still supports all map formats that have e
|
||||
}
|
||||
}
|
||||
|
||||
defformatstring(startmillis)("%d", millis_());
|
||||
defformatstring(startmillis)("%d", totalmillis);
|
||||
alias("gametimestart", startmillis, true);
|
||||
startmap(mname);
|
||||
res |= mapconfigerror;
|
||||
|
||||
Reference in New Issue
Block a user