Esempio n. 1
0
        /// <summary>
        /// Creates a new client, starts reading and parsing packets, and sets up some base settings for the client.
        /// </summary>
        /// <param name="baseSock"></param>
        /// <param name="ip"></param>
        public NetworkClient(TcpClient baseSock, string ip)
        {
            // -- Creates an object for holding all of the settings for this client.
            // -- This is to declutter the main client class of tons of variables.
            CS = new ClientSettings
            {
                LastActive = DateTime.UtcNow,
                Entities = new Dictionary<int, EntityStub>(),
                CPEExtensions = new Dictionary<string, int>(),
                SelectionCuboids = new List<byte>(),
                LoggedIn = false,
                CurrentIndex = 0,
                UndoObjects = new List<Undo>(),
                Ip = ip
            };

            BaseSocket = baseSock; // -- Sets up the socket
            BaseStream = BaseSocket.GetStream();

            WSock = new ClassicWrapped.ClassicWrapped {Stream = BaseStream};

            SendQueue = new ConcurrentQueue<IPacket>(); // -- Send queue for outgoing packets.
            Populate(); // -- Populates reconizable client -> server packets.

            DataRunner = new Thread(DataHandler); // -- Thread for handling incoming data, sending data from the send queue, and updating entity positions.
            DataRunner.Start();

            EntityThread = new Thread(ExtrasHandler); // -- Thread for checking position for teleporters and kill blocks.
            EntityThread.Start();
        }
Esempio n. 2
0
        /// <summary>
        /// Begins the connection process to the server, including the sending of a handshake once connected.
        /// </summary>
        public void Connect()
        {
            try {
                BaseSock = new TcpClient();
                var ar = BaseSock.BeginConnect(ClientBot.Ip, ClientBot.Port, null, null);

                using (ar.AsyncWaitHandle) {
                    if (!ar.AsyncWaitHandle.WaitOne(TimeSpan.FromSeconds(5), false)) {
                        BaseSock.Close();
                        ClientBot.RaiseErrorMessage("Failed to connect: Timeout.");
                        return;
                    }

                    BaseSock.EndConnect(ar);
                }
            } catch (Exception e) {
                ClientBot.RaiseErrorMessage("Failed to connect: " + e.Message);
                return;
            }

            ClientBot.RaiseInfoMessage("Connected to server.");

            BaseStream = BaseSock.GetStream();
            WSock = new ClassicWrapped.ClassicWrapped {_Stream = BaseStream};

            DoHandshake();

            _handler = new Thread(Handle);
            _handler.Start();

            _timeoutHandler = new Thread(Timeout);
            _timeoutHandler.Start();
        }
Esempio n. 3
0
        public NetworkClient(TcpClient baseSock, Hypercube Core)
        {
            BaseSocket = baseSock;
            BaseStream = BaseSocket.GetStream();

            ServerCore = Core;

            wSock         = new ClassicWrapped.ClassicWrapped();
            wSock._Stream = BaseStream;

            Populate();

            CS = new ClientSettings();
            CS.CPEExtensions    = new Dictionary <string, int>();
            CS.SelectionCuboids = new List <byte>();
            CS.LoggedIn         = false;

            DataRunner = new Thread(DataHandler);
            DataRunner.Start();
        }
Esempio n. 4
0
        /// <summary>
        /// For kicking clients in the pre-connection stage with a message.
        /// </summary>
        /// <param name="message"></param>
        /// <param name="client"></param>
        public void RawKick(string message, TcpClient client)
        {
            var tempWrapped = new ClassicWrapped.ClassicWrapped {Stream = client.GetStream()};

            tempWrapped.WriteByte(14);
            tempWrapped.WriteString(message);
            tempWrapped.Purge();
            Thread.Sleep(100); // -- Small delay to ensure message delivery
        }