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

Help to make cooldown plugin and add the player to mysql


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
gjedde
Junior Member
Join Date: Aug 2016
Old 03-31-2019 , 18:54   Help to make cooldown plugin and add the player to mysql
Reply With Quote #1

Hey guys i could need some help with some code to put in my plugin

First i need a 5 min timer like you see on faceit were people got 5 min to join or they will be issued a ban after that i need to get the players steamid 64 into mysql so he can get a timeout on the website,

Its for alittle experiment im doing, nothing that will ever see the light of day i think but its still pretty fun to work with

i got the main plugin, where i need the timer on, and then i got the mysql plugin next to it where i need that to read what player didnt join
gjedde is offline
sdz
Senior Member
Join Date: Feb 2012
Old 04-01-2019 , 13:06   Re: Help to make cooldown plugin and add the player to mysql
Reply With Quote #2

for your timer: Unix Time
for your database woes: https://wiki.alliedmods.net/SQL_(Sou...ing)#Threading
sdz is offline
gjedde
Junior Member
Join Date: Aug 2016
Old 04-02-2019 , 21:12   Re: Help to make cooldown plugin and add the player to mysql
Reply With Quote #3

Thank you, not exactly what i was expecting but it can diffently help alittle, but i again, how can i make the server tell if the client dropped connection and isnt back in the next 5 min, and then register him in mysql, i need that too, and if he doesnt join before the warmup ends thats what i am going for.
gjedde is offline
CliptonHeist
Senior Member
Join Date: Feb 2016
Old 04-03-2019 , 02:03   Re: Help to make cooldown plugin and add the player to mysql
Reply With Quote #4

I'd use a datapack to pass player steamids through to a 5 min timer when they disconnect, which will then check if that steamid is on the server after 5mins and if not ban them.

Last edited by CliptonHeist; 04-03-2019 at 02:04.
CliptonHeist is offline
gjedde
Junior Member
Join Date: Aug 2016
Old 04-03-2019 , 02:39   Re: Help to make cooldown plugin and add the player to mysql
Reply With Quote #5

Quote:
Originally Posted by CliptonHeist View Post
I'd use a datapack to pass player steamids through to a 5 min timer when they disconnect, which will then check if that steamid is on the server after 5mins and if not ban them.
that is accutaly not a bad idea, how would you set it up tho?
gjedde is offline
adma
Senior Member
Join Date: Oct 2015
Old 04-03-2019 , 03:03   Re: Help to make cooldown plugin and add the player to mysql
Reply With Quote #6

I was bored so here is an example for you. In theory this should work but it is untested.
This adds a 5min timer against someones steamid when they disconnect and if they reconnect while timer is still going it will stop. If the timer fires it will ban them then insert/update a row in a table which has columns steamid and ban_expiry. On your website you can check if their steamid exists in this table, and see if their ban_expiry has been reached yet.

PHP Code:
#include <sourcemod>

StringMap g_hTimers = new StringMap();
Database g_hDatabase;

public 
void OnPluginStart() {
  static 
char szError[512];
  
g_hDatabase SQL_Connect("db_name"falseszErrorsizeof(szError));
  if (
g_hDatabase == INVALID_HANDLESetFailState(szError);
}

public 
void OnClientAuthorized(int iClientchar[] szSteamID) {
  
Handle hTimer;
  if (
g_hTimers.GetValue(szSteamIDhTimer)) {
    
KillTimer(hTimer);
    
g_hTimers.Remove(szSteamID);
  }
}

public 
void OnClientDisconnect(int iClient) {
  static 
char szSteamID[32];
  if (
GetClientAuthId(iClientAuthId_Steam2szSteamIDsizeof(szSteamID))) {
    
DataPack hPack = new DataPack();
    
hPack.WriteString(szSteamID);
    
Handle hTimer CreateTimer(300.0Timer_BanhPackTIMER_HNDL_CLOSE);
    
g_hTimers.SetValue(szSteamIDhTimer);
  }
}

public 
Action Timer_Ban(Handle hTimerDataPack hPack) {
  static 
char szSteamID[32];
  static 
char szQuery[512];

  
int iBanExpiry GetTime() + (69*60);

  
hPack.Reset()
  
hPack.ReadString(szSteamIDsizeof(szSteamID));

  
g_hTimers.Remove(szSteamID);
  
  
BanIdentity(szSteamID69BANFLAG_AUTHID"You were banned for being naughty""automatic_timer_ban"0);

  
g_hDatabase.Format(szQuerysizeof(szQuery), "INSERT INTO `table_name` (`steamid`, `ban_expiry`) VALUES (\'%s\', %i) ON DUPLICATE KEY UPDATE `ban_expiry` = %i"szSteamIDiBanExpiryiBanExpiry);

  
g_hDatabase.Query(QueryCallback_InsertBanszQuery);

  return 
Plugin_Handled;
}

public 
void QueryCallback_InsertBan(Database hDatabaseDBResultSet hResults, const char[] szErrorany data) {
  
delete hDatabase// this is a cloned Handle of g_hDatabase
  
if (strlen(szError) > 0PrintToServer("Failed to insert ban");


Last edited by adma; 04-03-2019 at 03:12. Reason: INSERT -> INSERT ... ON DUPLICATE KEY UPDATE
adma is offline
gjedde
Junior Member
Join Date: Aug 2016
Old 04-03-2019 , 03:13   Re: Help to make cooldown plugin and add the player to mysql
Reply With Quote #7

Quote:
Originally Posted by adma View Post
I was bored so here is an example for you. In theory this should work but it is untested.
This adds a 5min timer against someones steamid when they disconnect and if they reconnect while timer is still going it will stop. If the timer fires it will ban them then insert/update a row in a table which has columns steamid and ban_expiry. On your website you can check if their steamid exists in this table, and see if their ban_expiry has been reached yet.

PHP Code:
#include <sourcemod>

StringMap g_hTimers = new StringMap();
Database g_hDatabase;

public 
void OnPluginStart() {
  static 
char szError[512];
  
g_hDatabase SQL_Connect("db_name"falseszErrorsizeof(szError));
  if (
g_hDatabase == INVALID_HANDLESetFailState(szError);
}

public 
void OnClientAuthorized(int iClientchar[] szSteamID) {
  
Handle hTimer;
  if (
g_hTimers.GetValue(szSteamIDhTimer)) {
    
KillTimer(hTimer);
    
g_hTimers.Remove(szSteamID);
  }
}

public 
void OnClientDisconnect(int iClient) {
  static 
char szSteamID[32];
  if (
GetClientAuthId(iClientAuthId_Steam2szSteamIDsizeof(szSteamID))) {
    
DataPack hPack = new DataPack();
    
hPack.WriteString(szSteamID);
    
Handle hTimer CreateTimer(300.0Timer_BanhPackTIMER_HNDL_CLOSE);
    
g_hTimers.SetValue(szSteamIDhTimer);
  }
}

public 
Action Timer_Ban(Handle hTimerDataPack hPack) {
  static 
char szSteamID[32];
  static 
char szQuery[512];

  
int iBanExpiry GetTime() + (69*60);

  
hPack.Reset()
  
hPack.ReadString(szSteamIDsizeof(szSteamID));

  
g_hTimers.Remove(szSteamID);
  
  
BanIdentity(szSteamID69BANFLAG_AUTHID"You were banned for being naughty""automatic_timer_ban"0);

  
g_hDatabase.Format(szQuerysizeof(szQuery), "INSERT INTO `table_name` (`steamid`, `ban_expiry`) VALUES (\'%s\', %i)"szSteamIDiBanExpiry);

  
g_hDatabase.Query(QueryCallback_InsertBanszQuery);

  return 
Plugin_Handled;
}

public 
void QueryCallback_InsertBan(Database hDatabaseDBResultSet hResults, const char[] szErrorany data) {
  
delete hDatabase// this is a cloned Handle of g_hDatabase
  
if (strlen(szError) > 0PrintToServer("Failed to insert ban");

You are amazing, Thank you so much i will look trough this and see if it can work out with my little project i will come with some feedback when im done thank you so much thats more then i hoped for
gjedde is offline
adma
Senior Member
Join Date: Oct 2015
Old 04-03-2019 , 03:18   Re: Help to make cooldown plugin and add the player to mysql
Reply With Quote #8

No problem, I updated my original post changing the INSERT statement so it updates the ban_expiry if the steamid already exists in the database.
adma is offline
backwards
AlliedModders Donor
Join Date: Feb 2014
Location: USA
Old 04-03-2019 , 04:07   Re: Help to make cooldown plugin and add the player to mysql
Reply With Quote #9

The above method wouldn't give the correct logic like MM. This method can be exploited easily if the player leaves for 4 minutes and 50 seconds, then rejoins, then leaves again. He will have a reset timer of 5 minutes to be disconnected again and not be limited to 10 more seconds. You want to create a timer that ticks every second and while a players not connected, you increment the value until it reaches the 300 ticks for 5 minutes or (60*5)
__________________
I highly recommend joining the SourceMod Discord Server for real time support.
backwards is offline
gjedde
Junior Member
Join Date: Aug 2016
Old 04-03-2019 , 04:28   Re: Help to make cooldown plugin and add the player to mysql
Reply With Quote #10

Yeah i noticed that too but its still a good start. still trying to figure out how i can check if a steamid doesnt connect to the game before warmupends the steamids are stored in a json file before they can join the server and the match, its just tricky
gjedde 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 13:09.


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