private void SendServerMessage(ExtractorMessage serverMsg = ExtractorMessage.SyncAll) { if (Main.netMode != NetmodeID.Server) { return; } bool syncAll = serverMsg == ExtractorMessage.SyncAll; ModPacket packet = GadgetBox.Instance.GetPacket(MessageType.ExtractorMessage, syncAll ? 12 : serverMsg == ExtractorMessage.SyncOn ? 6 : 7); packet.Write(ID); packet.Write((byte)serverMsg); if (serverMsg == ExtractorMessage.SyncOn || syncAll) { packet.Write(IsON); } if (serverMsg == ExtractorMessage.SyncPower || syncAll) { packet.Write(Power); } if (serverMsg == ExtractorMessage.SyncMud || syncAll) { packet.Write(Mud); } if (serverMsg == ExtractorMessage.SyncChlorophyte || syncAll) { packet.Write(Chlorophyte); } packet.Send(); }
private void SendClientMessage(ExtractorMessage clientMsg, short mud = 0) { if (Main.netMode != NetmodeID.MultiplayerClient) { return; } bool AddMud = clientMsg == ExtractorMessage.SyncMud; ModPacket packet = GadgetBox.Instance.GetPacket(MessageType.ExtractorMessage, AddMud ? 7 : 5); packet.Write(ID); packet.Write((byte)clientMsg); if (AddMud) { packet.Write(mud); } packet.Send(); }
internal void ReceiveExtractorMessage(BinaryReader reader, int whoAmI) { ExtractorMessage message = (ExtractorMessage)reader.ReadByte(); ModPacket packet; switch (message) { case ExtractorMessage.SyncPlayer: byte owner = reader.ReadByte(); if (Main.netMode == NetmodeID.MultiplayerClient) { if (ID == ChlorophyteExtractorUI.ExtractorTE.ID && owner != Main.myPlayer) { CloseUI(false, true); if (owner == byte.MaxValue) { break; } } else if (ID != ChlorophyteExtractorUI.ExtractorTE.ID && owner == Main.myPlayer) { Main.LocalPlayer.Gadget().machinePos = Position; OpenUI(true); } CurrentPlayer = owner; break; } if (owner != byte.MaxValue && owner != whoAmI) { break; } CurrentPlayer = owner; packet = GadgetBox.Instance.GetPacket(MessageType.ExtractorMessage, 6); packet.Write(ID); packet.Write((byte)ExtractorMessage.SyncPlayer); packet.Write(owner); packet.Send(-1, whoAmI); break; case ExtractorMessage.RequestExtractorOpen: if (Main.netMode != NetmodeID.Server || CurrentPlayer != byte.MaxValue) { break; } CurrentPlayer = (byte)whoAmI; packet = GadgetBox.Instance.GetPacket(MessageType.ExtractorMessage, 6); packet.Write(ID); packet.Write((byte)ExtractorMessage.SyncPlayer); packet.Write((byte)whoAmI); packet.Send(); break; case ExtractorMessage.SyncOn: case ExtractorMessage.SyncPower: case ExtractorMessage.SyncMud: case ExtractorMessage.SyncChlorophyte: case ExtractorMessage.SyncAll: bool syncAll = message == ExtractorMessage.SyncAll; bool isServer = Main.netMode == NetmodeID.Server; if (message == ExtractorMessage.SyncOn || syncAll) { IsON = isServer ? !IsON : reader.ReadBoolean(); } if (message == ExtractorMessage.SyncPower || syncAll) { Power = isServer ? MaxResources : reader.ReadInt16(); } if (message == ExtractorMessage.SyncMud || syncAll) { Mud = (short)(reader.ReadInt16() + (isServer ? Mud : 0)); } if (message == ExtractorMessage.SyncChlorophyte || syncAll) { if (isServer) { ExtractChloro(); } else { Chlorophyte = reader.ReadInt16(); } } SendServerMessage(message); break; case ExtractorMessage.ExtractorEffect: ExtractorEffect(reader.ReadInt16(), reader.ReadInt16()); break; } }