============
*/
extern qbool prvm_runawaycheck;
-static size_t Cmd_PreprocessString(cmd_state_t *cmd, const char *intext, char *outtext, unsigned maxoutlen, cmd_alias_t *alias);
void Cbuf_Execute (cmd_buf_t *cbuf)
{
cmd_input_t *current;
- char preprocessed[MAX_INPUTLINE];
- size_t preprocessed_len;
- char *firstchar;
unsigned int i = 0;
// LadyHavoc: making sure the tokenizebuffer doesn't get filled up by repeated crashes
*/
current->pending = false;
+ Cmd_PreprocessAndExecuteString(current->source, current->text, current->length, src_local, false);
cbuf->size -= current->length;
-
- firstchar = current->text;
- while(*firstchar && ISWHITESPACE(*firstchar))
- ++firstchar;
- if((strncmp(firstchar, "alias", 5) || !ISWHITESPACE(firstchar[5]))
- && (strncmp(firstchar, "bind", 4) || !ISWHITESPACE(firstchar[4]))
- && (strncmp(firstchar, "in_bind", 7) || !ISWHITESPACE(firstchar[7])))
- {
- if((preprocessed_len = Cmd_PreprocessString(current->source, current->text, preprocessed, sizeof(preprocessed), NULL)))
- Cmd_ExecuteString(current->source, preprocessed, preprocessed_len, src_local, false);
- }
- else
- {
- Cmd_ExecuteString(current->source, current->text, current->length, src_local, false);
- }
-
// Recycle memory so using WASD doesn't cause a malloc and free
List_Move_Tail(¤t->list, &cbuf->free);
- current = NULL;
-
if (cbuf->wait)
{
/*
Cbuf_InsertText(cmd, buffer2);
}
+void Cmd_PreprocessAndExecuteString(cmd_state_t *cmd, const char *text, size_t textlen, cmd_source_t src, qbool lockmutex)
+{
+ char preprocessed[MAX_INPUTLINE];
+ size_t preprocessed_len;
+ const char *firstchar;
+
+ firstchar = text;
+ while(*firstchar && ISWHITESPACE(*firstchar))
+ ++firstchar;
+ if((strncmp(firstchar, "alias", 5) || !ISWHITESPACE(firstchar[5]))
+ && (strncmp(firstchar, "bind", 4) || !ISWHITESPACE(firstchar[4]))
+ && (strncmp(firstchar, "in_bind", 7) || !ISWHITESPACE(firstchar[7])))
+ {
+ if((preprocessed_len = Cmd_PreprocessString(cmd, text, preprocessed, sizeof(preprocessed), NULL)))
+ Cmd_ExecuteString(cmd, preprocessed, preprocessed_len, src, lockmutex);
+ }
+ else
+ Cmd_ExecuteString(cmd, text, textlen, src, lockmutex);
+}
+
/*
========
Cmd_List
/// Parses a single line of text into arguments and tries to execute it.
/// The text can come from the command buffer, a remote client, or stdin.
void Cmd_ExecuteString(cmd_state_t *cmd, const char *text, size_t textlen, cmd_source_t src, qbool lockmutex);
+/// Like Cmd_ExecuteString, but with variable expansion.
+void Cmd_PreprocessAndExecuteString(cmd_state_t *cmd, const char *text, size_t textlen, cmd_source_t src, qbool lockmutex);
/// quotes a string so that it can be used as a command argument again;
/// quoteset is a string that contains one or more of ", \, $ and specifies
while((userpass_end = strchr(userpass_start, ' ')))
{
have_usernames = true;
- dp_strlcpy(buf, userpass_start, ((size_t)(userpass_end-userpass_start) >= sizeof(buf)) ? (int)(sizeof(buf)) : (int)(userpass_end-userpass_start+1));
+ dp_ustr2stp(buf, sizeof(buf), userpass_start, userpass_end - userpass_start);
if(buf[0]) // Ignore empty entries due to leading/duplicate space.
if(comparator(peeraddress, buf, password, cs, cslen))
goto allow;
while((userpass_end = strchr(userpass_start, ' ')))
{
have_usernames = true;
- dp_strlcpy(buf, userpass_start, ((size_t)(userpass_end-userpass_start) >= sizeof(buf)) ? (int)(sizeof(buf)) : (int)(userpass_end-userpass_start+1));
+ dp_ustr2stp(buf, sizeof(buf), userpass_start, userpass_end - userpass_start);
if(buf[0]) // Ignore empty entries due to leading/duplicate space.
if(comparator(peeraddress, buf, password, cs, cslen))
goto check;
if(l)
{
client_t *host_client_save = host_client;
- //Cmd_ExecuteString(cmd_local, s, src_local, true); // no variable expansion
- // bones_was_here: prepending allows a loop such as `alias foo "bar; wait; foo"; foo`
- // to be broken with an alias or unalias command
- Cbuf_InsertText(cmd_local, s);
+ Cmd_PreprocessAndExecuteString(cmd_local, s, l, src_local, true);
host_client = host_client_save;
// in case it is a command that changes host_client (like restart)
}