-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathZaupLeaderboard.cs
53 lines (48 loc) · 1.83 KB
/
ZaupLeaderboard.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
using System;
using System.Collections.Generic;
using Rocket.API;
using Rocket.Core.Logging;
using Rocket.Core.Plugins;
using Rocket.Unturned;
using Rocket.Unturned.Events;
using Rocket.Unturned.Player;
using Rocket.Unturned.Plugins;
using Steamworks;
using SDG.Unturned;
namespace ZaupLeaderboard
{
public class ZaupLeaderboard : RocketPlugin<ZLConfiguration>
{
public static ZaupLeaderboard Instance;
public ZLDatabaseManager DatabaseMgr;
public string UpdatePlayedTimeSql;
public delegate void OnChangeStats(CSteamID steamID, string WhichStat);
public event OnChangeStats OnChangeStatsEvent;
protected override void Load()
{
ZaupLeaderboard.Instance = this;
this.DatabaseMgr = new ZLDatabaseManager();
this.UpdatePlayedTimeSql = "update `"
+ ZaupLeaderboard.Instance.Configuration.Instance.DatabaseTableName
+ "` set `lastdisconn`=current_timestamp, `timeplayed`=`timeplayed`+ TIMESTAMPDIFF(SECOND,`"
+ ZaupLeaderboard.Instance.Configuration.Instance.DatabaseTableName
+ "`.`lastconn`,CURRENT_TIMESTAMP())";
U.Events.OnPlayerConnected += this.OnPlayerConnected;
}
internal void OnUpdateStats(CSteamID steamID, string WhichStat)
{
if(OnChangeStatsEvent != null)
{
OnChangeStatsEvent(steamID, WhichStat);
}
}
private void OnPlayerConnected(UnturnedPlayer player)
{
byte success = ZaupLeaderboard.Instance.DatabaseMgr.OnPlayerConnected(player.CSteamID, player.CharacterName);
if (success <= 0)
{
Logger.Log("Could not add or update the leaderboard for " + player.CharacterName + ".");
}
}
}
}