Package net.sf.robocode.host

Examples of net.sf.robocode.host.IHostedThread


    }

    // Ok, we need to figure out who our robot is.
    Thread c = Thread.currentThread();

    IHostedThread robotProxy = threadManager.getLoadedOrLoadingRobotProxy(c);

    if (robotProxy == null) {
      Logger.logError("Preventing unknown thread " + Thread.currentThread().getName() + " from access: " + perm);
      return false;
    }

    // Attempt to stop the window from displaying
    if (perm instanceof java.awt.AWTPermission) {
      final String message = "Preventing " + robotProxy.getStatics().getName() + " from access: " + perm;

      robotProxy.punishSecurityViolation(message);

      // this is hack, because security exception is not enough
      throw new ThreadDeath();
    }

    // FilePermission access request.
    if (perm instanceof FilePermission) {
      FilePermission filePermission = (FilePermission) perm;
      // Get the fileSystemManager
      RobotFileSystemManager fileSystemManager = robotProxy.getRobotFileSystemManager();

      // Robot wants access to read something
      if (filePermission.getActions().equals("read")) {
        return impliesRobotFileRead(robotProxy, fileSystemManager, filePermission);

      } // Robot wants access to write something
      else if (filePermission.getActions().equals("write")) {
        return impliesRobotFileWrite(robotProxy, fileSystemManager, filePermission);

      } // Robot wants access to write something
      else if (filePermission.getActions().equals("delete")) {
        return impliesRobotFileDelete(robotProxy, fileSystemManager, filePermission);

      }
    }

    // check package access
    if (perm instanceof RuntimePermission && name.startsWith("accessClassInPackage.")) {
      return impliesRobotPackageAccess(robotProxy, name.substring(21));
    }

    // Permission denied.
    final String message = "Preventing " + robotProxy.getStatics().getName() + " from access: " + perm;

    robotProxy.punishSecurityViolation(message);
    return false;
  }
View Full Code Here


        break;
      }
    }
    if (!found) {
      String message = "Preventing " + c.getName() + " from access to " + t.getName();
      IHostedThread robotProxy = threadManager.getLoadedOrLoadingRobotProxy(c);

      if (robotProxy != null) {
        robotProxy.punishSecurityViolation(message);
      }
      throw new AccessControlException(message);
    }
  }
View Full Code Here

      // What the heck is going on here?  JDK 1.3 is sending me a dead thread.
      // This crashes the entire jvm if I don't return here.
      return;
    }

    IHostedThread robotProxy = threadManager.getLoadedOrLoadingRobotProxy(c);

    if (robotProxy == null) {
      throw new AccessControlException("Preventing " + c.getName() + " from access to " + g.getName());     
    }

    if (cg.activeCount() > 5) {
      String message = "Robots are only allowed to create up to 5 threads!";

      robotProxy.punishSecurityViolation(message);
      throw new AccessControlException(message);
    }
  }
View Full Code Here

    }
    return null;
  }

  public synchronized IHostedThread getLoadedOrLoadingRobotProxy(Thread t) {
    IHostedThread robotProxy = getRobotProxy(t);

    if (robotProxy == null) {
      robotProxy = getLoadingRobotProxy(t);
    }
    return robotProxy;
View Full Code Here

  }

  public FileOutputStream createRobotFileStream(String fileName, boolean append) throws IOException {
    final Thread c = Thread.currentThread();

    final IHostedThread robotProxy = getRobotProxy(c);

    if (robotProxy == null) {
      syserr.println("RobotProxy is null");
      return null;
    }
    if (!robotProxy.getStatics().isAdvancedRobot()) {
      throw new RobotException("Only advanced robots could create files");
    }
   
    final File dir = robotProxy.getRobotFileSystemManager().getWritableDirectory();

    if (!dir.exists()) {
      robotProxy.println("SYSTEM: Creating a data directory for you.");
      AccessController.doPrivileged(new PrivilegedAction<Object>() {
        public Object run() {
          outputStreamThreads.add(c);
          if (!dir.exists() && !dir.mkdirs()) {
            syserr.println("Can't create dir " + dir.toString());
          }
          return null;
        }
      });
    }

    final RobotFileSystemManager fileSystemManager = robotProxy.getRobotFileSystemManager();

    File f = new File(fileName);
    long len;

    if (f.exists()) {
View Full Code Here

    if (isSafeThread(c)) {
      return null;
    }

    IHostedThread robotProxy = getLoadedOrLoadingRobotProxy(c);

    return (robotProxy != null) ? robotProxy.getOut() : null;
  }
View Full Code Here

TOP

Related Classes of net.sf.robocode.host.IHostedThread

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.