Raised This Month: $32 Target: $400
 8% 

Infractions - The Early Stages


Post New Thread Reply   
 
Thread Tools Display Modes
QuantumToast
Member
Join Date: May 2017
Location: US
Old 06-15-2017 , 15:19   Re: Infractions - The Early Stages
Reply With Quote #21

I have improved the OnCustomCommandChange function to cover nearly all cases. Anything I seem to be missing?
PHP Code:
public void OnCustomCommandChange(ConVar convar, const char[] oldValue, const char[] newValue)
{
    if(
strcmp(newValue"") == 0)                                                                    // If the cvar string is empty "", meaning there is no custom command
    
{
        
PrintToServer("[SM] Infractions custom command is empty.");
        
RemoveCommandListener(CustomCallbackoldValue);
    }
    else if(
strcmp(oldValue"") == && CommandExists(newValue))    // If the previous cvar setting was "", don't try to remove a non-existant listener
    
{
        
PrintToServer("[SM] Infractions custom command set to \"%s\""newValue);
        
AddCommandListener(CustomCallbacknewValue);
    }
    else if(
CommandExists(newValue))                                                            // Remove the old listener, and create a new listener with the new command
    
{
        
PrintToServer("[SM] Infractions custom command set to \"%s\""newValue);
        
RemoveCommandListener(CustomCallbackoldValue);
        
AddCommandListener(CustomCallbacknewValue);
    }
    else return;

I apologize for the non-aligned comments, it seems that the forums treat tabs weirdly - they are aligned in my editor :/

Last edited by QuantumToast; 06-15-2017 at 15:26. Reason: Didn't want to delete old comment, so I edited instead
QuantumToast is offline
Kryptanyte
Junior Member
Join Date: Dec 2015
Old 06-15-2017 , 22:32   Re: Infractions - The Early Stages
Reply With Quote #22

You're not necessarily missing anything but you don't need to have the last else statement. You can keep the return at the end of the function:
PHP Code:
public void OnCustomCommandChange(ConVar convar, const char[] oldValue, const char[] newValue)
{
    if(
strcmp(newValue"") == 0// If the cvar string is empty "", meaning there is no custom command
    
{
        
PrintToServer("[SM] Infractions custom command is empty.");
        
RemoveCommandListener(CustomCallbackoldValue);
    }
    else if(
strcmp(oldValue"") == && CommandExists(newValue)) // If the previous cvar setting was "", don't try to remove a non-existant listener
    
{
        
PrintToServer("[SM] Infractions custom command set to \"%s\""newValue);
        
AddCommandListener(CustomCallbacknewValue);
    }
    else if(
CommandExists(newValue)) // Remove the old listener, and create a new listener with the new command
    
{
        
PrintToServer("[SM] Infractions custom command set to \"%s\""newValue);
        
RemoveCommandListener(CustomCallbackoldValue);
        
AddCommandListener(CustomCallbacknewValue);
    }
    
    return;

Kryptanyte is offline
QuantumToast
Member
Join Date: May 2017
Location: US
Old 06-16-2017 , 12:49   Re: Infractions - The Early Stages
Reply With Quote #23

Quote:
Originally Posted by Kryptanyte View Post
You're not necessarily missing anything but you don't need to have the last else statement. You can keep the return at the end of the function:
Thank you for that, I'm pretty used to some of my previous languages and how they handle if statements, so I kind of autopiloted

Now, I'm writing a new function, Event_CheckInfractionsOnConnect, which is hooked to the event player_connect with this:
PHP Code:
HookEvent("player_connect"Event_CheckInfractionsOnConnectEventHookMode_Post
I assume that I did that part correctly, but I'm having a bit of an issue wrapping my head around getting the information from player_connect. Here's what the documentation has to say about the information it contains:
Code:
string	name	player name
byte	index	player slot (entity index-1)
short	userid	user ID on server (unique on server)
string	networkid	player network (i.e steam) id
string	address	ip:port
short	bot	is a bot
How do I get a byte and/or short? I don't seem to see a GetEventByte or GetEventShort. Would I have to make my own function? Or can I just "cast" the data to a different type with GetEventString and GetEventInt?

Last edited by QuantumToast; 06-16-2017 at 13:14.
QuantumToast is offline
QuantumToast
Member
Join Date: May 2017
Location: US
Old 06-16-2017 , 13:12   Re: Infractions - The Early Stages
Reply With Quote #24

Apologies for posting so much, but I think I've finalized OnCustomCommandChange. I didn't like that it would have to check if the command was valid more than once, so I just made it its own if statement. I'm also gonna start spoiler-ing my code to not clog up pages
Spoiler

Last edited by QuantumToast; 06-16-2017 at 13:15.
QuantumToast is offline
Chaosxk
Veteran Member
Join Date: Aug 2010
Location: Westeros
Old 06-16-2017 , 13:25   Re: Infractions - The Early Stages
Reply With Quote #25

Quote:
Originally Posted by QuantumToast View Post
How do I get a byte and/or short? I don't seem to see a GetEventByte or GetEventShort. Would I have to make my own function? Or can I just "cast" the data to a different type with GetEventString and GetEventInt?
GetEventInt should be fine for both.
__________________
Chaosxk is offline
QuantumToast
Member
Join Date: May 2017
Location: US
Old 06-16-2017 , 15:13   Re: Infractions - The Early Stages
Reply With Quote #26

Looking at some examples of plugins that use some sort of hook to player_connect, they seem to follow this format:
PHP Code:
public Action Event_PlayerConnect(Handle event, const String name[], bool dontBroadcast
Are the second two arguments required? Additionally, should I need anything other than the networkid (player SteamID) information from the event? All the function will do is compare their SteamID to the database and check if they have infractions, and if so, print a message to admins.

Last edited by QuantumToast; 06-16-2017 at 15:29.
QuantumToast is offline
Chaosxk
Veteran Member
Join Date: Aug 2010
Location: Westeros
Old 06-16-2017 , 17:32   Re: Infractions - The Early Stages
Reply With Quote #27

Quote:
Originally Posted by QuantumToast View Post
Looking at some examples of plugins that use some sort of hook to player_connect, they seem to follow this format:
PHP Code:
public Action Event_PlayerConnect(Handle event, const String name[], bool dontBroadcast
You have a mix between old/new syntax, should be something like this for new:
PHP Code:
public Action Event_PlayerConnect(Event event, const char[] namebool dontBroadcast)
{
    
int index event.GetInt("index");
    
int client GetClientOfUserId(event.GetInt("userid"));
    
    
//do something

You can take a look at the API for the format: https://sm.alliedmods.net/new-api/events/EventHook

Quote:
Originally Posted by QuantumToast View Post
Are the second two arguments required?
Yes those 2 arguments are required.

Quote:
Originally Posted by QuantumToast View Post
Additionally, should I need anything other than the networkid (player SteamID) information from the event? All the function will do is compare their SteamID to the database and check if they have infractions, and if so, print a message to admins.
Well try it out and adjust if your missing something.
__________________
Chaosxk is offline
QuantumToast
Member
Join Date: May 2017
Location: US
Old 06-16-2017 , 18:28   Re: Infractions - The Early Stages
Reply With Quote #28

Quote:
Originally Posted by Chaosxk View Post
You have a mix between old/new syntax, should be something like this for new:
PHP Code:
public Action Event_PlayerConnect(Event event, const char[] namebool dontBroadcast)
{
    
int index event.GetInt("index");
    
int client GetClientOfUserId(event.GetInt("userid"));
    
    
//do something

I apologize, I am not actually using the old format, I directly copy/pasted that from someone else's old plugin source, after searching around for some examples of player_connect event hooks :/ But thank you for making sure I was on the right track!

Also, regarding the last two arguments, what exactly are they used for? The API is great and all for finding the correct functions and syntaxes, but it has fairly poor descriptions of what the function is used for or what it even does. It also has no examples, just definitions for mostly everything :/

Quote:
Originally Posted by Chaosxk View Post
Well try it out and adjust if your missing something.
I haven't even begun to set up a SQL database yet, so I can't really test it. I have zero experience with it, but some nice people have posted some examples and links to get me started. It'll be slow progress since I'll be busy this weekend.

Last edited by QuantumToast; 06-16-2017 at 18:30.
QuantumToast is offline
hmmmmm
Great Tester of Whatever
Join Date: Mar 2017
Location: ...
Old 06-16-2017 , 20:25   Re: Infractions - The Early Stages
Reply With Quote #29

Wiki has a lot of useful info too and answers most of your questions: https://wiki.alliedmods.net/Events_(SourceMod_Scripting)
hmmmmm is offline
QuantumToast
Member
Join Date: May 2017
Location: US
Old 06-19-2017 , 13:40   Re: Infractions - The Early Stages
Reply With Quote #30

Sorry I've been absent, I had a busy weekend. Last night and this morning, I threw together this function, Event_CheckInfractionsOnConnect. The entire plugin compiles successfully, but of course that doesn't mean it works. I can't get on to test it for myself, but I thought I would see if any of you could offer advice or help me make sure all is well. Assume that the function PlayerHasInfractions works correctly. The function isn't 100% complete, because I haven't set up SQL database stuff, yet.
PHP Code:
public Action Event_CheckInfractionsOnConnect(Event event, const char[] namebool dontBroadcast)
{
  
int bot 0;
  
GetEventInt(event"bot"0);
  
int index 0;
  
GetEventInt(event"index"1);
  if(
bot == || !PlayerHasInfractions(index))
  {
    
FireEvent(eventfalse);
    
PrintToConsole(index"[SM] Connection handled by Infractions.");
    
PrintToServer("[SM] Connection handled by Infractions.");
    return 
Plugin_Handled;
  }
  else
  {
    for(
int i 1<= MaxClientsi++)
    {
      if(
IsClientInGame(i))
      {
        
int flags GetUserFlagBits(i);
        if(
flags ADMFLAG_ROOT || flags ADMFLAG_CUSTOM1 || flags ADMFLAG_CUSTOM2 || flags ADMFLAG_CUSTOM3 || flags ADMFLAG_CUSTOM4)
        {
          
PrintToChat(i"%L has joined the game and has infractions"i);
          
PrintToConsole(i"[SM] Connection handled by Infractions.");
          
PrintToServer("[SM] Connection handled by Infractions.");
        }
        else 
FireEvent(eventfalse);
        return 
Plugin_Handled;
      }
    }
  }
  return 
Plugin_Handled;

Thank you all

Edit: I did test it very briefly on my break at work, and it doesn't seem to do anything. I have edited the code to show what I did with it, namely that it should print to console AND server when a player connects, whether or not they have infractions.

Last edited by QuantumToast; 06-19-2017 at 14:44.
QuantumToast 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 18:12.


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