Skip to content

Commit

Permalink
Merge pull request #279 from Srdjan-V/master
Browse files Browse the repository at this point in the history
Make AbstractMsgBase write methods type specific
  • Loading branch information
LossyDragon authored Sep 13, 2024
2 parents b4b3d74 + 35be983 commit f138bc1
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 48 deletions.
84 changes: 42 additions & 42 deletions src/main/java/in/dragonbra/javasteam/base/AbstractMsgBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,39 +50,67 @@ public long seek(long offset, SeekOrigin seekOrigin) {
return payload.seek(offset, seekOrigin);
}

public void write(byte data) throws IOException {
public void writeByte(byte data) throws IOException {
writer.write(data);
}

public void write(short data) throws IOException {
public byte readByte() throws IOException {
return reader.readByte();
}

public void writeBytes(byte[] data) throws IOException {
writer.write(data);
}

public byte[] readBytes(int numBytes) throws IOException {
return reader.readBytes(numBytes);
}

public void writeShort(short data) throws IOException {
writer.writeShort(data);
}

public void write(int data) throws IOException {
public short readShort() throws IOException {
return reader.readShort();
}

public void writeInt(int data) throws IOException {
writer.writeInt(data);
}

public void write(long data) throws IOException {
public int readInt() throws IOException {
return reader.readInt();
}

public void writeLong(long data) throws IOException {
writer.writeLong(data);
}

public void write(byte[] data) throws IOException {
writer.write(data);
public long readLong() throws IOException {
return reader.readLong();
}

public void write(float data) throws IOException {
public void writeFloat(float data) throws IOException {
writer.writeFloat(data);
}

public void write(double data) throws IOException {
public float readFloat() throws IOException {
return reader.readFloat();
}

public void writeDouble(double data) throws IOException {
writer.writeDouble(data);
}

public void write(String data) throws IOException {
write(data, Charset.defaultCharset());
public double readDouble() throws IOException {
return reader.readDouble();
}

public void writeString(String data) throws IOException {
writeString(data, Charset.defaultCharset());
}

public void write(String data, Charset charset) throws IOException {
public void writeString(String data, Charset charset) throws IOException {
if (data == null) {
return;
}
Expand All @@ -91,44 +119,16 @@ public void write(String data, Charset charset) throws IOException {
throw new IllegalArgumentException("charset is null");
}

write(data.getBytes(charset));
writeBytes(data.getBytes(charset));
}

public void writeNullTermString(String data) throws IOException {
writeNullTermString(data, Charset.defaultCharset());
}

public void writeNullTermString(String data, Charset charset) throws IOException {
write(data, charset);
write("\0", charset);
}

public byte readByte() throws IOException {
return reader.readByte();
}

public byte[] readBytes(int numBytes) throws IOException {
return reader.readBytes(numBytes);
}

public short readShort() throws IOException {
return reader.readShort();
}

public int readInt() throws IOException {
return reader.readInt();
}

public long readLong() throws IOException {
return reader.readLong();
}

public float readFloat() throws IOException {
return reader.readFloat();
}

public double readDouble() throws IOException {
return reader.readDouble();
writeString(data, charset);
writeString("\0", charset);
}

public String readNullTermString() throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,9 @@ private void handleEncryptRequest(IPacketMsg packetMsg) {
byte[] keyCrc = CryptoHelper.crcHash(encryptedHandshakeBlob);

try {
response.write(encryptedHandshakeBlob);
response.write(keyCrc);
response.write(0);
response.writeBytes(encryptedHandshakeBlob);
response.writeBytes(keyCrc);
response.writeInt(0);
} catch (IOException e) {
logger.debug(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -423,9 +423,9 @@ class SteamFriends : ClientMsgHandler() {
body.type = EChatInfoType.StateChange

try {
write(client.steamID.convertToUInt64()) // ChatterActedOn
write(EChatMemberStateChange.Left.code()) // StateChange
write(client.steamID.convertToUInt64()) // ChatterActedBy
writeLong(client.steamID.convertToUInt64()) // ChatterActedOn
writeInt(EChatMemberStateChange.Left.code()) // StateChange
writeLong(client.steamID.convertToUInt64()) // ChatterActedBy
} catch (e: IOException) {
logger.debug(e)
}
Expand Down

0 comments on commit f138bc1

Please sign in to comment.