Skip to content
Open
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ bld/
[Oo]bj/
[Ll]og/
[Ll]ogs/
[Bb]uild/

# Visual Studio 2015/2017 cache/options directory
.vs/
Expand Down
217 changes: 142 additions & 75 deletions Vanillafier/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ public class Vanillafier : TerrariaPlugin
{
const string ConfirmationCommand = "vanillafy-confirm";
const string GroupName = "Vanillafied";
const string DefualtGuestGroupName = "guest";
const string DefaultRegistrationGroupName = "default";
static string TShockConfigPath { get { return Path.Combine(TShock.SavePath, "config.json"); } }

public override string Author => "Pryaxis";
Expand All @@ -26,121 +28,186 @@ public Vanillafier(Main game) : base(game) { }

public override void Initialize()
{
Commands.ChatCommands.Add(new Command(Permissions.managegroup, Vanillafy, "vanillafy"));
Commands.ChatCommands.Add(new Command(Permissions.managegroup, vanillafy, "vanillafy"));
}

public void Vanillafy(CommandArgs args)
bool checkState()
{
bool hasGroup = TShock.Groups.GroupExists(GroupName);
bool isDefualt = Group.DefaultGroup.Name == GroupName;

TShockConfig tsConfig = TShock.Config;
bool isDefaultOfConfig = tsConfig.Settings.DefaultGuestGroupName == GroupName && tsConfig.Settings.DefaultRegistrationGroupName == GroupName;

return hasGroup && isDefualt && isDefaultOfConfig;
}

void printVanillafyState(TSPlayer player)
{
string stateString = checkState() ? "Open" : "Closed";
player.SendInfoMessage($"Vanillafy State: {stateString}");
}

void vanillafy(CommandArgs args)
{
var player = args.Player;
if (player == null)
{
return;
}

if (TShock.Groups.GroupExists(GroupName))
if (args.Parameters.Count <= 0)
{
player.SendErrorMessage("The vanillafy command has already been run.");
player.SendWarningMessage("If you proceed with running this command, your existing vanilla configuration will be reset.");
}
else
{
player.SendWarningMessage("This command will disable most cheat and grief protection for all non-superadmin users.");
printHelp(player);
return;
}

player.SendWarningMessage($"Are you sure you wish to run this command? Use {TShock.Config.Settings.CommandSpecifier}{ConfirmationCommand} to complete configuration.");
player.AwaitingResponse.Add(ConfirmationCommand, Confirm);
switch (args.Parameters[0]) {
case "on":
if (checkState())
{
player.SendErrorMessage("The vanillafy command has already been run.");
player.SendWarningMessage("If you proceed with running this command, your existing vanilla configuration will be reset.");
}
else
{
player.SendWarningMessage("This command will disable most cheat and grief protection for all non-superadmin users.");
}

player.SendWarningMessage($"Are you sure you wish to run this command? Use {TShock.Config.Settings.CommandSpecifier}{ConfirmationCommand} to complete configuration.");
player.AwaitingResponse.Add(ConfirmationCommand, trunOnConfirm);
break;
case "off":
if (checkState())
{
player.SendWarningMessage("Vanilla gameplay will be closed soon.");
player.SendWarningMessage($"Are you sure you wish to run this command? Use {TShock.Config.Settings.CommandSpecifier}{ConfirmationCommand} to complete configuration.");
player.AwaitingResponse.Add(ConfirmationCommand, trunOffConfirm);
}
else
{
player.SendErrorMessage("Server is not yet open vanilla gameplay.");
}
break;
case "state":
printVanillafyState(player);
break;
case "help":
default:
printHelp(player);
break;
}
}

public void Confirm(object obj)
void printHelp(TSPlayer player)
{
if (obj == null)
{
return;
}

CommandArgs args = (CommandArgs)obj;
var player = args.Player ?? TSPlayer.Server;
player.SendInfoMessage("/vanillafy on - Open Vanillafy");
player.SendInfoMessage("/vanillafy off - Close Vanillafy");
player.SendInfoMessage("/vanillafy state - Get Vanillafy State");
player.SendInfoMessage("/vanillafy help - Get Vanillafy Help");
}

//Get the TShock group manager and setup the new vanilla group
GroupManager gm = TShock.Groups;
Group group = CreateVanillaGroupObject();
if (!gm.GroupExists(GroupName))
{
gm.AddGroup(name: GroupName, parentname: null, permissions: group.Permissions, chatcolor: Group.defaultChatColor);
}
else
{
gm.UpdateGroup(name: GroupName, parentname: null, permissions: group.Permissions, chatcolor: Group.defaultChatColor, suffix: null, prefix: null);
}
//Retrieve the group again just so that the object state is synced with db state
group = gm.GetGroupByName(GroupName);
void changeState(Group group, string defaultGuestGroupName=DefualtGuestGroupName)
{
var GroupName = group.Name;

//Get the TShock user manager, select all non-superadmin groups, and change their group to the new vanilla group
UserAccountManager um = TShock.UserAccounts;
um.GetUserAccounts().Where(u => u.Group != "superadmin" && u.Group != "owner").ForEach(u => um.SetUserGroup(u, GroupName));

//Update all active player's groups, as long as they're not a superadmin
foreach (var ply in TShock.Players)
foreach (var player in TShock.Players)
{
if (ply?.Group == null || ply.Group is SuperAdminGroup)
if (player?.Group == null || player.Group is SuperAdminGroup)
{
continue;
}

ply.Group = group;
player.Group = group;
}

//Set the default group for any new guests joining
Group.DefaultGroup = group;

//Update the TShock config file so all new guest users will be assigned to the vanilla group
TShockConfig tsConfig = TShock.Config;
tsConfig.Settings.DefaultGuestGroupName = GroupName;
tsConfig.Settings.DefaultGuestGroupName = defaultGuestGroupName;
tsConfig.Settings.DefaultRegistrationGroupName = GroupName;
//Write the config file so that this change persists
tsConfig.Write(TShockConfigPath);
}

void trunOnConfirm(object obj)
{
if (obj == null)
{
return;
}

GroupManager groupManager = TShock.Groups;
Group group = createVanillaGroupObject();
if (!groupManager.GroupExists(GroupName))
{
groupManager.AddGroup(name: GroupName, parentname: null, permissions: group.Permissions, chatcolor: Group.defaultChatColor);
}
else
{
groupManager.UpdateGroup(name: GroupName, parentname: null, permissions: group.Permissions, chatcolor: Group.defaultChatColor, suffix: null, prefix: null);
}
changeState(groupManager.GetGroupByName(GroupName), GroupName);

CommandArgs args = (CommandArgs)obj;
var player = args.Player ?? TSPlayer.Server;
player.SendSuccessMessage("Server has successfully been configured for vanilla gameplay.");
}

void trunOffConfirm(object obj)
{
if (obj == null)
{
return;
}

changeState(TShock.Groups.GetGroupByName(DefaultRegistrationGroupName));

CommandArgs args = (CommandArgs)obj;
var player = args.Player ?? TSPlayer.Server;
player.SendSuccessMessage("Server has been unconfigured for vanilla gameplay.");
}

Group CreateVanillaGroupObject()
Group createVanillaGroupObject()
{
Group g = new Group(GroupName);

g.AddPermission("tshock.ignore.*");
g.AddPermission("!tshock.ignore.ssc"); //Allow SSC gameplay

g.AddPermission("tshock.account.*"); //Register, login, logout, change password

g.AddPermission("tshock.npc.hurttown");
g.AddPermission("tshock.npc.startinvasion");
g.AddPermission("tshock.npc.startdd2");
g.AddPermission("tshock.npc.summonboss");
g.AddPermission("tshock.npc.spawnpets");

g.AddPermission("tshock.tp.rod");
g.AddPermission("tshock.tp.wormhole");
g.AddPermission("tshock.tp.pylon");
g.AddPermission("tshock.tp.tppotion");
g.AddPermission("tshock.tp.magicconch");
g.AddPermission("tshock.tp.demonconch");

g.AddPermission("tshock.world.editspawn");
g.AddPermission("tshock.world.modify");
g.AddPermission("tshock.world.movenpc");
g.AddPermission("tshock.world.paint");
g.AddPermission("tshock.world.time.usesundial");
g.AddPermission("tshock.world.toggleparty");
Group group = new Group(GroupName);

group.AddPermission("tshock.ignore.*");
group.AddPermission("!tshock.ignore.ssc");

group.AddPermission("tshock.account.*");

group.AddPermission("tshock.npc.hurttown");
group.AddPermission("tshock.npc.startinvasion");
group.AddPermission("tshock.npc.startdd2");
group.AddPermission("tshock.npc.summonboss");
group.AddPermission("tshock.npc.spawnpets");

group.AddPermission("tshock.tp.rod");
group.AddPermission("tshock.tp.wormhole");
group.AddPermission("tshock.tp.pylon");
group.AddPermission("tshock.tp.tppotion");
group.AddPermission("tshock.tp.magicconch");
group.AddPermission("tshock.tp.demonconch");

group.AddPermission("tshock.world.editspawn");
group.AddPermission("tshock.world.modify");
group.AddPermission("tshock.world.movenpc");
group.AddPermission("tshock.world.paint");
group.AddPermission("tshock.world.time.usesundial");
group.AddPermission("tshock.world.toggleparty");

g.AddPermission("tshock.canchat");
g.AddPermission("tshock.partychat");
g.AddPermission("tshock.thirdperson");
g.AddPermission("tshock.whisper");
g.AddPermission("tshock.sendemoji");
group.AddPermission("tshock.canchat");
group.AddPermission("tshock.partychat");
group.AddPermission("tshock.thirdperson");
group.AddPermission("tshock.whisper");
group.AddPermission("tshock.sendemoji");

g.AddPermission("tshock.journey.*");
group.AddPermission("tshock.journey.*");

return g;
return group;
}
}
}
35 changes: 26 additions & 9 deletions Vanillafier/Vanillafier.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,23 @@
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
<Reference Include="OTAPI, Version=1.3.5.3, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>refs\OTAPI.dll</HintPath>
<Reference Include="BCrypt.Net, Version=0.1.4141.31969, Culture=neutral, PublicKeyToken=f3bc8f8c31beeb49, processorArchitecture=MSIL">
<HintPath>..\packages\BCrypt.Net.0.1.0\lib\net35\BCrypt.Net.dll</HintPath>
</Reference>
<Reference Include="HttpServer, Version=2.0.0.0, Culture=neutral, PublicKeyToken=5684c2c737cd4271, processorArchitecture=MSIL">
<HintPath>..\packages\TerrariaServer.TShock.4.5.5\lib\net452\HttpServer.dll</HintPath>
</Reference>
<Reference Include="Mono.Data.Sqlite, Version=2.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756, processorArchitecture=MSIL">
<HintPath>..\packages\TerrariaServer.TShock.4.5.5\lib\net452\Mono.Data.Sqlite.dll</HintPath>
</Reference>
<Reference Include="MySql.Data, Version=6.9.12.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d, processorArchitecture=MSIL">
<HintPath>..\packages\MySql.Data.6.9.12\lib\net45\MySql.Data.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="OTAPI, Version=1.4.2.3, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\TerrariaServer.TShock.4.5.5\lib\net452\OTAPI.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
Expand All @@ -61,20 +75,23 @@
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
<Reference Include="TerrariaServer, Version=1.3.5.3, Culture=neutral, processorArchitecture=x86">
<SpecificVersion>False</SpecificVersion>
<HintPath>refs\TerrariaServer.exe</HintPath>
<Reference Include="TerrariaServer, Version=1.4.2.3, Culture=neutral, processorArchitecture=x86">
<HintPath>..\packages\TerrariaServer.TShock.4.5.5\lib\net452\TerrariaServer.exe</HintPath>
</Reference>
<Reference Include="TShockAPI">
<HintPath>refs\TShockAPI.dll</HintPath>
<Reference Include="TShockAPI, Version=4.5.5.0, Culture=neutral, processorArchitecture=x86">
<HintPath>..\packages\TerrariaServer.TShock.4.5.5\lib\net452\TShockAPI.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Main.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>xcopy /y /d "$(TargetPath)" "$(ProjectDir)build\"</PostBuildEvent>
</PropertyGroup>
</Project>
</Project>
17 changes: 17 additions & 0 deletions Vanillafier/app.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.data>
<DbProviderFactories>
<remove invariant="MySql.Data.MySqlClient" />
<add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=6.9.12.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
</DbProviderFactories>
</system.data>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="MySql.Data" publicKeyToken="c5687fc88969c44d" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-6.9.12.0" newVersion="6.9.12.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
Binary file removed Vanillafier/build/Vanillafier.dll
Binary file not shown.
7 changes: 7 additions & 0 deletions Vanillafier/packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="BCrypt.Net" version="0.1.0" targetFramework="net452" />
<package id="MySql.Data" version="6.9.12" targetFramework="net452" />
<package id="Newtonsoft.Json" version="10.0.3" targetFramework="net452" />
<package id="TerrariaServer.TShock" version="4.5.5" targetFramework="net452" />
</packages>
Binary file removed Vanillafier/refs/OTAPI.dll
Binary file not shown.
Binary file removed Vanillafier/refs/TShockAPI.dll
Binary file not shown.
Binary file removed Vanillafier/refs/TerrariaServer.exe
Binary file not shown.