Ticket #3832: t3832-post-revert.patch
File t3832-post-revert.patch, 9.1 KB (added by , 8 years ago) |
---|
-
binaries/data/mods/public/gui/lobby/lobby.js
116 116 updateLeaderboard(); 117 117 updatePlayerList(); 118 118 Engine.GetGUIObjectByName("hostButton").enabled = false; 119 addChatMessage({ "from": "system", "text": translate("Disconnected.") + msg.text, "color": g_SystemColor }); 119 addChatMessage({ 120 "from": "system", 121 "text": translate("Disconnected.") + msg.text, 122 "color": g_SystemColor, 123 "time": msg.time 124 }); 120 125 }, 121 126 "error": msg => { 122 addChatMessage({ "from": "system", "text": msg.text, "color": g_SystemColor }); 127 addChatMessage({ 128 "from": "system", 129 "text": msg.text, 130 "color": g_SystemColor, 131 "time": msg.time 132 }); 123 133 } 124 134 }, 125 135 "chat": { … … 129 139 "join": msg => { 130 140 addChatMessage({ 131 141 "text": "/special " + sprintf(translate("%(nick)s has joined."), { "nick": msg.text }), 132 "isSpecial": true 142 "isSpecial": true, 143 "time": msg.time 133 144 }); 134 145 Engine.SendGetRatingList(); 135 146 }, … … 136 147 "leave": msg => { 137 148 addChatMessage({ 138 149 "text": "/special " + sprintf(translate("%(nick)s has left."), { "nick": msg.text }), 139 "isSpecial": true 150 "isSpecial": true, 151 "time": msg.time 140 152 }); 141 153 }, 142 154 "presence": msg => { … … 147 159 "oldnick": msg.text, 148 160 "newnick": msg.data 149 161 }), 150 "isSpecial": true 162 "isSpecial": true, 163 "time": msg.time 151 164 }); 152 165 }, 153 166 "room-message": msg => { … … 154 167 addChatMessage({ 155 168 "from": escapeText(msg.from), 156 169 "text": escapeText(msg.text), 157 " datetime": msg.datetime170 "time": msg.time 158 171 }); 159 172 }, 160 173 "private-message": msg => { … … 162 175 addChatMessage({ 163 176 "from": "(Private) " + escapeText(msg.from), // TODO: placeholder 164 177 "text": escapeText(msg.text.trim()), // some XMPP clients send trailing whitespace 165 " datetime": msg.datetime178 "time": msg.time 166 179 }); 167 180 } 168 181 }, … … 663 676 "text": sprintf( 664 677 translate("This game's address '%(ip)s' does not appear to be valid."), 665 678 { "ip": game.ip } 666 ) 679 ), 680 "time": Date.now() / 1000 667 681 }); 668 682 return; 669 683 } … … 774 788 default: 775 789 addChatMessage({ 776 790 "from": "system", 777 "text": sprintf(translate("We're sorry, the '%(cmd)s' command is not supported."), { "cmd": cmd }) 791 "text": sprintf(translate("We're sorry, the '%(cmd)s' command is not supported."), { "cmd": cmd }), 792 "time": Date.now() / 1000 778 793 }); 779 794 } 780 795 return true; … … 796 811 if (g_Username != msg.from) 797 812 msg.text = msg.text.replace(g_Username, colorPlayerName(g_Username)); 798 813 799 // Run spam test if it's not a historical message 800 if (!msg.datetime) 801 { 802 updateSpamMonitor(msg.from); 803 if (isSpam(msg.text, msg.from)) 804 return; 805 } 814 updateSpamMonitor(msg); 815 816 if (isSpam(msg.text, msg.from)) 817 return; 806 818 } 807 819 808 820 var formatted = ircFormat(msg); … … 884 896 if (!g_ShowTimestamp) 885 897 return formattedMessage; 886 898 887 var time; 888 if (msg.datetime) 889 { 890 let dTime = msg.datetime.split("T"); 891 let parserDate = dTime[0].split("-"); 892 let parserTime = dTime[1].split(":"); 893 // See http://xmpp.org/extensions/xep-0082.html#sect-idp285136 for format of datetime 894 // Date takes Year, Month, Day, Hour, Minute, Second 895 time = new Date(Date.UTC(parserDate[0], parserDate[1], parserDate[2], parserTime[0], parserTime[1], parserTime[2].split("Z")[0])); 896 } 897 else 898 time = new Date(Date.now()); 899 // Convert from UTC to localtime 900 var time = msg.time - new Date().getTimezoneOffset() * 60; 899 901 900 902 // Translation: Time as shown in the multiplayer lobby (when you enable it in the options page). 901 903 // For a list of symbols that you can use, see: 902 904 // https://sites.google.com/site/icuprojectuserguide/formatparse/datetime?pli=1#TOC-Date-Field-Symbol-Table 903 var timeString = Engine.FormatMillisecondsIntoDateString(time .getTime(), translate("HH:mm"));905 var timeString = Engine.FormatMillisecondsIntoDateString(time * 1000, translate("HH:mm")); 904 906 905 907 // Translation: Time prefix as shown in the multiplayer lobby (when you enable it in the options page). 906 908 var timePrefixString = '[font="' + g_SenderFont + '"]' + sprintf(translate("\\[%(time)s]"), { "time": timeString }) + '[/font]'; … … 912 914 /** 913 915 * Update the spam monitor. 914 916 * 915 * @param { string} from - User to update.917 * @param {Object} msg - Message containing user to update. 916 918 */ 917 function updateSpamMonitor( from)919 function updateSpamMonitor(msg) 918 920 { 919 if (g_SpamMonitor[from]) 920 ++g_SpamMonitor[from].count; 921 // Ignore historical messages 922 if (msg.time < Date.now() / 1000 - g_SpamBlockDuration) 923 return; 924 925 if (g_SpamMonitor[msg.from]) 926 ++g_SpamMonitor[msg.from].count; 921 927 else 922 g_SpamMonitor[ from] = {928 g_SpamMonitor[msg.from] = { 923 929 "count": 1, 924 930 "lastSend": Math.floor(Date.now() / 1000), 925 931 "lastBlock": 0 … … 961 967 g_SpamMonitor[from].lastBlock = time; 962 968 963 969 if (from == g_Username) 964 addChatMessage({ "from": "system", "text": translate("Please do not spam. You have been blocked for thirty seconds.") }); 970 addChatMessage({ 971 "from": "system", 972 "text": translate("Please do not spam. You have been blocked for thirty seconds."), 973 "time": Date.now() / 1000 974 }); 965 975 966 976 return true; 967 977 } -
source/lobby/XmppClient.cpp
19 19 #include "XmppClient.h" 20 20 #include "StanzaExtensions.h" 21 21 22 #include "glooxwrapper/glooxwrapper.h"23 22 #include "i18n/L10n.h" 23 24 #if OS_WIN 25 #include "lib/sysdep/os/win/wposix/wtime.h" 26 #endif 24 27 #include "lib/utf8.h" 28 25 29 #include "ps/CLogger.h" 26 30 #include "ps/ConfigDB.h" 27 31 #include "ps/Pyrogenesis.h" 32 28 33 #include "scriptinterface/ScriptInterface.h" 29 34 30 35 //debug … … 592 597 scriptInterface.SetProperty(ret, "level", message.level); 593 598 if (!message.data.empty()) 594 599 scriptInterface.SetProperty(ret, "data", message.data); 595 if (!message.datetime.empty()) 596 scriptInterface.SetProperty(ret, "datetime", message.datetime); 600 scriptInterface.SetProperty(ret, "time", message.time); 597 601 598 602 m_GuiMessageQueue.pop_front(); 599 603 } … … 655 659 message.level = L"room-message"; 656 660 message.from = wstring_from_utf8(msg.from().resource().to_string()); 657 661 message.text = wstring_from_utf8(msg.body().to_string()); 658 if (msg.when()) 659 // See http://xmpp.org/extensions/xep-0082.html#sect-idp285136 for format 660 message.datetime = msg.when()->stamp().to_string(); 662 message.time = ComputeTimestamp(msg); 661 663 PushGuiMessage(message); 662 664 } 663 665 … … 674 676 message.level = L"private-message"; 675 677 message.from = wstring_from_utf8(msg.from().username().to_string()); 676 678 message.text = wstring_from_utf8(msg.body().to_string()); 677 if (msg.when()) 678 //See http://xmpp.org/extensions/xep-0082.html#sect-idp285136 for format 679 message.datetime = msg.when()->stamp().to_string(); 679 message.time = ComputeTimestamp(msg); 680 680 PushGuiMessage(message); 681 681 } 682 682 … … 769 769 message.level = wstring_from_utf8(level); 770 770 message.text = wstring_from_utf8(text); 771 771 message.data = wstring_from_utf8(data); 772 message.time = time(NULL); 772 773 PushGuiMessage(message); 773 774 } 774 775 … … 939 940 *****************************************************/ 940 941 941 942 /** 943 * Compute the POSIX timestamp of a message. Uses message datetime when possible, current time otherwise. 944 * 945 * @param msg The message on which to base the computation 946 * @returns POSIX UTC seconds since Jan. 1st 1970 947 */ 948 u32 XmppClient::ComputeTimestamp(const glooxwrapper::Message& msg) 949 { 950 if (!msg.when()) 951 return 0; 952 953 glooxwrapper::string timestampStr = msg.when()->stamp(); 954 struct tm timestamp = {0}; 955 956 // See http://xmpp.org/extensions/xep-0082.html#sect-idp285136 for format 957 char* res = strptime(timestampStr.c_str(), "%Y-%m-%dT%H:%M:%SZ", ×tamp); 958 if (!res) 959 LOGERROR("Received delayed message with corrupted timestamp %s", timestampStr.to_string()); 960 961 // FIXME this should be looked into during review 962 // make sure no cast problems can arise + 963 // create a real UTC timestamp without that hack 964 return (u32)(mktime(×tamp) - timezone); 965 } 966 967 /** 942 968 * Convert a gloox presence type to string. 943 969 * 944 970 * @param p Presence to be converted -
source/lobby/XmppClient.h
127 127 std::string StanzaErrorToString(gloox::StanzaError err) const; 128 128 std::string ConnectionErrorToString(gloox::ConnectionError err) const; 129 129 std::string RegistrationResultToString(gloox::RegistrationResult res) const; 130 u32 ComputeTimestamp(const glooxwrapper::Message& msg); 130 131 131 132 public: 132 133 /* Messages */ … … 138 139 std::wstring data; 139 140 std::wstring from; 140 141 std::wstring message; 141 std::string datetime;142 u32 time; // UTC timestamp in seconds 142 143 }; 143 144 void GuiPollMessage(ScriptInterface& scriptInterface, JS::MutableHandleValue ret); 144 145 void SendMUCMessage(const std::string& message);