public void autoSave() { bool firstrun = true; DateTime lastsave = new DateTime(); ISender console = new ConsoleSender(); List <string> empty = new List <string>(); ArgumentList arguments = new ArgumentList(); while (isEnabled) { if (autosaveenabled) { if (!firstrun && (DateTime.UtcNow > lastsave.AddMinutes(autosaveinterval))) { if (!arguments.Contains("automap")) { arguments.Add("automap"); } MapCommand(console, arguments); lastsave = DateTime.UtcNow; } if (firstrun) { firstrun = false; lastsave = DateTime.UtcNow; } } Thread.Sleep(1000); } }
// bans if ban = true, unbans if ban = false public static void ban(String name, String bannedby, bool ban) { Player player = FindPlayer(name); Sender sender = new ConsoleSender(); ArgumentList command = new ArgumentList(); command.Add(name); if (player != null) { if (player.Name != null) { if (ban) { Commands.Ban(sender, command); server.sendToOneClient(Packet.PLAYER_BANNED(name), bannedby); } } } else { if (ban) server.sendToOneClient(Packet.PLAYER_NOT_FOUND_ERROR(), bannedby); else { Commands.UnBan(sender, command); server.sendToOneClient(Packet.PLAYER_UNBANNED(name), bannedby); } } }
/// <summary> /// Handles a chat message /// </summary> /// <param name="playerId">Id of chat sender</param> /// <param name="playerName">Name of chat sender</param> /// <param name="message">Chat message sent</param> protected void OnChatMessage(int source, List <object> args, string rawCommand) { // Split command into arguments, extract name, and modify to exclude name var new_args = rawCommand.Split(' ').ToList(); var name = new_args.First().ToLowerInvariant(); new_args = new_args.Skip(1).ToList(); //List<string> new_args = args.Select(m => m.ToString()).Skip(1).ToList(); var command = this.commands.FirstOrDefault(c => c.Name.ToLowerInvariant() == name); if (command == null) { return; } ICommandSender sender; if (source > 0) { sender = MCoreServer.Instance.GetMPlayerBynetId(source); } else { sender = new ConsoleSender(); } command.Execute(new CommandContext(command, sender, new_args)); }
public void Execute(User executor, List <string> arguments) { if (executor.Name != Instance.Config.Admin) { return; } Thread.Sleep(800); if (arguments.Count > 0) { if (arguments[0] == "cur") { Instance.SoundOutBackground.Stop(); ConsoleSender.SendCommand($"Skipped a song, {Instance.BackGroundQueue.PlayList.Count} in queue", ConsoleSender.Command.Chat); return; } if (arguments[0] == "que") { Instance.BackGroundQueue.PlayList = new ConcurrentQueue <Instance.Song>(); ConsoleSender.SendCommand("Done, now playlist is clear", ConsoleSender.Command.Chat); return; } } Instance.SoundOutBackground.Stop(); Instance.BackGroundQueue.PlayList = new ConcurrentQueue <Instance.Song>(); ConsoleSender.SendCommand("BackGroundQueue is now clear", ConsoleSender.Command.Chat); }
public static bool IsBlocked(string user) { if (user == Instance.Config.Admin) { return(false); } if (_spammerlist.Any(n => n.nickname == user)) { var spamuser = _spammerlist.First(n => n.nickname == user); if ((DateTime.Now - spamuser.bannedtime).TotalMinutes < 5 * spamuser.bantimes) { return(true); } if (spamuser.requests.IsOverflowed(Instance.Config.MaximumParsesPerMin)) { spamuser.bannedtime = DateTime.Now; spamuser.bantimes++; var bantime = (spamuser.bannedtime.AddMinutes(5 * spamuser.bantimes) - DateTime.Now).TotalMinutes .ToString("###"); ConsoleSender.SendCommand($"Now {user} is banned for flood. Wait {bantime}", ConsoleSender.Command.Chat); Logger.Write(Logger.Status.Info, $"User {user} got blocked for too frequent messages."); return(true); } } return(false); }
public void Execute(User executor, List <string> arguments) { ConsoleSender.SendCommand("status", ConsoleSender.Command.Raw); Thread.Sleep(2000); if (Instance.SoundOutBackground.PlaybackState == PlaybackState.Playing) { if (MusicId != Instance.SoundOutBackground.WaveSource.Length) { VoteUsers.Clear(); MusicId = Instance.SoundOutBackground.WaveSource.Length; VoteUsers.Add(executor.Name); var pl = PlayersCount < 4 ? 1 : PlayersCount / 2; ConsoleSender.SendCommand( $"{executor.Name} voted to skip this song. { VoteUsers.Count}/{pl}", ConsoleSender.Command.Chat); if (VoteUsers.Count >= PlayersCount / 4) { Instance.SoundOutBackground.Stop(); ConsoleSender.SendCommand($"This song has been skipped", ConsoleSender.Command.Chat); } } else { if (VoteUsers.Count >= PlayersCount / 4) { Instance.SoundOutBackground.Stop(); ConsoleSender.SendCommand($"This song has been skipped", ConsoleSender.Command.Chat); } if (VoteUsers.Contains(executor.Name)) { ConsoleSender.SendCommand( $"{executor.Name} already voted to skip this song. { VoteUsers.Count}/{PlayersCount}", ConsoleSender.Command.Chat); } else { ConsoleSender.SendCommand( $"{executor.Name} voted to skip this song. {VoteUsers.Count}/{PlayersCount}", ConsoleSender.Command.Chat); if (VoteUsers.Count >= PlayersCount) { Instance.SoundOutBackground.Stop(); ConsoleSender.SendCommand($"This song has been skipped", ConsoleSender.Command.Chat); } } } } else { ConsoleSender.SendCommand($"{executor.Name}, the queue is empty.", ConsoleSender.Command.Chat); } }
/// <summary> /// Parses new console command /// </summary> /// <param name="line">Command to parse</param> /// <param name="sender">Sending entity</param> public void ParseConsoleCommand(string line, ConsoleSender sender = null) { line = line.Trim(); if (sender == null) { sender = consoleSender; } ParseAndProcess(sender, line); }
public static void LoadPlugins() { ProgramLog.Log(Languages.Startup_LoadingPlugins); Terraria_Server.Plugins.PluginManager.Initialize(Statics.PluginPath, Statics.LibrariesPath); var ctx = new HookContext() { Sender = ConsoleSender = new ConsoleSender() }; var eArgs = new HookArgs.ServerStateChange() { ServerChangeState = ServerState.INITIALIZING }; HookPoints.ServerStateChange.Invoke(ref ctx, ref eArgs); PluginManager.LoadPlugins(); ProgramLog.Log(Languages.Startup_PluginsLoaded + ' ' + PluginManager.PluginCount); }
public static System.Drawing.Bitmap map(int x1, int y1, int x2, int y2) { if (MapPlugin.initialized && !MapPlugin.instance.isMapping) { ISender console = new ConsoleSender(); ArgumentList coords = new ArgumentList(); coords.Add("api-call"); coords.Add("-x1=" + x1); coords.Add("-x2=" + x2); coords.Add("-y1=" + y1); coords.Add("-y2=" + y2); MapPlugin.instance.MapCommand(console, coords); while (MapPlugin.instance.isMapping) { ; } } return(MapPlugin.bmp); }
public void Execute(User executor, List <string> arguments) { var possiblecommands = Instance.Commands.GetCommands().Where(n => n.Status == CommandManager.Status.Enabled) .ToList(); if (possiblecommands.Count > 0) { if (arguments.Count > 0) { ushort page; if (ushort.TryParse(arguments[0], out page)) { if (page <= possiblecommands.Count - 1 && page != 0) { ConsoleSender.SendCommand($"-> !{possiblecommands[page-1].Name} | {possiblecommands[page-1].Help}", ConsoleSender.Command.Chat); ConsoleSender.SendCommand($"Page {page} / {possiblecommands.Count-1}", ConsoleSender.Command.Chat); } else { ConsoleSender.SendCommand($"Page is out of range", ConsoleSender.Command.Chat); } } else { ConsoleSender.SendCommand($"Can't parse page number", ConsoleSender.Command.Chat); } } else { ConsoleSender.SendCommand($"There are {possiblecommands.Count-1} possible commands to display", ConsoleSender.Command.Chat); ConsoleSender.SendCommand($"Use !{this.Name} {{page}} to display commands", ConsoleSender.Command.Chat); } } else { ConsoleSender.SendCommand("0 possible commands to display", ConsoleSender.Command.Chat); } }
public void Execute(User executor, List <string> arguments) { Thread.Sleep(1600); if (Instance.BackGroundQueue.PlayList.Count == 0) { ConsoleSender.SendCommand("Queue is currently empty, request some stuff with !request", ConsoleSender.Command.Chat); } else { Array TempPlaylist = Instance.BackGroundQueue.PlayList.ToArray(); ConsoleSender.SendCommand("Current queue:", ConsoleSender.Command.Chat); foreach (Instance.Song song in TempPlaylist) { ConsoleSender.SendCommand($"{song.Title} requested by {song.RequestedBy.Name}", ConsoleSender.Command.Chat); } } if (Instance.SoundOutBackground.PlaybackState == PlaybackState.Playing) { ConsoleSender.SendCommand($"Now playing: {Instance.CurrentTitle} requested by {Instance.CurrentSongFrom}", ConsoleSender.Command.Chat); } }
static void Main(string[] args) { List <Person> contactBook = new List <Person>(); contactBook.Add(new Person("Oleg", "Vysotskiy", "*****@*****.**", "0672200521")); contactBook.Add(new Person("Lera", "Vysotska", "*****@*****.**", "0672200521")); var email = from em in contactBook select em.Email; MailAddress from = new MailAddress("*****@*****.**", "Oleg"); SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587); smtp.Credentials = new NetworkCredential("vysotskiyod", "19051985"); smtp.EnableSsl = true; foreach (var i in email) { ISender sender = new ConsoleSender(); sender.Send("Some message " + i); var sender2 = new EmailSender.EmailSender(); MailAddress to = new MailAddress(i); MailMessage m = new MailMessage(from, to); m.Subject = "Тест"; sender2.SetEmailProviderInfo(m, smtp); string wrMess; wrMess = Console.ReadLine(); sender2.Send(wrMess); FileWriter.FileWriter fwm = new FileWriter.FileWriter(); fwm.Send(wrMess); } Console.ReadLine(); }
public void Execute(User executor, List <string> arguments) { if (executor.Name != Instance.Config.Admin) { ConsoleSender.SendCommand("Current volume: " + Instance.Config.BaseVolume + "%", ConsoleSender.Command.Chat); return; } Thread.Sleep(1600); if (arguments.Count <= 0) { ConsoleSender.SendCommand("Usage: !volume [percentage]", ConsoleSender.Command.Chat); ConsoleSender.SendCommand("Current volume: " + Instance.Config.BaseVolume + "%", ConsoleSender.Command.Chat); return; } int VolumePercent; try { VolumePercent = Int32.Parse(arguments[0]); } catch (Exception) { ConsoleSender.SendCommand("Invalid argument", ConsoleSender.Command.Chat); return; } if (VolumePercent > 100 || VolumePercent < 0) { ConsoleSender.SendCommand("Invalid percentage", ConsoleSender.Command.Chat); return; } Instance.Config.BaseVolume = VolumePercent; ConsoleSender.SendCommand("Music volume has been set to " + Instance.Config.BaseVolume + "%", ConsoleSender.Command.Chat); }
private static void Play() { while (true) { // BackGround if (Instance.SoundOutBackground.PlaybackState == PlaybackState.Playing) { Instance.SoundOutBackground.Volume = Instance.SoundOutForeground.PlaybackState == PlaybackState.Playing ? 0.25f : 0.5f; if (Instance.SoundOutBackground.WaveSource != null) { if (Instance.SoundOutBackground.WaveSource.Length - Instance.SoundOutBackground.WaveSource.Position < Instance.SoundOutBackground.WaveSource.WaveFormat.BytesPerSecond / 100) { Instance.SoundOutBackground.Stop(); } } } if (Instance.BackGroundQueue.GetQueueLenght() > 0) { if (Instance.SoundOutBackground.PlaybackState == PlaybackState.Stopped) { Instance.Song s; if (Instance.BackGroundQueue.PlayList.TryDequeue(out s)) { Task.Run( () => { Thread.Sleep(800); ConsoleSender.SendCommand( string.Format(Localization.Localization.CORE_PLAYING_TITLE_FROM, s.Title, s.RequestedBy.Name), ConsoleSender.Command.Chat); Player(s.Source, Instance.SoundOutBackground); Instance.SoundOutBackground.Volume = 0.10f; }); } } } // First Placed! if (Instance.SoundOutForeground.PlaybackState == PlaybackState.Playing) { if (Instance.SoundOutForeground.WaveSource != null) { if (Instance.SoundOutForeground.WaveSource.Length - Instance.SoundOutForeground.WaveSource.Position < Instance.SoundOutForeground.WaveSource.WaveFormat.BytesPerSecond / 1000) { Instance.SoundOutForeground.Stop(); } } } if (Instance.QueueForeGround.Count > 0) { if (Instance.SoundOutForeground.PlaybackState == PlaybackState.Stopped) { IWaveSource s; if (Instance.QueueForeGround.TryDequeue(out s)) { Task.Run(() => { Player(s, Instance.SoundOutForeground); }); } } } Thread.Sleep(60); } }
public static bool CloseDoor(Func<Int32, Int32, ITile> TileRefs, ISandbox sandbox, int x, int y, bool forced, ISender sender) { if (TileRefs == null) TileRefs = TileCollection.ITileAt; if (sender == null) sender = new ConsoleSender(); if (Program.properties.NPCDoorOpenCancel && sender is NPC) return false; var ctx = new HookContext { Sender = sender, }; var args = new HookArgs.DoorStateChanged { X = x, Y = y, Direction = 1, Open = false, }; HookPoints.DoorStateChanged.Invoke(ref ctx, ref args); if (ctx.CheckForKick()) return false; if (ctx.Result == HookResult.IGNORE) return false; if (ctx.Result == HookResult.RECTIFY) { NetMessage.SendData(19, -1, -1, "", 0, (float)x, (float)y, 0); //Inform the client of the update return false; } int num = 0; int num2 = x; int num3 = y; int frameX = (int)TileRefs(x, y).FrameX; int frameY = (int)TileRefs(x, y).FrameY; if (frameX == 0) { num2 = x; num = 1; } else if (frameX == 18) { num2 = x - 1; num = 1; } else if (frameX == 36) { num2 = x + 1; num = -1; } else if (frameX == 54) { num2 = x; num = -1; } if (frameY == 0) { num3 = y; } else if (frameY == 18) { num3 = y - 1; } else if (frameY == 36) { num3 = y - 2; } int num4 = num2; if (num == -1) { num4 = num2 - 1; } if (!forced) { for (int k = num3; k < num3 + 3; k++) { if (!Collision.EmptyTile(num2, k, true)) return false; } } for (int l = num4; l < num4 + 2; l++) { for (int m = num3; m < num3 + 3; m++) { if (l == num2) { TileRefs(l, m).SetType(10); TileRefs(l, m).SetFrameX((short)(genRand.Next(3) * 18)); } else { TileRefs(l, m).SetActive(false); } } } /* 1.1 */ int num5 = num2; for (int n = num3; n <= num3 + 2; n++) { if (numNoWire < MAX_WIRE - 1) { noWireX[numNoWire] = num5; noWireY[numNoWire] = n; numNoWire++; } } for (int n = num2 - 1; n <= num2 + 1; n++) { for (int num6 = num3 - 1; num5 <= num3 + 2; num5++) { TileFrame(TileRefs, sandbox, n, num5, false, false); } } return true; }
public static bool OpenDoor(int i, int j, int direction, bool state = false, DoorOpener opender = DoorOpener.SERVER, Sender sender = null) { if (sender == null) { ConsoleSender cSender = new ConsoleSender(Program.server); cSender.ConsoleCommand.Sender = new Sender(); sender = cSender; } DoorStateChangeEvent doorEvent = new DoorStateChangeEvent(); doorEvent.Sender = sender; doorEvent.setVector(new Vector2(i, j)); doorEvent.setDirection(direction); doorEvent.setOpener(opender); doorEvent.setOpened(state); Program.server.getPluginManager().processHook(Hooks.DOOR_STATECHANGE, doorEvent); if (doorEvent.Cancelled) { return true; } int num = 0; if (Main.tile[i, j - 1] == null) { Main.tile[i, j - 1] = new Tile(); } if (Main.tile[i, j - 2] == null) { Main.tile[i, j - 2] = new Tile(); } if (Main.tile[i, j + 1] == null) { Main.tile[i, j + 1] = new Tile(); } if (Main.tile[i, j] == null) { Main.tile[i, j] = new Tile(); } if (Main.tile[i, j - 1].frameY == 0 && Main.tile[i, j - 1].type == Main.tile[i, j].type) { num = j - 1; } else { if (Main.tile[i, j - 2].frameY == 0 && Main.tile[i, j - 2].type == Main.tile[i, j].type) { num = j - 2; } else { if (Main.tile[i, j + 1].frameY == 0 && Main.tile[i, j + 1].type == Main.tile[i, j].type) { num = j + 1; } else { num = j; } } } int num2 = i; short num3 = 0; int num4; if (direction == -1) { num2 = i - 1; num3 = 36; num4 = i - 1; } else { num2 = i; num4 = i + 1; } bool flag = true; for (int k = num; k < num + 3; k++) { if (Main.tile[num4, k] == null) { Main.tile[num4, k] = new Tile(); } if (Main.tile[num4, k].Active) { if (Main.tile[num4, k].type != 3 && Main.tile[num4, k].type != 24 && Main.tile[num4, k].type != 52 && Main.tile[num4, k].type != 61 && Main.tile[num4, k].type != 62 && Main.tile[num4, k].type != 69 && Main.tile[num4, k].type != 71 && Main.tile[num4, k].type != 73 && Main.tile[num4, k].type != 74) { flag = false; break; } WorldGen.KillTile(num4, k, false, false, false); } } if (flag) { Main.tile[num2, num].Active = true; Main.tile[num2, num].type = 11; Main.tile[num2, num].frameY = 0; Main.tile[num2, num].frameX = num3; if (Main.tile[num2 + 1, num] == null) { Main.tile[num2 + 1, num] = new Tile(); } Main.tile[num2 + 1, num].Active = true; Main.tile[num2 + 1, num].type = 11; Main.tile[num2 + 1, num].frameY = 0; Main.tile[num2 + 1, num].frameX = (short)(num3 + 18); if (Main.tile[num2, num + 1] == null) { Main.tile[num2, num + 1] = new Tile(); } Main.tile[num2, num + 1].Active = true; Main.tile[num2, num + 1].type = 11; Main.tile[num2, num + 1].frameY = 18; Main.tile[num2, num + 1].frameX = num3; if (Main.tile[num2 + 1, num + 1] == null) { Main.tile[num2 + 1, num + 1] = new Tile(); } Main.tile[num2 + 1, num + 1].Active = true; Main.tile[num2 + 1, num + 1].type = 11; Main.tile[num2 + 1, num + 1].frameY = 18; Main.tile[num2 + 1, num + 1].frameX = (short)(num3 + 18); if (Main.tile[num2, num + 2] == null) { Main.tile[num2, num + 2] = new Tile(); } Main.tile[num2, num + 2].Active = true; Main.tile[num2, num + 2].type = 11; Main.tile[num2, num + 2].frameY = 36; Main.tile[num2, num + 2].frameX = num3; if (Main.tile[num2 + 1, num + 2] == null) { Main.tile[num2 + 1, num + 2] = new Tile(); } Main.tile[num2 + 1, num + 2].Active = true; Main.tile[num2 + 1, num + 2].type = 11; Main.tile[num2 + 1, num + 2].frameY = 36; Main.tile[num2 + 1, num + 2].frameX = (short)(num3 + 18); for (int l = num2 - 1; l <= num2 + 2; l++) { for (int m = num - 1; m <= num + 2; m++) { WorldGen.TileFrame(l, m, false, false); } } } return flag; }
public static bool CloseDoor(int i, int j, bool forced = false, DoorOpener opener = DoorOpener.SERVER, Sender sender = null) { if (sender == null) { ConsoleSender cSender = new ConsoleSender(Program.server); cSender.ConsoleCommand.Sender = new Sender(); sender = cSender; } DoorStateChangeEvent doorEvent = new DoorStateChangeEvent(); doorEvent.Sender = sender; doorEvent.setVector(new Vector2(i, j)); doorEvent.setDirection(1); doorEvent.setOpener(opener); doorEvent.setOpened(forced); Program.server.getPluginManager().processHook(Hooks.DOOR_STATECHANGE, doorEvent); if (doorEvent.Cancelled) { return true; } int num = 0; int num2 = i; int num3 = j; if (Main.tile[i, j] == null) { Main.tile[i, j] = new Tile(); } int frameX = (int)Main.tile[i, j].frameX; int frameY = (int)Main.tile[i, j].frameY; if (frameX == 0) { num2 = i; num = 1; } else { if (frameX == 18) { num2 = i - 1; num = 1; } else { if (frameX == 36) { num2 = i + 1; num = -1; } else { if (frameX == 54) { num2 = i; num = -1; } } } } if (frameY == 0) { num3 = j; } else { if (frameY == 18) { num3 = j - 1; } else { if (frameY == 36) { num3 = j - 2; } } } int num4 = num2; if (num == -1) { num4 = num2 - 1; } if (!forced) { for (int k = num3; k < num3 + 3; k++) { if (!Collision.EmptyTile(num2, k, true)) { return false; } } } for (int l = num4; l < num4 + 2; l++) { for (int m = num3; m < num3 + 3; m++) { if (l == num2) { if (Main.tile[l, m] == null) { Main.tile[l, m] = new Tile(); } Main.tile[l, m].type = 10; Main.tile[l, m].frameX = (short)(WorldGen.genRand.Next(3) * 18); } else { if (Main.tile[l, m] == null) { Main.tile[l, m] = new Tile(); } Main.tile[l, m].Active = false; } } } for (int n = num2 - 1; n <= num2 + 1; n++) { for (int num5 = num3 - 1; num5 <= num3 + 2; num5++) { WorldGen.TileFrame(n, num5, false, false); } } return true; }
public void Execute(User executor, List <string> arguments) { if (arguments.Count <= 0) { return; } var url = arguments[0]; var regex = new Regex(@"^(https?:\/\/)?(www.)?soundcloud\.com\/[\w\-\.]+(\/)+[\w\-\.]+/?$"); if (regex.Match(url).Success) { try { using (var web = new WebClient()) { var info = web.DownloadString( "http://api.soundcloud.com/resolve.json?url=" + url + "&client_id=" + clientID + "&app_version=" + AppID); var b = JsonConvert.DeserializeObject <Track>(info); if (b.streamable && b.kind == "track") { var durl = web.DownloadString( "https://api.soundcloud.com/tracks/" + b.id + "/streams?client_id=" + clientID + "&app_version=" + AppID); var urls = JsonConvert.DeserializeObject <DownloadURL>(durl); if (urls.http_mp3_128_url != null) { if (!Instance.IsMuted) { ConsoleSender.SendCommand( $"{b.title} was added to the queue", ConsoleSender.Command.Chat); } Instance.BackGroundQueue.PlayList.Enqueue( new Instance.Song( b.title, new Mp3MediafoundationDecoder(urls.http_mp3_128_url).ToMono(), executor)); return; } } } } catch (Exception) { return; } } var youtube = new Regex(@"youtube\..+?/watch.*?v=(.*?)(?:&|/|$)"); var shortregex = new Regex(@"youtu\.be/(.*?)(?:\?|&|/|$)"); if (youtube.Match(url).Success || shortregex.Match(url).Success) { var id = YoutubeClient.ParseVideoId(url); var client = new YoutubeClient(); var streamInfoSet = client.GetVideoMediaStreamInfosAsync(id); var streamInfo = streamInfoSet.Result.Audio.FirstOrDefault(n => n.AudioEncoding == AudioEncoding.Aac); if (streamInfo == null) { return; } var ext = streamInfo.Url; var title = client.GetVideoAsync(id).Result.Title; if (!Instance.IsMuted) { ConsoleSender.SendCommand($"{title} was added to the queue", ConsoleSender.Command.Chat); } Instance.BackGroundQueue.PlayList.Enqueue(new Instance.Song(title, new AacDecoder(ext).ToMono(), executor)); } else { if (arguments.Count >= 1) { var text = arguments.Aggregate(" ", (current, argument) => current + " " + argument); var client = new YoutubeClient(); var vids = client.SearchVideosAsync(text, 1).Result; if (vids.Count > 0) { var streamInfoSet = client.GetVideoMediaStreamInfosAsync(vids[0].Id); var streamInfo = streamInfoSet.Result.Audio.FirstOrDefault(n => n.AudioEncoding == AudioEncoding.Aac); if (streamInfo == null) { return; } var ext = streamInfo.Url; var title = client.GetVideoAsync(vids[0].Id).Result.Title; if (!Instance.IsMuted) { ConsoleSender.SendCommand($"{title} was added to the queue", ConsoleSender.Command.Chat); } Instance.BackGroundQueue.PlayList.Enqueue(new Instance.Song(title, new AacDecoder(ext).ToMono(), executor)); } } } }
/*private static string _logPath; * private static string logPath * { * get * { * if (string.IsNullOrEmpty(_logPath)) * _logPath = GetString(loggerPath); * if(string.IsNullOrEmpty(_logPath)) * { * _logPath = Path.Combine(Application.dataPath, defaultLogFilePath); * SetString(loggerPath, _logPath); * } * return _logPath; * } * }*/ public static void HookLog(string path) { //UnityEngine.Debug.Log("Hooking debug!"); Application.logMessageReceived += LogToFile; sender = new ConsoleSender(path); }
public static void give(String from, String target, String item, String amount) { Sender sender = new ConsoleSender(); ArgumentList command = new ArgumentList(); command.Add(target); command.Add(amount); command.Add(item); Commands.Give(sender, command); server.sendToOneClient(Packet.GAVE_ITEM(item, amount), from); }
public static bool OpenDoor(int x, int y, int direction, bool state = false, DoorOpener opener = DoorOpener.SERVER, ISender sender = null) { if (sender == null) { ConsoleSender cSender = new ConsoleSender(Program.server); cSender.ConsoleCommand.Sender = new Sender(); sender = cSender; } DoorStateChangeEvent doorEvent = new DoorStateChangeEvent(); doorEvent.Sender = sender; doorEvent.X = x; doorEvent.Y = y; doorEvent.Direction = direction; doorEvent.Opener = opener; doorEvent.isOpened = state; Program.server.PluginManager.processHook(Hooks.DOOR_STATECHANGE, doorEvent); if (doorEvent.Cancelled) { return true; } int num = 0; if (Main.tile.At(x, y - 1).FrameY == 0 && Main.tile.At(x, y - 1).Type == Main.tile.At(x, y).Type) { num = y - 1; } else { if (Main.tile.At(x, y - 2).FrameY == 0 && Main.tile.At(x, y - 2).Type == Main.tile.At(x, y).Type) { num = y - 2; } else { if (Main.tile.At(x, y + 1).FrameY == 0 && Main.tile.At(x, y + 1).Type == Main.tile.At(x, y).Type) { num = y + 1; } else { num = y; } } } int num2 = x; short num3 = 0; int num4; if (direction == -1) { num2 = x - 1; num3 = 36; num4 = x - 1; } else { num2 = x; num4 = x + 1; } bool flag = true; for (int k = num; k < num + 3; k++) { if (Main.tile.At(num4, k).Active) { if (Main.tile.At(num4, k).Type != 3 && Main.tile.At(num4, k).Type != 24 && Main.tile.At(num4, k).Type != 52 && Main.tile.At(num4, k).Type != 61 && Main.tile.At(num4, k).Type != 62 && Main.tile.At(num4, k).Type != 69 && Main.tile.At(num4, k).Type != 71 && Main.tile.At(num4, k).Type != 73 && Main.tile.At(num4, k).Type != 74) { flag = false; break; } WorldGen.KillTile(num4, k, false, false, false); } } if (flag) { Main.tile.At(num2, num).SetActive (true); Main.tile.At(num2, num).SetType (11); Main.tile.At(num2, num).SetFrameY (0); Main.tile.At(num2, num).SetFrameX (num3); Main.tile.At(num2 + 1, num).SetActive (true); Main.tile.At(num2 + 1, num).SetType (11); Main.tile.At(num2 + 1, num).SetFrameY (0); Main.tile.At(num2 + 1, num).SetFrameX ((short)(num3 + 18)); Main.tile.At(num2, num + 1).SetActive (true); Main.tile.At(num2, num + 1).SetType (11); Main.tile.At(num2, num + 1).SetFrameY (18); Main.tile.At(num2, num + 1).SetFrameX (num3); Main.tile.At(num2 + 1, num + 1).SetActive (true); Main.tile.At(num2 + 1, num + 1).SetType (11); Main.tile.At(num2 + 1, num + 1).SetFrameY (18); Main.tile.At(num2 + 1, num + 1).SetFrameX ((short)(num3 + 18)); Main.tile.At(num2, num + 2).SetActive (true); Main.tile.At(num2, num + 2).SetType (11); Main.tile.At(num2, num + 2).SetFrameY (36); Main.tile.At(num2, num + 2).SetFrameX (num3); Main.tile.At(num2 + 1, num + 2).SetActive (true); Main.tile.At(num2 + 1, num + 2).SetType (11); Main.tile.At(num2 + 1, num + 2).SetFrameY (36); Main.tile.At(num2 + 1, num + 2).SetFrameX ((short)(num3 + 18)); for (int l = num2 - 1; l <= num2 + 2; l++) { for (int m = num - 1; m <= num + 2; m++) { WorldGen.TileFrame(l, m, false, false); } } } return flag; }
public static bool OpenDoor(Func<Int32, Int32, ITile> TileRefs, ISandbox sandbox, int x, int y, int direction, ISender sender) { if (TileRefs == null) TileRefs = TileCollection.ITileAt; if (sender == null) sender = new ConsoleSender(); if (Program.properties.NPCDoorOpenCancel && sender is NPC) return false; var ctx = new HookContext { Sender = sender, }; var args = new HookArgs.DoorStateChanged { X = x, Y = y, Direction = direction, Open = true, }; HookPoints.DoorStateChanged.Invoke(ref ctx, ref args); if (ctx.CheckForKick()) return false; if (ctx.Result == HookResult.IGNORE) return false; if (ctx.Result == HookResult.RECTIFY) { NetMessage.SendData(19, -1, -1, "", 1, (float)x, (float)y, 0); //Inform the client of the update return false; } int num = 0; if (TileRefs(x, y - 1).FrameY == 0 && TileRefs(x, y - 1).Type == TileRefs(x, y).Type) { num = y - 1; } else if (TileRefs(x, y - 2).FrameY == 0 && TileRefs(x, y - 2).Type == TileRefs(x, y).Type) { num = y - 2; } else if (TileRefs(x, y + 1).FrameY == 0 && TileRefs(x, y + 1).Type == TileRefs(x, y).Type) { num = y + 1; } else { num = y; } int num2 = x; short num3 = 0; int num4; if (direction == -1) { num2 = x - 1; num3 = 36; num4 = x - 1; } else { num2 = x; num4 = x + 1; } bool flag = true; for (int k = num; k < num + 3; k++) { if (TileRefs(num4, k).Active) { if (!Main.tileCut[(int)TileRefs(num4, k).Type] && TileRefs(num4, k).Type != 3 && TileRefs(num4, k).Type != 24 && TileRefs(num4, k).Type != 52 && TileRefs(num4, k).Type != 61 && TileRefs(num4, k).Type != 62 && TileRefs(num4, k).Type != 69 && TileRefs(num4, k).Type != 71 && TileRefs(num4, k).Type != 73 && TileRefs(num4, k).Type != 74) { flag = false; break; } KillTile(TileRefs, sandbox, num4, k); } } if (flag) { for (int l = num2; l <= num2 + 1; l++) for (int m = num; m <= num + 2; m++) if (numNoWire < MAX_WIRE - 1) { noWireX[numNoWire] = l; noWireY[numNoWire] = m; numNoWire++; } TileRefs(num2, num).SetActive(true); TileRefs(num2, num).SetType(11); TileRefs(num2, num).SetFrameY(0); TileRefs(num2, num).SetFrameX(num3); TileRefs(num2 + 1, num).SetActive(true); TileRefs(num2 + 1, num).SetType(11); TileRefs(num2 + 1, num).SetFrameY(0); TileRefs(num2 + 1, num).SetFrameX((short)(num3 + 18)); TileRefs(num2, num + 1).SetActive(true); TileRefs(num2, num + 1).SetType(11); TileRefs(num2, num + 1).SetFrameY(18); TileRefs(num2, num + 1).SetFrameX(num3); TileRefs(num2 + 1, num + 1).SetActive(true); TileRefs(num2 + 1, num + 1).SetType(11); TileRefs(num2 + 1, num + 1).SetFrameY(18); TileRefs(num2 + 1, num + 1).SetFrameX((short)(num3 + 18)); TileRefs(num2, num + 2).SetActive(true); TileRefs(num2, num + 2).SetType(11); TileRefs(num2, num + 2).SetFrameY(36); TileRefs(num2, num + 2).SetFrameX(num3); TileRefs(num2 + 1, num + 2).SetActive(true); TileRefs(num2 + 1, num + 2).SetType(11); TileRefs(num2 + 1, num + 2).SetFrameY(36); TileRefs(num2 + 1, num + 2).SetFrameX((short)(num3 + 18)); for (int l = num2 - 1; l <= num2 + 2; l++) { for (int m = num - 1; m <= num + 2; m++) { TileFrame(TileRefs, sandbox, l, m, false, false); } } } return flag; }
private static void Play() { while (true) { // Background stuff (music) if (Instance.SoundOutBackground.PlaybackState == PlaybackState.Playing) { Instance.SoundOutBackground.Volume = Instance.SoundOutForeground.PlaybackState == PlaybackState.Playing ? ((float)Instance.Config.BaseVolume * 0.005f) : ((float)Instance.Config.BaseVolume * 0.01f); if (Instance.SoundOutBackground.WaveSource != null) { if (Instance.SoundOutBackground.WaveSource.Length - Instance.SoundOutBackground.WaveSource.Position < Instance.SoundOutBackground.WaveSource.WaveFormat.BytesPerSecond / 100) { Instance.SoundOutBackground.Stop(); Logger.Write(Logger.Status.Info, "Stopped at Position: " + Instance.SoundOutBackground.WaveSource.Position.ToString() + " Length: " + Instance.SoundOutBackground.WaveSource.Length.ToString()); } } } if (Instance.BackGroundQueue.GetQueueLenght() > 0) { if (Instance.SoundOutBackground.PlaybackState == PlaybackState.Stopped && Instance.NewSongLock == false) { Instance.Song s; if (Instance.BackGroundQueue.PlayList.TryDequeue(out s)) { Task.Run( () => { Thread.Sleep(1600); ConsoleSender.SendCommand( string.Format(Localization.Localization.CORE_PLAYING_TITLE_FROM, s.Title, s.RequestedBy.Name), ConsoleSender.Command.Chat); Logger.Write(Logger.Status.Info, string.Format(Localization.Localization.CORE_PLAYING_TITLE_FROM, s.Title, s.RequestedBy.Name)); Player(s.Source, Instance.SoundOutBackground); Instance.NewSongLock = true; Instance.CurrentTitle = s.Title; Instance.CurrentSongFrom = s.RequestedBy.Name; Logger.Write(Logger.Status.Info, "Started at Position: " + Instance.SoundOutBackground.WaveSource.Position.ToString() + " Length: " + Instance.SoundOutBackground.WaveSource.Length.ToString()); }); } } } // Check to make sure sound output has actually started (prevent queue skipping) if (Instance.SoundOutBackground.PlaybackState == PlaybackState.Playing && Instance.NewSongLock == true) { Instance.NewSongLock = false; } // Foreground stuff (tts) if (Instance.SoundOutForeground.PlaybackState == PlaybackState.Playing) { if (Instance.SoundOutForeground.WaveSource != null) { if (Instance.SoundOutForeground.WaveSource.Length - Instance.SoundOutForeground.WaveSource.Position < Instance.SoundOutForeground.WaveSource.WaveFormat.BytesPerSecond / 1000) { Instance.SoundOutForeground.Stop(); } } } if (Instance.QueueForeGround.Count > 0) { if (Instance.SoundOutForeground.PlaybackState == PlaybackState.Stopped) { IWaveSource s; if (Instance.QueueForeGround.TryDequeue(out s)) { Task.Run(() => { Player(s, Instance.SoundOutForeground); }); } } } Thread.Sleep(60); } }
public static void purge(String from, String topurge) { Sender sender = new ConsoleSender(); ArgumentList command = new ArgumentList(); command.Add(topurge); Commands.Purge(sender, command); server.sendToOneClient(Packet.PURGED(topurge), from); }
public static void op(String name, String oppedby, String password) { Player player = FindPlayer(name); if (player != null) { if (player.Name != null) { Sender sender = new ConsoleSender(); ArgumentList command = new ArgumentList(); command.Add(name); if (!player.Op) { command.Add(password); Commands.OpPlayer(sender, command); server.sendToOneClient(Packet.OPPED(name), oppedby); } else { Commands.DeopPlayer(sender, command); server.sendToOneClient(Packet.DEOPPED(name), oppedby); } } } else { server.sendToOneClient(Packet.PLAYER_NOT_FOUND_ERROR(), oppedby); } }
public static void kick(String name, String kickedby) { Player player = FindPlayer(name); if (player != null) { if (player.Name != null) { Sender sender = new ConsoleSender(); ArgumentList command = new ArgumentList(); command.Add(name); Commands.Kick(sender, command); server.sendToOneClient(Packet.PLAYER_KICKED(name), kickedby); } } else { server.sendToOneClient(Packet.PLAYER_NOT_FOUND_ERROR(), kickedby); } }
public void Execute(User executor, List <string> arguments) { if (arguments.Count <= 0) { ConsoleSender.SendCommand("Usage: !request [song name or url]", ConsoleSender.Command.Chat); return; } var url = arguments[0]; var soundcloudregex = new Regex(@"^(https?:\/\/)?(www.)?soundcloud\.com\/[\w\-\.]+(\/)+[\w\-\.]+/?$"); if (soundcloudregex.Match(url).Success) { try { using (var web = new WebClient()) { var info = web.DownloadString( "http://api.soundcloud.com/resolve.json?url=" + url + "&client_id=" + clientID + "&app_version=" + AppID); var b = JsonConvert.DeserializeObject <Track>(info); if (b.streamable && b.kind == "track") { var durl = web.DownloadString( "https://api.soundcloud.com/tracks/" + b.id + "/streams?client_id=" + clientID + "&app_version=" + AppID); var urls = JsonConvert.DeserializeObject <DownloadURL>(durl); if (urls.http_mp3_128_url != null) { Instance.BackgroundEnqueue(Instance.SongType.MP3, urls.http_mp3_128_url, executor.Name, b.title); return; } } } } catch (Exception) { return; } } var youtube = new Regex(@"youtube\..+?/watch.*?v=(.*?)(?:&|/|$)"); var shortregex = new Regex(@"youtu\.be/(.*?)(?:\?|&|/|$)"); if (youtube.Match(url).Success || shortregex.Match(url).Success) { var client = new YoutubeClient(); var video = client.Videos.GetAsync(url).Result; var streamManifest = client.Videos.Streams.GetManifestAsync(video.Id).Result; if (streamManifest.Streams.Count == 0) { return; } var streamInfo = streamManifest.GetAudioOnly().Where(n => n.AudioCodec.Contains("mp4")) .FirstOrDefault(); if (streamInfo == null) { return; } var ext = streamInfo.Url; if (ext == string.Empty) { return; } var title = video.Title; ConsoleSender.SendCommand($"{title} was added to the queue", ConsoleSender.Command.Chat); Instance.BackgroundEnqueue(Instance.SongType.AAC, ext, executor.Name, title); } else { var text = arguments.Aggregate(" ", (current, argument) => current + " " + argument); var client = new YoutubeClient(); var vids = client.Search.GetVideosAsync(text).BufferAsync(5).Result; if (vids.Count > 0) { for (int i = 0; i < vids.Count; i++) { var streamManifest = client.Videos.Streams.GetManifestAsync(vids[i].Id).Result; if (streamManifest.Streams.Count == 0) { return; } var streamInfo = streamManifest.GetAudioOnly().Where(n => n.AudioCodec.Contains("mp4")) .FirstOrDefault(); if (streamInfo == null) { return; } var ext = streamInfo.Url; if (ext == string.Empty) { return; } var title = client.Videos.GetAsync(vids[i].Id).Result.Title; Instance.BackgroundEnqueue(Instance.SongType.AAC, ext, executor.Name, title); break; } } } }
public static void time(String time, String changedby) { Sender sender = new ConsoleSender(); ArgumentList command = new ArgumentList(); command.Add(time); Commands.Time(sender, command); server.sendToOneClient(Packet.TIME_CHANGED(time), changedby); }
public static bool CloseDoor(int i, int j, bool forced = false, DoorOpener opener = DoorOpener.SERVER, ISender sender = null) { if (sender == null) { ConsoleSender cSender = new ConsoleSender(Program.server); cSender.ConsoleCommand.Sender = new Sender(); sender = cSender; } DoorStateChangeEvent doorEvent = new DoorStateChangeEvent(); doorEvent.Sender = sender; doorEvent.X = i; doorEvent.Y = j; doorEvent.Direction = 1; doorEvent.Opener = opener; doorEvent.isOpened = forced; Program.server.PluginManager.processHook(Hooks.DOOR_STATECHANGE, doorEvent); if (doorEvent.Cancelled) { return true; } int num = 0; int num2 = i; int num3 = j; int frameX = (int)Main.tile.At(i, j).FrameX; int frameY = (int)Main.tile.At(i, j).FrameY; if (frameX == 0) { num2 = i; num = 1; } else { if (frameX == 18) { num2 = i - 1; num = 1; } else { if (frameX == 36) { num2 = i + 1; num = -1; } else { if (frameX == 54) { num2 = i; num = -1; } } } } if (frameY == 0) { num3 = j; } else { if (frameY == 18) { num3 = j - 1; } else { if (frameY == 36) { num3 = j - 2; } } } int num4 = num2; if (num == -1) { num4 = num2 - 1; } if (!forced) { for (int k = num3; k < num3 + 3; k++) { if (!Collision.EmptyTile(num2, k, true)) { return false; } } } for (int l = num4; l < num4 + 2; l++) { for (int m = num3; m < num3 + 3; m++) { if (l == num2) { Main.tile.At(l, m).SetType (10); Main.tile.At(l, m).SetFrameX ((short)(WorldGen.genRand.Next(3) * 18)); } else { Main.tile.At(l, m).SetActive (false); } } } for (int n = num2 - 1; n <= num2 + 1; n++) { for (int num5 = num3 - 1; num5 <= num3 + 2; num5++) { WorldGen.TileFrame(n, num5, false, false); } } return true; }
public void Execute(User executor, List <string> arguments) { if (arguments.Count <= 0) { return; } var url = arguments[0]; var soundcloudregex = new Regex(@"^(https?:\/\/)?(www.)?soundcloud\.com\/[\w\-\.]+(\/)+[\w\-\.]+/?$"); if (soundcloudregex.Match(url).Success) { try { using (var web = new WebClient()) { var info = web.DownloadString( "http://api.soundcloud.com/resolve.json?url=" + url + "&client_id=" + clientID + "&app_version=" + AppID); var b = JsonConvert.DeserializeObject <Track>(info); if (b.streamable && b.kind == "track") { var durl = web.DownloadString( "https://api.soundcloud.com/tracks/" + b.id + "/streams?client_id=" + clientID + "&app_version=" + AppID); var urls = JsonConvert.DeserializeObject <DownloadURL>(durl); if (urls.http_mp3_128_url != null) { Instance.BackgroundEnqueue(Instance.SongType.MP3, urls.http_mp3_128_url, executor.Name, b.title); return; } } } } catch (Exception) { return; } } var youtube = new Regex(@"youtube\..+?/watch.*?v=(.*?)(?:&|/|$)"); var shortregex = new Regex(@"youtu\.be/(.*?)(?:\?|&|/|$)"); if (youtube.Match(url).Success || shortregex.Match(url).Success) { var id = YoutubeClient.ParseVideoId(url); var client = new YoutubeClient(); var streamInfoSet = client.GetVideoMediaStreamInfosAsync(id); var streamInfo = streamInfoSet.Result; if (streamInfo == null) { return; } var ext = ""; foreach (var ad in streamInfo.Audio) { if (Enum.GetName(typeof(AudioEncoding), ad.AudioEncoding) == "Aac") //Msbuild f**k upped this moment. I cant compare different enums. MSBUILD 16 VS19 RC3 { ext = ad.Url; break; } } if (ext == string.Empty) { return; } var title = client.GetVideoAsync(id).Result.Title; ConsoleSender.SendCommand($"{title} was added to the queue", ConsoleSender.Command.Chat); Instance.BackgroundEnqueue(Instance.SongType.AAC, ext, executor.Name, title); } else { var text = arguments.Aggregate(" ", (current, argument) => current + " " + argument); var client = new YoutubeClient(); var vids = client.SearchVideosAsync(text, 1).Result; if (vids.Count > 0) { for (int i = 0; i < vids.Count; i++) { var streamInfoSet = client.GetVideoMediaStreamInfosAsync(vids[i].Id).ConfigureAwait(false).GetAwaiter().GetResult(); var ext = ""; foreach (var ad in streamInfoSet.Audio) { if (Enum.GetName(typeof(AudioEncoding), ad.AudioEncoding) == "Aac") //Msbuild f**k upped this moment. I cant compare different enums. MSBUILD 16 VS19 RC3 { ext = ad.Url; break; } } if (ext == string.Empty) { continue; } var title = client.GetVideoAsync(vids[i].Id).Result.Title; Instance.BackgroundEnqueue(Instance.SongType.AAC, ext, executor.Name, title); break; } } } }
public static void reload(String sentby) { Sender sender = new ConsoleSender(); ArgumentList command = new ArgumentList(); server.sendToOneClient(Packet.RESTART_REQUEST_SENT(), sentby); Thread.Sleep(500); Commands.Restart(sender, command); }
public void Execute(User executor, List <string> arguments) { ConsoleSender.SendCommand("RequestifyTF2 by cymug/DllMain/nullptr/Weespin", ConsoleSender.Command.Chat); ConsoleSender.SendCommand("Download at: github.com/cymug/RequestifyTF2", ConsoleSender.Command.Chat); }
public static void spawn(String from, String target, String npc, String amount) { Sender sender = new ConsoleSender(); ArgumentList command = new ArgumentList(); command.Add(amount); command.Add(npc); command.Add(target); Commands.SpawnNPC(sender, command); server.sendToOneClient(Packet.SPAWNED_NPC(npc, amount), from); }
public void autoSave() { bool firstrun = true; DateTime lastsave = new DateTime(); ISender console = new ConsoleSender(); List<string> empty = new List<string>(); ArgumentList arguments = new ArgumentList(); while (isEnabled) { if (autosaveenabled) { if (!firstrun && (DateTime.UtcNow > lastsave.AddMinutes(autosaveinterval))) { if (!arguments.Contains("automap")) { arguments.Add("automap"); } MapCommand(console, arguments); lastsave = DateTime.UtcNow; } if (firstrun) { firstrun = false; lastsave = DateTime.UtcNow; } } Thread.Sleep(1000); } }