示例#1
0
        public static void OnUnkownPacketSend(ref HookContext ctx, ref HookArgs.UnkownSendPacket args)
        {
            switch (args.PacketId)
            {
            case (int)Packets.CLIENT_MOD_GOD:
            {
                NetMessageExtension msg = new NetMessageExtension();

                if (args.RemoteClient != -1)
                {
                    var player = Main.players[args.RemoteClient];

                    if (player.HasClientMod)
                    {
                        if (Server.AllowTDCMRPG)
                        {
                            Server.notifyOps(
                                String.Format("Failed attempt to {0} God Mode on an RPG Server.", true, (args.Number == 1) ? "give" : "remove"));
                            return;
                        }

                        Server.notifyOps(
                            String.Format("{0} {1} God Mode.", true, player.Name, (args.Number == 1) ? "has" : "doesn't have"));

                        msg.GodTDCMClient(args.Number == 1);
                        args.Message = msg;
                        ctx.SetResult(HookResult.IGNORE);         //Let TDSM know it's to ignore returning.
                    }
                }
                break;
            }
            }
        }
        public static int SendData(int packetId, int remoteClient = -1, int ignoreClient = -1, string text = "", int number = 0, float number2 = 0f, float number3 = 0f, float number4 = 0f, int number5 = 0)
        {
            if (!NetPlay.anyClients)
            {
                return(0);
            }

            try
            {
                var msg = PrepareThreadInstance();

                switch (packetId)
                {
                case (int)Packet.CONNECTION_REQUEST:
                    msg.ConnectionRequest(Statics.CURRENT_TERRARIA_RELEASE_STR);
                    break;

                case (int)Packet.DISCONNECT:
                    msg.Disconnect(text);
                    break;

                case (int)Packet.CONNECTION_RESPONSE:
                    msg.ConnectionResponse(remoteClient);
                    break;

                case (int)Packet.PLAYER_DATA:
                    msg.PlayerData(number);
                    break;

                case (int)Packet.INVENTORY_DATA:
                    msg.InventoryData(number, (byte)number2, (int)number3);
                    break;

                case (int)Packet.WORLD_REQUEST:
                    msg.WorldRequest();
                    break;

                case (int)Packet.WORLD_DATA:
                    msg.WorldData();
                    break;

                case (int)Packet.REQUEST_TILE_BLOCK:
                    msg.RequestTileBlock();
                    break;

                case (int)Packet.SEND_TILE_LOADING:
                    msg.SendTileLoading(number, text);
                    break;

                case (int)Packet.SEND_TILE_ROW:
                    msg.SendTileRow(number, (int)number2, (int)number3);
                    break;

                case (int)Packet.SEND_TILE_CONFIRM:
                    msg.SendTileConfirm(number, (int)number2, (int)number3, (int)number4);
                    break;

                case (int)Packet.RECEIVING_PLAYER_JOINED:
                    msg.ReceivingPlayerJoined(number);
                    break;

                case (int)Packet.PLAYER_STATE_UPDATE:
                    msg.PlayerStateUpdate(number);
                    break;

                case (int)Packet.SYNCH_BEGIN:
                    msg.SynchBegin(number, (int)number2);
                    break;

                case (int)Packet.UPDATE_PLAYERS:
                    msg.UpdatePlayers();
                    break;

                case (int)Packet.PLAYER_HEALTH_UPDATE:
                    msg.PlayerHealthUpdate(number);
                    break;

                case (int)Packet.TILE_BREAK:
                    msg.TileBreak(number, (int)number2, (int)number3, (int)number4, (int)number5);
                    break;

                case (int)Packet.TIME_SUN_MOON_UPDATE:
                    msg.TimeSunMoonUpdate();
                    break;

                case (int)Packet.DOOR_UPDATE:
                    msg.DoorUpdate(number, (int)number2, (int)number3, (int)number4);
                    break;

                case (int)Packet.TILE_SQUARE:
                    msg.TileSquare(number, (int)number2, (int)number3);
                    break;

                case (int)Packet.ITEM_INFO:
                    msg.ItemInfo(number);
                    break;

                case (int)Packet.ITEM_OWNER_INFO:
                    msg.ItemOwnerInfo(number);
                    break;

                case (int)Packet.NPC_INFO:
                    msg.NPCInfo(number);
                    break;

                case (int)Packet.STRIKE_NPC:
                    msg.StrikeNPC(number, (int)number2);
                    break;

                case (int)Packet.PLAYER_CHAT:
                    msg.PlayerChat(number, text, (byte)number2, (byte)number3, (byte)number4);
                    break;

                case (int)Packet.STRIKE_PLAYER:
                    msg.StrikePlayer(number, text, (int)number2, (int)number3, (int)number4);
                    break;

                case (int)Packet.PROJECTILE:
                    msg.Projectile(Main.projectile[number]);
                    break;

                case (int)Packet.DAMAGE_NPC:
                    msg.DamageNPC(number, (int)number2, number3, (int)number4);
                    break;

                case (int)Packet.KILL_PROJECTILE:
                    msg.KillProjectile(number, (int)number2);
                    break;

                case (int)Packet.PLAYER_PVP_CHANGE:
                    msg.PlayerPVPChange(number);
                    break;

                case (int)Packet.OPEN_CHEST:
                    msg.OpenChest();
                    break;

                case (int)Packet.CHEST_ITEM:
                    msg.ChestItem(number, (int)number2);
                    break;

                case (int)Packet.PLAYER_CHEST_UPDATE:
                    msg.PlayerChestUpdate(number);
                    break;

                case (int)Packet.KILL_TILE:
                    msg.KillTile();
                    break;

                case (int)Packet.HEAL_PLAYER:
                    msg.HealPlayer(number, (int)number2);
                    break;

                case (int)Packet.ENTER_ZONE:
                    msg.EnterZone(number);
                    break;

                case (int)Packet.PASSWORD_REQUEST:
                    msg.PasswordRequest();
                    break;

                case (int)Packet.PASSWORD_RESPONSE:
                    msg.PasswordResponse();
                    break;

                case (int)Packet.ITEM_OWNER_UPDATE:
                    msg.ItemOwnerUpdate(number);
                    break;

                case (int)Packet.NPC_TALK:
                    msg.NPCTalk(number);
                    break;

                case (int)Packet.PLAYER_BALLSWING:
                    msg.PlayerBallswing(number);
                    break;

                case (int)Packet.PLAYER_MANA_UPDATE:
                    msg.PlayerManaUpdate(number);
                    break;

                case (int)Packet.PLAYER_USE_MANA_UPDATE:
                    msg.PlayerUseManaUpdate(number, (int)number2);
                    break;

                case (int)Packet.KILL_PLAYER_PVP:
                    msg.KillPlayerPVP(number, text, (int)number2, (int)number3, (int)number4);
                    break;

                case (int)Packet.PLAYER_JOIN_PARTY:
                    msg.PlayerJoinParty(number);
                    break;

                case (int)Packet.READ_SIGN:
                    msg.ReadSign(number, (int)number2);
                    break;

                case (int)Packet.WRITE_SIGN:
                    msg.WriteSign(number);
                    break;

                case (int)Packet.FLOW_LIQUID:
                    msg.FlowLiquid(number, (int)number2);
                    break;

                case (int)Packet.SEND_SPAWN:
                    msg.SendSpawn();
                    break;

                case (int)Packet.PLAYER_BUFFS:
                    msg.PlayerBuffs(number);
                    break;

                case (int)Packet.SUMMON_SKELETRON:
                    msg.SummonSkeletron((byte)number, (byte)number2);
                    break;

                case (int)Packet.CHEST_UNLOCK:
                    msg.ChestUnlock(number, (int)number2, (int)number3, (int)number4);
                    break;

                case (int)Packet.NPC_ADD_BUFF:
                    msg.NPCAddBuff(number, (int)number2, (int)number3);
                    break;

                case (int)Packet.NPC_BUFFS:
                    msg.NPCBuffs(number);
                    break;

                case (int)Packet.PLAYER_ADD_BUFF:
                    msg.PlayerAddBuff(number, (int)number2, (int)number3);
                    break;

                case (int)Packet.CLIENT_MOD:
                    msg.ClientMod(remoteClient);
                    break;

                case (int)Packet.CLIENT_MOD_SPAWN_NPC:
                    msg.RpgNPCSpawned(number);
                    break;

                case (int)Packet.NPC_NAME:
                    msg.NPCName(number, Main.chrName[number]);
                    break;

                default:
                {
                    //Unknown packet :3
                    var ctx = new HookContext()
                    {
                    };

                    var args = new HookArgs.UnkownSendPacket()
                    {
                        Message      = msg,
                        PacketId     = packetId,
                        RemoteClient = remoteClient,
                        IgnoreClient = ignoreClient,
                        Text         = text,
                        Number       = number,
                        Number2      = number2,
                        Number3      = number3,
                        Number4      = number4,
                        Number5      = number5
                    };

                    HookPoints.UnkownSendPacket.Invoke(ref ctx, ref args);

                    /* Update Locals */
                    msg          = args.Message;
                    remoteClient = args.RemoteClient;
                    ignoreClient = args.IgnoreClient;

                    if (ctx.Result != HookResult.IGNORE)
                    {
                        return(0);
                    }
                    else
                    {
                        break;
                    }
                }
                }

                //var bytes = msg.Output;
                if (remoteClient == -1)
                {
                    msg.BroadcastExcept(ignoreClient);
//					for (int num11 = 0; num11 < 256; num11++)
//					{
//						if (num11 != ignoreClient && Netplay.slots[num11].state >= SlotState.PLAYING && Netplay.slots[num11].Connected)
//						{
//							NetMessage.buffer[num11].spamCount++;
//							Netplay.slots[num11].Send (bytes);
//						}
//					}
                }
                else if (NetPlay.slots[remoteClient].Connected)
                {
                    msg.Send(remoteClient);
                    //NetMessage.buffer[remoteClient].spamCount++;
                    //Netplay.slots[remoteClient].Send (bytes);
                }
                return(msg.Written);
            }
            catch (Exception e)
            {
                ProgramLog.Log(e, "SendData error");
            }
            return(0);
        }