Raised This Month: $51 Target: $400
 12% 

How to use a keyvalues file?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
CoolPeter
Member
Join Date: Nov 2005
Old 09-09-2006 , 11:47   How to use a keyvalues file?
Reply With Quote #1

Hi,

i have a problem and hope that someone can help me.
I want to load a file like that:

Code:
"ips.txt"
{
  "127.0.0.1"
  {
    "id"  "1"
    "pw"  "123"
  }
  ...
}
Now i want to load the file in the plugin::load void.

Code:
GET_V_IFACE_ANY(engineFactory, m_FileSystem, IFileSystem, FILESYSTEM_INTERFACE_VERSION);
...
KeyValues *kv = new KeyValues("ips.txt");
...
if(!kv || !kv->LoadFromFile(m_FileSystem, "ips.txt")) {
  META_CONPRINT("Can't load ips.txt!\n");
  return false;
}
But the server crashs on kv->LoadFromFile...
Any idea?
CoolPeter is offline
c0ldfyr3
AlliedModders Donor
Join Date: Aug 2005
Location: Ireland
Old 09-09-2006 , 12:06   Re: How to use a keyvalues file?
Reply With Quote #2

Code:
if ( !m_FileSystem )
{
  META_CONPRINT( "FileSystem interface not loaded correctly.\n" );
  return false;
}
if ( m_FileSystem->FileExists( "ips.txt" ) )
{
  KeyValues *kv = new KeyValues( "ips.txt" );
  ... // Whats this?
  if( !kv || !kv->LoadFromFile(m_FileSystem, "ips.txt" ) ) 
  {
    META_CONPRINT( "Can't load ips.txt!\n" );
    return false;
  }
}
else
{
    META_CONPRINT( "Can't locate file \"ips.txt\"!\n" );
}
You sure it's crashing on that line? Do you run it in MSVC debug mode?
__________________

Last edited by c0ldfyr3; 09-09-2006 at 12:48.
c0ldfyr3 is offline
Send a message via MSN to c0ldfyr3 Send a message via Yahoo to c0ldfyr3
CoolPeter
Member
Join Date: Nov 2005
Old 09-09-2006 , 13:02   Re: How to use a keyvalues file?
Reply With Quote #3

Yes i'm sure...
If i delete " || !kv->LoadFromFile(m_FileSystem, "ips.txt" )" it doesn't crash.
And m_FileSystem is ok otherwise it display "Could not find interface: ..." and return false.

If i use your code it still crash
But it crashs here "m_FileSystem->FileExists( "ips.txt" )"...
So there is something wrong with m_FileSystem...

What's wrong with this:

GET_V_IFACE_ANY(engineFactory, m_FileSystem, IFileSystem, FILESYSTEM_INTERFACE_VERSION);

?

Edit:

Ok i got it... It works with this:

GET_V_IFACE_CURRENT(engineFactory, m_FileSystem, IFileSystem, FILESYSTEM_INTERFACE_VERSION);

Last edited by CoolPeter; 09-09-2006 at 13:08.
CoolPeter is offline
BAILOPAN
Join Date: Jan 2004
Old 09-09-2006 , 17:06   Re: How to use a keyvalues file?
Reply With Quote #4

Are you sure you're supposed to use the engineFactory and not the filesystemFactory? But if it works with that, might as well not break it again.
__________________
egg
BAILOPAN is offline
CoolPeter
Member
Join Date: Nov 2005
Old 09-10-2006 , 03:45   Re: How to use a keyvalues file?
Reply With Quote #5

I don't know
This is in the sample vsp:

filesystem = (IFileSystem*)interfaceFactory(FILESYSTEM_INT ERFACE_VERSION, NULL)
CoolPeter is offline
sslice
Senior Member
Join Date: Feb 2005
Location: Texas, USA
Old 09-10-2006 , 11:53   Re: How to use a keyvalues file?
Reply With Quote #6

I don't even load IFileSystem for the use of KeyValues.. I just copy the whole file into a buffer with stdio, then use kv->LoadFromBuffer(). If you can't get IFileSystem stuff working right, try this.
__________________
sslice is offline
c0ldfyr3
AlliedModders Donor
Join Date: Aug 2005
Location: Ireland
Old 09-11-2006 , 04:13   Re: How to use a keyvalues file?
Reply With Quote #7

The IFileSystem interface works correctly if instantiated correctly, its an interface provided for our use (sometimes they claim otherwise go figure), so it's easier for novices to practice how its preached in the SDK IMO =)
__________________
c0ldfyr3 is offline
Send a message via MSN to c0ldfyr3 Send a message via Yahoo to c0ldfyr3
L. Duke
Veteran Member
Join Date: Apr 2005
Location: Walla Walla
Old 09-11-2006 , 10:53   Re: How to use a keyvalues file?
Reply With Quote #8

Hahahahaja...provided for our use...that's a good one <wipes a tear from his eye>

Like everything else, that's for mods. Plugins shouldn't be modifying anything. According to a setinfo on #sourcemod, Mani was told by someone at Valve that he shouldn't be using IFileSystem.
L. Duke is offline
Stormsys
Member
Join Date: Oct 2005
Old 10-02-2006 , 15:11   Re: How to use a keyvalues file?
Reply With Quote #9

Quote:
Originally Posted by L. Duke View Post
............... shouldn't be using IFileSystem.
then why the ........ do valve include it in the sdk, its like givving somone a pen and telling them not to use it.
Stormsys is offline
BAILOPAN
Join Date: Jan 2004
Old 10-02-2006 , 17:16   Re: How to use a keyvalues file?
Reply With Quote #10

It basically reimplements everything in libc anyway so what's the point? At least libc is well documented and supported, no reason not to use it.
__________________
egg
BAILOPAN 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 03:56.


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