TsgcWebSocketFirewallEvents › OnResolveCountry

OnResolveCountry Event

Fires during GeoIP evaluation so the application can supply a custom country code for an IP.

Syntax

property OnResolveCountry: TsgcFirewallOnResolveCountry;
// TsgcFirewallOnResolveCountry = procedure(Sender: TObject; const aIP: string; var aCountryCode: string) of object

Default Value

Remarks

OnResolveCountry is raised by the GeoIP module when it needs to map aIP to a country. The built-in CSV database (loaded via LoadGeoIPDatabase) is consulted first; the event is invoked so your application can override or supplement the result with a lookup against a different source (third-party MaxMind DB, a REST service, an internal cache, etc.). Assign the two-letter ISO 3166-1 alpha-2 code (for example "US", "DE", "CN") to the aCountryCode var parameter. Return an empty string to leave the IP unclassified (GeoIP allow/block rules will then treat it as unknown). The handler runs in the server I/O thread; it is invoked on every connection when GeoIP is enabled, so cache lookups aggressively and avoid blocking network calls.

Example

procedure TForm1.sgcWebSocketFirewall1ResolveCountry(Sender: TObject;
  const aIP: string; var aCountryCode: string);
begin
  // quick in-memory cache
  aCountryCode := FCountryCache.Values[aIP];
  if aCountryCode <> '' then
    Exit;

  // fall back to your own GeoIP provider
  aCountryCode := MyGeoIPProvider.Lookup(aIP);
  if aCountryCode <> '' then
    FCountryCache.Values[aIP] := aCountryCode;
end;

Back to Events