本文整理汇总了C#中GonzoNet.NetworkClient.Disconnect方法的典型用法代码示例。如果您正苦于以下问题:C# NetworkClient.Disconnect方法的具体用法?C# NetworkClient.Disconnect怎么用?C# NetworkClient.Disconnect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GonzoNet.NetworkClient
的用法示例。
在下文中一共展示了NetworkClient.Disconnect方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnChallengeRecieved
public static void OnChallengeRecieved(NetworkClient Client, ProcessedPacket Packet)
{
byte[] CResponse = Packet.ReadBytes(Packet.ReadByte());
if (CResponse.SequenceEqual(ChallengeResponse))
Console.WriteLine("Received correct challenge response, client was authenticated!");
else
Console.WriteLine("Received incorrect challenge response, client was NOT authenticated!");
string Username = Packet.ReadString();
Console.WriteLine("Username: " + Username);
byte[] PasswordHash = Packet.ReadBytes(Packet.ReadByte());
Client.Disconnect();
}
示例2: OnPacket
public override void OnPacket(NetworkClient client, ProcessedPacket packet)
{
lock (TickBuffer)
{
var tick = new VMNetTickList();
try {
using (var reader = new BinaryReader(packet))
{
tick.Deserialize(reader);
}
} catch (Exception)
{
client.Disconnect();
return;
}
for (int i = 0; i < tick.Ticks.Count; i++)
{
TickBuffer.Enqueue(tick.Ticks[i]);
}
}
}
示例3: OnLoginFailResponse
/// <summary>
/// Occurs when the client was not authenticated by the loginserver.
/// Called by UILoginDialog.cs.
/// </summary>
/// <param name="Client">The client that received the packet.</param>
/// <param name="Packet">The packet that was received.</param>
public static void OnLoginFailResponse(ref NetworkClient Client, ProcessedPacket Packet)
{
EventObject Event;
switch (Packet.ReadByte())
{
case 0x01:
Event = new EventObject(EventCodes.BAD_USERNAME);
EventSink.RegisterEvent(Event);
break;
case 0x02:
Event = new EventObject(EventCodes.BAD_PASSWORD);
EventSink.RegisterEvent(Event);
break;
case 0x03:
Event = new EventObject(EventCodes.AUTHENTICATION_FAILURE);
EventSink.RegisterEvent(Event);
break;
}
Client.Disconnect();
}
示例4: OnInvalidVersionResponse
public static void OnInvalidVersionResponse(ref NetworkClient Client, ProcessedPacket Packet)
{
Client.Disconnect();
}
示例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: HandleCharacterCreate
public static void HandleCharacterCreate(NetworkClient Client, ProcessedPacket P)
{
Logger.LogDebug("Received CharacterCreate!");
bool ClientAuthenticated = false;
byte AccountStrLength = (byte)P.ReadByte();
byte[] AccountNameBuf = new byte[AccountStrLength];
P.Read(AccountNameBuf, 0, AccountStrLength);
string AccountName = Encoding.ASCII.GetString(AccountNameBuf);
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);
Client.ClientEncryptor.Username = AccountName;
string Token = P.ReadString();
string GUID = "";
foreach (ClientToken CToken in NetworkFacade.TransferringClients.GetList())
{
if (CToken.ClientIP == Client.RemoteIP)
{
if (CToken.Token == Token)
{
PacketStream SuccessPacket = new PacketStream(0x64, (int)(PacketHeaders.ENCRYPTED + 1));
SuccessPacket.WriteByte((byte)TSODataModel.Entities.CharacterCreationStatus.Success);
Client.SendEncrypted(0x64, SuccessPacket.ToArray());
ClientAuthenticated = true;
GUID = CToken.CharacterGUID;
}
break;
}
}
SimBase Char = new SimBase(new Guid(GUID));
Char.Timestamp = P.ReadPascalString();
Char.Name = P.ReadPascalString();
Char.Sex = P.ReadPascalString();
Char.Description = P.ReadPascalString();
Char.HeadOutfitID = P.ReadUInt64();
Char.BodyOutfitID = P.ReadUInt64();
Char.Appearance = (AppearanceType)P.ReadByte();
Char.CityID = new Guid(P.ReadString());
Char.CreatedThisSession = true;
var characterModel = new Character();
characterModel.Name = Char.Name;
characterModel.Sex = Char.Sex;
characterModel.Description = Char.Description;
characterModel.LastCached = Char.Timestamp;
characterModel.GUID = Char.GUID;
characterModel.HeadOutfitID = (long)Char.HeadOutfitID;
characterModel.BodyOutfitID = (long)Char.BodyOutfitID;
characterModel.AccountID = account.AccountID;
characterModel.AppearanceType = (int)Char.Appearance;
characterModel.City = Char.CityID.ToString();
var status = db.Characters.CreateCharacter(characterModel);
}
//Invalid token, should never occur...
if (!ClientAuthenticated)
{
PacketStream SuccessPacket = new PacketStream(0x65, (int)(PacketHeaders.ENCRYPTED + 1));
SuccessPacket.WriteByte((byte)TSODataModel.Entities.CharacterCreationStatus.GeneralError);
Client.SendEncrypted(0x64, SuccessPacket.ToArray());
Client.Disconnect();
}
}
示例8: 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);
//.........这里部分代码省略.........
示例9: Reconnect
/// <summary>
/// Reconnects to a CityServer.
/// </summary>
public void Reconnect(ref NetworkClient Client, CityInfo SelectedCity, LoginArgsContainer LoginArgs)
{
Client.Disconnect();
if (LoginArgs.Enc == null)
{
System.Diagnostics.Debug.WriteLine("LoginArgs.Enc was null!");
LoginArgs.Enc = new GonzoNet.Encryption.AESEncryptor(Convert.ToBase64String(PlayerAccount.Hash));
}
else if (LoginArgs.Username == null || LoginArgs.Password == null)
{
System.Diagnostics.Debug.WriteLine("LoginArgs.Username or LoginArgs.Password was null!");
LoginArgs.Username = PlayerAccount.Username;
LoginArgs.Password = Convert.ToBase64String(PlayerAccount.Hash);
}
Client.Connect(LoginArgs);
}
示例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);
}