Wednesday, December 15, 2010

SmartFoxServer Entity Library

If you've been with me so far we have installed our dev environment, created our projects, started our server and created our database and web application to allow users to be created. The next step is important as we are going to create our entities in [GameName]Entities. This is the last step before we begin messages between the client and the server.

So we need to open NetBeans and go to our [GameName]Entities project and get started. First we need to connect NetBeans with our database.

  1. Click the tab that says Services
  2. Right click on Databases and click New Connection.
  3. A new window will appear. Click in the drop down and select MySQL (Connector/J Driver)
  4. Hit Next
  5. leave the host as localhost
  6. Update the database to be your database name
  7. Update the user and password to the user and password you created in part 6.
  8. Click Next then finish.
That gives us our database connection we will need to create the entities in our project. Up next is the actual creation of those entities.

  1. Right click on source packages and select New... -> Entity Classes from Database
  2. If Entity Classes from Database is unavailable click Other...
  3. Under the selection Persistence is Entity Classes from Database. select it.
  4. A new window will appear and will have a drop down. If it doesn't already contain your database, click it and select your database connection you created.
  5. The window will load all the tables in your database. For now you only need to add the classes [game_name]_account and sf_guard_user. 
  6. click Next
  7. Update the Package. The standard package convention is to list it as domain.domainname.gamename.entities. So for mine i did com.cjrgaming.aegisborn.entities.
  8. Leave the rest of the default selections and Click finish.
This will have created 2 packages, one called META-INF and another which is your package above like mine.

Now you can right click on the [GameName]Entities project and click Build which will build a jar file. Now we can put that into our SmartFoxServer. Navigate in an explorer window to your project. In the dist folder is a jar file called [GameName]Entities.jar. Copy this file into [SFSInstallDir]\SFS2X\lib. And lastly you will want to go to your [GameName]Entities\src folder and copy the META-INF folder into [SFSInstallDir]\SFS2X.

This concludes this tutorial. We are now completely set up and ready for the messaging between the server and client.

1 comment:

Anonymous said...

Looking forward to the next instalment.