Sie sind auf Seite 1von 19

Lobby Module

Server Side Setup Guide


Version 1.16
Novel Games
Web Site: http://www.novelgames.com
Support Email: support@novelgames.com Page 2 of 19

Table of Contents
Introduction......................................................................................................................................3
Directory Structure...........................................................................................................................4
Step By Step Example......................................................................................................................5
Parameters on the Server Side........................................................................................................6
Obscene Names Filter......................................................................................................................9
Recording Results..........................................................................................................................10
Facebook Sharing..........................................................................................................................12
Getting Runtime Information...........................................................................................................14
Parameters to Pass to the SWF File..............................................................................................15
Troubleshooting..............................................................................................................................18
Document Modification History.......................................................................................................19

Copyright 2010 - 2012, Novel Games Limited. All Rights Reserved. Page 2 of 19
Novel Games
Web Site: http://www.novelgames.com
Support Email: support@novelgames.com Page 3 of 19

Introduction

This document tells you how to set up the server side for using the Lobby Module in
your Multiplayer Flash games.

Two sets of server side codes are supplied: PHP and ASP.NET 2.0 C#. If your server is
using other technologies, then you should implement these parts yourself.

Copyright 2010 - 2012, Novel Games Limited. All Rights Reserved. Page 3 of 19
Novel Games
Web Site: http://www.novelgames.com
Support Email: support@novelgames.com Page 4 of 19

Directory Structure

The files are arranged in the following directory structure:


+
+-- mnaualServer.pdf (this file)
+-- PHP
+-- lobbyFiles
+-- pictures
+-- PHP files
+-- ASP.NET
+-- lobbyFiles
+-- pictures
+-- ASPX files

We will discuss each of these files in the next section

Copyright 2010 - 2012, Novel Games Limited. All Rights Reserved. Page 4 of 19
Novel Games
Web Site: http://www.novelgames.com
Support Email: support@novelgames.com Page 5 of 19

Step By Step Example

In this section we'll walk through a step by step example of setting up the server for
working with the Lobby Module.

1. We supply two sets of server side codes: one in PHP and another in ASP.NET
2.0 C#. If you are using other technologies in the server, then you should set up
the server yourself. The following are the steps for PHP, the steps for ASP.NET
are the same
2. Upload all the things under the PHP directory to your web server.
3. There is a folder called lobbyFiles in the PHP directory that is uploaded when
you perform the previous step, make sure that the web server can write to this
directory. For example if you uploaded the files using FTP, then you may need
to set the permission of that folder so that everyone can write
4. Do the same for the pictures folder
5. Upload the game.js, HTM and the SWF files of the games to the same
directory. Note that the directory should now look like this:
lobbyFiles
pictures
config.php
common.php

game.js
rockpaperscissors.htm
rockpaperscissors.swf
6. Navigate to test.php in your web browser, this script will run a few tests to see if
the settings are correct. If errors appear, then please double check the settings.
7. That's all of the setup. Now navigate to game HTM files in your web browser
and test the games. You can open a few browser windows to try the multiplayer
gaming
8. You can navigate to restart.php to restart the server, by default the username
and password are both admin . You can modify config.php to change these.

Copyright 2010 - 2012, Novel Games Limited. All Rights Reserved. Page 5 of 19
Novel Games
Web Site: http://www.novelgames.com
Support Email: support@novelgames.com Page 6 of 19

Parameters on the Server Side

In this section we'll explain the parameters that can be tuned on the server side. These
parameters are put in the config.php file. In ASP.NET the parameters are the same and
are put in config.aspx

Parameter Description
$defaultRoomNames The default names of the game rooms, see also
$gameRoomNames
$defaultRoomCapacities The default capacities of the game rooms, see also
$gameRoomCapacities
$gameRoomNames The names of the game rooms for each particular
game. For example, if $defaultRoomNames is
array('Gold', 'Silver'), and if
$gameRoomNames[7] is array('Pro',
'Amateur'), then the game rooms shown to the
player playing the game with gameID 7 will be Pro
and Amateur, and the game rooms shown to the
player playing other games will be Gold and Silver
$gameRoomCapacities The capacities of the game rooms for each particular
game. Use -1 for unlimited capacity. For example if
$defaultRoomCapacities is array(10, 20),
and if $gameRoomCapacities[7] is array(5,
10), then the game rooms shown to the player
playing the game with gameID 7 will have capacities 5
and 10, and the game rooms shown to the player
playing other games will have capacities 10 and 20
$controlUsername The username for the restart.php script
$controlPassword The password for the restart.php script
$duplicateNameTreatmen The action to take when another player with the same
t name entered the lobby, possible values are:
addIndex - an index will be appended to the end of
the name
showAll - all the players will be shown with the same
name
disconnectOld - the existing player with the same
name will be disconnected
disconnectNew - the new player will not be able to
join the room

Copyright 2010 - 2012, Novel Games Limited. All Rights Reserved. Page 6 of 19
Novel Games
Web Site: http://www.novelgames.com
Support Email: support@novelgames.com Page 7 of 19

$hashKey The hash key used, if the hash key is already set,
then do not change it
$extraKeyLength The length of the extra key generated for each player
$filesPath The state of the players will be kept in files. This
parameter controls the location of those files
$picturesPath The path to the folder where the pictures will be
stored
$inactiveTimeout When a player is inactive for the specified number of
seconds, then the player will be considered to be
disconnected
$shareWinText The text used when sharing if the player wins
$shareDrawText The text used when sharing if the player draws
$shareRankText The text used when sharing if the player loses
$shareFacebookAppID The facebook app ID. This is required if login through
facebook is allowed. In other cases this is optional, if
a valid facebook app id is there, then the player can
post results on facebook and can send challenges to
friends.
$shareFacebookAppSecre The facebook app secret. This is required if login
t through facebook is allowed.
$shareFacebookActionTe Used only if $shareFacebookAppID is non empty.
xt The action text to show
$shareFacebookEnableCh Used only if $shareFacebookAppID is non empty.
allenge Whether challenges are enabled, if enabled, you need
to modify the canvas page of the app so that
challenges are dealt with correctly. See the section on
Facebook Sharing for details.
$shareFacebookThanksTe Used only if $shareFacebookAppID is non empty.
xt The text to show on the challenge page
$shareFacebookChalleng Used only if $shareFacebookAppID is non empty.
eText The text shown on the challenge button on the
challenge page
$shareFacebookCloseTex Used only if $shareFacebookAppID is non empty.
t The text shown on the close button on the challenge
page
$shareFacebookRequestT Used only if $shareFacebookAppID is non empty.
itle The title on the facebook send request page
$shareFacebookRequestW Used only if $shareFacebookAppID is non empty.
inText The text content of the facebook request if the player

Copyright 2010 - 2012, Novel Games Limited. All Rights Reserved. Page 7 of 19
Novel Games
Web Site: http://www.novelgames.com
Support Email: support@novelgames.com Page 8 of 19

wins
$shareFacebookRequestD Used only if $shareFacebookAppID is non empty.
rawText The text content of the facebook request if the player
draws
$shareFacebookRequestR Used only if $shareFacebookAppID is non empty.
ankText The text content of the facebook request if the player
loses
$emailSender The email address of the sender of the emails. This
must be set to a valid email address in your domain
(e.g. your own email address).
$emailSubject The subject of the challenge email
$emailWinContent The content of the challenge email if the player wins
$emailDrawContent The content of the challenge email if the player draws
$emailRankContent The content of the challenge email if the player loses
$emailDefaultURL The default url of the game, in case the game could
not properly send its url to the script

Copyright 2010 - 2012, Novel Games Limited. All Rights Reserved. Page 8 of 19
Novel Games
Web Site: http://www.novelgames.com
Support Email: support@novelgames.com Page 9 of 19

Obscene Names Filter

An obscene names filter is installed so that obscene names will not be input to the
database. You can edit obscene.txt to add or remove obscene words.

If an obscene word is part of the name (ignoring spaces) input by the user, then the
name will be rejected.

Copyright 2010 - 2012, Novel Games Limited. All Rights Reserved. Page 9 of 19
Novel Games
Web Site: http://www.novelgames.com
Support Email: support@novelgames.com Page 10 of 19

Recording Results

When the game has ended, you can choose to record the results of the game. To do
this, implement the recordResult function in config.php (or config.aspx if you are using
ASP.NET version).

Method function recordResult($siteID, $gameID, $roomID,


$tableUID, $tableID, $playIndex, $playerNames,
$playerEmails, $playerIDs, $playerUsernames,
$playerFacebookUserIDs, $ranks, $playerIndex,
$customExtra)
Description This function will be called from each of the players when the game
has ended.
Parameters siteID the siteID
gameID the gameID
roomID the roomID
tableUID the unique ID of the table. The combination of siteID,
gameID, roomID and tableUID is guaranteed to be unique
tableID the table ID, this is relevant only if the tableID is passed
through FlashVars
playIndex the index of the play, or the number of replays in this
table. If it is the first play on this table then it is zero.
playerNames an array of names of the playing players
playerEmails an array of emails of the playing players. This is
relevant only for enterType set to nameEmail
playerIDs an array of player ID's of the playing players. This is
relevant only for enterType set to login
playerUsernames an array of usernames of the playing players.
This is relevant only for enterType set to login
playerFacebookUserIDs an array of facebook user IDs of the
playing players.
ranks the ranks of the players. The ranks begin at zero. For
example if ranks is an array of [ 0, 2, 0, 3] then the first player and the
third player have both won the game, while the second runner up is
the second player, the third runner up is the fourth player.
playerIndex the index (beginning at zero) of the player sending
this result
customExtra the string passed to the customExtra parameter
when gameEnded is called

Copyright 2010 - 2012, Novel Games Limited. All Rights Reserved. Page 10 of 19
Novel Games
Web Site: http://www.novelgames.com
Support Email: support@novelgames.com Page 11 of 19

Copyright 2010 - 2012, Novel Games Limited. All Rights Reserved. Page 11 of 19
Novel Games
Web Site: http://www.novelgames.com
Support Email: support@novelgames.com Page 12 of 19

Facebook Sharing

When the player finished playing the game he will have the option to share the game
on facebook. There are several ways to configure the high scores module to share the
game on facebook.

The first case is the basic sharing, in this case the shareFacebookAppID is set to an
empty string, in this case only the URL is shared, the player's results will not be
included in the share message (unless the player types it himself).

The second case is a more extended sharing, in this case the shareFacebookAppID
is set to a valid facebook app ID, and facebookEnableChallenge is set to false, in
this case the player's result will also be posted on the share message, but after the
sharing the player will not have the option to challenge his friends.

The last case is the advanced sharing, in this case the shareFacebookAppID is set
to a valid facebook app ID, and facebookEnableChallenge is set to true. In this
case after sharing the game, the player can also choose to challenge his friends.
Challenges are sent by Facebook Requests, the URL to share is put in the data field
of the request object, and the data field will be a JSON string, with the shareURL field
storing the URL to share. Please consult the documentation on facebook on how to
handle the requests. For example, if you are using PHP, the code to handle the request
may look like this:

<?php

$FACBOOKAPPID = '';
$FACBOOKAPPSECRET = '';

$request_ids = $_GET['request_ids'];

$result =
file_get_contents('https://graph.facebook.com/oauth/access_token
?client_id=' . $FACEBOOKAPPID . '&client_secret=' .
$FACEBOOKAPPSECRET . '&grant_type=client_credentials');

Copyright 2010 - 2012, Novel Games Limited. All Rights Reserved. Page 12 of 19
Novel Games
Web Site: http://www.novelgames.com
Support Email: support@novelgames.com Page 13 of 19

parse_str($result, $parameters);
$access_token = $parameters['access_token'];

$result = file_get_contents("https://graph.facebook.com/
$request_ids/?access_token=$access_token");

$details = json_decode($result);
$data = json_decode($details->data);
$shareURL = $data->shareURL;

$socket = fsockopen('ssl://graph.facebook.com', 443);


if(!$socket) exit;

fputs($socket, "DELETE /$request_ids/?access_token=$access_token


HTTP/1.1\r\nHost: graph.facebook.com\r\nConnection:
close\r\n\r\n");
while(!feof($socket)) {
fgets($socket, 1024);
}
fclose($socket);

echo '<script type="text/Javascript">top.location.href = "' .


$shareURL . '";</script>';
?>

Copyright 2010 - 2012, Novel Games Limited. All Rights Reserved. Page 13 of 19
Novel Games
Web Site: http://www.novelgames.com
Support Email: support@novelgames.com Page 14 of 19

Getting Runtime Information

There are some scripts that you can call to get the runtime information of the server.
For example, you can use the information returned to show the number of playing
players of each game in your web page. The list here are PHP files, the corresponding
ASPX files are also available.

Script getAllInfo.php
Description Call this script to get an XML text showing the information about all the
sites and games and rooms and players and tables.

Script getSiteInfo.php
POST siteID the siteID of the site you want to query
parameters
Description Call this script to get an XML text showing the information about all the
site queried

Copyright 2010 - 2012, Novel Games Limited. All Rights Reserved. Page 14 of 19
Novel Games
Web Site: http://www.novelgames.com
Support Email: support@novelgames.com Page 15 of 19

Parameters to Pass to the SWF File

In this section we'll explain the parameters that can be passed to the SWF file. These
parameters should be passed from the HTML file to the SWF file by Flash Vars, e.g.

<object id="novelgames_flashGame" classid="clsid:d27cdb6e-ae6d-


11cf-96b8-444553540000"
codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/fl
ash/swflash.cab#version=9,0,0,0" width="600" height="400">
<param name="movie" value="rockpaperscissors.swf" />
<param name="allowScriptAccess" value="always" />
<param name="allowFullScreen" value="true" />
<param name="loop" value="false" />
<param name="menu" value="false" />
<param name="quality" value="high" />
<param name="wmode" value="window" />
<param name="FlashVars"
value="playerID=1&playerName=John+Smith" />
<embed name="novelgames_flashGame"
src="rockpaperscissors.swf"
width="600" height="400"
allowScriptAccess="always"
allowFullScreen="true"
loop="false" menu="false" quality="high"
wmode="window"
FlashVars="playerID=1&playerName=John+Smith"
type="application/x-shockwave-flash"

pluginspage="http://www.macromedia.com/go/getflashplayer">
</embed>
</object>

Parameter Description
siteID If this parameter is set then it will override the site ID set in the SWF

Copyright 2010 - 2012, Novel Games Limited. All Rights Reserved. Page 15 of 19
Novel Games
Web Site: http://www.novelgames.com
Support Email: support@novelgames.com Page 16 of 19

file
gameID If this parameter is set then it will override the game ID set in the SWF
file
gameName If this parameter is set then it will override the game name set in the
SWF file
playerName This parameter controls the name of the player. If this parameters is
not present, then the player needs to input his / her name before
entering the lobby. If this parameter is present, then the player will
enter the lobby using this name.
playerPict This parameter controls the URL of the picture of the player. If this
ureURL parameter is present, then the player's avatar in the lobby will be
loaded from this URL.
playerFace This parameter sets the facebook user ID of the playing player. If this
bookUserID parameter is set, you should also set the
playerFacebookUserName, playerFacebookUserPicture,
playerFacebookFriendIDs parameters.
playerFace This parameter sets the facebook user name of the playing player. If
bookUserNa this parameter is set, you should also set the
me playerFacebookUserID, playerFacebookUserPicture,
playerFacebookFriendIDs parameters.
playerFace This parameter sets the facebook user picture of the playing player. If
bookUserPi this parameter is set, you should also set the
cture playerFacebookUserID, playerFacebookUserName,
playerFacebookFriendIDs parameters.
playerFace This parameter sets the facebook user ID's of the friends of the
bookFriend playing player. The value should be a comma delimited list of ID's. If
IDs this parameter is set, you should also set the
playerFacebookUserID, playerFacebookUserName,
playerFacebookUserPicture parameters.
tablePlaye The name of this parameter should match the value set in the
rNames0, tablePlayerNamesFlashVars of the lobby module in the FLA. This
tablePlaye parameter is used to pass the names of the players to the game. It is
rNames1, useful only if you have your own player matching system. If this
etc parameters is not present, then the player will need to manually open
a table, join a table or invite players to play. If this parameter is
present, then the player will not need to open table and invite players
and the game will start automatically with the predetermined players.

e.g. if your player matching system determines that John and Mary
are to start a game, then the FlashVars to pass to the game opened
by John will be:

Copyright 2010 - 2012, Novel Games Limited. All Rights Reserved. Page 16 of 19
Novel Games
Web Site: http://www.novelgames.com
Support Email: support@novelgames.com Page 17 of 19

playerName=John&tablePlayerNames0=John&tablePlayerN
ames1=Mary

and the FlashVars to pass to the game opened by Mary will be:

playerName=Mary&tablePlayerNames0=John&tablePlayerN
ames1=Mary
tableID The name of this parameter should match the value set in the
tableIDFlashVars of the lobby module in the FLA. This parameter is
used to pass the ID of the table to join to the game. It is useful only if
you have your own player matching system. If this parameter is
present, then the player will not need to open table and invite players
manually and the game will start automatically with other players with
the same table ID value
tableNoOfP The name of this parameter should match the value set in the
layers tableNoOfPlayersFlashVars of the lobby module in the FLA. This
parameter is used only when tableID is used. If this parameter is
not set, then the game will start as soon as the game can start (e.g. if
the game supports 2, 3 and 4 players, then the game will start as soon
as 2 players have joined), otherwise the game will start only when the
specified number of players have joined.
tableNoOfR The name of this parameter should match the value set in the
obots tableNoOfRobotsFlashVars of the lobby module in the FLA. This
parameters is used only if both the tableID and
tableNoOfPlayers parameters are used. If this parameter is set,
then the game will start with not more than the specified number of
robots.
robotName The name of this parameter should match the value set in the
robotNameFlashVars of the lobby module in the FLA. This
parameter controls the name of the robot.

Copyright 2010 - 2012, Novel Games Limited. All Rights Reserved. Page 17 of 19
Novel Games
Web Site: http://www.novelgames.com
Support Email: support@novelgames.com Page 18 of 19

Troubleshooting

Q) The lobby doesn't work


A) Please check
1. Whether you can run the test.php (or test.aspx) file without errors
2. Whether all the files, PHP (or ASPX), JS, HTM, SWF are under the same directory
If it still doesn't work:
1. check the error log of the web server to see if you can find anything
2. if you are using SELinux, check to see if SELinux is configured to allow the web
server to access the files in the lobbyFiles directory
3. check to see if PHP safe mode is turned off, if it is turned on, turn it off

Q) We want to organize the scripts so that the server side scripts and the game SWF
file are in different folders, is it possible?
A) Yes, you can add a base parameter to the object and embed tags of the HTML
page, for example if the game is accessed by
http://www.yoursite.com/games/game.htm and the server side scripts are put in
http://www.yoursite.com/php/ folder, then the object and embed tags should look
like this

<object ......>
...
<param name="base" value="http://www.yoursite.com/php/" />
<embed ...
base="http://www.yoursite.com/php/">
</embed>
</object>

If you have any questions, please feel free to contact us at support@novelgames.com

Copyright 2010 - 2012, Novel Games Limited. All Rights Reserved. Page 18 of 19
Novel Games
Web Site: http://www.novelgames.com
Support Email: support@novelgames.com Page 19 of 19

Document Modification History

Version Date Description


1.0 2010-4-12 First Draft
1.1 2010-4-23 Added descriptions about ASP.NET version
Added Recording Results section
Added Getting Runtime Information section
1.2 2010-10-12 Added details about challenging friends by email
1.3 2010-12-6 Added emailSender parameter in PHP and ASPX files
1.4 2010-12-23 Added siteID, gameID, gameName parameters
Updated step by step guide so that the directory structure is clearer
Added troubleshooting section
1.5 2011-3-1 Fixed an error in the troubleshooting section about the base
parameter
Moved the Modification History to a Document Modification History
section
1.6 2011-3-7 Added a duplicateNameTreatment parameter
1.7 2011-3-11 Added a tablePlayerNames parameter
1.8 2011-4-13 Updated facebook sharing mechanism
1.9 2011-4-14 Added support for tableID and tableNoOfPlayers parameters
1.10 2011-5-31 Added tableID to recordResult function
1.11 2011-6-11 Updated recordResult location
Added playIndex parameter to recordResult
1.12 2011-7-6 Updated to support custom share text and picture
Updated to support customExtra when recording results
1.13 2011-9-10 Added support for playerPictureURL parameter
1.14 2011-11-14 Added details about facebook login
1.15 2012-1-4 Added more details to the troubleshooting section about lobby doesn't
work
1.16 2012-2-20 Added support to tableNoOfRobots and robotName FlashVars

Copyright 2010 - 2012, Novel Games Limited. All Rights Reserved. Page 19 of 19

Das könnte Ihnen auch gefallen