Esempio n. 1
0
void
CommandEventHandler::handleTimeout()
{
  if (mDataEventHandler && !mDataEventHandler->closed())
    mDataEventHandler->handleTimeout();
  if (mDataEventHandler->closed())
  {
    delete mDataEventHandler;
    mDataEventHandler = NULL;
    sendPrompt();
  }
}
Esempio n. 2
0
// Send the string in 'out' to a player's output queue.
void Player::sendToPlayer(String out, ...) {
	char buffer[4096];
	va_list args;


	va_start(args, out);

	vsnprintf(buffer, 4096, out.c_str(), args);

	va_end(args);

	if(atPrompt)
		output("\r\n");
	output(buffer);
	sendPrompt();
}
Esempio n. 3
0
bool
CommandEventHandler::checkDataEventHandler(PRPollDesc desc)
{
  if (!closed() && mDataEventHandler)
  {
    if (!mDataEventHandler->closed())
      mDataEventHandler->handleEvent(desc);
    if (mDataEventHandler->closed())
    {
      delete mDataEventHandler;
      mDataEventHandler = NULL;
      sendPrompt();
      return false;
    }
    return true;
  }
  return false;
}
Esempio n. 4
0
void Console::addClient()
{
    struct sockaddr client;
    socklen_t client_len;

    /* new client */
    client_len = sizeof( client );
    int fd = accept(_listenfd, (struct sockaddr *)&client, &client_len );

    // add fd to list of FD
    if( fd != -1 ) {
        FD_SET(fd, &_read_set);
        _fds.push_back(fd);
        _maxfd = std::max(_maxfd,fd);

        sendPrompt(fd);
    }
}
Esempio n. 5
0
bool Console::parseCommand(int fd)
{
    auto r = readline(fd);
    if(r < 1)
        return false;

    bool found=false;
    for(int i=0; i < _maxCommands; ++i) {
        if( strncmp(_buffer, _commands[i].name,strlen(_commands[i].name)) == 0 ) {
            // XXX TODO FIXME
            // Ideally this loop should execute the function in the cocos2d according to a variable
            // But clang crashes in runtime when doing that (bug in clang, not in the code).
            // So, unfortunately, the only way to fix it was to move that logic to the callback itself
            _commands[i].callback(fd, _buffer);
            found = true;
            break;
        }
    }

    // user commands
    for(int i=0; i < _maxUserCommands && !found; ++i) {
        if( strncmp(_buffer, _userCommands[i].name,strlen(_userCommands[i].name)) == 0 ) {
            _userCommands[i].callback(fd, _buffer);
            found = true;
            break;
        }
    }

    if(!found && strcmp(_buffer, "\r\n")!=0) {
        const char err[] = "Unknown command. Type 'help' for options\n";
        write(fd, err, sizeof(err));
    }

    sendPrompt(fd);

    return true;
}
Esempio n. 6
0
//a one line colorless error message followed by \r\n and prompt
void Client::sendError(const QString &aText)
{
	sendRawText(aText);
	sendEOL();
	sendPrompt();
}
Esempio n. 7
0
CommandEventHandler::CommandEventHandler(PRFileDesc* socket)
  : mBufSocket(socket), mDataEventHandler(NULL), mPrompt("$>")
{
  registerWithReactor();
  sendPrompt();
}