Pages

Monday, July 30, 2012

Finally, MYSQL + code::blocks!

Hello everybody, today I'll make a "postmortem analysis" and will install and set up MySql server

     <Been out for a long time <again>, had many things to do and my project got stucked again, but it didn't get forgotten! I have been reading all the code again and had time to think about it, the things I have done right and which things should I change / improve, and made an small list:>

GOOD THINGS
  1. The server actually works!
  2. Client program able to create players, connect, and "move around"
  3. Worked quite fast in a desktop computer using small amounts of RAM
BAD THINGS
  1. Ugly code, I feel really ashamed about that, but it is the result of writing code in a "fast 15 min way"
  2. Server is unstable, yeah, after fixing many, many bugs it did worked, but still had things to fix.
  3. I was not using a real scenario , data was not being loaded from server, so player creation, maps, etc was everything client-side, obviously that is not good, for many reasons (security, for example)
  4. World didn't had persistent data, players, objects, etc were not stored  after closing client program
In other words I just did a network demo, I was so anxious to make the server work with thousands of clients that I didn't realized I was starting to loose the focus in my objective: MAKE THE GAME!

So I took a hard decision, dropped the code and to make a second server with all the good things the first server had + all the things it SHOULD HAVE like persistent data, and a true server-client model.

Having persistent data meant to use some kind of static storage, so I thought in using just plain files plus standard c++ io functions to write data, but I dropped the idea fast because there are already libraries to solve the "writing another text parser" like TinyXml , but after playing with that again I found that if I used that library I will be making two times the work because:
  1. First I will have to write all the data in .xml files
  2. To later rewrite the code again to switch to a real database..
I went back to my very first objectives and the name MySql, came to my mind...

<NOTE: I have completely dropped support for windows in the server part, that means I wont be posting how to install and make it run under Windows OS family, basically I made that because that's the OS I will be using to make and run the server and I cant loose more time in something I wont be using, although anybody could check how to download and install the required libraries for the OS you choose..>

So I installed the mysql server:
sudo apt-get install mysql-server
It just asked me for the "root" database password, it is very important because it will be used to connect to MySql and use the database, NOTE: it is not the linux root account so you can / should have different passwords .

I installed too MySql tuner:
sudo apt-get install mysqltuner
Used to get advice to tune the databases

And the client libraries:
sudo apt-get install libmysqlclient-dev
Used to connect from the client app

To check that the MySql server is running:
sudo netstat -tap | grep mysql
  
You can restart the service with:
sudo service mysql restart

 
<You can see installing MySql server is quite simple, in the next post I will write about comand-line database management, and finally start using it with code::blocks>