use of battleship.packets.GameOfferPacket in project Spark by igniterealtime.
the class ChatRoomOpeningListener method chatRoomOpened.
@Override
public void chatRoomOpened(final ChatRoom room) {
if (// Check for 1on1 Chat
!(room instanceof ChatRoomImpl)) {
return;
}
final ChatRoomButton sendGameButton = new ChatRoomButton("BS");
room.getToolBar().addChatRoomButton(sendGameButton);
final String opponentJID = ((ChatRoomImpl) room).getJID();
sendGameButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
final GameOfferPacket offer = new GameOfferPacket();
offer.setTo(opponentJID);
offer.setType(IQ.Type.get);
room.getTranscriptWindow().insertCustomText(BsRes.getString("request"), false, false, Color.BLUE);
try {
SparkManager.getConnection().sendStanza(offer);
} catch (SmackException.NotConnectedException e1) {
Log.warning("Unable to send offer to " + opponentJID, e1);
}
SparkManager.getConnection().addAsyncStanzaListener(new StanzaListener() {
@Override
public void processPacket(Stanza stanza) {
GameOfferPacket answer = (GameOfferPacket) stanza;
answer.setStartingPlayer(offer.isStartingPlayer());
answer.setGameID(offer.getGameID());
String name = XmppStringUtils.parseLocalpart(opponentJID);
if (answer.getType() == IQ.Type.result) {
// ACCEPT
room.getTranscriptWindow().insertCustomText(BsRes.getString("accepted", name), false, false, Color.BLUE);
createWindow(answer, opponentJID);
} else {
// DECLINE
room.getTranscriptWindow().insertCustomText(BsRes.getString("declined", name), false, false, Color.RED);
}
}
}, new PacketIDFilter(offer.getPacketID()));
}
});
}
use of battleship.packets.GameOfferPacket in project Spark by igniterealtime.
the class BattleshipPlugin method initialize.
@Override
public void initialize() {
ProviderManager.addIQProvider(GameOfferPacket.ELEMENT_NAME, GameOfferPacket.NAMESPACE, GameOfferPacket.class);
ProviderManager.addExtensionProvider(MovePacket.ELEMENT_NAME, MovePacket.NAMESPACE, MovePacket.class);
ProviderManager.addExtensionProvider(MoveAnswerPacket.ELEMENT_NAME, MoveAnswerPacket.NAMESPACE, MoveAnswerPacket.class);
_gameofferListener = new StanzaListener() {
@Override
public void processPacket(Stanza stanza) {
GameOfferPacket invitation = (GameOfferPacket) stanza;
if (invitation.getType() == IQ.Type.get) {
showInvitationInChat(invitation);
}
}
};
SparkManager.getConnection().addAsyncStanzaListener(_gameofferListener, new StanzaTypeFilter(GameOfferPacket.class));
_chatRoomListener = new ChatRoomOpeningListener();
SparkManager.getChatManager().addChatRoomListener(_chatRoomListener);
}
Aggregations