SmartFoxServer PRO bits

Need help with SmartFoxServer? You didn't find an answer in our documentation? Please, post your questions here!

Moderators: Lapo, Bax

User avatar
Lapo
Site Admin
Posts: 23026
Joined: 21 Mar 2005, 09:50
Location: Italy

SmartFoxServer PRO bits

Postby Lapo » 27 May 2005, 14:26

Hello,
we've been quite busy in the last weeks working on final parts of the SmartFoxServer PRO engine. During the next weeks we'll be completing the various tests and writing new documentation.

Since we're constantly receiving questions about how server side extensions will work, I am giving you a quick example.

Let's say we want to send a list of numbers from the client to one of our custom extensions. The extension will simply return another list with those numbers multiplied by 2.


1) Here's the code for the client:

Code: Select all

public function sendValues()
{
   var obj:Object = {}
   obj.values = [100, 200, 300, 400, 500]

   smartfox.sendXtMessage("simpleTest", "double", obj)
}


Just 3 lines: first we setup an object that will contain all the parameters we're sending to the extension.
We create an array property called "values" containing five numbers and finally we send the request to the extension using the sendXtMessage command.

The first argument is the name of the extension, the second is the name of the command we'd like to execute on that extension and finally we pass an object with the data to be processed.


2) Ok, now let'see how the request is received on the server side:

Code: Select all

function handleRequest(cmd, params, user, fromRoom)
{
   if (cmd == "double")
   {
      var response = {}
      response._cmd = "double"
      response.values = []
            
      for (var i = 0; i < params.values.length; i++)
      {
         var n = params.values[i]
         response.values[i] = n * 2
      }

      _server.sendResponse(response, -1, null, [user])
   }
}


A little bit more of code here because we're doing more things together: receiving the data, elaborate it and send a response back to the client.

The cmd argument is the name of the command requested from the client, in this case we've called it "double".
In the following lines we prepare the response object. Basically it is made of two fields only:

_cmd = the name of the command that was sent from the server (can be a good practice to keep it the same of the client-to-server request)

values = a list with the new values multiplied by 2

The for loop cycles through the list sent by the client and stores the doubled value in the response.value list.

Finally it's time to send the new data to the client using the _server.sendResponse() method.

The first argument is the response object, the second is the room number (-1, if we don't need this particular info), the third is the sender user object (null, if we don't need it) and the 4th parameter is a list with the users that will receive this message. In this case we just pass a list with the user that sent the request.


3) The third step is to see how the client handles the message fromt the server.
Here's the code:

Code: Select all

smartfox.onExtensionResponse = function(resObj:Object, type:String)
{
   if (resObj._cmd == "double")
   {
      trace("res: " + resObj.values)
   }
}


The code here is almost self-explaining. The resObj passed to the event handler contains the same properties we sent from the server, so its just a matter of reading them.
As a convention the "_cmd" property is used to pass the name of the command being sent.

That's all for now. In the next days I'll post some more example code bits showing database interaction!

Stay tuned for more news!
Last edited by Lapo on 02 Jul 2005, 13:49, edited 1 time in total.
Lapo
--
gotoAndPlay()
...addicted to flash games
User avatar
maguas
Posts: 8
Joined: 02 Jul 2005, 09:25
Contact:

Postby maguas » 02 Jul 2005, 09:48

Hi Lapo, we've been thinking a lot how to prevent game cheating/hacking and it seems that server-side extensions is the unique efficient way to prevent it. Maybe I'm wrong so I would like you to express your opinion in this aspect as this is an essential issue for any serious project.

The other question is that this system will require the administration of matches in the server. As far as I see it there are two possibilities:

1)Having a server side application that handles each match and it's launched by socket server. It will be based on standard variables and would only require two connections to database per match (first at the begining of the match and second at the end of it).

2) Having all matches handled by server side functions (socket-server) and database. This means each time a player ends his turn a message is sent to socket-server whose task is to get that match current variables from database (match database structure) make some operations, return them to both players and writing them in database. This would require 2 connections to database per turn which means lots more connections apart from a structure where match variables are stored.

So the question is: Will SmartFox Server PRO allow the first option? in other words, will it allow to create specific apis with all socket server functionality which keeps all match variables until that match is finished?

Thanks!
User avatar
Lapo
Site Admin
Posts: 23026
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 02 Jul 2005, 13:24

Hi,
about security I can certainly agree that using server side extensions can enhance the degree of protection you can achieve in your games.
By keeping all the important informations on the server side (score, settings, game data etc...) and by validating all the client requests its way more difficult to hack a multiplayer game.
If things are programmed well, it's going to be very difficult.

About the match management I am not sure if understand exactly what you are going to do but I will give you a short overview of how extensions work...

In a nutshell an extension allows you to create as many server side actions as you need to control the logic of the game. All the game data, statuses etc.. are kept on the server side writing your code in plain Actionscript, as you would normally do with Flash.

From your client application you can call all those new actions you have written and create your custom game interaction.

Moreover the extensions can be plugged at Room Level and Zone Level. Essentially this changes the amount of control you have in your server code: extensions plugged at Room Level only control the objects and the events of that specific room while those plugged at Zone Level will be able to control the entire zone with all its rooms and users etc...

Room Level extensions can be very helpful for developing games: let's say you want to create a game of poker. You write your server side code to handle each player turn, bets etc... for a single game.
Then, each time a game room is started, a copy of your extension is attached to that room and it will handle the game logic.

The server side Actionscript framework that we're going to provide with SFS PRO will give you all the necessary tools for interacting with the server, handling events, client requests, connect to databases, read and write data to files etc...

Moreover, if this wouldn't be enough, you can also access the entire Java2 framework from within your Actionscript code (!!): in other words you can instantiate any Java class and use it as a normal object in Actionscript, accessing its properties and callind its methods!

( More on this here >> viewtopic.php?p=311 )

Let me know if you have any more questions... :)
Last edited by Lapo on 01 Aug 2005, 19:53, edited 1 time in total.
Lapo

--

gotoAndPlay()

...addicted to flash games
User avatar
maguas
Posts: 8
Joined: 02 Jul 2005, 09:25
Contact:

Postby maguas » 02 Jul 2005, 14:35

Ok I think that's what we are looking for. If I understood you well we can do the following communications sequence (1vs1 card game):

1) P1 challenges P2

2) Server creates a match handler which knows from database each player's stats (modifiers and so on).

3) P1 exectutes an ACTION (throws a card)

4) Match handler is called to calculate the effect of this card on both players.

5) Match handler sends a message to each player with calculated effects.

6) Each client executes the effects visually and the turn ends.
User avatar
Lapo
Site Admin
Posts: 23026
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 02 Jul 2005, 15:08

Yes, absolutely! :)
Lapo

--

gotoAndPlay()

...addicted to flash games
User avatar
maguas
Posts: 8
Joined: 02 Jul 2005, 09:25
Contact:

Postby maguas » 02 Jul 2005, 15:27

And, more or less, how many matches you think SmartFox PRO will be able to handle with that gameplay structure?
User avatar
Lapo
Site Admin
Posts: 23026
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 02 Jul 2005, 15:54

This very difficult to tell. It depends on too many factors: the hardware you're using, how complex is the server side logic, how much bandwidth you have, how optimized is your code etc...

Since it's a card game and I guess it will be turn-based I guess you could handle many thousands of them on a good server equipped with enough RAM (let's say 1Gb) and a fast cpu. (2ghz +)
Lapo

--

gotoAndPlay()

...addicted to flash games

Return to “SmartFoxServer 1.x Discussions and Help”

Who is online

Users browsing this forum: No registered users and 75 guests