Wednesday, December 15, 2010

SmartFoxServer Game Extension

So now we have the basis for our server and client from end to end. We have our dev environment which encompasses Unity3D, NetBeans, and either Visual Studio or Mono Develop. We are now to the point where we need to create our extension. This part starts easy and is quickly expandable.

Open NetBeans and head over to your [GameName]Extension project. First create your package. In my last post I said it should be created as domain.domainname.gamename.entities. For our extension I create a base package called domain.domainname.gamename and this is where we will put our extension class.So:

  1. Right click on Source Packages and hit New -> Java Package.
  2. Type in the full name. Again I am using com.cjrgaming.aegisborn for my game.
  3. Click Finish.
  4. In the new package, right click and New -> Java Class...
  5. Give it the name of your game. For example [GameName]Extension.
  6. Click Finish.
This gives you your new class where we will put in the functions and handlers to deal with our new game. The first thing you want to do is append extends SFSExtension between the classname and the {.

Next we will create the init function:
@Override
public void init()
{
}
Thats all there is to it. Just an empty init function. We will fill this in later with our handlers and entity manager. Now is the time to make note of our package structure and extension name. We will be filling it into the Smart Fox Server information in just a bit.


First we need to right click our [GameName]Extension project and hit Build. Then we need to go to our project's folder, go into the dist folder and copy out the [GameName]Extension.jar file.


Go to [SFSInstallDir]\SFS2X\extensions and create a new directory called [GameName]Extension and place the [GameName]Extension.jar file in it.


Next log into the SmartFoxServer web management page (normally located at http://localhost:8080/admin ). Log into the server and go to Zone Configurator. Below the Zone section click the little green circle with the + and the second half of the window will appear.

  1. Enter [GameName] for the zone
  2. Click the Zone extension tab.
  3. In name put [GameName]Extension - this is the name of the folder containing your jar file.
  4. In File put domain.domainname.gamename.[GameName]Extension - i.e. com.cjrgaming.aegisborn.AegisBornExtension
  5. Click Submit at the bottom
There, now we have our extension with our java file loaded. Lets go ahead and create a general chat area.

  1. Select the zone [GameName]
  2. click the green button with the + sign under Rooms
  3. Give it a room name, i.e. General
  4. Leave everything else alone except the drop down for Auto-remove mode use NEVER_REMOVE.
  5. Click Submit
We now have a room called General under our new zone. The room is permanent and won't go away, this is good for general chat rooms that will be accessible to everyone for things like system messages or if you want a world wide chat in your game.

Now you need to restart the server to get the changes to take effect. Thats all for this tutorial. We now have our server ready and waiting for any connections to be made to it. Next up, Login and joining a room from unity3d.

No comments: