本文整理汇总了C#中RemoteClient.Disconnect方法的典型用法代码示例。如果您正苦于以下问题:C# RemoteClient.Disconnect方法的具体用法?C# RemoteClient.Disconnect怎么用?C# RemoteClient.Disconnect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RemoteClient
的用法示例。
在下文中一共展示了RemoteClient.Disconnect方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: EncryptionKeyResponse
public static void EncryptionKeyResponse(RemoteClient client, MinecraftServer server, IPacket _packet)
{
var packet = (EncryptionKeyResponsePacket)_packet;
var decryptedToken = server.CryptoServiceProvider.Decrypt(packet.VerificationToken, false);
for (int i = 0; i < decryptedToken.Length; i++)
{
if (decryptedToken[i] != client.VerificationToken[i])
{
client.Disconnect("Unable to authenticate.");
return;
}
}
client.SharedKey = server.CryptoServiceProvider.Decrypt(packet.SharedSecret, false);
client.SendPacket(new EncryptionKeyResponsePacket(new byte[0], new byte[0]));
}
示例2: EncryptionKeyResponse
public static void EncryptionKeyResponse(RemoteClient client, MinecraftServer server, IPacket _packet)
{
var packet = (EncryptionKeyResponsePacket)_packet;
var decryptedToken = server.CryptoServiceProvider.Decrypt(packet.VerificationToken, false);
for (int i = 0; i < decryptedToken.Length; i++)
{
if (decryptedToken[i] != client.VerificationToken[i])
{
client.Disconnect("Unable to authenticate.");
return;
}
}
client.SharedKey = server.CryptoServiceProvider.Decrypt(packet.SharedSecret, false);
// Create a hash for session verification
AsnKeyBuilder.AsnMessage encodedKey = AsnKeyBuilder.PublicKeyToX509(server.ServerKey);
byte[] shaData = Encoding.UTF8.GetBytes(client.ServerId)
.Concat(client.SharedKey)
.Concat(encodedKey.GetBytes()).ToArray();
string hash = Cryptography.JavaHexDigest(shaData);
// Talk to sessionserver.minecraft.net
if (server.Settings.OnlineMode)
{
var webClient = new WebClient();
var webReader = new StreamReader(webClient.OpenRead(
new Uri(string.Format(sessionCheckUri, client.Username, hash))));
string response = webReader.ReadToEnd();
webReader.Close();
var json = JToken.Parse(response);
if (string.IsNullOrEmpty(response))
{
client.Disconnect("Failed to verify username!");
return;
}
client.UUID = json["id"].Value<string>();
}
client.NetworkStream = new AesStream(client.NetworkClient.GetStream(), client.SharedKey);
client.NetworkManager.BaseStream = client.NetworkStream;
client.EncryptionEnabled = true;
var eventArgs = new ConnectionEstablishedEventArgs(client);
server.OnConnectionEstablished(eventArgs);
if (eventArgs.PermitConnection)
server.LogInPlayer(client);
else
client.Disconnect(eventArgs.DisconnectReason);
}
示例3: LoginStart
public static void LoginStart(RemoteClient client, MinecraftServer server, IPacket _packet)
{
var packet = (LoginStartPacket)_packet;
if (server.Clients.Any(c => c.IsLoggedIn && c.Username == packet.Username))
client.Disconnect("You're already on this server!");
else
{
client.Username = packet.Username;
if (server.Settings.OnlineMode)
client.ServerId = CreateId();
else
{
client.ServerId = CreateId();
client.UUID = Guid.NewGuid().ToJavaUUID();
}
if (server.Settings.EnableEncryption)
client.SendPacket(CreateEncryptionRequest(client, server));
else
server.LogInPlayer(client);
}
}
示例4: ClientStatus
public static void ClientStatus(RemoteClient client, MinecraftServer server, IPacket _packet)
{
var packet = (ClientStatusPacket)_packet;
if (packet.Status == ClientStatusPacket.ClientStatus.InitialSpawn)
{
// Create a hash for session verification
AsnKeyBuilder.AsnMessage encodedKey = AsnKeyBuilder.PublicKeyToX509(server.ServerKey);
byte[] shaData = Encoding.UTF8.GetBytes(client.AuthenticationHash)
.Concat(client.SharedKey)
.Concat(encodedKey.GetBytes()).ToArray();
string hash = Cryptography.JavaHexDigest(shaData);
// Talk to session.minecraft.net
if (server.Settings.OnlineMode)
{
var webClient = new WebClient();
var webReader = new StreamReader(webClient.OpenRead(
new Uri(string.Format(sessionCheckUri, client.Username, hash))));
string response = webReader.ReadToEnd();
webReader.Close();
if (response != "YES")
{
client.Disconnect("Failed to verify username!");
return;
}
}
var eventArgs = new ConnectionEstablishedEventArgs(client);
server.OnConnectionEstablished(eventArgs);
if (eventArgs.PermitConnection)
server.LogInPlayer(client);
else
client.Disconnect(eventArgs.DisconnectReason);
}
else if (packet.Status == ClientStatusPacket.ClientStatus.Respawn)
{
var world = client.Entity.World;
client.Entity.Position = new Vector3(
client.Entity.SpawnPoint.X,
// FIXME: This seems to drop the player camera from half the height of a login spawn
client.Entity.SpawnPoint.Y,
client.Entity.SpawnPoint.Z);
client.Entity.Health = client.Entity.MaxHealth;
client.Entity.Food = 20;
client.Entity.FoodSaturation = 20;
server.EntityManager.SpawnEntity(world, client.Entity);
client.SendPacket(new UpdateHealthPacket(client.Entity.Health, client.Entity.Food, client.Entity.FoodSaturation));
client.SendPacket(new RespawnPacket(Dimension.Overworld, server.Settings.Difficulty, client.GameMode, World.Height, world.WorldGenerator.GeneratorName));
client.SendPacket(new PlayerPositionAndLookPacket(client.Entity.Position.X, client.Entity.Position.Y, client.Entity.Position.Z,
client.Entity.Position.Y + PlayerEntity.Height, client.Entity.Yaw, client.Entity.Pitch, true));
}
}