本文整理汇总了C#中GonzoNet.NetworkClient.Send方法的典型用法代码示例。如果您正苦于以下问题:C# NetworkClient.Send方法的具体用法?C# NetworkClient.Send怎么用?C# NetworkClient.Send使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GonzoNet.NetworkClient
的用法示例。
在下文中一共展示了NetworkClient.Send方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SendServerInfo
/// <summary>
/// Send information about this CityServer to the LoginServer...
/// </summary>
/// <param name="Client">The client connected to the LoginServer.</param>
public static void SendServerInfo(NetworkClient Client)
{
PacketStream Packet = new PacketStream(0x64, 0);
Packet.WriteByte(0x64);
MemoryStream PacketBody = new MemoryStream();
BinaryWriter PacketWriter = new BinaryWriter(PacketBody);
PacketWriter.Write((string)GlobalSettings.Default.CityName);
PacketWriter.Write((string)GlobalSettings.Default.CityDescription);
PacketWriter.Write((string)Settings.BINDING.Address.ToString());
PacketWriter.Write((int)Settings.BINDING.Port);
PacketWriter.Write((byte)1); //CityInfoStatus.OK
PacketWriter.Write((ulong)GlobalSettings.Default.CityThumbnail);
PacketWriter.Write((string)GlobalSettings.Default.ServerID);
PacketWriter.Write((ulong)GlobalSettings.Default.Map);
PacketWriter.Flush();
Packet.WriteUInt16((ushort)(PacketBody.ToArray().Length + PacketHeaders.UNENCRYPTED));
Packet.Write(PacketBody.ToArray(), 0, (int)PacketWriter.BaseStream.Length);
Packet.Flush();
PacketWriter.Close();
Client.Send(Packet.ToArray());
}
示例2: HandleChallengeResponse
public static void HandleChallengeResponse(NetworkClient Client, ProcessedPacket P)
{
PacketStream OutPacket;
if (P.DecryptedSuccessfully)
{
int Length = P.ReadByte();
byte[] CResponse;
if (P.BufferLength >= Length)
CResponse = P.ReadBytes(Length);
else
{
//Authentication failed, so send this packet unencrypted.
OutPacket = new PacketStream((byte)PacketType.LOGIN_FAILURE_CITY, 0);
OutPacket.WriteHeader();
OutPacket.WriteUInt16((ushort)(PacketHeaders.UNENCRYPTED + 1));
OutPacket.WriteByte(0x03); //Bad challenge response.
Client.Send(OutPacket.ToArray());
Logger.LogInfo("Sent LOGIN_FAILURE_CITY!");
return;
}
AESDecryptionArgs DecryptionArgs = Client.ClientEncryptor.GetDecryptionArgsContainer().AESDecryptArgs;
if (DecryptionArgs.Challenge.SequenceEqual(CResponse))
{
OutPacket = new PacketStream((byte)PacketType.LOGIN_SUCCESS_CITY, 0);
OutPacket.WriteByte(0x01);
Client.SendEncrypted((byte)PacketType.LOGIN_SUCCESS_CITY, OutPacket.ToArray());
Logger.LogInfo("Sent LOGIN_SUCCESS_CITY!");
}
else
{
//Authentication failed, so send this packet unencrypted.
OutPacket = new PacketStream((byte)PacketType.LOGIN_FAILURE_CITY, 0);
OutPacket.WriteHeader();
OutPacket.WriteUInt16((ushort)(PacketHeaders.UNENCRYPTED + 1));
OutPacket.WriteByte(0x03); //Bad challenge response.
Client.Send(OutPacket.ToArray());
Logger.LogInfo("Sent LOGIN_FAILURE_CITY!");
}
}
else
{
//Authentication failed, so send this packet unencrypted.
OutPacket = new PacketStream((byte)PacketType.LOGIN_FAILURE_CITY, 0);
OutPacket.WriteHeader();
OutPacket.WriteUInt16((ushort)(PacketHeaders.UNENCRYPTED + 1));
OutPacket.WriteByte(0x03); //Bad challenge response.
Client.Send(OutPacket.ToArray());
Debug.WriteLine("HandleChallengeResponse - decryption failed!");
Logger.LogInfo("Sent LOGIN_FAILURE_CITY!");
}
}
示例3: InitialClientConnect
/// <summary>
/// A client requested login.
/// </summary>
/// <param name="Client">NetworkClient instance.</param>
/// <param name="Packet">ProcessedPacket instance.</param>
public static void InitialClientConnect(NetworkClient Client, ProcessedPacket Packet)
{
Console.WriteLine("Server receives data - test 1");
PacketStream EncryptedPacket = new PacketStream(0x02, 0);
EncryptedPacket.WriteHeader();
ClientPublicKey = Packet.ReadBytes((Packet.ReadByte()));
AESEncryptor Enc = (AESEncryptor)Client.ClientEncryptor;
Enc.NOnce = Packet.ReadBytes((Packet.ReadByte()));
Enc.PublicKey = ClientPublicKey;
Enc.PrivateKey = ServerPrivateKey;
Client.ClientEncryptor = Enc;
//THIS IS IMPORTANT - public key must be derived from private!
ServerPublicKey = ServerPrivateKey.PublicKey.ToByteArray();
ChallengeResponse = new byte[16];
m_Random.GetNonZeroBytes(ChallengeResponse);
MemoryStream StreamToEncrypt = new MemoryStream();
BinaryWriter Writer = new BinaryWriter(StreamToEncrypt);
Writer.Write(ChallengeResponse, 0, ChallengeResponse.Length);
Writer.Flush();
byte[] EncryptedData = StaticStaticDiffieHellman.Encrypt(ServerPrivateKey,
ECDiffieHellmanCngPublicKey.FromByteArray(ClientPublicKey, CngKeyBlobFormat.EccPublicBlob), Enc.NOnce,
StreamToEncrypt.ToArray());
EncryptedPacket.WriteUInt16((ushort)(PacketHeaders.UNENCRYPTED +
(1 + ServerPublicKey.Length) +
(1 + EncryptedData.Length)));
EncryptedPacket.WriteByte((byte)ServerPublicKey.Length);
EncryptedPacket.WriteBytes(ServerPublicKey);
EncryptedPacket.WriteByte((byte)EncryptedData.Length);
EncryptedPacket.WriteBytes(EncryptedData);
Client.Send(EncryptedPacket.ToArray());
NetworkFacade.Listener.UpdateClient(Client);
Console.WriteLine("Test 1: passed!");
}
示例4: SendInitialConnectPacket
//First packet sent from client to server.
public static void SendInitialConnectPacket(NetworkClient Client, string Username)
{
PacketStream InitialPacket = new PacketStream(0x01, 0);
InitialPacket.WriteHeader();
ECDiffieHellmanCng PrivateKey = Client.ClientEncryptor.GetDecryptionArgsContainer().AESDecryptArgs.PrivateKey;
//IMPORTANT: Public key must derive from the private key!
PacketHandlers.ClientPublicKey = PrivateKey.PublicKey.ToByteArray();
byte[] NOnce = Client.ClientEncryptor.GetDecryptionArgsContainer().AESDecryptArgs.NOnce;
InitialPacket.WriteUInt16((ushort)((byte)PacketHeaders.UNENCRYPTED +
(PacketHandlers.ClientPublicKey.Length + 1) + (NOnce.Length + 1)));
InitialPacket.WriteByte((byte)PacketHandlers.ClientPublicKey.Length);
InitialPacket.WriteBytes(PacketHandlers.ClientPublicKey);
InitialPacket.WriteByte((byte)NOnce.Length);
InitialPacket.WriteBytes(NOnce);
Client.Send(InitialPacket.ToArray());
}
示例5: 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;
}
}
示例6: 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;
}
//.........这里部分代码省略.........
示例7: HandleLoginRequest
/**
* Actual packet handlers
*/
public static void HandleLoginRequest(NetworkClient Client, ProcessedPacket P)
{
Logger.LogInfo("Received LoginRequest!\r\n");
byte AccountStrLength = (byte)P.ReadByte();
byte[] AccountNameBuf = new byte[AccountStrLength];
P.Read(AccountNameBuf, 0, AccountStrLength);
string AccountName = SanitizeAccount(Encoding.ASCII.GetString(AccountNameBuf));
Logger.LogInfo("Accountname: " + AccountName + "\r\n");
byte HashLength = (byte)P.ReadByte();
byte[] HashBuf = new byte[HashLength];
P.Read(HashBuf, 0, HashLength);
if (AccountName == "")
{
PacketStream OutPacket = new PacketStream((byte)PacketType.LOGIN_FAILURE, 2);
OutPacket.WriteHeader();
OutPacket.WriteByte(0x01);
Client.Send(OutPacket.ToArray());
Logger.LogInfo("Bad accountname - sent SLoginFailResponse!\r\n");
Client.Disconnect();
return;
}
using (var db = DataAccess.Get())
{
var account = db.Accounts.GetByUsername(AccountName);
byte KeyLength = (byte)P.ReadByte();
byte[] EncKey = new byte[KeyLength];
P.Read(EncKey, 0, KeyLength);
//TODO: Do something with this...
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;
}
if (!GlobalSettings.Default.CreateAccountsOnLogin)
{
Logger.LogInfo("Done reading LoginRequest, checking account...\r\n");
if (account == null)
{
PacketStream OutPacket = new PacketStream((byte)PacketType.LOGIN_FAILURE, 2);
OutPacket.WriteHeader();
OutPacket.WriteByte(0x01);
Client.Send(OutPacket.ToArray());
Logger.LogInfo("Bad accountname - sent SLoginFailResponse!\r\n");
Client.Disconnect();
return;
}
else
Client.ClientEncryptor = new ARC4Encryptor(account.Password, EncKey);
}
else
{
if (account == null)
{
try
{
db.Accounts.Create(new Account
{
AccountName = AccountName.ToLower(),
Password = Convert.ToBase64String(HashBuf)
});
}
catch (Exception)
{
PacketStream OutPacket = new PacketStream((byte)PacketType.LOGIN_FAILURE, 2);
OutPacket.WriteHeader();
OutPacket.WriteByte(0x01);
Client.Send(OutPacket.ToArray());
Logger.LogInfo("Bad accountname - sent SLoginFailResponse!\r\n");
Client.Disconnect();
return;
}
account = db.Accounts.GetByUsername(AccountName);
//.........这里部分代码省略.........
示例8: HandleClientToken
/// <summary>
/// A client wanted to transfer to this server, so a token was generated by the login server.
/// </summary>
public static void HandleClientToken(NetworkClient Client, ProcessedPacket P)
{
try
{
ClientToken Token = new ClientToken();
byte CharacterCreate = (byte)P.ReadByte();
Token.AccountID = P.ReadInt32();
Token.ClientIP = P.ReadString();
int ClientPort = P.ReadInt32();
Token.CharacterGUID = P.ReadString();
Token.Token = P.ReadString();
PacketStream PlayerOnlinePacket = new PacketStream(0x67, 0);
PlayerOnlinePacket.WriteHeader();
PlayerOnlinePacket.WriteUInt16((ushort)(PacketHeaders.UNENCRYPTED + 1 +
Token.Token.Length + 1 + Token.ClientIP.Length + 1 + 4));
if (CharacterCreate == 0)
{
if (NetworkFacade.CurrentSession.GetPlayer(Token.CharacterGUID) == null)
{
NetworkClient WaitingClient = NetworkFacade.NetworkListener.GetClient(Token.ClientIP, ClientPort);
//Uh-oh, someone's waiting for their token!
if(WaitingClient != null)
{
PacketStream SuccessPacket = new PacketStream((byte)PacketType.CITY_TOKEN, 0);
SuccessPacket.WriteByte((byte)CityTransferStatus.Success);
WaitingClient.SendEncrypted((byte)PacketType.CITY_TOKEN, SuccessPacket.ToArray());
}
PlayerOnlinePacket.WriteByte(0x01);
PlayerOnlinePacket.WriteString(Token.Token);
PlayerOnlinePacket.WriteString(Token.ClientIP);
PlayerOnlinePacket.WriteInt32(ClientPort);
lock (NetworkFacade.TransferringClients)
{
if (!NetworkFacade.TransferringClients.Contains(Token))
NetworkFacade.TransferringClients.Add(Token);
}
Client.Send(PlayerOnlinePacket.ToArray());
}
else
{
PlayerOnlinePacket.WriteByte(0x02);
PlayerOnlinePacket.WriteString(Token.Token);
PlayerOnlinePacket.WriteString(Token.ClientIP);
PlayerOnlinePacket.WriteInt32(ClientPort);
Client.Send(PlayerOnlinePacket.ToArray());
}
}
else
{
NetworkClient WaitingClient = NetworkFacade.NetworkListener.GetClient(Token.ClientIP, ClientPort);
//Uh-oh, someone's waiting for their token!
if (WaitingClient != null)
{
PacketStream SuccessPacket = new PacketStream((byte)PacketType.CITY_TOKEN, 0);
SuccessPacket.WriteByte((byte)CityTransferStatus.Success);
WaitingClient.SendEncrypted((byte)PacketType.CITY_TOKEN, SuccessPacket.ToArray());
}
if (!NetworkFacade.TransferringClients.Contains(Token))
NetworkFacade.TransferringClients.Add(Token);
}
}
catch (Exception E)
{
Logger.LogDebug("Exception in HandleClientToken: " + E.ToString());
}
}
示例9: HandleKeyFetch
/// <summary>
/// A cityserver requested a decryptionkey for a client!
/// </summary>
public static void HandleKeyFetch(NetworkClient Client, ProcessedPacket P)
{
string AccountName = P.ReadString();
byte[] EncKey = new byte[1];
foreach (NetworkClient Cl in NetworkFacade.CServerListener.Clients)
{
if (Cl.ClientEncryptor.Username == AccountName)
{
EncKey = Cl.ClientEncryptor.GetDecryptionArgsContainer().ARC4DecryptArgs.EncryptionKey;
//TODO: Figure out what to do about CurrentlyActiveSim...
//if (Cl.CurrentlyActiveSim.CreatedThisSession)
{
//TODO: Update the DB to reflect the city that
// this sim resides in.
//Database.UpdateCityForCharacter(Cl.CurrentlyActiveSim.Name, Client.ServerInfo.Name);
}
}
}
PacketStream OutPacket = new PacketStream(0x01, 0x00);
OutPacket.WriteByte((byte)0x01);
OutPacket.WriteByte((byte)(EncKey.Length + 2));
OutPacket.WriteByte((byte)EncKey.Length);
OutPacket.Write(EncKey, 0, EncKey.Length);
Client.Send(OutPacket.ToArray());
//For now, assume client has already disconnected and doesn't need to be disconnected manually.
NetworkFacade.CServerListener.TransferringClients.Remove(Client);
}
示例10: HandleLoginRequest
/**
* Actual packet handlers
*/
public static void HandleLoginRequest(NetworkClient Client, ProcessedPacket P)
{
Logger.LogInfo("Received LoginRequest!\r\n");
byte AccountStrLength = (byte)P.ReadByte();
byte[] AccountNameBuf = new byte[AccountStrLength];
P.Read(AccountNameBuf, 0, AccountStrLength);
string AccountName = Encoding.ASCII.GetString(AccountNameBuf);
Logger.LogInfo("Accountname: " + AccountName + "\r\n");
byte HashLength = (byte)P.ReadByte();
byte[] HashBuf = new byte[HashLength];
P.Read(HashBuf, 0, HashLength);
using (var db = DataAccess.Get())
{
var account = db.Accounts.GetByUsername(AccountName);
byte KeyLength = (byte)P.ReadByte();
byte[] EncKey = new byte[KeyLength];
P.Read(EncKey, 0, KeyLength);
Client.ClientEncryptor = new ARC4Encryptor(account.Password, EncKey);
//TODO: Do something with this...
byte Version1 = (byte)P.ReadByte();
byte Version2 = (byte)P.ReadByte();
byte Version3 = (byte)P.ReadByte();
byte Version4 = (byte)P.ReadByte();
Logger.LogInfo("Done reading LoginRequest, checking account...\r\n");
if (account == null)
{
PacketStream OutPacket = new PacketStream(0x02, 2);
OutPacket.WriteHeader();
OutPacket.WriteByte(0x01);
Client.Send(OutPacket.ToArray());
Logger.LogInfo("Bad accountname - sent SLoginFailResponse!\r\n");
Client.Disconnect();
return;
}
if (account.IsCorrectPassword(AccountName, HashBuf))
{
//0x01 = InitLoginNotify
PacketStream OutPacket = new PacketStream(0x01, 1);
OutPacket.WriteHeader();
OutPacket.WriteByte(0x01);
Client.ClientEncryptor.Username = AccountName;
//This is neccessary to encrypt packets.
//TODO: Put something else here
//Client.Password = Account.GetPassword(AccountName);
Client.Send(OutPacket.ToArray());
Logger.LogInfo("Sent InitLoginNotify!\r\n");
}
}
//Client was modified, update it.
NetworkFacade.ClientListener.UpdateClient(Client);
}
示例11: InitialClientConnect
public static void InitialClientConnect(NetworkClient Client, ProcessedPacket P)
{
Logger.LogInfo("Received InitialClientConnect!");
PacketStream EncryptedPacket = new PacketStream((byte)PacketType.LOGIN_NOTIFY_CITY, 0);
EncryptedPacket.WriteHeader();
AESEncryptor Enc = (AESEncryptor)Client.ClientEncryptor;
Enc.PublicKey = P.ReadBytes((P.ReadByte()));
Enc.NOnce = P.ReadBytes((P.ReadByte()));
Enc.PrivateKey = NetworkFacade.ServerPrivateKey;
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.ServerPrivateKey,
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());
}
示例12: SendOneOff
//uh, this is a little silly.
private void SendOneOff(NetworkClient client, VMNetTick tick)
{
var ticks = new VMNetTickList { Ticks = new List<VMNetTick>() { tick }, ImmediateMode = true };
byte[] data;
using (var stream = new MemoryStream())
{
using (var writer = new BinaryWriter(stream))
{
ticks.SerializeInto(writer);
}
data = stream.ToArray();
}
using (var stream = new PacketStream((byte)PacketType.VM_PACKET, 0))
{
stream.WriteHeader();
stream.WriteInt32(data.Length + (int)PacketHeaders.UNENCRYPTED);
stream.WriteBytes(data);
client.Send(stream.ToArray());
}
}