| 206 | void Chat_Add(const cc_string* text) { Chat_AddOf(text, MSG_TYPE_NORMAL); } |
| 207 | |
| 208 | void Chat_AddOf(const cc_string* text, int msgType) { |
| 209 | cc_string str; |
| 210 | if (msgType == MSG_TYPE_NORMAL) { |
| 211 | /* Check for chat overflow (see issue #837) */ |
| 212 | /* This happens because Offset/Length are packed into a single 32 bit value, */ |
| 213 | /* with 9 bits used for length. Hence if offset exceeds 2^23 (8388608), it */ |
| 214 | /* overflows and earlier chat messages start wrongly appearing instead */ |
| 215 | if (Chat_Log.totalLength > 8388000) { |
| 216 | ClearChatLogs(); |
| 217 | Chat_AddRaw("&cChat log cleared as it hit 8.3 million character limit"); |
| 218 | } |
| 219 | |
| 220 | /* StringsBuffer_Add will abort game if try to add string > 511 characters */ |
| 221 | str = *text; |
| 222 | str.length = min(str.length, DRAWER2D_MAX_TEXT_LENGTH); |
| 223 | |
| 224 | Chat_GetLogTime(Chat_Log.count) = Game.Time; |
| 225 | AppendChatLog(&str); |
| 226 | StringsBuffer_Add(&Chat_Log, &str); |
| 227 | } else if (msgType >= MSG_TYPE_STATUS_1 && msgType <= MSG_TYPE_STATUS_3) { |
| 228 | /* Status[0] is for texture pack downloading message */ |
| 229 | /* Status[1] is for reduced performance mode message */ |
| 230 | String_Copy(&Chat_Status[2 + (msgType - MSG_TYPE_STATUS_1)], text); |
| 231 | } else if (msgType >= MSG_TYPE_BOTTOMRIGHT_1 && msgType <= MSG_TYPE_BOTTOMRIGHT_3) { |
| 232 | String_Copy(&Chat_BottomRight[msgType - MSG_TYPE_BOTTOMRIGHT_1], text); |
| 233 | } else if (msgType == MSG_TYPE_ANNOUNCEMENT) { |
| 234 | String_Copy(&Chat_Announcement, text); |
| 235 | Chat_AnnouncementLeft = 5.0f; |
| 236 | } else if (msgType == MSG_TYPE_BIGANNOUNCEMENT) { |
| 237 | String_Copy(&Chat_BigAnnouncement, text); |
| 238 | Chat_BigAnnouncementLeft = 5.0f; |
| 239 | } else if (msgType == MSG_TYPE_SMALLANNOUNCEMENT) { |
| 240 | String_Copy(&Chat_SmallAnnouncement, text); |
| 241 | Chat_SmallAnnouncementLeft = 5.0f; |
| 242 | } else if (msgType >= MSG_TYPE_CLIENTSTATUS_1 && msgType <= MSG_TYPE_CLIENTSTATUS_2) { |
| 243 | String_Copy(&Chat_ClientStatus[msgType - MSG_TYPE_CLIENTSTATUS_1], text); |
| 244 | } else if (msgType >= MSG_TYPE_EXTRASTATUS_1 && msgType <= MSG_TYPE_EXTRASTATUS_2) { |
| 245 | String_Copy(&Chat_Status[msgType - MSG_TYPE_EXTRASTATUS_1], text); |
| 246 | } |
| 247 | |
| 248 | Event_RaiseChat(&ChatEvents.ChatReceived, text, msgType); |
| 249 | } |
| 250 | |
| 251 | |
| 252 | /*########################################################################################################################* |
no test coverage detected