当前位置: 首页>>代码示例>>C#>>正文


C# Session.Write方法代码示例

本文整理汇总了C#中Session.Write方法的典型用法代码示例。如果您正苦于以下问题:C# Session.Write方法的具体用法?C# Session.Write怎么用?C# Session.Write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Session的用法示例。


在下文中一共展示了Session.Write方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TestInitialConnectionPromptsAfterEachWrite

        public void TestInitialConnectionPromptsAfterEachWrite()
        {
            string endl = Environment.NewLine;
            var connection = new FakeConnection();
            var session = new Session(connection);

            // Send a prompt through the connection. (This should be asking which character to login, or to create a new one.)
            var prompt = session.State.BuildPrompt();
            Verify.IsTrue(prompt.Length > 0);
            Verify.AreEqual(1, connection.FakeMessagesSent.Count);

            connection.Reset();

            session.Write("test 1", true);
            Verify.AreEqual(1, connection.FakeMessagesSent.Count);
            Verify.AreEqual("test 1" + endl + prompt, connection.FakeMessagesSent[0]);

            connection.Reset();

            session.Write("test 2", false);
            Verify.AreEqual(1, connection.FakeMessagesSent.Count);
            Verify.AreEqual(endl + "test 2", connection.FakeMessagesSent[0]);

            connection.Reset();

            session.Write("test 3a");
            session.Write("test 3b");
            Verify.AreEqual(2, connection.FakeMessagesSent.Count);
            Verify.AreEqual("test 3a" + endl + prompt, connection.FakeMessagesSent[0]);
            Verify.AreEqual(endl + "test 3b" + endl + prompt, connection.FakeMessagesSent[1]);
        }
开发者ID:Hobbitron,项目名称:WheelMUD,代码行数:31,代码来源:TestSession.cs

示例2: PlayingState

        /// <summary>
        /// Initializes a new instance of the PlayingState class.
        /// </summary>
        /// <param name="session">The session entering this state.</param>
        public PlayingState(Session session)
            : base(session)
        {
            // JFED -- Temporary workaround - null exceptions
            if(session.Thing != null)
            {
                var behavior = session.Thing.Behaviors.FindFirst<PlayerBehavior>();
                this.playerBehavior = new WeakReference<PlayerBehavior>(behavior);
            }

            string nl = Environment.NewLine;
            session.Write(string.Format("{0}Welcome, {1}.{0}{0}", nl, this.Session.UserName), false);
        }
开发者ID:Hobbitron,项目名称:WheelMUD,代码行数:17,代码来源:PlayingState.cs

示例3: SendErrorMessage

        /// <summary>
        /// Sends the error message to the player.
        /// </summary>
        /// <param name="session">The session.</param>
        /// <param name="message">The message.</param>
        public static void SendErrorMessage(Session session, string message)
        {
            var divider = new StringBuilder();
            var wrappedMessage = new StringBuilder();

            foreach (char t in message)
            {
                divider.Append("=");
            }

            wrappedMessage.Append("<%red%>" + divider + Environment.NewLine);
            wrappedMessage.Append(message + Environment.NewLine);
            wrappedMessage.Append(divider + "<%n%>");

            session.Write(wrappedMessage.ToString());
        }
开发者ID:Hobbitron,项目名称:WheelMUD,代码行数:21,代码来源:WRMChargenCommon.cs

示例4: Messenger

 public Messenger(Session session)
 {
     this.session = session;
     session.Write("Slim -- V0.5\n");
 }
开发者ID:jediwhale,项目名称:fitsharp,代码行数:5,代码来源:Messenger.cs

示例5: LoginState

 /// <summary>
 /// Initializes a new instance of the LoginState class.
 /// </summary>
 /// <param name="session">The session entering this state.</param>
 public LoginState(Session session)
     : base(session)
 {
     session.Write("Please enter your password:");
 }
开发者ID:Hobbitron,项目名称:WheelMUD,代码行数:9,代码来源:LoginState.cs

示例6: OnSessionAuthenticated

        /// <summary>Called upon authentication of a session.</summary>
        /// <param name="session">The authenticated session.</param>
        public void OnSessionAuthenticated(Session session)
        {
            // If there was already a connected player for this new, authentic user session,
            // kick the old one (as it may have been a prior disconnect or whatnot).
            PlayerBehavior previousPlayer = this.FindLoggedInPlayer(session.UserName);
            if (previousPlayer != null)
            {
                var msg = "Duplicate player match, kicking session id " + previousPlayer.SessionId;
                this.SystemHost.UpdateSystemHost(this, msg);

                var existingUserControlledBehavior = previousPlayer.Parent.Behaviors.FindFirst<UserControlledBehavior>();
                if (existingUserControlledBehavior != null)
                {
                    existingUserControlledBehavior.Controller.Write("Another connection has logged in as you; closing this connection.");
                }

                // @@@ TEST: Ensure this closes the connection correctly, etc; used to be rigged
                //     dangerously directly through the ServerManager.
                previousPlayer.LogOut();
                this.RemovePlayer(previousPlayer.Parent);
            }

            bool wasPlayerMissingDocument = false;

            // If this session doesn't have a player thing attached yet, load it up.  Note that
            // for situations like character creation, we might already have our Thing, so we
            // don't want to load a duplicate version of the just-created player Thing.
            if (session.Thing == null)
            {
                var playerBehavior = new PlayerBehavior();
                playerBehavior.Load(session.UserName);

                var player = new Thing(null)
                {
                    Name = playerBehavior.PlayerData.DisplayName
                };

                // Make sure that the playerBehavior has a parent set.
                playerBehavior.Parent = player;

                // Load game data from disk (RavenDb/NoSQL)
                PlayerDocument pd = this.LoadPlayerDocument(playerBehavior.PlayerData.ID);
                if (pd == null)
                {
                    // If we are here, this means that the player that we are trying to
                    // load does not have a corresponding player document in the NoSQL
                    // (RavenDb) store. Let's go and create a player document with default
                    // values.
                    player = PrepareBaseCharacter(session);
                    player.Name = playerBehavior.PlayerData.DisplayName;
                    playerBehavior.Parent = player;
                    playerBehavior.CreateMissingPlayerDocument();

                    var sb = new StringBuilder();

                    sb.AppendLine("This character is missing gaming data.");
                    sb.AppendFormat("The MUD engine is creating a default game settings for {0}.", playerBehavior.PlayerData.DisplayName);
                    sb.Append(Environment.NewLine);
                    sb.AppendLine("The system will now log you out. Please login again, to continue playing.");

                    session.Write(sb.ToString());

                    playerBehavior.LogOut();
                }

                // Get SensesBehavior and UserControlledBehavior from the PlayerDocument.
                var sensesBehavior = pd.Behaviors.OfType<SensesBehavior>().FirstOrDefault();
                var userControlledBehavior = pd.Behaviors.OfType<UserControlledBehavior>().FirstOrDefault();

                // Setup the controlled behavior controller.
                userControlledBehavior.Controller = session;

                // Initialize the player behavior event processor.
                playerBehavior.InitEventProcessor(sensesBehavior, userControlledBehavior);

                // Get the player behavior with the game data
                var persistedPlayerBehavior = pd.Behaviors.OfType<PlayerBehavior>().FirstOrDefault();

                // Get data from the persisted player behavior and merge it into the manually created one
                playerBehavior.Gender = persistedPlayerBehavior.Gender;
                playerBehavior.Race = persistedPlayerBehavior.Race;
                playerBehavior.SessionId = session.ID;
                playerBehavior.Name = session.UserName;
                playerBehavior.Prompt = pd.PlayerPrompt;
                playerBehavior.RoleData = persistedPlayerBehavior.RoleData;
                playerBehavior.ID = persistedPlayerBehavior.ID;

                // We don't need the persisted player behavior anymore, so remove it
                pd.Behaviors.Remove(persistedPlayerBehavior);

                if (!wasPlayerMissingDocument)
                {
                    // Put all the persisted game data onto the right objects.
                    this.TranslateFromPlayerDocument(ref player, pd);

                    // Make sure to add the player behavior to the player Thing object.
                    playerBehavior.Parent = player;
                    player.Behaviors.Add(playerBehavior);
//.........这里部分代码省略.........
开发者ID:Hobbitron,项目名称:WheelMUD,代码行数:101,代码来源:PlayerManager.cs


注:本文中的Session.Write方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。