SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Plugin Development

Reply
 
Thread Tools Display Modes
Old 04/03/2012, 11:23 PM   #1
jhonyxakep
Gangsta
 
jhonyxakep's Avatar
 
Join Date: May 2011
Location: Russia, Vladivostok
Posts: 795
Reputation: 43
Smile System Control

System Control Plugin
Version 0.3
Author: jhonyxakep
Mail:jhonyxakep@qip.ru
ICQ:354794596
Jabber:jhonyxakep@qip.ru


I thought this plugin could be useful in the english section.

Description:

The plugin uses the BASS library (http://un4seen.com) to work with audio files.

In the plug collected some very useful features not available in SA: MP



Installation:

Windows:
Put the files from the plugins in the plugins folder on the server.

bass.dll file should be placed in the root directory of the server (the ones where the samp-server.exe), or the windows system directory


Linux:
File libbass.so should be put in the folder / lib /, / usr / lib /, / usr / local / lib /.

Add the plug-in in plugins section in SA: MP config.

Include SystemControl.inc to your script.


Use:

Plugin functions:

ClearConsole(); - clears the server console. In Windows, use the call CLS, in Linux - clear


system(file[]); - Launches an external application (on server) and waits for its completion. Returns exit code of the application. In Linux equivalent function WinExec.

WinExec(file[],ShowParam); - launch an external application (on server) without having to wait

In the first argument specifies the path to the application that should run.

ShowParam can be one of constant:
PHP Code:
#define SW_HIDE             0
#define SW_SHOWNORMAL       1
#define SW_NORMAL           1
#define SW_SHOWMINIMIZED    2
#define SW_SHOWMAXIMIZED    3
#define SW_MAXIMIZE         3
#define SW_SHOWNOACTIVATE   4
#define SW_SHOW             5
#define SW_MINIMIZE         6
#define SW_SHOWMINNOACTIVE  7
#define SW_SHOWNA           8
#define SW_RESTORE          9
#define SW_SHOWDEFAULT      10
#define SW_FORCEMINIMIZE    11
#define SW_MAX              11 
In the Linux version is a wrapper function over the system, in which case the argument is ignored ShowParam

More information about the work function can be read on MSDN: http://msdn.microsoft.com/en-us/libr...(v=vs.85).aspx

Fixed:
Sleep(milliseconds); - suspends the execution of an application for a specified number of milliseconds

Can be used with multithreading plug-ins.
In Linux uses usleep

http://msdn.microsoft.com/en-us/libr...(v=vs.85).aspx


GetCursorPos(&x,&y); - get the position of the cursor on the screen (the server)

Return the position of the cursor on the server.
In linux returns 0.

http://msdn.microsoft.com/en-us/libr...(v=vs.85).aspx


GetAudioURLFileLengthSec(URL[]); - returns the length of the audio stream in seconds
GetAudioURLFileLengthBytes(URL[]); - returns the length in bytes of the audio stream

Uses BASS library. Gets the length of the audio stream or file from the server.
If the stream does not have the length function returns -1, otherwise returns GetAudioURLFileLengthSec length in seconds, GetAudioURLFileLengthBytes in bytes.

ListDirs(path[]); - dirs listing in current path. Call OnListDir if dir founded.

Example:
PHP Code:
public OnFilterScriptInit()
{
           
ListDirs("."); 
    return 
1;
}

public 
OnListDir(dir[])
{

    new 
string[35];
    
format(string,sizeof(string),"Found dir: %s",dir);
    print(string);
    return 
1;

ListFiles(path[]); - files listing in current path. Call OnListFile if file founded.

Example:
PHP Code:
public OnFilterScriptInit()
{
           
ListFiles(".");
    return 
1;
}

public 
OnListFile(file[])
{

    new 
string[35];
    
format(string,sizeof(string),"Found file: %s",dir);
    print(string);
    return 
1;



Example filterscript
PHP Code:
/*
System Control Plugin
by jhonyxakep

Mail:jhonyxakep@qip.ru
ICQ:354794596
Jabber:jhonyxakep@qip.ru
 */

#include <a_samp>
#include "SystemControl"

public OnFilterScriptInit()
{
    
WinExec("notepad.exe",SW_NORMAL);//Run Notepad (only windows)

    
new string[35];
    
format(string,sizeof(string),"Stream Length: %d Seconds",GetAudioURLFileLengthSec("http://listen.radio-mixer.ru:8000/DNB")); //return -1, because stream does not have the length
    
print(string); 

    
format(string,sizeof(string),"Stream Length: %d Seconds"GetAudioURLFileLengthSec("http://upload.wikimedia.org/wikipedia/ru/4/4d/Omen.ogg")); //return 35 seconds.
    
print(string);

    return 
1;
}

public 
OnPlayerText(playerid,text[])
{
    return 
1;
}

public 
OnPlayerUpdate(playerid)
{
    
ClearConsole(); //Clear the console window

    
new xy;
    
GetCursorPos(x,y); //x,y contain cursor position

    
new string[35];
    
format(string,sizeof(string),"X:%d Y:%d",x,y);

    print(string);

    return 
1;


Callbacks:
public OnListDir(dir[])
public OnListFile(file[])


Useful const:
Math:

PHP Code:
 M_E        e
 
M_LOG2E    log2(e)
 * 
M_LOG10E   log10(e)
 * 
M_LN2      ln(2)
 * 
M_LN10     ln(10)
 * 
M_PI       pi
 
M_PI_2     pi/2
 
M_PI_4     pi/4
 
M_1_PI     1/pi
 
M_2_PI     2/pi
 
M_2_SQRTPI 2/sqrt(pi)
 * 
M_SQRT2    sqrt(2)
 * 
M_SQRT1_2  1/sqrt(2



Who wants to see more of the system, Windows, and other functions in this plug-in, write in the comments.


SysControl.zip = Include + Example Script + linux and windows version of plugin + Source code


Download:

in attachment

Sorry for my bad English.

Original post: http://forum.sa-mp.com/showthread.ph...32#post1708632
Attached Files
File Type: zip SysControl.zip (1,009.8 KB, 133 views)

Last edited by jhonyxakep; 09/03/2012 at 08:11 AM.
jhonyxakep is offline   Reply With Quote
Old 05/03/2012, 05:02 PM   #2
Gamer_Z
High-roller
 
Gamer_Z's Avatar
 
Join Date: Jun 2009
Location: Fontys University of Applied Sciences, Eindhoven, NL
Posts: 2,778
Reputation: 989
Default Re: System Control

I'm kinda wondering how everyone is going to use this to exploit hosters...
Gamer_Z is offline   Reply With Quote
Old 05/03/2012, 05:15 PM   #3
T0pAz
Guest
 
Posts: n/a
Default Re: System Control

GetCursorPos(&x,&y); - Awesome!
  Reply With Quote
Old 05/03/2012, 05:15 PM   #4
Mauzen
High-roller
 
Mauzen's Avatar
 
Join Date: Jun 2007
Location: Western Germany
Posts: 4,408
Reputation: 1130
Default Re: System Control

Well, it still cant do more than the permissions allow, so as long as the hosters set everything up properly nothings going to be exploited

Anyways, nice plugin, im quite sure that some people can make good use of system executions.
Mauzen is offline   Reply With Quote
Old 05/03/2012, 05:40 PM   #5
TheArcher
High-roller
 
TheArcher's Avatar
 
Join Date: Dec 2009
Location: Home
Posts: 2,517
Reputation: 233
Default Re: System Control

How can i use GetCursorPos if the cursor is hidden? btw good job
__________________
TheArcher is offline   Reply With Quote
Old 05/03/2012, 05:52 PM   #6
T0pAz
Guest
 
Posts: n/a
Default Re: System Control

helloworld.cpp
pawn Code:
//----------------------------------------------------------
/*

SA:MP System Control Plugin

Mail:jhonyxakep@qip.ru
ICQ:354794596
Jabber:jhonyxakep@qip.ru

*/

//----------------------------------------------------------

#include "../SDK/amx/amx.h"
#include "../SDK/plugincommon.h"
//#include "../PAWN/functions.h"
#include <iostream>
#include <string>
#include <cstring>
#include <sstream>
#include <stdio.h>


#include "bass.h" //For audio processing
#pragma comment (lib, "bass.lib")

#ifdef _WIN32
#include <windows.h>
#include <process.h> //Threading
#else
#include <unistd.h>
#include <sys/stat.h>
#include <sys/types.h>
#endif


//----------------------------------------------------------



typedef void (*logprintf_t)(char* format, ...);
typedef int(*Send)(int a); //(int a,LPCSTR ip,LPCSTR send);
bool  (*IInit)(int);
bool  (*CreateFM)();
int (*PlayerConnect)(int16_t);
//void (*pFunction)(char *);
logprintf_t logprintf;
void **ppPluginData;
extern void *pAMXFunctions;

AMX *globamx;
DWORD the;



//----------------------------------------------------------
// The Support() function indicates what possibilities this
// plugin has. The SUPPORTS_VERSION flag is required to check
// for compatibility with the server.

PLUGIN_EXPORT unsigned int PLUGIN_CALL Supports()
{
    return SUPPORTS_VERSION | SUPPORTS_AMX_NATIVES;
}


//----------------------------------------------------------
// The Unload() function is called when the server shuts down,
// meaning this plugin gets shut down with it.

PLUGIN_EXPORT void PLUGIN_CALL Unload( )
{
    logprintf( "System Control Unloading..." );
   


    logprintf( "System Control UNLOADED!" );
}



//**********************
const char *GetString( AMX *amx, cell params ) //Convert cell to String
{
    cell* phys_addr;
    int length;
    char* dest;
    amx_GetAddr( amx, params, &phys_addr );
    amx_StrLen( phys_addr, &length );
    // Fix for null string crash
    if ( length <= 0 )
    {
        dest = new char[ 5 ];
        sprintf( dest, "NULL" );
        dest[ 5 ] = '\0';
        return dest;
    }
    dest = new char[ length + 1 ];
    amx_GetString( dest, phys_addr, 0, UNLIMITED );
    dest[ length ] = '\0';
    return dest;
}

void SetString( AMX *amx, cell addr, const char *source ) //String to cell
{
    cell* dest;
    amx_GetAddr( amx, addr, &dest );
    amx_SetString( dest, source, 0, 0, strlen( source ) + 1 );
}

//***********************


//Внешние функции SA-MP
/*
int IsPlayerConnected(AMX *amx,int playerid) // AMX *amx must stay but it's just the playerid parameter that counts in his function.
{
    int index;
    if (amx == NULL) amx=globamx;
    if(!amx_FindPublic(amx, "__IsPlayerConnected", &index))
    {
        cell retVal;
        amx_Push(amx, playerid);
        amx_Exec(amx, &retVal, index);
        return (int)retVal;
    }
    return -1;
}


int sampSendClientMessage(int playerid,int color,const char * message)
{
    logprintf("sendClientMessageCalled");
    AMX* amx;
    amx=globamx;
    int idx;
    if(!amx_FindPublic(amx, "sampSendClientMessage", &idx))
    {
        cell ret, amx_Address,*phys_addr;
        amx_PushString(amx,&amx_Address,&phys_addr,message,0,0);
        amx_Push(amx, color);
        amx_Push(amx, playerid);
        amx_Exec(amx, &ret, idx);
        return (int)ret;
    }
   
    return 0;









int sampSetWeather(AMX* amx,int weath)
{
    if (amx == NULL) amx=globamx;
    int idx;
    if(!amx_FindPublic(amx, "sampSetWeather", &idx))
    {
        cell ret;
        amx_Push(amx, weath);
        amx_Exec(amx, &ret, idx);
        return (int)ret;
    }
    return 0;

}

//Внешние функции SA-MP

*/


//----------------------------------------------------------
// The Load() function gets passed on exported functions from
// the SA-MP Server, like the AMX Functions and logprintf().
// Should return true if loading the plugin has succeeded.

PLUGIN_EXPORT bool PLUGIN_CALL Load( void **ppData )
{
    pAMXFunctions = ppData[PLUGIN_DATA_AMX_EXPORTS];
    logprintf = (logprintf_t)ppData[PLUGIN_DATA_LOGPRINTF];

    logprintf( "System Control loading..." );
   
    BASS_Init(0, 44100, 0, NULL, NULL);
   
    logprintf( "System Control LOADED!" );
    return true;
}


//----------------------------------------------------------
// This is the sourcecode of the HelloWorld pawn native that we
// will be adding. "amx" is a pointer to the AMX-instance that's
// calling the function (e.g. a filterscript) and "params" is
// an array to the passed parameters. The first entry (params[0])
// is equal to  4 * PassedParameters, e.g. 16 for 4 parameters.


static cell AMX_NATIVE_CALL n_Init( AMX* amx, cell* params ) //Init
{
    logprintf( "System Control started." );
    return 1;
}
/*
static cell AMX_NATIVE_CALL n_PlConnect( AMX* amx, cell* params ) //OnPlayerConnect
{


    if(IsPlayerConnected(amx, params[1]))
    {
   
    }


    return 0;
}


static cell AMX_NATIVE_CALL n_PlDisconnect( AMX* amx, cell* params ) //OnPlayerDisconnect
{
    globamx = amx;
    char *s;
    if (params[2] == 0) s="Timed out"; else
        if (params[2] == 1) s="Left normally"; else s="Kicked or banned";
           

    logprintf("%s %i Reason: %s","Player successfully Disconnected: ",params[1],s );



    return 0;
}

static cell AMX_NATIVE_CALL n_PlText( AMX* amx, cell* params ) //OnPlayerText
{
    globamx = amx;
    logprintf("%s %i %s %s","Player ",params[1],"say: ", GetString( amx, params[2] ));
    sampSendClientMessage(params[1],0xAAAAAAAA,GetString(amx, params[2]));
    return 0;
}
*/

//**********************
/*

static cell AMX_NATIVE_CALL n_PlaySoundFileToStream( AMX* amx, cell* params ) //Запускает песню в эфир(если сервер запущен)
{
   
    globamx = amx;
    //logprintf("PlaySoundToStream %s",GetString( amx, params[1] )); //Думаю это нам тоже уже ненадо
    loc = BASS_StreamCreateFile(FALSE,GetString(amx, params[1]), 0, 0,BASS_STREAM_DECODE);//|BASS_SAMPLE_FLOAT|BASS_MIXER_BUFFER
    BASS_Mixer_StreamAddChannel(cast,loc,BASS_STREAM_AUTOFREE|BASS_MIXER_BUFFER);
    //BASS_ChannelPlay(cast,false); //Теперь ненужно, мы не используем звуковуху
    BASS_ChannelSetSync(loc,BASS_SYNC_FREE,NULL,&EndOfFile, NULL);
    return 0;
}


static cell AMX_NATIVE_CALL n_PlaySoundUrlToStream( AMX* amx, cell* params ) //Запускает песню в эфир по указанному URL
{
   
    globamx = amx;
    loc = BASS_StreamCreateURL(GetString(amx, params[1]), 0,BASS_STREAM_DECODE,0,0);
    BASS_Mixer_StreamAddChannel(cast,loc,BASS_STREAM_AUTOFREE|BASS_MIXER_BUFFER);
    BASS_ChannelSetSync(loc,BASS_SYNC_FREE,NULL,&EndOfFile, NULL);
    return 0;
}


static cell AMX_NATIVE_CALL n_StopPlaying( AMX* amx, cell* params ) //Останавливает воспроизведение текущего трека
{
    globamx = amx;
    if(!BASS_Mixer_ChannelRemove(loc))
    {
    return BASS_ErrorGetCode();
    }
   
    return 0;
}



static cell AMX_NATIVE_CALL n_SoundServerStop( AMX* amx, cell* params ) //Останавливаем сервер вещания
{
    globamx = amx;
    if(!BASS_Encode_Stop(encoder))
    {
    return BASS_ErrorGetCode();
    }
   endt = true;
    return 0;
}

static cell AMX_NATIVE_CALL n_IsServerActive( AMX* amx, cell* params ) //Кодер запущен значит сервер запущен => IsEncoderActive == IsServerActive =)
{
    globamx = amx;
    if(BASS_Encode_IsActive(encoder) == BASS_ACTIVE_PLAYING)
    {
        return true;
    }
    return false;
}
*/

//*******************************

/*
static cell AMX_NATIVE_CALL n_PlCommand( AMX* amx, cell* params ) //OnPlayerText
{
    globamx = amx;
    logprintf("%s %i %s %s","Player ",params[1],"command: ", GetString( amx, params[2] ));

    return 0;
}

static cell AMX_NATIVE_CALL n_PlSpawn( AMX* amx, cell* params ) //OnPlayerText
{
    globamx = amx;
    logprintf("%s %i %s","Player ",params[1],"successfully spawned");

    return 0;
}

static cell AMX_NATIVE_CALL n_PlDeath( AMX* amx, cell* params ) //OnPlayerText
{
    globamx = amx;
    logprintf("Player %i has killed by id %i by reason %i",params[1],params[2],params[3]);

    return 0;
}
*/



static cell AMX_NATIVE_CALL n_WinExec( AMX* amx, cell* params ) //WinExec function (and *nix eqialent)
{
   
    globamx = amx;
    #ifdef _WIN32
    return WinExec(GetString(amx, params[1]),params[2]);
    #else
    return system (GetString(amx, params[1]));
    #endif
   
}

static cell AMX_NATIVE_CALL n_system( AMX* amx, cell* params ) //C++ system dunction
{
   
    globamx = amx;

    return system (GetString(amx, params[1]));

   
}


static cell AMX_NATIVE_CALL n_ClearConsole( AMX* amx, cell* params ) //Console Clear
{
   
    globamx = amx;

   
        #ifdef _WIN32
    return system ("CLS");
    #else
    return system ("clear");
    #endif
   
}

static cell AMX_NATIVE_CALL n_Sleep( AMX* amx, cell* params ) //process delay
{
   
    globamx = amx;
    #ifdef _WIN32
    Sleep(params[1]);
    #else
    usleep(params[1]*100);
    #endif

   
    return 0;
}

static cell AMX_NATIVE_CALL n_GetCurPosX( AMX* amx, cell* params ) //GetCursorPosX only for windows
{
   
    globamx = amx;
   
    #ifdef _WIN32
    POINT cp;
    GetCursorPos(&cp);
    return cp.x;
    #else
    return 0;
    #endif

}

static cell AMX_NATIVE_CALL n_GetCurPosY( AMX* amx, cell* params ) //GetCursorPosY
{
   
    globamx = amx;

    #ifdef _WIN32
    POINT cp;
    GetCursorPos(&cp);
    return cp.y;
    #else
    return 0;
    #endif

}

static cell AMX_NATIVE_CALL n_GetAudioURLFileLengthSec( AMX* amx, cell* params ) //Return stream length
{
   
    globamx = amx;
    HSTREAM loc = BASS_StreamCreateURL(GetString(amx, params[1]), 0,BASS_STREAM_DECODE,0,0);
    int len = BASS_ChannelBytes2Seconds(loc, BASS_ChannelGetLength(loc, BASS_POS_BYTE));
    BASS_StreamFree(loc);
    return len;
}

static cell AMX_NATIVE_CALL n_GetAudioURLFileLengthBytes( AMX* amx, cell* params ) //Return stream length
{
   
    globamx = amx;
    HSTREAM loc = BASS_StreamCreateURL(GetString(amx, params[1]), 0,BASS_STREAM_DECODE,0,0);
    int len = BASS_ChannelGetLength(loc, BASS_POS_BYTE);
    BASS_StreamFree(loc);
    return len;
}

// And an array containing the native function-names and the functions
// specified with them, e.g. HelloWorld -> n_HelloWorld in this example.
AMX_NATIVE_INFO smpExNatives[ ] =
{
    { "Init",           n_Init },
/*  { "PlConnect",          n_PlConnect},
    { "PlDisconnect",           n_PlDisconnect},
    { "PlText",         n_PlText},
    { "PlCommand",          n_PlCommand},
    { "PlSpawn",            n_PlSpawn},*/

    { "WinExec",            n_WinExec},
    { "Sleep",          n_Sleep},
    { "system",         n_system},
    { "GetCurPosX",         n_GetCurPosX},
    { "GetCurPosY",         n_GetCurPosY},
    { "ClearConsole",           n_ClearConsole},
    { "GetAudioURLFileLengthSec",           n_GetAudioURLFileLengthSec},
    { "GetAudioURLFileLengthBytes",         n_GetAudioURLFileLengthBytes},
    { 0,                    0 }
};
//
//----------------------------------------------------------
// The AmxLoad() function gets called when a new gamemode or
// filterscript gets loaded with the server. In here we register
// the native functions we like to add to the scripts.

PLUGIN_EXPORT int PLUGIN_CALL AmxLoad( AMX *amx )
{
    return amx_Register( amx, smpExNatives, -1 );
}

//----------------------------------------------------------
// When a gamemode is over or a filterscript gets unloaded, this
// function gets called. No special actions needed in here.

PLUGIN_EXPORT int PLUGIN_CALL AmxUnload( AMX *amx )
{
    return AMX_ERR_NONE;
}

This plugin makes no sense.
  Reply With Quote
Old 05/03/2012, 06:10 PM   #7
Zxdsl
Big Clucker
 
Join Date: Jan 2012
Location: Really IDK
Posts: 118
Reputation: 9
Default Re: System Control

Kinda Good Job
__________________
<•>Teen Age Criminals | World Of Fun+DM[•] (=) IP ~ 81.205.0.219:7777

-=-=-=-=-=-=-=-=-=-=-=-=-=-

[My 1st FS] [Auto Bike Helmet] = http://forum.sa-mp.com/showthread.php?t=329619

-=-=-=-=-=-=-=-=-=-=-=-=-=-

Give Me ReputatiOn If My Post Help You
Zxdsl is offline   Reply With Quote
Old 05/03/2012, 08:13 PM   #8
jhonyxakep
Gangsta
 
jhonyxakep's Avatar
 
Join Date: May 2011
Location: Russia, Vladivostok
Posts: 795
Reputation: 43
Default Re: System Control

Quote:
How can i use GetCursorPos if the cursor is hidden
This function works only on Windows, but if the cursor is hidden, it will still have a position

Quote:
This plugin makes no sense.
Why? You do not like the source plug-in?
jhonyxakep is offline   Reply With Quote
Old 05/03/2012, 08:19 PM   #9
TheArcher
High-roller
 
TheArcher's Avatar
 
Join Date: Dec 2009
Location: Home
Posts: 2,517
Reputation: 233
Default Re: System Control

Quote:
Originally Posted by jhonyxakep View Post
This function works only on Windows, but if the cursor is hidden, it will still have a position
What is it used for? You can't see the arrow and you just get a random coords for your cursor.
__________________
TheArcher is offline   Reply With Quote
Old 05/03/2012, 08:26 PM   #10
Gamer_Z
High-roller
 
Gamer_Z's Avatar
 
Join Date: Jun 2009
Location: Fontys University of Applied Sciences, Eindhoven, NL
Posts: 2,778
Reputation: 989
Default Re: System Control

pawn Code:
cell AMX_NATIVE_CALL n_Sleep

You actually know that this will stop the whole server for the amount of miliseconds?

Also, em, Sleep(miliseconds) != usleep(miliseconds * 100).

microseconds to miliseconds conversion goes actually by x 1000... not x 100.
Gamer_Z is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[FilterScript] Vehicle Control System [0.3c] Shadow_ Filterscripts 52 25/04/2013 06:00 PM
[FilterScript] SA-MP 0.3c Vehicle Control System (Control everything, you want) Auxxx Filterscripts 78 09/10/2012 10:40 PM
[FilterScript] Vehicle Control System [First Release] Jack_Leslie Filterscripts 38 27/02/2012 07:20 PM
[FilterScript] Vehicle Control System With Dialogs! - TLG - [NEW] rbcrp Filterscripts 3 13/12/2011 12:58 PM
Vehicle Control System GTA-Roleplay Help Archive 3 09/08/2011 04:32 PM


All times are GMT. The time now is 05:23 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.