-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClass1.cs
More file actions
117 lines (109 loc) · 4.33 KB
/
Copy pathClass1.cs
File metadata and controls
117 lines (109 loc) · 4.33 KB
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
using Rocket.API;
using Rocket.Core.Plugins;
using Rocket.Unturned.Player;
using SDG.Unturned;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
namespace UnQueue
{
public class Class1 : RocketPlugin<Config>, IRocketPlayer
{
Task Offload;
public string Id => throw new NotImplementedException();
public string DisplayName => throw new NotImplementedException();
public bool IsAdmin => throw new NotImplementedException();
public int CompareTo(object obj)
{
throw new NotImplementedException();
}
protected override void Load()
{
Rocket.Core.Logging.Logger.Log("Loading");
if(Configuration.Instance.sync) StartCoroutine(nameof(loop));
else Offload = Task.Run(() => StartCoroutine(nameof(loop)));
if(Configuration.Instance.ReservedSlots != 0 && Configuration.Instance.MaxPlayers != 0)
{
Rocket.Unturned.U.Events.OnPlayerDisconnected += PDC;
}
Rocket.Core.Logging.Logger.Log("Loaded");
}
protected override void Unload()
{
StopAllCoroutines();
if (!Configuration.Instance.sync) Offload.Dispose();
if (Configuration.Instance.ReservedSlots != 0 && Configuration.Instance.MaxPlayers != 0)
{
Rocket.Unturned.U.Events.OnPlayerDisconnected -= PDC;
}
Rocket.Core.Logging.Logger.Log("Unloaded");
}
void PDC(UnturnedPlayer player)
{
if (Provider.maxPlayers > Configuration.Instance.MaxPlayers) Provider.maxPlayers = (byte)Provider.clients.Count;
}
private IEnumerator loop()
{
yield return new WaitForSeconds(Configuration.Instance.Interval);
CheckQueue();
StartCoroutine(nameof(loop));
}
void oCC() {
#if DEBUG
Rocket.Core.Logging.Logger.Log("Client connected! (" + Provider.pending.Count.ToString() + ")");
#endif
CheckQueue();
}
void CheckQueue()
{
//List<SteamPending> gg = Provider.pending;
for (byte i = 0; i < Provider.pending.Count; i++)
try
{
if (Provider.pending[i] == null || Provider.pending[i].playerID.steamID == null) continue;
RocketPlayer player = new RocketPlayer(Provider.pending[i].playerID.steamID.ToString());
if (player != null && player.HasPermission(Configuration.Instance.Permission))
{
if (Provider.clients.Count >= Provider.maxPlayers)
{
if (Configuration.Instance.BypassMaxPlayers || Configuration.Instance.ReservedSlots > Provider.maxPlayers) { Provider.maxPlayers += 1; } else { PrependQue(ref i); player = null; continue; }
}
if (Provider.pending[i].canAcceptYet)
{
#if DEBUG
Rocket.Core.Logging.Logger.Log("Accepting " + i);
#endif
Provider.accept(Provider.pending[i]);
continue;
}
#if DEBUG
Rocket.Core.Logging.Logger.Log("Sending verify packets to " + i);
#endif
PrependQue(ref i);
Provider.pending[i].sendVerifyPacket();
Provider.pending[i].inventoryDetailsReady();
}
player = null;
}
catch (Exception e) { Rocket.Core.Logging.Logger.LogException(e); }
}
void PrependQue(ref byte i)
{
if (i > Configuration.Instance.PrependPosition)
{
Provider.pending.Insert(0, Provider.pending[i]);
Provider.pending.RemoveAt(i + 1);
// i--;
// Unneccessary in this case
#if DEBUG
Rocket.Core.Logging.Logger.Log("Prepended " + i);
#endif
//Provider.pending.RemoveAt(i);
}
}
}
}