forked from ClassiCube/MCGalaxy-Plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
LowLatency.cs
38 lines (31 loc) · 1 KB
/
LowLatency.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
using System;
using MCGalaxy;
using MCGalaxy.Events.PlayerEvents;
public class LowLatency : Plugin
{
public override string name { get { return "LowLatency"; } }
public override string MCGalaxy_Version { get { return "1.9.3.8"; } }
public override string creator { get { return "Not UnknownShadow200"; } }
public override void Load(bool startup) {
OnPlayerFinishConnectingEvent.Register(OnPlayerFinishConnecting, Priority.Low);
SetAllNoDelay(true);
}
public override void Unload(bool shutdown) {
OnPlayerFinishConnectingEvent.Unregister(OnPlayerFinishConnecting);
SetAllNoDelay(false);
}
static void OnPlayerFinishConnecting(Player p) {
SetNoDelay(p, true);
}
static void SetNoDelay(Player p, bool noDelay) {
try {
p.Socket.LowLatency = noDelay;
} catch {
// exception can be rarely thrown when socket is disconnected
}
}
static void SetAllNoDelay(bool noDelay) {
Player[] players = PlayerInfo.Online.Items;
foreach (Player pl in players) { SetNoDelay(pl, noDelay); }
}
}