Exemplo n.º 1
0
        internal bool InvokeNetSendBytes(RemoteClient socket, byte[] buffer, int offset, int count)
        {
            SendBytesEventArgs args = new SendBytesEventArgs
            {
                Socket = socket,
                Buffer = buffer,
                Offset = offset,
                Count  = count
            };

            this.NetSendBytes.Invoke(args);
            return(args.Handled);
        }
Exemplo n.º 2
0
		internal bool InvokeNetSendBytes(RemoteClient socket, byte[] buffer, int offset, int count)
		{
			SendBytesEventArgs args = new SendBytesEventArgs
			{
				Socket = socket,
				Buffer = buffer,
				Offset = offset,
				Count = count
			};

			this.NetSendBytes.Invoke(args);
			return args.Handled;
		}
Exemplo n.º 3
0
 /// <summary>
 /// NetSendBytes callback.
 /// </summary>
 /// <param name="args"></param>
 private void OnNetSendBytes(SendBytesEventArgs args)
 {
     lock (this.m_AddonsLock)
     {
         this.m_Addons.ForEach(a =>
             {
                 var data = args.Buffer.Skip(args.Offset).Take(args.Count).ToArray();
                 var msgId = data[2];
                 var ret = a.Value.InvokeEvent("NetSendBytes", args.Socket.whoAmI, (int)msgId, args.Count, data.GetRawString());
                 if (ret != null && ret.Length >= 1)
                 {
                     bool result;
                     if (bool.TryParse(ret[0].ToString(), out result) && result)
                         args.Handled = true;
                 }
             });
     }
 }
Exemplo n.º 4
0
        void OnSendBytes(SendBytesEventArgs e)
        {
            bool build = Build[e.Socket.WhoAmI];
            switch (e.Buffer[2])
            {
                case 7:
                    using (var writer = new BinaryWriter(new MemoryStream(e.Buffer, 3, e.Count - 3)))
                    {
                        writer.Write(build ? 27000 : (int)Main.time);
                        BitsByte bb = 0;
                        bb[0] = build ? true : Main.dayTime;
                        bb[1] = build ? false : Main.bloodMoon;
                        bb[2] = build ? false : Main.eclipse;
                        writer.Write(bb);

                        writer.BaseStream.Position += 9;
                        writer.Write(build ? (short)Main.maxTilesY : (short)Main.worldSurface);
                        writer.Write(build ? (short)Main.maxTilesY : (short)Main.rockLayer);

                        writer.BaseStream.Position += 4;
                        writer.Write(Main.worldName);

                        writer.BaseStream.Position += 49;
                        writer.Write(build ? 0f : Main.maxRaining);
                    }
                    break;
                case 18:
                    using (var writer = new BinaryWriter(new MemoryStream(e.Buffer, 3, e.Count - 3)))
                    {
                        writer.Write(build ? true : Main.dayTime);
                        writer.Write(build ? 27000 : (int)Main.time);
                    }
                    break;
                case 23:
                    NPC npc = Main.npc[BitConverter.ToInt16(e.Buffer, 3)];
                    if (!npc.friendly)
                    {
                        Buffer.BlockCopy(BitConverter.GetBytes(build ? 0f : npc.position.X), 0, e.Buffer, 5, 4);
                        Buffer.BlockCopy(BitConverter.GetBytes(build ? 0f : npc.position.Y), 0, e.Buffer, 9, 4);
                    }
                    break;
                case 27:
                    short id = BitConverter.ToInt16(e.Buffer, 3);
                    int owner = e.Buffer[27];
                    Projectile proj = Main.projectile[TShock.Utils.SearchProjectile(id, owner)];
                    if (!proj.friendly)
                        Buffer.BlockCopy(BitConverter.GetBytes((short)(build ? 0 : proj.type)), 0, e.Buffer, 28, 2);
                    break;
            }
        }
Exemplo n.º 5
0
 void OnSendBytes(SendBytesEventArgs args)
 {
     if ((args.Buffer[4] != 7 && args.Buffer[4] != 18) || args.Socket.whoAmI < 0 || args.Socket.whoAmI > 255 || esPlayers[args.Socket.whoAmI].ptTime < 0.0)
     {
         return;
     }
     switch (args.Buffer[4])
     {
         case 7:
             Buffer.BlockCopy(BitConverter.GetBytes((int)esPlayers[args.Socket.whoAmI].ptTime), 0, args.Buffer, 5, 4);
             args.Buffer[9] = (byte)(esPlayers[args.Socket.whoAmI].ptDay ? 1 : 0);
             break;
         case 18:
             args.Buffer[5] = (byte)(esPlayers[args.Socket.whoAmI].ptDay ? 1 : 0);
             Buffer.BlockCopy(BitConverter.GetBytes((int)esPlayers[args.Socket.whoAmI].ptTime), 0, args.Buffer, 6, 4);
             break;
     }
 }