Project SkyFire Core
SkyFire 5.4.8 server core API documentation
Loading...
Searching...
No Matches
Util.cpp File Reference
#include "Common.h"
#include "Errors.h"
#include "Platform/TimeUtils.h"
#include "sfmt.h"
#include "utf8.h"
#include "Util.h"
#include <atomic>
#include <cstdarg>
#include <random>
Include dependency graph for Util.cpp:

Go to the source code of this file.

Typedefs

typedef wchar_t const *const * wstrlist

Functions

bool consoleToUtf8 (const std::string &conStr, std::string &utf8str)
uint32 CreatePIDFile (const std::string &filename)
 create PID file
float frand (float min, float max)
std::string GetAddressString (Skyfire::Net::Address const &addr)
 Transforms network address into string format "dotted_ip:port".
std::wstring GetMainPartOfName (std::wstring wname, uint32 declension)
bool IsIPAddress (char const *ipaddress)
 Check if the string is a valid ip address representation.
bool IsIPAddrInNetwork (Skyfire::Net::Address const &net, Skyfire::Net::Address const &addr, Skyfire::Net::Address const &subnetMask)
 Checks if address belongs to the a network with specified submask.
int64 MoneyStringToMoney (const std::string &moneyString)
int32 rand32 ()
double rand_chance (void)
double rand_norm (void)
std::string secsToTimeString (uint64 timeInSecs, bool shortText, bool hoursOnly)
static CRandomSFMT & SfmtRand ()
void stripLineInvisibleChars (std::string &str)
uint32 TimeStringToSecs (const std::string &timestring)
std::string TimeToTimestampStr (time_t t)
bool Utf8FitTo (const std::string &str, const std::wstring &search)
size_t utf8length (std::string &utf8str)
void utf8printf (FILE *out, const char *str,...)
bool utf8ToConsole (const std::string &utf8str, std::string &conStr)
bool Utf8toWStr (char const *utf8str, size_t csize, wchar_t *wstr, size_t &wsize)
bool Utf8toWStr (const std::string &utf8str, std::wstring &wstr)
void utf8truncate (std::string &utf8str, size_t len)
void vutf8printf (FILE *out, const char *str, va_list *ap)
bool WStrToUtf8 (const std::wstring &wstr, std::string &utf8str)
bool WStrToUtf8 (wchar_t *wstr, size_t size, std::string &utf8str)

Typedef Documentation

◆ wstrlist

typedef wchar_t const* const* wstrlist

Definition at line 394 of file Util.cpp.

Function Documentation

◆ consoleToUtf8()

bool consoleToUtf8 ( const std::string & conStr,
std::string & utf8str )

Definition at line 458 of file Util.cpp.

References WStrToUtf8().

Referenced by CliRunnable::Run().

◆ CreatePIDFile()

uint32 CreatePIDFile ( const std::string & filename)

create PID file

Definition at line 253 of file Util.cpp.

Referenced by main(), and Master::Run().

◆ frand()

◆ GetAddressString()

std::string GetAddressString ( Skyfire::Net::Address const & addr)

Transforms network address into string format "dotted_ip:port".

Definition at line 237 of file Util.cpp.

References Skyfire::Net::Address::GetHost(), and Skyfire::Net::Address::GetPort().

Referenced by AuthSocket::_HandleRealmList().

◆ GetMainPartOfName()

std::wstring GetMainPartOfName ( std::wstring wname,
uint32 declension )

Definition at line 396 of file Util.cpp.

References isCyrillicCharacter().

Referenced by ObjectMgr::CheckDeclinedNames().

◆ IsIPAddress()

bool IsIPAddress ( char const * ipaddress)

Check if the string is a valid ip address representation.

Definition at line 229 of file Util.cpp.

References Skyfire::Net::IsIPv4Address().

Referenced by ban_commandscript::HandleBanHelper(), ban_commandscript::HandleBanInfoIPCommand(), and ban_commandscript::HandleUnBanHelper().

◆ IsIPAddrInNetwork()

bool IsIPAddrInNetwork ( Skyfire::Net::Address const & net,
Skyfire::Net::Address const & addr,
Skyfire::Net::Address const & subnetMask )

Checks if address belongs to the a network with specified submask.

Definition at line 244 of file Util.cpp.

References Skyfire::Net::Address::ToIPv4NetworkOrder().

Referenced by AuthSocket::GetAddressForClient().

◆ MoneyStringToMoney()

int64 MoneyStringToMoney ( const std::string & moneyString)

Definition at line 150 of file Util.cpp.

References Tokenizer::begin(), and Tokenizer::end().

Referenced by modify_commandscript::HandleModifyMoneyCommand().

◆ rand32()

int32 rand32 ( )

Definition at line 45 of file Util.cpp.

References SfmtRand().

Referenced by Player::GetRandomResearchProjectForRace(), and Player::OnArchaeologyFindUsed().

◆ rand_chance()

◆ rand_norm()

◆ secsToTimeString()

◆ SfmtRand()

CRandomSFMT & SfmtRand ( )
static

Definition at line 33 of file Util.cpp.

Referenced by frand(), rand32(), rand_chance(), and rand_norm().

◆ stripLineInvisibleChars()

void stripLineInvisibleChars ( std::string & str)

Definition at line 94 of file Util.cpp.

Referenced by WorldSession::HandleMessagechatOpcode().

◆ TimeStringToSecs()

uint32 TimeStringToSecs ( const std::string & timestring)

◆ TimeToTimestampStr()

◆ Utf8FitTo()

◆ utf8length()

size_t utf8length ( std::string & utf8str)

◆ utf8printf()

void utf8printf ( FILE * out,
const char * str,
... )

Definition at line 489 of file Util.cpp.

References vutf8printf().

Referenced by AppenderConsole::_write().

◆ utf8ToConsole()

bool utf8ToConsole ( const std::string & utf8str,
std::string & conStr )

Definition at line 441 of file Util.cpp.

References Utf8toWStr().

◆ Utf8toWStr() [1/2]

bool Utf8toWStr ( char const * utf8str,
size_t csize,
wchar_t * wstr,
size_t & wsize )

Definition at line 305 of file Util.cpp.

Referenced by ObjectMgr::AddGameTele(), ObjectMgr::CheckDeclinedNames(), ObjectMgr::CheckPetName(), ObjectMgr::CheckPlayerName(), ObjectMgr::DeleteGameTele(), ChannelMgr::GetChannel(), ObjectMgr::GetGameTele(), ObjectMgr::GetGameTeleExactName(), ChannelMgr::GetJoinChannel(), WorldSession::HandleAuctionListItems(), learn_commandscript::HandleLearnAllRecipesCommand(), lookup_commandscript::HandleLookupAreaCommand(), lookup_commandscript::HandleLookupCreatureCommand(), lookup_commandscript::HandleLookupEventCommand(), lookup_commandscript::HandleLookupFactionCommand(), lookup_commandscript::HandleLookupItemCommand(), lookup_commandscript::HandleLookupItemSetCommand(), lookup_commandscript::HandleLookupMapCommand(), lookup_commandscript::HandleLookupObjectCommand(), lookup_commandscript::HandleLookupQuestCommand(), lookup_commandscript::HandleLookupSkillCommand(), lookup_commandscript::HandleLookupSpellCommand(), lookup_commandscript::HandleLookupTaxiNodeCommand(), lookup_commandscript::HandleLookupTeleCommand(), lookup_commandscript::HandleLookupTitleCommand(), modify_commandscript::HandleModifyRepCommand(), WorldSession::HandleSetPlayerDeclinedNames(), WorldSession::HandleWhoOpcode(), ObjectMgr::IsReservedName(), ObjectMgr::IsValidCharterName(), ChannelMgr::LeftChannel(), ObjectMgr::LoadGameTele(), ObjectMgr::LoadReservedPlayersNames(), normalizePlayerName(), AccountMgr::normalizeString(), Utf8FitTo(), utf8print(), utf8ToConsole(), and vutf8printf().

◆ Utf8toWStr() [2/2]

bool Utf8toWStr ( const std::string & utf8str,
std::wstring & wstr )

Definition at line 333 of file Util.cpp.

Referenced by Utf8toWStr().

◆ utf8truncate()

void utf8truncate ( std::string & utf8str,
size_t len )

Definition at line 284 of file Util.cpp.

Referenced by PlayerSocial::SetFriendNote(), and Guild::BankTab::SetText().

◆ vutf8printf()

void vutf8printf ( FILE * out,
const char * str,
va_list * ap )

Definition at line 497 of file Util.cpp.

References Utf8toWStr(), and vsnprintf.

Referenced by utf8printf().

◆ WStrToUtf8() [1/2]

bool WStrToUtf8 ( const std::wstring & wstr,
std::string & utf8str )

Definition at line 371 of file Util.cpp.

◆ WStrToUtf8() [2/2]

bool WStrToUtf8 ( wchar_t * wstr,
size_t size,
std::string & utf8str )

Definition at line 348 of file Util.cpp.

Referenced by consoleToUtf8(), normalizePlayerName(), and AccountMgr::normalizeString().