Merge pull request #895 from WhiteXZ/general-devel
Adds a time parameter to the tempgroup command
This commit is contained in:
commit
ac5359e4f9
3 changed files with 39 additions and 0 deletions
|
|
@ -870,6 +870,10 @@ namespace TShockAPI
|
||||||
args.Player.PlayerData = new PlayerData(args.Player);
|
args.Player.PlayerData = new PlayerData(args.Player);
|
||||||
args.Player.Group = TShock.Groups.GetGroupByName(TShock.Config.DefaultGuestGroupName);
|
args.Player.Group = TShock.Groups.GetGroupByName(TShock.Config.DefaultGuestGroupName);
|
||||||
args.Player.tempGroup = null;
|
args.Player.tempGroup = null;
|
||||||
|
if (args.Player.tempGroupTimer != null)
|
||||||
|
{
|
||||||
|
args.Player.tempGroupTimer.Stop();
|
||||||
|
}
|
||||||
args.Player.UserAccountName = null;
|
args.Player.UserAccountName = null;
|
||||||
args.Player.UserID = -1;
|
args.Player.UserID = -1;
|
||||||
args.Player.IsLoggedIn = false;
|
args.Player.IsLoggedIn = false;
|
||||||
|
|
@ -1630,6 +1634,21 @@ namespace TShockAPI
|
||||||
return;
|
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]);
|
Group g = TShock.Utils.GetGroup(args.Parameters[1]);
|
||||||
|
|
||||||
ply[0].tempGroup = g;
|
ply[0].tempGroup = g;
|
||||||
|
|
|
||||||
|
|
@ -22,9 +22,11 @@ using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
|
using System.Timers;
|
||||||
using Terraria;
|
using Terraria;
|
||||||
using TShockAPI.DB;
|
using TShockAPI.DB;
|
||||||
using TShockAPI.Net;
|
using TShockAPI.Net;
|
||||||
|
using Timer = System.Timers.Timer;
|
||||||
|
|
||||||
namespace TShockAPI
|
namespace TShockAPI
|
||||||
{
|
{
|
||||||
|
|
@ -112,6 +114,8 @@ namespace TShockAPI
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Group tempGroup = null;
|
public Group tempGroup = null;
|
||||||
|
|
||||||
|
public Timer tempGroupTimer;
|
||||||
|
|
||||||
private Group group = null;
|
private Group group = null;
|
||||||
|
|
||||||
public bool ReceivedInfo { get; set; }
|
public bool ReceivedInfo { get; set; }
|
||||||
|
|
@ -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)
|
public void SendWorldInfo(int tilex, int tiley, bool fakeid)
|
||||||
{
|
{
|
||||||
using (var ms = new MemoryStream())
|
using (var ms = new MemoryStream())
|
||||||
|
|
|
||||||
|
|
@ -1022,6 +1022,11 @@ namespace TShockAPI
|
||||||
{
|
{
|
||||||
RememberedPos.InsertLeavePos(tsplr.Name, tsplr.IP, (int) (tsplr.X/16), (int) (tsplr.Y/16));
|
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.
|
// The last player will leave after this hook is executed.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue