Package bluffinmuffin.protocol.observer.lobby

Source Code of bluffinmuffin.protocol.observer.lobby.LobbyServerObserver

package bluffinmuffin.protocol.observer.lobby;

import java.util.StringTokenizer;

import bluffinmuffin.protocol.commands.DisconnectCommand;
import bluffinmuffin.protocol.commands.lobby.AbstractLobbyCommand;
import bluffinmuffin.protocol.commands.lobby.GameCommand;
import bluffinmuffin.protocol.commands.lobby.JoinTableCommand;
import bluffinmuffin.protocol.commands.lobby.ListTableCommand;
import bluffinmuffin.protocol.commands.lobby.career.AuthenticateUserCommand;
import bluffinmuffin.protocol.commands.lobby.career.CheckDisplayExistCommand;
import bluffinmuffin.protocol.commands.lobby.career.CheckUserExistCommand;
import bluffinmuffin.protocol.commands.lobby.career.CreateCareerTableCommand;
import bluffinmuffin.protocol.commands.lobby.career.CreateUserCommand;
import bluffinmuffin.protocol.commands.lobby.career.GetUserCommand;
import bluffinmuffin.protocol.commands.lobby.training.CreateTrainingTableCommand;
import bluffinmuffin.protocol.commands.lobby.training.IdentifyCommand;
import bluffinmuffin.protocol.observer.CommandObserver;

public class LobbyServerObserver extends CommandObserver<ILobbyServerListener>
{
    @Override
    protected void commandReceived(String line)
    {
        final StringTokenizer token = new StringTokenizer(line, "" + AbstractLobbyCommand.Delimitter);
        final String commandName = token.nextToken();
       
        if (commandName.equals(IdentifyCommand.COMMAND_NAME))
        {
            authentification(new IdentifyCommand(token));
        }
        else if (commandName.equals(DisconnectCommand.COMMAND_NAME))
        {
            disconnect(new DisconnectCommand(token));
        }
        else if (commandName.equals(ListTableCommand.COMMAND_NAME))
        {
            listTables(new ListTableCommand(token));
        }
        else if (commandName.equals(JoinTableCommand.COMMAND_NAME))
        {
            joinTables(new JoinTableCommand(token));
        }
        else if (commandName.equals(GameCommand.COMMAND_NAME))
        {
            game(new GameCommand(token));
        }
        else if (commandName.equals(CreateUserCommand.COMMAND_NAME))
        {
            createUser(new CreateUserCommand(token));
        }
        else if (commandName.equals(CheckUserExistCommand.COMMAND_NAME))
        {
            checkUserExist(new CheckUserExistCommand(token));
        }
        else if (commandName.equals(CheckDisplayExistCommand.COMMAND_NAME))
        {
            checkDisplayExist(new CheckDisplayExistCommand(token));
        }
        else if (commandName.equals(AuthenticateUserCommand.COMMAND_NAME))
        {
            authenticateUser(new AuthenticateUserCommand(token));
        }
        else if (commandName.equals(GetUserCommand.COMMAND_NAME))
        {
            getUser(new GetUserCommand(token));
        }
        else if (commandName.equals(CreateTrainingTableCommand.COMMAND_NAME))
        {
            createTrainingTable(new CreateTrainingTableCommand(token));
        }
        else if (commandName.equals(CreateCareerTableCommand.COMMAND_NAME))
        {
            createCareerTable(new CreateCareerTableCommand(token));
        }
        else
        {
            super.commandReceived(line);
        }
    }
   
    private void createUser(CreateUserCommand createUserCommand)
    {
        for (final ILobbyServerListener listener : getSubscribers())
        {
            listener.createUserCommandReceived(createUserCommand);
        }
    }
   
    private void checkUserExist(CheckUserExistCommand checkUserExistCommand)
    {
        for (final ILobbyServerListener listener : getSubscribers())
        {
            listener.checkUserExistCommandReceived(checkUserExistCommand);
        }
    }
   
    private void checkDisplayExist(CheckDisplayExistCommand checkDisplayExistCommand)
    {
        for (final ILobbyServerListener listener : getSubscribers())
        {
            listener.checkDisplayExistCommandReceived(checkDisplayExistCommand);
        }
    }
   
    private void authenticateUser(AuthenticateUserCommand authenticateUserCommand)
    {
        for (final ILobbyServerListener listener : getSubscribers())
        {
            listener.authenticateUserCommandReceived(authenticateUserCommand);
        }
    }
   
    private void getUser(GetUserCommand getUserCommand)
    {
        for (final ILobbyServerListener listener : getSubscribers())
        {
            listener.getUserCommandReceived(getUserCommand);
        }
    }
   
    private void game(GameCommand gameCommand)
    {
        for (final ILobbyServerListener listener : getSubscribers())
        {
            listener.gameCommandReceived(gameCommand);
        }
       
    }
   
    private void joinTables(JoinTableCommand lobbyJoinTableCommand)
    {
        for (final ILobbyServerListener listener : getSubscribers())
        {
            listener.joinTableCommandReceived(lobbyJoinTableCommand);
        }
    }
   
    private void listTables(ListTableCommand lobbyListTableCommand)
    {
        for (final ILobbyServerListener listener : getSubscribers())
        {
            listener.listTableCommandReceived(lobbyListTableCommand);
        }
    }
   
    private void disconnect(DisconnectCommand lobbyDisconnectCommand)
    {
        for (final ILobbyServerListener listener : getSubscribers())
        {
            listener.disconnectCommandReceived(lobbyDisconnectCommand);
        }
    }
   
    private void authentification(IdentifyCommand lobbyConnectCommand)
    {
        for (final ILobbyServerListener listener : getSubscribers())
        {
            listener.identifyCommandReceived(lobbyConnectCommand);
        }
    }
   
    private void createTrainingTable(CreateTrainingTableCommand lobbyCreateTableCommand)
    {
        for (final ILobbyServerListener listener : getSubscribers())
        {
            listener.createTrainingTableCommandReceived(lobbyCreateTableCommand);
        }
    }
   
    private void createCareerTable(CreateCareerTableCommand lobbyCreateTableCommand)
    {
        for (final ILobbyServerListener listener : getSubscribers())
        {
            listener.createCareerTableCommandReceived(lobbyCreateTableCommand);
        }
    }
}
TOP

Related Classes of bluffinmuffin.protocol.observer.lobby.LobbyServerObserver

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.