Author Topic: Full document for Squirrel plugins  (Read 8079 times)

0 Members and 1 Guest are viewing this topic.

Offline ysc123

  • Street Thug
  • *
  • Posts: 29
    • View Profile
Full document for Squirrel plugins
« on: October 01, 2014, 11:00:10 pm »
0.4 Sockets
Code: [Select]
Function:
NewSocket(pszDataFunc)

Class:
CSquirrelSockets
Connect(szHost,usPort)
Disconnect(ucConn)
Send(sz)
SendClient(sz,ucConn)
SetLostConnFunc(function)
SetNewConnFunc(function)
Start(usPort,usMaxConns)
Stop()

0.4 Hashing Algorithms
Code: [Select]
base64_encode(Input)
base64_decode(Input)
MD5(Input)
SHA1(Input)
SHA224(Input)
SHA256(Input)
SHA384(Input)
SHA512(Input)
RIPEMD128(Input)
RIPEMD160(Input)
RIPEMD256(Input)
RIPEMD320(Input)
WHIRLPOOL(Input)

0.4 SQLite
Code: [Select]
ConnectSQL(filename)
DisconnectSQL(database)
QuerySQL(database,sql)
GetSQLNextRow(query)
GetSQLColumnCount(query)
GetSQLColumnData(query,column)
FreeSQLQuery(query)
escapeSQLString(string)

0.4 INIParser
Code: [Select]
ReadIniString(pszFile,pszSection,pszVar)
ReadIniInteger(pszFile,pszSection,pszVar)
ReadIniNumber(pszFile,pszSection,pszVar)
ReadIniBool(pszFile,pszSection,pszVar)
WriteIniString(pszFile,pszSection,pszVar,pszVal)
WriteIniInteger(pszFile,pszSection,pszVar,pszVal)
WriteIniNumber(pszFile,pszSection,pszVar,pszVal)
WriteIniBool(pszFile,pszSection,pszVar,pszVal)
CountIniSection(pszFile,pszSection)
RemoveIniValue(pszFile,pszSection,pszVar)
DeleteIniSection(pszFile,pszSection)
ClearIni(pszFile)

0.4 MySQL
Code: [Select]
mysql_connect(szServer,szUser,szPass,szDatabase)
mysql_close(pConn)
mysql_query(pConn,szQuery)
mysql_num_rows(pConn)
mysql_num_fields(pConn)
mysql_fetch_row(pConn)
mysql_fetch_assoc(pConn)
mysql_fetch_lengths(pConn)
mysql_free_result(pConn)
mysql_errno(pConn)
mysql_error(pConn)
mysql_ping(pConn)
mysql_escape_string(pConn,szText)
mysql_select_db(pConn,szDatabase)
mysql_change_user(pConn,szUser,szPass)
mysql_warning_count(pConn)
mysql_affected_rows(pConn)
mysql_insert_id(pConn)
mysql_info(pConn)
Please reply me if it's any issue in this document! :)

Offline thijn

  • LU testers
  • VC:MP Veteran
  • *
  • Posts: 667
  • Im proud to be pro.
    • View Profile
    • Vice Underdogs
Re: Full document for Squirrel plugins
« Reply #1 on: October 01, 2014, 11:14:14 pm »
The rows related mysql function don't need the connection, they need the rowset returned from mysql_query.

Offline sk

  • Street Thug
  • *
  • Posts: 6
    • View Profile
Re: Full document for Squirrel plugins
« Reply #2 on: October 02, 2014, 08:02:08 pm »
thankx for the mysql sockets
one question how can we use mysql_fetch_assoc which stores all the data in arrays so very useful if used with loops in php
but in squirrel i don,t understand the arguments.According to your post
mysql_fetch_assoc( mysql_connect(szServer,szUser,szPass,szDatabase) );
but in php it is
mysql_fetch_assoc( mysql_query( SELECT 'blah' FROM 'blah' (etc) ) );
so can u please tell me the correct arguments to use SELECT function as sqlite had GetSQLColumnData(querysql(query) ); to get SELECT query
i will show u some of my codes that i used in php 
Code: [Select]
<?php
$db 
mysql_connect('localhost','root','mypass');
$mydb mysql_select_db('sk');
function 
getip($name){
$sql "SELECT * FROM testaccount where name = '$name'";
$row mysql_fetch_assocmysql_query($sql) );
$ip $row['IP'];
return 
$ip;
}
echo 
$getip getip('sk');

?>
this above code works good for php page but now check it out for squirrel
Code: [Select]
function onScriptLoad()
{
    stats <- array( GetMaxPlayers(), null );
db <- mysql_connect("localhost","root","mypass","Sk");
}
function getip(player){
local sql = "SELECT * FROM 'testaccount' where 'Name' = '"+player.Name+"'";
local row = mysql_fetch_assoc( mysql_query(db,sql) );
local ip =  row["IP"];
return ip;
}
function onPlayerCommand( player , cmd , text){
if ( cmd == "myip"){
local myip = getip(player);
MessagePlayer("Your last used ip was : " + myip,player);
}
Note = 'mypass' is not my original pass.
not its just a test server so i m just testing to use select query fucntion in squirrel which i m not able to do successfully >.<.
so ysc123 can u please tell me any alternative way to do it? or just fix the code that i provided..

Offline thijn

  • LU testers
  • VC:MP Veteran
  • *
  • Posts: 667
  • Im proud to be pro.
    • View Profile
    • Vice Underdogs
Re: Full document for Squirrel plugins
« Reply #3 on: October 02, 2014, 08:21:23 pm »
Code: [Select]
function onScriptLoad()
{
local DB = mysql_connect("localhost", "user", "pass", "database");
if ( DB )
{
local q = mysql_query(DB, "SELECT * FROM accounts WHERE `username` = '" + mysql_escape_string( DB, "TestUser") + "'");
if ( q && mysql_num_rows( q ) > 0 )
{
local row = mysql_fetch_assoc( q );
print( "Username: " + row["username"] );
print( "IP: " + row["ip"] );
}
else
print("Query failed: " + mysql_error( DB ) );
}
else
print("Connection to MySQL failed: " + mysql_error( DB ) );
}

Returns:
Quote
[SCRIPT]  Username: TestUser
[SCRIPT]  IP: 127.0.0.1
« Last Edit: October 04, 2014, 12:33:08 pm by thijn »

Offline sk

  • Street Thug
  • *
  • Posts: 6
    • View Profile
Re: Full document for Squirrel plugins
« Reply #4 on: October 03, 2014, 10:05:20 pm »
Code: [Select]
function onScriptLoad()
{
local DB = mysql_connect("localhost", "user", "pass", "database");
if ( DB )
{
local q = mysql_query(DB, "SELECT * FROM accounts WHERE `username` = '" + mysql_escape_string( DB, "TestUser") + "'");
if ( q )
{
local row = mysql_fetch_assoc( q );
print( "Username: " + row["username"] );
print( "IP: " + row["ip"] );
}
else
print("Query failed: " + mysql_error( DB ) );
}
else
print("Connection to MySQL failed: " + mysql_error( DB ) );
}

Returns:
Quote
[SCRIPT]  Username: TestUser
[SCRIPT]  IP: 127.0.0.1
Thankx it works perfectly but only if data already exist in database if we change the Name "TestUser" to something else it shows index `Name` does not exist
so when i created a function to check if the player is registered or not its just showing an error.
so any way to get around it?

Offline stormeus

  • VC:MP Developer
  • VC:MP Veteran
  • *
  • Posts: 1122
    • View Profile
Re: Full document for Squirrel plugins
« Reply #5 on: October 03, 2014, 10:20:50 pm »
if ( q && mysql_num_rows( q ) > 0 )
Do not PM me for support.




Offline thijn

  • LU testers
  • VC:MP Veteran
  • *
  • Posts: 667
  • Im proud to be pro.
    • View Profile
    • Vice Underdogs
Re: Full document for Squirrel plugins
« Reply #6 on: October 04, 2014, 12:33:22 pm »
if ( q && mysql_num_rows( q ) > 0 )
Updated my code :]

Offline sk

  • Street Thug
  • *
  • Posts: 6
    • View Profile
Re: Full document for Squirrel plugins
« Reply #7 on: October 05, 2014, 01:13:06 am »
if ( q && mysql_num_rows( q ) > 0 )
THANKXXXXXXX
worked :}
(Why didn,t i think of that >.<)
« Last Edit: October 05, 2014, 01:38:21 am by sk »