|
View:
New views
2 Messages
—
Rating Filter:
Alert me
|
|
|
Robocode Security ErrorHi,
I have problem with my newly created robot for which what i did is create class named as KeyStrokeConfig inside robocode manager.And for my Sprobot i made changes in it.Please see keyStrokeConfig.java and Sprobot.java.Now when i try to run my game and try to play with Sprobot it gives me this error Rebuilding robot database. multiplayer.MprobotTest: Got an error with this class: java.lang.IllegalStateException: Can't overwrite cause multiplayer.MprobotTest2: Got an error with this class: java.lang.IllegalStateException: Can't overwrite cause multiplayer.MprobotTest3: Got an error with this class: java.lang.IllegalStateException: Can't overwrite cause sample.Uniteam3aTest: Got an error with this class: java.lang.IllegalStateException: Can't overwrite cause Preparing battle... ---------------------- Let the games begin! Testing value10 Preparing battle... Round 1 cleaning up. ---------------------- Round 1 initializing..java.security.AccessControlException: Preventing Robot Loader from access to the internal Robocode pakage: robocode.manager java.security.AccessControlException: Preventing Robot Loader from access to the internal Robocode pakage: robocode.manager at robocode.security.RobocodeSecurityManager.checkPackageAccess(RobocodeSecurityManager.java:559) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:273) at java.lang.ClassLoader.loadClass(ClassLoader.java:299) at robocode.security.RobocodeClassLoader.loadClass(RobocodeClassLoader.java:116) at java.lang.ClassLoader.loadClass(ClassLoader.java:251) at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319) at singleplayer.Sprobot.<init>(Sprobot.java:26) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27) at java.lang.reflect.Constructor.newInstance(Constructor.java:513) at java.lang.Class.newInstance0(Class.java:355) at java.lang.Class.newInstance(Class.java:308) at robocode.battle.Battle.unsafeLoadRobots(Battle.java:1435) at robocode.battle.Battle$UnsafeLoadRobotsThread.run(Battle.java:1679) java.security.AccessControlException: Preventing Robot Loader from access to the internal Robocode pakage: robocode.manager java.security.AccessControlException: Preventing Robot Loader from access to the internal Robocode pakage: robocode.manager at robocode.security.RobocodeSecurityManager.checkPackageAccess(RobocodeSecurityManager.java:559) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:273) at java.lang.ClassLoader.loadClass(ClassLoader.java:299) at robocode.security.RobocodeClassLoader.loadClass(RobocodeClassLoader.java:116) at java.lang.ClassLoader.loadClass(ClassLoader.java:251) at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319) at singleplayer.Sprobot.<init>(Sprobot.java:26) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27) at java.lang.reflect.Constructor.newInstance(Constructor.java:513) at java.lang.Class.newInstance0(Class.java:355) at java.lang.Class.newInstance(Class.java:308) at robocode.battle.Battle.unsafeLoadRobots(Battle.java:1435) at robocode.battle.Battle$UnsafeLoadRobotsThread.run(Battle.java:1679) .. Here are KeyStrokeConfig,java package robocode.manager; public class KeyStrokeConfig { public int UpKey=0x26; int DownKey=0x28; int RightKey=0x27; int LeftKey=0x25; int FirePower1Key=0x4A; int FirePower2Key=0x48; int FirePower3Key=0x47; int GunRightKey=0x55; int GunLeftKey=0x49; public void setKeysValues(int upKey,int downKey, int rightKey, int leftKey, int firePower1Key, int firePower2Key, int firePower3Key, int gunRightKey, int gunLeftKey) { UpKey=upKey; DownKey=downKey; RightKey=rightKey; LeftKey=leftKey; FirePower1Key=firePower1Key; FirePower2Key=firePower2Key; FirePower3Key=firePower3Key; GunRightKey=gunRightKey; GunLeftKey=gunLeftKey; } public int getRightKey() { return RightKey; } public int getDownKey() { return DownKey; } public int getUpKey() { return UpKey; } public int getleftKey() { return LeftKey; } public int getFirePower1Key() { return FirePower1Key; } public int getFirePower2Key() { return FirePower2Key; } public int getFirePower3Key() { return FirePower3Key; } public int getGunRightKey() { return GunRightKey; } public int getGunleftKey() { return GunLeftKey; } } Here is my Sprobot.java package singleplayer; import robocode.AdvancedRobot; import robocode.manager.RobocodeManager; import robocode.manager.*; import java.awt.*; import java.awt.event.KeyEvent; public class Sprobot extends AdvancedRobot { public RobocodeManager manager; // Move direction: 1 = move forward, 0 = stand still, -1 = move backward int moveDirection; // Turn direction: 1 = turn right, 0 = no turning, -1 = turn left int turnDirection; // Amount of pixels/units to move double moveAmount; // Fire power, where 0 = don't fire int firePower; int firePower2; String sr; KeyStrokeConfig keyconfig= new KeyStrokeConfig(); // Called when the robot must run public void run() { // Sets the colors of the robot // body = black, gun = white, radar = red setColors(Color.BLACK, Color.BLACK, Color.YELLOW); // Loop forever for (;;) { // Sets the robot to move forward, backward or stop moving depending // on the move direction and amount of pixels to move setAhead(moveAmount * moveDirection); // Decrement the amount of pixels to move until we reach 0 pixels // This way the robot will automatically stop if the mouse wheel // has stopped it's rotation moveAmount = Math.max(0, moveAmount - 1); // Sets the robot to turn right or turn left (at maximum speed) or // stop turning depending on the turn direction setTurnRight(45 * turnDirection); // degrees // Fire the gun with the specified fire power, unless the fire power = 0 if (firePower > 0) { setFire(firePower); } // Execute all pending set-statements execute(); // Next turn is processed in this loop.. } } public void onKeyPressed(KeyEvent e) { if(e.getKeyCode()==keyconfig.getUpKey()) { moveDirection = 1; moveAmount = Double.POSITIVE_INFINITY; } if(e.getKeyCode()==keyconfig.getDownKey()) { moveDirection = -1; moveAmount = Double.POSITIVE_INFINITY; } if(e.getKeyCode()==keyconfig.getleftKey()) { turnDirection = -1; } if(e.getKeyCode()==keyconfig.getRightKey()) { turnDirection = 1; } if(e.getKeyCode()==keyconfig.getFirePower1Key()) { firePower = 3; setBulletColor(Color.RED); } if(e.getKeyCode()==keyconfig.getFirePower2Key()) { firePower = 2; setBulletColor(Color.YELLOW); } if(e.getKeyCode()==keyconfig.getFirePower3Key()) { firePower = 1; setBulletColor(Color.BLUE); } if(e.getKeyCode()==keyconfig.getGunleftKey()) { char c = e.getKeyChar(); if (c == 'u') { setTurnGunLeft(90); } } if(e.getKeyCode()==keyconfig.getGunRightKey()) { char d = e.getKeyChar(); if (d == 'u') { setTurnGunRight(90); } } } public void onKeyReleased(KeyEvent e) { if(e.getKeyCode()==keyconfig.getUpKey()) { } if(e.getKeyCode()==keyconfig.getDownKey()) { moveDirection = 0; } if(e.getKeyCode()==keyconfig.getleftKey()) { turnDirection = 0; } if(e.getKeyCode()==keyconfig.getRightKey()) { } if(e.getKeyCode()==keyconfig.getFirePower1Key()) { firePower = 0; } if(e.getKeyCode()==keyconfig.getFirePower2Key()) { firePower = 0; } if(e.getKeyCode()==keyconfig.getFirePower3Key()) { firePower = 0; } } } |
|
|
Re: Robocode Security ErrorYou got the following exception:
java.security.AccessControlException: Preventing Robot Loader from access to the internal Robocode pakage: robocode.manager java.security.AccessControlException: Preventing Robot Loader from access to the internal Robocode pakage: robocode.manager The reason is that robots are not allowed to access internal Robocode packages and classes other than the public API that is visible from the javadocs (see http://robocode.sourceforge.net/docs/robocode/). Robot's should not mess with game logic etc. That would be hacking the API, and the Robocode Security Manager prohibits this as you see. There are several reasons for this: 1) Security: Robots should not be able to access internal logic - they could cheat! 2) Security: Robots could misuse the API, and hence do harm on the users computer, like a virus or similar. 3) The internal logic in Robocode is always changed. If robots or other applications were allowed to use it, they would expect these never to change, which is definitely not true. Classes, methods etc. inside the game come and go every release. Howver, the user is able to disable some security, but not all. You can set the -DNOSECURITY=true with the robocode.cmd/sh file like this: java -Xmx512M -DNOSECURITY=true -Dsun.io.useCanonCaches=false -cp libs/robocode.jar;libs/codesize.jar;libs/cachecleaner.jar robocode.Robocode But this can only be done by the user, so it will only work on your system, if you disable security. Best regards, - Flemming --- In Robocode@..., "asherbaig" <devilvsevil@...> wrote: > > Hi, > I have problem with my newly created robot for which what i did is > create class named as KeyStrokeConfig inside robocode manager.And for > my Sprobot i made changes in it.Please see keyStrokeConfig.java and > Sprobot.java.Now when i try to run my game and try to play with > Sprobot it gives me this error > > > Rebuilding robot database. > multiplayer.MprobotTest: Got an error with this class: > java.lang.IllegalStateException: Can't overwrite cause > multiplayer.MprobotTest2: Got an error with this class: > java.lang.IllegalStateException: Can't overwrite cause > multiplayer.MprobotTest3: Got an error with this class: > java.lang.IllegalStateException: Can't overwrite cause > sample.Uniteam3aTest: Got an error with this class: > java.lang.IllegalStateException: Can't overwrite cause > Preparing battle... > ---------------------- > > Let the games begin! > Testing value10 > Preparing battle... > Round 1 cleaning up. > ---------------------- > Round 1 initializing..java.security.AccessControlException: Preventing > Robot Loader from access to the internal Robocode pakage: > java.security.AccessControlException: Preventing Robot Loader from > access to the internal Robocode pakage: robocode.manager > at > robocode.security.RobocodeSecurityManager.checkPackageAccess(RobocodeSecurityManager.java:559) > at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:273) > at java.lang.ClassLoader.loadClass(ClassLoader.java:299) > at > robocode.security.RobocodeClassLoader.loadClass(RobocodeClassLoader.java:116) > at java.lang.ClassLoader.loadClass(ClassLoader.java:251) > at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319) > at singleplayer.Sprobot.<init>(Sprobot.java:26) > at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) > at > sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39) > at > sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27) > at java.lang.reflect.Constructor.newInstance(Constructor.java:513) > at java.lang.Class.newInstance0(Class.java:355) > at java.lang.Class.newInstance(Class.java:308) > at robocode.battle.Battle.unsafeLoadRobots(Battle.java:1435) > at robocode.battle.Battle$UnsafeLoadRobotsThread.run(Battle.java:1679) > java.security.AccessControlException: Preventing Robot Loader from > access to the internal Robocode pakage: robocode.manager > java.security.AccessControlException: Preventing Robot Loader from > access to the internal Robocode pakage: robocode.manager > at > > at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:273) > at java.lang.ClassLoader.loadClass(ClassLoader.java:299) > at > robocode.security.RobocodeClassLoader.loadClass(RobocodeClassLoader.java:116) > at java.lang.ClassLoader.loadClass(ClassLoader.java:251) > at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319) > at singleplayer.Sprobot.<init>(Sprobot.java:26) > at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) > at > sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39) > at > sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27) > at java.lang.reflect.Constructor.newInstance(Constructor.java:513) > at java.lang.Class.newInstance0(Class.java:355) > at java.lang.Class.newInstance(Class.java:308) > at robocode.battle.Battle.unsafeLoadRobots(Battle.java:1435) > at robocode.battle.Battle$UnsafeLoadRobotsThread.run(Battle.java:1679) > .. > > > > Here are KeyStrokeConfig,java > > package robocode.manager; > > public class KeyStrokeConfig { > > public > int UpKey=0x26; > int DownKey=0x28; > int RightKey=0x27; > int LeftKey=0x25; > int FirePower1Key=0x4A; > int FirePower2Key=0x48; > int FirePower3Key=0x47; > int GunRightKey=0x55; > int GunLeftKey=0x49; > > > public void setKeysValues(int upKey,int downKey, > int rightKey, > int leftKey, > int firePower1Key, > int firePower2Key, > int firePower3Key, > int gunRightKey, > int gunLeftKey) > { > UpKey=upKey; > DownKey=downKey; > RightKey=rightKey; > LeftKey=leftKey; > FirePower1Key=firePower1Key; > FirePower2Key=firePower2Key; > FirePower3Key=firePower3Key; > GunRightKey=gunRightKey; > GunLeftKey=gunLeftKey; > > } > public int getRightKey() > { > return RightKey; > } > > public int getDownKey() > { > return DownKey; > } > public int getUpKey() > { > return UpKey; > } > public int getleftKey() > { > return LeftKey; > } > public int getFirePower1Key() > { > return FirePower1Key; > } > public int getFirePower2Key() > { > return FirePower2Key; > } > public int getFirePower3Key() > { > return FirePower3Key; > } > public int getGunRightKey() > { > return GunRightKey; > } > public int getGunleftKey() > { > return GunLeftKey; > } > > } > > > Here is my Sprobot.java > > package singleplayer; > import robocode.AdvancedRobot; > import robocode.manager.RobocodeManager; > import robocode.manager.*; > > import java.awt.*; > import java.awt.event.KeyEvent; > > > public class Sprobot extends AdvancedRobot { > > public RobocodeManager manager; > // Move direction: 1 = move forward, 0 = stand still, -1 = move > int moveDirection; > > // Turn direction: 1 = turn right, 0 = no turning, -1 = turn left > int turnDirection; > > // Amount of pixels/units to move > double moveAmount; > > // Fire power, where 0 = don't fire > int firePower; > int firePower2; > String sr; > KeyStrokeConfig keyconfig= new KeyStrokeConfig(); > > // Called when the robot must run > public void run() { > > // Sets the colors of the robot > // body = black, gun = white, radar = red > setColors(Color.BLACK, Color.BLACK, Color.YELLOW); > > // Loop forever > for (;;) { > // Sets the robot to move forward, backward or stop moving depending > // on the move direction and amount of pixels to move > setAhead(moveAmount * moveDirection); > > // Decrement the amount of pixels to move until we reach 0 pixels > // This way the robot will automatically stop if the mouse wheel > // has stopped it's rotation > moveAmount = Math.max(0, moveAmount - 1); > > // Sets the robot to turn right or turn left (at maximum speed) or > // stop turning depending on the turn direction > setTurnRight(45 * turnDirection); // degrees > > > > // Fire the gun with the specified fire power, unless the fire > power = 0 > if (firePower > 0) { > setFire(firePower); > } > > // Execute all pending set-statements > execute(); > > // Next turn is processed in this loop.. > } > } > > > public void onKeyPressed(KeyEvent e) { > > if(e.getKeyCode()==keyconfig.getUpKey()) > { > moveDirection = 1; > moveAmount = Double.POSITIVE_INFINITY; > } > if(e.getKeyCode()==keyconfig.getDownKey()) > { > moveDirection = -1; > moveAmount = Double.POSITIVE_INFINITY; > } > if(e.getKeyCode()==keyconfig.getleftKey()) > { > turnDirection = -1; > } > if(e.getKeyCode()==keyconfig.getRightKey()) > { > turnDirection = 1; > } > if(e.getKeyCode()==keyconfig.getFirePower1Key()) > { > firePower = 3; > setBulletColor(Color.RED); > } > if(e.getKeyCode()==keyconfig.getFirePower2Key()) > { > firePower = 2; > setBulletColor(Color.YELLOW); > } > if(e.getKeyCode()==keyconfig.getFirePower3Key()) > { > firePower = 1; > setBulletColor(Color.BLUE); > } > if(e.getKeyCode()==keyconfig.getGunleftKey()) > { > char c = e.getKeyChar(); > if (c == 'u') { > setTurnGunLeft(90); > } > } > if(e.getKeyCode()==keyconfig.getGunRightKey()) > { > char d = e.getKeyChar(); > if (d == 'u') { > setTurnGunRight(90); > } > } > } > > public void onKeyReleased(KeyEvent e) { > if(e.getKeyCode()==keyconfig.getUpKey()) > { > > } > if(e.getKeyCode()==keyconfig.getDownKey()) > { > moveDirection = 0; > } > if(e.getKeyCode()==keyconfig.getleftKey()) > { > turnDirection = 0; > } > if(e.getKeyCode()==keyconfig.getRightKey()) > { > > } > if(e.getKeyCode()==keyconfig.getFirePower1Key()) > { > firePower = 0; > } > if(e.getKeyCode()==keyconfig.getFirePower2Key()) > { > firePower = 0; > > } > if(e.getKeyCode()==keyconfig.getFirePower3Key()) > { > firePower = 0; > > } > > } > } > |
| Free embeddable forum powered by Nabble | Forum Help |