Console client: Adding support for additional network packets (avatar handling). This is not specifically for use in the console, but for .NET based test cases.

This commit is contained in:
lotodore
2009-01-11 11:18:51 +00:00
parent d72cdb6873
commit 4f7cf0bdb2
11 changed files with 405 additions and 0 deletions
+8
View File
@@ -25,6 +25,14 @@ namespace pokerth_lib
{
public class GameInfo : IdObject
{
public enum AvatarFileType
{
PNG,
GIF,
JPG,
UNKNOWN
}
public enum Mode
{
Created = 1,
+3
View File
@@ -48,5 +48,8 @@ namespace pokerth_lib
void RemovedFromGame();
void ChatText(string name, string message);
void Error(string message);
void AvatarBegin(uint id, uint fileSize, GameInfo.AvatarFileType type);
void AvatarData(uint id, byte[] block);
void AvatarEnd(uint id);
}
}
+5
View File
@@ -55,5 +55,10 @@ namespace pokerth_lib
void VisitRemovedFromGame(NetPacket p);
void VisitChatText(NetPacket p);
void VisitError(NetPacket p);
void VisitRetrieveAvatar(NetPacket p);
void VisitAvatarHeader(NetPacket p);
void VisitAvatarFile(NetPacket p);
void VisitAvatarEnd(NetPacket p);
void VisitUnknownAvatar(NetPacket p);
}
}
+24
View File
@@ -146,6 +146,12 @@ namespace pokerth_lib
ChatText,
ErrorReason,
RemoveReason,
RequestId,
AvatarMD5,
AvatarFileSize,
AvatarFileType,
AvatarBlockSize,
AvatarFileData,
}
public enum ListPropType
@@ -288,6 +294,9 @@ namespace pokerth_lib
case NetTypeError :
tmpPacket = new NetPacketError();
break;
case NetTypeRetrieveAvatar :
tmpPacket = new NetPacketRetrieveAvatar();
break;
}
return tmpPacket;
}
@@ -367,6 +376,21 @@ namespace pokerth_lib
case NetTypeError :
tmpPacket = new NetPacketError(size, reader);
break;
case NetTypeRetrieveAvatar :
tmpPacket = new NetPacketRetrieveAvatar(size, reader);
break;
case NetTypeAvatarHeader :
tmpPacket = new NetPacketAvatarHeader(size, reader);
break;
case NetTypeAvatarFile :
tmpPacket = new NetPacketAvatarFile(size, reader);
break;
case NetTypeAvatarEnd :
tmpPacket = new NetPacketAvatarEnd(size, reader);
break;
case NetTypeUnknownAvatar :
tmpPacket = new NetPacketUnknownAvatar(size, reader);
break;
default:
break;
}
+56
View File
@@ -0,0 +1,56 @@
/***************************************************************************
* Copyright (C) 2009 by Lothar May *
* *
* This file is part of pokerth_console. *
* pokerth_console is free software: you can redistribute it and/or *
* modify it under the terms of the GNU Affero General Public License *
* as published by the Free Software Foundation, either version 3 of *
* the License, or (at your option) any later version. *
* *
* pokerth_console is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the *
* GNU Affero General Public License along with pokerth_console. *
* If not, see <http://www.gnu.org/licenses/>. *
***************************************************************************/
using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.Net.Sockets;
using System.IO;
namespace pokerth_lib
{
class NetPacketAvatarEnd : NetPacket
{
public NetPacketAvatarEnd()
: base(NetPacket.NetTypeAvatarEnd)
{
}
public NetPacketAvatarEnd(int size, BinaryReader r)
: base(NetPacket.NetTypeAvatarEnd)
{
if (size != 8)
throw new NetPacketException("NetPacketAvatarEnd invalid size.");
Properties.Add(PropType.RequestId,
Convert.ToString(IPAddress.NetworkToHostOrder((int)r.ReadUInt32())));
}
public override void Accept(INetPacketVisitor visitor)
{
visitor.VisitAvatarEnd(this);
}
public override byte[] ToByteArray()
{
throw new NotImplementedException();
}
}
}
@@ -0,0 +1,62 @@
/***************************************************************************
* Copyright (C) 2009 by Lothar May *
* *
* This file is part of pokerth_console. *
* pokerth_console is free software: you can redistribute it and/or *
* modify it under the terms of the GNU Affero General Public License *
* as published by the Free Software Foundation, either version 3 of *
* the License, or (at your option) any later version. *
* *
* pokerth_console is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the *
* GNU Affero General Public License along with pokerth_console. *
* If not, see <http://www.gnu.org/licenses/>. *
***************************************************************************/
using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.Net.Sockets;
using System.IO;
namespace pokerth_lib
{
class NetPacketAvatarFile : NetPacket
{
public NetPacketAvatarFile()
: base(NetPacket.NetTypeAvatarFile)
{
}
public NetPacketAvatarFile(int size, BinaryReader r)
: base(NetPacket.NetTypeAvatarFile)
{
if (size < 12)
throw new NetPacketException("NetPacketAvatarFile invalid size.");
Properties.Add(PropType.RequestId,
Convert.ToString(IPAddress.NetworkToHostOrder((int)r.ReadUInt32())));
int avatarBlockSize = IPAddress.NetworkToHostOrder((short)r.ReadUInt16());
Properties.Add(PropType.AvatarBlockSize,
Convert.ToString(avatarBlockSize));
r.ReadUInt16(); // reserved
Properties.Add(PropType.AvatarFileData,
Convert.ToBase64String(r.ReadBytes(avatarBlockSize)));
}
public override void Accept(INetPacketVisitor visitor)
{
visitor.VisitAvatarFile(this);
}
public override byte[] ToByteArray()
{
throw new NotImplementedException();
}
}
}
@@ -0,0 +1,60 @@
/***************************************************************************
* Copyright (C) 2009 by Lothar May *
* *
* This file is part of pokerth_console. *
* pokerth_console is free software: you can redistribute it and/or *
* modify it under the terms of the GNU Affero General Public License *
* as published by the Free Software Foundation, either version 3 of *
* the License, or (at your option) any later version. *
* *
* pokerth_console is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the *
* GNU Affero General Public License along with pokerth_console. *
* If not, see <http://www.gnu.org/licenses/>. *
***************************************************************************/
using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.Net.Sockets;
using System.IO;
namespace pokerth_lib
{
class NetPacketAvatarHeader : NetPacket
{
public NetPacketAvatarHeader()
: base(NetPacket.NetTypeAvatarHeader)
{
}
public NetPacketAvatarHeader(int size, BinaryReader r)
: base(NetPacket.NetTypeAvatarHeader)
{
if (size != 16)
throw new NetPacketException("NetPacketAvatarHeader invalid size.");
Properties.Add(PropType.RequestId,
Convert.ToString(IPAddress.NetworkToHostOrder((int)r.ReadUInt32())));
Properties.Add(PropType.AvatarFileSize,
Convert.ToString(IPAddress.NetworkToHostOrder((int)r.ReadUInt32())));
Properties.Add(PropType.AvatarFileType,
Convert.ToString(IPAddress.NetworkToHostOrder((short)r.ReadUInt16())));
}
public override void Accept(INetPacketVisitor visitor)
{
visitor.VisitAvatarHeader(this);
}
public override byte[] ToByteArray()
{
throw new NotImplementedException();
}
}
}
@@ -0,0 +1,67 @@
/***************************************************************************
* Copyright (C) 2009 by Lothar May *
* *
* This file is part of pokerth_console. *
* pokerth_console is free software: you can redistribute it and/or *
* modify it under the terms of the GNU Affero General Public License *
* as published by the Free Software Foundation, either version 3 of *
* the License, or (at your option) any later version. *
* *
* pokerth_console is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the *
* GNU Affero General Public License along with pokerth_console. *
* If not, see <http://www.gnu.org/licenses/>. *
***************************************************************************/
using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.Net.Sockets;
using System.IO;
namespace pokerth_lib
{
class NetPacketRetrieveAvatar : NetPacket
{
public NetPacketRetrieveAvatar()
: base(NetPacket.NetTypeRetrieveAvatar)
{
}
public NetPacketRetrieveAvatar(int size, BinaryReader r)
: base(NetPacket.NetTypeRetrieveAvatar)
{
if (size != 24)
throw new NetPacketException("NetTypeRetrieveAvatar invalid size.");
Properties.Add(PropType.RequestId,
Convert.ToString(IPAddress.NetworkToHostOrder((int)r.ReadUInt32())));
Properties.Add(PropType.AvatarMD5,
Convert.ToBase64String(r.ReadBytes(16)));
}
public override void Accept(INetPacketVisitor visitor)
{
visitor.VisitRetrieveAvatar(this);
}
public override byte[] ToByteArray()
{
MemoryStream memStream = new MemoryStream();
BinaryWriter w = new BinaryWriter(memStream);
w.Write(IPAddress.HostToNetworkOrder((short)Type));
w.Write(IPAddress.HostToNetworkOrder((short)24));
w.Write(IPAddress.HostToNetworkOrder((int)
Convert.ToUInt32(Properties[PropType.RequestId])));
w.Write(Convert.FromBase64String(Properties[PropType.AvatarMD5]));
return memStream.ToArray();
}
}
}
@@ -0,0 +1,56 @@
/***************************************************************************
* Copyright (C) 2009 by Lothar May *
* *
* This file is part of pokerth_console. *
* pokerth_console is free software: you can redistribute it and/or *
* modify it under the terms of the GNU Affero General Public License *
* as published by the Free Software Foundation, either version 3 of *
* the License, or (at your option) any later version. *
* *
* pokerth_console is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the *
* GNU Affero General Public License along with pokerth_console. *
* If not, see <http://www.gnu.org/licenses/>. *
***************************************************************************/
using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.Net.Sockets;
using System.IO;
namespace pokerth_lib
{
class NetPacketUnknownAvatar : NetPacket
{
public NetPacketUnknownAvatar()
: base(NetPacket.NetTypeUnknownAvatar)
{
}
public NetPacketUnknownAvatar(int size, BinaryReader r)
: base(NetPacket.NetTypeUnknownAvatar)
{
if (size != 8)
throw new NetPacketException("NetPacketUnknownAvatar invalid size.");
Properties.Add(PropType.RequestId,
Convert.ToString(IPAddress.NetworkToHostOrder((int)r.ReadUInt32())));
}
public override void Accept(INetPacketVisitor visitor)
{
visitor.VisitUnknownAvatar(this);
}
public override byte[] ToByteArray()
{
throw new NotImplementedException();
}
}
}
+49
View File
@@ -398,6 +398,55 @@ namespace pokerth_lib
m_callback.Error(p.Properties[NetPacket.PropType.ErrorReason]);
}
public void VisitRetrieveAvatar(NetPacket p)
{
// TODO
}
public void VisitAvatarHeader(NetPacket p)
{
uint tmpAvatarType = Convert.ToUInt32(p.Properties[NetPacket.PropType.AvatarFileType]);
GameInfo.AvatarFileType avatarType;
switch (tmpAvatarType)
{
case 1 :
avatarType = GameInfo.AvatarFileType.PNG;
break;
case 2 :
avatarType = GameInfo.AvatarFileType.JPG;
break;
case 3 :
avatarType = GameInfo.AvatarFileType.GIF;
break;
default :
avatarType = GameInfo.AvatarFileType.UNKNOWN;
break;
}
m_callback.AvatarBegin(
Convert.ToUInt32(p.Properties[NetPacket.PropType.RequestId]),
Convert.ToUInt32(p.Properties[NetPacket.PropType.AvatarFileSize]),
avatarType);
}
public void VisitAvatarFile(NetPacket p)
{
m_callback.AvatarData(
Convert.ToUInt32(p.Properties[NetPacket.PropType.RequestId]),
Convert.FromBase64String(p.Properties[NetPacket.PropType.AvatarFileData]));
}
public void VisitAvatarEnd(NetPacket p)
{
m_callback.AvatarEnd(
Convert.ToUInt32(p.Properties[NetPacket.PropType.RequestId]));
}
public void VisitUnknownAvatar(NetPacket p)
{
// TODO
}
private PokerTHData m_data;
private SenderThread m_sender;
private ICallback m_callback;