Exemplo n.º 1
0
        private void timer_Elapsed(object sender, ElapsedEventArgs e)
        {
            timer.Stop();
            try {
                var b = tas.GetBattle();
                if (!autoHost.ComFix(TasSayEventArgs.Default, "silent"))
                {
                    return;
                }

                var  factions = new List <IFaction>(server.GetFactions(account));
                var  sides    = tas.GetBattle().Mod.Sides.ToList();
                bool teamsOk  = true;
                foreach (var user in b.Users.Where(x => !x.IsSpectator && x.SyncStatus != SyncStatuses.Unknown))
                {
                    var info = server.GetPlayerInfo(account, user.name);
                    if (info == null)
                    {
                        tas.ForceSpectator(user.name);
                        tas.Say(TasClient.SayPlace.User, user.name, string.Format("This is online campaign server - http://{0}/ - you must register first /to play here. \n To register say: !register side newpassword (optional planetnname) \n Example: !register core secretpw \n Or: !register arm mynewpassword Alpha Centauri", host), false);
                    }
                    else
                    {
                        int    hisFaction      = factions.IndexOf(factions.Find((f) => f.Name == info.FactionName));
                        string springSideName  = sides.SingleOrDefault(s => s.ToUpper() == info.FactionName.ToUpper());
                        int    springSideIndex = sides.IndexOf(springSideName);

                        // he is in wrong team
                        if (user.AllyNumber != hisFaction)
                        {
                            tas.ForceAlly(user.name, hisFaction);
                            teamsOk = false;
                        }
                        else if (user.Side != springSideIndex)
                        {
                            tas.ForceSide(user.name, springSideIndex);
                        }
                    }
                }
                if (!teamsOk)
                {
                    return;                           // dont proceed to balancing if teams are bing changed
                }
                var grouping = b.Users.Where(u => !u.IsSpectator && u.SyncStatus != SyncStatuses.Unknown).GroupBy(u => u.AllyNumber).OrderBy(g => g.Count()).ToList();
                if (grouping.Count() == 2)
                {
                    if (grouping[1].Count() > 2 * grouping[0].Count())
                    {
                        var newest = b.Users.Where(u => u.AllyNumber == grouping[1].Key && !u.IsSpectator).OrderByDescending(u => u.JoinTime).First();
                        tas.ForceSpectator(newest.name);
                        autoHost.SayBattle(string.Format("There are too many players on that side {0}, sorry you joined last.", newest.name));
                    }
                }
            } catch (Exception ex) {
                autoHost.SayBattle("Problem with PlanetWars:" + ex);
            } finally {
                timer.Start();
            }
        }
Exemplo n.º 2
0
        void tas_BattleUserJoined(object sender, BattleUserEventArgs e1)
        {
            if (e1.BattleID != tas.MyBattleID)
            {
                return;
            }
            string name = e1.UserName;

            string welc = config.Welcome;

            if (!string.IsNullOrEmpty(welc))
            {
                welc = welc.Replace("%1", name);
                welc = welc.Replace("%2", GetUserLevel(name).ToString());
                welc = welc.Replace("%3", MainConfig.SpringieVersion);
                SayBattlePrivate(name, welc);
            }
            if (spring.IsRunning)
            {
                spring.AddUser(e1.UserName, e1.ScriptPassword);
                TimeSpan started = DateTime.Now.Subtract(spring.GameStarted);
                started = new TimeSpan((int)started.TotalHours, started.Minutes, started.Seconds);
                SayBattlePrivate(name, String.Format("THIS GAME IS CURRENTLY IN PROGRESS, PLEASE WAIT UNTIL IT ENDS! Running for {0}", started));
                SayBattlePrivate(name, "If you say !notify, I will message you when the current game ends.");
            }

            if (SpawnConfig == null)
            {
                try {
                    var serv             = GlobalConst.GetSpringieService();
                    PlayerJoinResult ret = serv.AutohostPlayerJoined(tas.MyBattle.GetContext(), tas.ExistingUsers[name].AccountID);
                    if (ret != null)
                    {
                        if (!string.IsNullOrEmpty(ret.PrivateMessage))
                        {
                            tas.Say(SayPlace.User, name, ret.PrivateMessage, false);
                        }
                        if (!string.IsNullOrEmpty(ret.PublicMessage))
                        {
                            tas.Say(SayPlace.Battle, "", ret.PublicMessage, true);
                        }
                        if (ret.ForceSpec)
                        {
                            tas.ForceSpectator(name);
                        }
                        if (ret.Kick)
                        {
                            tas.Kick(name);
                        }
                    }
                } catch (Exception ex) {
                    SayBattle("ServerManage error: " + ex, false);
                }
            }

            if (SpawnConfig != null && SpawnConfig.Owner == name) // owner joins, set him boss
            {
                ComBoss(TasSayEventArgs.Default, new[] { name });
            }
        }
Exemplo n.º 3
0
        private void tas_BattleUserStatusChanged(object sender, TasEventArgs e)
        {
            UserBattleStatus u;
            var b = tas.GetBattle();

            if (b != null && b.ContainsUser(e.ServerParams[0], out u))
            {
                /*if (u.SyncStatus == SyncStatuses.Unsynced) {
                 * SayBattle("kicking " + u.name + " - has incorrect spring or mod version");
                 * tas.Kick(u.name);
                 * }*/


                if (Program.main.config.PlanetWarsEnabled && u.name != tas.UserName)
                {
                    try {
                        var pw       = Program.main.PlanetWars;
                        var info     = pw.GetPlayerInfo(u.name);
                        var factions = pw.GetFactions();
                        if (info == null)
                        {
                            if (!u.IsSpectator)
                            {
                                tas.ForceSpectator(u.name);
                                SayBattle(string.Format("{0} cannot play, (s)he is not registered, register using PlanetWars client or !register command", u.name), false);
                                return;
                            }
                        }
                        else
                        {
                            int hisFaction = factions.IndexOf(factions.Find((f) => f.Name == info.FactionName));
                            if (u.AllyNumber != hisFaction)
                            {
                                tas.ForceAlly(u.name, hisFaction);
                                SayBattle(string.Format("{0} must play in team {1}", u.name, hisFaction + 1), false);
                                return;
                            }
                        }
                    } catch (Exception ex) {
                        SayBattle(string.Format("Warning, PlanetWars problem: {0} ", ex.Message), false);
                    }
                }


                if (KickSpectators && u.IsSpectator && u.name != tas.UserName)
                {
                    SayBattle(config.KickSpectatorText);
                    ComKick(TasSayEventArgs.Default, new[] { u.name });
                }
                HandleAutoLocking();

                int cnt = 0;
                foreach (var ubs in b.Users)
                {
                    if (!ubs.IsSpectator && ubs.IsReady)
                    {
                        cnt++;
                    }
                }
                List <string> usname;
                int           allyno;
                if (!manager.Enabled)
                {
                    if ((cnt == config.MaxPlayers || (autoLock > 0 && autoLock == cnt)) && AllReadyAndSynced(out usname) && AllUniqueTeams(out usname) && BalancedTeams(out allyno))
                    {
                        SayBattle("server is full, starting");
                        Thread.Sleep(1000);                         // just to make sure that other clients update their game info and balance ends
                        ComStart(TasSayEventArgs.Default, new string[] {});
                    }
                }
            }
        }