Example #1
0
        public static bool OnSendData(ref int msgType, ref int remoteClient, ref int ignoreClient, ref string text, ref int number, ref float number2, ref float number3, ref float number4, ref int number5)
        {
            if (NetHooks.SendData == null)
            {
                return(false);
            }
            SendDataEventArgs sendDataEventArgs = new SendDataEventArgs
            {
                MsgID        = (PacketTypes)msgType,
                remoteClient = remoteClient,
                ignoreClient = ignoreClient,
                text         = text,
                number       = number,
                number2      = number2,
                number3      = number3,
                number4      = number4,
                number5      = number5
            };

            NetHooks.SendData(sendDataEventArgs);
            msgType      = (int)sendDataEventArgs.MsgID;
            remoteClient = sendDataEventArgs.remoteClient;
            ignoreClient = sendDataEventArgs.ignoreClient;
            text         = sendDataEventArgs.text;
            number       = sendDataEventArgs.number;
            number2      = sendDataEventArgs.number2;
            number3      = sendDataEventArgs.number3;
            number4      = sendDataEventArgs.number4;
            return(sendDataEventArgs.Handled);
        }
 private static void NetHooks_SendData(SendDataEventArgs e)
 {
     if (Main.netMode != 2 && e.MsgID == PacketTypes.ChatText)
     {
         string text = e.text;
         e.Handled = ClientHooks.OnChat(ref text);
         e.text = text;
     }
 }
 private static void NetHooks_SendData(SendDataEventArgs e)
 {
     if (Main.netMode != 2 && e.MsgID == PacketTypes.ChatText)
     {
         string text = e.text;
         e.Handled = ClientHooks.OnChat(ref text);
         e.text    = text;
     }
 }
Example #4
0
 public static bool OnSendData(ref int msgType, ref int remoteClient, ref int ignoreClient, ref string text, ref int number, ref float number2, ref float number3, ref float number4, ref int number5)
 {
     if (NetHooks.SendData == null)
     {
         return false;
     }
     SendDataEventArgs sendDataEventArgs = new SendDataEventArgs
     {
         MsgID = (PacketTypes)msgType,
         remoteClient = remoteClient,
         ignoreClient = ignoreClient,
         text = text,
         number = number,
         number2 = number2,
         number3 = number3,
         number4 = number4,
         number5 = number5
     };
     NetHooks.SendData(sendDataEventArgs);
     msgType = (int)sendDataEventArgs.MsgID;
     remoteClient = sendDataEventArgs.remoteClient;
     ignoreClient = sendDataEventArgs.ignoreClient;
     text = sendDataEventArgs.text;
     number = sendDataEventArgs.number;
     number2 = sendDataEventArgs.number2;
     number3 = sendDataEventArgs.number3;
     number4 = sendDataEventArgs.number4;
     return sendDataEventArgs.Handled;
 }
Example #5
0
        public void OnSendData(SendDataEventArgs e)
        {
            if (e.Handled)
                return;
            try
            {
                if (e.MsgID == PacketTypes.NpcStrike)
                {
                    NPC npc = Main.npc[e.number];
                    // Console.WriteLine("(SendData) NpcStrike -> 1:{0} 2:{4} 3:{5} 4:{6} 5:{1} remote:{2} ignore:{3}", e.number, e.number5, e.remoteClient, e.ignoreClient, e.number2, e.number3, e.number4);
                    // Console.WriteLine("NPC: life:{0} reallife:{1}", npc.life);
                    if (npc != null)
                    {
                        if (npc.boss)
                        {
                            if (npc.life <= 0)
                            {
                                for (int i = BossList.Count - 1; i >= 0; i--)
                                {
                                    if (BossList[i].Npc == null)
                                        BossList.RemoveAt(i);
                                    else if (BossList[i].Npc == npc)
                                    {
                                        var rewardDict = BossList[i].GetRecalculatedReward();
                                        foreach (KeyValuePair<int, int> reward in rewardDict)
                                        {
                                            if (PlayerList[reward.Key] != null)
                                                PlayerList[reward.Key].ChangeMoney(reward.Value, MoneyEventFlags.Kill, config.AnnounceBossGain);
                                        }
                                        BossList.RemoveAt(i);
                                    }
                                    else if (!BossList[i].Npc.active)
                                        BossList.RemoveAt(i);
                                }

                                if (e.ignoreClient >= 0)
                                {
                                    var player = PlayerList[e.ignoreClient];
                                    if (player != null)
                                        player.AddKill(npc.netID);
                                }
                            }
                            else if (e.ignoreClient >= 0)
                            {
                                var bossnpc = BossList.Find(n => n.Npc == npc);
                                if (bossnpc != null)
                                    bossnpc.AddDamage(e.ignoreClient, (int)e.number2);
                                else
                                {
                                    BossNPC newBoss = new BossNPC(npc);
                                    newBoss.AddDamage(e.ignoreClient, (int)e.number2);
                                    BossList.Add(newBoss);
                                }
                            }
                        }
                        else if (npc.life <= 0 && e.ignoreClient >= 0)
                        {
                            var player = PlayerList[e.ignoreClient];
                            if (player != null)
                            {
                                if (npc.value > 0)
                                {
                                    float Mod = 1;
                                    if (player.TSPlayer.TPlayer.buffType.Contains(13)) // battle potion
                                        Mod *= config.BattlePotionModifier;
                                    if (config.OptionalMobModifier.ContainsKey(npc.netID))
                                        Mod *= config.OptionalMobModifier[npc.netID]; // apply custom modifiers

                                    int minVal = (int)((npc.value - (npc.value * 0.1)) * Mod);
                                    int maxVal = (int)((npc.value + (npc.value * 0.1)) * Mod);
                                    int rewardAmt = RandomNumber(minVal, maxVal);
                                    player.ChangeMoney(rewardAmt, MoneyEventFlags.Kill, config.AnnounceKillGain);
                                }
                                player.AddKill(npc.netID);
                            }
                        }
                    }
                }
                else if (e.MsgID == PacketTypes.PlayerKillMe)
                {
                    //Console.WriteLine("(SendData) PlayerKillMe -> 1:{0} 2:{4} 3:{5} 4:{6} 5:{1} remote:{2} ignore:{3}", e.number, e.number5, e.remoteClient, e.ignoreClient, e.number2, e.number3, e.number4);
                    // 1-playerID, 2-direction, 3-dmg, 4-PVP
                    var deadPlayer = PlayerList[e.number];
                    if (deadPlayer != null)
                    {
                        int penaltyAmmount = 0;
                        if (config.StaticDeathPenalty)
                            penaltyAmmount = RandomNumber(config.DeathPenaltyMin, config.DeathPenaltyMax);
                        else
                            penaltyAmmount = (int)(deadPlayer.Money * (config.DeathPenaltyPercent / 100f));
                     //   Console.WriteLine("penalty ammount: {0}", penaltyAmmount);
                        if (e.number4 == 1)
                        {
                            if (!deadPlayer.TSPlayer.Group.HasPermission("vault.bypass.death") && deadPlayer.ChangeMoney(-penaltyAmmount, MoneyEventFlags.PvP, true) && config.PvPWinnerTakesLoosersPenalty && deadPlayer.LastPVPid != -1)
                            {
                                var killer = PlayerList[deadPlayer.LastPVPid];
                                if (killer != null)
                                    killer.ChangeMoney(penaltyAmmount, MoneyEventFlags.PvP, true);
                            }
                        }
                        else if (!deadPlayer.TSPlayer.Group.HasPermission("vault.bypass.death"))
                            deadPlayer.ChangeMoney(-penaltyAmmount, MoneyEventFlags.Death,true);
                    }
                }
                else if (e.MsgID == PacketTypes.PlayerDamage)
                {
                    // Console.WriteLine("(SendData) PlayerDamage -> 1:{0} 2:{4} 3:{5} 4:{6} 5:{1} remote:{2} ignore:{3}", e.number, e.number5, e.remoteClient, e.ignoreClient, e.number2, e.number3, e.number4);
                    // 1: pID, ignore: Who, 2: dir, 3:dmg, 4:pvp;
                    if (e.number4 == 1) // if PvP
                    {
                        var player = PlayerList[e.number];
                        if (player != null)
                            player.LastPVPid = e.ignoreClient;
                    }
                }
            }
            catch (Exception ex) { Log.ConsoleError(ex.ToString()); }
        }
Example #6
0
        private void NetHooks_SendData(SendDataEventArgs e)
        {
            if (e.MsgID == PacketTypes.Disconnect)
            {
                Action<ServerSock, string> senddisconnect = (sock, str) =>
                                                                {
                                                                    if (sock == null || !sock.active)
                                                                        return;
                                                                    sock.kill = true;
                                                                    using (var ms = new MemoryStream())
                                                                    {
                                                                        new DisconnectMsg {Reason = str}.PackFull(ms);
                                                                        SendBytesBufferless(sock, ms.ToArray());
                                                                    }
                                                                };

                if (e.remoteClient != -1)
                {
                    senddisconnect(Netplay.serverSock[e.remoteClient], e.text);
                }
                else
                {
                    for (int i = 0; i < Netplay.serverSock.Length; i++)
                    {
                        if (e.ignoreClient != -1 && e.ignoreClient == i)
                            continue;

                        senddisconnect(Netplay.serverSock[i], e.text);
                    }
                }
                e.Handled = true;
            }
        }
        public void OnSendData(SendDataEventArgs e)
        {
            try
            {
                List<int> ghostIDs = new List<int>();
                for (int i = 0; i < 256; i++)
                {

                    if (isGhost[i])
                    {

                        ghostIDs.Add(i);

                    }

                }
                switch (e.MsgID)
                {
                    case PacketTypes.DoorUse:
                    case PacketTypes.EffectHeal:
                    case PacketTypes.EffectMana:
                    case PacketTypes.PlayerDamage:
                    case PacketTypes.Zones:
                    case PacketTypes.PlayerAnimation:
                    case PacketTypes.PlayerTeam:
                    case PacketTypes.PlayerSpawn:
                        if ((ghostIDs.Contains(e.number)) && (isGhost[e.number]))
                            e.Handled = true;
                        break;
                    case PacketTypes.ProjectileNew:
                    case PacketTypes.ProjectileDestroy:
                        if ((ghostIDs.Contains(e.ignoreClient)) && (isGhost[e.ignoreClient]))
                            e.Handled = true;
                        break;
                    default: break;

                }
                if ((e.number >= 0) && (e.number <= 255) && (isGhost[e.number]))
                {

                    if ((!cansend) && (e.MsgID == PacketTypes.PlayerUpdate))
                    {

                        e.Handled = true;

                    }
                }
            }
            catch (Exception) { }
        }
        private void OnSendData(SendDataEventArgs e)
        {
            if (e.MsgID == PacketTypes.TileSendSection)
            {

                short width = (short)e.number;
                int x = (int)e.number2;
                int y = (int)e.number3;
                foreach (Point thePoint in getTempOutline(tempPoints[e.remoteClient]))
                {
                    if (!tilesToRevert.Keys.Contains(new Point(thePoint.X, thePoint.Y)))
                    {
                        tilesToRevert.Add(new Point(thePoint.X, thePoint.Y), Main.tile[thePoint.X, thePoint.Y].Data);
                        Main.tile[thePoint.X, thePoint.Y].active = true;
                        Main.tile[thePoint.X, thePoint.Y].type = 70;
                    }
                }

            }
        }
Example #9
0
        private void NetHooks_SendData(SendDataEventArgs e)
        {
            if (e.MsgID == PacketTypes.Disconnect)
            {
                Action<ServerSock, string> senddisconnect = (sock, str) =>
                                                                {
                                                                    if (sock == null || !sock.active)
                                                                        return;
                                                                    sock.kill = true;
                                                                    using (var ms = new MemoryStream())
                                                                    {
                                                                        new DisconnectMsg {Reason = str}.PackFull(ms);
                                                                        SendBytesBufferless(sock, ms.ToArray());
                                                                    }
                                                                };

                if (e.remoteClient != -1)
                {
                    senddisconnect(Netplay.serverSock[e.remoteClient], e.text);
                }
                else
                {
                    for (int i = 0; i < Netplay.serverSock.Length; i++)
                    {
                        if (e.ignoreClient != -1 && e.ignoreClient == i)
                            continue;

                        senddisconnect(Netplay.serverSock[i], e.text);
                    }
                }
                e.Handled = true;
            }
            if (e.MsgID == PacketTypes.WorldInfo)
            {
                if (e.remoteClient == -1) return;
                var player = Players[e.remoteClient];
                if (player == null) return;
                if (Config.UseServerName)
                {
                    using (var ms = new MemoryStream())
                    {
                        var msg = new WorldInfoMsg
                        {
                            Time = (int)Main.time,
                            DayTime = Main.dayTime,
                            MoonPhase = (byte)Main.moonPhase,
                            BloodMoon = Main.bloodMoon,
                            MaxTilesX = Main.maxTilesX,
                            MaxTilesY = Main.maxTilesY,
                            SpawnX = Main.spawnTileX,
                            SpawnY = Main.spawnTileY,
                            WorldSurface = (int)Main.worldSurface,
                            RockLayer = (int)Main.rockLayer,
                            WorldID = Main.worldID,
                            WorldFlags =
                                (WorldGen.shadowOrbSmashed ? WorldInfoFlag.OrbSmashed : WorldInfoFlag.None) |
                                (NPC.downedBoss1 ? WorldInfoFlag.DownedBoss1 : WorldInfoFlag.None) |
                                (NPC.downedBoss2 ? WorldInfoFlag.DownedBoss2 : WorldInfoFlag.None) |
                                (NPC.downedBoss3 ? WorldInfoFlag.DownedBoss3 : WorldInfoFlag.None) |
                                (Main.hardMode ? WorldInfoFlag.HardMode : WorldInfoFlag.None) |
                                (NPC.downedClown ? WorldInfoFlag.DownedClown : WorldInfoFlag.None),
                            WorldName = Config.ServerName
                        };
                        msg.PackFull(ms);
                        player.SendRawData(ms.ToArray());
                    }
                    e.Handled = true;
                }
            }
        }
Example #10
0
        public void SendData(SendDataEventArgs e)
        {
            try
            {
                switch (e.MsgID)
                {
                   /* case PacketTypes.Status:
                        {
                            Console.WriteLine("(SendData) Status ->  1: {0}, 2: {4}, 3: {5}, 4: {6}, 5: {1}, remote: {2}, ignore: {3}", e.number, e.number5, e.remoteClient, e.ignoreClient, e.number2, e.number3, e.number4);
                            break;
                        */
                    case PacketTypes.TogglePvp:
                        {
                            //Console.WriteLine("(SendData) PvP ->  1: {0}, 2: {4}, 3: {5}, 4: {6}, 5: {1}, remote: {2}, ignore: {3}", e.number, e.number5, e.remoteClient, e.ignoreClient, e.number2, e.number3, e.number4);
                            if (e.remoteClient == -1)
                            {
                                var player = PlayerList[e.number];
                                if (player != null && player.Faction != null)
                                {
                                    for (int i = 0; i < PlayerList.Length; i++)
                                    {
                                        if (PlayerList[i] != null)
                                        {
                                            if (!player.Faction.Members.Contains(PlayerList[i].UserID) && PlayerList[i].Faction != null && player.Faction.Allies.Contains(PlayerList[i].Faction.ID))
                                            {
                                                player.TSplayer.TPlayer.hostile = false;
                                               // Console.WriteLine("Player {0} is an ally", PlayerList[i].ID);
                                            }
                                            else
                                            {
                                                player.TSplayer.TPlayer.hostile = player.Faction.Hostile;
                                                //Console.WriteLine("Player {0} is outsider", PlayerList[i].ID);
                                            }
                                            PlayerList[i].TSplayer.SendData(PacketTypes.TogglePvp, "", e.number);
                                        }
                                    }
                                    e.Handled = true;

                                    /*if (e.ignoreClient != -1)
                                    {
                                        e.Handled = true;
                                        NetMessage.SendData((int)PacketTypes.TogglePvp, -1, -1, "", e.number);
                                    }*/
                                }
                            }
                            break;
                        }
                    case PacketTypes.PlayerTeam:
                        {
                            //Console.WriteLine("team change -> 1: {0}, 2: {4}, 3: {5}, 4: {6}, 5: {1}, remote: {2}, ignore: {3}", e.number, e.number5, e.remoteClient, e.ignoreClient, e.number2, e.number3, e.number4);
                            if (e.remoteClient == -1)
                            {
                                var player = PlayerList[e.number];
                                if (player != null)
                                {
                                    int oldteam = player.TSplayer.TPlayer.team;
                                    for (int i = 0; i < PlayerList.Length; i++)
                                    {
                                        if (PlayerList[i] != null)
                                        {
                                            if (PlayerList[i].Faction != null)
                                            {
                                                if (PlayerList[i].Faction.Members.Contains(player.UserID))
                                                    player.TSplayer.TPlayer.team = PlayerList[i].Faction.Team;
                                                else
                                                    player.TSplayer.TPlayer.team = 0;
                                            }
                                            else if (player.Faction != null)
                                                player.TSplayer.TPlayer.team = 0;
                                            else
                                                player.TSplayer.TPlayer.team = oldteam;
                                            //Console.WriteLine("(Send Data) Sending Team Change to {0} for player {1}", PlayerList[i].ID, e.number);
                                            PlayerList[i].TSplayer.SendData(PacketTypes.PlayerTeam, "", e.number);
                                        }
                                    }
                                    player.TSplayer.TPlayer.team = oldteam;
                                }
                                e.Handled = true;
                            }
                            break;
                        }
                }
            }
            catch (Exception ex) { Log.ConsoleError(ex.ToString()); }
        }
Example #11
0
        void onSendData(SendDataEventArgs e)
        {
            try
            {
                if (e.MsgID == PacketTypes.ChatText && e.Handled == false && LastJoinIndex > -1)
                {
                    if (LastJoinIndex < TShock.Players.Length && e.text.EndsWith(" has joined.") && e.number2 == Color.Yellow.R && e.number3 == Color.Yellow.G && e.number4 == Color.Yellow.B)
                    {
                        var tsplr = TShock.Players[LastJoinIndex];
                        LastJoinIndex = -1;

                        if (tsplr == null) return;

                        if (cfg.CustomMessages.ContainsKey(tsplr.Name))
                        {
                            if (cfg.CustomMessages[tsplr.Name].HideJoin)
                                e.Handled = true;
                            else if (cfg.CustomMessages[tsplr.Name].JoinMessage != string.Empty)
                                e.text = string.Format(cfg.CustomMessages[tsplr.Name].JoinMessage, tsplr.Name, tsplr.Country ?? string.Empty);
                        }
                    }
                    else
                        LastJoinIndex = -1;
                }
            }
            catch { }
        }
Example #12
0
        public void OnSendData(SendDataEventArgs e)
        {
            try
            {
                List<int> list = new List<int>();
                for (int i = 0; i < 256; i++)
                {
                    if (FLogoff.offlineindex[i])
                    {
                        list.Add(i);
                    }
                }
                PacketTypes msgID = e.MsgID;
                if (msgID <= PacketTypes.DoorUse)
                {
                    if (msgID != PacketTypes.PlayerSpawn && msgID != PacketTypes.DoorUse)
                    {
                        goto IL_D2;
                    }
                }
                else
                {
                    switch (msgID)
                    {
                        case PacketTypes.PlayerDamage:
                            break;

                        case PacketTypes.ProjectileNew:
                        case PacketTypes.ProjectileDestroy:
                            if (list.Contains(e.ignoreClient) && FLogoff.offlineindex[e.ignoreClient])
                            {
                                e.Handled = true;
                                goto IL_D2;
                            }
                            goto IL_D2;

                        case PacketTypes.NpcStrike:
                            goto IL_D2;

                        default:
                            switch (msgID)
                            {
                                case PacketTypes.EffectHeal:
                                case PacketTypes.Zones:
                                    break;

                                default:
                                    switch (msgID)
                                    {
                                        case PacketTypes.PlayerAnimation:
                                        case PacketTypes.EffectMana:
                                        case PacketTypes.PlayerTeam:
                                            break;

                                        case PacketTypes.PlayerMana:
                                        case PacketTypes.PlayerKillMe:
                                            goto IL_D2;

                                        default:
                                            goto IL_D2;
                                    }
                                    break;
                            }
                            break;
                    }
                }
                if (list.Contains(e.number) && FLogoff.offlineindex[e.number])
                {
                    e.Handled = true;
                }
            IL_D2:
                if (e.number >= 0 && e.number <= 255 && FLogoff.offlineindex[e.number] && e.MsgID == PacketTypes.PlayerUpdate)
                {
                    e.Handled = true;
                }
            }
            catch (Exception)
            {
            }
        }
Example #13
0
        public static void SendData(SendDataEventArgs e)
        {
            if (e.Handled)
                return;
            try
            {
                if (e.MsgID == PacketTypes.ChatText)
                {
                 //   Log.ConsoleInfo(String.Format("ChatText> 1: {0}, 2: {4}, 3: {5}, 4: {6}, 5: {1}, remote: {2}, ignore: {3}", e.number, e.number5, e.remoteClient, e.ignoreClient, e.number2, e.number3, e.number4));
                    int sender = e.ignoreClient; // -1 = system
                    if (sender == -1 && TShock.Config.EnableChatAboveHeads)
                        sender = e.number;
                    if (e.remoteClient == -1) // message to all players
                    {
                        if (e.number5 == 0) // Default message, needs processing
                        {
                            if (sender >= 0 && sender != 255)
                            {
                                var player = PlayerList[sender];
                                if (player != null && !player.InMenu && !player.TSPlayer.mute)
                                {
                                 //   Console.WriteLine("sender {0} in channel {1}", sender, player.Channel);
                                    var playerGroup = player.TSPlayer.Group;
                                    int number1 = 255;
                                    if (TShock.Config.EnableChatAboveHeads)
                                        number1 = e.ignoreClient;
                                    NetMessage.SendData((int)PacketTypes.ChatText, -1, sender, e.text, e.number, e.number2, e.number3, e.number4, player.Channel + 2);
                                }
                            }
                            else
                                NetMessage.SendData((int)PacketTypes.ChatText, -1, -1, e.text, e.number, e.number2, e.number3, e.number4, 1);
                        }
                        else
                        {

                            int channel = e.number5 - 2;
                            MsgType msgType = MsgType.Global;
                            if (channel >= 0)
                            {
                                msgType = MsgType.Channel;
                                if (TShock.Config.EnableChatAboveHeads && sender != -1 && sender != 255)
                                {
                                    TSPlayer tsplr = TShock.Players[sender];
                                    string msg = String.Format(TShock.Config.ChatFormat, tsplr.Group.Name, tsplr.Group.Prefix, tsplr.Name, tsplr.Group.Suffix, e.text);
                                    Channels[channel].AddToLog(new ChatMessage(msg, new Color((byte)e.number2, (byte)e.number3, (byte)e.number4), msgType, sender)); // add to channel log
                                }
                                else
                                    Channels[channel].AddToLog(new ChatMessage(e.text, new Color((byte)e.number2, (byte)e.number3, (byte)e.number4), msgType, sender)); // add to channel log
                            }
                            else
                            {
                                AddLogItem(new ChatMessage(e.text, new Color((byte)e.number2, (byte)e.number3, (byte)e.number4), msgType, sender)); // add to global log
                                if (config.EnableDeathMsgFilter || config.EnableJoinQuitFilter)
                                {
                                    var plyName = StartsWithPlayerName(e.text);
                                    if (plyName != "")
                                    {
                                        if (config.EnableJoinQuitFilter && e.text == String.Format("{0} has joined.", plyName))
                                            msgType = MsgType.Join;
                                        else if (config.EnableJoinQuitFilter && e.text == String.Format("{0} left", plyName))
                                            msgType = MsgType.Quit;
                                        else if (config.EnableDeathMsgFilter && IsDeathMsg(e.text, plyName))
                                            msgType = MsgType.Death;
                                    }
                                }
                            }
                            for (int i = 0; i < PlayerList.Length; i++)
                            {
                                if (PlayerList[i] != null && !PlayerList[i].InMenu && !PlayerList[i].Ignores.Contains(sender) && (msgType == MsgType.Global || channel == PlayerList[i].Channel || (msgType == MsgType.Death && !PlayerList[i].Flags.HasFlag(PlayerSettings.HideDeathMsg)) || ((msgType == MsgType.Join || msgType == MsgType.Quit) && !PlayerList[i].Flags.HasFlag(PlayerSettings.HideJoinQuitMsg))))
                                    NetMessage.SendData((int)PacketTypes.ChatText, PlayerList[i].Index, sender, e.text, e.number, e.number2, e.number3, e.number4, 1); // custom message > e.number5 = 1, e.ignoreClient = sender
                            }

                            String logMessage = String.Format("[Chat][{1}]{2} {0}", e.text, msgType.ToString(), (msgType == MsgType.Channel && Channels[channel] != null) ? String.Format("[{0}]", Channels[channel].Name) : "");
                            Console.WriteLine(logMessage);
                            Log.Data(logMessage);
                        }
                        e.Handled = true;
                    }
                    else // message for player id = e.remoteClient
                    {
                        var player = PlayerList[e.remoteClient];
                        if (player == null)
                            return;
                        if (e.number5 == 0) // default message
                        {
                            if (e.text.StartsWith("(Whisper From)<"))
                            {
                                var senderName = e.text.Substring(15, e.text.IndexOf('>', 14) - 15);
                                var wPly = CAPlayer.GetPlayerByName(senderName);
                                if (wPly != null && player.Ignores.Contains(wPly.Index))  //  Private message from ignored player
                                {
                                    e.Handled = true;
                                    return;
                                }
                            }
                            player.AddToLog(new ChatMessage(e.text, new Color((byte)e.number2, (byte)e.number3, (byte)e.number4), MsgType.Private, sender));
                            if (player.InMenu)
                                e.Handled = true;
                        }
                    }
                }
                else if (e.MsgID == PacketTypes.PlayerInfo)
                {
                   //  Console.WriteLine(String.Format("PlayerInfo> 1: {0}, 2: {4}, 3: {5}, 4: {6}, 5: {1}, remote: {2}, ignore: {3} text: {7}", e.number, e.number5, e.remoteClient, e.ignoreClient, e.number2, e.number3, e.number4, e.text));
                    if (TShock.Config.EnableChatAboveHeads && e.number5 == 0) //default message
                    {
                        var player = PlayerList[e.number];
                        if (player != null)
                        {
                            e.Handled = true;
                            NetMessage.SendData((int)PacketTypes.PlayerInfo, e.remoteClient, e.ignoreClient, String.Format(TShock.Config.ChatFormat, player.TSPlayer.Group.Name, player.TSPlayer.Group.Prefix, player.TSPlayer.Name, player.TSPlayer.Group.Suffix, ""), e.number, e.number2, e.number3, e.number4, 1);
                        }
                    }
                }
            }
            catch (Exception ex) { Log.ConsoleError(ex.ToString()); }
        }
Example #14
0
        private void NetHooks_SendData(SendDataEventArgs e)
        {
            try
            {
                var player = Players.FirstOrDefault(p => p != null && p.Player.Index == e.number);

                switch (e.MsgID)
                {
                    case PacketTypes.DoorUse:
                    case PacketTypes.EffectHeal:
                    case PacketTypes.EffectMana:
                    case PacketTypes.PlayerDamage:
                    case PacketTypes.Zones:
                    case PacketTypes.PlayerAnimation:
                    case PacketTypes.PlayerTeam:
                    case PacketTypes.PlayerSpawn:
                        if (player != null && player.IsGhost)
                        {
                            e.Handled = true;
                        }
                        break;
                    case PacketTypes.ProjectileNew:
                    case PacketTypes.ProjectileDestroy:
                        var ignorePlayer = Players.FirstOrDefault(p => p != null && p.Player.Index == e.ignoreClient);
                        if (ignorePlayer != null && ignorePlayer.IsGhost)
                        {
                            e.Handled = true;
                        }
                        break;
                }

                if (e.number >= 0 && e.number <= 255 && player != null && player.IsGhost)
                {
                    e.Handled = true;
                }
            }
            catch (Exception ex)
            {
                ExtendedLog.Current.Log(ex.ToString());
                Console.WriteLine("An exception occurred, see ExtendedAdmin.log for details.");
            }
        }