Пример #1
0
        public void OnDamage( object sender, TShockAPI.GetDataHandlers.PlayerDamageEventArgs args )
        {
            Region r = TShock.Regions.GetTopRegion(
                TShock.Regions.InAreaRegion((int)Main.player[args.ID].position.X / 16, (int)Main.player[args.ID].position.Y / 16));
            if( r != null )
            {
               FlaggedRegion reg = regionManager.getRegion(r.Name);
               if (reg != null)
               {
                   List<Flags> flags = reg.getFlags();
                   if( flags.Contains( Flags.HEALONDAMAGE ) )
                   {
                       int heal = 0;
                       int damage = Math.Max(args.Damage*(args.Critical ? 2 : 1) -
                                    (int)(Math.Round(Main.player[args.ID].statDefense * .5)), 1);

                       var items = TShock.Utils.GetItemByIdOrName("heart");
                       while(heal < damage)
                       {
                           Utilities.GiveItem(items[0].name, (int)Main.player[args.ID].position.X, (int)Main.player[args.ID].position.Y, items[0].width,
                                items[0].height, items[0].type, 1, items[0].prefix, args.ID, Main.player[args.ID].velocity);
                           heal += 20;
                       }
                   }
               }
            }
        }
Пример #2
0
		private async void TShockAPI_JistChatCommand(TShockAPI.CommandArgs args)
		{
			if (args.Parameters.Count == 0) {
				//TODO: Print help
				return;
			}

			if (args.Parameters[0].Equals("dumpenv", StringComparison.CurrentCultureIgnoreCase)) {
				if (Instance == null) {
					return;
				}

				foreach (var property in Instance.DumpGlobalEnvironment().OrderBy(i => i.Key)) {
					args.Player.SendInfoMessage("{0}: {1}", property.Key,
						property.Value.Get.HasValue == false ? "undefined" : property.Value.Get.Value.ToString());
				}
			} else if (args.Parameters[0].Equals("dumptasks", StringComparison.CurrentCultureIgnoreCase)) {
				foreach (Wolfje.Plugins.Jist.stdlib.RecurringFunction recur in Instance.stdTask.DumpTasks().OrderBy(i => i.NextRunTime)) {
					args.Player.SendInfoMessage(recur.ToString());
				}
			} else if (args.Parameters[0].Equals("eval", StringComparison.CurrentCultureIgnoreCase)
			                    || args.Parameters[0].Equals("ev", StringComparison.CurrentCultureIgnoreCase)
			                    && (args.Parameters.Count > 1)) {
				args.Player.SendInfoMessage(Instance.Eval(args.Parameters[1]));
			} else if (args.Parameters[0].Equals("reload", StringComparison.CurrentCultureIgnoreCase)
			                    || args.Parameters[0].Equals("rl", StringComparison.CurrentCultureIgnoreCase)) {
				Instance.Dispose();
				Instance = null;
				Instance = new JistEngine(this);
				await Instance.LoadEngineAsync();
				args.Player.SendInfoMessage("Jist reloaded");
			}
		}
Пример #3
0
 public static void LoadQuestData(TShockAPI.Hooks.ReloadEventArgs args)
 {
     QTools.LoadPlayers();
     QTools.LoadQuests();
     QTools.LoadRegions();
     args.Player.SendMessage("Successfully reloaded QuestSystem data.", Color.Yellow);
 }
Пример #4
0
 public override void Execute(TShockAPI.CommandArgs args)
 {
     args.Player.SendMessage("Avialable Boxes commands:");
     args.Player.SendMessage("" +  Commands.SLASH_COMMAND + " set [1/2] " +  Commands.SLASH_COMMAND + " define [boxName] " +  Commands.SLASH_COMMAND + " protect [boxName] [true/false]");
     args.Player.SendMessage("" +  Commands.SLASH_COMMAND + " name (provides boxName)");
     args.Player.SendMessage("" +  Commands.SLASH_COMMAND + " delete [boxName] " +  Commands.SLASH_COMMAND + " clear (temporary box)");
     args.Player.SendMessage("" +  Commands.SLASH_COMMAND + " allow [playerName] [boxName]");
     args.Player.SendMessage("" +  Commands.SLASH_COMMAND + " resize [boxname] [u/d/l/r] [amount]");
 }
Пример #5
0
        /// <summary>Checks whether a given player is near a given region.</summary>
        /// <param name="tPlayer">The player to check</param>
        /// <param name="area">The region to check</param>
        /// <returns>true if the player is within 100 tiles of the region; false otherwise</returns>
        public static bool isPlayerNearby(TShockAPI.TSPlayer tPlayer, Rectangle area)
        {
            int playerX = (int) (tPlayer.X / 16);
            int playerY = (int) (tPlayer.Y / 16);

            return playerX >= area.Left   - NearRange &&
                   playerX <= area.Right  + NearRange &&
                   playerY >= area.Top    - NearRange &&
                   playerY <= area.Bottom + NearRange;
        }
        /// <summary>
        /// Invokes a command ignoring permissions
        /// </summary>
        public static bool RunWithoutPermissions(this TShockAPI.Command cmd, string msg, TShockAPI.TSPlayer ply, List<string> parms) {
            try {
                TShockAPI.CommandDelegate cmdDelegateRef = SEconomyPlugin.GetPrivateField<TShockAPI.CommandDelegate>(cmd.GetType(), cmd, "command");

                cmdDelegateRef(new TShockAPI.CommandArgs(msg, ply, parms));
            } catch (Exception e) {
                ply.SendErrorMessage("Command failed, check logs for more details.");
                TShockAPI.Log.Error(e.ToString());
            }

            return true;
        }
Пример #7
0
 public void OnItemDrop(object sender, TShockAPI.GetDataHandlers.ItemDropEventArgs args)
 {
     var reg =
         TShock.Regions.GetTopRegion(TShock.Regions.InAreaRegion((int)args.Position.X / 16, (int)args.Position.Y / 16));
     if (reg != null)
     {
         var freg = regionManager.getRegion(reg.Name);
         if (freg != null && freg.getFlags().Contains(Flags.NOITEM))
         {
             Main.item[args.ID].SetDefaults(0);
             args.Handled = true;
         }
     }
 }
Пример #8
0
		/// <summary>
		/// Occurs when someone executes an alias command
		/// </summary>
		internal void ChatCommand_AliasExecuted(TShockAPI.CommandArgs e)
		{
			string commandIdentifier = e.Message;

			if (!string.IsNullOrEmpty(e.Message)) {
				commandIdentifier = e.Message.Split(' ').FirstOrDefault();
			}

			if (AliasExecuted != null) {
				AliasExecutedEventArgs args = new AliasExecutedEventArgs() {
					CommandIdentifier = commandIdentifier,
					CommandArgs = e
				};

				AliasExecuted(this, args);
			}
		}
Пример #9
0
		protected async void ChatCommand_GeneralCommand(TShockAPI.CommandArgs args)
		{
			if (args.Parameters.Count >= 1 && args.Parameters[0].Equals("reload", StringComparison.CurrentCultureIgnoreCase) && args.Player.Group.HasPermission("aliascmd.reloadconfig")) {
				args.Player.SendInfoMessage("aliascmd: Reloading configuration file.");

				try {
					await ReloadConfigAfterDelayAsync(1);
					args.Player.SendInfoMessage("aliascmd: reloading complete.");
				} catch (Exception ex) {
					args.Player.SendErrorMessage("aliascmd: reload failed.  You need to check the server console to find out what went wrong.");
					TShock.Log.ConsoleError("aliascmd reload: Cannot load configuration: {0}", ex.Message);
				}

			} else {
				args.Player.SendErrorMessage("aliascmd: usage: /aliascmd reload: reloads the AliasCmd configuration file.");
			}
		}
Пример #10
0
        private void ChatCommand_GeneralCommand(TShockAPI.CommandArgs args) {

            if (args.Parameters.Count >= 1 && args.Parameters[0].Equals("reload", StringComparison.CurrentCultureIgnoreCase) && args.Player.Group.HasPermission("aliascmd.reloadconfig")) {
                args.Player.SendInfoMessage("aliascmd: Reloading configuration file.");

                ReloadConfigAfterDelayAsync(1).ContinueWith((task) => {
                    if (task.IsFaulted) {
                        args.Player.SendErrorMessage("aliascmd: reload failed.  You need to check the server console to find out what went wrong.");
                        TShockAPI.Log.ConsoleError(task.Exception.ToString());
                    } else {
                        args.Player.SendInfoMessage("aliascmd: reload successful.");
                    }
                });
            } else {
                args.Player.SendErrorMessageFormat("aliascmd: usage: /aliascmd reload: reloads the AliasCmd configuration file.");
            }

        }
Пример #11
0
        public void applyPotion(TShockAPI.TSPlayer ply)
        {
            if( ply.Group.HasPermission( perm ) )
            {
                int l = Math.Min(10, potions.Count);

                for (int i = 0; i < l; i++)
                {
                    ply.SetBuff(potions[i], 60*( length ), true );
                }

                ply.SendMessage( String.Format( "Potion {0} has been applied for {1}", name, length), Color.Green );
            }
            else
            {
                ply.SendMessage( "You do not have permission for this potion.", Color.Red );
            }
        }
Пример #12
0
 public void OnDamage( object sender, TShockAPI.GetDataHandlers.PlayerDamageEventArgs args )
 {
     Region r = TShock.Regions.GetTopRegion(
         TShock.Regions.InAreaRegion((int)Main.player[args.ID].position.X / 16, (int)Main.player[args.ID].position.Y / 16));
     if( r != null )
     {
        FlaggedRegion reg = regionManager.getRegion(r.Name);
        if (reg != null)
        {
            List<Flags> flags = reg.getFlags();
            if( flags.Contains( Flags.HEAL ) )
            {
                var items = TShock.Utils.GetItemByIdOrName("heart");
                GiveItem(items[0].name, (int)Main.player[args.ID].position.X, (int)Main.player[args.ID].position.Y, items[0].width,
                    items[0].height, items[0].type, 10, items[0].prefix, args.ID, Main.player[args.ID].velocity);
            }
        }
     }
 }
Пример #13
0
 public void OnNPCStrike( object sender, TShockAPI.GetDataHandlers.NPCStrikeEventArgs args )
  {
      Region r = TShock.Regions.GetTopRegion( 
          TShock.Regions.InAreaRegion((int)Main.npc[args.ID].position.X / 16, (int)Main.npc[args.ID].position.Y / 16) );
      if( r != null )
      {
         FlaggedRegion reg = regionManager.getRegion(r.Name);
         if (reg != null)
         {
             List<Flags> flags = reg.getFlags();
             if( flags.Contains( Flags.GODMOB ) )
             {
                 args.Handled = true;
                 Main.npc[args.ID].life = Main.npc[args.ID].lifeMax;
                 NetMessage.SendData(23, -1, -1, "", args.ID, 0f, 0f, 0f, 0);
             }
         }
      }
  }
Пример #14
0
        internal void NotifyPlayer(TShockAPI.TSPlayer Player)
        {
            switch (State)
            {
                case VoteState.Captcha:
                    Player.SendSuccessMessage("[TServerWeb] Please enter CAPTCHA!");
                    break;

                case VoteState.Fail:
                    Player.SendSuccessMessage("[TServerWeb] Your previous vote failed! Please wait 5 minutes before trying again!");
                    break;

                case VoteState.InProgress:
                    Player.SendSuccessMessage("[TServerWeb] Your vote is being processed, please wait...");
                    break;

                case VoteState.Success:
                case VoteState.Wait:
                    Player.SendSuccessMessage("[TServerWeb] Please wait 24 hours before voting for this server again!");
                    break;
            }
        }
Пример #15
0
Файл: Z.cs Проект: mawize/Boxes
 public override void Execute(TShockAPI.CommandArgs args)
 {
     if (args.Parameters.Count == 3)
     {
         string boxName = args.Parameters[1];
         if(args.Player.Group.HasPermission("boxes.admin")|| args.Player.Group.Name == "superadmin")
         {
             int z = 0;
             if (int.TryParse(args.Parameters[2], out z))
             {
                 if (boxman.SetZ(boxName, z))
                     ChatHandler.communicate(ChatHandler.CustomSuccess, args.Player, "Box's z is now " + z);
                 else
                     ChatHandler.communicate(ChatHandler.BoxNotFound, args.Player, boxName);
             }
             else
                 ChatHandler.communicate(ChatHandler.InvalidSyntax, args.Player, "z [name] [#]");
         }
         else
             ChatHandler.communicate(ChatHandler.NoPermission, args.Player, boxName);
     }
     else
         ChatHandler.communicate(ChatHandler.InvalidSyntax, args.Player, "z [name] [#]");
 }
Пример #16
0
        private void OnReload(TShockAPI.Hooks.ReloadEventArgs e)
        {
            if (!File.Exists(SavePath))
            {
                AddDefaultsToConfig();
                config.Write(SavePath);
            }
            config.Read(SavePath);

            Regexes.Clear();

            foreach (EmoteRegex regex in config.Emotes)
            {
                Regexes.Add(new Regex(regex.ToString()), regex);
            }

            Commands.ChatCommands.Remove(_emoteCmd);
            _emoteCmd.HelpDesc = config.HelpText;
            Commands.ChatCommands.Add(_emoteCmd);
        }
Пример #17
0
        void TileEdit(Object sender, TShockAPI.GetDataHandlers.TileEditEventArgs args)
        {
            /* Console.WriteLine("Data: "+Main.tile[args.X,args.Y].Data.active+" type:"+Main.tile[args.X,args.Y].Data.type+" wall:"+Main.tile[args.X,args.Y].Data.wall+" -x:"+Main.tile[args.X,args.Y].Data.frameX+" y:"+Main.tile[args.X,args.Y].Data.frameY);
            Console.WriteLine("Active: " + Main.tile[args.X, args.Y].active + " checkLiq: " + Main.tile[args.X, args.Y].checkingLiquid + " framenum: " + Main.tile[args.X, args.Y].frameNumber + " framex:" + Main.tile[args.X, args.Y].frameX + " framey:" + Main.tile[args.X, args.Y].frameY);
            Console.WriteLine("lava: " + Main.tile[args.X, args.Y].lava + " lighted:" + Main.tile[args.X, args.Y].lighted + " liquid:" + Main.tile[args.X, args.Y].liquid + " skipLiq.:" + Main.tile[args.X, args.Y].skipLiquid + " type:" + Main.tile[args.X, args.Y].type);
            Console.WriteLine("wall: " + Main.tile[args.X, args.Y].wall + " wallframenum:" + Main.tile[args.X, args.Y].wallFrameNumber + " wallframeX:" + Main.tile[args.X, args.Y].wallFrameX + " wallframeY:" + Main.tile[args.X, args.Y].wallFrameY + " wire:" + Main.tile[args.X, args.Y].wire);
            */
            if (awaitingPlayers.Count > 0 && awaitingPlayers.Keys.Contains(args.Player.UserID))
            {
                byte awaitingType = awaitingPlayers[args.Player.UserID];
                if (awaitingType == 1)
                {
                    generateBoulder(args.X, args.Y);
                    args.Handled = true;
                    updateTile(args.X, args.Y);
                    if (AddTrap(args.X, args.Y, 138))
                        args.Player.SendMessage("Added Boulder Trap to selected location");
                    else
                        args.Player.SendMessage("Failed to add new trap", Color.Red);
                }
                else if (awaitingType == 2)
                {
                    generateExplosives(args.X, args.Y);
                    args.Handled = true;
                    updateTile(args.X, args.Y);
                    if (AddTrap(args.X, args.Y, 141))
                        args.Player.SendMessage("Added Explosives Trap to selected location");
                    else
                        args.Player.SendMessage("Failed to add new trap", Color.Red);
                }
                else
                {
                    if (DelTrap(args.X,args.Y))
                        args.Player.SendMessage("Removed Trap Reset from selected location");
                    else
                        args.Player.SendMessage("Failed to remove trap", Color.Red);

                }
                awaitingPlayers.Remove(args.Player.UserID);
            }
            /*else if (boulderCannonPlayers.Count > 0 && boulderCannonPlayers.Contains(args.Player.UserID))
            {
                generateBoulder(args.X, args.Y);
                updateTile(args.X, args.Y);
                args.Player.SendTileSquare(args.X, args.Y, 1);
            }
            */
        }
Пример #18
0
        private void OnTileEdit(object sender, TShockAPI.GetDataHandlers.TileEditEventArgs e)
        {
            if (e.Action > GetDataHandlers.EditAction.KillTileNoItem ||
                e.Action == GetDataHandlers.EditAction.KillWall) return;
            if (e.Action == GetDataHandlers.EditAction.PlaceTile && e.EditData == Terraria.ID.TileID.MagicalIceBlock) return;

            lock (players) {
                Player player = findPlayer(e.Player.Index);
                if (player == null) return;
                if (player.regions.Count == 0) return;

                // Stop the edit if a phantom tile is the only thing making it possible.
                foreach (Region region in player.regions) {
                    // Clear the region borders if they break one of the phantom ice blocks.
                    if ((e.Action == GetDataHandlers.EditAction.KillTile || e.Action == GetDataHandlers.EditAction.KillTileNoItem) && (Main.tile[e.X, e.Y] == null || !Main.tile[e.X, e.Y].active()) &&
                        e.X >= region.showArea.Left - 1 && e.X <= region.showArea.Right + 1 && e.Y >= region.showArea.Top - 1 && e.Y <= region.showArea.Bottom + 1 &&
                        !(e.X >= region.showArea.Left + 2 && e.X <= region.showArea.Right - 2 && e.Y >= region.showArea.Top + 2 && e.Y <= region.showArea.Bottom - 2)) {
                        e.Handled = true;
                        //clearRegions(player);
                        break;
                    }
                    if ((e.Action == GetDataHandlers.EditAction.PlaceTile || e.Action == GetDataHandlers.EditAction.PlaceWall) && !tileValidityCheck(region, e.X, e.Y, e.Action)) {
                        e.Handled = true;
                        player.TSPlayer.SendData(PacketTypes.TileSendSquare, "", 1, e.X, e.Y, 0, 0);
                        if (e.Action == GetDataHandlers.EditAction.PlaceTile) giveTile(player, e);
                        if (e.Action == GetDataHandlers.EditAction.PlaceWall) giveWall(player, e);
                        break;
                    }
                }
                if (e.Handled) clearRegions(player);
            }
        }
Пример #19
0
 private void onPlayerCommand(TShockAPI.Hooks.PlayerCommandEventArgs e)
 {
     if (e.Parameters.Count >= 2 && e.CommandName.ToLower() == "region" && new string[] {"delete", "resize", "expand"}.Contains(e.Parameters[0].ToLower())) {
         if (Commands.ChatCommands.Any(c => c.HasAlias("region") && c.CanRun(e.Player)))
             refreshTimer.Interval = 1500;
     }
 }
Пример #20
0
 /// <summary>Returns the item used to attempt a rejected background wall edit to the player.</summary>
 /// <param name="player">The player attempting the edit</param>
 /// <param name="e">The data from the edit event</param>
 public void giveWall(Player player, TShockAPI.GetDataHandlers.TileEditEventArgs e)
 {
     Item item = new Item(); bool found = false;
     for (int i = 1; i <= Terraria.ID.ItemID.Count; i++) {
         item.SetDefaults(i, true);
         if (item.createWall == e.EditData) {
             found = true;
             break;
         }
     }
     if (found) giveItem(player, item);
 }
Пример #21
0
		public IBankAccount GetBankAccount(TShockAPI.TSPlayer tsPlayer)
		{
			if (tsPlayer == null || RunningJournal == null) {
				return null;
			}

			if (tsPlayer == TSPlayer.Server) {
				return WorldAccount;
			}

			try {
				return RunningJournal.GetBankAccountByName(tsPlayer.UserAccountName);
			} catch (Exception ex) {
				TShock.Log.ConsoleError("seconomy error: Error getting bank account for {0}: {1}", 
					tsPlayer.Name, ex.Message);
				return null;
			}
		}
Пример #22
0
        public static bool MatchUserByPlayerName(string playerName, out TShockAPI.DB.User user, TSPlayer messagesReceiver = null)
        {
            user = null;
              TShockAPI.DB.User tsUser = TShock.Users.GetUserByName(playerName);
              if (tsUser == null) {
            TSPlayer player;
            if (!TShockEx.MatchPlayerByName(playerName, out player, messagesReceiver))
              return false;

            user = TShock.Users.GetUserByID(player.User.ID);
              } else {
            user = tsUser;
              }

              return true;
        }
Пример #23
0
 // showLifeMana ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 private static void showLifeMana( CommandArgs        args,
                               TShockAPI.TSPlayer player )
 {
     args.Player.SendMessage( string.Format( "{0} [Ip:{1}] [Life/Mana: {2}/{3}] [Account: {4}] [Group: {5}]",
                                         player.Name,
                                         player.IP,
                                         player.FirstMaxHP,
                                         player.FirstMaxMP,
                                         player.UserAccountName,
                                         player.Group.Name ), Color.White );
 }
Пример #24
0
        // showInv +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
        private static void showInv( CommandArgs        args,
                                 TShockAPI.TSPlayer player )
        {
            StringBuilder response = new StringBuilder();
              int       row;
              String    itemName;
              List<int> firstSlot = new List<int>(5) {  0, 0, 10, 20, 30 };
              List<int> lastSlot  = new List<int>(5) { -1, 9, 19, 29, 39 };

              if ( args.Parameters.Count == 3 )
              {
            row = Convert.ToInt32( args.Parameters[2] );
            if ( row < firstSlot.Count && lastSlot[row] > 0 )
            {
              for ( int index = firstSlot[row]; index <= lastSlot[row]; index++ ) {
            itemName = player.TPlayer.inventory[index].name;
            if ( itemName.Length == 0 ) { itemName = "(no item)"; } // if
            response.Append( itemName ).Append( " (" );
            response.Append( player.TPlayer.inventory[index].stack ).Append( ")" );
            if ( index < lastSlot[row] ) { response.Append( " | " ); } // if
              } // for
              IEnumerable<string> invLines;
              invLines = SplitByLength( response.ToString(), 100 );
              string firstLine;
              firstLine = invLines.First();
              args.Player.SendMessage( string.Format( "{0}: Inv Row [{1}]: {2}", player.Name, row, firstLine ), Color.White );

              foreach ( string line in invLines )
              {
            if ( !line.Equals( firstLine ) )
            {
              args.Player.SendMessage( line, Color.White );
            } // if
              } // foreach
            } // if
            else
            {
              args.Player.SendMessage( string.Format( "Invalid row: {0}.  Only 1 - 4 are allowed.", row ), Color.Red );
            } // else
              } // if
              else
              {
            args.Player.SendMessage( "Row required for INV action (e.g. iirc name row)", Color.Red );
              } // else
        }
Пример #25
0
        // showBuffs +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
        private static void showBuffs( CommandArgs        args,
                                   TShockAPI.TSPlayer player )
        {
            StringBuilder response = new StringBuilder();
              String buffName;
              bool buffFound = false;
              int buffType;
              int buffCount = player.TPlayer.countBuffs();

              //if ( buffCount > 9 ) buffCount = 9;

              for ( int index = 0; index < buffCount; index++ ) {
            buffType = player.TPlayer.buffType[index];
            if ( buffType > 0 ) {
              buffName = TShock.Utils.GetBuffName( buffType );
              response.Append( buffName ).Append( " (" );
              response.Append( player.TPlayer.buffTime[index] ).Append( ")" );
              if ( index < buffCount-1 ) { response.Append( " | " ); } // if
              buffFound = true;
            } // if
              } // for

              if ( buffFound )
              {
            args.Player.SendMessage( string.Format( "{0}: Buffs: {1}",
                                                player.Name, response ), Color.White );
              } // if
              else
              {
            args.Player.SendMessage( string.Format( "{0} has no Buffs", player.Name, Color.White ) );
              } // else
        }
Пример #26
0
        // showAmm +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
        private static void showAmm( CommandArgs        args,
                                 TShockAPI.TSPlayer player )
        {
            StringBuilder response = new StringBuilder();
              String itemName;
              int firstSlot = 44, lastSlot = 47;

              for ( int index = firstSlot; index <= lastSlot; index++ ) {
            itemName = player.TPlayer.inventory[index].name;
            if ( itemName.Length == 0 ) { itemName = "(no item)"; } // if
            response.Append( itemName ).Append( " (" );
            response.Append( player.TPlayer.inventory[index].stack ).Append( ")" );
            if ( index < lastSlot ) { response.Append( " | " ); } // if
              } // for

              args.Player.SendMessage( string.Format( "{0}: Ammo: {1}", player.Name, response), Color.White );
        }
        private void OnPostLogin(TShockAPI.Hooks.PlayerPostLoginEventArgs Args)
        {
            IBasicProperties replyProps = OverallInformations.channel.CreateBasicProperties();
            Request01 RequestContent = new Request01()
            {
                RequestType = "APlayerLogin",
                Parameters = new List<string>()
                {
                    Args.Player.Name,
                    Args.Player.User.Name
                }
            };
            string RequestString = Newtonsoft.Json.JsonConvert.SerializeObject(RequestContent);
            byte[] RequestBytes = Encoding.UTF8.GetBytes(RequestString);

            OverallInformations.channel.BasicPublish(exchange: OverallInformations.LauncherServerTShockExchange, routingKey: OverallInformations.LauncherServerGetRequestFromTShockRouterKey, basicProperties: replyProps, body: RequestBytes);
        }
        private void OnPlayerCommand(TShockAPI.Hooks.PlayerCommandEventArgs Args)
        {
            if (Args.Handled)
            {
                return;
            }

            IBasicProperties ReplyProps = OverallInformations.channel.CreateBasicProperties();
               TShockACommandInformations aCommand = new TShockACommandInformations()
            {
                CommandName = Args.CommandName,
                CommandPrefix = Args.CommandPrefix,
                CommandText = Args.CommandText,
                Parameters = Args.Parameters,
                PlayerName = Args.Player.Name
            };

            if (Args.Player.User != null)
            {
                aCommand.UserName = Args.Player.User.Name;
            }

            Request01 RequestContent = new Request01()
            {
                RequestType = "PlayerCommand",
                Parameters = new List<string>()
                {
                    Newtonsoft.Json.JsonConvert.SerializeObject(aCommand)
                }
            };

            string RequestString = Newtonsoft.Json.JsonConvert.SerializeObject(RequestContent);
            byte[] RequestBytes = Encoding.UTF8.GetBytes(RequestString);

            OverallInformations.channel.BasicPublish(exchange: OverallInformations.LauncherServerTShockExchange, routingKey: OverallInformations.LauncherServerGetRequestFromTShockRouterKey, basicProperties: ReplyProps, body: RequestBytes);
        }
Пример #29
0
        // showAcc +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
        // These have the same source array (armor), just different indexes
        private static void showAccArm( CommandArgs        args,
                                    TShockAPI.TSPlayer player,
                                    bool               acc    )
        {
            StringBuilder response = new StringBuilder();
              String itemName, type;
              int    firstSlot, lastSlot;

              if ( acc )  { type = "Access"; firstSlot = 3; lastSlot  = 7; } // if
              else        { type = "Armour"; firstSlot = 0; lastSlot  = 2; } // else

            //      args.Player.SendMessage( string.Format( "~ type: {0}", type ), Color.Pink );
            //      args.Player.SendMessage( string.Format( "~ name: {0}", player.Name ), Color.Pink );

              for ( int index = firstSlot; index <= lastSlot; index++ ) {
            itemName = player.TPlayer.armor[index].name;
            //        args.Player.SendMessage( string.Format( "~ {0}: [{1}]", type, itemName ), Color.Pink );
            if ( itemName.Length == 0 ) { itemName = "(no item)"; } // if
            response.Append( itemName );
            if ( index < lastSlot ) { response.Append( " | " ); } // if
              } // for

              args.Player.SendMessage( string.Format( "{0}: {1}: {2}", player.Name, type, response ), Color.White );
        }
Пример #30
0
        private void OnChat(TShockAPI.Hooks.PlayerCommandEventArgs args)
        {
            //If the used command is an existing command, ignore.
            if (Commands.TShockCommands.Count(p => p.Name == args.CommandName) > 0 || Commands.ChatCommands.Count(p => p.Name == args.CommandName) > 0)
            {
                return;
            }

            //Check if our config has the typed command
            if (config.shortcommands.ContainsKey(args.CommandName))
            {
                KeyValuePair<string, string> shortcmd = new KeyValuePair<string, string>();

                //Retrieve the long commands by finding the short command.
                foreach (KeyValuePair<string, string> thecommand in config.shortcommands)
                {
                    if (args.CommandName == thecommand.Key)
                    {
                        shortcmd = thecommand;
                    }
                }

                //Split the long commands into the different commands
                List<string> usecmds = shortcmd.Value.Split(';').ToList();
                List<string> usecmdnames = new List<string>();

                //Make a separate list of the actual command names
                foreach (string cmd in usecmds)
                {
                    usecmdnames.Add(cmd.Split(' ')[0]);
                }

                //Loop through each bound command
                for (int j = 0; j < usecmds.Count; j++)
                {
                    //Temporarily store the individual command & name
                    string usecmd = usecmds[j];
                    string usecmdname = usecmdnames[j];

                    //Check if the command is real or not (no shortcommands!)
                    if (Commands.TShockCommands.Count(p => p.Name == usecmdname) == 0 && Commands.ChatCommands.Count(p => p.Name == usecmdname) == 0)
                    {
                        args.Player.SendErrorMessage("Unknown command: {0}", usecmdname);
                        TShock.Log.Warn("Unknown ShortCommand entry: {0}", usecmdname);
                        args.Handled = true;
                        return;
                    }

                    //Handle replacing params with {0} and {+}
                    List<string> param = new List<string>();

                    for (int i = 0; i < args.Parameters.Count; i++)
                    {
                        param.Add(args.Parameters[i]);
                    }

                    int replaced = 0;

                    for (int i = 0; i < 10; i++)
                    {
                        string replacer = "{" + i.ToString() + "}";
                        if (usecmd.Contains(replacer) && param.Count > i)
                        {
                            usecmd = usecmd.Replace(replacer, param[i]);
                            replaced++;
                        }
                        else
                            break;
                    }

                    while (replaced > 0)
                    {
                        param.RemoveAt(0);
                        replaced--;
                    }

                    string replacer2 = "{+}";
                    if (usecmd.Contains(replacer2) && param.Count > 0)
                    {
                        usecmd = usecmd.Replace(replacer2, string.Join(" ", param.Select(p => p)));
                    }

                    string replacer3 = "{player}";
                    if (usecmd.Contains(replacer3))
                    {
                        usecmd = usecmd.Replace(replacer3, args.Player.User.Name);
                    }

                    string replacer4 = "{website}";
                    if (usecmd.Contains(replacer4))
                    {
                        usecmd = usecmd.Replace(replacer4, config.website);
                    }

                    //Handle the Command.
                    Commands.HandleCommand(args.Player, string.Format("{0}{1}", args.CommandPrefix, usecmd));
                } //Loop back through the rest of the bound commands

                //Don't let TShock handle it (it would give "Invalid Command" after already running the commands.
                args.Handled = true;
            }
        }