Exemplo n.º 1
0
void GScr_FS_ReadLine(){
    char buffer[2048];
    int ret;

    if(Scr_GetNumParam() != 1)
        Scr_Error("Usage: FS_ReadLine(<filehandle>)\n");

    fileHandle_t fh = Scr_GetInt(0);

    *buffer = 0;

    ret = Scr_FS_ReadLine(buffer, sizeof(buffer), fh);
    if(ret < 1 )
        Scr_AddUndefined();

    else if(*buffer == 0)
        Scr_AddString("");

    else{
        int len = strlen(buffer);

        if(buffer[len -1] == '\n')
            buffer[len -1] = 0;

        Scr_AddString(buffer);
    }
}
qboolean Scr_PlayerSay(gentity_t* from, int mode, const char* text){

    int callback;
    int threadId;

    callback = script_CallBacks_new[SCR_CB_NEW_SAY];
    if(!callback){
        return qfalse;
    }
    if(!say_forwardAll)
    {
        if(*text != '/' && *text != '.' && *text != '&')
            return qfalse;

        Scr_AddString(&text[1]);

    }else{
        Scr_AddString(text);
    }
    if(mode == 0)
        Scr_AddBool( qfalse );
    else
        Scr_AddBool( qtrue );

    threadId = Scr_ExecEntThread(from, callback, 1);

    Scr_FreeThread(threadId);

    return qtrue;

}
Exemplo n.º 3
0
void GScr_CopyString(){

    if(Scr_GetNumParam() != 1){
        Scr_Error("Usage: CopyStr(<string>)\n");
    }
    Scr_AddString(Scr_GetString(0));
}
Exemplo n.º 4
0
void PlayerCmd_GetUserinfo(scr_entref_t arg){

    gentity_t* gentity;
    int entityNum = 0;
    client_t *cl;
	mvabuf;


    if(HIWORD(arg)){

        Scr_ObjectError("Not an entity");

    }else{

        entityNum = LOWORD(arg);
        gentity = &g_entities[entityNum];

        if(!gentity->client){
            Scr_ObjectError(va("Entity: %i is not a player", entityNum));
        }
    }
    if(Scr_GetNumParam() != 1){
        Scr_Error("Usage: self getUserinfo( <string> )\n");
    }

    char* u_key = Scr_GetString(0);

    cl = &svs.clients[entityNum];

    char* value = Info_ValueForKey(cl->userinfo, u_key);

    Scr_AddString(value);
}
void GScr_CbufAddTextEx(){

    char string[1024];
    char outputbuf[1024];

    if(Scr_GetNumParam() != 1){
        Scr_Error("Usage: execex(<string>)\n");
    }
    Com_sprintf(string, sizeof(string), "%s\n",Scr_GetString(0));

    cmd_exec_redirect_buf[0] = '\0';

    if(!Q_stricmpn(string, "map", 3) || !Q_stricmpn(string, "fast_restart", 12))
    {

        Cbuf_AddText( string );

    }else{

        Com_BeginRedirect(outputbuf, sizeof(outputbuf), GScr_CbufExecRedirect);
        Cmd_ExecuteSingleCommand(0,0, string);
        Com_EndRedirect();
        cmd_exec_redirect_buf[sizeof(cmd_exec_redirect_buf) -1] = '\0';

    }

    Scr_AddString( cmd_exec_redirect_buf );
}
Exemplo n.º 6
0
void GScr_mysql_fetch_field(int entityIndex) {
    MYSQL_RES *res = (MYSQL_RES*)Scr_GetInt(0);
    MYSQL_FIELD *f = mysql_fetch_field(res);
    if(!f)
        Scr_AddUndefined();
    else
        Scr_AddString(f->name);
}
Exemplo n.º 7
0
void GScr_mysql_real_escape_string(int entityIndex) {
    MYSQL *m = (MYSQL*)Scr_GetInt(0);
    char* escape = Scr_GetString(1);
    char* str = (char*)malloc(strlen(escape) * 2 + 1);
    mysql_real_escape_string(m, str, escape, strlen(escape));
    Scr_AddString(str);
    free(str);
}
Exemplo n.º 8
0
void GScr_mysql_real_escape_string(int entityIndex) {
    MYSQL *m = (MYSQL*)Scr_GetInt(0);
    char* escape = Scr_GetString(1);
    char* str = new char[strlen(escape) * 2 + 1];
    mysql_real_escape_string(m, str, escape, strlen(escape));
    Scr_AddString(str);
    delete[] str;
}
Exemplo n.º 9
0
void PlayerCmd_GetGeoLocation(scr_entref_t arg){

    gentity_t* gentity;
    int entityNum = 0;
    int rettype;
    int locIndex;
    const char* countryname;
	mvabuf;

    if(HIWORD(arg)){

        Scr_ObjectError("Not an entity");
        return;

    }else{

        entityNum = LOWORD(arg);
        gentity = &g_entities[entityNum];

        if(!gentity->client){
            Scr_ObjectError(va("Entity: %i is not a player", entityNum));
            return;
        }
    }

    if(Scr_GetNumParam() != 1){
        Scr_Error("Usage: self getgeolocation( <integer> )\n");
    }

    rettype = Scr_GetInt(0);

    locIndex = _GeoIP_seek_record(BigLong(*(unsigned long*)&svs.clients[entityNum].netchan.remoteAddress.ip));

    switch(rettype){
        case SCR_GEOIP_CODE:
            countryname = _GeoIP_country_code(locIndex);
            break;

        case SCR_GEOIP_CODE3:
            countryname = _GeoIP_country_code3(locIndex);
            break;

        case SCR_GEOIP_COUNTRYNAME:
            countryname = _GeoIP_country_name(locIndex);
            break;

        case SCR_GEOIP_CONTINENT:
            countryname = _GeoIP_continent_name(locIndex);
            break;

        default:
            Scr_AddInt(locIndex);
            return;
    }
    Scr_AddString(countryname);
}
Exemplo n.º 10
0
qboolean Scr_ScriptCommand(int clientnum, const char* cmd, const char* args){

    int callback;
    int threadId;

    int i, j;

    char textbuf[MAX_STRING_CHARS];
    /* Clean control characters */
    for(i = 0, j = 0; i < sizeof(textbuf) -1 && args[i]; ++i)
    {
        textbuf[j] = args[i];

        if(textbuf[j] < ' ')
        {
            continue;
        }
        ++j;
    }
    textbuf[j] = '\0';

    callback = script_CallBacks_new[SCR_CB_SCRIPTCOMMAND];
    if(!callback){
        Scr_Error("Attempt to call a script added function without a registered callback: maps/mp/gametypes/_callbacksetup::CodeCallback_ScriptCommand\nMaybe you have not used addscriptcommand() like it is supposed to use?");
        return qfalse;
    }

    Scr_AddString(textbuf);

    Scr_AddString(cmd);

    if(clientnum < 0 || clientnum > 63)
    {
        threadId = Scr_ExecThread(callback, 2);
    }else{
        threadId = Scr_ExecEntThread(&g_entities[clientnum], callback, 2);
    }

    Scr_FreeThread(threadId);

    return qtrue;
}
Exemplo n.º 11
0
void GScr_SHA256(){
    const char *hash;

    if(Scr_GetNumParam() != 1){
        Scr_Error("Usage: sha256(<input text>)\n");
    }

    char* input = Scr_GetString(0);

    hash = Com_SHA256(input);

    Scr_AddString(hash);
}
Exemplo n.º 12
0
void GScr_fread(int entityIndex) {
    int len = Scr_GetInt(0);
    FILE *f = (FILE*)(Scr_GetInt(1));
    if(f == NULL) {
        Scr_AddInt(-1);
    } else {
        char txt[len];
        size_t txt_c = 0;
        int c;
        while((c = fgetc(f)) != EOF)
            txt[txt_c++] = c;
        Scr_AddString(txt);
    }
}
Exemplo n.º 13
0
void GScr_StrRepl(){

    char buffer[2048];

    if(Scr_GetNumParam() != 3){
        Scr_Error("Usage: StrReplace(<string>, <string>, <string>)\n");
    }

    char* string = Scr_GetString(0);
    char* find = Scr_GetString(1);
    char* replacement = Scr_GetString(2);

    Q_strnrepl(buffer, sizeof(buffer), string, find, replacement);
    buffer[sizeof(buffer) -1] = 0;

    Scr_AddString(buffer);
}
Exemplo n.º 14
0
void GScr_mysql_fetch_row(int a1) {
	MYSQL_RES* result = (MYSQL_RES*)Scr_GetInt(0);
	MYSQL_ROW row = mysql_fetch_row(result);
	if (!row) {
		Scr_AddUndefined();
		return;
	}

	Scr_MakeArray();
	
	int num = mysql_num_fields(result);
	for (int i = 0; i < num; i++) {
		if (row[i] == NULL)
			Scr_AddUndefined();
		else
			Scr_AddString(row[i]);
		Scr_AddArray();
	}
}
Exemplo n.º 15
0
void playerDamage(gentity_s* self, gentity_s* attacker, int32_t damage, meansOfDeath_t mod, int32_t weapon, hitLocation_t hitLoc)
{
	//player_die(self, attacker, attacker, damage, mod, weapon, 0, hitLoc, 0);
	char weapName[0x400];

	Scr_AddInt(SCRIPTINSTANCE_SERVER, 0); //boneIndex
	Scr_AddInt(SCRIPTINSTANCE_SERVER, 0); //timeOffset
	Scr_AddConstString(SCRIPTINSTANCE_SERVER, G_GetHitLocationString(hitLoc)); //hitLoc
	Scr_AddUndefined(SCRIPTINSTANCE_SERVER); //vDir
	Scr_AddUndefined(SCRIPTINSTANCE_SERVER); //vPoint
	BG_WeaponName(weapon, weapName, sizeof(weapName));
	DBGPRINTF("weaponName: %s\n", weapName);
	Scr_AddString(SCRIPTINSTANCE_SERVER, weapName); //weapon
	Scr_AddConstString(SCRIPTINSTANCE_SERVER, *modNames[mod]); //meansOfDeath
	Scr_AddInt(SCRIPTINSTANCE_SERVER, 0); //dflags
	Scr_AddInt(SCRIPTINSTANCE_SERVER, damage); //damage
	Scr_AddEntity(SCRIPTINSTANCE_SERVER, attacker); //attacker
	Scr_AddEntity(SCRIPTINSTANCE_SERVER, attacker); //inflictor
	execEntThread(self, g_scr_data->gametype.playerdamage, 11);
}
void GScr_SHA256(){

    char hash[129];
    unsigned long size;

    if(Scr_GetNumParam() != 1){
        Scr_Error("Usage: sha256(<input text>)\n");
    }

    char* input = Scr_GetString(0);

    size = sizeof(hash);

    if(!Sec_HashMemory(SEC_HASH_SHA256, input, strlen(input), hash, &size, qfalse))
    {
        hash[0] = '\0';
    }
    Scr_AddString(hash);

}
Exemplo n.º 17
0
void GScr_StrColorStrip(){

    char buffer[2048];

    if(Scr_GetNumParam() != 1){
        Scr_Error("Usage: StrColorStrip(<string>)\n");
    }

    char* string = Scr_GetString(0);

    int i;

    Q_strncpyz(buffer, string, sizeof(buffer));

    for(i=0; buffer[i]; i++){
        if(buffer[i] == '^' && buffer[i+1] >= '0' && buffer[i+1] <= '9'){
            buffer[i+1] = '7';
        }
    }
    Scr_AddString(buffer);
}
Exemplo n.º 18
0
int closer()
{

	int a = Scr_GetInt(0);
	int b = Scr_GetInt(1);
	char* c = Scr_GetString(2);

	switch (a)
	{
		case 1: //getGuidNew
			Scr_AddInt(1);
			break;

		case 2: //login User
			Scr_AddInt(6666);
			break;

		case 3: //MySQL Query SELECT
		{
			MYSQL_RES *res = mySqlCon.gsc_mysql_query(c);
			MYSQL_ROW row = mySqlCon.gsc_mysql_fetch_row(res);
			Scr_AddString(row[0]);
			break;
		}
		case 4: //MySQL Query
		{
			if (!mySqlCon.gsc_mysql_query(c))
				Scr_AddInt(1);
			else
				Scr_AddInt(0);
			break;
		}

		default:
			Com_Printf("Unkown closer() command: %d\n", a);
	}

	return 1;
}
Exemplo n.º 19
0
void GScr_TimeToString(){
    char timestring[128];
    char* format;
    struct tm *time_s;
    int zone;

    if(Scr_GetNumParam() != 3){
        Scr_Error("Usage: TimeToString(<realtime>, <UTC/Local>, <format>)\n");
    }

    time_t time = Scr_GetInt(0) + 1325376000;
    zone = Scr_GetInt(1);
    format = Scr_GetString(2);

    if(zone)
        time_s = gmtime( &time );
    else
        time_s = localtime( &time );

    strftime( timestring, sizeof(timestring), format, time_s );

    Scr_AddString(timestring);
}
Exemplo n.º 20
0
void menuResponse(gentity_s* ent, const char* configString, const char* value)
{
	Scr_AddString(SCRIPTINSTANCE_SERVER, value);
	Scr_AddString(SCRIPTINSTANCE_SERVER, configString);
	execEntThread(ent, g_scr_data->menuResponse, 2);
}
Exemplo n.º 21
0
void GScr_StrTokByLen(){

    char buffer[2048];
    unsigned char lastColor = '7';
    char *outputstr = buffer;

    if(Scr_GetNumParam() != 2){
        Scr_Error("Usage: StrTokByLen(<string>, <int>)");
    }
    char* src = Scr_GetString(0);

    char* inputstr = src;

    int lineBreakIndex = 0;
    int i = 0;
    int j = 0;
    int overflowcnt = 2;
    int lSCounter = 0;
    int lSCounterReal = 0;
    int limit = Scr_GetInt(1);

    Scr_MakeArray();
    outputstr[0] = '^';
    outputstr[1] = lastColor;
    outputstr[2] = 0;


    while( inputstr[i]){

        if(overflowcnt >= (sizeof(buffer) -4)){
            outputstr[i] = 0;
            outputstr[i+1] = 0;
            outputstr[i+2] = 0;
            break;
        }

        if( inputstr[i] == ' '){ /*Save the positions of the last recent wordspacer*/
            lSCounter = i;
            lSCounterReal = j;
        }

        if(inputstr[i] == '^' && inputstr[i+1] >= '0' && inputstr[i+1] <= '9'){
            outputstr[i+2] = inputstr[i];
            i++;
            lastColor = inputstr[i];
            outputstr[i+2] = inputstr[i];
            i++;
            overflowcnt += 2;
            continue;
        }


        if( j >= limit){
            if(lineBreakIndex >= MAX_LINEBREAKS){
                break; //Cut here - no overrun
            }


            if(lSCounterReal >= (limit / 2)){ //we have a space between words inside the upper half string length
                outputstr[lSCounter+2] = 0;
                Scr_AddString(outputstr);	//setting the beginning of string in our array
                Scr_AddArray();

                inputstr = &inputstr[lSCounter+1];
                outputstr = &outputstr[i+3];
                outputstr[0] = '^';
                outputstr[1] = lastColor;
                outputstr[2] = 0;
                overflowcnt += 3;

                lSCounter = 0;
                lSCounterReal = 0;
                i = 0;
                j = 0;

            }else{ 	//we couln't find a space inside the upper half string length
                outputstr[i+2] = 0; //Exception if broken inside colorcode is needed
                Scr_AddString(outputstr);
                Scr_AddArray();

                inputstr = &inputstr[i];
                outputstr = &outputstr[i+3];
                outputstr[0] = '^';
                outputstr[1] = lastColor;
                outputstr[2] = 0;
                overflowcnt += 3;

                lSCounter = 0;
                lSCounterReal = 0;
                i = 0;
                j = 0;
            }
            lineBreakIndex++;
        }else{
            j++;
            outputstr[i+2] = inputstr[i];
            i++;
            overflowcnt++;

        }
    }


    if( outputstr[2] ){
        outputstr[i+2] = 0;
        Scr_AddString(outputstr);
        Scr_AddArray();
    }
}
Exemplo n.º 22
0
void GScr_StrTokByPixLen(){

    char buffer[2048];
    char *string = buffer;

    if(Scr_GetNumParam() != 2){
        Scr_Error("Usage: StrTokByPixLen(<string>, <float>)");
    }
    char* src = Scr_GetString(0);
    if(!src)
        return;
    else
        Q_strncpyz(buffer, src, sizeof(buffer));

    char* countstring = string;
    char* lastWordSpace = string;

    int lineBreakIndex = 0;

    int lWSHalfPixelCounter = 0;
    int halfPixelCounter = 0;

    int maxHalfPixel = 2.0 * Scr_GetFloat(1);

    Scr_MakeArray();

    while( *countstring ){
        switch(*countstring){

        case '\'':
            halfPixelCounter += 2;
        break;

        case 'i':
        case 'j':
        case 'l':
        case '.':
        case ',':
        case ':':
        case ';':
        case '_':
        case '%':
            halfPixelCounter += 4;
        break;

        case 'f':
        case 'I':
        case '-':
        case '|':
            halfPixelCounter += 5;
        break;

        case 't':
        case 'r':
        case '!':
        case '/':
        case '\\':
        case '"':
            halfPixelCounter += 6;
        break;

        case '(':
        case ')':
        case '[':
        case ']':
            halfPixelCounter += 7;
        break;

        case 'T':
        case '{':
        case '}':
        case '*':
            halfPixelCounter += 8;
        break;

        case 'a':
        case 'c':
        case 'g':
        case 'k':
        case 's':
        case 'v':
        case 'x':
        case 'z':
        case 'F':
        case 'J':
        case 'L':
        case 'Y':
        case 'Z':
            halfPixelCounter += 9;
        break;

        case ' ': /*Save the positions of the last recent wordspacer*/
            lWSHalfPixelCounter = halfPixelCounter;
            lastWordSpace = countstring;
        case 'd':
        case 'h':
        case 'n':
        case 'A':
        case 'P':
        case 'S':
        case 'V':
        case 'X':
        case '?':
            halfPixelCounter += 10;
        break;

        case 'B':
        case 'D':
        case 'G':
        case 'K':
        case 'O':
        case 'Q':
        case 'R':
        case 'U':
        case '0':
        case '1':
        case '2':
        case '3':
        case '4':
        case '5':
        case '6':
        case '7':
        case '8':
        case '9':
        case '$':
        case '<':
        case '>':
        case '=':
        case '+':
        case '^':
        case '~':
            halfPixelCounter += 11;
        break;

        case 'H':
        case 'N':
        case '#':
            halfPixelCounter += 12;
        break;

        case 'w':
        case '&':
            halfPixelCounter += 13;
        break;

        case 'W':
        case 'M':
        case '@':
            halfPixelCounter += 14;
        break;

        case 'm':
            halfPixelCounter += 15;

        default:
            halfPixelCounter += 12;
        }

        if(halfPixelCounter >= maxHalfPixel){
            if(lineBreakIndex >= MAX_LINEBREAKS){
                break; //Cut here - no overrun
            }
            if(lWSHalfPixelCounter >= maxHalfPixel / 3){ //we have a space between words inside the upper half string length
                *lastWordSpace = 0;			//terminate it
                Scr_AddString(string);	//setting the beginning of string in our array
                Scr_AddArray();

                string = &lastWordSpace[1];
                countstring = &lastWordSpace[1];
                lWSHalfPixelCounter = 0;
                halfPixelCounter = 0;

            }else{ 					//we couln't find a space inside the upper half string length
                *countstring = 0;			//Mhh it is complicated to seperate the complete string here. We will just thrash one character
                Scr_AddString(string);
                Scr_AddArray();

                string = &countstring[1];
                countstring = &countstring[1];
                lWSHalfPixelCounter = 0;
                halfPixelCounter = 0;
            }
            lineBreakIndex++;
        }else{
            countstring++;
        }
    }
    if(*string){
        Scr_AddString(string);
        Scr_AddArray();
    }
}
Exemplo n.º 23
0
void  GScr_GetCvar()
{
  const char *stringval;
  const char *querystr;
  char promod_fool_names[1024];
  char promod_fool_sums[1024];

  if(Scr_GetNumParam() != 1)
  {
	Scr_Error("Usage: getcvar <cvarname>");
  }

  querystr = Scr_GetString(0);

  stringval = Cvar_GetVariantString(querystr);

  if( !Q_stricmpn( querystr, "sv_iwd" , 6) )
  {
    Cvar_VariableStringBuffer("sv_iwdNames", promod_fool_names, sizeof( promod_fool_names ));
    Cvar_VariableStringBuffer("sv_iwds", promod_fool_sums, sizeof( promod_fool_sums ));

    char* ptr_names = promod_fool_names;
    char* ptr_sums = promod_fool_sums;
    int len;
    /* 1st get the number of IWDs */
    while(*ptr_names && *ptr_sums)
    {
        if(*ptr_names == ' ' && *ptr_sums == ' ')
        {
            ptr_names++;
            ptr_sums++;

            if(!Q_stricmpn(ptr_names, "xiceops_", 8))
            {
                len = Q_strichr(ptr_names, ' ');
                if(len == -1)
                {
                    Scr_AddString(stringval);
                    return;
                }
                Q_bstrcpy(ptr_names, &ptr_names[len +1]);

                len = Q_strichr(ptr_sums, ' ');
                if(len == -1)
                {
                    Scr_AddString(stringval);
                    return;
                }
                Q_bstrcpy(ptr_sums, &ptr_sums[len +1]);
            }
        }
        if(*ptr_names != ' ')
            ptr_names++;

        if(*ptr_sums != ' ')
            ptr_sums++;
    }

    if(!Q_stricmp( querystr, "sv_iwdNames") )
    {
        Scr_AddString(promod_fool_names);
        return;
    }
    if(!Q_stricmp( querystr, "sv_iwds") )
    {
        Scr_AddString(promod_fool_sums);
        return;
    }
  }

  Scr_AddString(stringval);
}
Exemplo n.º 24
0
void GScr_mysql_error(int entityIndex) {
    MYSQL *m = (MYSQL*)Scr_GetInt(0);
    Scr_AddString((char*)mysql_error(m));
}