本文整理汇总了C#中ProcessedPacket.ReadBytes方法的典型用法代码示例。如果您正苦于以下问题:C# ProcessedPacket.ReadBytes方法的具体用法?C# ProcessedPacket.ReadBytes怎么用?C# ProcessedPacket.ReadBytes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ProcessedPacket
的用法示例。
在下文中一共展示了ProcessedPacket.ReadBytes方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: HandleChallengeResponse
/// <summary>
/// Client sent a response to our challenge, as well as account name and password.
/// </summary>
public static void HandleChallengeResponse(NetworkClient Client, ProcessedPacket P)
{
PacketStream OutPacket;
if (P.BufferLength <= 1)
{
OutPacket = new PacketStream((byte)PacketType.LOGIN_FAILURE, 0);
OutPacket.WriteByte(0x03); //Bad challenge response.
Client.Send(OutPacket.ToArray());
Logger.LogInfo("Bad challenge response - sent SLoginFailResponse!\r\n");
return; //How does this even happen?!
}
int Length = P.ReadByte();
byte[] CResponse;
if (P.BufferLength >= Length)
CResponse = P.ReadBytes(Length);
else
return;
AESDecryptionArgs DecryptionArgs = Client.ClientEncryptor.GetDecryptionArgsContainer().AESDecryptArgs;
if (DecryptionArgs.Challenge.SequenceEqual(CResponse))
{
string AccountName = SanitizeAccount(P.ReadString());
Length = P.ReadByte();
byte[] PasswordHash;
if (P.BufferLength >= Length)
PasswordHash = P.ReadBytes(Length);
else
return;
// Check whether the accountname is empty or is/contains "username"
if (AccountName == string.Empty || AccountName.ToLower().Equals("username") || AccountName.ToLower().Contains("username"))
{
OutPacket = new PacketStream((byte)PacketType.LOGIN_FAILURE, 0);
OutPacket.WriteHeader();
OutPacket.WriteUInt16((ushort)(PacketHeaders.UNENCRYPTED + 1));
OutPacket.WriteByte(0x01);
Client.Send(OutPacket.ToArray());
Logger.LogInfo(@"Bad accountname (""" + AccountName + @""") - sent SLoginFailResponse!\r\n");
Client.Disconnect();
return;
}
using (var db = DataAccess.Get())
{
var account = db.Accounts.GetByUsername(AccountName);
if (!GlobalSettings.Default.CreateAccountsOnLogin)
{
Logger.LogInfo("Done reading LoginRequest, checking account...\r\n");
if (account == null)
{
OutPacket = new PacketStream((byte)PacketType.LOGIN_FAILURE, 0);
OutPacket.WriteHeader();
OutPacket.WriteUInt16((ushort)(PacketHeaders.UNENCRYPTED + 1));
OutPacket.WriteByte(0x01);
Client.Send(OutPacket.ToArray());
Logger.LogInfo(@"Bad accountname (""" + AccountName + @""") - sent SLoginFailResponse!\r\n");
Client.Disconnect();
return;
}
}
else
{
if (account == null)
{
try
{
if (!AccountName.ToLower().Equals("username") || !AccountName.ToLower().Contains("username"))
db.Accounts.Create(new Account
{
AccountName = AccountName.ToLower(),
Password = Convert.ToBase64String(PasswordHash)
});
}
catch (Exception)
{
OutPacket = new PacketStream((byte)PacketType.LOGIN_FAILURE, 0);
OutPacket.WriteHeader();
OutPacket.WriteUInt16((ushort)(PacketHeaders.UNENCRYPTED + 1));
OutPacket.WriteByte(0x01);
Client.Send(OutPacket.ToArray());
Logger.LogInfo(@"Bad accountname (""" + AccountName + @""") - sent SLoginFailResponse!\r\n");
Client.Disconnect();
return;
}
//.........这里部分代码省略.........
示例2: HandleLoginRequest
/// <summary>
/// Client wanted to log in!
/// </summary>
public static void HandleLoginRequest(NetworkClient Client, ProcessedPacket P)
{
try
{
Logger.LogInfo("Received LoginRequest!\r\n");
byte Version1 = (byte)P.ReadByte();
byte Version2 = (byte)P.ReadByte();
byte Version3 = (byte)P.ReadByte();
byte Version4 = (byte)P.ReadByte();
string ClientVersion = Version1.ToString() + "." + Version2.ToString() + "." + Version3.ToString() +
"." + Version4.ToString();
if (ClientVersion != GlobalSettings.Default.ClientVersion)
{
PacketStream OutPacket = new PacketStream((byte)PacketType.INVALID_VERSION, 2);
OutPacket.WriteHeader();
OutPacket.WriteByte(0x01);
Client.Send(OutPacket.ToArray());
Logger.LogInfo("Bad version - sent SInvalidVersion!\r\n");
Client.Disconnect();
return;
}
PacketStream EncryptedPacket = new PacketStream((byte)PacketType.LOGIN_NOTIFY, 0);
EncryptedPacket.WriteHeader();
AESEncryptor Enc = (AESEncryptor)Client.ClientEncryptor;
if (Enc == null)
Enc = new AESEncryptor("");
Enc.PublicKey = P.ReadBytes((P.ReadByte()));
Enc.NOnce = P.ReadBytes((P.ReadByte()));
Enc.PrivateKey = NetworkFacade.ServerKey;
Client.ClientEncryptor = Enc;
MemoryStream StreamToEncrypt = new MemoryStream();
BinaryWriter Writer = new BinaryWriter(StreamToEncrypt);
Writer.Write(Enc.Challenge, 0, Enc.Challenge.Length);
Writer.Flush();
byte[] EncryptedData = StaticStaticDiffieHellman.Encrypt(NetworkFacade.ServerKey,
System.Security.Cryptography.ECDiffieHellmanCngPublicKey.FromByteArray(Enc.PublicKey,
System.Security.Cryptography.CngKeyBlobFormat.EccPublicBlob), Enc.NOnce, StreamToEncrypt.ToArray());
EncryptedPacket.WriteUInt16((ushort)(PacketHeaders.UNENCRYPTED +
(1 + NetworkFacade.ServerPublicKey.Length) +
(1 + EncryptedData.Length)));
EncryptedPacket.WriteByte((byte)NetworkFacade.ServerPublicKey.Length);
EncryptedPacket.WriteBytes(NetworkFacade.ServerPublicKey);
EncryptedPacket.WriteByte((byte)EncryptedData.Length);
EncryptedPacket.WriteBytes(EncryptedData);
Client.Send(EncryptedPacket.ToArray());
}
//This should HOPEFULLY wade off clients sending unreadable (I.E old protocol) packets...
catch (Exception E)
{
Logger.LogDebug("Error while handling login request, disconnecting client: " +
E.ToString());
Client.Disconnect();
return;
}
}
示例3: OnLoginNotifyCity
/// <summary>
/// Received initial packet from CityServer.
/// </summary>
public static void OnLoginNotifyCity(NetworkClient Client, ProcessedPacket Packet)
{
LogThis.Log.LogThis("Received OnLoginNotifyCity!", LogThis.eloglevel.info);
//Should this be stored for permanent access?
byte[] ServerPublicKey = Packet.ReadBytes(Packet.ReadByte());
byte[] EncryptedData = Packet.ReadBytes(Packet.ReadByte());
lock (Client.ClientEncryptor)
{
AESEncryptor Enc = (AESEncryptor)Client.ClientEncryptor;
Enc.PublicKey = ServerPublicKey;
Client.ClientEncryptor = Enc;
lock (NetworkFacade.Client)
NetworkFacade.Client.ClientEncryptor = Enc;
}
ECDiffieHellmanCng PrivateKey = Client.ClientEncryptor.GetDecryptionArgsContainer().AESDecryptArgs.PrivateKey;
byte[] NOnce = Client.ClientEncryptor.GetDecryptionArgsContainer().AESDecryptArgs.NOnce;
byte[] ChallengeResponse = StaticStaticDiffieHellman.Decrypt(PrivateKey,
ECDiffieHellmanCngPublicKey.FromByteArray(ServerPublicKey, CngKeyBlobFormat.EccPublicBlob),
NOnce, EncryptedData);
MemoryStream StreamToEncrypt = new MemoryStream();
BinaryWriter Writer = new BinaryWriter(StreamToEncrypt);
Writer.Write((byte)ChallengeResponse.Length);
Writer.Write(ChallengeResponse, 0, ChallengeResponse.Length);
Writer.Flush();
//Encrypt data using key and IV from server, hoping that it'll be decrypted correctly at the other end...
Client.SendEncrypted((byte)PacketType.CHALLENGE_RESPONSE, StreamToEncrypt.ToArray());
}