Esempio n. 1
0
        internal static void UpdatePrimary(ZombieGame game, Player p)
        {
            int    left   = (int)(game.RoundEnd - DateTime.UtcNow).TotalSeconds;
            string status = FormatPrimary(game, left);

            p.SendCpeMessage(CpeMessageType.Status1, status);
        }
Esempio n. 2
0
        internal static bool Handles(Player p, ushort x, ushort y, ushort z,
                                     byte action, byte block, byte old, ZombieGame game)
        {
            if (action == 1 && !game.CurLevel.Pillaring && !p.Game.Referee)
            {
                if (NotPillaring(block, old))
                {
                    p.Game.BlocksStacked = 0;
                }
                else if (CheckCoords(p, x, y, z))
                {
                    p.Game.BlocksStacked++;
                }
                else
                {
                    p.Game.BlocksStacked = 0;
                }

                if (MessagePillaring(p, x, y, z))
                {
                    return(true);
                }
            }
            p.Game.LastX = x; p.Game.LastY = y; p.Game.LastZ = z;
            return(false);
        }
Esempio n. 3
0
        /// <summary> Moves all players to the level which has the highest number of votes. </summary>
        static void MoveToNextLevel(Random r, List <string> levels, ZombieGame game)
        {
            int v1 = game.Votes1, v2 = game.Votes2, v3 = game.Votes3;

            if (v1 >= v2)
            {
                if (v3 > v1 && v3 > v2)
                {
                    game.ChangeLevel(game.Candidate3);
                }
                else
                {
                    game.ChangeLevel(game.Candidate1);
                }
            }
            else
            {
                if (v3 > v1 && v3 > v2)
                {
                    game.ChangeLevel(game.Candidate3);
                }
                else
                {
                    game.ChangeLevel(game.Candidate2);
                }
            }
            Player[] online = PlayerInfo.Online.Items;
            foreach (Player pl in online)
            {
                pl.voted = false;
            }
        }
Esempio n. 4
0
        static void RemoveRecentLevels(List <string> maps, ZombieGame game)
        {
            // Try to avoid recently played levels, avoiding most recent
            List <string> recent = game.RecentMaps;

            for (int i = recent.Count - 1; i >= 0; i--)
            {
                if (maps.Count > 3 && maps.CaselessContains(recent[i]))
                {
                    maps.CaselessRemove(recent[i]);
                }
            }

            // Try to avoid maps voted last round if possible
            if (maps.Count > 3 && maps.CaselessContains(game.Candidate1))
            {
                maps.CaselessRemove(game.Candidate1);
            }
            if (maps.Count > 3 && maps.CaselessContains(game.Candidate2))
            {
                maps.CaselessRemove(game.Candidate2);
            }
            if (maps.Count > 3 && maps.CaselessContains(game.Candidate3))
            {
                maps.CaselessRemove(game.Candidate3);
            }
        }
Esempio n. 5
0
        public static void HandOut(ZombieGame game)
        {
            Player[] alive = game.Alive.Items, dead = game.Infected.Items;
            game.CurLevel.ChatLevel("&aThe game has ended!");

            if (alive.Length == 0)
            {
                game.CurLevel.ChatLevel("&4Zombies have won this round.");
            }
            else if (alive.Length == 1)
            {
                game.CurLevel.ChatLevel("&2Congratulations to the sole survivor:");
            }
            else
            {
                game.CurLevel.ChatLevel("&2Congratulations to the survivors:");
            }
            AnnounceWinners(game, alive, dead);

            game.CurLevel.RoundsPlayed++;
            if (alive.Length > 0)
            {
                game.CurLevel.RoundsHumanWon++;
                foreach (Player p in alive)
                {
                    IncreaseAliveStats(p, game);
                }
            }

            GiveMoney(game, alive);
            DoLottery(game);
        }
Esempio n. 6
0
        internal static void UpdateAllPrimary(ZombieGame game)
        {
            int    left   = (int)(game.RoundEnd - DateTime.UtcNow).TotalSeconds;
            string status = FormatPrimary(game, left);

            MessageAll(game, CpeMessageType.Status1, status);
        }
Esempio n. 7
0
        static string FormatSecondary(ZombieGame game)
        {
            string pillar = "%SPillaring " + (game.CurLevel.Pillaring ? "&aYes" : "&cNo");
            string type   = "%S, Type is &a" + game.CurLevel.BuildType;

            return(pillar + type);
        }
Esempio n. 8
0
        static void AnnounceWinners(ZombieGame game, Player[] alive, Player[] dead)
        {
            if (alive.Length > 0)
            {
                string winners = alive.Join(p => p.ColoredName);
                game.CurLevel.ChatLevel(winners);
                return;
            }

            int maxKills = 0, count = 0;

            for (int i = 0; i < dead.Length; i++)
            {
                maxKills = Math.Max(maxKills, dead[i].Game.CurrentInfected);
            }
            for (int i = 0; i < dead.Length; i++)
            {
                if (dead[i].Game.CurrentInfected == maxKills)
                {
                    count++;
                }
            }

            string group  = count == 1 ? " zombie " : " zombies ";
            string suffix = maxKills == 1 ? " %Skill" : " %Skills";
            Func <Player, string> formatter = p => p.Game.CurrentInfected == maxKills ? p.ColoredName : null;

            game.CurLevel.ChatLevel("&8Best" + group + "%S(&b" + maxKills
                                    + suffix + "%S)&8: " + dead.Join(formatter));
        }
Esempio n. 9
0
        static void VoteCountdown(ZombieGame game)
        {
            // Show message for non-CPE clients
            Player[] players = PlayerInfo.Online.Items;
            foreach (Player pl in players)
            {
                if (pl.level != game.CurLevel || pl.HasCpeExt(CpeExt.MessageTypes))
                {
                    continue;
                }
                pl.SendMessage("You have 20 seconds to vote for the next map");
            }

            for (int i = 0; i < 20; i++)
            {
                players = PlayerInfo.Online.Items;
                foreach (Player pl in players)
                {
                    if (pl.level != game.CurLevel || !pl.HasCpeExt(CpeExt.MessageTypes))
                    {
                        continue;
                    }
                    pl.SendCpeMessage(CpeMessageType.BottomRight1, "&e" + (20 - i) + "s %Sleft to vote");
                }
                Thread.Sleep(1000);
            }
        }
Esempio n. 10
0
        static void IncreaseAliveStats(Player p, ZombieGame game)
        {
            if (p.Game.PledgeSurvive)
            {
                p.SendMessage("You received &a5 %3" + Server.moneys +
                              " %Sfor successfully pledging that you would survive.");
                p.SetMoney(p.money + 5);
            }

            p.Game.CurrentRoundsSurvived++;
            p.Game.TotalRoundsSurvived++;
            p.Game.MaxRoundsSurvived = Math.Max(p.Game.CurrentRoundsSurvived, p.Game.MaxRoundsSurvived);
            p.SetPrefix(); // stars before name
        }
Esempio n. 11
0
        static string FormatPrimary(ZombieGame game, int seconds)
        {
            string timespan = GetTimeLeft(seconds);

            if (timespan.Length > 0)
            {
                const string format = "&a{0} %Salive %S({2}, map: {1})";
                return(String.Format(format, game.Alive.Count, game.CurLevelName, timespan));
            }
            else
            {
                const string format = "&a{0} %Salive %S(map: {1})";
                return(String.Format(format, game.Alive.Count, game.CurLevelName));
            }
        }
Esempio n. 12
0
        public bool ShouldShowJoinMessage(Level prev)
        {
            ZombieGame zs = Server.zombie;

            if (zs.Running && name.CaselessEq(zs.CurLevelName) &&
                (prev == this || zs.LastLevelName == "" || prev.name.CaselessEq(zs.LastLevelName)))
            {
                return(false);
            }
            if (Server.lava.active && Server.lava.HasMap(name))
            {
                return(false);
            }
            return(true);
        }
Esempio n. 13
0
 static void MessageAll(ZombieGame game, CpeMessageType type, string message)
 {
     if (!game.Running)
     {
         return;
     }
     Player[] online = PlayerInfo.Online.Items;
     foreach (Player p in online)
     {
         if (!p.level.name.CaselessEq(game.CurLevelName))
         {
             continue;
         }
         p.SendCpeMessage(type, message);
     }
 }
Esempio n. 14
0
        static void DoLevelVote(ZombieGame game)
        {
            Server.votingforlevel = true;
            Player[] players = PlayerInfo.Online.Items;
            foreach (Player pl in players)
            {
                if (pl.level != game.CurLevel)
                {
                    continue;
                }
                SendVoteMessage(pl, game);
            }

            VoteCountdown(game);
            Server.votingforlevel = false;
        }
Esempio n. 15
0
        /// <summary> Sends the formatted vote message to the player (using bottom right if supported) </summary>
        internal static void SendVoteMessage(Player p, ZombieGame game)
        {
            const string line1 = "&eLevel vote - type &a1&e, &b2&e or &c3";
            string       line2 = "&a" + game.Candidate1 + "&e, &b"
                                 + game.Candidate2 + "&e, &c" + game.Candidate3;

            if (p.HasCpeExt(CpeExt.MessageTypes))
            {
                p.SendCpeMessage(CpeMessageType.BottomRight3, line1);
                p.SendCpeMessage(CpeMessageType.BottomRight2, line2);
            }
            else
            {
                p.SendMessage(line1);
                p.SendMessage(line2);
            }
        }
Esempio n. 16
0
        static void DoLottery(ZombieGame game)
        {
            string[] players = game.Lottery.Items;
            if (players.Length == 0)
            {
                return;
            }

            // Ensure the players are actually online
            List <Player> online = new List <Player>(players.Length);

            foreach (string name in players)
            {
                Player pl = PlayerInfo.FindExact(name);
                if (pl == null)
                {
                    continue;
                }
                online.Add(pl);
            }
            if (online.Count == 0)
            {
                return;
            }

            int    amount = 10;
            Player winner = online[0];

            if (online.Count == 1)
            {
                winner.SendMessage("Your money was refunded as you were " +
                                   "the only player still in the lottery.");
            }
            else
            {
                Random rand = new Random();
                winner = online[rand.Next(online.Count)];
                amount = 9 * online.Count;
                game.CurLevel.ChatLevel(winner.ColoredName + " %Swon the lottery for &6"
                                        + amount + " " + Server.moneys);
            }
            game.Lottery.Clear();
            winner.SetMoney(winner.money + 10);
        }
Esempio n. 17
0
        /// <summary> Whether block changes made on this level should be
        /// saved to the BlockDB and .lvl files. </summary>
        public bool ShouldSaveChanges()
        {
            if (!saveLevel)
            {
                return(false);
            }
            ZombieGame zs = Server.zombie;

            if (zs.Running && !ZombieGameProps.SaveLevelBlockchanges &&
                (name.CaselessEq(zs.CurLevelName) || name.CaselessEq(zs.LastLevelName)))
            {
                return(false);
            }
            if (Server.lava.active && Server.lava.HasMap(name))
            {
                return(false);
            }
            return(true);
        }
Esempio n. 18
0
        internal static void ChooseNextLevel(ZombieGame game)
        {
            if (game.QueuedLevel != null)
            {
                game.ChangeLevel(game.QueuedLevel); return;
            }
            if (!ZombieGameProps.ChangeLevels)
            {
                return;
            }

            try {
                List <string> maps = GetCandidateLevels();
                if (maps == null)
                {
                    return;
                }
                RemoveRecentLevels(maps, game);
                game.Votes1 = 0; game.Votes2 = 0; game.Votes3 = 0;

                Random r = new Random();
                game.Candidate1 = GetRandomLevel(r, maps);
                game.Candidate2 = GetRandomLevel(r, maps);
                game.Candidate3 = GetRandomLevel(r, maps);

                if (!game.Running || game.Status == ZombieGameStatus.LastRound)
                {
                    return;
                }
                DoLevelVote(game);

                if (!game.Running || game.Status == ZombieGameStatus.LastRound)
                {
                    return;
                }
                MoveToNextLevel(r, maps, game);
            } catch (Exception ex) {
                Server.ErrorLog(ex);
            }
        }
Esempio n. 19
0
        static void GiveMoney(ZombieGame game, Player[] alive)
        {
            Player[] online = PlayerInfo.Online.Items;
            Random   rand   = new Random();

            foreach (Player pl in online)
            {
                if (!pl.level.name.CaselessEq(game.CurLevelName))
                {
                    continue;
                }
                pl.Game.ResetInvisibility();
                int reward = GetMoneyReward(pl, alive, rand);

                if (reward == -1)
                {
                    pl.SendMessage("You may not hide inside a block! No " + Server.moneys + " for you."); reward = 0;
                }
                else if (reward > 0)
                {
                    pl.SendMessage(Colors.gold + "You gained " + reward + " " + Server.moneys);
                }

                pl.SetMoney(pl.money + reward);
                pl.Game.ResetZombieState();
                if (pl.Game.Referee)
                {
                    pl.SendMessage("You gained one " + Server.moneys + " because you're a ref. Would you like a medal as well?");
                    pl.SetMoney(pl.money + 1);
                }

                Entities.GlobalDespawn(pl, false);
                Entities.GlobalSpawn(pl, false);
                TabList.Add(pl, pl, Entities.SelfID);
                HUD.UpdateTertiary(pl);
            }
        }
Esempio n. 20
0
        internal static void UpdateAllSecondary(ZombieGame game)
        {
            string status = FormatSecondary(game);

            MessageAll(game, CpeMessageType.Status2, status);
        }
Esempio n. 21
0
        internal static void UpdateSecondary(ZombieGame game, Player p)
        {
            string status = FormatSecondary(game);

            p.SendCpeMessage(CpeMessageType.Status2, status);
        }
Esempio n. 22
0
        public void Start()
        {
            serverConfig = ConfigElement.GetAll(typeof(Server), typeof(ZombieGame));

            PlayerInfo.players   = PlayerInfo.Online.list;
            Player.players       = PlayerInfo.Online.list;
            Server.levels        = LevelInfo.Loaded.list;
            PlayerBot.playerbots = PlayerBot.Bots.list;
            StartTime            = DateTime.UtcNow;
            StartTimeLocal       = StartTime.ToLocalTime();
            shuttingDown         = false;
            Log("Starting Server");
            try {
                if (File.Exists("Restarter.exe"))
                {
                    File.Delete("Restarter.exe");
                }
            } catch { }
            try {
                if (File.Exists("Restarter.pdb"))
                {
                    File.Delete("Restarter.pdb");
                }
            } catch { }

            CheckFile("MySql.Data.dll");
            CheckFile("System.Data.SQLite.dll");
            CheckFile("sqlite3.dll");
            CheckFile("Newtonsoft.Json.dll");
            CheckFile("LibNoise.dll");

            EnsureFilesExist();
            MoveOutdatedFiles();
            Chat.LoadCustomTokens();

            if (File.Exists("text/emotelist.txt"))
            {
                foreach (string s in File.ReadAllLines("text/emotelist.txt"))
                {
                    Player.emoteList.Add(s);
                }
            }
            else
            {
                File.Create("text/emotelist.txt").Dispose();
            }

            lava      = new LavaSurvival();
            zombie    = new ZombieGame();
            Countdown = new CountdownGame();
            LoadAllSettings();

            InitDatabase();
            Economy.LoadDatabase();
            Server.zombie.CheckTableExists();

            Level[] loaded = LevelInfo.Loaded.Items;
            foreach (Level l in loaded)
            {
                l.Unload();
            }
            ml.Queue(LoadMainLevel);
            Plugin.Load();
            ml.Queue(LoadPlayerLists);
            ml.Queue(LoadAutoloadCommands);
            ml.Queue(LoadGCAccepted);

            ml.Queue(InitTimers);
            ml.Queue(InitRest);
            ml.Queue(InitHeartbeat);
            UpdateStaffList();
        }
Esempio n. 23
0
        public void Start()
        {
            serverConfig = ConfigElement.GetAll(typeof(Server), typeof(ZombieGameProps));
            levelConfig  = ConfigElement.GetAll(typeof(Level));

            #pragma warning disable 0618
            Player.players       = PlayerInfo.Online.list;
            PlayerInfo.players   = PlayerInfo.Online.list;
            Server.levels        = LevelInfo.Loaded.list;
            PlayerBot.playerbots = PlayerBot.Bots.list;
            #pragma warning restore 0618

            StartTime      = DateTime.UtcNow;
            StartTimeLocal = StartTime.ToLocalTime();
            shuttingDown   = false;
            Log("Starting Server");
            try {
                if (File.Exists("Restarter.exe"))
                {
                    File.Delete("Restarter.exe");
                }
            } catch { }
            try {
                if (File.Exists("Restarter.pdb"))
                {
                    File.Delete("Restarter.pdb");
                }
            } catch { }

            CheckFile("MySql.Data.dll");
            CheckFile("System.Data.SQLite.dll");
            CheckFile("sqlite3.dll");
            CheckFile("Newtonsoft.Json.dll");
            CheckFile("LibNoise.dll");

            EnsureFilesExist();
            MoveOutdatedFiles();

            lava      = new LavaSurvival();
            zombie    = new ZombieGame();
            Countdown = new CountdownGame();
            LoadAllSettings();

            InitDatabase();
            Economy.LoadDatabase();
            Server.zombie.CheckTableExists();

            Level[] loaded = LevelInfo.Loaded.Items;
            foreach (Level l in loaded)
            {
                l.Unload();
            }

            Background.QueueOnce(UpgradeTasks.CombineEnvFiles);
            Background.QueueOnce(LoadMainLevel);
            Plugin.Load();
            Background.QueueOnce(UpgradeTasks.UpgradeOldBlacklist);
            Background.QueueOnce(LoadPlayerLists);
            Background.QueueOnce(LoadAutoloadCommands);
            Background.QueueOnce(UpgradeTasks.MovePreviousLevelFiles);
            Background.QueueOnce(UpgradeTasks.UpgradeOldLockdown);

            Background.QueueOnce(SetupSocket);
            Background.QueueOnce(InitTimers);
            Background.QueueOnce(InitRest);
            Background.QueueOnce(InitHeartbeat);

            Devs.Clear();
            Mods.Clear();
            Background.QueueOnce(InitTasks.UpdateStaffList);

            MainScheduler.QueueRepeat(ServerTasks.TemprankExpiry,
                                      null, TimeSpan.FromMinutes(1));
            Background.QueueRepeat(ServerTasks.AutoSave,
                                   1, TimeSpan.FromSeconds(Server.backupInterval));
            Background.QueueRepeat(ServerTasks.BlockUpdates,
                                   null, TimeSpan.FromSeconds(Server.blockInterval));
            Background.QueueRepeat(ThreadSafeCache.DBCache.CleanupTask,
                                   null, TimeSpan.FromMinutes(5));
        }