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


C# GSPacketIn.ToArray方法代码示例

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


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

示例1: HandlePacket

		public void HandlePacket(GSPacketIn packet)
		{
			if (packet == null || m_client == null)
				return;

			int code = packet.ID;

			Statistics.BytesIn += packet.PacketSize;
			Statistics.PacketsIn++;

			SavePacket(packet);

			IPacketHandler packetHandler = null;
			if (code < m_packetHandlers.Length)
			{
				packetHandler = m_packetHandlers[code];
			}



			else if (log.IsErrorEnabled)
			{
				log.ErrorFormat("Received packet code is outside of m_packetHandlers array bounds! " + m_client);
				log.Error(Marshal.ToHexDump(
				          	String.Format("===> <{2}> Packet 0x{0:X2} (0x{1:X2}) length: {3} (ThreadId={4})", code, code ^ 168,
				          	              (m_client.Account != null) ? m_client.Account.Name : m_client.TcpEndpoint,
				          	              packet.PacketSize, Thread.CurrentThread.ManagedThreadId),
				          	packet.ToArray()));
			}

			// make sure we can handle this packet at this stage
			var preprocess = PacketPreprocessing.CanProcessPacket(m_client, packet);
			if(!preprocess)
			{
				// this packet can't be processed by this client right now, for whatever reason
				return;
			}

			if (packetHandler != null)
			{
				Timer monitorTimer = null;
				if (log.IsDebugEnabled)
				{
					try
					{
						monitorTimer = new Timer(10000);
						m_activePacketHandler = packetHandler;
						m_handlerThreadID = Thread.CurrentThread.ManagedThreadId;
						monitorTimer.Elapsed += HandlePacketTimeout;
						monitorTimer.Start();
					}
					catch (Exception e)
					{
						if (log.IsErrorEnabled)
							log.Error("Starting packet monitor timer", e);

						if (monitorTimer != null)
						{
							monitorTimer.Stop();
							monitorTimer.Close();
							monitorTimer = null;
						}
					}
				}

#if LOGACTIVESTACKS
				//Put the current thread into the active thread list!
				//No need to lock the hashtable since we created it
				//synchronized! One reader, multiple writers supported!
				m_activePacketThreads.Add(Thread.CurrentThread, m_client);
#endif
				long start = Environment.TickCount;
				try
				{
					packetHandler.HandlePacket(m_client, packet);

                }
				catch (Exception e)
				{
					if (log.IsErrorEnabled)
					{
						string client = (m_client == null ? "null" : m_client.ToString());
						log.Error(
							"Error while processing packet (handler=" + packetHandler.GetType().FullName + "  client: " + client + ")", e);
					}
				}
#if LOGACTIVESTACKS
				finally
				{
					//Remove the thread from the active list after execution
					//No need to lock the hashtable since we created it
					//synchronized! One reader, multiple writers supported!
					m_activePacketThreads.Remove(Thread.CurrentThread);
				}
#endif
				long timeUsed = Environment.TickCount - start;
				if (monitorTimer != null)
				{
					monitorTimer.Stop();
					monitorTimer.Close();
//.........这里部分代码省略.........
开发者ID:mynew4,项目名称:DAoC,代码行数:101,代码来源:PacketProcessor.cs

示例2: HandlePacket


//.........这里部分代码省略.........
                    int fallSpeed = (flyingflag & 0xFFF) - 100 * safeFallLevel; // 0x7FF fall speed and 0x800 bit = fall speed overcaped
                    int fallMinSpeed = 400;
                    int fallDivide = 6;
                    if (client.Version >= GameClient.eClientVersion.Version188)
                    {
                        fallMinSpeed = 500;
                        fallDivide = 15;
                    }

                    int fallPercent = Math.Min(99, (fallSpeed - (fallMinSpeed + 1)) / fallDivide);

                    if (fallSpeed > fallMinSpeed)
                    {
                        client.Out.SendMessage(LanguageMgr.GetTranslation(client, "PlayerPositionUpdateHandler.FallingDamage"),
                        eChatType.CT_Damaged, eChatLoc.CL_SystemWindow);
                        client.Player.CalcFallDamage(fallPercent);
                    }

                    client.Player.MaxLastZ = client.Player.Z;
                }

                else
                {
                    // always set Z if on the ground
                    if (flyingflag == 0)
                        client.Player.MaxLastZ = client.Player.Z;
                    // set Z if in air and higher than old Z
                    else if (maxLastZ < client.Player.Z)
                        client.Player.MaxLastZ = client.Player.Z;
                }
            }
            //**************//

            byte[] con168 = packet.ToArray();
            //Riding is set here!
            if (client.Player.Steed != null && client.Player.Steed.ObjectState == GameObject.eObjectState.Active)
            {
                client.Player.Heading = client.Player.Steed.Heading;

                con168[2] = 0x18; // Set ride flag 00011000
                con168[3] = 0; // player speed = 0 while ride
                con168[12] = (byte)(client.Player.Steed.ObjectID >> 8); //heading = steed ID
                con168[13] = (byte)(client.Player.Steed.ObjectID & 0xFF);
                con168[14] = (byte)0;
                con168[15] = (byte)(client.Player.Steed.RiderSlot(client.Player)); // there rider slot this player
            }
            else if (!client.Player.IsAlive)
            {
                con168[2] &= 0xE3; //11100011
                con168[2] |= 0x14; //Set dead flag 00010100
            }
            //diving is set here
            con168[16] &= 0xFB; //11 11 10 11
            if ((con168[16] & 0x02) != 0x00)
            {
                client.Player.IsDiving = true;
                con168[16] |= 0x04;
            }
            else
                client.Player.IsDiving = false;

            con168[16] &= 0xFC; //11 11 11 00 cleared Wireframe & Stealth bits
            if (client.Player.IsWireframe)
            {
                con168[16] |= 0x01;
            }
开发者ID:uvbs,项目名称:Dawn-of-Light-core,代码行数:67,代码来源:PlayerPositionUpdateHandler.cs

示例3: HandlePacket

        public void HandlePacket(GameClient client, GSPacketIn packet)
        {
            if (client == null || client.Player == null)
                return;

            if (client.Player.ObjectState != GameObject.eObjectState.Active) return;

            ushort sessionId = packet.ReadShort(); // session ID
            if (client.SessionID != sessionId)
            {
                //				GameServer.BanAccount(client, 120, "Hack sessionId", string.Format("Wrong sessionId:0x{0} in 0xBA packet (SessionID:{1})", sessionId, client.SessionID));
                return; // client hack
            }

            ushort head = packet.ReadShort();
            client.Player.Heading = (ushort)(head & 0xFFF);
            packet.Skip(1); // unknown
            int flags = packet.ReadByte();
            //			client.Player.PetInView = ((flags & 0x04) != 0); // TODO
            client.Player.GroundTargetInView = ((flags & 0x08) != 0);
            client.Player.TargetInView = ((flags & 0x10) != 0);

            byte[] con = packet.ToArray();
            if (!client.Player.IsAlive)
            {
                con[9] = 5; // set dead state
            }
            else if (client.Player.Steed != null && client.Player.Steed.ObjectState == GameObject.eObjectState.Active)
            {
                client.Player.Heading = client.Player.Steed.Heading;
                con[9] = 6; // Set ride state
                con[7] = (byte)(client.Player.Steed.RiderSlot(client.Player)); // there rider slot this player
                con[2] = (byte)(client.Player.Steed.ObjectID >> 8); //heading = steed ID
                con[3] = (byte)(client.Player.Steed.ObjectID & 0xFF);
            }
            con[5] &= 0xC0; //11 00 00 00 = 0x80(Torch) + 0x40(Unknown), all other in view check's not need send anyone
            if (client.Player.IsWireframe)
            {
                con[5] |= 0x01;
            }
            //stealth is set here
            if (client.Player.IsStealthed)
            {
                con[5] |= 0x02;
            }
            con[8] = (byte)((con[8] & 0x80) | client.Player.HealthPercent);

            GSUDPPacketOut outpak = new GSUDPPacketOut(client.Out.GetPacketCode(eServerPackets.PlayerHeading));
            //Now copy the whole content of the packet
            outpak.Write(con, 0, /*con.Length*/10);
            outpak.WritePacketLength();

            GSUDPPacketOut outpak190 = null;

            //			byte[] outp = outpak.GetBuffer();
            //			outpak = null;

            foreach (GamePlayer player in client.Player.GetPlayersInRadius(WorldMgr.VISIBILITY_DISTANCE))
            {
                if (player != null && player != client.Player)
                {
                    if (player.Client.Version >= GameClient.eClientVersion.Version190)
                    {
                        if (outpak190 == null)
                        {
                            outpak190 = new GSUDPPacketOut(client.Out.GetPacketCode(eServerPackets.PlayerHeading));
                            byte[] con190 = (byte[])con.Clone();
                            //Now copy the whole content of the packet
                            outpak190.Write(con190, 0, /*con190.Lenght*/10);
                            outpak190.WriteByte(client.Player.ManaPercent);
                            outpak190.WriteByte(client.Player.EndurancePercent);
                            outpak190.WritePacketLength();
                            //							byte[] outp190 = outpak190.GetBuffer();
                            //							outpak190 = null;// ?
                        }
                        player.Out.SendUDPRaw(outpak190);
                    }
                    else
                        player.Out.SendUDPRaw(outpak);
                }
            }
        }
开发者ID:uvbs,项目名称:Dawn-of-Light-core,代码行数:82,代码来源:PlayerHeadingUpdateHandler.cs


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