Skip to content

Commit 3b47229

Browse files
Allow setting ban expiry (#559)
1 parent 763f478 commit 3b47229

2 files changed

Lines changed: 19 additions & 12 deletions

File tree

src/Libraries/Covalence/RustServer.cs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -145,14 +145,18 @@ public DateTime Time
145145
/// <param name="id"></param>
146146
/// <param name="reason"></param>
147147
/// <param name="duration"></param>
148-
public void Ban(string id, string reason, TimeSpan duration = default)
149-
{
150-
if (!IsBanned(id))
151-
{
152-
ServerUsers.Set(ulong.Parse(id), ServerUsers.UserGroup.Banned, Name, reason);
153-
ServerUsers.Save();
154-
}
155-
}
148+
public void Ban(string id, string reason, TimeSpan duration = default)
149+
{
150+
if (IsBanned(id)) return;
151+
long expiryUnixTime = -1L;
152+
if (duration != TimeSpan.Zero)
153+
{
154+
DateTime expiryTime = DateTime.UtcNow.Add(duration);
155+
expiryUnixTime = new DateTimeOffset(expiryTime).ToUnixTimeSeconds();
156+
}
157+
ServerUsers.Set(ulong.Parse(id), ServerUsers.UserGroup.Banned, Name, reason, expiryUnixTime);
158+
ServerUsers.Save();
159+
}
156160

157161
/// <summary>
158162
/// Gets the amount of time remaining on the player's ban

src/Libraries/Player.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,15 +120,16 @@ public CultureInfo Language(BasePlayer player)
120120
/// </summary>
121121
/// <param name="id"></param>
122122
/// <param name="reason"></param>
123-
public void Ban(ulong id, string reason = "")
123+
/// <param name="expiry"></param>
124+
public void Ban(ulong id, string reason = "", long expiry = -1L)
124125
{
125126
if (IsBanned(id))
126127
{
127128
return;
128129
}
129130

130131
BasePlayer player = FindById(id);
131-
ServerUsers.Set(id, ServerUsers.UserGroup.Banned, player?.displayName ?? "Unknown", reason);
132+
ServerUsers.Set(id, ServerUsers.UserGroup.Banned, player?.displayName ?? "Unknown", reason, expiry);
132133
ServerUsers.Save();
133134
if (player != null && IsConnected(player))
134135
{
@@ -141,14 +142,16 @@ public void Ban(ulong id, string reason = "")
141142
/// </summary>
142143
/// <param name="id"></param>
143144
/// <param name="reason"></param>
144-
public void Ban(string id, string reason = "") => Ban(Convert.ToUInt64(id), reason);
145+
/// <param name="expiry"></param>
146+
public void Ban(string id, string reason = "", long expiry = -1L) => Ban(Convert.ToUInt64(id), reason, expiry);
145147

146148
/// <summary>
147149
/// Bans the player from the server
148150
/// </summary>
149151
/// <param name="player"></param>
150152
/// <param name="reason"></param>
151-
public void Ban(BasePlayer player, string reason = "") => Ban(player.UserIDString, reason);
153+
/// <param name="expiry"></param>
154+
public void Ban(BasePlayer player, string reason = "", long expiry = -1L) => Ban(player.UserIDString, reason, expiry);
152155

153156
/// <summary>
154157
/// Heals the player by specified amount

0 commit comments

Comments
 (0)