Пример #1
0
 internal void AddNewTrader(TraderHandler newTrader)
 {
     lock (traders)
     {
         lock (theMarket)
         {
             logger.LogConnect(newTrader.GetId());
             traders.Add(newTrader.GetId(), newTrader);
             CheckRemainingTraders();
             UpdateMarketInfo();
         }
     }
 }
Пример #2
0
 internal void RemoveTrader(TraderHandler yeetThisTrader)
 {
     lock (traders)
     {
         lock (theMarket)
         {
             //log that the trader has disconnected
             logger.LogDisconnect(yeetThisTrader.GetId());
             traders.Remove(yeetThisTrader.GetId());
             CheckRemainingTraders();
             UpdateMarketInfo();
         }
     }
 }
Пример #3
0
        internal GiveStockResponse AttemptToGiveStock(TraderHandler sender, string recipient)
        {
            GiveStockResponse response;
            string            sendID = sender.GetId();

            lock (traders)
            {
                lock (theMarket)
                {
                    if (sendID.Equals(stockholder))
                    {
                        if (traders.ContainsKey(recipient))
                        {
                            if (sendID.Equals(recipient))
                            {
                                //if sender sent it to themselves, don't bother updating anything because they were being greedy.
                                response = new GiveStockResponse(true, theMarket.CopyThis(), GiveStockResponse.WOW_GREEDY);
                                logger.LogTrade(sendID, recipient);
                            }
                            else
                            {
                                //if sender sent it to somebody else, it's time to actually update the state of the market
                                stockholder = recipient;
                                theMarket.UpdateStockholder(stockholder);
                                //also let the user know that they successfully managed to trade their item
                                response = new GiveStockResponse(true, theMarket.CopyThis(), GiveStockResponse.GAVE_STOCK);
                                logger.LogTrade(sendID, recipient);
                                logger.LogMarketInfo(theMarket);
                            }
                        }
                        else
                        {
                            //cant give stocks to people what don't exist
                            response = new GiveStockResponse(false, theMarket.CopyThis(), GiveStockResponse.RECIPIENT_DOESNT_EXIST);
                        }
                    }
                    else
                    {
                        //can't send stonks you don't own
                        response = new GiveStockResponse(false, theMarket.CopyThis(), GiveStockResponse.NOT_STOCK_OWNER);
                    }
                }
            }
            return(response);
        }