From c68c3746dd1554fdd3b31a7cff7d7c4f93c7ff34 Mon Sep 17 00:00:00 2001 From: kaetemi Date: Sat, 24 Oct 2020 19:07:41 +0800 Subject: [PATCH 01/10] Build fix --- nel/tools/3d/panoply_preview/main_window.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nel/tools/3d/panoply_preview/main_window.cpp b/nel/tools/3d/panoply_preview/main_window.cpp index 1b743d439..1ef144a14 100644 --- a/nel/tools/3d/panoply_preview/main_window.cpp +++ b/nel/tools/3d/panoply_preview/main_window.cpp @@ -53,7 +53,7 @@ namespace { QString nli18n(const char *label) { - return QString::fromUtf16(CI18N::get(label).c_str()); + return QString::fromUtf16((const ushort *)CI18N::get(label).c_str()); } } /* anonymous namespace */ From c068d757eb2442692f47201e9124afbab6c2f523 Mon Sep 17 00:00:00 2001 From: kaetemi Date: Sat, 24 Oct 2020 19:23:11 +0800 Subject: [PATCH 02/10] Build fix --- nel/include/nel/misc/string_common.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/nel/include/nel/misc/string_common.h b/nel/include/nel/misc/string_common.h index 9f6d59aae..6021b8159 100644 --- a/nel/include/nel/misc/string_common.h +++ b/nel/include/nel/misc/string_common.h @@ -193,6 +193,10 @@ inline std::string toString(const sint32 &val) { return toString("%d", val); } inline std::string toString(const uint64 &val) { return toString("%" NL_I64 "u", val); } inline std::string toString(const sint64 &val) { return toString("%" NL_I64 "d", val); } +#ifdef NL_OS_WINDOWS +inline std::string toString(const wchar_t &val) { return toString(reinterpret_cast(val)); } +#endif + #ifdef NL_COMP_GCC # if GCC_VERSION == 40102 @@ -246,6 +250,10 @@ inline bool fromString(const std::string &str, sint64 &val) { bool ret = sscanf( inline bool fromString(const std::string &str, float &val) { bool ret = sscanf(str.c_str(), "%f", &val) == 1; if (!ret) val = 0.0f; return ret; } inline bool fromString(const std::string &str, double &val) { bool ret = sscanf(str.c_str(), "%lf", &val) == 1; if (!ret) val = 0.0; return ret; } +#ifdef NL_OS_WINDOWS +inline bool fromString(const std::string &str, wchar_t &val) { return fromString(str, reinterpret_cast(val)); } +#endif + // Fast string to bool, reliably defined for strings starting with 0, 1, t, T, f, F, y, Y, n, N, anything else is undefined. // (str[0] == '1' || (str[0] & 0xD2) == 0x50) // - Kaetemi From 8d94baaf14a9ba71ffbca056df6673383e3cd7ae Mon Sep 17 00:00:00 2001 From: kaetemi Date: Sat, 24 Oct 2020 21:17:22 +0800 Subject: [PATCH 03/10] More consistent unicode behaviour for text --- nel/include/nel/gui/group_editbox.h | 4 +- nel/src/gui/ctrl_base.cpp | 52 ++++++++++--------- nel/src/gui/ctrl_text_button.cpp | 8 +-- nel/src/gui/dbgroup_combo_box.cpp | 2 +- nel/src/gui/dbview_quantity.cpp | 7 +-- nel/src/gui/group_editbox.cpp | 20 +------ nel/src/gui/group_html.cpp | 4 +- nel/src/gui/group_list.cpp | 9 ++-- nel/src/gui/group_menu.cpp | 7 +-- nel/src/gui/group_paragraph.cpp | 9 ++-- nel/src/gui/group_tree.cpp | 7 +-- nel/src/gui/lua_ihm.cpp | 6 +-- nel/src/gui/view_text.cpp | 12 ++--- nel/src/gui/view_text_formated.cpp | 38 +++++++------- nel/src/gui/view_text_id_formated.cpp | 27 +++++----- nel/src/misc/system_utils.cpp | 21 +++++--- .../src/interface_v3/macrocmd_manager.cpp | 10 ++-- ryzom/client/src/login.cpp | 4 +- 18 files changed, 121 insertions(+), 126 deletions(-) diff --git a/nel/include/nel/gui/group_editbox.h b/nel/include/nel/gui/group_editbox.h index 096f3daa0..dc343410b 100644 --- a/nel/include/nel/gui/group_editbox.h +++ b/nel/include/nel/gui/group_editbox.h @@ -79,8 +79,6 @@ namespace NLGUI sint64 getInputStringAsInt64() const; void setInputStringAsFloat(float val); float getInputStringAsFloat() const; - void setInputStringAsStdString(const std::string &str); - std::string getInputStringAsStdString() const; void setInputStringAsUtf8(const std::string &str); std::string getInputStringAsUtf8() const; void setColor(NLMISC::CRGBA col); @@ -189,7 +187,7 @@ namespace NLGUI REFLECT_LUA_METHOD("setSelectionAll", luaSetSelectionAll); REFLECT_LUA_METHOD("setFocusOnText", luaSetFocusOnText); REFLECT_LUA_METHOD("cancelFocusOnText", luaCancelFocusOnText); - REFLECT_STRING("input_string", getInputStringAsStdString, setInputStringAsStdString); + REFLECT_STRING("input_string", getInputStringAsUtf8, setInputStringAsUtf8); REFLECT_UCSTRING("uc_input_string", getInputString, setInputString); REFLECT_EXPORT_END diff --git a/nel/src/gui/ctrl_base.cpp b/nel/src/gui/ctrl_base.cpp index 2d67ccc30..0124bfdee 100644 --- a/nel/src/gui/ctrl_base.cpp +++ b/nel/src/gui/ctrl_base.cpp @@ -122,30 +122,26 @@ namespace NLGUI CXMLAutoPtr prop; // get static toolTip - prop = (char*) xmlGetProp( cur, (xmlChar*)"tooltip" ); - if (prop) + prop = (char *)xmlGetProp(cur, (xmlChar *)"tooltip_i18n"); + if ((bool)prop && strlen((const char *)prop) > 0) { - const char *propPtr = prop; - if (strlen(propPtr) > 2 && propPtr[0] == 'u' && propPtr[1] == ':') - _ContextHelp = ucstring::makeFromUtf8(std::string(propPtr).substr(2)); + // Force I18N tooltip + if (!editorMode) + _ContextHelp = CI18N::get((const char *)prop); else - _ContextHelp = ucstring(propPtr); - - - if( !editorMode && ( strlen(propPtr) > 2 ) ) - { - if ((propPtr[0] == 'u') && (propPtr[1] == 'i')) - _ContextHelp = CI18N::get ((const char *) prop); - } + _ContextHelp.fromUtf8((const char *)prop); } - // Force I18N tooltip - prop = (char*) xmlGetProp( cur, (xmlChar*)"tooltip_i18n" ); - if ((bool)prop && strlen((const char*)prop)>0) + else { - if( !editorMode ) - _ContextHelp = CI18N::get ((const char *) prop); - else - _ContextHelp = (const char*)prop; + // get static toolTip + prop = (char *)xmlGetProp(cur, (xmlChar *)"tooltip"); + if (prop) + { + if (!editorMode && NLMISC::startsWith((const char *)prop, "ui")) + _ContextHelp = CI18N::get((const char *)prop); + else + _ContextHelp.fromUtf8((const char *)prop); + } } // get dynamic toolTip ActionHandler @@ -173,7 +169,7 @@ namespace NLGUI _ToolTipSpecialParent= CStringShared(); if(prop) { - _ToolTipSpecialParent= std::string((const char*)prop); + _ToolTipSpecialParent= (const char*)prop; } // Tooltip posref @@ -201,12 +197,12 @@ namespace NLGUI { if( name == "tooltip" ) { - return _ContextHelp.toString(); + return _ContextHelp.toUtf8(); } else if( name == "tooltip_i18n" ) { - return _ContextHelp.toString(); + return _ContextHelp.toUtf8(); } else if( name == "on_tooltip" ) @@ -262,13 +258,19 @@ namespace NLGUI { if( name == "tooltip" ) { - _ContextHelp = ucstring::makeFromUtf8(value); + if (!editorMode && NLMISC::startsWith(value, "ui")) + _ContextHelp = CI18N::get(value); + else + _ContextHelp.fromUtf8(value); return; } else if( name == "tooltip_i18n" ) { - _ContextHelp = value; + if (!editorMode) + _ContextHelp = CI18N::get(value); + else + _ContextHelp.fromUtf8(value); return; } else diff --git a/nel/src/gui/ctrl_text_button.cpp b/nel/src/gui/ctrl_text_button.cpp index de01174ed..942dd11f8 100644 --- a/nel/src/gui/ctrl_text_button.cpp +++ b/nel/src/gui/ctrl_text_button.cpp @@ -596,9 +596,11 @@ namespace NLGUI if (prop) { const char *propPtr = prop; - ucstring text = ucstring(propPtr); - if ((strlen(propPtr)>2) && (propPtr[0] == 'u') && (propPtr[1] == 'i')) - text = CI18N::get (propPtr); + ucstring text; + if (NLMISC::startsWith(propPtr, "ui")) + text = CI18N::get(propPtr); + else + text.fromUtf8(propPtr); _ViewText->setText(text); } } diff --git a/nel/src/gui/dbgroup_combo_box.cpp b/nel/src/gui/dbgroup_combo_box.cpp index 834d2d5bf..59a8b03c8 100644 --- a/nel/src/gui/dbgroup_combo_box.cpp +++ b/nel/src/gui/dbgroup_combo_box.cpp @@ -467,7 +467,7 @@ namespace NLGUI void CDBGroupComboBox::setViewText(const ucstring & text) { _IsExternViewText = true; - _ExternViewText = ucstring(text); + _ExternViewText = text; _ViewText->setText(_ExternViewText); } diff --git a/nel/src/gui/dbview_quantity.cpp b/nel/src/gui/dbview_quantity.cpp index cac772c96..0b01f14f0 100644 --- a/nel/src/gui/dbview_quantity.cpp +++ b/nel/src/gui/dbview_quantity.cpp @@ -147,9 +147,10 @@ namespace NLGUI if(ptr) { const char *propPtr = ptr; - _EmptyText = ucstring(propPtr); - if ((strlen(propPtr)>2) && (propPtr[0] == 'u') && (propPtr[1] == 'i')) - _EmptyText = CI18N::get (propPtr); + if (NLMISC::startsWith(propPtr, "ui")) + _EmptyText = CI18N::get(propPtr); + else + _EmptyText.fromUtf8(propPtr); } // init cache. diff --git a/nel/src/gui/group_editbox.cpp b/nel/src/gui/group_editbox.cpp index 136909f63..2879a62af 100644 --- a/nel/src/gui/group_editbox.cpp +++ b/nel/src/gui/group_editbox.cpp @@ -1229,7 +1229,7 @@ namespace NLGUI { makeTopWindow(); // for french, deutsch and russian, be aware of unicode - std::string command = ucstring(_InputString.substr(1)).toUtf8(); + std::string command = _InputString.substr(1).toUtf8(); ICommand::expand(command); // then back to ucstring _InputString.fromUtf8(command); @@ -1735,26 +1735,10 @@ namespace NLGUI CInterfaceGroup::setActive(active); } - // *************************************************************************** - void CGroupEditBox::setInputStringAsStdString(const std::string &str) - { - setInputString(ucstring(str)); - } - - // *************************************************************************** - std::string CGroupEditBox::getInputStringAsStdString() const - { - std::string result; - _InputString.toString(result); - return result; - } - // *************************************************************************** void CGroupEditBox::setInputStringAsUtf8(const std::string &str) { - ucstring tmp; - tmp.fromUtf8(str); - setInputString(tmp); + setInputString(ucstring::makeFromUtf8(str)); } // *************************************************************************** diff --git a/nel/src/gui/group_html.cpp b/nel/src/gui/group_html.cpp index 50b381a3c..0c294c766 100644 --- a/nel/src/gui/group_html.cpp +++ b/nel/src/gui/group_html.cpp @@ -4716,7 +4716,7 @@ namespace NLGUI const char *funcName = "addString"; CLuaIHM::checkArgCount(ls, funcName, 1); CLuaIHM::checkArgType(ls, funcName, 1, LUA_TSTRING); - addString(ucstring(ls.toString(1))); + addString(ucstring::makeFromUtf8(ls.toString(1))); return 0; } @@ -5470,7 +5470,7 @@ namespace NLGUI } else { - ctrlButton->setDefaultContextHelp(ucstring(tooltip)); + ctrlButton->setDefaultContextHelp(ucstring::makeFromUtf8(tooltip)); } } diff --git a/nel/src/gui/group_list.cpp b/nel/src/gui/group_list.cpp index b49eed7cc..d619a8146 100644 --- a/nel/src/gui/group_list.cpp +++ b/nel/src/gui/group_list.cpp @@ -518,11 +518,10 @@ namespace NLGUI { _HardText = std::string( (const char*)ptr ); const char *propPtr = ptr; - ucstring Text = ucstring(propPtr); - if ((strlen(propPtr)>2) && (propPtr[0] == 'u') && (propPtr[1] == 'i')) - Text = CI18N::get (propPtr); - - addTextChild(Text); + if (NLMISC::startsWith(propPtr, "ui")) + addTextChild(CI18N::get(propPtr)); + else + addTextChild(ucstring::makeFromUtf8(propPtr)); } else { diff --git a/nel/src/gui/group_menu.cpp b/nel/src/gui/group_menu.cpp index 3fc8d0bbb..830b74fb9 100644 --- a/nel/src/gui/group_menu.cpp +++ b/nel/src/gui/group_menu.cpp @@ -283,9 +283,10 @@ namespace NLGUI if (name) { const char *ptrName = (const char*)name; - ucstrName = ucstring(ptrName); - if ((strlen(ptrName)>2) && (ptrName[0] == 'u') && (ptrName[1] == 'i')) - ucstrName = CI18N::get (ptrName); + if (NLMISC::startsWith(ptrName, "ui")) + ucstrName = CI18N::get(ptrName); + else + ucstrName.fromUtf8(ptrName); } CXMLAutoPtr ah((const char*) xmlGetProp (cur, (xmlChar*)"handler")); diff --git a/nel/src/gui/group_paragraph.cpp b/nel/src/gui/group_paragraph.cpp index 9424c0218..f772309a6 100644 --- a/nel/src/gui/group_paragraph.cpp +++ b/nel/src/gui/group_paragraph.cpp @@ -476,11 +476,10 @@ namespace NLGUI { _HardText = std::string( (const char*)ptr ); const char *propPtr = ptr; - ucstring Text = ucstring(propPtr); - if ((strlen(propPtr)>2) && (propPtr[0] == 'u') && (propPtr[1] == 'i')) - Text = CI18N::get (propPtr); - - addTextChild(Text); + if (NLMISC::startsWith(propPtr, "ui")) + addTextChild(CI18N::get(propPtr)); + else + addTextChild(ucstring::makeFromUtf8(propPtr)); } else { diff --git a/nel/src/gui/group_tree.cpp b/nel/src/gui/group_tree.cpp index 83c080b5e..9fad363f0 100644 --- a/nel/src/gui/group_tree.cpp +++ b/nel/src/gui/group_tree.cpp @@ -306,9 +306,10 @@ namespace NLGUI if (name) { const char *ptrName = (const char*)name; - Text = ucstring(ptrName); - if ((strlen(ptrName)>2) && (ptrName[0] == 'u') && (ptrName[1] == 'i')) - Text = CI18N::get (ptrName); + if (NLMISC::startsWith(ptrName, "ui")) + Text = CI18N::get(ptrName); + else + ucstring::makeFromUtf8(ptrName); } CXMLAutoPtr color((const char*) xmlGetProp (cur, (xmlChar*)"color")); diff --git a/nel/src/gui/lua_ihm.cpp b/nel/src/gui/lua_ihm.cpp index 946baa560..cf60444a6 100644 --- a/nel/src/gui/lua_ihm.cpp +++ b/nel/src/gui/lua_ihm.cpp @@ -1880,21 +1880,21 @@ namespace NLGUI ucstring CLuaIHM::findReplaceAll(const ucstring &str, const std::string &search, const std::string &replace) { //H_AUTO(Lua_CLuaIHM_findReplaceAll) - return findReplaceAll(str, ucstring(search), ucstring(replace)); + return findReplaceAll(str, ucstring::makeFromUtf8(search), ucstring::makeFromUtf8(replace)); } // *************************************************************************** ucstring CLuaIHM::findReplaceAll(const ucstring &str, const std::string &search, const ucstring &replace) { //H_AUTO(Lua_CLuaIHM_findReplaceAll) - return findReplaceAll(str, ucstring(search), ucstring(replace)); + return findReplaceAll(str, ucstring::makeFromUtf8(search), replace); } // *************************************************************************** ucstring CLuaIHM::findReplaceAll(const ucstring &str, const ucstring &search, const std::string &replace) { //H_AUTO(Lua_CLuaIHM_findReplaceAll) - return findReplaceAll(str, ucstring(search), ucstring(replace)); + return findReplaceAll(str, search, ucstring::makeFromUtf8(replace)); } diff --git a/nel/src/gui/view_text.cpp b/nel/src/gui/view_text.cpp index dab618ff8..1b7d3f457 100644 --- a/nel/src/gui/view_text.cpp +++ b/nel/src/gui/view_text.cpp @@ -982,11 +982,11 @@ namespace NLGUI if (prop) { const char *propPtr = prop; - _Text = ucstring(propPtr); - - if ((strlen(propPtr)>2) && (propPtr[0] == 'u') && (propPtr[1] == 'i')) - _Text = CI18N::get (propPtr); - setCase (_Text, _CaseMode); + if (NLMISC::startsWith(propPtr, "ui")) + _Text = CI18N::get(propPtr); + else + _Text.fromUtf8(propPtr); + setCase(_Text, _CaseMode); } prop = (char*) xmlGetProp( cur, (xmlChar*)"hardtext_format" ); @@ -2155,7 +2155,7 @@ namespace NLGUI float dotWidth = 0.f; if (_OverflowText.size() > 0) { - si = TextContext->getStringInfo (ucstring(_OverflowText)); + si = TextContext->getStringInfo(_OverflowText); dotWidth = si.StringWidth; } diff --git a/nel/src/gui/view_text_formated.cpp b/nel/src/gui/view_text_formated.cpp index ac9263936..aa948e986 100644 --- a/nel/src/gui/view_text_formated.cpp +++ b/nel/src/gui/view_text_formated.cpp @@ -34,26 +34,26 @@ namespace NLGUI CViewTextFormated::IViewTextFormatter *CViewTextFormated::textFormatter = NULL; - std::string CViewTextFormated::getProperty( const std::string &name ) const - { - if( name == "format" ) - { - return getFormatString().toString(); - } - else - return CViewText::getProperty( name ); - } - - void CViewTextFormated::setProperty( const std::string &name, const std::string &value ) - { - if( name == "format" ) + std::string CViewTextFormated::getProperty(const std::string &name) const + { + if (name == "format") { - setFormatString( value ); - return; + return getFormatString().toUtf8(); } else - CViewText::setProperty( name, value ); - } + return CViewText::getProperty(name); + } + + void CViewTextFormated::setProperty(const std::string &name, const std::string &value) + { + if (name == "format") + { + setFormatString(ucstring::makeFromUtf8(value)); + return; + } + else + CViewText::setProperty(name, value); + } xmlNodePtr CViewTextFormated::serialize( xmlNodePtr parentNode, const char *type ) const { @@ -62,7 +62,7 @@ namespace NLGUI return NULL; xmlSetProp( node, BAD_CAST "type", BAD_CAST "text_formated" ); - xmlSetProp( node, BAD_CAST "format", BAD_CAST getFormatString().c_str() ); + xmlSetProp( node, BAD_CAST "format", BAD_CAST getFormatString().toUtf8().c_str() ); return NULL; } @@ -73,7 +73,7 @@ namespace NLGUI if (!CViewText::parse(cur, parentGroup)) return false; CXMLAutoPtr prop((const char*) xmlGetProp( cur, (xmlChar*)"format" )); if (prop) - setFormatString(ucstring((const char *) prop)); + setFormatString(ucstring::makeFromUtf8((const char *)prop)); else setFormatString(ucstring("$t")); return true; diff --git a/nel/src/gui/view_text_id_formated.cpp b/nel/src/gui/view_text_id_formated.cpp index 28998cee0..5304e9e5c 100644 --- a/nel/src/gui/view_text_id_formated.cpp +++ b/nel/src/gui/view_text_id_formated.cpp @@ -33,36 +33,35 @@ NLMISC_REGISTER_OBJECT(CViewBase, CViewTextIDFormated, std::string, "text_id_for namespace NLGUI { - std::string CViewTextIDFormated::getProperty( const std::string &name ) const + std::string CViewTextIDFormated::getProperty(const std::string &name) const { - if( name == "format" ) + if (name == "format") { - return getFormatString().toString(); + return getFormatString().toUtf8(); } else - return CViewTextID::getProperty( name ); + return CViewTextID::getProperty(name); } - - void CViewTextIDFormated::setProperty( const std::string &name, const std::string &value ) + void CViewTextIDFormated::setProperty(const std::string &name, const std::string &value) { - if( name == "format" ) + if (name == "format") { - setFormatString( value ); + setFormatString(ucstring::makeFromUtf8(value)); return; } else - CViewTextID::setProperty( name, value ); + CViewTextID::setProperty(name, value); } - xmlNodePtr CViewTextIDFormated::serialize( xmlNodePtr parentNode, const char *type ) const + xmlNodePtr CViewTextIDFormated::serialize(xmlNodePtr parentNode, const char *type) const { - xmlNodePtr node = CViewTextID::serialize( parentNode, type ); - if( node == NULL ) + xmlNodePtr node = CViewTextID::serialize(parentNode, type); + if (node == NULL) return NULL; xmlSetProp( node, BAD_CAST "type", BAD_CAST "text_id_formated" ); - xmlSetProp( node, BAD_CAST "format", BAD_CAST getFormatString().c_str() ); + xmlSetProp( node, BAD_CAST "format", BAD_CAST getFormatString().toUtf8().c_str() ); return node; } @@ -73,7 +72,7 @@ namespace NLGUI if (!CViewTextID::parse(cur, parentGroup)) return false; CXMLAutoPtr prop((const char*) xmlGetProp( cur, (xmlChar*)"format" )); if (prop) - setFormatString(ucstring((const char *) prop)); + setFormatString(ucstring::makeFromUtf8((const char *)prop)); else setFormatString(ucstring("$t")); return true; diff --git a/nel/src/misc/system_utils.cpp b/nel/src/misc/system_utils.cpp index 45da347bd..42fe63fca 100644 --- a/nel/src/misc/system_utils.cpp +++ b/nel/src/misc/system_utils.cpp @@ -167,7 +167,10 @@ bool CSystemUtils::copyTextToClipboard(const ucstring &text) bool isUnicode = (IsClipboardFormatAvailable(CF_UNICODETEXT) == TRUE); // allocates a buffer to copy text in global memory - HGLOBAL mem = GlobalAlloc(GHND|GMEM_DDESHARE, (text.size()+1) * (isUnicode ? 2:1)); + std::string textLocal; + if (!isUnicode) textLocal = NLMISC::wideToMbcs(text); + if (text.size() && !textLocal.size()) textLocal = text.toString(); + HGLOBAL mem = GlobalAlloc(GHND | GMEM_DDESHARE, isUnicode ? ((text.size() + 1) * sizeof(wchar_t)) : textLocal.size()); if (mem) { @@ -179,7 +182,7 @@ bool CSystemUtils::copyTextToClipboard(const ucstring &text) if (isUnicode) wcscpy((wchar_t *)hLock, (const wchar_t *)text.c_str()); else - strcpy((char *)hLock, text.toString().c_str()); + strcpy((char *)hLock, textLocal.c_str()); // unlock buffer GlobalUnlock(mem); @@ -213,7 +216,7 @@ bool CSystemUtils::pasteTextFromClipboard(ucstring &text) // get data from clipboard (if not of this type, they are converted) // warning, this code can't be debuggued in VC++ IDE, hObj will be always NULL - HANDLE hObj = GetClipboardData(isUnicode ? CF_UNICODETEXT:CF_TEXT); + HANDLE hObj = GetClipboardData(isUnicode ? CF_UNICODETEXT : CF_TEXT); if (hObj) { @@ -224,9 +227,15 @@ bool CSystemUtils::pasteTextFromClipboard(ucstring &text) { // retrieve clipboard data if (isUnicode) - text = (const ucchar*)hLock; - else - text = (const char*)hLock; + { + text = (const ucchar *)hLock; + } + else + { + static_cast(text) = NLMISC::mbcsToWide((const char *)hLock); + if (!text.size() && ((const char *)hLock)[0]) + text = (const char *)hLock; + } // unlock data GlobalUnlock(hObj); diff --git a/ryzom/client/src/interface_v3/macrocmd_manager.cpp b/ryzom/client/src/interface_v3/macrocmd_manager.cpp index 4ffb2bb17..6aa831eac 100644 --- a/ryzom/client/src/interface_v3/macrocmd_manager.cpp +++ b/ryzom/client/src/interface_v3/macrocmd_manager.cpp @@ -636,7 +636,7 @@ public: CDBCtrlSheet *pCS = dynamic_cast(CWidgetManager::getInstance()->getElementFromId(Params)); if (pCS == NULL) return; - pCS->setMacroText(pEB->getInputStringAsStdString()); + pCS->setMacroText(pEB->getInputStringAsUtf8()); } }; REGISTER_ACTION_HANDLER( CHandlerEBUpdateMacroText, "eb_update_macro_text"); @@ -703,10 +703,10 @@ public: CGroupEditBox *pEB = dynamic_cast(CWidgetManager::getInstance()->getElementFromId(CTRL_MACROICONCREATION_EDITTEXT)); if (pEB != NULL) { - pEB->setInputStringAsStdString(pMCM->CurrentEditMacro.DispText); + pEB->setInputStringAsUtf8(pMCM->CurrentEditMacro.DispText); CDBCtrlSheet *pCS = dynamic_cast(CWidgetManager::getInstance()->getElementFromId(CTRL_MACROICONCREATION_ICON)); if (pCS != NULL) - pCS->setMacroText(pEB->getInputStringAsStdString()); + pCS->setMacroText(pEB->getInputStringAsUtf8()); } CAHManager::getInstance()->runActionHandler("set_macro_back", NULL, string("target=")+CTRL_MACROICONCREATION_ICON+"|value="+toString(back)); @@ -862,11 +862,11 @@ public: if (pEB == NULL) return; CMacroCmdManager *pMCM = CMacroCmdManager::getInstance(); - pMCM->CurrentEditMacro.Name = pEB->getInputStringAsStdString(); + pMCM->CurrentEditMacro.Name = pEB->getInputStringAsUtf8(); if ((pMCM->CurrentEditMacro.Name.size() >= 2) && (pMCM->CurrentEditMacro.Name[0] == 'u') && (pMCM->CurrentEditMacro.Name[1] == 'i')) pMCM->CurrentEditMacro.Name[0] = 'U'; - pEB->setInputString(pMCM->CurrentEditMacro.Name); + pEB->setInputStringAsUtf8(pMCM->CurrentEditMacro.Name); } }; REGISTER_ACTION_HANDLER( CHandlerNewMacroEnterName, "new_macro_enter_name"); diff --git a/ryzom/client/src/login.cpp b/ryzom/client/src/login.cpp index 2da407ecb..96922d399 100644 --- a/ryzom/client/src/login.cpp +++ b/ryzom/client/src/login.cpp @@ -1379,8 +1379,8 @@ class CAHOnLogin : public IActionHandler return; } - LoginLogin = pGEBLog->getInputStringAsStdString(); - LoginPassword = pGEBPwd->getInputStringAsStdString(); + LoginLogin = pGEBLog->getInputString().toString(); // FIXME: Unicode login + LoginPassword = pGEBPwd->getInputString().toString(); onlogin(); } From 639b4328171882c35d48fa0bfd7bb6ade71d1f87 Mon Sep 17 00:00:00 2001 From: kaetemi Date: Sat, 24 Oct 2020 21:17:44 +0800 Subject: [PATCH 04/10] Match GL behaviour in D3D for screensaver --- .../3d/driver/direct3d/driver_direct3d.cpp | 23 ++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/nel/src/3d/driver/direct3d/driver_direct3d.cpp b/nel/src/3d/driver/direct3d/driver_direct3d.cpp index fc853602f..211ed27fd 100644 --- a/nel/src/3d/driver/direct3d/driver_direct3d.cpp +++ b/nel/src/3d/driver/direct3d/driver_direct3d.cpp @@ -1225,12 +1225,29 @@ static LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM l D3DWndProc (pDriver, hWnd, message, wParam, lParam); } + if (message == WM_SYSCOMMAND) + { + switch (wParam) + { #ifdef NL_DISABLE_MENU - // disable menu (F10, ALT and ALT+SPACE key doesn't freeze or open the menu) - if(message == WM_SYSCOMMAND && wParam == SC_KEYMENU) - return 0; + // disable menu (F10, ALT and ALT+SPACE key doesn't freeze or open the menu) + case SC_KEYMENU: #endif // NL_DISABLE_MENU + // Screensaver Trying To Start? + case SC_SCREENSAVE: + + // Monitor Trying To Enter Powersave? + case SC_MONITORPOWER: + + // Prevent From Happening + return 0; + + default: + break; + } + } + // ace: if we receive close, exit now or it'll assert after if(message == WM_CLOSE) { From 8c6609943b1217735eaabcf77b273bee77554f89 Mon Sep 17 00:00:00 2001 From: kaetemi Date: Sun, 25 Oct 2020 01:23:14 +0800 Subject: [PATCH 05/10] Dump scenario, kaetemi/ryzomclassic#155 --- ryzom/client/src/r2/dmc/client_edition_module.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/ryzom/client/src/r2/dmc/client_edition_module.cpp b/ryzom/client/src/r2/dmc/client_edition_module.cpp index 6740dabfe..e388707ca 100644 --- a/ryzom/client/src/r2/dmc/client_edition_module.cpp +++ b/ryzom/client/src/r2/dmc/client_edition_module.cpp @@ -1154,6 +1154,15 @@ void CClientEditionModule::startingScenario(class NLNET::IModuleProxy * /* serve { ok = true; connectionState = "uiR2EDUploadScenario"; + +#if !FINAL_VERSION + string filename = CFile::findNewFile("scenario.rt.txt"); + COFile output(filename); + std::string ss; + rtDataPtr->serialize(ss); + output.serialBuffer((uint8*)ss.c_str(),(uint)ss.size()); + output.flush(); +#endif } else { From 78917354d9bd23f279bd07f6feb01e2e1501f6c3 Mon Sep 17 00:00:00 2001 From: kaetemi Date: Sun, 25 Oct 2020 01:23:29 +0800 Subject: [PATCH 06/10] Disable tmp debug feature --- ryzom/client/src/connection.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ryzom/client/src/connection.cpp b/ryzom/client/src/connection.cpp index 47c45984d..38a10d7e4 100644 --- a/ryzom/client/src/connection.cpp +++ b/ryzom/client/src/connection.cpp @@ -981,7 +981,7 @@ TInterfaceState globalMenu() while (PlayerWantToGoInGame == false) { - #if defined(NL_OS_WINDOWS) && defined(NL_DEBUG) + #if defined(NL_OS_WINDOWS) && defined(NL_DEBUG) && 0 // tmp for debug if (::GetAsyncKeyState(VK_SPACE)) { @@ -1067,7 +1067,7 @@ TInterfaceState globalMenu() nlSleep(ClientCfg.Sleep); } - #if defined(NL_OS_WINDOWS) && defined(NL_DEBUG) + #if defined(NL_OS_WINDOWS) && defined(NL_DEBUG) && 0 if (::GetAsyncKeyState(VK_CONTROL)) { pIM->displayUIViewBBoxs(""); From 06b430349c0b3d5150747c9f0f375fcc52517668 Mon Sep 17 00:00:00 2001 From: kaetemi Date: Sun, 25 Oct 2020 01:55:35 +0800 Subject: [PATCH 07/10] Disconnect if UDP Login fails, ryzom/ryzomcore#622 --- ryzom/client/src/network_connection.cpp | 12 ++++++++++++ ryzom/client/src/network_connection.h | 1 + 2 files changed, 13 insertions(+) diff --git a/ryzom/client/src/network_connection.cpp b/ryzom/client/src/network_connection.cpp index 731677043..c1e9d8975 100644 --- a/ryzom/client/src/network_connection.cpp +++ b/ryzom/client/src/network_connection.cpp @@ -680,6 +680,7 @@ bool CNetworkConnection::connect(string &result) _LatestLoginTime = ryzomGetLocalTime (); _LatestSyncTime = _LatestLoginTime; _LatestProbeTime = _LatestLoginTime; + m_LoginAttempts = 0; nlinfo("CNET[%p]: Client connected to shard, attempting login", this); return true; @@ -1091,6 +1092,17 @@ bool CNetworkConnection::stateLogin() { sendSystemLogin(); _LatestLoginTime = _UpdateTime; + if (m_LoginAttempts > 24) + { + m_LoginAttempts = 0; + disconnect(); // will send disconnection message + nlwarning("CNET[%p]: Too many LOGIN attempts, connection problem", this); + return false; // exit now from loop, don't expect a new state + } + else + { + ++m_LoginAttempts; + } } return false; diff --git a/ryzom/client/src/network_connection.h b/ryzom/client/src/network_connection.h index d11702682..84bb26d43 100644 --- a/ryzom/client/src/network_connection.h +++ b/ryzom/client/src/network_connection.h @@ -822,6 +822,7 @@ private: void sendSystemLogin(); bool stateLogin(); NLMISC::TTime _LatestLoginTime; + int m_LoginAttempts; // void receiveSystemSync(NLMISC::CBitMemStream &msgin); From 2568b6f321507c9d5b8178d55eed8385fca6fd48 Mon Sep 17 00:00:00 2001 From: kaetemi Date: Sun, 25 Oct 2020 01:56:10 +0800 Subject: [PATCH 08/10] Don't probe if normal received in probe state, otherwise server will not enter probe state, ryzom/ryzomcore#622, ryzom/ryzomcore#133 --- ryzom/client/src/network_connection.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/ryzom/client/src/network_connection.cpp b/ryzom/client/src/network_connection.cpp index c1e9d8975..4778641c0 100644 --- a/ryzom/client/src/network_connection.cpp +++ b/ryzom/client/src/network_connection.cpp @@ -2320,6 +2320,7 @@ bool CNetworkConnection::stateProbe() else { nlwarning("CNET[%p]: received normal in state Probe", this); + _LatestProbeTime = _UpdateTime; } } } From c252b56c93e5d7f18e66ace296d6a46fb84b93c3 Mon Sep 17 00:00:00 2001 From: kaetemi Date: Sun, 25 Oct 2020 04:18:56 +0800 Subject: [PATCH 09/10] Fix crash on save file corruption --- ryzom/client/src/item_group_manager.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/ryzom/client/src/item_group_manager.cpp b/ryzom/client/src/item_group_manager.cpp index fddba873f..83c8b4f5a 100644 --- a/ryzom/client/src/item_group_manager.cpp +++ b/ryzom/client/src/item_group_manager.cpp @@ -301,10 +301,18 @@ bool CItemGroupManager::loadGroups() NLMISC::CIFile f; f.open(userGroupFileName); NLMISC::CIXml xmlStream; - xmlStream.init(f); - // Actual loading xmlNodePtr globalEnclosing; - globalEnclosing = xmlStream.getRootNode(); + try + { + xmlStream.init(f); + // Actual loading + globalEnclosing = xmlStream.getRootNode(); + } + catch (const NLMISC::EXmlParsingError &ex) + { + nlwarning("Failed to parse '%s', skip", userGroupFileName.c_str()); + return false; + } if(!globalEnclosing) { nlwarning("no root element in item_group xml, skipping xml parsing"); From a3780e307ed084223b87af505d613bb2a61ed468 Mon Sep 17 00:00:00 2001 From: kaetemi Date: Sun, 25 Oct 2020 05:44:08 +0800 Subject: [PATCH 10/10] Fix missing ghost components in animation loading mode, kaetemi/ryzomclassic#155 --- ryzom/client/src/r2/editor.cpp | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/ryzom/client/src/r2/editor.cpp b/ryzom/client/src/r2/editor.cpp index 96b935e34..036e77b21 100644 --- a/ryzom/client/src/r2/editor.cpp +++ b/ryzom/client/src/r2/editor.cpp @@ -212,14 +212,24 @@ CDynamicMapClient(eid, clientGateway, luaState) void CDynamicMapClientEventForwarder::nodeErased(const std::string& instanceId, const std::string& attrName, sint32 position) { //H_AUTO(R2_CDynamicMapClientEventForwarder_nodeErased) - if (getEditor().getMode() != CEditor::EditionMode) return; + if (getEditor().getMode() != CEditor::EditionMode) + { + nlassert(getEditor().getMode() != CEditor::AnimationModeLoading); /* Probably should not happen */ + nldebug("Node erased, but not in edition mode"); + return; + } getEditor().nodeErased(instanceId, attrName, position); } void CDynamicMapClientEventForwarder::nodeSet(const std::string& instanceId, const std::string& attrName, CObject* value) { //H_AUTO(R2_CDynamicMapClientEventForwarder_nodeSet) - if (getEditor().getMode() != CEditor::EditionMode) return; + if (getEditor().getMode() != CEditor::EditionMode + && getEditor().getMode() != CEditor::AnimationModeLoading /* Loading animation scenario from terminal, ghost nodes created by translator */) + { + nldebug("Node set, but not in edition mode"); + return; + } getEditor().nodeSet(instanceId, attrName, value); } @@ -227,7 +237,12 @@ void CDynamicMapClientEventForwarder::nodeInserted(const std::string& instanceId const std::string& key, CObject* value) { //H_AUTO(R2_CDynamicMapClientEventForwarder_nodeInserted) - if (getEditor().getMode() != CEditor::EditionMode) return; + if (getEditor().getMode() != CEditor::EditionMode + && getEditor().getMode() != CEditor::AnimationModeLoading /* Loading animation scenario from terminal, ghost nodes created by translator */) + { + nldebug("Node inserted, but not in edition mode"); + return; + } getEditor().nodeInserted(instanceId, attrName, position, key, value); } @@ -236,7 +251,12 @@ void CDynamicMapClientEventForwarder::nodeMoved( const std::string& destInstanceId, const std::string& destAttrName, sint32 destPosition) { //H_AUTO(R2_CDynamicMapClientEventForwarder_nodeMoved) - if (getEditor().getMode() != CEditor::EditionMode) return; + if (getEditor().getMode() != CEditor::EditionMode) + { + nlassert(getEditor().getMode() != CEditor::AnimationModeLoading); /* Probably should not happen */ + nldebug("Node moved, but not in edition mode"); + return; + } getEditor().nodeMoved(instanceId, attrName, position, destInstanceId, destAttrName, destPosition); }