Inheritance: IReturnValueReceiver
Example #1
0
        public void StopAndReset()
        {
            uniqueCompilationId++;
            isOn             = false;
            sleepTimer       = 0f;
            remoteCaller     = null;
            _mockProgram     = null;
            waitingForInput  = false;
            executionCounter = 0;
            executionTime    = 0;

            if (_sprakRunner != null)
            {
                _sprakRunner.returnFromExternalFunctionCall = false;
            }
        }
Example #2
0
        public void StartAtFunctionWithMockReceiver(string functionName, object[] args, MockProgram pMockProgram)
        {
            Start();

            try {
                remoteCaller = null;
                _mockProgram = pMockProgram;
                _sprakRunner.ResetAtFunction(functionName, args);
            }
            catch (Error e) {
                D.Log("Error when trying to call function using mock receiver: " + e);
                if (remoteCaller != null)
                {
                    remoteCaller._sprakRunner.getRuntimeErrorHandler().errorOccured(e);
                }
                _sprakRunner.getRuntimeErrorHandler().errorOccured(e);
            }
        }
Example #3
0
        public void StopAndReset()
        {
            uniqueCompilationId++;
            isOn = false;
            sleepTimer = 0f;
            remoteCaller = null;
            _mockProgram = null;
            waitingForInput = false;
            executionCounter = 0;
            executionTime = 0;

            if(_sprakRunner != null) {
                _sprakRunner.returnFromExternalFunctionCall = false;
            }
        }
Example #4
0
        public void StartAtFunctionWithMockReceiver(string functionName, object[] args, MockProgram pMockProgram)
        {
            Start();

            try {
                remoteCaller = null;
                _mockProgram = pMockProgram;
                _sprakRunner.ResetAtFunction (functionName, args);
            }
            catch(Error e) {
                D.Log("Error when trying to call function using mock receiver: " + e);
                if (remoteCaller != null) {
                    remoteCaller._sprakRunner.getRuntimeErrorHandler().errorOccured (e);
                }
                _sprakRunner.getRuntimeErrorHandler().errorOccured (e);
            }
        }
Example #5
0
        public void StartAtFunction(string functionName, object[] args, Program pCaller, bool pEnsureThatFunctionExists)
        {
            if(_sprakRunner == null) {
                #if LOG_START_AT_FUNCTION
                D.Log("Calling remote function " + functionName + " on " + nameOfOwner + " but it's sprakrunner is null, will try to compile");
                #endif
                var errors = Compile();

                if(_sprakRunner == null) {
                    if(pCaller != null) {
                        #if LOG_START_AT_FUNCTION
                        D.Log("Sprak runner is still null, will send back " + errors.Length + " errors to caller:");
                        #endif
                        foreach(var e in errors) {
                            pCaller._sprakRunner.getRuntimeErrorHandler().errorOccured (e);
                            D.Log(" - " + e);
                        }
                    } else {
                        #if LOG_START_AT_FUNCTION
                        D.Log("Sprak runner is still null, and no caller");
                        #endif
                    }
                    D.Log("Will NOT run " + functionName + " on " + nameOfOwner + ", failed to create sprak runner second time");
                    return;
                }
            }
            else {
                if(ContainsErrors()) {
                    D.Log("Clearing errors (" + GetErrors().Length + ") on " + this.ToString() + " because of incoming function call " + functionName);
                    ClearErrors(); // <- TODO: trying this out now
                }
            }

            //          var errors = Compile();
            //
            //          if(_sprakRunner == null || _sprakRunner.interpreter == null) {
            //
            //              if(pCaller != null) {
            //                  #if LOG_START_AT_FUNCTION
            //                  D.Log("Sprak runner is still null, will send back " + errors.Length + " errors to caller:");
            //                  #endif
            //                  foreach(var e in errors) {
            //                      pCaller._sprakRunner.getRuntimeErrorHandler().errorOccured (e);
            //                      D.Log(" - " + e);
            //                  }
            //              } else {
            //                  #if LOG_START_AT_FUNCTION
            //                  D.Log("Sprak runner is still null, and no caller");
            //                  #endif
            //              }
            //
            //              D.Log("Will NOT run " + functionName + " on " + nameOfOwner + ", failed to create sprak runner second time");
            //              return;
            //          }

            try {
                remoteCaller = pCaller;
                _mockProgram = null;

                if(remoteCaller != null) {
                    //D.Log("Set caller of " + this.ToString() + " to " + remoteCaller);
                    callersUniqueCompilationId = pCaller.uniqueCompilationId;
                    //D.Log("Set callersUniqueCompilationId of " + this.ToString() + " to the caller " + pCaller.ToString() + "'s uniqueCompilationId " + callersUniqueCompilationId);
                }
                else {
                    //D.Log("Program " + this.ToString() + " has no caller");
                }

                var functionCallStatus = _sprakRunner.ResetAtFunction (functionName, args);

                if(functionCallStatus == InterpreterTwo.ProgramFunctionCallStatus.NO_FUNCTION) {
                    var e = new Error("Can't find function '" + functionName + "' (forgot quotes?)");
                    if(pEnsureThatFunctionExists) {
                        throw e;
                    } else {
                        //D.Log("Can't find optional function '" + functionName + "' in " + this.ToString());
                        if(remoteCaller != null) {
                            remoteCaller._sprakRunner.getRuntimeErrorHandler().errorOccured (e);
                        }
                        StopAndReset();
                        return;
                    }
                }
                else if(functionCallStatus == InterpreterTwo.ProgramFunctionCallStatus.NORMAL_FUNCTION) {
                    isOn = true;
                }
                else if(functionCallStatus == InterpreterTwo.ProgramFunctionCallStatus.EXTERNAL_FUNCTION) {
                    isOn = true; // turning it on but it will only return it's value and then end
                    sprakRunner.returnFromExternalFunctionCall = true;
                }

                waitingForInput = false; // TODO: Is this an OK hack, why didn't I do this before?!!

                #if LOG
                D.Log("Program " + this.ToString() + " set to execute function " + functionName + ", waitingForInput: " + waitingForInput);
                #endif
            }
            catch(Error e) {
                D.Log("Error when trying to call function: " + e + " of type " + e.getErrorType());
                if (remoteCaller != null && e.getErrorType() != Error.ErrorType.RUNTIME) {
                    D.Log("Logging error on only remote caller: " + remoteCaller);
                    remoteCaller._sprakRunner.getRuntimeErrorHandler().errorOccured (e);
                }
                else {
                    D.Log("Logging error on self: " + this + " and remote caller " + remoteCaller);

                    if(remoteCaller != null && remoteCaller._sprakRunner != null && remoteCaller._sprakRunner.getRuntimeErrorHandler() != null) {
                        remoteCaller._sprakRunner.getRuntimeErrorHandler().errorOccured (e);
                    }

                    if(_sprakRunner == null) {
                        Compile();
                    }
                    if(_sprakRunner != null) {
                        _sprakRunner.getRuntimeErrorHandler().errorOccured (e);
                    } else {
                        D.Log("Sprak runner in " + this.ToString() + " still null, when trying to add runtime error: " + e);
                    }
                }
            }
        }
Example #6
0
        public void Hack(MimanTing pHackableTing)
        {
            if(pHackableTing == null) {
                D.Log("Hackable ting of " + name + " was null!");
                return;
            }

            if(hackdev == null) {
                D.Log(name + " has got no hackdev to hack with");
                return;
            }

            //logger.Log("Going to hack " + pHackableTing.name);

            if (pHackableTing != handItem) {
                FaceTing (pHackableTing);
            }
            pHackableTing.PrepareForBeingHacked();

            if (pHackableTing == hackdev) {
                _worldSettings.Notify (name, "Modifier can't modify itself");
            }
            else if(pHackableTing.programs.Length > 0) {
                MockProgram receiver = new MockProgram (retVal => {
                    //D.Log("Got response from hackdev Allow function: " + retVal);
                    if(retVal.GetType() == typeof(bool) && ((bool)retVal) == true) {
                        StartAction("Hacking", pHackableTing, LONG_TIME, LONG_TIME);
                        _dialogueRunner.EventHappened(name + "_hack_" + pHackableTing.name);
                    } else {
                        D.Log("Hacking not allowed with current device for character " + name);
                        _worldSettings.Notify(name, "Not allowed with current device");
                        StopAction();
                    }
                });

                StartAction("AttemptHacking", pHackableTing, 1.0f, 1.0f);

                pHackableTing.PrepareForBeingHacked ();
                hackdev.PrepareForBeingHacked ();

                if (hackdev.masterProgram.HasFunction ("Allow", true)) {
                    hackdev.masterProgram.StartAtFunctionWithMockReceiver ("Allow", new object[] {
                        pHackableTing.name,
                        (float)pHackableTing.securityLevel
                    }, receiver);
                } else {
                    _worldSettings.Notify(name, "No Allow-function in " + hackdev.name);
                }
            }
            else {
                _worldSettings.Notify(name, "No programs to hack in " + pHackableTing.name);
                StopAction();
            }
        }
Example #7
0
        public void StartAtFunction(string functionName, object[] args, Program pCaller, bool pEnsureThatFunctionExists)
        {
            if (_sprakRunner == null)
            {
                                #if LOG_START_AT_FUNCTION
                D.Log("Calling remote function " + functionName + " on " + nameOfOwner + " but it's sprakrunner is null, will try to compile");
                                #endif
                var errors = Compile();

                if (_sprakRunner == null)
                {
                    if (pCaller != null)
                    {
                                                #if LOG_START_AT_FUNCTION
                        D.Log("Sprak runner is still null, will send back " + errors.Length + " errors to caller:");
                                                #endif
                        foreach (var e in errors)
                        {
                            pCaller._sprakRunner.getRuntimeErrorHandler().errorOccured(e);
                            D.Log(" - " + e);
                        }
                    }
                    else
                    {
                                                #if LOG_START_AT_FUNCTION
                        D.Log("Sprak runner is still null, and no caller");
                                                #endif
                    }
                    D.Log("Will NOT run " + functionName + " on " + nameOfOwner + ", failed to create sprak runner second time");
                    return;
                }
            }
            else
            {
                if (ContainsErrors())
                {
                    D.Log("Clearing errors (" + GetErrors().Length + ") on " + this.ToString() + " because of incoming function call " + functionName);
                    ClearErrors();                     // <- TODO: trying this out now
                }
            }

            //          var errors = Compile();
            //
            //          if(_sprakRunner == null || _sprakRunner.interpreter == null) {
            //
            //              if(pCaller != null) {
            //                  #if LOG_START_AT_FUNCTION
            //                  D.Log("Sprak runner is still null, will send back " + errors.Length + " errors to caller:");
            //                  #endif
            //                  foreach(var e in errors) {
            //                      pCaller._sprakRunner.getRuntimeErrorHandler().errorOccured (e);
            //                      D.Log(" - " + e);
            //                  }
            //              } else {
            //                  #if LOG_START_AT_FUNCTION
            //                  D.Log("Sprak runner is still null, and no caller");
            //                  #endif
            //              }
            //
            //              D.Log("Will NOT run " + functionName + " on " + nameOfOwner + ", failed to create sprak runner second time");
            //              return;
            //          }

            try {
                remoteCaller = pCaller;
                _mockProgram = null;

                if (remoteCaller != null)
                {
                    //D.Log("Set caller of " + this.ToString() + " to " + remoteCaller);
                    callersUniqueCompilationId = pCaller.uniqueCompilationId;
                    //D.Log("Set callersUniqueCompilationId of " + this.ToString() + " to the caller " + pCaller.ToString() + "'s uniqueCompilationId " + callersUniqueCompilationId);
                }
                else
                {
                    //D.Log("Program " + this.ToString() + " has no caller");
                }

                var functionCallStatus = _sprakRunner.ResetAtFunction(functionName, args);

                if (functionCallStatus == InterpreterTwo.ProgramFunctionCallStatus.NO_FUNCTION)
                {
                    var e = new Error("Can't find function '" + functionName + "' (forgot quotes?)");
                    if (pEnsureThatFunctionExists)
                    {
                        throw e;
                    }
                    else
                    {
                        //D.Log("Can't find optional function '" + functionName + "' in " + this.ToString());
                        if (remoteCaller != null)
                        {
                            remoteCaller._sprakRunner.getRuntimeErrorHandler().errorOccured(e);
                        }
                        StopAndReset();
                        return;
                    }
                }
                else if (functionCallStatus == InterpreterTwo.ProgramFunctionCallStatus.NORMAL_FUNCTION)
                {
                    isOn = true;
                }
                else if (functionCallStatus == InterpreterTwo.ProgramFunctionCallStatus.EXTERNAL_FUNCTION)
                {
                    isOn = true;                     // turning it on but it will only return it's value and then end
                    sprakRunner.returnFromExternalFunctionCall = true;
                }

                waitingForInput = false;                 // TODO: Is this an OK hack, why didn't I do this before?!!

                                #if LOG
                D.Log("Program " + this.ToString() + " set to execute function " + functionName + ", waitingForInput: " + waitingForInput);
                                #endif
            }
            catch (Error e) {
                D.Log("Error when trying to call function: " + e + " of type " + e.getErrorType());
                if (remoteCaller != null && e.getErrorType() != Error.ErrorType.RUNTIME)
                {
                    D.Log("Logging error on only remote caller: " + remoteCaller);
                    remoteCaller._sprakRunner.getRuntimeErrorHandler().errorOccured(e);
                }
                else
                {
                    D.Log("Logging error on self: " + this + " and remote caller " + remoteCaller);

                    if (remoteCaller != null && remoteCaller._sprakRunner != null && remoteCaller._sprakRunner.getRuntimeErrorHandler() != null)
                    {
                        remoteCaller._sprakRunner.getRuntimeErrorHandler().errorOccured(e);
                    }

                    if (_sprakRunner == null)
                    {
                        Compile();
                    }
                    if (_sprakRunner != null)
                    {
                        _sprakRunner.getRuntimeErrorHandler().errorOccured(e);
                    }
                    else
                    {
                        D.Log("Sprak runner in " + this.ToString() + " still null, when trying to add runtime error: " + e);
                    }
                }
            }
        }