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


C# NetIncomingMessage.ReadAllFields方法代码示例

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


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

示例1: HandleSeverMessage

        void HandleSeverMessage(NetIncomingMessage msg)
        {
            MessageFunction type = (MessageFunction)msg.ReadInt32();
            switch (type)
            {
                case MessageFunction.ClassMessage:
                    SendTo sendTo = (SendTo)msg.ReadInt32();
                    string assemblyName = msg.ReadString();
                    string classType = msg.ReadString();
                    Message report = (Message)Activator.CreateInstance(assemblyName, classType).Unwrap();
                    msg.ReadAllFields(report);
                    SendNetworkMessage(report, sendTo, msg);
                    break;
                case MessageFunction.SpawnPlayer:
                    // broadcast this to all connections, except sender
                    List<NetConnection> all2 = m_server.Connections; // get copy
                    all2.Remove(msg.SenderConnection);

                    int id2 = msg.ReadInt32();
                    string playerName = msg.ReadString();
                    if (all2.Count > 0)
                    {
                        NetOutgoingMessage om = m_server.CreateMessage();
                        om.Write((int)MessageFunction.SpawnPlayer);
                        om.Write(id2);
                        om.Write(playerName);

                        m_server.SendMessage(om, all2, NetDeliveryMethod.ReliableUnordered, 0);
                    }
                    SpawnPlayer(id2, playerName, msg.SenderConnection);
                    break;
                default:
                    Debug.LogWarning("Unhandled msg type: " + type.ToString());
                    break;
            }
        }
开发者ID:Fr0sZ,项目名称:Skylines-Multiplayer,代码行数:36,代码来源:MultiplayerManager.cs

示例2: HandleClientMessage

        void HandleClientMessage(NetIncomingMessage msg)
        {
            MessageFunction type = (MessageFunction)msg.ReadInt32();
            switch (type)
            {
                case MessageFunction.ClassMessage:
                    string assemblyName = msg.ReadString();
                    string classType = msg.ReadString();
                    Message report = (Message)Activator.CreateInstance(assemblyName, classType).Unwrap();
                    msg.ReadAllFields(report);
                    report.OnCalled(report, msg);
                    break;
                case MessageFunction.SpawnAllPlayer:
                    int count = msg.ReadInt32();
                    for (int i = 0; i < count; i++)
                    {
                        int id = msg.ReadInt32();
                        string playerName = msg.ReadString();

                        SpawnPlayer(id, playerName);
                    }

                    int newId = SpawnLocalPlayer();
                    MessageSpawnPlayer spawnMessage = new MessageSpawnPlayer();
                    spawnMessage.playerId = newId;
                    spawnMessage.playerName = Steam.personaName;
                    SendNetworkMessage(spawnMessage, SendTo.Others);
                    break;
                case MessageFunction.UpdateVehiclesPositions:
                    m_vNetworkManager.UpdateCarsPositions(msg);
                    break;
                case MessageFunction.RemoveVehicle:
                    int carID2 = msg.ReadInt32();
                    m_vNetworkManager.RemoveCar(carID2);
                    break;
                case MessageFunction.UpdateCitizensPositions:
                    m_cNetworkManager.UpdateCitizensPositions(msg);
                    break;
                default:
                    Debug.LogWarning("Unhandled msg type: " + type.ToString());
                    break;
            }
        }
开发者ID:Fr0sZ,项目名称:Skylines-Multiplayer,代码行数:43,代码来源:MultiplayerManager.cs


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