/************************************************************************/ /* PRIVATE METHODS */ /************************************************************************/ private void updateSpringie() { if (enabled && !spring.IsRunning) { timer.Enabled = false; using (WebClient wc = new WebClient()) { try { string remoteVersion = wc.DownloadString(updateSite + "version.txt").Trim(); if (!string.IsNullOrEmpty(remoteVersion) && remoteVersion != MainConfig.SpringieVersion.Trim()) { string target = Application.ExecutablePath; target = target.Remove(target.LastIndexOf('.')); target += ".upd"; tas.Say(TasClient.SayPlace.Battle, "", "Springie is now downloading new version", true); wc.DownloadFile(updateSite + "springie.upd", target); File.Delete(Application.ExecutablePath + ".bak"); File.Move(Application.ExecutablePath, Application.ExecutablePath + ".bak"); File.Move(target, Application.ExecutablePath); tas.Say(TasClient.SayPlace.Battle, "", "Springie is auto-upgrading to newer version, rejoin please", true); System.Diagnostics.Process.Start(Application.ExecutablePath); Application.Exit(); } } catch (WebException) { } } timer.Enabled = true; } }
private void tas_BattleMapChanged(object sender, TasEventArgs e) { if (config.DisplayMapLink) { SayBattle("maplink: " + linker.GetMapBounceLink(tas.GetBattle().Map.Name)); } Battle b = tas.GetBattle(); string mapName = b.Map.ArchiveName.ToLower(); if (MapBoxes.ContainsKey(mapName)) { for (int i = 0; i < b.Rectangles.Count; ++i) { tas.RemoveBattleRectangle(i); } Dictionary <int, BattleRect> dict = MapBoxes[mapName]; foreach (KeyValuePair <int, BattleRect> v in dict) { tas.AddBattleRectangle(v.Key, v.Value); } } if (Program.main.config.PlanetWarsEnabled) { try { var pw = Program.main.PlanetWars; string name = tas.GetBattle().Map.Name; var mapInfo = pw.GetAttackOptions().Find(m => m.MapName == name); if (mapInfo.StartBoxes != null && mapInfo.StartBoxes.Count > 0) { var rectangles = tas.GetBattle().Rectangles.Count; for (int i = 0; i < rectangles; ++i) { tas.RemoveBattleRectangle(i); } for (int i = 0; i < mapInfo.StartBoxes.Count; ++i) { var mi = mapInfo.StartBoxes[i]; tas.AddBattleRectangle(i, new BattleRect(mi.Left, mi.Top, mi.Right, mi.Bottom)); } } foreach (string command in mapInfo.AutohostCommands) { tas.Say(TasClient.SayPlace.Channel, tas.UserName, command, false); } SayBattle("Planet changed succesfully!"); var notifyList = pw.GetPlayersToNotify(name); notifyList.ForEach(userName => tas.Say(TasClient.SayPlace.User, userName, string.Format("Your planet {0} is under attack! Come defend it!", mapInfo.Name), false)); } catch (Exception ex) { SayBattle(string.Format("Error setting planet starting boxes: {0}", ex.Message)); } } }
public bool Start() { tas.Connected += tas_Connected; tas.LoginDenied += tas_LoginDenied; tas.LoginAccepted += tas_LoginAccepted; using (var db = new ZkDataContext()) { var acc = db.Accounts.FirstOrDefault(x => x.Name == GlobalConst.NightwatchName); if (acc != null) { acc.SetPasswordPlain(config.AccountPassword); acc.IsBot = true; acc.IsZeroKAdmin = true; db.SaveChanges(); } } Auth = new AuthService(tas); adminCommands = new AdminCommands(tas); offlineMessages = new OfflineMessages(tas); playerMover = new PlayerMover(tas); SteamHandler = new NwSteamHandler(tas, new Secrets().GetSteamWebApiKey()); chatRelay = new ChatRelay(tas, new Secrets().GetNightwatchPassword(), new List <string>() { "zkdev", "sy", "moddev" }); PayPalInterface = new PayPalInterface(); PayPalInterface.Error += (e) => { tas.Say(SayPlace.Channel, "zkdev", "PAYMENT ERROR: " + e.ToString(), true); }; PayPalInterface.NewContribution += (c) => { tas.Say(SayPlace.Channel, "zkdev", string.Format("WOOHOO! {0:d} New contribution of {1:F2}€ by {2} - for the jar {3}", c.Time, c.Euros, c.Name.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).FirstOrDefault(), c.ContributionJar.Name), true); if (c.AccountByAccountID == null) { tas.Say(SayPlace.Channel, "zkdev", string.Format("Warning, user account unknown yet, payment remains unassigned. If you know user name, please assign it manually {0}/Contributions", GlobalConst.BaseSiteUrl), true); } else { tas.Say(SayPlace.Channel, "zkdev", string.Format("It is {0} {2}/Users/Detail/{1}", c.AccountByAccountID.Name, c.AccountID, GlobalConst.BaseSiteUrl), true); } }; tas.Connect(config.ServerHost, config.ServerPort); return(true); }
void mapDownloader_DownloadProgressChanged(object sender, TasEventArgs e) { if (tas.IsConnected) { tas.Say(TasClient.SayPlace.Battle, "", e.ServerParams[0] + " " + e.ServerParams[1] + "% done", true); } }
void btnNo_Click(object sender, EventArgs e) { if (isSpad) { tas.Say(SayPlace.Battle, "", "!vote n", false); } else { tas.Say(SayPlace.Battle, "", "!n", false); } }
public void MapChanged() { try { string name = tas.GetBattle().Map.Name; var mapInfo = server.GetAttackOptions(account).Where(m => m.MapName == name).Single(); if (mapInfo.StartBoxes != null && mapInfo.StartBoxes.Count > 0) { int rectangles = tas.GetBattle().Rectangles.Count; for (int i = 0; i < rectangles; ++i) { tas.RemoveBattleRectangle(i); } for (int i = 0; i < mapInfo.StartBoxes.Count; ++i) { var mi = mapInfo.StartBoxes[i]; tas.AddBattleRectangle(i, new BattleRect(mi.Left, mi.Top, mi.Right, mi.Bottom)); } } foreach (var command in mapInfo.AutohostCommands) { tas.Say(TasClient.SayPlace.Channel, tas.UserName, command, false); } autoHost.SayBattle(String.Format("Welcome to {0}! (http://{2}/planet.aspx?name={1})", mapInfo.Name, Uri.EscapeUriString(mapInfo.Name), host)); var notifyList = server.GetPlayersToNotify(account, name, ReminderEvent.OnBattlePreparing); foreach (var userName in notifyList) { tas.Say(TasClient.SayPlace.User, userName, string.Format("Planet {0} is under attack! Join the fight!", mapInfo.Name), false); } } catch (Exception ex) { autoHost.SayBattle(string.Format("Error setting planet starting boxes: {0}", ex)); } }
void AddButtonClick(PwMatchCommand.VoteOption opt, Button but) { PwMatchCommand.VoteOption opt1 = opt; but.Click += (s2, ev) => { if (Program.SpringScanner.HasResource(opt1.Map)) { tas.Say(TasClient.SayPlace.User, GlobalConst.NightwatchName, "!" + opt1.PlanetID, true); } else { tas.Say(TasClient.SayPlace.Channel, tas.MyUser.Faction, string.Format("wants to play {0}, but lacks the map..", opt1.PlanetID), true); } }; }
private void spring_SpringExited(object sender, EventArgs e) { tas.ChangeLock(false); var b = tas.GetBattle(); foreach (var s in toNotify) { if (b != null && b.ContainsUser(s)) { tas.Ring(s); } tas.Say(TasClient.SayPlace.User, s, "** Game just ended, join me! **", false); } toNotify.Clear(); }
protected bool CheckEnd(out int winVote) { int[] sums = new int[options]; foreach (int val in votes) { if (val > 0 && val <= options) { sums[val - 1]++; } } for (int i = 0; i < sums.Length; ++i) { string text = string.Format("option {0} has {1} of {2} votes", i + 1, sums[i], (int)(initialUserCount * ratio) + 1); tas.Say(TasClient.SayPlace.Battle, "", text, true); spring.SayGame(text); if (sums[i] > (int)(initialUserCount * ratio)) { winVote = i + 1; return(true); } } winVote = 0; return(false); }
public void SendLobbyMessage(Account account, string text) { User ex; if (client.ExistingUsers.TryGetValue(account.Name, out ex)) { client.Say(SayPlace.User, account.Name, text, false); } else { var message = new LobbyMessage { SourceLobbyID = client.MyUser != null ? client.MyUser.AccountID : 0, SourceName = client.UserName, Created = DateTime.UtcNow, Message = text, TargetName = account.Name, TargetLobbyID = account.AccountID }; using (var db = new ZkDataContext()) { db.LobbyMessages.InsertOnSubmit(message); db.SubmitChanges(); } } }
public void Apply(TasClient tas, Ladder ladder) { var b = tas.GetBattle(); if (b == null) { return; } var d = b.Details; int mint, maxt; if (ladder != null) { d = ladder.CheckBattleDetails(d, out mint, out maxt); } tas.UpdateBattleDetails(d); if (enableAllUnits) { tas.EnableAllUnits(); } if (disabledUnits.Length > 0) { tas.DisableUnits(UnitInfo.ToStringList(disabledUnits)); } foreach (var s in perform) { tas.Say(TasClient.SayPlace.Battle, "", s, false); } }
private void SendError(string text) { if (tas.IsConnected && tas.IsLoggedIn) { tas.JoinChannel("zkerror"); string history; while (queue.TryDequeue(out history)) { tas.Say(SayPlace.Channel, "zkerror", history, true); } tas.Say(SayPlace.Channel, "zkerror", text, true); } else { queue.Enqueue(text); } }
public static void SayBattle(TasClient tas, Spring spring, string text) { tas.Say(TasClient.SayPlace.Battle, "", text, true); if (spring.IsRunning) { spring.SayGame(text); } }
private void spring_PlayerSaid(object sender, SpringLogEventArgs e) { tas.GameSaid(e.Username, e.Line); if (config.RedirectGameChat && e.Username != tas.UserName && !e.Line.StartsWith("Allies:") && !e.Line.StartsWith("Spectators:")) { tas.Say(TasClient.SayPlace.Battle, "", "[" + e.Username + "]" + e.Line, false); } }
void StopIfCountLow() { if (count < ah.config.MinToJuggle) { starting = false; tas.Say(SayPlace.Battle, "", string.Format("Queue needs {0} more people", ah.config.MinToJuggle - count), true); } }
/************************************************************************/ /* PRIVATE METHODS */ /************************************************************************/ private void SayLines(string text, TasClient tas, TasSayEventArgs e) { string[] lines = text.Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries); foreach (string l in lines) { tas.Say(TasClient.SayPlace.User, e.UserName, l, false); } }
void client_ChannelUserAdded(object sender, ChannelUserInfo e) { Task.Run(async() => { try { var chan = e.Channel.Name; List <LobbyMessage> messages; foreach (var user in e.Users) { using (var db = new ZkDataContext()) { messages = db.LobbyMessages.Where(x => x.TargetName == user.Name && x.Channel == chan).ToList(); db.LobbyMessages.DeleteAllOnSubmit(messages); db.SubmitChanges(); } foreach (var m in messages) { var text = string.Format("!pm|{0}|{1}|{2}|{3}", m.Channel, m.SourceName, m.Created.ToString(CultureInfo.InvariantCulture), m.Message); await client.Say(SayPlace.User, user.Name, text, false); await Task.Delay(MessageDelay); } } } catch (Exception ex) { Trace.TraceError("Error adding user: {0}", ex); } }); }
void client_ChannelUserAdded(object sender, TasEventArgs e) { Task.Factory.StartNew(() => { try { var name = e.ServerParams[1]; var chan = e.ServerParams[0]; List <LobbyMessage> messages; using (var db = new ZkDataContext()) { messages = db.LobbyMessages.Where(x => x.TargetName == name && x.Channel == chan).ToList(); db.LobbyMessages.DeleteAllOnSubmit(messages); db.SubmitChanges(); } foreach (var m in messages) { var text = string.Format("!pm|{0}|{1}|{2}|{3}", m.Channel, m.SourceName, m.Created.ToString(CultureInfo.InvariantCulture), m.Message); client.Say(TasClient.SayPlace.User, name, text, false); Thread.Sleep(MessageDelay); } } catch (Exception ex) { Trace.TraceError("Error adding user: {0}", ex); } }); }
public void ComBan(TasSayEventArgs e, string[] words) { if (words.Length == 0) { ah.Respond(e, "this command needs at least 1 argument - exact user name"); return; } int duration = 0; if (words.Length > 1) { if (!int.TryParse(words[1], out duration)) { ah.Respond(e, "second argument must be a number - ban time in minutes or 0 - forever"); return; } } if (IsBanned(words[0])) { ah.Respond(e, "this user is already banned"); return; } if (duration < 0) { duration = 0; } TimeSpan dur; if (duration == 0) { dur = TimeSpan.FromDays(365 * 1000); } else { dur = TimeSpan.FromMinutes(duration); } var b = new BannedUser(words[0]); b.Duration = dur; b.Reason = Utils.Glue(words, 2); var battle = tas.GetBattle(); UserBattleStatus ubs; if (battle.ContainsUser(b.Name, out ubs)) { if (ubs.ip != IPAddress.None) { b.ipAddresses.Add(ubs.ip.ToString()); } } Items.Add(b); tas.Say(TasClient.SayPlace.Battle, "", b.Name + " banned - " + b.Reason, true); tas.Kick(b.Name); Save(); }
void SpeechEngineSpeechRecognized(object sender, SpeechRecognizedEventArgs e) { var rule = voiceRules.FirstOrDefault(g => e.Result.Grammar.Name == g.Name); if (rule == null) { return; } rule.Aknowledge(speechSynthesizer, e.Result); var table = rule.ToLua(e.Result); client.Say(TasClient.SayPlace.User, client.MyBattle.Founder.Name, "!transmit voice" + table.Replace("\n", ""), false); }
void AutoRespond() { if (client.MyBattle != null && client.MyBattleStatus != null && client.MyBattleStatus.SyncStatus != SyncStatuses.Synced) { var moddl = Program.Downloader.Downloads.FirstOrDefault(x => x.Name == client.MyBattle.ModName); var mapdl = Program.Downloader.Downloads.FirstOrDefault(x => x.Name == client.MyBattle.MapName); if (moddl != null && moddl.IsComplete != true) { client.Say(SayPlace.Battle, "", string.Format("Mod download progress: {0}%, eta: {1}", Math.Round(moddl.TotalProgress), moddl.TimeRemaining), true); } if (mapdl != null && mapdl.IsComplete != true) { client.Say(SayPlace.Battle, "", string.Format("Map download progress: {0}%, eta: {1}", Math.Round(mapdl.TotalProgress), mapdl.TimeRemaining), true); } } }
public static void ProcessResult(RecognitionResult result, SpeechSynthesizer speechSynthesizer, TasClient client) { var grammar = zkGrammars.FirstOrDefault(g => result.Grammar.Name == g.Name); if (grammar == null) { speechSynthesizer.SpeakAsync("What was that?"); } grammar.Aknowledge(speechSynthesizer, result); var table = grammar.ToLua(result); client.Say(TasClient.SayPlace.User, client.MyBattle.Founder.Name, "!transmit voice" + table.Replace("\n", ""), false); }
private void UpdateCa() { if (Program.main.config.CaUpdating == MainConfig.CaUpdateMode.None) { return; } var b = tas.GetBattle(); if (b != null) { spring.Reload(true, false); string selMod = b.Mod.Name; int vers = int.MinValue; foreach (var s in spring.UnitSync.ModList.Keys) { if (s.Contains("Complete Annihilation")) { if ((Program.main.config.CaUpdating == MainConfig.CaUpdateMode.Stable && s.Contains("stable")) || Program.main.config.CaUpdating == MainConfig.CaUpdateMode.Latest) { int nv = ExtractVersionNumber(s); if (nv > vers) { vers = nv; selMod = s; } } } } if (b.Mod.Name != selMod) { tas.Say(TasClient.SayPlace.Battle, "", "Springie is now rehosting to new version of CA - " + selMod, true); Program.main.AutoHost.ComRehost(TasSayEventArgs.Default, new[] { selMod }); } } }
void tas_BattleUserIpRecieved(object sender, TasEventArgs e) { UpdateWithUserIp(e.ServerParams[0], IPAddress.Parse(e.ServerParams[1])); BannedUser b; if (IsBanned(e.ServerParams[0], out b)) { tas.Say(TasClient.SayPlace.Battle, "", e.ServerParams[0] + " (" + b.Name + ") is banned for " + b.Reason, true); tas.Kick(e.ServerParams[0]); } }
public static void Respond(TasClient tas, Spring spring, TasSayEventArgs e, string text) { TasClient.SayPlace p = TasClient.SayPlace.User; bool emote = false; if (e.Place == TasSayEventArgs.Places.Battle) { p = TasClient.SayPlace.Battle; emote = true; } if (e.Place == TasSayEventArgs.Places.Game && spring.IsRunning) { spring.SayGame(text); } else { tas.Say(p, e.UserName, text, emote); } }
void OnLoggedToBothSteamAndTas() { if (tas.MyUser.SteamID == null) { string token = SteamHelper.GetClientAuthTokenHex(); if (!string.IsNullOrEmpty(token)) { tas.Say(SayPlace.User, GlobalConst.NightwatchName, string.Format("!linksteam {0}", token), false); } } foreach (User u in tas.ExistingUsers.Values.ToList().Where(x => x.SteamID != null && friends.Contains(x.SteamID.Value))) { AddFriend(u.Name); } if (Program.Conf.EnableVoiceChat && Environment.OSVersion.Platform != PlatformID.Unix) { Voice.Init(SteamID); } }
protected bool CheckEnd(out int winVote) { int[] sums = new int[options]; foreach (int val in votes) { if (val > 0 && val <= options) { sums[val - 1]++; } } int votesLeft = votes.FindAll(delegate(int t) { return(t == 0); }).Count; bool canDecide = false; int winLimit = (int)(initialUserCount * ratio); for (int i = 0; i < sums.Length; ++i) { string text = string.Format("option {0} has {1} of {2} votes", i + 1, sums[i], winLimit + 1); tas.Say(TasClient.SayPlace.Battle, "", text, true); spring.SayGame(text); if (sums[i] > winLimit) { winVote = i + 1; return(true); } if (sums[i] + votesLeft > winLimit) { canDecide = true; } } winVote = 0; if (!canDecide) { return(true); } else { return(false); } }
private void spring_SpringExited(object sender, EventArgs e) { tas.ChangeLock(false); var b = tas.GetBattle(); foreach (var s in toNotify) { if (b != null && b.ContainsUser(s)) { tas.Ring(s); } tas.Say(TasClient.SayPlace.User, s, "** Game just ended, join me! **", false); } toNotify.Clear(); if (!string.IsNullOrEmpty(delayedModChange)) { string mod = delayedModChange; delayedModChange = null; SayBattle("Updating to latest mod version: " + mod); ComRehost(TasSayEventArgs.Default, new[] { mod }); } }
public static void SayBattle(TasClient tas, Spring spring, string text, bool ingame) { tas.Say(SayPlace.Battle, "", text, true); if (spring.IsRunning && ingame) spring.SayGame(text); }
public MatchMakerQueue(AutoHost ah) { this.ah = ah; ah.Commands.Commands.RemoveAll(x => !allowedCommands.Contains(x.Name)); tas = ah.tas; tas.BattleOpened += (sender, args) => { starting = false; UpdateCount(); StopIfCountLow(); lastCount = count; }; tas.BattleUserJoined += (sender, args) => { if (tas.MyBattleID != args.BattleID) return; tas.Say(SayPlace.BattlePrivate, args.UserName, string.Format("Hi {0}, you are {1}. in the queue", args.UserName, tas.MyBattle.NonSpectatorCount), true); }; tas.BattleUserLeft += (sender, args) => { if (tas.MyBattleID != args.BattleID) return; UpdateCount(); StopIfCountLow(); lastCount = count; }; tas.BattleUserStatusChanged += (sender, args) => { UpdateCount(); if (count != lastCount) // user count changed { if (count > lastCount) // users added { if (count >= ah.config.MinToJuggle) // enough to start { if (!starting) // start fresh { startingFrom = DateTime.Now; scheduledStart = startingFrom.AddSeconds(initialDelay); // start in one minute starting = true; foreach (var user in tas.MyBattle.Users.Keys) tas.Ring(SayPlace.BattlePrivate, user); } else // postpone { DateTime postpone = scheduledStart.AddSeconds(newJoinerDelay); DateTime deadline = startingFrom.AddSeconds(maxDelay); if (postpone > deadline) scheduledStart = deadline; else scheduledStart = postpone; } tas.Say(SayPlace.Battle, "", string.Format("Queue starting in {0}s", Math.Round(scheduledStart.Subtract(DateTime.Now).TotalSeconds)), true); } else // not enough to start tas.Say(SayPlace.Battle, "", string.Format("Queue needs {0} more people", ah.config.MinToJuggle - count), true); } else // users removed StopIfCountLow(); lastCount = count; } }; var timer = new Timer(); timer.Interval = 1000; timer.AutoReset = true; timer.Elapsed += (sender, args) => { if (starting && DateTime.Now >= scheduledStart) { starting = false; var teams = BuildTeams(); if (teams == null) tas.Say(SayPlace.Battle, "", "Queue cannot start yet because of skill differences", true); else { var spectators = tas.MyBattle.Users.Values.Where(x => x.IsSpectator && x.Name != tas.MyBattle.Founder.Name && x.SyncStatus == SyncStatuses.Synced).ToList(); foreach (var t in teams) { CreateSlave(t, spectators); spectators = null; } } } }; timer.Start(); }
public AutoHost(MetaDataCache cache, AhConfig config, int hostingPort, SpawnConfig spawn) { this.config = config; Commands = new CommandList(config); this.cache = cache; SpawnConfig = spawn; this.hostingPort = hostingPort; string version = config.SpringVersion ?? Program.main.Config.SpringVersion ?? GlobalConst.DefaultEngineOverride; springPaths = new SpringPaths(Program.main.paths.GetEngineFolderByVersion(version), Program.main.Config.DataDir); springPaths.SpringVersionChanged += (s, e) => { if (!String.IsNullOrEmpty(requestedEngineChange) && requestedEngineChange == springPaths.SpringVersion) { config.SpringVersion = requestedEngineChange; springPaths.SetEnginePath(Program.main.paths.GetEngineFolderByVersion(requestedEngineChange)); requestedEngineChange = null; tas.Say(SayPlace.Battle, "", "rehosting to engine version " + springPaths.SpringVersion, true); ComRehost(TasSayEventArgs.Default, new string[] { }); } }; spring = new Spring(springPaths) { UseDedicatedServer = true }; bool isManaged = SpawnConfig == null && config.Mode != AutohostMode.None; tas = new TasClient(MainConfig.SpringieVersion, isManaged ? Login.ClientTypes.SpringieManaged : Login.ClientTypes.Springie, Program.main.Config.IpOverride); pollTimer = new Timer(PollTimeout * 1000); pollTimer.Enabled = false; pollTimer.AutoReset = false; pollTimer.Elapsed += pollTimer_Elapsed; spring.SpringExited += spring_SpringExited; spring.GameOver += spring_GameOver; spring.SpringExited += spring_SpringExited; spring.SpringStarted += spring_SpringStarted; spring.PlayerSaid += spring_PlayerSaid; spring.BattleStarted += spring_BattleStarted; tas.BattleUserLeft += tas_BattleUserLeft; tas.UserStatusChanged += tas_UserStatusChanged; tas.BattleUserJoined += tas_BattleUserJoined; tas.MyBattleMapChanged += tas_MyBattleMapChanged; tas.BattleOpened += tas_BattleOpened; tas.UserAdded += (o, u) => { if (u.Name == GetAccountName()) { OpenBattleRoom(null, null); } }; tas.RegistrationDenied += (s, e) => { Trace.TraceWarning("Registration denied: {0} {1}", e.ResultCode.Description(), e.Reason); CloneNumber++; tas.Login(GetAccountName(), config.Password); }; tas.RegistrationAccepted += (s, e) => tas.Login(GetAccountName(), config.Password); tas.ConnectionLost += tas_ConnectionLost; tas.Connected += tas_Connected; tas.LoginDenied += tas_LoginDenied; tas.LoginAccepted += tas_LoginAccepted; tas.Said += tas_Said; tas.MyBattleStarted += tas_MyStatusChangedToInGame; linkSpringieClient = new ResourceLinkSpringieClient(this); // queue autohost if (config != null && config.MinToJuggle != null && SpawnConfig == null) { queue = new MatchMakerQueue(this); } Program.main.Downloader.PackagesChanged += Downloader_PackagesChanged; timer = new Timer(15000); timer.Elapsed += (s, e) => { try { timer.Stop(); timerTick++; // auto update engine branch if (!String.IsNullOrEmpty(config.AutoUpdateSpringBranch) && timerTick % 4 == 0) { CheckEngineBranch(); } // auto verify pw map if (!spring.IsRunning && config.Mode != AutohostMode.None) { if (SpawnConfig == null && config.Mode == AutohostMode.Planetwars) { ServerVerifyMap(false); } } // auto start split vote if (!spring.IsRunning && config.SplitBiggerThan != null && tas.MyBattle != null && config.SplitBiggerThan < tas.MyBattle.NonSpectatorCount) { if (DateTime.Now.Subtract(spring.GameExited).TotalSeconds >= GameExitSplitDelay) { ComSplitPlayers(TasSayEventArgs.Default, new string[] {}); } /* * int cnt = tas.MyBattle.NonSpectatorCount; * if (cnt > lastSplitPlayersCountCalled && cnt%2 == 0) { * StartVote(new VoteSplitPlayers(tas, spring, this), TasSayEventArgs.Default, new string[] { }); * lastSplitPlayersCountCalled = cnt; * }*/ } // auto rehost to latest mod version if (!string.IsNullOrEmpty(config.AutoUpdateRapidTag) && SpawnConfig == null) { UpdateRapidMod(config.AutoUpdateRapidTag); } } catch (Exception ex) { Trace.TraceError(ex.ToString()); } finally { timer.Start(); } }; timer.Start(); }
public static void Respond(TasClient tas, Spring spring, TasSayEventArgs e, string text) { var p = SayPlace.User; bool emote = false; if (e.Place == SayPlace.Battle) { p = SayPlace.BattlePrivate; emote = true; } if (e.Place == SayPlace.Game && spring.IsRunning) spring.SayGame(text); else tas.Say(p, e.UserName, text, emote); }
void tas_Said(object sender, TasSayEventArgs e) { if (e.UserName.Contains("Nightwatch")) { return; } if (e.Place == SayPlace.User) { if (e.Text.StartsWith("!move")) { var db = new ZkDataContext(); var acc = db.Accounts.Find(tas.ExistingUsers[e.UserName].AccountID); if (acc.IsZeroKAdmin) { var parts = e.Text.Split(' '); if (parts.Length != 3) { tas.Say(SayPlace.User, e.UserName, "!move [from] [to]", false); } else { var from = tas.ExistingBattles.Values.FirstOrDefault(x => x.Founder.Name == parts[1]); var to = tas.ExistingBattles.Values.FirstOrDefault(x => x.Founder.Name == parts[2]); if (from != null && to != null) { foreach (var b in from.Users.Values) { if (!b.LobbyUser.IsInGame && b.Name != from.Founder.Name) { tas.ForceJoinBattle(b.Name, to.BattleID); } } } else { tas.Say(SayPlace.User, e.UserName, "Not a valid battle host name", false); } } } } // split players evenly into two games by median elo -> expand to specify proportion to shunt? // TODO: split players and specs separately else if (e.Text.StartsWith("!splitplayers")) { var db = new ZkDataContext(); var acc = db.Accounts.Find(tas.ExistingUsers[e.UserName].AccountID); if (acc.IsZeroKAdmin) { var parts = e.Text.Split(' '); if (parts.Length != 3) { tas.Say(SayPlace.User, e.UserName, "!splitplayers [from] [to]", false); } else { var from = tas.ExistingBattles.Values.FirstOrDefault(x => x.Founder.Name == parts[1]); var to = tas.ExistingBattles.Values.FirstOrDefault(x => x.Founder.Name == parts[2]); if (from != null && to != null) { var list = from.Users.Values.Where(x => !x.LobbyUser.IsInGame && x.Name != from.Founder.Name && !x.IsSpectator).OrderBy(x => x.LobbyUser.EffectiveElo); var toMove = list.Take(list.Count() / 2); foreach (var b in toMove) { tas.ForceJoinBattle(b.Name, to.BattleID); } } else { tas.Say(SayPlace.User, e.UserName, "Not a valid battle host name", false); } } } } } }