예제 #1
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;
                //}
            }
        }
예제 #2
0
파일: NetHooks.cs 프로젝트: Vednix/Hydra
        public static void OnGreetPlayer(GreetPlayerEventArgs args)
        {
            var player = TShockB.Players[args.Who];

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

            string playername = $"[c/4747BF:{player.Name}]";

            if (!Main.player[player.Index].Male)
            {
                playername = $"[c/800080:{player.Name}]";
            }

            string via = "[c/ff4500:(via PC)]";

            if (TSPlayerB.isMobile[player.Index])
            {
                via = "[c/ff198d:(via Mobile)]";
            }
            string country = $" ({player.Country})";

            if (country.Contains("N/A") || !TShock.Config.EnableGeoIP)
            {
                country = string.Empty;
            }
            if (!player.SilentJoinInProgress)
            {
                TShockB.AllSendMessage(DefaultMessage: $"{playername}{country} has joined the server {via}!", Color.White,
                                       PortugueseMessage: $"{playername}{country} entrou no servidor {via}!",
                                       SpanishMessage: $"{playername}{country} entró al servidor {(via.Contains("(via PC)") ? "[c/ff4500:(a través de PC)]" : "[c/ff198d:(vía teléfono móvil)]")}!", ignore: player);
            }

            Logger.doLog($"{player.Name}{country} has joined the server {(TSPlayerB.isMobile[player.Index] ? "(via Mobile)" : "(via PC)")}!", Config.DebugLevel.Info);

            if (TShock.Config.DisplayIPToAdmins)
            {
                TShock.Utils.SendLogs(string.Format("{0} IP => {1}", player.Name, player.IP), Color.Blue);
            }

            TSPlayerB.SendFileTextAsMessage(player.Index, FileToolsB.MotdPath);

            string pvpMode = TShock.Config.PvPMode.ToLowerInvariant();

            if (pvpMode == "always")
            {
                player.TPlayer.hostile = true;
                player.SendData(PacketTypes.TogglePvp, "", player.Index);
                TSPlayer.All.SendData(PacketTypes.TogglePvp, "", player.Index);
            }

            if (!player.IsLoggedIn)
            {
                if (Main.ServerSideCharacter)
                {
                    TSPlayerB.IsDisabledForSSC[player.Index] = true;
                    TSPlayerB.SendErrorMessage(player.Index, DefaultMessage: String.Format("Server side characters is enabled!\nPlease [c/ffd700:{0}register] or [c/ffd700:{0}login] to play!", TShockAPI.Commands.Specifier),
                                               PortugueseMessage: "SSC está ativo neste servidor.\nEfetue [c/ffd700:{TShockAPI.Commands.Specifier}registro] ou [c/ffd700:{TShockAPI.Commands.Specifier}login] para jogar.",
                                               SpanishMessage: $"SSC está activo en este servidor.\nInicia [c/ffd700:{TShockAPI.Commands.Specifier}sesión] o [c/ffd700:{TShockAPI.Commands.Specifier}registrarse] para jugar");
                    player.LoginHarassed = true;
                }
                else if (TShock.Config.RequireLogin)
                {
                    TSPlayerB.SendErrorMessage(player.Index, DefaultMessage: $"Please [c/ffd700:{TShockAPI.Commands.Specifier}register] or [c/ffd700:{TShockAPI.Commands.Specifier}login] to play!",
                                               PortugueseMessage: $"Efetue [c/ffd700:{TShockAPI.Commands.Specifier}registro] ou [c/ffd700:{TShockAPI.Commands.Specifier}login] para jogar.",
                                               SpanishMessage: $"Inicia [c/ffd700:{TShockAPI.Commands.Specifier}sesión] o [c/ffd700:{TShockAPI.Commands.Specifier}registrarse] para jugar");
                    player.LoginHarassed = true;
                }
            }

            player.LastNetPosition = new Vector2(Main.spawnTileX * 16f, Main.spawnTileY * 16f);

            if (TShock.Config.RememberLeavePos && (TShock.RememberedPos.GetLeavePos(player.Name, player.IP) != Vector2.Zero) && !player.LoginHarassed)
            {
                player.RPPending = 1;
                TSPlayerB.SendInfoMessage(player.Index, DefaultMessage: "You will be teleported to your last known location...",
                                          PortugueseMessage: "Você será teleportado para sua última localização...",
                                          SpanishMessage: "Serás teletransportado a tu última ubicación...");
            }

            args.Handled = true;
        }