void InitialData(RakNet::BitStream * pBitStream, RakNet::Packet * pPacket) { // Get the playerid EntityId playerId = (EntityId) pPacket->guid.systemIndex; // Read the player version DWORD dwVersion; pBitStream->Read(dwVersion); // Read the player name RakNet::RakString _strName; pBitStream->Read(_strName); CString strName(_strName.C_String()); // Read the player serial RakNet::RakString _strSerial; pBitStream->Read(_strSerial); CString strSerial(_strSerial.C_String()); // Is the network version invalid? if (dwVersion != (DWORD)/*NETWORK_VERSION*/0x0) { // TODO } // Is the nickname already in use? // TODO: check is nick in use // Is the player banned? // TODO: check is banned // Add the player to the manager // TODO: add to player manager CPlayerEntity * pPlayer = new CPlayerEntity(); pPlayer->SetName(strName); // Do we need the id; maybe internal for easier sync but definetly not public to the scripting engine pPlayer->SetId(CServer::GetInstance()->GetPlayerManager()->Add(pPlayer)); playerId = pPlayer->GetId(); CLogFile::Printf("[join] %s (%i) has connected to the server. (%s)", strName.Get(), playerId, strSerial.Get()); CScriptArguments args; CScriptPlayer * pScriptPlayer = new CScriptPlayer(); pScriptPlayer->SetEntity(pPlayer); pPlayer->SetScriptPlayer(pScriptPlayer); args.push(pScriptPlayer); CEvents::GetInstance()->Call("playerJoin", &args, CEventHandler::eEventType::GLOBAL_EVENT, 0); // Construct a new bitstream RakNet::BitStream bitStream; // Write the player id bitStream.WriteCompressed(playerId); // Write the player colour bitStream.Write(0xFFFFFF/*CServer::GetInstance()->GetPlayerManager()->GetAt(playerId)->GetColor()*/); // Write the server name bitStream.Write(RakNet::RakString("IV:Network DEV Server")); // Write the max player count bitStream.Write(CVAR_GET_INTEGER("maxplayers")); // Write the port bitStream.Write(CVAR_GET_INTEGER("port")); // Send it back to the player CServer::GetInstance()->GetNetworkModule()->Call(GET_RPC_CODEX(RPC_INITIAL_DATA), &bitStream, HIGH_PRIORITY, RELIABLE, playerId, false); CServer::GetInstance()->GetNetworkModule()->Call(GET_RPC_CODEX(RPC_START_GAME), &bitStream, HIGH_PRIORITY, RELIABLE, playerId, false); for (EntityId i = 0; i < CServer::GetInstance()->GetPlayerManager()->GetMax(); ++i) { if (CServer::GetInstance()->GetPlayerManager()->DoesExists(i) && i != playerId) { bitStream.Reset(); bitStream.WriteCompressed(i); bitStream.Write(CServer::GetInstance()->GetPlayerManager()->GetAt(i)->GetName().Get()); CServer::GetInstance()->GetNetworkModule()->Call(GET_RPC_CODEX(RPC_NEW_PLAYER), &bitStream, HIGH_PRIORITY, RELIABLE, playerId, false); } } for (EntityId i = 0; i < CServer::GetInstance()->GetPlayerManager()->GetMax(); ++i) { if (CServer::GetInstance()->GetPlayerManager()->DoesExists(i) && i != playerId) { bitStream.Reset(); bitStream.WriteCompressed(playerId); bitStream.Write(strName.Get()); CServer::GetInstance()->GetNetworkModule()->Call(GET_RPC_CODEX(RPC_NEW_PLAYER), &bitStream, HIGH_PRIORITY, RELIABLE, i, false); } } for (EntityId i = 0; i < CServer::GetInstance()->GetVehicleManager()->GetMax(); ++i) { if (CServer::GetInstance()->GetVehicleManager()->DoesExists(i)) { bitStream.Reset(); CVehicleEntity * pVehicle = CServer::GetInstance()->GetVehicleManager()->GetAt(i); bitStream.Write(pVehicle->GetId()); bitStream.Write(/*pVehicle->GetModelId()*/90); CVector3 vecPosition; pVehicle->GetPosition(vecPosition); bitStream.Write(vecPosition); CServer::GetInstance()->GetNetworkModule()->Call(GET_RPC_CODEX(RPC_CREATE_VEHICLE), &bitStream, HIGH_PRIORITY, RELIABLE_ORDERED, -1, true); } } bitStream.Reset(); bitStream.WriteCompressed(playerId); bitStream.Write(7); bitStream.Write(3); bitStream.Write(3); bitStream.Write(1); }
void DownloadFinished(RakNet::BitStream * pBitStream, RakNet::Packet * pPacket) { // Read the player name RakNet::RakString _strName; pBitStream->Read(_strName); CString strName(_strName.C_String()); // Read the player serial RakNet::RakString _strSerial; pBitStream->Read(_strSerial); CString strSerial(_strSerial.C_String()); // Is the nickname already in use? // TODO: check is nick in use // Is the player banned? // TODO: check is banned // Add the player to the manager // TODO: add to player manager CPlayerEntity * pPlayer = new CPlayerEntity(); pPlayer->SetName(strName); // Do we need the id; maybe internal for easier sync but definetly not public to the scripting engine pPlayer->SetId(CServer::GetInstance()->GetPlayerManager()->Add(pPlayer)); EntityId playerId = pPlayer->GetId(); srand(time(NULL)); pPlayer->SetColor(CColor(rand() % 256, rand() % 256, rand() % 256).dwHexColor); //generate random color CLogFile::Printf("[join] %s (%i) has connected to the server. (%s)", strName.Get(), playerId, strSerial.Get()); CScriptArguments args; CScriptPlayer * pScriptPlayer = new CScriptPlayer(); pScriptPlayer->SetEntity(pPlayer); pPlayer->SetScriptPlayer(pScriptPlayer); args.push(pScriptPlayer); CEvents::GetInstance()->Call("playerJoin", &args, CEventHandler::eEventType::NATIVE_EVENT, 0); // Construct a new bitstream RakNet::BitStream bitStream; // Write the player id bitStream.Write(playerId); // Write the player colour bitStream.Write(pPlayer->GetColor()); // Write the server name bitStream.Write(RakNet::RakString("IV:Network DEV Server")); // Write the max player count bitStream.Write(CVAR_GET_INTEGER("maxplayers")); // Write the port bitStream.Write(CVAR_GET_INTEGER("port")); // Send it back to the player CServer::GetInstance()->GetNetworkModule()->Call(GET_RPC_CODEX(RPC_INITIAL_DATA), &bitStream, HIGH_PRIORITY, RELIABLE_ORDERED, playerId, false); for (EntityId i = 0; i < CServer::GetInstance()->GetPlayerManager()->GetMax(); ++i) { if (CServer::GetInstance()->GetPlayerManager()->DoesExists(i) && i != playerId) { bitStream.Reset(); bitStream.Write(i); bitStream.Write(CServer::GetInstance()->GetPlayerManager()->GetAt(i)->GetName().Get()); bitStream.Write(CServer::GetInstance()->GetPlayerManager()->GetAt(i)->GetColor()); CServer::GetInstance()->GetNetworkModule()->Call(GET_RPC_CODEX(RPC_NEW_PLAYER), &bitStream, HIGH_PRIORITY, RELIABLE_ORDERED, playerId, false); } } for (EntityId i = 0; i < CServer::GetInstance()->GetPlayerManager()->GetMax(); ++i) { if (CServer::GetInstance()->GetPlayerManager()->DoesExists(i) && i != playerId) { bitStream.Reset(); bitStream.Write(playerId); bitStream.Write(pPlayer->GetName().Get()); bitStream.Write(pPlayer->GetColor()); CServer::GetInstance()->GetNetworkModule()->Call(GET_RPC_CODEX(RPC_NEW_PLAYER), &bitStream, HIGH_PRIORITY, RELIABLE_ORDERED, i, false); } } for (EntityId i = 0; i < CServer::GetInstance()->GetVehicleManager()->GetMax(); ++i) { if (CServer::GetInstance()->GetVehicleManager()->DoesExists(i)) { bitStream.Reset(); CVehicleEntity * pVehicle = CServer::GetInstance()->GetVehicleManager()->GetAt(i); bitStream.Write(pVehicle->GetId()); bitStream.Write(pVehicle->GetModelId()); CVector3 vecPosition; pVehicle->GetPosition(vecPosition); bitStream.Write(vecPosition); CVector3 vecRotation; pVehicle->GetRotation(vecRotation); bitStream.Write(vecRotation.fX); bitStream.Write(pVehicle->GetColor(1)); bitStream.Write(pVehicle->GetColor(2)); bitStream.Write(pVehicle->GetColor(3)); bitStream.Write(pVehicle->GetColor(4)); bitStream.Write(pVehicle->GetColor(5)); CServer::GetInstance()->GetNetworkModule()->Call(GET_RPC_CODEX(RPC_CREATE_VEHICLE), &bitStream, HIGH_PRIORITY, RELIABLE_ORDERED, playerId, false); } } for (EntityId i = 0; i < CServer::GetInstance()->GetCheckpointManager()->GetMax(); ++i) { if (CServer::GetInstance()->GetCheckpointManager()->DoesExists(i)) { bitStream.Reset(); CCheckpointEntity * pCheckpoint = CServer::GetInstance()->GetCheckpointManager()->GetAt(i); bitStream.Write(pCheckpoint->GetId()); bitStream.Write(pCheckpoint->GetType()); CVector3 vecPosition; pCheckpoint->GetPosition(vecPosition); bitStream.Write(vecPosition); CVector3 vecTargetPosition; pCheckpoint->GetTargetPosition(vecTargetPosition); bitStream.Write(vecTargetPosition); bitStream.Write(pCheckpoint->GetRadius()); CServer::GetInstance()->GetNetworkModule()->Call(GET_RPC_CODEX(RPC_CREATE_CHECKPOINT), &bitStream, HIGH_PRIORITY, RELIABLE_ORDERED, playerId, false); // Checkpoint visibility if (!pCheckpoint->GetVisible()) { bitStream.Reset(); bitStream.Write(pCheckpoint->GetId()); CServer::GetInstance()->GetNetworkModule()->Call(GET_RPC_CODEX(RPC_CHECKPOINT_HIDE), &bitStream, HIGH_PRIORITY, RELIABLE_ORDERED, playerId, false); } } } }
int main(int argc, char *argv[]) { if (argc < 2) { fprintf(stderr, "%s [-l log_level][-s serial] test_xml\n", argv[0]); return 1; } int logLevel = Log::ELogE; char* serial = NULL; int opt; while ((opt = getopt(argc, argv, "l:s:")) != -1) { switch (opt) { case 'l': logLevel = atoi(optarg); break; case 's': serial = optarg; break; default: usage(argv[0]); return 1; } } if (optind >= argc) { usage(argv[0]); return 1; } android::String8 xmlFile(argv[optind]); android::String8 dirName; if (!FileUtil::prepare(dirName)) { fprintf(stderr, "cannot prepare report dir"); return 1; } UniquePtr<CleanupStatics> staticStuffs(new CleanupStatics()); if (Settings::Instance() == NULL) { fprintf(stderr, "caanot create Settings"); return 1; } if (serial != NULL) { android::String8 strSerial(serial); Settings::Instance()->addSetting(Settings::EADB, strSerial); } if (Log::Instance(dirName.string()) == NULL) { fprintf(stderr, "cannot create Log"); return 1; } Log::Instance()->setLogLevel((Log::LogLevel)logLevel); // Log can be used from here if (Report::Instance(dirName.string()) == NULL) { LOGE("cannot create log"); return 1; } GenericFactory factory; ClientInterface* client = factory.createClientInterface(); if (client == NULL) { fprintf(stderr, "cannot create ClientInterface"); return 1; } if (!client->init(Settings::Instance()->getSetting(Settings::EADB))) { fprintf(stderr, "cannot init ClientInterface"); return 1; } android::String8 deviceInfo; if (!client->getAudio()->getDeviceInfo(deviceInfo)) { fprintf(stderr, "cannot get device info"); return 1; } delete client; // release so that it can be used in tests Settings::Instance()->addSetting(Settings::EDEVICE_INFO, deviceInfo); ModelBuilder modelBuilder; UniquePtr<TaskGeneric> topTask(modelBuilder.parseTestDescriptionXml(xmlFile)); if (topTask.get() == NULL) { LOGE("Parsing of %x failed", xmlFile.string()); return 1; } Settings::Instance()->addSetting(Settings::ETEST_XML, xmlFile); topTask->run(); return 0; }