예제 #1
0
void BotThread::registerStep(QScriptValue function, int frec)
{
    if(function.isFunction())
    {
        m_steps.append(new BotStep(function,frec));
        calcDelay();
    }
}
예제 #2
0
void startServer()
/* Start up bottleneck server. */
{
int acceptor;
unsigned char parsedSubnetBuf[4];	/* Buffer for holding parsed subnet. */
unsigned char *parsedSubnet = NULL;	/* Parsed subnet. */
if (subnet != NULL)
    {
    internetParseDottedQuad(subnet, parsedSubnetBuf);
    parsedSubnet = parsedSubnetBuf;
    }
trackerHash = newHash(18);
acceptor = netAcceptingSocket(port, 64);
for (;;)
    {
    struct tracker *tracker;
    int socket = netAcceptFrom(acceptor, parsedSubnet);
    char buf[256], *s;
    s = netGetString(socket, buf);
    if (s != NULL)
	{
	now = time(NULL);
	if (s[0] == '?')
	    {
	    if (s[1] == 0)
		forkOutList(socket);
	    else
	        {
		char *command = nextWord(&s);
		if (sameString(command, "?set"))
		    {
		    char *ip = nextWord(&s);
		    char *millis = nextWord(&s);
		    if (millis != NULL)
		        {
			tracker = trackerForIp(ip);
			tracker->curDelay = atoi(millis) - penalty;
			tracker->lastAccess = now;
			}
		    }
		}
	    }
	else
	    {
	    tracker = trackerForIp(s);
	    tracker->accessCount += 1;
	    tracker->curDelay = calcDelay(tracker);
	    if (tracker->maxDelay < tracker->curDelay)
	        tracker->maxDelay = tracker->curDelay;
	    tracker->lastAccess = now;
	    safef(buf, sizeof(buf), "%d", tracker->curDelay);
	    netSendString(socket, buf);
	    }
	}
    close(socket);
    }
}
예제 #3
0
void returnList(int socket)
/* Send list of all things tracked down socket. */
{
struct tracker *tracker;
char buf[256];
int timeDiff;
safef(buf, sizeof(buf), "#IP_ADDRESS\thits\ttime\tmax\tcurrent");
netSendString(socket, buf);
for (tracker = trackerList; tracker != NULL; tracker = tracker->next)
    {
    timeDiff = now - tracker->lastAccess;
    safef(buf, sizeof(buf), "%s\t%d\t%d\t%d\t%d", 
    	tracker->name, tracker->accessCount, timeDiff, 
	tracker->maxDelay, calcDelay(tracker));
    if (!netSendString(socket, buf))
        break;
    }
netSendString(socket, "");
}
예제 #4
0
void BotThread::registerStep(std::function<void()> function, int frec)
{
    m_steps.append(new BotStep(function,frec));
    calcDelay();
}
예제 #5
0
void EventOutputQueue::fire_timer_callback(OSObject* /* owner */, IOTimerEventSource* /* sender */) {
  // We need to cancelEventOutputQueueItems in fire_timer_callback
  // in order to cancel key repeat and __HoldingKeyToKey__ events.
  RemapClassManager::cancelEventOutputQueueItems();

  // Delete canceled items.
  Item* p = nullptr;

  p = static_cast<Item*>(queue_.safe_front());
  while (p) {
    if (p->isCanceled()) {
      p = static_cast<Item*>(queue_.erase_and_delete(p));
    } else {
      p = static_cast<Item*>(p->getnext());
    }
  }

  // ------------------------------------------------------------
  // Send key event.
  p = static_cast<Item*>(queue_.safe_front());
  if (!p) return;

  // Delay after modifier or click.
  unsigned int delay = calcDelay(p->getParamsBase());

  // ----------------------------------------
  {
    auto params = (p->getParamsBase()).get_Params_KeyboardEventCallBack();
    if (params) {
      bool handled = VirtualKey::handleAfterEnqueued(*params);
      if (!handled) {
        ListHookedKeyboard::instance().apply(*params);
      }

      // We need to wait at least 1ms in order to avoid changing key sequence order randomly.
      // (If VMware Fusion's driver is installed, the wrong order issue will be happen.)
      delay = maxDelay(delay, 1);
    }
  }
  {
    auto params = (p->getParamsBase()).get_Params_UpdateEventFlagsCallback();
    if (params) {
      // We need to wait at least 1ms in order to avoid changing key sequence order randomly.
      // (If VMware Fusion's driver is installed, the wrong order issue will be happen.)
      delay = maxDelay(delay, 1);
    }
  }
  {
    auto params = (p->getParamsBase()).get_Params_KeyboardSpecialEventCallback();
    if (params) {
      if (!ListHookedConsumer::instance().apply(*params)) {
        // If there is no consumer device, we send an event as a software key.
        VirtualKey::VK_IOHIDPOSTEVENT::post(*params);
      }

      // We need to wait at least 1ms in order to avoid changing key sequence order randomly.
      // (If VMware Fusion's driver is installed, the wrong order issue will be happen.)
      delay = maxDelay(delay, 1);
    }
  }
  {
    auto params = (p->getParamsBase()).get_Params_RelativePointerEventCallback();
    if (params) {
      ListHookedPointing::instance().apply(*params);
    }
  }
  {
    auto params = (p->getParamsBase()).get_Params_ScrollWheelEventCallback();
    if (params) {
      ListHookedPointing::instance().apply(*params);
    }
  }
  {
    auto params = (p->getParamsBase()).get_Params_Wait();
    if (params) {
      delay = maxDelay(delay, static_cast<unsigned int>(params->milliseconds));
    }
  }

  queue_.pop_front();

  // ----------------------------------------
  // Set timeout for next event.

  // Delay before modifier and click.
  Item* next = static_cast<Item*>(queue_.safe_front());
  if (!next) return;
  delay = maxDelay(delay, calcDelay(next->getParamsBase()));

  fire_timer_.setTimeoutMS(delay);
}