本文整理汇总了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;
}
}
//.........这里部分代码省略.........