.Request handler not found
My extesion is this:
Code: Select all
public class ZufallsZahlenExtension extends SFSExtension {
private static final ISFSApi ISFSApi = null;
private Vector<ZufallsZahlenGenerieren> _game = new Vector<ZufallsZahlenGenerieren>();
Map<String,String> invocationTable;
@Override
public void init() {
// TODO Auto-generated method stub
/**REQUEST HANDLER**/
this.addRequestHandler(String.valueOf(Commands.GET_USER_DATA.ordinal()), GetUserData.class);
/** IN GAME REQUSTS**/
this.addRequestHandler(String.valueOf(Commands.GET_DICES.ordinal()), InGameRequest.class);
this.addRequestHandler(String.valueOf(Commands.QUIT_GAME.ordinal()), InGameRequest.class);
this.addRequestHandler(String.valueOf(Commands.GET_MYRAND_NR.ordinal()), MyRand.class);
/** EVENT HANDLER**/
addEventHandler(SFSEventType.USER_JOIN_ROOM, UserJoinedEH.class);
invocationTable();
}
public void invocationTable()
{
/**INVOCATION TABLE**/
invocationTable = new HashMap<String,String>();
invocationTable.put(String.valueOf(Commands.GET_MYRAND_NR.ordinal()), "Myrand");
invocationTable.put(String.valueOf(Commands.GET_DICES.ordinal()), "GetDices");
}
/**PUBLIC REQUEST HANDLER**/
public void handleRequest(String cmd, ISFSObject obj, User user)
{
String handlerClassName = invocationTable.get(cmd);
if(handlerClassName != null)
{
try
{
Class handlerClass = Class.forName(handlerClassName);
IRequestHandler handler = (IRequestHandler) handlerClass.newInstance();
handler.setExtension(this);
handler.onRequest(obj, user);
}
catch(InstantiationException | IllegalAccessException issue)
{
System.out.println("There was a problem with the instantiation of the class " + handlerClassName);
}
catch (ClassNotFoundException issue)
{
// TODO Auto-generated catch block
System.out.println("The class was not found!" + handlerClassName);
}
}
else
{
throw new UnsupportedOperationException("Unknown request id: " + cmd);
}
}
this is my IRequestHandler
Code: Select all
package com.m2p.zuffalszahlen;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
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 interface IRequestHandler {
public void setExtension(SFSExtension ext);
public void onRequest(ISFSObject obj, User user);
}
and this is the my class
Code: Select all
package com.m2p.zuffalszahlen;
import java.util.ArrayList;
import java.util.List;
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 GetDices implements IRequestHandler{
SFSExtension sfs;
@Override
public void setExtension(SFSExtension ext) {
// TODO Auto-generated method stub
sfs = ext;
}
@Override
public void onRequest(ISFSObject obj, User user) {
// TODO Auto-generated method stub
final List<Integer> myRandInt = new ArrayList<Integer>();
final int[] myIntegers = {0,64,128,192,256,320,384,448,512,576,640,704,768,832,896,960,1024,1088,1152,1216};
final List<Integer> myNumbers = new ArrayList<Integer>();
for (int i = 0; i < myIntegers.length; i++)
{
myNumbers.add(myIntegers[i]);
}
ISFSObject nr = new SFSObject();
nr.putIntArray("myNumbers", myNumbers);
sfs.send(String.valueOf(Commands.GET_DICES.ordinal()), nr, user);
}
}
I have a class where I put my commands like this:
Code: Select all
package com.m2p.zuffalszahlen;
enum Commands
{
UNKNOWN,
GET_USER_DATA,
GET_DICES,
GET_MYRAND_NR,
//INGAME MESSAGES
RUNDOM_NUMBER,
QUIT_GAME,
}
Can you please help me?
Thank you in advance for your help!