forked from mekanism/Mekanism
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'development' into 1.8.9
- Loading branch information
Showing
20 changed files
with
296 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
116 changes: 116 additions & 0 deletions
116
src/main/java/mekanism/common/network/PacketSecurityUpdate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
package mekanism.common.network; | ||
|
||
import io.netty.buffer.ByteBuf; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import mekanism.client.MekanismClient; | ||
import mekanism.common.Mekanism; | ||
import mekanism.common.PacketHandler; | ||
import mekanism.common.frequency.Frequency; | ||
import mekanism.common.network.PacketSecurityUpdate.SecurityUpdateMessage; | ||
import mekanism.common.security.SecurityData; | ||
import mekanism.common.security.SecurityFrequency; | ||
import net.minecraftforge.fml.common.network.simpleimpl.IMessage; | ||
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler; | ||
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext; | ||
|
||
public class PacketSecurityUpdate implements IMessageHandler<SecurityUpdateMessage, IMessage> | ||
{ | ||
@Override | ||
public IMessage onMessage(SecurityUpdateMessage message, MessageContext context) | ||
{ | ||
if(message.packetType == SecurityPacket.UPDATE) | ||
{ | ||
MekanismClient.clientSecurityMap.put(message.playerUsername, message.securityData); | ||
} | ||
|
||
return null; | ||
} | ||
|
||
public static class SecurityUpdateMessage implements IMessage | ||
{ | ||
public SecurityPacket packetType; | ||
|
||
public String playerUsername; | ||
public SecurityData securityData; | ||
|
||
public SecurityUpdateMessage() {} | ||
|
||
public SecurityUpdateMessage(SecurityPacket type, String username, SecurityData data) | ||
{ | ||
packetType = type; | ||
|
||
if(packetType == SecurityPacket.UPDATE) | ||
{ | ||
playerUsername = username; | ||
securityData = data; | ||
} | ||
} | ||
|
||
@Override | ||
public void toBytes(ByteBuf dataStream) | ||
{ | ||
dataStream.writeInt(packetType.ordinal()); | ||
|
||
if(packetType == SecurityPacket.UPDATE) | ||
{ | ||
PacketHandler.writeString(dataStream, playerUsername); | ||
securityData.write(dataStream); | ||
} | ||
else if(packetType == SecurityPacket.FULL) | ||
{ | ||
List<SecurityFrequency> frequencies = new ArrayList<SecurityFrequency>(); | ||
|
||
for(Frequency frequency : Mekanism.securityFrequencies.getFrequencies()) | ||
{ | ||
if(frequency instanceof SecurityFrequency) | ||
{ | ||
frequencies.add((SecurityFrequency)frequency); | ||
} | ||
} | ||
|
||
dataStream.writeInt(frequencies.size()); | ||
|
||
for(SecurityFrequency frequency : frequencies) | ||
{ | ||
PacketHandler.writeString(dataStream, frequency.owner); | ||
new SecurityData(frequency).write(dataStream); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public void fromBytes(ByteBuf dataStream) | ||
{ | ||
packetType = SecurityPacket.values()[dataStream.readInt()]; | ||
|
||
if(packetType == SecurityPacket.UPDATE) | ||
{ | ||
playerUsername = PacketHandler.readString(dataStream); | ||
securityData = SecurityData.read(dataStream); | ||
} | ||
else if(packetType == SecurityPacket.FULL) | ||
{ | ||
MekanismClient.clientSecurityMap.clear(); | ||
|
||
int amount = dataStream.readInt(); | ||
|
||
for(int i = 0; i < amount; i++) | ||
{ | ||
String owner = PacketHandler.readString(dataStream); | ||
SecurityData data = SecurityData.read(dataStream); | ||
|
||
MekanismClient.clientSecurityMap.put(owner, data); | ||
} | ||
} | ||
} | ||
} | ||
|
||
public static enum SecurityPacket | ||
{ | ||
UPDATE, | ||
FULL; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package mekanism.common.security; | ||
|
||
import io.netty.buffer.ByteBuf; | ||
import mekanism.common.security.ISecurityTile.SecurityMode; | ||
|
||
public class SecurityData | ||
{ | ||
public SecurityMode mode = SecurityMode.PUBLIC; | ||
public boolean override; | ||
|
||
public SecurityData() {} | ||
|
||
public SecurityData(SecurityFrequency frequency) | ||
{ | ||
mode = frequency.securityMode; | ||
override = frequency.override; | ||
} | ||
|
||
public void write(ByteBuf dataStream) | ||
{ | ||
dataStream.writeInt(mode.ordinal()); | ||
dataStream.writeBoolean(override); | ||
} | ||
|
||
public static SecurityData read(ByteBuf dataStream) | ||
{ | ||
SecurityData data = new SecurityData(); | ||
|
||
data.mode = SecurityMode.values()[dataStream.readInt()]; | ||
data.override = dataStream.readBoolean(); | ||
|
||
return data; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.