wasStitchNET – Blame information for rev 13

Subversion Repositories:
Rev:
Rev Author Line No. Line
13 office 1 ///////////////////////////////////////////////////////////////////////////
2 // Copyright (C) Wizardry and Steamworks 2017 - License: GNU GPLv3 //
3 // Please see: http://www.gnu.org/licenses/gpl.html for legal details, //
4 // rights of fair usage, the disclaimer and warranty conditions. //
5 ///////////////////////////////////////////////////////////////////////////
6  
7 using System;
8 using System.IO.Compression;
9 using System.Net;
10 using System.Reflection;
11 using MaxMind.GeoIP2;
12 using MaxMind.GeoIP2.Responses;
13  
14 namespace wasStitchNET.GeoIP
15 {
16 public static class Extensions
17 {
18 public static CityResponse GeoIPGetCity(this IPAddress address)
19 {
20 // Open the MaxMind GeoIP database.
21 using (var gZipStream =
22 new GZipStream(
23 Assembly.GetExecutingAssembly()
24 .GetManifestResourceStream($"wasStitchNET.GeoIP.MaxMind.{STITCH_CONSTANTS.GEOIP_CITY_DATABASE}"),
25 CompressionMode.Decompress))
26 {
27 // Resolve the IP address to a city response.
28 using (var reader = new DatabaseReader(gZipStream))
29 {
30 CityResponse response;
31 if (reader.TryCity(address, out response))
32 return response;
33 }
34 }
35  
36 return null;
37 }
38 }
39 }