bool zoSms::getPacketWire(ZO_PROTOCOL_PACKET* packet) { uint8_t i; if( i2cPacketReceived ) { enterCritical(); //copy buffered packet packet->addressedNodeID = BufferedPacket.addressedNodeID; packet->ownNodeID = BufferedPacket.ownNodeID; packet->commandID = BufferedPacket.commandID; packet->byteCount = BufferedPacket.byteCount; packet->lrc = BufferedPacket.lrc; for(i=0;i<packet->byteCount;i++) packet->data[i] = BufferedPacket.data[i]; //indicate received packet was used i2cPacketReceived = false; exitCritical(); return true; } else return false; }
const TypeFile *TypeDir::file(const std::string &name) const { enterCritical(); auto it = std::find(m_files.begin(), m_files.end(), name); leaveCritical(); if (it == m_files.end()) return nullptr; return &*it; }
bool getReceivalOfPacketStarted(void) { bool returnVal; enterCritical(); returnVal = PacketRxStarted; exitCritical(); return returnVal; }
bool TypeDir::removeDir(const TypeDir &dir) { enterCritical(); auto it = std::find(m_dirs.begin(), m_dirs.end(), dir); if (it == m_dirs.end()) { leaveCritical(); return false; } m_dirs.erase(it); leaveCritical(); return true; }
bool TypeDir::removeFile(const TypeFile &file) { enterCritical(); auto it = std::find(m_files.begin(), m_files.end(), file); if (it == m_files.end()) { leaveCritical(); return false; } m_files.erase(it); leaveCritical(); return true; }
bool TypeDir::replaceFile(const TypeFile &oldfile, const TypeFile &newfile) { enterCritical(); auto it = std::find(m_files.begin(), m_files.end(), oldfile); if (it == m_files.end()) { leaveCritical(); return false; } m_files.erase(it); m_files.insert(newfile); leaveCritical(); return true; }
void XFTimeoutManager::addTimeout(XFTimeout * pNewTimeout) { enterCritical(); if (!_timeouts.empty()) { // Insert timeout before timeout(s) triggering later TimeoutList::iterator i = _timeouts.begin(); if ((*i)->_relTicks >= pNewTimeout->_relTicks) { // A new timeout at the beginning _timeouts.push_front(pNewTimeout); // Remove time from following timeout (*i)->_relTicks -= pNewTimeout->_relTicks; } else { unsigned int index = 0; // Remove time from new timeout pNewTimeout->_relTicks -= (*i)->_relTicks; i++; index++; while (i != _timeouts.end() && (*i)->_relTicks < pNewTimeout->_relTicks) { pNewTimeout->_relTicks -= (*i)->_relTicks; i++; index++; } // Insert new timeout before i = _timeouts.insert(i, pNewTimeout); if (_timeouts.size() > index + 1) { // Remove time from following timeout i++; assert(i != _timeouts.end()); (*i)->_relTicks -= pNewTimeout->_relTicks; } } } else { _timeouts.push_front(pNewTimeout); } exitCritical(); }
// Repeatedly read input from the input slot. // Returns when last player exits game. void GameServer::run() { DWORD nNextMessageSize, nMessagesLeft, nBytesRead; InputData idMessage; char szBuffer[245]; // Call randomize() in the GameServer's operational thread (usually same thread as main()) myRandomize(); while ( true ) { nMessagesLeft = 0; nNextMessageSize = MAILSLOT_NO_MESSAGE; // Check the status of the slot. GetMailslotInfo(hInputSlot, NULL, &nNextMessageSize, &nMessagesLeft, NULL); // If there's no input, sleep and then return to top of loop. if ( nNextMessageSize == MAILSLOT_NO_MESSAGE ) { Sleep(100); continue; } // If there's a message, read it and process it. if ( nMessagesLeft > 0 ) { // Ignore invalid message sizes (see MS Knowledge Base Q192276) if ( nNextMessageSize < 0 || nNextMessageSize > 500 ) continue; ReadFile(hInputSlot, szBuffer, nNextMessageSize, &nBytesRead, NULL); idMessage = szBuffer; enterCritical(); handleInput(idMessage); leaveCritical(); // If last player just exited, shut down the server. if ( idMessage.nType == IP_FINISHED && nPlayersInGame == 0 ) { CloseHandle(hInputSlot); DeleteCriticalSection(&csCritical); return; } } } }
/** * Removes all timeouts corresponding the given parameters. */ void XFTimeoutManager::removeTimeouts(int timeoutId, IXFReactive * pReactive) { const XFTimeout timeout(timeoutId, 0, pReactive); XFTimeout * pTimeout; enterCritical(); for (TimeoutList::iterator i = _timeouts.begin(); i != _timeouts.end();) { pTimeout = *i; // Check if behavior and timeout id are equal if (*pTimeout == timeout) { TimeoutList::iterator next = i; // Check if remaining ticks can be given further if (++next != _timeouts.end()) { // Add (remaining) ticks to next timeout in list (*next)->_relTicks += pTimeout->_relTicks; } i = _timeouts.erase(i); delete pTimeout; } else { i++; } } exitCritical(); }
void TypeDir::addFile(const TypeFile &file) { enterCritical(); m_files.insert(file); leaveCritical(); }
void TypeDir::addDir(const TypeDir &dir) { enterCritical(); m_dirs.insert(dir); leaveCritical(); }
// Processes input messages and redirects them to the proper node thread. void GameServer::handleInput(InputData idMessage) { // If message is from a totally out-of-range node number, ignore it. if ( idMessage.nFrom < 0 || idMessage.nFrom >= MAX_NODE ) return; // If an enter-game message: if ( idMessage.nType == IP_ENTER_GAME ) { if ( gNode[idMessage.nFrom] != NULL ) { gNode[idMessage.nFrom]->print("Error: Node already in game. Please wait 5 seconds and re-enter game."); gNode[idMessage.nFrom]->exitGame(); return; } // Create the new node and then return. Start round thread if needed. Verify the player isn't a dupe. nPlayersInGame++; addNode(idMessage.nFrom, idMessage.szMessage); if ( nPlayersInGame == 1 ) _beginthread(startRoundThread, 4096, this); for ( short n = 0; n < MAX_NODE; n++ ) { if ( gNode[n] == NULL || n == idMessage.nFrom ) continue; if ( strcmpi(gNode[n]->szRealName, gNode[idMessage.nFrom]->szRealName) == 0 ) { gNode[idMessage.nFrom]->print("You are on-line on multiple nodes!\r\nPlease wait 5 seconds and re-enter the game."); gNode[n]->print("You are on-line on multiple nodes!\r\nPlease wait 5 seconds and re-enter the game."); gNode[idMessage.nFrom]->exitGame(); gNode[n]->exitGame(); } } return; } // If input is from an invalid node, ignore it. if ( gNode[idMessage.nFrom] == NULL ) return; // If an exit-game message: if ( idMessage.nType == IP_FINISHED ) { // Kill the node. If the node has a thread, wait until the // thread is terminated (by a IP_FORCE_EXIT) before proceeding. while ( gNode[idMessage.nFrom]->bHasThread ) { leaveCritical(); Sleep(200); enterCritical(); } CloseHandle(gNode[idMessage.nFrom]->hOutputSlot); delete gNode[idMessage.nFrom]; gNode[idMessage.nFrom] = NULL; nPlayersInGame--; return; } // Otherwise, message is IP_NORMAL or IP_FORCE_EXIT. In either case, route the // InputData to the appropriate node, and let the node's thread take care of it. // If not using separate threads for each node, have an outside function handle // the message instead. if ( gNode[idMessage.nFrom]->bHasThread ) gNode[idMessage.nFrom]->mqInput.enqueue(idMessage); else centralInput(idMessage); }
void setReceivalOfPacketStarted(bool trueFalse) { enterCritical(); PacketRxStarted = trueFalse; exitCritical(); }