-
Notifications
You must be signed in to change notification settings - Fork 23
/
Networking.cs
78 lines (70 loc) · 2.76 KB
/
Networking.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
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
namespace BossChecklist
{
enum PacketMessageType : byte {
RequestHideBoss,
RequestClearHidden,
RequestMarkedDownEntry,
RequestClearMarkedDowns,
SendClientConfigMessage,
UpdateAllowTracking,
SendPersonalBestRecordsToServer,
UpdateRecordsFromServerToPlayer,
RequestWorldRecords,
SendWorldRecordsFromServerToPlayer,
UpdateWorldRecordsToAllPlayers,
ResetPlayerRecordForServer,
ResetTrackers
}
internal enum ClientMessageType : byte {
Despawn,
Limb,
Moon
}
internal class Networking {
public static bool NewPersonalBest(NetRecordID netRecord) => netRecord.HasFlag(NetRecordID.PersonalBest_Duration) || netRecord.HasFlag(NetRecordID.PersonalBest_HitsTaken);
public static bool NewWorldRecord(NetRecordID netRecord) => netRecord.HasFlag(NetRecordID.WorldRecord_Duration) || netRecord.HasFlag(NetRecordID.WorldRecord_HitsTaken);
public static bool ResettingRecords(NetRecordID netRecord) => netRecord.HasFlag(NetRecordID.PersonalBest_Reset) || netRecord.HasFlag(NetRecordID.FirstVictory_Reset);
public static bool DownedEntryCheck(ref bool downed) {
bool temp = downed;
downed = true;
if (temp == false && Main.netMode == NetmodeID.Server) {
NetMessage.SendData(MessageID.WorldData);
return true;
}
return false;
}
/// <summary>
/// Send a packet to the server to add, remove, or clear entries from the hidden entries list.
/// </summary>
/// <param name="Key">Provide an entry key to add/remove the entry. Leave blank to clear the entire hidden list.</param>
public static void RequestHiddenEntryUpdate(string Key = null, bool hide = true) {
if (Main.netMode != NetmodeID.MultiplayerClient)
return;
ModPacket packet = BossChecklist.instance.GetPacket();
packet.Write(string.IsNullOrEmpty(Key) ? (byte)PacketMessageType.RequestClearHidden : (byte)PacketMessageType.RequestHideBoss);
if (!string.IsNullOrEmpty(Key)) {
packet.Write(Key);
packet.Write(hide);
}
packet.Send(); // Multiplayer --> Server
}
/// <summary>
/// Send a packet to the server to add, remove, or clear entries from the marked entries list.
/// </summary>
/// <param name="Key">Provide an entry key to add/remove the entry. Leave blank to clear the entire marked list.</param>
public static void RequestMarkedEntryUpdate(string Key = null, bool mark = true) {
if (Main.netMode != NetmodeID.MultiplayerClient)
return;
ModPacket packet = BossChecklist.instance.GetPacket();
packet.Write(string.IsNullOrEmpty(Key) ? (byte)PacketMessageType.RequestClearMarkedDowns : (byte)PacketMessageType.RequestMarkedDownEntry);
if (!string.IsNullOrEmpty(Key)) {
packet.Write(Key);
packet.Write(mark);
}
packet.Send(); // Multiplayer --> Server
}
}
}