public HostingShell(IRobotItem itemSpecification, IHostManager hostManager, IRobotPeer peer, IRobotStatics jstatics, string dllFileName) { robotPeer = peer; Init(true); Open(dllFileName); JniGlobalHandle hmHandle = ((IJvmProxy) hostManager).JvmHandle; JniGlobalHandle peerhandle = ((IJvmProxy)peer).JvmHandle; JniGlobalHandle itemHandle = ((IJvmProxy)itemSpecification).JvmHandle; domain.SetData("hostManager", hmHandle.DangerousGetHandle()); domain.SetData("peer", peerhandle.DangerousGetHandle()); domain.SetData("item", itemHandle.DangerousGetHandle()); var statics = serializer.ConvertJ2C<RobotStatics>(RbSerializerN.RobotStatics_TYPE, (Object) jstatics); domain.SetData("statics", statics); domain.SetData("robotName", statics.getName()); try { domain.DoCallBack(HostingSeed.Construct); } catch (Exception) { robotPeer.punishBadBehavior(BadBehavior.SECURITY_VIOLATION); } hmHandle.HoldThisHandle(); peerhandle.HoldThisHandle(); itemHandle.HoldThisHandle(); }
public HostingShell(IRobotItem itemSpecification, IHostManager hostManager, IRobotPeer peer, IRobotStatics jstatics, string dllFileName) { robotPeer = peer; Init(true); Open(dllFileName); JniGlobalHandle hmHandle = ((IJvmProxy)hostManager).JvmHandle; JniGlobalHandle peerhandle = ((IJvmProxy)peer).JvmHandle; JniGlobalHandle itemHandle = ((IJvmProxy)itemSpecification).JvmHandle; domain.SetData("hostManager", hmHandle.DangerousGetHandle()); domain.SetData("peer", peerhandle.DangerousGetHandle()); domain.SetData("item", itemHandle.DangerousGetHandle()); var statics = serializer.ConvertJ2C <RobotStatics>(RbSerializerN.RobotStatics_TYPE, (Object)jstatics); domain.SetData("statics", statics); domain.SetData("robotName", statics.getName()); try { domain.DoCallBack(HostingSeed.Construct); } catch (Exception) { robotPeer.punishBadBehavior(BadBehavior.SECURITY_VIOLATION); } hmHandle.HoldThisHandle(); peerhandle.HoldThisHandle(); itemHandle.HoldThisHandle(); }
public void Dispose() { if (domain != null) { try { AppDomain.Unload(domain); domain = null; GC.Collect(); } catch (Exception ex) { LoggerN.logError(ex); if (robotPeer != null) { robotPeer.punishBadBehavior(BadBehavior.UNSTOPPABLE); } } } if (tempDir != null && Directory.Exists(tempDir)) { try { Directory.Delete(tempDir, true); } catch (IOException) { //ignore } tempDir = null; } }
public static void WaitForStopThread() { try { if (!robotThread.Join(1000)) { LoggerN.logError("Unable to stop thread for " + statics.getName()); robotPeer.punishBadBehavior(BadBehavior.UNSTOPPABLE); robotPeer.setRunning(false); } } catch (Exception ex) { LoggerN.logError(ex); throw; } }
public void run() { peer.setRunning(true); if (robotSpecification.isValid() && loadRobotRound()) { try { if (robot != null) { // peer.setRunning(true); // Does not work with .NET version // Process all events for the first turn. // This is done as the first robot status event must occur before the robot // has started running. eventManager.ProcessEvents(); // Call user code CallUserCode(); } // noinspection InfiniteLoopStatement for (;;) { executeImpl(); } } catch (WinException) { // Do nothing } catch (AbortedException) { // Do nothing } catch (DeathException) { println("SYSTEM: " + statics.getName() + " has died"); } catch (DisabledException e) { drainEnergy(); string msg = e.getMessage(); if (msg == null) { msg = ""; } else { msg = ": " + msg; } println("SYSTEM: Robot disabled: " + msg); LoggerN.logMessage("Robot disabled: " + statics.getName()); } catch (SecurityException e) { punishSecurityViolation(statics.getName() + " Exception: " + e); } catch (Exception e) { if (e.InnerException is SecurityException) { punishSecurityViolation(statics.getName() + " " + e.InnerException + " Exception: " + e); } else { drainEnergy(); println(e); LoggerN.logMessage(statics.getName() + ": Exception: " + e); // without stack here } } finally { waitForBattleEndImpl(); } } else { drainEnergy(); peer.punishBadBehavior(BadBehavior.CANNOT_START); waitForBattleEndImpl(); } peer.setRunning(false); }