Skip to content
This repository was archived by the owner on Dec 7, 2020. It is now read-only.

Commit ff7c4aa

Browse files
KaiKai
authored andcommitted
Added UTF-8 support
You can now send UTF-8 encoded characters through PRoCon to the server. However, RCON itself is not sending UTF-8 encoded characters. So, PRoCon now can send UTF-8 encoded characters, but can't receive them. This is ofcourse also working for Plugins, but keep in mind that you have to save your Plugin in UTF-8 format for this to work.
1 parent 43a43da commit ff7c4aa

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/PRoCon.Core/Remote/Packet.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,12 +181,16 @@ public byte[] EncodePacket() {
181181
strWord = strWord.Substring(0, UInt16.MaxValue - 1);
182182
}
183183

184-
byte[] appendEncodedWords = new byte[encodedWords.Length + strWord.Length + 5];
184+
// Convert the word into a null terminated utf-8 string
185+
byte[] byteWord = Encoding.UTF8.GetBytes(strWord + Convert.ToChar(0x00));
186+
187+
byte[] appendEncodedWords = new byte[encodedWords.Length + byteWord.Length + 4];
185188

186189
encodedWords.CopyTo(appendEncodedWords, 0);
187190

188-
BitConverter.GetBytes(strWord.Length).CopyTo(appendEncodedWords, encodedWords.Length);
189-
Encoding.GetEncoding(1252).GetBytes(strWord + Convert.ToChar(0x00)).CopyTo(appendEncodedWords, encodedWords.Length + 4);
191+
// append the actual word size (ignoring the null terminated character) and word
192+
BitConverter.GetBytes(byteWord.Length - 1).CopyTo(appendEncodedWords, encodedWords.Length);
193+
byteWord.CopyTo(appendEncodedWords, encodedWords.Length + 4);
190194

191195
encodedWords = appendEncodedWords;
192196
}
@@ -223,7 +227,7 @@ public void DecodePacket(byte[] rawPacket) {
223227
for (UInt32 ui32WordCount = 0; ui32WordCount < ui32Words; ui32WordCount++) {
224228
UInt32 ui32WordLength = BitConverter.ToUInt32(rawPacket, Packet.PacketHeaderSize + iWordOffset);
225229

226-
this.Words.Add(Encoding.GetEncoding(1252).GetString(rawPacket, Packet.PacketHeaderSize + iWordOffset + 4, (int)ui32WordLength));
230+
this.Words.Add(Encoding.UTF8.GetString(rawPacket, Packet.PacketHeaderSize + iWordOffset + 4, (int)ui32WordLength));
227231

228232
iWordOffset += Convert.ToInt32(ui32WordLength) + 5; // WordLength + WordSize + NullByte
229233
}

0 commit comments

Comments
 (0)