Thread: chat messages
View Single Post
  #9  
Old 03-12-2012, 08:35 PM
Smokeynz Smokeynz is offline
Approved Member
 
Join Date: Apr 2011
Posts: 106
Default

@ kodiak, been noticing that with lists they tend to grow ever larger, in this case Consigness grows larger every time a sendChatMessage is called. A player name is added many times, old players who have left stay in the list.

So added in "Consignees.Clear();" , do you think this effective addition, and in the right place?


Code:
private void sendChatMessage(int army, string msg, params object[] args)
    {
        Consignees.Clear();
        List<Player> Consignees = new List<Player>();
        if (GamePlay.gpPlayer() != null)
            Consignees.Add(GamePlay.gpPlayer());
        if (GamePlay.gpRemotePlayers() != null)
            Consignees.AddRange(GamePlay.gpRemotePlayers());

        if (army == -1)
            GamePlay.gpLogServer(null, msg, args);
        else if (Consignees.Exists(item => item.Army() == army))
            GamePlay.gpLogServer(Consignees.FindAll(item => item.Army() == army).ToArray(), msg, args);
    }
Reply With Quote