Server Help Forum Index Server Help
Community forums for Subgame, ASSS, and bots
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   StatisticsStatistics   RegisterRegister 
 ProfileProfile   Login to check your private messagesLogin to check your private messages   LoginLogin (SSL) 

Server Help | ASSS Wiki (0) | Shanky.com
Buffer Issues :/

 
Post new topic   Reply to topic Printable version
 View previous topic  Read Now Urgent Post :: Post how to make a bot?  View next topic  
Author Message
Dark_Nexus
Newbie


Age:39
Gender:Gender:Female
Joined: Jan 02 2004
Posts: 23
Offline

PostPosted: Wed Apr 07, 2004 12:41 am    Post subject: Buffer Issues :/ Reply to topic Reply with quote

I am using a windows function to access reg keys and .ini files, here is the function with its syntax:

GetPrivateProfileSection(section name,buffer name,size of buffer,path to file)

so lets say i have an .ini file with one section and use that function to retrieve the data from it:

[Operators]
Dark_Nexus=3
blehbleh=4
bleep=2

the way it returns the section is, each data key gets put into the buffer as a string, it is followed by a NULL terminating character, and the last string of the buffer has two NULL terminating characters. So it looks like this in the buffer:

Dark_Nexus=3 \n blehbleh=4 \n bleep=2 \n\n

So now lets say i want to assign a variable to the buffer, as in:

String msg = buffer;

now String msg will only equal the first string, as in Dark_Nexus=3, because it encounters the first NULL terminating character and thinks it is a string.

So i need a way to sort through the buffer, and place the data i need into a String variable.

here is what i have tried (and does not work):



Code: Show/Hide
msg = "Operators: ";
GetPrivateProfileSection("Operators",buffer,250,path);
String opstr = buffer;
GetPrivateProfileString("Operators","ASOCount",0,question_num,3,path);
for (int i = 1;i <= atoi(question_num);i++)
{
    msg += opstr.split('\n');
    msg += ", ";
}
sendPrivate(p,msg);


so lets say i have 3 moderators, it will look like this in game:

Bot> Operators: Dark_Nexus=3, Dark_Nexus=3, Dark_Nexus=3

icon_sad.gif helppppp
_________________
"In fact, about the only reasonable holiday is 4th of July (US). We celebrate something that actually happened by blowing shit up."
-Mr Ekted
Back to top
View users profile Send private message Add User to Ignore List Send email AIM Address MSN Messenger
Mr Ekted
Movie Geek


Gender:Gender:Male
Joined: Feb 09 2004
Posts: 1379
Offline

PostPosted: Wed Apr 07, 2004 1:22 am    Post subject: Reply to topic Reply with quote

Off the top of my head...

Code: Show/Hide
char *p;

p = buffer;  // loaded with results of function call

while (*p)
   {
   // set your string = p and do what you like
   p += strlen(p) + 1;
   }


This shows C's strength: the ability to handle memory in an arbitrary format.
_________________
4,691 irradiated haggis!
Back to top
View users profile Send private message Add User to Ignore List
Mine GO BOOM
Hunch Hunch
What What
Hunch Hunch<br>What What


Age:41
Gender:Gender:Male
Joined: Aug 01 2002
Posts: 3615
Location: Las Vegas
Offline

PostPosted: Wed Apr 07, 2004 10:28 am    Post subject: Reply to topic Reply with quote

Mr Ekted wrote:
This shows C's strength: the ability to handle memory in an arbitrary format.

Would you come up with a source to show in anyway how C++ is a subset of C?
Back to top
View users profile Send private message Add User to Ignore List Send email
Mr Ekted
Movie Geek


Gender:Gender:Male
Joined: Feb 09 2004
Posts: 1379
Offline

PostPosted: Wed Apr 07, 2004 11:41 am    Post subject: Reply to topic Reply with quote

C++ is a superset of C. I'm not sure what you are asking.
Back to top
View users profile Send private message Add User to Ignore List
D1st0rt
Miss Directed Wannabe


Age:37
Gender:Gender:Male
Joined: Aug 31 2003
Posts: 2247
Location: Blacksburg, VA
Offline

PostPosted: Wed Apr 07, 2004 11:50 am    Post subject: Reply to topic Reply with quote

Heres a solution, thanks to Dustpuppy:

It's golden icon_cool.gif
_________________





From the EXPLBOT source

iniaccess.zip - 1.56 KB
File downloaded or viewed 15 time(s)
Back to top
View users profile Send private message Add User to Ignore List Visit posters website
50% Packetloss
Server Help Squatter


Age:40
Gender:Gender:Male
Joined: Sep 09 2003
Posts: 561
Location: Santa Clarita, California
Offline

PostPosted: Wed Apr 07, 2004 12:36 pm    Post subject: Reply to topic Reply with quote

char *INIAccess::GetString(char *section, char *key, char *strdefault)

if you run this function, make sure you delete [] what it returns, so that you dont get a memory leak
Back to top
View users profile Send private message Add User to Ignore List Send email AIM Address
Mr Ekted
Movie Geek


Gender:Gender:Male
Joined: Feb 09 2004
Posts: 1379
Offline

PostPosted: Wed Apr 07, 2004 1:22 pm    Post subject: Reply to topic Reply with quote

This is one of my main dislikes of C++ (if you go overboard). It makes the coding at the top level look all nice and simple, when in fact, there's 10x more going on under the hood. More code executing (slower + larger), and unnecessary memory allocations/frees. IMO, C++ is best used to encapsulate large functional blocks. Of course, you can do this in C just as well.
Back to top
View users profile Send private message Add User to Ignore List
50% Packetloss
Server Help Squatter


Age:40
Gender:Gender:Male
Joined: Sep 09 2003
Posts: 561
Location: Santa Clarita, California
Offline

PostPosted: Wed Apr 07, 2004 1:50 pm    Post subject: Re: Buffer Issues :/ Reply to topic Reply with quote

Dark_Nexus wrote:

the way it returns the section is, each data key gets put into the buffer as a string, it is followed by a NULL terminating character, and the last string of the buffer has two NULL terminating characters. So it looks like this in the buffer:

Dark_Nexus=3 \n blehbleh=4 \n bleep=2 \n\n


rofl, a null looks like \0
the \n is a newline character.

I dont think that function will work anyway.
Back to top
View users profile Send private message Add User to Ignore List Send email AIM Address
Dustpuppy
Server Help Squatter


Age:40
Gender:Gender:Male
Joined: Jan 23 2003
Posts: 215
Location: England
Offline

PostPosted: Wed Apr 07, 2004 3:47 pm    Post subject: Reply to topic Reply with quote

That class doesn't provide for reading an entire section, which is what Dark Nexus wanted.
To be honest, INIs aren't meant for this sort of data and you would be better off reading from a standard text file, one operator to a line.

If you really wanted to keep it in an ini, perhaps you could use:

[Operators]
Sysop=Foo:Bar
Smod=Blah:bleh

etc

If you wanted to keep your current format, I think Ekted's code would be best. But if you wanted to use a MERV String, you could try using a strncpy:
I believe GetPrivateProfileSection returns the length of the string it copied into buffer, so you could store the length it returned, then strncpy into your String.msg, and use split on the newlines.

I can't remember if the String object lets you access the msg property though.
_________________
Back to top
View users profile Send private message Add User to Ignore List Send email Visit posters website
Cyan~Fire
I'll count you!
I'll count you!


Age:37
Gender:Gender:Male
Joined: Jul 14 2003
Posts: 4608
Location: A Dream
Offline

PostPosted: Wed Apr 07, 2004 5:59 pm    Post subject: Reply to topic Reply with quote

Just get lines from the file and process them one at a time.

Some crap code using iostreams (please don't yell Ekted):
Code: Show/Hide
ifstream op_file;
char buffer[100], ops[20][12], levels[20];
for (int i = 0; i < 20; i++)
{
   if (op_file.eof())
      break;
   op_file.getline(buffer, 100);
   int loc = find(bufffer, '=');   //some kind of character finding func
   strncpy(ops[i], buffer, loc);
   levels[i] = atoi(buffer + loc + 1);
}

Hope this helps... and that I didn't make too many mistakes!
_________________
This help is informational only. No representation is made or warranty given as to its content. User assumes all risk of use. Cyan~Fire assumes no responsibility for any loss or delay resulting from such use.
Wise men STILL seek Him.
Back to top
View users profile Send private message Add User to Ignore List Visit posters website
Dark_Nexus
Newbie


Age:39
Gender:Gender:Female
Joined: Jan 02 2004
Posts: 23
Offline

PostPosted: Wed Apr 07, 2004 8:37 pm    Post subject: Reply to topic Reply with quote

GetPrivateProfileSection is a standard windows function...i would hope it was microsoft tested and approved tongue.gif
Back to top
View users profile Send private message Add User to Ignore List Send email AIM Address MSN Messenger
Mr Ekted
Movie Geek


Gender:Gender:Male
Joined: Feb 09 2004
Posts: 1379
Offline

PostPosted: Wed Apr 07, 2004 10:39 pm    Post subject: Reply to topic Reply with quote

Dark_Nexus wrote:
GetPrivateProfileSection is a standard windows function...i would hope it was microsoft tested and approved tongue.gif


Agreed. Don't roll your own with INI files.
Back to top
View users profile Send private message Add User to Ignore List
Cyan~Fire
I'll count you!
I'll count you!


Age:37
Gender:Gender:Male
Joined: Jul 14 2003
Posts: 4608
Location: A Dream
Offline

PostPosted: Wed Apr 07, 2004 10:52 pm    Post subject: Reply to topic Reply with quote

Except for the fact that file file you're writing is not really an INI.
Back to top
View users profile Send private message Add User to Ignore List Visit posters website
Dustpuppy
Server Help Squatter


Age:40
Gender:Gender:Male
Joined: Jan 23 2003
Posts: 215
Location: England
Offline

PostPosted: Thu Apr 08, 2004 7:56 pm    Post subject: Reply to topic Reply with quote

It is an INI but it shouldn't be. I already went over this...
Back to top
View users profile Send private message Add User to Ignore List Send email Visit posters website
Display posts from previous:   
Post new topic   Reply to topic    Server Help Forum Index -> Bot Questions All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum
View online users | View Statistics | View Ignored List


Software by php BB © php BB Group
Server Load: 331 page(s) served in previous 5 minutes.

phpBB Created this page in 0.513191 seconds : 40 queries executed (91.5%): GZIP compression disabled