Esempio n. 1
0
STDMETHODIMP CCoFAHost::Init(IUnknown *events)
{
    TRY_CATCH_COM

    Log.Add(_MESSAGE_,_T("CCoFAHost::Init()"));

    HRESULT result;
    Log.Add(_MESSAGE_,_T("CCoFAHost::Init(0x%08x) m_dwRef=0x%x"),events,m_dwRef);
    // Attaching to broker events (which is actually not events, but broker pointer, having the same sence)
    //CComPtr<IUnknown> eventsUnkn;
    //eventsUnkn.Attach(reinterpret_cast<IUnknown*>(events));
    //if(S_OK != (result=eventsUnkn.QueryInterface(&m_brokerEvents)))
    //{
    //	SetLastError(result);
    //	MCException_Win(_T("QueryInterface(_IBrokerClientEvents) failed "));
    //}

    CComPtr<IUnknown> eventsUnkn(events);
    CComPtr<_IBrokerClientEvents> brokerEvents;
    if(S_OK != (result=eventsUnkn.QueryInterface(&brokerEvents)))
    {
        SetLastError(result);
        throw MCException_Win(_T("QueryInterface(_IBrokerClientEvents) failed "));
    }

    if(S_OK!=(result=m_brokerEvents.Attach(brokerEvents)))
        throw CExceptionBase(__LINE__,_T(__FILE__),_T(__DATE__),tstring(_T("Broker object GIT registeration failed")),result);

    /// Requesting stream
    if((result=brokerEvents->GetSubStream(CComBSTR(BUSERIDPDV_AUTOSET), BSVCIDPDV_AUTOSET, FASSID_MAIN, FASSP_SERVICE))!=S_OK)
    {
        SetLastError(result);
        throw MCException_Win("Service substream obtaining failed");
    }

    /// Sending request to indicate - service is on
    if(NULL != brokerEvents.p)
        brokerEvents->RequestSent(CComBSTR(BUSERIDPDV_LOCAL),BSVCIDPDV_JS,CComBSTR(BUSERIDPDV_AUTOSET),BSVCIDPDV_AUTOSET,0/*rid*/,BRT_SRV_STATE_CHANGED,ESM_SERVICE_STARTED/*on*/,CComBSTR(_T("File manager"))); //TODO: treat name carefully

    /// Starting notifications thread
    Start();

    CATCH_LOG_COM
}
Esempio n. 2
0
bool LoadSessionData(
    IN MRABase& _db,
    IN MAKFC_CString databaseKey, 
    OUT MAKFC_CString& sDevId, 
    OUT MAKFC_CString& sA, 
    OUT MAKFC_CString& sSessionKey, 
    OUT MAKFC_CString& ts)
{
    gigabase::dbArray<gigabase::byte> data;
    if ( !_db.ReadRawData( tstring(databaseKey.NetStrW()), L"", ICQ_PARTNERS_LOGIN_DATA, data ) )
    {
        return false;
    }

    MAKFC_CString sCookies = (LPCWSTR) data.get();
    if ( !sCookies.Len() )
        return false;

    int iStart1 = 0;
    MAKFC_CString sToken1;

    while ( ( sToken1 = sCookies.Tokenize( L";", iStart1 ) ).GetLength() )
    {
        int iStart2 = 0;
        MAKFC_CString sLeft = sToken1.Tokenize( L"=", iStart2 );
        MAKFC_CString sRight = sToken1.Mid( iStart2 );

        if ( sLeft == L"k" )
            sDevId = sRight;
        else if ( sLeft == L"a" )
            sA = sRight;
        else if ( sLeft == L"session_key" )
            sSessionKey = sRight;
        else if ( sLeft == L"time_offset" )
        {
            __int64 offset = _wtoi64( sRight );
            time_t tt = 0;
            FileTimeToUnixTime( &tt, CFileTime( CFileTime::GetCurrentTime().GetTime() - offset ) );
            ts.Format( L"%d", (DWORD) tt );
        }
    }

    return true;
}
Esempio n. 3
0
void CCPU::StartTurn()
{
	BaseClass::StartTurn();

	if (m_bProducing)
	{
		m_iTurnsToProduceRogue -= (size_t)1;
		if (m_iTurnsToProduceRogue == (size_t)0)
		{
			if (GameNetwork()->IsHost())
			{
				CDigitank* pTank = GameServer()->Create<CScout>("CScout");
				pTank->SetGlobalOrigin(GetGlobalOrigin());
				pTank->CalculateVisibility();
				GetDigitanksPlayer()->AddUnit(pTank);

				for (size_t x = 0; x < UPDATE_GRID_SIZE; x++)
				{
					for (size_t y = 0; y < UPDATE_GRID_SIZE; y++)
					{
						if (GetDigitanksPlayer()->HasDownloadedUpdate(x, y))
							pTank->DownloadComplete(x, y);
					}
				}

				// Face him toward the center.
				pTank->Move(pTank->GetGlobalOrigin() + -GetGlobalOrigin().Normalized()*15);
				pTank->Turn(VectorAngles(-GetGlobalOrigin().Normalized()));

				pTank->StartTurn();
			}

			m_bProducing = false;

			GetDigitanksPlayer()->AppendTurnInfo("Production finished on Rogue");

			GetDigitanksPlayer()->AddActionItem(this, ACTIONTYPE_UNITREADY);
		}
		else
		{
			GetDigitanksPlayer()->AppendTurnInfo(tsprintf(tstring("Producing Rogue (%d turns left)"), m_iTurnsToProduceRogue.Get()));
		}
	}
}
void FavoriteHubsFrame::addEntry(const FavoriteHubEntry* entry, int pos, int groupIndex) {
	TStringList l;
	l.push_back(Text::toT(entry->getName()));
	l.push_back(Text::toT(entry->getDescription()));
	l.push_back(Text::toT(entry->getNick(false)));
	l.push_back(tstring(entry->getPassword().size(), 0x25CF));
	l.push_back(Text::toT(entry->getServer()));
	l.push_back(Text::toT(entry->getUserDescription()));
	bool b = entry->getConnect();
	int i = ctrlHubs.insert(pos, l, 0, (LPARAM)entry);
	ctrlHubs.SetCheckState(i, b);

    LVITEM lvItem = { 0 };
    lvItem.mask = LVIF_GROUPID;
    lvItem.iItem = i;
    lvItem.iSubItem = 0;
    lvItem.iGroupId = groupIndex;
    ctrlHubs.SetItem( &lvItem );
}
LRESULT FavoriteHubsFrame::onEdit(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/) {
	int i = -1;
	if((i = ctrlHubs.GetNextItem(i, LVNI_SELECTED)) != -1)
	{
		FavoriteHubEntry* e = (FavoriteHubEntry*)ctrlHubs.GetItemData(i);
		dcassert(e != NULL);
		FavHubProperties dlg(e);
		if(dlg.DoModal(m_hWnd) == IDOK)
		{
			ctrlHubs.SetItemText(i, COLUMN_NAME, Text::toT(e->getName()).c_str());
			ctrlHubs.SetItemText(i, COLUMN_DESCRIPTION, Text::toT(e->getDescription()).c_str());
			ctrlHubs.SetItemText(i, COLUMN_SERVER, Text::toT(e->getServer()).c_str());
			ctrlHubs.SetItemText(i, COLUMN_NICK, Text::toT(e->getNick(false)).c_str());
			ctrlHubs.SetItemText(i, COLUMN_PASSWORD, tstring(e->getPassword().size(), '*').c_str());
			ctrlHubs.SetItemText(i, COLUMN_USERDESCRIPTION, Text::toT(e->getUserDescription()).c_str());
		}
	}
	return 0;
}
Esempio n. 6
0
void CGameServer::SetClientNickname(int iClient, const tstring& sNickname)
{
	if (iClient == GetClientIndex() && Game()->GetNumLocalPlayers())
	{
		Game()->GetLocalPlayer(0)->SetPlayerName(sNickname);
		return;
	}

	for (size_t i = 0; i < Game()->GetNumPlayers(); i++)
	{
		if (Game()->GetPlayer(i)->GetClient() == iClient)
		{
			Game()->GetPlayer(i)->SetPlayerName(sNickname);
			return;
		}
	}

	TMsg(sprintf(tstring("Can't find client %d to give nickname %s.\n"), iClient, sNickname.c_str()));
}
Esempio n. 7
0
static void print_share_mode(share_mode_entry *e, char *fname)
{
	char           *utf8_fname;

	printf("<tr><td>%s</td>",_(mapPid2Machine(e->pid)));
	printf("<td>");
	switch ((e->share_mode>>4)&0xF) {
	case DENY_NONE: printf("DENY_NONE"); break;
	case DENY_ALL:  printf("DENY_ALL   "); break;
	case DENY_DOS:  printf("DENY_DOS   "); break;
	case DENY_READ: printf("DENY_READ  "); break;
	case DENY_WRITE:printf("DENY_WRITE "); break;
	}
	printf("</td>");

	printf("<td>");
	switch (e->share_mode&0xF) {
	case 0: printf("%s", _("RDONLY     ")); break;
	case 1: printf("%s", _("WRONLY     ")); break;
	case 2: printf("%s", _("RDWR       ")); break;
	}
	printf("</td>");

	printf("<td>");
	if((e->op_type & 
	    (EXCLUSIVE_OPLOCK|BATCH_OPLOCK)) == 
	   (EXCLUSIVE_OPLOCK|BATCH_OPLOCK))
		printf("EXCLUSIVE+BATCH ");
	else if (e->op_type & EXCLUSIVE_OPLOCK)
		printf("EXCLUSIVE       ");
	else if (e->op_type & BATCH_OPLOCK)
		printf("BATCH           ");
	else if (e->op_type & LEVEL_II_OPLOCK)
		printf("LEVEL_II        ");
	else
		printf("NONE            ");
	printf("</td>");

	push_utf8_allocate(&utf8_fname, fname);
	printf("<td>%s</td><td>%s</td></tr>\n",
	       utf8_fname,tstring(e->time.tv_sec));
	SAFE_FREE(utf8_fname);
}
Esempio n. 8
0
/* traversal fn for showing share connections */
static int traverse_fn3(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf, void* state)
{
	struct connections_data crec;

	if (dbuf.dsize != sizeof(crec))
		return 0;

	memcpy(&crec, dbuf.dptr, sizeof(crec));

	if (crec.cnum == -1 || !process_exists(crec.pid))
		return 0;

	printf("<tr><td>%s</td><td>%s</td><td>%s</td><td>%d</td><td>%s</td><td>%s</td></tr>\n",
	       crec.name,uidtoname(crec.uid),
	       gidtoname(crec.gid),(int)crec.pid,
	       crec.machine,
	       tstring(crec.start));
	return 0;
}
Esempio n. 9
0
LRESULT CCoFAViewer::OnMouseActivate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
TRY_CATCH

	HRESULT result;
	if(!m_brokerEvents.m_dwCookie)
		throw MCException("_IBrokerClientEvents has not set. Call IBrokerClient::Init() method at first");
	CComPtr<_IBrokerClientEvents> brokerEvents;
	if(S_OK!=(result=m_brokerEvents.CopyTo(&brokerEvents)))
		throw CExceptionBase(__LINE__,_T(__FILE__),_T(__DATE__),tstring(_T("IBrokerClientEvents obtaining failed in Broker")),result);
	if(!brokerEvents.p)
		throw MCException("_IBrokerClientEvents has not marshaled");

	brokerEvents->RequestSent(CComBSTR(BUSERIDPDV_LOCAL),BSVCIDPDV_JS,CComBSTR(BUSERIDPDV_AUTOSET),BSVCIDPDV_AUTOSET,RId(),BRT_SELECT_WIDGET,0,CComBSTR(_T("empty")));

	return MA_ACTIVATE;

CATCH_THROW()
}
Esempio n. 10
0
int tstring::Replace(LPCTSTR pszOld, LPCTSTR pszNew)
{
	if(*PSTRING == TEXT("")) return 0;
	if(tstring(pszOld) == TEXT("")) return 0;

	int intPos = 0;
	int intCount = 0;
	while(1)
	{
		intPos = PSTRING->find(pszOld, intPos);
		if(intPos == tstring::npos) break;

		PSTRING->replace(intPos, lstrlen(pszOld), pszNew);
		intPos += lstrlen(pszNew);
		intCount++;
	}

	return intCount;
}
Esempio n. 11
0
void CgcTcpClient::OnReceiveData(const TcpClientPointer& tcpClient, const mycp::asio::ReceiveBuffer::pointer& data)
{
	BOOST_ASSERT (tcpClient.get() != 0);
	BOOST_ASSERT (data.get() != 0);
	if (data->size() <= 0) return;
	if (m_pCallback != NULL)
		m_pCallback->OnReceiveData(data);
	//unsigned char lpszBuffer[1024];
	//memcpy(lpszBuffer,data->data(),data->size());
	//m_tSendRecv = time(0);
	//this->parseData(CCgcData::create(data->data(), data->size()));
#ifdef USES_PARSER_HTTP
	if (m_bHttpResponseOk)
	{
		//printf("******** %s, OnReceiveData(size=%d) HttpResponseOk=1 error\n",m_sResponseSaveFile.c_str(), data->size());
		return;
	}
	m_tLastTime = time(0);
	if (m_pParserHttp.get()==NULL)
	{
		CPpHttp* parserHttp = new CPpHttp();
		parserHttp->SetResponseSaveFile(m_sResponseSaveFile);
		parserHttp->theUpload.setDeleteFile(m_bDeleteFile);
		parserHttp->theUpload.setEnableAllContentType(true);
		parserHttp->theUpload.setEnableUpload(true);
		parserHttp->theUpload.setMaxFileCount(0);
		parserHttp->theUpload.setMaxFileSize(0);
		parserHttp->theUpload.setMaxUploadSize(0);
		//parserHttp->theUpload.load(theXmlFile);
		//parserHttp->setFileSystemService(theFileSystemService);
		m_pParserHttp = cgcParserHttp::pointer(parserHttp);
	}
	//printf("***%d\n%s\n***\n",data->size(),data->data());
	if (m_pParserHttp->doParse(data->data(),data->size()))
		m_bHttpResponseOk = true;
	//const int nReceiveSize = ((CPpHttp*)m_pParserHttp.get())->GetReceiveSize();
	//printf("******** (%s), OnReceiveData(size=%d), ContentLength=%d, ReceiveSize=%d, HttpResponseOk=%d\n",(const char*)data->data(),data->size(),m_pParserHttp->getContentLength(),nReceiveSize,(int)(m_bHttpResponseOk?1:0));
	//printf("******** %s, OnReceiveData(size=%d), ContentLength=%d, ReceiveSize=%d, HttpResponseOk=%d\n",m_sResponseSaveFile.c_str(),data->size(),m_pParserHttp->getContentLength(),nReceiveSize,(int)(m_bHttpResponseOk?1:0));
#else
	m_sReceiveData.append(tstring((const char*)data->data(), data->size()));
#endif
}
Esempio n. 12
0
bool CStreamCgcProxy::sendP2PAck(CDoP2PClientHandler::pointer pP2PClient, long nP2PType, long nP2PParam, bool bAckAck)
{
	BOOST_ASSERT (pP2PClient.get() != NULL);

	if (!avsIsOpenSession()) return false;
	if (m_sCurrentUser.empty()) return false;
	if (pP2PClient == NULL) return false;

	DoSotpClientHandler::pointer pDoHandler = pP2PClient->dohandler();
	BOOST_ASSERT(pDoHandler.get() != NULL);

	pDoHandler->doBeginCallLock();
	if (bAckAck)
		pDoHandler->doAddParameter(CGC_PARAMETER(_T("P2PACKACK"), tstring(_T("1"))));
	pDoHandler->doAddParameter(CGC_PARAMETER(_T("FromUser"), m_sCurrentUser));
	pDoHandler->doAddParameter(CGC_PARAMETER(_T("P2PType"), nP2PType));
	pDoHandler->doAddParameter(CGC_PARAMETER(_T("P2PParam"), nP2PParam));
	pDoHandler->doSendAppCall(const_CallSign_P2PAck, const_Avs_Api_P2PAck);
	return true;
}
Esempio n. 13
0
bool MultipleInstanceManager::GetParameters(std::list<tstring>& params, DWORD size)
{
	HANDLE hMappedFile;
	BYTE* buffer;

	if( !CreateSharedData(&buffer, &hMappedFile, size) )
		return false;

	TCHAR* pParam = reinterpret_cast<TCHAR*>( buffer );
	while( *pParam )
	{
		params.push_back( tstring(pParam) );

		pParam += (_tcslen(pParam) + 1);
	}

	ReleaseSharedData(buffer, hMappedFile);

	return true;
}
Esempio n. 14
0
CMBR::CMBR(const TCHAR* deviceName, HANDLE hDevice)
{
	m_pPhysRawDisk = NULL;
	VOLUME_DISK_EXTENTS extents;
	memset(&extents, 0, sizeof(extents));
	DWORD byteswritten = 0;
	if (!hDevice)
	{
		CRawDisk tempdisk(deviceName);
		hDevice = tempdisk.getHandle();
		if (!DeviceIoControl(hDevice, IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS, NULL, 0, &extents, sizeof(extents), &byteswritten, NULL))
		{
			cout << "Error getting Physical Device (" << GetLastError() << "), aborting...\n";
			throw "Error in MBR (" __FILE__ ") attaining physcial device";
		}
	}
	else
	{
		if (!DeviceIoControl(hDevice, IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS, NULL, 0, &extents, sizeof(extents), &byteswritten, NULL))
		{
			cout << "Error getting Physical Device (" << GetLastError() << "), aborting...\n";
			throw "Error in MBR (" __FILE__ ") attaining physcial device";
		}
	}
	m_hDevice = hDevice;
	if (!DeviceIoControl(hDevice, IOCTL_DISK_GET_DRIVE_GEOMETRY, NULL, 0, &geometry, sizeof(geometry), &byteswritten, NULL))
	{
		cout << "Error getting Physical Device (" << GetLastError() << "), aborting...\n";
		throw "Error in MBR (" __FILE__ ") attaining physcial device";
	}
	int nPhysDrive = extents.Extents[0].DiskNumber;
	tstring path = tstring(_T("\\\\.\\PhysicalDrive") + to_tstring(nPhysDrive));
	m_physicalpath = path;
	m_pPhysRawDisk = new CRawDisk(path.c_str());
	m_pPhysRawDisk->setSectorSize(geometry.BytesPerSector);
	PARTITION_INFORMATION_EX partinfo;
	DWORD read = 0;
	if (!DeviceIoControl(hDevice, IOCTL_DISK_GET_PARTITION_INFO_EX, NULL, 0, &partinfo, sizeof(partinfo), &read, NULL))
		throw "Cannot get partititon information";
	m_partsize = partinfo.PartitionLength.QuadPart / geometry.BytesPerSector;
}
Esempio n. 15
0
void FavoriteHubsFrame::addEntry(const FavoriteHubEntryPtr& entry, int pos, int groupIndex) {
	TStringList l;
	l.push_back(Text::toT(entry->getName()));
	l.push_back(Text::toT(entry->getDescription()));
	l.push_back(Text::toT(entry->get(HubSettings::Nick)));
	l.push_back(tstring(entry->getPassword().size(), '*'));
	l.push_back(Text::toT(entry->getServer()));
	l.push_back(Text::toT(entry->get(HubSettings::Description)));
	l.push_back(Text::toT(entry->getShareProfileName()));
	bool b = entry->getAutoConnect();
	int i = ctrlHubs.insert(pos, l, 0, (LPARAM)entry.get());
	ctrlHubs.SetCheckState(i, b);

    LVITEM lvItem = { 0 };
    lvItem.mask = LVIF_GROUPID | LVIF_IMAGE;
    lvItem.iItem = i;
	lvItem.iImage = isOnline(entry->getServer()) ? 0 : 1;
    lvItem.iSubItem = 0;
    lvItem.iGroupId = groupIndex;
    ctrlHubs.SetItem( &lvItem );
}
Esempio n. 16
0
void CGameServer::ClientInfo(int iConnection, CNetworkParameters* p)
{
	if (m_iClient != p->i1)
		CGame::ClearLocalPlayers(NULL);

	m_iClient = p->i1;
	float flNewGameTime = p->fl2;
	if (flNewGameTime - m_flGameTime > 0.1f)
		TMsg(sprintf(tstring("New game time from server %.1f different!\n"), flNewGameTime - m_flGameTime));

	m_flGameTime = flNewGameTime;

	// Can't send any client commands until we've gotten the client info because we need m_iClient filled out properly.
	if (!m_bGotClientInfo)
	{
		GameNetwork()->SetRunningClientFunctions(false);
		SendNickname.RunCommand(m_sNickname);
	}

	m_bGotClientInfo = true;
}
Esempio n. 17
0
	SaveFileDialog::SaveFileDialog(Window& parent, const tstring& filter)
	{
		OPENFILENAME ofn           = {0};
		TCHAR FileName[MAX_PATH]   = WIDEN("");
		TCHAR leFilter[MAX_PATH]   = WIDEN("");

		unsigned int i = 0;
		for(const auto& letter : filter)
			leFilter[i++] = letter;

		ofn.lStructSize     = sizeof(ofn);
		ofn.hwndOwner       = parent.GetHandle();
		ofn.lpstrFilter		= leFilter;
		ofn.lpstrFile       = FileName;
		ofn.lpstrInitialDir = WIDEN(".");
		ofn.nMaxFile        = MAX_PATH;
		ofn.Flags           = OFN_EXPLORER | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;

		if(GetSaveFileName(&ofn))
			this->retStr = tstring(FileName);
	}
Esempio n. 18
0
void DirectoryMonitor::processNotification(const string& aPath, const ByteVector& aBuf) {
	char* pBase = (char*)&aBuf[0];
	string oldPath;

	for (;;)
	{
		FILE_NOTIFY_INFORMATION& fni = (FILE_NOTIFY_INFORMATION&)*pBase;

		string notifyPath(Text::fromT(tstring(fni.FileName, fni.FileNameLength / sizeof(wchar_t) )));

		auto fileName = Util::getFileName(notifyPath);

		notifyPath = aPath + notifyPath;
		switch(fni.Action) {
			case FILE_ACTION_ADDED: 
				// The file was added to the directory.
				fire(DirectoryMonitorListener::FileCreated(), notifyPath);
				break;
			case FILE_ACTION_REMOVED: 
				// The file was removed from the directory.
				fire(DirectoryMonitorListener::FileDeleted(), notifyPath);
				break;
			case FILE_ACTION_RENAMED_OLD_NAME: 
				// The file was renamed and this is the old name. 
				oldPath = notifyPath;
				break;
			case FILE_ACTION_RENAMED_NEW_NAME: 
				// The file was renamed and this is the new name.
				fire(DirectoryMonitorListener::FileRenamed(), oldPath, notifyPath);
				break;
			case FILE_ACTION_MODIFIED:
				fire(DirectoryMonitorListener::FileModified(), notifyPath);
				break;
		}

		if (!fni.NextEntryOffset)
			break;
		pBase += fni.NextEntryOffset;
	};
}
Esempio n. 19
0
/* traversal fn for showing machine connections */
static int traverse_fn2(const struct connections_key *key,
                        const struct connections_data *crec,
                        void *private_data)
{
	if (crec->cnum == -1 || !process_exists(crec->pid) ||
	    procid_equal(&crec->pid, &smbd_pid))
		return 0;

	addPid2Machine (crec->pid, crec->machine);

	printf("<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td>\n",
	       procid_str_static(&crec->pid),
	       crec->machine, crec->addr,
	       tstring(talloc_tos(),crec->start));
	if (geteuid() == 0) {
		printf("<td><input type=submit value=\"X\" name=\"kill_%s\"></td>\n",
		       procid_str_static(&crec->pid));
	}
	printf("</tr>\n");

	return 0;
}
Esempio n. 20
0
size_t CGameServer::CreateEntity(const tstring& sClassName, size_t iHandle, size_t iSpawnSeed)
{
	if (CVar::GetCVarBool("net_debug"))
		TMsg(tstring("Creating entity: ") + sClassName + "\n");

	auto it = CBaseEntity::GetEntityRegistration().find(sClassName);
	if (it == CBaseEntity::GetEntityRegistration().end())
	{
		TAssert(!"Entity does not exist. Did you forget to REGISTER_ENTITY ?");
		return ~0;
	}

	CBaseEntity::s_iOverrideEntityListIndex = iHandle;
	iHandle = it->second.m_pfnCreateCallback();
	CBaseEntity::s_iOverrideEntityListIndex = ~0;

	CEntityHandle<CBaseEntity> hEntity(iHandle);
	hEntity->m_sClassName = sClassName;

	hEntity->SetSaveDataDefaults();

	size_t iPostSeed = mtrand();

	if (iSpawnSeed)
		hEntity->SetSpawnSeed(iSpawnSeed);
	else
		hEntity->SetSpawnSeed(mtrand()%99999);	// Don't pick a number so large that it can't fit in (int)

	hEntity->SetSpawnTime(GameServer()->GetGameTime());

	hEntity->Spawn();

	mtsrand(iPostSeed);

	if (dynamic_cast<CGame*>(hEntity.GetPointer()))
		m_hGame = CEntityHandle<CGame>(hEntity->GetHandle());

	return iHandle;
}
Esempio n. 21
0
void CPlayerPanel::ColorChosenCallback(const tstring& sArgs)
{
#if 0
	CLobbyPlayer* pPlayer = CGameLobbyClient::L_GetPlayer(m_iLobbyPlayer);

	TAssert(pPlayer);
	if (!pPlayer)
		return;

	size_t iSelected = m_pColor->GetSelectedMenu();
	m_bRandomColor = (iSelected == 0);
	if (!m_bRandomColor)
		m_iColor = m_aiAvailableColors[iSelected-1];

	m_pColor->Pop(true, true);

	if (m_bRandomColor)
		CGameLobbyClient::S_UpdatePlayer(pPlayer->iID, _T("color"), _T("random"));
	else
		CGameLobbyClient::S_UpdatePlayer(pPlayer->iID, _T("color"), tsprintf(tstring("%d"), m_iColor));
#endif
}
Esempio n. 22
0
static void print_share_mode(share_mode_entry *e, char *fname)
{
	printf("<tr><td>%s</td>", mapPid2Machine (e->pid));
	printf("<td>");
	switch ((e->share_mode>>4)&0xF) {
	case DENY_NONE: printf("DENY_NONE"); break;
	case DENY_ALL:  printf("DENY_ALL   "); break;
	case DENY_DOS:  printf("DENY_DOS   "); break;
	case DENY_READ: printf("DENY_READ  "); break;
	case DENY_WRITE:printf("DENY_WRITE "); break;
	}
	printf("</td>");

	printf("<td>");
	switch (e->share_mode&0xF) {
	case 0: printf("RDONLY     "); break;
	case 1: printf("WRONLY     "); break;
	case 2: printf("RDWR       "); break;
	}
	printf("</td>");

	printf("<td>");
	if((e->op_type & 
	    (EXCLUSIVE_OPLOCK|BATCH_OPLOCK)) == 
	   (EXCLUSIVE_OPLOCK|BATCH_OPLOCK))
		printf("EXCLUSIVE+BATCH ");
	else if (e->op_type & EXCLUSIVE_OPLOCK)
		printf("EXCLUSIVE       ");
	else if (e->op_type & BATCH_OPLOCK)
		printf("BATCH           ");
	else if (e->op_type & LEVEL_II_OPLOCK)
		printf("LEVEL_II        ");
	else
		printf("NONE            ");
	printf("</td>");

	printf("<td>%s</td><td>%s</td></tr>\n",
	       dos_to_unix_static(fname),tstring(e->time.tv_sec));
}
Esempio n. 23
0
int KDownloadUpdatePackage::DownLoadVersion()
{
	int nRetCode = false;
	int nResult  = false;
	tstring strURL;

    m_strUpdateEntryFile  = m_szUpdatePath;
    m_strUpdateEntryFile += UPDATE_VERSION_FILE;

    strURL  = tstring(m_szRemotePath) + UPDATE_VERSION_FILE;

    nRetCode = KGU_DownloadHttpFile(strURL.c_str(), m_strUpdateEntryFile.c_str());
    KGLOG_PROCESS_ERROR(nRetCode);

	nResult = true;
Exit0:
    if (!nResult)
    {
        KLastError::SetErrorCode(UPDATE_ERR_UPDATE_FAILED);
    }
	return nResult;
}
Esempio n. 24
0
void FireInput(class CCommand* pCommand, tvector<tstring>& asTokens, const tstring& sCommand)
{
	if (!CVar::GetCVarBool("cheats"))
		return;

	if (asTokens.size() < 3)
	{
		TMsg("Format: ent_input entityname input [optional args]\n");
		return;
	}

	tvector<CBaseEntity*> apEntities;
	CBaseEntity::FindEntitiesByName(asTokens[1], apEntities);

	if (!apEntities.size())
	{
		if (CVar::GetCVarBool("debug_entity_outputs"))
			TMsg("Console -> none\n");
		else
			TError("No entities found that match name \"" + asTokens[1] + "\".\n");

		return;
	}

	tstring sArgs;
	for (size_t i = 3; i < asTokens.size(); i++)
		sArgs += asTokens[i] + " ";

	for (size_t i = 0; i < apEntities.size(); i++)
	{
		CBaseEntity* pTargetEntity = apEntities[i];

		if (CVar::GetCVarBool("debug_entity_outputs"))
			TMsg("Console -> " + tstring(pTargetEntity->GetClassName()) + "(\"" + pTargetEntity->GetName() + "\")." + asTokens[2] + "(\"" + sArgs + "\")\n");

		pTargetEntity->CallInput(asTokens[2], sArgs);
	}
}
Esempio n. 25
0
LRESULT NotepadFrame::onClose(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled) {
	if(!closed) {
		SettingsManager::getInstance()->removeListener(this);
		if(dirty || ctrlPad.GetModify()) {
				AutoArray<TCHAR> buf(ctrlPad.GetWindowTextLength() + 1);
			ctrlPad.GetWindowText(buf, ctrlPad.GetWindowTextLength() + 1);
			try {
				string tmp(Text::fromT(tstring(buf, ctrlPad.GetWindowTextLength())));
				File(Util::getNotepadFile(), File::WRITE, File::CREATE | File::TRUNCATE).write(tmp);
			} catch(const FileException&) {
				// Oops...
			}
		}

		closed = true;
		WinUtil::setButtonPressed(IDC_NOTEPAD, false);
		PostMessage(WM_CLOSE);
		return 0;
	} else {
		bHandled = FALSE;
		return 0;
	}
}
Esempio n. 26
0
tstring::size_type
tstring::find(char_type const* s, size_type pos, size_type n) const
{    
	if( size() == 0 ) {
		if( n == 0 )
			return 0;
		else
			return npos;
	}

	TINFRA_ASSERT(pos == npos || pos <= this->size() );

    tstring const other = tstring(s, n, false);
    const_iterator result = std::search(
        begin()+pos,
        end(),
        other.begin(),
        other.end());
    if( result == end() )
        return npos;
    else
        return result - begin(); 
}
bool AppSettings::FindFile(const tstring& fname, tstring& resolved_name) const
{
	TCHAR buffer[MAX_PATH];

	// Simply check for fully qualified path
	if (!PathIsRelative(fname.c_str())) {
		if (-1 != _taccess(fname.c_str(), 0)) {
			resolved_name = fname;
			return true;
		}
	}

	// Test if its relative and in one of the specified root paths
	for (tstringlist::const_iterator itr = rootPaths.begin(), end = rootPaths.end(); itr != end; ++itr) {
		PathCombine(buffer, itr->c_str(), fname.c_str());
		if (-1 != _taccess(buffer, 0)) {
			resolved_name = tstring(buffer);
			return true;
		}
	}
	resolved_name = fname;
	return false;
}
Esempio n. 28
0
	OpenFileDialog::OpenFileDialog(Window& parent, const tstring& filter)
	{
		OPENFILENAME ofn           = {0};
		TCHAR FileName[MAX_PATH]   = WIDEN("");
		TCHAR leFilter[MAX_PATH]   = WIDEN("");

		unsigned int i = 0;
		for(const auto& letter : filter)
			leFilter[i++] = letter;

		ofn.lStructSize    = sizeof(OPENFILENAME);
		ofn.hwndOwner      = parent.GetHandle();
		ofn.lpstrFilter    = leFilter;
		ofn.lpstrFile      = FileName;
		ofn.nMaxFile       = MAX_PATH;
		ofn.Flags          = OFN_EXPLORER | OFN_FILEMUSTEXIST;
		ofn.nFileOffset    = 0;
		ofn.nFileExtension = 0;
		ofn.nFilterIndex   = 0;

		if(GetOpenFileName(&ofn))
			this->retStr = tstring(FileName);
	}
void AppSettings::Initialize(Interface *gi)
{
	TCHAR iniName[MAX_PATH];
	GetIniFileName(iniName);
	if (-1 != _taccess(iniName, 0)) {
		bool reparse = GetIniValue<bool>(TEXT("System"), TEXT("Reparse"), false, iniName);
		if (reparse || TheAppSettings.empty()) {
			TheAppSettings.clear();
		}
		TheAppSettingsInitialized = true;

		tstring Applications = GetIniValue<tstring>(TEXT("System"), TEXT("KnownApplications"), TEXT(""), iniName);
		tstringlist apps = TokenizeString(Applications.c_str(), TEXT(";"));
		apps.push_back(tstring(TEXT("User"))); // always ensure that user is present
		for (tstringlist::iterator appstr = apps.begin(); appstr != apps.end(); ++appstr) {
			AppSettings* setting = FindAppSetting(*appstr);
			if (nullptr == setting) {
				AppSettingsMap::iterator itr = TheAppSettings.insert(TheAppSettings.end(), AppSettings(*appstr));
				(*itr).ReadSettings(iniName);
			}
		}
	}
}
Esempio n. 30
0
LRESULT ChatControl::onViewLButtonDblClick(UINT /*uMsg*/, WPARAM wParam, LPARAM lParam, BOOL& bHandled) {
  bHandled = FALSE;
  POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
  int i = ctrlClient.CharFromPos(pt);
  int line = ctrlClient.LineFromChar(i);
  int c = LOWORD(i) - ctrlClient.LineIndex(line);
  int len = ctrlClient.LineLength(i) + 1;
  if (len < 3) {
    return 0;
  }
  AutoArray<TCHAR> buf(len);
  ctrlClient.GetLine(line, buf, len);
  tstring x = tstring(buf, len-1);
  string::size_type start = x.find_last_of(_T(" <\t\r\n"), c);
  if (start == string::npos) {
    start = 0;
  }
  else {
    start++;
  }
  string::size_type end = x.find_first_of(_T(" >\t"), start+1);
  if (end == string::npos) { // get EOL as well
    end = x.length();
  }
  else if (end == start + 1) {
    return 0;
  }
  // Nickname click, let's see if we can find one like it in the name list...
  const tstring nick = x.substr(start, end - start);
  UserInfo* ui = m_listener->findUser(nick);
  if (ui) {
    m_listener->onUserDblClick(ui, wParam);
    bHandled = TRUE;
  }
  return 0;
}