CanMessage* CanAccess::txtMessage(const char* string) { boolean msg = false; boolean ext = false; long eid = 0; short sid = 0; if (*string == 'X' || *string == 'R') { msg = (string[0] == 'X'); ext = true; string += 2; eid = ((long)parseHexDigit(*string++)) << 28; eid |= ((long)parseHexDigit(*string++)) << 24; ++string; eid |= ((long)parseHexDigit(*string++)) << 20; eid |= ((long)parseHexDigit(*string++)) << 16; eid |= ((long)parseHexDigit(*string++)) << 12; ++string; eid |= ((long)parseHexDigit(*string++)) << 8; eid |= ((long)parseHexDigit(*string++)) << 4; eid |= ((long)parseHexDigit(*string++)); } else if (*string == 'S' || *string == 'r') { msg = (string[0] == 'S'); ext = false; string += 2; sid |= ((short)parseHexDigit(*string++)) << 8; sid |= ((short)parseHexDigit(*string++)) << 4; sid |= ((short)parseHexDigit(*string++)); } else { return NULL; } string += 3; byte length = parseHexDigit(*string++); if (length < 0 || 8 < length) return NULL; byte data[8]; string += 3; for (int p = 0; p < length; ++p) { data[p] = (parseHexDigit(*string++) << 4); data[p] |= parseHexDigit(*string++); ++string; } if (msg && ext) return &extMessage(eid, length, data); else if (msg) return &stdMessage(sid, length, data); else if (ext) return &extRequest(eid, length, data); else return &stdRequest(sid, length, data); }
//! When something from a server extension is received this function is called. Could be position updating of gameobject, a private message or just a notification. The ["cmd"] parameter of the event that is received reveals which extension that was spitting out the info. Based on extension this function will do different things. void NetworkManager::OnSmartFoxExtensionResponse(unsigned long long ptrContext, boost::shared_ptr<BaseEvent> ptrEvent) { // get pointer to main frame. NetworkManager* ptrMainFrame = (NetworkManager*)ptrContext; // Check that we're still alive and running if (ptrMainFrame == NULL) { return; } // Get the cmd parameter of the event boost::shared_ptr<map<string, boost::shared_ptr<void>>> ptrEventParams = ptrEvent->Params(); boost::shared_ptr<void> ptrEventParamValueCmd = (*ptrEventParams)["cmd"]; boost::shared_ptr<string> ptrNotifiedCmd = ((boost::static_pointer_cast<string>)(ptrEventParamValueCmd)); // check the type of the command if (*ptrNotifiedCmd == "PilotEvent") { boost::shared_ptr<void> ptrEventParamValueParams = (*ptrEventParams)["params"]; boost::shared_ptr<ISFSObject> ptrNotifiedISFSObject = ((boost::static_pointer_cast<ISFSObject>)(ptrEventParamValueParams)); pInputRotX = *(ptrNotifiedISFSObject->GetDouble("sgctRotY")); pInputRotZ = *(ptrNotifiedISFSObject->GetDouble("sgctRotX")); bool pInputForward = *(ptrNotifiedISFSObject->GetBool("sgctForward")); //bool pInputBackward = *(ptrNotifiedISFSObject->GetBool("sgctBackward")); accRotX += pInputRotX * accRotVal; accRotZ += pInputRotZ * accRotVal; if (pInputForward) { if (enginePowerup.getVal() <= 0.0 && navigationSpeed < accThrustMax * eInputEngine) navigationSpeed += accThrustVal * eInputEngine; else if (navigationSpeed < accThrustMax * eInputEngine * 2.0) navigationSpeed += accThrustVal * eInputEngine * 2.0; } //if (pInputBackward && navigationSpeed > -0.1) { // navigationSpeed -= accThrustVal * eInputEngine; //} } if (*ptrNotifiedCmd == "GunnerEvent") { boost::shared_ptr<void> ptrEventParamValueParams = (*ptrEventParams)["params"]; boost::shared_ptr<ISFSObject> ptrNotifiedISFSObject = ((boost::static_pointer_cast<ISFSObject>)(ptrEventParamValueParams)); gInputRotX = *(ptrNotifiedISFSObject->GetDouble("sgctRotX")) * 3.0; gInputRotY = *(ptrNotifiedISFSObject->GetDouble("sgctRotY")) * 3.0; bool fire = *(ptrNotifiedISFSObject->GetBool("sgctFire")); if (fire && fireTimer <= 0.0) { //if (gEngine->isMaster()) soundManager.play("laser", osg::Vec3f(0.0f, 0.0f, 0.0f)); fireSync.setVal(true); fireTimer = fireRate / eInputTurret; } } if (*ptrNotifiedCmd == "EngineerEvent") { boost::shared_ptr<void> ptrEventParamValueParams = (*ptrEventParams)["params"]; boost::shared_ptr<ISFSObject> ptrNotifiedISFSObject = ((boost::static_pointer_cast<ISFSObject>)(ptrEventParamValueParams)); eInputEngine = ((float)(*(ptrNotifiedISFSObject->GetFloat("sgctEngine"))) * 3 + 0.5); // 0.5 - 3.5 eInputShield = 1.0 - 0.75 * ((float)(*(ptrNotifiedISFSObject->GetFloat("sgctShield"))));// 1.0 - 0.25 (percent of damage taken) eInputTurret = ((float)(*(ptrNotifiedISFSObject->GetFloat("sgctTurret"))) + 0.5); // 0.5 - 1.5 } if (*ptrNotifiedCmd == "BenchMarking") { boost::shared_ptr<void> ptrEventParamValueParams = (*ptrEventParams)["params"]; boost::shared_ptr<ISFSObject> ptrNotifiedISFSObject = ((boost::static_pointer_cast<ISFSObject>)(ptrEventParamValueParams)); double item = *(ptrNotifiedISFSObject->GetDouble("1")); double item2 = *(ptrNotifiedISFSObject->GetDouble("2")); double item3 = *(ptrNotifiedISFSObject->GetDouble("3")); double item4 = *(ptrNotifiedISFSObject->GetDouble("4")); end = omp_get_wtime(); std::cout << "Reply from server, " << static_cast<int>((end - start) * 1000) << "ms." << endl; start = omp_get_wtime(); // send new item if (itemsSent++ < 35 && benchmarkingStarted) { boost::shared_ptr<ISFSObject> parameters(new SFSObject()); parameters->PutDouble("1", 0.923); parameters->PutDouble("2", 0.953); parameters->PutDouble("3", 0.343); parameters->PutDouble("4", 0.523); // find our room to send to. boost::shared_ptr<Room> lastJoined = ptrMainFrame->m_ptrSmartFox->LastJoinedRoom(); // Perform extensionrequest boost::shared_ptr<IRequest> extRequest(new ExtensionRequest("BenchMarking", parameters, lastJoined)); ptrMainFrame->m_ptrSmartFox->Send(extRequest); } else { benchmarkingStarted = false; itemsSent = 0; } } }