Raised This Month: $ Target: $400
 0% 

Hud causing overflow


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Jhob94
AMX Mod X Donor
Join Date: Jul 2012
Old 07-30-2014 , 14:34   Hud causing overflow
Reply With Quote #1

Hum, i guess the code is fine. I don't code so much as i did before but i think i didn't became so noob
Or i am just great by making stupid bugged plugin, wich problably i am

PHP Code:
#include <amxmodx>
#include <amxmisc>
#include <sockets>

#define PLUGIN "Alternative Redirect"
#define VERSION "0.0.9"

#define AREDIRECT_PREFIX "AREDIRECT"

new show_playershud_timehud_redhud_greenhud_blue
new configsdir[200], serversfile[200]
new 
Data[255], charnum
new Left[25], Right[50]
new 
g_iServersg_iMaxPlayers
new IP[22]

public 
plugin_init()
{
    
register_plugin(PLUGINVERSION"Jhob94")
    
    
get_configsdir(configsdircharsmax(configsdir))
    
format(serversfilecharsmax(serversfile), "%s/servers.cfg"configsdir)
    
    if(!
file_exists(serversfile))
    {
        new 
error[100]
        
formatex(errorcharsmax(error), "[%s] Server Can't Load The File: %s!"AREDIRECT_PREFIXserversfile)
        
set_fail_state(error)
        return
    }
    
    
show_players register_cvar("ar_show_players""0"// Turn 1 to display amount of players and maxplayers in servers menu
    
    
hud_time register_cvar("ar_hud_delay""60.0"// Time to show again the HUD message of servers
    
set_task(get_pcvar_float(hud_time), "Servers_Hud"___"b")
        
    
/* RGB HUD COLORS */
    
hud_red register_cvar("ar_hud_red""0")
    
hud_green register_cvar("ar_hud_green""0")
    
hud_blue register_cvar("ar_hud_blue""250")
    
    
get_user_ip(0IP21false)
    
    
g_iServers file_size(serversfile1)
    
g_iMaxPlayers get_maxplayers()
}

public 
Servers_Hud()
{
    new 
hudservers[500], playersmaxplayers
    formatex
(hudserverscharsmax(hudservers), "%s^n"PLUGIN)
    
    for(new 
ig_iServersi++)
    {
        
read_file(serversfileiDatacharsmax(Data), charnum)
        if(
strlen(Data) < || Data[0] == ';' || equali(Data"//"2))
            continue
        
        
strbreak(DataLeftcharsmax(Left), Rightcharsmax(Right))
        
        if(
get_pcvar_num(show_players) && containi(LeftIP) == -1// I guess containi is fine. I cant remove quotes yet and i dont want to add unnecessary lines
            
get_data(Leftplayersmaxplayers)
            
        
remove_quotes(Right)
        
        if(
equali(LeftIP))
            
formatex(Rightcharsmax(Right), "%s - (%d/%d)"Rightget_playersnum(1), g_iMaxPlayers)
        
        else
            
formatex(Rightcharsmax(Right), "%s - (%d/%d)"Rightplayersmaxplayers)
        
        
formatex(hudserverscharsmax(hudservers), "%s%s^n"hudserversRight)
    }
    
    
set_hudmessage(get_pcvar_num(hud_red), get_pcvar_num(hud_green), get_pcvar_num(hud_blue), -1.00.106.012.0)
    
show_hudmessage(0hudservers)
}

stock get_data(host[], &players, &maxplayers)
{
    new 
ip[32], port[10], err
    copy
(ipcharsmax(ip), host)
    
copy(portcharsmax(port), "27015")
    if(
containi(host":") != -1)
        
strtok(hostipcharsmax(ip), portcharsmax(port), ':')
        
    
players maxplayers = -1
    
new sock socket_open(ipstr_to_num(port), SOCKET_UDPerr)
    if(
sock || err)
    {
        
AR_Log("[SOCKET] Socket error")
        
socket_close(sock)
        return
    }
    
    new 
buffer[1500]
    
copy(buffercharsmax(buffer), "^xFF^xFF^xFF^xFF^x54Source Engine Query")
    
socket_send2(sockbufferstrlen(buffer) + 1)
    
    new 
socket_recv(sockbuffersizeof(buffer))
    
socket_close(sock)
    if(
2)
    {
        
AR_Log("[SOCKET] No data")
        return
    }
    
    new 
ij5
    
while(c)
    {
        if(
buffer[c+i++] == '^0'
            
j++
            
        if(
== c)
        {
            
players buffer[j+i]
            
maxplayers buffer[++j+i]
            
0
        
}
    }
}

AR_Log(const message_fmt[], any:...)
{
    static 
message[256]
    
vformat(messagesizeof(message) - 1message_fmt2)
    
    static 
filename[96]
    static 
dir[64]
    if(!
dir[0])
    {
        
get_basedir(dirsizeof(dir) - 1)
        
add(dirsizeof(dir) - 1"/logs")
    }
    
    
format_time(filenamesizeof(filename) - 1"%m-%d-%Y")
    
format(filenamesizeof(filename) - 1"%s/%s_%s.log"dirAREDIRECT_PREFIXfilename)
    
    
log_to_file(filename"%s"message)

Note: this is just one part of the plugin, i dont want to show all that is coming on next version
__________________
Jhob94 is offline
schmurgel1983
Veteran Member
Join Date: Aug 2006
Location: Germany
Old 07-31-2014 , 01:48   Re: Hud causing overflow
Reply With Quote #2

Get you a overflow on show_hudmessage?
http://www.amxmodx.org/funcwiki.php?..._hud&go=search
__________________

Working on:
nothing
schmurgel1983 is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 07-31-2014 , 04:02   Re: Hud causing overflow
Reply With Quote #3

I don't know about the issue as it's quite vague, but no joking your code is crap: reading file each x seconds, using read_file in a loop, wrong formatex usage, etc..

Quote:
this is just one part of the plugin, i dont want to show all that is coming on next version
HOLY SHIT, PLEASE KEEP THIS FOR YOU.
__________________

Last edited by Arkshine; 07-31-2014 at 04:03.
Arkshine is offline
Jhob94
AMX Mod X Donor
Join Date: Jul 2012
Old 07-31-2014 , 06:04   Re: Hud causing overflow
Reply With Quote #4

Quote:
Originally Posted by Arkshine View Post
I don't know about the issue as it's quite vague, but no joking your code is crap: reading file each x seconds, using read_file in a loop, wrong formatex usage, etc..
I know and as i said somewhere, i will optimize stuff, when i have time for it.
At moment just fixing crash problem and adding some new stuff.
Optimizations arent such urgent things. As long as plugin works fine, i have time to do the optimizations.
__________________
Jhob94 is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 07-31-2014 , 06:15   Re: Hud causing overflow
Reply With Quote #5

The formatex misusage is not an optimization. And what I've said is not about optimization anyway, it's about using the proper natives first.
__________________

Last edited by Arkshine; 07-31-2014 at 06:32.
Arkshine is offline
Jhob94
AMX Mod X Donor
Join Date: Jul 2012
Old 07-31-2014 , 08:30   Re: Hud causing overflow
Reply With Quote #6

Its optimization, or it isnt. I dont know how to call it
I pretend to read IPs and Names once and save the results. But that isnt urgent, cuz the plugin works at moment.
And i said before that i hadnt much time and if someone wanted could remake the plugin and trash the current one. This plugin is what is cleaning the mess that valve did. Not saying they shouldnt block connect, just saying they should of have done something to allow redirect and block fake servers. Wich didnt happened. I am cleaning up someone's mess, so stop judging it. I have full time work, community and my personal life. If you think this cant wait, then remake the plugin by yourself
__________________
Jhob94 is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 07-31-2014 , 09:43   Re: Hud causing overflow
Reply With Quote #7

Wow. You are in SCRIPTING SECTION, there is no need to react like that. You are here to learn and do some coding. I've just pointed out some POSSIBLE issue with the code that YOU posted. I'm TRYING TO HELP YOU. And not what I''ve said is not about optimizations, because how works such natives internally, and considering plugin context, they could have some issue around this, that's why you should anyway use FROM THE START proper natives to do the job, then you can try to optimize your code after that. I'm not even talking about YOU.
__________________

Last edited by Arkshine; 07-31-2014 at 09:45.
Arkshine is offline
Jhob94
AMX Mod X Donor
Join Date: Jul 2012
Old 07-31-2014 , 10:24   Re: Hud causing overflow
Reply With Quote #8

You remind me my ex-gf. I didnt said anything in agressive meant. I am weak, i dont attack anyone
__________________
Jhob94 is offline
.Dare Devil.
Veteran Member
Join Date: Sep 2010
Old 07-31-2014 , 11:45   Re: Hud causing overflow
Reply With Quote #9

Are you sure that hudmessage is causing this?
If yes, then i guess debug it.

First see what is going into hudmessage ( print that hudservers somewhere where you can read. )
Check how many times that function is called where hudmessage is.

Basically just checking is the code really running the way it should by logging everything somewhere.
I just write .txt file if for example there is crash or something that prevent me using console print.

Also when you write your code, make sure you test it also in extreme conditions.
For example reading that file what you're reading, when file is huge.
.Dare Devil. 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