DCore: Now keep track of player's ID within the Players table.

This commit is contained in:
UnknownShadow200 2016-11-06 15:06:43 +11:00
parent 21d7802ae1
commit b4035ffe93
6 changed files with 31 additions and 10 deletions

View File

@ -51,12 +51,16 @@ namespace MCGalaxy {
public int Count { get { lock (locker) return players.Count; } }
public void AddOrReplace(string p) {
/// <summary> Adds or replaces the given name,
/// returning the index of the item within the list. </summary>
public int AddOrReplace(string p) {
p = p.ToLower();
lock (locker) {
int idx = players.IndexOf(p);
if (idx >= 0) return;
if (idx >= 0) return idx;
players.Add(p);
return players.Count - 1;
}
}

View File

@ -86,7 +86,6 @@ namespace MCGalaxy {
public string realName;
public int warn = 0;
public byte id;
public int DatabaseID = -1;
public string ip;
public string color;
public Group group;
@ -173,7 +172,11 @@ namespace MCGalaxy {
public bool voted = false;
public bool flipHead = false;
public GameProps Game = new GameProps();
/// <summary> Persistent ID of this user in the Players table. </summary>
public int UserID;
public const int SessionIDMask = (1 << 23) - 1;
/// <summary> Temp unique ID for this session only. </summary>
public int SessionID;
//Countdown

View File

@ -104,10 +104,11 @@ namespace MCGalaxy {
time = new TimeSpan(0, 0, 0, 1);
DataTable playerDb = Database.Backend.GetRows("Players", "*", "WHERE Name=@0", name);
if (playerDb.Rows.Count == 0)
if (playerDb.Rows.Count == 0) {
InitPlayerStats(playerDb);
else
} else {
LoadPlayerStats(playerDb);
}
Server.MainScheduler.QueueOnce(ShowAltsTask, name, TimeSpan.Zero);
CheckState();
@ -197,8 +198,8 @@ namespace MCGalaxy {
void LoadPlayerStats(DataTable playerDb) {
PlayerData.Load(playerDb, this);
SendMessage("Welcome back " + color + prefix + DisplayName + "%S! " +
"You've been here " + totalLogins + " times!");
SendMessage("Welcome back " + FullName + "%S! You've been here "
+ totalLogins + " times!");
}
void CheckState() {

View File

@ -45,13 +45,25 @@ namespace MCGalaxy {
Database.Backend.AddRow("Players", "Name, IP, FirstLogin, LastLogin, totalLogin, Title, " +
"totalDeaths, Money, totalBlocks, totalKicked, TimeSpent",
p.name, p.ip, now, now, 1, "", 0, 0, 0, 0, p.time.ToDBTime());
using (DataTable ids = Database.Backend.GetRows("Players",
"ID", "WHERE Name = @0", p.name)) {
if (ids.Rows.Count > 0) {
string id = ids.Rows[0]["ID"].ToString();
p.UserID = PlayerData.ParseInt(id);
} else {
int index = Server.invalidIds.AddOrReplace(p.name);
p.UserID = int.MaxValue - index;
Server.s.Log("INVALID!! " + p.UserID + " - " + p.name);
}
}
}
internal static void Load(DataTable playerDb, Player p) {
PlayerData data = PlayerData.Fill(playerDb.Rows[0]);
p.totalLogins = data.Logins + 1;
p.time = data.TotalTime.ParseDBTime();
p.DatabaseID = data.UserID;
p.UserID = data.UserID;
p.firstLogin = data.FirstLogin;
p.lastLogin = data.LastLogin;
@ -76,7 +88,7 @@ namespace MCGalaxy {
PlayerData data = new PlayerData();
data.Name = row["Name"].ToString().Trim();
data.IP = row["IP"].ToString().Trim();
data.UserID = int.Parse(row["ID"].ToString().Trim());
data.UserID = ParseInt(row["ID"].ToString());
data.TotalTime = row["TimeSpent"].ToString();
data.FirstLogin = DateTime.Parse(row["FirstLogin"].ToString());

View File

@ -78,7 +78,7 @@ namespace MCGalaxy {
public static bool UseCTF = false;
public static bool ServerSetupFinished = false;
public static CTFGame ctf = null;
public static PlayerList bannedIP, whiteList, ircControllers, muted;
public static PlayerList bannedIP, whiteList, ircControllers, muted, invalidIds;
public static PlayerList ignored, frozen, hidden, agreed, vip, noEmotes, lockdown;
public static PlayerExtList jailed, models, skins, reach;

View File

@ -90,6 +90,7 @@ namespace MCGalaxy {
models = PlayerExtList.Load("extra/models.txt");
skins = PlayerExtList.Load("extra/skins.txt");
reach = PlayerExtList.Load("extra/reach.txt");
invalidIds = PlayerList.Load("extra/invalidids.txt");
foreach (Group grp in Group.GroupList)
grp.playerList = PlayerList.Load(grp.fileName);