Raised This Month: $ Target: $400
 0% 

Verify system and and question.


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
duydangle
Senior Member
Join Date: May 2010
Old 10-19-2011 , 23:27   Verify system and and question.
Reply With Quote #1

Taking advice from Scone, I make a new thread to ask some question.
The code is here
PHP Code:
/* Plugin Template generated by Pawn Studio */

#pragma semicolon 1
#include <sourcemod>
#include <halflife>
#include <steamtools>
#define RED 0
#define BLU 1
#define TEAM_OFFSET 2

new bool:teamReadyState[2] = { falsefalse };
new 
bool:recordOnRestart false;
new 
bool:recording false;
new 
Handle:hDatabase INVALID_HANDLE;
new 
String:forum_name[256];
new 
String:forum_id[64];
public 
Plugin:myinfo 
{
        
name "Xtremezone.VN Verify System (For Competitve)",
        
author "duydangle, with help from zazxxx and Scone",
        
description "Integrate users between Xenforo and Source Servers",
        
version "1.0.3",
        
url "Xtremezone.VN"
}    

public 
OnPluginStart()
{
    
// Team status updates
    
HookEvent("tournament_stateupdate"TeamStateEvent);

    
// Game restart
    
HookEvent("teamplay_restart_round"GameRestartEvent);

    
// Win conditions met (maxrounds, timelimit)
    
HookEvent("teamplay_game_over"GameOverEvent);

    
// Win conditions met (windifference)
    
HookEvent("tf_game_over"GameOverEvent);

    
// Hook into mp_tournament_restart
    
RegServerCmd("mp_tournament_restart"TournamentRestartHook);

    
decl String:error[255];
    
    
hDatabase SQL_Connect("forum"trueerrorsizeof(error));

    if (
hDatabase == INVALID_HANDLE)
        
LogError("Database failure: %s"error);
    else
        
LogMessage("Connect to database completed");
}

public 
OnClientPutInServer(client)
{
    
CreateTimer(5.0Welcomeclient);
}

public 
Action:Welcome(Handle:timerany:client)
{
    
decl String:authstring[64];
    
GetClientAuthString(clientauthstringsizeof(authstring));
    
PrintToChatAll("%N (%s) - %s da tham gia vao server"clientforum_nameauthstring);
    
PrintToConsole(client"Welcome to Xtremezone.VN Server");
}

public 
OnClientAuthorized(client)
{
    if (
IsFakeClient(client)) return;
    
    
decl String:steamID[64];
    
    
Steam_GetCSteamIDForClient(clientsteamIDsizeof(steamID));
    
    
decl String:query[256];
    
    
Format(querysizeof(query), "SELECT user_id FROM xf_user_external_auth WHERE provider_key='%s' AND provider='steam'"steamID);
    
SQL_TQuery(hDatabaseCallback_Verify_OnequeryGetClientUserId(client));
}

public 
Callback_Verify_One(Handle:ownerHandle:hQuery, const String:error[], any:userid)
{
    if(
hQuery == INVALID_HANDLE
    {
        
LogError("Query failed! %s"error);
        return;
    }

    new 
client GetClientOfUserId(userid);

    if(
client == 0
    {
        
// User already left
        
CloseHandle(hQuery);
        return;
    }

    if(!
SQL_FetchRow(hQuery)) 
    {
        
CloseHandle(hQuery);
        
KickClient(client"Hay dang ki nick forum, confirm email va dang nhap forum bang tai khoang Steam truoc khi vao server");
        return;
    }
        
    
SQL_FetchString(hQuery,0,forum_id,sizeof(forum_id));
    
CloseHandle(hQuery);
    
    
decl String:query[256];
    
    
Format(querysizeof(query), "SELECT user_state FROM xf_user WHERE user_id='%s'"forum_id);
    
SQL_TQuery(hDatabaseCallback_Verify_TwoqueryGetClientUserId(client));
}

public 
Callback_Verify_Two(Handle:ownerHandle:hQuery, const String:error[], any:userid)
{
    if(
hQuery == INVALID_HANDLE
    {
        
LogError("Query failed! %s"error);
        return;
    }
    new 
client GetClientOfUserId(userid);
    if(
client == 0
    {
        
// User already left
        
CloseHandle(hQuery);
        return;
    }
    if(!
SQL_FetchRow(hQuery)) 
    {
        
CloseHandle(hQuery);
        return;
    }
    
decl String:status[16];
    
SQL_FetchString(hQuery0statussizeof(status));

    if(!
StrEqual(status"valid")) 
    {
        
CloseHandle(hQuery);
        
KickClient(client"Ban chua xac nhan tai khoan, hoac tai khoan forum cua ban da bi disabled");
        return;
    }
    
CloseHandle(hQuery);
    
    
decl String:query[256];
    
    
Format(querysizeof(query), "SELECT username FROM xf_user WHERE user_id='%s'"forum_id);
    
SQL_TQuery(hDatabaseCallback_Verify_ThreequeryGetClientUserId(client));
}
public 
Callback_Verify_Three(Handle:ownerHandle:hQuery, const String:error[], any:userid)
{
    if(
hQuery == INVALID_HANDLE
    {
        
LogError("Query failed! %s"error);
        return;
    }
    new 
client GetClientOfUserId(userid);
    if(
client == 0
    {
        
// User already left
        
CloseHandle(hQuery);
        return;
    }
    if(!
SQL_FetchRow(hQuery)) 
    {
        
CloseHandle(hQuery);
        return;
    }
    
SQL_FetchString(hQuery0forum_namesizeof(forum_name));
}
public 
TeamStateEvent(Handle:event, const String:name[], bool:dontBroadcast)
{
    new 
team GetClientTeam(GetEventInt(event"userid")) - TEAM_OFFSET;
    new 
bool:nameChange GetEventBool(event"namechange");
    new 
bool:readyState GetEventBool(event"readystate");

    if (!
nameChange)
    {
        
teamReadyState[team] = readyState;

        
// If both teams are ready wait for round restart to start recording
        
if (teamReadyState[RED] && teamReadyState[BLU])
        {
            
recordOnRestart true;
        }
        else
        {
            
recordOnRestart false;
        }
    }
}

public 
GameRestartEvent(Handle:event, const String:name[], bool:dontBroadcast)
{
    
// Start recording only if both team are in ready state
    
if (recordOnRestart)
    {
        
StartRecording();
        
recordOnRestart false;
        
teamReadyState[RED] = false;
        
teamReadyState[BLU] = false;
        
decl String:t_name[64], String:t_steamid[24];
        
PrintToChatAll("Danh sach nguoi choi:");
        for (new 
1<= MaxClients+1i++)
        {
            if(
IsClientInGame(i) && !IsFakeClient(i))
            {
                
GetClientName(it_namesizeof(t_name));
                
GetClientAuthString(it_steamidsizeof(t_steamid));
                
PrintToChatAll("%s (%s) - %s",t_nameforum_namet_steamid);
            }
        }
        
PrintToChatAll("Good Luck, Have fun!");
    }
}


public 
GameOverEvent(Handle:event, const String:name[], bool:dontBroadcast)
{
    
StopRecording();
}

public 
Action:TournamentRestartHook(args)
{
    
// If mp_tournament_restart is called, stop recording
    
if (recording)
    {
        
StopRecording();
    }

    return 
Plugin_Continue;
}

public 
OnMapStart()
{
    
ResetVariables();

    
// Check every 30secs if there are still players on the server
    
CreateTimer(30.0CheckPlayers0TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
}

public 
OnMapEnd()
{
}

// Stop recording if there are no players on the server - thanks jasonfrog!
public Action:CheckPlayers(Handle:timer)
{
    if (
recording)
    {
        for (new 
1<= MaxClientsi++)
        {
            if (
IsClientConnected(i) && !IsFakeClient(i))
            {
                return;
            }
        }

        
StopRecording();
    }
}

//------------------------------------------------------------------------------
// Private functions
//------------------------------------------------------------------------------

ResetVariables()
{
    
teamReadyState[RED] = false;
    
teamReadyState[BLU] = false;
    
recordOnRestart false;
    
recording false;
}

StartRecording()
{
    if (
recording)
    {
        
PrintToChatAll("Already recording");
        return;
    }

    
// Format the demo filename
    
new String:timestamp[16];
    new 
String:map[32];
    new 
String:filename[64];
    new 
String:command[128];

    
FormatTime(timestampsizeof(timestamp), "%Y%m%d-%H%M");
    
GetCurrentMap(mapsizeof(map));
    
Format(filenamesizeof(filename), "%s-%s.dem"timestampmap);
    
Format(commandsizeof(command), "tv_record %s"filename);

    
// Start recording
    
ServerCommand(command);

    
PrintToChatAll("Recording started");
    
recording true;
}

StopRecording()
{
    if (
recording)
    {
        
// Stop recording
        
ServerCommand("tv_stoprecord");

        
PrintToChatAll("Recording stopped");

        
recording false;
    }

The original idea is checking the player joining server is registered or not. I am using xenforo board, the users' data are stored in xf_user table, the steam community ids are stored in xf_user_external_auth.

The original part is done, thanks to Scone.

Now I am planning to develop the plugin for using in Competitive Mode. The Competitive Code I use a lot from http://forums.alliedmods.net/showthread.php?p=830122. A demo will be recorded when the match happen.

When the match happens, I want to print all player: players' name, their username on the forum, and their Steamid. I put that in the part
PHP Code:
// Start recording only if both team are in ready state
    
if (recordOnRestart)
    {
        
StartRecording();
        
recordOnRestart false;
        
teamReadyState[RED] = false;
        
teamReadyState[BLU] = false;
        
decl String:t_name[64], String:t_steamid[24];
        
PrintToChatAll("Danh sach nguoi choi:");
        for (new 
1<= MaxClients+1i++)
        {
            if(
IsClientInGame(i) && !IsFakeClient(i))
            {
                
GetClientName(it_namesizeof(t_name));
                
GetClientAuthString(it_steamidsizeof(t_steamid));
                
PrintToChatAll("%s (%s) - %s",t_nameforum_namet_steamid);
            }
        }
        
PrintToChatAll("Good Luck, Have fun!");
    } 
But then error happens, the players' username on the forum are not printed. Please help, thanks.
Attached Files
File Type: sp Get Plugin or Get Source (verify-competitive.sp - 97 views - 7.3 KB)
duydangle 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 23:27.


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