本文整理汇总了C#中MinecraftServer类的典型用法代码示例。如果您正苦于以下问题:C# MinecraftServer类的具体用法?C# MinecraftServer怎么用?C# MinecraftServer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MinecraftServer类属于命名空间,在下文中一共展示了MinecraftServer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SendPacket
public override void SendPacket(MinecraftServer server, MinecraftClient client)
{
client.SendData(CreateBuffer(
DataUtility.CreateInt32(EntityId),
DataUtility.CreateInt16(SlotIndex),
Item.GetData()));
}
示例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)
{
byte[] payload = new byte[] { PacketId, (byte)EntityIds.Length };
foreach (int id in EntityIds)
payload = payload.Concat(DataUtility.CreateInt32(id)).ToArray();
client.SendData(payload);
}
示例4: 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 ?
}
}
示例5: ThreadSleepForever
private MinecraftServer mc; /* synthetic field */
#endregion Fields
#region Constructors
public ThreadSleepForever(MinecraftServer minecraftserver)
{
mc = minecraftserver;
//
setDaemon(true);
start();
}
示例6: Handshake
public static void Handshake(MinecraftClient client, MinecraftServer server, IPacket _packet)
{
var packet = (HandshakePacket)_packet;
if (packet.ProtocolVersion < PacketReader.ProtocolVersion)
{
client.SendPacket(new DisconnectPacket("Outdated client!"));
return;
}
if (packet.ProtocolVersion > PacketReader.ProtocolVersion)
{
client.SendPacket(new DisconnectPacket("Outdated server!"));
return;
}
if (server.Clients.Any(c => c.Username == packet.Username))
{
client.SendPacket(new DisconnectPacket(""));
return;
}
client.Username = packet.Username;
client.Hostname = packet.ServerHostname + ":" + packet.ServerPort;
if (server.Settings.OnlineMode)
client.AuthenticationHash = CreateHash();
else
client.AuthenticationHash = "-";
if (server.Settings.EnableEncryption)
client.SendPacket(CreateEncryptionRequest(client, server));
else
server.LogInPlayer(client);
}
示例7: KeepAlive
public static void KeepAlive(MinecraftClient client, MinecraftServer server, IPacket _packet)
{
var packet = (KeepAlivePacket)_packet;
// TODO: Confirm value validity
client.LastKeepAlive = DateTime.Now;
client.Ping = (short)(client.LastKeepAlive - client.LastKeepAliveSent).TotalMilliseconds;
}
示例8: GetPingValue
private static string GetPingValue(MinecraftServer server)
{
return "§1\0" + PacketReader.ProtocolVersion + "\0" +
PacketReader.FriendlyVersion + "\0" +
server.Settings.MotD + "\0" + server.Clients.Count(c => c.IsLoggedIn) +
"\0" + server.Settings.MaxPlayers;
}
示例9: 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
}
}
示例10: 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());
}
示例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: RegisterHandlers
public static void RegisterHandlers(MinecraftServer server)
{
server.RegisterPacketHandler(typeof(HandshakePacket), LoginHandlers.Handshake);
server.RegisterPacketHandler(typeof(LoginStartPacket), LoginHandlers.LoginStart);
server.RegisterPacketHandler(typeof(EncryptionKeyResponsePacket), LoginHandlers.EncryptionKeyResponse);
server.RegisterPacketHandler(typeof(ClientStatusPacket), LoginHandlers.ClientStatus);
server.RegisterPacketHandler(typeof(ClientSettingsPacket), LoginHandlers.ClientSettings);
server.RegisterPacketHandler(typeof(PlayerPacket), PlayerMovementHandlers.Player);
server.RegisterPacketHandler(typeof(PlayerPositionPacket), PlayerMovementHandlers.PlayerPosition);
server.RegisterPacketHandler(typeof(PlayerLookPacket), PlayerMovementHandlers.PlayerLook);
server.RegisterPacketHandler(typeof(PlayerPositionAndLookPacket), PlayerMovementHandlers.PlayerPositionAndLook);
server.RegisterPacketHandler(typeof(AnimationPacket), PlayerMovementHandlers.Animation);
server.RegisterPacketHandler(typeof(EntityActionPacket), PlayerMovementHandlers.EntityAction);
server.RegisterPacketHandler(typeof(PlayerAbilitiesPacket), PlayerMovementHandlers.PlayerAbilities);
server.RegisterPacketHandler(typeof(CreativeInventoryActionPacket), InventoryHandlers.CreativeInventoryAction);
server.RegisterPacketHandler(typeof(ClickWindowPacket), InventoryHandlers.ClickWindow);
server.RegisterPacketHandler(typeof(CloseWindowPacket), InventoryHandlers.CloseWindow);
server.RegisterPacketHandler(typeof(HeldItemPacket), InventoryHandlers.HeldItemChange);
server.RegisterPacketHandler(typeof(PlayerBlockActionPacket), InteractionHandlers.PlayerDigging);
server.RegisterPacketHandler(typeof(RightClickPacket), InteractionHandlers.RightClick);
server.RegisterPacketHandler(typeof(StatusRequestPacket), StatusRequest);
server.RegisterPacketHandler(typeof(StatusPingPacket), StatusPing);
server.RegisterPacketHandler(typeof(ChatMessagePacket), ChatMessage);
server.RegisterPacketHandler(typeof(KeepAlivePacket), KeepAlive);
}
示例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: SendPacket
public override void SendPacket(MinecraftServer server, MinecraftClient client)
{
byte[] data = new byte[] {PacketId}
.Concat(DataUtility.CreateInt32(EntityId))
.Concat(new byte[] {(byte)Animation}).ToArray();
client.SendData(data);
}