Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

ByteMe95

Accessing a database from within a full-screen game app

This topic is 5916 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I''ve never written any database access code in C++ before, all I know is basic stuff in ASP/PHP/CGI code to acccess a database. Pretty much I want to have a global high score system for my game, and I want the user to be able to post their score from within the game without going to some website, I want the game to take care of taking the score, accessing the DB on some server, adding the score, and that''s it. I think someone mentioned something about python once, but i might be waaaay off on that Also, right now I open up a url from in game, so it minimizes the game and opens a cgi URL with proper values to add a score (Like script.cgi?name=name&score=score, etc, all encoded) Is tehre a way to just open the link script.cgi and send the data as POST data so that no one else can see it, all from in game. Those are two separate questions, I need the answer to both if possible, the first one is more important to me right now Thanks ByteMe95::~ByteMe95() My S(h)ite

Share this post


Link to post
Share on other sites
Advertisement
Fruny: I assume that answers the second question, right?

thanks for the info, i''ll look into it.

Still need the answer for the first if anyone knows

ByteMe95::~ByteMe95()
My S(h)ite

Share this post


Link to post
Share on other sites
Ive been readingh through msdn for about 2 hours and I feel like i know less now than i did before i started!!

I have no idea how to open a socket to http in windows.

So now this is what i really want to know:
How do I send POST information to a cgi script from within a windows c++ program (ie, my game)

If anyone can answer that i will be happy!!!

ByteMe95::~ByteMe95()
My S(h)ite

Share this post


Link to post
Share on other sites
a socket is a socket is a socket. there''s no such thing as an XML socket, an http socket or a foo-fooBlue socket. you just send data over a socket. it can be whatever data you want as long as whatever is receiving it can parse that data. a socket is just a channel of communication. to send http to a socket just connect your socket to port 80 of the webserver that''s running your php code and send the appropriate page request to the server. the socket will respond and you can just text parse the data.

do a google search on "WinSock tutorial". (the johnny''s winsock tutorial - lost the link - had enough for me to set up socket
communication bet 2 apps on the same machine).

not sure about a POST to a cgi script. you''d need to do more than that though, b/c you''d need to capture the output of the SQL call that the cgi script makes. for which, again, you''d need sockets, most likely. just running the cgi db access script isn''t going to give your app the info all by itself.

i''m sure that somewhere there are database libraries with which you can directly access a database from within a C++ program. i KNOW there are ones for java (which are incedentally very easy). jdbc for java, i think. though setting up the drivers for the database can be a bitch...

i don''t know anything about C++ database access libraries. i''d look into the docs of your database b/c i''m sure you could just send SQL over a socket to the database and have it reply to you (though i''m not all that sure about it). goto your database company''s website and either ask the tech support people or look around on the site to see if they provide any documentation or libraries. ideally the database would provide a socket you can access directly (though typically you need a driver or some other annoying to set up thing).

-me

Share this post


Link to post
Share on other sites
Most of PHP script is using MySQL. So, use it as well! If MySQL port is open on your server, than u could write all DB management in C++. Go to mysql.com & see for C or C++ API tutorial. Really it is GOOD!

P.S. Besides, PHP & C API for MySQL is almost the same...

Lekha

Share this post


Link to post
Share on other sites
Look up the HTTP RFC. It explains that an HTTP request is fundamentally just nicely-formatted plain text sent down a socket, typically to port 80. Basically, all you need to do is send the request, the request headers, a blank line, and your ''entity body'' (your POST data). It amounts to probably 7 or 8 lines of plain text. You then call recv() to collect the response until the socket closes.

[ MSVC Fixes | STL | SDL | Game AI | Sockets | C++ Faq Lite | Boost | Asking Questions | Organising code files ]

Share this post


Link to post
Share on other sites
I dont know whats better, I want to store a simple table of high scores/player name.
Is that worth a mysql db? Not that it''s hard to implement.

Also if i do go with mysql and the mysql API calls from my code, how would I protect my username/password, that would be easily viewed by anyone that knowns anything about looking through an exe file.

ByteMe95::~ByteMe95()
My S(h)ite

Share this post


Link to post
Share on other sites
You might try looking into mySQL (www.mysql.org); it's free, it's powerful enough for many applications (I believe there are more than one MMORPGs that might be using it, but I can't confirm that rumor), and it took me an afternoon to setup the db, connect a C++ application to it, and actually do something useful (queries etc). It automatically manages networked connections too, which is very handy. Check it out.



MatrixCubed
http://MatrixCubed.cjb.net



[edited by - MatrixCubed on June 2, 2002 11:18:29 AM]

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!