Package edu.drexel.cs544.mcmuc.actions

Examples of edu.drexel.cs544.mcmuc.actions.Action


    /**
     * When the primary timer for a room expires, and the client is not actively using the room,
     * send a Timeout action on the control channel for the room.
     */
    public void run() {
        Controller controller = Controller.getInstance();
        Timeout timeout = new Timeout(Arrays.asList(port));
        controller.send(timeout);
        startSecondaryTimer();
    }
View Full Code Here


                channel = c;
                message = m;
            }

            public void run() {
                Room r = (Room) channel;
                Presence p = new Presence(r.getUserName(), r.getStatus());
                channel.send(p);
                channel.send(message);
            }
        }
        Thread t = new Thread(new Runner(this, channel));
View Full Code Here

                channel = c;
                message = m;
            }

            public void run() {
                Room r = (Room) channel;
                Presence p = new Presence(r.getUserName(), r.getStatus());
                channel.send(p);
                channel.send(message);
            }
View Full Code Here

                message = m;
            }

            public void run() {
                if (message.hasKey()) {
                    Room r = (Room) channel;
                    Certificate privateKey = r.getKeyPairs().get(message.getKey());
                    if (privateKey != null)
                        message.decryptBody(privateKey);
                }
                if (message.hasTo()) {
                    Room r = (Room) channel;
                    if (r.getUserName().equals(message.getTo()))
                        Controller.getInstance().output(message.getFrom() + "@" + ((Room) channel).getName() + " (private): " + message.getBody() + " (" + message.getUID() + ")");
                } else
                    Controller.getInstance().output(message.getFrom() + "@" + ((Room) channel).getName() + ": " + message.getBody() + " (" + message.getUID() + ")");
                channel.send(message);
            }
View Full Code Here

                message = m;
            }

            public void run() {
                if (message.hasKey()) {
                    Room r = (Room) channel;
                    Certificate privateKey = r.getKeyPairs().get(message.getKey());
                    if (privateKey != null)
                        message.decryptBody(privateKey);
                }
                if (message.hasTo()) {
                    Room r = (Room) channel;
                    if (r.getUserName().equals(message.getTo()))
                        Controller.getInstance().output(message.getFrom() + "@" + ((Room) channel).getName() + " (private): " + message.getBody() + " (" + message.getUID() + ")");
                } else
                    Controller.getInstance().output(message.getFrom() + "@" + ((Room) channel).getName() + ": " + message.getBody() + " (" + message.getUID() + ")");
                channel.send(message);
            }
View Full Code Here

     *
     * @param args String command-line arguments to program, which are ignored
     */
    public static void main(String[] args) {

        CLI cli = new CLI();
        cli.start();

        Controller controller = Controller.getInstance();
        controller.setUI(cli);

        while (true) {
            try {
                CLICommand command = cli.getNextCommand();
                if (command.getCommand() == CLICommand.Command.EXIT) { // Stop and kill this program
                    System.err.println("Exit command received, shutting down...");
                    controller.shutdown();
                    System.exit(0);
                } else if (command.getCommand() == CLICommand.Command.USEROOM) {
                    controller.useRoom(command.getArg(1), command.getArg(0));
                } else if (command.getCommand() == CLICommand.Command.LEAVEROOM) {
                    controller.leaveRoom(command.getArg(0));
                } else if (command.getCommand() == CLICommand.Command.PRESENCE) {
                    Status s;
                    if (command.getArg(1).equalsIgnoreCase("Online"))
                        s = Status.Online;
                    else if (command.getArg(1).equalsIgnoreCase("Offline"))
                        s = Status.Offline;
                    else {
                        System.err.println("Unknown status");
                        continue;
                    }
                    controller.setRoomStatus(command.getArg(0), s);
                } else if (command.getCommand() == CLICommand.Command.MESSAGE) {
                    controller.messageRoom(command.getArg(0), new Message(controller.getUserName(command.getArg(0)), command.getArg(1)));
                } else if (command.getCommand() == CLICommand.Command.PVTMESSAGE) {
                    controller.messageRoom(command.getArg(1), new Message(controller.getUserName(command.getArg(1)), command.getArg(2), command.getArg(0)));
                } else if (command.getCommand() == CLICommand.Command.ADDKEY) {
                    FileInputStream publicKeyFile = new FileInputStream(command.getArg(1));
                    byte publicKey[] = new byte[(int) publicKeyFile.available()];
                    publicKeyFile.read(publicKey);

                    FileInputStream privateKeyFile = new FileInputStream(command.getArg(2));
                    byte privateKey[] = new byte[(int) privateKeyFile.available()];
                    privateKeyFile.read(privateKey);

                    controller.addKeyPair(command.getArg(0), new Certificate("X.509", publicKey), new Certificate("X.509", privateKey));
                } else if (command.getCommand() == CLICommand.Command.REMOVEKEY) {
                    FileInputStream publicKeyFile = new FileInputStream(command.getArg(1));
                    byte publicKey[] = new byte[(int) publicKeyFile.available()];
                    publicKeyFile.read(publicKey);

                    controller.removeKeyPair(command.getArg(0), new Certificate("X.509", publicKey));

                } else if (command.getCommand() == CLICommand.Command.SECUREMESSAGE) {
                    FileInputStream publicKeyFile = new FileInputStream(command.getArg(0));
                    byte publicKey[] = new byte[(int) publicKeyFile.available()];
                    publicKeyFile.read(publicKey);

                    Certificate cert = new Certificate("X.509", publicKey);
                    controller.messageRoom(command.getArg(2), new Message(controller.getUserName(command.getArg(2)), command.getArg(3), command.getArg(1), cert));
                }
            } catch (RoomDoesNotExistException e) {
                cli.alert(e.getMessage());
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
View Full Code Here

        Controller controller = Controller.getInstance();
        controller.setUI(cli);

        while (true) {
            try {
                CLICommand command = cli.getNextCommand();
                if (command.getCommand() == CLICommand.Command.EXIT) { // Stop and kill this program
                    System.err.println("Exit command received, shutting down...");
                    controller.shutdown();
                    System.exit(0);
                } else if (command.getCommand() == CLICommand.Command.USEROOM) {
                    controller.useRoom(command.getArg(1), command.getArg(0));
                } else if (command.getCommand() == CLICommand.Command.LEAVEROOM) {
                    controller.leaveRoom(command.getArg(0));
                } else if (command.getCommand() == CLICommand.Command.PRESENCE) {
                    Status s;
                    if (command.getArg(1).equalsIgnoreCase("Online"))
                        s = Status.Online;
                    else if (command.getArg(1).equalsIgnoreCase("Offline"))
                        s = Status.Offline;
                    else {
                        System.err.println("Unknown status");
                        continue;
                    }
                    controller.setRoomStatus(command.getArg(0), s);
                } else if (command.getCommand() == CLICommand.Command.MESSAGE) {
                    controller.messageRoom(command.getArg(0), new Message(controller.getUserName(command.getArg(0)), command.getArg(1)));
                } else if (command.getCommand() == CLICommand.Command.PVTMESSAGE) {
                    controller.messageRoom(command.getArg(1), new Message(controller.getUserName(command.getArg(1)), command.getArg(2), command.getArg(0)));
                } else if (command.getCommand() == CLICommand.Command.ADDKEY) {
                    FileInputStream publicKeyFile = new FileInputStream(command.getArg(1));
                    byte publicKey[] = new byte[(int) publicKeyFile.available()];
                    publicKeyFile.read(publicKey);

                    FileInputStream privateKeyFile = new FileInputStream(command.getArg(2));
                    byte privateKey[] = new byte[(int) privateKeyFile.available()];
                    privateKeyFile.read(privateKey);

                    controller.addKeyPair(command.getArg(0), new Certificate("X.509", publicKey), new Certificate("X.509", privateKey));
                } else if (command.getCommand() == CLICommand.Command.REMOVEKEY) {
                    FileInputStream publicKeyFile = new FileInputStream(command.getArg(1));
                    byte publicKey[] = new byte[(int) publicKeyFile.available()];
                    publicKeyFile.read(publicKey);

                    controller.removeKeyPair(command.getArg(0), new Certificate("X.509", publicKey));

                } else if (command.getCommand() == CLICommand.Command.SECUREMESSAGE) {
                    FileInputStream publicKeyFile = new FileInputStream(command.getArg(0));
                    byte publicKey[] = new byte[(int) publicKeyFile.available()];
                    publicKeyFile.read(publicKey);

                    Certificate cert = new Certificate("X.509", publicKey);
                    controller.messageRoom(command.getArg(2), new Message(controller.getUserName(command.getArg(2)), command.getArg(3), command.getArg(1), cert));
                }
            } catch (RoomDoesNotExistException e) {
                cli.alert(e.getMessage());
            } catch (FileNotFoundException e) {
                e.printStackTrace();
View Full Code Here

        try {
            String from = json.getString("from");
            String body = json.getString("body");

            String to = null;
            Certificate key = null;

            if (json.has("to"))
                to = json.getString("to");

            if (json.has("key"))
                key = new Certificate(json.getJSONObject("key"));

            init(from, body, to, key, false);

        } catch (JSONException e) {
            e.printStackTrace();
View Full Code Here

            }

            public void run() {
                if (message.hasKey()) {
                    Room r = (Room) channel;
                    Certificate privateKey = r.getKeyPairs().get(message.getKey());
                    if (privateKey != null)
                        message.decryptBody(privateKey);
                }
                if (message.hasTo()) {
                    Room r = (Room) channel;
View Full Code Here

            }

            public void run() {
                if (message.hasKey()) {
                    Room r = (Room) channel;
                    Certificate privateKey = r.getKeyPairs().get(message.getKey());
                    if (privateKey != null)
                        message.decryptBody(privateKey);
                }
                if (message.hasTo()) {
                    Room r = (Room) channel;
View Full Code Here

TOP

Related Classes of edu.drexel.cs544.mcmuc.actions.Action

Copyright © 2018 www.massapicom. 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.