Exemple #1
0
 public void SendClickDistance(short distance)
 {
     byte[] buffer = new byte[3];
     buffer[0] = Opcode.CpeSetClickDistance;
     NetUtils.WriteI16(distance, buffer, 1);
     SendRaw(buffer);
 }
Exemple #2
0
 public static byte[] ClickDistance(short distance)
 {
     byte[] buffer = new byte[3];
     buffer[0] = Opcode.CpeSetClickDistance;
     NetUtils.WriteI16(distance, buffer, 1);
     return(buffer);
 }
Exemple #3
0
 public void SendExtRemovePlayerName(byte id)
 {
     byte[] buffer = new byte[3];
     buffer[0] = Opcode.CpeExtRemovePlayerName;
     NetUtils.WriteI16(id, buffer, 1);
     SendRaw(buffer);
 }
Exemple #4
0
 public static byte[] ExtInfo(byte count)
 {
     byte[] buffer = new byte[67];
     buffer[0] = Opcode.CpeExtInfo;
     NetUtils.WriteAscii("MCGalaxy " + Server.Version, buffer, 1);
     NetUtils.WriteI16((short)count, buffer, 65);
     return(buffer);
 }
Exemple #5
0
 static void WriteMapAppearance(byte[] buffer, string url, byte side, byte edge, int sideLevel)
 {
     buffer[0] = Opcode.CpeEnvSetMapApperance;
     NetUtils.WriteAscii(url, buffer, 1);
     buffer[65] = side;
     buffer[66] = edge;
     NetUtils.WriteI16((short)sideLevel, buffer, 67);
 }
Exemple #6
0
 void SendExtInfo(byte count)
 {
     byte[] buffer = new byte[67];
     buffer[0] = Opcode.CpeExtInfo;
     NetUtils.WriteAscii("MCGalaxy " + Server.Version, buffer, 1);
     NetUtils.WriteI16((short)count, buffer, 65);
     SendRaw(buffer, true);
 }
Exemple #7
0
 public static byte[] MapAppearanceV2(string url, byte side, byte edge, int sideLevel,
                                      int cloudHeight, int maxFog)
 {
     byte[] buffer = new byte[73];
     WriteMapAppearance(buffer, url, side, edge, sideLevel);
     NetUtils.WriteI16((short)cloudHeight, buffer, 69);
     NetUtils.WriteI16((short)maxFog, buffer, 71);
     return(buffer);
 }
Exemple #8
0
 public static byte[] EnvColor(byte type, short r, short g, short b)
 {
     byte[] buffer = new byte[8];
     buffer[0] = Opcode.CpeEnvColors;
     buffer[1] = type;
     NetUtils.WriteI16(r, buffer, 2);
     NetUtils.WriteI16(g, buffer, 4);
     NetUtils.WriteI16(b, buffer, 6);
     return(buffer);
 }
Exemple #9
0
 public void SendSetMapAppearance(string url, byte sideblock, byte edgeblock, short sidelevel)
 {
     byte[] buffer = new byte[69];
     buffer[0] = Opcode.CpeEnvSetMapApperance;
     NetUtils.WriteAscii(url, buffer, 1);
     buffer[65] = sideblock;
     buffer[66] = edgeblock;
     NetUtils.WriteI16(sidelevel, buffer, 67);
     SendRaw(buffer);
 }
Exemple #10
0
 public void SendEnvColor(byte type, short r, short g, short b)
 {
     byte[] buffer = new byte[8];
     buffer[0] = Opcode.CpeEnvColors;
     buffer[1] = type;
     NetUtils.WriteI16(r, buffer, 2);
     NetUtils.WriteI16(g, buffer, 4);
     NetUtils.WriteI16(b, buffer, 6);
     SendRaw(buffer);
 }
Exemple #11
0
 public void SendExtAddPlayerName(byte id, string listName, string displayName, string grp, byte grpRank)
 {
     byte[] buffer = new byte[196];
     buffer[0] = Opcode.CpeExtAddPlayerName;
     NetUtils.WriteI16(id, buffer, 1);
     NetUtils.WriteAscii(listName, buffer, 3);
     NetUtils.WriteAscii(displayName, buffer, 67);
     NetUtils.WriteAscii(grp, buffer, 131);
     buffer[195] = grpRank;
     SendRaw(buffer);
 }
Exemple #12
0
 void SendHackControl(byte allowflying, byte allownoclip, byte allowspeeding, byte allowrespawning,
                      byte allowthirdperson, short maxjumpheight)
 {
     byte[] buffer = new byte[8];
     buffer[0] = Opcode.CpeHackControl;
     buffer[1] = allowflying;
     buffer[2] = allownoclip;
     buffer[3] = allowspeeding;
     buffer[4] = allowrespawning;
     buffer[5] = allowthirdperson;
     NetUtils.WriteI16(maxjumpheight, buffer, 6);
     SendRaw(buffer);
 }
Exemple #13
0
 public void SendSetMapAppearanceV2(string url, byte sideblock, byte edgeblock, short sidelevel,
                                    short cloudHeight, short maxFog)
 {
     byte[] buffer = new byte[73];
     buffer[0] = Opcode.CpeEnvSetMapApperance;
     NetUtils.WriteAscii(url, buffer, 1);
     buffer[65] = sideblock;
     buffer[66] = edgeblock;
     NetUtils.WriteI16(sidelevel, buffer, 67);
     NetUtils.WriteI16(cloudHeight, buffer, 69);
     NetUtils.WriteI16(maxFog, buffer, 71);
     SendRaw(buffer);
 }
Exemple #14
0
 public static byte[] HackControl(bool canFly, bool canNoclip,
                                  bool canSpeed, bool canRespawn,
                                  bool can3rdPerson, short maxJumpHeight)
 {
     byte[] buffer = new byte[8];
     buffer[0] = Opcode.CpeHackControl;
     buffer[1] = (byte)(canFly ? 1 : 0);
     buffer[2] = (byte)(canNoclip ? 1 : 0);
     buffer[3] = (byte)(canSpeed ? 1 : 0);
     buffer[4] = (byte)(canRespawn ? 1 : 0);
     buffer[5] = (byte)(can3rdPerson ? 1 : 0);
     NetUtils.WriteI16(maxJumpHeight, buffer, 6);
     return(buffer);
 }
Exemple #15
0
 public void SendMakeSelection(byte id, string label, short smallx, short smally, short smallz, short bigx, short bigy, short bigz, short r, short g, short b, short opacity)
 {
     byte[] buffer = new byte[86];
     buffer[0] = Opcode.CpeMakeSelection;
     buffer[1] = id;
     NetUtils.WriteAscii(label, buffer, 2);
     NetUtils.WriteI16(smallx, buffer, 66);
     NetUtils.WriteI16(smally, buffer, 68);
     NetUtils.WriteI16(smallz, buffer, 70);
     NetUtils.WriteI16(bigx, buffer, 72);
     NetUtils.WriteI16(bigy, buffer, 74);
     NetUtils.WriteI16(bigz, buffer, 76);
     NetUtils.WriteI16(r, buffer, 78);
     NetUtils.WriteI16(g, buffer, 80);
     NetUtils.WriteI16(b, buffer, 82);
     NetUtils.WriteI16(opacity, buffer, 84);
     SendRaw(buffer);
 }
Exemple #16
0
        public static byte[] MakeSelection(byte id, string label, Vec3U16 p1, Vec3U16 p2,
                                           short r, short g, short b, short opacity)
        {
            byte[] buffer = new byte[86];
            buffer[0] = Opcode.CpeMakeSelection;
            buffer[1] = id;
            NetUtils.WriteAscii(label, buffer, 2);

            NetUtils.WriteU16(p1.X, buffer, 66);
            NetUtils.WriteU16(p1.Y, buffer, 68);
            NetUtils.WriteU16(p1.Z, buffer, 70);
            NetUtils.WriteU16(p2.X, buffer, 72);
            NetUtils.WriteU16(p2.Y, buffer, 74);
            NetUtils.WriteU16(p2.Z, buffer, 76);

            NetUtils.WriteI16(r, buffer, 78);
            NetUtils.WriteI16(g, buffer, 80);
            NetUtils.WriteI16(b, buffer, 82);
            NetUtils.WriteI16(opacity, buffer, 84);
            return(buffer);
        }
Exemple #17
0
        public bool SendRawMap(Level oldLevel, Level level)
        {
            if (level.blocks == null)
            {
                return(false);
            }
            bool success = true;

            useCheckpointSpawn  = false;
            lastCheckpointIndex = -1;

            try {
                int    usedLength = 0;
                byte[] buffer     = CompressRawMap(out usedLength);

                if (hasBlockDefs)
                {
                    if (oldLevel != null && oldLevel != level)
                    {
                        RemoveOldLevelCustomBlocks(oldLevel);
                    }
                    BlockDefinition.SendLevelCustomBlocks(this);
                }

                SendRaw(Opcode.LevelInitialise);
                int totalRead = 0;
                while (totalRead < usedLength)
                {
                    byte[] packet = new byte[1028]; // need each packet separate for Mono
                    packet[0] = Opcode.LevelDataChunk;
                    short length = (short)Math.Min(buffer.Length - totalRead, 1024);
                    NetUtils.WriteI16(length, packet, 1);
                    Buffer.BlockCopy(buffer, totalRead, packet, 3, length);
                    packet[1027] = (byte)(100 * (float)totalRead / buffer.Length);

                    SendRaw(packet);
                    if (ip != "127.0.0.1")
                    {
                        Thread.Sleep(Server.updateTimer.Interval > 1000 ? 100 : 10);
                    }
                    totalRead += length;
                }

                buffer    = new byte[7];
                buffer[0] = Opcode.LevelFinalise;
                NetUtils.WriteI16((short)level.Width, buffer, 1);
                NetUtils.WriteI16((short)level.Height, buffer, 3);
                NetUtils.WriteI16((short)level.Length, buffer, 5);
                SendRaw(buffer);
                Loading = false;

                if (HasCpeExt(CpeExt.EnvWeatherType))
                {
                    SendSetMapWeather(level.weather);
                }
                if (HasCpeExt(CpeExt.EnvColors))
                {
                    SendCurrentEnvColors();
                }
                if (HasCpeExt(CpeExt.EnvMapAppearance) || HasCpeExt(CpeExt.EnvMapAppearance, 2))
                {
                    SendCurrentMapAppearance();
                }

                if (OnSendMap != null)
                {
                    OnSendMap(this, buffer);
                }
                if (!level.guns)
                {
                    aiming = false;
                }
            } catch (Exception ex) {
                success = false;
                Command.all.Find("goto").Use(this, Server.mainLevel.name);
                SendMessage("There was an error sending the map data, you have been sent to the main level.");
                Server.ErrorLog(ex);
            } finally {
                GC.Collect();
                GC.WaitForPendingFinalizers();
            }

            if (HasCpeExt(CpeExt.BlockPermissions))
            {
                SendCurrentBlockPermissions();
            }
            return(success);
        }
Exemple #18
0
        bool SendRawMapCore(Level oldLevel, Level level)
        {
            if (level.blocks == null)
            {
                return(false);
            }
            bool success = true;

            useCheckpointSpawn  = false;
            lastCheckpointIndex = -1;

            LevelAccess access = level.BuildAccess.Check(this);

            AllowBuild = access == LevelAccess.Whitelisted || access == LevelAccess.Allowed;

            try {
                if (hasBlockDefs)
                {
                    if (oldLevel != null && oldLevel != level)
                    {
                        RemoveOldLevelCustomBlocks(oldLevel);
                    }
                    BlockDefinition.SendLevelCustomBlocks(this);
                }

                SendRaw(Opcode.LevelInitialise);
                using (LevelChunkStream s = new LevelChunkStream(this))
                    LevelChunkStream.CompressMap(this, s);

                byte[] buffer = new byte[7];
                buffer[0] = Opcode.LevelFinalise;
                NetUtils.WriteI16((short)level.Width, buffer, 1);
                NetUtils.WriteI16((short)level.Height, buffer, 3);
                NetUtils.WriteI16((short)level.Length, buffer, 5);
                Send(buffer);
                AFKCooldown = DateTime.UtcNow.AddSeconds(2);
                Loading     = false;

                if (HasCpeExt(CpeExt.EnvWeatherType))
                {
                    Send(Packet.EnvWeatherType((byte)level.Weather));
                }
                if (HasCpeExt(CpeExt.EnvColors))
                {
                    SendCurrentEnvColors();
                }
                SendCurrentMapAppearance();
                if (HasCpeExt(CpeExt.BlockPermissions))
                {
                    SendCurrentBlockPermissions();
                }

                if (OnSendMap != null)
                {
                    OnSendMap(this, buffer);
                }
                if (!level.guns && aiming)
                {
                    aiming = false;
                    ClearBlockchange();
                }
            } catch (Exception ex) {
                success = false;
                PlayerActions.ChangeMap(this, Server.mainLevel);
                SendMessage("There was an error sending the map data, you have been sent to the main level.");
                Server.ErrorLog(ex);
            } finally {
                GC.Collect();
                GC.WaitForPendingFinalizers();
            }
            return(success);
        }