Commit 92faa770 authored by mercury233's avatar mercury233

Merge branch 'master' into patch-v1362

parents cb634664 b08d0a2d
......@@ -298,6 +298,8 @@ namespace WindBot.Game
string otherName = (player == 0) ? _room.Names[1] : _room.Names[0];
if (player < 4)
Logger.DebugWriteLine(otherName + " say to " + myName + ": " + message);
else
Logger.DebugWriteLine("System message(" + player + "): " + message);
}
private void OnErrorMsg(BinaryReader packet)
......@@ -308,6 +310,7 @@ namespace WindBot.Game
packet.ReadByte();
packet.ReadByte();
int pcode = packet.ReadInt32();
Logger.DebugWriteLine("Error message received: " + msg + ", code: " + pcode);
if (msg == 2) //ERRMSG_DECKERROR
{
int code = pcode & 0xFFFFFFF;
......
......@@ -73,7 +73,7 @@ namespace WindBot.Game
packet = GamePacketFactory.Create(CtosMessage.JoinGame);
packet.Write(_proVersion);
packet.Write(junk);
packet.WriteUnicode(_roomInfo, 30);
packet.WriteUnicode(_roomInfo, 20);
Connection.Send(packet);
}
......@@ -84,9 +84,8 @@ namespace WindBot.Game
public void Chat(string message)
{
byte[] content = Encoding.Unicode.GetBytes(message + "\0");
BinaryWriter chat = GamePacketFactory.Create(CtosMessage.Chat);
chat.Write(content);
chat.WriteUnicodeAutoLength(message, 255);
Connection.Send(chat);
}
......
......@@ -6,15 +6,40 @@ namespace YGOSharp.Network.Utils
{
public static class BinaryExtensions
{
// fixed length strings
public static void WriteUnicode(this BinaryWriter writer, string text, int len)
{
byte[] unicode = Encoding.Unicode.GetBytes(text);
byte[] result = new byte[len * 2];
int max = len * 2 - 2;
Array.Copy(unicode, result, unicode.Length > max ? max : unicode.Length);
int copy = unicode.Length;
if (unicode.Length > len * 2 - 2)
{
copy = len * 2 - 2;
#if DEBUG
throw new ArgumentException("String '" + text + "' is too long for fixed length " + len + ".");
#endif
}
Array.Copy(unicode, result, copy);
writer.Write(result);
}
// variable length strings
public static void WriteUnicodeAutoLength(this BinaryWriter writer, string text, int maxlen)
{
byte[] result = Encoding.Unicode.GetBytes(text + "\0");
int len = result.Length / 2;
if (len > maxlen)
{
len = maxlen;
result[len * 2 - 2] = 0;
result[len * 2 - 1] = 0;
#if DEBUG
throw new ArgumentException("String '" + text + "' is too long for max length " + maxlen + ".");
#endif
}
writer.Write(result, 0, len * 2);
}
public static string ReadUnicode(this BinaryReader reader, int len)
{
byte[] unicode = reader.ReadBytes(len * 2);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment