public LoginCommandHandler()
        {
            Parser = new CommandParser();

            Parser.AddCommand(
                new Sequence(new KeyWord("LOGIN", false), new SingleWord("NAME")),
                new CommandProcessorWrapper((m, a) =>
            {
                a.Short = m.Arguments["NAME"].ToString();
                a.ConnectedClient.CommandHandler = Mud.ParserCommandHandler;
                a.Rank = 500;                         //Everyone is a wizard!
                Thing.Move(a, Mud.GetObject("dummy"));
                Mud.EnqueuClientCommand(a.ConnectedClient, "look");
            }),
                "Login to an existing account.");
        }
Esempio n. 2
0
        void OnData(IAsyncResult _asyncResult)
        {
            var Client = _asyncResult.AsyncState as TelnetClient;

            try
            {
                System.Net.Sockets.SocketError Error;
                int DataSize = Client.Socket.EndReceive(_asyncResult, out Error);

                if (DataSize == 0 || Error != System.Net.Sockets.SocketError.Success)
                {
                    Mud.ClientDisconnected(Client);
                }
                else
                {
                    for (int i = 0; i < DataSize; ++i)
                    {
                        if (Client.Storage[i] == '\n' || Client.Storage[i] == '\r')
                        {
                            if (!String.IsNullOrEmpty(Client.CommandQueue))
                            {
                                String Command = Client.CommandQueue;
                                Client.CommandQueue = "";
                                Mud.EnqueuClientCommand(Client, Command);
                            }
                        }
                        else if (Client.Storage[i] == '\b')
                        {
                            if (Client.CommandQueue.Length > 0)
                            {
                                Client.CommandQueue = Client.CommandQueue.Remove(Client.CommandQueue.Length - 1);
                            }
                        }
                        else if (ValidCharacters.Contains((char)Client.Storage[i]))
                        {
                            Client.CommandQueue += (char)Client.Storage[i];
                        }
                    }

                    Client.Socket.BeginReceive(Client.Storage, 0, 1024, System.Net.Sockets.SocketFlags.Partial, OnData, Client);
                }
            }
            catch (Exception e)
            {
                Mud.ClientDisconnected(Client);
            }
        }