44 std::stringstream urlBuilder;
45 urlBuilder <<
"http://" <<
sConfig.net.imageServer <<
":" <<
sConfig.net.imageServerPort <<
"/";
46 _url = urlBuilder.str();
52 sLog.Cyan(
" ImageServer",
"Image Server URL: %s",
_url.c_str());
53 sLog.Cyan(
" ImageServer",
"Image Server path: %s",
_basePath.c_str());
62 sLog.Blue(
" ImageServer",
"Image Server Initalized.");
67 sLog.Warning(
" ImageServer",
" ReportNewImage() called.");
71 _limboImages.insert(std::pair<
uint32,std::shared_ptr<std::vector<char> > >(accountID, imageData));
79 sLog.Warning(
" ImageServer",
" ReportNewCharacter() called.");
84 sLog.Error(
" ImageServer",
" Image not received for characterID %u.", characterID);
91 std::string dirName =
"Character";
92 std::string path(
GetFilePath(dirName, characterID, 512));
93 FILE * fp = fopen(path.c_str(),
"wb");
96 std::shared_ptr<std::vector<char> > data =
_limboImages[creatorAccountID];
98 fwrite(&((*data)[0]), 1, data->size(), fp);
112 sLog.Green(
" ImageServer",
"Received image from %u and saved as %s", creatorAccountID, path.c_str());
117 sLog.Cyan(
" ImageServer",
" GetImage() called. Cat: %s, id: %u, size:%u", category.c_str(), id, size);
120 return std::shared_ptr<std::vector<char> >();
124 FILE * fp = fopen(path.c_str(),
"rb");
126 return std::shared_ptr<std::vector<char> >();
127 fseek(fp, 0, SEEK_END);
128 size_t length = ftell(fp);
129 fseek(fp, 0, SEEK_SET);
141 std::shared_ptr<std::vector<char> > ret = std::shared_ptr<std::vector<char> >(
new std::vector<char>());
146 fread(&((*ret)[0]), 1, length, fp);
153 std::string extension = category ==
"Character" ?
"jpg" :
"png";
158 std::stringstream builder;
159 builder <<
_basePath << category <<
"/" <<
id <<
"_" << size <<
"." << extension;
160 return builder.str();
165 if (category ==
"InventoryType")
166 return size == 64 || size == 32;
168 if (category ==
"Alliance")
169 return size == 256 || size == 128 || size == 64 || size == 32;
171 if (category ==
"Corporation")
172 return size == 256 || size == 128 || size == 64 || size == 32;
175 return size == 1024 || size == 512 || size == 256 || size == 128 || size == 64 || size == 40 || size == 32;
180 for (
int i = 0; i < 5; i++)
204 _io = std::shared_ptr<boost::asio::io_context>(
new boost::asio::io_context());
#define sConfig
A macro for easier access to the singleton.
static const char *const Categories[]
static const char *const FallbackURL
boost::asio::detail::mutex & _mutex
void ReportNewCharacter(uint32 creatorAccountID, uint32 characterID)
void ReportNewImage(uint32 accountID, std::shared_ptr< std::vector< char > > imageData)
std::shared_ptr< std::vector< char > > GetImage(std::string &category, uint32 id, uint32 size)
boost::asio::detail::mutex _limboLock
#define sLog
Evaluates to a NewLog instance.
bool ValidateSize(std::string &category, uint32 size)
int CreateDirectory(const char *name, void *)
std::shared_ptr< ImageServerListener > _listener
Handles listening for new clients.
static const uint32 CategoryCount
Lock(boost::asio::detail::mutex &mutex)
std::shared_ptr< boost::asio::detail::thread > _ioThread
std::shared_ptr< boost::asio::io_context > _io
std::string GetFilePath(std::string &category, uint32 id, uint32 size)
bool ValidateCategory(std::string &category)
std::unordered_map< uint32, std::shared_ptr< std::vector< char > > > _limboImages