Exemplo n.º 1
0
 private static void SyncLocalArea(CommandArgs args)
 {
     args.Player.SendTileSquare((int)args.Player.TileX, (int)args.Player.TileY, 32);
     TSPlayerB.SendWarningMessage(args.Player.Index, DefaultMessage: "[Hydra] Sync'd!",
                                  PortugueseMessage: "[Hydra] Sincronizado!",
                                  SpanishMessage: "[Hydra] Sincronizado!");
 }
Exemplo n.º 2
0
        internal static async void OnServerChat(ServerChatEventArgs args)
        {
            if (args.Handled)
            {
                return;
            }

            var tsplr = TShockB.Players[args.Who];

            if (tsplr == null)
            {
                args.Handled = true;
                return;
            }

            if (args.Text.Length > 500)
            {
                TSPlayerB.SendWarningMessage(tsplr.Index, DefaultMessage: "Crash attempt via long chat packet.",
                                             PortugueseMessage: "Tentativa de exploit através de um pacote de bate-papo longo",
                                             SpanishMessage: "Intento de explotación a través de un paquete de chat largo");
                //Utils.Kick(tsplr, "Crash attempt via long chat packet.", true);
                args.Handled = true;
                return;
            }

            string text = args.Text;

            // Terraria now has chat commands on the client side.
            // These commands remove the commands prefix (e.g. /me /playing) and send the command id instead
            // In order for us to keep legacy code we must reverse this and get the prefix using the command id
            //Not in Terraria 1.3.0
            //foreach (var item in Terraria.UI.Chat.ChatManager.Commands._localizedCommands)
            //{
            //	if (item.Value._name == args.CommandId._name)
            //	{
            //		if (!String.IsNullOrEmpty(text))
            //		{
            //			text = item.Key.Value + ' ' + text;
            //		}
            //		else
            //		{
            //			text = item.Key.Value;
            //		}
            //		break;
            //	}
            //}

            if ((text.StartsWith(TShock.Config.CommandSpecifier) || text.StartsWith(TShock.Config.CommandSilentSpecifier)) && !string.IsNullOrWhiteSpace(text.Substring(1)))
            {
                try
                {
                    args.Handled = true;
                    if (!TShockAPI.Commands.HandleCommand(tsplr, text))
                    {
                        // This is required in case anyone makes HandleCommand return false again
                        TSPlayerB.SendErrorMessage(tsplr.Index, DefaultMessage: "The command could not be parsed.",
                                                   PortugueseMessage: "O comando não pôde ser analisado.",
                                                   SpanishMessage: "El comando no se pudo analizar.");

                        Logger.doLogLang(DefaultMessage: $"Unable to parse command '{text}' from player '{tsplr.Name}'.", Hydra.Config.DebugLevel.Error, (TSPlayerB.Language)Enum.Parse(typeof(TSPlayerB.Language), Base.Config.DefaultHydraLanguage), _name,
                                         PortugueseMessage: $"Não foi possível parsear o comando '{text}' executado pelo jogador '{tsplr.Name}'.",
                                         SpanishMessage: $"El comando no se pudo analizar '{text}' realizado por el jugador '{tsplr.Name}'.");
                    }
                }
                catch (Exception ex)
                {
                    Logger.doLogLang(DefaultMessage: $"An exception occurred executing a command.", Hydra.Config.DebugLevel.Critical, (TSPlayerB.Language)Enum.Parse(typeof(TSPlayerB.Language), Base.Config.DefaultHydraLanguage), _name,
                                     PortugueseMessage: $"Ocorreu uma exceção ao executar um comando.",
                                     SpanishMessage: $"Se produjo una excepción al ejecutar un comando.");

                    TShock.Log.Error(ex.ToString());
                }
            }
            else
            {
                if (TShock.Config.EnableChatAboveHeads)
                {
                    TShock.Config.EnableChatAboveHeads = false;
                    Logger.doLog($"ChatAboveHeads not yet implemented in {_name}, using default", Hydra.Config.DebugLevel.Critical, _name);
                }
                if (!tsplr.HasPermission(TShockAPI.Permissions.canchat))
                {
                    args.Handled = true;
                }
                else if (tsplr.mute)
                {
                    TSPlayerB.SendErrorMessage(tsplr.Index, DefaultMessage: "You have been muted!",
                                               PortugueseMessage: "Você foi silenciado!",
                                               SpanishMessage: "Has sido silenciado!");
                    args.Handled = true;
                }
                else if (!TShock.Config.EnableChatAboveHeads)
                {
                    string PreNSuf = $"{tsplr.Group.Prefix}{tsplr.Name}{tsplr.Group.Suffix}: ";
                    await Broadcast(PreNSuf, args.Text, tsplr.Group.R, tsplr.Group.G, tsplr.Group.B, tsplr, args);

                    //text = String.Format(Config.ChatFormat, tsplr.Group.Name, tsplr.Group.Prefix, tsplr.Name, tsplr.Group.Suffix,
                    //                         args.Text);
                    //Hooks.PlayerHooks.OnPlayerChat(tsplr, args.Text, ref text);
                    //Utils.Broadcast(text, tsplr.Group.R, tsplr.Group.G, tsplr.Group.B);

                    //var hexValue = tsplr.Group.R.ToString("X2") + tsplr.Group.G.ToString("X2") + tsplr.Group.B.ToString("X2");
                    //string c = Convert.ToInt32(hexValue, 16).ToString();
                    args.Handled = true;
                }
                //else
                //{
                //    Player ply = Main.player[args.Who];
                //    string name = ply.name;
                //    ply.name = String.Format(TShock.Config.ChatAboveHeadsFormat, tsplr.Group.Name, tsplr.Group.Prefix, tsplr.Name, tsplr.Group.Suffix);
                //    //Update the player's name to format text nicely. This needs to be done because Terraria automatically formats messages against our will
                //    NetMessage.SendData((int)PacketTypes.PlayerInfo, -1, -1, NetworkText.FromLiteral(ply.name), args.Who, 0, 0, 0, 0);

                //    //Give that poor player their name back :'c
                //    ply.name = name;
                //    PlayerHooks.OnPlayerChat(tsplr, args.Text, ref text);

                //    NetMessage.SendData((int)PacketTypes.ChatText, -1, args.Who, text, args.Who, tsplr.Group.R, tsplr.Group.G, tsplr.Group.B);
                //    NetMessage.SendData((int)PacketTypes.PlayerInfo, -1, -1, name, args.Who, 0, 0, 0, 0);
                //    //Downgrade to 1.3.0
                //    ////This netpacket is used to send chat text from the server to clients, in this case on behalf of a client
                //    //Terraria.Net.NetPacket packet = Terraria.GameContent.NetModules.NetTextModule.SerializeServerMessage(
                //    //    NetworkText.FromLiteral(text), new Color(tsplr.Group.R, tsplr.Group.G, tsplr.Group.B), (byte)args.Who
                //    //);
                //    ////Broadcast to everyone except the player who sent the message.
                //    ////This is so that we can send them the same nicely formatted message that everyone else gets
                //    //Terraria.Net.NetManager.Instance.Broadcast(packet, args.Who);

                //    //Reset their name
                //    //NetMessage.SendData((int)PacketTypes.PlayerInfo, -1, -1, NetworkText.FromLiteral(name), args.Who, 0, 0, 0, 0);

                //    string msg = String.Format("<{0}> {1}",
                //        String.Format(TShock.Config.ChatAboveHeadsFormat, tsplr.Group.Name, tsplr.Group.Prefix, tsplr.Name, tsplr.Group.Suffix),
                //        text
                //    ); ;

                //    //Send the original sender their nicely formatted message, and do all the loggy things
                //    tsplr.SendMessage(msg, tsplr.Group.R, tsplr.Group.G, tsplr.Group.B);
                //    TSPlayer.Server.SendMessage(msg, tsplr.Group.R, tsplr.Group.G, tsplr.Group.B);
                //    TShock.Log.Info("Broadcast: {0}", msg);
                //    args.Handled = true;
                //}
            }
        }