예제 #1
0
 /// <summary>
 /// Emits a message to TerrariaChatRelay that a client message have been received.
 /// </summary>
 /// <param name="sender">Object that is emitting this event.</param>
 /// <param name="user">User object detailing the client source and username</param>
 /// <param name="msg">Text content of the message</param>
 /// <param name="commandPrefix">Command prefix to indicate a command is being used.</param>
 /// <param name="clientPrefix">String to insert before the main chat message.</param>
 /// <param name="sourceChannelId">Optional id for clients that require id's to send to channels. Id of the channel the message originated from.</param>
 public static void RaiseClientMessageReceived(object sender, TCRClientUser user, string clientPrefix, string msg, string commandPrefix, ulong sourceChannelId = 0)
 {
     if (CommandServ.IsCommand(msg, commandPrefix))
     {
         var payload = CommandServ.GetExecutableCommand(msg, commandPrefix, user);
         msg = payload.Execute();
         ((IChatClient)sender).HandleCommand(payload, msg, sourceChannelId);
     }
     else
     {
         _adapter.BroadcastChatMessage($"{clientPrefix}<{user.Username}> {msg}", -1);
         OnClientMessageReceived?.Invoke(sender, new ClientChatEventArgs(user, msg));
     }
 }
        /// <summary>
        /// Parses raw chat message and returns an executable command payload.
        /// </summary>
        /// <param name="input">Raw chat message from client user.</param>
        /// <param name="commandPrefix">Command prefix to indicate a command is being used.</param>
        /// <returns>Command payload with associated data and user to run it.</returns>
        public ICommandPayload GetExecutableCommand(string input, string commandPrefix, TCRClientUser user)
        {
            string commandKey = input.Remove(0, commandPrefix.Length);
            string parameters = "";

            int indexOfSeparator = commandKey.IndexOf(' ');

            if (indexOfSeparator > 0)
            {
                parameters = commandKey.Substring(indexOfSeparator + 1, commandKey.Length - indexOfSeparator - 1);
                commandKey = commandKey.Substring(0, indexOfSeparator);
            }

            return(new CommandPayload(this, Commands[commandKey], parameters, user));
        }
예제 #3
0
 /// <summary>
 /// Message payload sent to subscribers when a game message has been received.
 /// </summary>
 /// <param name="player">Id of player in respect to Main.Player[i], where i is the index of the player.</param>
 /// <param name="color">Color to display the text.</param>
 /// <param name="msg">Text content of the message</param>
 public ClientChatEventArgs(TCRClientUser user, string msg)
 {
     User    = user;
     Message = msg;
 }
예제 #4
0
 /// <summary>
 /// Emits a message to TerrariaChatRelay that a client message have been received.
 /// </summary>
 /// <param name="sender">Object that is emitting this event.</param>
 /// <param name="user">User object detailing the client source and username</param>
 /// <param name="msg">Text content of the message</param>
 /// <param name="commandPrefix">Command prefix to indicate a command is being used.</param>
 /// <param name="sourceChannelId">Optional id for clients that require id's to send to channels. Id of the channel the message originated from.</param>
 public static void RaiseClientMessageReceived(object sender, TCRClientUser user, string msg, string commandPrefix, ulong sourceChannelId = 0)
 => RaiseClientMessageReceived(sender, user, "", msg, commandPrefix, sourceChannelId);
 public string Execute(string input = null, TCRClientUser whoRanCommand = null)
 {
     Main.ExecuteCommand(input, new TCRCommandCaller());
     return("Command executed.");
 }