Пример #1
0
Image::Image(MediaManager& Manager,
             const string& AssetName,
             const string& Params)
  : Asset(Manager, AssetName)
{
  string params = GetCleanWhitespace(Params);
  szt xPos = FindCharacter(params, ',');
  Filename = Media.AssetDir + CutString(params, 0, xPos);
  if (xPos != string::npos) {
    Priority = 1;
    szt yPos = FindCharacter(params, ',', ++xPos);
    const string& x = CutString(params, xPos, yPos);
    X = IntoReal(x);
    if (yPos != string::npos) {
      szt zoomPos = FindCharacter(params, ',', ++yPos);
      const string& y = CutString(params, yPos, zoomPos);
      Y = IntoReal(y);
      if (zoomPos != string::npos) {
        szt orderPos = FindCharacter(params, ',', ++zoomPos);
        const string& zoom = CutString(params, zoomPos, orderPos);
        Zoom = IntoReal(zoom);
        if (orderPos != string::npos) {
          const string& order = CutString(params, orderPos);
          Priority = Abs(IntoInt(order)) + 1; //0 reserved for BG
        }
      }
    }
  } else {
    BG = true;
  }
}
Пример #2
0
bool ClientList::SendPacket(const char* to, ServerPacket* pack) {
	if (to == 0 || to[0] == 0) {
		zoneserver_list.SendPacket(pack);
		return true;
	}
	else if (to[0] == '*') {
		// Cant send a packet to a console....
		return false;
	}
	else {
		ClientListEntry* cle = FindCharacter(to);
		if (cle != nullptr) {
			if (cle->Server() != nullptr) {
				cle->Server()->SendPacket(pack);
				return true;
			}
			return false;
		} else {
			ZoneServer* zs = zoneserver_list.FindByName(to);
			if (zs != nullptr) {
				zs->SendPacket(pack);
				return true;
			}
			return false;
		}
	}
	return false;
}
Пример #3
0
int main(int Count, char* Switches[])
{
  bool sound = true;
  int width = 0;
  int height = 0;
  for (int i = 1; i < Count; ++i) {
    const string argument(Switches[i]);
    //screen size
    if (i == 1 && !argument.empty() && isdigit(argument[0])) {
      szt xPos = FindCharacter(argument, 'x');
      if (xPos != string::npos) {
        width = Abs(IntoInt(CutString(argument, 0, xPos)));
        height = Abs(IntoInt(CutString(argument, xPos + 1)));
      }
    }
    if (argument == "-s" || argument == "-silent" || argument == "-no-sound") {
      sound = false;
    }
  }

  Reader reader(width, height, 32, sound);

  if (reader.Init()) {
    ulint lastTime = 0;
    real deltaTime = 0.1;
    while (reader.Tick(deltaTime)) {
      deltaTime = Input::LimitFPS(lastTime);
    }
    return 0;
  } else {
    LOG("Reader initialisation failed.");
    return 1;
  }
}
Пример #4
0
void Database::SendBody(Client *c, int MessageNumber) {

	int CharacterID = FindCharacter(c->MailBoxName().c_str());

	_log(UCS__TRACE, "SendBody: MsgID %i, to %s, CharID is %i", MessageNumber, c->MailBoxName().c_str(), CharacterID);

	if(CharacterID <= 0)
		return;

	char errbuf[MYSQL_ERRMSG_SIZE];
	char* query = 0;
	MYSQL_RES *result;
	MYSQL_ROW row;

	if (!RunQuery(query,MakeAnyLenString(&query, "select `msgid`, `body`, `to` from `mail` "
							"where `charid`=%i and `msgid`=%i", CharacterID, MessageNumber), errbuf, &result)){
		safe_delete_array(query);

		return ;
	}

	safe_delete_array(query);

	if (mysql_num_rows(result) != 1) {

		mysql_free_result(result);

		return;
	}

	row = mysql_fetch_row(result);

	_log(UCS__TRACE, "Message: %i  body (%i bytes)", MessageNumber, strlen(row[1]));

	int PacketLength = 12 + strlen(row[0]) + strlen(row[1]) + strlen(row[2]);

	EQApplicationPacket *outapp = new EQApplicationPacket(OP_MailSendBody,PacketLength);

	char *PacketBuffer = (char *)outapp->pBuffer;

	VARSTRUCT_ENCODE_INTSTRING(PacketBuffer, c->GetMailBoxNumber());
	VARSTRUCT_ENCODE_STRING(PacketBuffer,row[0]);
	VARSTRUCT_ENCODE_STRING(PacketBuffer,row[1]);
	VARSTRUCT_ENCODE_STRING(PacketBuffer,"1");
	VARSTRUCT_ENCODE_TYPE(uint8, PacketBuffer, 0);
	VARSTRUCT_ENCODE_TYPE(uint8, PacketBuffer, 0x0a);
	VARSTRUCT_ENCODE_STRING(PacketBuffer, "TO:"); PacketBuffer--;
	VARSTRUCT_ENCODE_STRING(PacketBuffer, row[2]); PacketBuffer--; // Overwrite the null terminator
	VARSTRUCT_ENCODE_TYPE(uint8, PacketBuffer, 0x0a);

	mysql_free_result(result);

	_pkt(UCS__PACKETS, outapp);

	c->QueuePacket(outapp);

	safe_delete(outapp);


}
Пример #5
0
bool Database::SendMail(std::string recipient, std::string from, std::string subject, std::string body, std::string recipientsString) {

	int characterID;
	std::string characterName;

	auto lastPeriod = recipient.find_last_of(".");

	if(lastPeriod == std::string::npos)
		characterName = recipient;
	else
		characterName = recipient.substr(lastPeriod+1);

	characterName[0] = toupper(characterName[0]);

	for(unsigned int i = 1; i < characterName.length(); i++)
		characterName[i] = tolower(characterName[i]);

	characterID = FindCharacter(characterName.c_str());

	_log(UCS__TRACE, "SendMail: CharacterID for recipient %s is %i", characterName.c_str(), characterID);

	if(characterID <= 0)
        return false;

	char *escSubject = new char[subject.length() * 2 + 1];
	char *escBody = new char[body.length() * 2 + 1];

	DoEscapeString(escSubject, subject.c_str(), subject.length());
	DoEscapeString(escBody, body.c_str(), body.length());

	int now = time(nullptr); // time returns a 64 bit int on Windows at least, which vsnprintf doesn't like.

    std::string query = StringFormat("INSERT INTO `mail` "
                                    "(`charid`, `timestamp`, `from`, `subject`, `body`, `to`, `status`) "
                                    "VALUES ('%i', %i, '%s', '%s', '%s', '%s', %i)",
                                    characterID, now, from.c_str(), escSubject, escBody,
                                    recipientsString.c_str(), 1);
    safe_delete_array(escSubject);
    safe_delete_array(escBody);
    auto results = QueryDatabase(query);
	if(!results.Success()) {
		_log(UCS__ERROR, "SendMail: Query %s failed with error %s", query.c_str(), results.ErrorMessage().c_str());
		return false;
	}

	_log(UCS__TRACE, "MessageID %i generated, from %s, to %s", results.LastInsertedID(), from.c_str(), recipient.c_str());


	Client *client = CL->IsCharacterOnline(characterName);

	if(client) {
		std::string FQN = GetMailPrefix() + from;
		client->SendNotification(client->GetMailBoxNumber(characterName), subject, FQN, results.LastInsertedID());
	}

	MailMessagesSent++;

	return true;
}
Пример #6
0
/*!***************************************************************************
 @fn       			MeasureText
 @param[out]		pfWidth				Width of the string in pixels
 @param[out]		pfHeight			Height of the string in pixels
 @param[in]			fFontSize			Font size
 @param[in]			sString				String to take the size of
 @brief      		Returns the size of a string in pixels.
*****************************************************************************/
void CPVRTPrint3D::MeasureText(
	float		* const pfWidth,
	float		* const pfHeight,
	float				fScale,
	const CPVRTArray<PVRTuint32>& utf32)
{
#if !defined (DISABLE_PRINT3D)
	if(utf32.GetSize() == 0) {
		if(pfWidth)
			*pfWidth = 0;
		if(pfHeight)
			*pfHeight = 0;
		return;
	}

	float fLength			= 0;
	float fMaxLength		= -1.0f;
	float fMaxHeight		= (float)m_uiNextLineH;
	PVRTuint32 txNextChar	= 0;
	PVRTuint32 uiIdx;
	for(PVRTuint32 uiIndex = 0; uiIndex < utf32.GetSize(); uiIndex++)
	{
		if(utf32[uiIndex] == 0x0D || utf32[uiIndex] == 0x0A)
		{
			if(fLength > fMaxLength)
				fMaxLength = fLength;

			fLength = 0;
			fMaxHeight += (float)m_uiNextLineH;
		}
		uiIdx = FindCharacter(utf32[uiIndex]);
		if(uiIdx == PVRTPRINT3D_INVALID_CHAR)		// No character found. Add a space.
		{
			fLength += m_uiSpaceWidth;
			continue;
		}

		float fKernOffset = 0;
		if ((uiIndex + 1) < utf32.GetSize())
		{
			txNextChar = utf32[uiIndex + 1];
			ApplyKerning(utf32[uiIndex], txNextChar, fKernOffset);
		}

		fLength += m_pCharMatrics[uiIdx].nAdv + fKernOffset;		// Add on this characters width
	}

	if(fMaxLength < 0.0f)		// Obviously no new line.
		fMaxLength = fLength;

	if(pfWidth)
		*pfWidth = fMaxLength * fScale;
	if(pfHeight)
		*pfHeight = fMaxHeight * fScale;
#endif
}
Пример #7
0
void Database::SendBody(Client *client, int messageNumber) {

	int characterID = FindCharacter(client->MailBoxName().c_str());

	_log(UCS__TRACE, "SendBody: MsgID %i, to %s, CharID is %i", messageNumber, client->MailBoxName().c_str(), characterID);

	if(characterID <= 0)
		return;

	std::string query = StringFormat("SELECT `msgid`, `body`, `to` FROM `mail` "
                                    "WHERE `charid`=%i AND `msgid`=%i", characterID, messageNumber);
    auto results = QueryDatabase(query);
	if (!results.Success())
		return;


	if (results.RowCount() != 1)
		return;

	auto row = results.begin();

	_log(UCS__TRACE, "Message: %i  body (%i bytes)", messageNumber, strlen(row[1]));

	int packetLength = 12 + strlen(row[0]) + strlen(row[1]) + strlen(row[2]);

	EQApplicationPacket *outapp = new EQApplicationPacket(OP_MailSendBody,packetLength);

	char *packetBuffer = (char *)outapp->pBuffer;

	VARSTRUCT_ENCODE_INTSTRING(packetBuffer, client->GetMailBoxNumber());
	VARSTRUCT_ENCODE_STRING(packetBuffer,row[0]);
	VARSTRUCT_ENCODE_STRING(packetBuffer,row[1]);
	VARSTRUCT_ENCODE_STRING(packetBuffer,"1");
	VARSTRUCT_ENCODE_TYPE(uint8, packetBuffer, 0);
	VARSTRUCT_ENCODE_TYPE(uint8, packetBuffer, 0x0a);
	VARSTRUCT_ENCODE_STRING(packetBuffer, "TO:");
	packetBuffer--;
	VARSTRUCT_ENCODE_STRING(packetBuffer, row[2]);
	packetBuffer--; // Overwrite the null terminator
	VARSTRUCT_ENCODE_TYPE(uint8, packetBuffer, 0x0a);

	_pkt(UCS__PACKETS, outapp);

	client->QueuePacket(outapp);

	safe_delete(outapp);
}
Пример #8
0
void ClientList::SendFriendsWho(ServerFriendsWho_Struct *FriendsWho, WorldTCPConnection* connection) {

	std::vector<ClientListEntry*> FriendsCLEs;
	FriendsCLEs.reserve(100);

	char Friend_[65];

	char *FriendsPointer = FriendsWho->FriendsString;

	// FriendsString is a comma delimited list of names.

	char *Seperator = nullptr;

	Seperator = strchr(FriendsPointer, ',');
	if(!Seperator) Seperator = strchr(FriendsPointer, '\0');

	uint32 TotalLength=0;

	while(Seperator != nullptr) {

		if((Seperator - FriendsPointer) > 64) return;

		strncpy(Friend_, FriendsPointer, Seperator - FriendsPointer);
		Friend_[Seperator - FriendsPointer] = 0;

		ClientListEntry* CLE = FindCharacter(Friend_);
		if(CLE && CLE->name() && (CLE->Online() >= CLE_Status_Zoning) && !(CLE->GetGM() && CLE->Anon())) {
			FriendsCLEs.push_back(CLE);
			TotalLength += strlen(CLE->name());
			int GuildNameLength = strlen(guild_mgr.GetGuildName(CLE->GuildID()));
			if(GuildNameLength>0)
				TotalLength += (GuildNameLength + 2);
		}

		if(Seperator[0] == '\0') break;

		FriendsPointer = Seperator + 1;
		Seperator = strchr(FriendsPointer, ',');
		if(!Seperator) Seperator = strchr(FriendsPointer, '\0');
	}


	try{
		ClientListEntry* cle;
		int FriendsOnline = FriendsCLEs.size();
		int PacketLength = sizeof(WhoAllReturnStruct) + (47 * FriendsOnline) + TotalLength;
		ServerPacket* pack2 = new ServerPacket(ServerOP_WhoAllReply, PacketLength);
		memset(pack2->pBuffer,0,pack2->size);
		uchar *buffer=pack2->pBuffer;
		uchar *bufptr=buffer;

		WhoAllReturnStruct *WARS = (WhoAllReturnStruct *)bufptr;

		WARS->id = FriendsWho->FromID;
		WARS->playerineqstring = 0xffff;
		strcpy(WARS->line, "");
		WARS->unknown35 = 0x0a;
		WARS->unknown36 = 0x00;

		if(FriendsCLEs.size() == 1)
			WARS->playersinzonestring = 5028; // 5028 There is %1 player in EverQuest.
		else
			WARS->playersinzonestring = 5036; // 5036 There are %1 players in EverQuest.

		WARS->unknown44[0] = 0;
		WARS->unknown44[1] = 0;
		WARS->unknown44[2] = 0;
		WARS->unknown44[3] = 0;
		WARS->unknown44[4] = 0;
		WARS->unknown52 = FriendsOnline;
		WARS->unknown56 = 1;
		WARS->playercount = FriendsOnline;

		bufptr+=sizeof(WhoAllReturnStruct);

		for(int CLEEntry = 0; CLEEntry < FriendsOnline; CLEEntry++) {

			cle = FriendsCLEs[CLEEntry];

			char GuildName[67]={0};
			if (cle->GuildID() != GUILD_NONE && cle->GuildID()>0)
				sprintf(GuildName,"<%s>", guild_mgr.GetGuildName(cle->GuildID()));
			uint16 FormatMSGID=5025; // 5025 %T1[%2 %3] %4 (%5) %6 %7 %8 %9
			if(cle->Anon()==1)
				FormatMSGID=5024; // 5024 %T1[ANONYMOUS] %2 %3
			else if(cle->Anon()==2)
				FormatMSGID=5023; // 5023 %T1[ANONYMOUS] %2 %3 %4

			uint16 PlayerClass=0;
			uint16 PlayerLevel=0;
			uint16 PlayerRace=0;
			uint16 ZoneMSGID=0xffff;
			uint16 PlayerZone=0;

			if(cle->Anon()==0) {
				PlayerClass=cle->class_();
				PlayerLevel=cle->level();
				PlayerRace=cle->race();
				ZoneMSGID=5006; // 5006 ZONE: %1
				PlayerZone=cle->zone();
			}

			char PlayerName[64]={0};
			strcpy(PlayerName,cle->name());

			WhoAllPlayerPart1* WAPP1 = (WhoAllPlayerPart1*)bufptr;

			WAPP1->FormatMSGID = FormatMSGID;
			WAPP1->PIDMSGID = 0xffff;
			strcpy(WAPP1->Name, PlayerName);

			bufptr += sizeof(WhoAllPlayerPart1) + strlen(PlayerName);
			WhoAllPlayerPart2* WAPP2 = (WhoAllPlayerPart2*)bufptr;

			WAPP2->RankMSGID = 0xffff;
			strcpy(WAPP2->Guild, GuildName);

			bufptr += sizeof(WhoAllPlayerPart2) + strlen(GuildName);
			WhoAllPlayerPart3* WAPP3 = (WhoAllPlayerPart3*)bufptr;

			WAPP3->Unknown80[0] = 0xffff;
			WAPP3->Unknown80[1] = 0xffff;
			WAPP3->Unknown80[2] = 0xffff;
			WAPP3->ZoneMSGID = ZoneMSGID;
			WAPP3->Zone = PlayerZone;
			WAPP3->Class_ = PlayerClass;
			WAPP3->Level = PlayerLevel;
			WAPP3->Race = PlayerRace;
			WAPP3->Account[0] = 0;

			bufptr += sizeof(WhoAllPlayerPart3);

			WhoAllPlayerPart4* WAPP4 = (WhoAllPlayerPart4*)bufptr;
			WAPP4->Unknown100 = 211;

			bufptr += sizeof(WhoAllPlayerPart4);

		}
		pack2->Deflate();
		SendPacket(FriendsWho->FromName,pack2);
		safe_delete(pack2);
	}
	catch(...){
		_log(WORLD__ZONELIST_ERR,"Unknown error in world's SendFriendsWho (probably mem error), ignoring...");
		return;
	}
}
Пример #9
0
/** @brief parses the save file and fills histories (does't load any snapshot)
  */
bool Session::Load()
{
  File Save;
  const string& savePath = STORY_DIR + SLASH + BookName + SLASH
                           + Filename + SESSION_EXT;
  if (!Disk::Exists(savePath) || !Save.Read(savePath)) {
    LOG(savePath + " - save file missing");
    return false;
  }

  string buffer;
  Save.GetLine(buffer); // session name:
  Save.GetLine(Name);
  Save.GetLine(buffer); // book title:
  Save.GetLine(BookName);
  Save.GetLine(buffer);
  Save.GetLine(buffer); // steps taken:
  Save.GetLine(buffer); // #
  Save.GetLine(buffer);

  // queue
  while (Save.GetLine(buffer)) {
    QueueHistory.push_back(buffer);
  }

  // assets
  Save.GetLine(buffer); // asset states:
  Save.GetLine(buffer); // #
  Save.GetLine(buffer);
  while (Save.GetLine(buffer)) {
    string historyEntry = buffer;
    while (Save.GetLine(buffer)) {
      historyEntry += "\n";
      historyEntry += buffer;
    }
    AssetsHistory.push_back(historyEntry);
  }

  // values
  Save.GetLine(buffer); // tracked values:
  Save.GetLine(buffer); // #
  // resize the array to fit all the values tracked
  ValuesHistories.resize(IntoSizeT(buffer));
  Save.GetLine(buffer);
  while (Save.GetLine(buffer)) {
    string indexBuffer;
    Save.GetLine(indexBuffer);
    cszt index = IntoSizeT(indexBuffer);
    ValuesHistoryNames[buffer] = IntoSizeT(index);
    while (Save.GetLine(buffer)) {
      ValuesHistories[index].push_back(buffer);
    }
  }

  // changes
  while (Save.GetLine(buffer)) {
    cszt pos = FindCharacter(buffer, VALUE_SEPARATOR);
    const string& valueIndex = CutString(buffer, 0, pos);
    const string& changeIndex = CutString(buffer, pos + 1);
    cszt_pair change(IntoSizeT(valueIndex), IntoSizeT(changeIndex));
    ValuesChanges.push_back(change);
  }

  // snapshots
  while (Save.GetLine(buffer)) {
    cszt pos = FindCharacter(buffer, VALUE_SEPARATOR);
    cszt pos2 = FindCharacter(buffer, VALUE_SEPARATOR, pos + 1);
    const string& queueIndex = CutString(buffer, 0, pos);
    const string& assetIndex = CutString(buffer, pos + 1, pos2);
    const string& changeIndex = CutString(buffer, pos2 + 1);
    const Snapshot loadedSnapshot(IntoSizeT(queueIndex),
                                  IntoSizeT(assetIndex),
                                  IntoSizeT(changeIndex));
    Snapshots.push_back(loadedSnapshot);
  }

  // bookmarks
  while (Save.GetLine(buffer)) {
    cszt index = IntoSizeT(buffer);
    string bookmarkDescription;
    while (Save.GetLine(buffer)) {
      bookmarkDescription += buffer;
    }
    Bookmarks[index].Description = bookmarkDescription;
  }

  // repeat last snapshot
  LoadSnapshot(Snapshots.size() - 1);
  return true;
}
Пример #10
0
/** @brief you need to init system nouns beforehand
  */
bool Session::LoadSnapshot(cszt Index)
{
  if (Index >= Snapshots.size() || !Index) {
    // if it's not within the history or is the start of the story
    // there's nothing to load and the story is ready to go from the init
    return false;
  }
  CurrentSnapshot = Index;
  szt queueI = Snapshots[Index].QueueIndex;
  szt assetI = Snapshots[Index].AssetsIndex;
  szt changeI = Snapshots[Index].ChangesIndex;

  // load the current queue
  if (queueI > 0) {
    const string& queueValue = QueueHistory[--queueI];
    *QueueNoun = Properties(queueValue);
  } else {
    // this is at the start of the book, no loading needed
    return false;
  }

  // find the most up to date positions of value histories for each history
  vector<szt> currentIndex;
  currentIndex.resize(ValuesHistories.size(), 0);
  for (szt i = 0; i < changeI; ++i) {
    cszt_pair& change = ValuesChanges[i];
    currentIndex[change.X] = change.Y;
  }

  for (const auto& value : ValuesHistoryNames) {
    const string& name = value.first;
    cszt i = value.second;
    // all indeces here are 1-based, 0 meaning book values should be used
    if (currentIndex[i]) {
      // it's safe to decrement as it's a temporary
      const string& oldValue = ValuesHistories[i][--currentIndex[i]];
      UserValues[name] = Properties(oldValue);
    } else {
      // remove user values that are the same as in the book
      // because we don't have a record of the initial state
      auto it = UserValues.find(name);
      if (it != UserValues.end()) {
        // but don't remove system nouns, they are initialised
        bool nonSystem = true;
        for (const Properties* systemNoun : SystemNouns) {
          if (&(it->second) == systemNoun) {
            nonSystem = false;
            break;
          }
        }
        if (nonSystem) {
          UserValues.erase(it);
        }
      }
    }
  }

  AssetStates.clear();
  // assetI 0 means all assets are off
  if (assetI > 0) {
    const string& assets = AssetsHistory[--assetI];
    szt lastPos = 0;
    szt pos = FindCharacter(assets, '\n', lastPos);

    while (pos != string::npos && pos > lastPos) {
      const string& assetName = CutString(assets, lastPos, pos);
      AssetStates[assetName] = true;
      lastPos = ++pos;
      pos = FindCharacter(assets, '\n', lastPos);
    }
    if (lastPos < assets.size()) {
      // last value doesn't have a \n at the end
      const string& assetName = CutString(assets, lastPos);
      AssetStates[assetName] = true;
    }
  }

  return true;
}
Пример #11
0
/*!***************************************************************************
 @Function			UpdateLine
 @Description
*****************************************************************************/
unsigned int CPVRTPrint3D::UpdateLine(const float fZPos, float XPos, float YPos, const float fScale, const unsigned int Colour, const CPVRTArray<PVRTuint32>& Text, SPVRTPrint3DAPIVertex * const pVertices)
{
	/* Nothing to update */
	if (Text.GetSize() == 0) 
		return 0;

	if(!m_bUsingProjection)
	{
		XPos *= m_fScreenScale[0];
		YPos *= m_fScreenScale[1];
	}

	YPos -= PVRTMakeWhole(m_uiAscent * fScale);

	float fPreXPos	= XPos;		// The original offset (after screen scale modification) of the X coordinate.

	float		fKernOffset;
	float		fAOff;
	float		fYOffset;
	unsigned int VertexCount = 0;
	PVRTint32 NextChar;

	unsigned int uiNumCharsInString = Text.GetSize();
	for(unsigned int uiIndex = 0; uiIndex < uiNumCharsInString; uiIndex++)
	{
		if(uiIndex > MAX_LETTERS) 
			break;

		// Newline
		if(Text[uiIndex] == 0x0A)
		{
			XPos = fPreXPos;
			YPos -= PVRTMakeWhole(m_uiNextLineH * fScale);
			continue;
		}

		// Get the character
		PVRTuint32 uiIdx = FindCharacter(Text[uiIndex]);

		// Not found. Add a space.
		if(uiIdx == PVRTPRINT3D_INVALID_CHAR)		// No character found. Add a space.
		{
			XPos += PVRTMakeWhole(m_uiSpaceWidth * fScale);
			continue;
		}

		fKernOffset = 0;
		fYOffset	= PVRTMakeWhole(m_pYOffsets[uiIdx] * fScale);
		fAOff		= PVRTMakeWhole(m_pCharMatrics[uiIdx].nXOff * fScale);					// The A offset. Could include overhang or underhang.
		if(uiIndex < uiNumCharsInString - 1)
		{
			NextChar = Text[uiIndex + 1];
			ApplyKerning(Text[uiIndex], NextChar, fKernOffset);
		}

		/* Filling vertex data */
		pVertices[VertexCount+0].sx		= f2vt(XPos + fAOff + 0.0f);
		pVertices[VertexCount+0].sy		= f2vt(YPos + fYOffset + 0.0f);
		pVertices[VertexCount+0].sz		= f2vt(fZPos);
		pVertices[VertexCount+0].rhw	= f2vt(1.0f);
		pVertices[VertexCount+0].tu		= f2vt(m_pUVs[uiIdx].fUL);
		pVertices[VertexCount+0].tv		= f2vt(m_pUVs[uiIdx].fVT);

		pVertices[VertexCount+1].sx		= f2vt(XPos + fAOff + PVRTMakeWhole(m_pRects[uiIdx].nW * fScale));
		pVertices[VertexCount+1].sy		= f2vt(YPos + fYOffset + 0.0f);
		pVertices[VertexCount+1].sz		= f2vt(fZPos);
		pVertices[VertexCount+1].rhw	= f2vt(1.0f);
		pVertices[VertexCount+1].tu		= f2vt(m_pUVs[uiIdx].fUR);
		pVertices[VertexCount+1].tv		= f2vt(m_pUVs[uiIdx].fVT);

		pVertices[VertexCount+2].sx		= f2vt(XPos + fAOff + 0.0f);
		pVertices[VertexCount+2].sy		= f2vt(YPos + fYOffset - PVRTMakeWhole(m_pRects[uiIdx].nH * fScale));
		pVertices[VertexCount+2].sz		= f2vt(fZPos);
		pVertices[VertexCount+2].rhw	= f2vt(1.0f);
		pVertices[VertexCount+2].tu		= f2vt(m_pUVs[uiIdx].fUL);
		pVertices[VertexCount+2].tv		= f2vt(m_pUVs[uiIdx].fVB);

		pVertices[VertexCount+3].sx		= f2vt(XPos + fAOff + PVRTMakeWhole(m_pRects[uiIdx].nW * fScale));
		pVertices[VertexCount+3].sy		= f2vt(YPos + fYOffset - PVRTMakeWhole(m_pRects[uiIdx].nH * fScale));
		pVertices[VertexCount+3].sz		= f2vt(fZPos);
		pVertices[VertexCount+3].rhw	= f2vt(1.0f);
		pVertices[VertexCount+3].tu		= f2vt(m_pUVs[uiIdx].fUR);
		pVertices[VertexCount+3].tv		= f2vt(m_pUVs[uiIdx].fVB);

		pVertices[VertexCount+0].color	= Colour;
		pVertices[VertexCount+1].color	= Colour;
		pVertices[VertexCount+2].color	= Colour;
		pVertices[VertexCount+3].color	= Colour;

		XPos = XPos + PVRTMakeWhole((m_pCharMatrics[uiIdx].nAdv + fKernOffset) * fScale);		// Add on this characters width
		VertexCount += 4;
	}

	return VertexCount;
}
Пример #12
0
bool Database::SendMail(std::string Recipient, std::string From, std::string Subject, std::string Body, std::string RecipientsString) {

	int CharacterID;

	std::string CharacterName;

	//printf("Database::SendMail(%s, %s, %s)\n", Recipient.c_str(), From.c_str(), Subject.c_str());

	std::string::size_type LastPeriod = Recipient.find_last_of(".");

	if(LastPeriod == std::string::npos)
		CharacterName = Recipient;
	else
		CharacterName = Recipient.substr(LastPeriod+1);

	CharacterName[0] = toupper(CharacterName[0]);

	for(unsigned int i = 1; i < CharacterName.length(); i++)
		CharacterName[i] = tolower(CharacterName[i]);

	CharacterID = FindCharacter(CharacterName.c_str());

	_log(UCS__TRACE, "SendMail: CharacterID for recipient %s is %i", CharacterName.c_str(), CharacterID);

	if(CharacterID <= 0) return false;

	char errbuf[MYSQL_ERRMSG_SIZE];
	char* query = 0;

	char *EscSubject = new char[Subject.length() * 2 + 1];
	char *EscBody = new char[Body.length() * 2 + 1];

	DoEscapeString(EscSubject, Subject.c_str(), Subject.length());
	DoEscapeString(EscBody, Body.c_str(), Body.length());

	const char *MailQuery="INSERT INTO `mail` (`charid`, `timestamp`, `from`, `subject`, `body`, `to`, `status`) "
				"VALUES ('%i', %i, '%s', '%s', '%s', '%s', %i)";

	uint32 LastMsgID;

	int Now = time(nullptr); // time returns a 64 bit int on Windows at least, which vsnprintf doesn't like.

	if(!RunQuery(query, MakeAnyLenString(&query, MailQuery, CharacterID, Now, From.c_str(), EscSubject, EscBody,
						RecipientsString.c_str(), 1), errbuf, 0, 0, &LastMsgID)) {

		_log(UCS__ERROR, "SendMail: Query %s failed with error %s", query, errbuf);

		safe_delete_array(EscSubject);
		safe_delete_array(EscBody);
		safe_delete_array(query);

		return false;
	}

	_log(UCS__TRACE, "MessageID %i generated, from %s, to %s", LastMsgID, From.c_str(), Recipient.c_str());

	safe_delete_array(EscSubject);
	safe_delete_array(EscBody);
	safe_delete_array(query);

	Client *c = CL->IsCharacterOnline(CharacterName);

	if(c) {
		std::string FQN = GetMailPrefix() + From;

		c->SendNotification(c->GetMailBoxNumber(CharacterName), Subject, FQN, LastMsgID);
	}

	MailMessagesSent++;

	return true;
}
Пример #13
0
void Database::SendHeaders(Client *c) {

	int UnknownField2 = 25015275;
	int UnknownField3 = 1;

	int CharacterID = FindCharacter(c->MailBoxName().c_str());
	_log(UCS__TRACE, "Sendheaders for %s, CharID is %i", c->MailBoxName().c_str(), CharacterID);
	if(CharacterID <= 0)
		return;


	char errbuf[MYSQL_ERRMSG_SIZE];
	char* query = 0;
	MYSQL_RES *result;
	MYSQL_ROW row;

	if (!RunQuery(query,MakeAnyLenString(&query, "select `msgid`,`timestamp`,`from`,`subject`, `status` from `mail` "
							"where `charid`=%i", CharacterID),errbuf,&result)){

		safe_delete_array(query);

		return ;
	}

	safe_delete_array(query);

	char Buf[100];

	uint32 NumRows = mysql_num_rows(result);

	int HeaderCountPacketLength = 0;

	sprintf(Buf, "%i", c->GetMailBoxNumber());
	HeaderCountPacketLength += (strlen(Buf) + 1);

	sprintf(Buf, "%i", UnknownField2);
	HeaderCountPacketLength += (strlen(Buf) + 1);

	sprintf(Buf, "%i", UnknownField3);
	HeaderCountPacketLength += (strlen(Buf) + 1);

	sprintf(Buf, "%i", NumRows);
	HeaderCountPacketLength += (strlen(Buf) + 1);

	EQApplicationPacket *outapp = new EQApplicationPacket(OP_MailHeaderCount, HeaderCountPacketLength);

	char *PacketBuffer = (char *)outapp->pBuffer;

	VARSTRUCT_ENCODE_INTSTRING(PacketBuffer, c->GetMailBoxNumber());
	VARSTRUCT_ENCODE_INTSTRING(PacketBuffer, UnknownField2);
	VARSTRUCT_ENCODE_INTSTRING(PacketBuffer, UnknownField3);
	VARSTRUCT_ENCODE_INTSTRING(PacketBuffer, NumRows);

	_pkt(UCS__PACKETS, outapp);

	c->QueuePacket(outapp);

	safe_delete(outapp);

	int RowNum = 0;

	while((row = mysql_fetch_row(result))) {


		int HeaderPacketLength = 0;

		sprintf(Buf, "%i", c->GetMailBoxNumber());
		HeaderPacketLength = HeaderPacketLength + strlen(Buf) + 1;
		sprintf(Buf, "%i", UnknownField2);
		HeaderPacketLength = HeaderPacketLength + strlen(Buf) + 1;
		sprintf(Buf, "%i", RowNum);
		HeaderPacketLength = HeaderPacketLength + strlen(Buf) + 1;

		HeaderPacketLength = HeaderPacketLength + strlen(row[0]) + 1;
		HeaderPacketLength = HeaderPacketLength + strlen(row[1]) + 1;
		HeaderPacketLength = HeaderPacketLength + strlen(row[4]) + 1;
		HeaderPacketLength = HeaderPacketLength + GetMailPrefix().length() + strlen(row[2]) + 1;
		HeaderPacketLength = HeaderPacketLength + strlen(row[3]) + 1;

		outapp = new EQApplicationPacket(OP_MailHeader, HeaderPacketLength);

		PacketBuffer = (char *)outapp->pBuffer;

		VARSTRUCT_ENCODE_INTSTRING(PacketBuffer, c->GetMailBoxNumber());
		VARSTRUCT_ENCODE_INTSTRING(PacketBuffer, UnknownField2);
		VARSTRUCT_ENCODE_INTSTRING(PacketBuffer, RowNum);
		VARSTRUCT_ENCODE_STRING(PacketBuffer, row[0]);
		VARSTRUCT_ENCODE_STRING(PacketBuffer, row[1]);
		VARSTRUCT_ENCODE_STRING(PacketBuffer, row[4]);
		VARSTRUCT_ENCODE_STRING(PacketBuffer, GetMailPrefix().c_str()); PacketBuffer--;
		VARSTRUCT_ENCODE_STRING(PacketBuffer, row[2]);
		VARSTRUCT_ENCODE_STRING(PacketBuffer, row[3]);

		_pkt(UCS__PACKETS, outapp);

		c->QueuePacket(outapp);

		safe_delete(outapp);

		RowNum++;
	}

	mysql_free_result(result);

}
Пример #14
0
//-------------------------------------------------------------------------
//
//-------------------------------------------------------------------------
bool SettingsFile::ParseSettingsString(const char *settings)
{
	if(!settings)
		return false;

	const char *first;
	std::string section;

	// Iterate through all the lines
	for(first = GetNextLine(settings); first && *first; first = GetNextLine(first))
	{
		if((first[0] == '[') && FindCharacter(first + 1, ']'))
		{
			// Found a section head, so create an entry for it
			const char *last = FindCharacter(first + 1, ']');
			if(last - first > 2)
			{
				const char *start = first + 1;
				const char *end = last - 1;
				TrimString(start, end);
				section.assign(start, end - start + 1);
			}
			// Skip what was scanned
			first = last + 1;
		}
		else if((first[0] == ';') || (first[0] == '#'))
		{
			first = SkipLine(first);
		}
		else
		{
			if(section.length() > 0)
			{
				const char *middle = FindCharacter(first + 1, '=');
				if(middle)
				{
					const char *start = first;
					const char *end = middle - 1;
					TrimString(start, end);
					if(end >= start)
					{
						std::string key;
						key.assign(start, end - start + 1);

						start = middle + 1;
						end = SkipLine(middle + 1);
						TrimString(start, end);
						if(end >= start)
						{
							std::string value;
							value.assign(start, end - start + 1);
							m_settings[section][key] = value;
						}
					}
				}
			}

			// Skip the line
			first = SkipLine(first);
		}
	}

	return false;
}
Пример #15
0
void Database::SendHeaders(Client *client) {

	int unknownField2 = 25015275;
	int unknownField3 = 1;
	int characterID = FindCharacter(client->MailBoxName().c_str());

	_log(UCS__TRACE, "Sendheaders for %s, CharID is %i", client->MailBoxName().c_str(), characterID);

	if(characterID <= 0)
		return;

	std::string query = StringFormat("SELECT `msgid`,`timestamp`, `from`, `subject`, `status` "
                                    "FROM `mail` WHERE `charid`=%i", characterID);
    auto results = QueryDatabase(query);
	if (!results.Success())
		return;

	char buffer[100];

	int headerCountPacketLength = 0;

	sprintf(buffer, "%i", client->GetMailBoxNumber());
	headerCountPacketLength += (strlen(buffer) + 1);

	sprintf(buffer, "%i", unknownField2);
	headerCountPacketLength += (strlen(buffer) + 1);

	sprintf(buffer, "%i", unknownField3);
	headerCountPacketLength += (strlen(buffer) + 1);

	sprintf(buffer, "%i", results.RowCount());
	headerCountPacketLength += (strlen(buffer) + 1);

	EQApplicationPacket *outapp = new EQApplicationPacket(OP_MailHeaderCount, headerCountPacketLength);

	char *packetBuffer = (char *)outapp->pBuffer;

	VARSTRUCT_ENCODE_INTSTRING(packetBuffer, client->GetMailBoxNumber());
	VARSTRUCT_ENCODE_INTSTRING(packetBuffer, unknownField2);
	VARSTRUCT_ENCODE_INTSTRING(packetBuffer, unknownField3);
	VARSTRUCT_ENCODE_INTSTRING(packetBuffer, results.RowCount());

	_pkt(UCS__PACKETS, outapp);

	client->QueuePacket(outapp);

	safe_delete(outapp);

	int rowIndex = 0;
	for(auto row = results.begin(); row != results.end(); ++row, ++rowIndex) {
		int headerPacketLength = 0;

		sprintf(buffer, "%i", client->GetMailBoxNumber());
		headerPacketLength += strlen(buffer) + 1;
		sprintf(buffer, "%i", unknownField2);
		headerPacketLength += strlen(buffer) + 1;
		sprintf(buffer, "%i", rowIndex);
		headerPacketLength += strlen(buffer) + 1;

		headerPacketLength += strlen(row[0]) + 1;
		headerPacketLength += strlen(row[1]) + 1;
		headerPacketLength += strlen(row[4]) + 1;
		headerPacketLength += GetMailPrefix().length() + strlen(row[2]) + 1;
		headerPacketLength += strlen(row[3]) + 1;

		outapp = new EQApplicationPacket(OP_MailHeader, headerPacketLength);

		packetBuffer = (char *)outapp->pBuffer;

		VARSTRUCT_ENCODE_INTSTRING(packetBuffer, client->GetMailBoxNumber());
		VARSTRUCT_ENCODE_INTSTRING(packetBuffer, unknownField2);
		VARSTRUCT_ENCODE_INTSTRING(packetBuffer, rowIndex);
		VARSTRUCT_ENCODE_STRING(packetBuffer, row[0]);
		VARSTRUCT_ENCODE_STRING(packetBuffer, row[1]);
		VARSTRUCT_ENCODE_STRING(packetBuffer, row[4]);
		VARSTRUCT_ENCODE_STRING(packetBuffer, GetMailPrefix().c_str());
		packetBuffer--;
		VARSTRUCT_ENCODE_STRING(packetBuffer, row[2]);
		VARSTRUCT_ENCODE_STRING(packetBuffer, row[3]);

		_pkt(UCS__PACKETS, outapp);

		client->QueuePacket(outapp);

		safe_delete(outapp);
	}

}