Esempio n. 1
0
        internal static void SendUpdatedPosition(this MasterServer server, int toClient, float[] newPos)
        {
            if (newPos == null || newPos.Length < 3)
            {
                MasterServer.DebugServer(server.serverTypeName, "The new position is either null or doesn't have an x, y, and z.");
                return;
            }

            using (Packet packet = new Packet((int)ServerPackets.updatePosition))
            {
                packet.Write(newPos[0]);
                packet.Write(newPos[1]);
                packet.Write(newPos[2]);

                server.SendUdpData(toClient, packet);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Gives the client an ID and checks if the current username belongs to them.
        /// </summary>
        /// <param name="server">The Master Server to run this on.</param>
        /// <param name="toClient">The client's new ID.</param>
        /// <param name="username">The client's username to validate.</param>
        internal static void ValidateLogin(this MasterServer server, int fromClient, Packet packet)
        {
            string username = packet.ReadString();

            // If the username's length is less than 3, disconnect the client and warn them.
            if (username.Length < 3)
            {
                server.Message(fromClient, "Please enter a username longer than 2 characters. Disconnecting.");
                server.DisconnectClient(fromClient);

                MasterServer.DebugServer(server.serverTypeName, $"Disconnecting Client#{fromClient} for having the username '{username}' which is too short.");

                return;
            }

            server.InitializeLogin(fromClient, username);
        }
Esempio n. 3
0
        /// <summary>
        /// Sends a Client their validated login information.
        /// </summary>
        /// <param name="server">The Master Server to run this on.</param>
        /// <param name="toClient">The client to give a username and ID.</param>
        /// <param name="username">The client's username.</param>
        internal static void InitializeLogin(this MasterServer server, int toClient, string username)
        {
            MasterServer.DebugServer(server.serverTypeName, $"Setting Client#{toClient}'s username to {username}.");

            /**
             * TODO:
             * 1. There's no API decided currently. But, when the time comes, the user should authenticate through that.
             * 2. For now, just receive a username and let them use that name. No real validation needs to take place yet.
             * 3. Think about making it flexible enough to allow users to import their own auth systems.
             */
            using (Packet packet = new Packet((int)ServerPackets.initializeLogin))
            {
                packet.Write(username);
                packet.Write(toClient);

                server.SendTcpData(toClient, packet);
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Handles the client's answer. If it matches the client's name
        /// then initialize them as a Cluster Client.
        /// </summary>
        /// <param name="server">The Master Server to run this on.</param>
        /// <param name="fromClient">The client sending this packet.</param>
        /// <param name="packet">The packet containing the answer and extra data.</param>
        internal static void AnswerPassphrase(this MasterServer server, int fromClient, Packet packet)
        {
            string answer      = packet.ReadString();
            string clusterName = packet.ReadString(); // The requested name for this cluster.

            if (answer == server.clients[fromClient].name)
            {
                server.InitializeCluster(fromClient, clusterName);
            }
            else
            {
                server.Message(fromClient, "Incorrect passphrase. Disconnecting.");
                server.DisconnectClient(fromClient);

                MasterServer.DebugServer(server.serverTypeName, $"Disconnecting Client#{fromClient} for answering their passphrase incorrectly.");

                return;
            }
        }