Example #1
0
        private bool InvokeNetSendData(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)
        {
            // TODO
            // This can be removed because our msgType is never going to be ChatText
            //if (Main.netMode != 2 && msgType == (int)PacketTypes.ChatText && this.InvokeClientChat(ref text))
            //    return true;

            SendDataEventArgs args = new SendDataEventArgs
            {
                MsgId = (PacketTypes)msgType,
                remoteClient = remoteClient,
                ignoreClient = ignoreClient,
                text = text,
                number = number,
                number2 = number2,
                number3 = number3,
                number4 = number4,
                number5 = number5
            };

            ServerApi.Hooks.NetSendData.Invoke(args);

            msgType = (int)args.MsgId;
            remoteClient = args.remoteClient;
            ignoreClient = args.ignoreClient;
            text = args.text;
            number = args.number;
            number2 = args.number2;
            number3 = args.number3;
            number4 = args.number4;
            number5 = args.number5;
            return args.Handled;
        }
Example #2
0
        internal bool InvokeNetSendData(
            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 (Main.netMode != 2 && msgType == (int)PacketTypes.ChatText && this.InvokeClientChat(ref text))
            {
                return(true);
            }

            SendDataEventArgs args = new SendDataEventArgs
            {
                MsgId        = (PacketTypes)msgType,
                remoteClient = remoteClient,
                ignoreClient = ignoreClient,
                text         = text,
                number       = number,
                number2      = number2,
                number3      = number3,
                number4      = number4,
                number5      = number5
            };

            this.NetSendData.Invoke(args);

            msgType      = (int)args.MsgId;
            remoteClient = args.remoteClient;
            ignoreClient = args.ignoreClient;
            text         = args.text;
            number       = args.number;
            number2      = args.number2;
            number3      = args.number3;
            number4      = args.number4;
            number5      = args.number5;
            return(args.Handled);
        }
Example #3
0
        internal bool InvokeNetSendData(
            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,
            ref int number6, ref int number7)
        {
            SendDataEventArgs args = new SendDataEventArgs
            {
                MsgId        = (PacketTypes)msgType,
                remoteClient = remoteClient,
                ignoreClient = ignoreClient,
                text         = text,
                number       = number,
                number2      = number2,
                number3      = number3,
                number4      = number4,
                number5      = number5,
                number6      = number6,
                number7      = number7
            };

            this.NetSendData.Invoke(args);

            msgType      = (int)args.MsgId;
            remoteClient = args.remoteClient;
            ignoreClient = args.ignoreClient;
            text         = args.text;
            number       = args.number;
            number2      = args.number2;
            number3      = args.number3;
            number4      = args.number4;
            number5      = args.number5;
            number6      = args.number6;
            number7      = args.number7;
            return(args.Handled);
        }
Example #4
0
 /// <summary>NetHooks_SendData - Fired when the server sends data.</summary>
 /// <param name="e">e - The SendDataEventArgs object.</param>
 private void NetHooks_SendData(SendDataEventArgs e)
 {
     if (e.MsgId == PacketTypes.PlayerHp)
     {
         if (Main.player[(byte)e.number].statLife <= 0)
         {
             e.Handled = true;
             return;
         }
     }
 }
        public void OnSendData(SendDataEventArgs e)
        {
            try
            {
                List<int> ghostIDs = new List<int>();
                foreach (Mplayer player in Players)
                {
                    if (player.isGhost)
                        ghostIDs.Add(player.Index);
                }

                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)) && (Utils.GetPlayers(e.number).isGhost))
                            {
                                e.Handled = true;
                            }
                        }
                        break;

                    case PacketTypes.ProjectileNew:
                    case PacketTypes.ProjectileDestroy:
                        {
                            if ((ghostIDs.Contains(e.ignoreClient)) && (Utils.GetPlayers(e.ignoreClient).isGhost))
                                e.Handled = true;
                        }
                        break;

                    default: break;
                }

                if ((e.number >= 0) && (e.number <= 255) && (Utils.GetPlayers(e.number).isGhost))
                {
                    if ((!cansend) && (e.MsgId == PacketTypes.PlayerUpdate))
                    {
                        e.Handled = true;
                    }
                }
            }
            catch (Exception) { }
        }
		internal bool InvokeNetSendData(
			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 (Main.netMode != 2 && msgType == (int)PacketTypes.ChatText && this.InvokeClientChat(ref text))
				return true;

			SendDataEventArgs args = new SendDataEventArgs
			{
				MsgId = (PacketTypes)msgType, 
				remoteClient = remoteClient, 
				ignoreClient = ignoreClient, 
				text = text, 
				number = number, 
				number2 = number2, 
				number3 = number3, 
				number4 = number4,
				number5 = number5
			};

			this.NetSendData.Invoke(args);

			msgType = (int)args.MsgId;
			remoteClient = args.remoteClient;
			ignoreClient = args.ignoreClient;
			text = args.text;
			number = args.number;
			number2 = args.number2;
			number3 = args.number3;
			number4 = args.number4;
			number5 = args.number5;
			return args.Handled;
		}
Example #7
0
        /// <summary>
        /// Occurs when the server has a chunk of data to send
        /// </summary>
        protected void NetHooks_SendData(SendDataEventArgs e)
        {
            try {
                if (e.MsgId == PacketTypes.PlayerDamage) {
                    //occurs when a player hits another player.  ignoreClient is the player that hit, e.number is the
                    //player that got hit, and e.number4 is a flag indicating PvP damage

                    if (Convert.ToBoolean(e.number4) && Terraria.Main.player[e.number] != null) {
                        PlayerHitPlayer(e.ignoreClient, e.number);
                    }
                } else if (e.MsgId == PacketTypes.PlayerKillMe) {
                    //Occrs when the player dies.
                    ProcessDeath(e.number, Convert.ToBoolean(e.number4));
                }
            } catch {

            }
        }
Example #8
0
 void OnSendData(SendDataEventArgs e)
 {
     if (e.MsgId == PacketTypes.ChatText && !e.Handled)
     {
         if (Config.DisableBossMessages && e.number2 == 175 && e.number3 == 75 && e.number4 == 255)
         {
             if (e.text.StartsWith("Eye of Cthulhu") || e.text.StartsWith("Eater of Worlds") ||
                 e.text.StartsWith("Skeletron") || e.text.StartsWith("King Slime") ||
                 e.text.StartsWith("The Destroyer") || e.text.StartsWith("The Twins") ||
                 e.text.StartsWith("Skeletron Prime") || e.text.StartsWith("Wall of Flesh") ||
                 e.text.StartsWith("Plantera") || e.text.StartsWith("Golem") || e.text.StartsWith("Brain of Cthulhu") ||
                 e.text.StartsWith("Queen Bee") || e.text.StartsWith("Duke Fishron"))
             {
                 e.Handled = true;
             }
         }
         if (Config.DisableOrbMessages && e.number2 == 50 && e.number3 == 255 && e.number4 == 130)
         {
             if (e.text == "A horrible chill goes down your spine..." ||
                 e.text == "Screams echo around you...")
             {
                 e.Handled = true;
             }
         }
     }
 }
Example #9
0
 void onSendData(SendDataEventArgs e)
 {
     try
     {
         if (e.MsgId == PacketTypes.NpcUpdate)
         {
             foreach (var dPly in dPlayers)
             {
                 if (dPly != null && dPly.NPCIndex == e.number)
                 {
                     e.ignoreClient = dPly.Index;
                 }
             }
         }
         if (e.MsgId == PacketTypes.PlayerUpdate)
         {
             if (dPlayers[e.ignoreClient].Disguised && dPlayers[e.ignoreClient].NPCIndex > -1)
             {
                 var dPly = dPlayers[e.ignoreClient];
                 int npcid = dPly.NPCIndex;
                 if (Main.npc[npcid] == null || !Main.npc[npcid].active)
                 {
                     npcid = NPC.NewNPC(dPly.tsPlayer.TileX * 16, dPly.tsPlayer.TileY * 16, dPly.DisguiseNPC, 0);
                     Main.npc[npcid].SetDefaults(dPly.DisguiseNPCname);
                     dPly.NPCIndex = npcid;
                 }
                 Main.npc[npcid].position = Main.player[e.ignoreClient].position;
                 Main.npc[npcid].velocity = Main.player[e.ignoreClient].velocity;
                 Main.npc[npcid].target = -1;
                 Main.npc[npcid].direction = Main.player[e.ignoreClient].direction;
                 Main.npc[npcid].directionY = 0;
                 Main.npc[npcid].life = Main.npc[npcid].lifeMax;
                 Main.npc[npcid].netID = dPly.DisguiseNPC;
                 e.MsgId = PacketTypes.NpcUpdate;
                 e.number =  npcid;
             }
         }
     }
     catch { }
 }
Example #10
0
		internal bool InvokeNetSendData(
			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,
			ref int number6, ref int number7)
		{

			SendDataEventArgs args = new SendDataEventArgs
			{
				MsgId = (PacketTypes)msgType,
				remoteClient = remoteClient,
				ignoreClient = ignoreClient,
				text = text,
				number = number,
				number2 = number2,
				number3 = number3,
				number4 = number4,
				number5 = number5,
				number6 = number6,
				number7 = number7
			};

			this.NetSendData.Invoke(args);

			msgType = (int)args.MsgId;
			remoteClient = args.remoteClient;
			ignoreClient = args.ignoreClient;
			text = args.text;
			number = args.number;
			number2 = args.number2;
			number3 = args.number3;
			number4 = args.number4;
			number5 = args.number5;
			number6 = args.number6;
			number7 = args.number7;
			return args.Handled;
		}
Example #11
0
 /// <summary>
 /// NetSendData callback.
 /// </summary>
 /// <param name="args"></param>
 private void OnNetSendData(SendDataEventArgs args)
 {
     lock (this.m_AddonsLock)
     {
         this.m_Addons.ForEach(a =>
             {
                 var ret = a.Value.InvokeEvent("NetSendData", args.ignoreClient, args.remoteClient, (int)args.MsgId, args.number, args.number2, args.number3, args.number4, args.number5, args.text);
                 if (ret != null && ret.Length >= 1)
                 {
                     bool result;
                     if (bool.TryParse(ret[0].ToString(), out result) && result)
                         args.Handled = true;
                 }
             });
     }
 }
Example #12
0
		void OnSendData(SendDataEventArgs e)
		{
			switch (e.MsgId)
			{
				case PacketTypes.NpcUpdate:
					DoNpcUpdate(e.number);
					break;
			}
		}
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);
                            TShock.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) { TShock.Log.ConsoleError(ex.ToString()); }
        }
Example #14
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 #15
0
		private void OnSendData(SendDataEventArgs args)
		{
			if (args.MsgId != PacketTypes.ItemDrop)
			{
				return;
			}
			int number = args.number;
			if (this._playerDropsPending.Count > 0 && number < 400)
			{
				Item item = Main.item[number];
				ItemDrop itemDrop = this._playerDropsPending.FirstOrDefault((ItemDrop x) => x.NetworkId == item.netID && x.Stack == item.stack && x.Prefix == item.prefix);
				if (itemDrop != null)
				{
					this._drops[number] = itemDrop;
					this._playerDropsPending.Remove(itemDrop);
				}
			}
		}
Example #16
0
File: Main.cs Project: ja450n/Vault
        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 #17
0
 public void SendData(SendDataEventArgs e)
 {
     if (e.MsgId == PacketTypes.WorldInfo)
     {
         if (e.remoteClient == -1)
         {
             for (int i = 0; i < TShock.Players.Length; i++)
             {
                 if (TShock.Players[i] != null && TShock.Players[i].Active && !DayClients.Contains(TShock.Players[i].Index))
                     TShock.Players[i].SendData(PacketTypes.WorldInfo);
             }
             e.Handled = true;
         }
     }
 }
Example #18
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;
                return;
            }
            else if (e.MsgId == PacketTypes.WorldInfo)
            {
                if (e.remoteClient == -1) return;
                var player = Players[e.remoteClient];
                if (player == null) return;
                using (var ms = new MemoryStream())
                {
                    var msg = new WorldInfoMsg
                    {
                        Time = (int)Main.time,
                        DayTime = Main.dayTime,
                        MoonPhase = (byte)Main.moonPhase,
                        BloodMoon = Main.bloodMoon,
                        Eclipse = Main.eclipse,
                        MaxTilesX = (short)Main.maxTilesX,
                        MaxTilesY = (short)Main.maxTilesY,
                        SpawnX = (short)Main.spawnTileX,
                        SpawnY = (short)Main.spawnTileY,
                        WorldSurface = (short)Main.worldSurface,
                        RockLayer = (short)Main.rockLayer,
                        //Sending a fake world id causes the client to not be able to find a stored spawnx/y.
                        //This fixes the bed spawn point bug. With a fake world id it wont be able to find the bed spawn.
                        WorldID = Main.worldID,
                        MoonType = (byte)Main.moonType,
                        TreeX0 = Main.treeX[0],
                        TreeX1 = Main.treeX[1],
                        TreeX2 = Main.treeX[2],
                        TreeStyle0 = (byte)Main.treeStyle[0],
                        TreeStyle1 = (byte)Main.treeStyle[1],
                        TreeStyle2 = (byte)Main.treeStyle[2],
                        TreeStyle3 = (byte)Main.treeStyle[3],
                        CaveBackX0 = Main.caveBackX[0],
                        CaveBackX1 = Main.caveBackX[1],
                        CaveBackX2 = Main.caveBackX[2],
                        CaveBackStyle0 = (byte)Main.caveBackStyle[0],
                        CaveBackStyle1 = (byte)Main.caveBackStyle[1],
                        CaveBackStyle2 = (byte)Main.caveBackStyle[2],
                        CaveBackStyle3 = (byte)Main.caveBackStyle[3],
                        SetBG0 = (byte)WorldGen.treeBG,
                        SetBG1 = (byte)WorldGen.corruptBG,
                        SetBG2 = (byte)WorldGen.jungleBG,
                        SetBG3 = (byte)WorldGen.snowBG,
                        SetBG4 = (byte)WorldGen.hallowBG,
                        SetBG5 = (byte)WorldGen.crimsonBG,
                        SetBG6 = (byte)WorldGen.desertBG,
                        SetBG7 = (byte)WorldGen.oceanBG,
                        IceBackStyle = (byte)Main.iceBackStyle,
                        JungleBackStyle = (byte)Main.jungleBackStyle,
                        HellBackStyle = (byte)Main.hellBackStyle,
                        WindSpeed = Main.windSpeed,
                        NumberOfClouds = (byte)Main.numClouds,
                        BossFlags = (WorldGen.shadowOrbSmashed ? BossFlags.OrbSmashed : BossFlags.None) |
                                    (NPC.downedBoss1 ? BossFlags.DownedBoss1 : BossFlags.None) |
                                    (NPC.downedBoss2 ? BossFlags.DownedBoss2 : BossFlags.None) |
                                    (NPC.downedBoss3 ? BossFlags.DownedBoss3 : BossFlags.None) |
                                    (Main.hardMode ? BossFlags.HardMode : BossFlags.None) |
                                    (NPC.downedClown ? BossFlags.DownedClown : BossFlags.None) |
                                    (Main.ServerSideCharacter ? BossFlags.ServerSideCharacter : BossFlags.None) |
                                    (NPC.downedPlantBoss ? BossFlags.DownedPlantBoss : BossFlags.None),
                        BossFlags2 = (NPC.downedMechBoss1 ? BossFlags2.DownedMechBoss1 : BossFlags2.None) |
                                     (NPC.downedMechBoss2 ? BossFlags2.DownedMechBoss2 : BossFlags2.None) |
                                     (NPC.downedMechBoss3 ? BossFlags2.DownedMechBoss3 : BossFlags2.None) |
                                     (NPC.downedMechBossAny ? BossFlags2.DownedMechBossAny : BossFlags2.None) |
                                     (Main.cloudBGActive >= 1f ? BossFlags2.CloudBg : BossFlags2.None) |
                                     (WorldGen.crimson ? BossFlags2.Crimson : BossFlags2.None) |
                                     (Main.pumpkinMoon ? BossFlags2.PumpkinMoon : BossFlags2.None) |
                                     (Main.snowMoon ? BossFlags2.SnowMoon : BossFlags2.None) ,
                        Rain = Main.maxRaining,
                        WorldName = TShock.Config.UseServerName ? TShock.Config.ServerName : Main.worldName
                    };
                    msg.PackFull(ms);
                    player.SendRawData(ms.ToArray());
                }
                e.Handled = true;
                return;
            }
            else if (e.MsgId == PacketTypes.PlayerHp)
            {
                if (Main.player[(byte)e.number].statLife <= 0)
                {
                    e.Handled = true;
                    return;
                }
            }
        }
Example #19
0
        public void SendData(SendDataEventArgs e)
        {
            if (e.MsgId == PacketTypes.WorldInfo)
            {
                if (e.remoteClient == -1)
                {
                    double temp = Main.time;
                    bool tempday = Main.dayTime;
                    for (int i = 0; i < TShock.Players.Length; i++)
                    {
                        TSPlayer plr = TShock.Players[i];
                        if (plr == null || plr.Active == false)
                            continue;

                        if (playertime.ContainsKey(plr.Index))
                        {
                            Main.dayTime = playertime[plr.Index].day;
                            Main.time = playertime[plr.Index].frames;
                        }

                        if (!DayClients.Contains(plr.Index))
                            plr.SendData(PacketTypes.WorldInfo);
                    }
                    e.Handled = true;
                    Main.time = temp;
                    Main.dayTime = tempday;
                }
            }

            if (e.MsgId == PacketTypes.TimeSet)
            {
                if (e.remoteClient == -1)
                {
                    foreach (TSPlayer plr in TShock.Players)
                    {
                        if (plr == null || !plr.Active)
                            continue;

                        if (playertime.ContainsKey(plr.Index))
                            continue;

                        plr.SendData(PacketTypes.TimeSet);
                    }

                    e.Handled = true;
                }
            }
        }