예제 #1
0
 public CVarSetPacketOut(CVar var, Server tserver)
 {
     UsageType = NetUsageType.GENERAL;
     ID = ServerToClientPacket.CVAR_SET;
     DataStream ds = new DataStream();
     DataWriter dw = new DataWriter(ds);
     dw.WriteInt(tserver.Networking.Strings.IndexForString(var.Name.ToLowerFast()));
     dw.WriteFullString(var.Value);
     Data = ds.ToArray();
 }
 private void Setup(CharacterEntity character, HelicopterEntity vehicle)
 {
     DataStream ds = new DataStream();
     DataWriter dw = new DataWriter(ds);
     dw.WriteLong(character.EID);
     dw.WriteByte(1); // TODO: Enum?
     dw.WriteLong(vehicle.EID);
     dw.Flush();
     Data = ds.ToArray();
     dw.Close();
 }
 private void Setup(CharacterEntity character, CarEntity vehicle)
 {
     DataStream ds = new DataStream();
     DataWriter dw = new DataWriter(ds);
     dw.WriteLong(character.EID);
     dw.WriteByte(0); // TODO: Enum?
     dw.WriteInt(vehicle.DrivingMotors.Count);
     dw.WriteInt(vehicle.SteeringMotors.Count);
     for (int i = 0; i < vehicle.DrivingMotors.Count; i++)
     {
         dw.WriteLong(vehicle.DrivingMotors[i].JID);
     }
     for (int i = 0; i < vehicle.SteeringMotors.Count; i++)
     {
         dw.WriteLong(vehicle.SteeringMotors[i].JID);
     }
     dw.Flush();
     Data = ds.ToArray();
     dw.Close();
 }
예제 #4
0
 public AddCloudPacketOut(Cloud cloud)
 {
     UsageType = NetUsageType.CLOUDS;
     ID = ServerToClientPacket.ADD_CLOUD;
     DataStream ds = new DataStream();
     DataWriter dw = new DataWriter(ds);
     dw.WriteBytes(cloud.Position.ToDoubleBytes());
     dw.WriteBytes((cloud.Velocity + cloud.TheRegion.Wind).ToDoubleBytes());
     dw.WriteLong(cloud.CID);
     dw.WriteInt(cloud.Points.Count);
     for (int i = 0; i < cloud.Points.Count; i++)
     {
         dw.WriteBytes(cloud.Points[i].ToDoubleBytes());
         dw.WriteFloat((float)cloud.Sizes[i]);
         dw.WriteFloat((float)cloud.EndSizes[i]);
     }
     dw.Flush();
     Data = ds.ToArray();
     dw.Close();
 }
예제 #5
0
 public BlockEditPacketOut(Location[] pos, ushort[] mat, byte[] dat, byte[] paints)
 {
     UsageType = NetUsageType.CHUNKS;
     ID = ServerToClientPacket.BLOCK_EDIT;
     DataStream outp = new DataStream();
     DataWriter dw = new DataWriter(outp);
     dw.WriteInt(pos.Length);
     for (int i = 0; i < pos.Length; i++)
     {
         dw.WriteBytes(pos[i].ToDoubleBytes());
     }
     for (int i = 0; i < mat.Length; i++)
     {
         dw.WriteBytes(Utilities.UshortToBytes(mat[i]));
     }
     dw.WriteBytes(dat);
     dw.WriteBytes(paints);
     dw.Flush();
     Data = outp.ToArray();
 }
예제 #6
0
 public void WriteBasicBytes(DataWriter dw)
 {
     dw.WriteInt(Count);
     dw.WriteInt(Datum);
     dw.WriteFloat((float)Weight);
     dw.WriteFloat((float)Volume);
     dw.WriteFloat((float)Temperature);
     dw.WriteInt(DrawColor.ToArgb());
     dw.WriteFullString(Name);
     dw.WriteFullString(SecondaryName == null ? "" : SecondaryName);
     dw.WriteFullString(DisplayName);
     dw.WriteFullString(Description);
     dw.WriteFullString(GetTextureName());
     dw.WriteFullString(GetModelName());
     dw.WriteByte((byte)(RenderAsComponent ? 1 : 0));
     dw.WriteFloat((float)ComponentRenderOffset.X);
     dw.WriteFloat((float)ComponentRenderOffset.Y);
     dw.WriteFloat((float)ComponentRenderOffset.Z);
     dw.WriteInt(SharedAttributes.Count);
     foreach (KeyValuePair<string, TemplateObject> entry in SharedAttributes)
     {
         if (entry.Key == null || entry.Value == null)
         {
             SysConsole.Output(OutputType.WARNING, "Null entry in SharedAttributes for " + Name);
             continue;
         }
         dw.WriteFullString(entry.Key);
         if (entry.Value is IntegerTag)
         {
             dw.WriteByte(0);
             dw.WriteLong(((IntegerTag)entry.Value).Internal);
         }
         else if (entry.Value is NumberTag)
         {
             dw.WriteByte(1);
             dw.WriteDouble(((NumberTag)entry.Value).Internal);
         }
         else if (entry.Value is BooleanTag)
         {
             dw.WriteByte(2);
             dw.WriteByte((byte)(((BooleanTag)entry.Value).Internal ? 1 : 0));
         }
         // TODO: shared BaseItemTag?
         else
         {
             dw.WriteByte(3);
             dw.WriteFullString(entry.Value.ToString());
         }
     }
 }
예제 #7
0
 public byte[] ToBytes()
 {
     DataStream ds = new DataStream(1000);
     DataWriter dw = new DataWriter(ds);
     WriteBasicBytes(dw);
     dw.WriteInt(Components.Count);
     foreach (ItemStackBase itb in Components)
     {
         dw.WriteFullBytes(itb.ToBytes());
     }
     dw.Flush();
     return ds.ToArray();
 }
예제 #8
0
 public ChunkInfoPacketOut(Chunk chunk, int lod)
 {
     UsageType = NetUsageType.CHUNKS;
     if (chunk.Flags.HasFlag(ChunkFlags.POPULATING) && (lod != 5 || chunk.LOD == null))
     {
         throw new Exception("Trying to transmit chunk while it's still loading! For chunk at " + chunk.WorldPosition);
     }
     ID = ServerToClientPacket.CHUNK_INFO;
     byte[] data_orig;
     if (lod == 1)
     {
         bool isAir = true;
         data_orig = new byte[chunk.BlocksInternal.Length * 4];
         for (int x = 0; x < chunk.BlocksInternal.Length; x++)
         {
             ushort mat = chunk.BlocksInternal[x].BlockMaterial;
             if (mat != 0)
             {
                 isAir = false;
             }
             data_orig[x * 2] = (byte)(mat & 0xFF);
             data_orig[x * 2 + 1] = (byte)((mat >> 8) & 0xFF);
         }
         if (isAir)
         {
             data_orig = null;
         }
         else
         {
             for (int i = 0; i < chunk.BlocksInternal.Length; i++)
             {
                 data_orig[chunk.BlocksInternal.Length * 2 + i] = chunk.BlocksInternal[i].BlockData;
                 data_orig[chunk.BlocksInternal.Length * 3 + i] = chunk.BlocksInternal[i]._BlockPaintInternal;
             }
         }
     }
     else
     {
         data_orig = chunk.LODBytes(lod, true);
     }
     if (data_orig == null)
     {
         Data = new byte[12];
         // TODO: This is a bit hackish
         ID = ServerToClientPacket.CHUNK_FORGET;
         Utilities.IntToBytes((int)chunk.WorldPosition.X).CopyTo(Data, 0);
         Utilities.IntToBytes((int)chunk.WorldPosition.Y).CopyTo(Data, 4);
         Utilities.IntToBytes((int)chunk.WorldPosition.Z).CopyTo(Data, 8);
         return;
     }
     byte[] gdata = FileHandler.Compress(data_orig);
     DataStream ds = new DataStream(gdata.Length + 16);
     DataWriter dw = new DataWriter(ds);
     dw.WriteInt((int)chunk.WorldPosition.X);
     dw.WriteInt((int)chunk.WorldPosition.Y);
     dw.WriteInt((int)chunk.WorldPosition.Z);
     dw.WriteInt(lod);
     byte[] reach = new byte[chunk.Reachability.Length];
     for (int i = 0; i < reach.Length; i++)
     {
         reach[i] = (byte)(chunk.Reachability[i] ? 1 : 0);
     }
     dw.WriteBytes(reach);
     dw.WriteBytes(gdata);
     Data = ds.ToArray();
 }
예제 #9
0
 public byte[] ServerBytes()
 {
     DataStream data = new DataStream(1000);
     DataWriter dw = new DataWriter(data);
     dw.WriteInt(Attributes.Count);
     foreach (KeyValuePair<string, TemplateObject> entry in Attributes)
     {
         dw.WriteFullString(entry.Key);
         if (entry.Value is IntegerTag)
         {
             dw.WriteByte(0);
             dw.WriteLong(((IntegerTag)entry.Value).Internal);
         }
         else if (entry.Value is NumberTag)
         {
             dw.WriteByte(1);
             dw.WriteDouble(((NumberTag)entry.Value).Internal);
         }
         else if (entry.Value is BooleanTag)
         {
             dw.WriteByte(2);
             dw.WriteByte((byte)(((BooleanTag)entry.Value).Internal ? 1 : 0));
         }
         // TODO: shared BaseItemTag?
         else
         {
             dw.WriteByte(3);
             dw.WriteFullString(entry.Value.ToString());
         }
     }
     WriteBasicBytes(dw);
     dw.WriteInt(Components.Count);
     foreach (ItemStack itb in Components)
     {
         dw.WriteFullBytes(itb.ServerBytes());
     }
     dw.Flush();
     return data.ToArray();
 }
예제 #10
0
 public byte[] GetCharacterNetData()
 {
     DataStream ds = new DataStream();
     DataWriter dr = new DataWriter(ds);
     dr.WriteBytes(GetPosition().ToDoubleBytes());
     Quaternion quat = GetOrientation();
     dr.WriteFloat((float)quat.X);
     dr.WriteFloat((float)quat.Y);
     dr.WriteFloat((float)quat.Z);
     dr.WriteFloat((float)quat.W);
     dr.WriteFloat((float)GetMass());
     dr.WriteFloat((float)CBAirForce);
     dr.WriteFloat((float)CBAirSpeed);
     dr.WriteFloat((float)CBCrouchSpeed);
     dr.WriteFloat((float)CBDownStepHeight);
     dr.WriteFloat((float)CBGlueForce);
     dr.WriteFloat((float)CBHHeight);
     dr.WriteFloat((float)CBJumpSpeed);
     dr.WriteFloat((float)CBMargin);
     dr.WriteFloat((float)CBMaxSupportSlope);
     dr.WriteFloat((float)CBMaxTractionSlope);
     dr.WriteFloat((float)CBProneSpeed);
     dr.WriteFloat((float)CBRadius);
     dr.WriteFloat((float)CBSlideForce);
     dr.WriteFloat((float)CBSlideJumpSpeed);
     dr.WriteFloat((float)CBSlideSpeed);
     dr.WriteFloat((float)CBStandSpeed);
     dr.WriteFloat((float)CBStepHeight);
     dr.WriteFloat((float)CBTractionForce);
     dr.WriteFloat((float)mod_xrot);
     dr.WriteFloat((float)mod_yrot);
     dr.WriteFloat((float)mod_zrot);
     dr.WriteFloat((float)mod_scale);
     dr.WriteInt(mod_color.ToArgb());
     byte dtx = 0;
     if (Visible)
     {
         dtx |= 1;
     }
     if (CGroup == CollisionUtil.Solid)
     {
         dtx |= 2;
     }
     else if (CGroup == CollisionUtil.NonSolid)
     {
         dtx |= 4;
     }
     else if (CGroup == CollisionUtil.Item)
     {
         dtx |= 2 | 4;
     }
     else if (CGroup == CollisionUtil.Player)
     {
         dtx |= 8;
     }
     else if (CGroup == CollisionUtil.Water)
     {
         dtx |= 2 | 8;
     }
     else if (CGroup == CollisionUtil.WorldSolid)
     {
         dtx |= 2 | 4 | 8;
     }
     else if (CGroup == CollisionUtil.Character)
     {
         dtx |= 16;
     }
     dr.Write(dtx);
     dr.WriteInt(TheServer.Networking.Strings.IndexForString(model));
     dr.Flush();
     byte[] Data = ds.ToArray();
     dr.Close();
     return Data;
 }