• R/O
  • HTTP
  • SSH
  • HTTPS

提交

标签

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Administrator's Toolkit VS plugin


Commit MetaInfo

修订版a4b36e597c3df04e67017e08d0056bb239cb35ec (tree)
时间2020-11-08 08:40:18
作者melchior <melchior@user...>
Commitermelchior

Log Message

Pre Beta 0.3.5 changes & fixes

更改概述

差异

--- /dev/null
+++ b/AdminToolkit/ATK_BasicFeatures.cs
@@ -0,0 +1,121 @@
1+using System;
2+using System.Text;
3+using System.Linq;
4+using System.Collections.Generic;
5+using System.IO;
6+
7+using Vintagestory.API.Common;
8+using Vintagestory.API.Server;
9+using Vintagestory.API.Config;
10+using Vintagestory.API.Datastructures;
11+
12+namespace AdminToolkit
13+{
14+ public partial class AdminToolkit : ModSystem
15+ {
16+ private void PopulateAdminRoleTable( )
17+ {
18+ AdminRoles = new List<string>( );
19+ foreach (var role in ServerAPI.Server.Config.Roles) {
20+
21+ if (role.PrivilegeLevel >= 200 && role.Privileges.Any(adminPriviledges.Contains)) {
22+
23+ AdminRoles.Add(role.Code);
24+
25+ #if DEBUG
26+ Mod.Logger.VerboseDebug("Role {0} =[{1}] considerd Admin-like", role.Name, role.Code);
27+ #endif
28+ }
29+ }
30+ }
31+
32+ private void PrepareServersideConfig( )
33+ {
34+ AdminModConfig config = ServerAPI.LoadModConfig<AdminModConfig>(_configFilename);
35+
36+ if (config == null) {
37+ //Regen default
38+ Mod.Logger.Warning("Regenerating default config as it was missing / unparsable...");
39+ ServerAPI.StoreModConfig<AdminModConfig>(new AdminModConfig( ), _configFilename);
40+ config = ServerAPI.LoadModConfig<AdminModConfig>(_configFilename);
41+ }
42+
43+ this.CachedConfiguration = config;
44+
45+ if (this.CachedConfiguration.RuleRoleChangerEnabled) { Mod.Logger.Notification("Admin toolkit; Role change on Rule accept: * ENABLED *"); }
46+ }
47+
48+ /// <summary>
49+ /// Makes Administrator text messages appear 'different'
50+ /// </summary>
51+ /// <returns>The voice of authority.</returns>
52+ /// <param name="byPlayer">By player.</param>
53+ /// <param name="channelId">Channel identifier.</param>
54+ /// <param name="message">Message.</param>
55+ /// <param name="consumed">Consumed.</param>
56+ private void BoomingVoiceOfAuthority(IServerPlayer byPlayer, int channelId, ref string message, ref string data, BoolRef consumed)
57+ {
58+ if (AdminRoles.Contains(byPlayer.Role.Code)) {
59+ //Make text lined
60+ consumed.value = false;
61+ StringBuilder adminMessage = new StringBuilder( );
62+ foreach (char letter in message) {
63+
64+ adminMessage.Append(letter);
65+ if (!Char.IsWhiteSpace(letter)) {
66+ //adminMessage.Append(@"̅̅̅");
67+ adminMessage.Append(@"̲");
68+ }
69+ }
70+
71+ message = adminMessage.ToString( );
72+ }
73+ }
74+
75+ private void SaveConfigSettings( )
76+ {
77+ if (this.CachedConfiguration != null) {
78+ Mod.Logger.Notification("Persisting configuration.");
79+ ServerAPI.StoreModConfig<AdminModConfig>(this.CachedConfiguration, _configFilename);
80+ }
81+ }
82+
83+ private void WelcomeMessage(IServerPlayer byPlayer)
84+ {
85+ if (AdminToolkit.AdminRoles.Contains(byPlayer.Role.Code)) {
86+ //Annonce to all players that Admin\Moderator has arrived
87+
88+ StringBuilder adminMessage = new StringBuilder( );
89+
90+ adminMessage.AppendFormat("<font color='{1}' weight='bold'>«{0}» {2}</font> Present.", byPlayer.Role.Name, byPlayer.Role.Color.Name, byPlayer.PlayerName);
91+
92+ ServerAPI.SendMessageToGroup(GlobalConstants.AllChatGroups, adminMessage.ToString( ), EnumChatType.AllGroups);
93+
94+ byPlayer.ServerData.CustomPlayerData[AdminToolkit._lastLoginKey] = DateTimeOffset.UtcNow.ToString("u");
95+ }
96+
97+ double elapsedDays = 0D;
98+ string elapsedDayStr;
99+
100+ if (byPlayer.ServerData.CustomPlayerData.TryGetValue(AdminToolkit._lastGameDayCountKey, out elapsedDayStr)
101+ &&
102+ double.TryParse(elapsedDayStr, out elapsedDays)) {
103+ elapsedDays = ServerAPI.World.Calendar.TotalDays - elapsedDays;
104+ var playerPos = byPlayer.Entity.Pos.AsBlockPos.Copy();
105+ //No Localized Season names?
106+ var welcomeMsg = $"Meantime... {elapsedDays:F1} days have passed. {ServerAPI.World.AllOnlinePlayers.Length} Players online. It is {ServerAPI.World.Calendar.GetSeason(playerPos)} in the {ServerAPI.World.Calendar.GetHemisphere(playerPos)}.";
107+
108+ byPlayer.SendMessage(GlobalConstants.CurrentChatGroup, welcomeMsg, EnumChatType.OthersMessage);
109+ }
110+ else {
111+ byPlayer.SendMessage(GlobalConstants.CurrentChatGroup, $"In the year; {ServerAPI.World.Calendar.PrettyDate( )}", EnumChatType.OthersMessage);
112+ }
113+
114+ byPlayer.ServerData.CustomPlayerData[AdminToolkit._lastGameDayCountKey] = ServerAPI.World.Calendar.TotalDays.ToString("R");
115+
116+
117+ }
118+
119+ }
120+}
121+
--- a/AdminToolkit/AdminToolkit.csproj
+++ b/AdminToolkit/AdminToolkit.csproj
@@ -77,6 +77,7 @@
7777 <Compile Include="Commands\BannerControl.cs" />
7878 <Compile Include="Commands\PingerCommand.cs" />
7979 <Compile Include="Commands\VariableSpawnpoints.cs" />
80+ <Compile Include="ATK_BasicFeatures.cs" />
8081 </ItemGroup>
8182 <ItemGroup>
8283 <Folder Include="VS_libs\" />
--- a/AdminToolkit/AdminToolkitMod.cs
+++ b/AdminToolkit/AdminToolkitMod.cs
@@ -15,7 +15,10 @@ namespace AdminToolkit
1515 /// <summary>
1616 /// Admininstrators toolkit Mod system
1717 /// </summary>
18- public class AdminToolkit : ModSystem
18+ /// <remarks>
19+ /// Boilerplate; all Functions in 'ATK_BasicFeatures.cs'
20+ /// </remarks>
21+ public partial class AdminToolkit : ModSystem
1922 {
2023 /* Things it should do:
2124 * ==============
@@ -27,7 +30,7 @@ namespace AdminToolkit
2730 * [DONE] Cyclic automatic Backups
2831 * [WIP} Broadcast messages, on a schedule ??????
2932 * [???] Custom Server name : custom formats to indicate server state/time/things
30- * [IDEA]: Player inventory Insurance; recover lost items for a (two) time fee... one policy per player.
33+ * [IDEA]: Player VIRTUAL (temp) Inventory; Move Player inventory to alternate [world] D.B. as Inventory backup
3134 * [WIP]: Variable Player (re)Spawn points from a list ~ at random
3235 */
3336
@@ -96,87 +99,24 @@ namespace AdminToolkit
9699 PopulateAdminRoleTable( );
97100 PrepareServersideConfig( );
98101
99- this.ServerAPI.RegisterCommand(new RulesCommand(this.ServerAPI) );
102+ if (this.CachedConfiguration.RuleRoleChangerEnabled) { this.ServerAPI.RegisterCommand(new RulesCommand(this.ServerAPI)); }
100103 this.ServerAPI.RegisterCommand(new AdminListingCommand(this.ServerAPI) );
101104 this.ServerAPI.RegisterCommand(new BackupCycleCommand(this.ServerAPI) );
102105 //this.ServerAPI.RegisterCommand(new BannerControl(this.ServerAPI));
103106 this.ServerAPI.RegisterCommand(new PingerCommand(this.ServerAPI));
104- this.ServerAPI.RegisterCommand(new VariableSpawnpoints(this.ServerAPI));
107+ if (this.CachedConfiguration.VariableSpawnpoints) { this.ServerAPI.RegisterCommand(new VariableSpawnpoints(this.ServerAPI)); }
105108
106109 if (CachedConfiguration.BoomingVoice) {
107110 this.ServerAPI.Event.PlayerChat += BoomingVoiceOfAuthority;
108111 }
109- //TODO: Server MOTD / Name, DYNAMIC status info [season, moon-phase, events... ect]
110112
111- this.ServerAPI.Event.ServerRunPhase(EnumServerRunPhase.Shutdown, SaveConfigSettings);
112- }
113-
114- private void PopulateAdminRoleTable( )
115- {
116- AdminRoles = new List<string>( );
117- foreach (var role in ServerAPI.Server.Config.Roles) {
118-
119- if (role.PrivilegeLevel >= 200 && role.Privileges.Any(adminPriviledges.Contains )) {
120-
121- AdminRoles.Add(role.Code);
122-
123- #if DEBUG
124- Mod.Logger.VerboseDebug("Role {0} =[{1}] considerd Admin-like", role.Name, role.Code);
125- #endif
126- }
127- }
128- }
129-
130- private void PrepareServersideConfig( )
131- {
132- AdminModConfig config = ServerAPI.LoadModConfig<AdminModConfig>(_configFilename);
133-
134- if (config == null) {
135- //Regen default
136- Mod.Logger.Warning("Regenerating default config as it was missing / unparsable...");
137- ServerAPI.StoreModConfig<AdminModConfig>(new AdminModConfig( ), _configFilename);
138- config = ServerAPI.LoadModConfig<AdminModConfig>(_configFilename);
139- }
113+ this.ServerAPI.Event.PlayerNowPlaying += WelcomeMessage;
140114
141- this.CachedConfiguration = config;
142115
143- if (this.CachedConfiguration.RuleRoleChangerEnabled) { Mod.Logger.Notification("Admin toolkit; Role change on Rule accept: * ENABLED *"); }
116+ this.ServerAPI.Event.ServerRunPhase(EnumServerRunPhase.Shutdown, SaveConfigSettings);
144117 }
145118
146- /// <summary>
147- /// Makes Administrator text messages appear 'different'
148- /// </summary>
149- /// <returns>The voice of authority.</returns>
150- /// <param name="byPlayer">By player.</param>
151- /// <param name="channelId">Channel identifier.</param>
152- /// <param name="message">Message.</param>
153- /// <param name="consumed">Consumed.</param>
154- private void BoomingVoiceOfAuthority(IServerPlayer byPlayer, int channelId, ref string message, ref string data, BoolRef consumed)
155- {
156- if (AdminRoles.Contains(byPlayer.Role.Code)) {
157- //Make text lined
158- consumed.value = false;
159- StringBuilder adminMessage = new StringBuilder( );
160- foreach (char letter in message) {
161-
162- adminMessage.Append(letter);
163- if (!Char.IsWhiteSpace(letter)) {
164- //adminMessage.Append(@"̅̅̅");
165- adminMessage.Append(@"̲");
166- }
167- }
168-
169- message = adminMessage.ToString( );
170- }
171- }
172119
173- private void SaveConfigSettings( )
174- {
175- if (this.CachedConfiguration != null) {
176- Mod.Logger.Notification("Persisting configuration.");
177- ServerAPI.StoreModConfig<AdminModConfig>(this.CachedConfiguration, _configFilename);
178- }
179- }
180120
181121 }
182122 }
--- a/AdminToolkit/Commands/BackupCycleCommand.cs
+++ b/AdminToolkit/Commands/BackupCycleCommand.cs
@@ -277,7 +277,7 @@ namespace AdminToolkit
277277 {
278278 //ServerAPI.WorldManager.CurrentWorldName
279279 //ServerAPI.WorldManager.SaveGame.WorldName
280- string worldNameTrimmed = Path.GetFileNameWithoutExtension(ServerAPI.WorldManager.CurrentWorldName);
280+ string worldNameTrimmed = Path.GetFileNameWithoutExtension( String.IsNullOrEmpty(ServerAPI.WorldManager.CurrentWorldName) ? GamePaths.DefaultSaveFilenameWithoutExtension : ServerAPI.WorldManager.CurrentWorldName);
281281
282282 fileFilter = $"{worldNameTrimmed}-*{GlobalConstants.WorldSaveExtension}";
283283 Logger.VerboseDebug("File Filter: {0}", fileFilter);
--- a/AdminToolkit/Commands/RulesCommand.cs
+++ b/AdminToolkit/Commands/RulesCommand.cs
@@ -10,6 +10,8 @@ using Vintagestory.API.Server;
1010 using Vintagestory.API.Common;
1111 using Vintagestory.API.Config;
1212
13+using Vintagestory.Client.NoObf;//Perhaps this 'LanguageConfig' moves to a more general place? ...API.Config...
14+
1315 namespace AdminToolkit
1416 {
1517 public class RulesCommand : AdminModCommand
@@ -41,8 +43,8 @@ namespace AdminToolkit
4143 {
4244 Rules = new Dictionary<string, List<string>>( );
4345 RulesPath = ServerAPI.GetOrCreateDataPath(_rulesPathKey);
44-
45- string[] lang_codes = { "en", "de", "it", "fr", "pt-br", "ru" };//FIXME: this should extracted from language codes
46+ GuiCompositeSettings.LanguageConfig[] supportedLangs = ServerAPI.Assets.Get<GuiCompositeSettings.LanguageConfig[]>(new AssetLocation("lang/languages.json"));
47+ string[ ] lang_codes = supportedLangs.Select(sl => sl.Code).ToArray( );//{ "en", "de", "it", "fr", "pt-br", "ru" };
4648
4749 foreach (var languageCode in lang_codes) {
4850 //For each locale that is configured... get rules_?.txt
@@ -148,17 +150,7 @@ namespace AdminToolkit
148150 /// <param name="byPlayer">By player.</param>
149151 private void UponJoin(IServerPlayer byPlayer)
150152 {
151- if (AdminToolkit.AdminRoles.Contains(byPlayer.Role.Code)) {
152- //Annonce to all Admin\Moderator is here.
153-
154- StringBuilder adminMessage = new StringBuilder( );
155-
156- adminMessage.AppendFormat("<font color='{1}' weight='bold'>«{0}» {2}</font> Present.", byPlayer.Role.Name, byPlayer.Role.Color.Name, byPlayer.PlayerName);
157-
158- ServerAPI.SendMessageToGroup(GlobalConstants.AllChatGroups, adminMessage.ToString( ), EnumChatType.AllGroups);
159-
160- byPlayer.ServerData.CustomPlayerData[AdminToolkit._lastLoginKey] = DateTimeOffset.UtcNow.ToString("u");
161- } else {
153+ if (!AdminToolkit.AdminRoles.Contains(byPlayer.Role.Code)) {
162154 //For regular players
163155 if (RulesCommand.CheckRuleAccepted(byPlayer) == false) {
164156 //TODO: localize
@@ -169,22 +161,6 @@ namespace AdminToolkit
169161 }
170162 }
171163 }
172-
173- double elapsedDays = 0D;
174- string elapsedDayStr;
175-
176- if (byPlayer.ServerData.CustomPlayerData.TryGetValue(AdminToolkit._lastGameDayCountKey, out elapsedDayStr)
177- &&
178- double.TryParse(elapsedDayStr, out elapsedDays))
179- {
180- elapsedDays = ServerAPI.World.Calendar.TotalDays - elapsedDays;
181- byPlayer.SendMessage(GlobalConstants.CurrentChatGroup, $"Meantime... {elapsedDays:F1} days have passed. {ServerAPI.World.AllOnlinePlayers.Length} Players online.", EnumChatType.OthersMessage);
182- } else
183- {
184- byPlayer.SendMessage(GlobalConstants.CurrentChatGroup, $"In the year; {ServerAPI.World.Calendar.PrettyDate( )}", EnumChatType.OthersMessage);
185- }
186-
187- byPlayer.ServerData.CustomPlayerData[AdminToolkit._lastGameDayCountKey] = ServerAPI.World.Calendar.TotalDays.ToString("R");
188164 }
189165
190166 private void PlayerAcceptsRulesAction(IServerPlayer byPlayer )