Exemplo n.º 1
0
        /// <summary>
        /// Creates an Rcon Server
        /// </summary>
        /// <param name="rconfig">RConsole Configuration to build off.</param>
        public Rcon(Configuration.RconConfig rconfig)
        {
            rconConnections = new SocketPipe[Rcon.MaxRconConnections];
            for ( int i = 0; i < Rcon.MaxRconConnections; i++ )
                rconConnections[i] = null;

            this.rconfig = rconfig;
            if ( File.Exists( rconfig.UserFile ) )
                rconUsers = new RconUserFile( rconfig.UserFile );
            else
                rconUsers = null; //For now.
            listenSocket = new Socket( AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp );
            listenSocket.SendBufferSize = rconfig.SocketBufferSize;
            listenSocket.ReceiveBufferSize = rconfig.SocketBufferSize;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Prompts a connected unauthenticated user to provide a root username
        /// and password, then very rudely disconnects him.
        /// </summary>
        /// <param name="s">The socket to use to do this.</param>
        public void CreateRootUser(Socket s)
        {
            string authmsg = "createroot";
            int offset = 0;
            SocketError errorCode;
            do {
                try {
                    offset += s.Send( IRCProtocol.Ascii.GetBytes( authmsg ),
                        offset, authmsg.Length - offset, SocketFlags.None, out errorCode );
                }
                catch ( SocketException ) {
                    s.Close();
                    return; //Give up. They can reconnect.
                }
            } while ( offset < authmsg.Length );

            if ( errorCode != SocketError.Success ) { s.Close(); return; }

            //Get Auth response. (firstauth - see config) (root username) (32 byte passwordhash)
            byte[] recvBuf = new byte[rconfig.SocketBufferSize];
            offset = s.Receive( recvBuf, 0, rconfig.SocketBufferSize, SocketFlags.None, out errorCode );
            if ( offset == 0 || errorCode != SocketError.Success ) { s.Close(); return; }

            string[] authReply = IRCProtocol.Ascii.GetString( recvBuf, 0, offset ).Split( ' ' );
            if ( authReply.Length != 3 ) { s.Close(); return; }

            if ( !authReply[0].Equals( rconfig.FirstAuth ) || authReply[2].Length != 32 ) { s.Close(); return; }

            RconUserFile.RconUser rc = new RconUserFile.RconUser( authReply[1], authReply[2], 11 );
            rconUsers = new RconUserFile( rconfig.UserFile, rc );

            authmsg = "success";
            offset = 0;
            do {
                try {
                    offset += s.Send( IRCProtocol.Ascii.GetBytes( authmsg ),
                        offset, authmsg.Length - offset, SocketFlags.None, out errorCode );
                }
                catch ( SocketException ) {
                    s.Close();
                    return; //Give up. They can reconnect.
                }
            } while ( offset < authmsg.Length );

            s.Close();
        }