// Actions performed before door shuts down void beforeExit() { // Tell the server this door node is exiting sendInput(NULL, IP_FORCE_EXIT); sendInput(NULL, IP_FINISHED); Sleep(2000); // Close the mailslots CloseHandle(hInputSlot); CloseHandle(hOutputSlot); }
bool KGameKeyIO::eventFilter( QObject *o, QEvent *e ) { if (!player()) { return false; } // key press/release if ( e->type() == QEvent::KeyPress || e->type() == QEvent::KeyRelease ) { QKeyEvent *k = (QKeyEvent*)e; // qCDebug(GAMES_PRIVATE_KGAME) << "KGameKeyIO" << this << "key press/release" << k->key(); QByteArray buffer; QDataStream stream(&buffer,QIODevice::WriteOnly); bool eatevent=false; emit signalKeyEvent(this,stream,k,&eatevent); QDataStream msg(buffer); if (eatevent && sendInput(msg)) { return eatevent; } return false; // do not eat otherwise } return QObject::eventFilter( o, e ); // standard event processing }
bool BlackBot::step(R dt) { const Player &me(client.getPlayers()[pid]); // walk forward cinput.y=1; cinput.devno=inputID; if (followMode) follow(); reachDir(); sendInput(); return true; }
TextInput::TextInput(QWidget* parent) : QLineEdit(parent) { setAttribute(Qt::WA_MacShowFocusRect, false); d.hint = "..."; d.index = 0; d.buffer = 0; d.parser = 0; d.completer = new IrcCompleter(this); connect(this, SIGNAL(bufferChanged(IrcBuffer*)), d.completer, SLOT(setBuffer(IrcBuffer*))); connect(this, SIGNAL(parserChanged(IrcCommandParser*)), d.completer, SLOT(setParser(IrcCommandParser*))); connect(d.completer, SIGNAL(completed(QString,int)), this, SLOT(doComplete(QString,int))); connect(this, SIGNAL(textEdited(QString)), d.completer, SLOT(reset())); connect(this, SIGNAL(returnPressed()), this, SLOT(sendInput())); connect(this, SIGNAL(textChanged(QString)), this, SLOT(updateHint(QString))); }
void Game::update(sf::Time dt) { switch(state) { case State::MENU: break; case State::CHARGEMENT: loading.update(dt); break; case State::JEU : if(!chat.isActive()) { testInput(); } else { playerInput.MoveUp = playerInput.MoveDown = playerInput.MoveLeft = playerInput.MoveRight = playerInput.aAttack = playerInput.eAttack = false; } if(pingTimer.asSeconds() >= 1) { sf::Packet packet; packet << NetworkValues::PING << ++pingId; informationSocket.send(packet); pingTimer -= sf::seconds(1.f); } else { pingTimer += dt; } pingCounter += dt; sendInput(); receivePacket(); receiveInformationPacket(); world.update(dt); chat.update(); break; } if(timeOutTimer >= timeOut) { std::cout << "Connection timed out" << std::endl; running = false; } }
void KGameIO::notifyTurn(bool b) { if (!player()) { qCWarning(GAMES_PRIVATE_KGAME) << ": player() is NULL"; return; } bool sendit=false; QByteArray buffer; QDataStream stream(&buffer, QIODevice::WriteOnly); emit signalPrepareTurn(stream, b, this, &sendit); if (sendit) { QDataStream ostream(buffer); quint32 sender = player()->id(); // force correct sender qCDebug(GAMES_PRIVATE_KGAME) << "Prepare turn sendInput"; sendInput(ostream, true, sender); } }
//void KGameProcessIO::clientMessage(const QByteArray& receiveBuffer, quint32 clientID, const QValueList <quint32> &recv) void KGameProcessIO::receivedMessage(const QByteArray& receiveBuffer) { QDataStream stream(receiveBuffer); int msgid; quint32 sender; quint32 receiver; KGameMessage::extractHeader(stream,sender,receiver,msgid); qCDebug(GAMES_PRIVATE_KGAME) << "************* Got process message sender =" << sender << "receiver=" << receiver << " msgid=" << msgid; // Cut out the header part...to not confuse network code QBuffer *buf=(QBuffer *)stream.device(); QByteArray newbuffer; newbuffer = QByteArray::fromRawData(buf->buffer().data()+buf->pos(),buf->size()-buf->pos()); QDataStream ostream(newbuffer); qCDebug(GAMES_PRIVATE_KGAME) << "Newbuffer size=" << newbuffer.size(); // This is a dummy message which allows us the process to talk with its owner if (msgid==KGameMessage::IdProcessQuery) { emit signalProcessQuery(ostream,this); } else if (player()) { sender = player()->id(); // force correct sender if (msgid==KGameMessage::IdPlayerInput) { sendInput(ostream,true,sender); } else { player()->forwardMessage(ostream,msgid,receiver,sender); } } else { qCDebug(GAMES_PRIVATE_KGAME) << ": Got message from process but no player defined!"; } newbuffer.clear(); }
// Gets input, checks it for certain globals, and sends it to the door server if not a global. void performIO() { char szString[241]; static char szOldString[241] = ""; extern short fhInput1; // Call getInput() to wait for and handle the player's input; this function also handles grabbing output // from the mailslot and printing it when appropriate getInput(szString, 190); // If user typed repeat command if ( strcmpi(szString, "!") == 0 || strcmpi(szString, "=r") == 0 ) { strcpy(szString, szOldString); local(szOldString, WHITE); } strcpy(szOldString, szString); // If user typed Who's Online in Synchronet version if ( getPlatform() == PL_XSDK32 && (strcmpi(szString, "#") == 0 || strcmpi(szString, "=#") == 0) ) { listOnlineUsers(); local(" "); bPromptOnScreen = false; fixStatline(); return; } // If user wanted to instantly exit if ( strcmpi(szString, "=x") == 0 ) exitDoor(0); // Send the input. sendInput(szString); // Since the previous prompt was answered, attempt to invalidate it. // This call will intentionally have no effect if the prompt is a combat/statline prompt. invalidatePrompt(); }
FGFSTelnetDialog::FGFSTelnetDialog(QObject* parent){ QVBoxLayout *layout = new QVBoxLayout(); layout->addWidget((textEdit = new QTextEdit)); layout->addWidget((lineEdit = new QLineEdit)); layout->addWidget((connectButton = new QPushButton(tr("Connect")))); layout->addWidget((statusLabel = new QLabel(tr("öff")))); connectButton->setCheckable(true); connectButton->setDefault (false); // should be default http://doc.trolltech.com/4.2/qpushbutton.html connectButton->setAutoDefault (false); // grrr textEdit->setReadOnly (true); textEdit->setEnabled(true); lineEdit->setEnabled(false); connect (connectButton, SIGNAL(toggled(bool)), this, SIGNAL (connect_checked(bool))); connect (lineEdit, SIGNAL(returnPressed()), this, SLOT(sendInput())); setLayout(layout); setWindowTitle(tr("FGFS Telnet Example")); data.reserve(1024); }
bool KGameMouseIO::eventFilter( QObject *o, QEvent *e ) { if (!player()) { return false; } //qCDebug(GAMES_PRIVATE_KGAME) << "KGameMouseIO" << this << QLatin1String( " " ) << e->type(); // mouse action if ( e->type() == QEvent::MouseButtonPress || e->type() == QEvent::MouseButtonRelease || e->type() == QEvent::MouseButtonDblClick || e->type() == QEvent::Wheel || e->type() == QEvent::MouseMove || e->type() == QEvent::GraphicsSceneMousePress || e->type() == QEvent::GraphicsSceneMouseRelease || e->type() == QEvent::GraphicsSceneMouseDoubleClick || e->type() == QEvent::GraphicsSceneWheel || e->type() == QEvent::GraphicsSceneMouseMove ) { QMouseEvent *k = (QMouseEvent*)e; // qCDebug(GAMES_PRIVATE_KGAME) << "KGameMouseIO" << this; QByteArray buffer; QDataStream stream(&buffer,QIODevice::WriteOnly); bool eatevent=false; emit signalMouseEvent(this,stream,k,&eatevent); // qCDebug(GAMES_PRIVATE_KGAME) << "################# eatevent=" << eatevent; QDataStream msg(buffer); if (eatevent && sendInput(msg)) { return eatevent; } return false; // do not eat otherwise } return QObject::eventFilter( o, e ); // standard event processing }
void GestureMoveRight::action() { //sendInput(0x0020);//space sendInput(0xff08);//backspace cout << "move right" << endl; }
void AriaClientDriver::controlloop(){ ros::Rate myLoopRate(10); sendInput(); ros::spinOnce(); myLoopRate.sleep(); }
void ClientUserInputHandler::defaultHandler(const QString &cmd, const BufferInfo &bufferInfo, const QString &text) { QString command = QString("/%1 %2").arg(cmd, text); emit sendInput(bufferInfo, command); }
int main(){ std::cout << "---------------------------------\n"; std::cout << "----- Lifeline test station -----\n"; std::cout << "-- Press ESC to clear screen ----\n"; std::cout << "-- Press enter to send ----------\n"; std::cout << "-- Press R to record ------------\n"; std::cout << "---------------------------------\n"; char* symbolbuffer = 0; unsigned int symbolbuffersize = 0; std::ifstream file("symbols.data", std::ifstream::binary); if( file.is_open() == false ){ std::cout << "Unable to open symbol database\n"; }else{ file.seekg(0, std::ios::end); symbolbuffersize = file.tellg(); file.seekg(0, std::ios::beg); symbolbuffer = new char[symbolbuffersize]; file.read(symbolbuffer, symbolbuffersize); file.close(); } if( symbolbuffer ){ recognizer.loadSymbolsFromMemory(symbolbuffer, symbolbuffersize); } window = new sf::RenderWindow(sf::VideoMode(900, 400, 32), "Testing Station"); timer = new sf::Clock; sf::Event Event; State = StateNothing; mouseDown = false; strokeList.clear(); timer->restart(); while( window->isOpen() ){ while(window->pollEvent(Event)) { switch( Event.type ){ case sf::Event::KeyPressed: break; case sf::Event::KeyReleased: switch( State ){ case StateNothing: if( Event.key.code == sf::Keyboard::Escape ){ if( strokeList.empty() ) window->close(); else strokeList.clear(); }else if( Event.key.code == sf::Keyboard::Return ){ sendInput(); strokeList.clear(); }else if( Event.key.code == sf::Keyboard::R ){ State = StateChoosingSymbol; std::cout << "Now press the key of the symbol you want to record features for. (A-Z)\n"; } break; case StateChoosingSymbol: if( Event.key.code == sf::Keyboard::Escape ){ State = StateNothing; std::cout << "Recording canceled.\n"; }else if( Event.key.code >= sf::Keyboard::A && Event.key.code <= sf::Keyboard::Z ){ symbol = 'A' + Event.key.code - sf::Keyboard::A; //recognizer_clear_samples(&recognizer); State = StateRecording; std::cout << "Recording symbol: " << symbol << "\n"; std::cout << "Press Enter after drawing each symbol. Press ESC when done.\n"; }else{ std::cout << "Invalid key, only A-Z supported\n"; } break; case StateRecording: if( Event.key.code == sf::Keyboard::Escape ){ if( strokeList.empty() ){ State = StateNothing; char symbolstring[2] = {symbol, 0}; //recognizer_save_samples(&recognizer, symbolstring); //The file buffer has been changed. Write it to the file if( symbolbuffer ){ std::ofstream file("symbols.data", std::ifstream::binary); if( file.is_open() == false ){ std::cout << "Unable to open symbol database\n"; }else{ file.write(symbolbuffer, symbolbuffersize); file.close(); std::cout << "Symbol file has been updated.\n"; } } std::cout << "Recording finished.\n"; }else{ strokeList.clear(); } }else if( Event.key.code == sf::Keyboard::Return ){ sendInput(); strokeList.clear(); } break; default: break; } break; case sf::Event::MouseWheelMoved: break; case sf::Event::MouseMoved: mouseMoved( Event.mouseMove.x, Event.mouseMove.y ); break; case sf::Event::MouseButtonPressed: mousePress( Event.mouseButton.button, true, Event.mouseButton.x, Event.mouseButton.y ); break; case sf::Event::MouseButtonReleased: mousePress( Event.mouseButton.button, false, Event.mouseButton.x, Event.mouseButton.y ); break; case sf::Event::Closed: window->close(); break; default: break; } } window->clear(sf::Color(170,220, 250)); // const sf::Shader* shader = sf::RenderStates::Default.shader; // shader->setParameter("color", sf::Color(0, 0, 0, 255)); sf::RenderStates states; if( strokeList.empty() == false ){ for( std::vector< std::vector<Touch> >::iterator lineIter = strokeList.begin(); lineIter != strokeList.end(); ++lineIter ){ if( lineIter->empty() ) continue; float prevX, prevY; std::vector<Touch>::iterator iter = lineIter->begin(); prevX = iter->x; prevY = iter->y; ++iter; while(iter != lineIter->end()){ sf::Vertex line[2] = { sf::Vertex(sf::Vector2<float>(prevX, prevY), sf::Color::Black), sf::Vertex(sf::Vector2<float>(iter->x, iter->y), sf::Color::Black) }; window->draw(line, 2, sf::Lines); prevX = iter->x; prevY = iter->y; ++iter; } } } #ifdef LDEBUG int n = recognizer.getImageDimension(); Lifeline::GridPoint *grid = recognizer.getImageGrid(); if( grid ){ const int px = 5; sf::RectangleShape rect; rect.setOrigin(sf::Vector2<float>(10, 10)); rect.setSize(sf::Vector2<float>(px*n+30, px*n+30)); rect.setFillColor(sf::Color(255,255,255)); window->draw(rect); sf::Color pixelColor; for(int i = 0; i < n; ++i) { for(int j = 0; j < n; ++j) { Lifeline::GridPoint& gridPoint = grid[i*n+j]; if( gridPoint.enabled ){ int color = gridPoint.type; //if( color == 0 && gridPoint.dummy == 0 && gridPoint.curvature == 0) pixelColor = sf::Color(120,120,120); //if( color == 0 && gridPoint.dummy == 0 && gridPoint.curvature == 1) pixelColor = sf::Color(255, 255, 0); //if( color == 0 && gridPoint.dummy == 0 && gridPoint.curvature == 2) pixelColor = sf::Color(255, 165, 0); //if( color == 0 && gridPoint.dummy == 0 && gridPoint.curvature == 3) pixelColor = sf::Color(255, 69, 0); if( color == 1 && gridPoint.dummy == 0) pixelColor = sf::Color(255,0,0); else if( color == 2 && gridPoint.dummy == 0) pixelColor = sf::Color(0,0,255); else if( color == 3 && gridPoint.dummy == 0) pixelColor = sf::Color(0,255,0); else if(color == 0 && gridPoint.dummy == 1) pixelColor = sf::Color(124, 252, 0); else if(color == 1 && gridPoint.dummy == 1) pixelColor = sf::Color(124, 252, 0); else if(color == 2 && gridPoint.dummy == 1) pixelColor = sf::Color(124, 252, 0); else if(color == 3 && gridPoint.dummy == 1) pixelColor = sf::Color(124, 252, 0); else if(color == 0 && gridPoint.dummy == 2) pixelColor = sf::Color(255,255,0); else if(color == 1 && gridPoint.dummy == 2) pixelColor = sf::Color(255,255,0); else if(color == 2 && gridPoint.dummy == 2) pixelColor = sf::Color(255,255,0); else if(color == 3 && gridPoint.dummy == 2) pixelColor = sf::Color(255,255,0); else if(color == 0 && gridPoint.dummy == 3) pixelColor = sf::Color(40,79,79); else if(color == 1 && gridPoint.dummy == 3) pixelColor = sf::Color(40,79,79); else if(color == 2 && gridPoint.dummy == 3) pixelColor = sf::Color(40,79,79); else if(color == 3 && gridPoint.dummy == 3) pixelColor = sf::Color(40,79,79); rect.setOrigin(sf::Vector2<float>(-(20 + px*j), -(20 + px*i))); rect.setSize(sf::Vector2<float>(px, px)); rect.setFillColor(pixelColor); window->draw(rect); } } } } #endif window->display(); sf::sleep(sf::milliseconds(20)); } if( symbolbuffer ) { recognizer.freeSymbols(symbolbuffer); delete[] symbolbuffer; } delete window; return 0; }
void User::update(float deltaSeconds) { m_unit.update(deltaSeconds); sendInput(); }
void main(int argc, char *argv[]) #endif { char szText[160]; bool bSuccess; short nTries = 0; // Set results of what happens when a call to new fails set_new_handler(badNew); // Call the startup function #ifdef OD32 startup(lpszCmdLine); #else startup(argc, argv); #endif Sleep(500); do { // Attempt to start up the door server process. (No need to check if the door server process is already // running; it does that on its own and shuts down extra copies as needed) bSuccess = CreateProcess(DOOR_SERVER_EXE, NULL, NULL, NULL, false, DETACHED_PROCESS, NULL, NULL, new STARTUPINFO, new PROCESS_INFORMATION); Sleep(1000); nTries++; } while ( bSuccess == false && nTries < 5 ); // Get a handle on the door server's input mailslot hInputSlot = openSlot(-1); // Create this node's output mailslot. hOutputSlot = createSlot( getNode() ); // If unable to open input slot, re-try up to 5 times (intial failure seems to happen on WinXP randomly) // If still failure, this indicates the door server is not running and could not be started, so shut down. nTries = 0; while (hInputSlot == INVALID_HANDLE_VALUE ) { Sleep(500); hInputSlot = openSlot(-1); if ( ++nTries > 5 ) { local("Unable to start door: IPC error"); exitDoor(1); } } // If the output slot for this node is already open, it means the node is already running the door. if ( hOutputSlot == INVALID_HANDLE_VALUE ) { local("Unable to start door: This node is already in use!"); pausePrompt(); exitDoor(1); } // Now that the mailslot handles were successful, call setupExitFunction() to register beforeExit() as the // function called upon exit. setupExitFunction(); // Send an input message to the server, to tell it a user is trying to enter the game. The user's info is // passed as a string in the format below. sprintf(szText, "%d&%c&%d&%s&%s", isSysop(), getGender(), getPlatform(), getAlias(), getRealName()); sendInput(szText, IP_ENTER_GAME); // Handle I/O for the user while (1) { performIO(); } }