1
0
Fork 0

(svn r21512) -Change/Feature: make the delay of the chat messages timing out unrelated to the number of passed game days, i.e. don't stop aging chat messages when the server is paused

release/1.1
rubidium 2010-12-14 14:57:51 +00:00
parent 4045429df6
commit e68efb9e71
5 changed files with 17 additions and 11 deletions

View File

@ -249,7 +249,6 @@ static void OnNewMonth()
static void OnNewDay()
{
#ifdef ENABLE_NETWORK
NetworkChatMessageDailyLoop();
if (_network_server) NetworkServerDailyLoop();
#endif /* ENABLE_NETWORK */

View File

@ -165,7 +165,7 @@ bool NetworkCompanyIsPassworded(CompanyID company_id)
* If 'self_send' is true, this is the client who is sending the message */
void NetworkTextMessage(NetworkAction action, ConsoleColour colour, bool self_send, const char *name, const char *str, int64 data)
{
const int duration = 10; // Game days the messages stay visible
const int duration = 20; // Seconds the messages stay visible
StringID strid;
switch (action) {

View File

@ -40,7 +40,7 @@ static const uint NETWORK_CHAT_LINE_SPACING = 3;
struct ChatMessage {
char message[DRAW_STRING_BUFFER];
TextColour colour;
Date end_date;
uint32 remove_time;
};
/* used for chat window */
@ -68,10 +68,10 @@ static inline uint GetChatMessageCount()
/**
* Add a text message to the 'chat window' to be shown
* @param colour The colour this message is to be shown in
* @param duration The duration of the chat message in game-days
* @param duration The duration of the chat message in seconds
* @param message message itself in printf() style
*/
void CDECL NetworkAddChatMessage(TextColour colour, uint8 duration, const char *message, ...)
void CDECL NetworkAddChatMessage(TextColour colour, uint duration, const char *message, ...)
{
char buf[DRAW_STRING_BUFFER];
const char *bufp;
@ -104,7 +104,7 @@ void CDECL NetworkAddChatMessage(TextColour colour, uint8 duration, const char *
/* The default colour for a message is company colour. Replace this with
* white for any additional lines */
cmsg->colour = (bufp == buf && (colour & IS_PALETTE_COLOUR)) ? colour : TC_WHITE;
cmsg->end_date = _date + duration;
cmsg->remove_time = _realtime_tick + duration * 1000;
bufp += strlen(bufp) + 1; // jump to 'next line' in the formatted string
}
@ -181,15 +181,15 @@ void NetworkUndrawChatMessage()
}
}
/** Check if a message is expired every day */
void NetworkChatMessageDailyLoop()
/** Check if a message is expired. */
void NetworkChatMessageLoop()
{
for (uint i = 0; i < MAX_CHAT_MESSAGES; i++) {
ChatMessage *cmsg = &_chatmsg_list[i];
if (cmsg->message[0] == '\0') continue;
/* Message has expired, remove from the list */
if (cmsg->end_date < _date) {
if (cmsg->remove_time < _realtime_tick) {
/* Move the remaining messages over the current message */
if (i != MAX_CHAT_MESSAGES - 1) memmove(cmsg, cmsg + 1, sizeof(*cmsg) * (MAX_CHAT_MESSAGES - i - 1));

View File

@ -79,9 +79,9 @@ void NetworkServerKickClient(ClientID client_id);
uint NetworkServerKickOrBanIP(const char *ip, bool ban);
void NetworkInitChatMessage();
void CDECL NetworkAddChatMessage(TextColour colour, uint8 duration, const char *message, ...) WARN_FORMAT(3, 4);
void CDECL NetworkAddChatMessage(TextColour colour, uint duration, const char *message, ...) WARN_FORMAT(3, 4);
void NetworkUndrawChatMessage();
void NetworkChatMessageDailyLoop();
void NetworkChatMessageLoop();
void NetworkAfterNewGRFScan();

View File

@ -1359,6 +1359,13 @@ void GameLoop()
/* Singleplayer */
StateGameLoop();
}
/* Check chat messages roughly once a second. */
static uint check_message = 0;
if (++check_message > 1000 / MILLISECONDS_PER_TICK) {
check_message = 0;
NetworkChatMessageLoop();
}
#else
StateGameLoop();
#endif /* ENABLE_NETWORK */