Witam
Prowadzę OTS (Open Tibia Server). Tibii nienawidzę, ale samo tworzenie serwera to fajna sprawa + zarobek + nauka. Trochę już załapałem C++ (mam źródła serwera i ciągle grzebię, kombinuję, patrzę, co gdzie jest, czemu tam i czemu tak) i mam w związku z tym problem.
Spolszczam serwer, nadaję przedmiotom nazwy polskie, lecz zamiast np. "nóż" muszę wpisać "noz" bo pisze podczas włączania serwera, że w pliku items.xml jest znak niezgodny z UTF-8 i serwer przestaje wczytywać jakiekolwiek przedmioty i każde zamiast nazwy to "Przedmiot typu ...id_przedmiotu".
Trochę grzebałem przy źródle i znalazłem tam coś takiego:
Tools.cpp
bool readXMLInteger(xmlNodePtr node, const char* tag, int32_t& value)
{
char* nodeValue = (char*)xmlGetProp(node, (xmlChar*)tag);
if(nodeValue)
{
value = atoi(nodeValue);
xmlFreeOTSERV(nodeValue);
return true;
}
return false;
}
#if (defined __WINDOWS__ || defined WIN32) && !defined __GNUC__
bool readXMLInteger(xmlNodePtr node, const char* tag, int32_t& value)
{
char* nodeValue = (char*)xmlGetProp(node, (xmlChar*)tag);
if(nodeValue)
{
value = atoi(nodeValue);
xmlFreeOTSERV(nodeValue);
return true;
}
return false;
}
#endif
bool readXMLInteger64(xmlNodePtr node, const char* tag, uint64_t& value)
{
char* nodeValue = (char*)xmlGetProp(node, (xmlChar*)tag);
if(nodeValue)
{
value = ATOI64(nodeValue);
xmlFreeOTSERV(nodeValue);
return true;
}
return false;
}
bool readXMLFloat(xmlNodePtr node, const char* tag, float& value)
{
char* nodeValue = (char*)xmlGetProp(node, (xmlChar*)tag);
if(nodeValue)
{
value = atof(nodeValue);
xmlFreeOTSERV(nodeValue);
return true;
}
return false;
}
bool utf8ToLatin1(char* intext, std::string& outtext)
{
outtext = "";
if(intext == NULL)
return false;
int32_t inlen = strlen(intext);
if(inlen == 0)
return false;
int32_t outlen = inlen * 2;
unsigned char* outbuf = new uint8_t[outlen];
int32_t res = UTF8Toisolat1(outbuf, &outlen, (unsigned char*)intext, &inlen);
if(res < 0)
{
delete[] outbuf;
return false;
}
outbuf[outlen] = '\0';
outtext = (char*)outbuf;
delete[] outbuf;
return true;
}
bool readXMLString(xmlNodePtr node, const char* tag, std::string& value)
{
char* nodeValue = (char*)xmlGetProp(node, (xmlChar*)tag);
if(nodeValue)
{
if(!utf8ToLatin1(nodeValue, value))
value = nodeValue;
xmlFreeOTSERV(nodeValue);
return true;
}
return false;
}
bool readXMLContentString(xmlNodePtr node, std::string& value)
{
char* nodeValue = (char*)xmlNodeGetContent(node);
if(nodeValue)
{
if(!utf8ToLatin1(nodeValue, value))
value = nodeValue;
xmlFreeOTSERV(nodeValue);
return true;
}
return false;
}
tools.h
bool utf8ToLatin1(char* intext, std::string& outtext);
bool readXMLInteger(xmlNodePtr node, const char* tag, int& value);
#if (defined __WINDOWS__ || defined WIN32) && !defined __GNUC__
bool readXMLInteger(xmlNodePtr node, const char* tag, int32_t& value);
#endif
bool readXMLInteger64(xmlNodePtr node, const char* tag, uint64_t& value);
bool readXMLFloat(xmlNodePtr node, const char* tag, float& value);
bool readXMLString(xmlNodePtr node, const char* tag, std::string& value);
bool readXMLContentString(xmlNodePtr node, std::string& value);
Jeden mój znajomy mi powiedział, że mam zmienić kodowanie, inny, że zamiast char dać wchar_t a jeszcze inny, że w konsoli nie da się odczytać polskich znaczków.
W związku z tym proszę o pomoc, jak zrobić, by konsola serwera poprawnie wczytywała plik z ogonkami polskimi, albo chociaż jakiekolwiek naprowadzenie na właściwą drogę bo już z tydzień się z tym męczę, jeśli komuś potrzeba więcej danych niż te co podałem w <></> to proszę pisać...