Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

添加插件:RegionView #16

Merged
merged 5 commits into from
Apr 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
135 changes: 135 additions & 0 deletions Noagent/Noagent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
using System;
using System.IO;
using System.Net;
using System.Net.Http;
using System.Net.Sockets;
using System.Text;
using System.Threading.Tasks;
using Terraria;
using TerrariaApi.Server;
using TShockAPI;

namespace Noagent;

[ApiVersion(2, 1)]
public class Noagent : TerrariaPlugin
{
public override string Author => "[星迹]Jonesn,肝帝熙恩更新适配1449";
public override string Description => "禁止代理登录";
public override string Name => "[禁止代理登录]Noagent";
public override Version Version => new Version(1, 0, 1);

public Noagent(Main game)
: base(game)
{
}

public override void Initialize()
{
ServerApi.Hooks.ServerJoin.Register(this, OnJoin);
}

protected override void Dispose(bool disposing)
{
if (disposing)
{
ServerApi.Hooks.ServerJoin.Deregister(this, OnJoin);
}
base.Dispose(disposing);
}

public class Message
{
public TSPlayer Player { get; set; }
public TaskCompletionSource<string> Result { get; set; }

public async void ThreadMain()
{
try
{
await Task.Delay(3000);
string ipAddress = Player.IP;
string apiUrl = $"https://blackbox.ipinfo.app/lookup/{ipAddress}";

using HttpClient client = new HttpClient();
HttpResponseMessage response = await client.GetAsync(apiUrl);
response.EnsureSuccessStatusCode();

string responseContent = await response.Content.ReadAsStringAsync();
Result.SetResult(responseContent);
}
catch (Exception ex)
{
Result.SetException(ex);
}
}
}

private async void OnJoin(JoinEventArgs args)
{
TSPlayer player = TShock.Players[args.Who];

// 忽略内网IP和回环地址
if (IsPrivateOrLoopbackAddress(player.IP))
{
Console.WriteLine($"{player.Name} 使用内网或回环地址,跳过代理检测");
return;
}
Message message = new Message
{
Player = player,
Result = new TaskCompletionSource<string>()
};

Thread thread = new Thread(message.ThreadMain);
thread.Start();

try
{
string result = await message.Result.Task;
if (result == "Y") // 假设新的IP查询服务返回 "Y" 表示代理IP
{
Console.WriteLine($"检测到{player.Name}为代理,已踢出");
player.Disconnect("本服务禁止代理IP登录");
}
else
{
Console.WriteLine($"{player.Name} IP无异常");
}
}
catch (Exception ex)
{
Console.WriteLine($"检测玩家{player.Name} IP时发生错误: {ex.Message}");
}
}

private bool IsPrivateOrLoopbackAddress(string ipAddress)
{
IPAddress ip;
if (!IPAddress.TryParse(ipAddress, out ip))
{
return false;
}

// 判断是否为内网IP
if (ip.AddressFamily == AddressFamily.InterNetwork)
{
byte[] bytes = ip.GetAddressBytes();
if ((bytes[0] == 10) || // 10.0.0.0/8
(bytes[0] == 172 && (bytes[1] >= 16 && bytes[1] <= 31)) || // 172.16.0.0/12
(bytes[0] == 192 && bytes[1] == 168)) // 192.168.0.0/16
{
return true;
}
}

// 判断是否为回环地址
if (IPAddress.IsLoopback(ip))
{
return true;
}

return false;
}

}
5 changes: 5 additions & 0 deletions Noagent/Noagent.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<Project Sdk="Microsoft.NET.Sdk">

<Import Project="..\template.targets" />

</Project>
26 changes: 26 additions & 0 deletions Noagent/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Noagent 反代理插件

- 作者: Jonesn,肝帝熙恩
- 出处: TShock中文官方群
- 调用`https://blackbox.ipinfo.app/lookup/`进行检测,实测效果还行

## 更新日志

```
暂无
```

## 指令

```
暂无
```

## 配置

```json
暂无
```
## 反馈
- 共同维护的插件库:https://github.com/THEXN/TShockPlugin/
- 国内社区trhub.cn 或 TShock官方群等
28 changes: 28 additions & 0 deletions Plugin.sln
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RecipesBrowser", "RecipesBr
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TownNPCHomes", "TownNPCHomes\TownNPCHomes.csproj", "{6FAF2ED2-38B1-46C7-83F1-B909D260D70E}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RegionView", "RegionView\RegionView.csproj", "{41B3DE8D-F7B2-44E0-AD35-971140F49E81}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Noagent", "Noagent\Noagent.csproj", "{AFB08FA2-C6C6-4759-8117-E1CD44E1BCD9}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -276,6 +280,30 @@ Global
{6FAF2ED2-38B1-46C7-83F1-B909D260D70E}.Release|Any CPU.Build.0 = Release|Any CPU
{6FAF2ED2-38B1-46C7-83F1-B909D260D70E}.Release|x64.ActiveCfg = Release|Any CPU
{6FAF2ED2-38B1-46C7-83F1-B909D260D70E}.Release|x64.Build.0 = Release|Any CPU
{41B3DE8D-F7B2-44E0-AD35-971140F49E81}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{41B3DE8D-F7B2-44E0-AD35-971140F49E81}.Debug|Any CPU.Build.0 = Debug|Any CPU
{41B3DE8D-F7B2-44E0-AD35-971140F49E81}.Debug|x64.ActiveCfg = Debug|Any CPU
{41B3DE8D-F7B2-44E0-AD35-971140F49E81}.Debug|x64.Build.0 = Debug|Any CPU
{41B3DE8D-F7B2-44E0-AD35-971140F49E81}.Release|Any CPU.ActiveCfg = Release|Any CPU
{41B3DE8D-F7B2-44E0-AD35-971140F49E81}.Release|Any CPU.Build.0 = Release|Any CPU
{41B3DE8D-F7B2-44E0-AD35-971140F49E81}.Release|x64.ActiveCfg = Release|Any CPU
{41B3DE8D-F7B2-44E0-AD35-971140F49E81}.Release|x64.Build.0 = Release|Any CPU
{41B3DE8D-F7B2-44E0-AD35-971140F49E81}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{41B3DE8D-F7B2-44E0-AD35-971140F49E81}.Debug|Any CPU.Build.0 = Debug|Any CPU
{41B3DE8D-F7B2-44E0-AD35-971140F49E81}.Debug|x64.ActiveCfg = Debug|Any CPU
{41B3DE8D-F7B2-44E0-AD35-971140F49E81}.Debug|x64.Build.0 = Debug|Any CPU
{41B3DE8D-F7B2-44E0-AD35-971140F49E81}.Release|Any CPU.ActiveCfg = Release|Any CPU
{41B3DE8D-F7B2-44E0-AD35-971140F49E81}.Release|Any CPU.Build.0 = Release|Any CPU
{41B3DE8D-F7B2-44E0-AD35-971140F49E81}.Release|x64.ActiveCfg = Release|Any CPU
{41B3DE8D-F7B2-44E0-AD35-971140F49E81}.Release|x64.Build.0 = Release|Any CPU
{AFB08FA2-C6C6-4759-8117-E1CD44E1BCD9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AFB08FA2-C6C6-4759-8117-E1CD44E1BCD9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AFB08FA2-C6C6-4759-8117-E1CD44E1BCD9}.Debug|x64.ActiveCfg = Debug|Any CPU
{AFB08FA2-C6C6-4759-8117-E1CD44E1BCD9}.Debug|x64.Build.0 = Debug|Any CPU
{AFB08FA2-C6C6-4759-8117-E1CD44E1BCD9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AFB08FA2-C6C6-4759-8117-E1CD44E1BCD9}.Release|Any CPU.Build.0 = Release|Any CPU
{AFB08FA2-C6C6-4759-8117-E1CD44E1BCD9}.Release|x64.ActiveCfg = Release|Any CPU
{AFB08FA2-C6C6-4759-8117-E1CD44E1BCD9}.Release|x64.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
14 changes: 8 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,11 @@
| [RandReSpawn](https://github.com/Controllerdestiny/TShockPlugin/tree/master/RandRespawn) | 随机出生点 | 无 |
| [CGive](https://github.com/Controllerdestiny/TShockPlugin/tree/master/CGive) | 离线命令 | 无 |
| [RainbowChat](https://github.com/Controllerdestiny/TShockPlugin/tree/master/RainbowChat) | 每次说话颜色不一样 | 无 |
| [NormalDropsBags](https://github.com/Controllerdestiny/TShockPlugin/tree/master/NormalDropsBags) | 普通难度宝藏袋 | 无 |
| [CheckBag](https://github.com/Controllerdestiny/TShockPlugin/tree/master/CheckBag) | 检查背包(超进度物品检测) | 无 |
| [DisableSurfaceProjectiles](https://github.com/Controllerdestiny/TShockPlugin/tree/master/DisableSurfaceProjectiles) | 禁地表弹幕 | 无 |
| [RecipesBrowser](https://github.com/Controllerdestiny/TShockPlugin/tree/master/RecipesBrowser) | 合成表 | 无 |
| [DisableGodMod](https://github.com/Controllerdestiny/TShockPlugin/tree/master/DisableGodMod) | 阻止玩家无敌 | 无 |
| [TownNPCHomes](https://github.com/Controllerdestiny/TShockPlugin/tree/master/TownNPCHomes) | NPC快速回家 | 无 |
| [NormalDropsBags](https://github.com/Controllerdestiny/TShockPlugin/tree/master/NormalDropsBags) | 普通难度宝藏袋 | 无 |
| [CheckBag](https://github.com/Controllerdestiny/TShockPlugin/tree/master/CheckBag) | 检查背包(超进度物品检测) | 无 |
| [DisableSurfaceProjectiles](https://github.com/Controllerdestiny/TShockPlugin/tree/master/DisableSurfaceProjectiles) | 禁地表弹幕 | 无 |
| [RecipesBrowser](https://github.com/Controllerdestiny/TShockPlugin/tree/master/RecipesBrowser) | 合成表 | 无 |
| [DisableGodMod](https://github.com/Controllerdestiny/TShockPlugin/tree/master/DisableGodMod) | 阻止玩家无敌 | 无 |
| [TownNPCHomes](https://github.com/Controllerdestiny/TShockPlugin/tree/master/TownNPCHomes) | NPC快速回家 | 无 |
| [RegionView](https://github.com/Controllerdestiny/TShockPlugin/tree/master/RegionView) | 显示区域边界 | 无 |
| [Noagent](https://github.com/Controllerdestiny/TShockPlugin/tree/master/Noagent) | 禁止代理ip进入 | 无 |
28 changes: 28 additions & 0 deletions RegionView/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# RegionView 区域显示

- 作者: TBC开发者团队,肝帝熙恩
- 出处: github
- 为区域添加边界显示,仅自己视角可见

## 更新日志

```
暂无
```

## 指令

| 语法 | 权限 | 说明 |
| -------------- | :-----------------: | :------: |
| /regionview <区域名称> 或 /rv <区域名称> | regionvision.regionview | 显示指定区域边界|
| /regionclear 或 /rc | regionvision.regionview | 取消显示所有区域边界|
| /regionviewnear 或 /rvn | regionvision.regionviewnear | 显示周围所有区域边界|

## 配置

```json
暂无
```
## 反馈
- 共同维护的插件库:https://github.com/THEXN/TShockPlugin/
- 国内社区trhub.cn 或 TShock官方群等
Loading
Loading