001         package com.croftsoft.apps.chat.server;
002    
003         import com.croftsoft.core.animation.model.ModelId;
004         import com.croftsoft.core.lang.NullArgumentException;
005    
006         import com.croftsoft.apps.chat.model.ChatModel;
007         import com.croftsoft.apps.chat.model.ChatWorld;
008         import com.croftsoft.apps.chat.request.MoveRequest;
009         import com.croftsoft.apps.chat.request.Request;
010         import com.croftsoft.apps.chat.response.MoveResponse;
011         import com.croftsoft.apps.chat.user.User;
012    
013         /*********************************************************************
014         * Moves an avatar.
015         *
016         * @version
017         *   2003-06-10
018         * @since
019         *   2003-06-06
020         * @author
021         *   <a href="https://www.croftsoft.com/">David Wallace Croft</a>
022         *********************************************************************/
023    
024         public final class  MoveServer
025           extends AbstractServer
026         //////////////////////////////////////////////////////////////////////
027         //////////////////////////////////////////////////////////////////////
028         {
029    
030         private final ChatWorld  chatWorld;
031    
032         //////////////////////////////////////////////////////////////////////
033         //////////////////////////////////////////////////////////////////////
034    
035         public  MoveServer ( ChatWorld  chatWorld )
036         //////////////////////////////////////////////////////////////////////
037         {
038           NullArgumentException.check ( this.chatWorld = chatWorld );
039         }
040    
041         //////////////////////////////////////////////////////////////////////
042         //////////////////////////////////////////////////////////////////////
043    
044         public Object  serve (
045           User     user,
046           Request  request )
047         //////////////////////////////////////////////////////////////////////
048         {
049           MoveRequest  moveRequest = ( MoveRequest ) request;
050    
051           ModelId  modelId = user.getModelId ( );
052    
053           if ( modelId == null )
054           {
055             return new MoveResponse ( true, true, false );
056           }
057    
058           ChatModel  chatModel = chatWorld.getChatModel ( modelId );
059    
060           if ( chatModel == null )
061           {
062             return new MoveResponse ( true, false, true );
063           }
064    
065           chatModel.setDestination ( moveRequest.getDestination ( ) );
066    
067           return null;
068         }
069    
070         //////////////////////////////////////////////////////////////////////
071         //////////////////////////////////////////////////////////////////////
072         }