Ejemplo n.º 1
0
KString::KString(LPCTSTR pStr1, size_t szLength1, LPCTSTR pStr2, size_t szLength2)
{
	Allocate(szLength1 + szLength2);

	memcpy(GetDataPtr(), pStr1, GetStreamCharsLength(szLength1));
	memcpy(GetDataPtr(szLength1), pStr2, GetStreamCharsLength(szLength2));
}
Ejemplo n.º 2
0
void CPageDocuments::DisplayShips(int index)
{
  CString info;
  m_list.DeleteAllItems();
  DeleteAllColumns();
  m_list.InsertColumn(0 , "船舰名字" , LVCFMT_LEFT , 100);
  m_list.InsertColumn(1 , "建造金属" , LVCFMT_LEFT , 80);
  m_list.InsertColumn(2 , "建造晶体" , LVCFMT_LEFT , 80);
  m_list.InsertColumn(3 , "建造重氢" , LVCFMT_LEFT , 80);
  m_list.InsertColumn(4 , "建造时间" , LVCFMT_LEFT , 80); 
  m_list.InsertColumn(5 , "攻击能力" , LVCFMT_LEFT , 80); 
  m_list.InsertColumn(6 , "运载能力" , LVCFMT_LEFT , 80); 
  m_list.InsertColumn(7 , "飞行速度" , LVCFMT_LEFT , 80); 
  m_list.InsertColumn(8 , "技术需求" , LVCFMT_LEFT , 250);

  for(int i = 0 ; i < BOAT_MAX ; ++i)
  {
    info.Format("%s" , BOATS_NAME[i]);
    m_list.InsertItem(i , info);

   //metal
    info.Format("%d" , BOATS_RESOURCE_NEED_BASE[i][0] );
    m_list.SetItemText(i , 1 , info);

    //crystal
    info.Format("%d" , BOATS_RESOURCE_NEED_BASE[i][1] );
    m_list.SetItemText(i , 2 , info);

    //diplogen
    info.Format("%d" , BOATS_RESOURCE_NEED_BASE[i][2] );
    m_list.SetItemText(i , 3 , info);

    //time
    double t = get_boat_produce_seconds(
                        GetDataPtr()->GetBuildingLevel(FACTORY_BUILDING_BOATYARD), //shipyard level
                        GetDataPtr()->GetBuildingLevel(FACTORY_BUILDING_NANITE),   //nanitefactory level
                        BOATS_RESOURCE_NEED_BASE[i][0] , 
                        BOATS_RESOURCE_NEED_BASE[i][1], 
                        1.0);
    
    HighFrequencyElapsedTimer timer;
    timer.Init(t * 1000);
    m_list.SetItemText(i , 4 , timer.ToCString());

    //attack force
    info.Format("%d" , UINT(SHIP_ATTACK_FORCE_BASE[i] * (1 + 0.1 * GetDataPtr()->GetResearchLevel(RESEARCH_WEAPON))) );
    m_list.SetItemText(i , 5 , info);

    //transfer capacity force    
    info.Format("%d" , SHIP_TRANSFER_CAPACITY[i] );
    m_list.SetItemText(i , 6 , info);

    //speed
    info.Format("%d" , kernel_.GetShipSpeed(ITEM_TYPE(i) , 0));
    m_list.SetItemText(i , 7 , info);

    //tech needed    
    m_list.SetItemText(i , 8 , Boats_Entry(i)->GetTechNeeded());
   }
}
Ejemplo n.º 3
0
size_t KString::Find(LPCTSTR pSString, size_t szStart) const
{
	DEBUG_VERIFY(szStart <= GetLength());

	LPCTSTR ptr = _tcsstr(GetDataPtr() + szStart, pSString);

	return ptr ? ptr - GetDataPtr() : UINT_MAX;
}
Ejemplo n.º 4
0
size_t KString::Find(TCHAR cChar, size_t szStart) const
{
	DEBUG_VERIFY(szStart <= GetLength());

	LPCTSTR ptr = _tcschr(GetDataPtr() + szStart, cChar);

	return ptr ? ptr - GetDataPtr() : UINT_MAX;
}
Ejemplo n.º 5
0
BOOL CPageBoatyard::IsResourceEnough(int index , UINT number)
{
  assert(index >= 0 && index < boat_keeper_->Size());
  if(GetDataPtr()->GetResource(RESOURCE_METAL) >=   (Boats_Entry(index)->GetProduceMinal() * number)    &&
    GetDataPtr()->GetResource(RESOURCE_CRYSTAL) >=  (Boats_Entry(index)->GetProduceCrystal()  * number) &&
    GetDataPtr()->GetResource(RESOURCE_DIPLOGEN) >= (Boats_Entry(index)->GetProduceDiplogen() * number))
    return TRUE;
  return FALSE;
}
Ejemplo n.º 6
0
TWideString::TWideString(LPCWSTR pWideString)
{
	const size_t szLength = wcslen(pWideString);

	AllocateAdd(szLength + 1);

	memcpy(GetDataPtr(), pWideString, szLength * sizeof(WCHAR));

	GetDataPtr()[szLength] = 0;
}
Ejemplo n.º 7
0
TAnsiString::TAnsiString(LPCSTR pAnsiString)
{
	const size_t szLength = strlen(pAnsiString);

	AllocateAdd(szLength + 1);

	memcpy(GetDataPtr(), pAnsiString, szLength * sizeof(CHAR));

	GetDataPtr()[szLength] = 0;
}
Ejemplo n.º 8
0
KString KString::operator + (TAlignment Alignment) const
{
	if(Alignment == ALIGNMENT_MIN)
		return KString(GetDataPtr(), GetLength(), TEXT("min"), 3);

	if(Alignment == ALIGNMENT_MID)
		return KString(GetDataPtr(), GetLength(), TEXT("mid"), 3);

	if(Alignment == ALIGNMENT_MAX)
		return KString(GetDataPtr(), GetLength(), TEXT("max"), 3);

	INITIATE_FAILURE;
}
Ejemplo n.º 9
0
TWideString::TWideString(LPCSTR pAnsiString)
{
	const size_t szLength = strlen(pAnsiString);

	AllocateAdd(szLength + 1);

	MultiByteToWideChar(CP_ACP,
						0,
						pAnsiString,
						szLength,
						GetDataPtr(),
						szLength);

	GetDataPtr()[szLength] = 0;
}
Ejemplo n.º 10
0
KString KString::Right(size_t szCount) const
{
	if(szCount > GetLength())
		throw 1;

	return KString(GetDataPtr() + (GetLength() - szCount), szCount);
}
Ejemplo n.º 11
0
KString KString::operator + (float fValue) const
{
	TCHAR Buf[32];
	_stprintf(Buf, TEXT("%.2f"), fValue);

	return KString(GetDataPtr(), GetLength(), Buf, _tcslen(Buf));
};
Ejemplo n.º 12
0
KString KString::operator + (double dValue) const
{
	TCHAR Buf[32];
	_stprintf(Buf, TEXT("%.4lf"), dValue);

	return KString(GetDataPtr(), GetLength(), Buf, _tcslen(Buf));
}
void* MMsgRoutingUnsubscribeDataObject::Pack(void)
{
	WTRACE("MMsgRoutingUnsubscribeDataObject::Pack");

	SetServiceType(WONMsg::MiniRoutingServer);
	SetMessageType(WONMsg::RoutingUnsubscribeDataObject);
	RoutingServerMessage::Pack();

	WDBG_LL("MMsgRoutingUnsubscribeDataObject::Pack Appending message data");

	// append the client/group id
	AppendClientOrGroupId(mLinkId);
	
	// append the datatype length followed by the datatype itself
	AppendByte(mDataType.size());
	AppendBytes(mDataType.size(), mDataType.data());

	// append the flags
	unsigned char aFlags = 0;
	if (mExactOrRecursiveFlag) aFlags |= 0x01;
	if (mGroupOrMembersFlag)   aFlags |= 0x02;
	AppendByte(aFlags);

	return GetDataPtr();
}
Ejemplo n.º 14
0
KString KString::operator + (const void* pPtr) const
{
	TCHAR Buf[32];
	_stprintf(Buf, TEXT("%p"), pPtr);

	return KString(GetDataPtr(), GetLength(), Buf, _tcslen(Buf));
}
void* MMsgRoutingCreateGroup::Pack(void)
{
	WTRACE("MMsgRoutingCreateGroup::Pack");

	SetServiceType(WONMsg::MiniRoutingServer);
	SetMessageType(WONMsg::RoutingCreateGroup);
	RoutingServerMessage::Pack();

	WDBG_LL("MMsgRoutingCreateGroup::Pack Appending message data");

	// append group name
	AppendGroupName(mGroupName);

	// append flags
	unsigned char aFlags = 0;
	if (mIsPublic)             aFlags |= 0x01;
	if (mAnnounceGroupChanges) aFlags |= 0x02;
	AppendByte(aFlags);

	// append client count
	_ASSERT(mClientList.size() <= USHRT_MAX);
	AppendShort(mClientList.size());

	// append client list
	std::list<unsigned short>::iterator itr = mClientList.begin();
	while (itr != mClientList.end())
		AppendClientId(*(itr++));

	return GetDataPtr();
}
Ejemplo n.º 16
0
err_t
TCPSendDataCallback(struct netif *netif, struct pbuf *p, struct ip_addr *dest)
{
    NDIS_STATUS NdisStatus;
    PNEIGHBOR_CACHE_ENTRY NCE;
    IP_PACKET Packet = { 0 };
    IP_ADDRESS RemoteAddress, LocalAddress;
    PIPv4_HEADER Header;
    UINT i;
    struct pbuf *p1;
    
    /* The caller frees the pbuf struct */
    
    if (((*(u8_t*)p->payload) & 0xF0) == 0x40)
    {
        Header = p->payload;
        
        LocalAddress.Type = IP_ADDRESS_V4;
        LocalAddress.Address.IPv4Address = Header->SrcAddr;
        
        RemoteAddress.Type = IP_ADDRESS_V4;
        RemoteAddress.Address.IPv4Address = Header->DstAddr;
    }
    else 
    {
        return ERR_IF;
    }

    if (!(NCE = RouteGetRouteToDestination(&RemoteAddress)))
    {
        return ERR_RTE;
    }
    
    NdisStatus = AllocatePacketWithBuffer(&Packet.NdisPacket, NULL, p->tot_len);
    if (NdisStatus != NDIS_STATUS_SUCCESS)
    {
        return ERR_MEM;
    }
    
    GetDataPtr(Packet.NdisPacket, 0, (PCHAR*)&Packet.Header, &Packet.ContigSize);
    
    for (i = 0, p1 = p; i < p->tot_len; i += p1->len, p1 = p1->next)
    {
        ASSERT(p1);
        RtlCopyMemory(((PUCHAR)Packet.Header) + i, p1->payload, p1->len);
    }
    
    Packet.HeaderSize = sizeof(IPv4_HEADER);
    Packet.TotalSize = p->tot_len;
    Packet.SrcAddr = LocalAddress;
    Packet.DstAddr = RemoteAddress;
    
    if (!NT_SUCCESS(IPSendDatagram(&Packet, NCE, TCPPacketSendComplete, NULL)))
    {
        FreeNdisPacket(Packet.NdisPacket);
        return ERR_IF;
    }
    
    return 0;
}
// TMsgDirFindServiceReply::Pack
// Virtual method from TMessage.  Packs data into message buffer and
// sets the new message length.
void*
TMsgDirFindServiceReply::Pack(void)
{
	WTRACE("TMsgDirFindServiceReply::Pack");
	SetServiceType(WONMsg::DirServer);
	SetMessageType(WONMsg::DirFindServiceReply);
	TMessage::Pack();

	WDBG_LL("TMsgDirFindServiceReply::Pack Appending message data");
	AppendShort(static_cast<short>(mStatus));

	// Service info only sent if status is ok
	if (mStatus == WONMsg::StatusCommon_Success)
	{
		Append_PW_STRING(mService.mPath);
		Append_PW_STRING(mService.mName);
		Append_PW_STRING(mService.mDisplayName);
		Append_PW_STRING(mService.mVersion);
		Append_PW_STRING(mService.mProtoName);
		Append_PW_STRING(mService.mProtoVersion);
		Append_PW_STRING(mService.mNetAddress);
		AppendLong(mService.mLifespan);
		AppendLong(mService.mCreated);
		AppendShort(mService.mBlobLen);
		AppendBytes(mService.mBlobLen, mService.mBlob);
	}

	return GetDataPtr();
}
Ejemplo n.º 18
0
// SMsgDirG2ModifyService::Pack
// Virtual method from SmallMessage.  Packs data into message buffer.
void*
SMsgDirG2ModifyService::Pack(void)
{
	WTRACE("SMsgDirG2ModifyService::Pack");
	SetKeyType(KT_SERVICE);
	SetServiceType(WONMsg::SmallDirServerG2);
	if (IsExtended())
	{
		SetMessageType(WONMsg::DirG2ModifyServiceEx);
		SetExtended(true, true);
	}
	else
		SetMessageType(WONMsg::DirG2ModifyService);

	SMsgDirG2UpdateExtendBase::Pack();
	AppendByte(mEntityFlags);
	PackKey(*this);
	Append_PW_STRING(mNewName);

	unsigned char aLen = mNewNetAddress.size();
	AppendByte(aLen);
	if (aLen > 0)
		AppendBytes(aLen, mNewNetAddress.data());

	Append_PW_STRING(mNewDisplayName);
	AppendLong(mNewLifespan);
	PackExtended();
	PackPeerData();

	return GetDataPtr();
}
Ejemplo n.º 19
0
KString KString::operator + (__int64 iValue) const
{
	TCHAR Buf[32];
	_stprintf(Buf, TEXT("%I64d"), iValue);

	return KString(GetDataPtr(), GetLength(), Buf, _tcslen(Buf));
}
void* MMsgRoutingModifyDataObject::Pack(void)
{
	WTRACE("MMsgRoutingModifyDataObject::Pack");

	SetServiceType(WONMsg::MiniRoutingServer);
	SetMessageType(WONMsg::RoutingModifyDataObject);
	RoutingServerMessage::Pack();

	WDBG_LL("MMsgRoutingModifyDataObject::Pack Appending message data");

	// append the client/group id
	AppendClientOrGroupId(mLinkId);
	
	// append the datatype, preceded by datatype length
	AppendByte(mDataType.size());
	AppendBytes(mDataType.size(), mDataType.data());
	
	// append the offset
	AppendShort(mOffset);

	// append the IsInsert flag
	AppendBool(mIsInsert);

	// append the data length followed by the data itself
	AppendShort(mData.size());
	AppendBytes(mData.size(), mData.data());

	return GetDataPtr();
}
// TMsgAuth1Complete::Pack
// Virtual method from TMessage.  Packs data into message buffer and
// sets the new message length.
void*
TMsgAuth1Complete::Pack(void)
{
	WTRACE("TMsgAuth1Complete::Pack");
	SetServiceType(WONMsg::Auth1PeerToPeer);
	SetMessageType(WONMsg::Auth1Complete);
	TMsgAuthRawBufferBase::Pack();

	WDBG_LL("TMsgAuth1Complete::Pack Appending message data");
	AppendShort(static_cast<short>(mStatus));

	// Append error info if status implies failure
	if (mStatus < 0)
	{
		WDBG_LL("TMsgAuth1Complete::Pack Failure status, append error info");
		AppendShort(mErrList.size());
		ErrorList::iterator anItr(mErrList.begin());
		for (; anItr != mErrList.end(); anItr++)
			Append_PA_STRING(*anItr);
	}

	// Otherwise append success info
	else
	{
		WDBG_LL("TMsgAuth1Complete::Pack Success status, append secret and optional session");
		PackRawBuf();
		if (mSessionId != 0) AppendShort(mSessionId);
	}

	return GetDataPtr();
}
void* MMsgRoutingSendData::Pack(void)
{
	WTRACE("MMsgRoutingSendData::Pack");

	SetServiceType(WONMsg::MiniRoutingServer);
	SetMessageType(WONMsg::RoutingSendData);
	RoutingServerMessage::Pack();

	WDBG_LL("MMsgRoutingSendData::Pack Appending message data");

	// append the flags
	unsigned char aFlags = 0;
	if (mShouldSendReply)    aFlags |= 0x01;
	if (mIncludeExcludeFlag) aFlags |= 0x02;
	AppendByte(aFlags);

	// append the message length and data
	_ASSERT(mData.size() <= USHRT_MAX);
	AppendShort(mData.size());
	AppendBytes(mData.size(), mData.data());
	
	// append the addressee list
	AppendAddresseeList(this);

	return GetDataPtr();
}
// SMsgDirG2ExplicitSetDataObjects::Pack
// Virtual method from SmallMessage.  Packs data into message buffer.
void*
SMsgDirG2ExplicitSetDataObjects::Pack(void)
{
	WTRACE("SMsgDirG2ExplicitSetDataObjects::Pack");
	SetServiceType(WONMsg::SmallDirServerG2);
	SetMessageType(mKeyType == KT_SERVICE ? WONMsg::DirG2ServiceExplicitSetDataObjects : WONMsg::DirG2DirectoryExplicitSetDataObjects);
	SMsgDirG2UpdateBase::Pack();

	PackKey(*this);

	AppendShort(mObjects.size());
	ExplicitDOInfoList::iterator anItr(mObjects.begin());
	for (; anItr != mObjects.end(); anItr++)
	{
		AppendByte(static_cast<unsigned char>(anItr->mSetMode));

		unsigned char aTypeLen = anItr->mData.GetDataType().size();
		AppendByte(aTypeLen);
		if (aTypeLen > 0)
			AppendBytes(aTypeLen, anItr->mData.GetDataType().data());

		unsigned short aDataLen = anItr->mData.GetData().size();
		AppendShort(aDataLen);
		if (aDataLen > 0)
			AppendBytes(aDataLen, anItr->mData.GetData().data());
	}

	PackPeerData();
	return GetDataPtr();
}
Ejemplo n.º 24
0
// Set all columns by value into this tuple.
void Tuple::SetValue(oid_t column_offset, const common::Value &value) {
  PL_ASSERT(tuple_schema);
  PL_ASSERT(tuple_data);

  const common::Type::TypeId type = tuple_schema->GetType(column_offset);

  const bool is_inlined = tuple_schema->IsInlined(column_offset);
  char *value_location = GetDataPtr(column_offset);
  UNUSED_ATTRIBUTE int32_t column_length =
      tuple_schema->GetLength(column_offset);
  if (is_inlined == false)
    column_length = tuple_schema->GetVariableLength(column_offset);

  // const bool is_in_bytes = false;
  // Allocate in heap or given data pool depending on whether a pool is provided
  // Skip casting if type is same
  if (type == value.GetTypeId()) {
    value.SerializeTo(value_location, is_inlined, nullptr);
  } else {
    common::Value *casted_value = value.CastAs(type);
    casted_value->SerializeTo(value_location, is_inlined, nullptr);
    // Do not clean up immediately
    // casted_value.SetCleanUp(false);
  }
}
Ejemplo n.º 25
0
LPCWSTR CDialogItemTemplate::GetClassName() const
{
	const WORD* pw = GetDataPtr();
	if ( *pw == 0xFFFF )
		return (LPCWSTR) MAKEINTATOM(pw[1]);
	else
		return (LPCWSTR) pw;
}
Ejemplo n.º 26
0
void CPageBoatyard::CancelCurrentProducing()
{
  GetDataPtr()->IncreaseResource(buff_cosume_metal , buff_cosume_cryst ,  buff_cosume_diplo);
  GetCommander()->Notify_Resource_Changed();
  is_producing_ = false;
  SetWorkFlag(false);
  UpdateItemText();
}
Ejemplo n.º 27
0
void Image::Draw(float x, float y) const
{
	if(!m_uWidth)
		return;
	SetMemAlign(m_uWidth, FALSE);
	glRasterPos2f(x, y);
	glDrawPixels(m_uWidth, m_uHeight, GetPixelFormat(), GL_UNSIGNED_BYTE, GetDataPtr());
}
Ejemplo n.º 28
0
KString& KString::operator += (const KString& SString)
{
	if(&SString == this)
	{
		size_t szOldLength = GetLength();

		Extend(GetLength());

		memcpy(GetDataPtr() + szOldLength, GetDataPtr(), GetStreamCharsLength(szOldLength));
	}
	else
	{
		Extend(SString, SString.GetLength());
	}

	return *this;
}
Ejemplo n.º 29
0
KString& KString::operator = (LPCTSTR pSString)
{
	Allocate(_tcslen(pSString));

	memcpy(GetDataPtr(), pSString, GetStreamCharsLength());

	return *this;
}
Ejemplo n.º 30
0
TAnsiString::TAnsiString(LPCWSTR pWideString)
{
	const size_t szLength = wcslen(pWideString);

	AllocateAdd(szLength + 1);

	WideCharToMultiByte(CP_ACP,
						0,
						pWideString,
						szLength,
						GetDataPtr(),
						szLength,
						NULL,
						NULL);

	GetDataPtr()[szLength] = 0;
}