-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathLineText.cs
103 lines (87 loc) · 3.31 KB
/
LineText.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
using Rocket.Unturned.Player;
using SDG.Unturned;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using UnityEngine;
namespace MOTD
{
class LineText
{
private string text;
public string getText()
{
return text;
}
public LineText(string configText, Tps tpsMonitor, UnturnedPlayer player, string date)
{
configText = Regex.Replace(configText, "%servername%", Provider.serverName, RegexOptions.IgnoreCase);
configText = Regex.Replace(configText, "%playername%", player.CharacterName, RegexOptions.IgnoreCase);
configText = Regex.Replace(configText, "%online%", Provider.clients.Count() + "/" + Provider.maxPlayers, RegexOptions.IgnoreCase);
configText = Regex.Replace(configText, "%adminsonline%", Admins(), RegexOptions.IgnoreCase);
configText = Regex.Replace(configText, "%mode%", Provider.mode.ToString(), RegexOptions.IgnoreCase);
configText = Regex.Replace(configText, "%pvp/pve%", PvPorPvE(), RegexOptions.IgnoreCase);
configText = Regex.Replace(configText, "%map%", Provider.map, RegexOptions.IgnoreCase);
configText = Regex.Replace(configText, "%uptime%", UpTime(), RegexOptions.IgnoreCase);
configText = Regex.Replace(configText, "%tps%", TPS(tpsMonitor), RegexOptions.IgnoreCase);
configText = Regex.Replace(configText, "%serverdays%", ServerDays(date), RegexOptions.IgnoreCase);
text = configText;
}
private string ServerDays(string dateStart)
{
DateTime time = Convert.ToDateTime(dateStart);
TimeSpan result = DateTime.Now.Subtract(time);
return result.Days.ToString();
}
private string PvPorPvE()
{
if (Provider.isPvP) { return "PvP"; }
return "PvE";
}
private string Admins()
{
string str = "";
List<SteamPlayer> Players = Provider.clients;
foreach(SteamPlayer p in Players)
{
if (p.isAdmin)
{
if (str != "") { str += ", "; }
str += p.player.name;
}
}
if (str == "")
{
str = "none";
}
return str;
}
private string UpTime()
{
int seconds = (int)Time.realtimeSinceStartup;
string uptime = "";
if (seconds >= (60 * 60 * 24))
{
uptime = (int)(seconds / (60 * 60 * 24)) + "d ";
}
if (seconds >= (60 * 60))
{
uptime += (int)((seconds / (60 * 60)) % 24) + "h ";
}
if (seconds >= 60)
{
uptime += (int)((seconds / 60) % 60) + "m ";
}
uptime += (int)(seconds % 60) + "s";
return uptime;
}
private string TPS(Tps tpsMonitor)
{
string tps1Min = tpsMonitor.get1Min().ToString("0.0");
string tps5Min = tpsMonitor.get5Min().ToString("0.0");
string tps15Min = tpsMonitor.get15Min().ToString("0.0");
return tps1Min + ", " + tps5Min + ", " + tps15Min;
}
}
}