Skip to content
This repository has been archived by the owner on May 14, 2023. It is now read-only.

Commit

Permalink
VPNShield 2.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
KarlOfDuty committed Oct 20, 2018
1 parent 687befb commit 023d2a2
Show file tree
Hide file tree
Showing 7 changed files with 331 additions and 0 deletions.
25 changes: 25 additions & 0 deletions VPNShield.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.28010.2046
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VPNShield", "VPNShield\VPNShield.csproj", "{1BCF42E3-41F9-46FA-AAC0-F45200EC10B9}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{1BCF42E3-41F9-46FA-AAC0-F45200EC10B9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1BCF42E3-41F9-46FA-AAC0-F45200EC10B9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1BCF42E3-41F9-46FA-AAC0-F45200EC10B9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1BCF42E3-41F9-46FA-AAC0-F45200EC10B9}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {279E95A4-19A5-4F85-98C9-6959D8533883}
EndGlobalSection
EndGlobal
36 changes: 36 additions & 0 deletions VPNShield/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("VPNShield")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("VPNShield")]
[assembly: AssemblyCopyright("Copyright © 2018")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("1bcf42e3-41f9-46fa-aac0-f45200ec10b9")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
200 changes: 200 additions & 0 deletions VPNShield/VPNShield.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,200 @@
using Newtonsoft.Json.Linq;
using Smod2;
using Smod2.Attributes;
using Smod2.Commands;
using Smod2.EventHandlers;
using Smod2.Events;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Xml;

namespace VPNShield
{
[PluginDetails(
author = "Karl Essinger",
name = "VPNShield",
description = "Blocks users connecting using VPNs.",
id = "karlofduty.vpnshield",
version = "2.0.0",
SmodMajor = 3,
SmodMinor = 1,
SmodRevision = 19
)]
public class VPNShield : Plugin
{
public JObject config;

readonly string defaultConfig =
"{\n" +
" \"block-vpns\": true,\n" +
" \"iphub-apikey\": \"put-key-here\",\n" +
" \"strictmode\": false,\n" +
" \"block-new-steam-accounts\": true,\n" +
"}";

public override void OnDisable()
{

}

public override void Register()
{
this.AddEventHandlers(new CheckPlayer(this), Priority.High);
this.AddCommand("vs_reload", new ReloadCommand(this));
}

public override void OnEnable()
{
if (!File.Exists(FileManager.AppFolder + "VPNShield/config.json"))
{
if (!Directory.Exists(FileManager.AppFolder + "VPNShield"))
Directory.CreateDirectory(FileManager.AppFolder + "VPNShield");
File.WriteAllText(FileManager.AppFolder + "VPNShield/config.json", defaultConfig);
}
config = JObject.Parse(File.ReadAllText(FileManager.AppFolder + "VPNShield/config.json"));
this.Info("VPNShield enabled.");
}

public bool CheckVPN(PlayerJoinEvent ev)
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://v2.api.iphub.info/ip/" + ev.Player.IpAddress.Replace("::ffff:", ""));
request.Headers.Add("x-key", "MjgzMDp3cmdVQzk0R0ZCQ1hadEhubXVMZWFKZG9HSW5GWmVrbA==");

HttpWebResponse response = (HttpWebResponse)request.GetResponse();

string responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();
JObject json = JObject.Parse(responseString);

int verificationLevel = json.Value<int>("block");
switch (verificationLevel)
{
case 0:
this.Info(ev.Player.Name + " is not using a detectable VPN.");
break;
case 1:
this.Info(ev.Player.Name + " is using a VPN.");
if (config.Value<bool>("block-vpn"))
{
ev.Player.Ban(0, "This server does not allow VPNs.");
return true;
}
break;
case 2:
this.Info(ev.Player.Name + " is possibly using a VPN.");
if (config.Value<bool>("block-vpn") && config.Value<bool>("strictmode"))
{
ev.Player.Ban(0, "This server does not allow VPNs.");
return true;
}
break;
}
return false;
}

public bool CheckSteamAccount(PlayerJoinEvent ev)
{
ServicePointManager.ServerCertificateValidationCallback = SSLValidation;
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://steamcommunity.com/profiles/" + ev.Player.SteamId + "?xml=1");
HttpWebResponse response = (HttpWebResponse)request.GetResponse();

string xmlResponse = new StreamReader(response.GetResponseStream()).ReadToEnd();

string[] foundStrings = xmlResponse.Split('\n').Where(w => w.Contains("isLimitedAccount")).ToArray();

if(foundStrings.Length == 0)
{
this.Error("Steam account check failed.");
return false;
}

bool isLimitedAccount = foundStrings[0].Where(c => char.IsDigit(c)).ToArray()[0] != '0';
if (isLimitedAccount && config.Value<bool>("block-new-steam-accounts"))
{
this.Info(ev.Player.Name + " has a new steam account with no games bought on it.");
ev.Player.Ban(0, "This server does not allow new Steam accounts, you have to buy something on Steam before playing.");
return true;
}
return false;
}

public bool SSLValidation(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
{
bool isOk = true;
// If there are errors in the certificate chain,
// look at each error to determine the cause.
if (sslPolicyErrors != SslPolicyErrors.None)
{
for (int i = 0; i < chain.ChainStatus.Length; i++)
{
if (chain.ChainStatus[i].Status == X509ChainStatusFlags.RevocationStatusUnknown)
{
continue;
}
chain.ChainPolicy.RevocationFlag = X509RevocationFlag.EntireChain;
chain.ChainPolicy.RevocationMode = X509RevocationMode.Online;
chain.ChainPolicy.UrlRetrievalTimeout = new TimeSpan(0, 1, 0);
chain.ChainPolicy.VerificationFlags = X509VerificationFlags.AllFlags;
bool chainIsValid = chain.Build((X509Certificate2)certificate);
if (!chainIsValid)
{
isOk = false;
break;
}
}
}
return isOk;
}
}
class ReloadCommand : ICommandHandler
{
private VPNShield plugin;
public ReloadCommand(VPNShield plugin)
{
this.plugin = plugin;
}

public string GetCommandDescription()
{
return "Reloads the JSON config of VPNShield";
}

public string GetUsage()
{
return "vs_reload";
}

public string[] OnCall(ICommandSender sender, string[] args)
{
plugin.config = JObject.Parse(File.ReadAllText(FileManager.AppFolder + "VPNShield/config.json"));
return new string[] { "VPNShield JSON config has been reloaded." };
}
}

class CheckPlayer : IEventHandlerPlayerJoin
{
private VPNShield plugin;
public CheckPlayer(VPNShield plugin)
{
this.plugin = plugin;
}
public void OnPlayerJoin(PlayerJoinEvent ev)
{
if(ev.Player.GetRankName() != "")
{
return;
}

if(plugin.CheckVPN(ev))
{
return;
}
plugin.CheckSteamAccount(ev);
}
}
}
66 changes: 66 additions & 0 deletions VPNShield/VPNShield.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" 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>{1BCF42E3-41F9-46FA-AAC0-F45200EC10B9}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>VPNShield</RootNamespace>
<AssemblyName>VPNShield</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>
<ItemGroup>
<Reference Include="Assembly-CSharp">
<HintPath>lib\Assembly-CSharp.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.11.0.2\lib\net35\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="Smod2">
<HintPath>lib\Smod2.dll</HintPath>
</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" />
</ItemGroup>
<ItemGroup>
<Compile Include="VPNShield.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>cd $(ProjectDir)
copy /y bin\VPNShield.dll ..\..\..\scpserver\sm_plugins\
mkdir ..\..\..\scpserver\sm_plugins\dependencies
copy /y bin\Newtonsoft.Json.dll ..\..\..\scpserver\sm_plugins\dependencies\</PostBuildEvent>
</PropertyGroup>
</Project>
Binary file added VPNShield/lib/Assembly-CSharp.dll
Binary file not shown.
Binary file added VPNShield/lib/Smod2.dll
Binary file not shown.
4 changes: 4 additions & 0 deletions VPNShield/packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Newtonsoft.Json" version="11.0.2" targetFramework="net35" />
</packages>

0 comments on commit 023d2a2

Please sign in to comment.