Skip to content

Commit

Permalink
Minor optimizations to MSG_QUERY_NEXT_MAIL_TIME handler.
Browse files Browse the repository at this point in the history
* Do not search for more unread mails when already found 2.
* Do not call time(NULL) every iteration.

Signed-off-by: hunuza <[email protected]>
  • Loading branch information
hunuza committed Jul 6, 2009
1 parent b3abb80 commit 9f433f3
Showing 1 changed file with 26 additions and 24 deletions.
50 changes: 26 additions & 24 deletions src/game/Mail.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -762,38 +762,40 @@ void WorldSession::HandleQueryNextMailTime(WorldPacket & /*recv_data*/ )
{
data << (uint32) 0; // float
data << (uint32) 0; // count

uint32 count = 0;
time_t now = time(NULL);
for(PlayerMails::iterator itr = _player->GetmailBegin(); itr != _player->GetmailEnd(); ++itr)
{
Mail *m = (*itr);
// not checked yet, already must be delivered
if((m->checked & MAIL_CHECK_MASK_READ)==0 && (m->deliver_time <= time(NULL)))
{
++count;
// must be not checked yet
if(m->checked & MAIL_CHECK_MASK_RED)
continue;

if(count > 2)
{
count = 2;
break;
}
// and already delivered
if(now < m->deliver_time)
continue;

data << (uint64) m->sender; // sender guid
data << (uint64) m->sender; // sender guid

switch(m->messageType)
{
case MAIL_AUCTION:
data << (uint32) 2;
data << (uint32) 2;
data << (uint32) m->stationery;
break;
default:
data << (uint32) 0;
data << (uint32) 0;
data << (uint32) m->stationery;
break;
}
data << (uint32) 0xC6000000; // float unk, time or something
switch(m->messageType)
{
case MAIL_AUCTION:
data << (uint32) 2;
data << (uint32) 2;
data << (uint32) m->stationery;
break;
default:
data << (uint32) 0;
data << (uint32) 0;
data << (uint32) m->stationery;
break;
}
data << (uint32) 0xC6000000; // float unk, time or something

++count;
if(count == 2) // do not display more than 2 mails
break;
}
data.put<uint32>(4, count);
}
Expand Down

0 comments on commit 9f433f3

Please sign in to comment.