22 package com.realtime.crossfire.jxclient.server.crossfire;
27 import java.nio.ByteBuffer;
28 import java.nio.charset.Charset;
29 import java.util.Iterator;
30 import org.jetbrains.annotations.NotNull;
44 protected static final Charset
UTF8 = Charset.forName(
"UTF-8");
160 drawinfoListeners.
add(listener);
168 drawinfoListeners.
remove(listener);
176 drawextinfoListeners.
add(listener);
184 drawextinfoListeners.
remove(listener);
192 queryListeners.
add(listener);
200 queryListeners.
remove(listener);
208 magicmapListeners.
add(listener);
216 magicmapListeners.
remove(listener);
224 crossfireUpdateItemListeners.
add(crossfireUpdateItemListener);
232 crossfireUpdateItemListeners.
remove(crossfireUpdateItemListener);
240 crossfireTickListeners.
add(listener);
248 crossfireSoundListeners.
add(listener);
256 crossfireMusicListeners.
add(listener);
264 crossfireComcListeners.
add(listener);
272 receivedPacketListeners.
add(listener);
280 crossfireAccountListeners.
add(listener);
288 crossfireAccountListeners.
remove(listener);
296 receivedPacketListeners.
remove(listener);
304 sentReplyListeners.
add(listener);
312 sentReplyListeners.
remove(listener);
320 crossfirePickupListeners.
add(listener);
328 crossfirePickupListeners.
remove(listener);
336 crossfireFailureListeners.
add(listener);
344 crossfireFailureListeners.
remove(listener);
349 crossfireAccountListener.manageAccount();
355 crossfireAccountListener.startAccountList(accountName);
361 crossfireAccountListener.addAccount(characterInformation);
367 crossfireAccountListener.endAccountList(count);
373 crossfireAccountListener.startPlaying();
379 listener.commandComcReceived(packetNo, time);
386 crossfireUpdateItemListener.delinvReceived(tag);
393 crossfireUpdateItemListener.delitemReceived(tags);
397 protected void fireFaceReceived(
final int faceNum,
final int faceSetNum,
final int faceChecksum, @NotNull
final String faceName) {
401 protected void fireFailure(@NotNull
final String command, @NotNull
final String arguments) {
403 crossfireFailureListener.failure(command, arguments);
413 crossfireFailureListener.clearFailure();
417 protected void fireAddItemReceived(
final int location,
final int tag,
final int flags,
final int weight,
final int faceNum,
final String name,
final String namePl,
final int anim,
final int animSpeed,
final int nrof,
final int type) {
418 model.
getItemsManager().
addItemReceived(location, tag, flags, weight, faceNum, name, namePl, anim, animSpeed, nrof, type);
420 crossfireUpdateItemListener.addItemReceived(location, tag, flags, weight, faceNum, name, namePl, anim, animSpeed, nrof, type);
426 listener.commandMagicmapReceived();
432 listener.commandMusicReceived(music);
438 crossfirePickupListener.pickupChanged(pickupOptions);
442 protected void firePlayerReceived(
final int tag,
final int weight,
final int faceNum, @NotNull
final String name) {
445 crossfireUpdateItemListener.playerReceived(tag, weight, faceNum, name);
451 listener.commandQueryReceived(prompt, queryType);
457 listener.commandSoundReceived(x, y, num, type);
461 protected void fireCommandSound2Received(
final int x,
final int y,
final int dir,
final int volume,
final int type, @NotNull
final String action, @NotNull
final String name) {
463 listener.commandSound2Received(x, y, dir, volume, type, action, name);
469 listener.tick(tickNo);
473 protected void fireUpditemReceived(
final int flags,
final int tag,
final int valLocation,
final int valFlags,
final int valWeight,
final int valFaceNum, @NotNull
final String valName, @NotNull
final String valNamePl,
final int valAnim,
final int valAnimSpeed,
final int valNrof) {
474 model.
getItemsManager().
upditemReceived(flags, tag, valLocation, valFlags, valWeight, valFaceNum, valName, valNamePl, valAnim, valAnimSpeed, valNrof);
476 crossfireUpdateItemListener.upditemReceived(flags, tag, valLocation, valFlags, valWeight, valFaceNum, valName, valNamePl, valAnim, valAnimSpeed, valNrof);
484 public void drawInfo(@NotNull
final String message,
final int color) {
486 listener.commandDrawinfoReceived(message, color);
494 public void drawextinfo(
final int color,
final int type,
final int subtype,
final String message) {
496 listener.commandDrawextinfoReceived(color, type, subtype, message);
506 listener.setDebugMode(printMessageTypes);
512 sentReplyListener.replySent();
523 receivedPacketListener.processEmpty(command);
535 final Iterator<ReceivedPacketListener> listeners = receivedPacketListeners.
iterator();
536 if (listeners.hasNext()) {
538 if (packet.hasRemaining()) {
539 while (listeners.hasNext()) {
541 packet.position(args);
558 final Iterator<ReceivedPacketListener> listeners = receivedPacketListeners.
iterator();
559 if (listeners.hasNext()) {
561 if (packet.hasRemaining()) {
562 while (listeners.hasNext()) {
564 packet.position(args);
581 final Iterator<ReceivedPacketListener> listeners = receivedPacketListeners.
iterator();
582 if (listeners.hasNext()) {
584 if (packet.hasRemaining()) {
585 while (listeners.hasNext()) {
587 packet.position(args);
604 final Iterator<ReceivedPacketListener> listeners = receivedPacketListeners.
iterator();
605 if (listeners.hasNext()) {
607 if (packet.hasRemaining()) {
608 while (listeners.hasNext()) {
610 packet.position(args);
627 final Iterator<ReceivedPacketListener> listeners = receivedPacketListeners.
iterator();
628 if (listeners.hasNext()) {
630 if (packet.hasRemaining()) {
631 while (listeners.hasNext()) {
633 packet.position(args);
651 receivedPacketListener.processStats(
"stats", stat, args);
663 final Iterator<ReceivedPacketListener> listeners = receivedPacketListeners.
iterator();
664 if (listeners.hasNext()) {
666 if (packet.hasRemaining()) {
667 while (listeners.hasNext()) {
669 packet.position(args);
685 for (cmdLen = 0; cmdLen < packet.limit(); cmdLen++) {
686 final byte ch = packet.get(cmdLen);
687 if ((ch&0xFF) <= 0x20 || (ch&0xFF) >= 0x80) {
701 protected static String
newString(
final ByteBuffer byteBuffer,
final int start,
final int len) {
702 final byte[] tmp =
new byte[len];
703 for (
int i = 0; i < len; i++) {
704 tmp[i] = byteBuffer.get(start+i);
706 return new String(tmp, UTF8);
709 protected void fireSelectCharacter(@NotNull
final String accountName, @NotNull
final String characterName) {
714 crossfireAccountListener.selectCharacter(accountName, characterName);
final EventListenerList2< CrossfireDrawextinfoListener > drawextinfoListeners
The CrossfireDrawextinfoListeners to be notified.
void addCrossfireMagicmapListener(@NotNull final CrossfireMagicmapListener listener)
Adds a listener from the list of objects listening to magicmap messages.the listener to add ...
void processIntArray(@NotNull String command, @NotNull ByteBuffer packet)
A packet having an array of int parameters has been received.
void fireUpditemReceived(final int flags, final int tag, final int valLocation, final int valFlags, final int valWeight, final int valFaceNum, @NotNull final String valName, @NotNull final String valNamePl, final int valAnim, final int valAnimSpeed, final int valNrof)
Abstract base class for CrossfireServerConnection implementing classes.
void removeCrossfireDrawextinfoListener(@NotNull final CrossfireDrawextinfoListener listener)
Removes the given listener from the list of objects listening to the drawextinfo S->C messages...
void addCrossfireSoundListener(@NotNull final CrossfireSoundListener listener)
Adds a listener to be notified about received sound commands.the listener to add
void processShortArray(@NotNull String command, @NotNull ByteBuffer packet)
A packet having an array of short integer parameters has been received.
void addCrossfireTickListener(@NotNull final CrossfireTickListener listener)
Adds a listener to be notified about tick changes.the listener to add
final EventListenerList2< CrossfireSoundListener > crossfireSoundListeners
The CrossfireSoundListeners to be notified.
void addCrossfireComcListener(@NotNull final CrossfireComcListener listener)
Adds a listener to be notified about received comc commands.the listener to add
final EventListenerList2< ReceivedPacketListener > receivedPacketListeners
The ReceivedPacketListeners to be notified.
void addCrossfireFailureListener(@NotNull final CrossfireFailureListener listener)
Adds a listener to be notified of failure messages.the listener to add
void addPacketWatcherListener(@NotNull final ReceivedPacketListener listener)
Adds a listener to be notified about received packets.the listener to add
void removeCrossfireDrawinfoListener(@NotNull final CrossfireDrawinfoListener listener)
Removes the given listener from the list of objects listening to the drawinfo S->C messages...
A list of event listeners.
void removeCrossfireAccountListener(@NotNull final CrossfireAccountListener listener)
Removes a listener to be notified about account events.the listener to remove
static final Charset UTF8
The Charset used for parsing or encoding strings received from or sent to the Crossfire server...
final EventListenerList2< CrossfireMusicListener > crossfireMusicListeners
The CrossfireMusicListeners to be notified.
Interface for listeners interested in drawinfo messages received from the Crossfire server...
ItemsManager getItemsManager()
void firePickupChanged(final int pickupOptions)
void notifyPacketWatcherListenersShortInt(@NotNull final ByteBuffer packet, final int args)
Notifies all ReceivedPacketListeners about a packet having a short and an in value as parameters...
void selectCharacter()
An character name was sent to the server.
void addCrossfireDrawinfoListener(@NotNull final CrossfireDrawinfoListener listener)
Adds a new listener monitoring the drawinfo S->C messages.the listener to remove
void drawextinfo(final int color, final int type, final int subtype, final String message)
Pretends that a drawextinfo message has been received.the message type the message subtype the messag...
void upditemReceived(final int flags, final int tag, final int valLocation, final int valFlags, final int valWeight, final int valFaceNum, @NotNull final String valName, @NotNull final String valNamePl, final int valAnim, final int valAnimSpeed, final int valNrof)
An "upditem" command has been received.
Interface for listeners interested in "sound" commands.
void fireDelitemReceived(@NotNull final int[] tags)
void clearFailure()
Inform the various failure listeners that they can clean the last displayed failure.
void start()
Starts operation.
Interface for listeners interested in "tick" commands.
void notifyPacketWatcherListenersMixed(@NotNull final ByteBuffer packet, final int args)
Notifies all ReceivedPacketListeners about a packet having mixed parameters.
final EventListenerList2< CrossfireMagicmapListener > magicmapListeners
The CrossfireMagicmapListeners to be notified of received magicmap commands.
void processMixed(@NotNull String command, @NotNull ByteBuffer packet)
A packet having mixed parameters has been received.
void addFace(@NotNull final Face face)
Adds a new face to the cache.
final EventListenerList2< CrossfireTickListener > crossfireTickListeners
The CrossfireTickListeners to be notified.
KnowledgeManager getKnowledgeManager()
void addCrossfirePickupListener(@NotNull final CrossfirePickupListener listener)
Adds a listener to be notified about received "pickup" messages.the listener to add ...
void delitemReceived(@NotNull final int[] tags)
A "delitem" command has been received.
void addCrossfireDrawextinfoListener(@NotNull final CrossfireDrawextinfoListener listener)
Adds a new listener monitoring the drawextinfo S->C messages.the listener to remove ...
void processShortInt(@NotNull String command, @NotNull ByteBuffer packet)
A packet having a short and an int parameter has been received.
final EventListenerList2< CrossfireFailureListener > crossfireFailureListeners
The CrossfireFailureListeners to be notified.
void removePacketWatcherListener(@NotNull final ReceivedPacketListener listener)
Removes a listener to be notified about received packets.the listener to add
void processAscii(@NotNull String command, @NotNull ByteBuffer packet)
A packet having ascii parameters has been received.
Listener for classes interested in sent "reply" commands.
final EventListenerList2< CrossfireAccountListener > crossfireAccountListeners
The CrossfireAccountListeners to be notified.
void addSentReplyListener(@NotNull final SentReplyListener listener)
Adds a listener to be notified about sent reply packets.the listener to add
static String extractCommand(@NotNull final ByteBuffer packet)
Returns the command string for a received packet.
Combines all model classes that are updated.
final EventListenerList2< CrossfireQueryListener > queryListeners
The CrossfireQueryListeners to be notified.
final Model model
The Model instance that is updated.
final EventListenerList2< CrossfireDrawinfoListener > drawinfoListeners
The CrossfireDrawinfoListeners to be notified.
void fireCommandQueryReceived(@NotNull final String prompt, final int queryType)
void notifyPacketWatcherListenersShortArray(@NotNull final ByteBuffer packet, final int args)
Notifies all ReceivedPacketListeners about a packet having an array of short values as parameters...
Interface for listeners interested in "music" commands.
Interface for listeners interested in the "failure" messages received from the Crossfire server...
final EventListenerList2< CrossfireUpdateItemListener > crossfireUpdateItemListeners
The CrossfireUpdateItemListeners to be notified.
Interface for listeners interested in "pickup" messages.
void selectCharacter()
A character name was sent to the server.
void notifyPacketWatcherListenersNoData(@NotNull final ByteBuffer packet, final int args)
Notifies all ReceivedPacketListeners about a packet having unknown parameters.
void removeCrossfirePickupListener(@NotNull final CrossfirePickupListener listener)
Removes a listener to be notified about received "pickup" messages.the listener to remove ...
final EventListenerList2< SentReplyListener > sentReplyListeners
The SentReplyListeners to be notified.
void fireCommandSoundReceived(final int x, final int y, final int num, final int type)
void removeCrossfireUpdateItemListener(@NotNull final CrossfireUpdateItemListener crossfireUpdateItemListener)
Removes a listener to be notified about item changes.the listener to remove
Interface for listeners interested in received packets.
void add(@NotNull final T listener)
Adds a listener.
void fireCommandComcReceived(final int packetNo, final int time)
Interface for listeners interested in magicmap messages received from the Crossfire server...
void fireCommandSound2Received(final int x, final int y, final int dir, final int volume, final int type, @NotNull final String action, @NotNull final String name)
void fireStartAccountList(@NotNull final String accountName)
void notifyPacketWatcherListenersEmpty(@NotNull final String command)
Notifies all ReceivedPacketListeners about an empty packet.
void fireMusicReceived(@NotNull final String music)
void addCrossfireAccountListener(@NotNull final CrossfireAccountListener listener)
Adds a listener to be notified about account events.the listener to add
void fireTick(final int tickNo)
Interface for listeners interested in account information related messages received from the Crossfir...
void fireFaceReceived(final int faceNum, final int faceSetNum, final int faceChecksum, @NotNull final String faceName)
void notifyPacketWatcherListenersIntArray(@NotNull final ByteBuffer packet, final int args)
Notifies all ReceivedPacketListeners about a packet having an array of int values as parameters...
void fireFailure(@NotNull final String command, @NotNull final String arguments)
AbstractCrossfireServerConnection(@NotNull final Model model)
Creates a new instance.
void removeSentReplyListener(@NotNull final SentReplyListener listener)
Removes a listener to be notified about sent reply packets.the listener to add
Interface for listeners interested in drawextinfo messages received from the Crossfire server...
void removeCrossfireQueryListener(@NotNull final CrossfireQueryListener listener)
Removes the given listener from the list of objects listening to the query S->C messages.the listener to remove
void addCrossfireQueryListener(@NotNull final CrossfireQueryListener listener)
Adds a new listener monitoring the query S->C messages.the listener to remove
void fireAddItemReceived(final int location, final int tag, final int flags, final int weight, final int faceNum, final String name, final String namePl, final int anim, final int animSpeed, final int nrof, final int type)
void firePlayerReceived(final int tag, final int weight, final int faceNum, @NotNull final String name)
static String newString(final ByteBuffer byteBuffer, final int start, final int len)
Extracts a string from a ByteBuffer range.
void fireSelectCharacter(@NotNull final String accountName, @NotNull final String characterName)
void addItemReceived(final int location, final int tag, final int flags, final int weight, final int faceNum, @NotNull final String name, @NotNull final String namePl, final int anim, final int animSpeed, final int nrof, final int type)
An "additem" has been received.
void addCrossfireMusicListener(@NotNull final CrossfireMusicListener listener)
Adds a listener to be notified about received music commands.the listener to add
Adds encoding/decoding of crossfire protocol packets to a ServerConnection.
void notifyPacketWatcherListenersStats(final int stat, @NotNull final Object... args)
Notifies all ReceivedPacketListeners about a packet having stat parameters.
Interface for listeners interested in comc commands received from the server.
SpellsManager getSpellsManager()
void notifyPacketWatcherListenersAscii(@NotNull final ByteBuffer packet, final int args)
Notifies all ReceivedPacketListeners about a packet having ascii parameters.
void delinvReceived(final int tag)
A "delinv" command has been received.
void drawInfoSetDebugMode(final boolean printMessageTypes)
Enables or disables printing of message types.whether to enable or disable message types ...
void playerReceived(final int tag, final int weight, final int faceNum, @NotNull final String name)
A "player" command has been received.
Interface for listeners interested in query messages received from the Crossfire server.
final EventListenerList2< CrossfireComcListener > crossfireComcListeners
The CrossfireComcListeners to be notified.
void selectCharacter()
A character name was sent to the server.
void processNoData(@NotNull String command, @NotNull ByteBuffer packet)
A packet having unknown parameters has been received.
void fireDelinvReceived(final int tag)
void remove(@NotNull final T listener)
Removes a listener.
void removeCrossfireFailureListener(@NotNull final CrossfireFailureListener listener)
Removes a listener to be notified of failure messages.the listener to remove
void removeCrossfireMagicmapListener(@NotNull final CrossfireMagicmapListener listener)
Removes a listener from the list of objects listening to magicmap messages.the listener to remove ...
QuestsManager getQuestsManager()
void fireAddAccount(@NotNull final CharacterInformation characterInformation)
void addCrossfireUpdateItemListener(@NotNull final CrossfireUpdateItemListener crossfireUpdateItemListener)
Adds a listener to be notified about item changes.the listener to add
void drawInfo(@NotNull final String message, final int color)
Pretends that a drawinfo message has been received.the message the color
Interface for listeners interested in item related commands.
final EventListenerList2< CrossfirePickupListener > crossfirePickupListeners
The CrossfirePickupListeners to be notified.
void fireEndAccountList(final int count)