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


C# NetworkMessage.ToString方法代码示例

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


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

示例1: HandleMessage

        public void HandleMessage(NetworkMessage message)
        {
            lock (this.statusLock)
            {
                if (Server.EnableLogging)
                {
                    string log = "Received";
                    if (this.user != null && this.user.Name != null)
                    {
                        log += " from " + this.user.Name;
                    }
                    log += ": ";
                    log += message.ToString();
                    Console.WriteLine(log);
                }

                if (message.MessageCategory == SystemMessages.SystemPrefix)
                {
                    switch (message.MessageType)
                    {
                        case SystemMessages.Connect:
                            {
                                ConnectInfo connectInfo = NetworkSerializer.Deserialize<ConnectInfo>(message.MessageContent);
                                if (Server.EnableLogging)
                                {
                                    Console.WriteLine(connectInfo.Username);
                                }
                                this.user = this.server.AddUser(connectInfo.Username, this);
                                AuthenticationInfo auth = new AuthenticationInfo();
                                auth.Username = user.Name;
                                auth.Authentication = user.Authentication;
                                NetworkMessage authMessage = new NetworkMessage();
                                authMessage.MessageCategory = SystemMessages.SystemPrefix;
                                authMessage.MessageType = SystemMessages.Authenticate;
                                authMessage.MessageContent = NetworkSerializer.Serialize(auth);
                                this.serverSocket.SendMessage(authMessage);

                                this.Status = ConnectionStatus.Ready;
                            }
                            break;
                        case SystemMessages.SendChat:
                            {
                                SendChatInfo chatInfo = NetworkSerializer.Deserialize<SendChatInfo>(message.MessageContent);
                                this.server.AddChat(this.user, chatInfo.Chat);
                                if (Server.EnableLogging)
                                {
                                    Console.WriteLine("Receiving chat");
                                }
                            }
                            break;
                        case SystemMessages.EnterLobby:
                            {
                                EnterLobbyInfo enterLobbyInfo = NetworkSerializer.Deserialize<EnterLobbyInfo>(message.MessageContent);
                                Lobby lobby = null;
                                if (this.server.Lobbies.TryGetValue(enterLobbyInfo.Lobby, out lobby))
                                {
                                    this.server.AddUserToLobby(this.user, lobby);
                                }

                            }
                            break;
                        case SystemMessages.Disconnect:
                            {
                                this.server.RemoveUserFromLobby(this.user, this.user.Lobby);
                                this.server.RemoveUser(this.user);
                                this.Status = ConnectionStatus.Exiting;
                                if (Server.EnableLogging)
                                {
                                    Console.WriteLine("Exiting");
                                }
                            }
                            break;
                        case SystemMessages.RequestGame:
                            {
                                GameSpecificationInfo gameSpecificationInfo = NetworkSerializer.Deserialize<GameSpecificationInfo>(message.MessageContent);
                                this.server.ProposeGameWithUsers(this, gameSpecificationInfo.Players, gameSpecificationInfo, this.user.Lobby);
                                if (Server.EnableLogging)
                                {
                                    Console.WriteLine("Proposing game with " + message.MessageContent);
                                }
                            }
                            break;
                        case SystemMessages.AcceptGame:
                            {
                                if (this.RespondedToGame != null)
                                {
                                    this.RespondedToGame(new RespondToGameEventArgs(this, true));
                                }
                            }
                            break;
                        case SystemMessages.DeclineGame:
                            {
                                if (this.RespondedToGame != null)
                                {
                                    this.RespondedToGame(new RespondToGameEventArgs(this, false));
                                }
                            }
                            break;
                    }
                }
//.........这里部分代码省略.........
开发者ID:alanjg,项目名称:MajorDomo,代码行数:101,代码来源:Connection.cs


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