void CFuncMachinegun::CheckSpawn( void ) { CBaseEntity *pFound = NULL; while ((pFound = UTIL_FindEntityInSphere(pFound, pev->oldorigin, 50)) != NULL) { if (pFound->IsPlayer() && pFound->IsAlive()) { pev->nextthink = gpGlobals->time + 1; return; } ReSpawn(); } }
void CZombie :: RunTask ( Task_t *pTask ) { switch ( pTask->iTask ) { case TASK_CHECK_FOR_NOBODY_AROUND: { CBaseEntity *pEnt = NULL; while (pEnt = UTIL_FindEntityInSphere(pEnt, pev->origin + Vector(0, 0, 20), 18)) { if (pEnt->edict() == edict()) continue; if (!pEnt->IsAlive()) continue; if (pEnt->pev->solid == SOLID_NOT || pEnt->pev->solid == SOLID_TRIGGER) continue; return; } TaskComplete(); } break; case TASK_AWAKE_FROM_DEAD: { if ( pev->frame >= 255 ) { ReSpawn(); TaskComplete(); } } break; default: CBaseMonster::RunTask(pTask); break; } }
void TClient::OnDataReceived(const QByteArray &data) { EPacketType packetType; quint16 packedDataSize; quint16 originDataSize; QByteArray content; QByteArray receivedPacket = data; const int midSize = sizeof(quint16); const int posOrigin = sizeof(char); const int posPacked = posOrigin + midSize; const int posContent = posPacked + midSize; try { while (receivedPacket.size() > 0) { packetType = (EPacketType)(char)(receivedPacket[0]); originDataSize = qFromBigEndian<quint16>( (const uchar*)receivedPacket.mid(posOrigin, midSize).constData()); packedDataSize = qFromBigEndian<quint16>( (const uchar*)receivedPacket.mid(posPacked, midSize).constData()); content = qUncompress(receivedPacket.mid(posContent, packedDataSize)); if( content.isEmpty() && (originDataSize || packedDataSize) ) throw UException("Wrong packet: cannot unpack data"); // Retrieve another packet from current. // We can receive more than one packet at once receivedPacket = receivedPacket.mid( packedDataSize + sizeof(char) + 2*midSize); switch (packetType) { case PT_Control: { if (!(PlayerStatus == PS_Spawned || PlayerStatus == PS_Dead)) { throw UException("Player not spawned!"); } Epsilon5::Control control; if (control.ParseFromArray(content.data(), content.size())) { size_t currentPacket = control.packet_number(); if (control.has_need_full()) { if (control.need_full()) { Server()->NeedFullPacket(Id); } } Server()->Application()->GetWorld()->SetPingForPlayer(Id, currentPacket); SetSeen(); emit ControlReceived(control); } else { throw UException("Parse error: control packet"); } } break; case PT_PlayerAuth: { if (PlayerStatus != PS_AuthWait) { throw UException("Player not waiting for auth!"); } Epsilon5::Auth auth; if (auth.ParseFromArray(content.data(), content.size())) { try { SetSeen(); NickName = auth.name().c_str(); SendPlayerInfo(); QTime dieTime= QTime::currentTime().addSecs(1); while( QTime::currentTime() < dieTime ) { QCoreApplication::processEvents(QEventLoop::AllEvents, 100); } qDebug() << "Player " << NickName << "(" << Addr.toString() << ") connected"; Team = rand() % 2 == 1 ? T_One : T_Second; // throw to random team ETeam NewTeam = Server()->AutoBalance(); if (NewTeam != T_Neutral) { Team = NewTeam; } emit PlayerConnected(); ReSpawn(true); } catch (const std::exception& e){ qDebug() << "Exceptiong: " << Q_FUNC_INFO << ": Error spawning player: " << e.what(); } } else { throw UException("Parse error: auth packet"); } } break; default: throw UException("Unknown packet type!"); break; } } } catch (const UException& e) { qDebug() << "Exceptiong: " << Q_FUNC_INFO << ": " << e.what(); } }