Esempio n. 1
0
 public ItemStack(byte[] data, Server tserver)
 {
     TheServer = tserver;
     DataStream ds = new DataStream(data);
     DataReader dr = new DataReader(ds);
     int attribs = dr.ReadInt();
     for (int i = 0; i < attribs; i++)
     {
         string cattrib = dr.ReadFullString();
         byte b = dr.ReadByte();
         if (b == 0)
         {
             Attributes.Add(cattrib, new IntegerTag(dr.ReadInt64()));
         }
         else if (b == 1)
         {
             Attributes.Add(cattrib, new NumberTag(dr.ReadDouble()));
         }
         else if (b == 2)
         {
             Attributes.Add(cattrib, new BooleanTag(dr.ReadByte() == 1));
         }
         else
         {
             Attributes.Add(cattrib, new TextTag(dr.ReadFullString()));
         }
     }
     Load(dr, (b) => new ItemStack(b, tserver));
 }
Esempio n. 2
0
 public override bool ParseBytesAndExecute(byte[] data)
 {
     if (data.Length < 4)
     {
         return false;
     }
     DataStream datums = new DataStream(data);
     DataReader dr = new DataReader(datums);
     int len = dr.ReadInt();
     List<Location> locs = new List<Location>();
     List<ushort> mats = new List<ushort>();
     for (int i = 0; i < len; i++)
     {
         locs.Add(Location.FromDoubleBytes(dr.ReadBytes(24), 0));
     }
     for (int i = 0; i < len; i++)
     {
         mats.Add(Utilities.BytesToUshort(dr.ReadBytes(2)));
     }
     byte[] dats = dr.ReadBytes(len);
     byte[] paints = dr.ReadBytes(len);
     for (int i = 0; i < len; i++)
     {
         TheClient.TheRegion.SetBlockMaterial(locs[i], mats[i], dats[i], paints[i], true); // TODO: Regen in PBAE not SBM.
     }
     return true;
 }
Esempio n. 3
0
 public override bool ParseBytesAndExecute(byte[] data)
 {
     DataStream ds = new DataStream(data);
     DataReader dr = new DataReader(ds);
     Location pos = Location.FromDoubleBytes(dr.ReadBytes(24), 0);
     Location vel = Location.FromDoubleBytes(dr.ReadBytes(24), 0);
     long cid = dr.ReadLong();
     for (int i = 0; i < TheClient.TheRegion.Clouds.Count; i++)
     {
         if (TheClient.TheRegion.Clouds[i].CID == cid)
         {
             TheClient.TheRegion.Clouds.RemoveAt(i);
             break;
         }
     }
     Cloud cloud = new Cloud(TheClient.TheRegion, pos);
     cloud.Velocity = vel;
     cloud.CID = cid;
     int count = dr.ReadInt();
     for (int i = 0; i < count; i++)
     {
         cloud.Points.Add(Location.FromDoubleBytes(dr.ReadBytes(24), 0));
         cloud.Sizes.Add(dr.ReadFloat());
         cloud.EndSizes.Add(dr.ReadFloat());
     }
     TheClient.TheRegion.Clouds.Add(cloud);
     dr.Close();
     return true;
 }
Esempio n. 4
0
 public ItemStack(Client tclient, byte[] data)
 {
     TheClient = tclient;
     DataStream ds = new DataStream(data);
     DataReader dr = new DataReader(ds);
     Load(dr, (b) => new ItemStack(tclient, b));
 }
Esempio n. 5
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();
 }
Esempio n. 7
0
 public byte[] Combine(List<byte[]> originals, bool angle)
 {
     Bitmap bmp = new Bitmap(Chunk.CHUNK_SIZE * (angle ? TexWidth2 : TexWidth), Chunk.CHUNK_SIZE * (angle ? TexWidth2 : TexWidth), PixelFormat.Format32bppArgb);
     using (Graphics graphics = Graphics.FromImage(bmp))
     {
         graphics.Clear(Transp);
         for (int i = 0; i < originals.Count; i++)
         {
             DataStream ds = new DataStream(originals[i]);
             Bitmap tbmp = new Bitmap(ds);
             graphics.DrawImage(tbmp, 0, 0);
             tbmp.Dispose();
         }
     }
     DataStream temp = new DataStream();
     bmp.Save(temp, ImageFormat.Png);
     return temp.ToArray();
 }
Esempio n. 8
0
 public override bool ParseBytesAndExecute(byte[] data)
 {
     if (data.Length < 16)
     {
         SysConsole.Output(OutputType.WARNING, "Got chunk info packet of size: " + data.Length);
         return false;
     }
     DataStream ds = new DataStream(data);
     DataReader dr = new DataReader(ds);
     int x = dr.ReadInt();
     int y = dr.ReadInt();
     int z = dr.ReadInt();
     int posMult = dr.ReadInt();
     double prio = (new Location(x, y, z) * Chunk.CHUNK_SIZE).DistanceSquared(TheClient.Player.GetPosition());
     lock (TheClient.TheRegion.PreppingNow)
     {
         TheClient.TheRegion.PrepChunks.Enqueue(() =>
         {
             lock (TheClient.TheRegion.PreppingNow)
             {
                 TheClient.TheRegion.PreppingNow.Add(new Vector3i(x, y, z));
             }
             TheClient.Schedule.StartASyncTask(() =>
             {
                 try
                 {
                     ParseData(data, dr, x, y, z, posMult);
                 }
                 catch (Exception ex)
                 {
                     Utilities.CheckException(ex);
                     SysConsole.Output(ex);
                     lock (TheClient.TheRegion.PreppingNow)
                     {
                         TheClient.TheRegion.PreppingNow.Remove(new Vector3i(x, y, z));
                     }
                 }
             });
         }, prio);
     }
     return true;
 }
 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();
 }
Esempio n. 10
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();
 }
Esempio n. 11
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();
 }
Esempio n. 12
0
 void RenderChunkInternal(WorldSystem.Region tregion, Vector3i chunkCoords, Chunk chunk)
 {
     Stopwatch sw = new Stopwatch();
     sw.Start();
     MaterialImage bmp = new MaterialImage() { Colors = new Color[BmpSize, BmpSize] };
     for (int x = 0; x < Chunk.CHUNK_SIZE; x++)
     {
         for (int y = 0; y < Chunk.CHUNK_SIZE; y++)
         {
             // TODO: async chunk read locker?
             BlockInternal topOpaque = BlockInternal.AIR;
             int topZ = 0;
             for (int z = 0; z < Chunk.CHUNK_SIZE; z++)
             {
                 BlockInternal bi = chunk.GetBlockAt(x, y, z);
                 if (bi.IsOpaque())
                 {
                     topOpaque = bi;
                     topZ = z;
                 }
             }
             if (!topOpaque.Material.RendersAtAll())
             {
                 DrawImage(bmp, MaterialImages[0], x * TexWidth, y * TexWidth, Color.Transparent);
             }
             for (int z = topZ; z < Chunk.CHUNK_SIZE; z++)
             {
                 BlockInternal bi = chunk.GetBlockAt(x, y, z);
                 if (bi.Material.RendersAtAll())
                 {
                     MaterialImage zmatbmp = MaterialImages[bi.Material.TextureID(MaterialSide.TOP)];
                     if (zmatbmp == null)
                     {
                         continue;
                     }
                     Color zcolor = Colors.ForByte(bi.BlockPaint);
                     if (zcolor.A == 0)
                     {
                         zcolor = Color.White;
                     }
                     DrawImage(bmp, zmatbmp, x * TexWidth, y * TexWidth, zcolor);
                 }
             }
         }
     }
     sw.Stop();
     Timings_A += sw.ElapsedTicks / (double)Stopwatch.Frequency;
     sw.Reset();
     sw.Start();
     Bitmap tbmp = new Bitmap(BmpSize2, BmpSize2);
     BitmapData bdat = tbmp.LockBits(new Rectangle(0, 0, tbmp.Width, tbmp.Height), ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb);
     int stride = bdat.Stride;
     // Surely there's a better way to do this!
     unsafe
     {
         byte* ptr = (byte*)bdat.Scan0;
         for (int x = 0; x < BmpSize; x++)
         {
             for (int y = 0; y < BmpSize; y++)
             {
                 Color tcol = bmp.Colors[x, y];
                 ptr[(x * 4) + y * stride + 0] = tcol.B;
                 ptr[(x * 4) + y * stride + 1] = tcol.G;
                 ptr[(x * 4) + y * stride + 2] = tcol.R;
                 ptr[(x * 4) + y * stride + 3] = tcol.A;
             }
         }
     }
     tbmp.UnlockBits(bdat);
     sw.Stop();
     Timings_B += sw.ElapsedTicks / (double)Stopwatch.Frequency;
     sw.Reset();
     sw.Start();
     DataStream ds = new DataStream();
     tbmp.Save(ds, ImageFormat.Png);
     tbmp.Dispose();
     sw.Stop();
     Timings_C += sw.ElapsedTicks / (double)Stopwatch.Frequency;
     sw.Reset();
     sw.Start();
     lock (OneAtATimePlease) // NOTE: We can probably make this grab off an array of locks to reduce load a little.
     {
         KeyValuePair<int, int> maxes = tregion.ChunkManager.GetMaxes((int)chunkCoords.X, (int)chunkCoords.Y);
         tregion.ChunkManager.SetMaxes((int)chunkCoords.X, (int)chunkCoords.Y, Math.Min(maxes.Key, (int)chunkCoords.Z), Math.Max(maxes.Value, (int)chunkCoords.Z));
     }
     tregion.ChunkManager.WriteImage((int)chunkCoords.X, (int)chunkCoords.Y, (int)chunkCoords.Z, ds.ToArray());
     sw.Stop();
     Timings_D += sw.ElapsedTicks / (double)Stopwatch.Frequency;
 }
 public override bool ParseBytesAndExecute(byte[] data)
 {
     DataStream ds = new DataStream(data);
     DataReader dr = new DataReader(ds);
     long PEID = dr.ReadLong();
     byte type = dr.ReadByte();
     Entity e = TheClient.TheRegion.GetEntity(PEID);
     if (type == 0)
     {
         if (e is PlayerEntity)
         {
             ((PlayerEntity)e).InVehicle = true;
             int drivecount = dr.ReadInt();
             int steercount = dr.ReadInt();
             PlayerEntity player = (PlayerEntity)e;
             player.DrivingMotors.Clear();
             player.SteeringMotors.Clear();
             for (int i = 0; i < drivecount; i++)
             {
                 long jid = dr.ReadLong();
                 JointVehicleMotor jvm = (JointVehicleMotor)TheClient.TheRegion.GetJoint(jid);
                 if (jvm == null)
                 {
                     dr.Close();
                     return false;
                 }
                 player.DrivingMotors.Add(jvm);
             }
             for (int i = 0; i < steercount; i++)
             {
                 long jid = dr.ReadLong();
                 JointVehicleMotor jvm = (JointVehicleMotor)TheClient.TheRegion.GetJoint(jid);
                 if (jvm == null)
                 {
                     dr.Close();
                     return false;
                 }
                 player.SteeringMotors.Add(jvm);
             }
             dr.Close();
             return true;
         }
         // TODO: other CharacterEntity's
     }
     else if (type == 1)
     {
         if (e is PlayerEntity)
         {
             long heloid = dr.ReadLong();
             Entity helo = TheClient.TheRegion.GetEntity(heloid);
             if (!(helo is ModelEntity))
             {
                 dr.Close();
                 return false;
             }
             ((PlayerEntity)e).InVehicle = true;
             ((PlayerEntity)e).Vehicle = helo;
             ModelEntity helomod = (ModelEntity)helo;
             helomod.TurnIntoHelicopter((PlayerEntity)e);
             dr.Close();
             return true;
         }
         // TODO: other CharacterEntity's
         dr.Close();
         return true;
     }
     else if (type == 2)
     {
         if (e is PlayerEntity)
         {
             long planeid = dr.ReadLong();
             Entity plane = TheClient.TheRegion.GetEntity(planeid);
             if (!(plane is ModelEntity))
             {
                 dr.Close();
                 return false;
             }
             ((PlayerEntity)e).InVehicle = true;
             ((PlayerEntity)e).Vehicle = plane;
             ModelEntity planemod = (ModelEntity)plane;
             planemod.TurnIntoPlane((PlayerEntity)e);
             dr.Close();
             return true;
         }
         // TODO: other CharacterEntity's
         dr.Close();
         return true;
     }
     dr.Close();
     return false;
 }
Esempio n. 14
0
 public SoundEffect LoadSound(DataStream stream, string name)
 {
     SoundEffect sfx = new SoundEffect();
     sfx.Name = name;
     int channels;
     int bits;
     int rate;
     byte[] data = LoadWAVE(stream, out channels, out bits, out rate);
     sfx.Internal = AL.GenBuffer();
     AL.BufferData(sfx.Internal, GetSoundFormat(channels, bits), data, data.Length, rate);
     return sfx;
 }
Esempio n. 15
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();
 }
Esempio n. 16
0
 /// <summary>
 /// Loads a model from .VMD (Voxalia Model Data) input.
 /// </summary>
 public Model3D LoadModel(byte[] data)
 {
     if (data.Length < 3 || data[0] != 'V' || data[1] != 'M' || data[2] != 'D')
     {
         throw new Exception("Model3D: Invalid header bits.");
     }
     byte[] dat_filt = new byte[data.Length - "VMD001".Length];
     Array.ConstrainedCopy(data, "VMD001".Length, dat_filt, 0, dat_filt.Length);
     dat_filt = FileHandler.UnGZip(dat_filt);
     DataStream ds = new DataStream(dat_filt);
     DataReader dr = new DataReader(ds);
     Model3D mod = new Model3D();
     mod.MatrixA = ReadMat(dr);
     int meshCount = dr.ReadInt();
     mod.Meshes = new List<Model3DMesh>(meshCount);
     for (int m = 0; m < meshCount; m++)
     {
         Model3DMesh mesh = new Model3DMesh();
         mod.Meshes.Add(mesh);
         mesh.Name = dr.ReadFullString();
         int vertexCount = dr.ReadInt();
         mesh.Vertices = new List<Vector3>(vertexCount);
         for (int v = 0; v < vertexCount; v++)
         {
             double f1 = dr.ReadFloat();
             double f2 = dr.ReadFloat();
             double f3 = dr.ReadFloat();
             mesh.Vertices.Add(new Vector3(f1, f2, f3));
         }
         int indiceCount = dr.ReadInt() * 3;
         mesh.Indices = new List<int>(indiceCount);
         for (int i = 0; i < indiceCount; i++)
         {
             mesh.Indices.Add(dr.ReadInt());
         }
         int tcCount = dr.ReadInt();
         mesh.TexCoords = new List<Vector2>(tcCount);
         for (int t = 0; t < tcCount; t++)
         {
             double f1 = dr.ReadFloat();
             double f2 = dr.ReadFloat();
             mesh.TexCoords.Add(new Vector2(f1, f2));
         }
         int normCount = dr.ReadInt();
         mesh.Normals = new List<Vector3>(normCount);
         for (int n = 0; n < normCount; n++)
         {
             double f1 = dr.ReadFloat();
             double f2 = dr.ReadFloat();
             double f3 = dr.ReadFloat();
             mesh.Normals.Add(new Vector3(f1, f2, f3));
         }
         int boneCount = dr.ReadInt();
         mesh.Bones = new List<Model3DBone>(boneCount);
         for (int b = 0; b < boneCount; b++)
         {
             Model3DBone bone = new Model3DBone();
             mesh.Bones.Add(bone);
             bone.Name = dr.ReadFullString();
             int weights = dr.ReadInt();
             bone.IDs = new List<int>(weights);
             bone.Weights = new List<double>(weights);
             for (int w = 0; w < weights; w++)
             {
                 bone.IDs.Add(dr.ReadInt());
                 bone.Weights.Add(dr.ReadFloat());
             }
             bone.MatrixA = ReadMat(dr);
         }
     }
     mod.RootNode = ReadSingleNode(null, dr);
     return mod;
 }
Esempio n. 17
0
 public SoundEffect LoadVorbisSound(DataStream stream, string name)
 {
     OggDecodeStream oggds = new OggDecodeStream(stream);
     return LoadSound(new DataStream(oggds.decodedStream.ToArray()), name);
 }
Esempio n. 18
0
 public void GetPage()
 {
     // TODO: FIX ME!
     string pageLow = http_request_page.ToLowerFast();
     #if PAGE_MAGIC
     if (pageLow.StartsWith("/map/region/"))
     {
         string after;
         string region = pageLow.Substring("/map/region/".Length).BeforeAndAfter("/", out after);
         for (int i = 0; i < TheServer.LoadedRegions.Count; i++)
         {
             if (TheServer.LoadedRegions[i].Name == region)
             {
                 string[] dat = after.SplitFast('/');
                 if (dat[0] == "img" && dat.Length >= 4)
                 {
                     int x = Utilities.StringToInt(dat[1]);
                     int y = Utilities.StringToInt(dat[2]);
                     int z = Utilities.StringToInt(dat[3].Before("."));
                     byte[] data = TheServer.LoadedRegions[i].ChunkManager.GetImage(x, y, z);
                     if (data != null)
                     {
                         http_response_contenttype = "image/png";
                         http_response_content = data;
                         return;
                     }
                 }
                 else if (dat[0] == "full_img" && dat.Length >= 3)
                 {
                     int x = Utilities.StringToInt(dat[1]);
                     int y = Utilities.StringToInt(dat[2].Before("."));
                     KeyValuePair<int, int> maxes = TheServer.LoadedRegions[i].ChunkManager.GetMaxes(x, y);
                     List<byte[]> datums = new List<byte[]>();
                     for (int z = maxes.Key; z <= maxes.Value; z++)
                     {
                         byte[] dt = TheServer.LoadedRegions[i].ChunkManager.GetImage(x, y, z);
                         if (dt != null)
                         {
                             datums.Add(dt);
                         }
                     }
                     http_response_contenttype = "image/png";
                     if (datums.Count > 1)
                     {
                         http_response_content = TheServer.BlockImages.Combine(datums, false);
                     }
                     else if (datums.Count == 1)
                     {
                         http_response_content = datums[0];
                     }
                     else
                     {
                         Bitmap bmp = new Bitmap(1, 1);
                         bmp.SetPixel(0, 0, Color.Black);
                         DataStream ds = new DataStream();
                         bmp.Save(ds, ImageFormat.Png);
                         http_response_content = ds.ToArray();
                         ds.Dispose();
                         bmp.Dispose();
                     }
                     return;
                 }
                 else if (dat[0] == "full_img_angle" && dat.Length >= 4)
                 {
                     int x = Utilities.StringToInt(dat[1]);
                     int y = Utilities.StringToInt(dat[2]);
                     int z = Utilities.StringToInt(dat[3].Before("."));
                     byte[] dt = TheServer.LoadedRegions[i].ChunkManager.GetImageAngle(x, y, z);
                     http_response_contenttype = "image/png";
                     if (dt != null)
                     {
                         http_response_content = dt;
                     }
                     else
                     {
                         Bitmap bmp = new Bitmap(1, 1);
                         bmp.SetPixel(0, 0, Color.Transparent);
                         DataStream ds = new DataStream();
                         bmp.Save(ds, ImageFormat.Png);
                         http_response_content = ds.ToArray();
                         ds.Dispose();
                         bmp.Dispose();
                     }
                     return;
                 }
                 else if (dat[0] == "maxes" && dat.Length >= 3)
                 {
                     int x = Utilities.StringToInt(dat[1]);
                     int y = Utilities.StringToInt(dat[2]);
                     KeyValuePair<int, int> maxes = TheServer.LoadedRegions[i].ChunkManager.GetMaxes(x, y);
                     http_response_content = FileHandler.encoding.GetBytes(maxes.Key + "," + maxes.Value);
                     return;
                 }
                 else if (dat[0] == "expquick" && dat.Length >= 3)
                 {
                     int bx = Utilities.StringToInt(dat[1]);
                     int by = Utilities.StringToInt(dat[2]);
                     int sz = Chunk.CHUNK_SIZE * BlockImageManager.TexWidth;
                     StringBuilder content = new StringBuilder();
                     content.Append("<!doctype html>\n<html>\n<head>\n<title>Voxalia EXP-QUICK</title>\n</head>\n<body>\n");
                     const int SIZE = 6;
                     for (int x = -SIZE; x <= SIZE; x++)
                     {
                         for (int y = -SIZE; y <= SIZE; y++)
                         {
                             content.Append("<img style=\"position:absolute;top:" + (y + SIZE) * sz + "px;left:" + (x + SIZE) * sz + "px;\" src=\"/map/region/"
                                 + region + "/full_img/" + (bx + x) + "/" + (by + y) + ".png\" width=\"" + sz + "\" height=\"" + sz + "\" />");
                         }
                     }
                     content.Append("\n</body>\n</html>\n");
                     http_response_content = FileHandler.encoding.GetBytes(content.ToString());
                     return;
                 }
                 else if (dat[0] == "expquick_angle" && dat.Length >= 4)
                 {
                     int bx = Utilities.StringToInt(dat[1]);
                     int by = Utilities.StringToInt(dat[2]);
                     int bz = Utilities.StringToInt(dat[3]);
                     int sz = Chunk.CHUNK_SIZE * BlockImageManager.TexWidth;
                     int sz2 = Chunk.CHUNK_SIZE * BlockImageManager.TexWidth2;
                     StringBuilder content = new StringBuilder();
                     content.Append("<!doctype html>\n<html>\n<head>\n<title>Voxalia EXP-QUICK (Angled)</title>\n</head>\n<body>\n");
                     const int SIZE = 3;
                     for (int x = -SIZE; x <= SIZE; x++)
                     {
                         for (int y = -SIZE; y <= SIZE; y++)
                         {
                             for (int z = -SIZE; z <= SIZE; z++)
                             {
                                 int x1 = (x) * sz;
                                 int y1 = (y) * sz;
                                 int z1 = (bz + z) * sz;
                                 int xw = (SIZE * 2 * sz) + (x1 - y1);
                                 int yw = ((SIZE * 2 * sz) + ((x1 + y1) - (z1))) / 2;
                                 content.Append("<img style=\"position:absolute;top:" + yw + "px;left:" + xw + "px;z-index:" + z + ";\" src=\"/map/region/"
                                     + region + "/full_img_angle/" + (bx + x) + "/" + (by + y) + "/" + (bz + z) + ".png\" width=\"" + sz2 + "\" height=\"" + sz2 + "\" />");
                             }
                         }
                     }
                     content.Append("\n</body>\n</html>\n");
                     http_response_content = FileHandler.encoding.GetBytes(content.ToString());
                     return;
                 }
                 break;
             }
         }
     }
     else
     #endif
     if (pageLow.StartsWith("/log_view/"))
     {
         string[] dat = pageLow.Substring("/log_view/".Length).SplitFast('/');
         string username = dat[0];
         string passcode = dat.Length < 2 ? "" : dat[1];
         bool valid = false;
         StringBuilder content = new StringBuilder();
         content.Append("<!doctype html>\n<html>\n<head>\n<title>Voxalia Log View</title>\n</head>\n<body>\n");
         lock (TheServer.TickLock)
         {
             FDSSection cfg = TheServer.GetPlayerConfig(username);
             valid = cfg != null
                 && cfg.GetString("web.is_admin", "false").ToLowerFast() == "true"
                 && cfg.GetString("web.passcode", "") == Utilities.HashQuick(username.ToLowerFast(), passcode);
         }
         if (valid)
         {
             content.Append("Logs follow:\n<pre><code>\n");
             lock (TheServer.RecentMessagesLock)
             {
                 foreach (string str in TheServer.RecentMessages)
                 {
                     foreach (string substr in str.SplitFast('\n'))
                     {
                         string trimmedsubstr = substr.Trim();
                         if (trimmedsubstr.Length > 0)
                         {
                             content.Append(trimmedsubstr.Replace("&", "&amp;").Replace("<", "&lt;").Replace(">", "&gt;")).Append("\n");
                         }
                     }
                 }
             }
             content.Append("\n</code></pre>");
         }
         else
         {
             content.Append("Not a valid login!");
         }
         content.Append("\n</body>\n</html>\n");
         http_response_content = FileHandler.encoding.GetBytes(content.ToString());
         return;
     }
     Do404();
 }
Esempio n. 19
0
 public override Entity Create(Region tregion, byte[] data)
 {
     DataStream ds = new DataStream(data);
     DataReader dr = new DataReader(ds);
     GenericCharacterEntity ent = new GenericCharacterEntity(tregion);
     ent.SetPosition(Location.FromDoubleBytes(dr.ReadBytes(24), 0));
     ent.SetOrientation(new BEPUutilities.Quaternion(dr.ReadFloat(), dr.ReadFloat(), dr.ReadFloat(), dr.ReadFloat()));
     ent.SetMass(dr.ReadFloat());
     ent.CBAirForce = dr.ReadFloat();
     ent.CBAirSpeed = dr.ReadFloat();
     ent.CBCrouchSpeed = dr.ReadFloat();
     ent.CBDownStepHeight = dr.ReadFloat();
     ent.CBGlueForce = dr.ReadFloat();
     ent.CBHHeight = dr.ReadFloat();
     ent.CBJumpSpeed = dr.ReadFloat();
     ent.CBMargin = dr.ReadFloat();
     ent.CBMaxSupportSlope = dr.ReadFloat();
     ent.CBMaxTractionSlope = dr.ReadFloat();
     ent.CBProneSpeed = dr.ReadFloat();
     ent.CBRadius = dr.ReadFloat();
     ent.CBSlideForce = dr.ReadFloat();
     ent.CBSlideJumpSpeed = dr.ReadFloat();
     ent.CBSlideSpeed = dr.ReadFloat();
     ent.CBStandSpeed = dr.ReadFloat();
     ent.CBStepHeight = dr.ReadFloat();
     ent.CBTractionForce = dr.ReadFloat();
     ent.PreRot *= Matrix4d.CreateRotationX(dr.ReadFloat() * Utilities.PI180);
     ent.PreRot *= Matrix4d.CreateRotationY(dr.ReadFloat() * Utilities.PI180);
     ent.PreRot *= Matrix4d.CreateRotationZ(dr.ReadFloat() * Utilities.PI180);
     ent.mod_scale = dr.ReadFloat();
     ent.PreRot = Matrix4d.Scale(ent.mod_scale) * ent.PreRot;
     ent.color = System.Drawing.Color.FromArgb(dr.ReadInt());
     byte dtx = dr.ReadByte();
     ent.Visible = (dtx & 1) == 1;
     int solidity = (dtx & (2 | 4 | 8));
     if (solidity == 2)
     {
         ent.CGroup = CollisionUtil.Solid;
     }
     else if (solidity == 4)
     {
         ent.CGroup = CollisionUtil.NonSolid;
     }
     else if (solidity == (2 | 4))
     {
         ent.CGroup = CollisionUtil.Item;
     }
     else if (solidity == 8)
     {
         ent.CGroup = CollisionUtil.Player;
     }
     else if (solidity == (2 | 8))
     {
         ent.CGroup = CollisionUtil.Water;
     }
     else if (solidity == (2 | 4 | 8))
     {
         ent.CGroup = CollisionUtil.WorldSolid;
     }
     else if (solidity == 16)
     {
         ent.CGroup = CollisionUtil.Character;
     }
     ent.model = tregion.TheClient.Models.GetModel(tregion.TheClient.Network.Strings.StringForIndex(dr.ReadInt()));
     dr.Close();
     return ent;
 }
Esempio n. 20
0
 void RenderChunkInternalAngle(WorldSystem.Region tregion, Vector3i chunkCoords, Chunk chunk)
 {
     MaterialImage bmp = new MaterialImage() { Colors = new Color[BmpSize2, BmpSize2] };
     for (int z = 0; z < Chunk.CHUNK_SIZE; z++)
     {
         for (int x = 0; x < Chunk.CHUNK_SIZE; x++)
         {
             for (int y = 0; y < Chunk.CHUNK_SIZE; y++)
             {
                 // TODO: async chunk read locker?
                 BlockInternal bi = chunk.GetBlockAt(x, y, z);
                 if (bi.Material.RendersAtAll())
                 {
                     RenderBlockIntoAngle(bi, x, y, z, bmp);
                 }
             }
         }
     }
     Bitmap tbmp = new Bitmap(BmpSize2, BmpSize2);
     BitmapData bdat = tbmp.LockBits(new Rectangle(0, 0, tbmp.Width, tbmp.Height), ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb);
     int stride = bdat.Stride;
     // Surely there's a better way to do this!
     unsafe
     {
         byte* ptr = (byte*)bdat.Scan0;
         for (int x = 0; x < BmpSize2; x++)
         {
             for (int y = 0; y < BmpSize2; y++)
             {
                 Color tcol = bmp.Colors[x, y];
                 ptr[(x * 4) + y * stride + 0] = tcol.B;
                 ptr[(x * 4) + y * stride + 1] = tcol.G;
                 ptr[(x * 4) + y * stride + 2] = tcol.R;
                 ptr[(x * 4) + y * stride + 3] = tcol.A;
             }
         }
     }
     DataStream ds = new DataStream();
     tbmp.Save(ds, ImageFormat.Png);
     tregion.ChunkManager.WriteImageAngle((int)chunkCoords.X, (int)chunkCoords.Y, (int)chunkCoords.Z, ds.ToArray());
 }
Esempio n. 21
0
 public byte[] LoadWAVE(DataStream stream, out int channels, out int bits, out int rate)
 {
     DataReader dr = new DataReader(stream);
     string signature = new string(dr.ReadChars(4));
     if (signature != "RIFF")
     {
         throw new NotSupportedException("Not a RIFF .wav file: " + signature);
     }
     /*int riff_chunk_size = */dr.ReadInt32();
     string format = new string(dr.ReadChars(4));
     if (format != "WAVE")
     {
         throw new NotSupportedException("Not a WAVE .wav file: " + format);
     }
     string format_signature = new string(dr.ReadChars(4));
     if (format_signature != "fmt ")
     {
         throw new NotSupportedException("Not a 'fmt ' .wav file: " + format_signature);
     }
     /*int format_chunk_size = */dr.ReadInt32();
     /*int audio_format = */dr.ReadInt16();
     int num_channels = dr.ReadInt16();
     if (num_channels != 1 && num_channels != 2)
     {
         throw new NotSupportedException("Invalid number of channels: " + num_channels);
     }
     int sample_rate = dr.ReadInt32();
     /*int byte_rate = */dr.ReadInt32();
     /*int block_align = */dr.ReadInt16();
     int bits_per_sample = dr.ReadInt16();
     string data_signature = new string(dr.ReadChars(4));
     if (data_signature != "data")
     {
         throw new NotSupportedException("Not a DATA .wav file: " + data_signature);
     }
     /*int data_chunk_size = */dr.ReadInt32();
     channels = num_channels;
     bits = bits_per_sample;
     rate = sample_rate;
     return dr.ReadBytes((int)dr.BaseStream.Length);
 }
Esempio n. 22
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();
 }
Esempio n. 23
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();
 }
Esempio n. 24
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;
 }