forked from cartman-2000/PlayerInfoLib
-
Notifications
You must be signed in to change notification settings - Fork 7
/
PlayerData.cs
88 lines (82 loc) · 3.25 KB
/
PlayerData.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
using Rocket.API;
using Rocket.Core;
using Steamworks;
using System;
using System.Linq;
namespace PlayerInfoLibrary
{
public class PlayerData
{
public CSteamID SteamID { get; private set; }
public string SteamName { get; internal set; }
public string CharacterName { get; internal set; }
public string IP { get; internal set; }
public DateTime LastLoginGlobal { get; internal set; }
public int TotalPlayime { get; internal set; }
public ushort LastServerID { get; internal set; }
public string LastServerName { get; internal set; }
public ushort ServerID { get; private set; }
public DateTime LastLoginLocal { get; internal set; }
public bool CleanedBuildables { get; internal set; }
public bool CleanedPlayerData { get; internal set; }
public DateTime CacheTime { get; internal set; }
/// <summary>
/// Checks to see if the server specific data stored in this class is from this server(local).
/// </summary>
/// <returns>true if the data is from this server.</returns>
public bool IsLocal()
{
if (!IsValid())
return false;
return ServerID == PlayerInfoLib.Database.InstanceID;
}
/// <summary>
/// Checks to see if the data is valid.
/// </summary>
/// <returns></returns>
public bool IsValid()
{
return SteamID != CSteamID.Nil;
}
/// <summary>
/// Checks to see if the Cache time on this data has expired.
/// </summary>
/// <returns></returns>
public bool IsCacheExpired()
{
if (CacheTime != null)
return ((DateTime.Now - CacheTime).TotalSeconds >= (PlayerInfoLib.Instance.Configuration.Instance.CacheTime * 60));
return true;
}
/// <summary>
/// Checks players groups against the config value set in the plugin config to see if they're a VIP.
/// </summary>
/// <returns>true if a match is found.</returns>
public bool IsVip()
{
if (!IsValid())
return false;
return R.Permissions.GetGroups(new RocketPlayer(SteamID.ToString()), true).FirstOrDefault(g => g.Id == PlayerInfoLib.Instance.Configuration.Instance.VipCheckGroupName) != null;
}
internal PlayerData()
{
SteamID = CSteamID.Nil;
TotalPlayime = 0;
}
internal PlayerData(CSteamID steamID, string steamName, string characterName, string ip, DateTime lastLoginGlobal, ushort lastServerID, string lastServerName, ushort serverID, DateTime lastLoginLocal, bool cleanedBuildables, bool cleanedPlayerData, int totalPlayTime)
{
SteamID = steamID;
SteamName = steamName;
CharacterName = characterName;
IP = ip;
LastLoginGlobal = lastLoginGlobal;
LastServerID = lastServerID;
LastServerName = lastServerName;
ServerID = serverID;
LastLoginLocal = lastLoginLocal;
CleanedBuildables = cleanedBuildables;
CleanedPlayerData = cleanedPlayerData;
TotalPlayime = totalPlayTime;
}
}
}