SA-MP Forums Archive
GetConsoleVarAsString float Server Crash - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP (https://sampforum.blast.hk/forumdisplay.php?fid=3)
+--- Forum: Bug Reports (https://sampforum.blast.hk/forumdisplay.php?fid=20)
+--- Thread: GetConsoleVarAsString float Server Crash (/showthread.php?tid=613615)



GetConsoleVarAsString float Server Crash - Freaksken - 29.07.2016

So, I created this thread in the Scripting Help forums. I'll post the contents of my first post again:
Quote:
Originally Posted by Freaksken
View Post
So I wanted the get the stream_distance set in server.cfg, which is a float value.
Since there is no GetConsoleVarAsFloat function, I've tried the approach found in this thread: click.
Code:
stock Float:GetConsoleVarAsFloat(var[]) {
     new string[30];
     GetConsoleVarAsString(var, string, sizeof(string)); //Crash happens here
     return floatstr(string);
}
But whenever I execute GetConsoleVarAsFloat("stream_distance"); the server crashes immediately.
GetConsoleVarAsInt and GetConsoleVarAsBool don't return the correct value obviously.
I have this line in my server.cfg file:
Code:
stream_distance 300.0
Does anyone know a solution?
Misiur replied this:
Quote:
Originally Posted by Misiur
View Post
You've found a bug: using GetConsoleVarAsString on anything other than string (integers, floats), causes segfault. Please report it, and nice find!
So, here I am reporting the problem.

EDIT:
See also this post in the Useful Functions thread.

EDIT 2:
The server also crashes if a nonexistent console variable is used.
I've updated the wiki page to show that this is a known bug.


Re: GetConsoleVarAsString float Server Crash - jlalt - 04.08.2016

You can use this as non stable way to check stream_distance vaule at the moment until this bug gets fixed.

how it works?
Sending rcon command varlist by the script then by a help from FileManager plugin move server log to scriptfiles folder then read last lines and get stream_distance vaule.

FileManager Plugin:
http://www.jatochnietdan.com/project/sa-mp/filemanager

Script:

PHP Code:
#include a_samp
#include filemanager
#pragma dynamic 18000
Float:GetServerVarAsFloat(var[])
{
   new 
Handle[5500];
   if(!
strcmp(var,"stream_distance", true))
   {
      
strcat(Handle, GetServerLog());
      new 
where = strfind(Handle, "stream_distance", true, 0);
      
strdel(Handle, 0, where);
      
strdel(Handle, 0, strfind(Handle,"=", true, 0)+2);
      
where = strfind(Handle,"(float)", true, 0);
      if(
where != -1)
      {
         
strdel(Handle, where, strlen(Handle));
      }
      
fremove("server_log.txt");
   }       
   else
   {
      
Handle = "0.0";
   }
   return 
floatstr(Handle);
}
GetServerLog()
{
   
SendRconCommand("varlist");
   
file_copy("server_log.txt", "scriptfiles/server_log.txt");
   new 
File:handle = fopen("server_log.txt", io_read);
   new 
Handle[5500];
   if(
handle)
   {
       
fseek(handle, -5000, seek_end);
       new 
buf[350];
       while(
fread(handle, buf))
       {
          
strcat(Handle, buf);
       }
       new 
where = strfind(Handle,"Console Variables:", true, where)+1;
       while(
strlen(Handle) && strfind(Handle,"Console Variables:", true, where))
       {
          
where = strfind(Handle,"Console Variables:", true, where)+1;
          
strdel(Handle, 0, where-1);
       }
       
fclose(handle);
   }
   else
   {
      
Handle = "stream_distance       = 301.000000";
   }
   return 
Handle;
} 
Usage example:

PHP Code:
public OnFilterScriptInit()
{
   new 
str[128];
   
format(str, sizeof str,"stream_distance Vaule is: %f", GetServerVarAsFloat("stream_distance"));
   
SendClientMessageToAll(-1, str);
} 



Re: GetConsoleVarAsString float Server Crash - Freaksken - 06.08.2016

The server also crashes if a nonexistent console variable is used.
I've updated the wiki page to show that this is a known bug.


Re: GetConsoleVarAsString float Server Crash - LolerotehC - 14.08.2016

You should use other alternatives


Re: GetConsoleVarAsString float Server Crash - Sew_Sumi - 17.08.2016

Quote:
Originally Posted by LolerotehC
View Post
You should use other alternatives
There is no alternative, and this is a bug as described.

There is a work-around, but it's not a fix, it only just works.