AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   [CS:GO] add database mysql this plugin !! (https://forums.alliedmods.net/showthread.php?t=306140)

Dr.Mohammad 03-17-2018 23:22

[CS:GO] add database mysql this plugin !!
 
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;



Reiko1231 03-18-2018 05:53

Re: [CS:GO] add database mysql this plugin !!
 
Use database interface. Detailed information on how to is in wiki.

Dr.Mohammad 03-20-2018 10:18

Re: [CS:GO] add database mysql this plugin !!
 
i can not add database :((

Reiko1231 03-20-2018 12:41

Re: [CS:GO] add database mysql this plugin !!
 
Provide your source code with your code and problems/compilation errors. If you can't write scripts at all, hire someone who can do it.
As arne1288 said: "This is a scripting help forum, not a "spoon-feed" or babysitter forum where you get everything served on a silver platter".
You can also find some useful examples on how to in this post.

Dr.Mohammad 03-21-2018 17:19

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

Originally Posted by Reiko1231 (Post 2583845)
Provide your source code with your code and problems/compilation errors. If you can't write scripts at all, hire someone who can do it.
As arne1288 said: "This is a scripting help forum, not a "spoon-feed" or babysitter forum where you get everything served on a silver platter".
You can also find some useful examples on how to in this post.

ok. thank you.:bacon!:


All times are GMT -4. The time now is 12:52.

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