Esempio n. 1
0
HRESULT RpcComProtocol::method_invoke(ULONG inType,ULONG inSequNo,UInt8 *inData,ULONG inLen)
{
    ULONG		sendlen1 = 0,sendlen2 = 0;;
    OS_Error	theErr	= OS_NoErr;
    HRESULT hr = E_FAIL;
    if(NULL == mSocketPtr)
    {
        return RPCCOM_E_CONN_INVALID;
    }
#define __SEND_ONE_MEM__
#ifndef __SEND_ONE_MEM__
    inLen = (inLen+3) & 0xFFFFFFFC;
    UInt8 theHeaderBuf[RpcComPacket::RPCCOM_PACEKER_HEADER_SIZE];
    ((ULONG*)theHeaderBuf)[0] = RPCCOM_PACEKER_HEADER_PREFIX;
    ((ULONG*)theHeaderBuf)[1] = inType;
    ((ULONG*)theHeaderBuf)[2] = inSequNo;
    ((ULONG*)theHeaderBuf)[3] = inLen;

    OSMutexLocker _locker(&mMutex);

    theErr	= mSocketPtr->Send((const char *)&theHeaderBuf,sizeof(theHeaderBuf),(UInt32*)&sendlen1);
    hr = map_oserror_to_hresult(theErr,RPCCOM_E_CONN_SEND_FAILED);
    if(FAILED(hr)) {
        ERR("Send header failed:0x%X\n",hr);
        return hr;
    }

    theErr	= mSocketPtr->Send((const char *)inData,inLen,(UInt32*)&sendlen2);
    hr = map_oserror_to_hresult(theErr,RPCCOM_E_CONN_SEND_FAILED);

    COND_EXEC(FAILED(hr),ERR("Send body failed:0x%X\n",hr));

    //TRACE("Send over:hr(0x%X),sendlen1(%lu),sendlen2(%lu)\r\n",hr,(unsigned long)sendlen1,(unsigned long)sendlen2);
#else
    OSMutexLocker _locker(&mMutex);
    UInt8* pBuf = new UInt8[RpcComPacket::RPCCOM_PACEKER_HEADER_SIZE + inLen];

    ((ULONG*)pBuf)[0] = RPCCOM_PACEKER_HEADER_PREFIX;
    ((ULONG*)pBuf)[1] = inType;
    ((ULONG*)pBuf)[2] = inSequNo;
    ((ULONG*)pBuf)[3] = inLen;

    memcpy((void*)&pBuf[RpcComPacket::RPCCOM_PACEKER_HEADER_SIZE], (void*)inData, inLen);

    theErr	= mSocketPtr->Send((const char *)pBuf, RpcComPacket::RPCCOM_PACEKER_HEADER_SIZE + inLen, (UInt32*)&sendlen1);
    hr = map_oserror_to_hresult(theErr,RPCCOM_E_CONN_SEND_FAILED);
    delete pBuf;
    if(FAILED(hr))
    {
        ERR("Send header failed:0x%X\n",hr);
        return hr;
    }
#endif

    return hr;
}
Esempio n. 2
0
void    OSEventThread::init_wakeuper()
{
    int ret;
    int filedes[2];

#ifdef USE_SOCKET_PAIR
    ret = dumb_socketpair(filedes, 0);
#else
    ret = pipe(filedes);
#endif

    if (ret < 0) {
        ERR("Error in pipe() errno:%d\n", errno);
    }

    mFdWakeupRead = filedes[0];
    mFdWakeupWrite = filedes[1];

    SetFileDescNonBlocking(mFdWakeupRead);
    SetEvent (&mWakeupFdEvent, mFdWakeupRead, true,
        processWakeupCallback, NULL);

    {
        OSMutexLocker _locker(&mMutex);
        addWatch(&mWakeupFdEvent);
    }
}
Esempio n. 3
0
INT KDeviceNameMgr::FixDosPathToNormalPath(LPCWSTR strDevicePath, WCHAR path[MAX_PATH])
{
	kis::KLocker _locker(m_lock);
	// 先看看是否以特殊的头开始
	if (_wcsnicmp(strDevicePath, DEVICE_PREFIX, wcslen(DEVICE_PREFIX)) == 0)
	{
		if (DevicePathToDosPath(strDevicePath, path))
			return 1;
		else
		{
			Refresh();
			if (DevicePathToDosPath(strDevicePath, path))
				return 1;
		}
		return 0;
	}
	else if (_wcsnicmp(strDevicePath, SYSTEM_ROOT_PREFIX, wcslen(SYSTEM_ROOT_PREFIX)) == 0)
	{
		wcscpy_s(path, MAX_PATH, GetSystemRoot());
		wcscat_s(path , MAX_PATH - 2, strDevicePath + wcslen(SYSTEM_ROOT_PREFIX)-1);
		if (::PathFileExists(path))
			return 2;
	}
	return 0;
}
Esempio n. 4
0
void OSEventThread::processTimeouts()
{
    TRACE("~~~~ +processTimeouts ~~~~\n");
    ULONG  now = OS::GetTickCount();

    OSMutexLocker _locker(&mMutex);
    event_timer_t * tev = UT_LIST_GET_FIRST(mTimerList);
    event_timer_t * next;

    // walk list, see if now >= ev->timeout for any events
    TRACE("~~~~ Looking for timers <= %lu ~~~~\n", (unsigned long)now);
    while ((tev) && (now > tev->timeout)) {
        // Timer expired
        TRACE("~~~~ firing timer ~~~~\n");
        next = UT_LIST_GET_NEXT(watchNode,tev);
        
        tev->status = 1;
        UT_LIST_ADD_FIRST(activeNode,mTimeoutList,tev);

        if (tev->persist == false){
            UT_LIST_REMOVE(watchNode,mTimerList,tev);
            //if(tev != &mIdleTimer)
            DecreaseWatchNum();
        }
        
        tev = next;
    }

    TRACE("~~~~ -processTimeouts ~~~~\n");
}
Esempio n. 5
0
void OSEventThread::processReadReadies(fd_set * rfds, int n)
{
    TRACE("~~~~ +processReadReadies (%d) ~~~~\n", n);

    OSMutexLocker _locker(&mMutex);
    event_req_t* rev = UT_LIST_GET_FIRST(mWatchList);
    event_req_t* next;
    
    while((NULL != rev) && (n > 0)){
        next = UT_LIST_GET_NEXT(watchNode,rev);
        if (FD_ISSET(rev->fd, rfds)) {
            rev->status = 1;
            UT_LIST_ADD_FIRST(activeNode,mPendingList,rev);
            
            if (rev->persist == false) {
                removeWatch(rev);
                DecreaseWatchNum();
            }
            n--;
        }
        rev = next;
    }

    TRACE("~~~~ -processReadReadies (%d) ~~~~\n", n);
}
void ZonePacketHandler::handleUpdateTransformMessage(Message* pack) {
	BaseClient* client = (BaseClient*) pack->getClient();

	uint64 objid = pack->parseLong();

	float x = pack->parseSignedShort() / 4.f;
	float z = pack->parseSignedShort() / 4.f;
	float y = pack->parseSignedShort() / 4.f;

	uint32 counter = pack->parseInt();

	SceneObject* scno = zone->getObject(objid);

	if (scno != NULL) {
		Locker _locker(scno);
		scno->setPosition(x, z, y);
		//scno->info("updating position");

		_locker.release();

		PlayerCreature* player = zone->getSelfPlayer();

		Locker _playerLocker(player);

		if (player->getFollowObject() == scno) {
			player->updatePosition(x, z, y);
		}
	}
}
void CreatureManagerImplementation::placeCreature(CreatureObject* creature, float x, float z, float y, uint64 parentID) {
	if (creature == NULL)
		return;

	Reference<SceneObject*> cellParent = NULL;

	if (parentID != 0) {
		cellParent = zoneServer->getObject(parentID);

		if (cellParent != NULL && !cellParent->isCellObject()) {
			error("trying to set a parent that is not a cell to creature");
			cellParent = NULL;
		}
	}

	//addCreatureToMap(creature);

	Locker _locker(creature);

	if (creature->isAiAgent()) {
		AiAgent* aio = cast<AiAgent*>(creature);
		aio->setHomeLocation(x, z, y, cellParent);
	}

	creature->initializePosition(x, z, y);

	//creature->insertToZone(zone);

	if (cellParent != NULL) {
		cellParent->transferObject(creature, -1);
	} else
		zone->transferObject(creature, -1, true);
}
Esempio n. 8
0
UInt32 __os_atomic_sub(UInt32 *area,UInt32 val)
{
	//OSGlobalCriticalSection _ogcs;
	OSMutexLocker _locker(&GetAtomicMutex());
	*area -= val;
	return *area;
}
Esempio n. 9
0
BOOL KProcessInfo::IsSkipSoftware()
{
	kis::KLocker	_locker(m_lock);
	if (m_pExeImage)
		return m_pExeImage->IsSkipSoftware();
	return FALSE;
}
Esempio n. 10
0
LPCWSTR	KProcessInfo::GetProcPath()
{
	kis::KLocker	_locker(m_lock);
	if (m_pExeImage)
		return m_pExeImage->GetPath();
	return NULL;
}
Esempio n. 11
0
void KProcessInfo::GetModuleStastic(DWORD& nUnkownCnt, DWORD& nDangerCnt, DWORD& nUnScanCnt)
{
	kis::KLocker	_locker(m_lock);

	if  (!m_ModuleList.empty())
	{
		vector<KProcImage*>	ImageLeft;
		size_t i = 0;
		while (i < m_ModuleList.size())
		{
			KProcImage* pImage = m_ModuleList[i];
			if (pImage->IsSafe())
			{
				delete pImage;
			}
			else
			{
				pImage->GetModuleStastic(nUnkownCnt, nDangerCnt, nUnScanCnt);
				ImageLeft.push_back(pImage);
			}
			i++;
		}
		m_ModuleList = ImageLeft;
	}
}
Esempio n. 12
0
BOOL KProcessInfo::OnLoadImage(ULONGLONG nLoadTime, KModuleInfo* pModule)
{
	kis::KLocker	_locker(m_lock);
	KProcImage* pImage = new KProcImage(pModule, nLoadTime);
	AddImageToList(pImage, nLoadTime);
	return TRUE;
}
Esempio n. 13
0
KModuleInfo* KProcessInfo::GetExeImage()
{
	kis::KLocker	_locker(m_lock);
	if (m_pExeImage)
		return m_pExeImage->GetModule();
	return NULL;
}
void ObjectManager::destroyObject(uint64 objectID) {
	Locker _locker(this);

	Reference<SceneObject*> object = objectMap->remove(objectID);

	if (object != NULL) {
		object->info("finalizing object");

		while (object->getSlottedObjectsSize() > 0) {
			Reference<SceneObject*> obj = object->getSlottedObject(0);

			object->removeObject(obj);

			destroyObject(obj->getObjectID());
		}

		while (object->getContainerObjectsSize() > 0) {
			Reference<SceneObject*> obj = object->getContainerObject(0);

			object->removeObject(obj);

			destroyObject(obj->getObjectID());
		}

		//object->finalize();
	}
}
Esempio n. 15
0
PortalLayout* TemplateManager::getPortalLayout(const String& fileName) {
	Locker _locker(&appearanceMapLock);

	PortalLayout* portalLayout = portalLayoutMap->get(fileName);

	if (portalLayout == NULL) {
		IffStream* iffStream = openIffFile(fileName);

		if (iffStream != NULL) {
			try {
				portalLayout = new PortalLayout();

				portalLayout->readObject(iffStream);

				info("parsed " + fileName);
			} catch (Exception& e) {
				info("could not parse " + fileName);

				delete portalLayout;
				portalLayout = NULL;
			}

			delete iffStream;
			iffStream = NULL;

			portalLayoutMap->put(fileName, portalLayout);
		}
	}

	return portalLayout;
	//return NULL;
}
Esempio n. 16
0
void Zone::stopFollow() {
	PlayerCreature* player = getSelfPlayer();

	Locker _locker(player);

	player->setFollow(NULL);
	client->getClient()->info("stopped following", true);
}
void ResourceManagerImplementation::shiftResources() {
	Locker _locker(_this.getReferenceUnsafeStaticCast());

	resourceSpawner->shiftResources();

	Reference<ResourceShiftTask*> resourceShift = new ResourceShiftTask(_this.getReferenceUnsafeStaticCast());
	resourceShift->schedule(shiftInterval);
}
void ResourceManagerImplementation::startResourceSpawner() {
	Locker _locker(_this.get());

	resourceSpawner->start();

	Reference<ResourceShiftTask*> resourceShift = new ResourceShiftTask(_this.get().get());
	resourceShift->schedule(shiftInterval);
}
CreatureObject* ChatManagerImplementation::removePlayer(const String& name) {
	Locker _locker(_this.getReferenceUnsafeStaticCast());

	String lName = name.toLowerCase();

	CreatureObject* player = playerMap->remove(lName, false);

	return player;
}
Esempio n. 20
0
DWORD KProcessInfo::GetProcSecurity()
{
	kis::KLocker	_locker(m_lock);
	if (m_nPID == 4 || m_nPID == 8 || m_nPID == 0)
		return enumKSBW_FSR_WHITE_FILE;
	if (m_pExeImage)
		return m_pExeImage->GetSecurityState();
	return 0;
}
Esempio n. 21
0
CScmClient::~CScmClient()
{
	OSMutexLocker _locker(&scm_rpc_client_mutex);
	if(--scm_rpc_client_count == 0)
	{
		scm_rpc_client->Release();
		scm_rpc_client = NULL;
	}
}
Esempio n. 22
0
UInt32 __os_atomic_or(UInt32 *area, UInt32 val)
{
	UInt32 oldval;

	//OSGlobalCriticalSection _ogcs;
	OSMutexLocker _locker(&GetAtomicMutex());
	oldval=*area;
	*area = oldval | val;
	return oldval;
}
Esempio n. 23
0
void OSEventThread::idleTimeOut(unsigned long timespan, void *userdata)
{
    OSEventThread * This = (OSEventThread*)userdata;
    OSMutexLocker _locker(&This->mMutex);
    
    TRACE("\n");
    if(This->mWatchNum == 0 && This->mIdleTimeout >=0 ){
        This->SendStopRequest();
    }
}
Esempio n. 24
0
	void Defer_OnNewUser(ChatSession*  cs,const String16& pwszUser)
	{
		_TRACE("ChatWorkThread:Defer_OnNewUser>>(cs %p) %s",cs,DISPLAY_STRING16(pwszUser));
		sp<work_item_t> data = new work_item_t(WORK_Defer_OnNewUser,cs,pwszUser,String16());
		Mutex::Autolock _locker(workMutex);
		work.add(data);
		workCond.signal();

		_TRACE("ChatWorkThread:Defer_OnNewUser<<(cs %p)",cs);		
	}
Esempio n. 25
0
	void Defer_OnUserLeft(ChatSession* cs,const String16& pwszUser)
	{
		_TRACE("ChatWorkThread:Defer_OnUserLeft>> (cs %p)",cs);
		sp<work_item_t> data = new work_item_t(WORK_Defer_OnUserLeft,cs,pwszUser,String16());	
		Mutex::Autolock _locker(workMutex);
		work.add(data);
		workCond.signal();

		_TRACE("ChatWorkThread:Defer_OnUserLeft<< (cs %p)",cs);		
	}
Esempio n. 26
0
BOOL KProcessInfo::SetExeImage(KModuleInfo* pModule)
{
	kis::KLocker	_locker(m_lock);
	if (!m_pExeImage)
	{
		m_pExeImage = new KProcImage(pModule, m_nCreateTime);
		pModule->SetTestChange(TRUE);
		return TRUE;
	}
	return FALSE;
}
Esempio n. 27
0
Log::~Log()
{
	if(m_outfileHandle)
	{
		fclose(m_outfileHandle);
	}
    WorkerThreads::getInstance()->removeThreadForMainRepeat(LOGUPDATESTRING);
    
    ScopedMutex _locker(m_mutexBuffer);
	m_networkBufList.clear();

}
Esempio n. 28
0
void KProcessInfo::ClearModuleList()
{
	kis::KLocker	_locker(m_lock);
	for (size_t i = 0; i < m_ModuleList.size(); i++)
		delete m_ModuleList[i];
	m_ModuleList.clear();
	if (m_pExeImage)
	{
		delete m_pExeImage;
		m_pExeImage = NULL;
	}
	m_nLastImageLoadTime = 0;
}
Esempio n. 29
0
int StructureManager::redeedStructure(CreatureObject* creature) {
	ManagedReference<DestroyStructureSession*> session = creature->getActiveSession(SessionFacadeType::DESTROYSTRUCTURE).castTo<DestroyStructureSession*>();

	if (session == NULL)
		return 0;

	ManagedReference<StructureObject*> structureObject =
			session->getStructureObject();

	if (structureObject == NULL)
		return 0;

	Locker _locker(structureObject);

	ManagedReference<StructureDeed*> deed =
			server->getObject(
					structureObject->getDeedObjectID()).castTo<StructureDeed*>();

	int maint = structureObject->getSurplusMaintenance();
	int redeedCost = structureObject->getRedeedCost();

	if (deed != NULL && structureObject->isRedeedable()) {
		Locker _lock(deed, structureObject);

		ManagedReference<SceneObject*> inventory = creature->getSlottedObject(
				"inventory");

		if (inventory == NULL || inventory->isContainerFull()) {
			creature->sendSystemMessage("@player_structure:inventory_full"); //This installation can not be redeeded because your inventory does not have room to put the deed.
			creature->sendSystemMessage(
					"@player_structure:deed_reclaimed_failed"); //Structure destroy and deed reclaimed FAILED!
			return session->cancelSession();
		} else {
			deed->setSurplusMaintenance(maint - redeedCost);
			deed->setSurplusPower(structureObject->getSurplusPower());

			structureObject->setDeedObjectID(0); //Set this to 0 so the deed doesn't get destroyed with the structure.

			destroyStructure(structureObject);

			inventory->transferObject(deed, -1, true);
			inventory->broadcastObject(deed, true);
			creature->sendSystemMessage("@player_structure:deed_reclaimed"); //Structure destroyed and deed reclaimed.
		}
	} else {
		destroyStructure(structureObject);
		creature->sendSystemMessage("@player_structure:structure_destroyed"); //Structured destroyed.
	}

	return session->cancelSession();
}
void ChatManagerImplementation::destroyRooms() {
	Locker _locker(_this.getReferenceUnsafeStaticCast());

	HashTableIterator<unsigned int, ManagedReference<ChatRoom* > > iter = roomMap->iterator();

	while (iter.hasNext()) {
		ChatRoom* room = iter.next();
		room->finalize();
	}

	roomMap->removeAll();

	gameRooms.removeAll();
}