public static IObservable <int> CreateCachingObservable() //singleton reference
        {
            var tradeListener = new TradeListener();              //singleton reference

            //We use .Publish() to convert our subject into a connectable observable.
            //We use .RefCount() to automatically call .OnCompleted() to signal a sequence end.
            var feed = tradeListener.DataFeed;

            //create an observable that is a subscription to our listener's observable
            var r = Observable
                    .Create <int>(observer =>
            {
                //when our observable is subscribed to, we start the listener and
                //relay the listener to our sequence.
                tradeListener.Start();

                var s = feed.Subscribe(observer);

                return(s);
            })
                    .Finally(() =>
            {
                //stop once we receive end of the signal
                tradeListener.Stop();
                //stop would dispose any resources as needed
            })
                    .Replay(1).RefCount()
            ;

            //TODO: what happens when if need to dispose TradeListener? (then dispose underlying on stop(), alternatively ? how do we guarantee that tradeListener eventually gets garbage collected?)
            return(r);
        }
예제 #2
0
 public void SubscribeToTradeUpdates(TradeListener tradeListener)
 {
     _tradeSubscription = new Subscription("DISTINCT",
                                           new[] { "TRADE:" + _accountId },
                                           new[] { "CONFIRMS", "OPU", "WOU" });
     _tradeSubscription.addListener(tradeListener);
     _lsClient.subscribe(_tradeSubscription);
 }
예제 #3
0
 void Start()
 {
     openObjects   = new List <GameObject>();
     gameManager   = GameObject.FindGameObjectWithTag("GameManager").GetComponent <GameManager>();
     raiding       = gameManager.GetComponent <Raiding>();
     invading      = gameManager.GetComponent <Invading>();
     tradeListener = tradeObject.GetComponentInChildren <TradeListener>();
 }
예제 #4
0
파일: Core.cs 프로젝트: zilveer/Exchange-7
        public void Start(QueueConfig consumerQueuConfig, QueueConfig producerQueueConfig, string filePath, ITimeProvider timeProvider, int quoteCurrencyDecimalPlances, int stepSize)
        {
            _outboundChannel = Channel.CreateBounded <byte[]>(new BoundedChannelOptions(100000)
            {
                FullMode = BoundedChannelFullMode.Wait, SingleReader = true, SingleWriter = true, AllowSynchronousContinuations = false
            });
            _outboundChannelReader  = _outboundChannel.Reader;
            _outboundChannelWritter = _outboundChannel.Writer;

            var tradeListner = new TradeListener(_outboundChannelWritter, timeProvider);

            _matchingEngine = new MatchingEngine(quoteCurrencyDecimalPlances, stepSize, tradeListner, new TimeProvider());

            _inboundChannel = Channel.CreateBounded <Message>(new BoundedChannelOptions(100000)
            {
                FullMode = BoundedChannelFullMode.Wait, SingleReader = true, SingleWriter = true, AllowSynchronousContinuations = false
            });
            _inboundChannelReader  = _inboundChannel.Reader;
            _inboundChannelWritter = _inboundChannel.Writer;

            _outboundQueueChannel = Channel.CreateBounded <byte[]>(new BoundedChannelOptions(100000)
            {
                FullMode = BoundedChannelFullMode.Wait, SingleReader = true, SingleWriter = true, AllowSynchronousContinuations = false
            });
            _outboundQueueChannelReader  = _outboundQueueChannel.Reader;
            _outboundQueueChannelWritter = _outboundQueueChannel.Writer;

            _outboundFileChannel = Channel.CreateBounded <byte[]>(new BoundedChannelOptions(100000)
            {
                FullMode = BoundedChannelFullMode.Wait, SingleReader = true, SingleWriter = true, AllowSynchronousContinuations = false
            });
            _outboundFileChannelReader  = _outboundFileChannel.Reader;
            _outboundFileChannelWritter = _outboundFileChannel.Writer;

            _tradeLogger   = new TradeLogger(filePath);
            _queueProducer = new QueueProducer(producerQueueConfig.ExchangeName, producerQueueConfig.ExchangeType, producerQueueConfig.QueueName, producerQueueConfig.RoutingKey, producerQueueConfig.HostName, producerQueueConfig.Vhost, producerQueueConfig.User, producerQueueConfig.Password);
            _queueConsumer = new QueueConsumer(consumerQueuConfig.ExchangeName, consumerQueuConfig.ExchangeType, consumerQueuConfig.QueueName, consumerQueuConfig.RoutingKey, consumerQueuConfig.HostName, consumerQueuConfig.Vhost, consumerQueuConfig.User, consumerQueuConfig.Password);

            _inboundQueueProcessor         = Task.Factory.StartNew(QueueConsumer);
            _inboundChannelProcessor       = Task.Factory.StartNew(async() => await InboundMessageProcessor());
            _outboundChannelProcessor      = Task.Factory.StartNew(async() => await OutboundMessageProcessor());
            _outboundQueueChannelProcessor = Task.Factory.StartNew(async() => await OutboundQueueMessageProcessor());
            _outboundFileChannelProcessor  = Task.Factory.StartNew(async() => await OutboundFileMessageProcessor());
        }
예제 #5
0
파일: Trade.cs 프로젝트: Yulli/SteamBot
        public Trade(SteamID me, SteamID other, string sessionId, string token, string apiKey, Bot bot, TradeListener listener = null/*, int maxtradetime = 180, int maxactiongap = 30*/)
        {
            MeSID = me;
            OtherSID = other;

            this.sessionId = sessionId;
            steamLogin = token;
            this.apiKey = apiKey;
            //this.MaximumTradeTime = maxtradetime <= 15 ? 15 : maxtradetime;             // Set a minimium time of 15 seconds
            //this.MaximumActionGap = maxactiongap <= 15 ? 15 : maxactiongap;             // Again, minimium time of 15 seconds
            AddListener (listener);

            baseTradeURL = String.Format (SteamTradeUrl, OtherSID.ConvertToUInt64 ());

            // try to poll for the first time
            try
            {
                Poll ();
            }
            catch (Exception)
            {
                bot.log.Error ("[TRADE] Failed To Connect to Steam!");
                //PrintConsole ("Failed to connect to Steam!", ConsoleColor.Red);

                if (OnError != null)
                    OnError("There was a problem connecting to Steam Trading.");
            }

            try
            {
                // fetch the other player's inventory
                OtherItems = GetInventory (OtherSID);
                if (OtherItems == null || OtherItems.success != "true")
                {
                    throw new Exception ("Could not fetch other player's inventory via Trading!");
                }

                // fetch our inventory
                MyItems = GetInventory (MeSID);
                if (MyItems == null || MyItems.success != "true")
                {
                    throw new Exception ("Could not fetch own inventory via Trading!");
                }

                // fetch other player's inventory from the Steam API.
                OtherInventory = Inventory.FetchInventory(OtherSID.ConvertToUInt64(), apiKey);
                if (OtherInventory == null)
                {
                    throw new Exception ("Could not fetch other player's inventory via Steam API!");
                }

                // fetch our inventory from the Steam API.
                MyInventory = Inventory.FetchInventory(MeSID.ConvertToUInt64(), apiKey);
                if (MyInventory == null)
                {
                    throw new Exception ("Could not fetch own inventory via Steam API!");
                }

                // check that the schema was already successfully fetched
                if (CurrentSchema == null)
                {
                    throw new Exception ("It seems the item schema was not fetched correctly!");
                }

                if (OnAfterInit != null)
                    OnAfterInit();

            }
            catch (Exception e)
            {
                if (OnError != null)
                    OnError ("I'm having a problem getting one of our backpacks. The Steam Community might be down. Ensure your backpack isn't private.");
                //Console.WriteLine (e);
                bot.log.Error (e.ToString ());
            }
        }
예제 #6
0
파일: Trade.cs 프로젝트: Yulli/SteamBot
 public void AddListener(TradeListener listener)
 {
     OnError += listener.OnError;
     OnTimeout += listener.OnTimeout;
     OnAfterInit += listener.OnAfterInit;
     OnUserAddItem += listener.OnUserAddItem;
     OnUserRemoveItem += listener.OnUserRemoveItem;
     OnMessage += listener.OnMessage;
     OnUserSetReady += listener.OnUserSetReadyState;
     OnUserAccept += listener.OnUserAccept;
     listener.trade = this;
 }
예제 #7
0
    public void onClick(string k)
    {
        GameManager.Kingdom kingdom = (GameManager.Kingdom)Enum.Parse(typeof(GameManager.Kingdom), k);
        gameManager.setAtWar(kingdom);

        int chance = -10;

        gameManager.invadePause = true;

        float modifier = gameManager.soldierCount;

        modifier = (gameManager.soldierCount * gameManager.soldierStrength);

        chance += (int)((modifier / 100) * invadeModifier);
        int roll = UnityEngine.Random.Range(1, 100);

        invade.SetActive(false);

        if (chance >= roll)
        {
            gameManager.puppetStates++;

            if (gameManager.puppetStates != 4)
            {
                invadeSuccess.SetActive(true);
            }
            gameManager.conqueredStatus[kingdom] = true;
            gameManager.warStatus[kingdom]       = false;

            textS.text = "Your forces have stormed the keep of " + kingdom.ToString() + ", and have taken the land. Your subjects congratulate you on your victory. " +
                         "There is a cost in victory though, as you have lost good men to claim these lands.";

            bool war = false;

            foreach (GameManager.Kingdom kin in gameManager.warStatus.Keys)
            {
                if (gameManager.warStatus[kin])
                {
                    war = true;
                }
            }

            if (!war)
            {
                gameManager.isAtWar = false;
            }

            float loss = ((gameManager.soldierCount / 100) * UnityEngine.Random.Range(30, 55));

            if (gameManager.ownsGarrison || gameManager.ownsBarracks)
            {
                loss -= (loss * ((gameManager.soldierStrength - 1)));
            }

            gameManager.soldierCount -= loss;
        }
        else
        {
            invadeFail.SetActive(true);
            textF.text = "Your forces were unable to overcome " + kingdom.ToString() + " 's defenses. You have lost a large majority of soldiers, and your people's happiness has dropped.";
            gameManager.soldierCount = ((gameManager.soldierCount / 100) * UnityEngine.Random.Range(15, 25)); // keep 15 to 25%
            gameManager.decreaseRelations(kingdom, 100);
        }

        if (tradeListener == null)
        {
            tradeListener = GameObject.FindGameObjectWithTag("Canvas").transform.Find("Trade").GetComponentInChildren <TradeListener>();
        }

        tradeListener.updateRelationsText(kingdom);
        gameManager.updateTradeStatus(kingdom);

        if (gameManager.puppetStates == 4)
        {
            gameManager.won = true;
            win.SetActive(true);
            actionMenu.setTask(true);
            actionMenu.openObjects.Add(win);
        }
    }
예제 #8
0
 void Start()
 {
     gameManager   = GetComponent <GameManager>();
     actionMenu    = GameObject.FindGameObjectWithTag("Player").GetComponent <ActionMenu>();
     tradeListener = GameObject.FindGameObjectWithTag("Canvas").transform.Find("Trade").GetComponentInChildren <TradeListener>();
 }
예제 #9
0
파일: Trade.cs 프로젝트: Top-Cat/SteamBot
		public Trade (SteamID me, SteamID other, string sessionId, string token, string apiKey, TradeListener listener = null) {
			meSID = me;
			otherSID = other;

			trades = new HashSet<ulong>[] { MyTrade, OtherTrade };
			Otrades = new HashSet<ulong>[] { OMyTrade, OOtherTrade };

			this.sessionId = sessionId;
			steamLogin = token;
			this.apiKey = apiKey;

			AddListener (listener);

			baseTradeURL = String.Format (SteamTradeUrl, otherSID.ConvertToUInt64 ());

			// try to poll for the first time
			try {
				Poll ();
			} catch (Exception) {
				PrintConsole ("Failed to connect to Steam!", ConsoleColor.Red);

				if (OnError != null)
					OnError(0);
			}

			try {
				SendMessage("Fetching data");

				// fetch the other player's inventory
				OtherItems = GetInventory (otherSID);
				if (OtherItems == null || OtherItems.success != "true") {
					throw new Exception ("Could not fetch other player's inventory via Trading!");
				}
				
				// fetch our inventory
				MyItems = GetInventory (meSID);
				if (MyItems == null || MyItems.success != "true") {
					throw new Exception ("Could not fetch own inventory via Trading!");
				}
				
				// fetch other player's inventory from the Steam API.
				OtherInventory = Inventory.FetchInventory(otherSID.ConvertToUInt64(), apiKey);
				if (OtherInventory == null) {
					throw new Exception ("Could not fetch other player's inventory via Steam API!");
				}
				
				// fetch our inventory from the Steam API.
				MyInventory = Inventory.FetchInventory(meSID.ConvertToUInt64(), apiKey);
				if (MyInventory == null) {
					throw new Exception ("Could not fetch own inventory via Steam API!");
				}

				SendMessage("Ready");
				inventories = new Inventory[] { MyInventory, OtherInventory };

				if (OnAfterInit != null)
					OnAfterInit();

			} catch (Exception e) {
				if (OnError != null)
					OnError(3);
				Console.WriteLine (e);
				throw e;
			}

		}