Skip to content
This repository has been archived by the owner on Dec 6, 2022. It is now read-only.

Commit

Permalink
Release
Browse files Browse the repository at this point in the history
  • Loading branch information
Freenex1911 committed Feb 25, 2016
1 parent 40351ec commit 109bd2a
Show file tree
Hide file tree
Showing 17 changed files with 5,922 additions and 0 deletions.
80 changes: 80 additions & 0 deletions FeexGeoBlock.cs
@@ -0,0 +1,80 @@
using Rocket.Core.Logging;
using Rocket.Core.Plugins;
using Rocket.Unturned.Permissions;
using SDG.Unturned;
using Steamworks;
using System;

namespace Freenex.FeexGeoBlock
{
public class FeexGeoBlock : RocketPlugin<FeexGeoBlockConfiguration>
{
public static FeexGeoBlock Instance;

protected override void Load()
{
Instance = this;
UnturnedPermissions.OnJoinRequested += UnturnedPermissions_OnJoinRequested;
Logger.Log("Freenex's FeexGeoBlock has been loaded!");
}

protected override void Unload()
{
UnturnedPermissions.OnJoinRequested -= UnturnedPermissions_OnJoinRequested;
Logger.Log("Freenex's FeexGeoBlock has been unloaded!");
}

private void UnturnedPermissions_OnJoinRequested(CSteamID player, ref ESteamRejection? rejectionReason)
{
P2PSessionState_t sessionStateP2P;
SteamGameServerNetworking.GetP2PSessionState(player, out sessionStateP2P);

LookupService playerLookup = new LookupService(".\\Libraries\\GeoIP.dat", LookupService.GEOIP_MEMORY_CACHE);
Country playerCountry = playerLookup.getCountry(Parser.getIPFromUInt32(sessionStateP2P.m_nRemoteIP));

if (playerCountry.getCode() == "--")
{
if (Configuration.Instance.KickOnNoCountry)
{
if (Configuration.Instance.Logging) { Logger.LogWarning("Access denied: " + player + " // Reason: No country."); }
rejectionReason = GetSteamRejection();
}
else
{
if (Configuration.Instance.Logging) { Logger.LogWarning("Access granted: " + player + " // Reason: No country."); }
}
}
else
{
bool grantAccess = false;
for (int i = 0; i < Configuration.Instance.Whitelist.Length; i++)
{
if (Configuration.Instance.Whitelist[i].WhitelistCountry == playerCountry.getCode())
{
grantAccess = true;
}
}

if (!grantAccess)
{
if (Configuration.Instance.Logging) { Logger.LogWarning("Access denied: " + player + " // Reason: Wrong country (" + playerCountry.getCode() + ")."); }
rejectionReason = GetSteamRejection();
}
}

}

public ESteamRejection GetSteamRejection()
{
var RejectionReason = ESteamRejection.WHITELISTED;

try
{
RejectionReason = (ESteamRejection)Enum.Parse(typeof(ESteamRejection), Configuration.Instance.RejectionReason, true);
}
catch { }

return RejectionReason;
}
}
}
103 changes: 103 additions & 0 deletions FeexGeoBlock.csproj
@@ -0,0 +1,103 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{BD060356-E701-4AE7-A892-02E2F887820B}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Freenex.FeexGeoBlock</RootNamespace>
<AssemblyName>FeexGeoBlock</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Assembly-CSharp, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>lib\Assembly-CSharp.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Assembly-CSharp-firstpass, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>lib\Assembly-CSharp-firstpass.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Rocket.API, Version=2.3.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>lib\Rocket.API.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Rocket.Core, Version=2.3.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>lib\Rocket.Core.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Rocket.Unturned, Version=4.9.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>lib\Rocket.Unturned.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
<Reference Include="UnityEngine, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>lib\UnityEngine.dll</HintPath>
<Private>False</Private>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="FeexGeoBlock.cs" />
<Compile Include="FeexGeoBlockConfiguration.cs" />
<Compile Include="GeoIP\Country.cs" />
<Compile Include="GeoIP\DatabaseInfo.cs" />
<Compile Include="GeoIP\Location.cs" />
<Compile Include="GeoIP\LookupService.cs" />
<Compile Include="GeoIP\Region.cs" />
<Compile Include="GeoIP\RegionName.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<Content Include="lib\Assembly-CSharp-firstpass.dll" />
<Content Include="lib\Assembly-CSharp.dll" />
<Content Include="lib\Rocket.API.dll" />
<Content Include="lib\Rocket.Core.dll" />
<Content Include="lib\Rocket.Unturned.dll" />
<Content Include="lib\UnityEngine.dll" />
</ItemGroup>
<ItemGroup>
<None Include="Libraries\GeoIP.dat">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
42 changes: 42 additions & 0 deletions FeexGeoBlockConfiguration.cs
@@ -0,0 +1,42 @@
using Rocket.API;
using System.Xml.Serialization;

namespace Freenex.FeexGeoBlock
{
public sealed class Whitelist
{
[XmlAttribute("CountryCode")]
public string WhitelistCountry;

public Whitelist(string countryCode)
{
WhitelistCountry = countryCode;
}
public Whitelist()
{
WhitelistCountry = string.Empty;
}
}

public class FeexGeoBlockConfiguration : IRocketPluginConfiguration
{
public string RejectionReason;
public bool KickOnNoCountry;
public bool Logging;

[XmlArrayItem("WhitelistCountryCode")]
[XmlArray(ElementName = "Whitelist")]
public Whitelist[] Whitelist;

public void LoadDefaults()
{
RejectionReason = "WHITELISTED";
KickOnNoCountry = true;
Logging = true;

Whitelist = new Whitelist[]{
new Whitelist("DE")
};
}
}
}
56 changes: 56 additions & 0 deletions GeoIP/Country.cs
@@ -0,0 +1,56 @@
/**
* Country.cs
*
* Copyright (C) 2008 MaxMind Inc. All Rights Reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/


using System;
using System.IO;
public class Country {

private String code;
private String name;

/**
* Creates a new Country.
*
* @param code the country code.
* @param name the country name.
*/
public Country(String code, String name) {
this.code = code;
this.name = name;
}
/**
* Returns the ISO two-letter country code of this country.
*
* @return the country code.
*/
public String getCode() {
return code;
}

/**
* Returns the name of this country.
*
* @return the country name.
*/
public String getName() {
return name;
}
}
110 changes: 110 additions & 0 deletions GeoIP/DatabaseInfo.cs
@@ -0,0 +1,110 @@
/**
* DatabaseInfo.cs
*
* Copyright (C) 2008 MaxMind Inc. All Rights Reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/


using System;
using System.IO;

public class DatabaseInfo {

public static int COUNTRY_EDITION = 1;
public static int REGION_EDITION_REV0 = 7;
public static int REGION_EDITION_REV1 = 3;
public static int CITY_EDITION_REV0 = 6;
public static int CITY_EDITION_REV1 = 2;
public static int ORG_EDITION = 5;
public static int ISP_EDITION = 4;
public static int PROXY_EDITION = 8;
public static int ASNUM_EDITION = 9;
public static int NETSPEED_EDITION = 10;
public static int DOMAIN_EDITION = 11;
public static int COUNTRY_EDITION_V6 = 12;
public static int ASNUM_EDITION_V6 = 21;
public static int ISP_EDITION_V6 = 22;
public static int ORG_EDITION_V6 = 23;
public static int DOMAIN_EDITION_V6 = 24;
public static int CITY_EDITION_REV1_V6 = 30;
public static int CITY_EDITION_REV0_V6 = 31;
public static int NETSPEED_EDITION_REV1 = 32;
public static int NETSPEED_EDITION_REV1_V6 = 33;


//private static SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd");

private String info;
/**
* Creates a new DatabaseInfo object given the database info String.
* @param info
*/

public DatabaseInfo(String info) {
this.info = info;
}

public int getType() {
if ((info == null) | (info == "")) {
return COUNTRY_EDITION;
}
else {
// Get the type code from the database info string and then
// subtract 105 from the value to preserve compatability with
// databases from April 2003 and earlier.
return Convert.ToInt32(info.Substring(4, 3)) - 105;
}
}

/**
* Returns true if the database is the premium version.
*
* @return true if the premium version of the database.
*/
public bool isPremium() {
return info.IndexOf("FREE") < 0;
}

/**
* Returns the date of the database.
*
* @return the date of the database.
*/
public DateTime getDate() {
for (int i=0; i<info.Length-9; i++) {
if (Char.IsWhiteSpace(info[i]) == true) {
String dateString = info.Substring(i+1, 8);
try {
//synchronized (formatter) {
return DateTime.ParseExact(dateString,"yyyyMMdd",null);
//}
}
catch (Exception e) {
Console.Write(e.Message);
}
break;
}
}
return DateTime.Now;
}

public String toString() {
return info;
}
}


0 comments on commit 109bd2a

Please sign in to comment.