void deathlog_command(const char *arg, struct session *ses) { FILE *fh; char fname[BUFFER_SIZE], text[BUFFER_SIZE], temp[BUFFER_SIZE], lfname[BUFFER_SIZE]; if (*arg) { arg = get_arg_in_braces(arg, temp, 0); arg = get_arg_in_braces(arg, text, 1); substitute_vars(temp, fname); substitute_myvars(fname, temp, ses); expand_filename(temp, fname, lfname); substitute_vars(text, temp); substitute_myvars(temp, text, ses); if ((fh = fopen(lfname, "a"))) { cfprintf(fh, "%s\n", text); fclose(fh); } else tintin_eprintf(ses, "#ERROR: COULDN'T OPEN FILE {%s}.", fname); } else tintin_eprintf(ses, "#ERROR: valid syntax is: #deathlog <file> <text>"); }
void strcmp_command(wchar_t *arg) { wchar_t arg1[BUFFER_SIZE], arg2[BUFFER_SIZE], if_then[BUFFER_SIZE], if_else[BUFFER_SIZE], temp[BUFFER_SIZE]; arg = get_arg_in_braces(arg,arg1,STOP_SPACES,sizeof(arg1)/sizeof(wchar_t)-1); substitute_vars(arg1,temp, sizeof(temp)/sizeof(wchar_t)); substitute_myvars(temp,arg1, sizeof(arg1)/sizeof(wchar_t)); arg = get_arg_in_braces(arg,arg2,STOP_SPACES,sizeof(arg2)/sizeof(wchar_t)-1); substitute_vars(arg2,temp, sizeof(temp)/sizeof(wchar_t)); substitute_myvars(temp,arg2, sizeof(arg2)/sizeof(wchar_t)); arg = get_arg_in_braces(arg,if_then,WITH_SPACES,sizeof(if_then)/sizeof(wchar_t)-1); substitute_vars(if_then,temp, sizeof(temp)/sizeof(wchar_t)); substitute_myvars(temp,if_then, sizeof(if_then)/sizeof(wchar_t)); arg = get_arg_in_braces(arg,if_else,WITH_SPACES,sizeof(if_else)/sizeof(wchar_t)-1); substitute_vars(if_else,temp, sizeof(temp)/sizeof(wchar_t)); substitute_myvars(temp,if_else, sizeof(if_else)/sizeof(wchar_t)); wchar_t *to_parse = !wcscmp(arg1, arg2) ? if_then : if_else; if( to_parse && wcslen(to_parse) ) { parse_input(to_parse); } }
void math_command(wchar_t *line) { wchar_t left[BUFFER_SIZE], right[BUFFER_SIZE], temp[BUFFER_SIZE], result[BUFFER_SIZE]; int i; line=get_arg_in_braces(line,left,STOP_SPACES,sizeof(left)/sizeof(wchar_t)-1); line=get_arg_in_braces(line,right,WITH_SPACES,sizeof(right)/sizeof(wchar_t)-1); substitute_vars(right, result, sizeof(result)/sizeof(wchar_t)); substitute_myvars(result, right, sizeof(right)/sizeof(wchar_t)); i=eval_expression(right); swprintf(temp,L"%d",i); VAR_INDEX ind = VarList.find(left); VAR* pvar; if ( ind != VarList.end() ) { pvar = ind->second; pvar->m_strVal = temp; } else { pvar = new VAR(temp); VarList[left] = pvar; } }
void if_command(wchar_t *line) { wchar_t if_expr[BUFFER_SIZE], if_then[BUFFER_SIZE], if_else[BUFFER_SIZE], temp[BUFFER_SIZE]; line=get_arg_in_braces(line,if_expr,STOP_SPACES,sizeof(if_expr)/sizeof(wchar_t)-1); substitute_vars(if_expr,temp, sizeof(temp)/sizeof(wchar_t));substitute_myvars(temp,if_expr, sizeof(if_expr)/sizeof(wchar_t)); line=get_arg_in_braces(line,if_then,WITH_SPACES,sizeof(if_then)/sizeof(wchar_t)-1); substitute_vars(if_then,temp, sizeof(temp)/sizeof(wchar_t));substitute_myvars(temp,if_then, sizeof(if_then)/sizeof(wchar_t)); line=get_arg_in_braces(line,if_else,WITH_SPACES,sizeof(if_else)/sizeof(wchar_t)-1); substitute_vars(if_else,temp, sizeof(temp)/sizeof(wchar_t));substitute_myvars(temp,if_else, sizeof(if_else)/sizeof(wchar_t)); wchar_t *to_parse = eval_expression(if_expr) ? if_then : if_else; if( to_parse && wcslen(to_parse) ) { parse_input(to_parse); } }
void unlink_command(const char *arg, struct session *ses) { char file[BUFFER_SIZE], temp[BUFFER_SIZE], lstr[BUFFER_SIZE]; if (*arg) { arg = get_arg_in_braces(arg, temp, 1); substitute_vars(temp, file); substitute_myvars(file, temp, ses); expand_filename(temp, file, lstr); unlink(lstr); } else tintin_eprintf(ses, "#ERROR: valid syntax is: #unlink <filename>"); }
void parse_input(char *input) { char command[BUFFER_SIZE], arg[BUFFER_SIZE], result[BUFFER_SIZE]; char *input2; bPasswordEcho = TRUE; if(*input=='\0') { write_line_mud(""); return ; } if ( verbatim && *input == cCommandChar && *(input+1) == 'v' ) {// check verbatim command char command[BUFFER_SIZE]; char* input2=get_arg_stop_spaces(input+1, command); if(command[0] == 'v' && is_abrev(command, "verbatim")){ char arg[BUFFER_SIZE]; get_arg_all(input2, arg); verbatim_command(arg); return; } } if (verbatim ) { write_line_mud(input); return ; } if (*input==verbatim_char) { input++; write_line_mud(input); return ; } substitute_myvars(input, result); input2=result; while(*input2) { //* en:colon // if(*input2==';') if(*input2==cCommandDelimiter||(bColon && *input2==';')&&*(input2-1)!='\\') input2++; //*/en input2=get_arg_stop_spaces(input2, command); input2=get_arg_all(input2, arg); //* en:prefix if(s_prefix[0] && command[0] != cCommandChar) { char p_command[BUFFER_SIZE]; strcpy(p_command,command); strcat(p_command," "); strcat(p_command,arg); strcpy(command,s_prefix); strcpy(arg,p_command); } //*/en if(*command==cCommandChar) { if (bDisplayCommands) { // output command in square brackets char strInputCommand[BUFFER_SIZE], strOutputBuffer[BUFFER_SIZE]; strcpy(strInputCommand, "\n["); strcat(strInputCommand, command); if (*arg != '\0') { strcat(strInputCommand, " "); strcat(strInputCommand, arg); } strcat(strInputCommand, "]"); add_codes(strInputCommand, strOutputBuffer, "brown", TRUE); tintin_puts2(strOutputBuffer); if (hLogFile.is_open()) { log(strInputCommand); } } parse_tintin_command(command+1, arg); } //* en:comments else if(*command==cCommentChar); //*/en else { //* en:waits if(iWaitState>0) { char *ptr1,*ptr2; for(ptr1=mQueue;*ptr1&&*ptr1!='\0';ptr1++); *ptr1++=cCommandDelimiter; for(ptr2=command;*ptr2&&*ptr2!='\0';ptr2++,ptr1++) *ptr1=*ptr2; if(*arg) *ptr1++=' '; for(ptr2=arg;*ptr2&&*ptr2!='\0';ptr2++,ptr1++) *ptr1=*ptr2; *ptr1++='\0'; continue; } //* en ALIAS_INDEX ind; if( (ind=AliasList.find(command)) != AliasList.end() && ind->second->m_pGroup->m_bEnabled ) { int i; char *cpsource, *cpsource2, newcommand[BUFFER_SIZE], end; strcpy(vars[0], arg); for(i=1, cpsource=arg; i<10; i++) { /* Next lines CHANGED to allow argument grouping with aliases */ while (*cpsource == ' ') cpsource++; end = (*cpsource == '{') ? '}' : ' '; cpsource = (*cpsource == '{') ? cpsource+1 : cpsource; for(cpsource2=cpsource; *cpsource2 && *cpsource2!=end; cpsource2++); strncpy(vars[i], cpsource, cpsource2-cpsource); *(vars[i]+(cpsource2-cpsource))='\0'; cpsource=(*cpsource2) ? cpsource2+1 : cpsource2; } ALIAS* pal = ind->second; prepare_actionalias((char*)pal->m_strRight.data(), newcommand); if(!strcmp(pal->m_strRight.data(), newcommand) && *arg) { strcat(newcommand, " "); strcat(newcommand, arg); } parse_input(newcommand); } else if(speedwalk && !*arg && is_speedwalk_dirs(command)) do_speedwalk(command); else { get_arg_with_spaces(arg,arg); write_com_arg_mud(command, arg); } } } return; }
void dogoto_command(const char *arg, struct session *ses) { char A[BUFFER_SIZE], B[BUFFER_SIZE], distvar[BUFFER_SIZE], locvar[BUFFER_SIZE], pathvar[BUFFER_SIZE]; char left[BUFFER_SIZE], right[BUFFER_SIZE], tmp[BUFFER_SIZE], cond[BUFFER_SIZE]; int a, b, i, j, s; int d[MAX_LOCATIONS], ok[MAX_LOCATIONS], way[MAX_LOCATIONS]; char path[BUFFER_SIZE], *pptr; arg=get_arg(arg, A, 0, ses); arg=get_arg(arg, B, 0, ses); arg=get_arg(arg, distvar, 0, ses); arg=get_arg(arg, locvar, 0, ses); arg=get_arg(arg, pathvar, 0, ses); if ((!*A)||(!*B)) { tintin_eprintf(ses, "#SYNTAX: #dogoto <from> <to> [<distvar> [<locvar> [<pathvar>]]] [#else ...]"); return; } bool flag=*distvar||*locvar||*pathvar; for (a=0;a<MAX_LOCATIONS;a++) if (ses->locations[a]&&!strcmp(ses->locations[a], A)) break; if (a==MAX_LOCATIONS) goto not_found; for (b=0;b<MAX_LOCATIONS;b++) if (ses->locations[b]&&!strcmp(ses->locations[b], B)) break; if (b==MAX_LOCATIONS) goto not_found; for (i=0;i<MAX_LOCATIONS;i++) { d[i]=INF; ok[i]=0; } d[a]=0; do { s=INF; for (j=0;j<MAX_LOCATIONS;j++) if (!ok[j]&&(d[j]<s)) s=d[i=j]; if (s==INF) goto not_found; ok[i]=1; for (struct routenode *r=ses->routes[i];r;r=r->next) if (d[r->dest]>s+r->distance) { if (!*(r->cond)) goto good; substitute_vars(r->cond, tmp); substitute_myvars(tmp, cond, ses); if (eval_expression(cond, ses)) { good: d[r->dest]=s+r->distance; way[r->dest]=i; } } } while (!ok[b]); sprintf(tmp, "%d", d[b]); if (*distvar) set_variable(distvar, tmp, ses); j=0; for (i=b;i!=a;i=way[i]) d[j++]=i; d[j]=a; pptr=path; for (i=j;i>=0;i--) pptr+=snprintf(pptr, path-pptr+BUFFER_SIZE, " %s", ses->locations[d[i]]); pptr=path+(pptr!=path); if (*locvar) set_variable(locvar, pptr, ses); pptr=path; for (i=j;i>0;i--) { for (struct routenode *r=ses->routes[d[i]];r;r=r->next) if (r->dest==d[i-1]) { if (flag) pptr+=snprintf(pptr, path-pptr+BUFFER_SIZE, " {%s}", r->path); else { tintin_printf(ses, "%-10s>%-10s {%s}", ses->locations[d[i]], ses->locations[d[i-1]], r->path); } } } pptr=path+(pptr!=path); if (*pathvar) set_variable(pathvar, pptr, ses); return; not_found: arg=get_arg_in_braces(arg, left, 0); if (*left == tintin_char) { if (is_abrev(left + 1, "else")) { get_arg_in_braces(arg, right, 1); parse_input(right, true, ses); return; } if (is_abrev(left + 1, "elif")) { if_command(arg, ses); return; } } if (*left) tintin_eprintf(ses, "#ERROR: cruft after #dogoto: {%s}", left); if (!flag) tintin_printf(ses, "No paths from %s to %s found.", A, B); }
void goto_command(const char *arg, struct session *ses) { char A[BUFFER_SIZE], B[BUFFER_SIZE], tmp[BUFFER_SIZE], cond[BUFFER_SIZE]; int a, b, i, j, s; int d[MAX_LOCATIONS], ok[MAX_LOCATIONS], way[MAX_LOCATIONS]; char *path[MAX_LOCATIONS], *locs[MAX_LOCATIONS]; arg=get_arg(arg, A, 0, ses); arg=get_arg(arg, B, 1, ses); if ((!*A)||(!*B)) { tintin_eprintf(ses, "#SYNTAX: #goto <from> <to>"); return; } for (a=0;a<MAX_LOCATIONS;a++) if (ses->locations[a]&&!strcmp(ses->locations[a], A)) break; if (a==MAX_LOCATIONS) { tintin_eprintf(ses, "#Location not found: [%s]", A); return; } for (b=0;b<MAX_LOCATIONS;b++) if (ses->locations[b]&&!strcmp(ses->locations[b], B)) break; if (b==MAX_LOCATIONS) { tintin_eprintf(ses, "#Location not found: [%s]", B); return; } for (i=0;i<MAX_LOCATIONS;i++) { d[i]=INF; ok[i]=0; } d[a]=0; do { s=INF; for (j=0;j<MAX_LOCATIONS;j++) if (!ok[j]&&(d[j]<s)) s=d[i=j]; if (s==INF) { tintin_eprintf(ses, "#No route from %s to %s!", A, B); return; } ok[i]=1; for (struct routenode *r=ses->routes[i];r;r=r->next) if (d[r->dest]>s+r->distance) { if (!*(r->cond)) goto good; substitute_vars(r->cond, tmp); substitute_myvars(tmp, cond, ses); if (eval_expression(cond, ses)) { good: d[r->dest]=s+r->distance; way[r->dest]=i; } } } while (!ok[b]); j=0; for (i=b;i!=a;i=way[i]) d[j++]=i; for (d[i=j]=a;i>0;i--) { locs[i]=mystrdup(ses->locations[d[i]]); for (struct routenode *r=ses->routes[d[i]];r;r=r->next) if (r->dest==d[i-1]) path[i]=mystrdup(r->path); } /* we need to copy all used route data (paths and location names) because of ugly bad users who can use #unroute in the middle of a #go command */ locs[0]=mystrdup(ses->locations[b]); for (i=j;i>0;i--) { if (ses->mesvar[MSG_GOTO]) { tintin_printf(ses, "#going from %s to %s", locs[i], locs[i-1]); } parse_input(path[i], true, ses); } for (i=j;i>=0;i--) SFREE(locs[i]); for (i=j;i>0;i--) SFREE(path[i]); set_variable("loc", B, ses); }