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


C# NetBuffer.ReadUInt16方法代码示例

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


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

示例1: HandleMessage

        private static void HandleMessage(NetMessageType type, NetConnection source, NetBuffer buffer)
        {
            switch (type)
            {
                case NetMessageType.DebugMessage:
                    WriteToConsole(buffer.ReadString());
                    break;
                case NetMessageType.StatusChanged:
                    WriteToConsole("New status: " + source.Status + " (" + buffer.ReadString() + ")");
                    UpdateStatisticsDisplay(source);
                    break;
                case NetMessageType.Data:
                    //System.IO.File.AppendAllText("C:\\receivedpackets.txt", s_userMessagesReceived.ToString() + ": " + msg.ReadString() + " (" + msg.m_sequenceNumber + ")" + Environment.NewLine);
                    s_userMessagesReceived++;

                    // simulate some processing of the message here
                    for (int i = 0; i < buffer.LengthBytes - 2; i++)
                        buffer.ReadByte();

                    // check checksum
                    ushort checksum = NetChecksum.Adler16(buffer.Data, 0, buffer.LengthBytes - 2);
                    ushort given = buffer.ReadUInt16();
                    if (checksum != given)
                        WriteToConsole("Wrong checksum! Expected " + checksum + " found given " + given);

                    double b = s_userMessagesReceived;
                    for (int i = 0; i < 1000; i++)
                        b += Math.Sqrt((double)i) / Math.Sin(s_tmp);
                    s_tmp += b / 10000.0;
                    break;
                default:
                    break;
            }
        }
开发者ID:JeffM2501,项目名称:HackSharp,代码行数:34,代码来源:Program.cs

示例2: ReadFrom

		/// <summary>
		/// Read this message from the packet buffer
		/// </summary>
		/// <returns>new read pointer position</returns>
		internal void ReadFrom(NetBuffer buffer, IPEndPoint endpoint)
		{
			m_senderEndPoint = endpoint;

			// read header
			byte header = buffer.ReadByte();
			m_type = (NetMessageLibraryType)(header & 7);
			m_sequenceChannel = (NetChannel)(header >> 3);
			m_sequenceNumber = buffer.ReadUInt16();

			int payLen = (int)buffer.ReadVariableUInt32();

			// copy payload into message buffer
			m_data.EnsureBufferSize(payLen * 8);
			buffer.ReadBytes(m_data.Data, 0, payLen);
			m_data.Reset(0, payLen * 8);

			return;
		}
开发者ID:marvel54,项目名称:lidgren-network,代码行数:23,代码来源:NetMessage.cs

示例3: StateUpdateEventArgs

		public StateUpdateEventArgs(NetBuffer msg) : base(msg)
		{
			EntitiesUpdatedState = new List<StateUpdateData>();
			RemarkableEvents = new List<RemarkableEventData>();

			LastAcknowledgedActionID = msg.ReadUInt64();
			Time = msg.ReadDouble();
			Vec2 velocity = new Vec2(msg.ReadFloat(), msg.ReadFloat());
			byte nbClients = msg.ReadByte();
			for (byte i = 0; i < nbClients; ++i) {
				ulong id = msg.ReadUInt64();
				Vec2 pos = new Vec2(msg.ReadFloat(), msg.ReadFloat());
				ChampionAnimation anim = (ChampionAnimation)msg.ReadByte();
				bool facingLeft = msg.ReadBoolean();

				EntitiesUpdatedState.Add(new StateUpdateData(id, pos, velocity, anim, facingLeft));
			}
			while (msg.Position != msg.LengthBits) {
				ServerCommand cmd = (ServerCommand)msg.ReadByte();
				RemarkableEventData data = null;
				switch (cmd) {
					case ServerCommand.SpellCast:
						data = new SpellCastEventData(
							msg.ReadUInt64(),
							msg.ReadUInt64(),
							(SpellTypes)msg.ReadByte(),
							msg.ReadFloat(),
							new Vec2(msg.ReadFloat(), msg.ReadFloat()),
							new Vec2(msg.ReadFloat(), msg.ReadFloat()),
							TimeSpan.FromSeconds(msg.ReadFloat()),
							msg.ReadFloat(),
							msg.ReadFloat());
						break;

					case ServerCommand.SpellDisappear:
						data = new SpellDisappearEventData(msg.ReadUInt64());
						break;

					case ServerCommand.StatsChanged:
						data = new StatsChangedEventData(msg.ReadUInt64(), msg.ReadFloat());
						break;

					case ServerCommand.ChampionDied:
						data = new ChampionDiedEventData(msg.ReadUInt64(),
						                                 msg.ReadUInt64(),
						                                 msg.ReadUInt32(), msg.ReadUInt32(), msg.ReadUInt32(), msg.ReadUInt32(),
						                                 TimeSpan.FromSeconds(msg.ReadUInt16()));
						break;

					case ServerCommand.StructureStatsChanged:
						data = new StructureStatsChangedEventData(msg.ReadBoolean() ? Teams.Left : Teams.Right,
						                                          (StructureTypes)msg.ReadByte(),
						                                          msg.ReadFloat());
						break;

					case ServerCommand.StructureDestroyed:
						data = new StructureDestroyedEventData(msg.ReadBoolean() ? Teams.Left : Teams.Right,
						                                       (StructureTypes)msg.ReadByte());
						break;

					case ServerCommand.EndOfGame:
						data = new EndOfGameEventData(msg.ReadBoolean() ? Teams.Left : Teams.Right);
						break;

					case ServerCommand.TowerPreparingToShoot:
						data = new TowerPreparingToShootEventData(msg.ReadBoolean() ? Teams.Left : Teams.Right,
						                                          (StructureTypes)msg.ReadByte());
						break;

					default:
						Debug.Fail("Unknown server command when updating (unknown remarkable event)");
						break;
				}
				if (data != null) {
					RemarkableEvents.Add(data);
				}
			}
		}
开发者ID:DrPandemic,项目名称:EraParadox,代码行数:78,代码来源:Client.cs


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