本文整理汇总了C#中MinecraftClient类的典型用法代码示例。如果您正苦于以下问题:C# MinecraftClient类的具体用法?C# MinecraftClient怎么用?C# MinecraftClient使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MinecraftClient类属于命名空间,在下文中一共展示了MinecraftClient类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: EncryptionKeyRequest
public static void EncryptionKeyRequest(MinecraftClient client, IPacket _packet)
{
var packet = (EncryptionKeyRequestPacket)_packet;
var random = RandomNumberGenerator.Create();
client.SharedSecret = new byte[16];
random.GetBytes(client.SharedSecret); // Generate a secure AES key
if (packet.ServerId != "-") // Online mode
{
// Authenticate with minecraft.net
var data = Encoding.ASCII.GetBytes(packet.ServerId)
.Concat(client.SharedSecret)
.Concat(packet.PublicKey).ToArray();
var hash = Cryptography.JavaHexDigest(data);
var webClient = new WebClient();
string result = webClient.DownloadString("http://session.minecraft.net/game/joinserver.jsp?user=" +
Uri.EscapeUriString(client.Session.Username) +
"&sessionId=" + Uri.EscapeUriString(client.Session.SessionId) +
"&serverId=" + Uri.EscapeUriString(hash));
if (result != "OK")
LogProvider.Log("Unable to verify session: " + result);
}
var parser = new AsnKeyParser(packet.PublicKey);
var key = parser.ParseRSAPublicKey();
// Encrypt shared secret and verification token
var crypto = new RSACryptoServiceProvider();
crypto.ImportParameters(key);
var encryptedSharedSecret = crypto.Encrypt(client.SharedSecret, false);
var encryptedVerification = crypto.Encrypt(packet.VerificationToken, false);
var response = new EncryptionKeyResponsePacket(encryptedSharedSecret, encryptedVerification);
client.SendPacket(response);
}
示例2: HandlePacket
public override void HandlePacket(MinecraftServer Server, ref MinecraftClient Client)
{
if (!Client.ReadyToSpawn)
return;
Client.Entity.Pitch = Pitch;
Client.Entity.Yaw = Yaw;
}
示例3: SendPacket
public override void SendPacket(MinecraftServer server, MinecraftClient client)
{
client.SendData(CreateBuffer(
DataUtility.CreateInt32(EntityId),
DataUtility.CreateInt16(SlotIndex),
Item.GetData()));
}
示例4: HandlePacket
public override void HandlePacket(MinecraftServer Server, ref MinecraftClient Client)
{
switch (Action)
{
case EntityAction.Crouch:
Client.IsCrouching = true;
break;
case EntityAction.Uncrouch:
Client.IsCrouching = false;
break;
case EntityAction.StartSprinting:
Client.IsSprinting = true;
break;
case EntityAction.StopSprinting:
Client.IsSprinting = false;
break;
}
if (Action != EntityAction.LeaveBed) // NOTE: Does this matter?
{
this.EntityId = Client.Entity.Id;
for (int i = 0; i <
Server.GetClientsInWorld(Server.GetClientWorld(Client)).Count(); i++)
{
if (Server.Clients [i] != Client)
Server.Clients [i].SendPacket(this);
}
Server.ProcessSendQueue();
}
}
示例5: EntityAction
public static void EntityAction(MinecraftClient client, MinecraftServer server, IPacket _packet)
{
var packet = (EntityActionPacket)_packet;
switch (packet.Action)
{
case EntityActionPacket.EntityAction.Crouch:
client.Entity.IsCrouching = true;
break;
case EntityActionPacket.EntityAction.Uncrouch:
client.Entity.IsCrouching = false;
break;
case EntityActionPacket.EntityAction.StartSprinting:
client.Entity.IsSprinting = true;
break;
case EntityActionPacket.EntityAction.StopSprinting:
client.Entity.IsSprinting = false;
break;
case EntityActionPacket.EntityAction.LeaveBed:
client.Entity.LeaveBed();
break;
}
if (packet.Action != EntityActionPacket.EntityAction.LeaveBed) // NOTE: Does this matter?
{
// TODO ?
}
}
示例6: SendPacket
public override void SendPacket(MinecraftServer server, MinecraftClient client)
{
byte[] payload = new byte[] { PacketId, (byte)EntityIds.Length };
foreach (int id in EntityIds)
payload = payload.Concat(DataUtility.CreateInt32(id)).ToArray();
client.SendData(payload);
}
示例7: AddChunk
private static void AddChunk(MinecraftClient client, int x, int z, ushort primaryBitMap, ushort addBitMap, bool lightIncluded, bool groundUp, byte[] data)
{
var coordinates = new Coordinates2D(x, z);
var relativePosition = GetRelativeChunkPosition(coordinates);
var chunk = new Chunk(relativePosition);
var sectionCount = GetSectionCount(primaryBitMap);
// Run through the sections
// TODO: Support block IDs >255
for (int y = 0; y < 16; y++)
{
if ((primaryBitMap & (1 << y)) > 0)
{
// Blocks
Array.Copy(data, y * BlockDataLength, chunk.Sections[y].Blocks, 0, BlockDataLength);
// Metadata
Array.Copy(data, (BlockDataLength * sectionCount) + (y * NibbleDataLength),
chunk.Sections[y].Metadata.Data, 0, NibbleDataLength);
// Light
Array.Copy(data, ((BlockDataLength + NibbleDataLength) * sectionCount) + (y * NibbleDataLength),
chunk.Sections[y].BlockLight.Data, 0, NibbleDataLength);
// Sky light
if (lightIncluded)
{
Array.Copy(data, ((BlockDataLength + NibbleDataLength + NibbleDataLength) * sectionCount) + (y * NibbleDataLength),
chunk.Sections[y].SkyLight.Data, 0, NibbleDataLength);
}
}
}
if (groundUp)
Array.Copy(data, data.Length - chunk.Biomes.Length, chunk.Biomes, 0, chunk.Biomes.Length);
client.World.SetChunk(coordinates, chunk);
//client.OnChunkRecieved(new ChunkRecievedEventArgs(position, new ReadOnlyChunk(chunk)));
}
示例8: EncryptionKeyResponse
public static void EncryptionKeyResponse(MinecraftClient client, IPacket _packet)
{
// Enable encryption
client.Stream = new MinecraftStream(new AesStream(new BufferedStream(client.NetworkStream), client.SharedSecret));
client.SendPacket(new ClientStatusPacket(ClientStatusPacket.ClientStatus.InitialSpawn));
LogProvider.Log("Logged in.");
}
示例9: SendPacket
public override void SendPacket(MinecraftServer server, MinecraftClient client)
{
// TODO: Refactor like mad
var buffer = new List<byte>();
buffer.Add(PacketId);
buffer.AddRange(DataUtility.CreateInt32(Item.Id));
if (Item.Item.Empty)
buffer.AddRange(DataUtility.CreateInt16(-1));
else
{
buffer.AddRange(DataUtility.CreateInt16((short)Item.Item.Id)); // TODO: Make slots use signed shorts
buffer.Add(Item.Item.Count);
buffer.AddRange(DataUtility.CreateInt16((short)Item.Item.Metadata));
buffer.AddRange(DataUtility.CreateInt16(-1)); // TODO: Nbt appears to be sent here
}
buffer.AddRange(DataUtility.CreateAbsoluteInteger(Item.Position.X));
buffer.AddRange(DataUtility.CreateAbsoluteInteger(Item.Position.Y));
buffer.AddRange(DataUtility.CreateAbsoluteInteger(Item.Position.Z));
buffer.AddRange(DataUtility.CreatePackedByte(Item.Pitch));
buffer.AddRange(DataUtility.CreatePackedByte(Item.Pitch));
buffer.AddRange(DataUtility.CreatePackedByte(Item.Yaw));
client.SendData(buffer.ToArray());
}
示例10: ClientStatus
public static void ClientStatus(MinecraftClient client, MinecraftServer server, IPacket _packet)
{
var packet = (ClientStatusPacket)_packet;
if (packet.Status == ClientStatusPacket.ClientStatus.InitialSpawn)
{
// Create a hash for session verification
SHA1 sha1 = SHA1.Create();
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.SendPacket(new DisconnectPacket("Failed to verify username!"));
return;
}
}
server.LogInPlayer(client);
}
else if (packet.Status == ClientStatusPacket.ClientStatus.Respawn)
{
// TODO
}
}
示例11: SendPacket
public override void SendPacket(MinecraftServer server, MinecraftClient client)
{
client.SendData(CreateBuffer(
DataUtility.CreateInt32((int)SpawnPosition.X),
DataUtility.CreateInt32((int)SpawnPosition.Y),
DataUtility.CreateInt32((int)SpawnPosition.Z)));
}
示例12: BlockChange
public static void BlockChange(MinecraftClient client, IPacket _packet)
{
var packet = (BlockChangePacket)_packet;
var position = new Coordinates3D(packet.X, packet.Y, packet.Z);
client.World.SetBlockId(position, (short)packet.BlockType);
client.World.SetMetadata(position, packet.BlockMetadata);
}
示例13: SendPacket
public override void SendPacket(MinecraftServer server, MinecraftClient client)
{
client.SendData(CreateBuffer(
DataUtility.CreateString(PlayerName),
DataUtility.CreateBoolean(Online),
DataUtility.CreateInt16(Ping)));
}
示例14: HandlePacket
public override void HandlePacket(MinecraftServer server, MinecraftClient client)
{
if (!client.ReadyToSpawn)
return;
client.Entity.Pitch = Pitch;
client.Entity.Yaw = Yaw;
}
示例15: ChatMessage
public static void ChatMessage(MinecraftClient client, IPacket _packet)
{
var packet = (ChatMessagePacket)_packet;
LogProvider.Log(packet.Message, LogImportance.High);
client.OnChatMessage(new ChatMessageEventArgs(packet.Message, RemoveChatCodes(packet.Message)));
}