use custom timespan numericupdown

This commit is contained in:
UnknownShadow200 2018-07-18 17:16:33 +10:00
parent ca308212d6
commit 0d7ed870da
41 changed files with 379 additions and 533 deletions

View File

@ -0,0 +1,118 @@
/*
Copyright 2015 MCGalaxy
Dual-licensed under the Educational Community License, Version 2.0 and
the GNU General Public License, Version 3 (the "Licenses"); you may
not use this file except in compliance with the Licenses. You may
obtain a copy of the Licenses at
http://www.opensource.org/licenses/ecl2.php
http://www.gnu.org/licenses/gpl-3.0.html
Unless required by applicable law or agreed to in writing,
software distributed under the Licenses are distributed on an "AS IS"
BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
or implied. See the Licenses for the specific language governing
permissions and limitations under the Licenses.
*/
using System;
using System.ComponentModel;
using System.Globalization;
using System.Media;
using System.Windows.Forms;
namespace MCGalaxy.Gui {
[DefaultBindingProperty("Seconds"), DefaultEvent("ValueChanged"), DefaultProperty("Seconds")]
public class TimespanUpDown : UpDownBase, ISupportInitialize {
long totalSecs;
EventHandler onValueChanged;
bool initializing;
public event EventHandler ValueChanged {
add { onValueChanged = (EventHandler)Delegate.Combine(onValueChanged, value); }
remove { onValueChanged = (EventHandler)Delegate.Remove(onValueChanged, value); }
}
[Bindable(true)]
public long Seconds {
get {
if (UserEdit) ValidateEditText();
return totalSecs;
}
set {
if (value == totalSecs) return;
if (value < 0) value = 0;
totalSecs = value;
if (onValueChanged != null) onValueChanged(this, EventArgs.Empty);
UpdateEditText();
}
}
public TimeSpan Value {
get { return TimeSpan.FromSeconds(Seconds); }
set { Seconds = value.SecondsLong(); }
}
public TimespanUpDown() { Text = "0s"; }
public void BeginInit() { initializing = true; }
public void EndInit() {
initializing = false;
Seconds = totalSecs;
UpdateEditText();
}
protected override void OnTextBoxKeyPress(object source, KeyPressEventArgs e) {
base.OnTextBoxKeyPress(source, e);
// don't intercept ctrl+A, ctrl+C etc
if ((Control.ModifierKeys & (Keys.Control | Keys.Alt)) != Keys.None) return;
// always allowed to input numbers
if (e.KeyChar == '\b' || char.IsDigit(e.KeyChar)) return;
try {
(Text + e.KeyChar.ToString()).ParseShort("s");
} catch {
e.Handled = true;
SystemSounds.Beep.Play();
}
}
protected override void OnLostFocus(EventArgs e) {
base.OnLostFocus(e);
if (UserEdit) UpdateEditText();
}
public override void DownButton() {
if (UserEdit) ParseEditText();
if (totalSecs <= 0) totalSecs = 1;
Seconds = totalSecs - 1;
}
public override void UpButton() {
if (UserEdit) ParseEditText();
if (totalSecs == long.MaxValue) return;
Seconds = totalSecs + 1;
}
void ParseEditText() {
try {
Value = Text.ParseShort("s");
} catch {
} finally {
UserEdit = false;
}
}
protected override void UpdateEditText() {
if (initializing) return;
if (UserEdit) ParseEditText();
Text = TimeSpan.FromSeconds(totalSecs).Shorten(true, true);
}
protected override void ValidateEditText() {
ParseEditText();
UpdateEditText();
}
}
}

View File

@ -54,6 +54,10 @@
<Compile Include="..\CLI\CLI.cs">
<Link>CLI.cs</Link>
</Compile>
<Compile Include="Controls\ColoredTextBox.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="Controls\TimespanUpDown.cs" />
<Compile Include="Descriptors.cs" />
<Compile Include="GuiPerms.cs" />
<Compile Include="Popups\ColorSelector.cs" />
@ -105,9 +109,6 @@
<Compile Include="Settings\PlayerProperties.cs" />
<Compile Include="Settings\TypeConverters.cs" />
<Compile Include="Settings\ZombieProperties.cs" />
<Compile Include="ColoredTextBox.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="..\MCGalaxy\properties\AssemblyInfo.cs" />
<Compile Include="UPnP.cs" />
<Compile Include="Window\Window.cs">
@ -120,9 +121,6 @@
<Compile Include="Window\Window.Main.cs" />
<Compile Include="Window\Window.Map.cs" />
<Compile Include="Window\Window.Players.cs" />
<EmbeddedResource Include="Popups\PortTools.resx">
<DependentUpon>PortTools.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Window\Window.resx">
<DependentUpon>Window.cs</DependentUpon>
<SubType>Designer</SubType>
@ -142,6 +140,7 @@
<Content Include="Galaxy.ico" />
</ItemGroup>
<ItemGroup>
<Folder Include="Controls" />
<Folder Include="Popups" />
<Folder Include="PropertyWindow" />
<Folder Include="Window" />

View File

@ -1,124 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<assembly alias="System.Drawing" name="System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<data name="toolTip1.TrayLocation" type="System.Drawing.Point, System.Drawing">
<value>17, 17</value>
</data>
</root>

View File

@ -132,7 +132,7 @@ namespace MCGalaxy.Gui
this.ls_numHeight = new System.Windows.Forms.NumericUpDown();
this.ls_cbMain = new System.Windows.Forms.CheckBox();
this.ls_cbStart = new System.Windows.Forms.CheckBox();
this.rank_numAfk = new System.Windows.Forms.NumericUpDown();
this.rank_numAfk = new MCGalaxy.Gui.TimespanUpDown();
this.sec_cbLogNotes = new System.Windows.Forms.CheckBox();
this.sec_cbChatAuto = new System.Windows.Forms.CheckBox();
this.pageBlocks = new System.Windows.Forms.TabPage();
@ -173,7 +173,6 @@ namespace MCGalaxy.Gui
this.rank_lblDefault = new System.Windows.Forms.Label();
this.rank_grpMisc = new System.Windows.Forms.GroupBox();
this.rank_cbAfk = new System.Windows.Forms.CheckBox();
this.rank_lblAfk = new System.Windows.Forms.Label();
this.rank_lblPrefix = new System.Windows.Forms.Label();
this.rank_lblPerm = new System.Windows.Forms.Label();
this.rank_lblMOTD = new System.Windows.Forms.Label();
@ -345,6 +344,8 @@ namespace MCGalaxy.Gui
this.tw_numGrace = new System.Windows.Forms.NumericUpDown();
this.tw_cbGrace = new System.Windows.Forms.CheckBox();
this.tw_grpScores = new System.Windows.Forms.GroupBox();
this.tw_lblMulti = new System.Windows.Forms.Label();
this.tw_lblAssist = new System.Windows.Forms.Label();
this.tw_cbStreaks = new System.Windows.Forms.CheckBox();
this.tw_numMultiKills = new System.Windows.Forms.NumericUpDown();
this.tw_numScoreAssists = new System.Windows.Forms.NumericUpDown();
@ -402,31 +403,25 @@ namespace MCGalaxy.Gui
this.sec_lblChatOnMute = new System.Windows.Forms.Label();
this.sec_numChatMsgs = new System.Windows.Forms.NumericUpDown();
this.sec_lblChatOnMsgs = new System.Windows.Forms.Label();
this.sec_numChatSecs = new System.Windows.Forms.NumericUpDown();
this.sec_lblChatOnSecs = new System.Windows.Forms.Label();
this.sec_numChatSecs = new MCGalaxy.Gui.TimespanUpDown();
this.sec_lblChatForMute = new System.Windows.Forms.Label();
this.sec_numChatMute = new System.Windows.Forms.NumericUpDown();
this.sec_lblChatForSecs = new System.Windows.Forms.Label();
this.sec_numChatMute = new MCGalaxy.Gui.TimespanUpDown();
this.sec_grpCmd = new System.Windows.Forms.GroupBox();
this.sec_cbCmdAuto = new System.Windows.Forms.CheckBox();
this.sec_lblCmdOnMute = new System.Windows.Forms.Label();
this.sec_numCmdMsgs = new System.Windows.Forms.NumericUpDown();
this.sec_lblCmdOnMsgs = new System.Windows.Forms.Label();
this.sec_numCmdSecs = new System.Windows.Forms.NumericUpDown();
this.sec_lblCmdOnSecs = new System.Windows.Forms.Label();
this.sec_numCmdSecs = new MCGalaxy.Gui.TimespanUpDown();
this.sec_lblCmdForMute = new System.Windows.Forms.Label();
this.sec_numCmdMute = new System.Windows.Forms.NumericUpDown();
this.sec_lblCmdForSecs = new System.Windows.Forms.Label();
this.sec_numCmdMute = new MCGalaxy.Gui.TimespanUpDown();
this.sec_grpIP = new System.Windows.Forms.GroupBox();
this.sec_cbIPAuto = new System.Windows.Forms.CheckBox();
this.sec_lblIPOnMute = new System.Windows.Forms.Label();
this.sec_numIPMsgs = new System.Windows.Forms.NumericUpDown();
this.sec_lblIPOnMsgs = new System.Windows.Forms.Label();
this.sec_numIPSecs = new System.Windows.Forms.NumericUpDown();
this.sec_lblIPOnSecs = new System.Windows.Forms.Label();
this.sec_numIPSecs = new MCGalaxy.Gui.TimespanUpDown();
this.sec_lblIPForMute = new System.Windows.Forms.Label();
this.sec_numIPMute = new System.Windows.Forms.NumericUpDown();
this.sec_lblIPForSecs = new System.Windows.Forms.Label();
this.sec_numIPMute = new MCGalaxy.Gui.TimespanUpDown();
this.sec_grpOther = new System.Windows.Forms.GroupBox();
this.sec_lblRank = new System.Windows.Forms.Label();
this.sec_grpBlocks = new System.Windows.Forms.GroupBox();
@ -434,10 +429,7 @@ namespace MCGalaxy.Gui
this.sec_lblBlocksOnMute = new System.Windows.Forms.Label();
this.sec_numBlocksMsgs = new System.Windows.Forms.NumericUpDown();
this.sec_lblBlocksOnMsgs = new System.Windows.Forms.Label();
this.sec_numBlocksSecs = new System.Windows.Forms.NumericUpDown();
this.sec_lblBlocksOnSecs = new System.Windows.Forms.Label();
this.tw_lblAssist = new System.Windows.Forms.Label();
this.tw_lblMulti = new System.Windows.Forms.Label();
this.sec_numBlocksSecs = new MCGalaxy.Gui.TimespanUpDown();
this.pageChat.SuspendLayout();
this.chat_grpTab.SuspendLayout();
this.chat_grpMessages.SuspendLayout();
@ -1491,14 +1483,11 @@ namespace MCGalaxy.Gui
// rank_numAfk
//
this.rank_numAfk.Location = new System.Drawing.Point(113, 102);
this.rank_numAfk.Maximum = new decimal(new int[] {
100000,
0,
0,
0});
this.rank_numAfk.Name = "rank_numAfk";
this.rank_numAfk.Size = new System.Drawing.Size(61, 21);
this.rank_numAfk.Size = new System.Drawing.Size(62, 21);
this.rank_numAfk.TabIndex = 23;
this.rank_numAfk.Text = "0s";
this.rank_numAfk.Seconds = ((long)(0));
this.rank_numAfk.ValueChanged += new System.EventHandler(this.rank_numAfk_ValueChanged);
//
// sec_cbLogNotes
@ -1913,7 +1902,6 @@ namespace MCGalaxy.Gui
//
this.rank_grpMisc.Controls.Add(this.rank_numAfk);
this.rank_grpMisc.Controls.Add(this.rank_cbAfk);
this.rank_grpMisc.Controls.Add(this.rank_lblAfk);
this.rank_grpMisc.Controls.Add(this.rank_lblPrefix);
this.rank_grpMisc.Controls.Add(this.rank_txtPrefix);
this.rank_grpMisc.Controls.Add(this.rank_lblPerm);
@ -1941,16 +1929,6 @@ namespace MCGalaxy.Gui
this.rank_cbAfk.UseVisualStyleBackColor = true;
this.rank_cbAfk.CheckedChanged += new System.EventHandler(this.rank_cbAfk_CheckedChanged);
//
// rank_lblAfk
//
this.rank_lblAfk.AutoSize = true;
this.rank_lblAfk.Location = new System.Drawing.Point(176, 106);
this.rank_lblAfk.Name = "rank_lblAfk";
this.rank_lblAfk.Size = new System.Drawing.Size(46, 13);
this.rank_lblAfk.TabIndex = 23;
this.rank_lblAfk.Text = "minutes";
this.rank_lblAfk.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
//
// rank_lblPrefix
//
this.rank_lblPrefix.AutoSize = true;
@ -3802,6 +3780,24 @@ namespace MCGalaxy.Gui
this.tw_grpScores.TabStop = false;
this.tw_grpScores.Text = "Scores";
//
// tw_lblMulti
//
this.tw_lblMulti.AutoSize = true;
this.tw_lblMulti.Location = new System.Drawing.Point(157, 47);
this.tw_lblMulti.Name = "tw_lblMulti";
this.tw_lblMulti.Size = new System.Drawing.Size(79, 13);
this.tw_lblMulti.TabIndex = 10;
this.tw_lblMulti.Text = "Multikill bonus:";
//
// tw_lblAssist
//
this.tw_lblAssist.AutoSize = true;
this.tw_lblAssist.Location = new System.Drawing.Point(168, 20);
this.tw_lblAssist.Name = "tw_lblAssist";
this.tw_lblAssist.Size = new System.Drawing.Size(69, 13);
this.tw_lblAssist.TabIndex = 9;
this.tw_lblAssist.Text = "Assist bonus:";
//
// tw_cbStreaks
//
this.tw_cbStreaks.AutoSize = true;
@ -4380,10 +4376,8 @@ namespace MCGalaxy.Gui
this.sec_grpChat.Controls.Add(this.sec_numChatMsgs);
this.sec_grpChat.Controls.Add(this.sec_lblChatOnMsgs);
this.sec_grpChat.Controls.Add(this.sec_numChatSecs);
this.sec_grpChat.Controls.Add(this.sec_lblChatOnSecs);
this.sec_grpChat.Controls.Add(this.sec_lblChatForMute);
this.sec_grpChat.Controls.Add(this.sec_numChatMute);
this.sec_grpChat.Controls.Add(this.sec_lblChatForSecs);
this.sec_grpChat.Location = new System.Drawing.Point(14, 6);
this.sec_grpChat.Name = "sec_grpChat";
this.sec_grpChat.Size = new System.Drawing.Size(238, 111);
@ -4429,28 +4423,11 @@ namespace MCGalaxy.Gui
// sec_numChatSecs
//
this.sec_numChatSecs.Location = new System.Drawing.Point(156, 45);
this.sec_numChatSecs.Maximum = new decimal(new int[] {
10000,
0,
0,
0});
this.sec_numChatSecs.Name = "sec_numChatSecs";
this.sec_numChatSecs.Size = new System.Drawing.Size(42, 21);
this.sec_numChatSecs.Size = new System.Drawing.Size(62, 21);
this.sec_numChatSecs.TabIndex = 34;
this.sec_numChatSecs.Value = new decimal(new int[] {
5,
0,
0,
0});
//
// sec_lblChatOnSecs
//
this.sec_lblChatOnSecs.AutoSize = true;
this.sec_lblChatOnSecs.Location = new System.Drawing.Point(199, 48);
this.sec_lblChatOnSecs.Name = "sec_lblChatOnSecs";
this.sec_lblChatOnSecs.Size = new System.Drawing.Size(28, 13);
this.sec_lblChatOnSecs.TabIndex = 33;
this.sec_lblChatOnSecs.Text = "secs";
this.sec_numChatSecs.Text = "5s";
this.sec_numChatSecs.Seconds = ((long)(5));
//
// sec_lblChatForMute
//
@ -4464,28 +4441,11 @@ namespace MCGalaxy.Gui
// sec_numChatMute
//
this.sec_numChatMute.Location = new System.Drawing.Point(53, 79);
this.sec_numChatMute.Maximum = new decimal(new int[] {
1000000,
0,
0,
0});
this.sec_numChatMute.Name = "sec_numChatMute";
this.sec_numChatMute.Size = new System.Drawing.Size(37, 21);
this.sec_numChatMute.Size = new System.Drawing.Size(62, 21);
this.sec_numChatMute.TabIndex = 32;
this.sec_numChatMute.Value = new decimal(new int[] {
60,
0,
0,
0});
//
// sec_lblChatForSecs
//
this.sec_lblChatForSecs.AutoSize = true;
this.sec_lblChatForSecs.Location = new System.Drawing.Point(91, 83);
this.sec_lblChatForSecs.Name = "sec_lblChatForSecs";
this.sec_lblChatForSecs.Size = new System.Drawing.Size(46, 13);
this.sec_lblChatForSecs.TabIndex = 33;
this.sec_lblChatForSecs.Text = "seconds";
this.sec_numChatMute.Text = "1m";
this.sec_numChatMute.Seconds = ((long)(60));
//
// sec_grpCmd
//
@ -4494,10 +4454,8 @@ namespace MCGalaxy.Gui
this.sec_grpCmd.Controls.Add(this.sec_numCmdMsgs);
this.sec_grpCmd.Controls.Add(this.sec_lblCmdOnMsgs);
this.sec_grpCmd.Controls.Add(this.sec_numCmdSecs);
this.sec_grpCmd.Controls.Add(this.sec_lblCmdOnSecs);
this.sec_grpCmd.Controls.Add(this.sec_lblCmdForMute);
this.sec_grpCmd.Controls.Add(this.sec_numCmdMute);
this.sec_grpCmd.Controls.Add(this.sec_lblCmdForSecs);
this.sec_grpCmd.Location = new System.Drawing.Point(14, 123);
this.sec_grpCmd.Name = "sec_grpCmd";
this.sec_grpCmd.Size = new System.Drawing.Size(238, 110);
@ -4554,28 +4512,11 @@ namespace MCGalaxy.Gui
// sec_numCmdSecs
//
this.sec_numCmdSecs.Location = new System.Drawing.Point(161, 45);
this.sec_numCmdSecs.Maximum = new decimal(new int[] {
10000,
0,
0,
0});
this.sec_numCmdSecs.Name = "sec_numCmdSecs";
this.sec_numCmdSecs.Size = new System.Drawing.Size(42, 21);
this.sec_numCmdSecs.Size = new System.Drawing.Size(62, 21);
this.sec_numCmdSecs.TabIndex = 34;
this.sec_numCmdSecs.Value = new decimal(new int[] {
1,
0,
0,
0});
//
// sec_lblCmdOnSecs
//
this.sec_lblCmdOnSecs.AutoSize = true;
this.sec_lblCmdOnSecs.Location = new System.Drawing.Point(204, 48);
this.sec_lblCmdOnSecs.Name = "sec_lblCmdOnSecs";
this.sec_lblCmdOnSecs.Size = new System.Drawing.Size(28, 13);
this.sec_lblCmdOnSecs.TabIndex = 33;
this.sec_lblCmdOnSecs.Text = "secs";
this.sec_numCmdSecs.Text = "1s";
this.sec_numCmdSecs.Seconds = ((long)(1));
//
// sec_lblCmdForMute
//
@ -4589,28 +4530,11 @@ namespace MCGalaxy.Gui
// sec_numCmdMute
//
this.sec_numCmdMute.Location = new System.Drawing.Point(53, 79);
this.sec_numCmdMute.Maximum = new decimal(new int[] {
1000000,
0,
0,
0});
this.sec_numCmdMute.Name = "sec_numCmdMute";
this.sec_numCmdMute.Size = new System.Drawing.Size(37, 21);
this.sec_numCmdMute.Size = new System.Drawing.Size(62, 21);
this.sec_numCmdMute.TabIndex = 32;
this.sec_numCmdMute.Value = new decimal(new int[] {
60,
0,
0,
0});
//
// sec_lblCmdForSecs
//
this.sec_lblCmdForSecs.AutoSize = true;
this.sec_lblCmdForSecs.Location = new System.Drawing.Point(91, 83);
this.sec_lblCmdForSecs.Name = "sec_lblCmdForSecs";
this.sec_lblCmdForSecs.Size = new System.Drawing.Size(46, 13);
this.sec_lblCmdForSecs.TabIndex = 33;
this.sec_lblCmdForSecs.Text = "seconds";
this.sec_numCmdMute.Text = "1m";
this.sec_numCmdMute.Seconds = ((long)(60));
//
// sec_grpIP
//
@ -4619,10 +4543,8 @@ namespace MCGalaxy.Gui
this.sec_grpIP.Controls.Add(this.sec_numIPMsgs);
this.sec_grpIP.Controls.Add(this.sec_lblIPOnMsgs);
this.sec_grpIP.Controls.Add(this.sec_numIPSecs);
this.sec_grpIP.Controls.Add(this.sec_lblIPOnSecs);
this.sec_grpIP.Controls.Add(this.sec_lblIPForMute);
this.sec_grpIP.Controls.Add(this.sec_numIPMute);
this.sec_grpIP.Controls.Add(this.sec_lblIPForSecs);
this.sec_grpIP.Location = new System.Drawing.Point(14, 240);
this.sec_grpIP.Name = "sec_grpIP";
this.sec_grpIP.Size = new System.Drawing.Size(238, 110);
@ -4679,28 +4601,11 @@ namespace MCGalaxy.Gui
// sec_numIPSecs
//
this.sec_numIPSecs.Location = new System.Drawing.Point(166, 45);
this.sec_numIPSecs.Maximum = new decimal(new int[] {
10000,
0,
0,
0});
this.sec_numIPSecs.Name = "sec_numIPSecs";
this.sec_numIPSecs.Size = new System.Drawing.Size(42, 21);
this.sec_numIPSecs.Size = new System.Drawing.Size(62, 21);
this.sec_numIPSecs.TabIndex = 34;
this.sec_numIPSecs.Value = new decimal(new int[] {
1,
0,
0,
0});
//
// sec_lblIPOnSecs
//
this.sec_lblIPOnSecs.AutoSize = true;
this.sec_lblIPOnSecs.Location = new System.Drawing.Point(209, 48);
this.sec_lblIPOnSecs.Name = "sec_lblIPOnSecs";
this.sec_lblIPOnSecs.Size = new System.Drawing.Size(28, 13);
this.sec_lblIPOnSecs.TabIndex = 33;
this.sec_lblIPOnSecs.Text = "secs";
this.sec_numIPSecs.Text = "1s";
this.sec_numIPSecs.Seconds = ((long)(1));
//
// sec_lblIPForMute
//
@ -4714,28 +4619,11 @@ namespace MCGalaxy.Gui
// sec_numIPMute
//
this.sec_numIPMute.Location = new System.Drawing.Point(53, 79);
this.sec_numIPMute.Maximum = new decimal(new int[] {
1000000,
0,
0,
0});
this.sec_numIPMute.Name = "sec_numIPMute";
this.sec_numIPMute.Size = new System.Drawing.Size(42, 21);
this.sec_numIPMute.Size = new System.Drawing.Size(62, 21);
this.sec_numIPMute.TabIndex = 32;
this.sec_numIPMute.Value = new decimal(new int[] {
300,
0,
0,
0});
//
// sec_lblIPForSecs
//
this.sec_lblIPForSecs.AutoSize = true;
this.sec_lblIPForSecs.Location = new System.Drawing.Point(96, 83);
this.sec_lblIPForSecs.Name = "sec_lblIPForSecs";
this.sec_lblIPForSecs.Size = new System.Drawing.Size(46, 13);
this.sec_lblIPForSecs.TabIndex = 33;
this.sec_lblIPForSecs.Text = "seconds";
this.sec_numIPMute.Text = "5m";
this.sec_numIPMute.Seconds = ((long)(300));
//
// sec_grpOther
//
@ -4767,7 +4655,6 @@ namespace MCGalaxy.Gui
this.sec_grpBlocks.Controls.Add(this.sec_numBlocksMsgs);
this.sec_grpBlocks.Controls.Add(this.sec_lblBlocksOnMsgs);
this.sec_grpBlocks.Controls.Add(this.sec_numBlocksSecs);
this.sec_grpBlocks.Controls.Add(this.sec_lblBlocksOnSecs);
this.sec_grpBlocks.Location = new System.Drawing.Point(264, 150);
this.sec_grpBlocks.Name = "sec_grpBlocks";
this.sec_grpBlocks.Size = new System.Drawing.Size(217, 83);
@ -4824,46 +4711,11 @@ namespace MCGalaxy.Gui
// sec_numBlocksSecs
//
this.sec_numBlocksSecs.Location = new System.Drawing.Point(142, 45);
this.sec_numBlocksSecs.Maximum = new decimal(new int[] {
10000,
0,
0,
0});
this.sec_numBlocksSecs.Name = "sec_numBlocksSecs";
this.sec_numBlocksSecs.Size = new System.Drawing.Size(42, 21);
this.sec_numBlocksSecs.Size = new System.Drawing.Size(62, 21);
this.sec_numBlocksSecs.TabIndex = 34;
this.sec_numBlocksSecs.Value = new decimal(new int[] {
5,
0,
0,
0});
//
// sec_lblBlocksOnSecs
//
this.sec_lblBlocksOnSecs.AutoSize = true;
this.sec_lblBlocksOnSecs.Location = new System.Drawing.Point(185, 48);
this.sec_lblBlocksOnSecs.Name = "sec_lblBlocksOnSecs";
this.sec_lblBlocksOnSecs.Size = new System.Drawing.Size(28, 13);
this.sec_lblBlocksOnSecs.TabIndex = 33;
this.sec_lblBlocksOnSecs.Text = "secs";
//
// tw_lblAssist
//
this.tw_lblAssist.AutoSize = true;
this.tw_lblAssist.Location = new System.Drawing.Point(168, 20);
this.tw_lblAssist.Name = "tw_lblAssist";
this.tw_lblAssist.Size = new System.Drawing.Size(69, 13);
this.tw_lblAssist.TabIndex = 9;
this.tw_lblAssist.Text = "Assist bonus:";
//
// tw_lblMulti
//
this.tw_lblMulti.AutoSize = true;
this.tw_lblMulti.Location = new System.Drawing.Point(157, 47);
this.tw_lblMulti.Name = "tw_lblMulti";
this.tw_lblMulti.Size = new System.Drawing.Size(79, 13);
this.tw_lblMulti.TabIndex = 10;
this.tw_lblMulti.Text = "Multikill bonus:";
this.sec_numBlocksSecs.Text = "5s";
this.sec_numBlocksSecs.Seconds = ((long)(5));
//
// PropertyWindow
//
@ -5134,8 +4986,7 @@ namespace MCGalaxy.Gui
private System.Windows.Forms.Label rank_lblCopy;
private System.Windows.Forms.NumericUpDown rank_numCopy;
private System.Windows.Forms.CheckBox rank_cbAfk;
private System.Windows.Forms.NumericUpDown rank_numAfk;
private System.Windows.Forms.Label rank_lblAfk;
private MCGalaxy.Gui.TimespanUpDown rank_numAfk;
private System.Windows.Forms.Label rank_lblUndo;
private System.Windows.Forms.NumericUpDown rank_numUndo;
private System.Windows.Forms.Label rank_lblDraw;
@ -5249,32 +5100,26 @@ namespace MCGalaxy.Gui
private System.Windows.Forms.GroupBox sec_grpChat;
private System.Windows.Forms.CheckBox sec_cbChatAuto;
private System.Windows.Forms.Label sec_lblChatForMute;
private System.Windows.Forms.NumericUpDown sec_numChatMute;
private MCGalaxy.Gui.TimespanUpDown sec_numChatMute;
private System.Windows.Forms.Label sec_lblChatOnMsgs;
private System.Windows.Forms.NumericUpDown sec_numChatMsgs;
private System.Windows.Forms.Label sec_lblChatOnMute;
private System.Windows.Forms.NumericUpDown sec_numChatSecs;
private System.Windows.Forms.Label sec_lblChatOnSecs;
private System.Windows.Forms.Label sec_lblChatForSecs;
private MCGalaxy.Gui.TimespanUpDown sec_numChatSecs;
private System.Windows.Forms.GroupBox sec_grpCmd;
private System.Windows.Forms.CheckBox sec_cbCmdAuto;
private System.Windows.Forms.Label sec_lblCmdForSecs;
private System.Windows.Forms.NumericUpDown sec_numCmdMute;
private MCGalaxy.Gui.TimespanUpDown sec_numCmdMute;
private System.Windows.Forms.Label sec_lblCmdForMute;
private System.Windows.Forms.Label sec_lblCmdOnSecs;
private System.Windows.Forms.NumericUpDown sec_numCmdSecs;
private MCGalaxy.Gui.TimespanUpDown sec_numCmdSecs;
private System.Windows.Forms.Label sec_lblCmdOnMsgs;
private System.Windows.Forms.NumericUpDown sec_numCmdMsgs;
private System.Windows.Forms.Label sec_lblCmdOnMute;
private System.Windows.Forms.GroupBox sec_grpIP;
private System.Windows.Forms.CheckBox sec_cbIPAuto;
private System.Windows.Forms.Label sec_lblIPForSecs;
private System.Windows.Forms.NumericUpDown sec_numIPMute;
private MCGalaxy.Gui.TimespanUpDown sec_numIPMute;
private System.Windows.Forms.Label sec_lblIPForMute;
private System.Windows.Forms.Label sec_lblIPOnSecs;
private System.Windows.Forms.NumericUpDown sec_numIPSecs;
private MCGalaxy.Gui.TimespanUpDown sec_numIPSecs;
private System.Windows.Forms.Label sec_lblIPOnMsgs;
private System.Windows.Forms.NumericUpDown sec_numIPMsgs;
private System.Windows.Forms.Label sec_lblIPOnMute;
@ -5288,8 +5133,7 @@ namespace MCGalaxy.Gui
private System.Windows.Forms.GroupBox sec_grpBlocks;
private System.Windows.Forms.CheckBox sec_cbBlocksAuto;
private System.Windows.Forms.Label sec_lblBlocksOnSecs;
private System.Windows.Forms.NumericUpDown sec_numBlocksSecs;
private MCGalaxy.Gui.TimespanUpDown sec_numBlocksSecs;
private System.Windows.Forms.Label sec_lblBlocksOnMsgs;
private System.Windows.Forms.NumericUpDown sec_numBlocksMsgs;
private System.Windows.Forms.Label sec_lblBlocksOnMute;

View File

@ -26,7 +26,7 @@ namespace MCGalaxy.Gui {
hackrank_kick.Checked = ServerConfig.HackrankKicks;
hackrank_kick_time.Text = ServerConfig.HackrankKickDelay.ToString();
afk_txtTimer.Text = ServerConfig.AutoAfkMins.ToString();
afk_txtTimer.Text = ServerConfig.AutoAfkTime.TotalSeconds.ToString();
chkPhysicsRest.Checked = ServerConfig.PhysicsRestart;
txtRP.Text = ServerConfig.PhysicsRestartLimit.ToString();
txtNormRp.Text = ServerConfig.PhysicsRestartNormLimit.ToString();
@ -46,7 +46,7 @@ namespace MCGalaxy.Gui {
ServerConfig.HackrankKicks = hackrank_kick.Checked;
ServerConfig.HackrankKickDelay = int.Parse(hackrank_kick_time.Text);
ServerConfig.AutoAfkMins = int.Parse(afk_txtTimer.Text);
ServerConfig.AutoAfkTime = TimeSpan.FromSeconds(int.Parse(afk_txtTimer.Text));
ServerConfig.PhysicsRestart = chkPhysicsRest.Checked;
ServerConfig.PhysicsRestartLimit = int.Parse(txtRP.Text);
ServerConfig.PhysicsRestartNormLimit = int.Parse(txtNormRp.Text);

View File

@ -41,9 +41,11 @@ namespace MCGalaxy.Gui {
List<Group> copiedGroups = new List<Group>();
Group curGroup;
void LoadRanks() {
rank_list.Items.Clear();
copiedGroups.Clear();
curGroup = null;
foreach (Group grp in Group.GroupList) {
copiedGroups.Add(grp.CopyConfig());
@ -60,21 +62,25 @@ namespace MCGalaxy.Gui {
void rank_btnColor_Click(object sender, EventArgs e) {
chat_ShowColorDialog(rank_btnColor, copiedGroups[rank_list.SelectedIndex].Name + " rank color");
copiedGroups[rank_list.SelectedIndex].Color = Colors.Parse(rank_btnColor.Text);
chat_ShowColorDialog(rank_btnColor, curGroup.Name + " rank color");
curGroup.Color = Colors.Parse(rank_btnColor.Text);
}
void rank_list_SelectedIndexChanged(object sender, EventArgs e) {
if (rankSupressEvents || rank_list.SelectedIndex == -1) return;
if (rankSupressEvents) return;
curGroup = null;
if (rank_list.SelectedIndex == -1) return;
Group grp = copiedGroups[rank_list.SelectedIndex];
curGroup = grp;
rank_txtName.Text = grp.Name;
rank_numPerm.Value = (int)grp.Permission;
chat_ParseColor(grp.Color, rank_btnColor);
rank_txtMOTD.Text = grp.MOTD;
rank_txtPrefix.Text = grp.Prefix;
rank_cbAfk.Checked = grp.AfkKicked;
rank_numAfk.Value = grp.AfkKickMinutes;
rank_numAfk.Value = grp.AfkKickTime;
rank_numDraw.Value = grp.DrawLimit;
rank_numUndo.Value = grp.MaxUndo;
@ -90,57 +96,56 @@ namespace MCGalaxy.Gui {
}
if (rank_txtName.Text.Length == 0) return;
copiedGroups[rank_list.SelectedIndex].Name = rank_txtName.Text;
curGroup.Name = rank_txtName.Text;
rankSupressEvents = true;
rank_list.Items[rank_list.SelectedIndex] = rank_txtName.Text + " = " + (int)copiedGroups[rank_list.SelectedIndex].Permission;
rank_list.Items[rank_list.SelectedIndex] = rank_txtName.Text + " = " + (int)curGroup.Permission;
rankSupressEvents = false;
}
void rank_numPerm_ValueChanged(object sender, EventArgs e) {
int perm = (int)rank_numPerm.Value;
copiedGroups[rank_list.SelectedIndex].Permission = (LevelPermission)perm;
curGroup.Permission = (LevelPermission)perm;
rankSupressEvents = true;
rank_list.Items[rank_list.SelectedIndex] = copiedGroups[rank_list.SelectedIndex].Name + " = " + perm;
rank_list.Items[rank_list.SelectedIndex] = curGroup.Name + " = " + perm;
rankSupressEvents = false;
}
void rank_txtMOTD_TextChanged(object sender, EventArgs e) {
copiedGroups[rank_list.SelectedIndex].MOTD = rank_txtMOTD.Text;
curGroup.MOTD = rank_txtMOTD.Text;
}
void rank_txtPrefix_TextChanged(object sender, EventArgs e) {
copiedGroups[rank_list.SelectedIndex].Prefix = rank_txtPrefix.Text;
curGroup.Prefix = rank_txtPrefix.Text;
}
void rank_cbAfk_CheckedChanged(object sender, EventArgs e) {
copiedGroups[rank_list.SelectedIndex].AfkKicked = rank_cbAfk.Checked;
curGroup.AfkKicked = rank_cbAfk.Checked;
rank_numAfk.Enabled = rank_cbAfk.Checked;
rank_lblAfk.Enabled = rank_cbAfk.Checked;
}
void rank_numAfk_ValueChanged(object sender, EventArgs e) {
copiedGroups[rank_list.SelectedIndex].AfkKickMinutes = (int)rank_numAfk.Value;
curGroup.AfkKickTime = rank_numAfk.Value;
}
void rank_numDraw_ValueChanged(object sender, EventArgs e) {
copiedGroups[rank_list.SelectedIndex].DrawLimit = (int)rank_numDraw.Value;
curGroup.DrawLimit = (int)rank_numDraw.Value;
}
void rank_numUndo_ValueChanged(object sender, EventArgs e) {
copiedGroups[rank_list.SelectedIndex].MaxUndo = (int)rank_numUndo.Value;
curGroup.MaxUndo = (int)rank_numUndo.Value;
}
void rank_numMaps_ValueChanged(object sender, EventArgs e) {
copiedGroups[rank_list.SelectedIndex].OverseerMaps = (int)rank_numMaps.Value;
curGroup.OverseerMaps = (int)rank_numMaps.Value;
}
void rank_numGen_ValueChanged(object sender, EventArgs e) {
copiedGroups[rank_list.SelectedIndex].GenVolume = (int)rank_numGen.Value;
curGroup.GenVolume = (int)rank_numGen.Value;
}
void rank_numCopy_ValueChanged(object sender, EventArgs e) {
copiedGroups[rank_list.SelectedIndex].CopySlots = (int)rank_numCopy.Value;
curGroup.CopySlots = (int)rank_numCopy.Value;
}
void rank_btnAdd_Click(object sender, EventArgs e) {

View File

@ -61,22 +61,22 @@ namespace MCGalaxy.Gui {
ServerConfig.ChatSpamCheck = sec_cbChatAuto.Checked;
ServerConfig.ChatSpamCount = (int)sec_numChatMsgs.Value;
ServerConfig.ChatSpamInterval = (int)sec_numChatSecs.Value;
ServerConfig.ChatSpamMuteTime = (int)sec_numChatMute.Value;
ServerConfig.ChatSpamInterval = sec_numChatSecs.Value;
ServerConfig.ChatSpamMuteTime = sec_numChatMute.Value;
ServerConfig.CmdSpamCheck = sec_cbCmdAuto.Checked;
ServerConfig.CmdSpamCount = (int)sec_numCmdMsgs.Value;
ServerConfig.CmdSpamInterval = (int)sec_numCmdSecs.Value;
ServerConfig.CmdSpamBlockTime = (int)sec_numCmdMute.Value;
ServerConfig.CmdSpamInterval = sec_numCmdSecs.Value;
ServerConfig.CmdSpamBlockTime = sec_numCmdMute.Value;
ServerConfig.BlockSpamCheck = sec_cbBlocksAuto.Checked;
ServerConfig.BlockSpamCount = (int)sec_numBlocksMsgs.Value;
ServerConfig.BlockSpamInterval = (int)sec_numBlocksSecs.Value;
ServerConfig.BlockSpamInterval = sec_numBlocksSecs.Value;
ServerConfig.IPSpamCheck = sec_cbIPAuto.Checked;
ServerConfig.IPSpamCount = (int)sec_numIPMsgs.Value;
ServerConfig.IPSpamInterval = (int)sec_numIPSecs.Value;
ServerConfig.IPSpamBlockTime = (int)sec_numIPMute.Value;
ServerConfig.IPSpamInterval = sec_numIPSecs.Value;
ServerConfig.IPSpamBlockTime = sec_numIPMute.Value;
}

View File

@ -170,7 +170,7 @@ namespace MCGalaxy.Commands {
}
block = Block.Parse(p, input);
if (block == Block.Invalid) p.Message("&cThere is no block \"{0}\".", input);
if (block == Block.Invalid) p.Message("%WThere is no block \"{0}\".", input);
return block != Block.Invalid;
}
@ -185,7 +185,7 @@ namespace MCGalaxy.Commands {
/// <summary> Returns whether the player is allowed to place/modify/delete the given block. </summary>
/// <remarks> Outputs information of which ranks can modify the block if not. </remarks>
public static bool IsBlockAllowed(Player p, string action, BlockID block) {
if (p.group.Blocks[block]) return true;
if (p.group.Blocks[block]) return true;
BlockPerms.Find(block).MessageCannotUse(p, action);
return false;
}

View File

@ -31,7 +31,7 @@ namespace MCGalaxy.Commands.Moderation {
if (!CommandParser.IsBlockAllowed(p, "change permissions of", block)) return;
BlockPerms perms = BlockPerms.Find(block);
SetPerms(p, args, perms, "block");
SetPerms(p, args, data, perms, "block");
}
protected override void UpdatePerms(ItemPerms perms, Player p, string msg) {

View File

@ -34,7 +34,7 @@ namespace MCGalaxy.Commands.Moderation {
if (args.Length == 2) {
CommandPerms perms = CommandPerms.Find(cmd.name);
SetPerms(p, args, perms, "command");
SetPerms(p, args, data, perms, "command");
} else {
int num = 0;
if (!CommandParser.GetInt(p, args[2], "Extra permission number", ref num)) return;
@ -43,7 +43,7 @@ namespace MCGalaxy.Commands.Moderation {
if (perms == null) {
p.Message("This command has no extra permission by that number."); return;
}
SetPerms(p, args, perms, "extra permission");
SetPerms(p, args, data, perms, "extra permission");
}
}

View File

@ -32,8 +32,7 @@ namespace MCGalaxy.Commands.Moderation {
}
static void AnnounceOps(Player p, string msg) {
LevelPermission hideRank = p.oHideRank == LevelPermission.Null ? p.Rank : p.oHideRank;
ItemPerms perms = new ItemPerms(hideRank, null, null);
ItemPerms perms = new ItemPerms(p.hideRank, null, null);
Chat.MessageFrom(ChatScope.Perms, p, msg, perms, null, true);
}
@ -54,6 +53,7 @@ namespace MCGalaxy.Commands.Moderation {
p.hidden = !p.hidden;
if (p.hidden) {
AnnounceOps(p, "To Ops -λNICK%S- is now &finvisible");
p.hideRank = data.Rank;
if (!silent) {
string leaveM = "&c- λFULL %S" + PlayerDB.GetLogoutMessage(p);
@ -64,7 +64,7 @@ namespace MCGalaxy.Commands.Moderation {
Server.hidden.AddIfNotExists(p.name);
} else {
AnnounceOps(p, "To Ops -λNICK%S- is now &fvisible");
p.oHideRank = LevelPermission.Null;
p.hideRank = LevelPermission.Banned;
if (!silent) {
string joinM = "&a+ λFULL %S" + PlayerDB.GetLoginMessage(p);

View File

@ -41,7 +41,7 @@ namespace MCGalaxy.Commands.Moderation {
Group group = ModActionCmd.CheckTarget(p, "mute", who.name);
if (group == null) return;
TimeSpan duration = TimeSpan.FromSeconds(ServerConfig.ChatSpamMuteTime);
TimeSpan duration = ServerConfig.ChatSpamMuteTime;
if (args.Length > 1) {
if (!CommandParser.GetTimespan(p, args[1], ref duration, "mute for", "s")) return;
}

View File

@ -32,11 +32,11 @@ namespace MCGalaxy.Commands.Moderation {
if (!CheckRank(p, who, "hide", false)) return;
bool own = args.Length >= 2 && args[1].CaselessEq("myrank");
if (own) who.oHideRank = data.Rank;
if (!own) data.Rank = who.Rank;
Command.Find("Hide").Use(who, "", data);
p.Message("Hidden {0} %Sfrom players below {1} rank",
who.ColoredName, own ? "your" : "their");
p.Message("Hidden {0} %Sfrom players ranked below {1}",
who.ColoredName, Group.GetColoredName(data.Rank));
}
public override void Help(Player p) {

View File

@ -22,9 +22,9 @@ namespace MCGalaxy.Commands.Moderation {
public override string type { get { return CommandTypes.Moderation; } }
public override LevelPermission defaultRank { get { return LevelPermission.Operator; } }
protected void SetPerms(Player p, string[] args, ItemPerms perms, string type) {
protected void SetPerms(Player p, string[] args, CommandData data, ItemPerms perms, string type) {
string grpName = args[1];
if (!perms.UsableBy(p.Rank)) {
if (!perms.UsableBy(data.Rank)) {
p.Message("You rank cannot use this {0}.", type); return;
}
@ -38,7 +38,7 @@ namespace MCGalaxy.Commands.Moderation {
Group grp = GetGroup(p, grpName.Substring(1));
if (grp == null) return;
if (p.Rank == grp.Permission) {
if (data.Rank == grp.Permission) {
p.Message("You cannot disallow your own rank from using a {0}.", type); return;
}

View File

@ -98,6 +98,7 @@ namespace MCGalaxy.Commands.Moderation {
who.group = newRank;
who.AllowBuild = who.level.BuildAccess.CheckAllowed(who);
if (who.hidden && who.hideRank < who.Rank) who.hideRank = who.Rank;
who.SetPrefix();
who.Send(Packet.UserType(who));

View File

@ -32,72 +32,7 @@ namespace MCGalaxy.Commands.World {
if (message.Length == 0) { Help(p); return; }
string[] args = message.SplitSpaces();
if (args.Length > 2) { Help(p); return; }
LoadLevel(p, args[0], false);
}
public static Level LoadLevel(Player p, string name, bool autoLoaded = false) {
name = name.ToLower();
try {
return LoadLevelCore(p, name, autoLoaded);
} finally {
Server.DoGC();
}
}
static Level LoadLevelCore(Player p, string name, bool autoLoaded) {
if (!LevelInfo.MapExists(name)) {
p.Message("Level \"{0}\" does not exist", name); return null;
}
Level existing = LevelInfo.FindExact(name);
if (existing != null) {
p.Message("Level {0} %Sis already loaded.", existing.ColoredName); return null;
}
Level lvl = ReadLevel(p, name);
if (lvl == null || !lvl.CanJoin(p)) return null;
existing = LevelInfo.FindExact(name);
if (existing != null) {
p.Message("Level {0} %Sis already loaded.", existing.ColoredName); return null;
}
LevelInfo.Loaded.Add(lvl);
OnLevelAddedEvent.Call(lvl);
if (!autoLoaded) {
string autoloadMsg = "Level " + lvl.ColoredName + " %Sloaded.";
Chat.Message(ChatScope.All, autoloadMsg, null, Chat.FilterVisible(p));
}
return lvl;
}
static Level ReadLevel(Player p, string name) {
Level level = Level.Load(name);
if (level != null) return level;
if (!File.Exists(LevelInfo.MapPath(name) + ".backup")) {
p.Message("Backup of {0} does not exist.", name); return null;
}
Logger.Log(LogType.Warning, "Attempting to load backup map for " + name);
level = Level.Load(name, LevelInfo.MapPath(name) + ".backup");
if (level != null) return level;
p.Message("Loading backup failed.");
string backupPath = LevelInfo.BackupBasePath(name);
if (Directory.Exists(backupPath)) {
int latest = LevelInfo.LatestBackup(name);
Logger.Log(LogType.Warning, "Attempting to load latest backup of {0}, number {1} instead.", name, latest);
string path = LevelInfo.BackupFilePath(name, latest.ToString());
level = Level.Load(name, path);
if (level == null)
p.Message("Loading latest backup failed as well.");
} else {
p.Message("Latest backup of {0} does not exist.", name);
}
return level;
LevelActions.Load(p, args[0], true);
}
public override void Help(Player p) {

View File

@ -56,7 +56,7 @@ namespace MCGalaxy.Commands.World {
}
if (LevelInfo.FindExact(map) == null)
CmdLoad.LoadLevel(p, map, ServerConfig.AutoLoadMaps);
LevelActions.Load(p, map, !ServerConfig.AutoLoadMaps);
if (LevelInfo.FindExact(map) != null)
PlayerActions.ChangeMap(p, map);
}

View File

@ -34,22 +34,22 @@ namespace MCGalaxy.Commands.World {
Level lvl = Matcher.FindLevels(p, args[0]);
if (lvl == null) return;
string newName = args[1].ToLower();
if (!Formatter.ValidName(p, newName, "level")) return;
string newMap = args[1].ToLower();
if (!Formatter.ValidName(p, newMap, "level")) return;
if (LevelInfo.MapExists(newName)) { p.Message("Level already exists."); return; }
if (LevelInfo.MapExists(newMap)) { p.Message("Level already exists."); return; }
if (lvl == Server.mainLevel) { p.Message("Cannot rename the main level."); return; }
if (!LevelInfo.ValidateAction(p, data, lvl, "rename this level")) return;
List<Player> players = lvl.getPlayers();
lvl.Unload();
LevelActions.Rename(lvl.name, newName);
CmdLoad.LoadLevel(p, newName);
Chat.MessageGlobal("Renamed {0} to {1}", lvl.name, newName);
LevelActions.Rename(lvl.name, newMap);
LevelActions.Load(p, newMap, true);
Chat.MessageGlobal("Renamed {0} to {1}", lvl.name, newMap);
// Move all the old players to the renamed map
foreach (Player pl in players)
PlayerActions.ChangeMap(pl, newName);
PlayerActions.ChangeMap(pl, newMap);
}
public override void Help(Player p) {

View File

@ -44,7 +44,7 @@ namespace MCGalaxy.Config {
}
return value;
}
}
}
// Hacky workaround for old ExponentialFog attribute
public sealed class ConfigBoolIntAttribute : ConfigIntAttribute {
@ -78,7 +78,7 @@ namespace MCGalaxy.Config {
public class ConfigRealAttribute : ConfigAttribute {
float defValue, minValue, maxValue;
public ConfigRealAttribute(string name, string section, float def,
public ConfigRealAttribute(string name, string section, float def,
float min = float.NegativeInfinity, float max = float.PositiveInfinity)
: base(name, section) { defValue = def; minValue = min; maxValue = max; }
@ -102,17 +102,23 @@ namespace MCGalaxy.Config {
}
public class ConfigTimespanAttribute : ConfigRealAttribute {
public ConfigTimespanAttribute(string name, string section, float def)
: base(name, section, def, 0) { }
bool mins;
public ConfigTimespanAttribute(string name, string section, float def, bool mins)
: base(name, section, def, 0) { this.mins = mins; }
public override object Parse(string raw) {
float value = (float)base.Parse(raw);
return TimeSpan.FromMinutes(value);
if (mins) {
return TimeSpan.FromMinutes(value);
} else {
return TimeSpan.FromSeconds(value);
}
}
public override string Serialise(object value) {
TimeSpan span = (TimeSpan)value;
return span.TotalMinutes.ToString();
double time = mins ? span.TotalMinutes : span.TotalSeconds;
return time.ToString();
}
}
}

View File

@ -142,7 +142,7 @@ namespace MCGalaxy {
static void SetOldAfkKick() {
foreach (Group grp in Group.GroupList) {
grp.AfkKickMinutes = old.afkKickMins;
grp.AfkKickTime = TimeSpan.FromMinutes(old.afkKickMins);
// 0 minutes had the special meaning of 'not AFK kicked'
grp.AfkKicked = old.afkKickMins > 0 && grp.Permission < old.afkKickMax;
}

View File

@ -41,7 +41,7 @@ namespace MCGalaxy.Core {
if (blockedUntil < now) {
if (!entry.AddSpamEntry(ServerConfig.IPSpamCount, ServerConfig.IPSpamInterval)) {
entry.BlockedUntil = now.AddSeconds(ServerConfig.IPSpamBlockTime);
entry.BlockedUntil = now.Add(ServerConfig.IPSpamBlockTime);
}
return true;
}
@ -62,7 +62,7 @@ namespace MCGalaxy.Core {
if (!ServerConfig.IPSpamCheck) { ips.Clear(); return; }
// Find all connections which last joined before the connection spam check interval
DateTime threshold = DateTime.UtcNow.AddSeconds(-ServerConfig.IPSpamInterval);
DateTime threshold = DateTime.UtcNow.Add(-ServerConfig.IPSpamInterval);
List<string> expired = null;
foreach (var kvp in ips) {
DateTime lastJoin = kvp.Value[kvp.Value.Count - 1];

View File

@ -86,8 +86,7 @@ namespace MCGalaxy.Eco {
p.Message("&aCreating level: '&f" + name + "&a' . . .");
UseCommand(p, "NewLvl", name + " " + preset.x + " " + preset.y + " " + preset.z + " " + preset.type);
CmdLoad.LoadLevel(Player.Console, name);
Level level = LevelInfo.FindExact(name);
Level level = LevelActions.Load(Player.Console, name, true);
CmdOverseer.SetPerms(p, level);
Level.SaveSettings(level);
PlayerActions.ChangeMap(p, name);

View File

@ -173,10 +173,8 @@ namespace MCGalaxy {
/// <summary> Returns whether the given player is able to see the target player (e.g. in /who). </summary>
public static bool CanSee(Player p, Player target) {
if (p == null || target == null || !target.hidden || p == target) return true;
if (target.oHideRank != LevelPermission.Null) return p.Rank >= target.oHideRank;
return p.Rank >= target.Rank;
if (p == null || target == null || !target.hidden || p == target) return true;
return p.Rank >= target.hideRank;
}
public static void UpdateModel(Entity entity, string model) {

View File

@ -52,11 +52,11 @@ namespace MCGalaxy.Games {
[ConfigInt("layer-count", null, 10, 0)]
public int LayerCount = 10;
[ConfigTimespan("layer-interval", null, 2)]
[ConfigTimespan("layer-interval", null, 2, true)]
public TimeSpan LayerInterval = TimeSpan.FromMinutes(2);
[ConfigTimespan("round-time", null, 15)]
[ConfigTimespan("round-time", null, 15, true)]
public TimeSpan RoundTime = TimeSpan.FromMinutes(15);
[ConfigTimespan("flood-time", null, 5)]
[ConfigTimespan("flood-time", null, 5, true)]
public TimeSpan FloodTime = TimeSpan.FromMinutes(5);
[ConfigVec3("block-flood", null)] public Vec3U16 FloodPos;

View File

@ -26,11 +26,11 @@ namespace MCGalaxy.Games {
int dz = Math.Abs(a.Pos.Z - b.Pos.Z);
return dx <= dist && dy <= dist && dz <= dist;
}
static TimeSpan interval = TimeSpan.FromSeconds(5);
public static bool DetectNoclip(Player p, Position newPos) {
if (p.Game.Referee || Hacks.CanUseNoclip(p, p.level)) return false;
if (!p.CheckIfInsideBlock() || p.Game.NoclipLog.AddSpamEntry(5, 1))
return false;
if (!p.IsInsideBlock() || p.Game.NoclipLog.AddSpamEntry(5, interval)) return false;
Warn(ref p.Game.LastNoclipWarn, p, "noclip");
return false;
@ -42,7 +42,7 @@ namespace MCGalaxy.Games {
int maxMove = (int)(moveDist * 32);
bool speedhacking = dx >= maxMove || dz >= maxMove;
if (!speedhacking || p.Game.SpeedhackLog.AddSpamEntry(5, 1)) return false;
if (!speedhacking || p.Game.SpeedhackLog.AddSpamEntry(5, interval)) return false;
Warn(ref p.Game.LastSpeedhackWarn, p, "speedhack");
p.SendPos(Entities.SelfID, p.Pos, p.Rot);

View File

@ -110,7 +110,7 @@ namespace MCGalaxy.Games {
protected virtual bool SetMap(string map) {
Picker.QueuedMap = null;
Level next = LevelInfo.FindExact(map);
if (next == null) next = CmdLoad.LoadLevel(Player.Console, map);
if (next == null) next = LevelActions.Load(Player.Console, map, false);
if (next == null) return false;
Map = next;

View File

@ -313,7 +313,7 @@ namespace MCGalaxy.Games {
}
static int GetMoneyReward(Player pl, ZSData data, Player[] alive, Random rand) {
if (pl.CheckIfInsideBlock()) return -1;
if (pl.IsInsideBlock()) return -1;
if (alive.Length == 0) {
return rand.Next(1 + data.CurrentInfected, 5 + data.CurrentInfected);

View File

@ -20,6 +20,7 @@ using System.IO;
using MCGalaxy.Blocks;
using MCGalaxy.Bots;
using MCGalaxy.DB;
using MCGalaxy.Events.LevelEvents;
using MCGalaxy.SQL;
using MCGalaxy.Util;
@ -264,5 +265,65 @@ namespace MCGalaxy {
return false;
}
}
public static Level Load(Player p, string map, bool announce) {
map = map.ToLower();
if (!LevelInfo.MapExists(map)) {
p.Message("Level \"{0}\" does not exist", map); return null;
}
Level cur = LevelInfo.FindExact(map);
if (cur != null) {
p.Message("%WLevel {0} %Wis already loaded.", cur.ColoredName); return null;
}
try {
Level lvl = ReadLevel(p, map);
if (lvl == null || !lvl.CanJoin(p)) return null;
cur = LevelInfo.FindExact(map);
if (cur != null) {
p.Message("%WLevel {0} %Wis already loaded.", cur.ColoredName); return null;
}
LevelInfo.Add(lvl);
if (!announce) return lvl;
string autoloadMsg = "Level " + lvl.ColoredName + " %Sloaded.";
Chat.Message(ChatScope.All, autoloadMsg, null, Chat.FilterVisible(p));
return lvl;
} finally {
Server.DoGC();
}
}
static Level ReadLevel(Player p, string map) {
Level lvl = Level.Load(map);
if (lvl != null) return lvl;
string path = LevelInfo.MapPath(map) + ".backup";
if (!File.Exists(path)) {
p.Message("%WBackup of {0} does not exist.", map); return null;
}
Logger.Log(LogType.Warning, "Attempting to load backup map for " + map);
lvl = Level.Load(map, path);
if (lvl != null) return lvl;
p.Message("%WLoading backup of {0} failed too.", map);
string backupDir = LevelInfo.BackupBasePath(map);
if (Directory.Exists(backupDir)) {
int latest = LevelInfo.LatestBackup(map);
Logger.Log(LogType.Warning, "Attempting to load latest backup ({1}) of {0} instead", map, latest);
path = LevelInfo.BackupFilePath(map, latest.ToString());
lvl = Level.Load(map, path);
if (lvl == null) p.Message("%WLoading latest backup failed too.");
} else {
p.Message("%WLatest backup of {0} does not exist.", map);
}
return lvl;
}
}
}

View File

@ -249,9 +249,9 @@ namespace MCGalaxy {
[ConfigEnum("BuildType", "Game", BuildType.Normal, typeof(BuildType))]
public BuildType BuildType = BuildType.Normal;
[ConfigTimespan("MinRoundTime", "Game", 4)]
[ConfigTimespan("MinRoundTime", "Game", 4, true)]
public TimeSpan MinRoundTime = TimeSpan.FromMinutes(4);
[ConfigTimespan("MaxRoundTime", "Game", 7)]
[ConfigTimespan("MaxRoundTime", "Game", 7, true)]
public TimeSpan MaxRoundTime = TimeSpan.FromMinutes(7);
[ConfigBool("DrawingAllowed", "Game", true)]
public bool Drawing = true;

View File

@ -59,8 +59,8 @@ namespace MCGalaxy {
public int OverseerMaps = 3;
[ConfigBool("AfkKicked", null, true)]
public bool AfkKicked = true;
[ConfigInt("AfkKickMinutes", null, 45, 0)]
public int AfkKickMinutes = 45;
[ConfigTimespan("AfkKickMinutes", null, 45, true)]
public TimeSpan AfkKickTime = TimeSpan.FromMinutes(45);
[ConfigString("Prefix", null, "", true)]
public string Prefix = "";
[ConfigInt("CopySlots", null, 0, 0)]
@ -113,7 +113,7 @@ namespace MCGalaxy {
copy.Name = Name; copy.Color = Color; copy.Permission = Permission;
copy.DrawLimit = DrawLimit; copy.MaxUndo = MaxUndo; copy.MOTD = MOTD;
copy.GenVolume = GenVolume; copy.OverseerMaps = OverseerMaps;
copy.AfkKicked = AfkKicked; copy.AfkKickMinutes = AfkKickMinutes;
copy.AfkKicked = AfkKicked; copy.AfkKickTime = AfkKickTime;
copy.Prefix = Prefix; copy.CopySlots = CopySlots; copy.filename = filename;
return copy;
}

View File

@ -60,7 +60,7 @@ namespace MCGalaxy {
public string ip;
public string color;
public Group group;
public LevelPermission oHideRank = LevelPermission.Null;
public LevelPermission hideRank = LevelPermission.Banned;
public bool hidden;
public bool painting;
public bool muted;

View File

@ -100,10 +100,7 @@ namespace MCGalaxy {
// hidden via /hide or /ohide
// TODO: Just use Entities.CanSee
if (target.hidden) {
if (target.oHideRank != LevelPermission.Null) return Rank >= target.oHideRank;
return Rank >= target.Rank;
}
if (target.hidden) return Rank >= target.hideRank;
if (!ZSGame.Instance.Running || Game.Referee) return true;
ZSData data = ZSGame.TryGet(target);
@ -138,7 +135,7 @@ namespace MCGalaxy {
return color + "[" + titleCol + title + color + "] ";
}
public bool CheckIfInsideBlock() {
public bool IsInsideBlock() {
AABB bb = ModelBB.OffsetPosition(Pos);
return AABB.IntersectsSolidBlocks(bb, level);
}

View File

@ -86,7 +86,7 @@ namespace MCGalaxy {
bool ignorePerms = p.summonedMap != null && p.summonedMap.CaselessEq(name);
if (!visitAccess.CheckDetailed(p, ignorePerms)) return false;
CmdLoad.LoadLevel(p, name, true);
LevelActions.Load(p, name, false);
Level lvl = LevelInfo.FindExact(name);
if (lvl != null) return GotoLevel(p, lvl);

View File

@ -62,7 +62,7 @@ namespace MCGalaxy {
if (chatLog.AddSpamEntry(ServerConfig.ChatSpamCount, ServerConfig.ChatSpamInterval))
return false;
TimeSpan duration = TimeSpan.FromSeconds(ServerConfig.ChatSpamMuteTime);
TimeSpan duration = ServerConfig.ChatSpamMuteTime;
ModAction action = new ModAction(p.name, Player.Console, ModActionType.Muted, "&0Auto mute for spamming", duration);
OnModActionEvent.Call(action);
return true;
@ -76,9 +76,10 @@ namespace MCGalaxy {
if (cmdLog.AddSpamEntry(ServerConfig.CmdSpamCount, ServerConfig.CmdSpamInterval))
return false;
p.Message("You have been blocked from using commands for " +
ServerConfig.CmdSpamBlockTime + " seconds due to spamming");
p.cmdUnblocked = DateTime.UtcNow.AddSeconds(ServerConfig.CmdSpamBlockTime);
string blockTime = ServerConfig.CmdSpamBlockTime.Shorten(true, true);
p.Message("You have been blocked from using commands for "
+ blockTime + " due to spamming");
p.cmdUnblocked = DateTime.UtcNow.Add(ServerConfig.CmdSpamBlockTime);
return true;
}
}

View File

@ -32,11 +32,9 @@ namespace MCGalaxy {
static void LoadMainLevel(SchedulerTask task) {
try {
mainLevel = CmdLoad.LoadLevel(Player.Console, ServerConfig.MainLevel);
if (mainLevel == null) GenerateMain();
mainLevel = LevelActions.Load(Player.Console, ServerConfig.MainLevel, false);
if (mainLevel == null) GenerateMain();
mainLevel.Config.AutoUnload = false;
LevelInfo.Add(mainLevel);
} catch (Exception ex) {
Logger.LogError("Error loading main level", ex);
}
@ -45,8 +43,10 @@ namespace MCGalaxy {
static void GenerateMain() {
Logger.Log(LogType.SystemActivity, "main level not found, generating..");
mainLevel = new Level(ServerConfig.MainLevel, 128, 64, 128);
MapGen.Generate(mainLevel, "flat", "", null);
mainLevel.Save();
LevelInfo.Add(mainLevel);
}
static void LoadPlayerLists(SchedulerTask task) {
@ -88,7 +88,7 @@ namespace MCGalaxy {
foreach (string map in maps) {
if (map.CaselessEq(ServerConfig.MainLevel)) continue;
CmdLoad.LoadLevel(Player.Console, map);
LevelActions.Load(Player.Console, map, false);
}
}

View File

@ -295,7 +295,7 @@ namespace MCGalaxy {
Level lvl = LevelInfo.FindExact(mapName);
if (lvl == null)
lvl = CmdLoad.LoadLevel(Player.Console, mapName);
lvl = LevelActions.Load(Player.Console, mapName, false);
if (lvl == null) return false;
SetMainLevel(lvl); return true;

View File

@ -94,8 +94,8 @@ namespace MCGalaxy {
[ConfigString("backup-location", "Backup", "")]
public static string BackupDirectory = Path.Combine(Utils.FolderPath, "levels/backups");
[ConfigInt("afk-minutes", "Other", 10)]
public static int AutoAfkMins = 10;
[ConfigTimespan("afk-minutes", "Other", 10, true)]
public static TimeSpan AutoAfkTime = TimeSpan.FromMinutes(10);
[ConfigString("default-rank", "General", "guest")]
public static string DefaultRankName = "guest";
@ -242,34 +242,34 @@ namespace MCGalaxy {
public static bool ChatSpamCheck = false;
[ConfigInt("spam-messages", "Spam control", 8, 0, 10000)]
public static int ChatSpamCount = 8;
[ConfigInt("spam-mute-time", "Spam control", 60, 0, 1000000)]
public static int ChatSpamMuteTime = 60;
[ConfigInt("spam-counter-reset-time", "Spam control", 5, 0, 10000)]
public static int ChatSpamInterval = 5;
[ConfigTimespan("spam-mute-time", "Spam control", 60, false)]
public static TimeSpan ChatSpamMuteTime = TimeSpan.FromSeconds(60);
[ConfigTimespan("spam-counter-reset-time", "Spam control", 5, false)]
public static TimeSpan ChatSpamInterval = TimeSpan.FromSeconds(5);
[ConfigBool("cmd-spam-check", "Spam control", true)]
public static bool CmdSpamCheck = true;
[ConfigInt("cmd-spam-count", "Spam control", 25, 0, 10000)]
public static int CmdSpamCount = 25;
[ConfigInt("cmd-spam-block-time", "Spam control", 30, 0, 1000000)]
public static int CmdSpamBlockTime = 30;
[ConfigInt("cmd-spam-interval", "Spam control", 1, 0, 10000)]
public static int CmdSpamInterval = 1;
[ConfigTimespan("cmd-spam-block-time", "Spam control", 30, false)]
public static TimeSpan CmdSpamBlockTime = TimeSpan.FromSeconds(30);
[ConfigTimespan("cmd-spam-interval", "Spam control", 1, false)]
public static TimeSpan CmdSpamInterval = TimeSpan.FromSeconds(1);
[ConfigBool("block-spam-check", "Spam control", true)]
public static bool BlockSpamCheck = true;
[ConfigInt("block-spam-count", "Spam control", 200, 0, 10000)]
public static int BlockSpamCount = 200;
[ConfigInt("block-spam-interval", "Spam control", 5, 0, 10000)]
public static int BlockSpamInterval = 5;
[ConfigTimespan("block-spam-interval", "Spam control", 5, false)]
public static TimeSpan BlockSpamInterval = TimeSpan.FromSeconds(5);
[ConfigBool("ip-spam-check", "Spam control", true)]
public static bool IPSpamCheck = true;
[ConfigInt("ip-spam-count", "Spam control", 25, 0, 10000)]
public static int IPSpamCount = 10;
[ConfigInt("ip-spam-block-time", "Spam control", 30, 0, 1000000)]
public static int IPSpamBlockTime = 180;
[ConfigInt("ip-spam-interval", "Spam control", 1, 0, 10000)]
public static int IPSpamInterval = 60;
[ConfigTimespan("ip-spam-block-time", "Spam control", 180, false)]
public static TimeSpan IPSpamBlockTime = TimeSpan.FromSeconds(180);
[ConfigTimespan("ip-spam-interval", "Spam control", 60, false)]
public static TimeSpan IPSpamInterval = TimeSpan.FromSeconds(60);
}
}

View File

@ -100,20 +100,22 @@ namespace MCGalaxy.Tasks {
p.Send(Packet.Ping());
}
if (ServerConfig.AutoAfkMins <= 0) return;
if (ServerConfig.AutoAfkTime.Ticks <= 0) return;
if (DateTime.UtcNow < p.AFKCooldown) return;
if (p.IsAfk) {
int time = p.group.AfkKickMinutes;
if (p.AutoAfk) time += ServerConfig.AutoAfkMins;
TimeSpan time = p.group.AfkKickTime;
if (p.AutoAfk) time += ServerConfig.AutoAfkTime;
if (p.group.AfkKicked && p.LastAction.AddMinutes(time) < DateTime.UtcNow) {
p.Leave("Auto-kick, AFK for " + p.group.AfkKickMinutes + " minutes");
if (p.group.AfkKicked && p.LastAction.Add(time) < DateTime.UtcNow) {
string afkTime = p.group.AfkKickTime.Shorten(true, true);
p.Leave("Auto-kick, AFK for " + afkTime);
}
} else {
DateTime lastAction = p.LastAction;
if (lastAction.AddMinutes(ServerConfig.AutoAfkMins) < DateTime.UtcNow) {
CmdAfk.ToggleAfk(p, "auto: Not moved for " + ServerConfig.AutoAfkMins + " minutes");
if (lastAction.Add(ServerConfig.AutoAfkTime) < DateTime.UtcNow) {
string afkTime = ServerConfig.AutoAfkTime.Shorten(true, true);
CmdAfk.ToggleAfk(p, "auto: Not moved for " + afkTime);
p.AutoAfk = true;
p.LastAction = lastAction;
}

View File

@ -37,7 +37,7 @@ namespace MCGalaxy {
return (long)(time.ToUniversalTime() - UnixEpoch).TotalSeconds;
}
public static bool AddSpamEntry(this List<DateTime> log, int maxEntries, int checkInterval) {
public static bool AddSpamEntry(this List<DateTime> log, int maxEntries, TimeSpan checkInterval) {
DateTime now = DateTime.UtcNow;
if (log.Count > 0 && log.Count >= maxEntries)
log.RemoveAt(0);
@ -45,7 +45,7 @@ namespace MCGalaxy {
if (log.Count < maxEntries) return true;
TimeSpan oldestDelta = now - log[0];
return oldestDelta.TotalSeconds > checkInterval;
return oldestDelta > checkInterval;
}
}
}

View File

@ -35,6 +35,10 @@ namespace MCGalaxy {
if (time.Length == 0) time = seconds ? "0s" : "0m";
return negate ? "-" + time : time;
}
public static long SecondsLong(this TimeSpan value) {
return value.Ticks / TimeSpan.TicksPerSecond;
}
static void Add(ref string time, int amount, char suffix, bool spaces) {
if (amount == 0) return;