没有太多文档,但这里是关于编写服务器端扩展的部分:
http://docs2x.smartfoxserver.com/AdvancedTopics/server-side-extensions
以下是功能列表:
http://docs2x.smartfoxserver.com/Overview/sfs2x-features
没有提及推或队列。
有使用smartfox服务器的宾果游戏,他们必须使用它来调用球。
可以使用SFS2x完成吗?它是否支持推送通知和理想情况下要推送到一组客户端的项目队列?如果是这样,是否有人有任何源代码或示例?
SFS论坛遗憾地关闭,不公开发布。
答案 0 :(得分:0)
我在sfs2x开发了一个宾果游戏。我只能给你一个指南,所以我希望它有所帮助。如果我理解了这个问题,您希望在没有请求或事件触发命令的情况下发送命令。
创建命令类: 包路径是相对于你的src文件夹。
package com.rcras.bingo1;
public class Commands
{
/** User buys bingo cards */
public static final String CMD_BUY_CARDS = "bc";
/** Server sends Bingo */
public static final String CMD_BINGO = "bo";
/** User Calls Bingo */
public static final String CMD_CALL_BINGO = "bingo";
/** Get the time left till next game */
public static final String CMD_GET_TIMER = "get_timer";
/** No bingos left --- Game Over */
public static final String CMD_GAME_OVER= "gaov";
/** Ready to start a game */
public static final String CMD_READY = "ready";
/** Bingo Draw */
public static final String CMD_DRAW = "draw";
/** tell the client app the game is starting */
public static final String CMD_START = "start";
}
我没有包含我使用的所有命令。无需设置事件或请求处理程序,因为该命令是从服务器端计时器事件发送的。
你必须写一个'bingogame'类并从你的扩展中调用该类。我的目标是拥有一些同时运营游戏的房间。我使用ConcurrentHashMap跟踪游戏:
import java.util.concurrent.ConcurrentHashMap;
import com.rcras.bingo1.Commands;
public class Bingo1 extends SFSExtension {
List<User> DiamondRoomPlayers;
Timer timer;
private static int min =2;
private static int sec = 60;
/** Current games */
private ConcurrentHashMap<Integer,BingoGame> games = null;
public ConcurrentHashMap<Integer, BingoGame> getGames() {
return games;
}
public void startDiamondGame()
{
Zone thisZone = this.getParentZone();
Room room2 = thisZone.getRoomByName("Diamond");
BingoGame bingoGame = this.getGames().get(room2.getId());
if(bingoGame == null || (bingoGame != null && bingoGame.isStarted() == false))
{
DiamondRoomPlayers=room2.getUserList();
ISFSObject DiamondObj = new SFSObject();
send(Commands.CMD_START, DiamondObj, DiamondRoomPlayers);
BingoGame DiamondRoomGame = new BingoGame(this, room2);
getGames().put(room2.getId(),DiamondRoomGame);
DiamondRoomGame.setId(room2.getId()) ;
DiamondRoomGame.init();
}
}
BingoGame类有一个触发绘图的计时器
public class BingoGame {
public BingoGame(Bingo1 ext, Room room)
{
Draw= new int[75];
setPlayers(room.getUserList());
//players = room.getUserList();
thisRoom = room;
this.extension=ext;
//setters
this.setFirstBingo(true);
this.setStarted(false);
this.setSecondBingo(true);
this.setFirstPrize(1000);
this.setSecondPrize(500);
}
public void init()
{
if(players.size() > 0)
{
StartBingoGame();
}
else
{
System.out.println("NOT ENOUGH PLAYER IN THE" + thisRoom.getName() + " Room!" );
}
}
private void StartBingoGame()
{
timer = new Timer();
timer.schedule(new BingoDrawTask(),
0, //initial delay
1*3000); //draw a number every 3 seconds
setStarted(true); //setter for started variable
}
class BingoDrawTask extends TimerTask {
private int BingoNum;
private boolean isThere = true;
@Override
public void run() {
isThere = true;
Random BingoCall = new Random();
while( isThere == true)
{
BingoNum = BingoCall.nextInt(75) + 1;
System.out.println("Bingo Draw:" + BingoNum);
isThere = CheckDrawArray(BingoNum);
}
Draw[NunbersCalled]=BingoNum;
NunbersCalled = NunbersCalled + 1;
System.out.println(thisRoom.getName() + " Room: Draw Number: " + NunbersCalled);
//this should never happen but it's there for testing
if (NunbersCalled == 75)
{
System.out.println("STOP!!!" );
StopBingoGame();
}
// Empty obj
ISFSObject numObj = new SFSObject();
numObj.putInt("cn", NunbersCalled);
numObj.putInt("dn", BingoNum);
numObj.putUtfString("rn", thisRoom.getName());
/*This command 'pushes' the command to a player list named players
extension.send(Commands.CMD_DRAW, numObj, players);
System.out.println("Send ----" + BingoNum);
}
在客户端
添加事件监听器
sfs.addEventListener(SFSEvent.EXTENSION_RESPONSE, onExtensionResponse);
添加处理程序
private function onExtensionResponse(evt:SFSEvent):void
{
var obj:SFSObject = evt.params.params as SFSObject;
if(evt.params.cmd == "draw")
{
//Handle draw - mostly handled by BingoCard class
}
}
我试图保持这个简短但没有发生。我希望我已经给你足够的代码来告诉你我是如何实现推动的?在我的'BINGO GAME'中。
答案 1 :(得分:0)
尝试我们的推送连接游戏功能HTML5 sample game walkthrough
希望得到这个帮助。