Browse Source

Handle \x01ACTION messages

kiwec 2 months ago
parent
commit
c819656d0b
5 changed files with 46 additions and 11 deletions
  1. 12 5
      src/App/Osu/Changelog.cpp
  2. 13 2
      src/App/Osu/Chat.cpp
  3. 1 1
      src/App/Osu/Osu.cpp
  4. 18 3
      src/Util/UString.cpp
  5. 2 0
      src/Util/UString.h

+ 12 - 5
src/App/Osu/Changelog.cpp

@@ -29,11 +29,16 @@ Changelog::Changelog() : ScreenBackable() {
     CHANGELOG latest;
     latest.title =
         UString::format("%.2f (%s, %s)", convar->getConVarByName("osu_version")->getFloat(), __DATE__, __TIME__);
-    latest.changes.push_back("- Fixed Artist/Creator/Title sorting to be in A-Z order");
-    latest.changes.push_back("- Improved sound engine reliability");
-    latest.changes.push_back("- Removed herobrine");
+    latest.changes.push_back("- Chat: fixed /me and #announce message formatting");
     changelogs.push_back(latest);
 
+    CHANGELOG v35_05;
+    v35_05.title = "35.05 (2024-06-13)";
+    v35_05.changes.push_back("- Fixed Artist/Creator/Title sorting to be in A-Z order");
+    v35_05.changes.push_back("- Improved sound engine reliability");
+    v35_05.changes.push_back("- Removed herobrine");
+    changelogs.push_back(v35_05);
+
     CHANGELOG v35_04;
     v35_04.title = "35.04 (2024-06-11)";
     v35_04.changes.push_back("- Changed \"Open Skins folder\" button to open the currently selected skin's folder");
@@ -43,7 +48,8 @@ Changelog::Changelog() : ScreenBackable() {
     v35_04.changes.push_back("- Fixed sliderslide and spinnerspin sounds not looping");
     v35_04.changes.push_back("- Improved sound engine reliability");
     v35_04.changes.push_back("- Re-added strain graphs");
-    v35_04.changes.push_back("- Removed sliderhead fadeout animation (set osu_slider_sliderhead_fadeout to 1 for old behavior)");
+    v35_04.changes.push_back(
+        "- Removed sliderhead fadeout animation (set osu_slider_sliderhead_fadeout to 1 for old behavior)");
     changelogs.push_back(v35_04);
 
     CHANGELOG v35_03;
@@ -68,7 +74,8 @@ Changelog::Changelog() : ScreenBackable() {
     v35_01.title = "35.01 (2024-06-08)";
     v35_01.changes.push_back("- Added ability to get spectated");
     v35_01.changes.push_back("- Added use_https convar (to support plain HTTP servers)");
-    v35_01.changes.push_back("- Added restart_sound_engine_before_playing convar (\"fixes\" sound engine lagging after a while)");
+    v35_01.changes.push_back(
+        "- Added restart_sound_engine_before_playing convar (\"fixes\" sound engine lagging after a while)");
     v35_01.changes.push_back("- Fixed chat channels being unread after joining");
     v35_01.changes.push_back("- Fixed flashlight mod");
     v35_01.changes.push_back("- Fixed FPoSu mode");

+ 13 - 2
src/App/Osu/Chat.cpp

@@ -59,8 +59,18 @@ void ChatChannel::add_message(ChatMessage msg) {
     UString text_str = "";
     float x = 10;
 
+    bool is_action = msg.text.startsWith("\001ACTION");
+    if(is_action) {
+        msg.text.erase(0, 7);
+        if(msg.text.endsWith("\001")) {
+            msg.text.erase(msg.text.length() - 1, 1);
+        }
+        msg.text.append("*");
+    }
+
     struct tm *tm = localtime(&msg.tms);
     auto timestamp_str = UString::format("%02d:%02d ", tm->tm_hour, tm->tm_min);
+    if(is_action) timestamp_str.append("*");
     float time_width = m_chat->font->getStringWidth(timestamp_str);
     CBaseUILabel *timestamp = new CBaseUILabel(x, y_total, time_width, line_height, "", timestamp_str);
     timestamp->setDrawFrame(false);
@@ -71,7 +81,6 @@ void ChatChannel::add_message(ChatMessage msg) {
     bool is_system_message = msg.author_name.length() == 0;
     if(!is_system_message) {
         float name_width = m_chat->font->getStringWidth(msg.author_name);
-
         auto user_box = new UIUserLabel(msg.author_id, msg.author_name);
         user_box->setTextColor(0xff2596be);
         user_box->setPos(x, y_total);
@@ -79,7 +88,9 @@ void ChatChannel::add_message(ChatMessage msg) {
         ui->getContainer()->addBaseUIElement(user_box);
         x += name_width;
 
-        text_str.append(": ");
+        if(!is_action) {
+            text_str.append(": ");
+        }
     }
 
     // XXX: Handle links, open them in the browser on click

+ 1 - 1
src/App/Osu/Osu.cpp

@@ -59,7 +59,7 @@ Osu *osu = NULL;
 
 // release configuration
 ConVar auto_update("auto_update", true, FCVAR_DEFAULT);
-ConVar osu_version("osu_version", 35.05f, FCVAR_DEFAULT | FCVAR_HIDDEN);
+ConVar osu_version("osu_version", 35.06f, FCVAR_DEFAULT | FCVAR_HIDDEN);
 
 #ifdef _DEBUG
 ConVar osu_debug("osu_debug", true, FCVAR_DEFAULT);

+ 18 - 3
src/Util/UString.cpp

@@ -154,10 +154,9 @@ UString UString::format(const char *utf8format, ...) {
         // https://github.com/McKay42/McEngine/commit/f5461d835a6ffb24fb26f0f36505e83e65e4bb2e
         // MSVC's standard library is horribly broken and switched the meaning of %s and %S for wide char functions
         // TODO: this doesn't handle patterns like "%%s"
-        while (true) {
+        while(true) {
             int pos = formatted.find("%s");
-            if (pos == -1)
-                break;
+            if(pos == -1) break;
 
             formatted.mUnicode[pos + 1] = L'S';
         }
@@ -653,6 +652,22 @@ bool UString::operator<(const UString &ustr) const {
     return mLength < ustr.mLength;
 }
 
+bool UString::startsWith(const UString &ustr) const {
+    if(mLength < ustr.mLength) return false;
+    for(int i = 0; i < ustr.mLength; i++) {
+        if(mUnicode[i] != ustr.mUnicode[i]) return false;
+    }
+    return true;
+}
+
+bool UString::endsWith(const UString &ustr) const {
+    if(mLength < ustr.mLength) return false;
+    for(int i = 0; i < ustr.mLength; i++) {
+        if(mUnicode[mLength - ustr.mLength + i] != ustr.mUnicode[i]) return false;
+    }
+    return true;
+}
+
 bool UString::equalsIgnoreCase(const UString &ustr) const {
     if(mLength != ustr.mLength) return false;
 

+ 2 - 0
src/Util/UString.h

@@ -89,6 +89,8 @@ class UString {
     bool operator!=(const UString &ustr) const;
     bool operator<(const UString &ustr) const;
 
+    bool startsWith(const UString &ustr) const;
+    bool endsWith(const UString &ustr) const;
     bool equalsIgnoreCase(const UString &ustr) const;
     bool lessThanIgnoreCase(const UString &ustr) const;