本文整理汇总了C#中ProcessedPacket.Read方法的典型用法代码示例。如果您正苦于以下问题:C# ProcessedPacket.Read方法的具体用法?C# ProcessedPacket.Read怎么用?C# ProcessedPacket.Read使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ProcessedPacket
的用法示例。
在下文中一共展示了ProcessedPacket.Read方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
//.........这里部分代码省略.........
示例2: 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);
}