-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNetHelper.cs
61 lines (57 loc) · 1.65 KB
/
NetHelper.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
using System.IO;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
namespace CheddarMod
{
public class NetHelper
{
public static void HandlePacket(BinaryReader reader, int sender)
{
MessageType type = (MessageType)reader.ReadByte();
switch (type)
{
case MessageType.WheelUpdate:
ReceiveWheelUpdate(reader);
break;
default:
break;
}
}
public static void SendWheelUpdate(bool enabled)
{
if (Main.netMode == NetmodeID.MultiplayerClient)
{
ModPacket packet = CheddarMod.Instance.GetPacket();
packet.Write((byte)MessageType.WheelUpdate);
packet.Write(enabled);
packet.Send();
}
}
public static void ReceiveWheelUpdate(BinaryReader reader)
{
bool flag = reader.ReadBoolean();
if (flag)
{
// Console.WriteLine("Enabled via packet");
Main.dayRate = 60;
Main.fastForwardTime = true;
}
else
{
// Console.WriteLine("Disabled via packet");
Main.fastForwardTime = false;
}
CheddarWorld.timeWheel = flag;
// CheddarWorld.timeWheel = reader.ReadBoolean();
if (Main.netMode == NetmodeID.Server)
{
NetMessage.SendData(MessageID.WorldData); // Just in case
}
}
}
enum MessageType : byte
{
WheelUpdate,
}
}