Raised This Month: $51 Target: $400
 12% 

Compiler error


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
3D-GRAF
Member
Join Date: Jun 2008
Old 04-29-2009 , 06:41   Compiler error
Reply With Quote #1

Hello, i'm new at sourcemod scripting. I can't compile my plugin because of the erros.
Here is the source:

PHP Code:
#include <sourcemod>

new Handle:hDatabase INVALID_HANDLE;

public 
Plugin:myinfo 
{
    
name "CGC SteamID Check",
    
author "F1NAL",
    
description "CGC SteamID Check",
    
url ""
};

public 
OnPluginStart()
{
    
HookEvent("player_connect"Event_Player_Connect);
    
hDatabase MySQL_Connect();
}

public 
Event_Player_Connect(Handle:event, const String:name[], bool:dontBroadcast) {
    new 
client GetClientOfUserId(GetEventInt(event"userid"));
    
    
decl String:steam_id[32];
    
GetClientAuthString(clientsteam_id64);
    
    if (
steam_id[0] == 0) {
        return;
    }
    
    if (
hDatabase == INVALID_HANDLE) {
        return;
    }
    
    new 
String:query_str[1024];
    
Format(query_strsizeof(query_str), "SELECT pid FROM cgc_players WHERE steam_id LIKE '%s'"steam_id[0]);
    
SQL_TQuery(hDatabaseTypoCallbackquery_str);
}

Handle:MySQL_Connect() {
    new 
String:error[256];
    new 
Handle:db INVALID_HANDLE;
    
    
db SQL_Connect("cgc"trueerrorsizeof(error));
    
    return 
db;
}

public 
TypoCallback(Handle:ownerHandle:hDatabase, const String:error[], client)
{
    if(!
SQL_GetRowCount(hDatabase))
    {
                
KickClient(client"Not regged");
                return;
    } 
    if(
hDatabase == INVALID_HANDLE) {
            return;
    }

During compiling i get errors:
HTML Code:
cgcheck.sp<35> : error 100: function prototypes do not match
cgcheck.sp<47> : warning 219: local variable "hDatabase" shadows a variable at a preceding level
Can anyone tell me what do these errors mean or how to fix them?
3D-GRAF is offline
BAILOPAN
Join Date: Jan 2004
Old 04-29-2009 , 06:45   Re: Compiler error
Reply With Quote #2

You've declared two variables as "hDatabase" and the second is in an inner scope -- just use a different name in your TypoCallback parameter list.

And the final parameter must have the "any" tag. something like:

Code:
public TypoCallback(Handle:owner, Handle:hDatabase, const String:error[], any:client)
__________________
egg
BAILOPAN is offline
3D-GRAF
Member
Join Date: Jun 2008
Old 04-29-2009 , 07:19   Re: Compiler error
Reply With Quote #3

thank you, errors disappered, but plugin doesn't work though..
how can i know where plugin stops working?
3D-GRAF is offline
paegus
Senior Member
Join Date: Nov 2004
Location: Extreme low earth orbit
Old 04-29-2009 , 08:25   Re: Compiler error
Reply With Quote #4

Code:
// Enable debugging mode. #define DEBUG 1 ...     // At various eventful locations, outputs current states and whatnot so you can see what the plugin is doing or if the plugin even reached this point.     #if DEBUG     PrintToServer("Things should look like %s and %d, etc", somestring, somenumber)     #endif ...

go crazy

e: though at the moment i'd have to go with the fact that the player_connect event is too soon for steamid verification. try the OnClientAuthorized(client, const String:auth[]) forward instead of hooking player_connect etc..

e^2: also your GetClientAuthString's maxlen is 64 where as steam_id is only 32. not that that'll actually cause a problem since steam ids aren't that long...
__________________
Live and learn or die and teach by example.
Plugins Mine | Hidden:SourceMod

Last edited by paegus; 04-29-2009 at 08:40.
paegus is offline
3D-GRAF
Member
Join Date: Jun 2008
Old 04-29-2009 , 13:25   Re: Compiler error
Reply With Quote #5

Fixed these

New problem, sql query doesn't work.
Source:
PHP Code:
#include <sourcemod>
#define DEBUG 1

new Handle:hDatabase INVALID_HANDLE;

public 
Plugin:myinfo 
{
    
name "CGCSC",
    
author "F1NAL",
    
description "CGC SteamID Check",
    
url ""
};

public 
OnPluginStart()
{
    
#if DEBUG
        
PrintToServer("[CGCSC] Plugin loaded");
        
#endif
}

public 
OnClientAuthorized(client, const String:auth[])
{
    
decl String:steam_id[32];
    
GetClientAuthString(clientsteam_id32);
    
    if (
steam_id[0] == 0) {
        return;
    }
    
    
#if DEBUG
        
PrintToServer("[CGCSC] %s Authorized"steam_id[0]);
        
#endif
    
    
hDatabase MySQL_Connect(); 
    
    if (
hDatabase == INVALID_HANDLE) {
        return;
    }
    
    new 
String:query_str[1024];
    
Format(query_strsizeof(query_str), "SELECT pid FROM cgc_players WHERE steam_id LIKE '%s'"steam_id[0]);
    
SQL_TQuery(hDatabaseTypoCallbackquery_str)
    
    
#if DEBUG
        
PrintToServer("SQL WORKS");
        
#endif
}

Handle:MySQL_Connect() {
    new 
String:error[256]; 
    new 
Handle:db INVALID_HANDLE;
    
    
db SQL_Connect("cgc"trueerrorsizeof(error));
    
    return 
db;


public 
TypoCallback(Handle:ownerHandle:hndl, const String:error[], any:client)
{
    if(!
SQL_GetRowCount(hndl)) 
    {
                
KickClient(client"Not regged");
                return; 
    } 
    if(
hndl == INVALID_HANDLE) {
        return;
    }

Why can hDatabase == INVALID_HANDLE ?
Is there any sql debug info?
3D-GRAF is offline
MikeJS
Senior Member
Join Date: Nov 2008
Old 04-29-2009 , 13:32   Re: Compiler error
Reply With Quote #6

try:
PHP Code:
Format(query_strsizeof(query_str), "SELECT pid FROM cgc_players WHERE steam_id='%s'"steam_id); 
__________________
MikeJS is offline
3D-GRAF
Member
Join Date: Jun 2008
Old 04-29-2009 , 13:39   Re: Compiler error
Reply With Quote #7

Changed, but plugin stop after
Quote:
if (hDatabase == INVALID_HANDLE) {
return;
}
Does this mean that plugin can't connect to db?
3D-GRAF is offline
MikeJS
Senior Member
Join Date: Nov 2008
Old 04-29-2009 , 13:54   Re: Compiler error
Reply With Quote #8

Try connecting to the database in OnPluginStart() and using a global handle for the database.
__________________
MikeJS is offline
3D-GRAF
Member
Join Date: Jun 2008
Old 04-29-2009 , 15:54   Re: Compiler error
Reply With Quote #9

thx everybody, i've got it working
3D-GRAF is offline
3D-GRAF
Member
Join Date: Jun 2008
Old 05-01-2009 , 11:12   Re: Compiler error
Reply With Quote #10

Last question

Is it possible not to make new handle and not to open new mysql connection in CheckSteamID()? I don't know how to use existing connection.

PHP Code:
#include <sourcemod>
#define DEBUG 1

new Handle:hDatabase INVALID_HANDLE;

public 
Plugin:myinfo 
{
    
name "CGC",
    
author "3D-GRAF",
    
description "CGC SteamID Check",
    
url "http://cgaming.ru/"
};

public 
OnPluginStart()
{
    
hDatabase MySQL_Connect();
    
#if DEBUG
        
PrintToServer("[CGC] Plugin loaded");
        
#endif
}

public 
OnClientPostAdminCheck(client)
{
    
decl String:steam_id[32];
    
GetClientAuthString(clientsteam_idsizeof(steam_id));
    
    
decl String:username[64];
    
GetClientName(clientusernamesizeof(username));
    
    if (
StrEqual(steam_id[0], "BOT")) {
        return;
    }
    
    
#if DEBUG
        
PrintToServer("[CGC] %s - %s Authorized"usernamesteam_id[0]);
        
#endif
    
    
    
if (hDatabase == INVALID_HANDLE) {
        return;
    }
    
    
PrintToChatAll("\x04[CGC]\x03 Checking [ \x04%s \x03- \x04%s \x03]"usernamesteam_id[0]);
    
    new 
String:query[255];
    
Format(querysizeof(query), "SELECT team FROM cgc_players WHERE steam_id = '%s'"steam_id[0]);
    
SQL_TQuery(hDatabaseCheckSteamIDqueryclient);
}

Handle:MySQL_Connect() {
    new 
String:error[256]; 
    new 
Handle:db INVALID_HANDLE;
    
    
db SQL_Connect("cgc"trueerrorsizeof(error));
    
    if (
db == INVALID_HANDLE) {
        
#if DEBUG
            
PrintToServer("[CGC] Can't connect MySQL: %s"error);
            
#endif
        
return db;
    } else {
        
#if DEBUG
            
PrintToServer("[CGC] MySQL Connected");
            
#endif
        
return db;
    }
}

public 
CheckSteamID(Handle:ownerHandle:hndl, const String:error[], any:client)
{
    if (
hndl == INVALID_HANDLE)
    {
        
KickClient(client"Ошибка авторизации");
        
#if DEBUG
            
PrintToServer("[CGC] Query failed");
            
#endif
        
        
return true;
    }
    
    
decl String:steam_id[32];
    
GetClientAuthString(clientsteam_idsizeof(steam_id));
    
    
decl String:username[64];
    
GetClientName(clientusernamesizeof(username));
    
    new 
String:teamid[255];
    new 
String:team[255];
    
    while (
SQL_FetchRow(hndl))
    {
        
SQL_FetchString(hndl0teamidsizeof(teamid));
        
teamid[0] = teamid[0] - 48;
        
        if (
teamid[0] != 0) {
            
            
            new 
String:queryt[255];
            
Format(querytsizeof(queryt), "SELECT name FROM cgc_teams WHERE tid = %i"teamid[0]);
            
            new 
Handle:hQuery INVALID_HANDLE;
            
hQuery MySQL_Connect();
            
            if ((
hQuery SQL_Query(hQueryqueryt)) == INVALID_HANDLE) {
                return 
true;
            }
            
            while (
SQL_FetchRow(hQuery))
            {
                
SQL_FetchString(hQuery0teamsizeof(team));
            }
            
CloseHandle(hQuery);
        } else {
            
team "Not in team";
        }
    }
    
    if (!
SQL_GetRowCount(hndl)) {
        
KickClient(client"Вы не заявлены на участие");
        
        
PrintToChatAll("\x04[CGC]\x03 Kicked [ \x04%s \x03- \x04%s \x03]"usernamesteam_id[0]);
        
        
#if DEBUG
            
PrintToServer("[CGC] %i not regged - kicked"client);
            
#endif
    
} else if (SQL_GetRowCount(hndl)) {
        
PrintToChatAll("\x04[CGC]\x03 Authenticated: \x04%s \x03Team: \x04%s"usernameteam[0]);
        
        
#if DEBUG
            
PrintToServer("[CGC] %s - %s Authenticated"steam_id[0], team[0]);
            
#endif
    
}
    
    return 
true;


Last edited by 3D-GRAF; 05-04-2009 at 11:04.
3D-GRAF 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 10:52.


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