Beispiel #1
0
        void ProcessEvent(int key, ExpandoObject obj)
        {
            //Console.WriteLine("Key " + key + " NextLogPos: " + (NextLogPos-1));

            if (key < Interlocked.Read(ref NextLogPos) - 1)
            {
                //Console.WriteLine("Ignoring...");
                return;
            }

            var evt = obj as IDictionary <string, object>;

            if (!evt.ContainsKey("action"))
            {
                return;
            }

            int action;

            if (!Int32.TryParse(evt["action"] as string, out action))
            {
                return;
            }

            string steamid = String.Empty;

            if (evt.ContainsKey("steamid"))
            {
                steamid = evt["steamid"] as string;
            }

            var steamId = new SteamID();

            steamId.SetFromUInt64(UInt64.Parse(steamid));

            if (steamId == OwnSteamId)
            {
                return;
            }

            var appid = evt["appid"] as int?;

            var tradeEvent = new TradeEvent();

            tradeEvent.sender = steamId;

            bool enqueue     = false;
            bool loadForeign = false;

            switch (action)
            {
            case 0: // Item added/remove
            case 1:
            {
                var item = new TradeItem();
                tradeEvent.type = (action == 0) ?
                                  ETradeEventType.ItemAdded : ETradeEventType.ItemRemoved;
                item.appid = appid.Value;
                int.TryParse(evt["assetid"] as string, out item.assetid);
                int.TryParse(evt["contextid"] as string, out item.contextid);
                tradeEvent.item = item;
                if (ForeignInventory == null)
                {
                    LoadForeignInventory(steamId, item.appid, item.contextid);
                    loadForeign = true;
                }
                enqueue = true;
                break;
            }

            case 2: // Ready/unready
            case 3:
            {
                tradeEvent.type = (action == 2) ?
                                  ETradeEventType.Ready : ETradeEventType.Unready;
                var timestamp = evt["timestamp"] as int?;
                tradeEvent.timestamp = (uint)timestamp.Value;
                enqueue = true;
                break;
            }

            case 4: // Confirmed
            {
                tradeEvent.type = ETradeEventType.Confirmed;
                var timestamp = evt["timestamp"] as int?;
                tradeEvent.timestamp = (uint)timestamp.Value;
                enqueue = true;
                break;
            }

            case 7: // Chat message
            {
                string text = String.Empty;
                if (evt.ContainsKey("text"))
                {
                    text = evt["text"] as string;
                }
                tradeEvent.type    = ETradeEventType.Message;
                tradeEvent.message = text;
                enqueue            = true;
                break;
            }

            default:
                Console.WriteLine("Invalid action: " + action);
                break;
            }

            if (loadForeign)
            {
                PendingEvents.Enqueue(tradeEvent);
            }
            else if (enqueue)
            {
                Events.Enqueue(tradeEvent);
            }

            ResetTimer();
        }
Beispiel #2
0
        void ProcessEvent(int key, ExpandoObject obj)
        {
            //Console.WriteLine("Key " + key + " NextLogPos: " + (NextLogPos-1));

            if (key < Interlocked.Read(ref NextLogPos) - 1)
            {
                //Console.WriteLine("Ignoring...");
                return;
            }

            var evt = obj as IDictionary<string, object>;

            if (!evt.ContainsKey("action"))
                return;

            int action;
            if (!Int32.TryParse(evt["action"] as string, out action))
                return;

            string steamid = String.Empty;
            if (evt.ContainsKey("steamid"))
                steamid = evt["steamid"] as string;

            var steamId = new SteamID();
            steamId.SetFromUInt64(UInt64.Parse(steamid));

            if (steamId == OwnSteamId)
                return;

            var appid = evt["appid"] as int?;

            var tradeEvent = new TradeEvent();
            tradeEvent.sender = steamId;

            bool enqueue = false;
            bool loadForeign = false;

            switch (action)
            {
            case 0: // Item added/remove
            case 1:
            {
                var item = new TradeItem();
                tradeEvent.type = (action == 0) ?
                    ETradeEventType.ItemAdded : ETradeEventType.ItemRemoved;
                item.appid = appid.Value;
                int.TryParse(evt["assetid"] as string, out item.assetid);
                int.TryParse(evt["contextid"] as string, out item.contextid);
                tradeEvent.item = item;
                if (ForeignInventory == null)
                {
                    LoadForeignInventory(steamId, item.appid, item.contextid);
                    loadForeign = true;
                }
                enqueue = true;
                break;
            }
            case 2: // Ready/unready
            case 3:
            {
                tradeEvent.type = (action == 2) ?
                    ETradeEventType.Ready : ETradeEventType.Unready;
                var timestamp = evt["timestamp"] as int?;
                tradeEvent.timestamp = (uint)timestamp.Value;
                enqueue = true;
                break;
            }
            case 4: // Confirmed
            {
                tradeEvent.type = ETradeEventType.Confirmed;
                var timestamp = evt["timestamp"] as int?;
                tradeEvent.timestamp = (uint)timestamp.Value;
                enqueue = true;
                break;
            }
            case 7: // Chat message
            {
                string text = String.Empty;
                if (evt.ContainsKey("text"))
                    text = evt["text"] as string;
                tradeEvent.type = ETradeEventType.Message;
                tradeEvent.message = text;
                enqueue = true;
                break;
            }
            default:
                Console.WriteLine("Invalid action: " + action);
                break;
            }

            if (loadForeign)
                PendingEvents.Enqueue(tradeEvent);
            else if (enqueue)
                Events.Enqueue(tradeEvent);

            ResetTimer();
        }
 /// <summary>
 /// Looks up an inventory item given a temporary trade item.
 /// </summary>
 public InventoryItem LookupItem(TradeItem item)
 {
     return Items[item.assetid]; 
 }
Beispiel #4
0
 /// <summary>
 /// Looks up an inventory item given a temporary trade item.
 /// </summary>
 public InventoryItem LookupItem(TradeItem item)
 {
     return(Items[item.assetid]);
 }