how to create room-level game extension for my board game?

Post here your questions about SFS2X. Here we discuss all server-side matters. For client API questions see the dedicated forums.

Moderators: Lapo, Bax

chris0990
Posts: 4
Joined: 11 Jul 2011, 00:24
Location: Philippines

how to create room-level game extension for my board game?

Postby chris0990 » 09 Aug 2011, 00:57

Greetings!

I have created a game lobby just like from the given examples on the installation. I also created a board game without any extension of smartfox.

I also have tried creating a simple extension that I followed from the youtube channel.

My question is: how do I create a room-level game extension so that I could use the game lobby app for my board game? Where do I start?
User avatar
Bax
Site Admin
Posts: 4609
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Postby Bax » 11 Aug 2011, 14:08

We suggest you to start from the SFSTris example (Tic-Tac-Toe game) distributed with SFS.
Paolo Bax
The SmartFoxServer Team
Rashomon
Posts: 72
Joined: 11 Aug 2010, 19:48

Postby Rashomon » 15 Nov 2011, 03:03

I’m having a similar problem. I thought about starting a new thread, but I’m trying to follow the SFSTris example as you recommended to Chris, so I thought I’d piggy-back.

The short version is that I’m having trouble creating my dynamic room with an extension. I get a successful message on my client, but the trace in my extension’s init method never shows up. Then, I get an error when I try to use an extension request.

Here’s what I have so far:

Main.fla:

Code: Select all

// This is from the SFSTris2X code:
//private const EXTENSION_ID:String = "sfsTris"
//private const EXTENSIONS_CLASS:String = "sfs2x.extensions.games.tris.SFSTrisGame"

const EXTENSION_ID:String = "SpellingBee"
const EXTENSIONS_CLASS:String = "com.mycompany.SpellingBee.SpellingBeeGame"

btn_createGame1.addEventListener(MouseEvent.CLICK,onCreateGameClick1);
function onCreateGameClick1(Event:MouseEvent):void
{
    sfs.addEventListener(SFSEvent.ROOM_ADD, onRoomCreated);
    sfs.addEventListener(SFSEvent.ROOM_JOIN, onRoomJoin);
    sfs.addEventListener(SFSEvent.ROOM_CREATION_ERROR, onRoomCreationError);
    sfs.addEventListener(SFSEvent.USER_ENTER_ROOM, onUserEnterRoom);
    sfs.addEventListener(SFSEvent.USER_EXIT_ROOM, onUserExitRoom);
         
    var roomName:String = "game1"
    var roomPwd:String = "";
    var roomMaxS:int = 0;   

    if (roomName.length > 0)
    {
   var settings:RoomSettings = new RoomSettings(roomName)
   settings.groupId = "game"
   settings.password = roomPwd
   settings.isGame = true
   settings.maxUsers = 2
   settings.maxSpectators = roomMaxS
   settings.extension = new RoomExtension(EXTENSION_ID, EXTENSIONS_CLASS)
   
   sfs.send( new CreateRoomRequest(settings, true, sfs.lastJoinedRoom) )
   
    }   
}



SpellingBee
--> CustomLoginHandler

SpellingBeeGame
--> JoinGameHandler


SpellingBee.jar:

Code: Select all

package com.mycompany.SpellingBee;

import com.smartfoxserver.v2.core.SFSEventType;
import com.smartfoxserver.v2.extensions.SFSExtension;

public class SpellingBee extends SFSExtension {
   
   @Override
   public void init() {
      this.addEventHandler(SFSEventType.USER_LOGIN, LoginEventHandler.class);
      trace(">>> SpellinBee Extension initialized <<<");
   }
}


SpellingBeeGame.jar:

Code: Select all

package com.mycompany.SpellingBee;

import com.smartfoxserver.v2.core.SFSEventType;
import com.smartfoxserver.v2.entities.Room;
import com.smartfoxserver.v2.entities.User;
import com.smartfoxserver.v2.entities.data.ISFSObject;
import com.smartfoxserver.v2.entities.data.SFSObject;
import com.smartfoxserver.v2.extensions.SFSExtension;

public class SpellingBeeGame extends SFSExtension {
   private static int playerCount;
   private volatile boolean gameStarted;
   
   @Override
   public void init() {
      playerCount = 0;
      
      this.addRequestHandler("join", JoinGameHandler.class);
      this.addRequestHandler("math", MathHandler.class);
      this.addRequestHandler("query", QueryHandler.class);
      trace(" .");
      trace(" .");
      trace(">>> SpellinBeeGame Extension initialized <<<");
      trace(" .");
      trace(" .");
   }

   public void increasePlayerCount() {
      playerCount++;
   }
   public void decreasePlayerCount() {
      playerCount--;
   }   
   
    public int getPlayerCount() {
        return playerCount;
    }   

}


JoinGameHandler.jar:

Code: Select all

package com.mycompany.SpellingBee;

import com.smartfoxserver.v2.SmartFoxServer;
import com.smartfoxserver.v2.entities.*;
import com.smartfoxserver.v2.entities.data.ISFSObject;
import com.smartfoxserver.v2.entities.data.SFSObject;
import com.smartfoxserver.v2.extensions.BaseClientRequestHandler;
import com.smartfoxserver.v2.extensions.ISFSExtension;

public class JoinGameHandler extends BaseClientRequestHandler {
   
   @Override
   public void handleClientRequest(User player, ISFSObject params) {
      trace(">>> JoinGameHandler <<<");

   }
}


SpellingBee.zone.xml:

Code: Select all

<zone>
  <name>SpellingBee</name>
  <isCustomLogin>true</isCustomLogin>

  <rooms>
    <room>
      <name>Backstage</name>
      <groupId></groupId>
      <password></password>
      <maxUsers>150</maxUsers>
      <maxSpectators>0</maxSpectators>
      <isDynamic>false</isDynamic>
      <isGame>false</isGame>
      <isHidden>false</isHidden>
      <autoRemoveMode>DEFAULT</autoRemoveMode>
      <permissions>
        <flags>ROOM_NAME_CHANGE,PASSWORD_STATE_CHANGE,PUBLIC_MESSAGES</flags>
        <maxRoomVariablesAllowed>10</maxRoomVariablesAllowed>
      </permissions>
      <events>USER_ENTER_EVENT,USER_EXIT_EVENT,USER_COUNT_CHANGE_EVENT,USER_VARIABLES_UPDATE_EVENT</events>
      <badWordsFilter isActive="true"/>
      <roomVariables/>
     
      <extension>
        <name></name>
        <type>JAVA</type>
        <file></file>
        <propertiesFile></propertiesFile>
        <reloadMode>AUTO</reloadMode>
      </extension>
     
    </room>
  </rooms>

  <extension>
    <name>SpellingBee</name>
    <type>JAVA</type>
    <file>com.mycompany.SpellingBee.SpellingBee</file>
    <propertiesFile></propertiesFile>
    <reloadMode>AUTO</reloadMode>
  </extension>

  <databaseManager active="true">
    <driverName>org.gjt.mm.mysql.Driver</driverName>
    <connectionString>jdbc:mysql://localhost:3306/spellingbee</connectionString>
    <userName>root</userName>
    <password></password>
    <testSql>select count(*) as cnt from user_table</testSql>
    <maxActiveConnections>10</maxActiveConnections>
    <maxIdleConnections>10</maxIdleConnections>
    <exhaustedPoolAction>FAIL</exhaustedPoolAction>
    <blockTime>20</blockTime>
  </databaseManager>
</zone>


As far as I can tell, I followed the SFSTris2X model. What am I missing???
Last edited by Rashomon on 15 Nov 2011, 22:06, edited 1 time in total.
User avatar
Bax
Site Admin
Posts: 4609
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Postby Bax » 15 Nov 2011, 09:01

Can you please show the error you get?
Paolo Bax
The SmartFoxServer Team
Rashomon
Posts: 72
Joined: 11 Aug 2010, 19:48

Postby Rashomon » 15 Nov 2011, 22:09

Sorry. Here are two server logs. The first one created an extension, but it's a server extension. On the second one, I tried to create a room extension, but failed.

PS - I also edited my previous post to use unedited extension & jar names to make sure they were synched up with the logs.

const EXTENSION_ID:String = "SpellingBee"
const EXTENSIONS_CLASS:String = "com.mycompany.SpellingBee.SpellingBeeGame"

Code: Select all

16:54:19,290 INFO  [main] v2.SmartFoxServer     - SmartFoxServer 2X (2.0.0-RC1b) READY!
16:54:45,552 INFO  [SocketReader] core.SocketAcceptor     - Session created: { Id: 1, Type: DEFAULT, Logged: No, IP: 127.0.0.1:52139 } on Server port: 9933 <---> 52139
16:54:45,587 INFO  [com.smartfoxserver.v2.controllers.SystemController-1] controllers.SystemController     - {IN}: Handshake
16:54:45,602 INFO  [com.smartfoxserver.v2.controllers.SystemController-1] controllers.SystemController     - {IN}: Login
16:54:45,608 INFO  [pool-1-thread-2] Extensions     - {SpellingBee}: Trying to query database
16:54:45,612 INFO  [pool-1-thread-2] api.SFSApi     - Login in, { Zone: SpellingBee }, ( User Name: 1, Id: 0, Priv: 0, Sess: 127.0.0.1:52139 )
16:54:45,624 INFO  [com.smartfoxserver.v2.controllers.SystemController-1] controllers.SystemController     - {IN}: JoinRoom
16:55:11,633 INFO  [com.smartfoxserver.v2.controllers.SystemController-1] controllers.SystemController     - {IN}: CreateRoom
16:55:11,643 INFO  [com.smartfoxserver.v2.controllers.SystemController-1] Extensions     - {SpellingBee}:  .
16:55:11,643 INFO  [com.smartfoxserver.v2.controllers.SystemController-1] Extensions     - {SpellingBee}:  .
16:55:11,643 INFO  [com.smartfoxserver.v2.controllers.SystemController-1] Extensions     - {SpellingBee}: >>> SpellinBeeGame Extension initialized <<<
16:55:11,643 INFO  [com.smartfoxserver.v2.controllers.SystemController-1] Extensions     - {SpellingBee}:  .
16:55:11,643 INFO  [com.smartfoxserver.v2.controllers.SystemController-1] Extensions     - {SpellingBee}:  .
16:55:11,644 INFO  [com.smartfoxserver.v2.controllers.SystemController-1] api.SFSApi     - Room created: [ Room: game1, Id: 4, Group: game, isGame: true ]
16:55:11,646 INFO  [com.smartfoxserver.v2.controllers.SystemController-1] system.CreateRoom     - /////////////// Room Dump ////////////////
   Name: game1
   Id: 4
   GroupId: game
   Password:
   Owner: ( User Name: 1, Id: 0, Priv: 0, Sess: 127.0.0.1:52139 )
   isDynamic: true
   isGame: true
   isHidden: false
   size: { u: 1, s: 0 }
   MaxUser: 2
   MaxSpect: 0
   MaxVars: 5
   RemoveMode: DEFAULT
   PlayerIdGen: com.smartfoxserver.v2.util.DefaultPlayerIdGenerator@4bd226a7
   Settings:
      ROOM_NAME_CHANGE: false
      PASSWORD_STATE_CHANGE: false
      PUBLIC_MESSAGES: true
      CAPACITY_CHANGE: false
      USER_ENTER_EVENT: true
      USER_EXIT_EVENT: true
      USER_COUNT_CHANGE_EVENT: true
      USER_VARIABLES_UPDATE_EVENT: true
   Extension:
      Name: SpellingBee
      Class: com.mycompany.SpellingBee.SpellingBeeGame
      Type: JAVA
      Props: config.properties
/////////////// End Dump /////////////////

16:55:11,653 ERROR [com.smartfoxserver.v2.controllers.ExtensionController-1] controllers.ExtensionController     -
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Exception: com.smartfoxserver.v2.exceptions.SFSRuntimeException
Message: Request handler not found: 'join'. Make sure the handler is registered in your extension using addRequestHandler()
Description: Error while handling client request in extension: { Ext: SpellingBee, Type: JAVA, Lev: ZONE, { Zone: SpellingBee }, {} }
Extension Cmd: join
+--- --- ---+
Stack Trace:
+--- --- ---+
com.smartfoxserver.v2.extensions.SFSExtension.handleClientRequest(SFSExtension.java:181)
com.smartfoxserver.v2.controllers.ExtensionController.processRequest(ExtensionController.java:137)
com.smartfoxserver.bitswarm.controllers.AbstractController.run(AbstractController.java:96)
java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
java.lang.Thread.run(Thread.java:637)
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::



const EXTENSION_ID:String = "SpellingBeeGame"
const EXTENSIONS_CLASS:String = "com.mycompany.SpellingBee.SpellingBeeGame"

Code: Select all

16:56:49,896 INFO  [main] v2.SmartFoxServer     - SmartFoxServer 2X (2.0.0-RC1b) READY!
16:57:11,799 INFO  [SocketReader] core.SocketAcceptor     - Session created: { Id: 1, Type: DEFAULT, Logged: No, IP: 127.0.0.1:52144 } on Server port: 9933 <---> 52144
16:57:11,827 INFO  [com.smartfoxserver.v2.controllers.SystemController-1] controllers.SystemController     - {IN}: Handshake
16:57:11,849 INFO  [com.smartfoxserver.v2.controllers.SystemController-1] controllers.SystemController     - {IN}: Login
16:57:11,855 INFO  [pool-1-thread-2] Extensions     - {SpellingBee}: Trying to query database
16:57:11,859 INFO  [pool-1-thread-2] api.SFSApi     - Login in, { Zone: SpellingBee }, ( User Name: 1, Id: 0, Priv: 0, Sess: 127.0.0.1:52144 )
16:57:11,870 INFO  [com.smartfoxserver.v2.controllers.SystemController-1] controllers.SystemController     - {IN}: JoinRoom
16:57:13,987 INFO  [com.smartfoxserver.v2.controllers.SystemController-1] controllers.SystemController     - {IN}: CreateRoom
16:57:13,995 WARN  [com.smartfoxserver.v2.controllers.SystemController-1] managers.SFSRoomManager     -
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Exception: com.smartfoxserver.v2.exceptions.SFSExtensionException
Message: Extension boot error. The provided path is not a directory: extensions/SpellingBeeGame
Description: Failure while creating room extension.
Possible Causes: If the CreateRoom request was sent from client make sure that the extension name matches the name of an existing extension
+--- --- ---+
Stack Trace:
+--- --- ---+
com.smartfoxserver.v2.entities.managers.SFSExtensionManager.createJavaExtension(SFSExtensionManager.java:352)
com.smartfoxserver.v2.entities.managers.SFSExtensionManager.createExtension(SFSExtensionManager.java:266)
com.smartfoxserver.v2.entities.managers.SFSRoomManager.createRoomExtension(SFSRoomManager.java:209)
com.smartfoxserver.v2.entities.managers.SFSRoomManager.createRoom(SFSRoomManager.java:168)
com.smartfoxserver.v2.entities.SFSZone.createRoom(SFSZone.java:230)
com.smartfoxserver.v2.api.SFSApi.createRoom(SFSApi.java:608)
com.smartfoxserver.v2.api.SFSApi.createRoom(SFSApi.java:585)
com.smartfoxserver.v2.controllers.system.CreateRoom.execute(CreateRoom.java:205)
com.smartfoxserver.v2.controllers.SystemController.processRequest(SystemController.java:127)
com.smartfoxserver.bitswarm.controllers.AbstractController.run(AbstractController.java:96)
java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
java.lang.Thread.run(Thread.java:637)
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

16:57:13,995 INFO  [com.smartfoxserver.v2.controllers.SystemController-1] api.SFSApi     - Room created: [ Room: game1, Id: 4, Group: game, isGame: true ]
16:57:13,998 INFO  [com.smartfoxserver.v2.controllers.SystemController-1] system.CreateRoom     - /////////////// Room Dump ////////////////
   Name: game1
   Id: 4
   GroupId: game
   Password:
   Owner: ( User Name: 1, Id: 0, Priv: 0, Sess: 127.0.0.1:52144 )
   isDynamic: true
   isGame: true
   isHidden: false
   size: { u: 1, s: 0 }
   MaxUser: 2
   MaxSpect: 0
   MaxVars: 5
   RemoveMode: DEFAULT
   PlayerIdGen: com.smartfoxserver.v2.util.DefaultPlayerIdGenerator@16debe8
   Settings:
      ROOM_NAME_CHANGE: false
      PASSWORD_STATE_CHANGE: false
      PUBLIC_MESSAGES: true
      CAPACITY_CHANGE: false
      USER_ENTER_EVENT: true
      USER_EXIT_EVENT: true
      USER_COUNT_CHANGE_EVENT: true
      USER_VARIABLES_UPDATE_EVENT: true
/////////////// End Dump /////////////////

16:57:14,004 ERROR [com.smartfoxserver.v2.controllers.ExtensionController-1] controllers.ExtensionController     -
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Exception: com.smartfoxserver.v2.exceptions.SFSRuntimeException
Message: Request handler not found: 'join'. Make sure the handler is registered in your extension using addRequestHandler()
Description: Error while handling client request in extension: { Ext: SpellingBee, Type: JAVA, Lev: ZONE, { Zone: SpellingBee }, {} }
Extension Cmd: join
+--- --- ---+
Stack Trace:
+--- --- ---+
com.smartfoxserver.v2.extensions.SFSExtension.handleClientRequest(SFSExtension.java:181)
com.smartfoxserver.v2.controllers.ExtensionController.processRequest(ExtensionController.java:137)
com.smartfoxserver.bitswarm.controllers.AbstractController.run(AbstractController.java:96)
java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
java.lang.Thread.run(Thread.java:637)
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
User avatar
rjgtav
Posts: 2813
Joined: 19 Apr 2009, 11:31
Location: Lisbon, Portugal

Postby rjgtav » 15 Nov 2011, 23:15

Hi.

By reading the following line:

Message: Extension boot error. The provided path is not a directory: extensions/SpellingBeeGame


It looks like you haven't set up your extension correctly. Are you sure that the extension jar file is inside a folder with that name? I mean, is the extension jar in the folder extensions/SpellingBeeGame?

Remember the name parameter is the folder where the extension is and not the extension name as in SFS1x, as in SFS2x you only have 1 extension per room and 1 per Zone, so extensions no longer need names to be identified.

In case you have the jar inside that folder, did you install SFS2x in the Program Files folder (C:\Program Files on Windows)? If yes, try to install it on a different folder that doesn't need administrator privileges, such as C:\Users\User\Documents\SFS2x.
Skills: SFS Pro, SFS2X, AS2.0/AS3.0, Java, HTML5/CSS3/JS, C#
Portfolio: https://rjgtav.wordpress.com/
SFS Tutorials: http://sfs-tutor.blogspot.com/ - Discontinued. Some examples may be bugged.
Rashomon
Posts: 72
Joined: 11 Aug 2010, 19:48

Postby Rashomon » 16 Nov 2011, 00:09

Thanks, rjgtav!

I have one extension folder:
/SFS2X/extensions/SpellingBee

This folder has one jar file:
SpellingBee.jar

My SpellingBee.jar file contains the following java files:
SpellingBee.java
LoginEventHandler.java
SpellingBeeGame.java
JoinGameHandler.java

did you install SFS2x in the Program Files folder (C:\Program Files on Windows)?


Yes

Remember the name parameter is the folder where the extension is and not the extension name as in SFS1x, as in SFS2x you only have 1 extension per room and 1 per Zone, so extensions no longer need names to be identified.


I'm using SpellingBee.java and LoginEventHandler.java to do a database lookup during login. I made this a server-level extension. (I think.) Since the "name" parameter is the folder where the extension is, and not the name of the extension, can I call SpellingBeeGame.java from the same jar, or do I need to put it in a seperate extension? (I thought I read something in the docs about specifying handlers... but maybe that was just for server/zone extensions.)
Rashomon
Posts: 72
Joined: 11 Aug 2010, 19:48

Postby Rashomon » 16 Nov 2011, 02:12

I tried splitting my code into two extensions:

/extensions/SpellingBee/SpellingBee.jar
Contains:
- SpellingBee.java
- LoginEventHandler.java

/extensions/SpellingBeeGame/SpellingBeeGame.jar
Contains:
- SpellingBeeGame.java
- JoinGameHandler.java

I'm creating the room with this:

Code: Select all

const EXTENSION_ID:String = "SpellingBeeGame"
const EXTENSIONS_CLASS:String = "com.mycompany.SpellingBeeGame.SpellingBeeGame"
.
.
.
var settings:RoomSettings = new RoomSettings(roomName)
settings.groupId = "game"
settings.password = roomPwd
settings.isGame = true
settings.maxUsers = 2
settings.maxSpectators = roomMaxS
settings.extension = new RoomExtension(EXTENSION_ID, EXTENSIONS_CLASS)

sfs.send( new CreateRoomRequest(settings, true, sfs.lastJoinedRoom) )


It looks like SFS is creating an extension, but it's still complaining about the "join" Request Handler.

Code: Select all

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
 >> Zone: SpellingBee
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

20:50:16,937 INFO  [main] managers.SFSZoneManager     - Creating room: (default)
 Backstage
20:50:16,937 INFO  [main] api.SFSApi     - Room created: [ Room: Backstage, Id:
2, Group: default, isGame: false ]
20:50:16,937 INFO  [main] Extensions     - {SpellingBee}: >>> SpellinBee Extensi
on initialized <<<
20:50:16,937 INFO  [main] api.SFSApi     - Room created: [ Room: AdminRoom, Id:
3, Group: default, isGame: false ]
20:50:16,953 INFO  [main] core.AdminToolService     - AdminTool Service started
20:50:17,812 INFO  [main] http.SFSHttpServer     - Http Server started.
20:50:17,859 INFO  [main] v2.SmartFoxServer     - Listening Sockets: { 127.0.0.1
:9933, (Tcp) }
20:50:17,859 INFO  [main] v2.SmartFoxServer     -
 _____ _____ _____    ___ __ __
|   __|   __|   __|  |_  |  |  |
|__   |   __|__   |  |  _|-   -|
|_____|__|  |_____|  |___|__|__|
 _____ _____ _____ ____  __ __
| __  |   __|  _  |    \|  |  |
|    -|   __|     |  |  |_   _|
|__|__|_____|__|__|____/  |_|
[ 2.0.0-RC1b ]

20:50:17,859 INFO  [main] v2.SmartFoxServer     - SmartFoxServer 2X (2.0.0-RC1b)
 READY!
20:50:43,343 INFO  [SocketReader] core.SocketAcceptor     - Session created: { I
d: 1, Type: DEFAULT, Logged: No, IP: 127.0.0.1:1383 } on Server port: 9933 <--->
 1383
20:50:43,359 INFO  [com.smartfoxserver.v2.controllers.SystemController-1] contro
llers.SystemController     - {IN}: Handshake
20:50:43,375 INFO  [com.smartfoxserver.v2.controllers.SystemController-1] contro
llers.SystemController     - {IN}: Login
20:50:43,375 INFO  [pool-1-thread-2] Extensions     - {SpellingBee}: Trying to q
uery database
20:50:43,390 INFO  [pool-1-thread-2] api.SFSApi     - Login in, { Zone: Spelling
Bee }, ( User Name: 1, Id: 0, Priv: 0, Sess: 127.0.0.1:1383 )
20:50:43,390 INFO  [com.smartfoxserver.v2.controllers.SystemController-1] contro
llers.SystemController     - {IN}: JoinRoom
20:50:52,390 INFO  [com.smartfoxserver.v2.controllers.SystemController-1] contro
llers.SystemController     - {IN}: CreateRoom
20:50:52,406 INFO  [com.smartfoxserver.v2.controllers.SystemController-1] Extens
ions     - {SpellingBeeGame}:  .
20:50:52,406 INFO  [com.smartfoxserver.v2.controllers.SystemController-1] Extens
ions     - {SpellingBeeGame}:  .
20:50:52,406 INFO  [com.smartfoxserver.v2.controllers.SystemController-1] Extens
ions     - {SpellingBeeGame}: >>> SpellinBeeGame Extension initialized <<<
20:50:52,406 INFO  [com.smartfoxserver.v2.controllers.SystemController-1] Extens
ions     - {SpellingBeeGame}:  .
20:50:52,406 INFO  [com.smartfoxserver.v2.controllers.SystemController-1] Extens
ions     - {SpellingBeeGame}:  .
20:50:52,406 INFO  [com.smartfoxserver.v2.controllers.SystemController-1] api.SF
SApi     - Room created: [ Room: game1, Id: 4, Group: game, isGame: true ]
20:50:52,406 INFO  [com.smartfoxserver.v2.controllers.SystemController-1] system
.CreateRoom     - /////////////// Room Dump ////////////////
        Name: game1
        Id: 4
        GroupId: game
        Password:
        Owner: ( User Name: 1, Id: 0, Priv: 0, Sess: 127.0.0.1:1383 )
        isDynamic: true
        isGame: true
        isHidden: false
        size: { u: 1, s: 0 }
        MaxUser: 2
        MaxSpect: 0
        MaxVars: 5
        RemoveMode: DEFAULT
        PlayerIdGen: com.smartfoxserver.v2.util.DefaultPlayerIdGenerator@f82c7d
        Settings:
                ROOM_NAME_CHANGE: false
                PASSWORD_STATE_CHANGE: false
                PUBLIC_MESSAGES: true
                CAPACITY_CHANGE: false
                USER_ENTER_EVENT: true
                USER_EXIT_EVENT: true
                USER_COUNT_CHANGE_EVENT: true
                USER_VARIABLES_UPDATE_EVENT: true
        Extension:
                Name: SpellingBeeGame
                Class: com.mycompany.SpellingBeeGame.SpellingBeeGame
                Type: JAVA
                Props: config.properties
/////////////// End Dump /////////////////

20:50:52,406 ERROR [com.smartfoxserver.v2.controllers.ExtensionController-1] con
trollers.ExtensionController     -
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Exception: com.smartfoxserver.v2.exceptions.SFSRuntimeException
Message: Request handler not found: 'join'. Make sure the handler is registered
in your extension using addRequestHandler()
Description: Error while handling client request in extension: { Ext: SpellingBe
e, Type: JAVA, Lev: ZONE, { Zone: SpellingBee }, {} }
Extension Cmd: join
+--- --- ---+
Stack Trace:
+--- --- ---+
com.smartfoxserver.v2.extensions.SFSExtension.handleClientRequest(SFSExtension.j
ava:181)
com.smartfoxserver.v2.controllers.ExtensionController.processRequest(ExtensionCo
ntroller.java:137)
com.smartfoxserver.bitswarm.controllers.AbstractController.run(AbstractControlle
r.java:96)
java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
java.lang.Thread.run(Unknown Source)


I'm trying to add the request handler in my SpellingBeeGame.java file:

Code: Select all

package com.mycompany.SpellingBeeGame;

import com.smartfoxserver.v2.core.SFSEventType;
import com.smartfoxserver.v2.entities.Room;
import com.smartfoxserver.v2.entities.User;
import com.smartfoxserver.v2.entities.data.ISFSObject;
import com.smartfoxserver.v2.entities.data.SFSObject;
import com.smartfoxserver.v2.extensions.SFSExtension;

public class SpellingBeeGame extends SFSExtension {
   
   @Override
   public void init() {
      this.addRequestHandler("join", JoinGameHandler.class);
      
      trace(" .");
      trace(">>> SpellinBeeGame Extension initialized <<<");
      trace(" .");
   }
}


This line stands out at me:
Error while handling client request in extension: { Ext: SpellingBee

It sounds like SFS is trying to attach the SpellingBee extension, rather than the SpellingBeeGame extension.


One thing that's odd is that the server does not restart when I update/export my jar file. Maybe the automatic restart only applies to zone extensions?

Thanks for your help. I've gone back through the docs and rewatched the YouTube tutorial on extensions, but most of what I saw was about zone-level extensions. I'm stumped! :(
User avatar
rjgtav
Posts: 2813
Joined: 19 Apr 2009, 11:31
Location: Lisbon, Portugal

Postby rjgtav » 16 Nov 2011, 07:35

hi.

It looks like you are sending the join extension request to the Zone Extension and not to the Room one.

For sending the request to a room extension, when you are creating the ExtensionRequest, you also have to specify the room where that extension is (3rd parameter).
Skills: SFS Pro, SFS2X, AS2.0/AS3.0, Java, HTML5/CSS3/JS, C#
Portfolio: https://rjgtav.wordpress.com/
SFS Tutorials: http://sfs-tutor.blogspot.com/ - Discontinued. Some examples may be bugged.
Rashomon
Posts: 72
Joined: 11 Aug 2010, 19:48

Postby Rashomon » 17 Nov 2011, 00:37

Hey! That did it!!! :)

I went back and looked at the docs for ExtensionRequest, and you were right. If the third parameter is missing or is null, the extension request goes to the zone extension. I added the following code, and got the desired results:

Code: Select all

function onRoomJoin(evt:SFSEvent):void
{
      var joinedRoom:Room = evt.params.room;
      var sfsObj:SFSObject = new SFSObject();
      sfsObj.putInt("userId", int(myId));
      var myExtReq:ExtensionRequest = new ExtensionRequest("join", sfsObj, joinedRoom);
      sfs.send(myExtReq);
}


I can't thank you enough, man. This was driving me nuts and really holding up my project. Now, I'm off to the races!!!!

THANKS! :)

Return to “SFS2X Questions”

Who is online

Users browsing this forum: No registered users and 46 guests