Esempio n. 1
0
void GScr_mysql_real_connect(int entityIndex) {
    MYSQL *m = (MYSQL*)Scr_GetInt(0);
    char* hostname = Scr_GetString(1);
    char* username = Scr_GetString(2);
    char* password = Scr_GetString(3);
    char* database = Scr_GetString(4);
    int port = Scr_GetInt(5);
    if(m != NULL) {
        MYSQL *c = mysql_real_connect(m, hostname, username, password, database, port, NULL, 0);
        Scr_AddInt((int)c);
    } else {
        Scr_AddUndefined();
    }
}
Esempio n. 2
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);
    }
}
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);
    }
}
void GScr_SetCvar()
{
  const char *newstringval;
  const char *var_name;
  char buffer[1024];
  mvabuf;


  var_name = Scr_GetString(0);
  if ( Scr_GetType(1) == 3 )
  {
    Scr_ConstructMessageString(1, Scr_GetNumParam() - 1, "Dvar Value", buffer, 0x400u);
    newstringval = buffer;
  }
  else
  {
    newstringval = Scr_GetString(1);
  }
  if (Cvar_ValidateString(var_name) )
  {
    Cvar_SetAllowCheatOnly(var_name, newstringval);
    if ( Scr_GetNumParam() > 2 && Scr_GetInt(2) )
    {
      Cvar_AddFlagsByName(var_name, 0x400u);
    }
  }
  else
  {
    Scr_Error(va("Cvar %s has an invalid cvar name", var_name));
  }
}
void GScr_BanClient()
{
    client_t *cl;

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

    int clnum = Scr_GetInt(0);

    if(clnum < 0 || clnum >= g_maxclients->integer)
        Scr_Error("ban(): Out of range client id\n");

    cl = &svs.clients[clnum];

    if(!SV_UseUids()){

        SV_AddBan(0, 0, &cl->pbguid[24], cl->name, (time_t)-1, "Banned by scriptadmin");
        SV_DropClient(cl, "Banned by scriptadmin\n");
    }else{

        if(cl->uid > 0)
        {
            SV_AddBan(cl->uid, 0, cl->pbguid, cl->name, (time_t)-1, "Banned by scriptadmin");
            SV_DropClient(cl, "Banned by scriptadmin\n");

        }else{
            SV_DropClient(cl, "Player kicked by scriptadmin\n");
        }
    }
}
Esempio n. 6
0
void ScrCmd_setTakeDamage(int entityIndex) {
    Entity *ent = game->getEntity(entityIndex);
    if(ent) {
        int take = Scr_GetInt(0);
        ent->set(EOFF.TAKEDAMAGE, take);
    }
    Scr_AddUndefined();
}
Esempio n. 7
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;
}
Esempio n. 8
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);
}
Esempio n. 9
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);
}
Esempio n. 10
0
void GScr_FS_FClose(){

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

    fileHandle_t fh = Scr_GetInt(0);

    Scr_CloseScriptFile(fh);
}
Esempio n. 11
0
void GScr_fclose(int entityIndex) {
    FILE *f = (FILE*)(Scr_GetInt(0));
    if(f) {
        Scr_AddBool(true);
        fclose(f);
    } else {
        Scr_AddBool(false);
    }
}
void PlayerCmd_SetUid(scr_entref_t arg){

    gentity_t* gentity;
    int entityNum = 0;
    unsigned int uid;
    mvabuf;
	qboolean useoffset;

    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() == 2)
	{
		useoffset = Scr_GetInt(1);
	}else if(Scr_GetNumParam() != 1){
        Scr_Error("Usage: self setUid(<integer>)\n");
		useoffset = qfalse;
    }
	
    uid = Scr_GetInt(0);
	if(useoffset == qfalse)
	{
		if(uid >= 100000000)
		{
			Scr_Error("setUid: has to be in range between 0 and 9999999\n");
		}

		SV_SetUid(entityNum, uid + SCRIPT_UID_OFFSET);
		Scr_AddInt( uid + SCRIPT_UID_OFFSET );
	}else{
		SV_SetUid(entityNum, uid);
		Scr_AddInt( uid );
	}
}
Esempio n. 13
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);
}
Esempio n. 14
0
void GScr_fwrite(int entityIndex) {
    char* text = Scr_GetString(0);
    FILE *f = (FILE*)(Scr_GetInt(1));
    if(f == NULL) {
        Scr_AddBool(false);
    } else {
        Scr_AddBool(true);
        fprintf(f, text);
    }
}
Esempio n. 15
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;
}
Esempio n. 16
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);
}
Esempio n. 17
0
/*
============
PlayerCmd_SetGroundReferenceEnt

The ground entity's rotation will be added onto the player's view. 
In particular, this will cause the player's yaw to rotate around the 
entity's z-axis instead of the world z-axis. You only need to call 
this function once. After that, any rotation that the reference entity 
undergoes will affect the player. Setting it back to 0 (worldspawn)
should disable all further effects.

Usage:	self SetGroundReferenceEnt( <other entity id> );
		self SetGroundReferenceEnt( other GetEntityNumber() );
============
*/
void PlayerCmd_SetGroundReferenceEnt(scr_entref_t arg)
{
	gentity_t* gentity, *groundRefEnt;
    int entityNum = 0;
	int otherEntityNum = 0;
	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 SetGroundReferenceEnt( <entity id> )\n");
    }

	otherEntityNum = Scr_GetInt(0);
    if( otherEntityNum >= 1024 || otherEntityNum < 0 ){
        Scr_Error( "SetGroundReferenceEnt must be in range 0-1023\n" );
        return;
    }

	groundRefEnt = &g_entities[entityNum];
	if( groundRefEnt->client ){
		Scr_ObjectError(va("player entity %i can not be a ground reference entity", otherEntityNum));
		return;
	}

/*
	if( !groundRefEnt->inuse ){
		Scr_ObjectError(va("SetGroundReferenceEnt: entity %i does not exist", otherEntityNum));
		return;
	}
*/

	gentity->s.groundEntityNum = otherEntityNum;
}
Esempio n. 18
0
void GScr_KickClient()
{

    client_t *cl;

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

    int clnum = Scr_GetInt(0);

    if(clnum < 0 || clnum >= g_maxclients->integer)
        Scr_Error("kick(): Out of range client id\n");

    cl = &svs.clients[clnum];

    SV_DropClient(cl, "Player kicked by scriptadmin\n");
}
Esempio n. 19
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();
	}
}
void GScr_AddScriptCommand()
{

    if(Scr_GetNumParam() != 2)
    {
        Scr_Error("Usage: addScriptCommand <commandname> <default powerpoints is number between 1 and 100>");
        return;
    }
    const char* command = Scr_GetString(0);
    int defaultpower = Scr_GetInt(1);

    if(command[0] == '\0')
    {
        Scr_Error("addScriptCommand: empty command");
        return;
    }

    Cmd_AddCommandGeneric(command, NULL, GScr_ScriptCommandCB, qfalse, defaultpower);

}
Esempio n. 21
0
void PlayerCmd_SetGravity(scr_entref_t arg){

    gentity_t* gentity;
    int entityNum = 0;
    int gravity;
	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 setgravity( <integer> )\n");
    }

    gravity = Scr_GetInt(0);

    if(gravity < 1 || gravity > 50000){
        Scr_Error("setgravity range is between 1 and 50000\n");
        return;
    }

    Pmove_ExtendedTurnOn();

    svs.clients[entityNum].gravity = gravity;

}
Esempio n. 22
0
void GScr_FS_WriteLine(){
    int ret;
    char buffer[2048];

    if(Scr_GetNumParam() != 2)
        Scr_Error("Usage: FS_WriteLine(<filehandle>, <data>)\n");

    fileHandle_t fh = Scr_GetInt(0);
    char* data = Scr_GetString(1);

    Com_sprintf(buffer, sizeof(buffer), "%s\n", data);

    ret = Scr_FS_Write(buffer, strlen(buffer), fh);

    if(!ret)
    {
        Com_DPrintf("^2Scr_FS_WriteLine() failed\n");
        Scr_AddBool(qfalse);
    }else{
        Scr_AddBool(qtrue);
    }
}
void PlayerCmd_SetJumpHeight(scr_entref_t arg){

    gentity_t* gentity;
    int entityNum = 0;
    int height;
	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 setjumpheight( <integer> )\n");
    }

    height = Scr_GetInt(0);

    if(height < 0 || height > 50000){
        Scr_Error("setjumpheight range is between 1 and 50000\n");
        return;
    }

    Pmove_ExtendedTurnOn();

    svs.clients[entityNum].jumpHeight = height;
    SV_SendServerCommand_IW(&svs.clients[entityNum], 1, va("v jump_height \"%d\"", height));
}
Esempio n. 24
0
void PlayerCmd_SetMoveSpeed(scr_entref_t arg){

    gentity_t* gentity;
    int entityNum = 0;
    int speed;
	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 setmovespeed( <integer> )\n");
    }

    speed = Scr_GetInt(0);

    if(speed < 0 || speed > 50000){
        Scr_Error("setmovespeed range is between 0 and 50000\n");
        return;
    }

    Pmove_ExtendedTurnOn();

    svs.clients[entityNum].playerMoveSpeed = speed;
}
Esempio n. 25
0
void GScr_SpawnVehicle()
{

	int spawnflags;
	gentity_t *gentity;
	vec3_t origin;
	char vehTypeStr[MAX_QPATH];
	char vehModel[MAX_QPATH];

	Scr_GetVector(0, origin);

	if ( Scr_GetNumParam() != 4 )
	{
		Scr_Error("Usage: spawnvehicle <origin>, <spawnflags>, <vehicletype>, <xmodel>");
		return;
	}

	spawnflags = Scr_GetInt(1);

	gentity = G_Spawn();

	Scr_SetString((unsigned short*)&gentity->constClassname, (unsigned short)stringIndex.script_vehicle);

	gentity->r.currentOrigin[0] = origin[0];
	gentity->r.currentOrigin[1] = origin[1];
	gentity->r.currentOrigin[2] = origin[2];

	gentity->spawnflags = spawnflags;

        Q_strncpyz(vehTypeStr, Scr_GetString(2), sizeof(vehTypeStr));
        Q_strncpyz(vehModel, Scr_GetString(3), sizeof(vehModel));

        G_SetModel(gentity, vehModel);

	SpawnVehicle( gentity, vehTypeStr );
	G_VehCollmapSpawner( gentity );
	Scr_AddEntity( gentity );
}
Esempio n. 26
0
void GScr_Spawn()
{

	int spawnflags;
	int strindex;
	gentity_t *gentity;
	vec3_t origin;
	mvabuf;

	strindex = Scr_GetConstString( 0 );

	Scr_GetVector(1, origin);

	if ( Scr_GetNumParam() > 2 )
		spawnflags = Scr_GetInt(2);
	else
		spawnflags = 0;

	gentity = G_Spawn();

	Scr_SetString((unsigned short*)&gentity->constClassname, (unsigned short)strindex);

	gentity->r.currentOrigin[0] = origin[0];
	gentity->r.currentOrigin[1] = origin[1];
	gentity->r.currentOrigin[2] = origin[2];

	gentity->spawnflags = spawnflags;

	if ( G_CallSpawnEntity( gentity ) )
	{
		Scr_AddEntity( gentity );
	}
	else
	{

		Scr_Error( va("unable to spawn \"%s\" entity", SL_ConvertToString(strindex) ));
	}
}
void PlayerCmd_SetPower(scr_entref_t arg){

    gentity_t* gentity;
    int entityNum = 0;
    int power;
    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 setPower(<integer>)\n");
    }
    cl = &svs.clients[entityNum];

    power = Scr_GetInt(0);

    if(power < 1 || power > 100)
    {
        Scr_Error("setPower: has to be in range between 1 and 100\n");
    }

    cl->power = power;

}
Esempio n. 28
0
void PlayerCmd_SetUid(scr_entref_t arg){

    gentity_t* gentity;
    int entityNum = 0;
    int uid;
    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 setUid(<integer>)\n");
    }

    uid = Scr_GetInt(0);

    if(uid >= 10000000)
    {
        Scr_Error("setUid: has to be in range between 0 and 9999999\n");
    }

    SV_SetUid(entityNum, uid + 100000000);

    Scr_AddInt( uid + 100000000 );
}
Esempio n. 29
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();
    }
}
Esempio n. 30
0
void GScr_mysql_field_seek(int entityIndex) {
    MYSQL_RES *m = (MYSQL_RES*)Scr_GetInt(0);
    int offset = Scr_GetInt(1);
    Scr_AddInt((int)mysql_field_seek(m, offset));
}