Merge pull request #895 from WhiteXZ/general-devel

Adds a time parameter to the tempgroup command
This commit is contained in:
Lucas Nicodemus 2015-04-05 21:30:05 -06:00
commit ac5359e4f9
3 changed files with 39 additions and 0 deletions

View file

@ -870,6 +870,10 @@ namespace TShockAPI
args.Player.PlayerData = new PlayerData(args.Player);
args.Player.Group = TShock.Groups.GetGroupByName(TShock.Config.DefaultGuestGroupName);
args.Player.tempGroup = null;
if (args.Player.tempGroupTimer != null)
{
args.Player.tempGroupTimer.Stop();
}
args.Player.UserAccountName = null;
args.Player.UserID = -1;
args.Player.IsLoggedIn = false;
@ -1630,6 +1634,21 @@ namespace TShockAPI
return;
}
if (args.Parameters.Count > 2)
{
int time;
if (!TShock.Utils.TryParseTime(args.Parameters[2], out time))
{
args.Player.SendErrorMessage("Invalid time string! Proper format: _d_h_m_s, with at least one time specifier.");
args.Player.SendErrorMessage("For example, 1d and 10h-30m+2m are both valid time strings, but 2 is not.");
return;
}
ply[0].tempGroupTimer = new System.Timers.Timer(time*1000);
ply[0].tempGroupTimer.Elapsed += ply[0].TempGroupTimerElapsed;
ply[0].tempGroupTimer.Start();
}
Group g = TShock.Utils.GetGroup(args.Parameters[1]);
ply[0].tempGroup = g;

View file

@ -22,9 +22,11 @@ using System.Diagnostics;
using System.IO;
using System.Text;
using System.Threading;
using System.Timers;
using Terraria;
using TShockAPI.DB;
using TShockAPI.Net;
using Timer = System.Timers.Timer;
namespace TShockAPI
{
@ -111,6 +113,8 @@ namespace TShockAPI
/// The player's temporary group. This overrides the user's actual group.
/// </summary>
public Group tempGroup = null;
public Timer tempGroupTimer;
private Group group = null;
@ -523,6 +527,17 @@ namespace TShockAPI
}
public void TempGroupTimerElapsed(object sender, ElapsedEventArgs args)
{
SendWarningMessage("Your temporary group access has expired.");
tempGroup = null;
if (sender != null)
{
((Timer)sender).Stop();
}
}
public void SendWorldInfo(int tilex, int tiley, bool fakeid)
{
using (var ms = new MemoryStream())

View file

@ -1022,6 +1022,11 @@ namespace TShockAPI
{
RememberedPos.InsertLeavePos(tsplr.Name, tsplr.IP, (int) (tsplr.X/16), (int) (tsplr.Y/16));
}
if (tsplr.tempGroupTimer != null)
{
tsplr.tempGroupTimer.Stop();
}
}
// The last player will leave after this hook is executed.