• R/O
  • HTTP
  • SSH
  • HTTPS

コミット

タグ

よく使われているワード(クリックで追加)

javaandroidc++linuxc#objective-ccocoa誰得qtrubybathyscaphegamephpguiwindowsc翻訳pythonomegattwitterframeworkbtronarduinovb.net計画中(planning stage)directxpreviewertestゲームエンジンdom

Administrator's Toolkit VS plugin


コミットメタ情報

リビジョンa72b240bbc1cf24ed6e43542240d183365e5b6ab (tree)
日時2019-07-12 11:56:53
作者melchior <melchior@user...>
コミッターmelchior

ログメッセージ

Refactored admin list into seperate command class,
code changes to facilitate seperate command classes

変更サマリ

差分

--- /dev/null
+++ b/AdminToolkit/AdminListingCommand.cs
@@ -0,0 +1,54 @@
1+using System;
2+using System.Text;
3+
4+
5+using Vintagestory.API.Common.Entities;
6+using Vintagestory.API.Server;
7+using Vintagestory.API.Common;
8+
9+
10+namespace AdminToolkit
11+{
12+ public class AdminListingCommand : ServerChatCommand
13+ {
14+ private ICoreServerAPI ServerAPI;
15+
16+ public AdminListingCommand(ICoreServerAPI _serverAPI )
17+ {
18+ ServerAPI = _serverAPI;
19+ this.Command = "admins";
20+ this.Description = "List of Server Administrators";
21+ this.handler += AdminsitratorListing;
22+ }
23+
24+
25+ private void AdminsitratorListing(IServerPlayer player, int groupId, CmdArgs args)
26+ {
27+ player.SendMessage(groupId, "Listing Administrators:", EnumChatType.CommandSuccess);
28+
29+ StringBuilder msgLine = new StringBuilder( );
30+
31+ foreach (var srvPlayer in ServerAPI.Server.Players) {
32+ if (AdminToolkit.AdminRoles.Contains(srvPlayer.Role.Code)) {
33+
34+ msgLine.AppendFormat("<font color='{2}'>[{0}]</font> -- \"{1}\" ", srvPlayer.Role.Name, srvPlayer.PlayerName, srvPlayer.Role.Color.Name);
35+
36+ if (srvPlayer.ConnectionState == EnumClientState.Playing) {
37+ msgLine.AppendFormat("IS: <font color='lime'>*{0}*</font>", srvPlayer.ConnectionState);
38+ } else {
39+ msgLine.AppendFormat("IS: <font color='yellow'>{0}</font>", srvPlayer.ConnectionState);
40+ }
41+
42+ if (srvPlayer.ServerData.CustomPlayerData.ContainsKey(AdminToolkit._lastLoginKey)) {
43+ msgLine.AppendFormat(" Last Login: {0}", srvPlayer.ServerData.CustomPlayerData[AdminToolkit._lastLoginKey]);
44+ }
45+ msgLine.AppendLine( );
46+ }
47+ }
48+
49+ player.SendMessage(groupId, msgLine.ToString( ), EnumChatType.CommandSuccess);
50+ }
51+
52+ }
53+}
54+
--- a/AdminToolkit/AdminToolkit.csproj
+++ b/AdminToolkit/AdminToolkit.csproj
@@ -61,6 +61,7 @@
6161 <ItemGroup>
6262 <Compile Include="AdminToolkitMod.cs" />
6363 <Compile Include="Properties\AssemblyInfo.cs" />
64+ <Compile Include="AdminListingCommand.cs" />
6465 </ItemGroup>
6566 <ItemGroup>
6667 <Folder Include="VS_libs\" />
--- a/AdminToolkit/AdminToolkitMod.cs
+++ b/AdminToolkit/AdminToolkitMod.cs
@@ -29,7 +29,7 @@ namespace AdminToolkit
2929 private ICoreAPI API { get; set; }
3030 private ICoreServerAPI ServerAPI { get; set; }
3131
32- private readonly string[] adminPriviledges = {
32+ internal readonly string[] adminPriviledges = {
3333 Privilege.buildblockseverywhere,
3434 Privilege.useblockseverywhere,
3535 Privilege.gamemode,
@@ -51,11 +51,11 @@ namespace AdminToolkit
5151 };
5252
5353 private const string _ruleAcceptKey = @"RulesAccepted";
54- private const string _lastLoginKey = @"LastLogin";
54+ internal const string _lastLoginKey = @"LastLogin";
5555 private const string _rulesPathKey = @"Rules";
5656 private const string _acceptKeyword = @"accept";
5757
58- internal List<string> AdminRoles;
58+ internal static List<string> AdminRoles;
5959 private string RulesPath;
6060 private Dictionary<string, List<string>> Rules;
6161
@@ -84,8 +84,8 @@ namespace AdminToolkit
8484
8585
8686 this.ServerAPI.RegisterCommand("rules", "Server Rules", "[accept]", ServerRulesCommand);
87- this.ServerAPI.RegisterCommand("admins", "List of Server Administrators", string.Empty, AdminsitratorListing);
88-
87+ this.ServerAPI.RegisterCommand(new AdminListingCommand(this.ServerAPI) );
88+ this.ServerAPI.RegisterCommand("say", "Say/Announce with Formated text", string.Empty, Say, Privilege.commandplayer);
8989
9090 this.ServerAPI.Event.PlayerJoin += UponJoin;
9191 this.ServerAPI.Event.PlayerChat += BoomingVoiceOfAuthority;
@@ -163,33 +163,7 @@ namespace AdminToolkit
163163 }
164164 }
165165
166- private void AdminsitratorListing(IServerPlayer player, int groupId, CmdArgs args)
167- {
168- player.SendMessage(groupId, "Listing Administrators:", EnumChatType.CommandSuccess);
169-
170- StringBuilder msgLine = new StringBuilder( );
171-
172- foreach (var srvPlayer in ServerAPI.Server.Players)
173- {
174- if (AdminRoles.Contains(srvPlayer.Role.Code)) {
175-
176- msgLine.AppendFormat("<font color='{2}'>[{0}]</font> -- \"{1}\" ", srvPlayer.Role.Name, srvPlayer.PlayerName, srvPlayer.Role.Color.Name);
177-
178- if (srvPlayer.ConnectionState == EnumClientState.Playing) {
179- msgLine.AppendFormat("IS: <font color='lime'>*{0}*</font>", srvPlayer.ConnectionState);
180- } else {
181- msgLine.AppendFormat("IS: <font color='yellow'>{0}</font>", srvPlayer.ConnectionState);
182- }
183-
184- if (srvPlayer.ServerData.CustomPlayerData.ContainsKey(_lastLoginKey)) {
185- msgLine.AppendFormat(" Last Login: {0}", srvPlayer.ServerData.CustomPlayerData[_lastLoginKey]);
186- }
187- msgLine.AppendLine( );
188- }
189- }
190166
191- player.SendMessage(groupId,msgLine.ToString(), EnumChatType.CommandSuccess);
192- }
193167
194168 private void PopulateAdminRoleTable( )
195169 {
@@ -273,6 +247,75 @@ namespace AdminToolkit
273247 return message;
274248 }
275249
250+ /// <summary>
251+ /// Say the formated text to a specific player / group / all
252+ /// </summary>
253+ /// <param name="player">Player.</param>
254+ /// <param name="groupId">Group identifier.</param>
255+ /// <param name="args">Arguments.</param>
256+ private void Say(IServerPlayer player, int groupId, CmdArgs args)
257+ {
258+ if (args.Length > 0) {
259+
260+ string first = args.PopWord( );
261+ string message, name, group_name;
262+ int? group_number;
263+
264+ switch (first)
265+ {
266+ case "*all*":
267+ message = args.PopAll( );
268+
269+ ServerAPI.BroadcastMessageToAllGroups(message, EnumChatType.Notification);//Check: if it preserves format!
270+
271+ break;
272+
273+ case "name":
274+
275+ name = args.PopWord( ); //Quotes?
276+ message = args.PopAll( ); //Ugh - QUOTES?!
277+
278+ IPlayer playerByName = ServerAPI.World.AllOnlinePlayers.FirstOrDefault(plr => string.Compare(plr.PlayerName, name, StringComparison.OrdinalIgnoreCase) == 0);
279+
280+ if (playerByName != null)
281+ {
282+ ServerAPI.SendMessage(playerByName, GlobalConstants.CurrentChatGroup, message, EnumChatType.OthersMessage);
283+ }
284+ else
285+ {
286+ player.SendMessage(GlobalConstants.CurrentChatGroup, $"No player found by name '{name}'", EnumChatType.CommandError);
287+ }
288+
289+ break;
290+
291+ case "group-name":
292+
293+ group_name = args.PopWord( );//More quotes?!
294+ message = args.PopAll( ); //Ugh - QUOTES?!
295+
296+ //GET: PlayerGroupMembership
297+
298+ //ServerAPI.SendMessageToGroup(0, message, EnumChatType.OthersMessage );
299+
300+ break;
301+
302+ case "group-number":
303+ group_number = args.PopInt();
304+ message = args.PopAll( ); //Ugh - QUOTES?!
305+
306+ ServerAPI.SendMessageToGroup(group_number.Value,message, EnumChatType.OthersMessage );
307+
308+ break;
309+
310+ default:
311+ player.SendMessage(GlobalConstants.CurrentChatGroup, @"/Say command not formated correctly.", EnumChatType.CommandError);
312+ break;
313+ }
314+
315+
316+ }
317+ }
318+
276319 private static bool CheckRuleAccepted(IServerPlayer byPlayer)
277320 {
278321 if (byPlayer.ServerData.CustomPlayerData.ContainsKey(_ruleAcceptKey)) {