Beispiel #1
0
        public void Receive(ref MinecraftClient client, GameStream stream)
        {
            string          username  = stream.ReadString();
            string          idRequest = new WebClient().DownloadString(PlayerDatabase.uuidRetrieval + username).Trim();
            UniqueIdRequest request   = JsonConvert.DeserializeObject <UniqueIdRequest>(idRequest);

            for (int x = 0; x < PlayerDatabase.Players.Count; x++)
            {
                Player player = PlayerDatabase.Players[x];
                if (player.UniqueId.toString().Remove('-') == request.UniqueId)
                {
                    player.Username = username; // Make sure username is updated
                    PlayerDatabase.Players.RemoveAt(x);
                    PlayerDatabase.Players.Add(player);
                    PlayerDatabase.Save();
                }
            }

            Logger.Log($"{username} is trying to connect. ({request.UniqueId})");

            if (!Config.EnableEncryption)
            {
                new LoginSuccess(false).Send(ref client, stream);
            }
            else
            {
                new EncryptionRequest().Send(ref client, stream);
            }
        }
Beispiel #2
0
        public static void ReceiveClientSettings(Player player, GameStream stream)
        {
            string   locale       = stream.ReadString();
            byte     viewDistance = stream.ReadByte();
            ChatMode chatMode     = (ChatMode)(int)stream.ReadVarInt().Value;
            bool     colors       = stream.ReadBoolean();
            byte     skinParts    = stream.ReadByte();
            VarInt   mainHand     = stream.ReadVarInt();

            player.Locale        = locale;
            player.ViewDistance  = viewDistance;
            player.ChatMode      = chatMode;
            player.ColorsEnabled = colors;

            foreach (SkinPart part in SkinParts)
            {
                if (skinParts.IsBitSet(part))
                {
                    player.DisplayedSkinParts.Add(part);
                }
            }

            player.MainHand.Value = mainHand;
            SendPlayerSlot(player, stream, player.Slot);
            // TODO - Declare Recipes
            // TODO - Set Tags
            // TODO - Set Entity Statuses
        }
Beispiel #3
0
        public static void ReceivePluginMessage(Player player, GameStream stream)
        {
            string channel    = stream.ReadString();
            long   lengthLeft = stream.Length - stream.Position;

            byte[]     name  = stream.ReadByteArray((int)lengthLeft);
            Identifier ident = new Identifier
            {
                Namespace = channel,
                Name      = Encoding.UTF8.GetString(name)
            };

            Logger.Write("Received identifier from client: " +
                         ident);
        }
Beispiel #4
0
        public static void ReceiveLoginStart(Player client, GameStream stream)
        {
            string username = stream.ReadString();

            stream.ServerId = RandomServerId();
            client.Username = username;
            Logger.Write(username + " is connecting.");

            if (Config.Security.EnableEncryption)
            {
                SendEncryptionRequest(client, stream);
            }
            else
            {
                SendSuccess(client, stream);
            }
        }
Beispiel #5
0
        public void Receive(ref MinecraftClient client, GameStream stream)
        {
            VarInt protocolVersion = stream.ReadVarInt();
            string serverAddress   = stream.ReadString();
            ushort port            = stream.ReadShort();
            VarInt nextState       = stream.ReadVarInt();

            if (nextState == 1)
            {
                client.State = ConnectionState.Status;
            }
            else if (nextState == 2)
            {
                client.State = ConnectionState.Login;
            }
            else
            {
                throw new Exception("Invalid Next State - Handshake");
            }
        }
        public static void ReceiveHandshake(Player client, GameStream stream)
        {
            VarInt protocolVersion = stream.ReadVarInt();
            string serverAddress   = stream.ReadString();
            ushort port            = stream.ReadShort();
            VarInt next            = stream.ReadVarInt();

            if (!CheckHandshakeInfo(protocolVersion, serverAddress, port, next))
            {
                return;
            }

            switch ((int)next.Value)
            {
            case 1:     // Status
                client.State = SessionState.Status;
                StatusPackets.SendStatus(client, stream);
                break;

            case 2:     // Login
                client.State = SessionState.Login;
                break;
            }
        }
 public override IByteReadable ReadFrom(GameStream stream)
 {
     this.Token = stream.ReadString();
     return(this);
 }