Raised This Month: $ Target: $400
 0% 

Working on a plugin. Little help please :)


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
rompom7
Senior Member
Join Date: May 2004
Old 06-11-2004 , 04:30   Working on a plugin. Little help please :)
Reply With Quote #1

Well I have put my War plugin on hold, and I decided to make this plugin. What it does is when someone types amx_login <username> <password>into console it checks with the file custom\amx_login\loginusers.ini and sees if they user and pass are correct, then sets them as admin.

Code:
/* AMX-X Login Script Commands: -     amx_login <user> <password> (c) 2003, James Romeril This file is provided as is (no warranties). */ #include <amxmodx> #include <amxmisc> #define max_admins 64 public login(id) {     new usercfg[64]     new linestring[255]     new linesize = 0     new i = 0     new arguser[32]     new argpass[32]     new username[32]     new password[32]     new flags[32]         get_customdir(usercfg, 63)     format(usercfg, 63, "%s/amx_login/loginusers.ini", usercfg)         if (file_exists(usercfg)){         while(read_file(usercfg,i,linestring,255,linesize)&&i < max_admins){             if(linestring[0] == ';'){                 continue             }                   parse(linestring, username[31], 31, password[31], 31, flags[31], 31)             read_argv(1,arguser,31)             read_argv(2,argpass,31)             if((equal(username, arguser))&&(equal(password, argpass))){                             set_user_flags(id, 1, id)                 new text[64]                 format(text, 128, "[AMXX AUTH] You are now logged in, with the flags: s%.", flags)                  client_print(id, print_chat, text)                 return PLUGIN_CONTINUE             }             if(!(equal(username, arguser))&&(equal(password, argpass))){                 client_print(id, print_chat, "[AMXX AUTH] Incorrect username and/or password.")                 return PLUGIN_CONTINUE             }         }     }     return PLUGIN_CONTINUE } public plugin_init(){     register_plugin("Admin Login","1.0","James Romeril")     register_clcmd("amx_login","login",-1,"amx_login <username> <password>") }

This is what I have in my loginusers.ini

Code:
"pxl" "password" "abcdefghijklmnopqrstuz"
So I start my dedicated and join it. Then I type into console amx_login and it says Unknown Command: amx_login.

Then I type into console amx_login pxl password and it freezes my server! I get connection lost and I can't see any error code because the Steam HLDS is screwed. So can someone just check over my code /methinks there is something wrong with the looping.
__________________
Forgive your enimies, but never forget their name.
rompom7 is offline
Send a message via MSN to rompom7
Johnny got his gun
Veteran Member
Join Date: Jan 2004
Location: Tokyo
Old 06-11-2004 , 04:48  
Reply With Quote #2

Weeell, I don't have the time to go through all that, but what ive seen so far:

Code:
  format(text, 128, "[AMXX AUTH] You are now logged in, with the flags: s%.", flags)

Change s% to %s...

Commands should end with return PLUGIN_HANDLED, else they will be like "Unknown command".

Also linestring[255] is 255 cells big so you can't set a max at 255 in read_file for that. Set 254 instead. (read_file(usercfg,i,linestring,254,linesize) ).

Also getting the cmd arguments within the loop is a bad idea. They will be the same each iteration of the loop, so be sure to retrieve those before the loop starts. (read_argv())

Also the two ifs that do the same evaluation, only the later use a "!", looks odd. Why not remove that last if and put it outside the loop. I assume you will have more entries in that ini file. Else if the right accoutn is not on first line, only the first one will ever work. actually I think you'll remove the second if altogether and outside the loop say "Sorry, incorrect password/username", because you return from the function whenever there's a match with user/password.

AND, one more thing :-)
Code:
                new text[64]                 format(text, 128, "[AMXX AUTH] You are now logged in, with the flags: s%.", flags)                     client_print(id, print_chat, text)
Ouch, why? If you're gonna do this, you can't set maxsize to 128 when text[64] is 64! Use 63 in that case. But why bother, just scrap all that and do this:
Code:
client_print(id, print_console, "[AMXX AUTH] You are now logged in, with the flags: %s.", flags) // don't forget %s, not s%
Btw I assume you want the output in console, not chat area...

Edit: Oh, I just noticed one more thing which could be really dangerous:
Code:
parse(linestring, username[31], 31, password[31], 31, flags[31], 31)
Should be
Code:
parse(linestring, username, 31, password, 31, flags, 31)
Else you start writing from the 32nd character in username, password and flags, and you tell it it's okay to write 31 characters from there, writing beyond the limit of the strings. That will totally mess things up.
Johnny got his gun is offline
rompom7
Senior Member
Join Date: May 2004
Old 06-11-2004 , 05:13  
Reply With Quote #3

Thank you jghg. Your ace
__________________
Forgive your enimies, but never forget their name.
rompom7 is offline
Send a message via MSN to rompom7
rompom7
Senior Member
Join Date: May 2004
Old 06-11-2004 , 09:33  
Reply With Quote #4

Ok, it works now, except that when you put in the correct name and password it says you have admin status, but you don't. Secondly if you get the password or username wrong, it crashes the HLDS. Any ideas anyone?

Code:
/* AMX-X Login Script Commands: -     amx_login <user> <password> MUCH Thanks to Johnny got his gun. (c) 2003, James Romeril This file is provided as is (no warranties). */ #include <amxmodx> #include <amxmisc> #define max_admins 64 public login(id) {     new usercfg[64]     new linestring[255]     new linesize = 0     new i = 0     new arguser[32]     new argpass[32]     new username[32]     new password[32]     new flags[32]         read_argv(1,arguser,31)     read_argv(2,argpass,31)         if((arguser[0] > 0)&&(argpass[0] > 0)){         get_customdir(usercfg, 63)         format(usercfg, 63, "%s/amx_login/loginusers.ini", usercfg)         if (file_exists(usercfg)){             while(read_file(usercfg, i,linestring,254,linesize)&& i < max_admins){                 if(linestring[0] == ';'){                     continue                 }                       parse(linestring, username, 31, password, 31, flags, 31)                 if((equal(username, arguser))&&(equal(password, argpass))){                     set_user_flags(0, ADMIN_LEVEL_A, id)                     new text[128]                     format(text, 128, "[AMXX AUTH] You are now logged in, with the flags: %s.", flags)                      client_print(id, print_console, text)                     return PLUGIN_HANDLED                 }             }             client_print(id, print_console, "[AMXX AUTH] Incorrect username and/or password.")         }     }     return PLUGIN_HANDLED } public plugin_init(){     register_plugin("Admin Login","1.0","James Romeril")     register_clcmd("amx_login","login",-1,"amx_login <username> <password>") }
__________________
Forgive your enimies, but never forget their name.
rompom7 is offline
Send a message via MSN to rompom7
Johnny got his gun
Veteran Member
Join Date: Jan 2004
Location: Tokyo
Old 06-11-2004 , 11:27  
Reply With Quote #5

Code:
    new line = 0, text[TEXTSIZE + 1], textlength     while ((line = read_file(file, line, text, TEXTSIZE, textlength)))  {         // parse text here     }

Looks like you dont increment the line counter.
Johnny got his gun 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 14:48.


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