Raised This Month: $ Target: $400
 0% 

SQL Get column as cvar.


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
XmasterOfficial
Junior Member
Join Date: Oct 2014
Old 12-29-2015 , 02:26   Re: SQL Get column as cvar.
Reply With Quote #1

Quote:
Originally Posted by Bugsy View Post
I edited the above code to use get_user_ip( 0 ) and it's working fine for me. Just let the plugin create the table and use it. I don't know what you mean by 'all the columns would be server IP's'. You should have 1 column with rows of IP's.
I did this:
Code:
#include <amxmodx>
#include <sqlx>

new const Version[] = "0.1"
new const szHost[] = "host"
new const szUser[] = "user"
new const szPass[] = "pass"
new const szDB[] = "plugin_licenses"

new Handle:g_SQLTuple , g_szBuffer[ 128 ]

public plugin_init() 
{
register_plugin( "Check IP License" , Version , "bugsy" )
g_SQLTuple = SQL_MakeDbTuple( szHost , szUser , szPass , szDB )
new szIP[20]
get_user_ip( 0 , szIP , charsmax( szIP ) , 1 )
server_print( "%s",szIP )
formatex( g_szBuffer , charsmax( g_szBuffer ) , "SELECT '%s' FROM Licenses WHERE 1;" , szIP )
ExecuteQuery( g_szBuffer , true )
}

public ExecuteQuery( const szQuery[] , bool:bNeedResults ) 
{ 
new szError[ 64 ] , Handle:SqlConnection , ErrorCode
SqlConnection = SQL_Connect( g_SQLTuple , ErrorCode , szError , charsmax( szError ) )
if( SqlConnection == Empty_Handle ) 
set_fail_state( szError );
new Handle:query = SQL_PrepareQuery( SqlConnection , szQuery )
SQL_Execute( query )
if ( bNeedResults )
{
if ( !SQL_NumResults( query ) )
{
set_fail_state( "License not found!" )
} else {
server_print( "Server license found!" )
}
}
SQL_FreeHandle( query )
SQL_FreeHandle( SqlConnection )
}
But, it allways tells "Server license found!". I edited a little bit so it should detect if the IP of the server is in the table "Licenses". Every column in "Licenses" have the IP of the servers. For example: Name: 192.168.1.2 and Value: 1. What could be the problem?
XmasterOfficial is offline
Reply



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

Forum Jump


All times are GMT -4. The time now is 18:07.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode