AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Authorization plugin instead of native amxx (https://forums.alliedmods.net/showthread.php?t=53601)

PlayingTalking 04-07-2007 07:56

Authorization plugin instead of native amxx
 
Hi everybody!

I write a plugin to replace amxx native user authorization engine. It requests the database for user info and sets flags according to user's group.
4 now I’ve done the following:

Code:

#include <amxmodx>
#include <amxmisc>
#include <fun>
#include <dbi>
 
 
#define PLUGIN "Auth Plugin"
#define VERSION "1.0"
#define AUTHOR "PlayingTalking"
#define dbhost "127.0.0.1"
#define dbname "xxx"
#define dbuser "xxx"
#define dbpass "xxx"
 
public plugin_init() {
    register_plugin(PLUGIN, VERSION, AUTHOR);
    register_event("ResetHUD", "hook_join_auth","be")
}
 
 
public hook_join_auth(id) {
 
          new playername[35]
          new playerpass[35]
          new playergroup
          get_user_name(id, playername, 50)
 
          new error[35]
 
          new Sql:dbh = dbi_connect(dbhost, dbuser, dbpass, dbname, error, 255);
 
          if (dbh == SQL_FAILED) {
                      log_amx("[PT Auth] SQL Connection Failed = %s", error)
                      return PLUGIN_HANDLED;
          }
 
          new Result:result
 
          result = dbi_query(dbh, "SELECT username, password, groupid FROM tblusers WHERE username = '%s'",  playername)           
          if (result > RESULT_NONE) {     
            if (dbi_num_rows(result)>0) {           
 
 
                      dbi_nextrow(result)
 
                      dbi_field(result, 1, playername, 31)
                      dbi_field(result, 2, playerpass, 31)
                      playergroup=dbi_field(result, 3)
 
                      new setinfopass[32]                 
                      get_user_info(id, "_password", setinfopass, 31)             
 
                      new md5sum[34]                     
                      md5(setinfopass,md5sum)                   
 
                      if (md5sum[31] == playerpass[31]) {                           
                                  //new flags
                                  remove_user_flags(id, ADMIN_USER)
                                  switch(playergroup){
                                              case 5:        // Site Admin – Server Top Admin                                                                                               
                                              {       
                                                          set_user_flags(id, read_flags("abcdefghijklmnopqrstu"))                                                             
                                              }
                                              case 3:        // Site Moderator – Server Admin
                                              {
                                                          set_user_flags(id, read_flags("bcdefju"))
 
                                              }
                                              case 2:        // VIP
                                              {
                                                          set_user_flags(id, read_flags("bj"))
 
 
                                              }
                                              case 1:        // User
                                              {
                                                          set_user_flags(id, read_flags("j"))                                             
                                              }
                                  }                                 
                      } else {                       
                                  server_cmd("kick #%d Wrong password for player %s. ",uid, playername)                                                                                                         
                      }                     
            }
            dbi_free_result(result)
          }                                 
          dbi_close(dbh) 
 
          return PLUGIN_HANDLED
}

Everything works fine but the plugin has 2 disadvantages:
1. The procedure of checking is called every round which is 2 often. And it starts only when a player is alive and has joined a team
2. This method disallows the slot reservation mechanism.
I’ve tried to add the following:

Code:


public client_connect(id)
{
hook_join_auth(id)
}

It work but as I funded out (imho) my function is called before amxx native auth procedures. Thus my plugin firstly sets proper flags to player and after that amxx changes them, back to "z"

This is my first plugin and everything I’ve done I've done by reading this forum. But now I couldn't fide answer for the question here:
Q1: How to call my function after amxx calls its own. Or if it s possible even disable amxx native authorization mechanism?

Maybe smb suggests an other salvation. To my mind:

1. At player connects server plugin should check his info and set flags according to group (top admin, common admin, vip, user) and flag "z" to other not registered users.
2. The same when client_infochanged
3. In future I want to disable slot reservation in my server. And therefore when an admin or vip connects full server the plugin should kick one of not registered players with worst kills/deaths coefficient. So my second question is:
Q2: how can I get players list with their kill/deaths information?

Emp` 04-07-2007 17:40

Re: Authorization plugin instead of native amxx
 
try with client_putinserver(id). if that doesn't work, just disable the amxx auth. (find where amxx does it, rescript it or strip it) or just add your function to the amxx way.

get_user_kills
get_user_deaths

PlayingTalking 04-08-2007 22:17

Re: Authorization plugin instead of native amxx
 
Thanks a lot.
  • client_putinserver(id) works fine.
  • I replaced get_user_kills to get_user_frags (I didn’t find get_user_kills in functions list)
I’ll post here my new plugin soon. If smb needs it. :oops:

PRoSToTeM@ 09-17-2017 18:46

Re: Authorization plugin instead of native amxx
 
Don't use userinfo for password storing. It can be stolen on other server.

BaD CopY 09-18-2017 15:11

Re: Authorization plugin instead of native amxx
 
Ok, I can change it whenever I want. Why server print '2345' if password is '12345' ?

fysiks 09-18-2017 21:13

Re: Authorization plugin instead of native amxx
 
What are you talking about? Please make a new thread for your question since your question doesn't appear to be about the original post.


All times are GMT -4. The time now is 06:38.

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