Esempio n. 1
0
UOExecutor::~UOExecutor()
{
	// note, the os_module isn't deleted here because
	// the Executor deletes its ExecutorModules.
    if ((instr_cycles >= 500) && watch.profile_scripts)
    {
        long elapsed = static_cast<long>(poltime() - start_time); // Doh! A script can't run more than 68 years, for this to work.
        Log( "Script %s: %"OUT64"d instr cycles, %"OUT64"d sleep cycles, %ld seconds\n",
                scriptname().c_str(), instr_cycles, sleep_cycles, elapsed );
        cerr << "Script " << scriptname() << ": "
                << instr_cycles << " instr cycles, "
                << sleep_cycles << " sleep cycles, " 
                << elapsed << " seconds elapsed." 
                << endl;
    }

	pParent = NULL;
	pChild = NULL;
}
Esempio n. 2
0
UOExecutor::~UOExecutor()
{
  // note, the os_module isn't deleted here because
  // the Executor deletes its ExecutorModules.
  if ((instr_cycles >= 500) && settingsManager.watch.profile_scripts)
  {
    int elapsed = static_cast<int>(poltime() - start_time); // Doh! A script can't run more than 68 years, for this to work.
    POLLOG_ERROR.Format("Script {}: {} instr cycles, {} sleep cycles, {} seconds\n")
        << scriptname() << instr_cycles << sleep_cycles << elapsed;
  }

  pParent = NULL;
  pChild = NULL;
}
Esempio n. 3
0
    void Script::run(const std::string& filename)
    {
        File f(filename.c_str(), FileRead);
        if(!f.isActive())
        {
            throw std::runtime_error("The script file '" + filename + "' was not found.");
        }
        
        f.seek(0, SeekEnd);
        unsigned int length = f.tell();
        f.seek(0, SeekStart);

        std::vector<char> buf(length);
        f.readRaw(buf.data(), length);

        std::string scriptname("@" + filename);
        if(luaL_loadbuffer(L, buf.data(), buf.size(), scriptname.c_str()) || lua_pcall(L, 0, LUA_MULTRET, 0))
        {
            throw std::runtime_error("Error found in script:\r\n" + std::string(lua_tostring(L, -1)));
        }
    }
bool ExportScript::FindExportedFunction( const char* name, unsigned args, unsigned& PC ) const
{
    const EScriptProgram* prog = uoexec.prog();
    for( unsigned i = 0; i < prog->exported_functions.size(); ++i )
    {
        if (stricmp( prog->exported_functions[i].name.c_str(), name ) == 0)
        {
            if (args != prog->exported_functions[i].nargs)
            {
                cout << "Exported function " << name 
                     << " in script " << scriptname() 
                     << " takes " << prog->exported_functions[i].nargs 
                     << " parameters, expected " << args << endl;
                return false;
            }
            PC = prog->exported_functions[i].PC;
            return true;
        }
    }
    return false;
}
Esempio n. 5
0
uint16 Script::getVideoRefString() {
	Common::String str;
	byte c;

	while ((c = readScript8bits())) {
		switch (c) {
		case 0x23:
			c = readScript8bits();
			c = _variables[c - 0x61] + 0x30;
			if (c >= 0x41 && c <= 0x5A) {
				c += 0x20;
			}
			break;
		case 0x7C:
			uint8 parta, partb;
			parta = readScriptChar(false, false, false);
			partb = readScriptChar(false, false, false);
			c = _variables[0x0A * parta + partb + 0x19] + 0x30;
			break;
		default:
			if (c >= 0x41 && c <= 0x5A) {
				c += 0x20;
			}
		}
		// Append the current character at the end of the string
		str += c;
	}

	// Add a trailing dot
	str += 0x2E;

	debugScript(0, false, "%s", str.c_str());

	// Extract the script name.
	Common::String scriptname(_scriptFile.c_str(), _scriptFile.size() - 4);

	// Get the fileref of the resource
	return _vm->_resMan->getRef(str, scriptname);
}
Esempio n. 6
0
Bscript::BObjectImp* UOExecutorModule::mf_PromptInput()
{
  Mobile::Character* chr;
  Items::Item* item;
  const Bscript::String* prompt;
  if ( !getCharacterParam( exec, 0, chr ) || !getItemParam( exec, 1, item ) ||
       !exec.getStringParam( 2, prompt ) )
  {
    return new Bscript::BError( "Invalid parameter" );
  }

  if ( chr->client == nullptr )
  {
    return new Bscript::BError( "No client attached" );
  }

  if ( chr->has_active_prompt() != false )
  {
    return new Bscript::BError( "Another script has an active prompt" );
  }

  if ( !uoexec.suspend() )
  {
    DEBUGLOG << "Script Error in '" << scriptname() << "' PC=" << exec.PC << ": \n"
             << "\tCall to function UO::RequestInput():\n"
             << "\tThe execution of this script can't be blocked!\n";
    return new Bscript::BError( "Script can't be blocked" );
  }

  Core::send_sysmessage( chr->client, prompt->data() );

  chr->client->gd->prompt_uoemod = this;
  prompt_chr = chr;

  Core::send_prompt( chr->client, ctBEu32( item->serial ) );

  return new Bscript::BLong( 0 );
}
Esempio n. 7
0
/*
 * Run an external script.
 * ask = 1 if first ask for confirmation.
 * s = scriptname, l=loginname, p=password.
 */
void runscript(int ask, const char *s, const char *l, const char *p)
{
  int status;
  int n, i;
  int pipefd[2];
  char buf[81];
  char scr_lines[5];
  char cmdline[128];
  struct pollfd fds[2];
  char *translated_cmdline;
  char *ptr;
  WIN *w;
  int done = 0;
  char *msg = _("Same as last");
  char *username = _(" A -   Username        :"******" B -   Password        :"******" C -   Name of script  :"),
       *question = _("Change which setting?     (Return to run, ESC to stop)");


  if (ask) {
    w = mc_wopen(10, 5, 70, 10, BDOUBLE, stdattr, mfcolor, mbcolor, 0, 0, 1);
    mc_wtitle(w, TMID, _("Run a script"));
    mc_wputs(w, "\n");
    mc_wprintf(w, "%s %s\n", username, scr_user[0] ? msg : "");
    mc_wprintf(w, "%s %s\n", password, scr_passwd[0] ? msg : "");
    mc_wprintf(w, "%s %s\n", name_of_script, scr_name);
    mc_wlocate(w, 4, 5);
    mc_wputs(w, question);
    mc_wredraw(w, 1);

    while (!done) {
      mc_wlocate(w, mbslen (question) + 5, 5);
      n = wxgetch();
      if (islower(n))
        n = toupper(n);
      switch (n) {
        case '\r':
        case '\n':
          if (scr_name[0] == '\0') {
            mc_wbell();
            break;
          }
          mc_wclose(w, 1);
          done = 1;
          break;
        case 27: /* ESC */
          mc_wclose(w, 1);
          return;
        case 'A':
          mc_wlocate(w, mbslen (username) + 1, 1);
          mc_wclreol(w);
          scr_user[0] = 0;
          mc_wgets(w, scr_user, 32, 32);
          break;
        case 'B':
          mc_wlocate(w, mbslen (password) + 1, 2);
          mc_wclreol(w);
          scr_passwd[0] = 0;
          mc_wgets(w, scr_passwd, 32, 32);
          break;
        case 'C':
          mc_wlocate(w, mbslen (name_of_script) + 1, 3);
          mc_wgets(w, scr_name, 32, 32);
          break;
        default:
          break;
      }
    }
  } else {
    strncpy(scr_user, l, sizeof(scr_user));
    strncpy(scr_name, s, sizeof(scr_name));
    strncpy(scr_passwd, p, sizeof(scr_passwd));
  }
  sprintf(scr_lines, "%d", (int) lines);  /* jl 13.09.97 */

  /* Throw away status line if temporary */
  if (tempst) {
    mc_wclose(st, 1);
    tempst = 0;
    st = NULL;
  }
  scriptname(scr_name);

  pipe(pipefd);

  if (mcd(P_SCRIPTDIR) < 0)
    return;

  snprintf(cmdline, sizeof(cmdline), "%s %s %s %s",
           P_SCRIPTPROG, scr_name, logfname, logfname[0]==0? "": homedir);

  switch (udpid = fork()) {
    case -1:
      werror(_("Out of memory: could not fork()"));
      close(pipefd[0]);
      close(pipefd[1]);
      mcd("");
      return;
    case 0: /* Child */
      dup2(portfd, 0);
      dup2(portfd, 1);
      dup2(pipefd[1], 2);
      close(pipefd[0]);
      close(pipefd[1]);

      for (n = 1; n < _NSIG; n++)
	signal(n, SIG_DFL);

      mc_setenv("LOGIN", scr_user);
      mc_setenv("PASS", scr_passwd);
      mc_setenv("TERMLIN", scr_lines);	/* jl 13.09.97 */
      translated_cmdline = translate(cmdline);

      if (translated_cmdline != NULL) {
        fastexec(translated_cmdline);
        free(translated_cmdline);
      }
      exit(1);
    default: /* Parent */
      break;
  }
  setcbreak(1); /* Cbreak, no echo */
  enab_sig(1, 0);	       /* But enable SIGINT */
  signal(SIGINT, udcatch);
  close(pipefd[1]);

  /* pipe output from "runscript" program to terminal emulator */
  fds[0].fd     = pipefd[0]; /* runscript */
  fds[0].events = POLLIN;
  fds[1].fd     = STDIN_FILENO; /* stdin */
  fds[1].events = POLLIN;
  script_running = 1;
  while (script_running && poll(fds, 2, -1) > 0)
    for (i = 0; i < 2; i++) {
      if (fds[i].revents & (POLLERR | POLLHUP | POLLNVAL))
        script_running = 0;
      else if ((fds[i].revents & POLLIN)
               && (n = read(fds[i].fd, buf, sizeof(buf)-1)) > 0) {
        ptr = buf;
        while (n--)
          if (i)
            vt_send(*ptr++);
          else
            vt_out(*ptr++);
        timer_update();
        mc_wflush();
      }
    }

  /* Collect status, and clean up. */
  m_wait(&status);
  enab_sig(0, 0);
  signal(SIGINT, SIG_IGN);
  setcbreak(2); /* Raw, no echo */
  close(pipefd[0]);
  scriptname("");
  mcd("");
}