NullReference session

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

Moderators: Lapo, Bax

Ardito
Posts: 128
Joined: 12 Sep 2016, 11:26
Location: Italy

NullReference session

Postby Ardito » 07 Oct 2019, 14:02

Hi,

In my project, when a user loggin, I set all the user variables inside a Session variable, so that they are accessible from any part of the Server code:

Code: Select all

session.setProperty ("user_var", userVar);


While the user plays in a 1 vs 1 game, if he accidentally disconnects, or loses the connection, the server shows the error NullReference on this variable.
Does anyone know how to solve this problem?
User avatar
Lapo
Site Admin
Posts: 23009
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: NullReference session

Postby Lapo » 07 Oct 2019, 14:30

Hi,
can you show me the server code that causes the issue and the stack trace of the error?

Thanks
Lapo
--
gotoAndPlay()
...addicted to flash games
Ardito
Posts: 128
Joined: 12 Sep 2016, 11:26
Location: Italy

Re: NullReference session

Postby Ardito » 07 Oct 2019, 16:36

Of course

My code:

Code: Select all

package loginserver;

import com.smartfoxserver.v2.entities.User;
import com.smartfoxserver.v2.entities.data.ISFSObject;
import com.smartfoxserver.v2.entities.data.SFSArray;
import com.smartfoxserver.v2.entities.data.SFSObject;
import com.smartfoxserver.v2.extensions.BaseClientRequestHandler;

import gamedata.GameData;
import gamedata.MatchUser;
import loginserver.MatchExtension.GAME_STATE;

public class PlayerAnswer extends BaseClientRequestHandler {

   @Override
   public void handleClientRequest(User user, ISFSObject params) {
      MatchExtension gameRoom = (MatchExtension)getParentExtension();

      if(gameRoom.gameStatus == GAME_STATE.GAME_END || gameRoom.currentPlayer.user != user || gameRoom.waitForPlayerAnswer == false)         
         return;
   
      gameRoom.waitForPlayerAnswer = false;      
      short featureID = params.getShort("ft");      
      MatchUser opponent = gameRoom.getOpponent(gameRoom.currentPlayer.id);
      boolean answerTrue = opponent.gameData.sel_card.currentFeatures.contains((short) featureID);
      opponent.gameData.deleteAllTokens();
      
      if(GameData.isDebug) Debug.Log("Player : " + gameRoom.currentPlayer.name + " answer has " + featureID + " IS " + answerTrue);

      SFSArray delCards = new SFSArray();
      short type_feature = (short)GameData.features[featureID].type;
      
      for(byte i = 0; i < opponent.gameData.slots.length; i++) {
         if(opponent.gameData.slots[i] == null) continue;
         
         if(opponent.gameData.slots[i].typeFeatureImmune.contains(type_feature))
            continue;
         
         if(answerTrue ^ opponent.gameData.slots[i].hasFeature((short) featureID)) {            
            SFSObject object = new SFSObject();
            object.putByte("sl", (byte)i);
            object.putShort("id", (short)opponent.gameData.slots[i].id);
            //System.out.println("Card " + (short)opponent.gameData.slots[i].id + " SL " + i);
            opponent.gameData.deleteCardFromSlot(i);
            delCards.addSFSObject(object);
         }         
      }
      
      //Pool Features
      if(answerTrue)
      {
         //Per le carte nel campo di battaglia
         for(byte i = 0; i < opponent.gameData.slots.length; i++) {
            if(opponent.gameData.slots[i] == null) continue;
         
            opponent.gameData.slots[i].setFeaturePool(featureID);
         }
         
         for(byte i = 0; i < opponent.gameData.deck.size(); i++) {         
            opponent.gameData.deck.get(i).setFeaturePool(featureID);
         }
      }
      
      SFSObject output = new SFSObject();
      output.putInt("player_id", gameRoom.currentPlayer.id);
      output.putBool("answer_istrue", answerTrue);
      //System.out.println(delCards.getDump());
      output.putSFSArray("del_cards", delCards);
      output.putShort("feature", featureID);
      send("server_answer", output, gameRoom.room.getUserList());
      
      gameRoom.turnJumpedCnt = 0;   
      gameRoom.updatePlayer(opponent, true, 5);

   }

}

Error:

Code: Select all

18:39:39,971 WARN  [SFSWorker:Ext:2] v290.ExtensionReqController     - com.smartfoxserver.v2.exceptions.SFSExtensionException: No extensions can be invoked: { Zone: Login }, RoomId: 4
        com.smartfoxserver.v2.controllers.v290.ExtensionReqController.processRequest(ExtensionReqController.java:157)
        com.smartfoxserver.v2.controllers.v290.ExtensionReqController$1.run(ExtensionReqController.java:68)
        java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
        java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
        java.lang.Thread.run(Unknown Source)
User avatar
Lapo
Site Admin
Posts: 23009
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: NullReference session

Postby Lapo » 08 Oct 2019, 08:54

The exception you have posted is not about a NullPointer and it's not related with User Variables.
It is telling you that a client invoked an Extension on a Room with id=4 and there are no Extension attached to it.

Cheers
Lapo

--

gotoAndPlay()

...addicted to flash games
Ardito
Posts: 128
Joined: 12 Sep 2016, 11:26
Location: Italy

Re: NullReference session

Postby Ardito » 08 Oct 2019, 10:37

This happens when a user logs out, but before it disconnects everything works.

What could be the problem?
User avatar
Lapo
Site Admin
Posts: 23009
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: NullReference session

Postby Lapo » 08 Oct 2019, 14:30

One thing is logging out and another is disconnecting. Which one is it?

Also I don't understand how a user who has just disconnected could cause the exception you've reported.
Can this problem be replicated? If so can you explain the steps to reproduce it?

Thanks
Lapo

--

gotoAndPlay()

...addicted to flash games
Ardito
Posts: 128
Joined: 12 Sep 2016, 11:26
Location: Italy

Re: NullReference session

Postby Ardito » 09 Oct 2019, 11:45

Lapo wrote:One thing is logging out and another is disconnecting. Which one is it?
disconnecting

Yes this problem can be replicated.

I found the error to come from this script:

Code: Select all

public class PlayerSelectSlot extends BaseClientRequestHandler {

   @Override
   public void handleClientRequest(User user, ISFSObject params) {
      MatchExtension gameRoom = (MatchExtension)getParentExtension(); //gameRoom is null
      PlayerCardset cardset = (PlayerCardset)user.getProperty("user_var");
      
      byte slotID = params.getByte("slot");
      if(slotID < 0 || slotID > 4) return;
      
      SFSObject output = new SFSObject();
      output.putByte("slot", slotID);
      send("sel_slot", output, gameRoom.getOpponent(cardset.id_user).user);
   }
}
User avatar
Lapo
Site Admin
Posts: 23009
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: NullReference session

Postby Lapo » 09 Oct 2019, 15:54

I found the error to come from this script:

I don't think so. The stack trace doesn't reference your Extension.

Yes this problem can be replicated.

If you can replicate it every time you can double check that the Room with ID provided in the error is actually running an Extension.
You can use the AdminTool > ZoneMonitor to verify it.

Cheers
Lapo

--

gotoAndPlay()

...addicted to flash games
Ardito
Posts: 128
Joined: 12 Sep 2016, 11:26
Location: Italy

Re: NullReference session

Postby Ardito » 09 Oct 2019, 17:42

You are right. The room is destroyed when a user is disconnected

Thank's for help me :D

Return to “SFS2X Questions”

Who is online

Users browsing this forum: No registered users and 48 guests