Package xnap.plugin.gift.net.lexer

Examples of xnap.plugin.gift.net.lexer.Command


    {
        if (!isConnected()) {
            return;
        }

        Command cmd = new Command("stats");
        queueCommand(cmd);
    }
View Full Code Here


    {
        if (!isConnected()) {
            return;
        }

        Command cmd = new Command("addsource");
        cmd.addKey("hash", sr.getHash());
        cmd.addKey("size", Long.toString(sr.getFilesize()));
        cmd.addKey("url", sr.getUrl());
        cmd.addKey("user", ((User) sr.getUser()).getGiFTName());
        // TODO
        cmd.addKey("save", sr.getShortFilename());
        queueCommand(cmd);
    }
View Full Code Here

      return;
    }
    if (downloads.get(dc) == null) {
      return;
    }
    Command cmd = new Command("transfer");
    cmd.setCommandArgument((String)downloads.get(dc));
    cmd.addKey("action", action);
    queueCommand(cmd)
  }
View Full Code Here

      return;
    }
    if (searches.get(s) == null) {
      return;
    }
    Command cmd = new Command("search");
    cmd.setCommandArgument((String)searches.get(s));
    cmd.addKey("action", action);
    queueCommand(cmd);
    System.out.println(cmd.print());
  }
View Full Code Here

    {
        if (!isConnected()) {
            return;
        }

    Command cmd = new Command("quit");
    try {
      OutputStream os = socket.getOutputStream();
      os.write(cmd.print().getBytes());
      os.flush();
    } catch (Exception e) {}
    try {
      socket.close();
    } catch (IOException e) {}
View Full Code Here

            return;
        }

        searches.put(Integer.toString(s.hashCode()), s);
    searches.put(s, Integer.toString(s.hashCode()));
        Command cmd = new Command("search");
        cmd.setCommandArgument(Integer.toString(s.hashCode()));
        cmd.addKey("query", s.getSearchFilter().getSearchText());
        queueCommand(cmd);
        s.searchStarted(new SearchControlEvent(ControlEvent.STARTED));
    }
View Full Code Here

        if (!isConnected()) {
            return;
        }

        // TODO: use 'quit' if giFT has been started by NXap
        Command cmd = new Command("detach");
        try {
          OutputStream os = socket.getOutputStream();
          os.write(cmd.print().getBytes());
          os.flush();
        } catch (Exception e) {}
    try {
      socket.close();
    } catch (IOException e) {}
View Full Code Here

    {
        if (!isConnected()) {
            return;
        }

        Command cmd = new Command("share");
        cmd.addKey("action", "sync");
        queueCommand(cmd);
        fireEvent(new SharesControlEvent(SharesControlEvent.SYNC_STARTED));
    }
View Full Code Here

    {
        if (!isConnected()) {
            return;
        }

        queueCommand(new Command("shares"));
        fireEvent(new SharesControlEvent(ControlEvent.STARTED));
    }
View Full Code Here

            return;
        } else if (cmd.getCommand().equalsIgnoreCase("STATS")) {
            Vector subCommands = cmd.getSubCommands();
            stats.clear();
      for (int i = 0; i < subCommands.size(); i++) {
                Command proto = (Command)subCommands.get(i);
                long files = -1;
                long users = -1;
                float size = -1;

                try {
                    files = Long.parseLong((String) proto.getKey("files"));
                } catch (NumberFormatException e) {
                }

                try {
                    users = Long.parseLong((String) proto.getKey("users"));
                } catch (NumberFormatException e) {
                }

                try {
                    size = Float.parseFloat((String) proto.getKey("size"));
                } catch (NumberFormatException e) {
                }

                if (!proto.getCommand().equalsIgnoreCase("gift")) {
                    stats.put(proto.getCommand(),
                        files + XNap.tr("Files", 1, 0) + ", " + users +
                        XNap.tr("Users", 1, 0) + ", " + size + " GB");
                }

                StatsEvent nsevt = new StatsEvent(proto.getCommand());
                nsevt.setFiles(files);
                nsevt.setUsers(users);
                nsevt.setSize(size);
                fireEvent(nsevt);
            }

            return;
        } else if (cmd.getCommand().equalsIgnoreCase("ITEM")) {
            // if share item
            if (cmd.getCommandArgument() == null) {
                if (cmd.hasKeys()) {
                    ShareItemEvent se = new ShareItemEvent();
                    se.setPath(cmd.getKey("path"));

                    try {
                        se.setSize(Long.parseLong(cmd.getKey("size")));
                    } catch (Exception e) {
                    }

                    se.setMime(cmd.getKey("mime"));
                    se.setHash(cmd.getKey("hash"));

                    Command meta = cmd.getSubCommandByName("META");

                    if (meta != null) {
                        Enumeration keys = meta.getKeys();

                        while (keys.hasMoreElements()) {
                            String key = (String) keys.nextElement();
                            se.addMetaItem(key, meta.getKey(key));
                        }
                    }

                    fireEvent(se);
                } else {
                    fireEvent(new SharesControlEvent(ControlEvent.FINISHED));
                }
            } else {
                if (cmd.hasKeys()) {
                    // search item
                    long size = -1;

                    try {
                        size = Long.parseLong(cmd.getKey("size"));
                    } catch (Exception e) {
                    }

                    int score = 1;

                    try {
                        score = Integer.parseInt(cmd.getKey("availability"));
                    } catch (Exception e) {
                    }

                    Hashtable meta = new Hashtable();

                    Command metaCmd = cmd.getSubCommandByName("META");

                    if (metaCmd != null) {
                        Enumeration keys = metaCmd.getKeys();

                        while (keys.hasMoreElements()) {
                            String key = (String) keys.nextElement();
                            meta.put(key, metaCmd.getKey(key));
                        }
                    }

                    IUser user = new User(cmd.getKey("user"));
                    SearchResult sr = new SearchResult(size, user,
View Full Code Here

TOP

Related Classes of xnap.plugin.gift.net.lexer.Command

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.