void plResponderModifier::Trigger(plNotifyMsg *msg) { #if 0 plNetClientApp::GetInstance()->DebugMsg("RM: Responder {} is triggering, num cmds={}, enabled={}, curCmd={}, t={f}\n", GetKeyName(), fStates[fCurState].fCmds.GetCount(), fEnabled, fCurCommand, hsTimer::GetSysSeconds()); #endif // If we're not in the middle of sending, reset and start sending commands if (fCurCommand == int8_t(-1) && fEnabled) { ResponderLog(ILog(plStatusLog::kGreen, "Trigger")); fNotifyMsgFlags = msg->GetAllBCastFlags(); fTriggerer = msg->GetSender(); fPlayerKey = msg->GetAvatarKey(); ISetResponderStateFromNotify(msg); proCollisionEventData *cEvent = (proCollisionEventData *)msg->FindEventRecord(proEventData::kCollision); fEnter = (cEvent ? cEvent->fEnter : false); fCompletedEvents.Reset(); fCurCommand = 0; DirtySynchState(kSDLResponder, 0); IContinueSending(); } else { ResponderLog(ILog(plStatusLog::kRed, "Rejected Trigger, %s", !fEnabled ? "responder disabled" : "responder is running")); } }
void plResponderModifier::IFastForward(bool python) { ResponderLog(ILog(plStatusLog::kGreen, "Fast Forward")); fCurCommand = 0; plResponderState& state = fStates[fCurState]; while (fCurCommand < state.fCmds.Count()) { plMessage *msg = state.fCmds[fCurCommand].fMsg; msg = IGetFastForwardMsg(msg, python); if (msg) plgDispatch::MsgSend(msg); fCurCommand++; } ResponderLog(ILog(plStatusLog::kGreen, "Reset")); fCurCommand = -1; ISetResponderState(state.fSwitchToState); plSynchEnabler enable(true); DirtySynchState(kSDLResponder, 0); }
int main() { ILog("Starting create selfsigned cert"); int nResult = ICertificateUtils::createSelfSignedCertMS(); if(nResult) { ILogR("Error in createSelfSignedCert", nResult); return nResult; } ILog("Success"); return 0; }
void VixMntMsgQue::unlink() { std::map<std::string, mqd_t>::iterator itr = VixMntMsgQue::vixMntMsgMap.begin(); while (itr != VixMntMsgQue::vixMntMsgMap.end()) { if (mq_unlink(itr->first.c_str()) < 0) { ILog("%s unlink faild.", itr->first.c_str()); } else { ILog("%s unlink ok.", itr->first.c_str()); } itr++; } VixMntMsgQue::vixMntMsgMap.clear(); }
VixMntMmap::VixMntMmap(size_t mmap_datasize, bool isRoot) { try { if (isRoot) { this->file_name = VixMntMmap::fileRoot; } else this->file_name = "/vmware_mnt_tmp"; } catch (std::exception &e) { ELog("set file_name error"); this->file_name = "/vmware_mnt_shm"; } this->fid = shm_open(this->file_name.c_str(), O_RDWR | O_CREAT | O_TRUNC, 0666); if (this->fid > 0) { ILog("open share memory %d %s", this->fid, this->file_name.c_str()); } else { ILog("open share memory faild, map to file%d", this->fid); } this->mmap_datasize = mmap_datasize > 0 ? mmap_datasize : MMAP_PAGE_SIZE; this->mmap_pagenum = this->mmap_datasize / MMAP_PAGE_SIZE + 1; int sh_result = ftruncate(this->fid, this->mmap_pagenum * MMAP_PAGE_SIZE); if (sh_result < 0) { ELog("shm ftruncate error "); } if (this->fid == -1) { this->mmap_data = (char *)mmap(NULL, this->mmap_pagenum * MMAP_PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0); } else { this->mmap_data = (char *)mmap(NULL, this->mmap_pagenum * MMAP_PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, this->fid, 0); } ILog("shm mmap addr : %x", this->mmap_data); }
void plResponderModifier::ISetResponderState(int8_t state) { // make sure that it is a valid state to switch to if (state >= 0 && state < fStates.Count()) { fCurState = state; } else { ResponderLog(ILog(plStatusLog::kRed, "Invalid state %d specified, will default to current state", state)); } }
void main() { setlocale(LC_CTYPE, ".1251"); try { TApplicationExample app; ISchannelUtils::printError(app.work()); } catch(...) { ILog("@@ Unhandled Exception"); } }
int main() { pthread_mutex_t mt; VixMntMutex lock(&mt, true); try { lock.lock(); lock.lock(); lock.unlock(); lock.unlock(); } catch (VixMntException &e) { ILog("%s", e.what()); } return 0; }
int main() { setlocale(LC_CTYPE, ".1251"); try { TLibHolder hDll(::LoadLibraryA("schannel.dll")); ISchannelUtils::printError(work()); } catch(...) { ILog("@@@ Unhandled exception"); system("pause"); } return 0; }
void test_computerId() { ILog("\nComputer identification test"); TComputerIdentifier compId; int nResult = ISchannelUtils::generateComputerID(compId); if(nResult) { ILogR("Error in generateComputerID", nResult); ILog(ISchannelUtils::printError(nResult)); return; } TBlob serialized; nResult = ISchannelUtils::serializeComputerId( compId, serialized); if(nResult) { ILogR("Error in serializeComputerId", nResult); ILog(ISchannelUtils::printError(nResult)); return; } ILog("Serialized data:"); ILog(ISchannelUtils::printHexDump(serialized.size(), &serialized.front())); TComputerIdentifier restoredCompId; nResult = ISchannelUtils::restoreComputerId( serialized, restoredCompId); if(nResult) { ILogR("Error in restoreComputerId", nResult); ILog(ISchannelUtils::printError(nResult)); return; } if(compId.isEqual(restoredCompId)) ILog("Restored successfully") else ILog("Failed to restore") }
plMessage* plResponderModifier::IGetFastForwardMsg(plMessage* msg, bool python) { if (!msg) return nil; if (plAnimCmdMsg* animMsg = plAnimCmdMsg::ConvertNoRef(msg)) { if (animMsg->Cmd(plAnimCmdMsg::kContinue) || animMsg->Cmd(plAnimCmdMsg::kAddCallbacks)) { plAnimCmdMsg* newAnimMsg = new plAnimCmdMsg; newAnimMsg->fCmd = animMsg->fCmd; newAnimMsg->fBegin = animMsg->fBegin; newAnimMsg->fEnd = animMsg->fEnd; newAnimMsg->fLoopEnd = animMsg->fLoopEnd; newAnimMsg->fLoopBegin = animMsg->fLoopBegin; newAnimMsg->fSpeed = animMsg->fSpeed; newAnimMsg->fSpeedChangeRate = animMsg->fSpeedChangeRate; newAnimMsg->fTime = animMsg->fTime; newAnimMsg->SetAnimName(animMsg->GetAnimName()); newAnimMsg->SetLoopName(animMsg->GetLoopName()); // Remove the callbacks newAnimMsg->fCmd.SetBit(plAnimCmdMsg::kAddCallbacks, false); if (newAnimMsg->Cmd(plAnimCmdMsg::kContinue)) { newAnimMsg->fCmd.SetBit(plAnimCmdMsg::kContinue, false); newAnimMsg->fCmd.SetBit(plAnimCmdMsg::kFastForward, true); } for (int i = 0; i < animMsg->GetNumReceivers(); i++) newAnimMsg->AddReceiver(animMsg->GetReceiver(i)); ResponderLog(ILog(plStatusLog::kWhite, "FF Animation Play Msg")); return newAnimMsg; } ResponderLog(ILog(plStatusLog::kWhite, "FF Animation Non-Play Msg")); hsRefCnt_SafeRef(msg); return msg; } else if(plSoundMsg *soundMsg = plSoundMsg::ConvertNoRef(msg)) { if( fFlags & kSkipFFSound ) { return nil; } if(soundMsg->Cmd(plSoundMsg::kPlay) || soundMsg->Cmd(plSoundMsg::kToggleState) || soundMsg->Cmd(plAnimCmdMsg::kAddCallbacks)) { plSoundMsg *newSoundMsg = new plSoundMsg; newSoundMsg->fCmd = soundMsg->fCmd; newSoundMsg->fBegin = soundMsg->fBegin; newSoundMsg->fEnd = soundMsg->fEnd; newSoundMsg->fLoop = soundMsg->fLoop; newSoundMsg->fSpeed = soundMsg->fSpeed; newSoundMsg->fTime = soundMsg->fTime; newSoundMsg->fIndex = soundMsg->fIndex; newSoundMsg->fRepeats = soundMsg->fRepeats; newSoundMsg->fPlaying = soundMsg->fPlaying; newSoundMsg->fNameStr = soundMsg->fNameStr; newSoundMsg->fVolume = soundMsg->fVolume; // Remove the callbacks newSoundMsg->fCmd.SetBit(plSoundMsg::kAddCallbacks, false); if(newSoundMsg->Cmd(plSoundMsg::kPlay)) { newSoundMsg->fCmd.SetBit(plSoundMsg::kPlay, false); newSoundMsg->fCmd.SetBit(plSoundMsg::kFastForwardPlay); ResponderLog(ILog(plStatusLog::kWhite, "FF Sound Play Msg")); } else if(newSoundMsg->Cmd(plSoundMsg::kToggleState)) { newSoundMsg->fCmd.SetBit(plSoundMsg::kToggleState, false); newSoundMsg->fCmd.SetBit(plSoundMsg::kFastForwardToggle); ResponderLog(ILog(plStatusLog::kWhite, "FF Sound Toggle State Msg")); } for (int i = 0; i < soundMsg->GetNumReceivers(); i++) newSoundMsg->AddReceiver(soundMsg->GetReceiver(i)); return newSoundMsg; } ResponderLog(ILog(plStatusLog::kWhite, "FF Sound Non-Play/Toggle Msg")); hsRefCnt_SafeRef(msg); return msg; } else if (msg->ClassIndex() == CLASS_INDEX_SCOPED(plExcludeRegionMsg)) { ResponderLog(ILog(plStatusLog::kWhite, "FF Exclude Region Msg")); hsRefCnt_SafeRef(msg); return msg; } else if (msg->ClassIndex() == CLASS_INDEX_SCOPED(plEnableMsg)) { ResponderLog(ILog(plStatusLog::kWhite, "FF Visibility/Detector Enable Msg")); hsRefCnt_SafeRef(msg); return msg; } else if (msg->ClassIndex() == CLASS_INDEX_SCOPED(plResponderEnableMsg)) { ResponderLog(ILog(plStatusLog::kWhite, "FF Responder Enable Msg")); hsRefCnt_SafeRef(msg); return msg; } else if (msg->ClassIndex() == CLASS_INDEX_SCOPED(plSimSuppressMsg)) { ResponderLog(ILog(plStatusLog::kWhite, "FF Physical Enable Msg")); hsRefCnt_SafeRef(msg); return msg; } return nil; }
void plResponderModifier::Restore() { // If we're the first player in and we're loading old state where this responder // was running, fast forward it if (plNetClientApp::GetInstance()->GetJoinOrder() == 0 && fCurCommand != -1 && !fGotFirstLoad) { fGotFirstLoad = true; IFastForward(false); return; } ResponderLog(ILog(plStatusLog::kGreen, "Load SDL State")); fGotFirstLoad = true; plResponderState& state = fStates[fCurState]; for (int i = 0; i < state.fNumCallbacks; i++) { if (!fCompletedEvents[i]) { int cmdIdx = state.fWaitToCmd[i]; plResponderCmd& cmd = state.fCmds[cmdIdx]; // // If it's a callback message (anim or sound), just send the callbacks again // plMessageWithCallbacks* callbackMsg = plMessageWithCallbacks::ConvertNoRef(cmd.fMsg); if (callbackMsg) { // Create a new message for just the callbacks plMessageWithCallbacks* newCallbackMsg = nil; if (plAnimCmdMsg* animMsg = plAnimCmdMsg::ConvertNoRef(callbackMsg)) { plAnimCmdMsg* newAnimMsg = new plAnimCmdMsg; newAnimMsg->SetCmd(plAnimCmdMsg::kAddCallbacks); newCallbackMsg = newAnimMsg; ResponderLog(ILog(plStatusLog::kGreen, "Restoring anim callback")); } else if (plSoundMsg* soundMsg = plSoundMsg::ConvertNoRef(callbackMsg)) { plSoundMsg* newSoundMsg = new plSoundMsg; newSoundMsg->SetCmd(plSoundMsg::kAddCallbacks); newCallbackMsg = newSoundMsg; ResponderLog(ILog(plStatusLog::kGreen, "Restoring sound callback")); } // Setup the sender and receiver newCallbackMsg->SetSender(callbackMsg->GetSender()); for (int iReceiver = 0; i < callbackMsg->GetNumReceivers(); i++) newCallbackMsg->AddReceiver(callbackMsg->GetReceiver(iReceiver)); // Add the callbacks int numCallbacks = callbackMsg->GetNumCallbacks(); for (int iCallback = 0; iCallback < numCallbacks; iCallback++) { plMessage* callback = callbackMsg->GetCallback(iCallback); // hsRefCnt_SafeRef(callback); AddCallback will ref this for us. newCallbackMsg->AddCallback(callback); } newCallbackMsg->Send(); } } } }
bool plResponderModifier::IContinueSending() { // If we haven't been started, exit if (fCurCommand == int8_t(-1)) return false; plResponderState& state = fStates[fCurState]; while (fCurCommand < state.fCmds.Count()) { plMessage *msg = state.fCmds[fCurCommand].fMsg; if (msg) { // If this command needs to wait, and it's condition hasn't been met yet, exit int8_t wait = state.fCmds[fCurCommand].fWaitOn; if (wait != -1 && !fCompletedEvents.IsBitSet(wait)) { ResponderLog(ILog(plStatusLog::kWhite, "Command %d is waiting for command %d(id:%d)", int8_t(fCurCommand)+1, ICmdFromWait(wait)+1, wait)); return false; } if (!(fNotifyMsgFlags & plMessage::kNetNonLocal)|| !IIsLocalOnlyCmd(msg)) { // make sure outgoing msgs inherit net flags as part of cascade uint32_t msgFlags = msg->GetAllBCastFlags(); plNetClientApp::InheritNetMsgFlags(fNotifyMsgFlags, &msgFlags, true); msg->SetAllBCastFlags(msgFlags); // If this is a responder message, let it know which player triggered this if (plResponderMsg* responderMsg = plResponderMsg::ConvertNoRef(msg)) { responderMsg->fPlayerKey = fPlayerKey; } else if (plNotifyMsg* notifyMsg = plNotifyMsg::ConvertNoRef(msg)) { bool foundCollision = false; // If we find a collision event, this message is meant to trigger a multistage for (int i = 0; i < notifyMsg->GetEventCount(); i++) { proEventData* event = notifyMsg->GetEventRecord(i); if (event->fEventType == proEventData::kCollision) { proCollisionEventData* collisionEvent = (proCollisionEventData*)event; collisionEvent->fHitter = fPlayerKey; foundCollision = true; } } // No collision event, this message is for notifying the triggerer if (!foundCollision) { notifyMsg->ClearReceivers(); notifyMsg->AddReceiver(fTriggerer); } notifyMsg->SetSender(GetKey()); } else if (plLinkToAgeMsg* linkMsg = plLinkToAgeMsg::ConvertNoRef(msg)) { if (linkMsg->GetNumReceivers() == 0) { plUoid netUoid(kNetClientMgr_KEY); plKey netKey = hsgResMgr::ResMgr()->FindKey(netUoid); hsAssert(netKey,"NetClientMgr not found"); linkMsg->AddReceiver(netKey); } } else if (plArmatureEffectStateMsg* stateMsg = plArmatureEffectStateMsg::ConvertNoRef(msg)) { stateMsg->ClearReceivers(); stateMsg->AddReceiver(fPlayerKey); stateMsg->fAddSurface = fEnter; } else if (plSubWorldMsg* swMsg = plSubWorldMsg::ConvertNoRef(msg)) { plArmatureMod *avatar = plAvatarMgr::GetInstance()->GetLocalAvatar(); if(avatar) { swMsg->AddReceiver(avatar->GetKey()); } } // If we're in anim debug mode, check if this is an anim play // message so we can put up the cue if (fDebugAnimBox) { plAnimCmdMsg* animMsg = plAnimCmdMsg::ConvertNoRef(msg); if (animMsg && animMsg->Cmd(plAnimCmdMsg::kContinue)) IDebugPlayMsg(animMsg); } if (plTimerCallbackMsg *timerMsg = plTimerCallbackMsg::ConvertNoRef(msg)) { hsRefCnt_SafeRef(timerMsg); plgTimerCallbackMgr::NewTimer(timerMsg->fTime, timerMsg); } else { hsRefCnt_SafeRef(msg); plgDispatch::MsgSend(msg); } } } fCurCommand++; DirtySynchState(kSDLResponder, 0); } // Make sure all callbacks we need to wait on are done before allowing a state switch or restart for (int i = 0; i < state.fNumCallbacks; i++) { if (!fCompletedEvents.IsBitSet(i)) { ResponderLog(ILog(plStatusLog::kWhite, "Can't reset, waiting for command %d(id:%d)", ICmdFromWait(i)+1, i)); return false; } } ResponderLog(ILog(plStatusLog::kGreen, "Reset")); fCurCommand = -1; ISetResponderState(state.fSwitchToState); DirtySynchState(kSDLResponder, 0); return true; }
bool plResponderModifier::MsgReceive(plMessage* msg) { plNotifyMsg* pNMsg = plNotifyMsg::ConvertNoRef(msg); if (pNMsg) { if (pNMsg->fType == plNotifyMsg::kResponderFF) { ISetResponderStateFromNotify(pNMsg); IFastForward(true); } else if (pNMsg->fType == plNotifyMsg::kResponderChangeState) { ISetResponderStateFromNotify(pNMsg); DirtySynchState(kSDLResponder, 0); } else { // assumes state of 0 means untriggered and state of 1 is triggered if ((pNMsg->fState != 0 && (fFlags & kDetectTrigger)) || (pNMsg->fState == 0 && (fFlags & kDetectUnTrigger))) { Trigger(pNMsg); DirtySynchState(kSDLResponder, 0); } } return true; } plResponderEnableMsg *pEnableMsg = plResponderEnableMsg::ConvertNoRef(msg); if (pEnableMsg) { fEnabled = pEnableMsg->fEnable; DirtySynchState(kSDLResponder, 0); return true; } plEventCallbackMsg *pEventMsg = plEventCallbackMsg::ConvertNoRef(msg); plTimerCallbackMsg *timerMsg = plTimerCallbackMsg::ConvertNoRef(msg); if (pEventMsg || timerMsg) { uint32_t waitID = pEventMsg ? pEventMsg->fUser : timerMsg->fID; if (waitID != -1) { // Flag that this callback completed and try sending in case any commands were waiting on this fCompletedEvents.SetBit(waitID); ResponderLog(ILog(plStatusLog::kWhite, "Got callback from command %d(id:%d)", ICmdFromWait((int8_t)waitID)+1, waitID)); IContinueSending(); DirtySynchState(kSDLResponder, 0); } // The is one of the stop callbacks we generated for debug mode else if (fDebugAnimBox) IDebugAnimBox(false); return true; } // pass sdl msg to sdlMod plSDLModifierMsg* sdlMsg = plSDLModifierMsg::ConvertNoRef(msg); if (sdlMsg && fResponderSDLMod) { if (fResponderSDLMod->MsgReceive(sdlMsg)) return true; // msg handled } return plSingleModifier::MsgReceive(msg); }
int main() { ILog("Info"); vixMntIPC_InitMmap(0x100, 0); const char msg[12] = "mmap test 1"; size_t msg_len = strlen(msg); char *buf = new char[msg_len]; /* * test same process whether mmap is works vixMntIPC_WriteMmap(msg,0,msg_len); vixMntIPC_ReadMmap(buf,0,msg_len); vixMntIPC_CleanMmap(); ILog("buf len %d -- (%s)",msg_len,buf); printf("%s\n",buf); */ /* * test mmap between two processes */ sem_t *semaphore = sem_open("/sema", O_CREAT, 0777, 0); pid_t pid = fork(); if (!pid) { vixMntIPC_WriteMmap(msg, 10, msg_len); sem_post(semaphore); sem_close(semaphore); exit(0); } sem_wait(semaphore); vixMntIPC_ReadMmap(buf, 10, msg_len); sem_close(semaphore); sem_unlink("/sema"); vixMntIPC_CleanMmap(); ILog("buf len %d -- (%s)", msg_len, buf); delete[] buf; pthread_t pid_t = listening(); pthread_t pid_t2 = listening(); VixMntMsgQue *msgque = VixMntMsgQue::getMsgQueInstance(); ILog("size of msgque instance %u", sizeof(*msgque)); VixMntMsgQue *msgque2 = new VixMntMsgQue("/test2"); VixMntMsgQue *msgque3 = new VixMntMsgQue("/test3"); ILog("size of msgque instance %u", sizeof(VixMntMsgQue)); delete msgque3; delete msgque2; if (!pid_t) { ELog("error goto clean"); goto clean; } /* * TODO : * will received ERROR when send HALT */ msgque->sendMsgOp(VixMntOp(MntInit)); msgque->sendMsgOp(VixMntOp(MntWrite)); msgque->sendMsgOp(VixMntOp(MntReadDone)); msgque->sendMsgOp(VixMntOp(MntRead)); msgque->sendMsgOp(VixMntOp(HALT)); msgque->sendMsgOp(VixMntOp(HALT)); // sleep(4); pthread_join(pid_t, NULL); pthread_join(pid_t2, NULL); msgque->unlink(); VixMntMsgQue::releaseMsgQueInstance(); clean: ILog("end all"); return 0; }
int work() { std::auto_ptr<ISocket> spSock(ISocket::create()); if(!spSock.get()) { ILog("Cannot create ISocket"); return -39; } int nResult = spSock->connect("localhost", "27015"); if(nResult) { ILogR("Error in listenAndAccept", nResult); return nResult; } ILog("> Connected to server"); std::auto_ptr<ICertificate> spCert(ICertificate::create()); if(!spCert.get()) { ILog("Cannot create certificate"); return -40; } ILog("> Certificate loaded"); std::auto_ptr<ISecurityChannel> spSessionClient( ISecurityChannel::create()); if(!spSessionClient.get()) { ILog("Cannot create ISecurityChannel"); return -41; } nResult = spSessionClient->authenticate(*spSock, *spCert); if(nResult) { ILogR("Error in authenticate", nResult); return nResult; } ILog("> Authentication complete"); std::auto_ptr<ISecurityChannelStream> spStream( ISecurityChannelStream::create()); if(!spStream.get()) { ILog("Cannot create ISecurityChannelStream"); return -42; } nResult = spStream->attach(*spSessionClient); if(nResult) { ILogR("Error in attach", nResult); return nResult; } std::string strMessage(">> Hello to Server!"); nResult = spStream->send(strMessage.c_str(), strMessage.length() + 1); if(nResult) { ILogR("Error in send", nResult); return nResult; } ILog("Sent message: " + strMessage); char cBuffer[150] = ""; size_t szRecieved = 0; nResult = spStream->receive(cBuffer, 150, szRecieved); if(nResult) { ILogR("Error in receive", nResult); return nResult; } ILog("Received message:"); ILog(cBuffer); ILog("> Shutting down channel"); nResult = spSessionClient->shutdown(true); if(nResult) { ILogR("Error in shutdown", nResult); return nResult; } return 0; }