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

[CS:GO] add database mysql this plugin !!


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
Dr.Mohammad
Senior Member
Join Date: Jan 2016
Location: CSGO Servers
Old 03-17-2018 , 23:22   [CS:GO] add database mysql this plugin !!
Reply With Quote #1

hi guys

how to i add data base for this plugin??
PHP Code:
#include <sourcemod>
#include <geoip>
#pragma semicolon 1
#pragma newdecls required
#define PLAYER_LOG_PATH "logs/connections/player"
#define ADMIN_LOG_PATH "logs/connections/admin"

public Plugin myinfo =
{
    
name "Log Connections",
    
author "Xander and IT-KiLLER",
    
description "This plugin logs players' connect and disconnect times along with their Name, SteamID, and IP Address to a text file at /sourcemod/logs/connections/ seperate from the server logs.",
    
version "1.2a",
    
url "https://github.com/IT-KiLLER"
}

char player_filepath[PLATFORM_MAX_PATH];
char admin_filepath[PLATFORM_MAX_PATH];
bool clientConnected[MAXPLAYERS+1] = {false,...};
bool clientIsAdmin[MAXPLAYERS+1] = {false,...};

public 
void OnPluginStart()
{
    
// PLAYER
    
BuildPath(Path_SMplayer_filepathsizeof(player_filepath), PLAYER_LOG_PATH);
    if (!
DirExists(player_filepath))
    {
        
CreateDirectory(player_filepath511);
        
        if (!
DirExists(player_filepath))
            
LogMessage("Failed to create directory at %s - Please manually create that path and reload this plugin."PLAYER_LOG_PATH);
    }
    
// ADMIN
    
BuildPath(Path_SMadmin_filepathsizeof(admin_filepath), ADMIN_LOG_PATH);
    if (!
DirExists(admin_filepath))
    {
        
CreateDirectory(admin_filepath511);
        
        if (!
DirExists(admin_filepath))
            
LogMessage("Failed to create directory at %s - Please manually create that path and reload this plugin."ADMIN_LOG_PATH);
    }

    
HookEvent("player_disconnect"Event_PlayerDisconnectEventHookMode_Pre);
    for(
int client 1client <= MaxClientsclient++)
    {
        if(
IsClientInGame(client))
        {
            
clientConnected[client] = true;
            if(
IsPlayerAdmin(client)) 
                
clientIsAdmin[client] = true;
        }
    }
}

public 
void OnMapStart()
{
    
char FormatedTime[100];
    
char MapName[100];
        
    
int CurrentTime GetTime();
    
    
GetCurrentMap(MapName100);
    
FormatTime(FormatedTime100"%d_%b_%Y"CurrentTime); //name the file 'day month year'
    
    
BuildPath(Path_SMplayer_filepathsizeof(player_filepath), "%s/%s_player.txt"PLAYER_LOG_PATH,FormatedTime);
    
BuildPath(Path_SMadmin_filepathsizeof(admin_filepath), "%s/%s_admin.txt"ADMIN_LOG_PATH,FormatedTime);
    
    
Handle playerHandle OpenFile(player_filepath"a+");
    
Handle adminHandle OpenFile(admin_filepath"a+");
    
    
FormatTime(FormatedTime100"%X"CurrentTime);
    
// PLAYER
    
WriteFileLine(playerHandle"");
    
WriteFileLine(playerHandle"%s - ===== Map change to %s ====="FormatedTimeMapName);
    
WriteFileLine(playerHandle"");
    
CloseHandle(playerHandle);
    
// ADMIN
    
WriteFileLine(adminHandle"");
    
WriteFileLine(adminHandle"%s - ===== Map change to %s ====="FormatedTimeMapName);
    
WriteFileLine(adminHandle"");
    
CloseHandle(adminHandle);
}

public 
void OnRebuildAdminCache(AdminCachePart part)
{
    for(
int client 1client <= MaxClientsclient++)
    {
        if(
IsClientInGame(client) && IsPlayerAdmin(client))
        {
            
clientIsAdmin[client] = true;
        }
    }
}

public 
void OnClientPostAdminCheck(int client) {
    if(!
client)
    {
        
// console or unknown client
    

    else if(
IsFakeClient(client))
    {
        
// bot
    
}    
    else if (
clientConnected[client])
    {
        
// Already connected
    
}
    else if(
IsPlayerAdmin(client)) 
    {     
// ADMIN
        
clientConnected[client] = true;
        
clientIsAdmin[client] = true;
        
char PlayerName[64];
        
char Authid[64];
        
char IPAddress[64];
        
char Country[64];
        
char FormatedTime[64];
        
        
GetClientName(clientPlayerName64);
        
GetClientAuthId(clientAuthId_Steam2Authidsizeof(Authid), false);
        
GetClientIP(clientIPAddress64);
        
FormatTime(FormatedTime64"%X"GetTime());
        
        if(!
GeoipCountry(IPAddressCountry64))
        {
            
Format(Country64"Unknown");
        }
        
        
Handle adminHandle OpenFile(admin_filepath"a+");
        
WriteFileLine(adminHandle"%s - <%s> <%s> <%s> CONNECTED from <%s>",
                                
FormatedTime,
                                
PlayerName,
                                
Authid,
                                
IPAddress,
                                
Country);

        
CloseHandle(adminHandle);
    }    
    else 
// PLAYER
    
{
        
clientConnected[client] = true;
        
clientIsAdmin[client] = false;
        
char PlayerName[64];
        
char Authid[64];
        
char IPAddress[64];
        
char Country[64];
        
char FormatedTime[64];
        
        
GetClientName(clientPlayerName64);
        
GetClientAuthId(clientAuthId_Steam2Authidsizeof(Authid), false);
        
GetClientIP(clientIPAddress64);
        
FormatTime(FormatedTime64"%X"GetTime());
        
        if(!
GeoipCountry(IPAddressCountry64))
        {
            
Format(Country64"Unknown");
        }
        
        
Handle playerHandle OpenFile(player_filepath"a+");
        
WriteFileLine(playerHandle"%s - <%s> <%s> <%s> CONNECTED from <%s>",
                                
FormatedTime,
                                
PlayerName,
                                
Authid,
                                
IPAddress,
                                
Country);

        
CloseHandle(playerHandle);
    }
}

public 
Action Event_PlayerDisconnect(Event eventchar[] namebool dontBroadcast)
{
    
int client GetClientOfUserId(GetEventInt(event"userid"));
    if(!
clientConnected[client]) return;
    
clientConnected[client] = false;
    if (!
client)
    {
        
// console or unknown client
    
}
    else if (
IsFakeClient(client))
    {
        
// bot
    
}    
    else if (
clientIsAdmin[client]) 
    {    
// ADMIN
        
int ConnectionTime = -1;
        
Handle adminHandle OpenFile(admin_filepath"a+");
        
        
char PlayerName[64];
        
char Authid[64];
        
char IPAddress[64];
        
char FormatedTime[64];
        
char Reason[128];
        
        
GetClientName(clientPlayerName64);
        
GetClientIP(clientIPAddress64);
        
FormatTime(FormatedTime64"%X"GetTime());
        
GetEventString(event"reason"Reason128);

        if (!
GetClientAuthId(clientAuthId_Steam2Authidsizeof(Authid), false))
        {
            
Format(Authid64"Unknown SteamID");
        }
        
        if (
IsClientInGame(client))
        {
            
ConnectionTime RoundToCeil(GetClientTime(client) / 60);
        }
        
        
WriteFileLine(adminHandle"%s - <%s> <%s> <%s> DISCONNECTED after %d minutes. <%s>",
                                
FormatedTime,
                                
PlayerName,
                                
Authid,
                                
IPAddress,
                                
ConnectionTime,
                                
Reason);
        
        
CloseHandle(adminHandle);
    }    
    else
    {    
// PLAYER
        
int ConnectionTime = -1;
        
Handle playerHandle OpenFile(admin_filepath"a+");
        
        
char PlayerName[64];
        
char Authid[64];
        
char IPAddress[64];
        
char FormatedTime[64];
        
char Reason[128];
        
        
GetClientName(clientPlayerName64);
        
GetClientIP(clientIPAddress64);
        
FormatTime(FormatedTime64"%X"GetTime());
        
GetEventString(event"reason"Reason128);

        if (!
GetClientAuthId(clientAuthId_Steam2Authidsizeof(Authid), false))
        {
            
Format(Authid64"Unknown SteamID");
        }
        
        if (
IsClientInGame(client))
        {
            
ConnectionTime RoundToCeil(GetClientTime(client) / 60);
        }
        
        
WriteFileLine(playerHandle"%s - <%s> <%s> <%s> DISCONNECTED after %d minutes. <%s>",
                                
FormatedTime,
                                
PlayerName,
                                
Authid,
                                
IPAddress,
                                
ConnectionTime,
                                
Reason);
        
        
CloseHandle(playerHandle);
    }
    
clientIsAdmin[client] = false;
}

// Checking if a client is admin
stock bool IsPlayerAdmin(int client)
{
    if (
CheckCommandAccess(client"Generic_admin"ADMFLAG_GENERICfalse))
    {
        return 
true;
    }
    return 
false;

Dr.Mohammad is offline
 



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:26.


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