예제 #1
0
        public static void GunHandler(Player player, Command cmd)
        {
            //to prevent players from doing /gun during a TDM game that arent actually playing in
            if (player.World.gameMode == GameMode.TeamDeathMatch && !player.Info.isPlayingTD)
            {
                player.Message("Players who are not playing Team DeathMatch can only spectate.");
                return;
            }

            if (player.Info.isPlayingCTF && player.Info.gunDisarmed)
            {
                player.Message("You are currently disarmed. You cannot use a gun until the disarm powerup has worn off.");
                return;
            }
            if (player.GunMode)
            {
                player.GunMode = false;
                try
                {
                    foreach (Vector3I block in player.GunCache.Values)
                    {
                        player.Send(PacketWriter.MakeSetBlock(block.X, block.Y, block.Z, player.WorldMap.GetBlock(block)));
                        Vector3I removed;
                        player.GunCache.TryRemove(block.ToString(), out removed);
                    }
                    if (player.bluePortal.Count > 0)
                    {
                        int i = 0;
                        foreach (Vector3I block in player.bluePortal)
                        {
                            if (player.WorldMap != null && player.World.IsLoaded)
                            {
                                player.WorldMap.QueueUpdate(new BlockUpdate(null, block, player.blueOld[i]));
                                i++;
                            }
                        }
                        player.blueOld.Clear();
                        player.bluePortal.Clear();
                    }
                    if (player.orangePortal.Count > 0)
                    {
                        int i = 0;
                        foreach (Vector3I block in player.orangePortal)
                        {
                            if (player.WorldMap != null && player.World.IsLoaded)
                            {
                                player.WorldMap.QueueUpdate(new BlockUpdate(null, block, player.orangeOld[i]));
                                i++;
                            }
                        }
                        player.orangeOld.Clear();
                        player.orangePortal.Clear();
                    }
                    player.Message("&SGunMode deactivated");
                }
                catch (Exception ex)
                {
                    Logger.Log(LogType.SeriousError, "" + ex);
                }
            }
            else
            {
                if (!player.World.gunPhysics)
                {
                    player.Message("&WGun physics are disabled on this world");
                    return;
                }
                player.GunMode = true;
                GunGlassTimer timer = new GunGlassTimer(player);
                timer.Start();
                player.Message("&SGunMode activated. Fire at will!");
            }
        }
예제 #2
0
        public static void gunMove(Player player)
        {
            World world = player.World;

            if (null == world)
            {
                return;
            }
            try
            {
                lock (world.SyncRoot)
                {
                    if (null == world.Map)
                    {
                        return;
                    }
                    if (player.IsOnline)
                    {
                        Position p    = player.Position;
                        double   ksi  = 2.0 * Math.PI * (-player.Position.L) / 256.0;
                        double   phi  = 2.0 * Math.PI * (player.Position.R - 64) / 256.0;
                        double   sphi = Math.Sin(phi);
                        double   cphi = Math.Cos(phi);
                        double   sksi = Math.Sin(ksi);
                        double   cksi = Math.Cos(ksi);

                        if (player.IsOnline)
                        {
                            if (player.GunCache.Values.Count > 0)
                            {
                                foreach (Vector3I block in player.GunCache.Values)
                                {
                                    if (player.IsOnline)
                                    {
                                        player.Send(PacketWriter.MakeSetBlock(block.X, block.Y, block.Z, world.Map.GetBlock(block)));
                                        Vector3I removed;
                                        player.GunCache.TryRemove(block.ToString(), out removed);
                                    }
                                }
                            }
                        }

                        for (int y = -1; y < 2; ++y)
                        {
                            for (int z = -1; z < 2; ++z)
                            {
                                if (player.IsOnline)
                                {
                                    //4 is the distance betwen the player and the glass wall
                                    Vector3I glassBlockPos = new Vector3I((int)(cphi * cksi * 4 - sphi * (0.5 + y) - cphi * sksi * (0.5 + z)),
                                                                          (int)(sphi * cksi * 4 + cphi * (0.5 + y) - sphi * sksi * (0.5 + z)),
                                                                          (int)(sksi * 4 + cksi * (0.5 + z)));
                                    glassBlockPos += p.ToBlockCoords();
                                    if (world.Map.GetBlock(glassBlockPos) == Block.Air)
                                    {
                                        player.Send(PacketWriter.MakeSetBlock(glassBlockPos, Block.Glass));
                                        player.GunCache.TryAdd(glassBlockPos.ToString(), glassBlockPos);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Log(LogType.SeriousError, "GunGlass: " + ex);
            }
        }
예제 #3
0
 public static void GunHandler(Player player, Command cmd)
 {
     if (player.GunMode)
     {
         player.GunMode = false;
         try
         {
             foreach (Vector3I block in player.GunCache.Values)
             {
                 player.Send(PacketWriter.MakeSetBlock(block.X, block.Y, block.Z, player.WorldMap.GetBlock(block)));
                 Vector3I removed;
                 player.GunCache.TryRemove(block.ToString(), out removed);
             }
             if (player.bluePortal.Count > 0)
             {
                 int i = 0;
                 foreach (Vector3I block in player.bluePortal)
                 {
                     if (player.WorldMap != null && player.World.IsLoaded)
                     {
                         player.WorldMap.QueueUpdate(new BlockUpdate(null, block, player.blueOld[i]));
                         i++;
                     }
                 }
                 player.blueOld.Clear();
                 player.bluePortal.Clear();
             }
             if (player.orangePortal.Count > 0)
             {
                 int i = 0;
                 foreach (Vector3I block in player.orangePortal)
                 {
                     if (player.WorldMap != null && player.World.IsLoaded)
                     {
                         player.WorldMap.QueueUpdate(new BlockUpdate(null, block, player.orangeOld[i]));
                         i++;
                     }
                 }
                 player.orangeOld.Clear();
                 player.orangePortal.Clear();
             }
             player.Message("&SGunMode deactivated");
         }
         catch (Exception ex)
         {
             Logger.Log(LogType.SeriousError, "" + ex);
         }
     }
     else
     {
         if (!player.World.gunPhysics)
         {
             player.Message("&WGun physics are disabled on this world");
             return;
         }
         player.GunMode = true;
         GunGlassTimer timer = new GunGlassTimer(player);
         timer.Start();
         player.Message("&SGunMode activated. Fire at will!");
     }
 }
예제 #4
0
파일: Map.cs 프로젝트: TheDireMaster/fCraft
        // Applies pending updates and sends them to players (if applicable).
        internal void ProcessUpdates()
        {
            if (World == null)
            {
                throw new InvalidOperationException("Map must be assigned to a world to process updates.");
            }

            if (World.IsLocked)
            {
                if (World.IsPendingMapUnload)
                {
                    World.UnloadMap(true);
                }
                return;
            }

            int         packetsSent         = 0;
            bool        canFlush            = false;
            int         maxPacketsPerUpdate = Server.CalculateMaxPacketsPerUpdate(World);
            BlockUpdate update = new BlockUpdate();

            while (packetsSent < maxPacketsPerUpdate)
            {
                if (!updates.Dequeue(ref update))
                {
                    if (World.IsFlushing)
                    {
                        canFlush = true;
                    }
                    break;
                }
                HasChangedSinceSave = true;
                if (!InBounds(update.X, update.Y, update.Z))
                {
                    continue;
                }
                int blockIndex = Index(update.X, update.Y, update.Z);
                Blocks[blockIndex] = (byte)update.BlockType;

                if (!World.IsFlushing)
                {
                    Packet packet = PacketWriter.MakeSetBlock(update.X, update.Y, update.Z, update.BlockType);
                    World.Players.SendLowPriority(update.Origin, packet);
                }
                packetsSent++;
            }

            if (drawOps.Count > 0)
            {
                lock ( drawOpLock ) {
                    if (drawOps.Count > 0)
                    {
                        packetsSent += ProcessDrawOps(maxPacketsPerUpdate - packetsSent);
                    }
                }
            }
            else if (canFlush)
            {
                World.EndFlushMapBuffer();
            }

            if (packetsSent == 0 && World.IsPendingMapUnload)
            {
                World.UnloadMap(true);
            }
        }
예제 #5
0
        // Change player class
        void ChangeClass(Player player, Command cmd)
        {
            string name         = cmd.Next();
            string newClassName = cmd.Next();

            if (name == null || newClassName == null)
            {
                player.Message("Usage: " + Color.Help + "/user PlayerName ClassName");
                player.Message("To see a list of classes and permissions, use " + Color.Help + "/class");
                return;
            }

            Player target = world.FindPlayer(name);

            if (target == null)
            {
                world.NoPlayerMessage(player, name);
                return;
            }

            PlayerClass newClass = world.classes.FindClass(newClassName);

            if (newClass == null)
            {
                player.Message("Unrecognized player class: " + newClassName);
                return;
            }

            if (target.info.playerClass == newClass)
            {
                player.Message(target.name + "'s class is already " + newClass.color + newClass.name);
                return;
            }

            bool promote = target.info.playerClass.rank < newClass.rank;

            if ((promote && !player.Can(Permissions.Promote)) || !promote && !player.Can(Permissions.Demote))
            {
                world.NoAccessMessage(player);
                return;
            }

            if (promote && !player.info.playerClass.CanPromote(newClass))
            {
                PlayerClass maxRank = player.info.playerClass.maxPromote;
                if (maxRank == null)
                {
                    player.Message("You can only promote players up to " + player.info.playerClass.color + player.info.playerClass.name);
                }
                else
                {
                    player.Message("You can only promote players up to " + maxRank.color + maxRank.name);
                }
                return;
            }
            else if (!promote && !player.info.playerClass.CanDemote(target.info.playerClass))
            {
                PlayerClass maxRank = player.info.playerClass.maxDemote;
                if (maxRank == null)
                {
                    player.Message("You can only demote players that are " + player.info.playerClass.color + player.info.playerClass.name + Color.Sys + " or lower.");
                }
                else
                {
                    player.Message("You can only demote players that are " + maxRank.color + maxRank.name + Color.Sys + " or lower.");
                }
                return;
            }

            if (promote && target.info.playerClass.rank < newClass.rank ||
                target.info.playerClass.rank > newClass.rank)
            {
                world.log.Log("{0} changed the class of {1} from {2} to {3}.", LogType.UserActivity,
                              player.name, target.info.name, target.info.playerClass.name, newClass.name);
                target.info.playerClass     = newClass;
                target.info.classChangeDate = DateTime.Now;
                target.info.classChangedBy  = player.name;

                target.Send(PacketWriter.MakeSetPermission(target));

                if (promote)
                {
                    player.Message("You promoted " + target.name + " to " + newClass.color + newClass.name + ".");
                    target.Message("You have been promoted to " + newClass.color + newClass.name + Color.Sys + " by " + player.name + "!");
                }
                else
                {
                    player.Message("You demoted " + target.name + " to " + newClass.color + newClass.name + ".");
                    target.Message("You have been demoted to " + newClass.color + newClass.name + Color.Sys + " by " + player.name + "!");
                }
                if (world.config.GetBool("ClassPrefixesInList") || world.config.GetBool("ClassColorsInChat"))       // TODO: colors in player names
                {
                    world.UpdatePlayer(target);
                }
                target.mode = BlockPlacementMode.Normal;
            }
            else
            {
                if (promote)
                {
                    player.Message(target.name + " is already same or lower rank than " + newClass.name);
                }
                else
                {
                    player.Message(target.name + " is already same or higher rank than " + newClass.name);
                }
            }
        }
예제 #6
0
        void DoBan(Player player, Command cmd, bool banIP, bool banAll, bool unban)
        {
            if (!banAll && !banIP && player.Can(Permissions.Ban) ||
                !banAll && player.Can(Permissions.BanIP) ||
                player.Can(Permissions.BanAll))
            {
                string     arg    = cmd.Next();
                string     reason = cmd.NextAll();
                IPAddress  address;
                Player     offender = world.FindPlayer(arg);
                PlayerInfo info     = world.db.FindPlayerInfoExact(arg);

                // ban by IP address
                if (banIP && IPAddress.TryParse(arg, out address))
                {
                    if (banIP)
                    {
                        DoIPBan(player, address, reason, null, banAll, unban);
                    }

                    // ban online players
                }
                else if (!unban && offender != null)
                {
                    address = offender.info.lastIP;
                    if (banIP)
                    {
                        DoIPBan(player, address, reason, offender.name, banAll, unban);
                    }
                    if (unban)
                    {
                        if (offender.info.ProcessUnBan(player.name, reason))
                        {
                            world.log.Log("{0} was unbanned by {1}.", LogType.UserActivity, offender.info.name, player.name);
                            world.SendToAll(PacketWriter.MakeMessage(Color.Red + offender.name + " was unbanned by " + player.name), offender);
                        }
                        else
                        {
                            player.Message(offender.name + " is not currently banned.");
                        }
                    }
                    else
                    {
                        if (offender.info.ProcessBan(player.name, reason))
                        {
                            world.log.Log("{0} was banned by {1}.", LogType.UserActivity, offender.info.name, player.name);
                            world.SendToAll(PacketWriter.MakeMessage(Color.Red + offender.name + " was banned by " + player.name), offender);
                            offender.session.Kick("You were banned by " + player.name + "!");
                        }
                        else
                        {
                            player.Message(offender.name + " is already banned.");
                        }
                    }

                    // ban offline players
                }
                else if (info != null)
                {
                    address = info.lastIP;
                    if (banIP)
                    {
                        DoIPBan(player, address, reason, info.name, banAll, unban);
                    }
                    if (unban)
                    {
                        if (info.ProcessUnBan(player.name, reason))
                        {
                            world.log.Log("{0} (offline) was unbanned by {1}", LogType.UserActivity, info.name, player.name);
                            world.SendToAll(PacketWriter.MakeMessage(Color.Red + info.name + " (offline) was unbanned by " + player.name), null);
                        }
                        else
                        {
                            player.Message(info.name + " (offline) is not currenty banned.");
                        }
                    }
                    else
                    {
                        if (info.ProcessBan(player.name, reason))
                        {
                            world.log.Log("{0} (offline) was banned by {1}.", LogType.UserActivity, info.name, player.name);
                            world.SendToAll(PacketWriter.MakeMessage(Color.Red + info.name + " (offline) was banned by " + player.name), null);
                        }
                        else
                        {
                            player.Message(info.name + " (offline) is already banned.");
                        }
                    }
                }
                else
                {
                    world.NoPlayerMessage(player, arg);
                }
            }
            else
            {
                world.NoAccessMessage(player);
            }
        }
예제 #7
0
 internal void SendAllEnvColor(byte variable, int  value) {
 	Packet packet = PacketWriter.MakeEnvSetColor(variable, value);
     foreach (Player p in Players.Where(p => p.usesCPE))
         p.Send(packet);
 }
예제 #8
0
 internal void SendAllMapWeather() {
     Packet packet = PacketWriter.MakeEnvWeatherAppearance((byte)WeatherCC);
     foreach (Player p in Players.Where(p => p.usesCPE))
         p.Send(packet);
 }
예제 #9
0
 internal void SendAllMapAppearance() {
     Packet packet = PacketWriter.MakeEnvSetMapAppearance(textureURL, SideBlock, EdgeBlock, EdgeLevel);
     foreach (Player p in Players.Where(p => p.usesCPE))
         p.Send(packet);
 }