コード例 #1
0
ファイル: ItemServer.cs プロジェクト: Teo1904/DiabloInterface
        void HandleClientConnection(NamedPipeServerStream pipe)
        {
            var reader  = new JsonStreamReader(pipe, Encoding.UTF8);
            var request = reader.ReadJson <QueryRequest>();

            QueryResponse response           = new QueryResponse();
            var           equipmentLocations = GetItemLocations(request);

            dataReader.ItemSlotAction(equipmentLocations, (itemReader, item) => {
                ItemResponse data = new ItemResponse();
                data.ItemName     = itemReader.GetFullItemName(item);
                data.Properties   = itemReader.GetMagicalStrings(item);
                response.Items.Add(data);
            });

            response.IsValid = equipmentLocations.Count > 0;
            response.Success = response.Items.Count > 0;
            var writer = new JsonStreamWriter(pipe, Encoding.UTF8);

            writer.WriteJson(response);
            writer.Flush();
        }
コード例 #2
0
ファイル: ItemServer.cs プロジェクト: palmettos/D2ID
        void HandleClientConnection(Object pipeObject)
        {
            try
            {
                NamedPipeServerStream pipe = (NamedPipeServerStream)pipeObject;
                var reader  = new JsonStreamReader(pipe, Encoding.UTF8);
                var request = reader.ReadJson <QueryRequest>();

                QueryResponse response           = new QueryResponse();
                var           equipmentLocations = GetItemLocations(request);

                dataReader.ItemSlotAction(equipmentLocations, (itemReader, item) =>
                {
                    ItemQuality quality = itemReader.GetItemQuality(item);
                    string color        = null;
                    switch (quality)
                    {
                    case ItemQuality.Low:
                    case ItemQuality.Normal:
                    case ItemQuality.Superior:
                        color = "WHITE";
                        break;

                    case ItemQuality.Magic:
                        color = "BLUE";
                        break;

                    case ItemQuality.Rare:
                        color = "YELLOW";
                        break;

                    case ItemQuality.Crafted:
                    case ItemQuality.Tempered:
                        color = "ORANGE";
                        break;

                    case ItemQuality.Unique:
                        color = "GOLD";
                        break;

                    case ItemQuality.Set:
                        color = "GREEN";
                        break;
                    }

                    ItemResponse data = new ItemResponse();
                    data.ItemName     = itemReader.GetFullItemName(item);
                    data.BaseItem     = itemReader.GetGrammaticalName(itemReader.GetItemName(item), out string grammerCase);
                    data.Quality      = color;
                    data.Properties   = itemReader.GetMagicalStrings(item);
                    data.Location     = itemReader.GetItemData(item)?.BodyLoc ?? BodyLocation.None;
                    response.Items.Add(data);
                });

                response.IsValid = equipmentLocations.Count > 0;
                response.Success = response.Items.Count > 0;
                var writer = new JsonStreamWriter(pipe, Encoding.UTF8);
                writer.WriteJson(response);
                writer.Flush();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Logger.Instance.WriteLine("exception caught in HandleClientConnection:");
                Logger.Instance.WriteLine(e.Message);
                return;
            }
        }