net.sf.juoserver.protocol
Class ControllerImpl

java.lang.Object
  extended by net.sf.juoserver.protocol.ControllerImpl
All Implemented Interfaces:
ProtocolController, Controller, IntercomListener

public class ControllerImpl
extends Object
implements Controller

Base controller class. A different instance of this class will be associated to each client's session.

This class adopts a modified version of the visitor pattern in order to handle the Message request instances: instead of placing an accept() method on every Message class and then having them call something like visitor.handle( this ), the getReply(Message) method detects the specific subclass of the Message parameter and invokes the right handler method. The same pattern is adopted in order to implement the postProcess(Message) method.

The detected methods are lazily saved into the handlers and postProcessors maps, which are static according to the fly-weight pattern, because they do not depend on the specific client whose conversation is being controlled.

See Also:
Visitor with Reflection, Java Tip

Constructor Summary
ControllerImpl(ClientHandler clientHandler, Core core, ClientMovementTracker movementTracker, Configuration configuration)
          Builds a new controller and attaches it to the specified ClientHandler.
 
Method Summary
protected  List<Message> asList(Message... serverList)
           
 void attach()
          Detach the listener from the communication network.
 void detach()
          Attach the listener to the communication network.
 boolean equals(Object obj)
           
 Account getAccount()
           
 UOObject getMobile()
           
 List<Message> getReply(Message request)
          Retrieves the reply for a certain request message.
 Message handle(CharacterSelect request)
           
 List<Message> handle(ClientVersion clientVersion)
           
 List<? extends Message> handle(DoubleClick doubleClick)
           
 List<Message> handle(DropItem dropItem)
           
 Message handle(GeneralInformation info)
           
 Message handle(GetPlayerStatus gps)
           
 Message handle(LoginRequest request)
           
 Message handle(LoginSeed seed)
           
 Message handle(LookRequest lookRequest)
           
 List<Message> handle(MegaClilocRequest mcr)
          Handles tooltips requests.
 List<Message> handle(MovementAck synchRequest)
          Handles possible client's position synchronization requests.
 List<Message> handle(MoveRequest request)
          Answers with the same sequence, increments the internal sequence (0 --> 256 and then always restart from 1).
 Message handle(PickUpItem pickUpItem)
           
 Message handle(PingPong ping)
           
 Message handle(SelectServer request)
           
 Message handle(ServerLoginRequest request)
           
 Message handle(SpyOnClient spyOnClient)
           
 Message handle(UnicodeSpeechRequest request)
           
 Message handle(WearItem wearItem)
           
 int hashCode()
           
 boolean isConversationActive()
           
 void onChangedClothes(Mobile wearingMobile)
          Receives the notification that the specified mobile has changed their clothes.
 void onEnteredRange(Mobile entered, UOObject target)
          Receives an update about a mobile, entered, which enters another mobile's, target, range.
 void onItemDropped(Mobile droppingMobile, Item item, int targetSerialId, int targetX, int targetY, int targetZ)
          Receives the notification about an item being dropped.
 void onOtherMobileMovement(Mobile moving)
          Receives an update about another mobile's movement.
 void onOtherMobileSpeech(Mobile speaker, MessageType type, int hue, int font, String language, String text)
          Receives an update about another mobile's speech.
 void postProcess(DropItem dropItem)
           
 void postProcess(Message request)
          Post-processes the request message.
 void postProcess(MoveRequest request)
          Let the other clients know about this movement.
 void postProcess(WearItem wearItem)
           
 void setAccount(Account account)
           
 void setMobile(Mobile mobile)
           
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ControllerImpl

public ControllerImpl(ClientHandler clientHandler,
                      Core core,
                      ClientMovementTracker movementTracker,
                      Configuration configuration)
Builds a new controller and attaches it to the specified ClientHandler.

Parameters:
clientHandler - client handler to attach this controller to
core - the core
movementTracker - a movement tracker
configuration - the used configuration
Method Detail

getReply

public List<Message> getReply(Message request)
Description copied from interface: ProtocolController
Retrieves the reply for a certain request message.

Specified by:
getReply in interface ProtocolController
Parameters:
request - request message
Returns:
reply message

postProcess

public void postProcess(Message request)
Description copied from interface: ProtocolController
Post-processes the request message.

Specified by:
postProcess in interface ProtocolController
Parameters:
request - the request message to be post-processed

isConversationActive

public boolean isConversationActive()
Specified by:
isConversationActive in interface ProtocolController
Returns:
true if and only if the conversation with the client is still active

attach

public void attach()
Description copied from interface: IntercomListener
Detach the listener from the communication network.

Specified by:
attach in interface IntercomListener

detach

public void detach()
Description copied from interface: IntercomListener
Attach the listener to the communication network.

Specified by:
detach in interface IntercomListener

handle

public Message handle(LoginRequest request)

handle

public Message handle(SelectServer request)

handle

public Message handle(ServerLoginRequest request)

handle

public Message handle(CharacterSelect request)

handle

public List<Message> handle(ClientVersion clientVersion)

handle

public List<Message> handle(MoveRequest request)
Answers with the same sequence, increments the internal sequence (0 --> 256 and then always restart from 1).

Parameters:
request - movement request
Returns:
movement response
Throws:
IntercomException - in case an inter-client error occurs

postProcess

public void postProcess(MoveRequest request)
Let the other clients know about this movement.

Parameters:
request - movement request
Throws:
IntercomException - in case of inter-client communication errors

handle

public List<Message> handle(MovementAck synchRequest)
Handles possible client's position synchronization requests.

Parameters:
synchRequest - synchronization request
Returns:
messages suitable for synchronizing the client's position

onOtherMobileMovement

public void onOtherMobileMovement(Mobile moving)
Description copied from interface: IntercomListener
Receives an update about another mobile's movement.

Specified by:
onOtherMobileMovement in interface IntercomListener
Parameters:
moving - the other, moving mobile

onEnteredRange

public void onEnteredRange(Mobile entered,
                           UOObject target)
Description copied from interface: IntercomListener
Receives an update about a mobile, entered, which enters another mobile's, target, range.

Specified by:
onEnteredRange in interface IntercomListener
Parameters:
entered - the mobile who has entered the target's range
target - the mobile whose range is being entered

handle

public Message handle(UnicodeSpeechRequest request)

onOtherMobileSpeech

public void onOtherMobileSpeech(Mobile speaker,
                                MessageType type,
                                int hue,
                                int font,
                                String language,
                                String text)
Description copied from interface: IntercomListener
Receives an update about another mobile's speech.

Specified by:
onOtherMobileSpeech in interface IntercomListener
Parameters:
speaker - the speaking mobile
type - message type
hue - message colour
font - message font
language - message language
text - message text

handle

public List<Message> handle(MegaClilocRequest mcr)
Handles tooltips requests.

Parameters:
mcr - request
Returns:
tooltip information

handle

public Message handle(PingPong ping)

handle

public Message handle(GetPlayerStatus gps)

handle

public List<? extends Message> handle(DoubleClick doubleClick)

handle

public Message handle(GeneralInformation info)

handle

public Message handle(LoginSeed seed)

handle

public Message handle(SpyOnClient spyOnClient)

handle

public Message handle(LookRequest lookRequest)

handle

public List<Message> handle(DropItem dropItem)

postProcess

public void postProcess(DropItem dropItem)

onItemDropped

public void onItemDropped(Mobile droppingMobile,
                          Item item,
                          int targetSerialId,
                          int targetX,
                          int targetY,
                          int targetZ)
Description copied from interface: IntercomListener
Receives the notification about an item being dropped.

Specified by:
onItemDropped in interface IntercomListener
Parameters:
droppingMobile - mobile dropping the item
item - item
targetSerialId - target serial ID
targetX - target X
targetY - target Y
targetZ - target Z

handle

public Message handle(PickUpItem pickUpItem)

handle

public Message handle(WearItem wearItem)

postProcess

public void postProcess(WearItem wearItem)

onChangedClothes

public void onChangedClothes(Mobile wearingMobile)
Description copied from interface: IntercomListener
Receives the notification that the specified mobile has changed their clothes.

Specified by:
onChangedClothes in interface IntercomListener
Parameters:
wearingMobile - the mobile changing their clothes

asList

protected List<Message> asList(Message... serverList)

hashCode

public int hashCode()
Overrides:
hashCode in class Object

equals

public boolean equals(Object obj)
Overrides:
equals in class Object

toString

public String toString()
Overrides:
toString in class Object

getAccount

public Account getAccount()

setAccount

public void setAccount(Account account)

getMobile

public UOObject getMobile()

setMobile

public void setMobile(Mobile mobile)


Copyright © 2010-2012. All Rights Reserved.