Skip to content

Commit adeaf51

Browse files
committed
Upload plugins
1 parent 9c5b287 commit adeaf51

File tree

14 files changed

+476
-1
lines changed

14 files changed

+476
-1
lines changed

.github/workflows/deployment.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: Deployment
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
version:
7+
description: 'Plugin Version (SemVer: https://semver.org)'
8+
required: true
9+
jobs:
10+
deploy:
11+
name: "NuGet Deployment"
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v2
15+
name: Checkout Repository
16+
with:
17+
fetch-depth: 0
18+
- name: Setup .NET
19+
uses: actions/setup-dotnet@v1
20+
with:
21+
dotnet-version: 5.0.x
22+
- name: Install dependencies
23+
run: dotnet restore
24+
- name: Update version
25+
run: "sed -i \"s#<Version>0.0.0</Version>#<Version>${{ github.event.inputs.version }}</Version>#\" Feli.OpenMod.JoinLeaveMessages/Feli.OpenMod.JoinLeaveMessages.csproj"
26+
- name: Update assembly version
27+
run: "sed -i \"s#<AssemblyVersion>0.0.0</AssemblyVersion>#<AssemblyVersion>${{ github.event.inputs.version }}</AssemblyVersion>#\" Feli.OpenMod.JoinLeaveMessages/Feli.OpenMod.JoinLeaveMessages.csproj"
28+
- name: Build
29+
run: dotnet build Feli.OpenMod.AdvancedCosmetics/Feli.OpenMod.AdvancedCosmetics.csproj --configuration Release --no-restore
30+
- name: Push to NuGet
31+
run: dotnet nuget push Feli.OpenMod.JoinLeaveMessages/bin/Release/*.nupkg
32+
--api-key ${{ secrets.NUGET_DEPLOY_KEY }}
33+
--source https://api.nuget.org/v3/index.json
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
using Feli.OpenMod.JoinLeaveMessages.Helpers;
2+
using Microsoft.Extensions.Configuration;
3+
using Microsoft.Extensions.Localization;
4+
using OpenMod.API.Eventing;
5+
using OpenMod.Unturned.Users.Events;
6+
using SDG.Unturned;
7+
using System.Threading.Tasks;
8+
using UnityEngine;
9+
10+
namespace Feli.OpenMod.JoinLeaveMessages.Events
11+
{
12+
public class EventListener : IEventListener<UnturnedUserConnectedEvent>, IEventListener<UnturnedUserDisconnectedEvent>
13+
{
14+
private readonly IConfiguration _configuration;
15+
private readonly IStringLocalizer _stringLocalizer;
16+
private readonly IpGeolocationHelper _geolocator;
17+
18+
public EventListener(
19+
IConfiguration configuration,
20+
IStringLocalizer stringLocalizer,
21+
IpGeolocationHelper geolocator)
22+
{
23+
_configuration = configuration;
24+
_stringLocalizer = stringLocalizer;
25+
_geolocator = geolocator;
26+
}
27+
28+
public async Task HandleEventAsync(object sender, UnturnedUserConnectedEvent @event)
29+
{
30+
if (!_configuration.GetSection("joinMessage:enabled").Get<bool>())
31+
return;
32+
33+
var country = string.Empty;
34+
35+
if (_configuration.GetSection("joinMessage:showCountry").Get<bool>())
36+
country = await _geolocator.GetCountryFromIpAsync(@event.User.Player.Address.MapToIPv4().ToString());
37+
38+
var message = _stringLocalizer["join", new
39+
{
40+
User = @event.User,
41+
Country = country
42+
}];
43+
44+
ChatManager.serverSendMessage(message, Color.green, mode: EChatMode.GLOBAL, iconURL: _configuration["joinMessage:customIconUrl"], useRichTextFormatting: true);
45+
}
46+
47+
public Task HandleEventAsync(object sender, UnturnedUserDisconnectedEvent @event)
48+
{
49+
if (!_configuration.GetSection("leaveMessage:enabled").Get<bool>())
50+
return Task.CompletedTask;
51+
52+
var message = _stringLocalizer["leave", new
53+
{
54+
User = @event.User
55+
}];
56+
57+
ChatManager.serverSendMessage(message, Color.green, mode: EChatMode.GLOBAL, iconURL: _configuration["leaveMessage:customIconUrl"], useRichTextFormatting: true);
58+
59+
return Task.CompletedTask;
60+
}
61+
}
62+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net461</TargetFramework>
5+
<LangVersion>latest</LangVersion>
6+
<AssemblyVersion>0.0.0</AssemblyVersion>
7+
</PropertyGroup>
8+
9+
<PropertyGroup>
10+
<PackageId>Feli.JoinLeaveMessages</PackageId>
11+
<PackageDescription>Broadcast users connections and disconnections to the global chat</PackageDescription>
12+
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
13+
<PackageAuthors>FPlugins;Felixer001</PackageAuthors>
14+
<PackageOwners>FPlugins</PackageOwners>
15+
<PackageTags>openmod openmod-plugin unturned</PackageTags>
16+
<Version>0.0.0</Version>
17+
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
18+
<GenerateNugetPackage>true</GenerateNugetPackage>
19+
</PropertyGroup>
20+
21+
<ItemGroup>
22+
<PackageReference Include="OpenMod.Unturned" Version="3.2.7" />
23+
</ItemGroup>
24+
25+
<ItemGroup>
26+
<EmbeddedResource Include="config.yaml" />
27+
<EmbeddedResource Include="translations.yaml" />
28+
</ItemGroup>
29+
</Project>
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
using Microsoft.Extensions.Logging;
2+
using Newtonsoft.Json.Linq;
3+
using System;
4+
using System.Net.Http;
5+
using System.Threading.Tasks;
6+
7+
namespace Feli.OpenMod.JoinLeaveMessages.Helpers
8+
{
9+
public class IpGeolocationHelper : IDisposable
10+
{
11+
private readonly ILogger<IpGeolocationHelper> _logger;
12+
private readonly HttpClient _client;
13+
14+
public IpGeolocationHelper(ILogger<IpGeolocationHelper> logger)
15+
{
16+
_logger = logger;
17+
_client = new HttpClient();
18+
}
19+
20+
public async Task<string> GetCountryFromIpAsync(string address)
21+
{
22+
var respnse = await _client.GetAsync($"http://ip-api.com/json/{address}?fields=status,message,country");
23+
24+
if (!respnse.IsSuccessStatusCode)
25+
{
26+
_logger.LogError($"HTTP Error: {(int)respnse.StatusCode}, {respnse.StatusCode}");
27+
return string.Empty;
28+
}
29+
30+
var content = await respnse.Content.ReadAsStringAsync();
31+
32+
var @object = JObject.Parse(content);
33+
34+
if (@object["status"].ToString() == "fail")
35+
{
36+
_logger.LogError($"Failed to get the ip location. Error: {@object["message"]}");
37+
return string.Empty;
38+
}
39+
40+
return @object["country"].ToString();
41+
}
42+
43+
public void Dispose()
44+
{
45+
_client.Dispose();
46+
}
47+
}
48+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
using Cysharp.Threading.Tasks;
2+
using Microsoft.Extensions.Logging;
3+
using OpenMod.API.Plugins;
4+
using OpenMod.Unturned.Plugins;
5+
using System;
6+
7+
[assembly: PluginMetadata("Feli.JoinLeaveMessages",
8+
DisplayName = "Join and Leave Messages",
9+
Author = "Feli",
10+
Description = "Broadcast users connections and disconnections to the global chat",
11+
Website = "https://discord.gg/4FF2548"
12+
)]
13+
14+
namespace Feli.OpenMod.JoinLeaveMessages
15+
{
16+
public class Plugin : OpenModUnturnedPlugin
17+
{
18+
private readonly ILogger<Plugin> _logger;
19+
20+
public Plugin(
21+
ILogger<Plugin> logger,
22+
IServiceProvider serviceProvider) : base(serviceProvider)
23+
{
24+
_logger = logger;
25+
}
26+
27+
protected override UniTask OnLoadAsync()
28+
{
29+
_logger.LogInformation($"JoinLeaveMessages plugin v{Version} loaded !");
30+
_logger.LogInformation("Do you want more cool plugins? Join now: https://discord.gg/4FF2548 !");
31+
return UniTask.CompletedTask;
32+
}
33+
}
34+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using Autofac;
2+
using Feli.OpenMod.JoinLeaveMessages.Helpers;
3+
using Microsoft.Extensions.DependencyInjection;
4+
using OpenMod.API.Plugins;
5+
using OpenMod.Core.Ioc.Extensions;
6+
using System;
7+
8+
namespace Feli.OpenMod.JoinLeaveMessages
9+
{
10+
public class PluginContainerConfigurator : IPluginContainerConfigurator
11+
{
12+
public void ConfigureContainer(IPluginServiceConfigurationContext context)
13+
{
14+
context.ContainerBuilder
15+
.Register(
16+
(builder) => ActivatorUtilities.CreateInstance<IpGeolocationHelper>(builder.Resolve<IServiceProvider>()))
17+
.WithLifetime(ServiceLifetime.Singleton)
18+
.OwnedByLifetimeScope();
19+
}
20+
}
21+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
joinMessage:
2+
enabled: true
3+
showCountry: true
4+
customIconUrl: "" # Leave empty if you dont want a custom icon
5+
6+
leaveMessage:
7+
enabled: false
8+
customIconUrl: "" # Leave empty if you dont want a custom icon
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
join: "<color=yellow>{User.DisplayName} has connected to the server from {Country}</color>"
2+
3+
leave: "<color=red>{User.DisplayName} disconnected from the server</color>"
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using Rocket.API;
2+
3+
namespace Feli.RocketMod.JoinLeaveMessages
4+
{
5+
public class Configuration : IRocketPluginConfiguration
6+
{
7+
public bool JoinMessages { get; set; }
8+
public bool ShowCountry { get; set; }
9+
public string CustomImageUrl { get; set; }
10+
public bool LeaveMessages { get; set; }
11+
12+
public void LoadDefaults()
13+
{
14+
JoinMessages = true;
15+
ShowCountry = true;
16+
CustomImageUrl = string.Empty;
17+
LeaveMessages = false;
18+
}
19+
}
20+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net461</TargetFramework>
5+
<LangVersion>latest</LangVersion>
6+
<Version>1.0.0</Version>
7+
<AssemblyVersion>1.0.0</AssemblyVersion>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
12+
<PackageReference Include="OpenMod.UnityEngine.Redist" Version="2019.4.10" />
13+
<PackageReference Include="OpenMod.Unturned.Redist" Version="3.21.33-preview.1" />
14+
</ItemGroup>
15+
16+
<ItemGroup>
17+
<Reference Include="Rocket.API">
18+
<HintPath>C:\Users\felin\Downloads\Rocket.Unturned\Rocket.API.dll</HintPath>
19+
</Reference>
20+
<Reference Include="Rocket.Core">
21+
<HintPath>C:\Users\felin\Downloads\Rocket.Unturned\Rocket.Core.dll</HintPath>
22+
</Reference>
23+
<Reference Include="Rocket.Unturned">
24+
<HintPath>C:\Users\felin\Downloads\Rocket.Unturned\Rocket.Unturned.dll</HintPath>
25+
</Reference>
26+
<Reference Include="System.Net.Http" />
27+
</ItemGroup>
28+
29+
</Project>

0 commit comments

Comments
 (0)