Jump to content

  • Log In with Google      Sign In   
  • Create Account

C++ and MySQL for the server


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
14 replies to this topic

#1 MisterVicodin   Members   -  Reputation: 107

Like
0Likes
Like

Posted 02 April 2013 - 11:24 PM

Is it secure and fast for me to make my C++ DirectX10 game retrieve data from my MySQL server via SQL queries that are run inside the client?



Sponsor:

#2 SimonForsman   Crossbones+   -  Reputation: 6112

Like
0Likes
Like

Posted 03 April 2013 - 02:22 AM

retrieving data is "secure" as long as you don't need to restrict in detail what data the client has access to. (having the client fetch for example a list of news directly from a SQL server is safe if the account used by the client is restricted to SELECTs on that specific table), it would probably be faster to use a cache layer between the SQL server and the client though.

 

Any semi-competent user will be able to retrieve the MySQL account used by the client and run their own queries with whatever permissions that account has, if you intend to use the SQL server to allow clients to modify and share the game state in a multiplayer game then no, it will be extremely insecure, and if the updates are frequent, very slow.


Edited by SimonForsman, 03 April 2013 - 02:26 AM.

I don't suffer from insanity, I'm enjoying every minute of it.
The voices in my head may not be real, but they have some good ideas!

#3 hplus0603   Moderators   -  Reputation: 5310

Like
1Likes
Like

Posted 03 April 2013 - 11:50 AM

No, it is going to be neither fast nor secure to let a database be exposed to the greater Internet. One role of application servers is to filter the kinds of requests that a client will make, and turn them into sanitized back-end queries. There is not sufficient capabilities in SQL servers to do this; that's not what they're for.

Separately, for a real-time game, most developers end up reading the important data into RAM in a persistent process in the application server (call it "game server") and only write back to the database on occasional snapshots or specific events. This is usually done for efficiency purposes.
enum Bool { True, False, FileNotFound };

#4 markr   Crossbones+   -  Reputation: 1653

Like
0Likes
Like

Posted 03 April 2013 - 03:54 PM

Definitely not; it is possible to do an effective DoS attack on a MySQL server even without access to any tables at all. You need to put a layer in between MySQL and the big, bad world.



#5 MisterVicodin   Members   -  Reputation: 107

Like
0Likes
Like

Posted 04 April 2013 - 07:39 PM

So how can i securely transfer data from my SQL server to the program/video game?



#6 hplus0603   Moderators   -  Reputation: 5310

Like
0Likes
Like

Posted 04 April 2013 - 11:52 PM

I already suggested how this is done: You create a game server (application server) that talks to the database, and provides the necessary view of the data to the client.
Separately, it accepts requests from the client, computes the result of those requests, and returns the authoritative response to the client, as well as stores important outcomes back into the database.
enum Bool { True, False, FileNotFound };

#7 MisterVicodin   Members   -  Reputation: 107

Like
0Likes
Like

Posted 05 April 2013 - 09:00 PM

I already suggested how this is done: You create a game server (application server) that talks to the database, and provides the necessary view of the data to the client.
Separately, it accepts requests from the client, computes the result of those requests, and returns the authoritative response to the client, as well as stores important outcomes back into the database.

Yes but you never explained how i would do this. Not everyone here have a Game Programming degree in C++ :P Lol. But do you have any suggestions on how i could do this?



#8 MisterVicodin   Members   -  Reputation: 107

Like
0Likes
Like

Posted 05 April 2013 - 09:02 PM

What i mean is, what should i use to make the server? Is there a tutorial on this? 



#9 hplus0603   Moderators   -  Reputation: 5310

Like
0Likes
Like

Posted 06 April 2013 - 11:38 AM

What i mean is, what should i use to make the server? Is there a tutorial on this?

You should use tools that are available to you, and that you are comfortable in using.
Successful game servers have been written using a variety of technologies, including but not limited to C++, Java, C#, Python, Visual Basic, Erlang, JavaScript, and C.

So, the first question is: What do you already know, and what do you have available to you?
enum Bool { True, False, FileNotFound };

#10 MisterVicodin   Members   -  Reputation: 107

Like
0Likes
Like

Posted 06 April 2013 - 06:05 PM

What i mean is, what should i use to make the server? Is there a tutorial on this?

You should use tools that are available to you, and that you are comfortable in using.
Successful game servers have been written using a variety of technologies, including but not limited to C++, Java, C#, Python, Visual Basic, Erlang, JavaScript, and C.

So, the first question is: What do you already know, and what do you have available to you?

What i meant is how do i make a server? Idek how i would do any of this but no-one is even giving me a hint on how to start coding a server.

 

What i already know is basically how to do everything needed to make an online game except how to code a server. So any help would be great!



#11 SimonForsman   Crossbones+   -  Reputation: 6112

Like
0Likes
Like

Posted 06 April 2013 - 11:50 PM



What i mean is, what should i use to make the server? Is there a tutorial on this?

You should use tools that are available to you, and that you are comfortable in using.
Successful game servers have been written using a variety of technologies, including but not limited to C++, Java, C#, Python, Visual Basic, Erlang, JavaScript, and C.

So, the first question is: What do you already know, and what do you have available to you?


What i meant is how do i make a server? Idek how i would do any of this but no-one is even giving me a hint on how to start coding a server.
 
What i already know is basically how to do everything needed to make an online game except how to code a server. So any help would be great!


Google: socket tutorial. There are plenty of examples on basic client server communication out there.

You could also pick some higher level networking library (RakNet for example) and look for tutorials on that instead.

Edited by SimonForsman, 06 April 2013 - 11:51 PM.

I don't suffer from insanity, I'm enjoying every minute of it.
The voices in my head may not be real, but they have some good ideas!

#12 hplus0603   Moderators   -  Reputation: 5310

Like
1Likes
Like

Posted 07 April 2013 - 01:51 AM

The FAQ for this forum has links to game network coding.

In very brief, to create a server, you can start as such:

1) Call socket() to create a TCP socket.
2) Call bind() to bind the socket to your given port, and IP address 0.0.0.0 (IPADDR_ANY).
3) Call listen() for basically historical reasons.
4) Now, enter a loop that does the following:
4.1) Put all active sockets in an FD_SET.
4.2) Call select() with that FD_SET to test readability of sockets. Perhaps use a timeout so you can run periodic events even if the server is idle.
4.3) For the listening socket, if it returns readable, it means someone is connecting; call accept() on it and allocate a data structure with incoming buffer and client information. (This is empty for now.) Put the mapping from socket ID to buffer/client information into a hash table.
4.4) For each connected socket that is readable by select(), call recv() once to attempt to fill up the incoming data buffer in the per-socket data structure. Recv() will not block the first time you call it after select() says it is readable.
4.4.1) Decode, remove, and dispatch any complete packet(s) that are in the receive buffer for this socket/client.
4.4.2) If recv() returns 0, or the client sends a "quit/disconnect" command, or the client is sending bad packets, close the socket, and de-allocate the buffer/client information structure for this socket.
4.5) Goto 4.1

That's really all there is to the basic server loop, based on select(). This will easily get you to many hundred simultaneous users.
enum Bool { True, False, FileNotFound };

#13 MisterVicodin   Members   -  Reputation: 107

Like
0Likes
Like

Posted 09 April 2013 - 05:18 PM

The FAQ for this forum has links to game network coding.

In very brief, to create a server, you can start as such:

1) Call socket() to create a TCP socket.
2) Call bind() to bind the socket to your given port, and IP address 0.0.0.0 (IPADDR_ANY).
3) Call listen() for basically historical reasons.
4) Now, enter a loop that does the following:
4.1) Put all active sockets in an FD_SET.
4.2) Call select() with that FD_SET to test readability of sockets. Perhaps use a timeout so you can run periodic events even if the server is idle.
4.3) For the listening socket, if it returns readable, it means someone is connecting; call accept() on it and allocate a data structure with incoming buffer and client information. (This is empty for now.) Put the mapping from socket ID to buffer/client information into a hash table.
4.4) For each connected socket that is readable by select(), call recv() once to attempt to fill up the incoming data buffer in the per-socket data structure. Recv() will not block the first time you call it after select() says it is readable.
4.4.1) Decode, remove, and dispatch any complete packet(s) that are in the receive buffer for this socket/client.
4.4.2) If recv() returns 0, or the client sends a "quit/disconnect" command, or the client is sending bad packets, close the socket, and de-allocate the buffer/client information structure for this socket.
4.5) Goto 4.1

That's really all there is to the basic server loop, based on select(). This will easily get you to many hundred simultaneous users.

I did not understand any of this except how to open a socket. Can someone just add me on Skype so in case i need help i will have someone to help me out?



#14 hplus0603   Moderators   -  Reputation: 5310

Like
1Likes
Like

Posted 10 April 2013 - 12:09 PM

If you do not understand that description, then you need to first do step 0: Learn to effectively develop software. This includes being good at at least two different programming languages, and being able to read and understand the manual pages and documentation of the system libraries.
If you do not yet have those skills, you cannot develop a robust game server. Right now, you're trying to learn calculus, from a textbook written in Latin, without knowing any Latin. You need to learn the Latin before you can learn the calculus.

If you want one-on-one help, there are many contractors and consultants that will spend their time helping you out. That will cost money, though.
enum Bool { True, False, FileNotFound };

#15 MisterVicodin   Members   -  Reputation: 107

Like
-1Likes
Like

Posted 24 April 2013 - 10:47 PM

If you do not understand that description, then you need to first do step 0: Learn to effectively develop software. This includes being good at at least two different programming languages, and being able to read and understand the manual pages and documentation of the system libraries.
If you do not yet have those skills, you cannot develop a robust game server. Right now, you're trying to learn calculus, from a textbook written in Latin, without knowing any Latin. You need to learn the Latin before you can learn the calculus.

If you want one-on-one help, there are many contractors and consultants that will spend their time helping you out. That will cost money, though.

Actually, i have successfully coded many many things in about 6 or 7 other languages. And learning to effectively code has nothing to do with it. I was asking what requirements i need. Suchas the include files. I have now coded a server btw. I was simply asking for the required information needed to be able to code a server. And actually, calculus is a good suggestion but is not actually necessary. Anyways. Thanks guys for all your help. I followed a WinSock tutorial to get started and coded the rest of the server myself. Hoping that i will have my MMORPG done by December. Good day everyone.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS