// возвращает текст без тегов Ogre::UTFString TextIterator::getOnlyText(const Ogre::UTFString& _text) { Ogre::UTFString ret; ret.reserve(_text.size()); Ogre::UTFString::const_iterator end = _text.end(); for (Ogre::UTFString::const_iterator iter=_text.begin(); iter!=end; ++iter) { if ((*iter) == L'#') { // следующий символ ++ iter; if (iter == end) break; // тэг цвета if ((*iter) != L'#') { // остальные 5 символов цвета for (size_t pos=0; pos<5; pos++) { ++ iter; if (iter == end) { --iter; break; } } continue; } } // обыкновенный символ ret.push_back(*iter); } return ret; }
void SendPrivateChat(int target_uid, Ogre::UTFString chatline, Ogre::UTFString target_username) { #ifdef USE_SOCKETW char buffer[MAX_MESSAGE_LENGTH] = {0}; const char *chat_msg = (const char *)chatline.asUTF8_c_str(); // format: int of UID, then chat message memcpy(buffer, &target_uid, sizeof(int)); strncpy(buffer + sizeof(int), chat_msg, MAX_MESSAGE_LENGTH - sizeof(int)); size_t len = sizeof(int) + chatline.size() * sizeof(wchar_t); buffer[len] = 0; RoR::Networking::AddPacket(m_stream_id, MSG2_UTF_PRIVCHAT, (unsigned int)len, buffer); if (target_username.empty()) { user_info_t user; if (RoR::Networking::GetUserInfo(target_uid, user)) { target_username = GetColouredName(user.username, user.colournum); } } // add local visual Ogre::UTFString local_username = GetColouredName(RoR::Networking::GetUsername(), RoR::Networking::GetUserColor()); Ogre::UTFString nmsg = local_username + RoR::Color::WhisperColour + _L(" [whispered to ") + RoR::Color::NormalColour + target_username + RoR::Color::WhisperColour + "]" + RoR::Color::NormalColour + ": " + chatline; #ifdef USE_MYGUI RoR::Application::GetGuiManager()->pushMessageChatBox(nmsg); #endif // USE_MYGUI #endif // USE_SOCKETW }
void ChatSystem::sendPrivateChat(int target_uid, Ogre::UTFString chatline, Ogre::UTFString username) { #ifdef USE_SOCKETW char buffer[MAX_MESSAGE_LENGTH] = ""; const char *chat_msg = (const char *)chatline.asUTF8_c_str(); // format: int of UID, then chat message memcpy(buffer, &target_uid, sizeof(int)); strncpy(buffer + sizeof(int), chat_msg, MAX_MESSAGE_LENGTH - sizeof(int)); size_t len = sizeof(int) + chatline.size() * sizeof(wchar_t); buffer[len] = 0; this->addPacket(MSG2_UTF_PRIVCHAT, (unsigned int)len, buffer); if(username.empty()) { client_t *c = net->getClientInfo(target_uid); if(c) username = getColouredName(*c); } // add local visual #ifdef USE_MYGUI UTFString nmsg = net->getNickname(true) + normalColour + whisperColour + _L(" [whispered to ") + normalColour + username + whisperColour + "]" + normalColour + ": " + chatline; Console::getInstance().putMessage(Console::CONSOLE_MSGTYPE_NETWORK, Console::CONSOLE_LOCAL_CHAT, nmsg, "script_key.png"); #endif // USE_MYGUI #endif // USE_SOCKETW }
Ogre::UTFString GetColouredName(Ogre::UTFString nick, int colour_number) { Ogre::ColourValue col_val = PlayerColours::getSingleton().getColour(colour_number); char tmp[255] = {0}; sprintf(tmp, "#%02X%02X%02X", (unsigned int)(col_val.r * 255.0f), (unsigned int)(col_val.g * 255.0f), (unsigned int)(col_val.b * 255.0f)); // replace # with X in nickname so the user cannot fake the colour for (unsigned int i=0; i<nick.size(); i++) if (nick[i] == '#') nick[i] = 'X'; return tryConvertUTF(tmp) + nick; }
bool TextIterator::setTagColour(Ogre::UTFString _colour) { if (mCurrent == mEnd) return false; // очищаем все цвета clearTagColour(); // на всякий if (mCurrent == mEnd) return false; // проверяем на цвет хоть чуть чуть if ( (_colour.size() != 7) || (_colour.find(L'#', 1) != _colour.npos) ) return false; // непосредственная вставка insert(mCurrent, _colour); return true; }
Ogre::UTFString GetColouredName(Ogre::UTFString nick, int colour_number) { #ifdef USE_SOCKETW Ogre::ColourValue col_val = Networking::GetPlayerColor(colour_number); char tmp[255] = {0}; sprintf(tmp, "#%02X%02X%02X", (unsigned int)(col_val.r * 255.0f), (unsigned int)(col_val.g * 255.0f), (unsigned int)(col_val.b * 255.0f)); // replace # with X in nickname so the user cannot fake the colour for (unsigned int i = 0; i < nick.size(); i++) if (nick[i] == '#') nick[i] = 'X'; return tryConvertUTF(tmp) + nick; #else // USE_SOCKETW return nick; #endif // USE_SOCKETW }
Ogre::UTFString ChatSystem::getColouredName(Ogre::UTFString nick, int auth, int colourNumber) { Ogre::ColourValue col_val = PlayerColours::getSingleton().getColour(colourNumber); char tmp[255] = ""; sprintf(tmp, "#%02X%02X%02X", (unsigned int)(col_val.r * 255.0f), (unsigned int)(col_val.g * 255.0f), (unsigned int)(col_val.b * 255.0f)); // replace # with X in nickname so the user cannot fake the colour for(unsigned int i=0; i<nick.size(); i++) if(nick[i] == '#') nick[i] = 'X'; return tryConvertUTF(tmp) + nick; #if 0 // old code: colour not depending on auth status anymore ... if(auth == AUTH_NONE) col = "#c9c9c9"; // grey if(auth & AUTH_BOT ) col = "#0000c9"; // blue if(auth & AUTH_RANKED) col = "#00c900"; // green if(auth & AUTH_MOD) col = "#c90000"; // red if(auth & AUTH_ADMIN) col = "#c97100"; // orange return col + nick; #endif //0 }
//---------------------------------------------------------------------------------------- QString ConvertToQString(Ogre::UTFString& value) { QByteArray encodedString((const char*)value.data(), value.size() * 2); QTextCodec *codec = QTextCodec::codecForName("UTF-16"); return codec->toUnicode(encodedString); }